rewrite parseh to use AST instead of direct types

some tests still failing
This commit is contained in:
Andrew Kelley
2017-09-02 04:11:23 -04:00
parent 0f38955ee5
commit e1d5da20a5
11 changed files with 744 additions and 1186 deletions

View File

@@ -6114,9 +6114,14 @@ static IrInstruction *ir_gen_fn_proto(IrBuilder *irb, Scope *parent_scope, AstNo
return irb->codegen->invalid_instruction;
}
IrInstruction *return_type = ir_gen_node(irb, node->data.fn_proto.return_type, parent_scope);
if (return_type == irb->codegen->invalid_instruction)
return irb->codegen->invalid_instruction;
IrInstruction *return_type;
if (node->data.fn_proto.return_type == nullptr) {
return_type = ir_build_const_void(irb, parent_scope, node);
} else {
return_type = ir_gen_node(irb, node->data.fn_proto.return_type, parent_scope);
if (return_type == irb->codegen->invalid_instruction)
return irb->codegen->invalid_instruction;
}
return ir_build_fn_proto(irb, parent_scope, node, param_types, align_value, return_type, is_var_args);
}
@@ -13358,9 +13363,11 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc
if (ira->codegen->verbose) {
fprintf(stderr, "\nC imports:\n");
fprintf(stderr, "-----------\n");
ast_render_decls(ira->codegen, stderr, 4, child_import);
ast_render(ira->codegen, stderr, child_import->root, 4);
}
scan_decls(ira->codegen, child_import->decls_scope, child_import->root);
ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
out_val->data.x_import = child_import;
return ira->codegen->builtin_types.entry_namespace;
@@ -15515,65 +15522,3 @@ bool ir_has_side_effects(IrInstruction *instruction) {
}
zig_unreachable();
}
FnTableEntry *ir_create_inline_fn(CodeGen *codegen, Buf *fn_name, VariableTableEntry *var, Scope *parent_scope) {
FnTableEntry *fn_entry = create_fn_raw(FnInlineAuto, GlobalLinkageIdInternal);
buf_init_from_buf(&fn_entry->symbol_name, fn_name);
fn_entry->fndef_scope = create_fndef_scope(nullptr, parent_scope, fn_entry);
fn_entry->child_scope = &fn_entry->fndef_scope->base;
assert(var->value->type->id == TypeTableEntryIdMaybe);
TypeTableEntry *src_fn_type = var->value->type->data.maybe.child_type;
assert(src_fn_type->id == TypeTableEntryIdFn);
FnTypeId new_fn_type = src_fn_type->data.fn.fn_type_id;
new_fn_type.cc = CallingConventionUnspecified;
fn_entry->type_entry = get_fn_type(codegen, &new_fn_type);
IrBuilder ir_builder = {0};
IrBuilder *irb = &ir_builder;
irb->codegen = codegen;
irb->exec = &fn_entry->ir_executable;
AstNode *source_node = parent_scope->source_node;
size_t arg_count = fn_entry->type_entry->data.fn.fn_type_id.param_count;
IrInstruction **args = allocate<IrInstruction *>(arg_count);
VariableTableEntry **arg_vars = allocate<VariableTableEntry *>(arg_count);
define_local_param_variables(codegen, fn_entry, arg_vars);
Scope *scope = fn_entry->child_scope;
irb->current_basic_block = ir_build_basic_block(irb, scope, "Entry");
// Entry block gets a reference because we enter it to begin.
ir_ref_bb(irb->current_basic_block);
IrInstruction *maybe_fn_ptr = ir_build_var_ptr(irb, scope, source_node, var, true, false);
IrInstruction *unwrapped_fn_ptr = ir_build_unwrap_maybe(irb, scope, source_node, maybe_fn_ptr, true);
IrInstruction *fn_ref_instruction = ir_build_load_ptr(irb, scope, source_node, unwrapped_fn_ptr);
for (size_t i = 0; i < arg_count; i += 1) {
IrInstruction *var_ptr_instruction = ir_build_var_ptr(irb, scope, source_node, arg_vars[i], true, false);
args[i] = ir_build_load_ptr(irb, scope, source_node, var_ptr_instruction);
}
IrInstruction *call_instruction = ir_build_call(irb, scope, source_node, nullptr, fn_ref_instruction,
arg_count, args, false, false);
ir_build_return(irb, scope, source_node, call_instruction);
if (codegen->verbose) {
fprintf(stderr, "{\n");
ir_print(codegen, stderr, &fn_entry->ir_executable, 4);
fprintf(stderr, "}\n");
}
analyze_fn_ir(codegen, fn_entry, nullptr);
codegen->fn_defs.append(fn_entry);
return fn_entry;
}