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:
		
							
								
								
									
										69
									
								
								nasm.c
									
									
									
									
									
								
							
							
						
						
									
										69
									
								
								nasm.c
									
									
									
									
									
								
							| @@ -174,11 +174,21 @@ static const struct warning { | |||||||
| static void no_pp_reset(char *file, int pass, ListGen *listgen, StrList **deplist); | static void no_pp_reset(char *file, int pass, ListGen *listgen, StrList **deplist); | ||||||
| static char *no_pp_getline(void); | static char *no_pp_getline(void); | ||||||
| static void no_pp_cleanup(int pass); | 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 = { | static struct preproc_ops no_pp = { | ||||||
|     no_pp_reset, |     no_pp_reset, | ||||||
|     no_pp_getline, |     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; | 	lt = *lt_p; | ||||||
|  |  | ||||||
| 	strftime(temp, sizeof temp, "__DATE__=\"%Y-%m-%d\"", <); | 	strftime(temp, sizeof temp, "__DATE__=\"%Y-%m-%d\"", <); | ||||||
| 	pp_pre_define(temp); | 	preproc->pre_define(temp); | ||||||
| 	strftime(temp, sizeof temp, "__DATE_NUM__=%Y%m%d", <); | 	strftime(temp, sizeof temp, "__DATE_NUM__=%Y%m%d", <); | ||||||
| 	pp_pre_define(temp); | 	preproc->pre_define(temp); | ||||||
| 	strftime(temp, sizeof temp, "__TIME__=\"%H:%M:%S\"", <); | 	strftime(temp, sizeof temp, "__TIME__=\"%H:%M:%S\"", <); | ||||||
| 	pp_pre_define(temp); | 	preproc->pre_define(temp); | ||||||
| 	strftime(temp, sizeof temp, "__TIME_NUM__=%H%M%S", <); | 	strftime(temp, sizeof temp, "__TIME_NUM__=%H%M%S", <); | ||||||
| 	pp_pre_define(temp); | 	preproc->pre_define(temp); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     gm_p = gmtime(&official_compile_time); |     gm_p = gmtime(&official_compile_time); | ||||||
| @@ -247,13 +257,13 @@ static void define_macros_early(void) | |||||||
| 	gm = *gm_p; | 	gm = *gm_p; | ||||||
|  |  | ||||||
| 	strftime(temp, sizeof temp, "__UTC_DATE__=\"%Y-%m-%d\"", &gm); | 	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); | 	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); | 	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); | 	strftime(temp, sizeof temp, "__UTC_TIME_NUM__=%H%M%S", &gm); | ||||||
| 	pp_pre_define(temp); | 	preproc->pre_define(temp); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     if (gm_p) |     if (gm_p) | ||||||
| @@ -265,7 +275,7 @@ static void define_macros_early(void) | |||||||
|  |  | ||||||
|     if (posix_time) { |     if (posix_time) { | ||||||
| 	snprintf(temp, sizeof temp, "__POSIX_TIME__=%"PRId64, 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", |     snprintf(temp, sizeof(temp), "__OUTPUT_FORMAT__=%s", | ||||||
|              ofmt_alias ? ofmt_alias->shortname : ofmt->shortname); |              ofmt_alias ? ofmt_alias->shortname : ofmt->shortname); | ||||||
|     pp_pre_define(temp); |     preproc->pre_define(temp); | ||||||
| } | } | ||||||
|  |  | ||||||
| static void emit_dependencies(StrList *list) | static void emit_dependencies(StrList *list) | ||||||
| @@ -362,7 +372,7 @@ int main(int argc, char **argv) | |||||||
|         ofmt->current_dfmt = &null_debug_form; |         ofmt->current_dfmt = &null_debug_form; | ||||||
|  |  | ||||||
|     if (ofmt->stdmac) |     if (ofmt->stdmac) | ||||||
|         pp_extra_stdmac(ofmt->stdmac); |         preproc->extra_stdmac(ofmt->stdmac); | ||||||
|     parser_global_info(&location); |     parser_global_info(&location); | ||||||
|     eval_global_info(ofmt, lookup_label, &location); |     eval_global_info(ofmt, lookup_label, &location); | ||||||
|  |  | ||||||
| @@ -380,7 +390,7 @@ int main(int argc, char **argv) | |||||||
|             char *line; |             char *line; | ||||||
|  |  | ||||||
| 	    if (depend_missing_ok) | 	    if (depend_missing_ok) | ||||||
| 		pp_include_path(NULL);	/* "assume generated" */ | 		preproc->include_path(NULL);	/* "assume generated" */ | ||||||
|  |  | ||||||
|             preproc->reset(inname, 0, &nasmlist, depend_ptr); |             preproc->reset(inname, 0, &nasmlist, depend_ptr); | ||||||
|             if (outname[0] == '\0') |             if (outname[0] == '\0') | ||||||
| @@ -719,22 +729,22 @@ static bool process_arg(char *p, char *q) | |||||||
|  |  | ||||||
| 	case 'p':			/* pre-include */ | 	case 'p':			/* pre-include */ | ||||||
| 	case 'P': | 	case 'P': | ||||||
| 	    pp_pre_include(param); | 	    preproc->pre_include(param); | ||||||
| 	    break; | 	    break; | ||||||
|  |  | ||||||
| 	case 'd':			/* pre-define */ | 	case 'd':			/* pre-define */ | ||||||
| 	case 'D': | 	case 'D': | ||||||
| 	    pp_pre_define(param); | 	    preproc->pre_define(param); | ||||||
| 	    break; | 	    break; | ||||||
|  |  | ||||||
| 	case 'u':			/* un-define */ | 	case 'u':			/* un-define */ | ||||||
| 	case 'U': | 	case 'U': | ||||||
| 	    pp_pre_undefine(param); | 	    preproc->pre_undefine(param); | ||||||
| 	    break; | 	    break; | ||||||
|  |  | ||||||
| 	case 'i':			/* include search path */ | 	case 'i':			/* include search path */ | ||||||
| 	case 'I': | 	case 'I': | ||||||
| 	    pp_include_path(param); | 	    preproc->include_path(param); | ||||||
| 	    break; | 	    break; | ||||||
|  |  | ||||||
| 	case 'l':			/* listing file */ | 	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) | static uint32_t get_cpu(char *value) | ||||||
| { | { | ||||||
|     if (!strcmp(value, "8086")) |     if (!strcmp(value, "8086")) | ||||||
|   | |||||||
							
								
								
									
										13
									
								
								nasm.h
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								nasm.h
									
									
									
									
									
								
							| @@ -378,6 +378,19 @@ struct preproc_ops { | |||||||
|  |  | ||||||
|     /* Called at the end of a pass */ |     /* Called at the end of a pass */ | ||||||
|     void (*cleanup)(int 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; | extern struct preproc_ops nasmpp; | ||||||
|   | |||||||
							
								
								
									
										17
									
								
								preproc.c
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								preproc.c
									
									
									
									
									
								
							| @@ -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; |     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; |     Token *inc, *space, *name; | ||||||
|     Line *l; |     Line *l; | ||||||
| @@ -5102,7 +5102,7 @@ void pp_pre_include(char *fname) | |||||||
|     predef = l; |     predef = l; | ||||||
| } | } | ||||||
|  |  | ||||||
| void pp_pre_define(char *definition) | static void pp_pre_define(char *definition) | ||||||
| { | { | ||||||
|     Token *def, *space; |     Token *def, *space; | ||||||
|     Line *l; |     Line *l; | ||||||
| @@ -5124,7 +5124,7 @@ void pp_pre_define(char *definition) | |||||||
|     predef = l; |     predef = l; | ||||||
| } | } | ||||||
|  |  | ||||||
| void pp_pre_undefine(char *definition) | static void pp_pre_undefine(char *definition) | ||||||
| { | { | ||||||
|     Token *def, *space; |     Token *def, *space; | ||||||
|     Line *l; |     Line *l; | ||||||
| @@ -5140,7 +5140,7 @@ void pp_pre_undefine(char *definition) | |||||||
|     predef = l; |     predef = l; | ||||||
| } | } | ||||||
|  |  | ||||||
| void pp_extra_stdmac(macros_t *macros) | static void pp_extra_stdmac(macros_t *macros) | ||||||
| { | { | ||||||
|     extrastdmac = macros; |     extrastdmac = macros; | ||||||
| } | } | ||||||
| @@ -5156,5 +5156,10 @@ static void make_tok_num(Token * tok, int64_t val) | |||||||
| struct preproc_ops nasmpp = { | struct preproc_ops nasmpp = { | ||||||
|     pp_reset, |     pp_reset, | ||||||
|     pp_getline, |     pp_getline, | ||||||
|     pp_cleanup |     pp_cleanup, | ||||||
|  |     pp_extra_stdmac, | ||||||
|  |     pp_pre_define, | ||||||
|  |     pp_pre_undefine, | ||||||
|  |     pp_pre_include, | ||||||
|  |     pp_include_path | ||||||
| }; | }; | ||||||
|   | |||||||
| @@ -47,10 +47,5 @@ extern const uint8_t pp_directives_len[]; | |||||||
| typedef const unsigned char macros_t; | typedef const unsigned char macros_t; | ||||||
|  |  | ||||||
| enum preproc_token pp_token_hash(const char *token); | 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 | #endif | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user