From: Damien Lespiau Subject: [PATCH 37/90] assembler: Refactor the code adding instructions and labels Date: Mon, 4 Feb 2013 15:27:32 +0000 Message-ID: <1359991705-5254-38-git-send-email-damien.lespiau@intel.com> References: <1359991705-5254-1-git-send-email-damien.lespiau@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTP id B8EA4E60CE for ; Mon, 4 Feb 2013 07:29:32 -0800 (PST) In-Reply-To: <1359991705-5254-1-git-send-email-damien.lespiau@intel.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: intel-gfx-bounces+gcfxdi-intel-gfx=m.gmane.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+gcfxdi-intel-gfx=m.gmane.org@lists.freedesktop.org To: intel-gfx@lists.freedesktop.org List-Id: intel-gfx@lists.freedesktop.org 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 --- assembler/gram.y | 84 ++++++++++++++++++++++++++++------------------------- 1 files changed, 44 insertions(+), 40 deletions(-) diff --git a/assembler/gram.y b/assembler/gram.y index f608d82..a1c09f7 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 { -- 1.7.7.5