From 06f35955dff99ed705317e86bfcb658cd8707c06 Mon Sep 17 00:00:00 2001 From: ketmar Date: Sun, 25 Mar 2012 11:12:48 +0300 Subject: [PATCH] added 'label:' --- src/awasm.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/awasm.c b/src/awasm.c index 8cd36eb..2d903e2 100644 --- a/src/awasm.c +++ b/src/awasm.c @@ -1988,6 +1988,58 @@ static void parseMacroInvocation (MacroDef *mc) { } +static void parseLabelDef () { + LabelInfo *l; + // + if (nextToken() != TK_ID) fatal("label name expected"); + // + l = findLabel(tstr); + if (strcmp(tstr, ".") == 0) fatal("can't declare temp label"); + // + if (l != NULL) { + // new + if (l->ext < 0) fatal("can't declare extern label: '%s'", tstr); + if (l->type != LB_CODE || l->value >= 0) fatal("can't redeclare label: '%s'", tstr); + //fixupLabelRefs(l, pc); + } else { + l = addLabel(tstr); + l->type = LB_CODE; + l->value = -1; + } + // + if (nextToken() == '=') { + nextToken(); + //fprintf(stderr, "token=%d\n", token); + if (token == '$') { + int ch; + // + //TODO: allow simple repeated math (with labels too) + l->value = pc; + skipSpaces(0); // not newlines + ch = nextChar(); + if (ch == '-' || ch == '+') { + nextToken(); + if (token != TK_NUM) fatal("number expected"); + if (ch == '-') tint = -tint; + l->value += tint; + //fprintf(stderr, "pc=%d; tint=%d; value=%d\n", pc, tint, l->value); + } else { + if (ch != EOF && ch != '\n') fatal("invalid label definition: '%s'", l->name); + } + } else if (token == TK_NUM) { + l->value = tint; + } else { + fatal("invalid label definition: '%s'", l->name); + } + nextToken(); + } else { + l->value = pc; + } + if (l->value < 0) l->value &= 0xffff; + fixupLabelRefs(l, l->value); +} + + static void process (void) { int gotext = 0; LabelInfo *l = addLabel("retval"); @@ -2075,6 +2127,9 @@ static void process (void) { if (nextToken() != TK_NUM) fatal("tvarbase: number expected"); vtlast = tint; nextToken(); + } else if (strcmp(tstr, "label") == 0) { + if (gotext) fatal("'label' can't be external"); + parseLabelDef(); } else { parseLabel(gotext); } -- 2.11.4.GIT