IR now builds with the new package system

This commit is contained in:
gingerBill
2018-05-27 10:49:14 +01:00
parent eb11edabe0
commit 7ee9051a56
9 changed files with 800 additions and 13 deletions
+7 -3
View File
@@ -531,11 +531,15 @@ void check_proc_decl(Checker *c, Entity *e, DeclInfo *d) {
check_decl_attributes(c, d->attributes, proc_decl_attribute, &ac);
}
e->deprecated_message = ac.deprecated_message;
ac.link_name = handle_link_name(c, e->token, ac.link_name, ac.link_prefix);
if (d->scope->package != nullptr && e->token.string == "main") {
AstPackage *package = nullptr;
if (d->scope->parent && d->scope->parent->is_package) {
package = d->scope->parent->package;
}
if (package != nullptr && e->token.string == "main") {
if (pt->param_count != 0 ||
pt->result_count != 0) {
gbString str = type_to_string(proc_type);
@@ -547,7 +551,7 @@ void check_proc_decl(Checker *c, Entity *e, DeclInfo *d) {
error(e->token, "Procedure 'main' cannot have a custom calling convention");
}
pt->calling_convention = ProcCC_Contextless;
if (d->scope->is_init) {
if (package->kind == ImportedPackage_Init) {
if (c->info.entry_point != nullptr) {
error(e->token, "Redeclaration of the entry pointer procedure 'main'");
} else {
+4
View File
@@ -533,6 +533,7 @@ void init_universal_scope(void) {
// NOTE(bill): No need to free these
gbAllocator a = heap_allocator();
universal_scope = create_scope(nullptr, a);
universal_scope->is_package = true;
// Types
for (isize i = 0; i < gb_count_of(basic_types); i++) {
@@ -2961,6 +2962,9 @@ void check_parsed_files(Checker *c) {
for_array(j, p->files.entries) {
AstFile *f = p->files.entries[j].value;
create_scope_from_file(c, f);
HashKey key = hash_string(f->fullpath);
map_set(&c->info.files, key, f);
add_curr_ast_file(c, f);
check_collect_entities(c, f->decls);
}
+23 -4
View File
@@ -7735,7 +7735,8 @@ bool ir_gen_init(irGen *s, Checker *c) {
String init_fullpath = c->parser->init_fullpath;
if (build_context.out_filepath.len == 0) {
s->output_name = filename_from_path(init_fullpath);
// s->output_name = filename_from_path(init_fullpath);
s->output_name = str_lit("main");
s->output_base = s->output_name;
} else {
s->output_name = build_context.out_filepath;
@@ -8255,9 +8256,17 @@ void ir_gen_tree(irGen *s) {
for_array(i, info->entities) {
Entity *e = info->entities[i];
String name = e->token.string;
bool is_global = false;
if (e->scope->is_package) {
is_global = true;
} else if (e->scope->parent && e->scope->parent->is_package) {
is_global = true;
}
if (e->kind == Entity_Variable) {
global_variable_max_count++;
} else if (e->kind == Entity_Procedure && !e->scope->is_global) {
} else if (e->kind == Entity_Procedure && !is_global) {
if (e->scope->is_init && name == "main") {
GB_ASSERT(e == entry_point);
// entry_point = e;
@@ -8306,9 +8315,16 @@ void ir_gen_tree(irGen *s) {
GB_ASSERT(e->kind == Entity_Variable);
bool is_global = false;
if (e->scope->is_package) {
is_global = true;
} else if (e->scope->parent && e->scope->parent->is_package) {
is_global = true;
}
bool is_foreign = e->Variable.is_foreign;
bool is_export = e->Variable.is_export;
bool no_name_mangle = e->scope->is_global || e->Variable.link_name.len > 0 || is_foreign || is_export;
bool no_name_mangle = is_global || e->Variable.link_name.len > 0 || is_foreign || is_export;
String name = e->token.string;
if (!no_name_mangle) {
@@ -8353,6 +8369,9 @@ void ir_gen_tree(irGen *s) {
continue;
}
Scope *package_scope = scope->parent;
GB_ASSERT(package_scope->is_package);
switch (e->kind) {
case Entity_Variable:
// NOTE(bill): Handled above as it requires a specific load order
@@ -8376,7 +8395,7 @@ void ir_gen_tree(irGen *s) {
String original_name = name;
if (!scope->is_global || polymorphic_struct || is_type_polymorphic(e->type)) {
if (!package_scope->is_global || polymorphic_struct || is_type_polymorphic(e->type)) {
if (e->kind == Entity_Procedure && e->Procedure.is_export) {
} else if (e->kind == Entity_Procedure && e->Procedure.link_name.len > 0) {
// Handle later
+1 -3
View File
@@ -14,11 +14,9 @@
#include "parser.cpp"
#include "docs.cpp"
#include "checker.cpp"
#if 0
#include "ir.cpp"
#include "ir_opt.cpp"
#include "ir_print.cpp"
#endif
// NOTE(bill): 'name' is used in debugging and profiling modes
i32 system_exec_command_line_app(char *name, bool is_silent, char *fmt, ...) {
@@ -811,7 +809,7 @@ int main(int arg_count, char **arg_ptr) {
check_parsed_files(&checker);
#if 0
#if 1
if (build_context.no_output_files) {
if (build_context.show_timings) {
show_timings(&checker, &timings);
+3 -1
View File
@@ -3831,7 +3831,6 @@ ParseFileError init_ast_file(AstFile *f, String fullpath, TokenPos *err_pos) {
isize init_token_cap = cast(isize)gb_max(next_pow2(cast(i64)(file_size/2ll)), 16);
array_init(&f->tokens, heap_allocator(), 0, gb_max(init_token_cap, 16));
if (err == TokenizerInit_Empty) {
Token token = {Token_EOF};
token.pos.file = fullpath;
@@ -4166,6 +4165,9 @@ ParseFileError parse_imported_file(Parser *p, AstPackage *package, FileInfo *fi,
AstFile *file = gb_alloc_item(heap_allocator(), AstFile);
file->package = package;
p->file_index += 1;
file->id = p->file_index;
TokenPos err_pos = {0};
ParseFileError err = init_ast_file(file, fi->fullpath, &err_pos);
+2
View File
@@ -40,6 +40,7 @@ struct ImportedPackage {
};
struct AstFile {
isize id;
AstPackage * package;
Scope * scope;
@@ -104,6 +105,7 @@ struct Parser {
isize total_line_count;
gbMutex file_add_mutex;
gbMutex file_decl_mutex;
isize file_index;
};
enum ProcInlining {
+4 -1
View File
@@ -259,7 +259,10 @@ bool string_contains_char(String const &s, u8 c) {
String filename_from_path(String s) {
isize i = string_extension_position(s);
s = substring(s, 0, i);
if (i >= 0) {
s = substring(s, 0, i);
return s;
}
if (i > 0) {
isize j = 0;
for (j = s.len-1; j >= 0; j--) {