From 22bd76e99769bc1a06968f4799f07c110e1d1696 Mon Sep 17 00:00:00 2001 From: Francesco Romani Date: Sun, 6 Jul 2014 16:06:44 +0200 Subject: parser: extract function to handle .accumulator Part-of: --- orc/orcparse.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) (limited to 'orc') diff --git a/orc/orcparse.c b/orc/orcparse.c index 61e34e0..eb989d5 100644 --- a/orc/orcparse.c +++ b/orc/orcparse.c @@ -98,6 +98,7 @@ static int orc_parse_handle_dotn (OrcParser *parser, const OrcLine *line); static int orc_parse_handle_dotm (OrcParser *parser, const OrcLine *line); static int orc_parse_handle_source (OrcParser *parser, const OrcLine *line); static int orc_parse_handle_dest (OrcParser *parser, const OrcLine *line); +static int orc_parse_handle_accumulator (OrcParser *parser, const OrcLine *line); static int orc_parse_handle_directive (OrcParser *parser, const OrcLine *line); static int orc_parse_handle_opcode (OrcParser *parser, const OrcLine *line); @@ -437,19 +438,7 @@ orc_parse_handle_legacy (OrcParser *parser, const OrcLine *line) const char **token = (const char **)(line->tokens); int n_tokens = line->n_tokens; - if (strcmp (token[0], ".accumulator") == 0) { - if (n_tokens < 3) { - orc_parse_add_error (parser, "line %d: .accumulator without size or name\n", - parser->line_number); - } else { - int size = strtol (token[1], NULL, 0); - int var; - var = orc_program_add_accumulator (parser->program, size, token[2]); - if (n_tokens > 3) { - orc_program_set_type_name (parser->program, var, token[3]); - } - } - } else if (strcmp (token[0], ".temp") == 0) { + if (strcmp (token[0], ".temp") == 0) { if (n_tokens < 3) { orc_parse_add_error (parser, "line %d: .temp without size or name\n", parser->line_number); @@ -702,6 +691,27 @@ orc_parse_handle_dest (OrcParser *parser, const OrcLine *line) return 1; } +static int +orc_parse_handle_accumulator (OrcParser *parser, const OrcLine *line) +{ + int size; + int var; + + if (line->n_tokens < 3) { + orc_parse_add_error (parser, "line %d: .accumulator without size or name\n", + parser->line_number); + return 0; + } + + size = strtol (line->tokens[1], NULL, 0); + var = orc_program_add_accumulator (parser->program, size, line->tokens[2]); + if (line->n_tokens > 3) { + orc_program_set_type_name (parser->program, var, line->tokens[3]); + } + + return 1; +} + static int orc_parse_handle_directive (OrcParser *parser, const OrcLine *line) { @@ -714,6 +724,7 @@ orc_parse_handle_directive (OrcParser *parser, const OrcLine *line) { ".m", orc_parse_handle_dotm }, { ".source", orc_parse_handle_source }, { ".dest", orc_parse_handle_dest }, + { ".accumulator", orc_parse_handle_accumulator }, { NULL, NULL } }; int i; -- cgit v1.2.1