diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-11-08 18:15:26 +0000 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-11-08 18:15:26 +0000 |
commit | cb2416554bc4afd76257dfd4cbd420f2d8e03789 (patch) | |
tree | b9e0ca0cf92682b20fea49a71003fe10d0c015e2 /asm/parser.h | |
parent | 253bebb4674e5fe8e600fd9fcb9c79d6705759a6 (diff) | |
download | ovm-cb2416554bc4afd76257dfd4cbd420f2d8e03789.tar.gz ovm-cb2416554bc4afd76257dfd4cbd420f2d8e03789.tar.bz2 ovm-cb2416554bc4afd76257dfd4cbd420f2d8e03789.zip |
Added a preprocessing routine in assembler
Preprocessor handles macros and macro blocks by working at the token
level, not doing any high level parsing or instruction making.
Essentially every macro is recorded in a registry, recording the name
and the tokens assigned to it. Then for every caller it just inserts
the tokens inline, creating a new stream and freeing the old one. It
leaves actual high level parsing to `parse_next` and
`process_presults`.
Diffstat (limited to 'asm/parser.h')
-rw-r--r-- | asm/parser.h | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/asm/parser.h b/asm/parser.h index 01358fc..a8748d0 100644 --- a/asm/parser.h +++ b/asm/parser.h @@ -27,6 +27,9 @@ typedef enum PERR_EXPECTED_SYMBOL, PERR_EXPECTED_LABEL, PERR_EXPECTED_OPERAND, + PERR_PREPROCESSOR_EXPECTED_NAME, + PERR_PREPROCESSOR_EXPECTED_END, + PERR_PREPROCESSOR_UNKNOWN_NAME, PERR_INVALID_RELATIVE_ADDRESS, PERR_UNKNOWN_OPERATOR, PERR_UNKNOWN_LABEL, @@ -38,32 +41,30 @@ const char *perr_as_cstr(perr_t); typedef struct { inst_t instruction; - darr_t instructions; + s_word address; struct PLabel { char *name; size_t size; } label; - s_word address; enum PResult_Type { PRES_LABEL = 0, PRES_LABEL_ADDRESS, PRES_GLOBAL_LABEL, PRES_RELATIVE_ADDRESS, - PRES_PP_CONST, PRES_COMPLETE_RESULT, } type; } presult_t; // TODO: Implement these presult_t presult_label(const char *, size_t, s_word); +presult_t presult_label_ref(inst_t, const char *, size_t); presult_t presult_instruction(inst_t); -presult_t presult_instructions(size_t); -presult_t presult_addr(s_word); -presult_t pres_pp_const(const char *, s_word, size_t); -// TODO: Refactor parser.c to use this instead +presult_t presult_relative(inst_t, s_word); +presult_t presult_global(const char *, size_t, s_word); void presult_free(presult_t); +void presults_free(presult_t *, size_t); typedef struct { @@ -74,8 +75,20 @@ typedef struct label_t search_labels(label_t *, size_t, char *, size_t); +typedef struct +{ + char *name; + size_t name_size; + darr_t code; +} block_t; + +block_t search_blocks(block_t *, size_t, char *, size_t); + +// Analyses then inlines corresponding tokens into stream directly +perr_t preprocessor(token_stream_t *); +// Parses from the preprocessed stream perr_t parse_next(token_stream_t *, presult_t *); -perr_t preprocessor(presult_t *, size_t, presult_t *); +// Deals with address building perr_t process_presults(presult_t *, size_t, prog_t **); perr_t parse_stream(token_stream_t *, prog_t **); |