0
0
mirror of https://github.com/netwide-assembler/nasm.git synced 2025-10-10 00:25:06 -04:00

preproc: Split get rid of global preproc methods

This will allow to hook on updated preprocessor
without breaking existing one.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
Cyrill Gorcunov
2012-05-07 01:57:55 +04:00
parent 6094166044
commit 0b78bff510
4 changed files with 76 additions and 28 deletions

69
nasm.c
View File

@@ -174,11 +174,21 @@ static const struct warning {
static void no_pp_reset(char *file, int pass, ListGen *listgen, StrList **deplist);
static char *no_pp_getline(void);
static void no_pp_cleanup(int pass);
static void no_pp_extra_stdmac(macros_t *macros);
static void no_pp_pre_define(char *definition);
static void no_pp_pre_undefine(char *definition);
static void no_pp_pre_include(char *fname);
static void no_pp_include_path(char *path);
static struct preproc_ops no_pp = {
no_pp_reset,
no_pp_getline,
no_pp_cleanup
no_pp_cleanup,
no_pp_extra_stdmac,
no_pp_pre_define,
no_pp_pre_undefine,
no_pp_pre_include,
no_pp_include_path
};
/*
@@ -233,13 +243,13 @@ static void define_macros_early(void)
lt = *lt_p;
strftime(temp, sizeof temp, "__DATE__=\"%Y-%m-%d\"", &lt);
pp_pre_define(temp);
preproc->pre_define(temp);
strftime(temp, sizeof temp, "__DATE_NUM__=%Y%m%d", &lt);
pp_pre_define(temp);
preproc->pre_define(temp);
strftime(temp, sizeof temp, "__TIME__=\"%H:%M:%S\"", &lt);
pp_pre_define(temp);
preproc->pre_define(temp);
strftime(temp, sizeof temp, "__TIME_NUM__=%H%M%S", &lt);
pp_pre_define(temp);
preproc->pre_define(temp);
}
gm_p = gmtime(&official_compile_time);
@@ -247,13 +257,13 @@ static void define_macros_early(void)
gm = *gm_p;
strftime(temp, sizeof temp, "__UTC_DATE__=\"%Y-%m-%d\"", &gm);
pp_pre_define(temp);
preproc->pre_define(temp);
strftime(temp, sizeof temp, "__UTC_DATE_NUM__=%Y%m%d", &gm);
pp_pre_define(temp);
preproc->pre_define(temp);
strftime(temp, sizeof temp, "__UTC_TIME__=\"%H:%M:%S\"", &gm);
pp_pre_define(temp);
preproc->pre_define(temp);
strftime(temp, sizeof temp, "__UTC_TIME_NUM__=%H%M%S", &gm);
pp_pre_define(temp);
preproc->pre_define(temp);
}
if (gm_p)
@@ -265,7 +275,7 @@ static void define_macros_early(void)
if (posix_time) {
snprintf(temp, sizeof temp, "__POSIX_TIME__=%"PRId64, posix_time);
pp_pre_define(temp);
preproc->pre_define(temp);
}
}
@@ -280,7 +290,7 @@ static void define_macros_late(void)
*/
snprintf(temp, sizeof(temp), "__OUTPUT_FORMAT__=%s",
ofmt_alias ? ofmt_alias->shortname : ofmt->shortname);
pp_pre_define(temp);
preproc->pre_define(temp);
}
static void emit_dependencies(StrList *list)
@@ -362,7 +372,7 @@ int main(int argc, char **argv)
ofmt->current_dfmt = &null_debug_form;
if (ofmt->stdmac)
pp_extra_stdmac(ofmt->stdmac);
preproc->extra_stdmac(ofmt->stdmac);
parser_global_info(&location);
eval_global_info(ofmt, lookup_label, &location);
@@ -380,7 +390,7 @@ int main(int argc, char **argv)
char *line;
if (depend_missing_ok)
pp_include_path(NULL); /* "assume generated" */
preproc->include_path(NULL); /* "assume generated" */
preproc->reset(inname, 0, &nasmlist, depend_ptr);
if (outname[0] == '\0')
@@ -719,22 +729,22 @@ static bool process_arg(char *p, char *q)
case 'p': /* pre-include */
case 'P':
pp_pre_include(param);
preproc->pre_include(param);
break;
case 'd': /* pre-define */
case 'D':
pp_pre_define(param);
preproc->pre_define(param);
break;
case 'u': /* un-define */
case 'U':
pp_pre_undefine(param);
preproc->pre_undefine(param);
break;
case 'i': /* include search path */
case 'I':
pp_include_path(param);
preproc->include_path(param);
break;
case 'l': /* listing file */
@@ -2109,6 +2119,31 @@ static void no_pp_cleanup(int pass)
}
}
static void no_pp_extra_stdmac(macros_t *macros)
{
(void)macros;
}
static void no_pp_pre_define(char *definition)
{
(void)definition;
}
static void no_pp_pre_undefine(char *definition)
{
(void)definition;
}
static void no_pp_pre_include(char *fname)
{
(void)fname;
}
static void no_pp_include_path(char *path)
{
(void)path;
}
static uint32_t get_cpu(char *value)
{
if (!strcmp(value, "8086"))

13
nasm.h
View File

@@ -378,6 +378,19 @@ struct preproc_ops {
/* Called at the end of a pass */
void (*cleanup)(int pass);
/* Additional macros specific to output format */
void (*extra_stdmac)(macros_t *macros);
/* Early definitions and undefinitions for macros */
void (*pre_define)(char *definition);
void (*pre_undefine)(char *definition);
/* Include file from command line */
void (*pre_include)(char *fname);
/* Include path from command line */
void (*include_path)(char *path);
};
extern struct preproc_ops nasmpp;

View File

@@ -5068,7 +5068,7 @@ static void pp_cleanup(int pass)
}
}
void pp_include_path(char *path)
static void pp_include_path(char *path)
{
IncPath *i;
@@ -5086,7 +5086,7 @@ void pp_include_path(char *path)
}
}
void pp_pre_include(char *fname)
static void pp_pre_include(char *fname)
{
Token *inc, *space, *name;
Line *l;
@@ -5102,7 +5102,7 @@ void pp_pre_include(char *fname)
predef = l;
}
void pp_pre_define(char *definition)
static void pp_pre_define(char *definition)
{
Token *def, *space;
Line *l;
@@ -5124,7 +5124,7 @@ void pp_pre_define(char *definition)
predef = l;
}
void pp_pre_undefine(char *definition)
static void pp_pre_undefine(char *definition)
{
Token *def, *space;
Line *l;
@@ -5140,7 +5140,7 @@ void pp_pre_undefine(char *definition)
predef = l;
}
void pp_extra_stdmac(macros_t *macros)
static void pp_extra_stdmac(macros_t *macros)
{
extrastdmac = macros;
}
@@ -5156,5 +5156,10 @@ static void make_tok_num(Token * tok, int64_t val)
struct preproc_ops nasmpp = {
pp_reset,
pp_getline,
pp_cleanup
pp_cleanup,
pp_extra_stdmac,
pp_pre_define,
pp_pre_undefine,
pp_pre_include,
pp_include_path
};

View File

@@ -47,10 +47,5 @@ extern const uint8_t pp_directives_len[];
typedef const unsigned char macros_t;
enum preproc_token pp_token_hash(const char *token);
void pp_include_path(char *);
void pp_pre_include(char *);
void pp_pre_define(char *);
void pp_pre_undefine(char *);
void pp_extra_stdmac(macros_t *);
#endif