mirror of
https://github.com/netwide-assembler/nasm.git
synced 2025-03-31 18:20:22 +08:00
Add --pragma and --before option; make --include = -P
Add --pragma to add pragmas on the command line; --before option to add *any* statement on the command line, and add --include as an alias for -P for familiarity with other toolchains. Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
This commit is contained in:
parent
a7f318c307
commit
0599034321
96
asm/nasm.c
96
asm/nasm.c
@ -718,7 +718,10 @@ enum text_options {
|
||||
OPT_BOGUS,
|
||||
OPT_VERSION,
|
||||
OPT_ABORT_ON_PANIC,
|
||||
OPT_MANGLE
|
||||
OPT_MANGLE,
|
||||
OPT_INCLUDE,
|
||||
OPT_PRAGMA,
|
||||
OPT_BEFORE
|
||||
};
|
||||
struct textargs {
|
||||
const char *label;
|
||||
@ -736,6 +739,9 @@ static const struct textargs textopts[] = {
|
||||
{"gpostfix", OPT_MANGLE, true, LM_GSUFFIX},
|
||||
{"lprefix", OPT_MANGLE, true, LM_LPREFIX},
|
||||
{"lpostfix", OPT_MANGLE, true, LM_LSUFFIX},
|
||||
{"include", OPT_INCLUDE, true, 0},
|
||||
{"pragma", OPT_PRAGMA, true, 0},
|
||||
{"before", OPT_BEFORE, true, 0},
|
||||
{NULL, OPT_BOGUS, false, 0}
|
||||
};
|
||||
|
||||
@ -899,45 +905,47 @@ static bool process_arg(char *p, char *q, int pass)
|
||||
"[-l listfile]\n"
|
||||
" [options...] [--] filename\n"
|
||||
" or nasm -v (or --v) for version info\n\n"
|
||||
" -t assemble in SciTech TASM compatible mode\n");
|
||||
" -t assemble in SciTech TASM compatible mode\n");
|
||||
printf
|
||||
(" -E (or -e) preprocess only (writes output to stdout by default)\n"
|
||||
" -a don't preprocess (assemble only)\n"
|
||||
" -M generate Makefile dependencies on stdout\n"
|
||||
" -MG d:o, missing files assumed generated\n"
|
||||
" -MF <file> set Makefile dependency file\n"
|
||||
" -MD <file> assemble and generate dependencies\n"
|
||||
" -MT <file> dependency target name\n"
|
||||
" -MQ <file> dependency target name (quoted)\n"
|
||||
" -MP emit phony target\n\n"
|
||||
" -Z<file> redirect error messages to file\n"
|
||||
" -s redirect error messages to stdout\n\n"
|
||||
" -g generate debugging information\n\n"
|
||||
" -F format select a debugging format\n\n"
|
||||
" -gformat same as -g -F format\n\n"
|
||||
" -o outfile write output to an outfile\n\n"
|
||||
" -f format select an output format\n\n"
|
||||
" -l listfile write listing to a listfile\n\n"
|
||||
" -I<path> adds a pathname to the include file path\n");
|
||||
(" -E (or -e) preprocess only (writes output to stdout by default)\n"
|
||||
" -a don't preprocess (assemble only)\n"
|
||||
" -M generate Makefile dependencies on stdout\n"
|
||||
" -MG d:o, missing files assumed generated\n"
|
||||
" -MF file set Makefile dependency file\n"
|
||||
" -MD file assemble and generate dependencies\n"
|
||||
" -MT file dependency target name\n"
|
||||
" -MQ file dependency target name (quoted)\n"
|
||||
" -MP emit phony target\n\n"
|
||||
" -Zfile redirect error messages to file\n"
|
||||
" -s redirect error messages to stdout\n\n"
|
||||
" -g generate debugging information\n\n"
|
||||
" -F format select a debugging format\n\n"
|
||||
" -gformat same as -g -F format\n\n"
|
||||
" -o outfile write output to an outfile\n\n"
|
||||
" -f format select an output format\n\n"
|
||||
" -l listfile write listing to a listfile\n\n"
|
||||
" -Ipath add a pathname to the include file path\n");
|
||||
printf
|
||||
(" -O<digit> optimize branch offsets\n"
|
||||
" -O0: No optimization\n"
|
||||
" -O1: Minimal optimization\n"
|
||||
" -Ox: Multipass optimization (default)\n\n"
|
||||
" -P<file> pre-includes a file\n"
|
||||
" -D<macro>[=<value>] pre-defines a macro\n"
|
||||
" -U<macro> undefines a macro\n"
|
||||
" -X<format> specifies error reporting format (gnu or vc)\n"
|
||||
" -w+foo enables warning foo (equiv. -Wfoo)\n"
|
||||
" -w-foo disable warning foo (equiv. -Wno-foo)\n\n"
|
||||
" -w[+-]error[=foo] can be used to promote warnings to errors\n"
|
||||
" -h show invocation summary and exit\n\n"
|
||||
"--prefix,--postfix\n"
|
||||
" these options prepend or append the given string\n"
|
||||
" to all extern, common and global symbols\n"
|
||||
"--lprefix,--lportfix\n"
|
||||
" these options prepend or append the given string\n"
|
||||
" to all other symbols\n"
|
||||
(" -Olevel optimize opcodes, immediates and branch offsets\n"
|
||||
" -O0 no optimization\n"
|
||||
" -O1 minimal optimization\n"
|
||||
" -Ox multipass optimization (default)\n"
|
||||
" -Pfile pre-include a file (also --include)\n"
|
||||
" -Dmacro[=str] pre-define a macro\n"
|
||||
" -Umacro undefine a macro\n"
|
||||
" -Xformat specifiy error reporting format (gnu or vc)\n"
|
||||
" -w+foo enable warning foo (equiv. -Wfoo)\n"
|
||||
" -w-foo disable warning foo (equiv. -Wno-foo)\n"
|
||||
" -w[+-]error[=foo]\n"
|
||||
" promote [specific] warnings to errors\n"
|
||||
" -h show invocation summary and exit\n\n"
|
||||
" --pragma str pre-executes a specific %%pragma\n"
|
||||
" --before str add line (usually a preprocessor statement) before the input\n"
|
||||
" --prefix str prepend the given string to all the given string\n"
|
||||
" to all extern, common and global symbols\n"
|
||||
" --suffix str append the given string to all the given string\n"
|
||||
" to all extern, common and global symbols\n"
|
||||
" --lprefix str prepend the given string to all other symbols\n"
|
||||
"\n"
|
||||
"Response files should contain command line parameters,\n"
|
||||
"one per line.\n"
|
||||
@ -1092,6 +1100,18 @@ static bool process_arg(char *p, char *q, int pass)
|
||||
if (pass == 2)
|
||||
set_label_mangle(tx->pvt, q);
|
||||
break;
|
||||
case OPT_INCLUDE:
|
||||
if (pass == 2)
|
||||
preproc->pre_include(q);
|
||||
break;
|
||||
case OPT_PRAGMA:
|
||||
if (pass == 2)
|
||||
preproc->pre_command("pragma", q);
|
||||
break;
|
||||
case OPT_BEFORE:
|
||||
if (pass == 2)
|
||||
preproc->pre_command(NULL, q);
|
||||
break;
|
||||
case OPT_BOGUS:
|
||||
nasm_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
|
||||
"unrecognized option `--%s'", p + 2);
|
||||
|
@ -164,6 +164,12 @@ static void nop_pre_include(char *fname)
|
||||
(void)fname;
|
||||
}
|
||||
|
||||
static void nop_pre_command(const char *what, char *string)
|
||||
{
|
||||
(void)what;
|
||||
(void)string;
|
||||
}
|
||||
|
||||
static void nop_include_path(char *path)
|
||||
{
|
||||
(void)path;
|
||||
@ -183,6 +189,7 @@ const struct preproc_ops preproc_nop = {
|
||||
nop_pre_define,
|
||||
nop_pre_undefine,
|
||||
nop_pre_include,
|
||||
nop_pre_command,
|
||||
nop_include_path,
|
||||
nop_error_list_macros,
|
||||
};
|
||||
|
@ -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.
|
||||
*
|
||||
@ -5389,6 +5389,27 @@ static void pp_pre_undefine(char *definition)
|
||||
predef = l;
|
||||
}
|
||||
|
||||
/* Insert an early preprocessor command that doesn't need special handling */
|
||||
static void pp_pre_command(const char *what, char *string)
|
||||
{
|
||||
char *cmd;
|
||||
Token *def, *space;
|
||||
Line *l;
|
||||
|
||||
def = tokenize(string);
|
||||
if (what) {
|
||||
cmd = nasm_strcat(what[0] == '%' ? "" : "%", what);
|
||||
space = new_Token(def, TOK_WHITESPACE, NULL, 0);
|
||||
def = new_Token(space, TOK_PREPROC_ID, cmd, 0);
|
||||
}
|
||||
|
||||
l = nasm_malloc(sizeof(Line));
|
||||
l->next = predef;
|
||||
l->first = def;
|
||||
l->finishes = NULL;
|
||||
predef = l;
|
||||
}
|
||||
|
||||
static void pp_add_stdmac(macros_t *macros)
|
||||
{
|
||||
macros_t **mp;
|
||||
@ -5454,6 +5475,7 @@ const struct preproc_ops nasmpp = {
|
||||
pp_pre_define,
|
||||
pp_pre_undefine,
|
||||
pp_pre_include,
|
||||
pp_pre_command,
|
||||
pp_include_path,
|
||||
pp_error_list_macros,
|
||||
};
|
||||
|
@ -365,6 +365,9 @@ struct preproc_ops {
|
||||
/* Include file from command line */
|
||||
void (*pre_include)(char *fname);
|
||||
|
||||
/* Add a command from the command line */
|
||||
void (*pre_command)(const char *what, char *str);
|
||||
|
||||
/* Include path from command line */
|
||||
void (*include_path)(char *path);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user