aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2019-09-12 19:39:48 -0700
committerH. Peter Anvin <hpa@zytor.com>2019-09-12 19:39:48 -0700
commitdd88aa9a1b065bb28eb4535a4382c3fe36c5fa31 (patch)
tree65198ccf74b436cb9ab2f680cac30f016d08c2d2
parenta039fcdb46b70a0645d6747b56b6a075b6ba9fc5 (diff)
downloadnasm-dd88aa9a1b065bb28eb4535a4382c3fe36c5fa31.tar.gz
nasm-dd88aa9a1b065bb28eb4535a4382c3fe36c5fa31.tar.xz
nasm-dd88aa9a1b065bb28eb4535a4382c3fe36c5fa31.zip
preproc: add %ifusable and %ifusing directives
%ifusable tests to see if a certain %use package is available in this version of NASM. %ifusing tests if a certain %use packages is already loaded. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
-rw-r--r--asm/pptok.dat2
-rw-r--r--asm/preproc.c22
2 files changed, 21 insertions, 3 deletions
diff --git a/asm/pptok.dat b/asm/pptok.dat
index bb908a31..d2f361c8 100644
--- a/asm/pptok.dat
+++ b/asm/pptok.dat
@@ -53,6 +53,8 @@
*num
*str
*token
+*usable
+*using
# Directives with -i- versions for case insensitive
%!assign
diff --git a/asm/preproc.c b/asm/preproc.c
index 1828c8a8..6c623327 100644
--- a/asm/preproc.c
+++ b/asm/preproc.c
@@ -521,6 +521,8 @@ static Token *new_Token(Token * next, enum pp_token_type type,
const char *text, size_t txtlen);
static Token *dup_Token(Token *next, const Token *src);
static Token *delete_Token(Token * t);
+static const struct use_package *
+get_use_pkg(Token *t, const char *dname, bool *err);
/*
* Macros for safe checking of token pointers, avoid *(NULL)
@@ -1989,10 +1991,11 @@ static enum cond_state if_condition(Token * tline, enum preproc_token ct)
char *p;
const char *dname = pp_directives[ct];
bool casesense = true;
+ enum preproc_token cond = PP_COND(ct);
origline = tline;
- switch (PP_COND(ct)) {
+ switch (cond) {
case PP_IFCTX:
j = false; /* have we matched yet? */
while (true) {
@@ -2235,6 +2238,20 @@ iftype:
j = reloc_value(evalresult) != 0;
break;
+ case PP_IFUSING:
+ case PP_IFUSABLE:
+ {
+ const struct use_package *pkg;
+ bool err;
+
+ pkg = get_use_pkg(tline, dname, &err);
+ if (err)
+ goto fail;
+
+ j = pkg && ((cond == PP_IFUSABLE) | use_loaded[pkg->index]);
+ break;
+ }
+
default:
nasm_nonfatal("unknown preprocessor directive `%s'", dname);
goto fail;
@@ -2767,7 +2784,6 @@ get_use_pkg(Token *t, const char *dname, bool *err)
*err = false;
- t = t->next; /* Skip directive */
skip_white_(t);
t = expand_smacro(t);
@@ -3188,7 +3204,7 @@ static int do_directive(Token *tline, Token **output)
const struct use_package *pkg;
bool err;
- pkg = get_use_pkg(tline, dname, &err);
+ pkg = get_use_pkg(tline->next, dname, &err);
if (err)
goto done;