From: Lukas Krickl Date: Sun, 5 Nov 2023 13:50:10 +0000 (+0100) Subject: WIP: preprocessor X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=dfec4ef87d38809a5f263a870fb07b35d935acab;p=ulas%2F.git WIP: preprocessor --- diff --git a/README.md b/README.md index f4b21f3..7d01470 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ulas -Unlink's light assembler is a C99 assembler for the 6502 without any external dependencies. +Unlink's light assembler is a C99 assembler without any external dependencies. ## Table of content diff --git a/doc/ulas.man b/doc/ulas.man index f7dbcdb..d168766 100644 --- a/doc/ulas.man +++ b/doc/ulas.man @@ -17,7 +17,25 @@ -v, --verbose verbose output -.SH SYNTAX +.SH PREPROCESSOR + +The preprocessor is a text based way of modifying the input before +the assembly step. + +Withing preprocessor macros +- $0 will expand to the literal argument string +- $1 to $9 will expand to the comma separated arguments of the macro +- $$ will expand to an internal macro call counter which can be used to make labels + that are expanded by a macro unique. + +Macros: + +#macro +label$$: + adc $1, $2 +#endm + +.SH ASSEMBLY SYNTAX diff --git a/include/ulas.h b/include/ulas.h index cecc23c..870fa2b 100644 --- a/include/ulas.h +++ b/include/ulas.h @@ -72,6 +72,23 @@ struct ulas_tok { union ulas_tokdat dat; }; +enum ulas_ppdirs { + ULAS_PP_DEF, + ULAS_PP_MACRO, +}; + +struct ulas_ppdir { + enum ulas_ppdirs type; +}; + +/** + * Symbols + */ + +struct ulas_sym { + const char *name; +}; + /** * Expressions */ @@ -113,6 +130,11 @@ void ulas_init(struct ulas_config cfg); int ulas_main(struct ulas_config cfg); +/** + * Tokenize and apply the preprocessor + */ +int ulas_preproc(FILE *dst, FILE *src); + char *ulas_strndup(const char *src, size_t n); #endif diff --git a/src/ulas.c b/src/ulas.c index ee6c299..24ed9d3 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -54,3 +54,5 @@ int ulas_main(struct ulas_config cfg) { return 0; } + +int ulas_preproc(FILE *dst, FILE *src) {}