authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-11-18 22:44:59-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-11-18 22:44:59-05:00
log31565efe9d6cde2e4909f986d50f8c46166d3311
tree024fbac9aa2153c884e6de86673578c12ef46517
parentd94cb0566be6463594f0904aa759de9e52585842

IR: fix decl references pointerness


1 files changed, 26 insertions(+), 13 deletions(-)

src/ir.cpp+26-13
...@@ -1152,25 +1152,43 @@ static IrInstruction *ir_gen_decl_ref(IrBuilder *irb, AstNode *source_node, AstN...@@ -1152,25 +1152,43 @@ static IrInstruction *ir_gen_decl_ref(IrBuilder *irb, AstNode *source_node, AstN
1152 if (decl_node->type == NodeTypeVariableDeclaration) {1152 if (decl_node->type == NodeTypeVariableDeclaration) {
1153 VariableTableEntry *var = decl_node->data.variable_declaration.variable;1153 VariableTableEntry *var = decl_node->data.variable_declaration.variable;
1154 IrInstruction *var_ptr = ir_build_var_ptr(irb, source_node, var);1154 IrInstruction *var_ptr = ir_build_var_ptr(irb, source_node, var);
1155 return ir_build_load_ptr(irb, source_node, var_ptr);1155 if (lval != LValPurposeNone)
1156 return var_ptr;
1157 else
1158 return ir_build_load_ptr(irb, source_node, var_ptr);
1156 } else if (decl_node->type == NodeTypeFnProto) {1159 } else if (decl_node->type == NodeTypeFnProto) {
1157 FnTableEntry *fn_entry = decl_node->data.fn_proto.fn_table_entry;1160 FnTableEntry *fn_entry = decl_node->data.fn_proto.fn_table_entry;
1158 assert(fn_entry->type_entry);1161 assert(fn_entry->type_entry);
1162 IrInstruction *ref_instruction;
1159 if (fn_entry->type_entry->id == TypeTableEntryIdGenericFn) {1163 if (fn_entry->type_entry->id == TypeTableEntryIdGenericFn) {
1160 return ir_build_const_generic_fn(irb, source_node, fn_entry->type_entry);1164 ref_instruction = ir_build_const_generic_fn(irb, source_node, fn_entry->type_entry);
1161 } else {1165 } else {
1162 return ir_build_const_fn(irb, source_node, fn_entry);1166 ref_instruction = ir_build_const_fn(irb, source_node, fn_entry);
1163 }1167 }
1168 if (lval != LValPurposeNone)
1169 return ir_build_un_op(irb, source_node, IrUnOpAddressOf, ref_instruction);
1170 else
1171 return ref_instruction;
1164 } else if (decl_node->type == NodeTypeContainerDecl) {1172 } else if (decl_node->type == NodeTypeContainerDecl) {
1173 IrInstruction *ref_instruction;
1165 if (decl_node->data.struct_decl.generic_params.length > 0) {1174 if (decl_node->data.struct_decl.generic_params.length > 0) {
1166 TypeTableEntry *type_entry = decl_node->data.struct_decl.generic_fn_type;1175 TypeTableEntry *type_entry = decl_node->data.struct_decl.generic_fn_type;
1167 assert(type_entry);1176 assert(type_entry);
1168 return ir_build_const_generic_fn(irb, source_node, type_entry);1177 ref_instruction = ir_build_const_generic_fn(irb, source_node, type_entry);
1169 } else {1178 } else {
1170 return ir_build_const_type(irb, source_node, decl_node->data.struct_decl.type_entry);1179 ref_instruction = ir_build_const_type(irb, source_node, decl_node->data.struct_decl.type_entry);
1171 }1180 }
1181 if (lval != LValPurposeNone)
1182 return ir_build_un_op(irb, source_node, IrUnOpAddressOf, ref_instruction);
1183 else
1184 return ref_instruction;
1172 } else if (decl_node->type == NodeTypeTypeDecl) {1185 } else if (decl_node->type == NodeTypeTypeDecl) {
1173 return ir_build_const_type(irb, source_node, decl_node->data.type_decl.child_type_entry);1186 TypeTableEntry *child_type = decl_node->data.type_decl.child_type_entry;
1187 IrInstruction *ref_instruction = ir_build_const_type(irb, source_node, child_type);
1188 if (lval != LValPurposeNone)
1189 return ir_build_un_op(irb, source_node, IrUnOpAddressOf, ref_instruction);
1190 else
1191 return ref_instruction;
1174 } else {1192 } else {
1175 zig_unreachable();1193 zig_unreachable();
1176 }1194 }
...@@ -1201,13 +1219,8 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, AstNode *node, LValPurpose l...@@ -1201,13 +1219,8 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, AstNode *node, LValPurpose l
1201 }1219 }
12021220
1203 AstNode *decl_node = find_decl(node->block_context, variable_name);1221 AstNode *decl_node = find_decl(node->block_context, variable_name);
1204 if (decl_node) {1222 if (decl_node)
1205 IrInstruction *value = ir_gen_decl_ref(irb, node, decl_node, lval, node->block_context);1223 return ir_gen_decl_ref(irb, node, decl_node, lval, node->block_context);
1206 if (lval == LValPurposeAddressOf)
1207 return ir_build_un_op(irb, node, IrUnOpAddressOf, value);
1208 else
1209 return value;
1210 }
12111224
1212 if (node->owner->any_imports_failed) {1225 if (node->owner->any_imports_failed) {
1213 // skip the error message since we had a failing import in this file1226 // skip the error message since we had a failing import in this file