#define XXX printf("%s:%i: %p -> %p\n", __func__, __LINE__, m, m->name); #define XXXX \ do { int x; for (x=0; x #include #include #include #include #include #include #include #include #include "nasm.h" #include "nasmlib.h" #include "nasm-pp.h" typedef struct SMacro SMacro; typedef struct MMacro MMacro; typedef struct Context Context; typedef struct Token Token; typedef struct Blocks Blocks; typedef struct Line Line; typedef struct Include Include; typedef struct Cond Cond; struct SMacro { SMacro *next; char *name; int casesense; int nparam; int in_progress; Token *expansion; }; struct MMacro { MMacro *next; char *name; int casesense; long nparam_min, nparam_max; int plus; /* is the last parameter greedy? */ int nolist; /* is this macro listing-inhibited? */ int in_progress; Token *dlist; /* All defaults as one list */ Token **defaults; /* Parameter default pointers */ int ndefs; /* number of default parameters */ Line *expansion; MMacro *next_active; MMacro *rep_nest; /* used for nesting %rep */ Token **params; /* actual parameters */ Token *iline; /* invocation line */ long nparam, rotate, *paramlen; unsigned long unique; int lineno; /* Current line number on expansion */ }; #define NHASH 31 extern void free_mmacro(MMacro * m); extern void free_tlist(Token * list_); extern void free_llist(Line * list_); extern MMacro *mmacros[NHASH]; extern SMacro *smacros[NHASH]; void pp_cleanup(int pass_) { int h; for (h = 0; h < NHASH; h++) { while (mmacros[h]) { MMacro *m = mmacros[h]; mmacros[h] = mmacros[h]->next; free_mmacro(m); } while (smacros[h]) { SMacro *s = smacros[h]; smacros[h] = smacros[h]->next; nasm_free(s->name); free_tlist(s->expansion); nasm_free(s); } } } #if 0 struct Include { Include *next; FILE *fp; Cond *conds; Line *expansion; char *fname; int lineno, lineinc; MMacro *mstk; /* stack of active macros/reps */ }; extern void free_tlist(Token * list_); #define NHASH 31 extern void free_llist(Line * list_); extern void ctx_pop(void); extern MMacro *mmacros[NHASH]; extern SMacro *smacros[NHASH]; extern FILE *first_fp; extern Line *builtindef; extern Line *predef; void delete_Blocks(void); extern void free_mmacro(MMacro * m); extern MMacro *defining; extern Context *cstk; extern Include *istk; extern void error(int severity, const char *fmt, ...); void pp_cleanup(int pass_) { int h; #if 1 if (defining) { error(ERR_NONFATAL, "end of file while still defining macro `%s'", defining->name); free_mmacro(defining); } while (cstk) ctx_pop(); #endif for (h = 0; h < NHASH; h++) { while (mmacros[h]) { MMacro *m = mmacros[h]; mmacros[h] = mmacros[h]->next; XXX free_mmacro(m); } while (smacros[h]) { SMacro *s = smacros[h]; smacros[h] = smacros[h]->next; nasm_free(s->name); free_tlist(s->expansion); nasm_free(s); } } #if 1 while (istk) { Include *i = istk; istk = istk->next; if (i->fp != first_fp) fclose(i->fp); nasm_free(i->fname); nasm_free(i); } while (cstk) ctx_pop(); if (pass_ == 0) { free_llist(builtindef); free_llist(predef); delete_Blocks(); } #endif } #endif