| author | |
| committer | |
| log | 27ba4f0baf5168b2fb8f0dd72b04f528092f075a |
| tree | fab0c72728f6f09a5214aa7386e083138d3ef8fa |
| parent | c627f9ea18b5f194860c6bf3730f3f0407c224f2 |
5 files changed, 38 insertions(+), 28 deletions(-)
src/all_types.hpp-1| ... | ... | @@ -1183,7 +1183,6 @@ enum FnInline { |
| 1183 | 1183 | struct FnExport { |
| 1184 | 1184 | Buf name; |
| 1185 | 1185 | GlobalLinkageId linkage; |
| 1186 | AstNode *source_node; | |
| 1187 | 1186 | }; |
| 1188 | 1187 | |
| 1189 | 1188 | struct FnTableEntry { |
src/analyze.cpp+33| ... | ... | @@ -2577,6 +2577,34 @@ TypeTableEntry *get_test_fn_type(CodeGen *g) { |
| 2577 | 2577 | return g->test_fn_type; |
| 2578 | 2578 | } |
| 2579 | 2579 | |
| 2580 | void 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 | ||
| 2580 | 2608 | static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) { |
| 2581 | 2609 | ImportTableEntry *import = tld_fn->base.import; |
| 2582 | 2610 | AstNode *source_node = tld_fn->base.source_node; |
| ... | ... | @@ -2588,6 +2616,11 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) { |
| 2588 | 2616 | FnTableEntry *fn_table_entry = create_fn(source_node); |
| 2589 | 2617 | get_fully_qualified_decl_name(&fn_table_entry->symbol_name, &tld_fn->base, '_'); |
| 2590 | 2618 | |
| 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 | 2624 | tld_fn->fn_entry = fn_table_entry; |
| 2592 | 2625 | |
| 2593 | 2626 | if (fn_table_entry->body_node) { |
src/analyze.hpp+1| ... | ... | @@ -183,5 +183,6 @@ TypeTableEntry *get_align_amt_type(CodeGen *g); |
| 183 | 183 | PackageTableEntry *new_anonymous_package(void); |
| 184 | 184 | |
| 185 | 185 | Buf *const_value_to_buffer(ConstExprValue *const_val); |
| 186 | void add_fn_export(CodeGen *g, FnTableEntry *fn_table_entry, Buf *symbol_name, GlobalLinkageId linkage, bool ccc); | |
| 186 | 187 | |
| 187 | 188 | #endif |
src/ir.cpp+3-27| ... | ... | @@ -10504,35 +10504,11 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi |
| 10504 | 10504 | add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here")); |
| 10505 | 10505 | } break; |
| 10506 | 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 | 10507 | case CallingConventionNaked: |
| 10528 | 10508 | case CallingConventionCold: |
| 10529 | case CallingConventionStdcall: { | |
| 10530 | FnExport *fn_export = fn_entry->export_list.add_one(); | |
| 10531 | memset(fn_export, 0, sizeof(FnExport)); | |
| 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; | |
| 10509 | case CallingConventionStdcall: | |
| 10510 | add_fn_export(ira->codegen, fn_entry, symbol_name, global_linkage_id, cc == CallingConventionC); | |
| 10511 | break; | |
| 10536 | 10512 | } |
| 10537 | 10513 | } break; |
| 10538 | 10514 | case TypeTableEntryIdStruct: |
src/parser.cpp+1| ... | ... | @@ -1553,6 +1553,7 @@ static AstNode *ast_parse_variable_declaration_expr(ParseContext *pc, size_t *to |
| 1553 | 1553 | AstNode *node = ast_create_node(pc, NodeTypeVariableDeclaration, var_token); |
| 1554 | 1554 | |
| 1555 | 1555 | node->data.variable_declaration.is_comptime = is_comptime; |
| 1556 | node->data.variable_declaration.is_export = is_export; | |
| 1556 | 1557 | node->data.variable_declaration.is_const = is_const; |
| 1557 | 1558 | node->data.variable_declaration.visib_mod = visib_mod; |
| 1558 | 1559 |