#include <build_files.h>
#include <macros.h>
+#include <set>
+#include <string>
+
#define STRINGIFY(val) #val
#define TOSTRING(val) STRINGIFY(val)
#define CHECK(cmd) ({ int ret = (cmd); if (ret == -1) { perror(#cmd " line " TOSTRING(__LINE__)); exit(1); }; ret; })
void print_oper(FILE *f, struct expr *e, const char *parent, const char *label)
{
- fprintf(f, "\"%s\" [shape=diamond,label=\"%s\"];\n", e->id, label);
+ using namespace std;
+ static set<string> seen_expr;
+
fprintf(f, "\"%s\" -> \"%s\";\n", parent, e->id);
- print_expr(f, e->left.expr, e->id, "l", "");
- print_expr(f, e->right.expr, e->id, "r", "");
+
+ if (seen_expr.find(e->id) == seen_expr.end()) {
+ seen_expr.insert(e->id);
+ fprintf(f, "\"%s\" [shape=diamond,label=\"%s\"];\n", e->id, label);
+ print_expr(f, e->left.expr, e->id, "l", "");
+ print_expr(f, e->right.expr, e->id, "r", "");
+ }
}
void print_expr(FILE *f, struct expr *e, const char *parent, const char *suffix, const char *edge_opts)