From 2cb9b2596ccebde7ab0ed2663756f15752a6dd74 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Sat, 18 Apr 2015 20:53:33 -0500 Subject: [PATCH] Implement parsing .rom_size directive. --- src/assembler/parse_util.c | 21 +++++++++++++++++++-- src/assembler/parse_util.h | 1 + src/assembler/preprocessor.c | 3 +-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/assembler/parse_util.c b/src/assembler/parse_util.c index 7f7c5fd..8635b9f 100644 --- a/src/assembler/parse_util.c +++ b/src/assembler/parse_util.c @@ -127,7 +127,24 @@ bool parse_uint8_t(uint8_t *result, const ASMLine *line, const char *directive) } /* - Parse the region code string in an ASMLine and store it in *result. + Parse a ROM size string in an ASMLine and store it in *result. + + Return true on success and false on failure; in the latter case, *result is + not modified. +*/ +bool parse_rom_size(uint32_t *result, const ASMLine *line) +{ + uint32_t bytes; + if (!parse_uint32_t(&bytes, line, DIR_ROM_SIZE)) + return false; + + if (size_bytes_to_code(bytes)) + return (*result = bytes), true; + return false; +} + +/* + Parse a region code string in an ASMLine and store it in *result. Return true on success and false on failure; in the latter case, *result is not modified. @@ -155,7 +172,7 @@ bool parse_region_string(uint8_t *result, const ASMLine *line) } /* - Parse the size code in an ASMLine and store it in *result. + Parse a size code in an ASMLine and store it in *result. Return true on success and false on failure; in the latter case, *result is not modified. diff --git a/src/assembler/parse_util.h b/src/assembler/parse_util.h index 4aadf77..05dd933 100644 --- a/src/assembler/parse_util.h +++ b/src/assembler/parse_util.h @@ -17,5 +17,6 @@ bool parse_uint32_t(uint32_t*, const ASMLine*, const char*); bool parse_uint16_t(uint16_t*, const ASMLine*, const char*); bool parse_uint8_t(uint8_t*, const ASMLine*, const char*); +bool parse_rom_size(uint32_t*, const ASMLine*); bool parse_region_string(uint8_t*, const ASMLine*); bool parse_size_code(uint8_t*, const ASMLine*); diff --git a/src/assembler/preprocessor.c b/src/assembler/preprocessor.c index bcf6651..6ee2d88 100644 --- a/src/assembler/preprocessor.c +++ b/src/assembler/preprocessor.c @@ -360,8 +360,7 @@ ErrorInfo* preprocess(AssemblerState *state, const LineBuffer *source) END_DIRECTIVE BEGIN_DIRECTIVE(DIR_ROM_SIZE, size_t, state->rom_size, 0) - // TODO: fixme - FAIL_ON_COND_(1, ED_PP_UNKNOWN) + USE_PARSER(uint32_t, rom_size) END_DIRECTIVE BEGIN_DIRECTIVE(DIR_ROM_HEADER, size_t, state->header.offset, DEFAULT_HEADER_OFFSET)