| ... | ... | @@ -314,6 +314,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionMaxValue *) { |
| 314 | 314 | return IrInstructionIdMaxValue; |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | static constexpr IrInstructionId ir_instruction_id(IrInstructionCompileErr *) { |
| 318 | return IrInstructionIdCompileErr; |
| 319 | } |
| 320 | |
| 317 | 321 | template<typename T> |
| 318 | 322 | static T *ir_create_instruction(IrExecutable *exec, Scope *scope, AstNode *source_node) { |
| 319 | 323 | T *special_instruction = allocate<T>(1); |
| ... | ... | @@ -1267,6 +1271,15 @@ static IrInstruction *ir_build_max_value(IrBuilder *irb, Scope *scope, AstNode * |
| 1267 | 1271 | return &instruction->base; |
| 1268 | 1272 | } |
| 1269 | 1273 | |
| 1274 | static IrInstruction *ir_build_compile_err(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *msg) { |
| 1275 | IrInstructionCompileErr *instruction = ir_build_instruction<IrInstructionCompileErr>(irb, scope, source_node); |
| 1276 | instruction->msg = msg; |
| 1277 | |
| 1278 | ir_ref_instruction(msg); |
| 1279 | |
| 1280 | return &instruction->base; |
| 1281 | } |
| 1282 | |
| 1270 | 1283 | |
| 1271 | 1284 | static void ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope, |
| 1272 | 1285 | bool gen_error_defers, bool gen_maybe_defers) |
| ... | ... | @@ -1924,6 +1937,15 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 1924 | 1937 | |
| 1925 | 1938 | return ir_build_min_value(irb, scope, node, arg0_value); |
| 1926 | 1939 | } |
| 1940 | case BuiltinFnIdCompileErr: |
| 1941 | { |
| 1942 | AstNode *arg0_node = node->data.fn_call_expr.params.at(0); |
| 1943 | IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope); |
| 1944 | if (arg0_value == irb->codegen->invalid_instruction) |
| 1945 | return arg0_value; |
| 1946 | |
| 1947 | return ir_build_compile_err(irb, scope, node, arg0_value); |
| 1948 | } |
| 1927 | 1949 | case BuiltinFnIdMemcpy: |
| 1928 | 1950 | case BuiltinFnIdMemset: |
| 1929 | 1951 | case BuiltinFnIdAlignof: |
| ... | ... | @@ -1935,7 +1957,6 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 1935 | 1957 | case BuiltinFnIdCInclude: |
| 1936 | 1958 | case BuiltinFnIdCDefine: |
| 1937 | 1959 | case BuiltinFnIdCUndef: |
| 1938 | | case BuiltinFnIdCompileErr: |
| 1939 | 1960 | case BuiltinFnIdCImport: |
| 1940 | 1961 | case BuiltinFnIdErrName: |
| 1941 | 1962 | case BuiltinFnIdBreakpoint: |
| ... | ... | @@ -1947,7 +1968,6 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 1947 | 1968 | case BuiltinFnIdDivExact: |
| 1948 | 1969 | case BuiltinFnIdTruncate: |
| 1949 | 1970 | case BuiltinFnIdIntType: |
| 1950 | | case BuiltinFnIdSetFnNoInline: |
| 1951 | 1971 | zig_panic("TODO IR gen more builtin functions"); |
| 1952 | 1972 | } |
| 1953 | 1973 | zig_unreachable(); |
| ... | ... | @@ -6782,6 +6802,18 @@ static TypeTableEntry *ir_analyze_instruction_max_value(IrAnalyze *ira, |
| 6782 | 6802 | return ir_analyze_min_max(ira, &instruction->base, instruction->value->other, true); |
| 6783 | 6803 | } |
| 6784 | 6804 | |
| 6805 | static TypeTableEntry *ir_analyze_instruction_compile_err(IrAnalyze *ira, |
| 6806 | IrInstructionCompileErr *instruction) |
| 6807 | { |
| 6808 | IrInstruction *msg_value = instruction->msg->other; |
| 6809 | Buf *msg_buf = ir_resolve_str(ira, msg_value); |
| 6810 | if (!msg_buf) |
| 6811 | return ira->codegen->builtin_types.entry_invalid; |
| 6812 | |
| 6813 | ir_add_error(ira, &instruction->base, msg_buf); |
| 6814 | return ira->codegen->builtin_types.entry_invalid; |
| 6815 | } |
| 6816 | |
| 6785 | 6817 | static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstruction *instruction) { |
| 6786 | 6818 | switch (instruction->id) { |
| 6787 | 6819 | case IrInstructionIdInvalid: |
| ... | ... | @@ -6870,6 +6902,8 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi |
| 6870 | 6902 | return ir_analyze_instruction_min_value(ira, (IrInstructionMinValue *)instruction); |
| 6871 | 6903 | case IrInstructionIdMaxValue: |
| 6872 | 6904 | return ir_analyze_instruction_max_value(ira, (IrInstructionMaxValue *)instruction); |
| 6905 | case IrInstructionIdCompileErr: |
| 6906 | return ir_analyze_instruction_compile_err(ira, (IrInstructionCompileErr *)instruction); |
| 6873 | 6907 | case IrInstructionIdCast: |
| 6874 | 6908 | case IrInstructionIdStructFieldPtr: |
| 6875 | 6909 | case IrInstructionIdEnumFieldPtr: |
| ... | ... | @@ -6964,6 +6998,7 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 6964 | 6998 | case IrInstructionIdSetFnVisible: |
| 6965 | 6999 | case IrInstructionIdSetDebugSafety: |
| 6966 | 7000 | case IrInstructionIdImport: |
| 7001 | case IrInstructionIdCompileErr: |
| 6967 | 7002 | return true; |
| 6968 | 7003 | case IrInstructionIdPhi: |
| 6969 | 7004 | case IrInstructionIdUnOp: |
| ... | ... | @@ -7291,20 +7326,6 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 7291 | 7326 | // return dest_type; |
| 7292 | 7327 | //} |
| 7293 | 7328 | // |
| 7294 | | //static TypeTableEntry *analyze_compile_err(CodeGen *g, ImportTableEntry *import, |
| 7295 | | // BlockContext *context, AstNode *node) |
| 7296 | | //{ |
| 7297 | | // AstNode *first_param_node = node->data.fn_call_expr.params.at(0); |
| 7298 | | // Buf *err_msg = resolve_const_expr_str(g, import, context, first_param_node->parent_field); |
| 7299 | | // if (!err_msg) { |
| 7300 | | // return g->builtin_types.entry_invalid; |
| 7301 | | // } |
| 7302 | | // |
| 7303 | | // add_node_error(g, node, err_msg); |
| 7304 | | // |
| 7305 | | // return g->builtin_types.entry_invalid; |
| 7306 | | //} |
| 7307 | | // |
| 7308 | 7329 | //static TypeTableEntry *analyze_int_type(CodeGen *g, ImportTableEntry *import, |
| 7309 | 7330 | // BlockContext *context, AstNode *node) |
| 7310 | 7331 | //{ |
| ... | ... | @@ -7344,41 +7365,6 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 7344 | 7365 | // |
| 7345 | 7366 | //} |
| 7346 | 7367 | // |
| 7347 | | //static TypeTableEntry *analyze_set_fn_no_inline(CodeGen *g, ImportTableEntry *import, |
| 7348 | | // BlockContext *context, AstNode *node) |
| 7349 | | //{ |
| 7350 | | // AstNode **fn_node = &node->data.fn_call_expr.params.at(0); |
| 7351 | | // AstNode **value_node = &node->data.fn_call_expr.params.at(1); |
| 7352 | | // |
| 7353 | | // FnTableEntry *fn_entry = resolve_const_expr_fn(g, import, context, fn_node); |
| 7354 | | // if (!fn_entry) { |
| 7355 | | // return g->builtin_types.entry_invalid; |
| 7356 | | // } |
| 7357 | | // |
| 7358 | | // bool is_noinline; |
| 7359 | | // bool ok = resolve_const_expr_bool(g, import, context, value_node, &is_noinline); |
| 7360 | | // if (!ok) { |
| 7361 | | // return g->builtin_types.entry_invalid; |
| 7362 | | // } |
| 7363 | | // |
| 7364 | | // if (fn_entry->fn_no_inline_set_node) { |
| 7365 | | // ErrorMsg *msg = add_node_error(g, node, buf_sprintf("function no inline attribute set twice")); |
| 7366 | | // add_error_note(g, msg, fn_entry->fn_no_inline_set_node, buf_sprintf("first set here")); |
| 7367 | | // return g->builtin_types.entry_invalid; |
| 7368 | | // } |
| 7369 | | // fn_entry->fn_no_inline_set_node = node; |
| 7370 | | // |
| 7371 | | // if (fn_entry->fn_inline == FnInlineAlways) { |
| 7372 | | // add_node_error(g, node, buf_sprintf("function is both inline and noinline")); |
| 7373 | | // fn_entry->proto_node->data.fn_proto.skip = true; |
| 7374 | | // return g->builtin_types.entry_invalid; |
| 7375 | | // } else if (is_noinline) { |
| 7376 | | // fn_entry->fn_inline = FnInlineNever; |
| 7377 | | // } |
| 7378 | | // |
| 7379 | | // return g->builtin_types.entry_void; |
| 7380 | | //} |
| 7381 | | // |
| 7382 | 7368 | //static TypeTableEntry *analyze_builtin_fn_call_expr(CodeGen *g, ImportTableEntry *import, BlockContext *context, |
| 7383 | 7369 | // TypeTableEntry *expected_type, AstNode *node) |
| 7384 | 7370 | //{ |
| ... | ... | @@ -7566,8 +7552,6 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 7566 | 7552 | // return analyze_div_exact(g, import, context, node); |
| 7567 | 7553 | // case BuiltinFnIdTruncate: |
| 7568 | 7554 | // return analyze_truncate(g, import, context, node); |
| 7569 | | // case BuiltinFnIdCompileErr: |
| 7570 | | // return analyze_compile_err(g, import, context, node); |
| 7571 | 7555 | // case BuiltinFnIdIntType: |
| 7572 | 7556 | // return analyze_int_type(g, import, context, node); |
| 7573 | 7557 | // case BuiltinFnIdSetFnTest: |