Skip to content

Commit 4a7c900

Browse files
emacdo12jeanlego
emacdo12
authored andcommitted
Odin: Improved graph printing tool
1 parent adc6d4b commit 4a7c900

File tree

2 files changed

+56
-23
lines changed

2 files changed

+56
-23
lines changed

ODIN_II/SRC/include/parse_making_ast.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,6 @@ void next_parsed_verilog_file(ast_node_t* file_items_list);
101101
/* VISUALIZATION */
102102
void graphVizOutputAst(std::string path, ast_node_t* top);
103103
void graphVizOutputAst_traverse_node(FILE* fp, ast_node_t* node, ast_node_t* from, int from_num);
104+
void graphVizOutputAst_Var_Declare(FILE* fp, ast_node_t* node, int from_num);
104105

105106
#endif

ODIN_II/SRC/parse_making_ast.cpp

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,55 +1844,87 @@ void graphVizOutputAst_traverse_node(FILE* fp, ast_node_t* node, ast_node_t* fro
18441844
int my_label = unique_label_count++;
18451845
fprintf(fp, "\t%d [label=<", my_label);
18461846

1847-
if (node->identifier_node) {
1848-
fprintf(fp, "%s<br/>", node->identifier_node->types.identifier);
1849-
}
1850-
fprintf(fp, "%s", ids_STR[node->type]);
18511847
switch (node->type) {
18521848
case VAR_DECLARE: {
1853-
std::stringstream temp;
1854-
if (node->types.variable.is_input) temp << " INPUT";
1855-
if (node->types.variable.is_output) temp << " OUTPUT";
1856-
if (node->types.variable.is_inout) temp << " INOUT";
1857-
if (node->types.variable.is_port) temp << " PORT";
1858-
if (node->types.variable.is_parameter) temp << " PARAMETER";
1859-
if (node->types.variable.is_wire) temp << " WIRE";
1860-
if (node->types.variable.is_reg) temp << " REG";
1861-
1862-
fprintf(fp, ": %s", temp.str().c_str());
1849+
if (node->types.variable.is_input)
1850+
fprintf(fp, " input");
1851+
else if (node->types.variable.is_output)
1852+
fprintf(fp, " output");
1853+
else if (node->types.variable.is_inout)
1854+
fprintf(fp, " inout");
1855+
else if (node->types.variable.is_parameter)
1856+
fprintf(fp, " parameter");
1857+
1858+
if (node->types.variable.is_wire)
1859+
fprintf(fp, " wire");
1860+
else if (node->types.variable.is_reg)
1861+
fprintf(fp, " reg");
1862+
1863+
oassert(node->identifier_node != NULL);
1864+
fprintf(fp, " %s", node->identifier_node->types.identifier);
1865+
18631866
break;
18641867
}
18651868
case NUMBERS:
1866-
fprintf(fp, ": %s (%s)",
1869+
fprintf(fp, " %s<br/>%s",
18671870
node->types.vnumber->to_vstring('h').c_str(),
1868-
node->types.vnumber->to_vstring('s').c_str());
1871+
node->types.vnumber->to_vstring('b').c_str());
18691872
break;
18701873

18711874
case UNARY_OPERATION: //fallthrough
18721875
case BINARY_OPERATION:
1873-
fprintf(fp, ": %s", name_based_on_op(node->types.operation.op));
1876+
fprintf(fp, " %s", name_based_on_op(node->types.operation.op));
18741877
break;
18751878

18761879
case IDENTIFIERS:
1877-
fprintf(fp, ": %s", node->types.identifier);
1880+
oassert(node->types.identifier);
1881+
fprintf(fp, " %s", node->types.identifier);
18781882
break;
18791883

18801884
default:
1885+
fprintf(fp, " %s", ids_STR[node->type]);
1886+
if (node->identifier_node) {
1887+
fprintf(fp, "<br/>%s", node->identifier_node->types.identifier);
1888+
}
18811889
break;
18821890
}
1891+
18831892
fprintf(fp, ">];\n");
18841893

18851894
/* print out the connection with the previous node */
18861895
if (from != NULL) {
18871896
fprintf(fp, "\t%d -> %d;\n", from_num, my_label);
18881897
}
1889-
//if (node->identifier_node) {
1890-
// graphVizOutputAst_traverse_node(fp, node->identifier_node, node, my_label, 1);
1891-
//}
1892-
for (long i = 0; i < node->num_children; i++) {
1893-
graphVizOutputAst_traverse_node(fp, node->children[i], node, my_label);
1898+
1899+
if (node->type == VAR_DECLARE) {
1900+
graphVizOutputAst_Var_Declare(fp, node, my_label);
1901+
} else {
1902+
for (long i = 0; i < node->num_children; i++) {
1903+
graphVizOutputAst_traverse_node(fp, node->children[i], node, my_label);
1904+
}
1905+
}
1906+
}
1907+
1908+
/*---------------------------------------------------------------------------------------------
1909+
* (function: graphVizOutputAst_Var_Declare)
1910+
*-------------------------------------------------------------------------------------------*/
1911+
void graphVizOutputAst_Var_Declare(FILE* fp, ast_node_t* node, int from_num) {
1912+
for (int i = 0; i < 4; i += 2) {
1913+
/* range come in pairs so we go two at a time */
1914+
if (node->children[i] && node->children[i + 1]) {
1915+
/* increase the unique count for other nodes since ours is recorded */
1916+
int my_label = unique_label_count++;
1917+
fprintf(fp,
1918+
"\t%d [label=<RANGE_REF>];\n"
1919+
"\t%d -> %d;\n",
1920+
my_label, from_num, my_label);
1921+
1922+
graphVizOutputAst_traverse_node(fp, node->children[i], node, my_label);
1923+
graphVizOutputAst_traverse_node(fp, node->children[i + 1], node, my_label);
1924+
}
18941925
}
18951926
}
1927+
18961928
/*---------------------------------------------------------------------------------------------
18971929
* (function: newVarDeclare) for 2D Array
18981930
*-------------------------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)