| ... | ... | @@ -7811,27 +7811,40 @@ static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un |
| 7811 | 7811 | return ira->codegen->builtin_types.entry_invalid; |
| 7812 | 7812 | } |
| 7813 | 7813 | |
| 7814 | static TypeTableEntry *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *instruction) { |
| 7815 | IrInstruction *value = instruction->value->other; |
| 7816 | TypeTableEntry *expr_type = value->value.type; |
| 7817 | if (expr_type->id == TypeTableEntryIdInvalid) |
| 7818 | return ira->codegen->builtin_types.entry_invalid; |
| 7819 | |
| 7820 | if (expr_type->id == TypeTableEntryIdInt) { |
| 7821 | if (instr_is_comptime(value)) { |
| 7822 | ConstExprValue *target_const_val = ir_resolve_const(ira, value, UndefBad); |
| 7823 | if (!target_const_val) |
| 7824 | return ira->codegen->builtin_types.entry_invalid; |
| 7825 | |
| 7826 | bool depends_on_compile_var = value->value.depends_on_compile_var; |
| 7827 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var); |
| 7828 | bignum_not(&out_val->data.x_bignum, &target_const_val->data.x_bignum, expr_type->data.integral.bit_count); |
| 7829 | return expr_type; |
| 7830 | } |
| 7831 | |
| 7832 | ir_build_un_op_from(&ira->new_irb, &instruction->base, IrUnOpBinNot, value); |
| 7833 | return expr_type; |
| 7834 | } |
| 7835 | |
| 7836 | ir_add_error(ira, &instruction->base, |
| 7837 | buf_sprintf("unable to perform binary not operation on type '%s'", buf_ptr(&expr_type->name))); |
| 7838 | return ira->codegen->builtin_types.entry_invalid; |
| 7839 | } |
| 7840 | |
| 7814 | 7841 | static TypeTableEntry *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) { |
| 7815 | 7842 | IrUnOp op_id = un_op_instruction->op_id; |
| 7816 | 7843 | switch (op_id) { |
| 7817 | 7844 | case IrUnOpInvalid: |
| 7818 | 7845 | zig_unreachable(); |
| 7819 | 7846 | case IrUnOpBinNot: |
| 7820 | | zig_panic("TODO analyze PrefixOpBinNot"); |
| 7821 | | //{ |
| 7822 | | // TypeTableEntry *expr_type = analyze_expression(g, import, context, expected_type, |
| 7823 | | // *expr_node); |
| 7824 | | // if (expr_type->id == TypeTableEntryIdInvalid) { |
| 7825 | | // return expr_type; |
| 7826 | | // } else if (expr_type->id == TypeTableEntryIdInt) { |
| 7827 | | // return expr_type; |
| 7828 | | // } else { |
| 7829 | | // add_node_error(g, node, buf_sprintf("unable to perform binary not operation on type '%s'", |
| 7830 | | // buf_ptr(&expr_type->name))); |
| 7831 | | // return g->builtin_types.entry_invalid; |
| 7832 | | // } |
| 7833 | | // // TODO const expr eval |
| 7834 | | //} |
| 7847 | return ir_analyze_bin_not(ira, un_op_instruction); |
| 7835 | 7848 | case IrUnOpNegation: |
| 7836 | 7849 | case IrUnOpNegationWrap: |
| 7837 | 7850 | return ir_analyze_negation(ira, un_op_instruction); |