aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gen_code.c45
-rw-r--r--gen_code.h10
2 files changed, 55 insertions, 0 deletions
diff --git a/gen_code.c b/gen_code.c
new file mode 100644
index 0000000..7471e8f
--- /dev/null
+++ b/gen_code.c
@@ -0,0 +1,45 @@
+#include "gen_code.h"
+#include "pc.h"
+
+int gen_label(t)
+ptree *t;
+{
+ int tmp;
+
+ if (!(t->l && t->r))
+ return 0;
+
+ if (t->l) {
+ tmp = gen_label(t->l);
+ t->l->label = (!tmp ? 1 : tmp);
+ } else
+ yyerror("GEN_LABEL: left child NULL, shouldn't happen!\n");
+
+
+ if (t->r)
+ t->r->label = gen_label(t->r);
+ else
+ t->r->label = 0;
+
+
+
+
+ if (t->r->label == t->l->label) {
+ return 1 + t->l->label;
+ } else {
+ return t->r->label > t->l->label ? t->r->label : t->l->label;
+ }
+
+}
+
+
+void gen_code(t)
+ptree *t;
+{
+ /*Test gen_label*/
+ if (t->type == ASSIGNOP){
+ gen_label(t->r);
+ print_tree(t->r);
+ }
+}
+
diff --git a/gen_code.h b/gen_code.h
new file mode 100644
index 0000000..8c9ad00
--- /dev/null
+++ b/gen_code.h
@@ -0,0 +1,10 @@
+#ifndef GEN_CODEH
+#define GEN_CODEH
+
+#include "tree.h"
+void gen_code(ptree*);
+
+void gen_expr(ptree*);
+void gen_statement(ptree*);
+
+#endif