summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lexer.l1
-rw-r--r--nqasm.c8
-rw-r--r--nqasm.h1
-rw-r--r--parser.y3
4 files changed, 9 insertions, 4 deletions
diff --git a/lexer.l b/lexer.l
index 5c8ebfb..053ac4e 100644
--- a/lexer.l
+++ b/lexer.l
@@ -74,6 +74,7 @@ HEX [0-9a-f]
<inst>addpc/{EOI} { BEGIN(args); return T_ADDPC; }
<inst>nop/{EOI} { BEGIN(args); return T_NOP; }
+<args>\. { return T_DOT; }
<args>@ { return T_DEREF; }
<args>[-+]?{DEC}+ { return intlit(yytext, 10, &yylval.lval); }
<args>0x{HEX}+ { return intlit(yytext+2, 16, &yylval.lval); }
diff --git a/nqasm.c b/nqasm.c
index 0b0bbd8..ee3010a 100644
--- a/nqasm.c
+++ b/nqasm.c
@@ -56,12 +56,12 @@ void add_instruction(const struct instruction *inst)
addr += 2;
}
-static long eval_argument(const struct argument *arg)
+static long eval_argument(const struct argument *arg, uint16_t pc)
{
struct label *l;
switch (arg->type) {
- case ARG_INTEGER:
- return arg->value;
+ case ARG_INTEGER: return arg->value;
+ case ARG_PC: return pc;
case ARG_LABEL:
l = vector_search(&labels->v, &(struct label) { .name = arg->label }, cmp_label);
@@ -82,7 +82,7 @@ static void assemble_instruction(const struct instruction *inst, uint16_t pc)
const struct operand *ops = mnem->operands;
const struct argument *args = inst->args.args;
for (int i = 0; i < 3 && ops[i].type; i++) {
- long value = eval_argument(args + i);
+ long value = eval_argument(args + i, pc);
switch (ops[i].type) {
case REG:
diff --git a/nqasm.h b/nqasm.h
index f2e036d..0bc51f7 100644
--- a/nqasm.h
+++ b/nqasm.h
@@ -3,6 +3,7 @@
#define ARG_INTEGER 0
#define ARG_LABEL 1
+#define ARG_PC 2
struct argument {
int type;
diff --git a/parser.y b/parser.y
index e698e47..2ec2264 100644
--- a/parser.y
+++ b/parser.y
@@ -15,6 +15,7 @@ void yyerror(const char *msg)
#define MKARGS(...) (struct arguments) { { __VA_ARGS__ } }
#define MKARGVALUE(v) (struct argument) { .type = ARG_INTEGER, .value = (v) }
#define MKARGLABEL(l) (struct argument) { .type = ARG_LABEL, .label = (l) }
+#define MKARGTYPE(t) (struct argument) { .type = (t) }
%}
@@ -80,6 +81,7 @@ void yyerror(const char *msg)
%token T_COMMA ","
%token T_COLON ":"
+%token T_DOT "."
%token T_DEREF "@"
%type <inst> inst
@@ -178,6 +180,7 @@ reg: T_LABEL {
expr:
intlit { $$ = MKARGVALUE($1); }
| T_LABEL { $$ = MKARGLABEL($1); }
+ | "." { $$ = MKARGTYPE(ARG_PC); }
;
intlit: T_INT