From 12191884973f2691923d0fcc79ad10ea469f6e4f Mon Sep 17 00:00:00 2001 From: Ali Gholami Rudi Date: Sun, 8 May 2011 18:08:51 +0430 Subject: [PATCH] ncc: move nogen to ncc.c --- gen.c | 27 ++++----------------------- gen.h | 2 -- ncc.c | 54 ++++++++++++++++++++++++++++++++++++++---------------- 3 files changed, 42 insertions(+), 41 deletions(-) diff --git a/gen.c b/gen.c index 16d26aa..3d837d9 100644 --- a/gen.c +++ b/gen.c @@ -31,7 +31,6 @@ static char ds[SECSIZE]; /* data segment */ static int dslen; static long bsslen; /* bss segment size */ -static int nogen; /* don't generate code */ static long sp; static long func_beg; static long maxsp; @@ -99,8 +98,6 @@ static void os(void *s, int n) static void oi(long n) { - if (nogen) - return; *(int *) (cs + cslen) = n; cslen += 4; } @@ -853,16 +850,6 @@ void o_call(int argc, int rets) tmp_push(REG_RET); } -void o_nogen(void) -{ - nogen++; -} - -void o_dogen(void) -{ - nogen--; -} - void o_mkbss(char *name, int size, int global) { out_sym(name, OUT_BSS | (global ? OUT_GLOB : 0), bsslen, size); @@ -1094,10 +1081,7 @@ static void i_num(int rd, long n) oi(ADD(I_MVN, rd, 0, 0, 1, 14) | enc); return; } - if (!nogen) { - int off = pool_num(n); - i_ldr(1, rd, REG_DP, off, LONGSZ); - } + i_ldr(1, rd, REG_DP, pool_num(n), LONGSZ); } static void i_add_anyimm(int rd, int rn, long n) @@ -1255,10 +1239,8 @@ static void i_ldr(int l, int rd, int rn, int off, int bt) static void i_sym(int rd, char *sym, int off) { - if (!nogen) { - int doff = pool_reloc(sym, off); - i_ldr(1, rd, REG_DP, doff, LONGSZ); - } + int doff = pool_reloc(sym, off); + i_ldr(1, rd, REG_DP, doff, LONGSZ); } static void i_neg(int rd) @@ -1361,8 +1343,7 @@ static void i_call_reg(int rd) static void i_call(char *sym, int off) { - if (!nogen) - out_rel(sym, OUT_CS | OUT_REL24, cslen); + out_rel(sym, OUT_CS | OUT_REL24, cslen); oi(BL(14, 1, off)); } diff --git a/gen.h b/gen.h index e851a5c..af2889f 100644 --- a/gen.h +++ b/gen.h @@ -73,5 +73,3 @@ void o_func_beg(char *name, int argc, int global, int vararg); void o_func_end(void); /* output */ void o_write(int fd); -void o_nogen(void); -void o_dogen(void); diff --git a/ncc.c b/ncc.c index e8dd618..067d3a7 100644 --- a/ncc.c +++ b/ncc.c @@ -16,6 +16,35 @@ #include "tok.h" #include "out.h" +static int nogen; /* don't generate code */ +/* nogen macros */ +#define o_bop(op) {if (!nogen) o_bop(op);} +#define o_uop(op) {if (!nogen) o_uop(op);} +#define o_cast(bt) {if (!nogen) o_cast(bt);} +#define o_memcpy() {if (!nogen) o_memcpy();} +#define o_memset() {if (!nogen) o_memset();} +#define o_call(argc, ret) {if (!nogen) o_call(argc, ret);} +#define o_ret(ret) {if (!nogen) o_ret(ret);} +#define o_assign(bt) {if (!nogen) o_assign(bt);} +#define o_deref(bt) {if (!nogen) o_deref(bt);} +#define o_load() {if (!nogen) o_load();} +#define o_popnum(c) (nogen ? 0 : o_popnum(c)) +#define o_num(n) {if (!nogen) o_num(n);} +#define o_local(addr) {if (!nogen) o_local(addr);} +#define o_sym(sym) {if (!nogen) o_sym(sym);} +#define o_tmpdrop(n) {if (!nogen) o_tmpdrop(n);} +#define o_tmpswap() {if (!nogen) o_tmpswap();} +#define o_tmpcopy() {if (!nogen) o_tmpcopy();} +#define o_mklabel() (nogen ? 0 : o_mklabel()) +#define o_jz(addr) (nogen ? 0 : o_jz(addr)) +#define o_jnz(addr) (nogen ? 0 : o_jnz(addr)) +#define o_jmp(addr) (nogen ? 0 : o_jmp(addr)) +#define o_filljmp(addr) {if (!nogen) o_filljmp(addr);} +#define o_filljmp2(addr, dst) {if (!nogen) o_filljmp2(addr, dst);} +#define o_fork() {if (!nogen) o_fork();} +#define o_forkpush() {if (!nogen) o_forkpush();} +#define o_forkjoin() {if (!nogen) o_forkjoin();} + #define MAXLOCALS (1 << 10) #define MAXGLOBALS (1 << 10) #define MAXARGS (1 << 5) @@ -845,11 +874,10 @@ static void readpre(void) struct type t; int op = !tok_jmp('('); if (readtype(&t)) { - o_nogen(); + nogen++; readexpr(); - o_dogen(); + nogen--; ts_pop(&t); - o_tmpdrop(1); } ts_push_bt(4); o_num(type_totsz(&t)); @@ -1078,21 +1106,17 @@ static int readcexpr_const(void) if (o_popnum(&c)) return -1; if (!c) - o_nogen(); + nogen++; reador(); ts_pop(NULL); tok_expect(':'); - if (c) { - o_nogen(); - } else { - o_dogen(); - o_tmpdrop(1); - } + if (c) + nogen++; + else + nogen--; reador(); - if (c) { - o_dogen(); - o_tmpdrop(1); - } + if (c) + nogen--; return 0; } @@ -1287,7 +1311,6 @@ static int initsize(void) tok_jump(addr); return n; } - o_nogen(); tok_expect('{'); while (tok_jmp('}')) { long idx = n; @@ -1305,7 +1328,6 @@ static int initsize(void) jumpbrace(); tok_jmp(','); } - o_dogen(); tok_jump(addr); return n; } -- 2.11.4.GIT