2015-01-29 11:27:38 +00:00
|
|
|
//clang++ -std=c++11 test.cpp && ./a.out && dot test.dot -Tpdf -otest.pdf && open test.pdf
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <regex>
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
typedef struct{
|
2015-01-29 22:10:34 +00:00
|
|
|
string name;
|
|
|
|
string drv_comp_name;
|
|
|
|
string drv_pin_name;
|
|
|
|
float value;
|
|
|
|
}pin_t;
|
|
|
|
|
|
|
|
typedef struct{
|
|
|
|
string name;
|
|
|
|
map<string,pin_t> pins;
|
2015-01-29 11:27:38 +00:00
|
|
|
}comp_t;
|
|
|
|
|
|
|
|
int main(){
|
2015-01-29 22:10:34 +00:00
|
|
|
bool include_unlinked_comps = false;
|
|
|
|
bool include_unlinked_pins = true;
|
|
|
|
|
|
|
|
map<string, comp_t> comps;
|
|
|
|
|
2015-01-29 11:27:38 +00:00
|
|
|
ifstream halfile("test.hal", fstream::in);
|
|
|
|
ofstream dotfile("test.dot", fstream::out);
|
|
|
|
string s((std::istreambuf_iterator<char>(halfile)), std::istreambuf_iterator<char>());
|
|
|
|
smatch m;
|
|
|
|
//m[] 1 2 3 4 5
|
|
|
|
regex e("(\\w+).(\\w+) <= (\\w+).(\\w+) = (.+)");
|
|
|
|
while(std::regex_search (s,m,e)){
|
2015-01-29 22:10:34 +00:00
|
|
|
comps[m[1].str()].name = m[1].str();
|
|
|
|
comps[m[1].str()].pins[m[2].str()].name = m[2].str();
|
|
|
|
comps[m[1].str()].pins[m[2].str()].drv_comp_name = m[3].str();
|
|
|
|
comps[m[1].str()].pins[m[2].str()].drv_pin_name = m[4].str();
|
|
|
|
comps[m[1].str()].pins[m[2].str()].value = stod(m[5].str());
|
2015-01-29 22:41:47 +00:00
|
|
|
|
2015-01-29 11:27:38 +00:00
|
|
|
s = m.suffix().str();
|
|
|
|
}
|
2015-01-29 18:35:23 +00:00
|
|
|
|
2015-01-29 11:27:38 +00:00
|
|
|
dotfile << "digraph G {" << endl;
|
2015-01-30 02:56:51 +00:00
|
|
|
dotfile << " rankdir = LR;" << endl;
|
2015-08-21 12:38:18 +00:00
|
|
|
dotfile << " ranksep = 2.0;" << endl;
|
|
|
|
//dotfile << " remincross = true;" << endl;
|
|
|
|
// dotfile << " splines = true;" << endl;
|
|
|
|
dotfile << " splines = spline;" << endl;
|
|
|
|
dotfile << " overlap = false;" << endl;
|
|
|
|
//dotfile << " concentrate = true;" << endl;
|
|
|
|
//dotfile << " start = regular;" << endl;
|
|
|
|
//dotfile << " forcelabels = true;" << endl;
|
|
|
|
dotfile << " nodesep = 0.5;" << endl;
|
2015-01-29 18:35:23 +00:00
|
|
|
|
2015-01-29 11:27:38 +00:00
|
|
|
for(auto &comp:comps){
|
2015-08-21 12:38:18 +00:00
|
|
|
dotfile << " " << comp.second.name << "[shape = \"none\", label = <<table border=\"2\" cellspacing=\"0\">\n <tr><td border=\"1\" bgcolor=\"#FFD08E\"> " << comp.second.name << "</td></tr>\n";
|
2015-01-29 22:10:34 +00:00
|
|
|
|
2015-01-29 18:34:01 +00:00
|
|
|
for(auto &pin:comp.second.pins){
|
2015-01-29 22:10:34 +00:00
|
|
|
if(include_unlinked_pins || comp.second.name != pin.second.drv_comp_name || pin.second.name != pin.second.drv_pin_name){
|
2015-08-21 12:38:18 +00:00
|
|
|
dotfile << " <tr><td port=\"" << pin.second.name << "\" border = \"1\"> " << pin.second.name << " = " << pin.second.value << " </td></tr>\n";
|
2015-01-29 22:10:34 +00:00
|
|
|
}
|
2015-01-29 18:34:01 +00:00
|
|
|
}
|
2015-08-21 12:38:18 +00:00
|
|
|
dotfile << " </table>>];" << endl;
|
2015-01-29 11:27:38 +00:00
|
|
|
}
|
2015-01-29 18:35:23 +00:00
|
|
|
|
2015-01-29 22:10:34 +00:00
|
|
|
for(auto &comp:comps){
|
|
|
|
for(auto &pin:comp.second.pins){
|
|
|
|
if(comp.second.name != pin.second.drv_comp_name || pin.second.name != pin.second.drv_pin_name){
|
2015-08-21 12:38:18 +00:00
|
|
|
dotfile << " " << pin.second.drv_comp_name << ":" << pin.second.drv_pin_name << " -> " << comp.second.name << ":" << pin.second.name << " [spines = \"ortho\"];" << endl;
|
2015-01-29 22:10:34 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-29 11:27:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dotfile << "}" << endl;
|
|
|
|
return 0;
|
2015-01-29 18:35:23 +00:00
|
|
|
}
|