authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-18 00:36:11-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-18 00:36:11-05:00
log3e4194bf9e0ccca122049be730ede0a2ca208c85
tree0aa24a03e9c2059424c558811fd71c299e10d279
parent05b3b6a45e425e2cb6d46358ec28437c29969e83

IR: add runime negation


1 files changed, 9 insertions(+), 4 deletions(-)

src/ir.cpp+9-4
...@@ -6319,11 +6319,13 @@ static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un...@@ -6319,11 +6319,13 @@ static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un
63196319
6320 if ((expr_type->id == TypeTableEntryIdInt && expr_type->data.integral.is_signed) ||6320 if ((expr_type->id == TypeTableEntryIdInt && expr_type->data.integral.is_signed) ||
6321 expr_type->id == TypeTableEntryIdNumLitInt ||6321 expr_type->id == TypeTableEntryIdNumLitInt ||
6322 ((expr_type->id == TypeTableEntryIdFloat || expr_type->id == TypeTableEntryIdNumLitFloat) &&6322 ((expr_type->id == TypeTableEntryIdFloat || expr_type->id == TypeTableEntryIdNumLitFloat) && !is_wrap_op))
6323 !is_wrap_op))
6324 {6323 {
6325 ConstExprValue *target_const_val = &value->static_value;6324 if (instr_is_comptime(value)) {
6326 if (target_const_val->special != ConstValSpecialRuntime) {6325 ConstExprValue *target_const_val = ir_resolve_const(ira, value, UndefBad);
6326 if (!target_const_val)
6327 return ira->codegen->builtin_types.entry_invalid;
6328
6327 bool depends_on_compile_var = value->static_value.depends_on_compile_var;6329 bool depends_on_compile_var = value->static_value.depends_on_compile_var;
6328 ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base, depends_on_compile_var);6330 ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base, depends_on_compile_var);
6329 bignum_negate(&out_val->data.x_bignum, &target_const_val->data.x_bignum);6331 bignum_negate(&out_val->data.x_bignum, &target_const_val->data.x_bignum);
...@@ -6344,6 +6346,9 @@ static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un...@@ -6344,6 +6346,9 @@ static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un
6344 }6346 }
6345 return expr_type;6347 return expr_type;
6346 }6348 }
6349
6350 ir_build_un_op_from(&ira->new_irb, &un_op_instruction->base, un_op_instruction->op_id, value);
6351 return expr_type;
6347 }6352 }
63486353
6349 const char *fmt = is_wrap_op ? "invalid wrapping negation type: '%s'" : "invalid negation type: '%s'";6354 const char *fmt = is_wrap_op ? "invalid wrapping negation type: '%s'" : "invalid negation type: '%s'";