diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-12-18 00:36:11 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-12-18 00:36:11 -0500 |
| commit | 3e4194bf9e0ccca122049be730ede0a2ca208c85 (patch) | |
| tree | 0aa24a03e9c2059424c558811fd71c299e10d279 /src/ir.cpp | |
| parent | 05b3b6a45e425e2cb6d46358ec28437c29969e83 (diff) | |
| download | zig-3e4194bf9e0ccca122049be730ede0a2ca208c85.tar.gz zig-3e4194bf9e0ccca122049be730ede0a2ca208c85.zip | |
IR: add runime negation
Diffstat (limited to 'src/ir.cpp')
| -rw-r--r-- | src/ir.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index 7211b4e614..64ffa022ac 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -6319,11 +6319,13 @@ static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un if ((expr_type->id == TypeTableEntryIdInt && expr_type->data.integral.is_signed) || expr_type->id == TypeTableEntryIdNumLitInt || - ((expr_type->id == TypeTableEntryIdFloat || expr_type->id == TypeTableEntryIdNumLitFloat) && - !is_wrap_op)) + ((expr_type->id == TypeTableEntryIdFloat || expr_type->id == TypeTableEntryIdNumLitFloat) && !is_wrap_op)) { - ConstExprValue *target_const_val = &value->static_value; - if (target_const_val->special != ConstValSpecialRuntime) { + if (instr_is_comptime(value)) { + ConstExprValue *target_const_val = ir_resolve_const(ira, value, UndefBad); + if (!target_const_val) + return ira->codegen->builtin_types.entry_invalid; + bool depends_on_compile_var = value->static_value.depends_on_compile_var; ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base, depends_on_compile_var); 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 } return expr_type; } + + ir_build_un_op_from(&ira->new_irb, &un_op_instruction->base, un_op_instruction->op_id, value); + return expr_type; } const char *fmt = is_wrap_op ? "invalid wrapping negation type: '%s'" : "invalid negation type: '%s'"; |
