use left recursion instead of right recursion to avoid memory exhausted issue when...
authorZou Nan hai <nanhai.zou@intel.com>
Wed, 21 Apr 2010 03:02:21 +0000 (11:02 +0800)
committerDamien Lespiau <damien.lespiau@intel.com>
Mon, 4 Mar 2013 15:54:27 +0000 (15:54 +0000)
assembler/src/gen4asm.h
assembler/src/gram.y

index a965d11..c67d94e 100644 (file)
@@ -122,6 +122,7 @@ struct brw_program_instruction {
  */
 struct brw_program {
        struct brw_program_instruction *first;
+       struct brw_program_instruction *last;
 };
 
 extern struct brw_program compiled_program;
index 4d061f3..438559a 100644 (file)
@@ -174,16 +174,15 @@ ROOT:             instrseq
 label:          STRING COLON
 ;
 
-instrseq:      instruction SEMICOLON instrseq
+instrseq:      instrseq instruction SEMICOLON 
                {
                  struct brw_program_instruction *list_entry =
                    calloc(sizeof(struct brw_program_instruction), 1);
-                 list_entry->instruction = $1;
-
-                 list_entry->next = $3.first;
-                 $3.first = list_entry;
-
-                 $$ = $3;
+                 list_entry->instruction = $2;
+                 list_entry->next = NULL;
+                 $1.last->next = list_entry;
+                 $1.last = list_entry;
+                 $$ = $1;
                }
                | instruction SEMICOLON
                {
@@ -194,17 +193,31 @@ instrseq: instruction SEMICOLON instrseq
                  list_entry->next = NULL;
 
                  $$.first = list_entry;
+                 $$.last = list_entry;
                }
-                | label instrseq
+                | instrseq label
                 {
                   struct brw_program_instruction *list_entry =
                     calloc(sizeof(struct brw_program_instruction), 1);
-                  list_entry->string = strdup($1);
+                  list_entry->string = strdup($2);
                   list_entry->islabel = 1;
-                  list_entry->next = $2.first;
-                      $2.first = list_entry;
-                      $$ = $2;
+                 list_entry->next = NULL;
+                 $1.last->next = list_entry;
+                 $1.last = list_entry;
+                 $$ = $1;
                 }
+               | label
+               {
+                 struct brw_program_instruction *list_entry =
+                   calloc(sizeof(struct brw_program_instruction), 1);
+                  list_entry->string = strdup($1);
+                  list_entry->islabel = 1;
+
+                 list_entry->next = NULL;
+
+                 $$.first = list_entry;
+                 $$.last = list_entry;
+               }
                | error SEMICOLON instrseq
                {
                  $$ = $3;