Skip to content

Instantly share code, notes, and snippets.

@harry830622
Created October 20, 2015 04:55
Show Gist options
  • Save harry830622/56f2c3fadd3fce57aed5 to your computer and use it in GitHub Desktop.
Save harry830622/56f2c3fadd3fce57aed5 to your computer and use it in GitHub Desktop.
// Parsing
Node* root = 0;
map<string, Node*> nodes; //container of all nodes, choose map for easy query
vector<Edge*> edges;
vector<Node*> primary_inputs;
vector<Node*> primary_outputs;
string str = "";
while (getline(delay_file, str)) {
stringstream ss(str);
string tmp = "";
ss >> tmp;
if (tmp == "input") {
ss >> tmp;
tmp = "vsource:" + tmp;
Node* n = new Node(tmp);
nodes.insert(pair<string, Node*>(tmp, n));
primary_inputs.push_back(n);
continue;
}
if (tmp == "output") {
ss >> tmp;
tmp = "vsink:" + tmp;
Node* n = new Node(tmp);
nodes.insert(pair<string, Node*>(tmp, n));
primary_outputs.push_back(n);
continue;
}
if (tmp == "setup") {
// TODO:useless?
continue;
}
if (tmp == "hold") {
// TODO:useless?
continue;
}
Node* tail = 0;
Node* head = 0;
if (nodes.find(tmp) == nodes.end()) {
tail = new Node(tmp);
nodes.insert(pair<string, Node*>(tmp, tail));
} else {
tail = nodes.find(tmp)->second;
}
ss >> tmp;
if (nodes.find(tmp) == nodes.end()) {
head = new Node(tmp);
nodes.insert(pair<string, Node*>(tmp, head));
} else {
head = nodes.find(tmp)->second;
}
double ed, ld;
ss >> ed >> ld;
Edge* e = new Edge(tail, head, ed, ld);
edges.push_back(e);
/* cout << e->tail_->name_ << " " << e->head_->name_ << " " << e->early_delay_ << " " << e->late_delay_ << endl; */
tail->edges_.push_back(e);
}
double clock_period = 0;
while (getline(timing_file, str)) {
stringstream ss(str);
string tmp;
ss >> tmp;
if (tmp == "clock") {
ss >> tmp;
tmp = "vsource:" + tmp;
root = nodes.find(tmp)->second;
ss >> clock_period;
continue;
}
ss >> tmp;
tmp = "vsource:" + tmp;
double eat, lat;
ss >> eat >> lat;
nodes.find(tmp)->second->earliest_arrival_time_ = eat;
nodes.find(tmp)->second->latest_arrival_time_ = lat;
}
vector<pair<string, string> > queries;
while (getline(query_file, str)) {
stringstream ss(str);
string name1 = "";
string name2 = "";
ss >> name1 >> name2;
queries.push_back(pair<string, string>(name1, name2));
/* cout << queries.back().first->name_ << " " << queries.back().second->name_ << endl; */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment