Merge branch 'nasm-2.14.xx'

* nasm-2.14.xx:
  preproc: command-line preproc directive after system-generated

gorcunov@: Had to fix include_path StrList conversion,
it is a bit ugly by now, will rework.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
Cyrill Gorcunov 2018-11-13 01:09:27 +03:00
commit e358851526
3 changed files with 85 additions and 38 deletions

View file

@ -134,6 +134,7 @@ static struct SAA *forwrefs; /* keep track of forward references */
static const struct forwrefinfo *forwref;
static const struct preproc_ops *preproc;
static StrList *include_path;
#define OP_NORMAL (1u << 0)
#define OP_PREPROCESS (1u << 1)
@ -258,7 +259,11 @@ static void nasm_fputs(const char *line, FILE * outfile)
puts(line);
}
static void define_macros_early(void)
/*
* Define system-defined macros that are not part of
* macros/standard.mac.
*/
static void define_macros(void)
{
const struct compile_time * const oct = &official_compile_time;
char temp[128];
@ -289,11 +294,6 @@ static void define_macros_early(void)
snprintf(temp, sizeof temp, "__POSIX_TIME__=%"PRId64, oct->posix);
preproc->pre_define(temp);
}
}
static void define_macros_late(void)
{
char temp[128];
/*
* In case if output format is defined by alias
@ -303,6 +303,40 @@ static void define_macros_late(void)
snprintf(temp, sizeof(temp), "__OUTPUT_FORMAT__=%s",
ofmt_alias ? ofmt_alias->shortname : ofmt->shortname);
preproc->pre_define(temp);
/*
* Output-format specific macros.
*/
if (ofmt->stdmac)
preproc->extra_stdmac(ofmt->stdmac);
/*
* Debug format, if any
*/
if (dfmt != &null_debug_form) {
snprintf(temp, sizeof(temp), "__DEBUG_FORMAT__=%s", dfmt->shortname);
preproc->pre_define(temp);
}
}
/*
* Initialize the preprocessor, set up the include path, and define
* the system-included macros. This is called between passes 1 and 2
* of parsing the command options; ofmt and dfmt are defined at this
* point.
*
* Command-line specified preprocessor directives (-p, -d, -u,
* --pragma, --before) are processed after this function.
*/
static void preproc_init(StrList *list)
{
struct strlist_entry *l;
preproc->init();
define_macros();
list_for_each(l, list->head)
preproc->include_path(l->str);
}
static void emit_dependencies(StrList *list)
@ -418,6 +452,8 @@ int main(int argc, char **argv)
iflag_set_default_cpu(&cpu);
iflag_set_default_cpu(&cmd_cpu);
include_path = strlist_allocate();
pass0 = 0;
want_usage = terminate_after_phase = false;
nasm_set_verror(nasm_verror_gnu);
@ -447,23 +483,7 @@ int main(int argc, char **argv)
return 1;
}
/*
* Define some macros dependent on the runtime, but not
* on the command line (as those are scanned in cmdline pass 2.)
*/
preproc->init();
define_macros_early();
parse_cmdline(argc, argv, 2);
if (terminate_after_phase) {
if (want_usage)
usage();
return 1;
}
/* Save away the default state of warnings */
memcpy(warning_state_init, warning_state, sizeof warning_state);
/* At this point we have ofmt and the name of the desired debug format */
if (!using_debug_info) {
/* No debug info, redirect to the null backend (empty stubs) */
dfmt = &null_debug_form;
@ -480,8 +500,19 @@ int main(int argc, char **argv)
}
}
if (ofmt->stdmac)
preproc->extra_stdmac(ofmt->stdmac);
preproc_init(include_path);
strlist_free(include_path);
include_path = NULL;
parse_cmdline(argc, argv, 2);
if (terminate_after_phase) {
if (want_usage)
usage();
return 1;
}
/* Save away the default state of warnings */
memcpy(warning_state_init, warning_state, sizeof warning_state);
/*
* If no output file name provided and this
@ -493,9 +524,6 @@ int main(int argc, char **argv)
outname = filename_set_extension(inname, ofmt->extension);
}
/* define some macros dependent of command-line */
define_macros_late();
if (depend_file || (operating_mode & OP_DEPEND))
depend_list = strlist_allocate();
@ -872,7 +900,7 @@ static bool process_arg(char *p, char *q, int pass)
break;
case 'O': /* Optimization level */
if (pass == 2) {
if (pass == 1) {
int opt;
if (!*param) {
@ -936,8 +964,8 @@ static bool process_arg(char *p, char *q, int pass)
case 'i': /* include search path */
case 'I':
if (pass == 2)
preproc->include_path(param);
if (pass == 1)
strlist_add_string(include_path, param);
break;
case 'l': /* listing file */
@ -951,7 +979,7 @@ static bool process_arg(char *p, char *q, int pass)
break;
case 'F': /* specify debug format */
if (pass == 2) {
if (pass == 1) {
using_debug_info = true;
debug_format = param;
}
@ -971,7 +999,7 @@ static bool process_arg(char *p, char *q, int pass)
break;
case 'g':
if (pass == 2) {
if (pass == 1) {
using_debug_info = true;
if (p[2])
debug_format = nasm_skip_spaces(p + 2);
@ -1165,7 +1193,7 @@ static bool process_arg(char *p, char *q, int pass)
preproc->pre_command(NULL, param);
break;
case OPT_LIMIT:
if (pass == 2)
if (pass == 1)
nasm_set_limit(p+olen, param);
break;
case OPT_KEEP_ALL:

View file

@ -7,9 +7,19 @@
The NASM 2 series supports x86-64, and is the production version of NASM
since 2007.
\S{cl-2.14.01} Version 2.14.01
\b Create all system-defined macros defore processing command-line
given preprocessing directives (\c{-p}, \c{-d}, \c{-u}, \c{--pragma},
\c{--before}).
\b If debugging is enabled, define a \c{__DEBUG_FORMAT__} predefined
macro. See \k{dfmtm}.
\S{cl-2.14} Version 2.14
\b Changed \c{-I} option semantics by adding a trailing path separator unconditionally.
\b Changed \c{-I} option semantics by adding a trailing path separator
unconditionally.
\b Fixed null dereference in corrupted invalid single line macros.

View file

@ -3898,9 +3898,9 @@ mode-dependent macros.
\S{ofmtm} \i\c{__OUTPUT_FORMAT__}: Current Output Format
The \c{__OUTPUT_FORMAT__} standard macro holds the current Output Format,
as given by the \c{-f} option or NASM's default. Type \c{nasm -hf} for a
list.
The \c{__OUTPUT_FORMAT__} standard macro holds the current output
format name, as given by the \c{-f} option or NASM's default. Type
\c{nasm -hf} for a list.
\c %ifidn __OUTPUT_FORMAT__, win32
\c %define NEWLINE 13, 10
@ -3908,6 +3908,15 @@ list.
\c %define NEWLINE 10
\c %endif
\S{dfmtm} \i\c{__DEBUG_FORMAT__}: Current Debug Format
If debugging information generation is enabled, The
\c{__DEBUG_FORMAT__} standard macro holds the current debug format
name as specified by the \c{-F} or \c{-g} option or the output format
default. Type \c{nasm -f} \e{output} \c{y} for a list.
\c{__DEBUG_FORMAT__} is not defined if debugging is not enabled, or if
the debug format specified is \c{null}.
\S{datetime} Assembly Date and Time Macros