summaryrefslogtreecommitdiff
path: root/preproc.c
diff options
context:
space:
mode:
authorCyrill Gorcunov <gorcunov@gmail.com>2011-06-30 01:16:35 +0400
committerCyrill Gorcunov <gorcunov@gmail.com>2011-06-30 01:16:35 +0400
commit194ba892cab16f6cd581b4e8a886b58e26419896 (patch)
tree00610efe11cd47f31cb667de231abc9d7dc872ac /preproc.c
parent5b6c96b9fda678dae2e9796ffaeeb3224893d879 (diff)
downloadnasm-194ba892cab16f6cd581b4e8a886b58e26419896.tar.gz
nasm-194ba892cab16f6cd581b4e8a886b58e26419896.tar.bz2
nasm-194ba892cab16f6cd581b4e8a886b58e26419896.zip
preproc: Add smacro paramter helpers
I belive this should simply code a bit. Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Diffstat (limited to 'preproc.c')
-rw-r--r--preproc.c38
1 files changed, 32 insertions, 6 deletions
diff --git a/preproc.c b/preproc.c
index 4eeda46..8f3e3cb 100644
--- a/preproc.c
+++ b/preproc.c
@@ -482,6 +482,28 @@ static ExpInv *new_ExpInv(int exp_type, ExpDef *ed);
#define tok_is_(x,v) (tok_type_((x), TOK_OTHER) && !strcmp((x)->text,(v)))
#define tok_isnt_(x,v) ((x) && ((x)->type!=TOK_OTHER || strcmp((x)->text,(v))))
+/*
+ * A few helpers for single macros
+ */
+
+/* We might be not smacro parameter at all */
+static bool is_smacro_param(Token *t)
+{
+ return t->type >= TOK_SMAC_PARAM;
+}
+
+/* smacro parameters are counted in a special way */
+static int smacro_get_param_idx(Token *t)
+{
+ return t->type - TOK_SMAC_PARAM;
+}
+
+/* encode smacro parameter index */
+static int smacro_set_param_idx(Token *t, unsigned int index)
+{
+ return t->type = TOK_SMAC_PARAM + index;
+}
+
#ifdef NASM_TRACE
#define stringify(x) #x
@@ -3248,7 +3270,10 @@ issue_error:
free_tlist(origline);
return DIRECTIVE_FOUND;
}
- tline->type = TOK_SMAC_PARAM + nparam++;
+
+ smacro_set_param_idx(tline, nparam);
+ nparam++;
+
tline = tline->next;
skip_white_(tline);
if (tok_is_(tline, ",")) {
@@ -3274,7 +3299,7 @@ issue_error:
while (t) {
if (t->type == TOK_ID) {
list_for_each(tt, param_start)
- if (tt->type >= TOK_SMAC_PARAM &&
+ if (is_smacro_param(tt) &&
!strcmp(tt->text, t->text))
t->type = tt->type;
}
@@ -4605,13 +4630,14 @@ again:
m->in_progress = true;
tline = tt;
list_for_each(t, m->expansion) {
- if (t->type >= TOK_SMAC_PARAM) {
+ if (is_smacro_param(t)) {
Token *pcopy = tline, **ptail = &pcopy;
Token *ttt, *pt;
- int i;
+ int i, idx;
- ttt = params[t->type - TOK_SMAC_PARAM];
- i = paramsize[t->type - TOK_SMAC_PARAM];
+ idx = smacro_get_param_idx(t);
+ ttt = params[idx];
+ i = paramsize[idx];
while (--i >= 0) {
pt = *ptail = new_Token(tline, ttt->type,
ttt->text, 0);