authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-13 01:48:40-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-13 01:48:40-05:00
loga6d2bdf6050642762cc7bc193bca34690f712d49
tree10db99199b91f09b0eb908013f96e35a6a5eceae
parent76a849b1f2c1bb57de4baf8dfd49fe9f9e2340f3

IR: implement breakpoint builtin


4 files changed, 44 insertions(+), 6 deletions(-)

src/all_types.hpp+5
...@@ -1419,6 +1419,7 @@ enum IrInstructionId {...@@ -1419,6 +1419,7 @@ enum IrInstructionId {
1419 IrInstructionIdMemcpy,1419 IrInstructionIdMemcpy,
1420 IrInstructionIdSlice,1420 IrInstructionIdSlice,
1421 IrInstructionIdMemberCount,1421 IrInstructionIdMemberCount,
1422 IrInstructionIdBreakpoint,
1422};1423};
14231424
1424struct IrInstruction {1425struct IrInstruction {
...@@ -1960,6 +1961,10 @@ struct IrInstructionMemberCount {...@@ -1960,6 +1961,10 @@ struct IrInstructionMemberCount {
1960 IrInstruction *container;1961 IrInstruction *container;
1961};1962};
19621963
1964struct IrInstructionBreakpoint {
1965 IrInstruction base;
1966};
1967
1963enum LValPurpose {1968enum LValPurpose {
1964 LValPurposeNone,1969 LValPurposeNone,
1965 LValPurposeAssign,1970 LValPurposeAssign,
src/codegen.cpp+7
...@@ -2053,6 +2053,11 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst...@@ -2053,6 +2053,11 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst
2053 }2053 }
2054}2054}
20552055
2056static LLVMValueRef ir_render_breakpoint(CodeGen *g, IrExecutable *executable, IrInstructionBreakpoint *instruction) {
2057 LLVMBuildCall(g->builder, g->trap_fn_val, nullptr, 0, "");
2058 return nullptr;
2059}
2060
2056static void set_debug_location(CodeGen *g, IrInstruction *instruction) {2061static void set_debug_location(CodeGen *g, IrInstruction *instruction) {
2057 AstNode *source_node = instruction->source_node;2062 AstNode *source_node = instruction->source_node;
2058 Scope *scope = instruction->scope;2063 Scope *scope = instruction->scope;
...@@ -2162,6 +2167,8 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,...@@ -2162,6 +2167,8 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
2162 return ir_render_memcpy(g, executable, (IrInstructionMemcpy *)instruction);2167 return ir_render_memcpy(g, executable, (IrInstructionMemcpy *)instruction);
2163 case IrInstructionIdSlice:2168 case IrInstructionIdSlice:
2164 return ir_render_slice(g, executable, (IrInstructionSlice *)instruction);2169 return ir_render_slice(g, executable, (IrInstructionSlice *)instruction);
2170 case IrInstructionIdBreakpoint:
2171 return ir_render_breakpoint(g, executable, (IrInstructionBreakpoint *)instruction);
2165 case IrInstructionIdSwitchVar:2172 case IrInstructionIdSwitchVar:
2166 case IrInstructionIdContainerInitList:2173 case IrInstructionIdContainerInitList:
2167 case IrInstructionIdStructInit:2174 case IrInstructionIdStructInit:
src/ir.cpp+25-6
...@@ -391,6 +391,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionMemberCount *) {...@@ -391,6 +391,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionMemberCount *) {
391 return IrInstructionIdMemberCount;391 return IrInstructionIdMemberCount;
392}392}
393393
394static constexpr IrInstructionId ir_instruction_id(IrInstructionBreakpoint *) {
395 return IrInstructionIdBreakpoint;
396}
397
394template<typename T>398template<typename T>
395static T *ir_create_instruction(IrExecutable *exec, Scope *scope, AstNode *source_node) {399static T *ir_create_instruction(IrExecutable *exec, Scope *scope, AstNode *source_node) {
396 T *special_instruction = allocate<T>(1);400 T *special_instruction = allocate<T>(1);
...@@ -1609,6 +1613,17 @@ static IrInstruction *ir_build_member_count(IrBuilder *irb, Scope *scope, AstNod...@@ -1609,6 +1613,17 @@ static IrInstruction *ir_build_member_count(IrBuilder *irb, Scope *scope, AstNod
1609 return &instruction->base;1613 return &instruction->base;
1610}1614}
16111615
1616static IrInstruction *ir_build_breakpoint(IrBuilder *irb, Scope *scope, AstNode *source_node) {
1617 IrInstructionBreakpoint *instruction = ir_build_instruction<IrInstructionBreakpoint>(irb, scope, source_node);
1618 return &instruction->base;
1619}
1620
1621static IrInstruction *ir_build_breakpoint_from(IrBuilder *irb, IrInstruction *old_instruction) {
1622 IrInstruction *new_instruction = ir_build_breakpoint(irb, old_instruction->scope, old_instruction->source_node);
1623 ir_link_new_instruction(new_instruction, old_instruction);
1624 return new_instruction;
1625}
1626
1612static void ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope,1627static void ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope,
1613 bool gen_error_defers, bool gen_maybe_defers)1628 bool gen_error_defers, bool gen_maybe_defers)
1614{1629{
...@@ -2491,12 +2506,13 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -2491,12 +2506,13 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
24912506
2492 return ir_build_member_count(irb, scope, node, arg0_value);2507 return ir_build_member_count(irb, scope, node, arg0_value);
2493 }2508 }
2509 case BuiltinFnIdBreakpoint:
2510 return ir_build_breakpoint(irb, scope, node);
2494 case BuiltinFnIdAlignof:2511 case BuiltinFnIdAlignof:
2495 case BuiltinFnIdAddWithOverflow:2512 case BuiltinFnIdAddWithOverflow:
2496 case BuiltinFnIdSubWithOverflow:2513 case BuiltinFnIdSubWithOverflow:
2497 case BuiltinFnIdMulWithOverflow:2514 case BuiltinFnIdMulWithOverflow:
2498 case BuiltinFnIdShlWithOverflow:2515 case BuiltinFnIdShlWithOverflow:
2499 case BuiltinFnIdBreakpoint:
2500 case BuiltinFnIdReturnAddress:2516 case BuiltinFnIdReturnAddress:
2501 case BuiltinFnIdFrameAddress:2517 case BuiltinFnIdFrameAddress:
2502 zig_panic("TODO IR gen more builtin functions");2518 zig_panic("TODO IR gen more builtin functions");
...@@ -8456,6 +8472,11 @@ static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrIns...@@ -8456,6 +8472,11 @@ static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrIns
8456 return ira->codegen->builtin_types.entry_num_lit_int;8472 return ira->codegen->builtin_types.entry_num_lit_int;
8457}8473}
84588474
8475static TypeTableEntry *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstructionBreakpoint *instruction) {
8476 ir_build_breakpoint_from(&ira->new_irb, &instruction->base);
8477 return ira->codegen->builtin_types.entry_void;
8478}
8479
8459static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstruction *instruction) {8480static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstruction *instruction) {
8460 switch (instruction->id) {8481 switch (instruction->id) {
8461 case IrInstructionIdInvalid:8482 case IrInstructionIdInvalid:
...@@ -8580,6 +8601,8 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi...@@ -8580,6 +8601,8 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi
8580 return ir_analyze_instruction_slice(ira, (IrInstructionSlice *)instruction);8601 return ir_analyze_instruction_slice(ira, (IrInstructionSlice *)instruction);
8581 case IrInstructionIdMemberCount:8602 case IrInstructionIdMemberCount:
8582 return ir_analyze_instruction_member_count(ira, (IrInstructionMemberCount *)instruction);8603 return ir_analyze_instruction_member_count(ira, (IrInstructionMemberCount *)instruction);
8604 case IrInstructionIdBreakpoint:
8605 return ir_analyze_instruction_breakpoint(ira, (IrInstructionBreakpoint *)instruction);
8583 case IrInstructionIdCast:8606 case IrInstructionIdCast:
8584 case IrInstructionIdStructFieldPtr:8607 case IrInstructionIdStructFieldPtr:
8585 case IrInstructionIdEnumFieldPtr:8608 case IrInstructionIdEnumFieldPtr:
...@@ -8683,6 +8706,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {...@@ -8683,6 +8706,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {
8683 case IrInstructionIdFence:8706 case IrInstructionIdFence:
8684 case IrInstructionIdMemset:8707 case IrInstructionIdMemset:
8685 case IrInstructionIdMemcpy:8708 case IrInstructionIdMemcpy:
8709 case IrInstructionIdBreakpoint:
8686 return true;8710 return true;
8687 case IrInstructionIdPhi:8711 case IrInstructionIdPhi:
8688 case IrInstructionIdUnOp:8712 case IrInstructionIdUnOp:
...@@ -8787,9 +8811,6 @@ bool ir_has_side_effects(IrInstruction *instruction) {...@@ -8787,9 +8811,6 @@ bool ir_has_side_effects(IrInstruction *instruction) {
8787// align_in_bytes, false);8811// align_in_bytes, false);
8788// }8812// }
8789// }8813// }
8790// case BuiltinFnIdBreakpoint:
8791// mark_impure_fn(g, context, node);
8792// return g->builtin_types.entry_void;
8793// case BuiltinFnIdReturnAddress:8814// case BuiltinFnIdReturnAddress:
8794// case BuiltinFnIdFrameAddress:8815// case BuiltinFnIdFrameAddress:
8795// mark_impure_fn(g, context, node);8816// mark_impure_fn(g, context, node);
...@@ -9035,8 +9056,6 @@ bool ir_has_side_effects(IrInstruction *instruction) {...@@ -9035,8 +9056,6 @@ bool ir_has_side_effects(IrInstruction *instruction) {
9035// zig_unreachable();9056// zig_unreachable();
9036// case BuiltinFnIdCompileVar:9057// case BuiltinFnIdCompileVar:
9037// return nullptr;9058// return nullptr;
9038// case BuiltinFnIdBreakpoint:
9039// return LLVMBuildCall(g->builder, g->trap_fn_val, nullptr, 0, "");
9040// case BuiltinFnIdFrameAddress:9059// case BuiltinFnIdFrameAddress:
9041// case BuiltinFnIdReturnAddress:9060// case BuiltinFnIdReturnAddress:
9042// {9061// {
src/ir_print.cpp+7
...@@ -812,6 +812,10 @@ static void ir_print_member_count(IrPrint *irp, IrInstructionMemberCount *instru...@@ -812,6 +812,10 @@ static void ir_print_member_count(IrPrint *irp, IrInstructionMemberCount *instru
812 fprintf(irp->f, ")");812 fprintf(irp->f, ")");
813}813}
814814
815static void ir_print_breakpoint(IrPrint *irp, IrInstructionBreakpoint *instruction) {
816 fprintf(irp->f, "@breakpoint()");
817}
818
815static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {819static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
816 ir_print_prefix(irp, instruction);820 ir_print_prefix(irp, instruction);
817 switch (instruction->id) {821 switch (instruction->id) {
...@@ -1009,6 +1013,9 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {...@@ -1009,6 +1013,9 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
1009 case IrInstructionIdMemberCount:1013 case IrInstructionIdMemberCount:
1010 ir_print_member_count(irp, (IrInstructionMemberCount *)instruction);1014 ir_print_member_count(irp, (IrInstructionMemberCount *)instruction);
1011 break;1015 break;
1016 case IrInstructionIdBreakpoint:
1017 ir_print_breakpoint(irp, (IrInstructionBreakpoint *)instruction);
1018 break;
1012 }1019 }
1013 fprintf(irp->f, "\n");1020 fprintf(irp->f, "\n");
1014}1021}