nooc

nooc programming language compiler
git clone git://git.nihaljere.xyz/nooc
Log | Files | Refs | LICENSE

commit da6f12fa617d04c526120ae4f53b873ac17519c1
parent 8196ebe9084c0e9341677b105e96edeeefe64e66
Author: Nihal Jere <nihal@nihaljere.xyz>
Date:   Mon, 10 Jan 2022 14:26:14 -0600

make toplevel a global

There's only one for now, so it can be global.

Diffstat:
Mir.c | 9+++++----
Mir.h | 1-
Mmain.c | 4++--
Mx64.c | 4+++-
4 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/ir.c b/ir.c @@ -14,6 +14,7 @@ extern struct types types; extern struct exprs exprs; extern struct assgns assgns; +extern struct toplevel toplevel; #define PUTINS(op, val) ins = (struct instr){(op), (val)} ; bumpinterval(out, &ins, val) ; array_add(out, ins) ; #define STARTINS(op, val) curi++ ; PUTINS((op), (val)) ; @@ -56,10 +57,10 @@ static void genblock(struct iproc *out, struct block *block); static uint64_t -procindex(struct toplevel *top, struct slice *s) +procindex(struct slice *s) { - for (size_t i = 0; i < top->code.len; i++) { - struct iproc *iproc = &top->code.data[i]; + for (size_t i = 0; i < toplevel.code.len; i++) { + struct iproc *iproc = &toplevel.code.data[i]; if (slice_cmp(s, &iproc->s) == 0) return i; } @@ -192,7 +193,7 @@ genexpr(struct iproc *out, size_t expri) } case EXPR_FCALL: { what = 1; // value doesn't matter - uint64_t proc = procindex(out->top, &expr->d.call.name); + uint64_t proc = procindex(&expr->d.call.name); size_t params[20]; assert(expr->d.call.params.len < 20); for (size_t i = 0; i < expr->d.call.params.len; i++) { diff --git a/ir.h b/ir.h @@ -41,7 +41,6 @@ struct iproc { size_t cap; uint64_t addr; struct instr *data; - struct toplevel *top; // FIXME: basically just used to pass a parameter... struct slice s; struct { size_t len; diff --git a/main.c b/main.c @@ -34,6 +34,8 @@ extern struct types types; extern const struct target x64_target; struct target targ; +struct toplevel toplevel; + char *infile; // TODO: remove @@ -141,7 +143,6 @@ gentoplevel(struct toplevel *toplevel, struct block *block) blockpush(&expr->d.proc.block); typecheck(&expr->d.proc.block); iproc = (struct iproc){ 0 }; - iproc.top = toplevel; iproc.s = decl->s; iproc.addr = curaddr; genproc(&iproc, &(expr->d.proc)); @@ -204,7 +205,6 @@ main(int argc, char *argv[]) inittypes(); struct block items = parse(head); - struct toplevel toplevel = { 0 }; gentoplevel(&toplevel, &items); FILE *out = fopen(argv[2], "w"); diff --git a/x64.c b/x64.c @@ -27,6 +27,8 @@ enum mod { char abi_arg[] = {RAX, RDI, RSI, RDX, R10, R8, R9}; unsigned short used_reg; +extern struct toplevel toplevel; + #define NEXT ins++; assert(ins <= end); static size_t @@ -181,7 +183,7 @@ emitblock(char *buf, struct iproc *proc, struct instr *start, struct instr *end, } // we assume call is constant width - this should probably change - offset = -(proc->addr + total - proc->top->code.data[dest].addr + call(NULL, 0)); + offset = -(proc->addr + total - toplevel.code.data[dest].addr + call(NULL, 0)); total += call(buf ? buf + total : NULL, offset); // FIXME: this won't work with non-64-bit things total += add_r64_imm(buf ? buf + total : NULL, RSP, 8*count);