authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-12-19 01:49:42-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-12-19 01:49:42-05:00
log27ba4f0baf5168b2fb8f0dd72b04f528092f075a
treefab0c72728f6f09a5214aa7386e083138d3ef8fa
parentc627f9ea18b5f194860c6bf3730f3f0407c224f2

export keyword works again


5 files changed, 38 insertions(+), 28 deletions(-)

src/all_types.hpp-1
...@@ -1183,7 +1183,6 @@ enum FnInline {...@@ -1183,7 +1183,6 @@ enum FnInline {
1183struct FnExport {1183struct FnExport {
1184 Buf name;1184 Buf name;
1185 GlobalLinkageId linkage;1185 GlobalLinkageId linkage;
1186 AstNode *source_node;
1187};1186};
11881187
1189struct FnTableEntry {1188struct FnTableEntry {
src/analyze.cpp+33
...@@ -2577,6 +2577,34 @@ TypeTableEntry *get_test_fn_type(CodeGen *g) {...@@ -2577,6 +2577,34 @@ TypeTableEntry *get_test_fn_type(CodeGen *g) {
2577 return g->test_fn_type;2577 return g->test_fn_type;
2578}2578}
25792579
2580void add_fn_export(CodeGen *g, FnTableEntry *fn_table_entry, Buf *symbol_name, GlobalLinkageId linkage, bool ccc) {
2581 if (ccc) {
2582 if (buf_eql_str(symbol_name, "main") && g->libc_link_lib != nullptr) {
2583 g->have_c_main = true;
2584 g->windows_subsystem_windows = false;
2585 g->windows_subsystem_console = true;
2586 } else if (buf_eql_str(symbol_name, "WinMain") &&
2587 g->zig_target.os == ZigLLVM_Win32)
2588 {
2589 g->have_winmain = true;
2590 g->windows_subsystem_windows = true;
2591 g->windows_subsystem_console = false;
2592 } else if (buf_eql_str(symbol_name, "WinMainCRTStartup") &&
2593 g->zig_target.os == ZigLLVM_Win32)
2594 {
2595 g->have_winmain_crt_startup = true;
2596 } else if (buf_eql_str(symbol_name, "DllMainCRTStartup") &&
2597 g->zig_target.os == ZigLLVM_Win32)
2598 {
2599 g->have_dllmain_crt_startup = true;
2600 }
2601 }
2602 FnExport *fn_export = fn_table_entry->export_list.add_one();
2603 memset(fn_export, 0, sizeof(FnExport));
2604 buf_init_from_buf(&fn_export->name, symbol_name);
2605 fn_export->linkage = linkage;
2606}
2607
2580static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {2608static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
2581 ImportTableEntry *import = tld_fn->base.import;2609 ImportTableEntry *import = tld_fn->base.import;
2582 AstNode *source_node = tld_fn->base.source_node;2610 AstNode *source_node = tld_fn->base.source_node;
...@@ -2588,6 +2616,11 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {...@@ -2588,6 +2616,11 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
2588 FnTableEntry *fn_table_entry = create_fn(source_node);2616 FnTableEntry *fn_table_entry = create_fn(source_node);
2589 get_fully_qualified_decl_name(&fn_table_entry->symbol_name, &tld_fn->base, '_');2617 get_fully_qualified_decl_name(&fn_table_entry->symbol_name, &tld_fn->base, '_');
25902618
2619 if (fn_proto->is_export) {
2620 bool ccc = (fn_proto->cc == CallingConventionUnspecified || fn_proto->cc == CallingConventionC);
2621 add_fn_export(g, fn_table_entry, &fn_table_entry->symbol_name, GlobalLinkageIdStrong, ccc);
2622 }
2623
2591 tld_fn->fn_entry = fn_table_entry;2624 tld_fn->fn_entry = fn_table_entry;
25922625
2593 if (fn_table_entry->body_node) {2626 if (fn_table_entry->body_node) {
src/analyze.hpp+1
...@@ -183,5 +183,6 @@ TypeTableEntry *get_align_amt_type(CodeGen *g);...@@ -183,5 +183,6 @@ TypeTableEntry *get_align_amt_type(CodeGen *g);
183PackageTableEntry *new_anonymous_package(void);183PackageTableEntry *new_anonymous_package(void);
184184
185Buf *const_value_to_buffer(ConstExprValue *const_val);185Buf *const_value_to_buffer(ConstExprValue *const_val);
186void add_fn_export(CodeGen *g, FnTableEntry *fn_table_entry, Buf *symbol_name, GlobalLinkageId linkage, bool ccc);
186187
187#endif188#endif
src/ir.cpp+3-27
...@@ -10504,35 +10504,11 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi...@@ -10504,35 +10504,11 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi
10504 add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here"));10504 add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here"));
10505 } break;10505 } break;
10506 case CallingConventionC:10506 case CallingConventionC:
10507 if (buf_eql_str(symbol_name, "main") && ira->codegen->libc_link_lib != nullptr) {
10508 ira->codegen->have_c_main = true;
10509 ira->codegen->windows_subsystem_windows = false;
10510 ira->codegen->windows_subsystem_console = true;
10511 } else if (buf_eql_str(symbol_name, "WinMain") &&
10512 ira->codegen->zig_target.os == ZigLLVM_Win32)
10513 {
10514 ira->codegen->have_winmain = true;
10515 ira->codegen->windows_subsystem_windows = true;
10516 ira->codegen->windows_subsystem_console = false;
10517 } else if (buf_eql_str(symbol_name, "WinMainCRTStartup") &&
10518 ira->codegen->zig_target.os == ZigLLVM_Win32)
10519 {
10520 ira->codegen->have_winmain_crt_startup = true;
10521 } else if (buf_eql_str(symbol_name, "DllMainCRTStartup") &&
10522 ira->codegen->zig_target.os == ZigLLVM_Win32)
10523 {
10524 ira->codegen->have_dllmain_crt_startup = true;
10525 }
10526 // fallthrough
10527 case CallingConventionNaked:10507 case CallingConventionNaked:
10528 case CallingConventionCold:10508 case CallingConventionCold:
10529 case CallingConventionStdcall: {10509 case CallingConventionStdcall:
10530 FnExport *fn_export = fn_entry->export_list.add_one();10510 add_fn_export(ira->codegen, fn_entry, symbol_name, global_linkage_id, cc == CallingConventionC);
10531 memset(fn_export, 0, sizeof(FnExport));10511 break;
10532 buf_init_from_buf(&fn_export->name, symbol_name);
10533 fn_export->linkage = global_linkage_id;
10534 fn_export->source_node = instruction->base.source_node;
10535 } break;
10536 }10512 }
10537 } break;10513 } break;
10538 case TypeTableEntryIdStruct:10514 case TypeTableEntryIdStruct:
src/parser.cpp+1
...@@ -1553,6 +1553,7 @@ static AstNode *ast_parse_variable_declaration_expr(ParseContext *pc, size_t *to...@@ -1553,6 +1553,7 @@ static AstNode *ast_parse_variable_declaration_expr(ParseContext *pc, size_t *to
1553 AstNode *node = ast_create_node(pc, NodeTypeVariableDeclaration, var_token);1553 AstNode *node = ast_create_node(pc, NodeTypeVariableDeclaration, var_token);
15541554
1555 node->data.variable_declaration.is_comptime = is_comptime;1555 node->data.variable_declaration.is_comptime = is_comptime;
1556 node->data.variable_declaration.is_export = is_export;
1556 node->data.variable_declaration.is_const = is_const;1557 node->data.variable_declaration.is_const = is_const;
1557 node->data.variable_declaration.visib_mod = visib_mod;1558 node->data.variable_declaration.visib_mod = visib_mod;
15581559