parse: Add n modifiers
authorDavid Schleef <ds@schleef.org>
Mon, 16 May 2011 18:52:19 +0000 (11:52 -0700)
committerDavid Schleef <ds@schleef.org>
Mon, 16 May 2011 18:53:10 +0000 (11:53 -0700)
orc/orcparse.c
orc/orcprogram.c
orc/orcprogram.h
tools/orcc.c

index 385ee26..975e766 100644 (file)
@@ -153,8 +153,40 @@ orc_parse_full (const char *code, OrcProgram ***programs, char **log)
           }
         }
       } else if (strcmp (token[0], ".n") == 0) {
-        int size = strtol (token[1], NULL, 0);
-        orc_program_set_constant_n (parser->program, size);
+        int i;
+        for(i=1;i<n_tokens;i++){
+          if (strcmp (token[i], "mult") == 0) {
+            if (i == n_tokens - 1) {
+              orc_parse_log (parser, "error: line %d: .n mult requires multiple value\n",
+                  parser->line_number);
+            } else {
+              orc_program_set_n_multiple (parser->program,
+                  strtol (token[1], NULL, 0));
+              i++;
+            }
+          } else if (strcmp (token[i], "min") == 0) {
+            if (i == n_tokens - 1) {
+              orc_parse_log (parser, "error: line %d: .n mult requires multiple value\n",
+                  parser->line_number);
+            } else {
+              orc_program_set_n_minimum (parser->program,
+                  strtol (token[1], NULL, 0));
+              i++;
+            }
+          } else if (strcmp (token[i], "max") == 0) {
+            if (i == n_tokens - 1) {
+              orc_parse_log (parser, "error: line %d: .n mult requires multiple value\n",
+                  parser->line_number);
+            } else {
+              orc_program_set_n_maximum (parser->program,
+                  strtol (token[1], NULL, 0));
+              i++;
+            }
+          } else {
+            orc_program_set_constant_n (parser->program,
+                strtol (token[1], NULL, 0));
+          }
+        }
       } else if (strcmp (token[0], ".m") == 0) {
         int size = strtol (token[1], NULL, 0);
         orc_program_set_constant_m (parser->program, size);
index 0371b2b..0e158fc 100644 (file)
@@ -202,6 +202,21 @@ void orc_program_set_constant_n (OrcProgram *program, int n)
   program->constant_n = n;
 }
 
+void orc_program_set_n_multiple (OrcProgram *program, int n)
+{
+  program->n_multiple = n;
+}
+
+void orc_program_set_n_minimum (OrcProgram *program, int n)
+{
+  program->n_minimum = n;
+}
+
+void orc_program_set_n_maximum (OrcProgram *program, int n)
+{
+  program->n_maximum = n;
+}
+
 void orc_program_set_constant_m (OrcProgram *program, int m)
 {
   program->constant_m = m;
@@ -289,31 +304,54 @@ orc_program_dup_temporary (OrcProgram *program, int var, int j)
 }
 
 /**
- * orc_program_add_source:
+ * orc_program_add_source_full:
  * @program: a pointer to an OrcProgram structure
  * @size: size of data values
  * @name: name of variable
+ * @type_name: name of type, or NULL
+ * @alignment: alignment in bytes, or 0
  *
  * Creates a new variable representing a source array.
  *
  * Returns: the index of the new variable
  */
 int
-orc_program_add_source (OrcProgram *program, int size, const char *name)
+orc_program_add_source_full (OrcProgram *program, int size, const char *name,
+    const char *type_name, int alignment)
 {
   int i = ORC_VAR_S1 + program->n_src_vars;
 
   program->vars[i].vartype = ORC_VAR_TYPE_SRC;
   program->vars[i].size = size;
-  program->vars[i].alignment = size;
+  if (alignment == 0) alignment = size;
+  program->vars[i].alignment = alignment;
   program->vars[i].name = strdup(name);
+  if (type_name) {
+    program->vars[i].type_name = strdup(type_name);
+  }
   program->n_src_vars++;
 
   return i;
 }
 
 /**
- * orc_program_add_destination:
+ * orc_program_add_source:
+ * @program: a pointer to an OrcProgram structure
+ * @size: size of data values
+ * @name: name of variable
+ *
+ * Creates a new variable representing a source array.
+ *
+ * Returns: the index of the new variable
+ */
+int
+orc_program_add_source (OrcProgram *program, int size, const char *name)
+{
+  return orc_program_add_source_full (program, size, name, NULL, 0);
+}
+
+/**
+ * orc_program_add_destination_full:
  * @program: a pointer to an OrcProgram structure
  * @size: size of data values
  * @name: name of variable
@@ -323,20 +361,41 @@ orc_program_add_source (OrcProgram *program, int size, const char *name)
  * Returns: the index of the new variable
  */
 int
