implement constant folding
authorDavid Schleef <ds@schleef.org>
Fri, 3 Sep 2010 19:29:36 +0000 (12:29 -0700)
committerDavid Schleef <ds@schleef.org>
Fri, 3 Sep 2010 19:29:36 +0000 (12:29 -0700)
orc/orcprogram.c

index 3cfe45b..287b8d6 100644 (file)
@@ -400,6 +400,7 @@ orc_program_add_constant_str (OrcProgram *program, int size,
   char *end;
   int val_i;
   double val_d;
+  int j;
 
   i = ORC_VAR_C1 + program->n_const_vars;
 
@@ -422,6 +423,12 @@ orc_program_add_constant_str (OrcProgram *program, int size,
     }
   }
 
+  for(j=0;j<program->n_const_vars;j++){
+    if (program->vars[ORC_VAR_C1 + j].value.i == program->vars[i].value.i) {
+      return ORC_VAR_C1 + j;
+    }
+  }
+
   program->vars[i].vartype = ORC_VAR_TYPE_CONST;
   program->vars[i].size = size;
   program->vars[i].name = strdup(name);