WIP moving all analysis to IR

This commit is contained in:
Andrew Kelley 2016-11-04 15:36:30 -04:00
parent bc6c33b1b6
commit a2e3293930
8 changed files with 3439 additions and 4104 deletions

View File

@ -738,8 +738,6 @@ struct AstNodeSymbolExpr {
// populated by semantic analyzer
Expr resolved_expr;
// set this to instead of analyzing the node, pretend it's a type entry and it's this one.
TypeTableEntry *override_type_entry;
TypeEnumField *enum_field;
uint32_t err_value;
};
@ -1439,7 +1437,6 @@ enum IrInstructionId {
IrInstructionIdElemPtr,
IrInstructionIdVarPtr,
IrInstructionIdCall,
IrInstructionIdBuiltinCall,
IrInstructionIdConst,
IrInstructionIdReturn,
IrInstructionIdCast,
@ -1449,6 +1446,7 @@ enum IrInstructionId {
IrInstructionIdTypeOf,
IrInstructionIdToPtrType,
IrInstructionIdPtrTypeChild,
IrInstructionIdSetFnTest,
};
struct IrInstruction {
@ -1630,13 +1628,6 @@ struct IrInstructionCall {
IrInstruction **args;
};
struct IrInstructionBuiltinCall {
IrInstruction base;
BuiltinFnEntry *fn;
IrInstruction **args;
};
struct IrInstructionConst {
IrInstruction base;
};
@ -1698,6 +1689,13 @@ struct IrInstructionPtrTypeChild {
IrInstruction *value;
};
struct IrInstructionSetFnTest {
IrInstruction base;
IrInstruction *fn_value;
IrInstruction *is_test;
};
enum LValPurpose {
LValPurposeNone,
LValPurposeAssign,

File diff suppressed because it is too large Load Diff

View File

@ -45,10 +45,6 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package,
AstNode *first_executing_node(AstNode *node);
TypeTableEntry *resolve_peer_type_compatibility(CodeGen *g, ImportTableEntry *import,
BlockContext *block_context, AstNode *parent_source_node,
AstNode **child_nodes, TypeTableEntry **child_types, size_t child_count);
// TODO move these over, these used to be static
bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTableEntry *actual_type);

View File

@ -261,17 +261,6 @@ static void print_indent(AstRender *ar) {
}
}
static bool is_node_void(AstNode *node) {
if (node->type == NodeTypeSymbol) {
if (node->data.symbol_expr.override_type_entry) {
return node->data.symbol_expr.override_type_entry->id == TypeTableEntryIdVoid;
} else if (buf_eql_str(node->data.symbol_expr.symbol, "void")) {
return true;
}
}
return false;
}
static bool is_alpha_under(uint8_t c) {
return (c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z') || c == '_';
@ -406,10 +395,8 @@ static void render_node(AstRender *ar, AstNode *node) {
fprintf(ar->f, ")");
AstNode *return_type_node = node->data.fn_proto.return_type;
if (!is_node_void(return_type_node)) {
fprintf(ar->f, " -> ");
render_node(ar, return_type_node);
}
fprintf(ar->f, " -> ");
render_node(ar, return_type_node);
break;
}
case NodeTypeFnDef:
@ -521,14 +508,7 @@ static void render_node(AstRender *ar, AstNode *node) {
break;
}
case NodeTypeSymbol:
{
TypeTableEntry *override_type = node->data.symbol_expr.override_type_entry;
if (override_type) {
fprintf(ar->f, "%s", buf_ptr(&override_type->name));
} else {
print_symbol(ar, node->data.symbol_expr.symbol);
}
}
print_symbol(ar, node->data.symbol_expr.symbol);
break;
case NodeTypePrefixOpExpr:
{
@ -623,10 +603,8 @@ static void render_node(AstRender *ar, AstNode *node) {
assert(field_node->type == NodeTypeStructField);
print_indent(ar);
print_symbol(ar, field_node->data.struct_field.name);
if (!is_node_void(field_node->data.struct_field.type)) {
fprintf(ar->f, ": ");
render_node(ar, field_node->data.struct_field.type);
}
fprintf(ar->f, ": ");
render_node(ar, field_node->data.struct_field.type);
fprintf(ar->f, ",\n");
}

View File

@ -2965,6 +2965,7 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
case IrInstructionIdToPtrType:
case IrInstructionIdPtrTypeChild:
case IrInstructionIdFieldPtr:
case IrInstructionIdSetFnTest:
zig_unreachable();
case IrInstructionIdReturn:
return ir_render_return(g, executable, (IrInstructionReturn *)instruction);
@ -2996,7 +2997,6 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
return ir_render_struct_field_ptr(g, executable, (IrInstructionStructFieldPtr *)instruction);
case IrInstructionIdSwitchBr:
case IrInstructionIdPhi:
case IrInstructionIdBuiltinCall:
case IrInstructionIdContainerInitList:
case IrInstructionIdContainerInitFields:
case IrInstructionIdReadField:
@ -5303,8 +5303,6 @@ static void get_c_type(CodeGen *g, TypeTableEntry *type_entry, Buf *out_buf) {
}
static void get_c_type_node(CodeGen *g, AstNode *type_node, Buf *out_buf) {
assert(type_node->type != NodeTypeSymbol || !type_node->data.symbol_expr.override_type_entry);
Expr *expr = get_resolved_expr(type_node);
assert(expr->type_entry);
assert(expr->type_entry->id == TypeTableEntryIdMetaType);

3925
src/ir.cpp

File diff suppressed because it is too large Load Diff

View File

@ -78,6 +78,12 @@ static void ir_print_const_value(IrPrint *irp, TypeTableEntry *type_entry, Const
fprintf(irp->f, "%s", buf_ptr(&fn_entry->symbol_name));
break;
}
case TypeTableEntryIdBlock:
{
AstNode *node = const_val->data.x_block->node;
fprintf(irp->f, "(scope:%zu:%zu)", node->line + 1, node->column + 1);
break;
}
case TypeTableEntryIdVar:
case TypeTableEntryIdFloat:
case TypeTableEntryIdArray:
@ -91,7 +97,6 @@ static void ir_print_const_value(IrPrint *irp, TypeTableEntry *type_entry, Const
case TypeTableEntryIdUnion:
case TypeTableEntryIdTypeDecl:
case TypeTableEntryIdNamespace:
case TypeTableEntryIdBlock:
case TypeTableEntryIdGenericFn:
zig_panic("TODO render more constant types in IR printer");
}
@ -263,18 +268,6 @@ static void ir_print_call(IrPrint *irp, IrInstructionCall *call_instruction) {
fprintf(irp->f, ")");
}
static void ir_print_builtin_call(IrPrint *irp, IrInstructionBuiltinCall *call_instruction) {
fprintf(irp->f, "@%s(", buf_ptr(&call_instruction->fn->name));
for (size_t i = 0; i < call_instruction->fn->param_count; i += 1) {
IrInstruction *arg = call_instruction->args[i];
if (i != 0)
fprintf(irp->f, ", ");
ir_print_other_instruction(irp, arg);
}
fprintf(irp->f, ")");
}
static void ir_print_cond_br(IrPrint *irp, IrInstructionCondBr *cond_br_instruction) {
const char *inline_kw = cond_br_instruction->is_inline ? "inline " : "";
fprintf(irp->f, "%sif (", inline_kw);
@ -393,6 +386,14 @@ static void ir_print_struct_field_ptr(IrPrint *irp, IrInstructionStructFieldPtr
fprintf(irp->f, ")");
}
static void ir_print_set_fn_test(IrPrint *irp, IrInstructionSetFnTest *instruction) {
fprintf(irp->f, "@setFnTest(");
ir_print_other_instruction(irp, instruction->fn_value);
fprintf(irp->f, ", ");
ir_print_other_instruction(irp, instruction->is_test);
fprintf(irp->f, ")");
}
static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
ir_print_prefix(irp, instruction);
switch (instruction->id) {
@ -425,9 +426,6 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
case IrInstructionIdBr:
ir_print_br(irp, (IrInstructionBr *)instruction);
break;
case IrInstructionIdBuiltinCall:
ir_print_builtin_call(irp, (IrInstructionBuiltinCall *)instruction);
break;
case IrInstructionIdPhi:
ir_print_phi(irp, (IrInstructionPhi *)instruction);
break;
@ -470,6 +468,9 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
case IrInstructionIdStructFieldPtr:
ir_print_struct_field_ptr(irp, (IrInstructionStructFieldPtr *)instruction);
break;
case IrInstructionIdSetFnTest:
ir_print_set_fn_test(irp, (IrInstructionSetFnTest *)instruction);
break;
case IrInstructionIdSwitchBr:
zig_panic("TODO print more IR instructions");
}

View File

@ -230,9 +230,7 @@ static AstNode *create_type_decl_node(Context *c, const char *name, AstNode *chi
}
static AstNode *make_type_node(Context *c, TypeTableEntry *type_entry) {
AstNode *node = create_node(c, NodeTypeSymbol);
node->data.symbol_expr.override_type_entry = type_entry;
return node;
zig_panic("TODO bypass AST in parseh");
}
static AstNode *create_fn_proto_node(Context *c, Buf *name, TypeTableEntry *fn_type) {