diff --git a/src/defs.h b/src/defs.h index 9cee7bfd..a2ebe9b6 100644 --- a/src/defs.h +++ b/src/defs.h @@ -45,6 +45,16 @@ /* Number of the available registers. Either 7 or 8 is accepted now. */ #define REG_CNT 8 +/* This macro will be automatically defined at shecc run-time. */ +#ifdef __SHECC__ +#define UNUSED(x) (x) +#define SHECC_CAST(x) (x) +#else +/* suppress GCC/Clang warnings */ +#define UNUSED(x) (void) (x) +#define SHECC_CAST(x) (void *) (x) +#endif + /* builtin types */ typedef enum { TYPE_void = 0, TYPE_int, TYPE_char, TYPE_struct } base_type_t; diff --git a/src/parser.c b/src/parser.c index 69514251..0c0c325e 100644 --- a/src/parser.c +++ b/src/parser.c @@ -2516,6 +2516,9 @@ void parse_internal() /* architecture defines */ add_alias(ARCH_PREDEFINED, "1"); + /* shecc run-time defines */ + add_alias("__SHECC__", "1"); + /* Linux syscall */ func = add_func("__syscall"); func->num_params = 0; diff --git a/src/ssa.c b/src/ssa.c index f6624882..6ae6dfe9 100644 --- a/src/ssa.c +++ b/src/ssa.c @@ -230,6 +230,8 @@ void build_dom() void bb_build_df(fn_t *fn, basic_block_t *bb) { + UNUSED(fn); + int i, cnt = 0; for (i = 0; i < MAX_BB_PRED; i++) if (bb->prev[i].bb) @@ -338,6 +340,8 @@ void fn_add_global(fn_t *fn, var_t *var) void bb_solve_globals(fn_t *fn, basic_block_t *bb) { + UNUSED(fn); + insn_t *insn; for (insn = bb->insn_list.head; insn; insn = insn->next) { if (insn->rs1) @@ -518,7 +522,7 @@ var_t *get_stack_top_subscript_var(var_t *var) abort(); } -void rename_var(block_t *block, var_t **var) +void rename_var(var_t **var) { if (!(*var)->base) (*var)->base = *var; @@ -558,10 +562,10 @@ void bb_solve_phi_params(basic_block_t *bb) new_name(bb->scope, &insn->rd); else { if (insn->rs1) - rename_var(bb->scope, &insn->rs1); + rename_var(&insn->rs1); if (insn->rs2) if (!insn->rs2->is_func) - rename_var(bb->scope, &insn->rs2); + rename_var(&insn->rs2); if (insn->rd) new_name(bb->scope, &insn->rd); } @@ -649,6 +653,8 @@ void append_unwound_phi_insn(basic_block_t *bb, var_t *dest, var_t *rs) void bb_unwind_phi(fn_t *fn, basic_block_t *bb) { + UNUSED(fn); + insn_t *insn; for (insn = bb->insn_list.head; insn; insn = insn->next) { if (insn->opcode != OP_phi) @@ -788,18 +794,18 @@ void bb_dump(FILE *fd, fn_t *fn, basic_block_t *bb) if (next_ && (then_ || else_)) printf("Warning: normal BB with condition\n"); - fprintf(fd, "subgraph cluster_%p {\n", bb); - fprintf(fd, "label=\"BasicBlock %p\"\n", bb); + fprintf(fd, "subgraph cluster_%p {\n", SHECC_CAST(bb)); + fprintf(fd, "label=\"BasicBlock %p\"\n", SHECC_CAST(bb)); insn_t *insn = bb->insn_list.head; if (!insn) - fprintf(fd, "pseudo_%p [label=\"pseudo\"]\n", bb); + fprintf(fd, "pseudo_%p [label=\"pseudo\"]\n", SHECC_CAST(bb)); if (!insn && (then_ || else_)) printf("Warning: pseudo node should only have NEXT\n"); for (; insn; insn = insn->next) { if (insn->opcode == OP_phi) { - fprintf(fd, "insn_%p [label=", insn); + fprintf(fd, "insn_%p [label=", SHECC_CAST(insn)); fprintf(fd, "<%s%d := PHI(%s%d", insn->rd->var_name, insn->rd->subscript, insn->phi_ops->var->var_name, @@ -923,11 +929,12 @@ void bb_dump(FILE *fd, fn_t *fn, basic_block_t *bb) printf("Unknown opcode\n"); abort(); } - fprintf(fd, "insn_%p [label=%s]\n", insn, str); + fprintf(fd, "insn_%p [label=%s]\n", SHECC_CAST(insn), str); } if (insn->next) - fprintf(fd, "insn_%p->insn_%p [weight=100]\n", insn, insn->next); + fprintf(fd, "insn_%p->insn_%p [weight=100]\n", SHECC_CAST(insn), + SHECC_CAST(insn->next)); } fprintf(fd, "}\n"); @@ -959,8 +966,8 @@ void dump_cfg(char name[]) fprintf(fd, "node [shape=box]\n"); for (fn = FUNC_LIST.head; fn; fn = fn->next) { fn->visited++; - fprintf(fd, "subgraph cluster_%p {\n", fn); - fprintf(fd, "label=\"%p\"\n", fn); + fprintf(fd, "subgraph cluster_%p {\n", SHECC_CAST(fn)); + fprintf(fd, "label=\"%p\"\n", SHECC_CAST(fn)); bb_dump(fd, fn, fn->bbs); fprintf(fd, "}\n"); } @@ -970,13 +977,14 @@ void dump_cfg(char name[]) void dom_dump(FILE *fd, basic_block_t *bb) { - fprintf(fd, "\"%p\"\n", bb); + fprintf(fd, "\"%p\"\n", SHECC_CAST(bb)); int i; for (i = 0; i < MAX_BB_DOM_SUCC; i++) { if (!bb->dom_next[i]) break; dom_dump(fd, bb->dom_next[i]); - fprintf(fd, "\"%p\":s->\"%p\":n\n", bb, bb->dom_next[i]); + fprintf(fd, "\"%p\":s->\"%p\":n\n", SHECC_CAST(bb), + SHECC_CAST(bb->dom_next[i])); } } @@ -989,8 +997,8 @@ void dump_dom(char name[]) fprintf(fd, "node [shape=box]\n"); fprintf(fd, "splines=polyline\n"); for (fn = FUNC_LIST.head; fn; fn = fn->next) { - fprintf(fd, "subgraph cluster_%p {\n", fn); - fprintf(fd, "label=\"%p\"\n", fn); + fprintf(fd, "subgraph cluster_%p {\n", SHECC_CAST(fn)); + fprintf(fd, "label=\"%p\"\n", SHECC_CAST(fn)); dom_dump(fd, fn->bbs); fprintf(fd, "}\n"); } @@ -1075,6 +1083,7 @@ void build_reversed_rpo() void bb_reset_live_kill_idx(fn_t *fn, basic_block_t *bb) { + UNUSED(fn); bb->live_kill_idx = 0; } @@ -1098,6 +1107,8 @@ void update_consumed(insn_t *insn, var_t *var) void bb_solve_locals(fn_t *fn, basic_block_t *bb) { + UNUSED(fn); + int i = 0; insn_t *insn; for (insn = bb->insn_list.head; insn; insn = insn->next) { @@ -1157,7 +1168,7 @@ void merge_live_in(var_t *live_out[], int *live_out_idx, basic_block_t *bb) } } -int recompute_live_out(fn_t *fn, basic_block_t *bb) +int recompute_live_out(basic_block_t *bb) { var_t *live_out[MAX_ANALYSIS_STACK_SIZE]; int live_out_idx = 0; @@ -1217,7 +1228,7 @@ void liveness_analysis() bb_add_killed_var(fn->bbs, fn->func->param_defs[i].subscripts[0]); fn->visited++; - args->preorder_cb = bb_solve_locals; + args->preorder_cb = &bb_solve_locals; bb_forward_traversal(args); } free(args); @@ -1228,13 +1239,15 @@ void liveness_analysis() do { changed = 0; for (bb = fn->exit; bb; bb = bb->rpo_r_next) - changed |= recompute_live_out(fn, bb); + changed |= recompute_live_out(bb); } while (changed); } } void bb_release(fn_t *fn, basic_block_t *bb) { + UNUSED(fn); + insn_t *insn = bb->insn_list.head; insn_t *next_insn; while (insn) {