diff options
author | H. Peter Anvin <hpa@linux.intel.com> | 2018-06-18 11:32:17 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@linux.intel.com> | 2018-06-18 11:34:33 -0700 |
commit | f7be8b3253b90ed590c7dc862c402da5e8ea08c2 (patch) | |
tree | e8dac38f94fc896d4ec64b05cf2b92e071300532 | |
parent | 41103ab4310c71836761c205a7424975edb4f2ad (diff) | |
download | nasm-f7be8b3253b90ed590c7dc862c402da5e8ea08c2.tar.gz |
pragma: define a hander for generic output (and debug) pragmas
There are cases where we may want to implement generic pragmas, while
still make them selective based on output and/or debug formats.
Initially, use this for the prefix/suffix options.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Cc: Chang Seok Bae <chang.seok.bae@intel.com>
-rw-r--r-- | asm/pragma.c | 30 | ||||
-rw-r--r-- | include/nasm.h | 3 | ||||
-rw-r--r-- | test/subsection.asm | 6 |
3 files changed, 25 insertions, 14 deletions
diff --git a/asm/pragma.c b/asm/pragma.c index 71861a94..a4e76094 100644 --- a/asm/pragma.c +++ b/asm/pragma.c @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------- * * - * Copyright 1996-2017 The NASM Authors - All Rights Reserved + * Copyright 1996-2018 The NASM Authors - All Rights Reserved * See the file AUTHORS included with the NASM distribution for * the specific copyright holders. * @@ -49,7 +49,7 @@ #include "assemble.h" #include "error.h" -static enum directive_result asm_pragma(const struct pragma *pragma); +static enum directive_result output_pragma(const struct pragma *pragma); static enum directive_result limit_pragma(const struct pragma *pragma); /* @@ -87,14 +87,14 @@ static enum directive_result limit_pragma(const struct pragma *pragma); */ static struct pragma_facility global_pragmas[] = { - { "asm", asm_pragma }, + { "asm", NULL }, { "limit", limit_pragma }, { "list", NULL }, { "file", NULL }, { "input", NULL }, - /* None of these should actually happen... */ - { "preproc", NULL }, /* This shouldn't happen... */ + /* None of these should actually happen due to special handling */ + { "preproc", NULL }, /* Handled in the preprocessor by necessity */ { "output", NULL }, { "debug", NULL }, { "ignore", NULL }, @@ -110,6 +110,7 @@ static struct pragma_facility global_pragmas[] = */ static bool search_pragma_list(const struct pragma_facility *list, const char *default_name, + pragma_handler generic_handler, struct pragma *pragma) { const struct pragma_facility *pf; @@ -137,6 +138,10 @@ found_it: else rv = DIRR_UNKNOWN; + /* Is there an additional, applicable generic handler? */ + if (rv == DIRR_UNKNOWN && generic_handler) + rv = generic_handler(pragma); + switch (rv) { case DIRR_UNKNOWN: switch (pragma->opcode) { @@ -210,15 +215,16 @@ void process_pragma(char *str) pragma.tail = nasm_trim_spaces(p); /* Look for a global pragma namespace */ - if (search_pragma_list(global_pragmas, NULL, &pragma)) + if (search_pragma_list(global_pragmas, NULL, NULL, &pragma)) return; /* Look to see if it is an output backend pragma */ - if (search_pragma_list(ofmt->pragmas, ofmt->shortname, &pragma)) + if (search_pragma_list(ofmt->pragmas, ofmt->shortname, + output_pragma, &pragma)) return; /* Look to see if it is a debug format pragma */ - if (search_pragma_list(dfmt->pragmas, dfmt->shortname, &pragma)) + if (search_pragma_list(dfmt->pragmas, dfmt->shortname, NULL, &pragma)) return; /* @@ -234,9 +240,10 @@ void process_pragma(char *str) } /* - * Pragmas for the assembler proper + * Generic pragmas that apply to all output backends; these are handled + * specially so they can be made selective based on the output format. */ -static enum directive_result asm_pragma(const struct pragma *pragma) +static enum directive_result output_pragma(const struct pragma *pragma) { switch (pragma->opcode) { case D_PREFIX: @@ -258,6 +265,9 @@ static enum directive_result asm_pragma(const struct pragma *pragma) } } +/* + * %pragma limit to set resource limits + */ static enum directive_result limit_pragma(const struct pragma *pragma) { return nasm_set_limit(pragma->opname, pragma->tail); diff --git a/include/nasm.h b/include/nasm.h index 00cea322..9eae9b8b 100644 --- a/include/nasm.h +++ b/include/nasm.h @@ -727,10 +727,11 @@ enum directive_result { * as part of the struct pragma. */ struct pragma; +typedef enum directive_result (*pragma_handler)(const struct pragma *); struct pragma_facility { const char *name; - enum directive_result (*handler)(const struct pragma *); + pragma_handler handler; }; /* diff --git a/test/subsection.asm b/test/subsection.asm index ce8ed4aa..8ba61978 100644 --- a/test/subsection.asm +++ b/test/subsection.asm @@ -4,9 +4,9 @@ ; Test of Mach-O subsection_by_symbol ; -%pragma output subsections_via_symbols -%pragma asm gprefix _ -%pragma asm lprefix L_ +%pragma macho subsections_via_symbols +%pragma macho gprefix _ +%pragma macho lprefix L. bits 32 |