#include #include #include "mnemonics.h" #include "nqasm.h" #include "lexer.h" #include "parser.h" #include "vector.h" struct label { const char *name; uint16_t addr; }; static struct labels { struct vector v; struct label l[]; } *labels; uint16_t addr; static int labels_init(void) { return !(labels = vector_init(8, sizeof labels->l[0], sizeof *labels)); } static struct label *labels_append(void) { struct vector *v = &labels->v; struct label *l = vector_append(&v); labels = (struct labels *)v; return l; } void add_instruction(const struct instruction *inst) { const struct mnemonic *mnem = &mnemonics[inst->mnem]; uint16_t bits = mnem->bits; const struct operand *ops = mnem->operands; const struct argument *args = inst->args.args; for (int i = 0; i < 3 && ops[i].type; i++) { bits |= args[i].value << ops[i].shift; } printf("%04x\n", bits); addr += 2; } void add_label(const char *name) { struct label *l = labels_append(); if (!l) { fprintf(stderr, "unable to allocate label\n"); exit(1); } *l = (struct label) { .name = name, .addr = addr }; } int main(int argc, char **argv) { labels_init(); yyparse(); return 0; }