-orc_program_add_destination (OrcProgram *program, int size, const char *name)
+orc_program_add_destination_full (OrcProgram *program, int size, const char *name,
+    const char *type_name, int alignment)
 {
   int i = ORC_VAR_D1 + program->n_dest_vars;
 
   program->vars[i].vartype = ORC_VAR_TYPE_DEST;
   program->vars[i].size = size;
-  program->vars[i].alignment = size;
+  if (alignment == 0) alignment = size;
+  program->vars[i].alignment = alignment;
   program->vars[i].name = strdup(name);
+  if (type_name) {
+    program->vars[i].type_name = strdup(type_name);
+  }
   program->n_dest_vars++;
 
   return i;
 }
 
 /**
+ * orc_program_add_destination:
+ * @program: a pointer to an OrcProgram structure
+ * @size: size of data values
+ * @name: name of variable
+ *
+ * Creates a new variable representing a destination array.
+ *
+ * Returns: the index of the new variable
+ */
+int
+orc_program_add_destination (OrcProgram *program, int size, const char *name)
+{
+  return orc_program_add_destination_full (program, size, name, NULL, 0);
+}
+
+/**
  * orc_program_add_constant:
  * @program: a pointer to an OrcProgram structure
  * @size: size of data value
index 8c07199..98af8f0 100644 (file)
@@ -408,6 +408,9 @@ struct _OrcProgram {
   void *backup_func;
   int is_2d;
   int constant_n;
+  int n_multiple;
+  int n_minimum;
+  int n_maximum;
   int constant_m;
 
   OrcCode *orccode;
@@ -643,6 +646,9 @@ const char * orc_program_get_name (OrcProgram *program);
 void orc_program_set_name (OrcProgram *program, const char *name);
 void orc_program_set_2d (OrcProgram *program);
 void orc_program_set_constant_n (OrcProgram *program, int n);
+void orc_program_set_n_multiple (OrcProgram *ex, int n);
+void orc_program_set_n_minimum (OrcProgram *ex, int n);
+void orc_program_set_n_maximum (OrcProgram *ex, int n);
 void orc_program_set_constant_m (OrcProgram *program, int m);
 
 void orc_program_append (OrcProgram *p, const char *opcode, int arg0, int arg1, int arg2);
@@ -681,7 +687,11 @@ int orc_program_find_var_by_name (OrcProgram *program, const char *name);
 int orc_program_add_temporary (OrcProgram *program, int size, const char *name);
 int orc_program_dup_temporary (OrcProgram *program, int i, int j);
 int orc_program_add_source (OrcProgram *program, int size, const char *name);
+int orc_program_add_source_full (OrcProgram *program, int size, const char *name,
+    const char *type_name, int alignment);
 int orc_program_add_destination (OrcProgram *program, int size, const char *name);
+int orc_program_add_destination_full (OrcProgram *program, int size, const char *name,
+    const char *type_name, int alignment);
 int orc_program_add_constant (OrcProgram *program, int size, int value, const char *name);
 int orc_program_add_constant_int64 (OrcProgram *program, int size, orc_int64 value, const char *name);
 int orc_program_add_constant_float (OrcProgram *program, int size, float value, const char *name);
index 1570946..8177548 100644 (file)
@@ -861,6 +861,21 @@ output_program_generation (OrcProgram *p, FILE *output, int is_inline)
     fprintf(output, "      orc_program_set_constant_n (p, %d);\n",
         p->constant_n);
   }
+  if (p->n_multiple != 0) {
+    REQUIRE(0,4,14,1);
+    fprintf(output, "      orc_program_set_n_multiple (p, %d);\n",
+        p->constant_n);
+  }
+  if (p->n_minimum != 0) {
+    REQUIRE(0,4,14,1);
+    fprintf(output, "      orc_program_set_n_minimum (p, %d);\n",
+        p->constant_n);
+  }
+  if (p->n_maximum != 0) {
+    REQUIRE(0,4,14,1);
+    fprintf(output, "      orc_program_set_n_maximum (p, %d);\n",
+        p->constant_n);
+  }
   if (p->is_2d) {
     fprintf(output, "      orc_program_set_2d (p);\n");
     if (p->constant_m != 0) {
@@ -876,15 +891,28 @@ output_program_generation (OrcProgram *p, FILE *output, int is_inline)
   for(i=0;i<4;i++){
     var = &p->vars[ORC_VAR_D1 + i];
     if (var->size) {
-      fprintf(output, "      orc_program_add_destination (p, %d, \"%s\");\n",
-          var->size, varnames[ORC_VAR_D1 + i]);
+      if (var->alignment != var->size) {
+        REQUIRE(0,4,14,1);
+        fprintf(output, "      orc_program_add_destination_full (p, %d, \"%s\", NULL, %d);\n",
+            var->size, varnames[ORC_VAR_D1 + i], var->alignment);
+      } else {
+        fprintf(output, "      orc_program_add_destination (p, %d, \"%s\");\n",
+            var->size, varnames[ORC_VAR_D1 + i]);
+      }
     }
   }
   for(i=0;i<8;i++){
     var = &p->vars[ORC_VAR_S1 + i];
     if (var->size) {
-      fprintf(output, "      orc_program_add_source (p, %d, \"%s\");\n",
-          var->size, varnames[ORC_VAR_S1 + i]);
+      if (var->alignment != var->size) {
+        REQUIRE(0,4,14,1);
+        fprintf(output, "      orc_program_add_source_full (p, %d, \"%s\", NULL, %d);\n",
+            var->size, varnames[ORC_VAR_S1 + i],
+            var->alignment);
+      } else {
+        fprintf(output, "      orc_program_add_source (p, %d, \"%s\");\n",
+            var->size, varnames[ORC_VAR_S1 + i]);
+      }
     }
   }
   for(i=0;i<4;i++){