authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-22 09:30:55-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-22 09:30:55-05:00
log37c07d4f3f52f2227e86943cf84aebdc729684b7
tree1f9d5d931ca6afffa1670f18a73e124a4927506f
parentb261da067248c4003b0008f6aaeefde43290a061

coroutines: analyze get_implicit_allocator instruction

see #727

2 files changed, 19 insertions(+), 5 deletions(-)

src/ir.cpp+17-5
......@@ -5884,7 +5884,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
58845884 IrInstruction **incoming_values = allocate<IrInstruction *>(2);
58855885 incoming_blocks[0] = entry_block;
58865886 incoming_values[0] = null_ptr;
5887 incoming_blocks[1] = dyn_alloc_block;
5887 incoming_blocks[1] = alloc_ok_block;
58885888 incoming_values[1] = coro_mem_ptr;
58895889 IrInstruction *coro_mem = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values);
58905890 irb->exec->coro_handle = ir_build_coro_begin(irb, scope, node, coro_id, coro_mem);
......@@ -10897,7 +10897,13 @@ static TypeTableEntry *ir_analyze_instruction_error_union(IrAnalyze *ira,
1089710897 return ira->codegen->builtin_types.entry_type;
1089810898}
1089910899
10900IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_instr, FnTableEntry *parent_fn_entry) {
10900IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_instr) {
10901 FnTableEntry *parent_fn_entry = exec_fn_entry(ira->new_irb.exec);
10902 if (parent_fn_entry == nullptr) {
10903 ir_add_error(ira, source_instr, buf_sprintf("no implicit allocator available"));
10904 return ira->codegen->invalid_instruction;
10905 }
10906
1090110907 FnTypeId *parent_fn_type = &parent_fn_entry->type_entry->data.fn.fn_type_id;
1090210908 if (parent_fn_type->cc != CallingConventionAsync) {
1090310909 ir_add_error(ira, source_instr, buf_sprintf("async function call from non-async caller requires allocator parameter"));
......@@ -11467,7 +11473,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1146711473 }
1146811474 IrInstruction *uncasted_async_allocator_inst;
1146911475 if (call_instruction->async_allocator == nullptr) {
11470 uncasted_async_allocator_inst = ir_get_implicit_allocator(ira, &call_instruction->base, parent_fn_entry);
11476 uncasted_async_allocator_inst = ir_get_implicit_allocator(ira, &call_instruction->base);
1147111477 if (type_is_invalid(uncasted_async_allocator_inst->value.type))
1147211478 return ira->codegen->builtin_types.entry_invalid;
1147311479 } else {
......@@ -11586,7 +11592,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1158611592 if (call_instruction->is_async) {
1158711593 IrInstruction *uncasted_async_allocator_inst;
1158811594 if (call_instruction->async_allocator == nullptr) {
11589 uncasted_async_allocator_inst = ir_get_implicit_allocator(ira, &call_instruction->base, parent_fn_entry);
11595 uncasted_async_allocator_inst = ir_get_implicit_allocator(ira, &call_instruction->base);
1159011596 if (type_is_invalid(uncasted_async_allocator_inst->value.type))
1159111597 return ira->codegen->builtin_types.entry_invalid;
1159211598 } else {
......@@ -16816,6 +16822,11 @@ static TypeTableEntry *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstr
1681616822 zig_panic("TODO ir_analyze_instruction_coro_begin");
1681716823}
1681816824
16825static TypeTableEntry *ir_analyze_instruction_get_implicit_allocator(IrAnalyze *ira, IrInstructionGetImplicitAllocator *instruction) {
16826 IrInstruction *result = ir_get_implicit_allocator(ira, &instruction->base);
16827 return result->value.type;
16828}
16829
1681916830static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstruction *instruction) {
1682016831 switch (instruction->id) {
1682116832 case IrInstructionIdInvalid:
......@@ -16831,7 +16842,6 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi
1683116842 case IrInstructionIdErrWrapCode:
1683216843 case IrInstructionIdErrWrapPayload:
1683316844 case IrInstructionIdCast:
16834 case IrInstructionIdGetImplicitAllocator:
1683516845 zig_unreachable();
1683616846 case IrInstructionIdReturn:
1683716847 return ir_analyze_instruction_return(ira, (IrInstructionReturn *)instruction);
......@@ -17029,6 +17039,8 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi
1702917039 return ir_analyze_instruction_coro_size(ira, (IrInstructionCoroSize *)instruction);
1703017040 case IrInstructionIdCoroBegin:
1703117041 return ir_analyze_instruction_coro_begin(ira, (IrInstructionCoroBegin *)instruction);
17042 case IrInstructionIdGetImplicitAllocator:
17043 return ir_analyze_instruction_get_implicit_allocator(ira, (IrInstructionGetImplicitAllocator *)instruction);
1703217044 }
1703317045 zig_unreachable();
1703417046}
src/ir_print.cpp+2
......@@ -839,6 +839,8 @@ static void ir_print_ptr_to_int(IrPrint *irp, IrInstructionPtrToInt *instruction
839839
840840static void ir_print_int_to_ptr(IrPrint *irp, IrInstructionIntToPtr *instruction) {
841841 fprintf(irp->f, "@intToPtr(");
842 ir_print_other_instruction(irp, instruction->dest_type);
843 fprintf(irp->f, ",");
842844 ir_print_other_instruction(irp, instruction->target);
843845 fprintf(irp->f, ")");
844846}