orcc: handle constants
authorDavid Schleef <ds@schleef.org>
Sun, 28 Jun 2009 07:10:26 +0000 (00:10 -0700)
committerDavid Schleef <ds@schleef.org>
Sun, 28 Jun 2009 07:12:18 +0000 (00:12 -0700)
orc/orcparse.c
tools/orcc.c

index 6fb9c08..e27f5c0 100644 (file)
@@ -137,6 +137,10 @@ orc_parse (const char *code, OrcProgram ***programs)
       } else if (strcmp (token[0], ".param") == 0) {
         int size = strtol (token[1], NULL, 0);
         orc_program_add_parameter (parser->program, size, token[2]);
+      } else if (strcmp (token[0], ".const") == 0) {
+        int size = strtol (token[1], NULL, 0);
+        int value = strtoul (token[3], NULL, 0);
+        orc_program_add_constant (parser->program, size, value, token[2]);
       } else {
         ORC_ERROR("ERROR: unknown directive: %s", token[0]);
       }
index fce5ef1..86938cf 100644 (file)
@@ -354,8 +354,13 @@ output_code (OrcProgram *p, FILE *output)
   for(i=0;i<8;i++){
     var = &p->vars[ORC_VAR_C1 + i];
     if (var->size) {
-      fprintf(output, "      orc_program_add_constant (p, %d, %d, \"%s\");\n",
-          var->size, var->value, varnames[ORC_VAR_C1 + i]);
+      if (var->value != 0x80000000) {
+        fprintf(output, "      orc_program_add_constant (p, %d, %u, \"%s\");\n",
+            var->size, var->value, varnames[ORC_VAR_C1 + i]);
+      } else {
+        fprintf(output, "      orc_program_add_constant (p, %d, 0x%08x, \"%s\");\n",
+            var->size, var->value, varnames[ORC_VAR_C1 + i]);
+      }
     }
   }
   for(i=0;i<8;i++){