diff --git a/src/stage1/all_types.hpp b/src/stage1/all_types.hpp index 7ad585a524e0d5173b775956cac6140058c62fbb..5e1d4969dbf57f2e11f8ef16dd3839d2998e436c 100644 --- a/src/stage1/all_types.hpp +++ b/src/stage1/all_types.hpp @@ -2629,7 +2629,8 @@ enum IrInstSrcId { IrInstSrcIdResolveResult, IrInstSrcIdResetResult, IrInstSrcIdSetAlignStack, - IrInstSrcIdArgType, + IrInstSrcIdArgTypeAllowVarFalse, + IrInstSrcIdArgTypeAllowVarTrue, IrInstSrcIdExport, IrInstSrcIdExtern, IrInstSrcIdErrorReturnTrace, @@ -4144,7 +4145,6 @@ struct IrInstSrcArgType { IrInstSrc *fn_type; IrInstSrc *arg_index; - bool allow_var; }; struct IrInstSrcExport { diff --git a/src/stage1/ir.cpp b/src/stage1/ir.cpp index 7906df3b0d89c697889c61d74d166b041465a33b..c004e49e480c8db7981016db5f6f64eea13efdb8 100644 --- a/src/stage1/ir.cpp +++ b/src/stage1/ir.cpp @@ -514,7 +514,8 @@ static void destroy_instruction_src(IrInstSrc *inst) { return heap::c_allocator.destroy(reinterpret_cast(inst)); case IrInstSrcIdSetAlignStack: return heap::c_allocator.destroy(reinterpret_cast(inst)); - case IrInstSrcIdArgType: + case IrInstSrcIdArgTypeAllowVarFalse: + case IrInstSrcIdArgTypeAllowVarTrue: return heap::c_allocator.destroy(reinterpret_cast(inst)); case IrInstSrcIdExport: return heap::c_allocator.destroy(reinterpret_cast(inst)); @@ -1546,10 +1547,6 @@ static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetAlignStack *) { return IrInstSrcIdSetAlignStack; } -static constexpr IrInstSrcId ir_inst_id(IrInstSrcArgType *) { - return IrInstSrcIdArgType; -} - static constexpr IrInstSrcId ir_inst_id(IrInstSrcExport *) { return IrInstSrcIdExport; } @@ -4590,10 +4587,17 @@ static IrInstSrc *ir_build_set_align_stack(IrBuilderSrc *irb, Scope *scope, AstN static IrInstSrc *ir_build_arg_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *fn_type, IrInstSrc *arg_index, bool allow_var) { - IrInstSrcArgType *instruction = ir_build_instruction(irb, scope, source_node); + IrInstSrcArgType *instruction = heap::c_allocator.create(); + instruction->base.id = allow_var ? + IrInstSrcIdArgTypeAllowVarTrue : IrInstSrcIdArgTypeAllowVarFalse; + instruction->base.base.scope = scope; + instruction->base.base.source_node = source_node; + instruction->base.base.debug_id = exec_next_debug_id(irb->exec); + instruction->base.owner_bb = irb->current_basic_block; + ir_instruction_append(irb->current_basic_block, &instruction->base); + instruction->fn_type = fn_type; instruction->arg_index = arg_index; - instruction->allow_var = allow_var; ir_ref_instruction(fn_type, irb->current_basic_block); ir_ref_instruction(arg_index, irb->current_basic_block); @@ -30976,7 +30980,9 @@ static IrInstGen *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, IrInstS return ir_const_void(ira, &instruction->base.base); } -static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgType *instruction) { +static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgType *instruction, + bool allow_var) +{ IrInstGen *fn_type_inst = instruction->fn_type->child; ZigType *fn_type = ir_resolve_type(ira, fn_type_inst); if (type_is_invalid(fn_type)) @@ -30998,7 +31004,7 @@ static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgTy FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id; if (arg_index >= fn_type_id->param_count) { - if (instruction->allow_var) { + if (allow_var) { // TODO remove this with var args return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_anytype); } @@ -31013,7 +31019,7 @@ static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgTy // Args are only unresolved if our function is generic. ir_assert(fn_type->data.fn.is_generic, &instruction->base.base); - if (instruction->allow_var) { + if (allow_var) { return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_anytype); } else { ir_add_error(ira, &arg_index_inst->base, @@ -32383,8 +32389,10 @@ static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruc return ir_analyze_instruction_reset_result(ira, (IrInstSrcResetResult *)instruction); case IrInstSrcIdSetAlignStack: return ir_analyze_instruction_set_align_stack(ira, (IrInstSrcSetAlignStack *)instruction); - case IrInstSrcIdArgType: - return ir_analyze_instruction_arg_type(ira, (IrInstSrcArgType *)instruction); + case IrInstSrcIdArgTypeAllowVarFalse: + return ir_analyze_instruction_arg_type(ira, (IrInstSrcArgType *)instruction, false); + case IrInstSrcIdArgTypeAllowVarTrue: + return ir_analyze_instruction_arg_type(ira, (IrInstSrcArgType *)instruction, true); case IrInstSrcIdExport: return ir_analyze_instruction_export(ira, (IrInstSrcExport *)instruction); case IrInstSrcIdExtern: @@ -32826,7 +32834,8 @@ bool ir_inst_src_has_side_effects(IrInstSrc *instruction) { case IrInstSrcIdAlignCast: case IrInstSrcIdImplicitCast: case IrInstSrcIdResolveResult: - case IrInstSrcIdArgType: + case IrInstSrcIdArgTypeAllowVarFalse: + case IrInstSrcIdArgTypeAllowVarTrue: case IrInstSrcIdErrorReturnTrace: case IrInstSrcIdErrorUnion: case IrInstSrcIdFloatOp: diff --git a/src/stage1/ir_print.cpp b/src/stage1/ir_print.cpp index 98d349012eaa408663277f9a326da5a06011b816..6750b6178cb5fcc8a629ab3230f5699b89dd012a 100644 --- a/src/stage1/ir_print.cpp +++ b/src/stage1/ir_print.cpp @@ -308,8 +308,10 @@ const char* ir_inst_src_type_str(IrInstSrcId id) { return "SrcResetResult"; case IrInstSrcIdSetAlignStack: return "SrcSetAlignStack"; - case IrInstSrcIdArgType: - return "SrcArgType"; + case IrInstSrcIdArgTypeAllowVarFalse: + return "SrcArgTypeAllowVarFalse"; + case IrInstSrcIdArgTypeAllowVarTrue: + return "SrcArgTypeAllowVarTrue"; case IrInstSrcIdExport: return "SrcExport"; case IrInstSrcIdExtern: @@ -2344,11 +2346,17 @@ static void ir_print_set_align_stack(IrPrintSrc *irp, IrInstSrcSetAlignStack *in fprintf(irp->f, ")"); } -static void ir_print_arg_type(IrPrintSrc *irp, IrInstSrcArgType *instruction) { +static void ir_print_arg_type(IrPrintSrc *irp, IrInstSrcArgType *instruction, bool allow_var) { fprintf(irp->f, "@ArgType("); ir_print_other_inst_src(irp, instruction->fn_type); fprintf(irp->f, ","); ir_print_other_inst_src(irp, instruction->arg_index); + fprintf(irp->f, ","); + if (allow_var) { + fprintf(irp->f, "allow_var=true"); + } else { + fprintf(irp->f, "allow_var=false"); + } fprintf(irp->f, ")"); } @@ -2942,8 +2950,11 @@ static void ir_print_inst_src(IrPrintSrc *irp, IrInstSrc *instruction, bool trai case IrInstSrcIdSetAlignStack: ir_print_set_align_stack(irp, (IrInstSrcSetAlignStack *)instruction); break; - case IrInstSrcIdArgType: - ir_print_arg_type(irp, (IrInstSrcArgType *)instruction); + case IrInstSrcIdArgTypeAllowVarFalse: + ir_print_arg_type(irp, (IrInstSrcArgType *)instruction, false); + break; + case IrInstSrcIdArgTypeAllowVarTrue: + ir_print_arg_type(irp, (IrInstSrcArgType *)instruction, true); break; case IrInstSrcIdExport: ir_print_export(irp, (IrInstSrcExport *)instruction);