summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Kanios <keith@kanios.net>2009-07-12 23:39:04 -0500
committerKeith Kanios <keith@kanios.net>2009-07-12 23:39:04 -0500
commite0725dc769b6b375466e5d1245d3fa1be0087c91 (patch)
treece92e6975408e84a124b603a60766f1dfff165fc
parent852f1eeed56c7ff2c53df0e09f57fe3cd6a395b5 (diff)
downloadnasm-defid.tar.gz
preproc: add %[i]defid supportdefid
-rw-r--r--pptok.dat2
-rw-r--r--preproc.c41
2 files changed, 43 insertions, 0 deletions
diff --git a/pptok.dat b/pptok.dat
index 48b55af1..4edde848 100644
--- a/pptok.dat
+++ b/pptok.dat
@@ -50,6 +50,7 @@
%assign
%clear
%define
+%defid
%defstr
%depend
%elif*
@@ -64,6 +65,7 @@
%fatal
%iassign
%idefine
+%idefid
%idefstr
%if*
%imacro
diff --git a/preproc.c b/preproc.c
index e549b795..40464d43 100644
--- a/preproc.c
+++ b/preproc.c
@@ -2959,6 +2959,47 @@ static int do_directive(Token * tline)
free_tlist(origline);
return DIRECTIVE_FOUND;
+ case PP_DEFID:
+ case PP_IDEFID:
+ casesense = (i == PP_IDEFID);
+
+ tline = tline->next;
+ skip_white_(tline);
+ tline = expand_id(tline);
+ if (!tline || (tline->type != TOK_ID &&
+ (tline->type != TOK_PREPROC_ID ||
+ tline->text[1] != '$'))) {
+ error(ERR_NONFATAL, "`%s' expects a macro identifier",
+ pp_directives[i]);
+ free_tlist(origline);
+ return DIRECTIVE_FOUND;
+ }
+
+ ctx = get_ctx(tline->text, &mname, false);
+ last = tline;
+ tline = expand_smacro(tline->next);
+ last->next = NULL;
+
+ while (tok_type_(tline, TOK_WHITESPACE))
+ tline = delete_Token(tline);
+
+ p = detoken(tline, false);
+ if (tok_type_(tline, TOK_STRING)) {
+ macro_start = new_Token(NULL, TOK_ID, p+1, strlen(p)-2);
+ } else {
+ macro_start = new_Token(NULL, TOK_ID, p, strlen(p));
+ }
+ nasm_free(p);
+
+ /*
+ * We now have a macro name, an implicit parameter count of
+ * zero, and an id token to use as an expansion. Create
+ * and store an SMacro.
+ */
+ define_smacro(ctx, mname, casesense, 0, macro_start);
+ free_tlist(origline);
+ return DIRECTIVE_FOUND;
+
case PP_DEFSTR:
case PP_IDEFSTR:
casesense = (i == PP_DEFSTR);