X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=blobdiff_plain;f=ir.c;h=9967d7d8dbd91649a62c55b69772a91fa3c6e2de;hp=4b7442e9ccf1a73fb714ee7be4554039b0f293b2;hb=6da151eba10aff16c1b897ee5fa3ce41c5d8fc8f;hpb=b2c8f3ebc5066a0c68d202b94f1e052e59eb1af4 diff --git a/ir.c b/ir.c index 4b7442e..9967d7d 100644 --- a/ir.c +++ b/ir.c @@ -248,7 +248,7 @@ static void irerror(lex_ctx_t ctx, const char *msg, ...) va_end(ap); } -static bool irwarning(lex_ctx_t ctx, int warntype, const char *fmt, ...) +static bool GMQCC_WARN irwarning(lex_ctx_t ctx, int warntype, const char *fmt, ...) { bool r; va_list ap; @@ -613,7 +613,7 @@ static bool instr_is_operation(uint16_t op) (op >= INSTR_NOT_F && op <= INSTR_NOT_FNC) || (op >= INSTR_AND && op <= INSTR_BITOR) || (op >= INSTR_CALL0 && op <= INSTR_CALL8) || - (op >= VINSTR_BITAND_V && op <= VINSTR_CROSS) ); + (op >= VINSTR_BITAND_V && op <= VINSTR_NEG_V) ); } static bool ir_function_pass_peephole(ir_function *self) @@ -1878,16 +1878,20 @@ ir_value* ir_block_create_unary(ir_block *self, lex_ctx_t ctx, case INSTR_NOT_V: case INSTR_NOT_S: case INSTR_NOT_ENT: - case INSTR_NOT_FNC: -#if 0 - case INSTR_NOT_I: -#endif + case INSTR_NOT_FNC: /* + case INSTR_NOT_I: */ ot = TYPE_FLOAT; break; - /* QC doesn't have other unary operations. We expect extensions to fill - * the above list, otherwise we assume out-type = in-type, eg for an - * unary minus + + /* + * Negation for virtual instructions is emulated with 0-value. Thankfully + * the operand for 0 already exists so we just source it from here. */ + case VINSTR_NEG_F: + return ir_block_create_general_instr(self, ctx, label, INSTR_SUB_F, NULL, operand, ot); + case VINSTR_NEG_V: + return ir_block_create_general_instr(self, ctx, label, INSTR_SUB_V, NULL, operand, ot); + default: ot = operand->vtype; break; @@ -3198,7 +3202,6 @@ static bool gen_blocks_recursive(code_t *code, ir_function *func, ir_block *bloc continue; } } - code_push_statement(code, &stmt, instr->context); } return true; @@ -3479,8 +3482,16 @@ static bool gen_global_function_code(ir_builder *ir, ir_value *global) irfun = global->constval.vfunc; if (!irfun) { if (global->cvq == CV_NONE) { - irwarning(global->context, WARN_IMPLICIT_FUNCTION_POINTER, - "function `%s` has no body and in QC implicitly becomes a function-pointer", global->name); + if (irwarning(global->context, WARN_IMPLICIT_FUNCTION_POINTER, + "function `%s` has no body and in QC implicitly becomes a function-pointer", + global->name)) + { + /* Not bailing out just now. If this happens a lot you don't want to have + * to rerun gmqcc for each such function. + */ + + /* return false; */ + } } /* this was a function pointer, don't generate code for those */ return true; @@ -3648,9 +3659,12 @@ static bool ir_builder_gen_global(ir_builder *self, ir_value *global, bool isloc /* TODO: same as above but for entity-fields rather than globsl */ } - else - irwarning(global->context, WARN_VOID_VARIABLES, "unrecognized variable of type void `%s`", - global->name); + else if(irwarning(global->context, WARN_VOID_VARIABLES, "unrecognized variable of type void `%s`", + global->name)) + { + /* Not bailing out */ + /* return false; */ + } /* I'd argue setting it to 0 is sufficient, but maybe some depend on knowing how far * the system fields actually go? Though the engine knows this anyway... * Maybe this could be an -foption @@ -3963,10 +3977,6 @@ bool ir_builder_generate(ir_builder *self, const char *filename) #define IND_BUFSZ 1024 -#ifdef _MSC_VER -# define strncat(dst, src, sz) strncat_s(dst, sz, src, _TRUNCATE) -#endif - static const char *qc_opname(int op) { if (op < 0) return ""; @@ -3985,6 +3995,8 @@ static const char *qc_opname(int op) case VINSTR_BITOR_VF: return "BITOR_VF"; case VINSTR_BITXOR_VF: return "BITXOR_VF"; case VINSTR_CROSS: return "CROSS"; + case VINSTR_NEG_F: return "NEG_F"; + case VINSTR_NEG_V: return "NEG_V"; default: return ""; } } @@ -4023,7 +4035,7 @@ void ir_function_dump(ir_function *f, char *ind, return; } oprintf("%sfunction %s\n", ind, f->name); - strncat(ind, "\t", IND_BUFSZ-1); + util_strncat(ind, "\t", IND_BUFSZ-1); if (vec_size(f->locals)) { oprintf("%s%i locals:\n", ind, (int)vec_size(f->locals)); @@ -4119,7 +4131,7 @@ void ir_block_dump(ir_block* b, char *ind, { size_t i; oprintf("%s:%s\n", ind, b->label); - strncat(ind, "\t", IND_BUFSZ-1); + util_strncat(ind, "\t", IND_BUFSZ-1); if (b->instr && b->instr[0]) oprintf("%s (%i) [entry]\n", ind, (int)(b->instr[0]->eid-1)); @@ -4153,7 +4165,7 @@ void ir_instr_dump(ir_instr *in, char *ind, return; } - strncat(ind, "\t", IND_BUFSZ-1); + util_strncat(ind, "\t", IND_BUFSZ-1); if (in->_ops[0] && (in->_ops[1] || in->_ops[2])) { ir_value_dump(in->_ops[0], oprintf);