export keyword works again

This commit is contained in:
Andrew Kelley 2017-12-19 01:49:42 -05:00
parent c627f9ea18
commit 27ba4f0baf
5 changed files with 38 additions and 28 deletions

View File

@ -1183,7 +1183,6 @@ enum FnInline {
struct FnExport { struct FnExport {
Buf name; Buf name;
GlobalLinkageId linkage; GlobalLinkageId linkage;
AstNode *source_node;
}; };
struct FnTableEntry { struct FnTableEntry {

View File

@ -2577,6 +2577,34 @@ TypeTableEntry *get_test_fn_type(CodeGen *g) {
return g->test_fn_type; return g->test_fn_type;
} }
void add_fn_export(CodeGen *g, FnTableEntry *fn_table_entry, Buf *symbol_name, GlobalLinkageId linkage, bool ccc) {
if (ccc) {
if (buf_eql_str(symbol_name, "main") && g->libc_link_lib != nullptr) {
g->have_c_main = true;
g->windows_subsystem_windows = false;
g->windows_subsystem_console = true;
} else if (buf_eql_str(symbol_name, "WinMain") &&
g->zig_target.os == ZigLLVM_Win32)
{
g->have_winmain = true;
g->windows_subsystem_windows = true;
g->windows_subsystem_console = false;
} else if (buf_eql_str(symbol_name, "WinMainCRTStartup") &&
g->zig_target.os == ZigLLVM_Win32)
{
g->have_winmain_crt_startup = true;
} else if (buf_eql_str(symbol_name, "DllMainCRTStartup") &&
g->zig_target.os == ZigLLVM_Win32)
{
g->have_dllmain_crt_startup = true;
}
}
FnExport *fn_export = fn_table_entry->export_list.add_one();
memset(fn_export, 0, sizeof(FnExport));
buf_init_from_buf(&fn_export->name, symbol_name);
fn_export->linkage = linkage;
}
static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) { static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
ImportTableEntry *import = tld_fn->base.import; ImportTableEntry *import = tld_fn->base.import;
AstNode *source_node = tld_fn->base.source_node; AstNode *source_node = tld_fn->base.source_node;
@ -2588,6 +2616,11 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
FnTableEntry *fn_table_entry = create_fn(source_node); FnTableEntry *fn_table_entry = create_fn(source_node);
get_fully_qualified_decl_name(&fn_table_entry->symbol_name, &tld_fn->base, '_'); get_fully_qualified_decl_name(&fn_table_entry->symbol_name, &tld_fn->base, '_');
if (fn_proto->is_export) {
bool ccc = (fn_proto->cc == CallingConventionUnspecified || fn_proto->cc == CallingConventionC);
add_fn_export(g, fn_table_entry, &fn_table_entry->symbol_name, GlobalLinkageIdStrong, ccc);
}
tld_fn->fn_entry = fn_table_entry; tld_fn->fn_entry = fn_table_entry;
if (fn_table_entry->body_node) { if (fn_table_entry->body_node) {

View File

@ -183,5 +183,6 @@ TypeTableEntry *get_align_amt_type(CodeGen *g);
PackageTableEntry *new_anonymous_package(void); PackageTableEntry *new_anonymous_package(void);
Buf *const_value_to_buffer(ConstExprValue *const_val); Buf *const_value_to_buffer(ConstExprValue *const_val);
void add_fn_export(CodeGen *g, FnTableEntry *fn_table_entry, Buf *symbol_name, GlobalLinkageId linkage, bool ccc);
#endif #endif

View File

@ -10504,35 +10504,11 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi
add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here")); add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here"));
} break; } break;
case CallingConventionC: case CallingConventionC:
if (buf_eql_str(symbol_name, "main") && ira->codegen->libc_link_lib != nullptr) {
ira->codegen->have_c_main = true;
ira->codegen->windows_subsystem_windows = false;
ira->codegen->windows_subsystem_console = true;
} else if (buf_eql_str(symbol_name, "WinMain") &&
ira->codegen->zig_target.os == ZigLLVM_Win32)
{
ira->codegen->have_winmain = true;
ira->codegen->windows_subsystem_windows = true;
ira->codegen->windows_subsystem_console = false;
} else if (buf_eql_str(symbol_name, "WinMainCRTStartup") &&
ira->codegen->zig_target.os == ZigLLVM_Win32)
{
ira->codegen->have_winmain_crt_startup = true;
} else if (buf_eql_str(symbol_name, "DllMainCRTStartup") &&
ira->codegen->zig_target.os == ZigLLVM_Win32)
{
ira->codegen->have_dllmain_crt_startup = true;
}
// fallthrough
case CallingConventionNaked: case CallingConventionNaked:
case CallingConventionCold: case CallingConventionCold:
case CallingConventionStdcall: { case CallingConventionStdcall:
FnExport *fn_export = fn_entry->export_list.add_one(); add_fn_export(ira->codegen, fn_entry, symbol_name, global_linkage_id, cc == CallingConventionC);
memset(fn_export, 0, sizeof(FnExport)); break;
buf_init_from_buf(&fn_export->name, symbol_name);
fn_export->linkage = global_linkage_id;
fn_export->source_node = instruction->base.source_node;
} break;
} }
} break; } break;
case TypeTableEntryIdStruct: case TypeTableEntryIdStruct:

View File

@ -1553,6 +1553,7 @@ static AstNode *ast_parse_variable_declaration_expr(ParseContext *pc, size_t *to
AstNode *node = ast_create_node(pc, NodeTypeVariableDeclaration, var_token); AstNode *node = ast_create_node(pc, NodeTypeVariableDeclaration, var_token);
node->data.variable_declaration.is_comptime = is_comptime; node->data.variable_declaration.is_comptime = is_comptime;
node->data.variable_declaration.is_export = is_export;
node->data.variable_declaration.is_const = is_const; node->data.variable_declaration.is_const = is_const;
node->data.variable_declaration.visib_mod = visib_mod; node->data.variable_declaration.visib_mod = visib_mod;