diff options
author | Damien Lespiau <damien.lespiau@intel.com> | 2013-01-21 17:07:28 +0000 |
---|---|---|
committer | Damien Lespiau <damien.lespiau@intel.com> | 2013-03-04 15:54:38 +0000 |
commit | 73d58edab9fca04d9b00f9e1a9095bbbb00f25a4 (patch) | |
tree | e0b4add5d3918c0198475368f4d33c466ccd4f83 /assembler | |
parent | 5e5861183df1326f74f66886c3f580d43d470d60 (diff) |
assembler: Refactor the code adding instructions and labels
Factoring out the code from the grammar will allow us to switch to
using brw_compile in a cleaner way.
Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
Diffstat (limited to 'assembler')
-rw-r--r-- | assembler/gram.y | 84 |
1 files changed, 44 insertions, 40 deletions
diff --git a/assembler/gram.y b/assembler/gram.y index f608d825..a1c09f72 100644 --- a/assembler/gram.y +++ b/assembler/gram.y @@ -97,6 +97,42 @@ void set_direct_dst_operand(struct dst_operand *dst, struct direct_reg *reg, void set_direct_src_operand(struct src_operand *src, struct direct_reg *reg, int type); +static void brw_program_init(struct brw_program *p) +{ + memset(p, 0, sizeof(struct brw_program)); +} + +static void brw_program_append_entry(struct brw_program *p, + struct brw_program_instruction *entry) +{ + entry->next = NULL; + if (p->last) + p->last->next = entry; + else + p->first = entry; + p->last = entry; +} + +static void brw_program_add_instruction(struct brw_program *p, + struct brw_instruction *instruction) +{ + struct brw_program_instruction *list_entry; + + list_entry = calloc(sizeof(struct brw_program_instruction), 1); + list_entry->instruction = *instruction; + brw_program_append_entry(p, list_entry); +} + +static void brw_program_add_label(struct brw_program *p, const char *label) +{ + struct brw_program_instruction *list_entry; + + list_entry = calloc(sizeof(struct brw_program_instruction), 1); + list_entry->string = strdup(label); + list_entry->islabel = 1; + brw_program_append_entry(p, list_entry); +} + %} %start ROOT @@ -345,59 +381,27 @@ instrseq: instrseq pragma } | instrseq instruction SEMICOLON { - struct brw_program_instruction *list_entry = - calloc(sizeof(struct brw_program_instruction), 1); - list_entry->instruction = $2; - list_entry->next = NULL; - if ($1.last) { - $1.last->next = list_entry; - } else { - $1.first = list_entry; - } - $1.last = list_entry; + brw_program_add_instruction(&$1, &$2); $$ = $1; } | instruction SEMICOLON { - struct brw_program_instruction *list_entry = - calloc(sizeof(struct brw_program_instruction), 1); - list_entry->instruction = $1; - - list_entry->next = NULL; - - $$.first = list_entry; - $$.last = list_entry; + brw_program_init(&$$); + brw_program_add_instruction(&$$, &$1); } - | instrseq SEMICOLON + | instrseq SEMICOLON { $$ = $1; } - | instrseq label + | instrseq label { - struct brw_program_instruction *list_entry = - calloc(sizeof(struct brw_program_instruction), 1); - list_entry->string = strdup($2); - list_entry->islabel = 1; - list_entry->next = NULL; - if ($1.last) { - $1.last->next = list_entry; - } else { - $1.first = list_entry; - } - $1.last = list_entry; + brw_program_add_label(&$1, $2); $$ = $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; + brw_program_init(&$$); + brw_program_add_label(&$$, $1); } | pragma { |