authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-11 17:17:00-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-11 17:17:00-05:00
logdf0cdceff7c84510662b9fa3e698ff36c31b1ede
tree14d69d40a55aa76408e034f5844b9fd6f930d705
parent9b17c0ff7fa7a3981697f4239afb5c66c609cd42

IR: implement compile time array multiplication


1 files changed, 190 insertions(+), 113 deletions(-)

src/ir.cpp+190-113
......@@ -4195,7 +4195,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
41954195 return ira->codegen->invalid_instruction;
41964196}
41974197
4198static IrInstruction *ir_get_casted_value(IrAnalyze *ira, IrInstruction *value, TypeTableEntry *expected_type) {
4198static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, TypeTableEntry *expected_type) {
41994199 assert(value);
42004200 assert(value != ira->codegen->invalid_instruction);
42014201 assert(!expected_type || expected_type->id != TypeTableEntryIdInvalid);
......@@ -4283,7 +4283,7 @@ static bool ir_resolve_usize(IrAnalyze *ira, IrInstruction *value, uint64_t *out
42834283 if (value->type_entry->id == TypeTableEntryIdInvalid)
42844284 return false;
42854285
4286 IrInstruction *casted_value = ir_get_casted_value(ira, value, ira->codegen->builtin_types.entry_usize);
4286 IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_usize);
42874287 if (casted_value->type_entry->id == TypeTableEntryIdInvalid)
42884288 return false;
42894289
......@@ -4299,7 +4299,7 @@ static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) {
42994299 if (value->type_entry->id == TypeTableEntryIdInvalid)
43004300 return false;
43014301
4302 IrInstruction *casted_value = ir_get_casted_value(ira, value, ira->codegen->builtin_types.entry_bool);
4302 IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_bool);
43034303 if (casted_value->type_entry->id == TypeTableEntryIdInvalid)
43044304 return false;
43054305
......@@ -4315,7 +4315,7 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic
43154315 if (value->type_entry->id == TypeTableEntryIdInvalid)
43164316 return false;
43174317
4318 IrInstruction *casted_value = ir_get_casted_value(ira, value, ira->codegen->builtin_types.entry_atomic_order_enum);
4318 IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_atomic_order_enum);
43194319 if (casted_value->type_entry->id == TypeTableEntryIdInvalid)
43204320 return false;
43214321
......@@ -4332,7 +4332,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
43324332 return nullptr;
43334333
43344334 TypeTableEntry *str_type = get_slice_type(ira->codegen, ira->codegen->builtin_types.entry_u8, true);
4335 IrInstruction *casted_value = ir_get_casted_value(ira, value, str_type);
4335 IrInstruction *casted_value = ir_implicit_cast(ira, value, str_type);
43364336 if (casted_value->type_entry->id == TypeTableEntryIdInvalid)
43374337 return nullptr;
43384338
......@@ -4366,7 +4366,7 @@ static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira,
43664366 return ir_unreach_error(ira);
43674367 ira->implicit_return_type_list.append(value);
43684368
4369 IrInstruction *casted_value = ir_get_casted_value(ira, value, ira->explicit_return_type);
4369 IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->explicit_return_type);
43704370 if (casted_value == ira->codegen->invalid_instruction)
43714371 return ir_unreach_error(ira);
43724372
......@@ -4392,11 +4392,11 @@ static TypeTableEntry *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp
43924392
43934393 TypeTableEntry *bool_type = ira->codegen->builtin_types.entry_bool;
43944394
4395 IrInstruction *casted_op1 = ir_get_casted_value(ira, op1, bool_type);
4395 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, bool_type);
43964396 if (casted_op1 == ira->codegen->invalid_instruction)
43974397 return ira->codegen->builtin_types.entry_invalid;
43984398
4399 IrInstruction *casted_op2 = ir_get_casted_value(ira, op2, bool_type);
4399 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, bool_type);
44004400 if (casted_op2 == ira->codegen->invalid_instruction)
44014401 return ira->codegen->builtin_types.entry_invalid;
44024402
......@@ -4485,11 +4485,11 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
44854485 zig_unreachable();
44864486 }
44874487
4488 IrInstruction *casted_op1 = ir_get_casted_value(ira, op1, resolved_type);
4488 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, resolved_type);
44894489 if (casted_op1 == ira->codegen->invalid_instruction)
44904490 return ira->codegen->builtin_types.entry_invalid;
44914491
4492 IrInstruction *casted_op2 = ir_get_casted_value(ira, op2, resolved_type);
4492 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, resolved_type);
44934493 if (casted_op2 == ira->codegen->invalid_instruction)
44944494 return ira->codegen->builtin_types.entry_invalid;
44954495
......@@ -4669,11 +4669,11 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
46694669 return ira->codegen->builtin_types.entry_invalid;
46704670 }
46714671
4672 IrInstruction *casted_op1 = ir_get_casted_value(ira, op1, resolved_type);
4672 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, resolved_type);
46734673 if (casted_op1 == ira->codegen->invalid_instruction)
46744674 return ira->codegen->builtin_types.entry_invalid;
46754675
4676 IrInstruction *casted_op2 = ir_get_casted_value(ira, op2, resolved_type);
4676 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, resolved_type);
46774677 if (casted_op2 == ira->codegen->invalid_instruction)
46784678 return ira->codegen->builtin_types.entry_invalid;
46794679
......@@ -4709,6 +4709,165 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
47094709 return resolved_type;
47104710}
47114711
4712static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruction) {
4713 IrInstruction *op1 = instruction->op1->other;
4714 if (op1->type_entry->id == TypeTableEntryIdInvalid)
4715 return ira->codegen->builtin_types.entry_invalid;
4716
4717 IrInstruction *op2 = instruction->op2->other;
4718 if (op2->type_entry->id == TypeTableEntryIdInvalid)
4719 return ira->codegen->builtin_types.entry_invalid;
4720
4721// AstNode **op1 = node->data.bin_op_expr.op1->parent_field;
4722// AstNode **op2 = node->data.bin_op_expr.op2->parent_field;
4723//
4724// TypeTableEntry *op1_type = analyze_expression(g, import, context, nullptr, *op1);
4725// TypeTableEntry *child_type;
4726// if (op1_type->id == TypeTableEntryIdInvalid) {
4727// return g->builtin_types.entry_invalid;
4728// } else if (op1_type->id == TypeTableEntryIdArray) {
4729// child_type = op1_type->data.array.child_type;
4730// } else if (op1_type->id == TypeTableEntryIdPointer &&
4731// op1_type->data.pointer.child_type == g->builtin_types.entry_u8) {
4732// child_type = op1_type->data.pointer.child_type;
4733// } else {
4734// add_node_error(g, *op1, buf_sprintf("expected array or C string literal, found '%s'",
4735// buf_ptr(&op1_type->name)));
4736// return g->builtin_types.entry_invalid;
4737// }
4738//
4739// TypeTableEntry *op2_type = analyze_expression(g, import, context, nullptr, *op2);
4740//
4741// if (op2_type->id == TypeTableEntryIdInvalid) {
4742// return g->builtin_types.entry_invalid;
4743// } else if (op2_type->id == TypeTableEntryIdArray) {
4744// if (op2_type->data.array.child_type != child_type) {
4745// add_node_error(g, *op2, buf_sprintf("expected array of type '%s', found '%s'",
4746// buf_ptr(&child_type->name),
4747// buf_ptr(&op2_type->name)));
4748// return g->builtin_types.entry_invalid;
4749// }
4750// } else if (op2_type->id == TypeTableEntryIdPointer &&
4751// op2_type->data.pointer.child_type == g->builtin_types.entry_u8) {
4752// } else {
4753// add_node_error(g, *op2, buf_sprintf("expected array or C string literal, found '%s'",
4754// buf_ptr(&op2_type->name)));
4755// return g->builtin_types.entry_invalid;
4756// }
4757//
4758// ConstExprValue *op1_val = &get_resolved_expr(*op1)->const_val;
4759// ConstExprValue *op2_val = &get_resolved_expr(*op2)->const_val;
4760//
4761// AstNode *bad_node;
4762// if (!op1_val->ok) {
4763// bad_node = *op1;
4764// } else if (!op2_val->ok) {
4765// bad_node = *op2;
4766// } else {
4767// bad_node = nullptr;
4768// }
4769// if (bad_node) {
4770// add_node_error(g, bad_node, buf_sprintf("array concatenation requires constant expression"));
4771// return g->builtin_types.entry_invalid;
4772// }
4773//
4774// ConstExprValue *const_val = &get_resolved_expr(node)->const_val;
4775// const_val->ok = true;
4776// const_val->depends_on_compile_var = op1_val->depends_on_compile_var ||
4777// op2_val->depends_on_compile_var;
4778//
4779// if (op1_type->id == TypeTableEntryIdArray) {
4780// uint64_t new_len = op1_type->data.array.len + op2_type->data.array.len;
4781// const_val->data.x_array.fields = allocate<ConstExprValue*>(new_len);
4782// uint64_t next_index = 0;
4783// for (uint64_t i = 0; i < op1_type->data.array.len; i += 1, next_index += 1) {
4784// const_val->data.x_array.fields[next_index] = op1_val->data.x_array.fields[i];
4785// }
4786// for (uint64_t i = 0; i < op2_type->data.array.len; i += 1, next_index += 1) {
4787// const_val->data.x_array.fields[next_index] = op2_val->data.x_array.fields[i];
4788// }
4789// return get_array_type(g, child_type, new_len);
4790// } else if (op1_type->id == TypeTableEntryIdPointer) {
4791// if (!op1_val->data.x_ptr.is_c_str) {
4792// add_node_error(g, *op1,
4793// buf_sprintf("expected array or C string literal, found '%s'",
4794// buf_ptr(&op1_type->name)));
4795// return g->builtin_types.entry_invalid;
4796// } else if (!op2_val->data.x_ptr.is_c_str) {
4797// add_node_error(g, *op2,
4798// buf_sprintf("expected array or C string literal, found '%s'",
4799// buf_ptr(&op2_type->name)));
4800// return g->builtin_types.entry_invalid;
4801// }
4802// const_val->data.x_ptr.is_c_str = true;
4803// const_val->data.x_ptr.len = op1_val->data.x_ptr.len + op2_val->data.x_ptr.len - 1;
4804// const_val->data.x_ptr.ptr = allocate<ConstExprValue*>(const_val->data.x_ptr.len);
4805// uint64_t next_index = 0;
4806// for (uint64_t i = 0; i < op1_val->data.x_ptr.len - 1; i += 1, next_index += 1) {
4807// const_val->data.x_ptr.ptr[next_index] = op1_val->data.x_ptr.ptr[i];
4808// }
4809// for (uint64_t i = 0; i < op2_val->data.x_ptr.len; i += 1, next_index += 1) {
4810// const_val->data.x_ptr.ptr[next_index] = op2_val->data.x_ptr.ptr[i];
4811// }
4812// return op1_type;
4813// } else {
4814// zig_unreachable();
4815// }
4816 zig_panic("TODO");
4817}
4818
4819static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instruction) {
4820 IrInstruction *op1 = instruction->op1->other;
4821 if (op1->type_entry->id == TypeTableEntryIdInvalid)
4822 return ira->codegen->builtin_types.entry_invalid;
4823
4824 IrInstruction *op2 = instruction->op2->other;
4825 if (op2->type_entry->id == TypeTableEntryIdInvalid)
4826 return ira->codegen->builtin_types.entry_invalid;
4827
4828 ConstExprValue *array_val = ir_resolve_const(ira, op1);
4829 if (!array_val)
4830 return ira->codegen->builtin_types.entry_invalid;
4831
4832 uint64_t mult_amt;
4833 if (!ir_resolve_usize(ira, op2, &mult_amt))
4834 return ira->codegen->builtin_types.entry_invalid;
4835
4836 TypeTableEntry *array_canon_type = get_underlying_type(op1->type_entry);
4837 if (array_canon_type->id != TypeTableEntryIdArray) {
4838 ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->type_entry->name)));
4839 // TODO if meta_type is type decl, add note pointing to type decl declaration
4840 return ira->codegen->builtin_types.entry_invalid;
4841 }
4842
4843 uint64_t old_array_len = array_canon_type->data.array.len;
4844
4845 BigNum array_len;
4846 bignum_init_unsigned(&array_len, old_array_len);
4847 if (bignum_multiply_by_scalar(&array_len, mult_amt)) {
4848 ir_add_error(ira, &instruction->base, buf_sprintf("operation results in overflow"));
4849 return ira->codegen->builtin_types.entry_invalid;
4850 }
4851
4852 bool depends_on_compile_var = op1->static_value.depends_on_compile_var || op2->static_value.depends_on_compile_var;
4853 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base, depends_on_compile_var);
4854
4855 uint64_t new_array_len = array_len.data.x_uint;
4856 out_val->data.x_array.size = new_array_len;
4857 out_val->data.x_array.elements = allocate<ConstExprValue>(new_array_len);
4858
4859 uint64_t i = 0;
4860 for (uint64_t x = 0; x < mult_amt; x += 1) {
4861 for (uint64_t y = 0; y < old_array_len; y += 1) {
4862 out_val->data.x_array.elements[i] = array_val->data.x_array.elements[y];
4863 i += 1;
4864 }
4865 }
4866 assert(i == new_array_len);
4867
4868 TypeTableEntry *child_type = array_canon_type->data.array.child_type;
4869 return get_array_type(ira->codegen, child_type, new_array_len);
4870}
47124871
47134872static TypeTableEntry *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
47144873 IrBinOp op_id = bin_op_instruction->op_id;
......@@ -4741,8 +4900,9 @@ static TypeTableEntry *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructi
47414900 case IrBinOpMod:
47424901 return ir_analyze_bin_op_math(ira, bin_op_instruction);
47434902 case IrBinOpArrayCat:
4903 return ir_analyze_array_cat(ira, bin_op_instruction);
47444904 case IrBinOpArrayMult:
4745 zig_panic("TODO analyze more binary operations");
4905 return ir_analyze_array_mult(ira, bin_op_instruction);
47464906 }
47474907 zig_unreachable();
47484908}
......@@ -4774,7 +4934,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
47744934
47754935 AstNode *source_node = decl_var_instruction->base.source_node;
47764936
4777 IrInstruction *casted_init_value = ir_get_casted_value(ira, init_value, explicit_type);
4937 IrInstruction *casted_init_value = ir_implicit_cast(ira, init_value, explicit_type);
47784938 TypeTableEntry *result_type = get_underlying_type(casted_init_value->type_entry);
47794939 switch (result_type->id) {
47804940 case TypeTableEntryIdTypeDecl:
......@@ -4859,7 +5019,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node
48595019 if (param_type->id == TypeTableEntryIdInvalid)
48605020 return false;
48615021
4862 IrInstruction *casted_arg = ir_get_casted_value(ira, arg, param_type);
5022 IrInstruction *casted_arg = ir_implicit_cast(ira, arg, param_type);
48635023 if (casted_arg->type_entry->id == TypeTableEntryIdInvalid)
48645024 return false;
48655025
......@@ -4893,7 +5053,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
48935053 if (is_var_type) {
48945054 casted_arg = arg;
48955055 } else {
4896 casted_arg = ir_get_casted_value(ira, arg, param_type);
5056 casted_arg = ir_implicit_cast(ira, arg, param_type);
48975057 if (casted_arg->type_entry->id == TypeTableEntryIdInvalid)
48985058 return false;
48995059 }
......@@ -5098,7 +5258,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
50985258 if (param_type->id == TypeTableEntryIdInvalid)
50995259 return ira->codegen->builtin_types.entry_invalid;
51005260
5101 IrInstruction *casted_arg = ir_get_casted_value(ira, first_arg, param_type);
5261 IrInstruction *casted_arg = ir_implicit_cast(ira, first_arg, param_type);
51025262 if (casted_arg->type_entry->id == TypeTableEntryIdInvalid)
51035263 return ira->codegen->builtin_types.entry_invalid;
51045264
......@@ -5114,7 +5274,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
51145274 TypeTableEntry *param_type = fn_type_id->param_info[next_arg_index].type;
51155275 if (param_type->id == TypeTableEntryIdInvalid)
51165276 return ira->codegen->builtin_types.entry_invalid;
5117 casted_arg = ir_get_casted_value(ira, old_arg, param_type);
5277 casted_arg = ir_implicit_cast(ira, old_arg, param_type);
51185278 if (casted_arg->type_entry->id == TypeTableEntryIdInvalid)
51195279 return ira->codegen->builtin_types.entry_invalid;
51205280 } else {
......@@ -5541,7 +5701,7 @@ static TypeTableEntry *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstruct
55415701 }
55425702
55435703 TypeTableEntry *bool_type = ira->codegen->builtin_types.entry_bool;
5544 IrInstruction *casted_condition = ir_get_casted_value(ira, condition, bool_type);
5704 IrInstruction *casted_condition = ir_implicit_cast(ira, condition, bool_type);
55455705 if (casted_condition == ira->codegen->invalid_instruction)
55465706 return ir_unreach_error(ira);
55475707
......@@ -5624,7 +5784,7 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
56245784 // cast all literal values to the resolved type
56255785 for (size_t i = 0; i < new_incoming_values.length; i += 1) {
56265786 IrInstruction *new_value = new_incoming_values.at(i);
5627 IrInstruction *casted_value = ir_get_casted_value(ira, new_value, resolved_type);
5787 IrInstruction *casted_value = ir_implicit_cast(ira, new_value, resolved_type);
56285788 new_incoming_values.items[i] = casted_value;
56295789 }
56305790
......@@ -5700,7 +5860,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
57005860 }
57015861
57025862 TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize;
5703 IrInstruction *casted_elem_index = ir_get_casted_value(ira, elem_index, usize);
5863 IrInstruction *casted_elem_index = ir_implicit_cast(ira, elem_index, usize);
57045864 if (casted_elem_index == ira->codegen->invalid_instruction)
57055865 return ira->codegen->builtin_types.entry_invalid;
57065866
......@@ -6076,7 +6236,7 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru
60766236 return value->type_entry;
60776237
60786238 TypeTableEntry *child_type = ptr->type_entry->data.pointer.child_type;
6079 IrInstruction *casted_value = ir_get_casted_value(ira, value, child_type);
6239 IrInstruction *casted_value = ir_implicit_cast(ira, value, child_type);
60806240 if (casted_value == ira->codegen->invalid_instruction)
60816241 return ira->codegen->builtin_types.entry_invalid;
60826242
......@@ -6717,7 +6877,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,
67176877 if (case_value->type_entry->id == TypeTableEntryIdInvalid)
67186878 return ir_unreach_error(ira);
67196879
6720 IrInstruction *casted_case_value = ir_get_casted_value(ira, case_value, target_value->type_entry);
6880 IrInstruction *casted_case_value = ir_implicit_cast(ira, case_value, target_value->type_entry);
67216881 if (casted_case_value->type_entry->id == TypeTableEntryIdInvalid)
67226882 return ir_unreach_error(ira);
67236883
......@@ -6751,7 +6911,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,
67516911 if (new_value->type_entry->id == TypeTableEntryIdInvalid)
67526912 continue;
67536913
6754 IrInstruction *casted_new_value = ir_get_casted_value(ira, new_value, target_value->type_entry);
6914 IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, target_value->type_entry);
67556915 if (casted_new_value->type_entry->id == TypeTableEntryIdInvalid)
67566916 continue;
67576917
......@@ -7265,7 +7425,7 @@ static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruc
72657425 if (value->type_entry->id == TypeTableEntryIdInvalid)
72667426 return ira->codegen->builtin_types.entry_invalid;
72677427
7268 IrInstruction *casted_value = ir_get_casted_value(ira, value, value->type_entry);
7428 IrInstruction *casted_value = ir_implicit_cast(ira, value, value->type_entry);
72697429 if (casted_value->type_entry->id == TypeTableEntryIdInvalid)
72707430 return ira->codegen->builtin_types.entry_invalid;
72717431
......@@ -7493,11 +7653,11 @@ static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstruct
74937653
74947654 TypeTableEntry *child_type = ptr->type_entry->data.pointer.child_type;
74957655
7496 IrInstruction *casted_cmp_value = ir_get_casted_value(ira, cmp_value, child_type);
7656 IrInstruction *casted_cmp_value = ir_implicit_cast(ira, cmp_value, child_type);
74977657 if (casted_cmp_value->type_entry->id == TypeTableEntryIdInvalid)
74987658 return ira->codegen->builtin_types.entry_invalid;
74997659
7500 IrInstruction *casted_new_value = ir_get_casted_value(ira, new_value, child_type);
7660 IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, child_type);
75017661 if (casted_new_value->type_entry->id == TypeTableEntryIdInvalid)
75027662 return ira->codegen->builtin_types.entry_invalid;
75037663
......@@ -7567,11 +7727,11 @@ static TypeTableEntry *ir_analyze_instruction_div_exact(IrAnalyze *ira, IrInstru
75677727 return ira->codegen->builtin_types.entry_invalid;
75687728 }
75697729
7570 IrInstruction *casted_op1 = ir_get_casted_value(ira, op1, result_type);
7730 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, result_type);
75717731 if (casted_op1->type_entry->id == TypeTableEntryIdInvalid)
75727732 return ira->codegen->builtin_types.entry_invalid;
75737733
7574 IrInstruction *casted_op2 = ir_get_casted_value(ira, op2, result_type);
7734 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, result_type);
75757735 if (casted_op2->type_entry->id == TypeTableEntryIdInvalid)
75767736 return ira->codegen->builtin_types.entry_invalid;
75777737
......@@ -7690,7 +7850,7 @@ static TypeTableEntry *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstruc
76907850
76917851 TypeTableEntry *bool_type = ira->codegen->builtin_types.entry_bool;
76927852
7693 IrInstruction *casted_value = ir_get_casted_value(ira, value, bool_type);
7853 IrInstruction *casted_value = ir_implicit_cast(ira, value, bool_type);
76947854 if (casted_value->type_entry->id == TypeTableEntryIdInvalid)
76957855 return ira->codegen->builtin_types.entry_invalid;
76967856
......@@ -8265,89 +8425,6 @@ bool ir_has_side_effects(IrInstruction *instruction) {
82658425// return return_type;
82668426//}
82678427//
8268//static TypeTableEntry *analyze_array_mult(CodeGen *g, ImportTableEntry *import, BlockContext *context,
8269// TypeTableEntry *expected_type, AstNode *node)
8270//{
8271// assert(node->type == NodeTypeBinOpExpr);
8272// assert(node->data.bin_op_expr.bin_op == BinOpTypeArrayMult);
8273//
8274// AstNode **op1 = node->data.bin_op_expr.op1->parent_field;
8275// AstNode **op2 = node->data.bin_op_expr.op2->parent_field;
8276//
8277// TypeTableEntry *op1_type = analyze_expression(g, import, context, nullptr, *op1);
8278// TypeTableEntry *op2_type = analyze_expression(g, import, context, nullptr, *op2);
8279//
8280// if (op1_type->id == TypeTableEntryIdInvalid ||
8281// op2_type->id == TypeTableEntryIdInvalid)
8282// {
8283// return g->builtin_types.entry_invalid;
8284// }
8285//
8286// ConstExprValue *op1_val = &get_resolved_expr(*op1)->const_val;
8287// ConstExprValue *op2_val = &get_resolved_expr(*op2)->const_val;
8288//
8289// AstNode *bad_node;
8290// if (!op1_val->ok) {
8291// bad_node = *op1;
8292// } else if (!op2_val->ok) {
8293// bad_node = *op2;
8294// } else {
8295// bad_node = nullptr;
8296// }
8297// if (bad_node) {
8298// add_node_error(g, bad_node, buf_sprintf("array multiplication requires constant expression"));
8299// return g->builtin_types.entry_invalid;
8300// }
8301//
8302// if (op1_type->id != TypeTableEntryIdArray) {
8303// add_node_error(g, *op1,
8304// buf_sprintf("expected array type, found '%s'", buf_ptr(&op1_type->name)));
8305// return g->builtin_types.entry_invalid;
8306// }
8307//
8308// if (op2_type->id != TypeTableEntryIdNumLitInt &&
8309// op2_type->id != TypeTableEntryIdInt)
8310// {
8311// add_node_error(g, *op2, buf_sprintf("expected integer type, found '%s'", buf_ptr(&op2_type->name)));
8312// return g->builtin_types.entry_invalid;
8313// }
8314//
8315// if (op2_val->data.x_bignum.is_negative) {
8316// add_node_error(g, *op2, buf_sprintf("expected positive number"));
8317// return g->builtin_types.entry_invalid;
8318// }
8319//
8320// ConstExprValue *const_val = &get_resolved_expr(node)->const_val;
8321// const_val->ok = true;
8322// const_val->depends_on_compile_var = op1_val->depends_on_compile_var || op2_val->depends_on_compile_var;
8323//
8324// TypeTableEntry *child_type = op1_type->data.array.child_type;
8325// BigNum old_array_len;
8326// bignum_init_unsigned(&old_array_len, op1_type->data.array.len);
8327//
8328// BigNum new_array_len;
8329// if (bignum_mul(&new_array_len, &old_array_len, &op2_val->data.x_bignum)) {
8330// add_node_error(g, node, buf_sprintf("operation results in overflow"));
8331// return g->builtin_types.entry_invalid;
8332// }
8333//
8334// uint64_t old_array_len_bare = op1_type->data.array.len;
8335// uint64_t operand_amt = op2_val->data.x_bignum.data.x_uint;
8336//
8337// uint64_t new_array_len_bare = new_array_len.data.x_uint;
8338// const_val->data.x_array.fields = allocate<ConstExprValue*>(new_array_len_bare);
8339//
8340// uint64_t i = 0;
8341// for (uint64_t x = 0; x < operand_amt; x += 1) {
8342// for (uint64_t y = 0; y < old_array_len_bare; y += 1) {
8343// const_val->data.x_array.fields[i] = op1_val->data.x_array.fields[y];
8344// i += 1;
8345// }
8346// }
8347//
8348// return get_array_type(g, child_type, new_array_len_bare);
8349//}
8350//
83518428//static TypeTableEntry *analyze_unwrap_error_expr(CodeGen *g, ImportTableEntry *import,
83528429// BlockContext *parent_context, TypeTableEntry *expected_type, AstNode *node)
83538430//{