From 34a048f7daaf93b16ae4121bf5238f9008f3465b Mon Sep 17 00:00:00 2001 From: gingerBill Date: Fri, 9 Dec 2022 11:29:28 +0000 Subject: Replace compiler for loops for the hash-table types to simplify code usage --- src/build_settings.cpp | 11 ++-- src/check_builtin.cpp | 5 +- src/check_decl.cpp | 12 ++-- src/check_expr.cpp | 25 ++++---- src/check_stmt.cpp | 14 ++--- src/check_type.cpp | 4 +- src/checker.cpp | 134 +++++++++++++++++++++---------------------- src/docs.cpp | 8 +-- src/docs_writer.cpp | 36 ++++++------ src/llvm_backend.cpp | 125 +++++++++++++++++----------------------- src/llvm_backend.hpp | 1 + src/llvm_backend_general.cpp | 8 +-- src/ptr_map.cpp | 21 +++++++ src/ptr_set.cpp | 21 +++++++ src/query_data.cpp | 8 +-- src/string_map.cpp | 23 ++++++++ src/string_set.cpp | 18 ++++++ src/types.cpp | 4 +- 18 files changed, 269 insertions(+), 209 deletions(-) (limited to 'src') diff --git a/src/build_settings.cpp b/src/build_settings.cpp index 1cd2899c4..ba68e388b 100644 --- a/src/build_settings.cpp +++ b/src/build_settings.cpp @@ -1328,23 +1328,26 @@ void enable_target_feature(TokenPos pos, String const &target_feature_list) { char const *target_features_set_to_cstring(gbAllocator allocator, bool with_quotes) { isize len = 0; - for_array(i, build_context.target_features_set.entries) { + isize i = 0; + for (auto const &entry : build_context.target_features_set) { if (i != 0) { len += 1; } - String feature = build_context.target_features_set.entries[i].value; + String feature = entry.value; len += feature.len; if (with_quotes) len += 2; + i += 1; } char *features = gb_alloc_array(allocator, char, len+1); len = 0; - for_array(i, build_context.target_features_set.entries) { + i = 0; + for (auto const &entry : build_context.target_features_set) { if (i != 0) { features[len++] = ','; } if (with_quotes) features[len++] = '"'; - String feature = build_context.target_features_set.entries[i].value; + String feature = entry.value; gb_memmove(features + len, feature.text, feature.len); len += feature.len; if (with_quotes) features[len++] = '"'; diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp index 809d1d9a5..533929200 100644 --- a/src/check_builtin.cpp +++ b/src/check_builtin.cpp @@ -3455,9 +3455,8 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32 error(ce->args[0], "Expected a constant string for '%.*s'", LIT(builtin_name)); } else if (operand->value.kind == ExactValue_String) { String pkg_name = operand->value.value_string; - // TODO(bill): probably should have this be a `StringMap` eventually - for_array(i, c->info->packages.entries) { - AstPackage *pkg = c->info->packages.entries[i].value; + for (auto const &entry : c->info->packages) { + AstPackage *pkg = entry.value; if (pkg->name == pkg_name) { value = true; break; diff --git a/src/check_decl.cpp b/src/check_decl.cpp index 0e41dbbb5..18e5477d6 100644 --- a/src/check_decl.cpp +++ b/src/check_decl.cpp @@ -1499,8 +1499,8 @@ void check_proc_body(CheckerContext *ctx_, Token token, DeclInfo *decl, Type *ty if (t->kind == Type_Struct) { Scope *scope = t->Struct.scope; GB_ASSERT(scope != nullptr); - MUTEX_GUARD_BLOCK(scope->mutex) for_array(i, scope->elements.entries) { - Entity *f = scope->elements.entries[i].value; + MUTEX_GUARD_BLOCK(scope->mutex) for (auto const &entry : scope->elements) { + Entity *f = entry.value; if (f->kind == Entity_Variable) { Entity *uvar = alloc_entity_using_variable(e, f->token, f->type, nullptr); if (is_value) uvar->flags |= EntityFlag_Value; @@ -1599,12 +1599,12 @@ void check_proc_body(CheckerContext *ctx_, Token token, DeclInfo *decl, Type *ty // NOTE(bill): Add the dependencies from the procedure literal (lambda) // But only at the procedure level - for_array(i, decl->deps.entries) { - Entity *e = decl->deps.entries[i].ptr; + for (auto const &entry : decl->deps) { + Entity *e = entry.ptr; ptr_set_add(&decl->parent->deps, e); } - for_array(i, decl->type_info_deps.entries) { - Type *t = decl->type_info_deps.entries[i].ptr; + for (auto const &entry : decl->type_info_deps) { + Type *t = entry.ptr; ptr_set_add(&decl->parent->type_info_deps, t); } diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 9846199f8..fbc4f8b63 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -205,8 +205,8 @@ void check_did_you_mean_objc_entity(String const &name, Entity *e, bool is_type, DidYouMeanAnswers d = did_you_mean_make(heap_allocator(), set.entries.count, name); defer (did_you_mean_destroy(&d)); - for_array(i, set.entries) { - did_you_mean_append(&d, set.entries[i].value); + for (auto const &entry : set) { + did_you_mean_append(&d, entry.value); } check_did_you_mean_print(&d, prefix); } @@ -242,12 +242,10 @@ void check_did_you_mean_scope(String const &name, Scope *scope, char const *pref DidYouMeanAnswers d = did_you_mean_make(heap_allocator(), scope->elements.entries.count, name); defer (did_you_mean_destroy(&d)); - mutex_lock(&scope->mutex); - for_array(i, scope->elements.entries) { - Entity *e = scope->elements.entries[i].value; + MUTEX_GUARD_BLOCK(&scope->mutex) for (auto const &entry : scope->elements) { + Entity *e = entry.value; did_you_mean_append(&d, e->token.string); } - mutex_unlock(&scope->mutex); check_did_you_mean_print(&d, prefix); } @@ -322,8 +320,8 @@ void check_scope_decls(CheckerContext *c, Slice const &nodes, isize reser check_collect_entities(c, nodes); - for_array(i, s->elements.entries) { - Entity *e = s->elements.entries[i].value; + for (auto const &entry : s->elements) { + Entity *e = entry.value; switch (e->kind) { case Entity_Constant: case Entity_TypeName: @@ -4918,8 +4916,8 @@ isize add_dependencies_from_unpacking(CheckerContext *c, Entity **lhs, isize lhs if (e != nullptr) { DeclInfo *decl = decl_info_of_entity(e); if (decl != nullptr) { - for_array(k, decl->deps.entries) { - Entity *dep = decl->deps.entries[k].ptr; + for (auto const &entry : decl->deps) { + Entity *dep = entry.ptr; ptr_set_add(&c->decl->deps, dep); } } @@ -5671,8 +5669,7 @@ Entity **populate_proc_parameter_list(CheckerContext *c, Type *proc_type, isize bool evaluate_where_clauses(CheckerContext *ctx, Ast *call_expr, Scope *scope, Slice *clauses, bool print_err) { if (clauses != nullptr) { - for_array(i, *clauses) { - Ast *clause = (*clauses)[i]; + for (Ast *clause : *clauses) { Operand o = {}; check_expr(ctx, &o, clause); if (o.mode != Addressing_Constant) { @@ -5693,8 +5690,8 @@ bool evaluate_where_clauses(CheckerContext *ctx, Ast *call_expr, Scope *scope, S if (scope != nullptr) { isize print_count = 0; - for_array(j, scope->elements.entries) { - Entity *e = scope->elements.entries[j].value; + for (auto const &entry : scope->elements) { + Entity *e = entry.value; switch (e->kind) { case Entity_TypeName: { if (print_count == 0) error_line("\n\tWith the following definitions:\n"); diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index 502eed57e..720b15c9c 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -622,9 +622,9 @@ bool check_using_stmt_entity(CheckerContext *ctx, AstUsingStmt *us, Ast *expr, b case Entity_ImportName: { Scope *scope = e->ImportName.scope; - MUTEX_GUARD_BLOCK(scope->mutex) for_array(i, scope->elements.entries) { - String name = scope->elements.entries[i].key.string; - Entity *decl = scope->elements.entries[i].value; + MUTEX_GUARD_BLOCK(scope->mutex) for (auto const &entry : scope->elements) { + String name = entry.key.string; + Entity *decl = entry.value; if (!is_entity_exported(decl)) continue; Entity *found = scope_insert_with_name(ctx->scope, name, decl); @@ -652,8 +652,8 @@ bool check_using_stmt_entity(CheckerContext *ctx, AstUsingStmt *us, Ast *expr, b if (t->kind == Type_Struct) { Scope *found = t->Struct.scope; GB_ASSERT(found != nullptr); - for_array(i, found->elements.entries) { - Entity *f = found->elements.entries[i].value; + for (auto const &entry : found->elements) { + Entity *f = entry.value; if (f->kind == Entity_Variable) { Entity *uvar = alloc_entity_using_variable(e, f->token, f->type, expr); if (!is_ptr && e->flags & EntityFlag_Value) uvar->flags |= EntityFlag_Value; @@ -2370,8 +2370,8 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) { Scope *scope = t->Struct.scope; GB_ASSERT(scope != nullptr); - for_array(i, scope->elements.entries) { - Entity *f = scope->elements.entries[i].value; + for (auto const &entry : scope->elements) { + Entity *f = entry.value; if (f->kind == Entity_Variable) { Entity *uvar = alloc_entity_using_variable(e, f->token, f->type, nullptr); uvar->flags |= (e->flags & EntityFlag_Value); diff --git a/src/check_type.cpp b/src/check_type.cpp index 377b2da1f..62ca19c57 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -1791,8 +1791,8 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_params, bool *is isize specialization_count = 0; if (scope != nullptr) { - for_array(i, scope->elements.entries) { - Entity *e = scope->elements.entries[i].value; + for (auto const &entry : scope->elements) { + Entity *e = entry.value; if (e->kind == Entity_TypeName) { Type *t = e->type; if (t->kind == Type_Generic && diff --git a/src/checker.cpp b/src/checker.cpp index 30a070d06..d5222f615 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -308,8 +308,8 @@ Scope *create_scope_from_package(CheckerContext *c, AstPackage *pkg) { } void destroy_scope(Scope *scope) { - for_array(i, scope->elements.entries) { - Entity *e =scope->elements.entries[i].value; + for (auto const &entry : scope->elements) { + Entity *e = entry.value; if (e->kind == Entity_Variable) { if (!(e->flags & EntityFlag_Used)) { #if 0 @@ -659,8 +659,8 @@ void check_scope_usage(Checker *c, Scope *scope) { Array vetted_entities = {}; array_init(&vetted_entities, heap_allocator()); - MUTEX_GUARD_BLOCK(scope->mutex) for_array(i, scope->elements.entries) { - Entity *e = scope->elements.entries[i].value; + MUTEX_GUARD_BLOCK(scope->mutex) for (auto const &entry : scope->elements) { + Entity *e = entry.value; if (e == nullptr) continue; VettedEntity ve_unused = {}; VettedEntity ve_shadowed = {}; @@ -755,9 +755,8 @@ AstPackage *get_core_package(CheckerInfo *info, String name) { gb_printf_err("Name: %.*s\n", LIT(name)); gb_printf_err("Fullpath: %.*s\n", LIT(path)); - for_array(i, info->packages.entries) { - auto *entry = &info->packages.entries[i]; - gb_printf_err("%.*s\n", LIT(entry->key.string)); + for (auto const &entry : info->packages) { + gb_printf_err("%.*s\n", LIT(entry.key.string)); } GB_ASSERT_MSG(found != nullptr, "Missing core package %.*s", LIT(name)); } @@ -1065,9 +1064,9 @@ void init_universal(void) { } bool defined_values_double_declaration = false; - for_array(i, bc->defined_values.entries) { - char const *name = bc->defined_values.entries[i].key; - ExactValue value = bc->defined_values.entries[i].value; + for (auto const &entry : bc->defined_values) { + char const *name = entry.key; + ExactValue value = entry.value; GB_ASSERT(value.kind != ExactValue_Invalid); Type *type = nullptr; @@ -1418,10 +1417,9 @@ isize type_info_index(CheckerInfo *info, Type *type, bool error_on_failure) { if (entry_index < 0) { // NOTE(bill): Do manual search // TODO(bill): This is O(n) and can be very slow - for_array(i, info->type_info_map.entries){ - auto *e = &info->type_info_map.entries[i]; - if (are_types_identical_unique_tuples(e->key, type)) { - entry_index = e->value; + for (auto const &e : info->type_info_map) { + if (are_types_identical_unique_tuples(e.key, type)) { + entry_index = e.value; // NOTE(bill): Add it to the search map map_set(&info->type_info_map, type, entry_index); break; @@ -1781,11 +1779,10 @@ void add_type_info_type_internal(CheckerContext *c, Type *t) { bool prev = false; isize ti_index = -1; - for_array(i, c->info->type_info_map.entries) { - auto *e = &c->info->type_info_map.entries[i]; - if (are_types_identical_unique_tuples(t, e->key)) { + for (auto const &e : c->info->type_info_map) { + if (are_types_identical_unique_tuples(t, e.key)) { // Duplicate entry - ti_index = e->value; + ti_index = e.value; prev = true; break; } @@ -1908,8 +1905,8 @@ void add_type_info_type_internal(CheckerContext *c, Type *t) { case Type_Struct: if (bt->Struct.scope != nullptr) { - for_array(i, bt->Struct.scope->elements.entries) { - Entity *e = bt->Struct.scope->elements.entries[i].value; + for (auto const &entry : bt->Struct.scope->elements) { + Entity *e = entry.value; switch (bt->Struct.soa_kind) { case StructSoa_Dynamic: add_type_info_type_internal(c, t_allocator); @@ -2132,8 +2129,8 @@ void add_min_dep_type_info(Checker *c, Type *t) { case Type_Struct: if (bt->Struct.scope != nullptr) { - for_array(i, bt->Struct.scope->elements.entries) { - Entity *e = bt->Struct.scope->elements.entries[i].value; + for (auto const &entry : bt->Struct.scope->elements) { + Entity *e = entry.value; switch (bt->Struct.soa_kind) { case StructSoa_Dynamic: add_min_dep_type_info(c, t_allocator); @@ -2230,13 +2227,12 @@ void add_dependency_to_set(Checker *c, Entity *entity) { return; } - for_array(i, decl->type_info_deps.entries) { - Type *type = decl->type_info_deps.entries[i].ptr; - add_min_dep_type_info(c, type); + for (auto const &entry : decl->type_info_deps) { + add_min_dep_type_info(c, entry.ptr); } - for_array(i, decl->deps.entries) { - Entity *e = decl->deps.entries[i].ptr; + for (auto const &entry : decl->deps) { + Entity *e = entry.ptr; add_dependency_to_set(c, e); if (e->kind == Entity_Procedure && e->Procedure.is_foreign) { Entity *fl = e->Procedure.foreign_library; @@ -2430,8 +2426,8 @@ void generate_minimum_dependency_set(Checker *c, Entity *start) { Scope *testing_scope = testing_package->scope; // Add all of testing library as a dependency - for_array(i, testing_scope->elements.entries) { - Entity *e = testing_scope->elements.entries[i].value; + for (auto const &entry : testing_scope->elements) { + Entity *e = entry.value; if (e != nullptr) { e->flags |= EntityFlag_Used; add_dependency_to_set(c, e); @@ -2445,8 +2441,8 @@ void generate_minimum_dependency_set(Checker *c, Entity *start) { AstPackage *pkg = c->info.init_package; Scope *s = pkg->scope; - for_array(i, s->elements.entries) { - Entity *e = s->elements.entries[i].value; + for (auto const &entry : s->elements) { + Entity *e = entry.value; if (e->kind != Entity_Procedure) { continue; } @@ -2512,15 +2508,15 @@ Array generate_entity_dependency_graph(CheckerInfo *info, gbA TIME_SECTION("generate_entity_dependency_graph: Calculate edges for graph M - Part 1"); // Calculate edges for graph M - for_array(i, M.entries) { - EntityGraphNode *n = M.entries[i].value; + for (auto const &entry : M) { + EntityGraphNode *n = entry.value; Entity *e = n->entity; DeclInfo *decl = decl_info_of_entity(e); GB_ASSERT(decl != nullptr); - for_array(j, decl->deps.entries) { - Entity *dep = decl->deps.entries[j].ptr; + for (auto const &entry : decl->deps) { + Entity *dep = entry.ptr; if (dep->flags & EntityFlag_Field) { continue; } @@ -2539,23 +2535,22 @@ Array generate_entity_dependency_graph(CheckerInfo *info, gbA TIME_SECTION("generate_entity_dependency_graph: Calculate edges for graph M - Part 2"); auto G = array_make(allocator, 0, M.entries.count); - for_array(i, M.entries) { - auto *entry = &M.entries[i]; - auto *e = entry->key; - EntityGraphNode *n = entry->value; + for (auto const &m_entry : M) { + auto *e = m_entry.key; + EntityGraphNode *n = m_entry.value; if (e->kind == Entity_Procedure) { // Connect each pred 'p' of 'n' with each succ 's' and from // the procedure node - for_array(j, n->pred.entries) { - EntityGraphNode *p = n->pred.entries[j].ptr; + for (auto const &p_entry : n->pred) { + EntityGraphNode *p = p_entry.ptr; // Ignore self-cycles if (p != n) { // Each succ 's' of 'n' becomes a succ of 'p', and // each pred 'p' of 'n' becomes a pred of 's' - for_array(k, n->succ.entries) { - EntityGraphNode *s = n->succ.entries[k].ptr; + for (auto const &s_entry : n->succ) { + EntityGraphNode *s = s_entry.ptr; // Ignore self-cycles if (s != n) { if (p->entity->kind == Entity_Procedure && @@ -4273,9 +4268,10 @@ Array generate_import_dependency_graph(Checker *c) { Array G = {}; array_init(&G, heap_allocator(), 0, M.entries.count); - for_array(i, M.entries) { - auto n = M.entries[i].value; - n->index = i; + isize i = 0; + for (auto const &entry : M) { + auto n = entry.value; + n->index = i++; n->dep_count = n->succ.entries.count; GB_ASSERT(n->dep_count >= 0); array_add(&G, n); @@ -4376,8 +4372,8 @@ void check_add_import_decl(CheckerContext *ctx, Ast *decl) { } else { AstPackage **found = string_map_get(pkgs, id->fullpath); if (found == nullptr) { - for_array(pkg_index, pkgs->entries) { - AstPackage *pkg = pkgs->entries[pkg_index].value; + for (auto const &entry : *pkgs) { + AstPackage *pkg = entry.value; gb_printf_err("%.*s\n", LIT(pkg->fullpath)); } gb_printf_err("%s\n", token_pos_to_string(token.pos)); @@ -4871,8 +4867,8 @@ void check_import_entities(Checker *c) { } } - for_array(i, n->pred.entries) { - ImportGraphNode *p = n->pred.entries[i].ptr; + for (auto const &entry : n->pred) { + ImportGraphNode *p = entry.ptr; p->dep_count = gb_max(p->dep_count-1, 0); priority_queue_fix(&pq, p->index); } @@ -4979,8 +4975,8 @@ bool find_entity_path_tuple(Type *tuple, Entity *end, PtrSet *visited, if (var_decl == nullptr) { continue; } - for_array(i, var_decl->deps.entries) { - Entity *dep = var_decl->deps.entries[i].ptr; + for (auto const &entry : var_decl->deps) { + Entity *dep = entry.ptr; if (dep == end) { auto path = array_make(heap_allocator()); array_add(&path, dep); @@ -5032,8 +5028,8 @@ Array find_entity_path(Entity *start, Entity *end, PtrSet *v return path; } } else { - for_array(i, decl->deps.entries) { - Entity *dep = decl->deps.entries[i].ptr; + for (auto const &entry : decl->deps) { + Entity *dep = entry.ptr; if (dep == end) { auto path = array_make(heap_allocator()); array_add(&path, dep); @@ -5091,8 +5087,8 @@ void calculate_global_init_order(Checker *c) { } } - for_array(i, n->pred.entries) { - EntityGraphNode *p = n->pred.entries[i].ptr; + for (auto const &entry : n->pred) { + EntityGraphNode *p = entry.ptr; p->dep_count -= 1; p->dep_count = gb_max(p->dep_count, 0); priority_queue_fix(&pq, p->index); @@ -5217,8 +5213,8 @@ void check_unchecked_bodies(Checker *c) { map_init(&untyped, heap_allocator()); defer (map_destroy(&untyped)); - for_array(i, c->info.minimum_dependency_set.entries) { - Entity *e = c->info.minimum_dependency_set.entries[i].ptr; + for (auto const &entry : c->info.minimum_dependency_set) { + Entity *e = entry.ptr; if (e == nullptr || e->kind != Entity_Procedure) { continue; } @@ -5267,8 +5263,8 @@ void check_test_procedures(Checker *c) { AstPackage *pkg = c->info.init_package; Scope *s = pkg->scope; - for_array(i, build_context.test_names.entries) { - String name = build_context.test_names.entries[i].value; + for (auto const &entry : build_context.test_names) { + String name = entry.value; Entity *e = scope_lookup(s, name); if (e == nullptr) { Token tok = {}; @@ -5422,9 +5418,9 @@ void add_untyped_expressions(CheckerInfo *cinfo, UntypedExprInfoMap *untyped) { if (untyped == nullptr) { return; } - for_array(i, untyped->entries) { - Ast *expr = untyped->entries[i].key; - ExprInfo *info = untyped->entries[i].value; + for (auto const &entry : *untyped) { + Ast *expr = entry.key; + ExprInfo *info = entry.value; if (expr != nullptr && info != nullptr) { mpmc_enqueue(&cinfo->checker->global_untyped_queue, UntypedExprInfo{expr, info}); } @@ -5590,8 +5586,8 @@ void check_unique_package_names(Checker *c) { string_map_init(&pkgs, heap_allocator(), 2*c->info.packages.entries.count); defer (string_map_destroy(&pkgs)); - for_array(i, c->info.packages.entries) { - AstPackage *pkg = c->info.packages.entries[i].value; + for (auto const &entry : c->info.packages) { + AstPackage *pkg = entry.value; if (pkg->files.count == 0) { continue; // Sanity check } @@ -5752,8 +5748,8 @@ void check_parsed_files(Checker *c) { check_merge_queues_into_arrays(c); TIME_SECTION("check scope usage"); - for_array(i, c->info.files.entries) { - AstFile *f = c->info.files.entries[i].value; + for (auto const &entry : c->info.files) { + AstFile *f = entry.value; check_scope_usage(c, f->scope); } @@ -5789,8 +5785,8 @@ void check_parsed_files(Checker *c) { DeclInfo *decl = e->decl_info; ast_node(pl, ProcLit, decl->proc_lit); if (pl->inlining == ProcInlining_inline) { - for_array(j, decl->deps.entries) { - Entity *dep = decl->deps.entries[j].ptr; + for (auto const &entry : decl->deps) { + Entity *dep = entry.ptr; if (dep == e) { error(e->token, "Cannot inline recursive procedure '%.*s'", LIT(e->token.string)); break; diff --git a/src/docs.cpp b/src/docs.cpp index 3ea3cce1b..b07181e28 100644 --- a/src/docs.cpp +++ b/src/docs.cpp @@ -222,8 +222,8 @@ void print_doc_package(CheckerInfo *info, AstPackage *pkg) { if (pkg->scope != nullptr) { auto entities = array_make(heap_allocator(), 0, pkg->scope->elements.entries.count); defer (array_free(&entities)); - for_array(i, pkg->scope->elements.entries) { - Entity *e = pkg->scope->elements.entries[i].value; + for (auto const &entry : pkg->scope->elements) { + Entity *e = entry.value; switch (e->kind) { case Entity_Invalid: case Entity_Builtin: @@ -359,8 +359,8 @@ void generate_documentation(Checker *c) { odin_doc_write(info, output_file_path); } else { auto pkgs = array_make(permanent_allocator(), 0, info->packages.entries.count); - for_array(i, info->packages.entries) { - AstPackage *pkg = info->packages.entries[i].value; + for (auto const &entry : info->packages) { + AstPackage *pkg = entry.value; if (build_context.cmd_doc_flags & CmdDocFlag_AllPackages) { array_add(&pkgs, pkg); } else { diff --git a/src/docs_writer.cpp b/src/docs_writer.cpp index 5246971ff..313d7b25a 100644 --- a/src/docs_writer.cpp +++ b/src/docs_writer.cpp @@ -480,11 +480,11 @@ OdinDocTypeIndex odin_doc_type(OdinDocWriter *w, Type *type) { if (found) { return *found; } - for_array(i, w->type_cache.entries) { + for (auto const &entry : w->type_cache) { // NOTE(bill): THIS IS SLOW - Type *other = w->type_cache.entries[i].key; + Type *other = entry.key; if (are_types_identical_unique_tuples(type, other)) { - OdinDocTypeIndex index = w->type_cache.entries[i].value; + OdinDocTypeIndex index = entry.value; map_set(&w->type_cache, type, index); return index; } @@ -914,23 +914,21 @@ OdinDocEntityIndex odin_doc_add_entity(OdinDocWriter *w, Entity *e) { void odin_doc_update_entities(OdinDocWriter *w) { { // NOTE(bill): Double pass, just in case entities are created on odin_doc_type - auto entities = array_make(heap_allocator(), w->entity_cache.entries.count); + auto entities = array_make(heap_allocator(), 0, w->entity_cache.entries.count); defer (array_free(&entities)); - for_array(i, w->entity_cache.entries) { - Entity *e = w->entity_cache.entries[i].key; - entities[i] = e; + for (auto const &entry : w->entity_cache) { + array_add(&entities, entry.key); } - for_array(i, entities) { - Entity *e = entities[i]; + for (Entity *e : entities) { OdinDocTypeIndex type_index = odin_doc_type(w, e->type); gb_unused(type_index); } } - for_array(i, w->entity_cache.entries) { - Entity *e = w->entity_cache.entries[i].key; - OdinDocEntityIndex entity_index = w->entity_cache.entries[i].value; + for (auto const &entry : w->entity_cache) { + Entity *e = entry.key; + OdinDocEntityIndex entity_index = entry.value; OdinDocTypeIndex type_index = odin_doc_type(w, e->type); OdinDocEntityIndex foreign_library = 0; @@ -948,8 +946,8 @@ void odin_doc_update_entities(OdinDocWriter *w) { auto pges = array_make(heap_allocator(), 0, e->ProcGroup.entities.count); defer (array_free(&pges)); - for_array(j, e->ProcGroup.entities) { - OdinDocEntityIndex index = odin_doc_add_entity(w, e->ProcGroup.entities[j]); + for (Entity *entity : e->ProcGroup.entities) { + OdinDocEntityIndex index = odin_doc_add_entity(w, entity); array_add(&pges, index); } grouped_entities = odin_write_slice(w, pges.data, pges.count); @@ -979,9 +977,9 @@ OdinDocArray odin_doc_add_pkg_entries(OdinDocWriter *w, AstPa auto entries = array_make(heap_allocator(), 0, w->entity_cache.entries.count); defer (array_free(&entries)); - for_array(i, pkg->scope->elements.entries) { - String name = pkg->scope->elements.entries[i].key.string; - Entity *e = pkg->scope->elements.entries[i].value; + for (auto const &entry : pkg->scope->elements) { + String name = entry.key.string; + Entity *e = entry.value; switch (e->kind) { case Entity_Invalid: case Entity_Nil: @@ -1021,8 +1019,8 @@ OdinDocArray odin_doc_add_pkg_entries(OdinDocWriter *w, AstPa void odin_doc_write_docs(OdinDocWriter *w) { auto pkgs = array_make(heap_allocator(), 0, w->info->packages.entries.count); defer (array_free(&pkgs)); - for_array(i, w->info->packages.entries) { - AstPackage *pkg = w->info->packages.entries[i].value; + for (auto const &entry : w->info->packages) { + AstPackage *pkg = entry.value; if (build_context.cmd_doc_flags & CmdDocFlag_AllPackages) { array_add(&pkgs, pkg); } else { diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index 1182beb53..2433dc9ba 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -1046,16 +1046,14 @@ void lb_finalize_objc_names(lbProcedure *p) { LLVMSetLinkage(p->value, LLVMInternalLinkage); lb_begin_procedure_body(p); - for_array(i, m->objc_classes.entries) { - auto const &entry = m->objc_classes.entries[i]; + for (auto const &entry : m->objc_classes) { String name = entry.key.string; args[0] = lb_const_value(m, t_cstring, exact_value_string(name)); lbValue ptr = lb_emit_runtime_call(p, "objc_lookUpClass", args); lb_addr_store(p, entry.value, ptr); } - for_array(i, m->objc_selectors.entries) { - auto const &entry = m->objc_selectors.entries[i]; + for (auto const &entry : m->objc_selectors) { String name = entry.key.string; args[0] = lb_const_value(m, t_cstring, exact_value_string(name)); lbValue ptr = lb_emit_runtime_call(p, "sel_registerName", args); @@ -1505,20 +1503,20 @@ WORKER_TASK_PROC(lb_llvm_function_pass_worker_proc) { } } - for_array(i, m->equal_procs.entries) { - lbProcedure *p = m->equal_procs.entries[i].value; + for (auto const &entry : m->equal_procs) { + lbProcedure *p = entry.value; lb_run_function_pass_manager(default_function_pass_manager, p); } - for_array(i, m->hasher_procs.entries) { - lbProcedure *p = m->hasher_procs.entries[i].value; + for (auto const &entry : m->hasher_procs) { + lbProcedure *p = entry.value; lb_run_function_pass_manager(default_function_pass_manager, p); } - for_array(i, m->map_get_procs.entries) { - lbProcedure *p = m->map_get_procs.entries[i].value; + for (auto const &entry : m->map_get_procs) { + lbProcedure *p = entry.value; lb_run_function_pass_manager(default_function_pass_manager, p); } - for_array(i, m->map_set_procs.entries) { - lbProcedure *p = m->map_set_procs.entries[i].value; + for (auto const &entry : m->map_set_procs) { + lbProcedure *p = entry.value; lb_run_function_pass_manager(default_function_pass_manager, p); } @@ -1636,8 +1634,8 @@ void lb_generate_code(lbGenerator *gen) { } char const *target_triple = alloc_cstring(permanent_allocator(), build_context.metrics.target_triplet); - for_array(i, gen->modules.entries) { - LLVMSetTarget(gen->modules.entries[i].value->mod, target_triple); + for (auto const &entry : gen->modules) { + LLVMSetTarget(entry.value->mod, target_triple); } LLVMTargetRef target = {}; @@ -1701,7 +1699,7 @@ void lb_generate_code(lbGenerator *gen) { // NOTE(bill): Target Machine Creation // NOTE(bill, 2021-05-04): Target machines must be unique to each module because they are not thread safe - auto target_machines = array_make(permanent_allocator(), gen->modules.entries.count); + auto target_machines = array_make(permanent_allocator(), 0, gen->modules.entries.count); // NOTE(dweiler): Dynamic libraries require position-independent code. LLVMRelocMode reloc_mode = LLVMRelocDefault; @@ -1727,21 +1725,25 @@ void lb_generate_code(lbGenerator *gen) { break; } - for_array(i, gen->modules.entries) { - target_machines[i] = LLVMCreateTargetMachine( + for (auto const entry : gen->modules) { + auto target_machine = LLVMCreateTargetMachine( target, target_triple, llvm_cpu, llvm_features, code_gen_level, reloc_mode, code_mode); - LLVMSetModuleDataLayout(gen->modules.entries[i].value->mod, LLVMCreateTargetDataLayout(target_machines[i])); + array_add(&target_machines, target_machine); + + lbModule *m = entry.value; + m->target_machine = target_machine; + LLVMSetModuleDataLayout(m->mod, LLVMCreateTargetDataLayout(target_machine)); } - for_array(i, gen->modules.entries) { - lbModule *m = gen->modules.entries[i].value; + for (auto const &entry : gen->modules) { + lbModule *m = entry.value; if (m->debug_builder) { // Debug Info - for_array(i, info->files.entries) { - AstFile *f = info->files.entries[i].value; + for (auto const &file_entry : info->files) { + AstFile *f = file_entry.value; String fullpath = f->fullpath; String filename = remove_directory_from_path(fullpath); String directory = directory_from_path(fullpath); @@ -2060,8 +2062,8 @@ void lb_generate_code(lbGenerator *gen) { gb_unused(startup_runtime); if (build_context.ODIN_DEBUG) { - for_array(i, builtin_pkg->scope->elements.entries) { - Entity *e = builtin_pkg->scope->elements.entries[i].value; + for (auto const &entry : builtin_pkg->scope->elements) { + Entity *e = entry.value; add_debug_info_for_global_constant_from_entity(gen, e); } } @@ -2130,10 +2132,9 @@ void lb_generate_code(lbGenerator *gen) { } TIME_SECTION("LLVM Procedure Generation"); - for_array(j, gen->modules.entries) { - lbModule *m = gen->modules.entries[j].value; - for_array(i, m->procedures_to_generate) { - lbProcedure *p = m->procedures_to_generate[i]; + for (auto const &entry : gen->modules) { + lbModule *m = entry.value; + for (lbProcedure *p : m->procedures_to_generate) { lb_generate_procedure(m, p); } } @@ -2143,10 +2144,9 @@ void lb_generate_code(lbGenerator *gen) { lb_create_main_procedure(default_module, startup_runtime); } - for_array(j, gen->modules.entries) { - lbModule *m = gen->modules.entries[j].value; - for_array(i, m->missing_procedures_to_check) { - lbProcedure *p = m->missing_procedures_to_check[i]; + for (auto const &entry : gen->modules) { + lbModule *m = entry.value; + for (lbProcedure *p : m->missing_procedures_to_check) { debugf("Generate missing procedure: %.*s\n", LIT(p->name)); lb_generate_procedure(m, p); } @@ -2155,24 +2155,9 @@ void lb_generate_code(lbGenerator *gen) { lb_finalize_objc_names(objc_names); if (build_context.ODIN_DEBUG) { - TIME_SECTION("LLVM Debug Info for global constant value declarations"); - { - // lbModule *m = default_module; - - - } - // if (gen->modules.entries.count == 1) { - // } else { - // for_array(j, gen->modules.entries) { - // lbModule *m = gen->modules.entries[j].value; - // if (m->debug_builder != nullptr) { - // } - // } - // } - TIME_SECTION("LLVM Debug Info Complete Types and Finalize"); - for_array(j, gen->modules.entries) { - lbModule *m = gen->modules.entries[j].value; + for (auto const &entry : gen->modules) { + lbModule *m = entry.value; if (m->debug_builder != nullptr) { lb_debug_complete_types(m); LLVMDIBuilderFinalize(m->debug_builder); @@ -2183,23 +2168,22 @@ void lb_generate_code(lbGenerator *gen) { TIME_SECTION("LLVM Function Pass"); - for_array(i, gen->modules.entries) { - lbModule *m = gen->modules.entries[i].value; - + for (auto const &entry : gen->modules) { + lbModule *m = entry.value; lb_llvm_function_pass_worker_proc(m); } TIME_SECTION("LLVM Module Pass"); - for_array(i, gen->modules.entries) { - lbModule *m = gen->modules.entries[i].value; + for (auto const &entry : gen->modules) { + lbModule *m = entry.value; lb_run_remove_unused_function_pass(m); lb_run_remove_unused_globals_pass(m); auto wd = gb_alloc_item(permanent_allocator(), lbLLVMModulePassWorkerData); wd->m = m; - wd->target_machine = target_machines[i]; + wd->target_machine = m->target_machine; lb_llvm_module_pass_worker_proc(wd); } @@ -2214,8 +2198,8 @@ void lb_generate_code(lbGenerator *gen) { } - for_array(j, gen->modules.entries) { - lbModule *m = gen->modules.entries[j].value; + for (auto const &entry : gen->modules) { + lbModule *m = entry.value; if (LLVMVerifyModule(m->mod, LLVMReturnStatusAction, &llvm_error)) { gb_printf_err("LLVM Error:\n%s\n", llvm_error); if (build_context.keep_temp_files) { @@ -2236,8 +2220,8 @@ void lb_generate_code(lbGenerator *gen) { build_context.build_mode == BuildMode_LLVM_IR) { TIME_SECTION("LLVM Print Module to File"); - for_array(j, gen->modules.entries) { - lbModule *m = gen->modules.entries[j].value; + for (auto const &entry : gen->modules) { + lbModule *m = entry.value; if (lb_is_module_empty(m)) { continue; @@ -2260,10 +2244,9 @@ void lb_generate_code(lbGenerator *gen) { TIME_SECTION("LLVM Add Foreign Library Paths"); - for_array(j, gen->modules.entries) { - lbModule *m = gen->modules.entries[j].value; - for_array(i, m->info->required_foreign_imports_through_force) { - Entity *e = m->info->required_foreign_imports_through_force[i]; + for (auto const &entry : gen->modules) { + lbModule *m = entry.value; + for (Entity *e : m->info->required_foreign_imports_through_force) { lb_add_foreign_library_path(m, e); } @@ -2275,16 +2258,16 @@ void lb_generate_code(lbGenerator *gen) { TIME_SECTION("LLVM Object Generation"); isize non_empty_module_count = 0; - for_array(j, gen->modules.entries) { - lbModule *m = gen->modules.entries[j].value; + for (auto const &entry : gen->modules) { + lbModule *m = entry.value; if (!lb_is_module_empty(m)) { non_empty_module_count += 1; } } if (do_threading && non_empty_module_count > 1) { - for_array(j, gen->modules.entries) { - lbModule *m = gen->modules.entries[j].value; + for (auto const &entry : gen->modules) { + lbModule *m = entry.value; if (lb_is_module_empty(m)) { continue; } @@ -2295,7 +2278,7 @@ void lb_generate_code(lbGenerator *gen) { array_add(&gen->output_temp_paths, filepath_ll); auto *wd = gb_alloc_item(permanent_allocator(), lbLLVMEmitWorker); - wd->target_machine = target_machines[j]; + wd->target_machine = m->target_machine; wd->code_gen_file_type = code_gen_file_type; wd->filepath_obj = filepath_obj; wd->m = m; @@ -2304,8 +2287,8 @@ void lb_generate_code(lbGenerator *gen) { thread_pool_wait(&global_thread_pool); } else { - for_array(j, gen->modules.entries) { - lbModule *m = gen->modules.entries[j].value; + for (auto const &entry : gen->modules) { + lbModule *m = entry.value; if (lb_is_module_empty(m)) { continue; } @@ -2319,7 +2302,7 @@ void lb_generate_code(lbGenerator *gen) { TIME_SECTION_WITH_LEN(section_name, gb_string_length(section_name)); - if (LLVMTargetMachineEmitToFile(target_machines[j], m->mod, cast(char *)filepath_obj.text, code_gen_file_type, &llvm_error)) { + if (LLVMTargetMachineEmitToFile(m->target_machine, m->mod, cast(char *)filepath_obj.text, code_gen_file_type, &llvm_error)) { gb_printf_err("LLVM Error: %s\n", llvm_error); gb_exit(1); return; diff --git a/src/llvm_backend.hpp b/src/llvm_backend.hpp index 911c915a8..a85056579 100644 --- a/src/llvm_backend.hpp +++ b/src/llvm_backend.hpp @@ -122,6 +122,7 @@ struct lbModule { LLVMContextRef ctx; struct lbGenerator *gen; + LLVMTargetMachineRef target_machine; CheckerInfo *info; AstPackage *pkg; // associated diff --git a/src/llvm_backend_general.cpp b/src/llvm_backend_general.cpp index 777755794..3ca98845a 100644 --- a/src/llvm_backend_general.cpp +++ b/src/llvm_backend_general.cpp @@ -137,8 +137,8 @@ bool lb_init_generator(lbGenerator *gen, Checker *c) { ptr_set_init(&gen->foreign_libraries_set, heap_allocator(), 1024); if (USE_SEPARATE_MODULES) { - for_array(i, gen->info->packages.entries) { - AstPackage *pkg = gen->info->packages.entries[i].value; + for (auto const &entry : gen->info->packages) { + AstPackage *pkg = entry.value; auto m = gb_alloc_item(permanent_allocator(), lbModule); m->pkg = pkg; @@ -153,8 +153,8 @@ bool lb_init_generator(lbGenerator *gen, Checker *c) { lb_init_module(&gen->default_module, c); - for_array(i, gen->modules.entries) { - lbModule *m = gen->modules.entries[i].value; + for (auto const &entry : gen->modules) { + lbModule *m = entry.value; LLVMContextRef ctx = LLVMGetModuleContext(m->mod); map_set(&gen->modules_through_ctx, ctx, m); } diff --git a/src/ptr_map.cpp b/src/ptr_map.cpp index 43e793b8a..ed4b20bf8 100644 --- a/src/ptr_map.cpp +++ b/src/ptr_map.cpp @@ -339,3 +339,24 @@ void multi_map_remove_all(PtrMap *h, K key) { } } #endif + + +template +PtrMapEntry *begin(PtrMap &m) { + return m.entries.data; +} +template +PtrMapEntry const *begin(PtrMap const &m) { + return m.entries.data; +} + + +template +PtrMapEntry *end(PtrMap &m) { + return m.entries.data + m.entries.count; +} + +template +PtrMapEntry const *end(PtrMap const &m) { + return m.entries.data + m.entries.count; +} diff --git a/src/ptr_set.cpp b/src/ptr_set.cpp index ffe48d69a..04ce162e2 100644 --- a/src/ptr_set.cpp +++ b/src/ptr_set.cpp @@ -233,3 +233,24 @@ gb_inline void ptr_set_clear(PtrSet *s) { s->hashes.data[i] = MAP_SENTINEL; } } + + +template +PtrSetEntry *begin(PtrSet &m) { + return m.entries.data; +} +template +PtrSetEntry const *begin(PtrSet const &m) { + return m.entries.data; +} + + +template +PtrSetEntry *end(PtrSet &m) { + return m.entries.data + m.entries.count; +} + +template +PtrSetEntry const *end(PtrSet const &m) { + return m.entries.data + m.entries.count; +} \ No newline at end of file diff --git a/src/query_data.cpp b/src/query_data.cpp index 71c21f2ba..ebf955fd4 100644 --- a/src/query_data.cpp +++ b/src/query_data.cpp @@ -449,8 +449,8 @@ void generate_and_print_query_data_global_definitions(Checker *c, Timings *timin auto sorted_packages = array_make(query_value_allocator, 0, c->info.packages.entries.count); defer (array_free(&sorted_packages)); - for_array(i, c->info.packages.entries) { - AstPackage *pkg = c->info.packages.entries[i].value; + for (auto const &entry : c->info.packages) { + AstPackage *pkg = entry.value; if (pkg != nullptr) { array_add(&sorted_packages, pkg); } @@ -880,8 +880,8 @@ void generate_and_print_query_data_go_to_definitions(Checker *c) { isize file_path_memory_needed = 0; auto files = array_make(a, 0, c->info.files.entries.count); - for_array(i, c->info.files.entries) { - AstFile *f = c->info.files.entries[i].value; + for (auto const &entry : c->info.files) { + AstFile *f = entry.value; file_path_memory_needed += f->fullpath.len+1; // add NUL terminator diff --git a/src/string_map.cpp b/src/string_map.cpp index 218a45482..e2a4d5f65 100644 --- a/src/string_map.cpp +++ b/src/string_map.cpp @@ -30,6 +30,8 @@ struct StringMapEntry { template struct StringMap { + using K = String; + using V = T; Slice hashes; Array > entries; }; @@ -270,3 +272,24 @@ gb_inline void string_map_clear(StringMap *h) { } } + + +template +StringMapEntry *begin(StringMap &m) { + return m.entries.data; +} +template +StringMapEntry const *begin(StringMap const &m) { + return m.entries.data; +} + + +template +StringMapEntry *end(StringMap &m) { + return m.entries.data + m.entries.count; +} + +template +StringMapEntry const *end(StringMap const &m) { + return m.entries.data + m.entries.count; +} \ No newline at end of file diff --git a/src/string_set.cpp b/src/string_set.cpp index 746ad9529..fce98ec75 100644 --- a/src/string_set.cpp +++ b/src/string_set.cpp @@ -215,3 +215,21 @@ gb_inline void string_set_clear(StringSet *s) { s->hashes.data[i] = MAP_SENTINEL; } } + + + +StringSetEntry *begin(StringSet &m) { + return m.entries.data; +} +StringSetEntry const *begin(StringSet const &m) { + return m.entries.data; +} + + +StringSetEntry *end(StringSet &m) { + return m.entries.data + m.entries.count; +} + +StringSetEntry const *end(StringSet const &m) { + return m.entries.data + m.entries.count; +} \ No newline at end of file diff --git a/src/types.cpp b/src/types.cpp index 28628fd97..9bdbf8d86 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -828,8 +828,8 @@ bool type_ptr_set_exists(PtrSet *s, Type *t) { // TODO(bill, 2019-10-05): This is very slow and it's probably a lot // faster to cache types correctly - for_array(i, s->entries) { - Type *f = s->entries[i].ptr; + for (auto const &entry : *s) { + Type *f = entry.ptr; if (are_types_identical(t, f)) { ptr_set_add(s, t); return true; -- cgit v1.2.3 From be22f0d1e1d5bb7c822dd31b1b60d7863fca6264 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Fri, 9 Dec 2022 11:32:52 +0000 Subject: Fix variable shadow in compiler --- src/docs_writer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/docs_writer.cpp b/src/docs_writer.cpp index 313d7b25a..b7b17cb1a 100644 --- a/src/docs_writer.cpp +++ b/src/docs_writer.cpp @@ -977,9 +977,9 @@ OdinDocArray odin_doc_add_pkg_entries(OdinDocWriter *w, AstPa auto entries = array_make(heap_allocator(), 0, w->entity_cache.entries.count); defer (array_free(&entries)); - for (auto const &entry : pkg->scope->elements) { - String name = entry.key.string; - Entity *e = entry.value; + for (auto const &element : pkg->scope->elements) { + String name = element.key.string; + Entity *e = element.value; switch (e->kind) { case Entity_Invalid: case Entity_Nil: -- cgit v1.2.3 From 144e357fd2cc85d16c04449730c25b0f1aa2390f Mon Sep 17 00:00:00 2001 From: gingerBill Date: Fri, 9 Dec 2022 11:37:15 +0000 Subject: Add extra check --- src/check_stmt.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index 720b15c9c..3fe6699ea 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -1949,6 +1949,7 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) { entity = alloc_entity_variable(ctx->scope, token, type, EntityState_Resolved); entity->flags |= EntityFlag_ForValue; entity->flags |= EntityFlag_Value; + entity->identifier = name; if (i == addressable_index && use_by_reference_for_value) { entity->flags &= ~EntityFlag_Value; } @@ -1973,6 +1974,7 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) { if (entity == nullptr) { entity = alloc_entity_dummy_variable(builtin_pkg->scope, ast_token(name)); + entity->identifier = name; // might not be an identifier } array_add(&entities, entity); -- cgit v1.2.3 From 5c3624eb86d1cad9076a3df198221101d92d8bde Mon Sep 17 00:00:00 2001 From: gingerBill Date: Fri, 9 Dec 2022 12:18:49 +0000 Subject: Fix map looping --- src/llvm_backend.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index 2433dc9ba..0a7aec95d 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -1725,18 +1725,17 @@ void lb_generate_code(lbGenerator *gen) { break; } - for (auto const entry : gen->modules) { - auto target_machine = LLVMCreateTargetMachine( + for (auto const &entry : gen->modules) { + LLVMTargetMachineRef target_machine = LLVMCreateTargetMachine( target, target_triple, llvm_cpu, llvm_features, code_gen_level, reloc_mode, code_mode); - array_add(&target_machines, target_machine); - lbModule *m = entry.value; m->target_machine = target_machine; LLVMSetModuleDataLayout(m->mod, LLVMCreateTargetDataLayout(target_machine)); + array_add(&target_machines, target_machine); } for (auto const &entry : gen->modules) { @@ -2134,7 +2133,8 @@ void lb_generate_code(lbGenerator *gen) { TIME_SECTION("LLVM Procedure Generation"); for (auto const &entry : gen->modules) { lbModule *m = entry.value; - for (lbProcedure *p : m->procedures_to_generate) { + for_array(i, m->procedures_to_generate) { + lbProcedure *p = m->procedures_to_generate[i]; lb_generate_procedure(m, p); } } @@ -2146,7 +2146,8 @@ void lb_generate_code(lbGenerator *gen) { for (auto const &entry : gen->modules) { lbModule *m = entry.value; - for (lbProcedure *p : m->missing_procedures_to_check) { + for_array(i, m->missing_procedures_to_check) { + lbProcedure *p = m->missing_procedures_to_check[i]; debugf("Generate missing procedure: %.*s\n", LIT(p->name)); lb_generate_procedure(m, p); } @@ -2177,7 +2178,6 @@ void lb_generate_code(lbGenerator *gen) { for (auto const &entry : gen->modules) { lbModule *m = entry.value; - lb_run_remove_unused_function_pass(m); lb_run_remove_unused_globals_pass(m); @@ -2222,7 +2222,6 @@ void lb_generate_code(lbGenerator *gen) { for (auto const &entry : gen->modules) { lbModule *m = entry.value; - if (lb_is_module_empty(m)) { continue; } @@ -2246,7 +2245,8 @@ void lb_generate_code(lbGenerator *gen) { for (auto const &entry : gen->modules) { lbModule *m = entry.value; - for (Entity *e : m->info->required_foreign_imports_through_force) { + for_array(i, m->info->required_foreign_imports_through_force) { + Entity *e = m->info->required_foreign_imports_through_force[i]; lb_add_foreign_library_path(m, e); } -- cgit v1.2.3 From ff6b76986a0647ffc7d99c7e7df78ec8e5fb91b2 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Fri, 9 Dec 2022 12:32:54 +0000 Subject: Use C++11 loops for some arrays --- src/llvm_backend.cpp | 85 ++++++++++++++++++++++++---------------------------- 1 file changed, 39 insertions(+), 46 deletions(-) (limited to 'src') diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index 0a7aec95d..0a44b0939 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -1086,76 +1086,75 @@ lbProcedure *lb_create_startup_runtime(lbModule *main_module, lbProcedure *start LLVMBuildCall2(p->builder, lb_type_internal_for_procedures_raw(main_module, objc_names->type), objc_names->value, nullptr, 0, ""); } - for_array(i, global_variables) { - auto *var = &global_variables[i]; - if (var->is_initialized) { + for (auto &var : global_variables) { + if (var.is_initialized) { continue; } lbModule *entity_module = main_module; - Entity *e = var->decl->entity; + Entity *e = var.decl->entity; GB_ASSERT(e->kind == Entity_Variable); e->code_gen_module = entity_module; - Ast *init_expr = var->decl->init_expr; + Ast *init_expr = var.decl->init_expr; if (init_expr != nullptr) { lbValue init = lb_build_expr(p, init_expr); if (init.value == nullptr) { - LLVMTypeRef global_type = llvm_addr_type(p->module, var->var); + LLVMTypeRef global_type = llvm_addr_type(p->module, var.var); if (is_type_untyped_undef(init.type)) { - // LLVMSetInitializer(var->var.value, LLVMGetUndef(global_type)); - LLVMSetInitializer(var->var.value, LLVMConstNull(global_type)); - var->is_initialized = true; + // LLVMSetInitializer(var.var.value, LLVMGetUndef(global_type)); + LLVMSetInitializer(var.var.value, LLVMConstNull(global_type)); + var.is_initialized = true; continue; } else if (is_type_untyped_nil(init.type)) { - LLVMSetInitializer(var->var.value, LLVMConstNull(global_type)); - var->is_initialized = true; + LLVMSetInitializer(var.var.value, LLVMConstNull(global_type)); + var.is_initialized = true; continue; } GB_PANIC("Invalid init value, got %s", expr_to_string(init_expr)); } if (is_type_any(e->type) || is_type_union(e->type)) { - var->init = init; + var.init = init; } else if (lb_is_const_or_global(init)) { - if (!var->is_initialized) { + if (!var.is_initialized) { if (is_type_proc(init.type)) { init.value = LLVMConstPointerCast(init.value, lb_type(p->module, init.type)); } - LLVMSetInitializer(var->var.value, init.value); - var->is_initialized = true; + LLVMSetInitializer(var.var.value, init.value); + var.is_initialized = true; continue; } } else { - var->init = init; + var.init = init; } } - if (var->init.value != nullptr) { - GB_ASSERT(!var->is_initialized); - Type *t = type_deref(var->var.type); + if (var.init.value != nullptr) { + GB_ASSERT(!var.is_initialized); + Type *t = type_deref(var.var.type); if (is_type_any(t)) { // NOTE(bill): Edge case for 'any' type - Type *var_type = default_type(var->init.type); - lbAddr g = lb_add_global_generated(main_module, var_type, var->init); - lb_addr_store(p, g, var->init); + Type *var_type = default_type(var.init.type); + lbAddr g = lb_add_global_generated(main_module, var_type, var.init); + lb_addr_store(p, g, var.init); lbValue gp = lb_addr_get_ptr(p, g); - lbValue data = lb_emit_struct_ep(p, var->var, 0); - lbValue ti = lb_emit_struct_ep(p, var->var, 1); + lbValue data = lb_emit_struct_ep(p, var.var, 0); + lbValue ti = lb_emit_struct_ep(p, var.var, 1); lb_emit_store(p, data, lb_emit_conv(p, gp, t_rawptr)); lb_emit_store(p, ti, lb_type_info(main_module, var_type)); } else { - LLVMTypeRef vt = llvm_addr_type(p->module, var->var); - lbValue src0 = lb_emit_conv(p, var->init, t); + LLVMTypeRef vt = llvm_addr_type(p->module, var.var); + lbValue src0 = lb_emit_conv(p, var.init, t); LLVMValueRef src = OdinLLVMBuildTransmute(p, src0.value, vt); - LLVMValueRef dst = var->var.value; + LLVMValueRef dst = var.var.value; LLVMBuildStore(p->builder, src, dst); } - var->is_initialized = true; + var.is_initialized = true; } } @@ -1253,8 +1252,8 @@ lbProcedure *lb_create_main_procedure(lbModule *m, lbProcedure *startup_runtime) LLVMValueRef indices[2] = {}; indices[0] = LLVMConstInt(lb_type(m, t_i32), 0, false); - for_array(i, m->info->testing_procedures) { - Entity *testing_proc = m->info->testing_procedures[i]; + isize testing_proc_index = 0; + for (Entity *testing_proc : m->info->testing_procedures) { String name = testing_proc->token.string; String pkg_name = {}; @@ -1265,7 +1264,7 @@ lbProcedure *lb_create_main_procedure(lbModule *m, lbProcedure *startup_runtime) lbValue v_name = lb_find_or_add_entity_string(m, name); lbValue v_proc = lb_find_procedure_value_from_entity(m, testing_proc); - indices[1] = LLVMConstInt(lb_type(m, t_int), i, false); + indices[1] = LLVMConstInt(lb_type(m, t_int), testing_proc_index++, false); LLVMValueRef vals[3] = {}; vals[0] = v_pkg.value; @@ -1473,9 +1472,7 @@ WORKER_TASK_PROC(lb_llvm_function_pass_worker_proc) { lb_populate_function_pass_manager(m, default_function_pass_manager_without_memcpy, true, build_context.optimization_level); LLVMFinalizeFunctionPassManager(default_function_pass_manager_without_memcpy); - - for_array(i, m->procedures_to_generate) { - lbProcedure *p = m->procedures_to_generate[i]; + for (lbProcedure *p : m->procedures_to_generate) { if (p->body != nullptr) { // Build Procedure if (p->flags & lbProcedureFlag_WithoutMemcpyPass) { lb_run_function_pass_manager(default_function_pass_manager_without_memcpy, p); @@ -1818,9 +1815,7 @@ void lb_generate_code(lbGenerator *gen) { // NOTE(bill): Removes need for heap allocation by making it global memory isize count = 0; - for_array(entry_index, m->info->type_info_types) { - Type *t = m->info->type_info_types[entry_index]; - + for (Type *t : m->info->type_info_types) { isize index = lb_type_info_index(m->info, t, false); if (index < 0) { continue; @@ -1891,8 +1886,7 @@ void lb_generate_code(lbGenerator *gen) { isize global_variable_max_count = 0; bool already_has_entry_point = false; - for_array(i, info->entities) { - Entity *e = info->entities[i]; + for (Entity *e : info->entities) { String name = e->token.string; if (e->kind == Entity_Variable) { @@ -1921,9 +1915,7 @@ void lb_generate_code(lbGenerator *gen) { auto global_variables = array_make(permanent_allocator(), 0, global_variable_max_count); - for_array(i, info->variable_init_order) { - DeclInfo *d = info->variable_init_order[i]; - + for (DeclInfo *d : info->variable_init_order) { Entity *e = d->entity; if ((e->scope->flags & ScopeFlag_File) == 0) { @@ -2068,8 +2060,7 @@ void lb_generate_code(lbGenerator *gen) { } TIME_SECTION("LLVM Global Procedures and Types"); - for_array(i, info->entities) { - Entity *e = info->entities[i]; + for (Entity *e : info->entities) { String name = e->token.string; Scope * scope = e->scope; @@ -2133,7 +2124,8 @@ void lb_generate_code(lbGenerator *gen) { TIME_SECTION("LLVM Procedure Generation"); for (auto const &entry : gen->modules) { lbModule *m = entry.value; - for_array(i, m->procedures_to_generate) { + // NOTE(bill): procedures may be added during generation + for (isize i = 0; i < m->procedures_to_generate.count; i++) { lbProcedure *p = m->procedures_to_generate[i]; lb_generate_procedure(m, p); } @@ -2146,7 +2138,8 @@ void lb_generate_code(lbGenerator *gen) { for (auto const &entry : gen->modules) { lbModule *m = entry.value; - for_array(i, m->missing_procedures_to_check) { + // NOTE(bill): procedures may be added during generation + for (isize i = 0; i < m->missing_procedures_to_check.count; i++) { lbProcedure *p = m->missing_procedures_to_check[i]; debugf("Generate missing procedure: %.*s\n", LIT(p->name)); lb_generate_procedure(m, p); -- cgit v1.2.3 From ac5f5a33e94054396de66a37043e226349b6c91c Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 18 Dec 2022 21:17:07 +0000 Subject: `gb_internal` a lot --- src/array.cpp | 150 +++++++-------- src/big_int.cpp | 158 ++++++++-------- src/build_settings.cpp | 83 ++++----- src/common.cpp | 90 ++++----- src/common_memory.cpp | 74 ++++---- src/error.cpp | 62 +++---- src/exact_value.cpp | 90 ++++----- src/main.cpp | 42 ++--- src/microsoft_craziness.h | 40 ++-- src/parser.cpp | 460 +++++++++++++++++++++++----------------------- src/parser.hpp | 30 +-- src/parser_pos.cpp | 4 +- src/priority_queue.cpp | 14 +- src/ptr_map.cpp | 84 ++++----- src/ptr_set.cpp | 54 +++--- src/queue.cpp | 12 +- src/range_cache.cpp | 10 +- src/string.cpp | 124 ++++++------- src/string_map.cpp | 82 ++++----- src/thread_pool.cpp | 20 +- src/threading.cpp | 192 +++++++++---------- src/timings.cpp | 36 ++-- src/tokenizer.cpp | 70 +++---- src/types.cpp | 241 ++++++++++-------------- src/unicode.cpp | 10 +- 25 files changed, 1091 insertions(+), 1141 deletions(-) (limited to 'src') diff --git a/src/array.cpp b/src/array.cpp index d08bd647f..c633078f6 100644 --- a/src/array.cpp +++ b/src/array.cpp @@ -23,32 +23,32 @@ struct Array { } }; -template void array_init (Array *array, gbAllocator const &a); -template void array_init (Array *array, gbAllocator const &a, isize count); -template void array_init (Array *array, gbAllocator const &a, isize count, isize capacity); -template Array array_make (gbAllocator const &a); -template Array array_make (gbAllocator const &a, isize count); -template Array array_make (gbAllocator const &a, isize count, isize capacity); -template Array array_make_from_ptr (T *data, isize count, isize capacity); -template void array_free (Array *array); -template void array_add (Array *array, T const &t); -template T * array_add_and_get (Array *array); -template void array_add_elems (Array *array, T const *elems, isize elem_count); -template T array_pop (Array *array); -template void array_clear (Array *array); -template void array_reserve (Array *array, isize capacity); -template void array_resize (Array *array, isize count); -template void array_set_capacity (Array *array, isize capacity); -template Array array_slice (Array const &array, isize lo, isize hi); -template Array array_clone (gbAllocator const &a, Array const &array); - -template void array_ordered_remove (Array *array, isize index); -template void array_unordered_remove(Array *array, isize index); - -template void array_copy(Array *array, Array const &data, isize offset); -template void array_copy(Array *array, Array const &data, isize offset, isize count); - -template T *array_end_ptr(Array *array); +template gb_internal void array_init (Array *array, gbAllocator const &a); +template gb_internal void array_init (Array *array, gbAllocator const &a, isize count); +template gb_internal void array_init (Array *array, gbAllocator const &a, isize count, isize capacity); +template gb_internal Array array_make (gbAllocator const &a); +template gb_internal Array array_make (gbAllocator const &a, isize count); +template gb_internal Array array_make (gbAllocator const &a, isize count, isize capacity); +template gb_internal Array array_make_from_ptr (T *data, isize count, isize capacity); +template gb_internal void array_free (Array *array); +template gb_internal void array_add (Array *array, T const &t); +template gb_internal T * array_add_and_get (Array *array); +template gb_internal void array_add_elems (Array *array, T const *elems, isize elem_count); +template gb_internal T array_pop (Array *array); +template gb_internal void array_clear (Array *array); +template gb_internal void array_reserve (Array *array, isize capacity); +template gb_internal void array_resize (Array *array, isize count); +template gb_internal void array_set_capacity (Array *array, isize capacity); +template gb_internal Array array_slice (Array const &array, isize lo, isize hi); +template gb_internal Array array_clone (gbAllocator const &a, Array const &array); + +template gb_internal void array_ordered_remove (Array *array, isize index); +template gb_internal void array_unordered_remove(Array *array, isize index); + +template gb_internal void array_copy(Array *array, Array const &data, isize offset); +template gb_internal void array_copy(Array *array, Array const &data, isize offset, isize count); + +template gb_internal T *array_end_ptr(Array *array); template @@ -56,14 +56,14 @@ struct Slice { T *data; isize count; - T &operator[](isize index) { + gb_inline T &operator[](isize index) { #if !defined(NO_ARRAY_BOUNDS_CHECK) GB_ASSERT_MSG(0 <= index && index < count, "Index %td is out of bounds ranges 0..<%td", index, count); #endif return data[index]; } - T const &operator[](isize index) const { + gb_inline T const &operator[](isize index) const { #if !defined(NO_ARRAY_BOUNDS_CHECK) GB_ASSERT_MSG(0 <= index && index < count, "Index %td is out of bounds ranges 0..<%td", index, count); #endif @@ -71,12 +71,12 @@ struct Slice { } }; -template Slice slice_from_array(Array const &a); +template gb_internal Slice slice_from_array(Array const &a); template -Slice slice_make(gbAllocator const &allocator, isize count) { +gb_internal Slice slice_make(gbAllocator const &allocator, isize count) { GB_ASSERT(count >= 0); Slice s = {}; s.data = gb_alloc_array(allocator, T, count); @@ -86,7 +86,7 @@ Slice slice_make(gbAllocator const &allocator, isize count) { } template -void slice_init(Slice *s, gbAllocator const &allocator, isize count) { +gb_internal void slice_init(Slice *s, gbAllocator const &allocator, isize count) { GB_ASSERT(count >= 0); s->data = gb_alloc_array(allocator, T, count); if (count > 0) { @@ -96,23 +96,23 @@ void slice_init(Slice *s, gbAllocator const &allocator, isize count) { } template -void slice_free(Slice *s, gbAllocator const &allocator) { +gb_internal void slice_free(Slice *s, gbAllocator const &allocator) { gb_free(allocator, s->data); } template -void slice_resize(Slice *s, gbAllocator const &allocator, isize new_count) { +gb_internal void slice_resize(Slice *s, gbAllocator const &allocator, isize new_count) { resize_array_raw(&s->data, allocator, s->count, new_count); s->count = new_count; } template -Slice slice_from_array(Array const &a) { +gb_internal Slice slice_from_array(Array const &a) { return {a.data, a.count}; } template -Slice slice_array(Array const &array, isize lo, isize hi) { +gb_internal Slice slice_array(Array const &array, isize lo, isize hi) { GB_ASSERT(0 <= lo && lo <= hi && hi <= array.count); Slice out = {}; isize len = hi-lo; @@ -125,30 +125,30 @@ Slice slice_array(Array const &array, isize lo, isize hi) { template -Slice slice_clone(gbAllocator const &allocator, Slice const &a) { +gb_internal Slice slice_clone(gbAllocator const &allocator, Slice const &a) { T *data = cast(T *)gb_alloc_copy_align(allocator, a.data, a.count*gb_size_of(T), gb_align_of(T)); return {data, a.count}; } template -Slice slice_clone_from_array(gbAllocator const &allocator, Array const &a) { +gb_internal Slice slice_clone_from_array(gbAllocator const &allocator, Array const &a) { auto c = array_clone(allocator, a); return {c.data, c.count}; } template -void slice_copy(Slice *slice, Slice const &data) { +gb_internal void slice_copy(Slice *slice, Slice const &data) { isize n = gb_min(slice->count, data.count); gb_memmove(slice->data, data.data, gb_size_of(T)*n); } template -void slice_copy(Slice *slice, Slice const &data, isize offset) { +gb_internal void slice_copy(Slice *slice, Slice const &data, isize offset) { isize n = gb_clamp(slice->count-offset, 0, data.count); gb_memmove(slice->data+offset, data.data, gb_size_of(T)*n); } template -void slice_copy(Slice *slice, Slice const &data, isize offset, isize count) { +gb_internal void slice_copy(Slice *slice, Slice const &data, isize offset, isize count) { isize n = gb_clamp(slice->count-offset, 0, gb_min(data.count, count)); gb_memmove(slice->data+offset, data.data, gb_size_of(T)*n); } @@ -156,7 +156,7 @@ void slice_copy(Slice *slice, Slice const &data, isize offset, isize count template -gb_inline Slice slice(Slice const &array, isize lo, isize hi) { +gb_internal gb_inline Slice slice(Slice const &array, isize lo, isize hi) { GB_ASSERT(0 <= lo && lo <= hi && hi <= array.count); Slice out = {}; isize len = hi-lo; @@ -169,7 +169,7 @@ gb_inline Slice slice(Slice const &array, isize lo, isize hi) { template -void slice_ordered_remove(Slice *array, isize index) { +gb_internal void slice_ordered_remove(Slice *array, isize index) { GB_ASSERT(0 <= index && index < array->count); isize bytes = gb_size_of(T) * (array->count-(index+1)); @@ -178,7 +178,7 @@ void slice_ordered_remove(Slice *array, isize index) { } template -void slice_unordered_remove(Slice *array, isize index) { +gb_internal void slice_unordered_remove(Slice *array, isize index) { GB_ASSERT(0 <= index && index < array->count); isize n = array->count-1; @@ -190,18 +190,18 @@ void slice_unordered_remove(Slice *array, isize index) { template -void array_copy(Array *array, Array const &data, isize offset) { +gb_internal void array_copy(Array *array, Array const &data, isize offset) { gb_memmove(array->data+offset, data.data, gb_size_of(T)*data.count); } template -void array_copy(Array *array, Array const &data, isize offset, isize count) { +gb_internal void array_copy(Array *array, Array const &data, isize offset, isize count) { gb_memmove(array->data+offset, data.data, gb_size_of(T)*gb_min(data.count, count)); } template -T *array_end_ptr(Array *array) { +gb_internal T *array_end_ptr(Array *array) { if (array->count > 0) { return &array->data[array->count-1]; } @@ -210,18 +210,18 @@ T *array_end_ptr(Array *array) { template -gb_inline void array_init(Array *array, gbAllocator const &a) { +gb_internal gb_inline void array_init(Array *array, gbAllocator const &a) { isize cap = ARRAY_GROW_FORMULA(0); array_init(array, a, 0, cap); } template -gb_inline void array_init(Array *array, gbAllocator const &a, isize count) { +gb_internal gb_inline void array_init(Array *array, gbAllocator const &a, isize count) { array_init(array, a, count, count); } template -gb_inline void array_init(Array *array, gbAllocator const &a, isize count, isize capacity) { +gb_internal gb_inline void array_init(Array *array, gbAllocator const &a, isize count, isize capacity) { array->allocator = a; array->data = nullptr; if (capacity > 0) { @@ -234,7 +234,7 @@ gb_inline void array_init(Array *array, gbAllocator const &a, isize count, is template -gb_inline Array array_make_from_ptr(T *data, isize count, isize capacity) { +gb_internal gb_inline Array array_make_from_ptr(T *data, isize count, isize capacity) { Array a = {0}; a.data = data; a.count = count; @@ -244,7 +244,7 @@ gb_inline Array array_make_from_ptr(T *data, isize count, isize capacity) { template -gb_inline Array array_make(gbAllocator const &a) { +gb_internal gb_inline Array array_make(gbAllocator const &a) { isize capacity = ARRAY_GROW_FORMULA(0); Array array = {}; array.allocator = a; @@ -254,7 +254,7 @@ gb_inline Array array_make(gbAllocator const &a) { return array; } template -gb_inline Array array_make(gbAllocator const &a, isize count) { +gb_internal gb_inline Array array_make(gbAllocator const &a, isize count) { Array array = {}; array.allocator = a; array.data = gb_alloc_array(a, T, count); @@ -263,7 +263,7 @@ gb_inline Array array_make(gbAllocator const &a, isize count) { return array; } template -gb_inline Array array_make(gbAllocator const &a, isize count, isize capacity) { +gb_internal gb_inline Array array_make(gbAllocator const &a, isize count, isize capacity) { Array array = {}; array.allocator = a; array.data = gb_alloc_array(a, T, capacity); @@ -275,7 +275,7 @@ gb_inline Array array_make(gbAllocator const &a, isize count, isize capacity) template -gb_inline void array_free(Array *array) { +gb_internal gb_inline void array_free(Array *array) { if (array->allocator.proc != nullptr) { gb_free(array->allocator, array->data); } @@ -284,7 +284,7 @@ gb_inline void array_free(Array *array) { } template -void array__grow(Array *array, isize min_capacity) { +gb_internal void array__grow(Array *array, isize min_capacity) { isize new_capacity = ARRAY_GROW_FORMULA(array->capacity); if (new_capacity < min_capacity) { new_capacity = min_capacity; @@ -293,7 +293,7 @@ void array__grow(Array *array, isize min_capacity) { } template -void array_add(Array *array, T const &t) { +gb_internal void array_add(Array *array, T const &t) { if (array->capacity < array->count+1) { array__grow(array, 0); } @@ -302,7 +302,7 @@ void array_add(Array *array, T const &t) { } template -T *array_add_and_get(Array *array) { +gb_internal T *array_add_and_get(Array *array) { if (array->count < array->capacity) { return &array->data[array->count++]; } @@ -314,7 +314,7 @@ T *array_add_and_get(Array *array) { template -void array_add_elems(Array *array, T const *elems, isize elem_count) { +gb_internal void array_add_elems(Array *array, T const *elems, isize elem_count) { GB_ASSERT(elem_count >= 0); if (array->capacity < array->count+elem_count) { array__grow(array, array->count+elem_count); @@ -325,26 +325,26 @@ void array_add_elems(Array *array, T const *elems, isize elem_count) { template -gb_inline T array_pop(Array *array) { +gb_internal gb_inline T array_pop(Array *array) { GB_ASSERT(array->count > 0); array->count--; return array->data[array->count]; } template -void array_clear(Array *array) { +gb_internal void array_clear(Array *array) { array->count = 0; } template -void array_reserve(Array *array, isize capacity) { +gb_internal void array_reserve(Array *array, isize capacity) { if (array->capacity < capacity) { array_set_capacity(array, capacity); } } template -void array_resize(Array *array, isize count) { +gb_internal void array_resize(Array *array, isize count) { if (array->capacity < count) { array__grow(array, count); } @@ -352,7 +352,7 @@ void array_resize(Array *array, isize count) { } template -void array_set_capacity(Array *array, isize capacity) { +gb_internal void array_set_capacity(Array *array, isize capacity) { if (capacity == array->capacity) { return; } @@ -381,7 +381,7 @@ void array_set_capacity(Array *array, isize capacity) { template -gb_inline Array array_slice(Array const &array, isize lo, isize hi) { +gb_internal gb_inline Array array_slice(Array const &array, isize lo, isize hi) { GB_ASSERT(0 <= lo && lo <= hi && hi <= array.count); Array out = {}; isize len = hi-lo; @@ -394,7 +394,7 @@ gb_inline Array array_slice(Array const &array, isize lo, isize hi) { } template -Array array_clone(gbAllocator const &allocator, Array const &array) { +gb_internal Array array_clone(gbAllocator const &allocator, Array const &array) { auto clone = array_make(allocator, array.count, array.count); array_copy(&clone, array, 0); return clone; @@ -402,7 +402,7 @@ Array array_clone(gbAllocator const &allocator, Array const &array) { template -void array_ordered_remove(Array *array, isize index) { +gb_internal void array_ordered_remove(Array *array, isize index) { GB_ASSERT(0 <= index && index < array->count); isize bytes = gb_size_of(T) * (array->count-(index+1)); @@ -411,7 +411,7 @@ void array_ordered_remove(Array *array, isize index) { } template -void array_unordered_remove(Array *array, isize index) { +gb_internal void array_unordered_remove(Array *array, isize index) { GB_ASSERT(0 <= index && index < array->count); isize n = array->count-1; @@ -424,35 +424,35 @@ void array_unordered_remove(Array *array, isize index) { template -T *begin(Array &array) { +gb_internal T *begin(Array &array) { return array.data; } template -T const *begin(Array const &array) { +gb_internal T const *begin(Array const &array) { return array.data; } template -T *end(Array &array) { +gb_internal T *end(Array &array) { return array.data + array.count; } template -T const *end(Array const &array) { +gb_internal T const *end(Array const &array) { return array.data + array.count; } template -T *begin(Slice &array) { +gb_internal T *begin(Slice &array) { return array.data; } template -T const *begin(Slice const &array) { +gb_internal T const *begin(Slice const &array) { return array.data; } template -T *end(Slice &array) { +gb_internal T *end(Slice &array) { return array.data + array.count; } template -T const *end(Slice const &array) { +gb_internal T const *end(Slice const &array) { return array.data + array.count; } diff --git a/src/big_int.cpp b/src/big_int.cpp index d8b3e63a7..0f6b921b2 100644 --- a/src/big_int.cpp +++ b/src/big_int.cpp @@ -37,86 +37,86 @@ void MP_FREE(void *mem, size_t size) { typedef mp_int BigInt; -void big_int_from_u64(BigInt *dst, u64 x); -void big_int_from_i64(BigInt *dst, i64 x); -void big_int_init (BigInt *dst, BigInt const *src); -void big_int_from_string(BigInt *dst, String const &s, bool *success); +gb_internal void big_int_from_u64(BigInt *dst, u64 x); +gb_internal void big_int_from_i64(BigInt *dst, i64 x); +gb_internal void big_int_init (BigInt *dst, BigInt const *src); +gb_internal void big_int_from_string(BigInt *dst, String const &s, bool *success); -void big_int_dealloc(BigInt *dst) { +gb_internal void big_int_dealloc(BigInt *dst) { mp_clear(dst); } -BigInt big_int_make(BigInt const *b, bool abs=false); -BigInt big_int_make_abs(BigInt const *b); -BigInt big_int_make_u64(u64 x); -BigInt big_int_make_i64(i64 x); +gb_internal BigInt big_int_make(BigInt const *b, bool abs=false); +gb_internal BigInt big_int_make_abs(BigInt const *b); +gb_internal BigInt big_int_make_u64(u64 x); +gb_internal BigInt big_int_make_i64(i64 x); -u64 big_int_to_u64 (BigInt const *x); -i64 big_int_to_i64 (BigInt const *x); -f64 big_int_to_f64 (BigInt const *x); -String big_int_to_string(gbAllocator allocator, BigInt const *x, u64 base = 10); +gb_internal u64 big_int_to_u64 (BigInt const *x); +gb_internal i64 big_int_to_i64 (BigInt const *x); +gb_internal f64 big_int_to_f64 (BigInt const *x); +gb_internal String big_int_to_string(gbAllocator allocator, BigInt const *x, u64 base = 10); -void big_int_add (BigInt *dst, BigInt const *x, BigInt const *y); -void big_int_sub (BigInt *dst, BigInt const *x, BigInt const *y); -void big_int_shl (BigInt *dst, BigInt const *x, BigInt const *y); -void big_int_shr (BigInt *dst, BigInt const *x, BigInt const *y); -void big_int_mul (BigInt *dst, BigInt const *x, BigInt const *y); -void big_int_mul_u64(BigInt *dst, BigInt const *x, u64 y); +gb_internal void big_int_add (BigInt *dst, BigInt const *x, BigInt const *y); +gb_internal void big_int_sub (BigInt *dst, BigInt const *x, BigInt const *y); +gb_internal void big_int_shl (BigInt *dst, BigInt const *x, BigInt const *y); +gb_internal void big_int_shr (BigInt *dst, BigInt const *x, BigInt const *y); +gb_internal void big_int_mul (BigInt *dst, BigInt const *x, BigInt const *y); +gb_internal void big_int_mul_u64(BigInt *dst, BigInt const *x, u64 y); -void big_int_quo_rem(BigInt const *x, BigInt const *y, BigInt *q, BigInt *r); -void big_int_quo (BigInt *z, BigInt const *x, BigInt const *y); -void big_int_rem (BigInt *z, BigInt const *x, BigInt const *y); +gb_internal void big_int_quo_rem(BigInt const *x, BigInt const *y, BigInt *q, BigInt *r); +gb_internal void big_int_quo (BigInt *z, BigInt const *x, BigInt const *y); +gb_internal void big_int_rem (BigInt *z, BigInt const *x, BigInt const *y); -void big_int_and (BigInt *dst, BigInt const *x, BigInt const *y); -void big_int_and_not(BigInt *dst, BigInt const *x, BigInt const *y); -void big_int_xor (BigInt *dst, BigInt const *x, BigInt const *y); -void big_int_or (BigInt *dst, BigInt const *x, BigInt const *y); -void big_int_not (BigInt *dst, BigInt const *x, i32 bit_count, bool is_signed); +gb_internal void big_int_and (BigInt *dst, BigInt const *x, BigInt const *y); +gb_internal void big_int_and_not(BigInt *dst, BigInt const *x, BigInt const *y); +gb_internal void big_int_xor (BigInt *dst, BigInt const *x, BigInt const *y); +gb_internal void big_int_or (BigInt *dst, BigInt const *x, BigInt const *y); +gb_internal void big_int_not (BigInt *dst, BigInt const *x, i32 bit_count, bool is_signed); -void big_int_add_eq(BigInt *dst, BigInt const *x); -void big_int_sub_eq(BigInt *dst, BigInt const *x); -void big_int_shl_eq(BigInt *dst, BigInt const *x); -void big_int_shr_eq(BigInt *dst, BigInt const *x); -void big_int_mul_eq(BigInt *dst, BigInt const *x); +gb_internal void big_int_add_eq(BigInt *dst, BigInt const *x); +gb_internal void big_int_sub_eq(BigInt *dst, BigInt const *x); +gb_internal void big_int_shl_eq(BigInt *dst, BigInt const *x); +gb_internal void big_int_shr_eq(BigInt *dst, BigInt const *x); +gb_internal void big_int_mul_eq(BigInt *dst, BigInt const *x); -void big_int_quo_eq(BigInt *dst, BigInt const *x); -void big_int_rem_eq(BigInt *dst, BigInt const *x); +gb_internal void big_int_quo_eq(BigInt *dst, BigInt const *x); +gb_internal void big_int_rem_eq(BigInt *dst, BigInt const *x); -bool big_int_is_neg(BigInt const *x); -void big_int_neg(BigInt *dst, BigInt const *x); +gb_internal bool big_int_is_neg(BigInt const *x); +gb_internal void big_int_neg(BigInt *dst, BigInt const *x); -void big_int_add_eq(BigInt *dst, BigInt const *x) { +gb_internal void big_int_add_eq(BigInt *dst, BigInt const *x) { BigInt res = {}; big_int_init(&res, dst); big_int_add(dst, &res, x); } -void big_int_sub_eq(BigInt *dst, BigInt const *x) { +gb_internal void big_int_sub_eq(BigInt *dst, BigInt const *x) { BigInt res = {}; big_int_init(&res, dst); big_int_sub(dst, &res, x); } -void big_int_shl_eq(BigInt *dst, BigInt const *x) { +gb_internal void big_int_shl_eq(BigInt *dst, BigInt const *x) { BigInt res = {}; big_int_init(&res, dst); big_int_shl(dst, &res, x); } -void big_int_shr_eq(BigInt *dst, BigInt const *x) { +gb_internal void big_int_shr_eq(BigInt *dst, BigInt const *x) { BigInt res = {}; big_int_init(&res, dst); big_int_shr(dst, &res, x); } -void big_int_mul_eq(BigInt *dst, BigInt const *x) { +gb_internal void big_int_mul_eq(BigInt *dst, BigInt const *x) { BigInt res = {}; big_int_init(&res, dst); big_int_mul(dst, &res, x); } -void big_int_quo_eq(BigInt *dst, BigInt const *x) { +gb_internal void big_int_quo_eq(BigInt *dst, BigInt const *x) { BigInt res = {}; big_int_init(&res, dst); big_int_quo(dst, &res, x); } -void big_int_rem_eq(BigInt *dst, BigInt const *x) { +gb_internal void big_int_rem_eq(BigInt *dst, BigInt const *x) { BigInt res = {}; big_int_init(&res, dst); big_int_rem(dst, &res, x); @@ -124,7 +124,7 @@ void big_int_rem_eq(BigInt *dst, BigInt const *x) { -i64 big_int_sign(BigInt const *x) { +gb_internal i64 big_int_sign(BigInt const *x) { if (mp_iszero(x)) { return 0; } @@ -132,44 +132,44 @@ i64 big_int_sign(BigInt const *x) { } -void big_int_from_u64(BigInt *dst, u64 x) { +gb_internal void big_int_from_u64(BigInt *dst, u64 x) { mp_init_u64(dst, x); } -void big_int_from_i64(BigInt *dst, i64 x) { +gb_internal void big_int_from_i64(BigInt *dst, i64 x) { mp_init_i64(dst, x); } -void big_int_init(BigInt *dst, BigInt const *src) { +gb_internal void big_int_init(BigInt *dst, BigInt const *src) { if (dst == src) { return; } mp_init_copy(dst, src); } -BigInt big_int_make(BigInt const *b, bool abs) { +gb_internal BigInt big_int_make(BigInt const *b, bool abs) { BigInt i = {}; big_int_init(&i, b); if (abs) mp_abs(&i, &i); return i; } -BigInt big_int_make_abs(BigInt const *b) { +gb_internal BigInt big_int_make_abs(BigInt const *b) { return big_int_make(b, true); } -BigInt big_int_make_u64(u64 x) { +gb_internal BigInt big_int_make_u64(u64 x) { BigInt i = {}; big_int_from_u64(&i, x); return i; } -BigInt big_int_make_i64(i64 x) { +gb_internal BigInt big_int_make_i64(i64 x) { BigInt i = {}; big_int_from_i64(&i, x); return i; } -void big_int_from_string(BigInt *dst, String const &s, bool *success) { +gb_internal void big_int_from_string(BigInt *dst, String const &s, bool *success) { *success = true; bool is_negative = false; @@ -262,66 +262,66 @@ void big_int_from_string(BigInt *dst, String const &s, bool *success) { -u64 big_int_to_u64(BigInt const *x) { +gb_internal u64 big_int_to_u64(BigInt const *x) { GB_ASSERT(x->sign == 0); return mp_get_u64(x); } -i64 big_int_to_i64(BigInt const *x) { +gb_internal i64 big_int_to_i64(BigInt const *x) { return mp_get_i64(x); } -f64 big_int_to_f64(BigInt const *x) { +gb_internal f64 big_int_to_f64(BigInt const *x) { return mp_get_double(x); } -void big_int_neg(BigInt *dst, BigInt const *x) { +gb_internal void big_int_neg(BigInt *dst, BigInt const *x) { mp_neg(x, dst); } -int big_int_cmp(BigInt const *x, BigInt const *y) { +gb_internal int big_int_cmp(BigInt const *x, BigInt const *y) { return mp_cmp(x, y); } -int big_int_cmp_zero(BigInt const *x) { +gb_internal int big_int_cmp_zero(BigInt const *x) { if (mp_iszero(x)) { return 0; } return x->sign ? -1 : +1; } -bool big_int_is_zero(BigInt const *x) { +gb_internal bool big_int_is_zero(BigInt const *x) { return mp_iszero(x); } -void big_int_add(BigInt *dst, BigInt const *x, BigInt const *y) { +gb_internal void big_int_add(BigInt *dst, BigInt const *x, BigInt const *y) { mp_add(x, y, dst); } -void big_int_sub(BigInt *dst, BigInt const *x, BigInt const *y) { +gb_internal void big_int_sub(BigInt *dst, BigInt const *x, BigInt const *y) { mp_sub(x, y, dst); } -void big_int_shl(BigInt *dst, BigInt const *x, BigInt const *y) { +gb_internal void big_int_shl(BigInt *dst, BigInt const *x, BigInt const *y) { u32 yy = mp_get_u32(y); mp_mul_2d(x, yy, dst); } -void big_int_shr(BigInt *dst, BigInt const *x, BigInt const *y) { +gb_internal void big_int_shr(BigInt *dst, BigInt const *x, BigInt const *y) { u32 yy = mp_get_u32(y); BigInt d = {}; mp_div_2d(x, yy, dst, &d); big_int_dealloc(&d); } -void big_int_mul_u64(BigInt *dst, BigInt const *x, u64 y) { +gb_internal void big_int_mul_u64(BigInt *dst, BigInt const *x, u64 y) { BigInt d = {}; big_int_from_u64(&d, y); mp_mul(x, &d, dst); @@ -329,12 +329,12 @@ void big_int_mul_u64(BigInt *dst, BigInt const *x, u64 y) { } -void big_int_mul(BigInt *dst, BigInt const *x, BigInt const *y) { +gb_internal void big_int_mul(BigInt *dst, BigInt const *x, BigInt const *y) { mp_mul(x, y, dst); } -u64 leading_zeros_u64(u64 x) { +gb_internal u64 leading_zeros_u64(u64 x) { #if defined(GB_COMPILER_MSVC) #if defined(GB_ARCH_64_BIT) return __lzcnt64(x); @@ -367,23 +367,23 @@ u64 leading_zeros_u64(u64 x) { // // q = x/y with the result truncated to zero // r = x - y*q -void big_int_quo_rem(BigInt const *x, BigInt const *y, BigInt *q_, BigInt *r_) { +gb_internal void big_int_quo_rem(BigInt const *x, BigInt const *y, BigInt *q_, BigInt *r_) { mp_div(x, y, q_, r_); } -void big_int_quo(BigInt *z, BigInt const *x, BigInt const *y) { +gb_internal void big_int_quo(BigInt *z, BigInt const *x, BigInt const *y) { BigInt r = {}; big_int_quo_rem(x, y, z, &r); big_int_dealloc(&r); } -void big_int_rem(BigInt *z, BigInt const *x, BigInt const *y) { +gb_internal void big_int_rem(BigInt *z, BigInt const *x, BigInt const *y) { BigInt q = {}; big_int_quo_rem(x, y, &q, z); big_int_dealloc(&q); } -void big_int_euclidean_mod(BigInt *z, BigInt const *x, BigInt const *y) { +gb_internal void big_int_euclidean_mod(BigInt *z, BigInt const *x, BigInt const *y) { BigInt y0 = {}; big_int_init(&y0, y); @@ -400,11 +400,11 @@ void big_int_euclidean_mod(BigInt *z, BigInt const *x, BigInt const *y) { -void big_int_and(BigInt *dst, BigInt const *x, BigInt const *y) { +gb_internal void big_int_and(BigInt *dst, BigInt const *x, BigInt const *y) { mp_and(x, y, dst); } -void big_int_and_not(BigInt *dst, BigInt const *x, BigInt const *y) { +gb_internal void big_int_and_not(BigInt *dst, BigInt const *x, BigInt const *y) { if (mp_iszero(x)) { big_int_init(dst, y); return; @@ -467,22 +467,22 @@ void big_int_and_not(BigInt *dst, BigInt const *x, BigInt const *y) { return; } -void big_int_xor(BigInt *dst, BigInt const *x, BigInt const *y) { +gb_internal void big_int_xor(BigInt *dst, BigInt const *x, BigInt const *y) { mp_xor(x, y, dst); } -void big_int_or(BigInt *dst, BigInt const *x, BigInt const *y) { +gb_internal void big_int_or(BigInt *dst, BigInt const *x, BigInt const *y) { mp_or(x, y, dst); } -void debug_print_big_int(BigInt const *x) { +gb_internal void debug_print_big_int(BigInt const *x) { String s = big_int_to_string(temporary_allocator(), x, 10); gb_printf_err("[DEBUG] %.*s\n", LIT(s)); } -void big_int_not(BigInt *dst, BigInt const *x, i32 bit_count, bool is_signed) { +gb_internal void big_int_not(BigInt *dst, BigInt const *x, i32 bit_count, bool is_signed) { GB_ASSERT(bit_count >= 0); if (bit_count == 0) { big_int_from_u64(dst, 0); @@ -530,7 +530,7 @@ void big_int_not(BigInt *dst, BigInt const *x, i32 bit_count, bool is_signed) { big_int_dealloc(&v); } -bool big_int_is_neg(BigInt const *x) { +gb_internal bool big_int_is_neg(BigInt const *x) { if (x == nullptr) { return false; } @@ -538,7 +538,7 @@ bool big_int_is_neg(BigInt const *x) { } -char digit_to_char(u8 digit) { +gb_internal char digit_to_char(u8 digit) { GB_ASSERT(digit < 16); if (digit <= 9) { return digit + '0'; @@ -548,7 +548,7 @@ char digit_to_char(u8 digit) { return '0'; } -String big_int_to_string(gbAllocator allocator, BigInt const *x, u64 base) { +gb_internal String big_int_to_string(gbAllocator allocator, BigInt const *x, u64 base) { GB_ASSERT(base <= 16); if (mp_iszero(x)) { diff --git a/src/build_settings.cpp b/src/build_settings.cpp index ba68e388b..d66db8099 100644 --- a/src/build_settings.cpp +++ b/src/build_settings.cpp @@ -57,7 +57,7 @@ enum TargetABIKind : u16 { }; -String target_os_names[TargetOs_COUNT] = { +gb_global String target_os_names[TargetOs_COUNT] = { str_lit(""), str_lit("windows"), str_lit("darwin"), @@ -72,7 +72,7 @@ String target_os_names[TargetOs_COUNT] = { str_lit("freestanding"), }; -String target_arch_names[TargetArch_COUNT] = { +gb_global String target_arch_names[TargetArch_COUNT] = { str_lit(""), str_lit("amd64"), str_lit("i386"), @@ -82,19 +82,19 @@ String target_arch_names[TargetArch_COUNT] = { str_lit("wasm64"), }; -String target_endian_names[TargetEndian_COUNT] = { +gb_global String target_endian_names[TargetEndian_COUNT] = { str_lit(""), str_lit("little"), str_lit("big"), }; -String target_abi_names[TargetABI_COUNT] = { +gb_global String target_abi_names[TargetABI_COUNT] = { str_lit(""), str_lit("win64"), str_lit("sysv"), }; -TargetEndianKind target_endians[TargetArch_COUNT] = { +gb_global TargetEndianKind target_endians[TargetArch_COUNT] = { TargetEndian_Invalid, TargetEndian_Little, TargetEndian_Little, @@ -107,7 +107,7 @@ TargetEndianKind target_endians[TargetArch_COUNT] = { #define ODIN_VERSION_RAW "dev-unknown-unknown" #endif -String const ODIN_VERSION = str_lit(ODIN_VERSION_RAW); +gb_global String const ODIN_VERSION = str_lit(ODIN_VERSION_RAW); @@ -162,7 +162,7 @@ enum CommandKind : u32 { Command_all = ~(u32)0, }; -char const *odin_command_strings[32] = { +gb_global char const *odin_command_strings[32] = { "run", "build", "check", @@ -333,10 +333,10 @@ struct BuildContext { gb_global BuildContext build_context = {0}; -bool global_warnings_as_errors(void) { +gb_internal bool global_warnings_as_errors(void) { return build_context.warnings_as_errors; } -bool global_ignore_warnings(void) { +gb_internal bool global_ignore_warnings(void) { return build_context.ignore_warnings; } @@ -502,9 +502,9 @@ gb_global NamedTargetMetrics named_targets[] = { { str_lit("freestanding_amd64_sysv"), &target_freestanding_amd64_sysv }, }; -NamedTargetMetrics *selected_target_metrics; +gb_global NamedTargetMetrics *selected_target_metrics; -TargetOsKind get_target_os_from_string(String str) { +gb_internal TargetOsKind get_target_os_from_string(String str) { for (isize i = 0; i < TargetOs_COUNT; i++) { if (str_eq_ignore_case(target_os_names[i], str)) { return cast(TargetOsKind)i; @@ -513,7 +513,7 @@ TargetOsKind get_target_os_from_string(String str) { return TargetOs_Invalid; } -TargetArchKind get_target_arch_from_string(String str) { +gb_internal TargetArchKind get_target_arch_from_string(String str) { for (isize i = 0; i < TargetArch_COUNT; i++) { if (str_eq_ignore_case(target_arch_names[i], str)) { return cast(TargetArchKind)i; @@ -523,7 +523,7 @@ TargetArchKind get_target_arch_from_string(String str) { } -bool is_excluded_target_filename(String name) { +gb_internal bool is_excluded_target_filename(String name) { String original_name = name; name = remove_extension_from_path(name); @@ -588,13 +588,13 @@ struct LibraryCollections { gb_global Array library_collections = {0}; -void add_library_collection(String name, String path) { +gb_internal void add_library_collection(String name, String path) { // TODO(bill): Check the path is valid and a directory LibraryCollections lc = {name, string_trim_whitespace(path)}; array_add(&library_collections, lc); } -bool find_library_collection_path(String name, String *path) { +gb_internal bool find_library_collection_path(String name, String *path) { for_array(i, library_collections) { if (library_collections[i].name == name) { if (path) *path = library_collections[i].path; @@ -604,7 +604,7 @@ bool find_library_collection_path(String name, String *path) { return false; } -bool is_arch_wasm(void) { +gb_internal bool is_arch_wasm(void) { switch (build_context.metrics.arch) { case TargetArch_wasm32: case TargetArch_wasm64: @@ -613,7 +613,7 @@ bool is_arch_wasm(void) { return false; } -bool is_arch_x86(void) { +gb_internal bool is_arch_x86(void) { switch (build_context.metrics.arch) { case TargetArch_i386: case TargetArch_amd64: @@ -622,7 +622,7 @@ bool is_arch_x86(void) { return false; } -bool allow_check_foreign_filepath(void) { +gb_internal bool allow_check_foreign_filepath(void) { switch (build_context.metrics.arch) { case TargetArch_wasm32: case TargetArch_wasm64: @@ -638,13 +638,14 @@ bool allow_check_foreign_filepath(void) { // is_abs_path // has_subdir -String const WIN32_SEPARATOR_STRING = {cast(u8 *)"\\", 1}; -String const NIX_SEPARATOR_STRING = {cast(u8 *)"/", 1}; +gb_global String const WIN32_SEPARATOR_STRING = {cast(u8 *)"\\", 1}; +gb_global String const NIX_SEPARATOR_STRING = {cast(u8 *)"/", 1}; -String const WASM_MODULE_NAME_SEPARATOR = str_lit(".."); +gb_global String const WASM_MODULE_NAME_SEPARATOR = str_lit(".."); -String internal_odin_root_dir(void); -String odin_root_dir(void) { +gb_internal String internal_odin_root_dir(void); + +gb_internal String odin_root_dir(void) { if (global_module_path_set) { return global_module_path; } @@ -670,7 +671,7 @@ String odin_root_dir(void) { #if defined(GB_SYSTEM_WINDOWS) -String internal_odin_root_dir(void) { +gb_internal String internal_odin_root_dir(void) { String path = global_module_path; isize len, i; wchar_t *text; @@ -725,7 +726,7 @@ String internal_odin_root_dir(void) { String path_to_fullpath(gbAllocator a, String s); -String internal_odin_root_dir(void) { +gb_internal String internal_odin_root_dir(void) { String path = global_module_path; isize len, i; u8 *text; @@ -777,9 +778,9 @@ String internal_odin_root_dir(void) { // NOTE: Linux / Unix is unfinished and not tested very well. #include -String path_to_fullpath(gbAllocator a, String s); +gb_internal String path_to_fullpath(gbAllocator a, String s); -String internal_odin_root_dir(void) { +gb_internal String internal_odin_root_dir(void) { String path = global_module_path; isize len, i; u8 *text; @@ -938,7 +939,7 @@ String internal_odin_root_dir(void) { gb_global BlockingMutex fullpath_mutex; #if defined(GB_SYSTEM_WINDOWS) -String path_to_fullpath(gbAllocator a, String s) { +gb_internal String path_to_fullpath(gbAllocator a, String s) { String result = {}; mutex_lock(&fullpath_mutex); defer (mutex_unlock(&fullpath_mutex)); @@ -965,7 +966,7 @@ String path_to_fullpath(gbAllocator a, String s) { return result; } #elif defined(GB_SYSTEM_OSX) || defined(GB_SYSTEM_UNIX) -String path_to_fullpath(gbAllocator a, String s) { +gb_internal String path_to_fullpath(gbAllocator a, String s) { char *p; mutex_lock(&fullpath_mutex); p = realpath(cast(char *)s.text, 0); @@ -978,7 +979,7 @@ String path_to_fullpath(gbAllocator a, String s) { #endif -String get_fullpath_relative(gbAllocator a, String base_dir, String path) { +gb_internal String get_fullpath_relative(gbAllocator a, String base_dir, String path) { u8 *str = gb_alloc_array(heap_allocator(), u8, base_dir.len+1+path.len+1); defer (gb_free(heap_allocator(), str)); @@ -1004,7 +1005,7 @@ String get_fullpath_relative(gbAllocator a, String base_dir, String path) { } -String get_fullpath_core(gbAllocator a, String path) { +gb_internal String get_fullpath_core(gbAllocator a, String path) { String module_dir = odin_root_dir(); String core = str_lit("core/"); @@ -1024,11 +1025,11 @@ String get_fullpath_core(gbAllocator a, String path) { return path_to_fullpath(a, res); } -bool show_error_line(void) { +gb_internal bool show_error_line(void) { return build_context.show_error_line; } -bool has_asm_extension(String const &path) { +gb_internal bool has_asm_extension(String const &path) { String ext = path_extension(path); if (ext == ".asm") { return true; @@ -1041,7 +1042,7 @@ bool has_asm_extension(String const &path) { } // temporary -char *token_pos_to_string(TokenPos const &pos) { +gb_internal char *token_pos_to_string(TokenPos const &pos) { gbString s = gb_string_make_reserve(temporary_allocator(), 128); String file = get_file_path_string(pos.file_id); switch (build_context.ODIN_ERROR_POS_STYLE) { @@ -1056,7 +1057,7 @@ char *token_pos_to_string(TokenPos const &pos) { return s; } -void init_build_context(TargetMetrics *cross_target) { +gb_internal void init_build_context(TargetMetrics *cross_target) { BuildContext *bc = &build_context; gb_affinity_init(&bc->affinity); @@ -1258,7 +1259,7 @@ void init_build_context(TargetMetrics *cross_target) { #endif -Array split_by_comma(String const &list) { +gb_internal Array split_by_comma(String const &list) { isize n = 1; for (isize i = 0; i < list.len; i++) { if (list.text[i] == ',') { @@ -1280,12 +1281,12 @@ Array split_by_comma(String const &list) { return res; } -bool check_target_feature_is_valid(TokenPos pos, String const &feature) { +gb_internal bool check_target_feature_is_valid(TokenPos pos, String const &feature) { // TODO(bill): check_target_feature_is_valid return true; } -bool check_target_feature_is_enabled(TokenPos pos, String const &target_feature_list) { +gb_internal bool check_target_feature_is_enabled(TokenPos pos, String const &target_feature_list) { BuildContext *bc = &build_context; mutex_lock(&bc->target_features_mutex); defer (mutex_unlock(&bc->target_features_mutex)); @@ -1307,7 +1308,7 @@ bool check_target_feature_is_enabled(TokenPos pos, String const &target_feature_ return true; } -void enable_target_feature(TokenPos pos, String const &target_feature_list) { +gb_internal void enable_target_feature(TokenPos pos, String const &target_feature_list) { BuildContext *bc = &build_context; mutex_lock(&bc->target_features_mutex); defer (mutex_unlock(&bc->target_features_mutex)); @@ -1326,7 +1327,7 @@ void enable_target_feature(TokenPos pos, String const &target_feature_list) { } -char const *target_features_set_to_cstring(gbAllocator allocator, bool with_quotes) { +gb_internal char const *target_features_set_to_cstring(gbAllocator allocator, bool with_quotes) { isize len = 0; isize i = 0; for (auto const &entry : build_context.target_features_set) { @@ -1359,7 +1360,7 @@ char const *target_features_set_to_cstring(gbAllocator allocator, bool with_quot // NOTE(Jeroen): Set/create the output and other paths and report an error as appropriate. // We've previously called `parse_build_flags`, so `out_filepath` should be set. -bool init_build_paths(String init_filename) { +gb_internal bool init_build_paths(String init_filename) { gbAllocator ha = heap_allocator(); BuildContext *bc = &build_context; diff --git a/src/common.cpp b/src/common.cpp index bc421b5fd..09203e633 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -29,14 +29,14 @@ #include #include // Because I wanted the C++11 memory order semantics, of which gb.h does not offer (because it was a C89 library) -gbAllocator heap_allocator(void); +gb_internal gbAllocator heap_allocator(void); #define for_array(index_, array_) for (isize index_ = 0; index_ < (array_).count; index_++) -i32 next_pow2(i32 n); -i64 next_pow2(i64 n); -isize next_pow2_isize(isize n); -void debugf(char const *fmt, ...); +gb_internal i32 next_pow2(i32 n); +gb_internal i64 next_pow2(i64 n); +gb_internal isize next_pow2_isize(isize n); +gb_internal void debugf(char const *fmt, ...); #if defined(GB_SYSTEM_WINDOWS) && defined(GB_ARCH_32_BIT) #error Odin on Windows requires a 64-bit build-system. The 'Developer Command Prompt' for VS still defaults to 32-bit shell. The 64-bit shell can be found under the name 'x64 Native Tools Command Prompt' for VS. For more information, please see https://odin-lang.org/docs/install/#for-windows @@ -51,14 +51,14 @@ void debugf(char const *fmt, ...); #include "range_cache.cpp" -bool is_power_of_two(i64 x) { +gb_internal gb_inline bool is_power_of_two(i64 x) { if (x <= 0) { return false; } return !(x & (x-1)); } -int isize_cmp(isize x, isize y) { +gb_internal int isize_cmp(isize x, isize y) { if (x < y) { return -1; } else if (x > y) { @@ -66,7 +66,7 @@ int isize_cmp(isize x, isize y) { } return 0; } -int u64_cmp(u64 x, u64 y) { +gb_internal int u64_cmp(u64 x, u64 y) { if (x < y) { return -1; } else if (x > y) { @@ -74,7 +74,7 @@ int u64_cmp(u64 x, u64 y) { } return 0; } -int i64_cmp(i64 x, i64 y) { +gb_internal int i64_cmp(i64 x, i64 y) { if (x < y) { return -1; } else if (x > y) { @@ -82,7 +82,7 @@ int i64_cmp(i64 x, i64 y) { } return 0; } -int i32_cmp(i32 x, i32 y) { +gb_internal int i32_cmp(i32 x, i32 y) { if (x < y) { return -1; } else if (x > y) { @@ -91,7 +91,7 @@ int i32_cmp(i32 x, i32 y) { return 0; } -u32 fnv32a(void const *data, isize len) { +gb_internal u32 fnv32a(void const *data, isize len) { u8 const *bytes = cast(u8 const *)data; u32 h = 0x811c9dc5; @@ -112,7 +112,7 @@ u32 fnv32a(void const *data, isize len) { return h; } -u64 fnv64a(void const *data, isize len) { +gb_internal u64 fnv64a(void const *data, isize len) { u8 const *bytes = cast(u8 const *)data; u64 h = 0xcbf29ce484222325ull; @@ -133,7 +133,7 @@ u64 fnv64a(void const *data, isize len) { return h; } -u64 u64_digit_value(Rune r) { +gb_internal u64 u64_digit_value(Rune r) { switch (r) { case '0': return 0; case '1': return 1; @@ -162,7 +162,7 @@ u64 u64_digit_value(Rune r) { } -u64 u64_from_string(String string) { +gb_internal u64 u64_from_string(String string) { u64 base = 10; bool has_prefix = false; if (string.len > 2 && string[0] == '0') { @@ -205,7 +205,7 @@ gb_global char const global_num_to_char_table[] = "abcdefghijklmnopqrstuvwxyz" "@$"; -String u64_to_string(u64 v, char *out_buf, isize out_buf_len) { +gb_internal String u64_to_string(u64 v, char *out_buf, isize out_buf_len) { char buf[32] = {0}; isize i = gb_size_of(buf); @@ -220,7 +220,7 @@ String u64_to_string(u64 v, char *out_buf, isize out_buf_len) { gb_memmove(out_buf, &buf[i], len); return make_string(cast(u8 *)out_buf, len); } -String i64_to_string(i64 a, char *out_buf, isize out_buf_len) { +gb_internal String i64_to_string(i64 a, char *out_buf, isize out_buf_len) { char buf[32] = {0}; isize i = gb_size_of(buf); bool negative = false; @@ -282,17 +282,17 @@ gb_global u64 const unsigned_integer_maxs[] = { }; -bool add_overflow_u64(u64 x, u64 y, u64 *result) { +gb_internal bool add_overflow_u64(u64 x, u64 y, u64 *result) { *result = x + y; return *result < x || *result < y; } -bool sub_overflow_u64(u64 x, u64 y, u64 *result) { +gb_internal bool sub_overflow_u64(u64 x, u64 y, u64 *result) { *result = x - y; return *result > x; } -void mul_overflow_u64(u64 x, u64 y, u64 *lo, u64 *hi) { +gb_internal void mul_overflow_u64(u64 x, u64 y, u64 *lo, u64 *hi) { #if defined(GB_COMPILER_MSVC) && defined(GB_ARCH_64_BIT) *lo = _umul128(x, y, hi); #else @@ -342,7 +342,7 @@ struct StringIntern { PtrMap string_intern_map = {}; // Key: u64 gb_global Arena string_intern_arena = {}; -char const *string_intern(char const *text, isize len) { +gb_internal char const *string_intern(char const *text, isize len) { u64 hash = gb_fnv64a(text, len); uintptr key = cast(uintptr)(hash ? hash : 1); StringIntern **found = map_get(&string_intern_map, key); @@ -363,18 +363,18 @@ char const *string_intern(char const *text, isize len) { return new_intern->str; } -char const *string_intern(String const &string) { +gb_internal char const *string_intern(String const &string) { return string_intern(cast(char const *)string.text, string.len); } -void init_string_interner(void) { +gb_internal void init_string_interner(void) { map_init(&string_intern_map, heap_allocator()); } -i32 next_pow2(i32 n) { +gb_internal i32 next_pow2(i32 n) { if (n <= 0) { return 0; } @@ -387,7 +387,7 @@ i32 next_pow2(i32 n) { n++; return n; } -i64 next_pow2(i64 n) { +gb_internal i64 next_pow2(i64 n) { if (n <= 0) { return 0; } @@ -401,7 +401,7 @@ i64 next_pow2(i64 n) { n++; return n; } -isize next_pow2_isize(isize n) { +gb_internal isize next_pow2_isize(isize n) { if (n <= 0) { return 0; } @@ -417,7 +417,7 @@ isize next_pow2_isize(isize n) { n++; return n; } -u32 next_pow2_u32(u32 n) { +gb_internal u32 next_pow2_u32(u32 n) { if (n == 0) { return 0; } @@ -432,7 +432,7 @@ u32 next_pow2_u32(u32 n) { } -i32 bit_set_count(u32 x) { +gb_internal i32 bit_set_count(u32 x) { x -= ((x >> 1) & 0x55555555); x = (((x >> 2) & 0x33333333) + (x & 0x33333333)); x = (((x >> 4) + x) & 0x0f0f0f0f); @@ -442,13 +442,13 @@ i32 bit_set_count(u32 x) { return cast(i32)(x & 0x0000003f); } -i64 bit_set_count(u64 x) { +gb_internal i64 bit_set_count(u64 x) { u32 a = *(cast(u32 *)&x); u32 b = *(cast(u32 *)&x + 1); return bit_set_count(a) + bit_set_count(b); } -u32 floor_log2(u32 x) { +gb_internal u32 floor_log2(u32 x) { x |= x >> 1; x |= x >> 2; x |= x >> 4; @@ -457,7 +457,7 @@ u32 floor_log2(u32 x) { return cast(u32)(bit_set_count(x) - 1); } -u64 floor_log2(u64 x) { +gb_internal u64 floor_log2(u64 x) { x |= x >> 1; x |= x >> 2; x |= x >> 4; @@ -468,7 +468,7 @@ u64 floor_log2(u64 x) { } -u32 ceil_log2(u32 x) { +gb_internal u32 ceil_log2(u32 x) { i32 y = cast(i32)(x & (x-1)); y |= -y; y >>= 32-1; @@ -480,7 +480,7 @@ u32 ceil_log2(u32 x) { return cast(u32)(bit_set_count(x) - 1 - y); } -u64 ceil_log2(u64 x) { +gb_internal u64 ceil_log2(u64 x) { i64 y = cast(i64)(x & (x-1)); y |= -y; y >>= 64-1; @@ -493,7 +493,7 @@ u64 ceil_log2(u64 x) { return cast(u64)(bit_set_count(x) - 1 - y); } -u32 prev_pow2(u32 n) { +gb_internal u32 prev_pow2(u32 n) { if (n == 0) { return 0; } @@ -504,7 +504,7 @@ u32 prev_pow2(u32 n) { n |= n >> 16; return n - (n >> 1); } -i32 prev_pow2(i32 n) { +gb_internal i32 prev_pow2(i32 n) { if (n <= 0) { return 0; } @@ -515,7 +515,7 @@ i32 prev_pow2(i32 n) { n |= n >> 16; return n - (n >> 1); } -i64 prev_pow2(i64 n) { +gb_internal i64 prev_pow2(i64 n) { if (n <= 0) { return 0; } @@ -528,7 +528,7 @@ i64 prev_pow2(i64 n) { return n - (n >> 1); } -u16 f32_to_f16(f32 value) { +gb_internal u16 f32_to_f16(f32 value) { union { u32 i; f32 f; } v; i32 i, s, e, m; @@ -579,7 +579,7 @@ u16 f32_to_f16(f32 value) { } } -f32 f16_to_f32(u16 value) { +gb_internal f32 f16_to_f32(u16 value) { typedef union { u32 u; f32 f; } fp32; fp32 v; @@ -595,7 +595,7 @@ f32 f16_to_f32(u16 value) { return v.f; } -f64 gb_sqrt(f64 x) { +gb_internal gb_inline f64 gb_sqrt(f64 x) { return sqrt(x); } @@ -623,7 +623,7 @@ f64 gb_sqrt(f64 x) { #if defined(GB_SYSTEM_WINDOWS) -wchar_t **command_line_to_wargv(wchar_t *cmd_line, int *_argc) { +gb_internal wchar_t **command_line_to_wargv(wchar_t *cmd_line, int *_argc) { u32 i, j; u32 len = cast(u32)string16_len(cmd_line); @@ -706,7 +706,7 @@ enum LoadedFileError { LoadedFile_COUNT, }; -LoadedFileError load_file_32(char const *fullpath, LoadedFile *memory_mapped_file, bool copy_file_contents) { +gb_internal LoadedFileError load_file_32(char const *fullpath, LoadedFile *memory_mapped_file, bool copy_file_contents) { LoadedFileError err = LoadedFile_None; if (!copy_file_contents) { @@ -811,7 +811,7 @@ LoadedFileError load_file_32(char const *fullpath, LoadedFile *memory_mapped_fil #define USE_DAMERAU_LEVENSHTEIN 1 -isize levenstein_distance_case_insensitive(String const &a, String const &b) { +gb_internal isize levenstein_distance_case_insensitive(String const &a, String const &b) { isize w = b.len+1; isize h = a.len+1; isize *matrix = gb_alloc_array(temporary_allocator(), isize, w*h); @@ -870,16 +870,16 @@ struct DidYouMeanAnswers { enum {MAX_SMALLEST_DID_YOU_MEAN_DISTANCE = 3-USE_DAMERAU_LEVENSHTEIN}; -DidYouMeanAnswers did_you_mean_make(gbAllocator allocator, isize cap, String const &key) { +gb_internal DidYouMeanAnswers did_you_mean_make(gbAllocator allocator, isize cap, String const &key) { DidYouMeanAnswers d = {}; array_init(&d.distances, allocator, 0, cap); d.key = key; return d; } -void did_you_mean_destroy(DidYouMeanAnswers *d) { +gb_internal void did_you_mean_destroy(DidYouMeanAnswers *d) { array_free(&d->distances); } -void did_you_mean_append(DidYouMeanAnswers *d, String const &target) { +gb_internal void did_you_mean_append(DidYouMeanAnswers *d, String const &target) { if (target.len == 0 || target == "_") { return; } @@ -888,7 +888,7 @@ void did_you_mean_append(DidYouMeanAnswers *d, String const &target) { dat.distance = levenstein_distance_case_insensitive(d->key, target); array_add(&d->distances, dat); } -Slice did_you_mean_results(DidYouMeanAnswers *d) { +gb_internal Slice did_you_mean_results(DidYouMeanAnswers *d) { gb_sort_array(d->distances.data, d->distances.count, gb_isize_cmp(gb_offset_of(DistanceAndTarget, distance))); isize count = 0; for (isize i = 0; i < d->distances.count; i++) { diff --git a/src/common_memory.cpp b/src/common_memory.cpp index 953462077..63b7c24ef 100644 --- a/src/common_memory.cpp +++ b/src/common_memory.cpp @@ -1,5 +1,5 @@ -gb_inline void zero_size(void *ptr, isize len) { +gb_internal gb_inline void zero_size(void *ptr, isize len) { memset(ptr, 0, len); } @@ -7,27 +7,27 @@ gb_inline void zero_size(void *ptr, isize len) { template -gb_inline U bit_cast(V &v) { return reinterpret_cast(v); } +gb_internal gb_inline U bit_cast(V &v) { return reinterpret_cast(v); } template -gb_inline U const &bit_cast(V const &v) { return reinterpret_cast(v); } +gb_internal gb_inline U const &bit_cast(V const &v) { return reinterpret_cast(v); } -gb_inline i64 align_formula(i64 size, i64 align) { +gb_internal gb_inline i64 align_formula(i64 size, i64 align) { if (align > 0) { i64 result = size + align-1; return result - result%align; } return size; } -gb_inline isize align_formula_isize(isize size, isize align) { +gb_internal gb_inline isize align_formula_isize(isize size, isize align) { if (align > 0) { isize result = size + align-1; return result - result%align; } return size; } -gb_inline void *align_formula_ptr(void *ptr, isize align) { +gb_internal gb_inline void *align_formula_ptr(void *ptr, isize align) { if (align > 0) { uintptr result = (cast(uintptr)ptr) + align-1; return (void *)(result - result%align); @@ -39,9 +39,9 @@ gb_inline void *align_formula_ptr(void *ptr, isize align) { gb_global BlockingMutex global_memory_block_mutex; gb_global BlockingMutex global_memory_allocator_mutex; -void platform_virtual_memory_init(void); +gb_internal void platform_virtual_memory_init(void); -void virtual_memory_init(void) { +gb_internal void virtual_memory_init(void) { mutex_init(&global_memory_block_mutex); mutex_init(&global_memory_allocator_mutex); platform_virtual_memory_init(); @@ -66,13 +66,13 @@ enum { DEFAULT_MINIMUM_BLOCK_SIZE = 8ll*1024ll*1024ll }; gb_global isize DEFAULT_PAGE_SIZE = 4096; -MemoryBlock *virtual_memory_alloc(isize size); -void virtual_memory_dealloc(MemoryBlock *block); -void *arena_alloc(Arena *arena, isize min_size, isize alignment); -void arena_free_all(Arena *arena); +gb_internal MemoryBlock *virtual_memory_alloc(isize size); +gb_internal void virtual_memory_dealloc(MemoryBlock *block); +gb_internal void *arena_alloc(Arena *arena, isize min_size, isize alignment); +gb_internal void arena_free_all(Arena *arena); -isize arena_align_forward_offset(Arena *arena, isize alignment) { +gb_internal isize arena_align_forward_offset(Arena *arena, isize alignment) { isize alignment_offset = 0; isize ptr = cast(isize)(arena->curr_block->base + arena->curr_block->used); isize mask = alignment-1; @@ -82,7 +82,7 @@ isize arena_align_forward_offset(Arena *arena, isize alignment) { return alignment_offset; } -void *arena_alloc(Arena *arena, isize min_size, isize alignment) { +gb_internal void *arena_alloc(Arena *arena, isize min_size, isize alignment) { GB_ASSERT(gb_is_power_of_two(alignment)); BlockingMutex *mutex = &global_memory_allocator_mutex; @@ -123,7 +123,7 @@ void *arena_alloc(Arena *arena, isize min_size, isize alignment) { return ptr; } -void arena_free_all(Arena *arena) { +gb_internal void arena_free_all(Arena *arena) { while (arena->curr_block != nullptr) { MemoryBlock *free_block = arena->curr_block; arena->curr_block = free_block->prev; @@ -142,12 +142,12 @@ struct PlatformMemoryBlock { gb_global std::atomic global_platform_memory_total_usage; gb_global PlatformMemoryBlock global_platform_memory_block_sentinel; -PlatformMemoryBlock *platform_virtual_memory_alloc(isize total_size); -void platform_virtual_memory_free(PlatformMemoryBlock *block); -void platform_virtual_memory_protect(void *memory, isize size); +gb_internal PlatformMemoryBlock *platform_virtual_memory_alloc(isize total_size); +gb_internal void platform_virtual_memory_free(PlatformMemoryBlock *block); +gb_internal void platform_virtual_memory_protect(void *memory, isize size); #if defined(GB_SYSTEM_WINDOWS) - void platform_virtual_memory_init(void) { + gb_internal void platform_virtual_memory_init(void) { global_platform_memory_block_sentinel.prev = &global_platform_memory_block_sentinel; global_platform_memory_block_sentinel.next = &global_platform_memory_block_sentinel; @@ -157,7 +157,7 @@ void platform_virtual_memory_protect(void *memory, isize size); GB_ASSERT(gb_is_power_of_two(DEFAULT_PAGE_SIZE)); } - PlatformMemoryBlock *platform_virtual_memory_alloc(isize total_size) { + gb_internal PlatformMemoryBlock *platform_virtual_memory_alloc(isize total_size) { PlatformMemoryBlock *pmblock = (PlatformMemoryBlock *)VirtualAlloc(0, total_size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); if (pmblock == nullptr) { gb_printf_err("Out of Virtual memory, oh no...\n"); @@ -168,17 +168,17 @@ void platform_virtual_memory_protect(void *memory, isize size); global_platform_memory_total_usage += total_size; return pmblock; } - void platform_virtual_memory_free(PlatformMemoryBlock *block) { + gb_internal void platform_virtual_memory_free(PlatformMemoryBlock *block) { global_platform_memory_total_usage -= block->total_size; GB_ASSERT(VirtualFree(block, 0, MEM_RELEASE)); } - void platform_virtual_memory_protect(void *memory, isize size) { + gb_internal void platform_virtual_memory_protect(void *memory, isize size) { DWORD old_protect = 0; BOOL is_protected = VirtualProtect(memory, size, PAGE_NOACCESS, &old_protect); GB_ASSERT(is_protected); } #else - void platform_virtual_memory_init(void) { + gb_internal void platform_virtual_memory_init(void) { global_platform_memory_block_sentinel.prev = &global_platform_memory_block_sentinel; global_platform_memory_block_sentinel.next = &global_platform_memory_block_sentinel; @@ -186,7 +186,7 @@ void platform_virtual_memory_protect(void *memory, isize size); GB_ASSERT(gb_is_power_of_two(DEFAULT_PAGE_SIZE)); } - PlatformMemoryBlock *platform_virtual_memory_alloc(isize total_size) { + gb_internal PlatformMemoryBlock *platform_virtual_memory_alloc(isize total_size) { PlatformMemoryBlock *pmblock = (PlatformMemoryBlock *)mmap(nullptr, total_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); if (pmblock == nullptr) { gb_printf_err("Out of Virtual memory, oh no...\n"); @@ -197,18 +197,18 @@ void platform_virtual_memory_protect(void *memory, isize size); global_platform_memory_total_usage += total_size; return pmblock; } - void platform_virtual_memory_free(PlatformMemoryBlock *block) { + gb_internal void platform_virtual_memory_free(PlatformMemoryBlock *block) { isize size = block->total_size; global_platform_memory_total_usage -= size; munmap(block, size); } - void platform_virtual_memory_protect(void *memory, isize size) { + gb_internal void platform_virtual_memory_protect(void *memory, isize size) { int err = mprotect(memory, size, PROT_NONE); GB_ASSERT(err == 0); } #endif -MemoryBlock *virtual_memory_alloc(isize size) { +gb_internal MemoryBlock *virtual_memory_alloc(isize size) { isize const page_size = DEFAULT_PAGE_SIZE; isize total_size = size + gb_size_of(PlatformMemoryBlock); @@ -250,7 +250,7 @@ MemoryBlock *virtual_memory_alloc(isize size) { return &pmblock->block; } -void virtual_memory_dealloc(MemoryBlock *block_to_free) { +gb_internal void virtual_memory_dealloc(MemoryBlock *block_to_free) { PlatformMemoryBlock *block = cast(PlatformMemoryBlock *)block_to_free; if (block != nullptr) { mutex_lock(&global_memory_block_mutex); @@ -265,9 +265,9 @@ void virtual_memory_dealloc(MemoryBlock *block_to_free) { -GB_ALLOCATOR_PROC(arena_allocator_proc); +gb_internal GB_ALLOCATOR_PROC(arena_allocator_proc); -gbAllocator arena_allocator(Arena *arena) { +gb_internal gbAllocator arena_allocator(Arena *arena) { gbAllocator a; a.proc = arena_allocator_proc; a.data = arena; @@ -275,7 +275,7 @@ gbAllocator arena_allocator(Arena *arena) { } -GB_ALLOCATOR_PROC(arena_allocator_proc) { +gb_internal GB_ALLOCATOR_PROC(arena_allocator_proc) { void *ptr = nullptr; Arena *arena = cast(Arena *)allocator_data; GB_ASSERT_NOT_NULL(arena); @@ -307,11 +307,11 @@ GB_ALLOCATOR_PROC(arena_allocator_proc) { gb_global gb_thread_local Arena permanent_arena = {nullptr, DEFAULT_MINIMUM_BLOCK_SIZE, true}; -gbAllocator permanent_allocator() { +gb_internal gbAllocator permanent_allocator() { return arena_allocator(&permanent_arena); } -gbAllocator temporary_allocator() { +gb_internal gbAllocator temporary_allocator() { return permanent_allocator(); } @@ -320,9 +320,9 @@ gbAllocator temporary_allocator() { -GB_ALLOCATOR_PROC(heap_allocator_proc); +gb_internal GB_ALLOCATOR_PROC(heap_allocator_proc); -gbAllocator heap_allocator(void) { +gb_internal gbAllocator heap_allocator(void) { gbAllocator a; a.proc = heap_allocator_proc; a.data = nullptr; @@ -330,7 +330,7 @@ gbAllocator heap_allocator(void) { } -GB_ALLOCATOR_PROC(heap_allocator_proc) { +gb_internal GB_ALLOCATOR_PROC(heap_allocator_proc) { void *ptr = nullptr; gb_unused(allocator_data); gb_unused(old_size); @@ -460,7 +460,7 @@ GB_ALLOCATOR_PROC(heap_allocator_proc) { template -void resize_array_raw(T **array, gbAllocator const &a, isize old_count, isize new_count) { +gb_internal void resize_array_raw(T **array, gbAllocator const &a, isize old_count, isize new_count) { GB_ASSERT(new_count >= 0); if (new_count == 0) { gb_free(a, *array); diff --git a/src/error.cpp b/src/error.cpp index faf4d11fb..085e1a8dd 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -17,11 +17,11 @@ gb_global ErrorCollector global_error_collector; #define MAX_ERROR_COLLECTOR_COUNT (36) -bool any_errors(void) { +gb_internal bool any_errors(void) { return global_error_collector.count.load() != 0; } -void init_global_error_collector(void) { +gb_internal void init_global_error_collector(void) { mutex_init(&global_error_collector.mutex); mutex_init(&global_error_collector.block_mutex); mutex_init(&global_error_collector.error_out_mutex); @@ -35,9 +35,9 @@ void init_global_error_collector(void) { // temporary // defined in build_settings.cpp -char *token_pos_to_string(TokenPos const &pos); +gb_internal char *token_pos_to_string(TokenPos const &pos); -bool set_file_path_string(i32 index, String const &path) { +gb_internal bool set_file_path_string(i32 index, String const &path) { bool ok = false; GB_ASSERT(index >= 0); mutex_lock(&global_error_collector.string_mutex); @@ -55,7 +55,7 @@ bool set_file_path_string(i32 index, String const &path) { return ok; } -bool thread_safe_set_ast_file_from_id(i32 index, AstFile *file) { +gb_internal bool thread_safe_set_ast_file_from_id(i32 index, AstFile *file) { bool ok = false; GB_ASSERT(index >= 0); mutex_lock(&global_error_collector.string_mutex); @@ -73,7 +73,7 @@ bool thread_safe_set_ast_file_from_id(i32 index, AstFile *file) { return ok; } -String get_file_path_string(i32 index) { +gb_internal String get_file_path_string(i32 index) { GB_ASSERT(index >= 0); mutex_lock(&global_error_collector.string_mutex); @@ -86,7 +86,7 @@ String get_file_path_string(i32 index) { return path; } -AstFile *thread_safe_get_ast_file_from_id(i32 index) { +gb_internal AstFile *thread_safe_get_ast_file_from_id(i32 index) { GB_ASSERT(index >= 0); mutex_lock(&global_error_collector.string_mutex); @@ -101,12 +101,12 @@ AstFile *thread_safe_get_ast_file_from_id(i32 index) { -void begin_error_block(void) { +gb_internal void begin_error_block(void) { mutex_lock(&global_error_collector.block_mutex); global_error_collector.in_block.store(true); } -void end_error_block(void) { +gb_internal void end_error_block(void) { if (global_error_collector.error_buffer.count > 0) { isize n = global_error_collector.error_buffer.count; u8 *text = gb_alloc_array(permanent_allocator(), u8, n+1); @@ -127,7 +127,7 @@ void end_error_block(void) { #define ERROR_OUT_PROC(name) void name(char const *fmt, va_list va) typedef ERROR_OUT_PROC(ErrorOutProc); -ERROR_OUT_PROC(default_error_out_va) { +gb_internal ERROR_OUT_PROC(default_error_out_va) { gbFile *f = gb_file_get_standard(gbFileStandard_Error); char buf[4096] = {}; @@ -154,15 +154,15 @@ ERROR_OUT_PROC(default_error_out_va) { } -ErrorOutProc *error_out_va = default_error_out_va; +gb_global ErrorOutProc *error_out_va = default_error_out_va; // NOTE: defined in build_settings.cpp -bool global_warnings_as_errors(void); -bool global_ignore_warnings(void); -bool show_error_line(void); -gbString get_file_line_as_string(TokenPos const &pos, i32 *offset); +gb_internal bool global_warnings_as_errors(void); +gb_internal bool global_ignore_warnings(void); +gb_internal bool show_error_line(void); +gb_internal gbString get_file_line_as_string(TokenPos const &pos, i32 *offset); -void error_out(char const *fmt, ...) { +gb_internal void error_out(char const *fmt, ...) { va_list va; va_start(va, fmt); error_out_va(fmt, va); @@ -170,7 +170,7 @@ void error_out(char const *fmt, ...) { } -bool show_error_on_line(TokenPos const &pos, TokenPos end) { +gb_internal bool show_error_on_line(TokenPos const &pos, TokenPos end) { if (!show_error_line()) { return false; } @@ -237,7 +237,7 @@ bool show_error_on_line(TokenPos const &pos, TokenPos end) { return false; } -void error_va(TokenPos const &pos, TokenPos end, char const *fmt, va_list va) { +gb_internal void error_va(TokenPos const &pos, TokenPos end, char const *fmt, va_list va) { global_error_collector.count.fetch_add(1); mutex_lock(&global_error_collector.mutex); @@ -257,7 +257,7 @@ void error_va(TokenPos const &pos, TokenPos end, char const *fmt, va_list va) { } } -void warning_va(TokenPos const &pos, TokenPos end, char const *fmt, va_list va) { +gb_internal void warning_va(TokenPos const &pos, TokenPos end, char const *fmt, va_list va) { if (global_warnings_as_errors()) { error_va(pos, end, fmt, va); return; @@ -280,11 +280,11 @@ void warning_va(TokenPos const &pos, TokenPos end, char const *fmt, va_list va) } -void error_line_va(char const *fmt, va_list va) { +gb_internal void error_line_va(char const *fmt, va_list va) { error_out_va(fmt, va); } -void error_no_newline_va(TokenPos const &pos, char const *fmt, va_list va) { +gb_internal void error_no_newline_va(TokenPos const &pos, char const *fmt, va_list va) { mutex_lock(&global_error_collector.mutex); global_error_collector.count++; // NOTE(bill): Duplicate error, skip it @@ -303,7 +303,7 @@ void error_no_newline_va(TokenPos const &pos, char const *fmt, va_list va) { } -void syntax_error_va(TokenPos const &pos, TokenPos end, char const *fmt, va_list va) { +gb_internal void syntax_error_va(TokenPos const &pos, TokenPos end, char const *fmt, va_list va) { mutex_lock(&global_error_collector.mutex); global_error_collector.count++; // NOTE(bill): Duplicate error, skip it @@ -323,7 +323,7 @@ void syntax_error_va(TokenPos const &pos, TokenPos end, char const *fmt, va_list } } -void syntax_warning_va(TokenPos const &pos, TokenPos end, char const *fmt, va_list va) { +gb_internal void syntax_warning_va(TokenPos const &pos, TokenPos end, char const *fmt, va_list va) { if (global_warnings_as_errors()) { syntax_error_va(pos, end, fmt, va); return; @@ -347,21 +347,21 @@ void syntax_warning_va(TokenPos const &pos, TokenPos end, char const *fmt, va_li -void warning(Token const &token, char const *fmt, ...) { +gb_internal void warning(Token const &token, char const *fmt, ...) { va_list va; va_start(va, fmt); warning_va(token.pos, {}, fmt, va); va_end(va); } -void error(Token const &token, char const *fmt, ...) { +gb_internal void error(Token const &token, char const *fmt, ...) { va_list va; va_start(va, fmt); error_va(token.pos, {}, fmt, va); va_end(va); } -void error(TokenPos pos, char const *fmt, ...) { +gb_internal void error(TokenPos pos, char const *fmt, ...) { va_list va; va_start(va, fmt); Token token = {}; @@ -370,7 +370,7 @@ void error(TokenPos pos, char const *fmt, ...) { va_end(va); } -void error_line(char const *fmt, ...) { +gb_internal void error_line(char const *fmt, ...) { va_list va; va_start(va, fmt); error_line_va(fmt, va); @@ -378,21 +378,21 @@ void error_line(char const *fmt, ...) { } -void syntax_error(Token const &token, char const *fmt, ...) { +gb_internal void syntax_error(Token const &token, char const *fmt, ...) { va_list va; va_start(va, fmt); syntax_error_va(token.pos, {}, fmt, va); va_end(va); } -void syntax_error(TokenPos pos, char const *fmt, ...) { +gb_internal void syntax_error(TokenPos pos, char const *fmt, ...) { va_list va; va_start(va, fmt); syntax_error_va(pos, {}, fmt, va); va_end(va); } -void syntax_warning(Token const &token, char const *fmt, ...) { +gb_internal void syntax_warning(Token const &token, char const *fmt, ...) { va_list va; va_start(va, fmt); syntax_warning_va(token.pos, {}, fmt, va); @@ -400,7 +400,7 @@ void syntax_warning(Token const &token, char const *fmt, ...) { } -void compiler_error(char const *fmt, ...) { +gb_internal void compiler_error(char const *fmt, ...) { va_list va; va_start(va, fmt); diff --git a/src/exact_value.cpp b/src/exact_value.cpp index 25ff08a82..d3ea4be68 100644 --- a/src/exact_value.cpp +++ b/src/exact_value.cpp @@ -15,7 +15,7 @@ struct Quaternion256 { f64 imag, jmag, kmag, real; }; -Quaternion256 quaternion256_inverse(Quaternion256 x) { +gb_internal Quaternion256 quaternion256_inverse(Quaternion256 x) { f64 invmag2 = 1.0 / (x.real*x.real + x.imag*x.imag + x.jmag*x.jmag + x.kmag*x.kmag); x.real = +x.real * invmag2; x.imag = -x.imag * invmag2; @@ -60,7 +60,7 @@ struct ExactValue { gb_global ExactValue const empty_exact_value = {}; -uintptr hash_exact_value(ExactValue v) { +gb_internal uintptr hash_exact_value(ExactValue v) { mutex_lock(&hash_exact_value_mutex); defer (mutex_unlock(&hash_exact_value_mutex)); @@ -97,44 +97,44 @@ uintptr hash_exact_value(ExactValue v) { } -ExactValue exact_value_compound(Ast *node) { +gb_internal ExactValue exact_value_compound(Ast *node) { ExactValue result = {ExactValue_Compound}; result.value_compound = node; return result; } -ExactValue exact_value_bool(bool b) { +gb_internal ExactValue exact_value_bool(bool b) { ExactValue result = {ExactValue_Bool}; result.value_bool = (b != 0); return result; } -ExactValue exact_value_string(String string) { +gb_internal ExactValue exact_value_string(String string) { // TODO(bill): Allow for numbers with underscores in them ExactValue result = {ExactValue_String}; result.value_string = string; return result; } -ExactValue exact_value_i64(i64 i) { +gb_internal ExactValue exact_value_i64(i64 i) { ExactValue result = {ExactValue_Integer}; big_int_from_i64(&result.value_integer, i); return result; } -ExactValue exact_value_u64(u64 i) { +gb_internal ExactValue exact_value_u64(u64 i) { ExactValue result = {ExactValue_Integer}; big_int_from_u64(&result.value_integer, i); return result; } -ExactValue exact_value_float(f64 f) { +gb_internal ExactValue exact_value_float(f64 f) { ExactValue result = {ExactValue_Float}; result.value_float = f; return result; } -ExactValue exact_value_complex(f64 real, f64 imag) { +gb_internal ExactValue exact_value_complex(f64 real, f64 imag) { ExactValue result = {ExactValue_Complex}; result.value_complex = gb_alloc_item(permanent_allocator(), Complex128); result.value_complex->real = real; @@ -142,7 +142,7 @@ ExactValue exact_value_complex(f64 real, f64 imag) { return result; } -ExactValue exact_value_quaternion(f64 real, f64 imag, f64 jmag, f64 kmag) { +gb_internal ExactValue exact_value_quaternion(f64 real, f64 imag, f64 jmag, f64 kmag) { ExactValue result = {ExactValue_Quaternion}; result.value_quaternion = gb_alloc_item(permanent_allocator(), Quaternion256); result.value_quaternion->real = real; @@ -152,27 +152,27 @@ ExactValue exact_value_quaternion(f64 real, f64 imag, f64 jmag, f64 kmag) { return result; } -ExactValue exact_value_pointer(i64 ptr) { +gb_internal ExactValue exact_value_pointer(i64 ptr) { ExactValue result = {ExactValue_Pointer}; result.value_pointer = ptr; return result; } -ExactValue exact_value_procedure(Ast *node) { +gb_internal ExactValue exact_value_procedure(Ast *node) { ExactValue result = {ExactValue_Procedure}; result.value_procedure = node; return result; } -ExactValue exact_value_typeid(Type *type) { +gb_internal ExactValue exact_value_typeid(Type *type) { ExactValue result = {ExactValue_Typeid}; result.value_typeid = type; return result; } -ExactValue exact_value_integer_from_string(String const &string) { +gb_internal ExactValue exact_value_integer_from_string(String const &string) { ExactValue result = {ExactValue_Integer}; bool success; big_int_from_string(&result.value_integer, string, &success); @@ -184,7 +184,7 @@ ExactValue exact_value_integer_from_string(String const &string) { -f64 float_from_string(String string) { +gb_internal f64 float_from_string(String string) { isize i = 0; u8 *str = string.text; isize len = string.len; @@ -262,7 +262,7 @@ f64 float_from_string(String string) { return sign * (frac ? (value / scale) : (value * scale)); } -ExactValue exact_value_float_from_string(String string) { +gb_internal ExactValue exact_value_float_from_string(String string) { if (string.len > 2 && string[0] == '0' && string[1] == 'h') { isize digit_count = 0; @@ -298,7 +298,7 @@ ExactValue exact_value_float_from_string(String string) { } -ExactValue exact_value_from_basic_literal(TokenKind kind, String const &string) { +gb_internal ExactValue exact_value_from_basic_literal(TokenKind kind, String const &string) { switch (kind) { case Token_String: return exact_value_string(string); case Token_Integer: return exact_value_integer_from_string(string); @@ -330,7 +330,7 @@ ExactValue exact_value_from_basic_literal(TokenKind kind, String const &string) return result; } -ExactValue exact_value_to_integer(ExactValue v) { +gb_internal ExactValue exact_value_to_integer(ExactValue v) { switch (v.kind) { case ExactValue_Bool: { i64 i = 0; @@ -357,7 +357,7 @@ ExactValue exact_value_to_integer(ExactValue v) { return r; } -ExactValue exact_value_to_float(ExactValue v) { +gb_internal ExactValue exact_value_to_float(ExactValue v) { switch (v.kind) { case ExactValue_Integer: return exact_value_float(big_int_to_f64(&v.value_integer)); @@ -368,7 +368,7 @@ ExactValue exact_value_to_float(ExactValue v) { return r; } -ExactValue exact_value_to_complex(ExactValue v) { +gb_internal ExactValue exact_value_to_complex(ExactValue v) { switch (v.kind) { case ExactValue_Integer: return exact_value_complex(big_int_to_f64(&v.value_integer), 0); @@ -383,7 +383,7 @@ ExactValue exact_value_to_complex(ExactValue v) { v.value_complex = gb_alloc_item(permanent_allocator(), Complex128); return r; } -ExactValue exact_value_to_quaternion(ExactValue v) { +gb_internal ExactValue exact_value_to_quaternion(ExactValue v) { switch (v.kind) { case ExactValue_Integer: return exact_value_quaternion(big_int_to_f64(&v.value_integer), 0, 0, 0); @@ -399,7 +399,7 @@ ExactValue exact_value_to_quaternion(ExactValue v) { return r; } -ExactValue exact_value_real(ExactValue v) { +gb_internal ExactValue exact_value_real(ExactValue v) { switch (v.kind) { case ExactValue_Integer: case ExactValue_Float: @@ -413,7 +413,7 @@ ExactValue exact_value_real(ExactValue v) { return r; } -ExactValue exact_value_imag(ExactValue v) { +gb_internal ExactValue exact_value_imag(ExactValue v) { switch (v.kind) { case ExactValue_Integer: case ExactValue_Float: @@ -427,7 +427,7 @@ ExactValue exact_value_imag(ExactValue v) { return r; } -ExactValue exact_value_jmag(ExactValue v) { +gb_internal ExactValue exact_value_jmag(ExactValue v) { switch (v.kind) { case ExactValue_Integer: case ExactValue_Float: @@ -440,7 +440,7 @@ ExactValue exact_value_jmag(ExactValue v) { return r; } -ExactValue exact_value_kmag(ExactValue v) { +gb_internal ExactValue exact_value_kmag(ExactValue v) { switch (v.kind) { case ExactValue_Integer: case ExactValue_Float: @@ -453,7 +453,7 @@ ExactValue exact_value_kmag(ExactValue v) { return r; } -ExactValue exact_value_make_imag(ExactValue v) { +gb_internal ExactValue exact_value_make_imag(ExactValue v) { switch (v.kind) { case ExactValue_Integer: return exact_value_complex(0, exact_value_to_float(v).value_float); @@ -466,7 +466,7 @@ ExactValue exact_value_make_imag(ExactValue v) { return r; } -ExactValue exact_value_make_jmag(ExactValue v) { +gb_internal ExactValue exact_value_make_jmag(ExactValue v) { switch (v.kind) { case ExactValue_Integer: return exact_value_quaternion(0, 0, exact_value_to_float(v).value_float, 0); @@ -479,7 +479,7 @@ ExactValue exact_value_make_jmag(ExactValue v) { return r; } -ExactValue exact_value_make_kmag(ExactValue v) { +gb_internal ExactValue exact_value_make_kmag(ExactValue v) { switch (v.kind) { case ExactValue_Integer: return exact_value_quaternion(0, 0, 0, exact_value_to_float(v).value_float); @@ -492,21 +492,21 @@ ExactValue exact_value_make_kmag(ExactValue v) { return r; } -i64 exact_value_to_i64(ExactValue v) { +gb_internal i64 exact_value_to_i64(ExactValue v) { v = exact_value_to_integer(v); if (v.kind == ExactValue_Integer) { return big_int_to_i64(&v.value_integer); } return 0; } -u64 exact_value_to_u64(ExactValue v) { +gb_internal u64 exact_value_to_u64(ExactValue v) { v = exact_value_to_integer(v); if (v.kind == ExactValue_Integer) { return big_int_to_u64(&v.value_integer); } return 0; } -f64 exact_value_to_f64(ExactValue v) { +gb_internal f64 exact_value_to_f64(ExactValue v) { v = exact_value_to_float(v); if (v.kind == ExactValue_Float) { return v.value_float; @@ -519,7 +519,7 @@ f64 exact_value_to_f64(ExactValue v) { -ExactValue exact_unary_operator_value(TokenKind op, ExactValue v, i32 precision, bool is_unsigned) { +gb_internal ExactValue exact_unary_operator_value(TokenKind op, ExactValue v, i32 precision, bool is_unsigned) { switch (op) { case Token_Add: { switch (v.kind) { @@ -596,7 +596,7 @@ failure: } // NOTE(bill): Make sure things are evaluated in correct order -i32 exact_value_order(ExactValue const &v) { +gb_internal i32 exact_value_order(ExactValue const &v) { switch (v.kind) { case ExactValue_Invalid: case ExactValue_Compound: @@ -623,7 +623,7 @@ i32 exact_value_order(ExactValue const &v) { } } -void match_exact_values(ExactValue *x, ExactValue *y) { +gb_internal void match_exact_values(ExactValue *x, ExactValue *y) { if (exact_value_order(*y) < exact_value_order(*x)) { match_exact_values(y, x); return; @@ -687,7 +687,7 @@ void match_exact_values(ExactValue *x, ExactValue *y) { } // TODO(bill): Allow for pointer arithmetic? Or are pointer slices good enough? -ExactValue exact_binary_operator_value(TokenKind op, ExactValue x, ExactValue y) { +gb_internal ExactValue exact_binary_operator_value(TokenKind op, ExactValue x, ExactValue y) { match_exact_values(&x, &y); switch (x.kind) { @@ -846,32 +846,32 @@ error:; // NOTE(bill): MSVC accepts this??? apparently you cannot declare variab return empty_exact_value; } -gb_inline ExactValue exact_value_add(ExactValue const &x, ExactValue const &y) { +gb_internal gb_inline ExactValue exact_value_add(ExactValue const &x, ExactValue const &y) { return exact_binary_operator_value(Token_Add, x, y); } -gb_inline ExactValue exact_value_sub(ExactValue const &x, ExactValue const &y) { +gb_internal gb_inline ExactValue exact_value_sub(ExactValue const &x, ExactValue const &y) { return exact_binary_operator_value(Token_Sub, x, y); } -gb_inline ExactValue exact_value_mul(ExactValue const &x, ExactValue const &y) { +gb_internal gb_inline ExactValue exact_value_mul(ExactValue const &x, ExactValue const &y) { return exact_binary_operator_value(Token_Mul, x, y); } -gb_inline ExactValue exact_value_quo(ExactValue const &x, ExactValue const &y) { +gb_internal gb_inline ExactValue exact_value_quo(ExactValue const &x, ExactValue const &y) { return exact_binary_operator_value(Token_Quo, x, y); } -gb_inline ExactValue exact_value_shift(TokenKind op, ExactValue const &x, ExactValue const &y) { +gb_internal gb_inline ExactValue exact_value_shift(TokenKind op, ExactValue const &x, ExactValue const &y) { return exact_binary_operator_value(op, x, y); } -gb_inline ExactValue exact_value_increment_one(ExactValue const &x) { +gb_internal gb_inline ExactValue exact_value_increment_one(ExactValue const &x) { return exact_binary_operator_value(Token_Add, x, exact_value_i64(1)); } -i32 cmp_f64(f64 a, f64 b) { +gb_internal gb_inline i32 cmp_f64(f64 a, f64 b) { return (a > b) - (a < b); } -bool compare_exact_values(TokenKind op, ExactValue x, ExactValue y) { +gb_internal bool compare_exact_values(TokenKind op, ExactValue x, ExactValue y) { match_exact_values(&x, &y); switch (x.kind) { @@ -974,7 +974,7 @@ Entity *strip_entity_wrapping(Entity *e); gbString write_expr_to_string(gbString str, Ast *node, bool shorthand); -gbString write_exact_value_to_string(gbString str, ExactValue const &v, isize string_limit=36) { +gb_internal gbString write_exact_value_to_string(gbString str, ExactValue const &v, isize string_limit=36) { switch (v.kind) { case ExactValue_Invalid: return str; @@ -1017,6 +1017,6 @@ gbString write_exact_value_to_string(gbString str, ExactValue const &v, isize st return str; }; -gbString exact_value_to_string(ExactValue const &v, isize string_limit=36) { +gb_internal gbString exact_value_to_string(ExactValue const &v, isize string_limit=36) { return write_exact_value_to_string(gb_string_make(heap_allocator(), ""), v, string_limit); } diff --git a/src/main.cpp b/src/main.cpp index 3b0a599db..614130bb6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,20 +8,20 @@ #include "build_settings.cpp" gb_global ThreadPool global_thread_pool; -void init_global_thread_pool(void) { +gb_internal void init_global_thread_pool(void) { isize thread_count = gb_max(build_context.thread_count, 1); isize worker_count = thread_count-1; // NOTE(bill): The main thread will also be used for work thread_pool_init(&global_thread_pool, permanent_allocator(), worker_count, "ThreadPoolWorker"); } -bool global_thread_pool_add_task(WorkerTaskProc *proc, void *data) { +gb_internal bool global_thread_pool_add_task(WorkerTaskProc *proc, void *data) { return thread_pool_add_task(&global_thread_pool, proc, data); } -void global_thread_pool_wait(void) { +gb_internal void global_thread_pool_wait(void) { thread_pool_wait(&global_thread_pool); } -void debugf(char const *fmt, ...) { +gb_internal void debugf(char const *fmt, ...) { if (build_context.show_debug_messages) { gb_printf_err("[DEBUG] "); va_list va; @@ -62,7 +62,7 @@ gb_global Timings global_timings = {0}; #include "bug_report.cpp" // NOTE(bill): 'name' is used in debugging and profiling modes -i32 system_exec_command_line_app(char const *name, char const *fmt, ...) { +gb_internal i32 system_exec_command_line_app(char const *name, char const *fmt, ...) { isize const cmd_cap = 64<<20; // 64 MiB should be more than enough char *cmd_line = gb_alloc_array(gb_heap_allocator(), char, cmd_cap); isize cmd_len = 0; @@ -124,7 +124,7 @@ i32 system_exec_command_line_app(char const *name, char const *fmt, ...) { } -i32 linker_stage(lbGenerator *gen) { +gb_internal i32 linker_stage(lbGenerator *gen) { i32 result = 0; Timings *timings = &global_timings; @@ -524,7 +524,7 @@ i32 linker_stage(lbGenerator *gen) { return result; } -Array setup_args(int argc, char const **argv) { +gb_internal Array setup_args(int argc, char const **argv) { gbAllocator a = heap_allocator(); #if defined(GB_SYSTEM_WINDOWS) @@ -553,7 +553,7 @@ Array setup_args(int argc, char const **argv) { #endif } -void print_usage_line(i32 indent, char const *fmt, ...) { +gb_internal void print_usage_line(i32 indent, char const *fmt, ...) { while (indent --> 0) { gb_printf_err("\t"); } @@ -564,7 +564,7 @@ void print_usage_line(i32 indent, char const *fmt, ...) { gb_printf_err("\n"); } -void usage(String argv0) { +gb_internal void usage(String argv0) { print_usage_line(0, "%.*s is a tool for managing Odin source code", LIT(argv0)); print_usage_line(0, "Usage:"); print_usage_line(1, "%.*s command [arguments]", LIT(argv0)); @@ -687,12 +687,12 @@ struct BuildFlag { }; -void add_flag(Array *build_flags, BuildFlagKind kind, String name, BuildFlagParamKind param_kind, u32 command_support, bool allow_mulitple=false) { +gb_internal void add_flag(Array *build_flags, BuildFlagKind kind, String name, BuildFlagParamKind param_kind, u32 command_support, bool allow_mulitple=false) { BuildFlag flag = {kind, name, param_kind, command_support, allow_mulitple}; array_add(build_flags, flag); } -ExactValue build_param_to_exact_value(String name, String param) { +gb_internal ExactValue build_param_to_exact_value(String name, String param) { ExactValue value = {}; /* @@ -747,7 +747,7 @@ ExactValue build_param_to_exact_value(String name, String param) { } // Writes a did-you-mean message for formerly deprecated flags. -void did_you_mean_flag(String flag) { +gb_internal void did_you_mean_flag(String flag) { gbAllocator a = heap_allocator(); String name = copy_string(a, flag); defer (gb_free(a, name.text)); @@ -760,7 +760,7 @@ void did_you_mean_flag(String flag) { gb_printf_err("Unknown flag: '%.*s'\n", LIT(flag)); } -bool parse_build_flags(Array args) { +gb_internal bool parse_build_flags(Array args) { auto build_flags = array_make(heap_allocator(), 0, BuildFlag_COUNT); add_flag(&build_flags, BuildFlag_Help, str_lit("help"), BuildFlagParam_None, Command_all); add_flag(&build_flags, BuildFlag_SingleFile, str_lit("file"), BuildFlagParam_None, Command__does_build | Command__does_check); @@ -1651,7 +1651,7 @@ bool parse_build_flags(Array args) { return !bad_flags; } -void timings_export_all(Timings *t, Checker *c, bool timings_are_finalized = false) { +gb_internal void timings_export_all(Timings *t, Checker *c, bool timings_are_finalized = false) { GB_ASSERT((!(build_context.export_timings_format == TimingsExportUnspecified) && build_context.export_timings_file.len > 0)); /* @@ -1749,7 +1749,7 @@ void timings_export_all(Timings *t, Checker *c, bool timings_are_finalized = fal gb_printf("Done.\n"); } -void show_timings(Checker *c, Timings *t) { +gb_internal void show_timings(Checker *c, Timings *t) { Parser *p = c->parser; isize lines = p->total_line_count; isize tokens = p->total_token_count; @@ -1878,7 +1878,7 @@ void show_timings(Checker *c, Timings *t) { } } -void remove_temp_files(lbGenerator *gen) { +gb_internal void remove_temp_files(lbGenerator *gen) { if (build_context.keep_temp_files) return; TIME_SECTION("remove keep temp files"); @@ -1902,7 +1902,7 @@ void remove_temp_files(lbGenerator *gen) { } -void print_show_help(String const arg0, String const &command) { +gb_internal void print_show_help(String const arg0, String const &command) { print_usage_line(0, "%.*s is a tool for managing Odin source code", LIT(arg0)); print_usage_line(0, "Usage:"); print_usage_line(1, "%.*s %.*s [arguments]", LIT(arg0), LIT(command)); @@ -2248,7 +2248,7 @@ void print_show_help(String const arg0, String const &command) { } } -void print_show_unused(Checker *c) { +gb_internal void print_show_unused(Checker *c) { CheckerInfo *info = &c->info; auto unused = array_make(permanent_allocator(), 0, info->entities.count); @@ -2322,7 +2322,7 @@ void print_show_unused(Checker *c) { print_usage_line(0, ""); } -bool check_env(void) { +gb_internal bool check_env(void) { gbAllocator a = heap_allocator(); char const *odin_root = gb_get_env("ODIN_ROOT", a); defer (gb_free(a, cast(void *)odin_root)); @@ -2348,7 +2348,7 @@ struct StripSemicolonFile { i64 written; }; -gbFileError write_file_with_stripped_tokens(gbFile *f, AstFile *file, i64 *written_) { +gb_internal gbFileError write_file_with_stripped_tokens(gbFile *f, AstFile *file, i64 *written_) { i64 written = 0; gbFileError err = gbFileError_None; u8 const *file_data = file->tokenizer.start; @@ -2388,7 +2388,7 @@ gbFileError write_file_with_stripped_tokens(gbFile *f, AstFile *file, i64 *writt return err; } -int strip_semicolons(Parser *parser) { +gb_internal int strip_semicolons(Parser *parser) { isize file_count = 0; for_array(i, parser->packages) { AstPackage *pkg = parser->packages[i]; diff --git a/src/microsoft_craziness.h b/src/microsoft_craziness.h index fc5f09904..4e6182e07 100644 --- a/src/microsoft_craziness.h +++ b/src/microsoft_craziness.h @@ -58,40 +58,40 @@ struct Find_Result { String vs_library_path; }; -String mc_wstring_to_string(wchar_t const *str) { +gb_internal String mc_wstring_to_string(wchar_t const *str) { return string16_to_string(mc_allocator, make_string16_c(str)); } -String16 mc_string_to_wstring(String str) { +gb_internal String16 mc_string_to_wstring(String str) { return string_to_string16(mc_allocator, str); } -String mc_concat(String a, String b) { +gb_internal String mc_concat(String a, String b) { return concatenate_strings(mc_allocator, a, b); } -String mc_concat(String a, String b, String c) { +gb_internal String mc_concat(String a, String b, String c) { return concatenate3_strings(mc_allocator, a, b, c); } -String mc_concat(String a, String b, String c, String d) { +gb_internal String mc_concat(String a, String b, String c, String d) { return concatenate4_strings(mc_allocator, a, b, c, d); } -String mc_get_env(String key) { +gb_internal String mc_get_env(String key) { char const * value = gb_get_env((char const *)key.text, mc_allocator); return make_string_c(value); } -void mc_free(String str) { +gb_internal void mc_free(String str) { if (str.len) gb_free(mc_allocator, str.text); } -void mc_free(String16 str) { +gb_internal void mc_free(String16 str) { if (str.len) gb_free(mc_allocator, str.text); } -void mc_free_all() { +gb_internal void mc_free_all() { gb_free_all(mc_allocator); } @@ -101,7 +101,7 @@ typedef struct _MC_Find_Data { } MC_Find_Data; -HANDLE mc_find_first(String wildcard, MC_Find_Data *find_data) { +gb_internal HANDLE mc_find_first(String wildcard, MC_Find_Data *find_data) { WIN32_FIND_DATAW _find_data; String16 wildcard_wide = mc_string_to_wstring(wildcard); @@ -115,7 +115,7 @@ HANDLE mc_find_first(String wildcard, MC_Find_Data *find_data) { return handle; } -bool mc_find_next(HANDLE handle, MC_Find_Data *find_data) { +gb_internal bool mc_find_next(HANDLE handle, MC_Find_Data *find_data) { WIN32_FIND_DATAW _find_data; bool success = !!FindNextFileW(handle, &_find_data); @@ -124,7 +124,7 @@ bool mc_find_next(HANDLE handle, MC_Find_Data *find_data) { return success; } -void mc_find_close(HANDLE handle) { +gb_internal void mc_find_close(HANDLE handle) { FindClose(handle); } @@ -216,7 +216,7 @@ struct Version_Data { }; typedef void (*MC_Visit_Proc)(String short_name, String full_name, Version_Data *data); -bool mc_visit_files(String dir_name, Version_Data *data, MC_Visit_Proc proc) { +gb_internal bool mc_visit_files(String dir_name, Version_Data *data, MC_Visit_Proc proc) { // Visit everything in one folder (non-recursively). If it's a directory // that doesn't start with ".", call the visit proc on it. The visit proc @@ -246,7 +246,7 @@ bool mc_visit_files(String dir_name, Version_Data *data, MC_Visit_Proc proc) { return true; } -String find_windows_kit_root(HKEY key, String const version) { +gb_internal String find_windows_kit_root(HKEY key, String const version) { // Given a key to an already opened registry entry, // get the value stored under the 'version' subkey. // If that's not the right terminology, hey, I never do registry stuff. @@ -275,7 +275,7 @@ String find_windows_kit_root(HKEY key, String const version) { return value; } -void win10_best(String short_name, String full_name, Version_Data *data) { +gb_internal void win10_best(String short_name, String full_name, Version_Data *data) { // Find the Windows 10 subdirectory with the highest version number. int i0, i1, i2, i3; @@ -307,7 +307,7 @@ void win10_best(String short_name, String full_name, Version_Data *data) { } } -void find_windows_kit_paths(Find_Result *result) { +gb_internal void find_windows_kit_paths(Find_Result *result) { bool sdk_found = false; HKEY main_key; @@ -355,7 +355,7 @@ void find_windows_kit_paths(Find_Result *result) { } } -bool find_visual_studio_by_fighting_through_microsoft_craziness(Find_Result *result) { +gb_internal bool find_visual_studio_by_fighting_through_microsoft_craziness(Find_Result *result) { // The name of this procedure is kind of cryptic. Its purpose is // to fight through Microsoft craziness. The things that the fine // Visual Studio team want you to do, JUST TO FIND A SINGLE FOLDER @@ -519,7 +519,7 @@ bool find_visual_studio_by_fighting_through_microsoft_craziness(Find_Result *res // NOTE(WalterPlinge): Environment variables can help to find Visual C++ and WinSDK paths for both // official and portable installations (like mmozeiko's portable msvc script). -void find_windows_kit_paths_from_env_vars(Find_Result *result) { +gb_internal void find_windows_kit_paths_from_env_vars(Find_Result *result) { if (build_context.metrics.arch != TargetArch_amd64 && build_context.metrics.arch != TargetArch_i386) { return; } @@ -669,7 +669,7 @@ void find_windows_kit_paths_from_env_vars(Find_Result *result) { // NOTE(WalterPlinge): Environment variables can help to find Visual C++ and WinSDK paths for both // official and portable installations (like mmozeiko's portable msvc script). This will only use // the first paths it finds, and won't overwrite any values that `result` already has. -void find_visual_studio_paths_from_env_vars(Find_Result *result) { +gb_internal void find_visual_studio_paths_from_env_vars(Find_Result *result) { if (build_context.metrics.arch != TargetArch_amd64 && build_context.metrics.arch != TargetArch_i386) { return; } @@ -756,7 +756,7 @@ void find_visual_studio_paths_from_env_vars(Find_Result *result) { } } -Find_Result find_visual_studio_and_windows_sdk() { +gb_internal Find_Result find_visual_studio_and_windows_sdk() { Find_Result r = {}; find_windows_kit_paths(&r); find_visual_studio_by_fighting_through_microsoft_craziness(&r); diff --git a/src/parser.cpp b/src/parser.cpp index 884ddefa2..1606f5b47 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -3,7 +3,7 @@ // #undef at the bottom of this file #define ALLOW_NEWLINE (!build_context.strict_style) -Token token_end_of_line(AstFile *f, Token tok) { +gb_internal Token token_end_of_line(AstFile *f, Token tok) { u8 const *start = f->tokenizer.start + tok.pos.offset; u8 const *s = start; while (*s && *s != '\n' && s < f->tokenizer.end) { @@ -13,7 +13,7 @@ Token token_end_of_line(AstFile *f, Token tok) { return tok; } -gbString get_file_line_as_string(TokenPos const &pos, i32 *offset_) { +gb_internal gbString get_file_line_as_string(TokenPos const &pos, i32 *offset_) { AstFile *file = thread_safe_get_ast_file_from_id(pos.file_id); if (file == nullptr) { return nullptr; @@ -55,7 +55,7 @@ gbString get_file_line_as_string(TokenPos const &pos, i32 *offset_) { -isize ast_node_size(AstKind kind) { +gb_internal isize ast_node_size(AstKind kind) { return align_formula_isize(gb_size_of(AstCommonStuff) + ast_variant_sizes[kind], gb_align_of(void *)); } @@ -63,7 +63,7 @@ isize ast_node_size(AstKind kind) { gb_global std::atomic global_total_node_memory_allocated; // NOTE(bill): And this below is why is I/we need a new language! Discriminated unions are a pain in C/C++ -Ast *alloc_ast_node(AstFile *f, AstKind kind) { +gb_internal Ast *alloc_ast_node(AstFile *f, AstKind kind) { gbAllocator a = ast_allocator(f); isize size = ast_node_size(kind); @@ -77,8 +77,8 @@ Ast *alloc_ast_node(AstFile *f, AstKind kind) { return node; } -Ast *clone_ast(Ast *node); -Array clone_ast_array(Array const &array) { +gb_internal Ast *clone_ast(Ast *node); +gb_internal Array clone_ast_array(Array const &array) { Array result = {}; if (array.count > 0) { result = array_make(ast_allocator(nullptr), array.count); @@ -88,7 +88,7 @@ Array clone_ast_array(Array const &array) { } return result; } -Slice clone_ast_array(Slice const &array) { +gb_internal Slice clone_ast_array(Slice const &array) { Slice result = {}; if (array.count > 0) { result = slice_clone(permanent_allocator(), array); @@ -99,7 +99,7 @@ Slice clone_ast_array(Slice const &array) { return result; } -Ast *clone_ast(Ast *node) { +gb_internal Ast *clone_ast(Ast *node) { if (node == nullptr) { return nullptr; } @@ -403,7 +403,7 @@ Ast *clone_ast(Ast *node) { } -void error(Ast *node, char const *fmt, ...) { +gb_internal void error(Ast *node, char const *fmt, ...) { Token token = {}; TokenPos end_pos = {}; if (node != nullptr) { @@ -421,7 +421,7 @@ void error(Ast *node, char const *fmt, ...) { } } -void error_no_newline(Ast *node, char const *fmt, ...) { +gb_internal void error_no_newline(Ast *node, char const *fmt, ...) { Token token = {}; if (node != nullptr) { token = ast_token(node); @@ -436,7 +436,7 @@ void error_no_newline(Ast *node, char const *fmt, ...) { } } -void warning(Ast *node, char const *fmt, ...) { +gb_internal void warning(Ast *node, char const *fmt, ...) { Token token = {}; TokenPos end_pos = {}; if (node != nullptr) { @@ -449,7 +449,7 @@ void warning(Ast *node, char const *fmt, ...) { va_end(va); } -void syntax_error(Ast *node, char const *fmt, ...) { +gb_internal void syntax_error(Ast *node, char const *fmt, ...) { Token token = {}; TokenPos end_pos = {}; if (node != nullptr) { @@ -467,14 +467,14 @@ void syntax_error(Ast *node, char const *fmt, ...) { } -bool ast_node_expect(Ast *node, AstKind kind) { +gb_internal bool ast_node_expect(Ast *node, AstKind kind) { if (node->kind != kind) { syntax_error(node, "Expected %.*s, got %.*s", LIT(ast_strings[kind]), LIT(ast_strings[node->kind])); return false; } return true; } -bool ast_node_expect2(Ast *node, AstKind kind0, AstKind kind1) { +gb_internal bool ast_node_expect2(Ast *node, AstKind kind0, AstKind kind1) { if (node->kind != kind0 && node->kind != kind1) { syntax_error(node, "Expected %.*s or %.*s, got %.*s", LIT(ast_strings[kind0]), LIT(ast_strings[kind1]), LIT(ast_strings[node->kind])); return false; @@ -482,14 +482,14 @@ bool ast_node_expect2(Ast *node, AstKind kind0, AstKind kind1) { return true; } -Ast *ast_bad_expr(AstFile *f, Token begin, Token end) { +gb_internal Ast *ast_bad_expr(AstFile *f, Token begin, Token end) { Ast *result = alloc_ast_node(f, Ast_BadExpr); result->BadExpr.begin = begin; result->BadExpr.end = end; return result; } -Ast *ast_tag_expr(AstFile *f, Token token, Token name, Ast *expr) { +gb_internal Ast *ast_tag_expr(AstFile *f, Token token, Token name, Ast *expr) { Ast *result = alloc_ast_node(f, Ast_TagExpr); result->TagExpr.token = token; result->TagExpr.name = name; @@ -497,7 +497,7 @@ Ast *ast_tag_expr(AstFile *f, Token token, Token name, Ast *expr) { return result; } -Ast *ast_tag_stmt(AstFile *f, Token token, Token name, Ast *stmt) { +gb_internal Ast *ast_tag_stmt(AstFile *f, Token token, Token name, Ast *stmt) { Ast *result = alloc_ast_node(f, Ast_TagStmt); result->TagStmt.token = token; result->TagStmt.name = name; @@ -505,14 +505,14 @@ Ast *ast_tag_stmt(AstFile *f, Token token, Token name, Ast *stmt) { return result; } -Ast *ast_unary_expr(AstFile *f, Token op, Ast *expr) { +gb_internal Ast *ast_unary_expr(AstFile *f, Token op, Ast *expr) { Ast *result = alloc_ast_node(f, Ast_UnaryExpr); result->UnaryExpr.op = op; result->UnaryExpr.expr = expr; return result; } -Ast *ast_binary_expr(AstFile *f, Token op, Ast *left, Ast *right) { +gb_internal Ast *ast_binary_expr(AstFile *f, Token op, Ast *left, Ast *right) { Ast *result = alloc_ast_node(f, Ast_BinaryExpr); if (left == nullptr) { @@ -531,7 +531,7 @@ Ast *ast_binary_expr(AstFile *f, Token op, Ast *left, Ast *right) { return result; } -Ast *ast_paren_expr(AstFile *f, Ast *expr, Token open, Token close) { +gb_internal Ast *ast_paren_expr(AstFile *f, Ast *expr, Token open, Token close) { Ast *result = alloc_ast_node(f, Ast_ParenExpr); result->ParenExpr.expr = expr; result->ParenExpr.open = open; @@ -539,7 +539,7 @@ Ast *ast_paren_expr(AstFile *f, Ast *expr, Token open, Token close) { return result; } -Ast *ast_call_expr(AstFile *f, Ast *proc, Array const &args, Token open, Token close, Token ellipsis) { +gb_internal Ast *ast_call_expr(AstFile *f, Ast *proc, Array const &args, Token open, Token close, Token ellipsis) { Ast *result = alloc_ast_node(f, Ast_CallExpr); result->CallExpr.proc = proc; result->CallExpr.args = slice_from_array(args); @@ -550,7 +550,7 @@ Ast *ast_call_expr(AstFile *f, Ast *proc, Array const &args, Token open, } -Ast *ast_selector_expr(AstFile *f, Token token, Ast *expr, Ast *selector) { +gb_internal Ast *ast_selector_expr(AstFile *f, Token token, Ast *expr, Ast *selector) { Ast *result = alloc_ast_node(f, Ast_SelectorExpr); result->SelectorExpr.token = token; result->SelectorExpr.expr = expr; @@ -558,14 +558,14 @@ Ast *ast_selector_expr(AstFile *f, Token token, Ast *expr, Ast *selector) { return result; } -Ast *ast_implicit_selector_expr(AstFile *f, Token token, Ast *selector) { +gb_internal Ast *ast_implicit_selector_expr(AstFile *f, Token token, Ast *selector) { Ast *result = alloc_ast_node(f, Ast_ImplicitSelectorExpr); result->ImplicitSelectorExpr.token = token; result->ImplicitSelectorExpr.selector = selector; return result; } -Ast *ast_selector_call_expr(AstFile *f, Token token, Ast *expr, Ast *call) { +gb_internal Ast *ast_selector_call_expr(AstFile *f, Token token, Ast *expr, Ast *call) { Ast *result = alloc_ast_node(f, Ast_SelectorCallExpr); result->SelectorCallExpr.token = token; result->SelectorCallExpr.expr = expr; @@ -574,7 +574,7 @@ Ast *ast_selector_call_expr(AstFile *f, Token token, Ast *expr, Ast *call) { } -Ast *ast_index_expr(AstFile *f, Ast *expr, Ast *index, Token open, Token close) { +gb_internal Ast *ast_index_expr(AstFile *f, Ast *expr, Ast *index, Token open, Token close) { Ast *result = alloc_ast_node(f, Ast_IndexExpr); result->IndexExpr.expr = expr; result->IndexExpr.index = index; @@ -584,7 +584,7 @@ Ast *ast_index_expr(AstFile *f, Ast *expr, Ast *index, Token open, Token close) } -Ast *ast_slice_expr(AstFile *f, Ast *expr, Token open, Token close, Token interval, Ast *low, Ast *high) { +gb_internal Ast *ast_slice_expr(AstFile *f, Ast *expr, Token open, Token close, Token interval, Ast *low, Ast *high) { Ast *result = alloc_ast_node(f, Ast_SliceExpr); result->SliceExpr.expr = expr; result->SliceExpr.open = open; @@ -595,7 +595,7 @@ Ast *ast_slice_expr(AstFile *f, Ast *expr, Token open, Token close, Token interv return result; } -Ast *ast_deref_expr(AstFile *f, Ast *expr, Token op) { +gb_internal Ast *ast_deref_expr(AstFile *f, Ast *expr, Token op) { Ast *result = alloc_ast_node(f, Ast_DerefExpr); result->DerefExpr.expr = expr; result->DerefExpr.op = op; @@ -603,7 +603,7 @@ Ast *ast_deref_expr(AstFile *f, Ast *expr, Token op) { } -Ast *ast_matrix_index_expr(AstFile *f, Ast *expr, Token open, Token close, Token interval, Ast *row, Ast *column) { +gb_internal Ast *ast_matrix_index_expr(AstFile *f, Ast *expr, Token open, Token close, Token interval, Ast *row, Ast *column) { Ast *result = alloc_ast_node(f, Ast_MatrixIndexExpr); result->MatrixIndexExpr.expr = expr; result->MatrixIndexExpr.row_index = row; @@ -614,24 +614,24 @@ Ast *ast_matrix_index_expr(AstFile *f, Ast *expr, Token open, Token close, Token } -Ast *ast_ident(AstFile *f, Token token) { +gb_internal Ast *ast_ident(AstFile *f, Token token) { Ast *result = alloc_ast_node(f, Ast_Ident); result->Ident.token = token; return result; } -Ast *ast_implicit(AstFile *f, Token token) { +gb_internal Ast *ast_implicit(AstFile *f, Token token) { Ast *result = alloc_ast_node(f, Ast_Implicit); result->Implicit = token; return result; } -Ast *ast_undef(AstFile *f, Token token) { +gb_internal Ast *ast_undef(AstFile *f, Token token) { Ast *result = alloc_ast_node(f, Ast_Undef); result->Undef = token; return result; } -ExactValue exact_value_from_token(AstFile *f, Token const &token) { +gb_internal ExactValue exact_value_from_token(AstFile *f, Token const &token) { String s = token.string; switch (token.kind) { case Token_Rune: @@ -648,7 +648,7 @@ ExactValue exact_value_from_token(AstFile *f, Token const &token) { return exact_value_from_basic_literal(token.kind, s); } -String string_value_from_token(AstFile *f, Token const &token) { +gb_internal String string_value_from_token(AstFile *f, Token const &token) { ExactValue value = exact_value_from_token(f, token); String str = {}; if (value.kind == ExactValue_String) { @@ -658,7 +658,7 @@ String string_value_from_token(AstFile *f, Token const &token) { } -Ast *ast_basic_lit(AstFile *f, Token basic_lit) { +gb_internal Ast *ast_basic_lit(AstFile *f, Token basic_lit) { Ast *result = alloc_ast_node(f, Ast_BasicLit); result->BasicLit.token = basic_lit; result->tav.mode = Addressing_Constant; @@ -666,14 +666,14 @@ Ast *ast_basic_lit(AstFile *f, Token basic_lit) { return result; } -Ast *ast_basic_directive(AstFile *f, Token token, Token name) { +gb_internal Ast *ast_basic_directive(AstFile *f, Token token, Token name) { Ast *result = alloc_ast_node(f, Ast_BasicDirective); result->BasicDirective.token = token; result->BasicDirective.name = name; return result; } -Ast *ast_ellipsis(AstFile *f, Token token, Ast *expr) { +gb_internal Ast *ast_ellipsis(AstFile *f, Token token, Ast *expr) { Ast *result = alloc_ast_node(f, Ast_Ellipsis); result->Ellipsis.token = token; result->Ellipsis.expr = expr; @@ -681,7 +681,7 @@ Ast *ast_ellipsis(AstFile *f, Token token, Ast *expr) { } -Ast *ast_proc_group(AstFile *f, Token token, Token open, Token close, Array const &args) { +gb_internal Ast *ast_proc_group(AstFile *f, Token token, Token open, Token close, Array const &args) { Ast *result = alloc_ast_node(f, Ast_ProcGroup); result->ProcGroup.token = token; result->ProcGroup.open = open; @@ -690,7 +690,7 @@ Ast *ast_proc_group(AstFile *f, Token token, Token open, Token close, Array const &where_clauses) { +gb_internal Ast *ast_proc_lit(AstFile *f, Ast *type, Ast *body, u64 tags, Token where_token, Array const &where_clauses) { Ast *result = alloc_ast_node(f, Ast_ProcLit); result->ProcLit.type = type; result->ProcLit.body = body; @@ -700,7 +700,7 @@ Ast *ast_proc_lit(AstFile *f, Ast *type, Ast *body, u64 tags, Token where_token, return result; } -Ast *ast_field_value(AstFile *f, Ast *field, Ast *value, Token eq) { +gb_internal Ast *ast_field_value(AstFile *f, Ast *field, Ast *value, Token eq) { Ast *result = alloc_ast_node(f, Ast_FieldValue); result->FieldValue.field = field; result->FieldValue.value = value; @@ -709,7 +709,7 @@ Ast *ast_field_value(AstFile *f, Ast *field, Ast *value, Token eq) { } -Ast *ast_enum_field_value(AstFile *f, Ast *name, Ast *value, CommentGroup *docs, CommentGroup *comment) { +gb_internal Ast *ast_enum_field_value(AstFile *f, Ast *name, Ast *value, CommentGroup *docs, CommentGroup *comment) { Ast *result = alloc_ast_node(f, Ast_EnumFieldValue); result->EnumFieldValue.name = name; result->EnumFieldValue.value = value; @@ -718,7 +718,7 @@ Ast *ast_enum_field_value(AstFile *f, Ast *name, Ast *value, CommentGroup *docs, return result; } -Ast *ast_compound_lit(AstFile *f, Ast *type, Array const &elems, Token open, Token close) { +gb_internal Ast *ast_compound_lit(AstFile *f, Ast *type, Array const &elems, Token open, Token close) { Ast *result = alloc_ast_node(f, Ast_CompoundLit); result->CompoundLit.type = type; result->CompoundLit.elems = slice_from_array(elems); @@ -728,14 +728,14 @@ Ast *ast_compound_lit(AstFile *f, Ast *type, Array const &elems, Token op } -Ast *ast_ternary_if_expr(AstFile *f, Ast *x, Ast *cond, Ast *y) { +gb_internal Ast *ast_ternary_if_expr(AstFile *f, Ast *x, Ast *cond, Ast *y) { Ast *result = alloc_ast_node(f, Ast_TernaryIfExpr); result->TernaryIfExpr.x = x; result->TernaryIfExpr.cond = cond; result->TernaryIfExpr.y = y; return result; } -Ast *ast_ternary_when_expr(AstFile *f, Ast *x, Ast *cond, Ast *y) { +gb_internal Ast *ast_ternary_when_expr(AstFile *f, Ast *x, Ast *cond, Ast *y) { Ast *result = alloc_ast_node(f, Ast_TernaryWhenExpr); result->TernaryWhenExpr.x = x; result->TernaryWhenExpr.cond = cond; @@ -743,7 +743,7 @@ Ast *ast_ternary_when_expr(AstFile *f, Ast *x, Ast *cond, Ast *y) { return result; } -Ast *ast_or_else_expr(AstFile *f, Ast *x, Token const &token, Ast *y) { +gb_internal Ast *ast_or_else_expr(AstFile *f, Ast *x, Token const &token, Ast *y) { Ast *result = alloc_ast_node(f, Ast_OrElseExpr); result->OrElseExpr.x = x; result->OrElseExpr.token = token; @@ -751,28 +751,28 @@ Ast *ast_or_else_expr(AstFile *f, Ast *x, Token const &token, Ast *y) { return result; } -Ast *ast_or_return_expr(AstFile *f, Ast *expr, Token const &token) { +gb_internal Ast *ast_or_return_expr(AstFile *f, Ast *expr, Token const &token) { Ast *result = alloc_ast_node(f, Ast_OrReturnExpr); result->OrReturnExpr.expr = expr; result->OrReturnExpr.token = token; return result; } -Ast *ast_type_assertion(AstFile *f, Ast *expr, Token dot, Ast *type) { +gb_internal Ast *ast_type_assertion(AstFile *f, Ast *expr, Token dot, Ast *type) { Ast *result = alloc_ast_node(f, Ast_TypeAssertion); result->TypeAssertion.expr = expr; result->TypeAssertion.dot = dot; result->TypeAssertion.type = type; return result; } -Ast *ast_type_cast(AstFile *f, Token token, Ast *type, Ast *expr) { +gb_internal Ast *ast_type_cast(AstFile *f, Token token, Ast *type, Ast *expr) { Ast *result = alloc_ast_node(f, Ast_TypeCast); result->TypeCast.token = token; result->TypeCast.type = type; result->TypeCast.expr = expr; return result; } -Ast *ast_auto_cast(AstFile *f, Token token, Ast *expr) { +gb_internal Ast *ast_auto_cast(AstFile *f, Token token, Ast *expr) { Ast *result = alloc_ast_node(f, Ast_AutoCast); result->AutoCast.token = token; result->AutoCast.expr = expr; @@ -780,7 +780,7 @@ Ast *ast_auto_cast(AstFile *f, Token token, Ast *expr) { } -Ast *ast_inline_asm_expr(AstFile *f, Token token, Token open, Token close, +gb_internal Ast *ast_inline_asm_expr(AstFile *f, Token token, Token open, Token close, Array const ¶m_types, Ast *return_type, Ast *asm_string, @@ -806,26 +806,26 @@ Ast *ast_inline_asm_expr(AstFile *f, Token token, Token open, Token close, -Ast *ast_bad_stmt(AstFile *f, Token begin, Token end) { +gb_internal Ast *ast_bad_stmt(AstFile *f, Token begin, Token end) { Ast *result = alloc_ast_node(f, Ast_BadStmt); result->BadStmt.begin = begin; result->BadStmt.end = end; return result; } -Ast *ast_empty_stmt(AstFile *f, Token token) { +gb_internal Ast *ast_empty_stmt(AstFile *f, Token token) { Ast *result = alloc_ast_node(f, Ast_EmptyStmt); result->EmptyStmt.token = token; return result; } -Ast *ast_expr_stmt(AstFile *f, Ast *expr) { +gb_internal Ast *ast_expr_stmt(AstFile *f, Ast *expr) { Ast *result = alloc_ast_node(f, Ast_ExprStmt); result->ExprStmt.expr = expr; return result; } -Ast *ast_assign_stmt(AstFile *f, Token op, Array const &lhs, Array const &rhs) { +gb_internal Ast *ast_assign_stmt(AstFile *f, Token op, Array const &lhs, Array const &rhs) { Ast *result = alloc_ast_node(f, Ast_AssignStmt); result->AssignStmt.op = op; result->AssignStmt.lhs = slice_from_array(lhs); @@ -834,7 +834,7 @@ Ast *ast_assign_stmt(AstFile *f, Token op, Array const &lhs, Array } -Ast *ast_block_stmt(AstFile *f, Array const &stmts, Token open, Token close) { +gb_internal Ast *ast_block_stmt(AstFile *f, Array const &stmts, Token open, Token close) { Ast *result = alloc_ast_node(f, Ast_BlockStmt); result->BlockStmt.stmts = slice_from_array(stmts); result->BlockStmt.open = open; @@ -842,7 +842,7 @@ Ast *ast_block_stmt(AstFile *f, Array const &stmts, Token open, Token clo return result; } -Ast *ast_if_stmt(AstFile *f, Token token, Ast *init, Ast *cond, Ast *body, Ast *else_stmt) { +gb_internal Ast *ast_if_stmt(AstFile *f, Token token, Ast *init, Ast *cond, Ast *body, Ast *else_stmt) { Ast *result = alloc_ast_node(f, Ast_IfStmt); result->IfStmt.token = token; result->IfStmt.init = init; @@ -852,7 +852,7 @@ Ast *ast_if_stmt(AstFile *f, Token token, Ast *init, Ast *cond, Ast *body, Ast * return result; } -Ast *ast_when_stmt(AstFile *f, Token token, Ast *cond, Ast *body, Ast *else_stmt) { +gb_internal Ast *ast_when_stmt(AstFile *f, Token token, Ast *cond, Ast *body, Ast *else_stmt) { Ast *result = alloc_ast_node(f, Ast_WhenStmt); result->WhenStmt.token = token; result->WhenStmt.cond = cond; @@ -862,7 +862,7 @@ Ast *ast_when_stmt(AstFile *f, Token token, Ast *cond, Ast *body, Ast *else_stmt } -Ast *ast_return_stmt(AstFile *f, Token token, Array const &results) { +gb_internal Ast *ast_return_stmt(AstFile *f, Token token, Array const &results) { Ast *result = alloc_ast_node(f, Ast_ReturnStmt); result->ReturnStmt.token = token; result->ReturnStmt.results = slice_from_array(results); @@ -870,7 +870,7 @@ Ast *ast_return_stmt(AstFile *f, Token token, Array const &results) { } -Ast *ast_for_stmt(AstFile *f, Token token, Ast *init, Ast *cond, Ast *post, Ast *body) { +gb_internal Ast *ast_for_stmt(AstFile *f, Token token, Ast *init, Ast *cond, Ast *post, Ast *body) { Ast *result = alloc_ast_node(f, Ast_ForStmt); result->ForStmt.token = token; result->ForStmt.init = init; @@ -880,7 +880,7 @@ Ast *ast_for_stmt(AstFile *f, Token token, Ast *init, Ast *cond, Ast *post, Ast return result; } -Ast *ast_range_stmt(AstFile *f, Token token, Slice vals, Token in_token, Ast *expr, Ast *body) { +gb_internal Ast *ast_range_stmt(AstFile *f, Token token, Slice vals, Token in_token, Ast *expr, Ast *body) { Ast *result = alloc_ast_node(f, Ast_RangeStmt); result->RangeStmt.token = token; result->RangeStmt.vals = vals; @@ -890,7 +890,7 @@ Ast *ast_range_stmt(AstFile *f, Token token, Slice vals, Token in_token, return result; } -Ast *ast_unroll_range_stmt(AstFile *f, Token unroll_token, Token for_token, Ast *val0, Ast *val1, Token in_token, Ast *expr, Ast *body) { +gb_internal Ast *ast_unroll_range_stmt(AstFile *f, Token unroll_token, Token for_token, Ast *val0, Ast *val1, Token in_token, Ast *expr, Ast *body) { Ast *result = alloc_ast_node(f, Ast_UnrollRangeStmt); result->UnrollRangeStmt.unroll_token = unroll_token; result->UnrollRangeStmt.for_token = for_token; @@ -902,7 +902,7 @@ Ast *ast_unroll_range_stmt(AstFile *f, Token unroll_token, Token for_token, Ast return result; } -Ast *ast_switch_stmt(AstFile *f, Token token, Ast *init, Ast *tag, Ast *body) { +gb_internal Ast *ast_switch_stmt(AstFile *f, Token token, Ast *init, Ast *tag, Ast *body) { Ast *result = alloc_ast_node(f, Ast_SwitchStmt); result->SwitchStmt.token = token; result->SwitchStmt.init = init; @@ -913,7 +913,7 @@ Ast *ast_switch_stmt(AstFile *f, Token token, Ast *init, Ast *tag, Ast *body) { } -Ast *ast_type_switch_stmt(AstFile *f, Token token, Ast *tag, Ast *body) { +gb_internal Ast *ast_type_switch_stmt(AstFile *f, Token token, Ast *tag, Ast *body) { Ast *result = alloc_ast_node(f, Ast_TypeSwitchStmt); result->TypeSwitchStmt.token = token; result->TypeSwitchStmt.tag = tag; @@ -922,7 +922,7 @@ Ast *ast_type_switch_stmt(AstFile *f, Token token, Ast *tag, Ast *body) { return result; } -Ast *ast_case_clause(AstFile *f, Token token, Array const &list, Array const &stmts) { +gb_internal Ast *ast_case_clause(AstFile *f, Token token, Array const &list, Array const &stmts) { Ast *result = alloc_ast_node(f, Ast_CaseClause); result->CaseClause.token = token; result->CaseClause.list = slice_from_array(list); @@ -931,21 +931,21 @@ Ast *ast_case_clause(AstFile *f, Token token, Array const &list, ArrayDeferStmt.token = token; result->DeferStmt.stmt = stmt; return result; } -Ast *ast_branch_stmt(AstFile *f, Token token, Ast *label) { +gb_internal Ast *ast_branch_stmt(AstFile *f, Token token, Ast *label) { Ast *result = alloc_ast_node(f, Ast_BranchStmt); result->BranchStmt.token = token; result->BranchStmt.label = label; return result; } -Ast *ast_using_stmt(AstFile *f, Token token, Array const &list) { +gb_internal Ast *ast_using_stmt(AstFile *f, Token token, Array const &list) { Ast *result = alloc_ast_node(f, Ast_UsingStmt); result->UsingStmt.token = token; result->UsingStmt.list = slice_from_array(list); @@ -954,14 +954,14 @@ Ast *ast_using_stmt(AstFile *f, Token token, Array const &list) { -Ast *ast_bad_decl(AstFile *f, Token begin, Token end) { +gb_internal Ast *ast_bad_decl(AstFile *f, Token begin, Token end) { Ast *result = alloc_ast_node(f, Ast_BadDecl); result->BadDecl.begin = begin; result->BadDecl.end = end; return result; } -Ast *ast_field(AstFile *f, Array const &names, Ast *type, Ast *default_value, u32 flags, Token tag, +gb_internal Ast *ast_field(AstFile *f, Array const &names, Ast *type, Ast *default_value, u32 flags, Token tag, CommentGroup *docs, CommentGroup *comment) { Ast *result = alloc_ast_node(f, Ast_Field); result->Field.names = slice_from_array(names); @@ -974,28 +974,28 @@ Ast *ast_field(AstFile *f, Array const &names, Ast *type, Ast *default_va return result; } -Ast *ast_field_list(AstFile *f, Token token, Array const &list) { +gb_internal Ast *ast_field_list(AstFile *f, Token token, Array const &list) { Ast *result = alloc_ast_node(f, Ast_FieldList); result->FieldList.token = token; result->FieldList.list = slice_from_array(list); return result; } -Ast *ast_typeid_type(AstFile *f, Token token, Ast *specialization) { +gb_internal Ast *ast_typeid_type(AstFile *f, Token token, Ast *specialization) { Ast *result = alloc_ast_node(f, Ast_TypeidType); result->TypeidType.token = token; result->TypeidType.specialization = specialization; return result; } -Ast *ast_helper_type(AstFile *f, Token token, Ast *type) { +gb_internal Ast *ast_helper_type(AstFile *f, Token token, Ast *type) { Ast *result = alloc_ast_node(f, Ast_HelperType); result->HelperType.token = token; result->HelperType.type = type; return result; } -Ast *ast_distinct_type(AstFile *f, Token token, Ast *type) { +gb_internal Ast *ast_distinct_type(AstFile *f, Token token, Ast *type) { Ast *result = alloc_ast_node(f, Ast_DistinctType); result->DistinctType.token = token; result->DistinctType.type = type; @@ -1003,7 +1003,7 @@ Ast *ast_distinct_type(AstFile *f, Token token, Ast *type) { } -Ast *ast_poly_type(AstFile *f, Token token, Ast *type, Ast *specialization) { +gb_internal Ast *ast_poly_type(AstFile *f, Token token, Ast *type, Ast *specialization) { Ast *result = alloc_ast_node(f, Ast_PolyType); result->PolyType.token = token; result->PolyType.type = type; @@ -1012,7 +1012,7 @@ Ast *ast_poly_type(AstFile *f, Token token, Ast *type, Ast *specialization) { } -Ast *ast_proc_type(AstFile *f, Token token, Ast *params, Ast *results, u64 tags, ProcCallingConvention calling_convention, bool generic, bool diverging) { +gb_internal Ast *ast_proc_type(AstFile *f, Token token, Ast *params, Ast *results, u64 tags, ProcCallingConvention calling_convention, bool generic, bool diverging) { Ast *result = alloc_ast_node(f, Ast_ProcType); result->ProcType.token = token; result->ProcType.params = params; @@ -1024,25 +1024,25 @@ Ast *ast_proc_type(AstFile *f, Token token, Ast *params, Ast *results, u64 tags, return result; } -Ast *ast_relative_type(AstFile *f, Ast *tag, Ast *type) { +gb_internal Ast *ast_relative_type(AstFile *f, Ast *tag, Ast *type) { Ast *result = alloc_ast_node(f, Ast_RelativeType); result->RelativeType.tag = tag; result->RelativeType.type = type; return result; } -Ast *ast_pointer_type(AstFile *f, Token token, Ast *type) { +gb_internal Ast *ast_pointer_type(AstFile *f, Token token, Ast *type) { Ast *result = alloc_ast_node(f, Ast_PointerType); result->PointerType.token = token; result->PointerType.type = type; return result; } -Ast *ast_multi_pointer_type(AstFile *f, Token token, Ast *type) { +gb_internal Ast *ast_multi_pointer_type(AstFile *f, Token token, Ast *type) { Ast *result = alloc_ast_node(f, Ast_MultiPointerType); result->MultiPointerType.token = token; result->MultiPointerType.type = type; return result; } -Ast *ast_array_type(AstFile *f, Token token, Ast *count, Ast *elem) { +gb_internal Ast *ast_array_type(AstFile *f, Token token, Ast *count, Ast *elem) { Ast *result = alloc_ast_node(f, Ast_ArrayType); result->ArrayType.token = token; result->ArrayType.count = count; @@ -1050,14 +1050,14 @@ Ast *ast_array_type(AstFile *f, Token token, Ast *count, Ast *elem) { return result; } -Ast *ast_dynamic_array_type(AstFile *f, Token token, Ast *elem) { +gb_internal Ast *ast_dynamic_array_type(AstFile *f, Token token, Ast *elem) { Ast *result = alloc_ast_node(f, Ast_DynamicArrayType); result->DynamicArrayType.token = token; result->DynamicArrayType.elem = elem; return result; } -Ast *ast_struct_type(AstFile *f, Token token, Slice fields, isize field_count, +gb_internal Ast *ast_struct_type(AstFile *f, Token token, Slice fields, isize field_count, Ast *polymorphic_params, bool is_packed, bool is_raw_union, Ast *align, Token where_token, Array const &where_clauses) { @@ -1075,7 +1075,7 @@ Ast *ast_struct_type(AstFile *f, Token token, Slice fields, isize field_c } -Ast *ast_union_type(AstFile *f, Token token, Array const &variants, Ast *polymorphic_params, Ast *align, UnionTypeKind kind, +gb_internal Ast *ast_union_type(AstFile *f, Token token, Array const &variants, Ast *polymorphic_params, Ast *align, UnionTypeKind kind, Token where_token, Array const &where_clauses) { Ast *result = alloc_ast_node(f, Ast_UnionType); result->UnionType.token = token; @@ -1089,7 +1089,7 @@ Ast *ast_union_type(AstFile *f, Token token, Array const &variants, Ast * } -Ast *ast_enum_type(AstFile *f, Token token, Ast *base_type, Array const &fields) { +gb_internal Ast *ast_enum_type(AstFile *f, Token token, Ast *base_type, Array const &fields) { Ast *result = alloc_ast_node(f, Ast_EnumType); result->EnumType.token = token; result->EnumType.base_type = base_type; @@ -1097,7 +1097,7 @@ Ast *ast_enum_type(AstFile *f, Token token, Ast *base_type, Array const & return result; } -Ast *ast_bit_set_type(AstFile *f, Token token, Ast *elem, Ast *underlying) { +gb_internal Ast *ast_bit_set_type(AstFile *f, Token token, Ast *elem, Ast *underlying) { Ast *result = alloc_ast_node(f, Ast_BitSetType); result->BitSetType.token = token; result->BitSetType.elem = elem; @@ -1105,7 +1105,7 @@ Ast *ast_bit_set_type(AstFile *f, Token token, Ast *elem, Ast *underlying) { return result; } -Ast *ast_map_type(AstFile *f, Token token, Ast *key, Ast *value) { +gb_internal Ast *ast_map_type(AstFile *f, Token token, Ast *key, Ast *value) { Ast *result = alloc_ast_node(f, Ast_MapType); result->MapType.token = token; result->MapType.key = key; @@ -1113,7 +1113,7 @@ Ast *ast_map_type(AstFile *f, Token token, Ast *key, Ast *value) { return result; } -Ast *ast_matrix_type(AstFile *f, Token token, Ast *row_count, Ast *column_count, Ast *elem) { +gb_internal Ast *ast_matrix_type(AstFile *f, Token token, Ast *row_count, Ast *column_count, Ast *elem) { Ast *result = alloc_ast_node(f, Ast_MatrixType); result->MatrixType.token = token; result->MatrixType.row_count = row_count; @@ -1122,7 +1122,7 @@ Ast *ast_matrix_type(AstFile *f, Token token, Ast *row_count, Ast *column_count, return result; } -Ast *ast_foreign_block_decl(AstFile *f, Token token, Ast *foreign_library, Ast *body, +gb_internal Ast *ast_foreign_block_decl(AstFile *f, Token token, Ast *foreign_library, Ast *body, CommentGroup *docs) { Ast *result = alloc_ast_node(f, Ast_ForeignBlockDecl); result->ForeignBlockDecl.token = token; @@ -1134,14 +1134,14 @@ Ast *ast_foreign_block_decl(AstFile *f, Token token, Ast *foreign_library, Ast * return result; } -Ast *ast_label_decl(AstFile *f, Token token, Ast *name) { +gb_internal Ast *ast_label_decl(AstFile *f, Token token, Ast *name) { Ast *result = alloc_ast_node(f, Ast_Label); result->Label.token = token; result->Label.name = name; return result; } -Ast *ast_value_decl(AstFile *f, Array const &names, Ast *type, Array const &values, bool is_mutable, +gb_internal Ast *ast_value_decl(AstFile *f, Array const &names, Ast *type, Array const &values, bool is_mutable, CommentGroup *docs, CommentGroup *comment) { Ast *result = alloc_ast_node(f, Ast_ValueDecl); result->ValueDecl.names = slice_from_array(names); @@ -1155,7 +1155,7 @@ Ast *ast_value_decl(AstFile *f, Array const &names, Ast *type, ArrayPackageDecl.token = token; result->PackageDecl.name = name; @@ -1164,7 +1164,7 @@ Ast *ast_package_decl(AstFile *f, Token token, Token name, CommentGroup *docs, C return result; } -Ast *ast_import_decl(AstFile *f, Token token, Token relpath, Token import_name, +gb_internal Ast *ast_import_decl(AstFile *f, Token token, Token relpath, Token import_name, CommentGroup *docs, CommentGroup *comment) { Ast *result = alloc_ast_node(f, Ast_ImportDecl); result->ImportDecl.token = token; @@ -1175,7 +1175,7 @@ Ast *ast_import_decl(AstFile *f, Token token, Token relpath, Token import_name, return result; } -Ast *ast_foreign_import_decl(AstFile *f, Token token, Array filepaths, Token library_name, +gb_internal Ast *ast_foreign_import_decl(AstFile *f, Token token, Array filepaths, Token library_name, CommentGroup *docs, CommentGroup *comment) { Ast *result = alloc_ast_node(f, Ast_ForeignImportDecl); result->ForeignImportDecl.token = token; @@ -1189,7 +1189,7 @@ Ast *ast_foreign_import_decl(AstFile *f, Token token, Array filepaths, To } -Ast *ast_attribute(AstFile *f, Token token, Token open, Token close, Array const &elems) { +gb_internal Ast *ast_attribute(AstFile *f, Token token, Token open, Token close, Array const &elems) { Ast *result = alloc_ast_node(f, Ast_Attribute); result->Attribute.token = token; result->Attribute.open = open; @@ -1199,7 +1199,7 @@ Ast *ast_attribute(AstFile *f, Token token, Token open, Token close, Arraycurr_token_index+1 < f->tokens.count) { f->curr_token = f->tokens[++f->curr_token_index]; return true; @@ -1209,7 +1209,7 @@ bool next_token0(AstFile *f) { } -Token consume_comment(AstFile *f, isize *end_line_) { +gb_internal Token consume_comment(AstFile *f, isize *end_line_) { Token tok = f->curr_token; GB_ASSERT(tok.kind == Token_Comment); isize end_line = tok.pos.line; @@ -1231,7 +1231,7 @@ Token consume_comment(AstFile *f, isize *end_line_) { } -CommentGroup *consume_comment_group(AstFile *f, isize n, isize *end_line_) { +gb_internal CommentGroup *consume_comment_group(AstFile *f, isize n, isize *end_line_) { Array list = {}; list.allocator = heap_allocator(); isize end_line = f->curr_token.pos.line; @@ -1257,7 +1257,7 @@ CommentGroup *consume_comment_group(AstFile *f, isize n, isize *end_line_) { return comments; } -void consume_comment_groups(AstFile *f, Token prev) { +gb_internal void consume_comment_groups(AstFile *f, Token prev) { if (f->curr_token.kind == Token_Comment) { CommentGroup *comment = nullptr; isize end_line = 0; @@ -1281,11 +1281,11 @@ void consume_comment_groups(AstFile *f, Token prev) { } } -gb_inline bool ignore_newlines(AstFile *f) { +gb_internal gb_inline bool ignore_newlines(AstFile *f) { return f->expr_level > 0; } -Token advance_token(AstFile *f) { +gb_internal Token advance_token(AstFile *f) { f->lead_comment = nullptr; f->line_comment = nullptr; @@ -1308,7 +1308,7 @@ Token advance_token(AstFile *f) { return prev; } -bool peek_token_kind(AstFile *f, TokenKind kind) { +gb_internal bool peek_token_kind(AstFile *f, TokenKind kind) { for (isize i = f->curr_token_index+1; i < f->tokens.count; i++) { Token tok = f->tokens[i]; if (kind != Token_Comment && tok.kind == Token_Comment) { @@ -1319,7 +1319,7 @@ bool peek_token_kind(AstFile *f, TokenKind kind) { return false; } -Token peek_token(AstFile *f) { +gb_internal Token peek_token(AstFile *f) { for (isize i = f->curr_token_index+1; i < f->tokens.count; i++) { Token tok = f->tokens[i]; if (tok.kind == Token_Comment) { @@ -1330,7 +1330,7 @@ Token peek_token(AstFile *f) { return {}; } -bool skip_possible_newline(AstFile *f) { +gb_internal bool skip_possible_newline(AstFile *f) { if (token_is_newline(f->curr_token)) { advance_token(f); return true; @@ -1338,7 +1338,7 @@ bool skip_possible_newline(AstFile *f) { return false; } -bool skip_possible_newline_for_literal(AstFile *f) { +gb_internal bool skip_possible_newline_for_literal(AstFile *f) { Token curr = f->curr_token; if (token_is_newline(curr)) { Token next = peek_token(f); @@ -1356,7 +1356,7 @@ bool skip_possible_newline_for_literal(AstFile *f) { return false; } -String token_to_string(Token const &tok) { +gb_internal String token_to_string(Token const &tok) { String p = token_strings[tok.kind]; if (token_is_newline(tok)) { p = str_lit("newline"); @@ -1365,7 +1365,7 @@ String token_to_string(Token const &tok) { } -Token expect_token(AstFile *f, TokenKind kind) { +gb_internal Token expect_token(AstFile *f, TokenKind kind) { Token prev = f->curr_token; if (prev.kind != kind) { String c = token_strings[kind]; @@ -1380,7 +1380,7 @@ Token expect_token(AstFile *f, TokenKind kind) { return prev; } -Token expect_token_after(AstFile *f, TokenKind kind, char const *msg) { +gb_internal Token expect_token_after(AstFile *f, TokenKind kind, char const *msg) { Token prev = f->curr_token; if (prev.kind != kind) { String p = token_to_string(prev); @@ -1400,7 +1400,7 @@ Token expect_token_after(AstFile *f, TokenKind kind, char const *msg) { } -bool is_token_range(TokenKind kind) { +gb_internal bool is_token_range(TokenKind kind) { switch (kind) { case Token_Ellipsis: case Token_RangeFull: @@ -1409,12 +1409,12 @@ bool is_token_range(TokenKind kind) { } return false; } -bool is_token_range(Token tok) { +gb_internal bool is_token_range(Token tok) { return is_token_range(tok.kind); } -Token expect_operator(AstFile *f) { +gb_internal Token expect_operator(AstFile *f) { Token prev = f->curr_token; if ((prev.kind == Token_in || prev.kind == Token_not_in) && (f->expr_level >= 0 || f->allow_in_expr)) { // okay @@ -1440,7 +1440,7 @@ Token expect_operator(AstFile *f) { return prev; } -Token expect_keyword(AstFile *f) { +gb_internal Token expect_keyword(AstFile *f) { Token prev = f->curr_token; if (!gb_is_between(prev.kind, Token__KeywordBegin+1, Token__KeywordEnd-1)) { String p = token_to_string(prev); @@ -1451,7 +1451,7 @@ Token expect_keyword(AstFile *f) { return prev; } -bool allow_token(AstFile *f, TokenKind kind) { +gb_internal bool allow_token(AstFile *f, TokenKind kind) { Token prev = f->curr_token; if (prev.kind == kind) { advance_token(f); @@ -1460,7 +1460,7 @@ bool allow_token(AstFile *f, TokenKind kind) { return false; } -Token expect_closing_brace_of_field_list(AstFile *f) { +gb_internal Token expect_closing_brace_of_field_list(AstFile *f) { Token token = f->curr_token; if (allow_token(f, Token_CloseBrace)) { return token; @@ -1476,19 +1476,19 @@ Token expect_closing_brace_of_field_list(AstFile *f) { return expect_token(f, Token_CloseBrace); } -bool is_blank_ident(String str) { +gb_internal bool is_blank_ident(String str) { if (str.len == 1) { return str[0] == '_'; } return false; } -bool is_blank_ident(Token token) { +gb_internal bool is_blank_ident(Token token) { if (token.kind == Token_Ident) { return is_blank_ident(token.string); } return false; } -bool is_blank_ident(Ast *node) { +gb_internal bool is_blank_ident(Ast *node) { if (node->kind == Ast_Ident) { ast_node(i, Ident, node); return is_blank_ident(i->token.string); @@ -1499,7 +1499,7 @@ bool is_blank_ident(Ast *node) { // NOTE(bill): Go to next statement to prevent numerous error messages popping up -void fix_advance_to_next_stmt(AstFile *f) { +gb_internal void fix_advance_to_next_stmt(AstFile *f) { for (;;) { Token t = f->curr_token; switch (t.kind) { @@ -1543,7 +1543,7 @@ void fix_advance_to_next_stmt(AstFile *f) { } } -Token expect_closing(AstFile *f, TokenKind kind, String const &context) { +gb_internal Token expect_closing(AstFile *f, TokenKind kind, String const &context) { if (f->curr_token.kind != kind && f->curr_token.kind == Token_Semicolon && (f->curr_token.string == "\n" || f->curr_token.kind == Token_EOF)) { @@ -1557,7 +1557,7 @@ Token expect_closing(AstFile *f, TokenKind kind, String const &context) { return expect_token(f, kind); } -void assign_removal_flag_to_semicolon(AstFile *f) { +gb_internal void assign_removal_flag_to_semicolon(AstFile *f) { // NOTE(bill): this is used for rewriting files to strip unneeded semicolons Token *prev_token = &f->tokens[f->prev_token_index]; Token *curr_token = &f->tokens[f->curr_token_index]; @@ -1587,7 +1587,7 @@ void assign_removal_flag_to_semicolon(AstFile *f) { } } -void expect_semicolon(AstFile *f) { +gb_internal void expect_semicolon(AstFile *f) { Token prev_token = {}; if (allow_token(f, Token_Semicolon)) { @@ -1626,17 +1626,17 @@ void expect_semicolon(AstFile *f) { } -Ast * parse_expr(AstFile *f, bool lhs); -Ast * parse_proc_type(AstFile *f, Token proc_token); -Array parse_stmt_list(AstFile *f); -Ast * parse_stmt(AstFile *f); -Ast * parse_body(AstFile *f); -Ast * parse_do_body(AstFile *f, Token const &token, char const *msg); -Ast * parse_block_stmt(AstFile *f, b32 is_when); +gb_internal Ast * parse_expr(AstFile *f, bool lhs); +gb_internal Ast * parse_proc_type(AstFile *f, Token proc_token); +gb_internal Array parse_stmt_list(AstFile *f); +gb_internal Ast * parse_stmt(AstFile *f); +gb_internal Ast * parse_body(AstFile *f); +gb_internal Ast * parse_do_body(AstFile *f, Token const &token, char const *msg); +gb_internal Ast * parse_block_stmt(AstFile *f, b32 is_when); -Ast *parse_ident(AstFile *f, bool allow_poly_names=false) { +gb_internal Ast *parse_ident(AstFile *f, bool allow_poly_names=false) { Token token = f->curr_token; if (token.kind == Token_Ident) { advance_token(f); @@ -1654,13 +1654,13 @@ Ast *parse_ident(AstFile *f, bool allow_poly_names=false) { return ast_ident(f, token); } -Ast *parse_tag_expr(AstFile *f, Ast *expression) { +gb_internal Ast *parse_tag_expr(AstFile *f, Ast *expression) { Token token = expect_token(f, Token_Hash); Token name = expect_token(f, Token_Ident); return ast_tag_expr(f, token, name, expression); } -Ast *unparen_expr(Ast *node) { +gb_internal Ast *unparen_expr(Ast *node) { for (;;) { if (node == nullptr) { return nullptr; @@ -1672,7 +1672,7 @@ Ast *unparen_expr(Ast *node) { } } -Ast *unselector_expr(Ast *node) { +gb_internal Ast *unselector_expr(Ast *node) { node = unparen_expr(node); if (node == nullptr) { return nullptr; @@ -1683,7 +1683,7 @@ Ast *unselector_expr(Ast *node) { return node; } -Ast *strip_or_return_expr(Ast *node) { +gb_internal Ast *strip_or_return_expr(Ast *node) { for (;;) { if (node == nullptr) { return node; @@ -1699,9 +1699,9 @@ Ast *strip_or_return_expr(Ast *node) { } -Ast *parse_value(AstFile *f); +gb_internal Ast *parse_value(AstFile *f); -Array parse_element_list(AstFile *f) { +gb_internal Array parse_element_list(AstFile *f) { auto elems = array_make(heap_allocator()); while (f->curr_token.kind != Token_CloseBrace && @@ -1722,7 +1722,7 @@ Array parse_element_list(AstFile *f) { return elems; } -CommentGroup *consume_line_comment(AstFile *f) { +gb_internal CommentGroup *consume_line_comment(AstFile *f) { CommentGroup *comment = f->line_comment; if (f->line_comment == f->lead_comment) { f->lead_comment = nullptr; @@ -1732,7 +1732,7 @@ CommentGroup *consume_line_comment(AstFile *f) { } -Array parse_enum_field_list(AstFile *f) { +gb_internal Array parse_enum_field_list(AstFile *f) { auto elems = array_make(heap_allocator()); while (f->curr_token.kind != Token_CloseBrace && @@ -1763,7 +1763,7 @@ Array parse_enum_field_list(AstFile *f) { return elems; } -Ast *parse_literal_value(AstFile *f, Ast *type) { +gb_internal Ast *parse_literal_value(AstFile *f, Ast *type) { Array elems = {}; Token open = expect_token(f, Token_OpenBrace); isize expr_level = f->expr_level; @@ -1777,7 +1777,7 @@ Ast *parse_literal_value(AstFile *f, Ast *type) { return ast_compound_lit(f, type, elems, open, close); } -Ast *parse_value(AstFile *f) { +gb_internal Ast *parse_value(AstFile *f) { if (f->curr_token.kind == Token_OpenBrace) { return parse_literal_value(f, nullptr); } @@ -1789,17 +1789,17 @@ Ast *parse_value(AstFile *f) { return value; } -Ast *parse_type_or_ident(AstFile *f); +gb_internal Ast *parse_type_or_ident(AstFile *f); -void check_proc_add_tag(AstFile *f, Ast *tag_expr, u64 *tags, ProcTag tag, String const &tag_name) { +gb_internal void check_proc_add_tag(AstFile *f, Ast *tag_expr, u64 *tags, ProcTag tag, String const &tag_name) { if (*tags & tag) { syntax_error(tag_expr, "Procedure tag already used: %.*s", LIT(tag_name)); } *tags |= tag; } -bool is_foreign_name_valid(String const &name) { +gb_internal bool is_foreign_name_valid(String const &name) { if (name.len == 0) { return false; } @@ -1847,7 +1847,7 @@ bool is_foreign_name_valid(String const &name) { return true; } -void parse_proc_tags(AstFile *f, u64 *tags) { +gb_internal void parse_proc_tags(AstFile *f, u64 *tags) { GB_ASSERT(tags != nullptr); while (f->curr_token.kind == Token_Hash) { @@ -1885,17 +1885,17 @@ void parse_proc_tags(AstFile *f, u64 *tags) { } -Array parse_lhs_expr_list (AstFile *f); -Array parse_rhs_expr_list (AstFile *f); -Ast * parse_simple_stmt (AstFile *f, u32 flags); -Ast * parse_type (AstFile *f); -Ast * parse_call_expr (AstFile *f, Ast *operand); -Ast * parse_struct_field_list(AstFile *f, isize *name_count_); -Ast *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, TokenKind follow, bool allow_default_parameters, bool allow_typeid_token); -Ast *parse_unary_expr(AstFile *f, bool lhs); +gb_internal Array parse_lhs_expr_list (AstFile *f); +gb_internal Array parse_rhs_expr_list (AstFile *f); +gb_internal Ast * parse_simple_stmt (AstFile *f, u32 flags); +gb_internal Ast * parse_type (AstFile *f); +gb_internal Ast * parse_call_expr (AstFile *f, Ast *operand); +gb_internal Ast * parse_struct_field_list(AstFile *f, isize *name_count_); +gb_internal Ast *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, TokenKind follow, bool allow_default_parameters, bool allow_typeid_token); +gb_internal Ast *parse_unary_expr(AstFile *f, bool lhs); -Ast *convert_stmt_to_expr(AstFile *f, Ast *statement, String const &kind) { +gb_internal Ast *convert_stmt_to_expr(AstFile *f, Ast *statement, String const &kind) { if (statement == nullptr) { return nullptr; } @@ -1912,7 +1912,7 @@ Ast *convert_stmt_to_expr(AstFile *f, Ast *statement, String const &kind) { return ast_bad_expr(f, f->curr_token, end); } -Ast *convert_stmt_to_body(AstFile *f, Ast *stmt) { +gb_internal Ast *convert_stmt_to_body(AstFile *f, Ast *stmt) { if (stmt->kind == Ast_BlockStmt) { syntax_error(stmt, "Expected a normal statement rather than a block statement"); return stmt; @@ -1929,7 +1929,7 @@ Ast *convert_stmt_to_body(AstFile *f, Ast *stmt) { } -void check_polymorphic_params_for_type(AstFile *f, Ast *polymorphic_params, Token token) { +gb_internal void check_polymorphic_params_for_type(AstFile *f, Ast *polymorphic_params, Token token) { if (polymorphic_params == nullptr) { return; } @@ -1952,16 +1952,16 @@ void check_polymorphic_params_for_type(AstFile *f, Ast *polymorphic_params, Toke } } -bool ast_on_same_line(Token const &x, Ast *yp) { +gb_internal bool ast_on_same_line(Token const &x, Ast *yp) { Token y = ast_token(yp); return x.pos.line == y.pos.line; } -bool ast_on_same_line(Ast *x, Ast *y) { +gb_internal bool ast_on_same_line(Ast *x, Ast *y) { return ast_on_same_line(ast_token(x), y); } -Ast *parse_force_inlining_operand(AstFile *f, Token token) { +gb_internal Ast *parse_force_inlining_operand(AstFile *f, Token token) { Ast *expr = parse_unary_expr(f, false); Ast *e = strip_or_return_expr(expr); if (e->kind != Ast_ProcLit && e->kind != Ast_CallExpr) { @@ -1997,7 +1997,7 @@ Ast *parse_force_inlining_operand(AstFile *f, Token token) { } -Ast *parse_check_directive_for_statement(Ast *s, Token const &tag_token, u16 state_flag) { +gb_internal Ast *parse_check_directive_for_statement(Ast *s, Token const &tag_token, u16 state_flag) { String name = tag_token.string; if (s == nullptr) { @@ -2076,7 +2076,7 @@ Ast *parse_check_directive_for_statement(Ast *s, Token const &tag_token, u16 sta return s; } -Array parse_union_variant_list(AstFile *f) { +gb_internal Array parse_union_variant_list(AstFile *f) { auto variants = array_make(heap_allocator()); while (f->curr_token.kind != Token_CloseBrace && f->curr_token.kind != Token_EOF) { @@ -2091,7 +2091,7 @@ Array parse_union_variant_list(AstFile *f) { return variants; } -Ast *parse_operand(AstFile *f, bool lhs) { +gb_internal Ast *parse_operand(AstFile *f, bool lhs) { Ast *operand = nullptr; // Operand switch (f->curr_token.kind) { case Token_Ident: @@ -2712,7 +2712,7 @@ Ast *parse_operand(AstFile *f, bool lhs) { return nullptr; } -bool is_literal_type(Ast *node) { +gb_internal bool is_literal_type(Ast *node) { node = unparen_expr(node); switch (node->kind) { case Ast_BadExpr: @@ -2735,7 +2735,7 @@ bool is_literal_type(Ast *node) { return false; } -Ast *parse_call_expr(AstFile *f, Ast *operand) { +gb_internal Ast *parse_call_expr(AstFile *f, Ast *operand) { auto args = array_make(heap_allocator()); Token open_paren, close_paren; Token ellipsis = {}; @@ -2796,7 +2796,7 @@ Ast *parse_call_expr(AstFile *f, Ast *operand) { return call; } -Ast *parse_atom_expr(AstFile *f, Ast *operand, bool lhs) { +gb_internal Ast *parse_atom_expr(AstFile *f, Ast *operand, bool lhs) { if (operand == nullptr) { if (f->allow_type) return nullptr; Token begin = f->curr_token; @@ -2950,7 +2950,7 @@ Ast *parse_atom_expr(AstFile *f, Ast *operand, bool lhs) { } -Ast *parse_unary_expr(AstFile *f, bool lhs) { +gb_internal Ast *parse_unary_expr(AstFile *f, bool lhs) { switch (f->curr_token.kind) { case Token_transmute: case Token_cast: { @@ -2997,7 +2997,7 @@ Ast *parse_unary_expr(AstFile *f, bool lhs) { return parse_atom_expr(f, parse_operand(f, lhs), lhs); } -bool is_ast_range(Ast *expr) { +gb_internal bool is_ast_range(Ast *expr) { if (expr == nullptr) { return false; } @@ -3008,7 +3008,7 @@ bool is_ast_range(Ast *expr) { } // NOTE(bill): result == priority -i32 token_precedence(AstFile *f, TokenKind t) { +gb_internal i32 token_precedence(AstFile *f, TokenKind t) { switch (t) { case Token_Question: case Token_if: @@ -3058,7 +3058,7 @@ i32 token_precedence(AstFile *f, TokenKind t) { return 0; } -Ast *parse_binary_expr(AstFile *f, bool lhs, i32 prec_in) { +gb_internal Ast *parse_binary_expr(AstFile *f, bool lhs, i32 prec_in) { Ast *expr = parse_unary_expr(f, lhs); for (;;) { Token op = f->curr_token; @@ -3119,12 +3119,12 @@ Ast *parse_binary_expr(AstFile *f, bool lhs, i32 prec_in) { return expr; } -Ast *parse_expr(AstFile *f, bool lhs) { +gb_internal Ast *parse_expr(AstFile *f, bool lhs) { return parse_binary_expr(f, lhs, 0+1); } -Array parse_expr_list(AstFile *f, bool lhs) { +gb_internal Array parse_expr_list(AstFile *f, bool lhs) { bool allow_newline = f->allow_newline; f->allow_newline = ALLOW_NEWLINE; @@ -3144,15 +3144,15 @@ Array parse_expr_list(AstFile *f, bool lhs) { return list; } -Array parse_lhs_expr_list(AstFile *f) { +gb_internal Array parse_lhs_expr_list(AstFile *f) { return parse_expr_list(f, true); } -Array parse_rhs_expr_list(AstFile *f) { +gb_internal Array parse_rhs_expr_list(AstFile *f) { return parse_expr_list(f, false); } -Array parse_ident_list(AstFile *f, bool allow_poly_names) { +gb_internal Array parse_ident_list(AstFile *f, bool allow_poly_names) { auto list = array_make(heap_allocator()); for (;;) { @@ -3167,7 +3167,7 @@ Array parse_ident_list(AstFile *f, bool allow_poly_names) { return list; } -Ast *parse_type(AstFile *f) { +gb_internal Ast *parse_type(AstFile *f) { Ast *type = parse_type_or_ident(f); if (type == nullptr) { Token token = advance_token(f); @@ -3177,7 +3177,7 @@ Ast *parse_type(AstFile *f) { return type; } -void parse_foreign_block_decl(AstFile *f, Array *decls) { +gb_internal void parse_foreign_block_decl(AstFile *f, Array *decls) { Ast *decl = parse_stmt(f); switch (decl->kind) { case Ast_EmptyStmt: @@ -3196,7 +3196,7 @@ void parse_foreign_block_decl(AstFile *f, Array *decls) { } } -Ast *parse_foreign_block(AstFile *f, Token token) { +gb_internal Ast *parse_foreign_block(AstFile *f, Token token) { CommentGroup *docs = f->lead_comment; Ast *foreign_library = nullptr; if (f->curr_token.kind == Token_OpenBrace) { @@ -3229,7 +3229,7 @@ Ast *parse_foreign_block(AstFile *f, Token token) { return decl; } -Ast *parse_value_decl(AstFile *f, Array names, CommentGroup *docs) { +gb_internal Ast *parse_value_decl(AstFile *f, Array names, CommentGroup *docs) { bool is_mutable = true; Array values = {}; @@ -3293,7 +3293,7 @@ Ast *parse_value_decl(AstFile *f, Array names, CommentGroup *docs) { return ast_value_decl(f, names, type, values, is_mutable, docs, f->line_comment); } -Ast *parse_simple_stmt(AstFile *f, u32 flags) { +gb_internal Ast *parse_simple_stmt(AstFile *f, u32 flags) { Token token = f->curr_token; CommentGroup *docs = f->lead_comment; @@ -3403,7 +3403,7 @@ Ast *parse_simple_stmt(AstFile *f, u32 flags) { -Ast *parse_block_stmt(AstFile *f, b32 is_when) { +gb_internal Ast *parse_block_stmt(AstFile *f, b32 is_when) { skip_possible_newline_for_literal(f); if (!is_when && f->curr_proc == nullptr) { syntax_error(f->curr_token, "You cannot use a block statement in the file scope"); @@ -3414,7 +3414,7 @@ Ast *parse_block_stmt(AstFile *f, b32 is_when) { -Ast *parse_results(AstFile *f, bool *diverging) { +gb_internal Ast *parse_results(AstFile *f, bool *diverging) { if (!allow_token(f, Token_ArrowRight)) { return nullptr; } @@ -3448,7 +3448,7 @@ Ast *parse_results(AstFile *f, bool *diverging) { } -ProcCallingConvention string_to_calling_convention(String const &s) { +gb_internal ProcCallingConvention string_to_calling_convention(String const &s) { if (s == "odin") return ProcCC_Odin; if (s == "contextless") return ProcCC_Contextless; if (s == "cdecl") return ProcCC_CDecl; @@ -3474,7 +3474,7 @@ ProcCallingConvention string_to_calling_convention(String const &s) { return ProcCC_Invalid; } -Ast *parse_proc_type(AstFile *f, Token proc_token) { +gb_internal Ast *parse_proc_type(AstFile *f, Token proc_token) { Ast *params = nullptr; Ast *results = nullptr; bool diverging = false; @@ -3530,7 +3530,7 @@ end: return ast_proc_type(f, proc_token, params, results, tags, cc, is_generic, diverging); } -Ast *parse_var_type(AstFile *f, bool allow_ellipsis, bool allow_typeid_token) { +gb_internal Ast *parse_var_type(AstFile *f, bool allow_ellipsis, bool allow_typeid_token) { if (allow_ellipsis && f->curr_token.kind == Token_Ellipsis) { Token tok = advance_token(f); Ast *type = parse_type_or_ident(f); @@ -3574,7 +3574,7 @@ gb_global ParseFieldPrefixMapping parse_field_prefix_mappings[] = { }; -FieldFlag is_token_field_prefix(AstFile *f) { +gb_internal FieldFlag is_token_field_prefix(AstFile *f) { switch (f->curr_token.kind) { case Token_EOF: return FieldFlag_Invalid; @@ -3604,7 +3604,7 @@ FieldFlag is_token_field_prefix(AstFile *f) { return FieldFlag_Invalid; } -u32 parse_field_prefixes(AstFile *f) { +gb_internal u32 parse_field_prefixes(AstFile *f) { i32 counts[gb_count_of(parse_field_prefix_mappings)] = {}; for (;;) { @@ -3646,7 +3646,7 @@ u32 parse_field_prefixes(AstFile *f) { return field_flags; } -u32 check_field_prefixes(AstFile *f, isize name_count, u32 allowed_flags, u32 set_flags) { +gb_internal u32 check_field_prefixes(AstFile *f, isize name_count, u32 allowed_flags, u32 set_flags) { for (i32 i = 0; i < gb_count_of(parse_field_prefix_mappings); i++) { bool err = false; auto const &m = parse_field_prefix_mappings[i]; @@ -3679,7 +3679,7 @@ struct AstAndFlags { u32 flags; }; -Array convert_to_ident_list(AstFile *f, Array list, bool ignore_flags, bool allow_poly_names) { +gb_internal Array convert_to_ident_list(AstFile *f, Array list, bool ignore_flags, bool allow_poly_names) { auto idents = array_make(heap_allocator(), 0, list.count); // Convert to ident list for_array(i, list) { @@ -3719,7 +3719,7 @@ Array convert_to_ident_list(AstFile *f, Array list, bool ign } -bool allow_field_separator(AstFile *f) { +gb_internal bool allow_field_separator(AstFile *f) { Token token = f->curr_token; if (allow_token(f, Token_Comma)) { return true; @@ -3733,7 +3733,7 @@ bool allow_field_separator(AstFile *f) { return false; } -Ast *parse_struct_field_list(AstFile *f, isize *name_count_) { +gb_internal Ast *parse_struct_field_list(AstFile *f, isize *name_count_) { Token start_token = f->curr_token; auto decls = array_make(heap_allocator()); @@ -3747,7 +3747,7 @@ Ast *parse_struct_field_list(AstFile *f, isize *name_count_) { // Returns true if any are polymorphic names -bool check_procedure_name_list(Array const &names) { +gb_internal bool check_procedure_name_list(Array const &names) { if (names.count == 0) { return false; } @@ -3775,7 +3775,7 @@ bool check_procedure_name_list(Array const &names) { return any_polymorphic_names; } -Ast *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, TokenKind follow, bool allow_default_parameters, bool allow_typeid_token) { +gb_internal Ast *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, TokenKind follow, bool allow_default_parameters, bool allow_typeid_token) { bool prev_allow_newline = f->allow_newline; defer (f->allow_newline = prev_allow_newline); f->allow_newline = ALLOW_NEWLINE; @@ -3976,7 +3976,7 @@ Ast *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, TokenKi return ast_field_list(f, start_token, params); } -Ast *parse_type_or_ident(AstFile *f) { +gb_internal Ast *parse_type_or_ident(AstFile *f) { bool prev_allow_type = f->allow_type; isize prev_expr_level = f->expr_level; defer ({ @@ -3995,7 +3995,7 @@ Ast *parse_type_or_ident(AstFile *f) { -Ast *parse_body(AstFile *f) { +gb_internal Ast *parse_body(AstFile *f) { Array stmts = {}; Token open, close; isize prev_expr_level = f->expr_level; @@ -4013,7 +4013,7 @@ Ast *parse_body(AstFile *f) { return ast_block_stmt(f, stmts, open, close); } -Ast *parse_do_body(AstFile *f, Token const &token, char const *msg) { +gb_internal Ast *parse_do_body(AstFile *f, Token const &token, char const *msg) { Token open, close; isize prev_expr_level = f->expr_level; bool prev_allow_newline = f->allow_newline; @@ -4034,7 +4034,7 @@ Ast *parse_do_body(AstFile *f, Token const &token, char const *msg) { return body; } -bool parse_control_statement_semicolon_separator(AstFile *f) { +gb_internal bool parse_control_statement_semicolon_separator(AstFile *f) { Token tok = peek_token(f); if (tok.kind != Token_OpenBrace) { return allow_token(f, Token_Semicolon); @@ -4046,7 +4046,7 @@ bool parse_control_statement_semicolon_separator(AstFile *f) { } -Ast *parse_if_stmt(AstFile *f) { +gb_internal Ast *parse_if_stmt(AstFile *f) { if (f->curr_proc == nullptr) { syntax_error(f->curr_token, "You cannot use an if statement in the file scope"); return ast_bad_stmt(f, f->curr_token, f->curr_token); @@ -4112,7 +4112,7 @@ Ast *parse_if_stmt(AstFile *f) { return ast_if_stmt(f, token, init, cond, body, else_stmt); } -Ast *parse_when_stmt(AstFile *f) { +gb_internal Ast *parse_when_stmt(AstFile *f) { Token token = expect_token(f, Token_when); Ast *cond = nullptr; Ast *body = nullptr; @@ -4160,7 +4160,7 @@ Ast *parse_when_stmt(AstFile *f) { } -Ast *parse_return_stmt(AstFile *f) { +gb_internal Ast *parse_return_stmt(AstFile *f) { Token token = expect_token(f, Token_return); if (f->curr_proc == nullptr) { @@ -4188,7 +4188,7 @@ Ast *parse_return_stmt(AstFile *f) { return ast_return_stmt(f, token, results); } -Ast *parse_for_stmt(AstFile *f) { +gb_internal Ast *parse_for_stmt(AstFile *f) { if (f->curr_proc == nullptr) { syntax_error(f->curr_token, "You cannot use a for statement in the file scope"); return ast_bad_stmt(f, f->curr_token, f->curr_token); @@ -4279,7 +4279,7 @@ Ast *parse_for_stmt(AstFile *f) { } -Ast *parse_case_clause(AstFile *f, bool is_type) { +gb_internal Ast *parse_case_clause(AstFile *f, bool is_type) { Token token = f->curr_token; Array list = {}; expect_token(f, Token_case); @@ -4299,7 +4299,7 @@ Ast *parse_case_clause(AstFile *f, bool is_type) { } -Ast *parse_switch_stmt(AstFile *f) { +gb_internal Ast *parse_switch_stmt(AstFile *f) { if (f->curr_proc == nullptr) { syntax_error(f->curr_token, "You cannot use a switch statement in the file scope"); return ast_bad_stmt(f, f->curr_token, f->curr_token); @@ -4361,7 +4361,7 @@ Ast *parse_switch_stmt(AstFile *f) { return ast_switch_stmt(f, token, init, tag, body); } -Ast *parse_defer_stmt(AstFile *f) { +gb_internal Ast *parse_defer_stmt(AstFile *f) { if (f->curr_proc == nullptr) { syntax_error(f->curr_token, "You cannot use a defer statement in the file scope"); return ast_bad_stmt(f, f->curr_token, f->curr_token); @@ -4391,7 +4391,7 @@ enum ImportDeclKind { ImportDecl_Using, }; -Ast *parse_import_decl(AstFile *f, ImportDeclKind kind) { +gb_internal Ast *parse_import_decl(AstFile *f, ImportDeclKind kind) { CommentGroup *docs = f->lead_comment; Token token = expect_token(f, Token_import); Token import_name = {}; @@ -4424,7 +4424,7 @@ Ast *parse_import_decl(AstFile *f, ImportDeclKind kind) { return s; } -Ast *parse_foreign_decl(AstFile *f) { +gb_internal Ast *parse_foreign_decl(AstFile *f) { CommentGroup *docs = f->lead_comment; Token token = expect_token(f, Token_foreign); @@ -4487,7 +4487,7 @@ Ast *parse_foreign_decl(AstFile *f) { return ast_bad_decl(f, token, f->curr_token); } -Ast *parse_attribute(AstFile *f, Token token, TokenKind open_kind, TokenKind close_kind) { +gb_internal Ast *parse_attribute(AstFile *f, Token token, TokenKind open_kind, TokenKind close_kind) { Array elems = {}; Token open = {}; Token close = {}; @@ -4542,7 +4542,7 @@ Ast *parse_attribute(AstFile *f, Token token, TokenKind open_kind, TokenKind clo } -Ast *parse_unrolled_for_loop(AstFile *f, Token unroll_token) { +gb_internal Ast *parse_unrolled_for_loop(AstFile *f, Token unroll_token) { Token for_token = expect_token(f, Token_for); Ast *val0 = nullptr; Ast *val1 = nullptr; @@ -4589,7 +4589,7 @@ Ast *parse_unrolled_for_loop(AstFile *f, Token unroll_token) { return ast_unroll_range_stmt(f, unroll_token, for_token, val0, val1, in_token, expr, body); } -Ast *parse_stmt(AstFile *f) { +gb_internal Ast *parse_stmt(AstFile *f) { Ast *s = nullptr; Token token = f->curr_token; switch (token.kind) { @@ -4781,7 +4781,7 @@ Ast *parse_stmt(AstFile *f) { return ast_bad_stmt(f, token, f->curr_token); } -Array parse_stmt_list(AstFile *f) { +gb_internal Array parse_stmt_list(AstFile *f) { auto list = array_make(heap_allocator()); while (f->curr_token.kind != Token_case && @@ -4802,7 +4802,7 @@ Array parse_stmt_list(AstFile *f) { } -ParseFileError init_ast_file(AstFile *f, String const &fullpath, TokenPos *err_pos) { +gb_internal ParseFileError init_ast_file(AstFile *f, String const &fullpath, TokenPos *err_pos) { GB_ASSERT(f != nullptr); f->fullpath = string_trim_whitespace(fullpath); // Just in case set_file_path_string(f->id, fullpath); @@ -4881,14 +4881,14 @@ ParseFileError init_ast_file(AstFile *f, String const &fullpath, TokenPos *err_p return ParseFile_None; } -void destroy_ast_file(AstFile *f) { +gb_internal void destroy_ast_file(AstFile *f) { GB_ASSERT(f != nullptr); array_free(&f->tokens); array_free(&f->comments); array_free(&f->imports); } -bool init_parser(Parser *p) { +gb_internal bool init_parser(Parser *p) { GB_ASSERT(p != nullptr); string_set_init(&p->imported_files, heap_allocator()); array_init(&p->packages, heap_allocator()); @@ -4902,7 +4902,7 @@ bool init_parser(Parser *p) { return true; } -void destroy_parser(Parser *p) { +gb_internal void destroy_parser(Parser *p) { GB_ASSERT(p != nullptr); // TODO(bill): Fix memory leak for_array(i, p->packages) { @@ -4930,16 +4930,16 @@ void destroy_parser(Parser *p) { } -void parser_add_package(Parser *p, AstPackage *pkg) { +gb_internal void parser_add_package(Parser *p, AstPackage *pkg) { mutex_lock(&p->packages_mutex); pkg->id = p->packages.count+1; array_add(&p->packages, pkg); mutex_unlock(&p->packages_mutex); } -ParseFileError process_imported_file(Parser *p, ImportedFile imported_file); +gb_internal ParseFileError process_imported_file(Parser *p, ImportedFile imported_file); -WORKER_TASK_PROC(parser_worker_proc) { +gb_internal WORKER_TASK_PROC(parser_worker_proc) { ParserWorkerData *wd = cast(ParserWorkerData *)data; ParseFileError err = process_imported_file(wd->parser, wd->imported_file); if (err != ParseFile_None) { @@ -4949,7 +4949,7 @@ WORKER_TASK_PROC(parser_worker_proc) { } -void parser_add_file_to_process(Parser *p, AstPackage *pkg, FileInfo fi, TokenPos pos) { +gb_internal void parser_add_file_to_process(Parser *p, AstPackage *pkg, FileInfo fi, TokenPos pos) { // TODO(bill): Use a better allocator ImportedFile f = {pkg, fi, pos, p->file_to_process_count++}; auto wd = gb_alloc_item(permanent_allocator(), ParserWorkerData); @@ -4958,7 +4958,7 @@ void parser_add_file_to_process(Parser *p, AstPackage *pkg, FileInfo fi, TokenPo global_thread_pool_add_task(parser_worker_proc, wd); } -WORKER_TASK_PROC(foreign_file_worker_proc) { +gb_internal WORKER_TASK_PROC(foreign_file_worker_proc) { ForeignFileWorkerData *wd = cast(ForeignFileWorkerData *)data; Parser *p = wd->parser; ImportedFile *imp = &wd->imported_file; @@ -4987,7 +4987,7 @@ WORKER_TASK_PROC(foreign_file_worker_proc) { } -void parser_add_foreign_file_to_process(Parser *p, AstPackage *pkg, AstForeignFileKind kind, FileInfo fi, TokenPos pos) { +gb_internal void parser_add_foreign_file_to_process(Parser *p, AstPackage *pkg, AstForeignFileKind kind, FileInfo fi, TokenPos pos) { // TODO(bill): Use a better allocator ImportedFile f = {pkg, fi, pos, p->file_to_process_count++}; auto wd = gb_alloc_item(permanent_allocator(), ForeignFileWorkerData); @@ -4999,7 +4999,7 @@ void parser_add_foreign_file_to_process(Parser *p, AstPackage *pkg, AstForeignFi // NOTE(bill): Returns true if it's added -AstPackage *try_add_import_path(Parser *p, String const &path, String const &rel_path, TokenPos pos, PackageKind kind = Package_Normal) { +gb_internal AstPackage *try_add_import_path(Parser *p, String const &path, String const &rel_path, TokenPos pos, PackageKind kind = Package_Normal) { String const FILE_EXT = str_lit(".odin"); mutex_lock(&p->import_mutex); @@ -5097,7 +5097,7 @@ gb_global Rune illegal_import_runes[] = { '|', ',', '<', '>', '?', }; -bool is_import_path_valid(String const &path) { +gb_internal bool is_import_path_valid(String const &path) { if (path.len > 0) { u8 *start = path.text; u8 *end = path.text + path.len; @@ -5129,7 +5129,7 @@ bool is_import_path_valid(String const &path) { return false; } -bool is_build_flag_path_valid(String const &path) { +gb_internal bool is_build_flag_path_valid(String const &path) { if (path.len > 0) { u8 *start = path.text; u8 *end = path.text + path.len; @@ -5171,7 +5171,7 @@ bool is_build_flag_path_valid(String const &path) { } -bool is_package_name_reserved(String const &name) { +gb_internal bool is_package_name_reserved(String const &name) { if (name == "builtin") { return true; } else if (name == "intrinsics") { @@ -5181,7 +5181,7 @@ bool is_package_name_reserved(String const &name) { } -bool determine_path_from_string(BlockingMutex *file_mutex, Ast *node, String base_dir, String const &original_string, String *path) { +gb_internal bool determine_path_from_string(BlockingMutex *file_mutex, Ast *node, String base_dir, String const &original_string, String *path) { GB_ASSERT(path != nullptr); // NOTE(bill): if file_mutex == nullptr, this means that the code is used within the semantics stage @@ -5295,9 +5295,9 @@ bool determine_path_from_string(BlockingMutex *file_mutex, Ast *node, String bas -void parse_setup_file_decls(Parser *p, AstFile *f, String const &base_dir, Slice &decls); +gb_internal void parse_setup_file_decls(Parser *p, AstFile *f, String const &base_dir, Slice &decls); -void parse_setup_file_when_stmt(Parser *p, AstFile *f, String const &base_dir, AstWhenStmt *ws) { +gb_internal void parse_setup_file_when_stmt(Parser *p, AstFile *f, String const &base_dir, AstWhenStmt *ws) { if (ws->body != nullptr) { auto stmts = ws->body->BlockStmt.stmts; parse_setup_file_decls(p, f, base_dir, stmts); @@ -5316,7 +5316,7 @@ void parse_setup_file_when_stmt(Parser *p, AstFile *f, String const &base_dir, A } } -void parse_setup_file_decls(Parser *p, AstFile *f, String const &base_dir, Slice &decls) { +gb_internal void parse_setup_file_decls(Parser *p, AstFile *f, String const &base_dir, Slice &decls) { for_array(i, decls) { Ast *node = decls[i]; if (!is_ast_decl(node) && @@ -5389,7 +5389,7 @@ void parse_setup_file_decls(Parser *p, AstFile *f, String const &base_dir, Slice } } -String build_tag_get_token(String s, String *out) { +gb_internal String build_tag_get_token(String s, String *out) { s = string_trim_whitespace(s); isize n = 0; while (n < s.len) { @@ -5408,7 +5408,7 @@ String build_tag_get_token(String s, String *out) { return s; } -bool parse_build_tag(Token token_for_pos, String s) { +gb_internal bool parse_build_tag(Token token_for_pos, String s) { String const prefix = str_lit("+build"); GB_ASSERT(string_starts_with(s, prefix)); s = string_trim_whitespace(substring(s, prefix.len, s.len)); @@ -5473,7 +5473,7 @@ bool parse_build_tag(Token token_for_pos, String s) { return any_correct; } -String dir_from_path(String path) { +gb_internal String dir_from_path(String path) { String base_dir = path; for (isize i = path.len-1; i >= 0; i--) { if (base_dir[i] == '\\' || @@ -5485,7 +5485,7 @@ String dir_from_path(String path) { return base_dir; } -isize calc_decl_count(Ast *decl) { +gb_internal isize calc_decl_count(Ast *decl) { isize count = 0; switch (decl->kind) { case Ast_BlockStmt: @@ -5516,7 +5516,7 @@ isize calc_decl_count(Ast *decl) { return count; } -bool parse_build_project_directory_tag(Token token_for_pos, String s) { +gb_internal bool parse_build_project_directory_tag(Token token_for_pos, String s) { String const prefix = str_lit("+build-project-name"); GB_ASSERT(string_starts_with(s, prefix)); s = string_trim_whitespace(substring(s, prefix.len, s.len)); @@ -5561,7 +5561,7 @@ bool parse_build_project_directory_tag(Token token_for_pos, String s) { return any_correct; } -bool parse_file(Parser *p, AstFile *f) { +gb_internal bool parse_file(Parser *p, AstFile *f) { if (f->tokens.count == 0) { return true; } @@ -5694,7 +5694,7 @@ bool parse_file(Parser *p, AstFile *f) { } -ParseFileError process_imported_file(Parser *p, ImportedFile imported_file) { +gb_internal ParseFileError process_imported_file(Parser *p, ImportedFile imported_file) { AstPackage *pkg = imported_file.pkg; FileInfo fi = imported_file.fi; TokenPos pos = imported_file.pos; @@ -5778,7 +5778,7 @@ ParseFileError process_imported_file(Parser *p, ImportedFile imported_file) { } -ParseFileError parse_packages(Parser *p, String init_filename) { +gb_internal ParseFileError parse_packages(Parser *p, String init_filename) { GB_ASSERT(init_filename.text[init_filename.len] == 0); String init_fullpath = path_to_full_path(heap_allocator(), init_filename); diff --git a/src/parser.hpp b/src/parser.hpp index e384f1e7e..a2d2c038e 100644 --- a/src/parser.hpp +++ b/src/parser.hpp @@ -258,7 +258,7 @@ enum ProcCallingConvention : i32 { ProcCC_ForeignBlockDefault = -1, }; -char const *proc_calling_convention_strings[ProcCC_MAX] = { +gb_global char const *proc_calling_convention_strings[ProcCC_MAX] = { "", "odin", "contextless", @@ -272,7 +272,7 @@ char const *proc_calling_convention_strings[ProcCC_MAX] = { "sysv", }; -ProcCallingConvention default_calling_convention(void) { +gb_internal ProcCallingConvention default_calling_convention(void) { return ProcCC_Odin; } @@ -332,7 +332,7 @@ enum InlineAsmDialectKind : u8 { InlineAsmDialect_COUNT, }; -char const *inline_asm_dialect_strings[InlineAsmDialect_COUNT] = { +gb_global char const *inline_asm_dialect_strings[InlineAsmDialect_COUNT] = { "", "att", "intel", @@ -729,7 +729,7 @@ enum AstKind : u16 { Ast_COUNT, }; -String const ast_strings[] = { +gb_global String const ast_strings[] = { {cast(u8 *)"invalid node", gb_size_of("invalid node")}, #define AST_KIND(_kind_name_, name, ...) {cast(u8 *)name, gb_size_of(name)-1}, AST_KINDS @@ -742,7 +742,7 @@ String const ast_strings[] = { #undef AST_KIND -isize const ast_variant_sizes[] = { +gb_global isize const ast_variant_sizes[] = { 0, #define AST_KIND(_kind_name_, name, ...) gb_size_of(GB_JOIN2(Ast, _kind_name_)), AST_KINDS @@ -793,33 +793,33 @@ struct Ast { #endif -gb_inline bool is_ast_expr(Ast *node) { +gb_internal gb_inline bool is_ast_expr(Ast *node) { return gb_is_between(node->kind, Ast__ExprBegin+1, Ast__ExprEnd-1); } -gb_inline bool is_ast_stmt(Ast *node) { +gb_internal gb_inline bool is_ast_stmt(Ast *node) { return gb_is_between(node->kind, Ast__StmtBegin+1, Ast__StmtEnd-1); } -gb_inline bool is_ast_complex_stmt(Ast *node) { +gb_internal gb_inline bool is_ast_complex_stmt(Ast *node) { return gb_is_between(node->kind, Ast__ComplexStmtBegin+1, Ast__ComplexStmtEnd-1); } -gb_inline bool is_ast_decl(Ast *node) { +gb_internal gb_inline bool is_ast_decl(Ast *node) { return gb_is_between(node->kind, Ast__DeclBegin+1, Ast__DeclEnd-1); } -gb_inline bool is_ast_type(Ast *node) { +gb_internal gb_inline bool is_ast_type(Ast *node) { return gb_is_between(node->kind, Ast__TypeBegin+1, Ast__TypeEnd-1); } -gb_inline bool is_ast_when_stmt(Ast *node) { +gb_internal gb_inline bool is_ast_when_stmt(Ast *node) { return node->kind == Ast_WhenStmt; } gb_global gb_thread_local Arena global_thread_local_ast_arena = {}; -gbAllocator ast_allocator(AstFile *f) { +gb_internal gbAllocator ast_allocator(AstFile *f) { Arena *arena = &global_thread_local_ast_arena; return arena_allocator(arena); } -Ast *alloc_ast_node(AstFile *f, AstKind kind); +gb_internal Ast *alloc_ast_node(AstFile *f, AstKind kind); -gbString expr_to_string(Ast *expression); -bool allow_field_separator(AstFile *f); \ No newline at end of file +gb_internal gbString expr_to_string(Ast *expression); +gb_internal bool allow_field_separator(AstFile *f); \ No newline at end of file diff --git a/src/parser_pos.cpp b/src/parser_pos.cpp index 54c3ec1f1..19a525e2e 100644 --- a/src/parser_pos.cpp +++ b/src/parser_pos.cpp @@ -1,4 +1,4 @@ -Token ast_token(Ast *node) { +gb_internal Token ast_token(Ast *node) { switch (node->kind) { case Ast_Ident: return node->Ident.token; case Ast_Implicit: return node->Implicit; @@ -360,6 +360,6 @@ Token ast_end_token(Ast *node) { return empty_token; } -TokenPos ast_end_pos(Ast *node) { +gb_internal TokenPos ast_end_pos(Ast *node) { return token_pos_end(ast_end_token(node)); } diff --git a/src/priority_queue.cpp b/src/priority_queue.cpp index aee2061b5..c0f1ddff0 100644 --- a/src/priority_queue.cpp +++ b/src/priority_queue.cpp @@ -7,7 +7,7 @@ struct PriorityQueue { }; template -bool priority_queue_shift_down(PriorityQueue *pq, isize i0, isize n) { +gb_internal bool priority_queue_shift_down(PriorityQueue *pq, isize i0, isize n) { // O(n log n) isize i = i0; isize j, j1, j2; @@ -29,7 +29,7 @@ bool priority_queue_shift_down(PriorityQueue *pq, isize i0, isize n) { } template -void priority_queue_shift_up(PriorityQueue *pq, isize j) { +gb_internal void priority_queue_shift_up(PriorityQueue *pq, isize j) { while (0 <= j && j < pq->queue.count) { isize i = (j-1)/2; if (i == j || pq->cmp(&pq->queue[0], j, i) >= 0) { @@ -43,20 +43,20 @@ void priority_queue_shift_up(PriorityQueue *pq, isize j) { // NOTE(bill): When an element at index `i0` has changed its value, this will fix the // the heap ordering. This using a basic "heapsort" with shift up and a shift down parts. template -void priority_queue_fix(PriorityQueue *pq, isize i) { +gb_internal void priority_queue_fix(PriorityQueue *pq, isize i) { if (!priority_queue_shift_down(pq, i, pq->queue.count)) { priority_queue_shift_up(pq, i); } } template -void priority_queue_push(PriorityQueue *pq, T const &value) { +gb_internal void priority_queue_push(PriorityQueue *pq, T const &value) { array_add(&pq->queue, value); priority_queue_shift_up(pq, pq->queue.count-1); } template -T priority_queue_pop(PriorityQueue *pq) { +gb_internal T priority_queue_pop(PriorityQueue *pq) { GB_ASSERT(pq->queue.count > 0); isize n = pq->queue.count - 1; @@ -67,7 +67,7 @@ T priority_queue_pop(PriorityQueue *pq) { template -T priority_queue_remove(PriorityQueue *pq, isize i) { +gb_internal T priority_queue_remove(PriorityQueue *pq, isize i) { GB_ASSERT(0 <= i && i < pq->queue.count); isize n = pq->queue.count - 1; if (n != i) { @@ -80,7 +80,7 @@ T priority_queue_remove(PriorityQueue *pq, isize i) { template -PriorityQueue priority_queue_create(Array queue, +gb_internal PriorityQueue priority_queue_create(Array queue, int (* cmp) (T *q, isize i, isize j), void (* swap)(T *q, isize i, isize j)) { PriorityQueue pq = {}; diff --git a/src/ptr_map.cpp b/src/ptr_map.cpp index ed4b20bf8..434680e91 100644 --- a/src/ptr_map.cpp +++ b/src/ptr_map.cpp @@ -26,7 +26,7 @@ struct PtrMap { }; -u32 ptr_map_hash_key(uintptr key) { +gb_internal gb_inline u32 ptr_map_hash_key(uintptr key) { #if defined(GB_ARCH_64_BIT) key = (~key) + (key << 21); key = key ^ (key >> 24); @@ -41,35 +41,35 @@ u32 ptr_map_hash_key(uintptr key) { return (word >> 22u) ^ word; #endif } -u32 ptr_map_hash_key(void const *key) { +gb_internal gb_inline u32 ptr_map_hash_key(void const *key) { return ptr_map_hash_key((uintptr)key); } -template void map_init (PtrMap *h, gbAllocator a, isize capacity = 16); -template void map_destroy (PtrMap *h); -template V * map_get (PtrMap *h, K key); -template void map_set (PtrMap *h, K key, V const &value); -template void map_remove (PtrMap *h, K key); -template void map_clear (PtrMap *h); -template void map_grow (PtrMap *h); -template void map_rehash (PtrMap *h, isize new_count); -template void map_reserve (PtrMap *h, isize cap); +template gb_internal void map_init (PtrMap *h, gbAllocator a, isize capacity = 16); +template gb_internal void map_destroy (PtrMap *h); +template gb_internal V * map_get (PtrMap *h, K key); +template gb_internal void map_set (PtrMap *h, K key, V const &value); +template gb_internal void map_remove (PtrMap *h, K key); +template gb_internal void map_clear (PtrMap *h); +template gb_internal void map_grow (PtrMap *h); +template gb_internal void map_rehash (PtrMap *h, isize new_count); +template gb_internal void map_reserve (PtrMap *h, isize cap); #if PTR_MAP_ENABLE_MULTI_MAP // Mutlivalued map procedure -template PtrMapEntry * multi_map_find_first(PtrMap *h, K key); -template PtrMapEntry * multi_map_find_next (PtrMap *h, PtrMapEntry *e); - -template isize multi_map_count (PtrMap *h, K key); -template void multi_map_get_all (PtrMap *h, K key, V *items); -template void multi_map_insert (PtrMap *h, K key, V const &value); -template void multi_map_remove (PtrMap *h, K key, PtrMapEntry *e); -template void multi_map_remove_all(PtrMap *h, K key); +template gb_internal PtrMapEntry * multi_map_find_first(PtrMap *h, K key); +template gb_internal PtrMapEntry * multi_map_find_next (PtrMap *h, PtrMapEntry *e); + +template gb_internal isize multi_map_count (PtrMap *h, K key); +template gb_internal void multi_map_get_all (PtrMap *h, K key, V *items); +template gb_internal void multi_map_insert (PtrMap *h, K key, V const &value); +template gb_internal void multi_map_remove (PtrMap *h, K key, PtrMapEntry *e); +template gb_internal void multi_map_remove_all(PtrMap *h, K key); #endif template -gb_inline void map_init(PtrMap *h, gbAllocator a, isize capacity) { +gb_internal gb_inline void map_init(PtrMap *h, gbAllocator a, isize capacity) { capacity = next_pow2_isize(capacity); slice_init(&h->hashes, a, capacity); array_init(&h->entries, a, 0, capacity); @@ -79,7 +79,7 @@ gb_inline void map_init(PtrMap *h, gbAllocator a, isize capacity) { } template -gb_inline void map_destroy(PtrMap *h) { +gb_internal gb_inline void map_destroy(PtrMap *h) { slice_free(&h->hashes, h->entries.allocator); array_free(&h->entries); } @@ -137,13 +137,13 @@ gb_internal b32 map__full(PtrMap *h) { } template -gb_inline void map_grow(PtrMap *h) { +gb_internal gb_inline void map_grow(PtrMap *h) { isize new_count = gb_max(h->hashes.count<<1, 16); map_rehash(h, new_count); } template -void map_reset_entries(PtrMap *h) { +gb_internal void map_reset_entries(PtrMap *h) { for (isize i = 0; i < h->hashes.count; i++) { h->hashes.data[i] = MAP_SENTINEL; } @@ -161,7 +161,7 @@ void map_reset_entries(PtrMap *h) { } template -void map_reserve(PtrMap *h, isize cap) { +gb_internal void map_reserve(PtrMap *h, isize cap) { array_reserve(&h->entries, cap); if (h->entries.count*2 < h->hashes.count) { return; @@ -172,12 +172,12 @@ void map_reserve(PtrMap *h, isize cap) { template -void map_rehash(PtrMap *h, isize new_count) { +gb_internal void map_rehash(PtrMap *h, isize new_count) { map_reserve(h, new_count); } template -V *map_get(PtrMap *h, K key) { +gb_internal V *map_get(PtrMap *h, K key) { MapIndex index = map__find(h, key).entry_index; if (index != MAP_SENTINEL) { return &h->entries.data[index].value; @@ -186,14 +186,14 @@ V *map_get(PtrMap *h, K key) { } template -V &map_must_get(PtrMap *h, K key) { +gb_internal V &map_must_get(PtrMap *h, K key) { MapIndex index = map__find(h, key).entry_index; GB_ASSERT(index != MAP_SENTINEL); return h->entries.data[index].value; } template -void map_set(PtrMap *h, K key, V const &value) { +gb_internal void map_set(PtrMap *h, K key, V const &value) { MapIndex index; MapFindResult fr; if (h->hashes.count == 0) { @@ -219,7 +219,7 @@ void map_set(PtrMap *h, K key, V const &value) { template -void map__erase(PtrMap *h, MapFindResult const &fr) { +gb_internal void map__erase(PtrMap *h, MapFindResult const &fr) { MapFindResult last; if (fr.entry_prev == MAP_SENTINEL) { h->hashes.data[fr.hash_index] = h->entries.data[fr.entry_index].next; @@ -242,7 +242,7 @@ void map__erase(PtrMap *h, MapFindResult const &fr) { } template -void map_remove(PtrMap *h, K key) { +gb_internal void map_remove(PtrMap *h, K key) { MapFindResult fr = map__find(h, key); if (fr.entry_index != MAP_SENTINEL) { map__erase(h, fr); @@ -250,7 +250,7 @@ void map_remove(PtrMap *h, K key) { } template -gb_inline void map_clear(PtrMap *h) { +gb_internal gb_inline void map_clear(PtrMap *h) { array_clear(&h->entries); for (isize i = 0; i < h->hashes.count; i++) { h->hashes.data[i] = MAP_SENTINEL; @@ -260,7 +260,7 @@ gb_inline void map_clear(PtrMap *h) { #if PTR_MAP_ENABLE_MULTI_MAP template -PtrMapEntry *multi_map_find_first(PtrMap *h, K key) { +gb_internal PtrMapEntry *multi_map_find_first(PtrMap *h, K key) { MapIndex i = map__find(h, key).entry_index; if (i == MAP_SENTINEL) { return nullptr; @@ -269,7 +269,7 @@ PtrMapEntry *multi_map_find_first(PtrMap *h, K key) { } template -PtrMapEntry *multi_map_find_next(PtrMap *h, PtrMapEntry *e) { +gb_internal PtrMapEntry *multi_map_find_next(PtrMap *h, PtrMapEntry *e) { MapIndex i = e->next; while (i != MAP_SENTINEL) { if (h->entries.data[i].key == e->key) { @@ -281,7 +281,7 @@ PtrMapEntry *multi_map_find_next(PtrMap *h, PtrMapEntry *e) { } template -isize multi_map_count(PtrMap *h, K key) { +gb_internal isize multi_map_count(PtrMap *h, K key) { isize count = 0; PtrMapEntry *e = multi_map_find_first(h, key); while (e != nullptr) { @@ -292,7 +292,7 @@ isize multi_map_count(PtrMap *h, K key) { } template -void multi_map_get_all(PtrMap *h, K key, V *items) { +gb_internal void multi_map_get_all(PtrMap *h, K key, V *items) { isize i = 0; PtrMapEntry *e = multi_map_find_first(h, key); while (e != nullptr) { @@ -302,7 +302,7 @@ void multi_map_get_all(PtrMap *h, K key, V *items) { } template -void multi_map_insert(PtrMap *h, K key, V const &value) { +gb_internal void multi_map_insert(PtrMap *h, K key, V const &value) { MapFindResult fr; MapIndex i; if (h->hashes.count == 0) { @@ -325,7 +325,7 @@ void multi_map_insert(PtrMap *h, K key, V const &value) { } template -void multi_map_remove(PtrMap *h, K key, PtrMapEntry *e) { +gb_internal void multi_map_remove(PtrMap *h, K key, PtrMapEntry *e) { MapFindResult fr = map__find_from_entry(h, e); if (fr.entry_index != MAP_SENTINEL) { map__erase(h, fr); @@ -333,7 +333,7 @@ void multi_map_remove(PtrMap *h, K key, PtrMapEntry *e) { } template -void multi_map_remove_all(PtrMap *h, K key) { +gb_internal void multi_map_remove_all(PtrMap *h, K key) { while (map_get(h, key) != nullptr) { map_remove(h, key); } @@ -342,21 +342,21 @@ void multi_map_remove_all(PtrMap *h, K key) { template -PtrMapEntry *begin(PtrMap &m) { +gb_internal PtrMapEntry *begin(PtrMap &m) { return m.entries.data; } template -PtrMapEntry const *begin(PtrMap const &m) { +gb_internal PtrMapEntry const *begin(PtrMap const &m) { return m.entries.data; } template -PtrMapEntry *end(PtrMap &m) { +gb_internal PtrMapEntry *end(PtrMap &m) { return m.entries.data + m.entries.count; } template -PtrMapEntry const *end(PtrMap const &m) { +gb_internal PtrMapEntry const *end(PtrMap const &m) { return m.entries.data + m.entries.count; } diff --git a/src/ptr_set.cpp b/src/ptr_set.cpp index 04ce162e2..9ecf1043e 100644 --- a/src/ptr_set.cpp +++ b/src/ptr_set.cpp @@ -10,20 +10,20 @@ struct PtrSet { Array> entries; }; -template void ptr_set_init (PtrSet *s, gbAllocator a, isize capacity = 16); -template void ptr_set_destroy(PtrSet *s); -template T ptr_set_add (PtrSet *s, T ptr); -template bool ptr_set_update (PtrSet *s, T ptr); // returns true if it previously existed -template bool ptr_set_exists (PtrSet *s, T ptr); -template void ptr_set_remove (PtrSet *s, T ptr); -template void ptr_set_clear (PtrSet *s); -template void ptr_set_grow (PtrSet *s); -template void ptr_set_rehash (PtrSet *s, isize new_count); -template void ptr_set_reserve(PtrSet *h, isize cap); +template gb_internal void ptr_set_init (PtrSet *s, gbAllocator a, isize capacity = 16); +template gb_internal void ptr_set_destroy(PtrSet *s); +template gb_internal T ptr_set_add (PtrSet *s, T ptr); +template gb_internal bool ptr_set_update (PtrSet *s, T ptr); // returns true if it previously existed +template gb_internal bool ptr_set_exists (PtrSet *s, T ptr); +template gb_internal void ptr_set_remove (PtrSet *s, T ptr); +template gb_internal void ptr_set_clear (PtrSet *s); +template gb_internal void ptr_set_grow (PtrSet *s); +template gb_internal void ptr_set_rehash (PtrSet *s, isize new_count); +template gb_internal void ptr_set_reserve(PtrSet *h, isize cap); template -void ptr_set_init(PtrSet *s, gbAllocator a, isize capacity) { +gb_internal void ptr_set_init(PtrSet *s, gbAllocator a, isize capacity) { if (capacity != 0) { capacity = next_pow2_isize(gb_max(16, capacity)); } @@ -36,7 +36,7 @@ void ptr_set_init(PtrSet *s, gbAllocator a, isize capacity) { } template -void ptr_set_destroy(PtrSet *s) { +gb_internal void ptr_set_destroy(PtrSet *s) { slice_free(&s->hashes, s->entries.allocator); array_free(&s->entries); } @@ -93,13 +93,13 @@ gb_internal bool ptr_set__full(PtrSet *s) { } template -gb_inline void ptr_set_grow(PtrSet *s) { +gb_internal gb_inline void ptr_set_grow(PtrSet *s) { isize new_count = gb_max(s->hashes.count<<1, 16); ptr_set_rehash(s, new_count); } template -void ptr_set_reset_entries(PtrSet *s) { +gb_internal void ptr_set_reset_entries(PtrSet *s) { for (isize i = 0; i < s->hashes.count; i++) { s->hashes.data[i] = MAP_SENTINEL; } @@ -117,7 +117,7 @@ void ptr_set_reset_entries(PtrSet *s) { } template -void ptr_set_reserve(PtrSet *s, isize cap) { +gb_internal void ptr_set_reserve(PtrSet *s, isize cap) { array_reserve(&s->entries, cap); if (s->entries.count*2 < s->hashes.count) { return; @@ -128,18 +128,18 @@ void ptr_set_reserve(PtrSet *s, isize cap) { template -void ptr_set_rehash(PtrSet *s, isize new_count) { +gb_internal void ptr_set_rehash(PtrSet *s, isize new_count) { ptr_set_reserve(s, new_count); } template -gb_inline bool ptr_set_exists(PtrSet *s, T ptr) { +gb_internal gb_inline bool ptr_set_exists(PtrSet *s, T ptr) { isize index = ptr_set__find(s, ptr).entry_index; return index != MAP_SENTINEL; } template -gb_inline isize ptr_entry_index(PtrSet *s, T ptr) { +gb_internal gb_inline isize ptr_entry_index(PtrSet *s, T ptr) { isize index = ptr_set__find(s, ptr).entry_index; if (index != MAP_SENTINEL) { return index; @@ -149,7 +149,7 @@ gb_inline isize ptr_entry_index(PtrSet *s, T ptr) { // Returns true if it already exists template -T ptr_set_add(PtrSet *s, T ptr) { +gb_internal T ptr_set_add(PtrSet *s, T ptr) { MapIndex index; MapFindResult fr; if (s->hashes.count == 0) { @@ -171,7 +171,7 @@ T ptr_set_add(PtrSet *s, T ptr) { } template -bool ptr_set_update(PtrSet *s, T ptr) { // returns true if it previously existsed +gb_internal bool ptr_set_update(PtrSet *s, T ptr) { // returns true if it previously existsed bool exists = false; MapIndex index; MapFindResult fr; @@ -198,7 +198,7 @@ bool ptr_set_update(PtrSet *s, T ptr) { // returns true if it previously exis template -void ptr_set__erase(PtrSet *s, MapFindResult fr) { +gb_internal void ptr_set__erase(PtrSet *s, MapFindResult fr) { MapFindResult last; if (fr.entry_prev == MAP_SENTINEL) { s->hashes.data[fr.hash_index] = s->entries.data[fr.entry_index].next; @@ -219,7 +219,7 @@ void ptr_set__erase(PtrSet *s, MapFindResult fr) { } template -void ptr_set_remove(PtrSet *s, T ptr) { +gb_internal void ptr_set_remove(PtrSet *s, T ptr) { MapFindResult fr = ptr_set__find(s, ptr); if (fr.entry_index != MAP_SENTINEL) { ptr_set__erase(s, fr); @@ -227,7 +227,7 @@ void ptr_set_remove(PtrSet *s, T ptr) { } template -gb_inline void ptr_set_clear(PtrSet *s) { +gb_internal gb_inline void ptr_set_clear(PtrSet *s) { array_clear(&s->entries); for (isize i = 0; i < s->hashes.count; i++) { s->hashes.data[i] = MAP_SENTINEL; @@ -236,21 +236,21 @@ gb_inline void ptr_set_clear(PtrSet *s) { template -PtrSetEntry *begin(PtrSet &m) { +gb_internal PtrSetEntry *begin(PtrSet &m) { return m.entries.data; } template -PtrSetEntry const *begin(PtrSet const &m) { +gb_internal PtrSetEntry const *begin(PtrSet const &m) { return m.entries.data; } template -PtrSetEntry *end(PtrSet &m) { +gb_internal PtrSetEntry *end(PtrSet &m) { return m.entries.data + m.entries.count; } template -PtrSetEntry const *end(PtrSet const &m) { +gb_internal PtrSetEntry const *end(PtrSet const &m) { return m.entries.data + m.entries.count; } \ No newline at end of file diff --git a/src/queue.cpp b/src/queue.cpp index ee8b1b086..4de5ac5e5 100644 --- a/src/queue.cpp +++ b/src/queue.cpp @@ -23,7 +23,7 @@ struct MPMCQueue { -void mpmc_internal_init_indices(MPMCQueueAtomicIdx *indices, i32 offset, i32 size) { +gb_internal void mpmc_internal_init_indices(MPMCQueueAtomicIdx *indices, i32 offset, i32 size) { GB_ASSERT(offset % 8 == 0); GB_ASSERT(size % 8 == 0); @@ -43,7 +43,7 @@ void mpmc_internal_init_indices(MPMCQueueAtomicIdx *indices, i32 offset, i32 siz template -void mpmc_init(MPMCQueue *q, gbAllocator a, isize size_i) { +gb_internal void mpmc_init(MPMCQueue *q, gbAllocator a, isize size_i) { if (size_i < 8) { size_i = 8; } @@ -64,7 +64,7 @@ void mpmc_init(MPMCQueue *q, gbAllocator a, isize size_i) { template -void mpmc_destroy(MPMCQueue *q) { +gb_internal void mpmc_destroy(MPMCQueue *q) { mutex_destroy(&q->mutex); gb_free(q->allocator, q->nodes); gb_free(q->allocator, q->indices); @@ -72,7 +72,7 @@ void mpmc_destroy(MPMCQueue *q) { template -bool mpmc_internal_grow(MPMCQueue *q) { +gb_internal bool mpmc_internal_grow(MPMCQueue *q) { mutex_lock(&q->mutex); i32 old_size = q->mask+1; i32 new_size = old_size*2; @@ -95,7 +95,7 @@ bool mpmc_internal_grow(MPMCQueue *q) { } template -i32 mpmc_enqueue(MPMCQueue *q, T const &data) { +gb_internal i32 mpmc_enqueue(MPMCQueue *q, T const &data) { GB_ASSERT(q->mask != 0); i32 head_idx = q->head_idx.load(std::memory_order_relaxed); @@ -125,7 +125,7 @@ i32 mpmc_enqueue(MPMCQueue *q, T const &data) { } template -bool mpmc_dequeue(MPMCQueue *q, T *data_) { +gb_internal bool mpmc_dequeue(MPMCQueue *q, T *data_) { if (q->mask == 0) { return false; } diff --git a/src/range_cache.cpp b/src/range_cache.cpp index 9701fb432..1f98c4b9e 100644 --- a/src/range_cache.cpp +++ b/src/range_cache.cpp @@ -10,17 +10,17 @@ struct RangeCache { }; -RangeCache range_cache_make(gbAllocator a) { +gb_internal RangeCache range_cache_make(gbAllocator a) { RangeCache cache = {}; array_init(&cache.ranges, a); return cache; } -void range_cache_destroy(RangeCache *c) { +gb_internal void range_cache_destroy(RangeCache *c) { array_free(&c->ranges); } -bool range_cache_add_index(RangeCache *c, i64 index) { +gb_internal bool range_cache_add_index(RangeCache *c, i64 index) { for_array(i, c->ranges) { RangeValue v = c->ranges[i]; if (v.lo <= index && index <= v.hi) { @@ -33,7 +33,7 @@ bool range_cache_add_index(RangeCache *c, i64 index) { } -bool range_cache_add_range(RangeCache *c, i64 lo, i64 hi) { +gb_internal bool range_cache_add_range(RangeCache *c, i64 lo, i64 hi) { GB_ASSERT(lo <= hi); for_array(i, c->ranges) { RangeValue v = c->ranges[i]; @@ -59,7 +59,7 @@ bool range_cache_add_range(RangeCache *c, i64 lo, i64 hi) { } -bool range_cache_index_exists(RangeCache *c, i64 index) { +gb_internal bool range_cache_index_exists(RangeCache *c, i64 index) { for_array(i, c->ranges) { RangeValue v = c->ranges[i]; if (v.lo <= index && index <= v.hi) { diff --git a/src/string.cpp b/src/string.cpp index bc55e370c..aeb31c7b0 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -1,6 +1,6 @@ gb_global BlockingMutex string_buffer_mutex = {}; -void init_string_buffer_memory(void) { +gb_internal void init_string_buffer_memory(void) { mutex_init(&string_buffer_mutex); } @@ -36,7 +36,7 @@ struct String16 { }; -gb_inline String make_string(u8 const *text, isize len) { +gb_internal gb_inline String make_string(u8 const *text, isize len) { String s; s.text = cast(u8 *)text; if (len < 0) { @@ -47,14 +47,14 @@ gb_inline String make_string(u8 const *text, isize len) { } -gb_inline String16 make_string16(wchar_t const *text, isize len) { +gb_internal gb_inline String16 make_string16(wchar_t const *text, isize len) { String16 s; s.text = cast(wchar_t *)text; s.len = len; return s; } -isize string16_len(wchar_t const *s) { +gb_internal isize string16_len(wchar_t const *s) { if (s == nullptr) { return 0; } @@ -66,15 +66,15 @@ isize string16_len(wchar_t const *s) { } -gb_inline String make_string_c(char const *text) { +gb_internal gb_inline String make_string_c(char const *text) { return make_string(cast(u8 *)cast(void *)text, gb_strlen(text)); } -gb_inline String16 make_string16_c(wchar_t const *text) { +gb_internal gb_inline String16 make_string16_c(wchar_t const *text) { return make_string16(text, string16_len(text)); } -String substring(String const &s, isize lo, isize hi) { +gb_internal String substring(String const &s, isize lo, isize hi) { isize max = s.len; GB_ASSERT_MSG(lo <= hi && hi <= max, "%td..%td..%td", lo, hi, max); @@ -82,14 +82,14 @@ String substring(String const &s, isize lo, isize hi) { } -char *alloc_cstring(gbAllocator a, String s) { +gb_internal char *alloc_cstring(gbAllocator a, String s) { char *c_str = gb_alloc_array(a, char, s.len+1); gb_memmove(c_str, s.text, s.len); c_str[s.len] = '\0'; return c_str; } -char *cstring_duplicate(gbAllocator a, char const *s) { +gb_internal char *cstring_duplicate(gbAllocator a, char const *s) { isize len = gb_strlen(s); char *c_str = gb_alloc_array(a, char, len+1); gb_memmove(c_str, s, len); @@ -99,7 +99,7 @@ char *cstring_duplicate(gbAllocator a, char const *s) { -gb_inline bool str_eq_ignore_case(String const &a, String const &b) { +gb_internal gb_inline bool str_eq_ignore_case(String const &a, String const &b) { if (a.len == b.len) { for (isize i = 0; i < a.len; i++) { char x = cast(char)a[i]; @@ -113,13 +113,13 @@ gb_inline bool str_eq_ignore_case(String const &a, String const &b) { return false; } -void string_to_lower(String *s) { +gb_internal void string_to_lower(String *s) { for (isize i = 0; i < s->len; i++) { s->text[i] = gb_char_to_lower(s->text[i]); } } -int string_compare(String const &x, String const &y) { +gb_internal int string_compare(String const &x, String const &y) { if (x.len != y.len || x.text != y.text) { isize n, fast, offset, curr_block; isize *la, *lb; @@ -157,7 +157,7 @@ int string_compare(String const &x, String const &y) { return 0; } -isize string_index_byte(String const &s, u8 x) { +gb_internal isize string_index_byte(String const &s, u8 x) { for (isize i = 0; i < s.len; i++) { if (s.text[i] == x) { return i; @@ -166,37 +166,37 @@ isize string_index_byte(String const &s, u8 x) { return -1; } -GB_COMPARE_PROC(string_cmp_proc) { +gb_internal GB_COMPARE_PROC(string_cmp_proc) { String x = *(String *)a; String y = *(String *)b; return string_compare(x, y); } -gb_inline bool str_eq(String const &a, String const &b) { +gb_internal gb_inline bool str_eq(String const &a, String const &b) { if (a.len != b.len) return false; return memcmp(a.text, b.text, a.len) == 0; } -gb_inline bool str_ne(String const &a, String const &b) { return !str_eq(a, b); } -gb_inline bool str_lt(String const &a, String const &b) { return string_compare(a, b) < 0; } -gb_inline bool str_gt(String const &a, String const &b) { return string_compare(a, b) > 0; } -gb_inline bool str_le(String const &a, String const &b) { return string_compare(a, b) <= 0; } -gb_inline bool str_ge(String const &a, String const &b) { return string_compare(a, b) >= 0; } - -gb_inline bool operator == (String const &a, String const &b) { return str_eq(a, b); } -gb_inline bool operator != (String const &a, String const &b) { return str_ne(a, b); } -gb_inline bool operator < (String const &a, String const &b) { return str_lt(a, b); } -gb_inline bool operator > (String const &a, String const &b) { return str_gt(a, b); } -gb_inline bool operator <= (String const &a, String const &b) { return str_le(a, b); } -gb_inline bool operator >= (String const &a, String const &b) { return str_ge(a, b); } - -template bool operator == (String const &a, char const (&b)[N]) { return str_eq(a, make_string(cast(u8 *)b, N-1)); } -template bool operator != (String const &a, char const (&b)[N]) { return str_ne(a, make_string(cast(u8 *)b, N-1)); } -template bool operator < (String const &a, char const (&b)[N]) { return str_lt(a, make_string(cast(u8 *)b, N-1)); } -template bool operator > (String const &a, char const (&b)[N]) { return str_gt(a, make_string(cast(u8 *)b, N-1)); } -template bool operator <= (String const &a, char const (&b)[N]) { return str_le(a, make_string(cast(u8 *)b, N-1)); } -template bool operator >= (String const &a, char const (&b)[N]) { return str_ge(a, make_string(cast(u8 *)b, N-1)); } - -gb_inline bool string_starts_with(String const &s, String const &prefix) { +gb_internal gb_inline bool str_ne(String const &a, String const &b) { return !str_eq(a, b); } +gb_internal gb_inline bool str_lt(String const &a, String const &b) { return string_compare(a, b) < 0; } +gb_internal gb_inline bool str_gt(String const &a, String const &b) { return string_compare(a, b) > 0; } +gb_internal gb_inline bool str_le(String const &a, String const &b) { return string_compare(a, b) <= 0; } +gb_internal gb_inline bool str_ge(String const &a, String const &b) { return string_compare(a, b) >= 0; } + +gb_internal gb_inline bool operator == (String const &a, String const &b) { return str_eq(a, b); } +gb_internal gb_inline bool operator != (String const &a, String const &b) { return str_ne(a, b); } +gb_internal gb_inline bool operator < (String const &a, String const &b) { return str_lt(a, b); } +gb_internal gb_inline bool operator > (String const &a, String const &b) { return str_gt(a, b); } +gb_internal gb_inline bool operator <= (String const &a, String const &b) { return str_le(a, b); } +gb_internal gb_inline bool operator >= (String const &a, String const &b) { return str_ge(a, b); } + +template gb_internal bool operator == (String const &a, char const (&b)[N]) { return str_eq(a, make_string(cast(u8 *)b, N-1)); } +template gb_internal bool operator != (String const &a, char const (&b)[N]) { return str_ne(a, make_string(cast(u8 *)b, N-1)); } +template gb_internal bool operator < (String const &a, char const (&b)[N]) { return str_lt(a, make_string(cast(u8 *)b, N-1)); } +template gb_internal bool operator > (String const &a, char const (&b)[N]) { return str_gt(a, make_string(cast(u8 *)b, N-1)); } +template gb_internal bool operator <= (String const &a, char const (&b)[N]) { return str_le(a, make_string(cast(u8 *)b, N-1)); } +template gb_internal bool operator >= (String const &a, char const (&b)[N]) { return str_ge(a, make_string(cast(u8 *)b, N-1)); } + +gb_internal gb_inline bool string_starts_with(String const &s, String const &prefix) { if (prefix.len > s.len) { return false; } @@ -204,7 +204,7 @@ gb_inline bool string_starts_with(String const &s, String const &prefix) { return substring(s, 0, prefix.len) == prefix; } -gb_inline bool string_ends_with(String const &s, String const &suffix) { +gb_internal gb_inline bool string_ends_with(String const &s, String const &suffix) { if (suffix.len > s.len) { return false; } @@ -212,7 +212,7 @@ gb_inline bool string_ends_with(String const &s, String const &suffix) { return substring(s, s.len-suffix.len, s.len) == suffix; } -gb_inline bool string_starts_with(String const &s, u8 prefix) { +gb_internal gb_inline bool string_starts_with(String const &s, u8 prefix) { if (1 > s.len) { return false; } @@ -221,7 +221,7 @@ gb_inline bool string_starts_with(String const &s, u8 prefix) { } -gb_inline bool string_ends_with(String const &s, u8 suffix) { +gb_internal gb_inline bool string_ends_with(String const &s, u8 suffix) { if (1 > s.len) { return false; } @@ -231,7 +231,7 @@ gb_inline bool string_ends_with(String const &s, u8 suffix) { -gb_inline String string_trim_starts_with(String const &s, String const &prefix) { +gb_internal gb_inline String string_trim_starts_with(String const &s, String const &prefix) { if (string_starts_with(s, prefix)) { return substring(s, prefix.len, s.len); } @@ -239,7 +239,7 @@ gb_inline String string_trim_starts_with(String const &s, String const &prefix) } -gb_inline isize string_extension_position(String const &str) { +gb_internal gb_inline isize string_extension_position(String const &str) { isize dot_pos = -1; isize i = str.len; while (i --> 0) { @@ -254,7 +254,7 @@ gb_inline isize string_extension_position(String const &str) { return dot_pos; } -String path_extension(String const &str, bool include_dot = true) { +gb_internal String path_extension(String const &str, bool include_dot = true) { isize pos = string_extension_position(str); if (pos < 0) { return make_string(nullptr, 0); @@ -262,7 +262,7 @@ String path_extension(String const &str, bool include_dot = true) { return substring(str, include_dot ? pos : pos + 1, str.len); } -String string_trim_whitespace(String str) { +gb_internal String string_trim_whitespace(String str) { while (str.len > 0 && rune_is_whitespace(str[str.len-1])) { str.len--; } @@ -279,7 +279,7 @@ String string_trim_whitespace(String str) { return str; } -bool string_contains_char(String const &s, u8 c) { +gb_internal bool string_contains_char(String const &s, u8 c) { isize i; for (i = 0; i < s.len; i++) { if (s[i] == c) @@ -288,7 +288,7 @@ bool string_contains_char(String const &s, u8 c) { return false; } -String filename_from_path(String s) { +gb_internal String filename_from_path(String s) { isize i = string_extension_position(s); if (i >= 0) { s = substring(s, 0, i); @@ -307,7 +307,7 @@ String filename_from_path(String s) { return make_string(nullptr, 0); } -String concatenate_strings(gbAllocator a, String const &x, String const &y) { +gb_internal String concatenate_strings(gbAllocator a, String const &x, String const &y) { isize len = x.len+y.len; u8 *data = gb_alloc_array(a, u8, len+1); gb_memmove(data, x.text, x.len); @@ -315,7 +315,7 @@ String concatenate_strings(gbAllocator a, String const &x, String const &y) { data[len] = 0; return make_string(data, len); } -String concatenate3_strings(gbAllocator a, String const &x, String const &y, String const &z) { +gb_internal String concatenate3_strings(gbAllocator a, String const &x, String const &y, String const &z) { isize len = x.len+y.len+z.len; u8 *data = gb_alloc_array(a, u8, len+1); gb_memmove(data, x.text, x.len); @@ -324,7 +324,7 @@ String concatenate3_strings(gbAllocator a, String const &x, String const &y, Str data[len] = 0; return make_string(data, len); } -String concatenate4_strings(gbAllocator a, String const &x, String const &y, String const &z, String const &w) { +gb_internal String concatenate4_strings(gbAllocator a, String const &x, String const &y, String const &z, String const &w) { isize len = x.len+y.len+z.len+w.len; u8 *data = gb_alloc_array(a, u8, len+1); gb_memmove(data, x.text, x.len); @@ -335,7 +335,7 @@ String concatenate4_strings(gbAllocator a, String const &x, String const &y, Str return make_string(data, len); } -String string_join_and_quote(gbAllocator a, Array strings) { +gb_internal String string_join_and_quote(gbAllocator a, Array strings) { if (!strings.count) { return make_string(nullptr, 0); } @@ -356,7 +356,7 @@ String string_join_and_quote(gbAllocator a, Array strings) { return make_string(cast(u8 *) s, gb_string_length(s)); } -String copy_string(gbAllocator a, String const &s) { +gb_internal String copy_string(gbAllocator a, String const &s) { u8 *data = gb_alloc_array(a, u8, s.len+1); gb_memmove(data, s.text, s.len); data[s.len] = 0; @@ -367,17 +367,17 @@ String copy_string(gbAllocator a, String const &s) { #if defined(GB_SYSTEM_WINDOWS) - int convert_multibyte_to_widechar(char const *multibyte_input, int input_length, wchar_t *output, int output_size) { + gb_internal int convert_multibyte_to_widechar(char const *multibyte_input, int input_length, wchar_t *output, int output_size) { return MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, multibyte_input, input_length, output, output_size); } - int convert_widechar_to_multibyte(wchar_t const *widechar_input, int input_length, char *output, int output_size) { + gb_internal int convert_widechar_to_multibyte(wchar_t const *widechar_input, int input_length, char *output, int output_size) { return WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, widechar_input, input_length, output, output_size, nullptr, nullptr); } #elif defined(GB_SYSTEM_UNIX) || defined(GB_SYSTEM_OSX) #include - int convert_multibyte_to_widechar(char const *multibyte_input, usize input_length, wchar_t *output, usize output_size) { + gb_internal int convert_multibyte_to_widechar(char const *multibyte_input, usize input_length, wchar_t *output, usize output_size) { iconv_t conv = iconv_open("WCHAR_T", "UTF-8"); size_t result = iconv(conv, cast(char **)&multibyte_input, &input_length, cast(char **)&output, &output_size); iconv_close(conv); @@ -385,7 +385,7 @@ String copy_string(gbAllocator a, String const &s) { return cast(int)result; } - int convert_widechar_to_multibyte(wchar_t const *widechar_input, usize input_length, char* output, usize output_size) { + gb_internal int convert_widechar_to_multibyte(wchar_t const *widechar_input, usize input_length, char* output, usize output_size) { iconv_t conv = iconv_open("UTF-8", "WCHAR_T"); size_t result = iconv(conv, cast(char**) &widechar_input, &input_length, cast(char **)&output, &output_size); iconv_close(conv); @@ -400,7 +400,7 @@ String copy_string(gbAllocator a, String const &s) { // TODO(bill): Make this non-windows specific -String16 string_to_string16(gbAllocator a, String s) { +gb_internal String16 string_to_string16(gbAllocator a, String s) { int len, len1; wchar_t *text; @@ -426,7 +426,7 @@ String16 string_to_string16(gbAllocator a, String s) { } -String string16_to_string(gbAllocator a, String16 s) { +gb_internal String string16_to_string(gbAllocator a, String16 s) { int len, len1; u8 *text; @@ -458,7 +458,7 @@ String string16_to_string(gbAllocator a, String16 s) { -bool is_printable(Rune r) { +gb_internal bool is_printable(Rune r) { if (r <= 0xff) { if (0x20 <= r && r <= 0x7e) { return true; @@ -473,7 +473,7 @@ bool is_printable(Rune r) { gb_global char const lower_hex[] = "0123456789abcdef"; -String quote_to_ascii(gbAllocator a, String str, u8 quote='"') { +gb_internal String quote_to_ascii(gbAllocator a, String str, u8 quote='"') { u8 *s = str.text; isize n = str.len; auto buf = array_make(a, 0, n); @@ -548,7 +548,7 @@ String quote_to_ascii(gbAllocator a, String str, u8 quote='"') { -bool unquote_char(String s, u8 quote, Rune *rune, bool *multiple_bytes, String *tail_string) { +gb_internal bool unquote_char(String s, u8 quote, Rune *rune, bool *multiple_bytes, String *tail_string) { u8 c; if (s[0] == quote && @@ -657,7 +657,7 @@ bool unquote_char(String s, u8 quote, Rune *rune, bool *multiple_bytes, String * } -String strip_carriage_return(gbAllocator a, String s) { +gb_internal String strip_carriage_return(gbAllocator a, String s) { isize buf_len = s.len; u8 *buf = gb_alloc_array(a, u8, buf_len); isize i = 0; @@ -675,7 +675,7 @@ String strip_carriage_return(gbAllocator a, String s) { // 0 == failure // 1 == original memory // 2 == new allocation -i32 unquote_string(gbAllocator a, String *s_, u8 quote=0, bool has_carriage_return=false) { +gb_internal i32 unquote_string(gbAllocator a, String *s_, u8 quote=0, bool has_carriage_return=false) { String s = *s_; isize n = s.len; if (quote == 0) { @@ -761,7 +761,7 @@ i32 unquote_string(gbAllocator a, String *s_, u8 quote=0, bool has_carriage_retu -bool string_is_valid_identifier(String str) { +gb_internal bool string_is_valid_identifier(String str) { if (str.len <= 0) return false; isize rune_count = 0; diff --git a/src/string_map.cpp b/src/string_map.cpp index e2a4d5f65..e289d4c9b 100644 --- a/src/string_map.cpp +++ b/src/string_map.cpp @@ -3,7 +3,7 @@ struct StringHashKey { String string; }; -gb_inline StringHashKey string_hash_string(String const &s) { +gb_internal gb_inline StringHashKey string_hash_string(String const &s) { StringHashKey hash_key = {}; hash_key.hash = fnv32a(s.text, s.len); hash_key.string = s; @@ -11,15 +11,15 @@ gb_inline StringHashKey string_hash_string(String const &s) { } -bool string_hash_key_equal(StringHashKey const &a, StringHashKey const &b) { +gb_internal gb_inline bool string_hash_key_equal(StringHashKey const &a, StringHashKey const &b) { if (a.hash == b.hash) { // NOTE(bill): If two string's hashes collide, compare the strings themselves return a.string == b.string; } return false; } -bool operator==(StringHashKey const &a, StringHashKey const &b) { return string_hash_key_equal(a, b); } -bool operator!=(StringHashKey const &a, StringHashKey const &b) { return !string_hash_key_equal(a, b); } +gb_internal bool operator==(StringHashKey const &a, StringHashKey const &b) { return string_hash_key_equal(a, b); } +gb_internal bool operator!=(StringHashKey const &a, StringHashKey const &b) { return !string_hash_key_equal(a, b); } template struct StringMapEntry { @@ -37,29 +37,29 @@ struct StringMap { }; -template void string_map_init (StringMap *h, gbAllocator a, isize capacity = 16); -template void string_map_destroy (StringMap *h); +template gb_internal void string_map_init (StringMap *h, gbAllocator a, isize capacity = 16); +template gb_internal void string_map_destroy (StringMap *h); -template T * string_map_get (StringMap *h, char const *key); -template T * string_map_get (StringMap *h, String const &key); -template T * string_map_get (StringMap *h, StringHashKey const &key); +template gb_internal T * string_map_get (StringMap *h, char const *key); +template gb_internal T * string_map_get (StringMap *h, String const &key); +template gb_internal T * string_map_get (StringMap *h, StringHashKey const &key); -template T & string_map_must_get (StringMap *h, char const *key); -template T & string_map_must_get (StringMap *h, String const &key); -template T & string_map_must_get (StringMap *h, StringHashKey const &key); +template gb_internal T & string_map_must_get (StringMap *h, char const *key); +template gb_internal T & string_map_must_get (StringMap *h, String const &key); +template gb_internal T & string_map_must_get (StringMap *h, StringHashKey const &key); -template void string_map_set (StringMap *h, StringHashKey const &key, T const &value); -template void string_map_set (StringMap *h, String const &key, T const &value); -template void string_map_set (StringMap *h, char const *key, T const &value); +template gb_internal void string_map_set (StringMap *h, StringHashKey const &key, T const &value); +template gb_internal void string_map_set (StringMap *h, String const &key, T const &value); +template gb_internal void string_map_set (StringMap *h, char const *key, T const &value); -template void string_map_remove (StringMap *h, StringHashKey const &key); -template void string_map_clear (StringMap *h); -template void string_map_grow (StringMap *h); -template void string_map_rehash (StringMap *h, isize new_count); -template void string_map_reserve (StringMap *h, isize cap); +template gb_internal void string_map_remove (StringMap *h, StringHashKey const &key); +template gb_internal void string_map_clear (StringMap *h); +template gb_internal void string_map_grow (StringMap *h); +template gb_internal void string_map_rehash (StringMap *h, isize new_count); +template gb_internal void string_map_reserve (StringMap *h, isize cap); template -gb_inline void string_map_init(StringMap *h, gbAllocator a, isize capacity) { +gb_internal gb_inline void string_map_init(StringMap *h, gbAllocator a, isize capacity) { capacity = next_pow2_isize(capacity); slice_init(&h->hashes, a, capacity); array_init(&h->entries, a, 0, capacity); @@ -69,7 +69,7 @@ gb_inline void string_map_init(StringMap *h, gbAllocator a, isize capacity) { } template -gb_inline void string_map_destroy(StringMap *h) { +gb_internal gb_inline void string_map_destroy(StringMap *h) { slice_free(&h->hashes, h->entries.allocator); array_free(&h->entries); } @@ -130,7 +130,7 @@ gb_inline void string_map_grow(StringMap *h) { template -void string_map_reset_entries(StringMap *h) { +gb_internal void string_map_reset_entries(StringMap *h) { for (isize i = 0; i < h->hashes.count; i++) { h->hashes.data[i] = MAP_SENTINEL; } @@ -148,7 +148,7 @@ void string_map_reset_entries(StringMap *h) { } template -void string_map_reserve(StringMap *h, isize cap) { +gb_internal void string_map_reserve(StringMap *h, isize cap) { array_reserve(&h->entries, cap); if (h->entries.count*2 < h->hashes.count) { return; @@ -159,12 +159,12 @@ void string_map_reserve(StringMap *h, isize cap) { template -void string_map_rehash(StringMap *h, isize new_count) { +gb_internal void string_map_rehash(StringMap *h, isize new_count) { string_map_reserve(h, new_count); } template -T *string_map_get(StringMap *h, StringHashKey const &key) { +gb_internal T *string_map_get(StringMap *h, StringHashKey const &key) { isize index = string_map__find(h, key).entry_index; if (index != MAP_SENTINEL) { return &h->entries.data[index].value; @@ -173,34 +173,34 @@ T *string_map_get(StringMap *h, StringHashKey const &key) { } template -gb_inline T *string_map_get(StringMap *h, String const &key) { +gb_internal gb_inline T *string_map_get(StringMap *h, String const &key) { return string_map_get(h, string_hash_string(key)); } template -gb_inline T *string_map_get(StringMap *h, char const *key) { +gb_internal gb_inline T *string_map_get(StringMap *h, char const *key) { return string_map_get(h, string_hash_string(make_string_c(key))); } template -T &string_map_must_get(StringMap *h, StringHashKey const &key) { +gb_internal T &string_map_must_get(StringMap *h, StringHashKey const &key) { isize index = string_map__find(h, key).entry_index; GB_ASSERT(index != MAP_SENTINEL); return h->entries.data[index].value; } template -gb_inline T &string_map_must_get(StringMap *h, String const &key) { +gb_internal gb_inline T &string_map_must_get(StringMap *h, String const &key) { return string_map_must_get(h, string_hash_string(key)); } template -gb_inline T &string_map_must_get(StringMap *h, char const *key) { +gb_internal gb_inline T &string_map_must_get(StringMap *h, char const *key) { return string_map_must_get(h, string_hash_string(make_string_c(key))); } template -void string_map_set(StringMap *h, StringHashKey const &key, T const &value) { +gb_internal void string_map_set(StringMap *h, StringHashKey const &key, T const &value) { MapIndex index; MapFindResult fr; if (h->hashes.count == 0) { @@ -225,18 +225,18 @@ void string_map_set(StringMap *h, StringHashKey const &key, T const &value) { } template -gb_inline void string_map_set(StringMap *h, String const &key, T const &value) { +gb_internal gb_inline void string_map_set(StringMap *h, String const &key, T const &value) { string_map_set(h, string_hash_string(key), value); } template -gb_inline void string_map_set(StringMap *h, char const *key, T const &value) { +gb_internal gb_inline void string_map_set(StringMap *h, char const *key, T const &value) { string_map_set(h, string_hash_string(make_string_c(key)), value); } template -void string_map__erase(StringMap *h, MapFindResult const &fr) { +gb_internal void string_map__erase(StringMap *h, MapFindResult const &fr) { MapFindResult last; if (fr.entry_prev == MAP_SENTINEL) { h->hashes.data[fr.hash_index] = h->entries.data[fr.entry_index].next; @@ -257,7 +257,7 @@ void string_map__erase(StringMap *h, MapFindResult const &fr) { } template -void string_map_remove(StringMap *h, StringHashKey const &key) { +gb_internal void string_map_remove(StringMap *h, StringHashKey const &key) { MapFindResult fr = string_map__find(h, key); if (fr.entry_index != MAP_SENTINEL) { string_map__erase(h, fr); @@ -265,7 +265,7 @@ void string_map_remove(StringMap *h, StringHashKey const &key) { } template -gb_inline void string_map_clear(StringMap *h) { +gb_internal gb_inline void string_map_clear(StringMap *h) { array_clear(&h->entries); for (isize i = 0; i < h->hashes.count; i++) { h->hashes.data[i] = MAP_SENTINEL; @@ -275,21 +275,21 @@ gb_inline void string_map_clear(StringMap *h) { template -StringMapEntry *begin(StringMap &m) { +gb_internal StringMapEntry *begin(StringMap &m) { return m.entries.data; } template -StringMapEntry const *begin(StringMap const &m) { +gb_internal StringMapEntry const *begin(StringMap const &m) { return m.entries.data; } template -StringMapEntry *end(StringMap &m) { +gb_internal StringMapEntry *end(StringMap &m) { return m.entries.data + m.entries.count; } template -StringMapEntry const *end(StringMap const &m) { +gb_internal StringMapEntry const *end(StringMap const &m) { return m.entries.data + m.entries.count; } \ No newline at end of file diff --git a/src/thread_pool.cpp b/src/thread_pool.cpp index 727cdcdda..1b3e74fbe 100644 --- a/src/thread_pool.cpp +++ b/src/thread_pool.cpp @@ -23,9 +23,9 @@ struct ThreadPool { }; -THREAD_PROC(thread_pool_thread_proc); +gb_internal THREAD_PROC(thread_pool_thread_proc); -void thread_pool_init(ThreadPool *pool, gbAllocator const &a, isize thread_count, char const *worker_name) { +gb_internal void thread_pool_init(ThreadPool *pool, gbAllocator const &a, isize thread_count, char const *worker_name) { pool->allocator = a; pool->stop = false; mutex_init(&pool->mutex); @@ -43,7 +43,7 @@ void thread_pool_init(ThreadPool *pool, gbAllocator const &a, isize thread_count } } -void thread_pool_destroy(ThreadPool *pool) { +gb_internal void thread_pool_destroy(ThreadPool *pool) { mutex_lock(&pool->mutex); pool->stop = true; condition_broadcast(&pool->task_cond); @@ -64,23 +64,23 @@ void thread_pool_destroy(ThreadPool *pool) { condition_destroy(&pool->task_cond); } -bool thread_pool_queue_empty(ThreadPool *pool) { +gb_internal bool thread_pool_queue_empty(ThreadPool *pool) { return pool->task_queue == nullptr; } -WorkerTask *thread_pool_queue_pop(ThreadPool *pool) { +gb_internal WorkerTask *thread_pool_queue_pop(ThreadPool *pool) { GB_ASSERT(pool->task_queue != nullptr); WorkerTask *task = pool->task_queue; pool->task_queue = task->next; return task; } -void thread_pool_queue_push(ThreadPool *pool, WorkerTask *task) { +gb_internal void thread_pool_queue_push(ThreadPool *pool, WorkerTask *task) { GB_ASSERT(task != nullptr); task->next = pool->task_queue; pool->task_queue = task; } -bool thread_pool_add_task(ThreadPool *pool, WorkerTaskProc *proc, void *data) { +gb_internal bool thread_pool_add_task(ThreadPool *pool, WorkerTaskProc *proc, void *data) { GB_ASSERT(proc != nullptr); mutex_lock(&pool->mutex); WorkerTask *task = gb_alloc_item(permanent_allocator(), WorkerTask); @@ -101,11 +101,11 @@ bool thread_pool_add_task(ThreadPool *pool, WorkerTaskProc *proc, void *data) { } -void thread_pool_do_task(WorkerTask *task) { +gb_internal void thread_pool_do_task(WorkerTask *task) { task->do_work(task->data); } -void thread_pool_wait(ThreadPool *pool) { +gb_internal void thread_pool_wait(ThreadPool *pool) { if (pool->threads.count == 0) { while (!thread_pool_queue_empty(pool)) { thread_pool_do_task(thread_pool_queue_pop(pool)); @@ -138,7 +138,7 @@ void thread_pool_wait(ThreadPool *pool) { } -THREAD_PROC(thread_pool_thread_proc) { +gb_internal THREAD_PROC(thread_pool_thread_proc) { ThreadPool *pool = cast(ThreadPool *)thread->user_data; for (;;) { diff --git a/src/threading.cpp b/src/threading.cpp index 63e3415b2..511d1b477 100644 --- a/src/threading.cpp +++ b/src/threading.cpp @@ -29,43 +29,43 @@ struct Thread { }; -void mutex_init (BlockingMutex *m); -void mutex_destroy (BlockingMutex *m); -void mutex_lock (BlockingMutex *m); -bool mutex_try_lock(BlockingMutex *m); -void mutex_unlock (BlockingMutex *m); -void mutex_init (RecursiveMutex *m); -void mutex_destroy (RecursiveMutex *m); -void mutex_lock (RecursiveMutex *m); -bool mutex_try_lock(RecursiveMutex *m); -void mutex_unlock (RecursiveMutex *m); - -void semaphore_init (Semaphore *s); -void semaphore_destroy(Semaphore *s); -void semaphore_post (Semaphore *s, i32 count); -void semaphore_wait (Semaphore *s); -void semaphore_release(Semaphore *s) { semaphore_post(s, 1); } - - -void condition_init(Condition *c); -void condition_destroy(Condition *c); -void condition_broadcast(Condition *c); -void condition_signal(Condition *c); -void condition_wait(Condition *c, BlockingMutex *m); -void condition_wait_with_timeout(Condition *c, BlockingMutex *m, u32 timeout_in_ms); - -u32 thread_current_id(void); - -void thread_init (Thread *t); -void thread_destroy (Thread *t); -void thread_start (Thread *t, ThreadProc *proc, void *data); -void thread_start_with_stack(Thread *t, ThreadProc *proc, void *data, isize stack_size); -void thread_join (Thread *t); -bool thread_is_running (Thread const *t); -void thread_set_name (Thread *t, char const *name); - -void yield_thread(void); -void yield_process(void); +gb_internal void mutex_init (BlockingMutex *m); +gb_internal void mutex_destroy (BlockingMutex *m); +gb_internal void mutex_lock (BlockingMutex *m); +gb_internal bool mutex_try_lock(BlockingMutex *m); +gb_internal void mutex_unlock (BlockingMutex *m); +gb_internal void mutex_init (RecursiveMutex *m); +gb_internal void mutex_destroy (RecursiveMutex *m); +gb_internal void mutex_lock (RecursiveMutex *m); +gb_internal bool mutex_try_lock(RecursiveMutex *m); +gb_internal void mutex_unlock (RecursiveMutex *m); + +gb_internal void semaphore_init (Semaphore *s); +gb_internal void semaphore_destroy(Semaphore *s); +gb_internal void semaphore_post (Semaphore *s, i32 count); +gb_internal void semaphore_wait (Semaphore *s); +gb_internal void semaphore_release(Semaphore *s) { semaphore_post(s, 1); } + + +gb_internal void condition_init(Condition *c); +gb_internal void condition_destroy(Condition *c); +gb_internal void condition_broadcast(Condition *c); +gb_internal void condition_signal(Condition *c); +gb_internal void condition_wait(Condition *c, BlockingMutex *m); +gb_internal void condition_wait_with_timeout(Condition *c, BlockingMutex *m, u32 timeout_in_ms); + +gb_internal u32 thread_current_id(void); + +gb_internal void thread_init (Thread *t); +gb_internal void thread_destroy (Thread *t); +gb_internal void thread_start (Thread *t, ThreadProc *proc, void *data); +gb_internal void thread_start_with_stack(Thread *t, ThreadProc *proc, void *data, isize stack_size); +gb_internal void thread_join (Thread *t); +gb_internal bool thread_is_running (Thread const *t); +gb_internal void thread_set_name (Thread *t, char const *name); + +gb_internal void yield_thread(void); +gb_internal void yield_process(void); struct MutexGuard { @@ -106,36 +106,36 @@ struct MutexGuard { struct BlockingMutex { SRWLOCK srwlock; }; - void mutex_init(BlockingMutex *m) { + gb_internal void mutex_init(BlockingMutex *m) { } - void mutex_destroy(BlockingMutex *m) { + gb_internal void mutex_destroy(BlockingMutex *m) { } - void mutex_lock(BlockingMutex *m) { + gb_internal void mutex_lock(BlockingMutex *m) { AcquireSRWLockExclusive(&m->srwlock); } - bool mutex_try_lock(BlockingMutex *m) { + gb_internal bool mutex_try_lock(BlockingMutex *m) { return !!TryAcquireSRWLockExclusive(&m->srwlock); } - void mutex_unlock(BlockingMutex *m) { + gb_internal void mutex_unlock(BlockingMutex *m) { ReleaseSRWLockExclusive(&m->srwlock); } struct RecursiveMutex { CRITICAL_SECTION win32_critical_section; }; - void mutex_init(RecursiveMutex *m) { + gb_internal void mutex_init(RecursiveMutex *m) { InitializeCriticalSection(&m->win32_critical_section); } - void mutex_destroy(RecursiveMutex *m) { + gb_internal void mutex_destroy(RecursiveMutex *m) { DeleteCriticalSection(&m->win32_critical_section); } - void mutex_lock(RecursiveMutex *m) { + gb_internal void mutex_lock(RecursiveMutex *m) { EnterCriticalSection(&m->win32_critical_section); } - bool mutex_try_lock(RecursiveMutex *m) { + gb_internal bool mutex_try_lock(RecursiveMutex *m) { return TryEnterCriticalSection(&m->win32_critical_section) != 0; } - void mutex_unlock(RecursiveMutex *m) { + gb_internal void mutex_unlock(RecursiveMutex *m) { LeaveCriticalSection(&m->win32_critical_section); } @@ -143,16 +143,16 @@ struct MutexGuard { void *win32_handle; }; - void semaphore_init(Semaphore *s) { + gb_internal void semaphore_init(Semaphore *s) { s->win32_handle = CreateSemaphoreA(NULL, 0, I32_MAX, NULL); } - void semaphore_destroy(Semaphore *s) { + gb_internal void semaphore_destroy(Semaphore *s) { CloseHandle(s->win32_handle); } - void semaphore_post(Semaphore *s, i32 count) { + gb_internal void semaphore_post(Semaphore *s, i32 count) { ReleaseSemaphore(s->win32_handle, count, NULL); } - void semaphore_wait(Semaphore *s) { + gb_internal void semaphore_wait(Semaphore *s) { WaitForSingleObjectEx(s->win32_handle, INFINITE, FALSE); } @@ -160,20 +160,20 @@ struct MutexGuard { CONDITION_VARIABLE cond; }; - void condition_init(Condition *c) { + gb_internal void condition_init(Condition *c) { } - void condition_destroy(Condition *c) { + gb_internal void condition_destroy(Condition *c) { } - void condition_broadcast(Condition *c) { + gb_internal void condition_broadcast(Condition *c) { WakeAllConditionVariable(&c->cond); } - void condition_signal(Condition *c) { + gb_internal void condition_signal(Condition *c) { WakeConditionVariable(&c->cond); } - void condition_wait(Condition *c, BlockingMutex *m) { + gb_internal void condition_wait(Condition *c, BlockingMutex *m) { SleepConditionVariableSRW(&c->cond, &m->srwlock, INFINITE, 0); } - void condition_wait_with_timeout(Condition *c, BlockingMutex *m, u32 timeout_in_ms) { + gb_internal void condition_wait_with_timeout(Condition *c, BlockingMutex *m, u32 timeout_in_ms) { SleepConditionVariableSRW(&c->cond, &m->srwlock, timeout_in_ms, 0); } @@ -181,19 +181,19 @@ struct MutexGuard { struct BlockingMutex { pthread_mutex_t pthread_mutex; }; - void mutex_init(BlockingMutex *m) { + gb_internal void mutex_init(BlockingMutex *m) { pthread_mutex_init(&m->pthread_mutex, nullptr); } - void mutex_destroy(BlockingMutex *m) { + gb_internal void mutex_destroy(BlockingMutex *m) { pthread_mutex_destroy(&m->pthread_mutex); } - void mutex_lock(BlockingMutex *m) { + gb_internal void mutex_lock(BlockingMutex *m) { pthread_mutex_lock(&m->pthread_mutex); } - bool mutex_try_lock(BlockingMutex *m) { + gb_internal bool mutex_try_lock(BlockingMutex *m) { return pthread_mutex_trylock(&m->pthread_mutex) == 0; } - void mutex_unlock(BlockingMutex *m) { + gb_internal void mutex_unlock(BlockingMutex *m) { pthread_mutex_unlock(&m->pthread_mutex); } @@ -201,21 +201,21 @@ struct MutexGuard { pthread_mutex_t pthread_mutex; pthread_mutexattr_t pthread_mutexattr; }; - void mutex_init(RecursiveMutex *m) { + gb_internal void mutex_init(RecursiveMutex *m) { pthread_mutexattr_init(&m->pthread_mutexattr); pthread_mutexattr_settype(&m->pthread_mutexattr, PTHREAD_MUTEX_RECURSIVE); pthread_mutex_init(&m->pthread_mutex, &m->pthread_mutexattr); } - void mutex_destroy(RecursiveMutex *m) { + gb_internal void mutex_destroy(RecursiveMutex *m) { pthread_mutex_destroy(&m->pthread_mutex); } - void mutex_lock(RecursiveMutex *m) { + gb_internal void mutex_lock(RecursiveMutex *m) { pthread_mutex_lock(&m->pthread_mutex); } - bool mutex_try_lock(RecursiveMutex *m) { + gb_internal bool mutex_try_lock(RecursiveMutex *m) { return pthread_mutex_trylock(&m->pthread_mutex) == 0; } - void mutex_unlock(RecursiveMutex *m) { + gb_internal void mutex_unlock(RecursiveMutex *m) { pthread_mutex_unlock(&m->pthread_mutex); } @@ -224,18 +224,18 @@ struct MutexGuard { semaphore_t osx_handle; }; - void semaphore_init (Semaphore *s) { semaphore_create(mach_task_self(), &s->osx_handle, SYNC_POLICY_FIFO, 0); } - void semaphore_destroy(Semaphore *s) { semaphore_destroy(mach_task_self(), s->osx_handle); } - void semaphore_post (Semaphore *s, i32 count) { while (count --> 0) semaphore_signal(s->osx_handle); } - void semaphore_wait (Semaphore *s) { semaphore_wait(s->osx_handle); } + gb_internal void semaphore_init (Semaphore *s) { semaphore_create(mach_task_self(), &s->osx_handle, SYNC_POLICY_FIFO, 0); } + gb_internal void semaphore_destroy(Semaphore *s) { semaphore_destroy(mach_task_self(), s->osx_handle); } + gb_internal void semaphore_post (Semaphore *s, i32 count) { while (count --> 0) semaphore_signal(s->osx_handle); } + gb_internal void semaphore_wait (Semaphore *s) { semaphore_wait(s->osx_handle); } #elif defined(GB_SYSTEM_UNIX) struct Semaphore { sem_t unix_handle; }; - void semaphore_init (Semaphore *s) { sem_init(&s->unix_handle, 0, 0); } - void semaphore_destroy(Semaphore *s) { sem_destroy(&s->unix_handle); } - void semaphore_post (Semaphore *s, i32 count) { while (count --> 0) sem_post(&s->unix_handle); } + gb_internal void semaphore_init (Semaphore *s) { sem_init(&s->unix_handle, 0, 0); } + gb_internal void semaphore_destroy(Semaphore *s) { sem_destroy(&s->unix_handle); } + gb_internal void semaphore_post (Semaphore *s, i32 count) { while (count --> 0) sem_post(&s->unix_handle); } void semaphore_wait (Semaphore *s) { int i; do { i = sem_wait(&s->unix_handle); } while (i == -1 && errno == EINTR); } #else #error Implement Semaphore for this platform @@ -246,22 +246,22 @@ struct MutexGuard { pthread_cond_t pthread_cond; }; - void condition_init(Condition *c) { + gb_internal void condition_init(Condition *c) { pthread_cond_init(&c->pthread_cond, NULL); } - void condition_destroy(Condition *c) { + gb_internal void condition_destroy(Condition *c) { pthread_cond_destroy(&c->pthread_cond); } - void condition_broadcast(Condition *c) { + gb_internal void condition_broadcast(Condition *c) { pthread_cond_broadcast(&c->pthread_cond); } - void condition_signal(Condition *c) { + gb_internal void condition_signal(Condition *c) { pthread_cond_signal(&c->pthread_cond); } - void condition_wait(Condition *c, BlockingMutex *m) { + gb_internal void condition_wait(Condition *c, BlockingMutex *m) { pthread_cond_wait(&c->pthread_cond, &m->pthread_mutex); } - void condition_wait_with_timeout(Condition *c, BlockingMutex *m, u32 timeout_in_ms) { + gb_internal void condition_wait_with_timeout(Condition *c, BlockingMutex *m, u32 timeout_in_ms) { struct timespec abstime = {}; abstime.tv_sec = timeout_in_ms/1000; abstime.tv_nsec = cast(long)(timeout_in_ms%1000)*1e6; @@ -279,7 +279,7 @@ struct Barrier { isize thread_count; }; -void barrier_init(Barrier *b, isize thread_count) { +gb_internal void barrier_init(Barrier *b, isize thread_count) { mutex_init(&b->mutex); condition_init(&b->cond); b->index = 0; @@ -287,13 +287,13 @@ void barrier_init(Barrier *b, isize thread_count) { b->thread_count = 0; } -void barrier_destroy(Barrier *b) { +gb_internal void barrier_destroy(Barrier *b) { condition_destroy(&b->cond); mutex_destroy(&b->mutex); } // Returns true if it is the leader -bool barrier_wait(Barrier *b) { +gb_internal bool barrier_wait(Barrier *b) { mutex_lock(&b->mutex); defer (mutex_unlock(&b->mutex)); isize local_gen = b->generation_id; @@ -313,7 +313,7 @@ bool barrier_wait(Barrier *b) { -u32 thread_current_id(void) { +gb_internal u32 thread_current_id(void) { u32 thread_id; #if defined(GB_SYSTEM_WINDOWS) #if defined(GB_ARCH_32_BIT) && defined(GB_CPU_X86) @@ -340,7 +340,7 @@ u32 thread_current_id(void) { } -gb_inline void yield_thread(void) { +gb_internal gb_inline void yield_thread(void) { #if defined(GB_SYSTEM_WINDOWS) _mm_pause(); #elif defined(GB_SYSTEM_OSX) @@ -358,7 +358,7 @@ gb_inline void yield_thread(void) { #endif } -gb_inline void yield(void) { +gb_internal gb_inline void yield(void) { #if defined(GB_SYSTEM_WINDOWS) YieldProcessor(); #else @@ -367,7 +367,7 @@ gb_inline void yield(void) { } -void thread_init(Thread *t) { +gb_internal void thread_init(Thread *t) { gb_zero_item(t); #if defined(GB_SYSTEM_WINDOWS) t->win32_handle = INVALID_HANDLE_VALUE; @@ -378,27 +378,27 @@ void thread_init(Thread *t) { semaphore_init(t->semaphore); } -void thread_destroy(Thread *t) { +gb_internal void thread_destroy(Thread *t) { thread_join(t); semaphore_destroy(t->semaphore); gb_free(heap_allocator(), t->semaphore); } -void gb__thread_run(Thread *t) { +gb_internal void gb__thread_run(Thread *t) { semaphore_release(t->semaphore); t->return_value = t->proc(t); } #if defined(GB_SYSTEM_WINDOWS) - DWORD __stdcall internal_thread_proc(void *arg) { + gb_internal DWORD __stdcall internal_thread_proc(void *arg) { Thread *t = cast(Thread *)arg; t->is_running.store(true); gb__thread_run(t); return 0; } #else - void *internal_thread_proc(void *arg) { + gb_internal void *internal_thread_proc(void *arg) { #if (GB_SYSTEM_LINUX) // NOTE: Don't permit any signal delivery to threads on Linux. sigset_t mask = {}; @@ -413,9 +413,9 @@ void gb__thread_run(Thread *t) { } #endif -void thread_start(Thread *t, ThreadProc *proc, void *user_data) { thread_start_with_stack(t, proc, user_data, 0); } +gb_internal void thread_start(Thread *t, ThreadProc *proc, void *user_data) { thread_start_with_stack(t, proc, user_data, 0); } -void thread_start_with_stack(Thread *t, ThreadProc *proc, void *user_data, isize stack_size) { +gb_internal void thread_start_with_stack(Thread *t, ThreadProc *proc, void *user_data, isize stack_size) { GB_ASSERT(!t->is_running.load()); GB_ASSERT(proc != NULL); t->proc = proc; @@ -441,7 +441,7 @@ void thread_start_with_stack(Thread *t, ThreadProc *proc, void *user_data, isize semaphore_wait(t->semaphore); } -void thread_join(Thread *t) { +gb_internal void thread_join(Thread *t) { if (!t->is_running.load()) { return; } @@ -457,9 +457,9 @@ void thread_join(Thread *t) { t->is_running.store(false); } -bool thread_is_running(Thread const *t) { return t->is_running.load(); } +gb_internal bool thread_is_running(Thread const *t) { return t->is_running.load(); } -void thread_set_name(Thread *t, char const *name) { +gb_internal void thread_set_name(Thread *t, char const *name) { #if defined(GB_COMPILER_MSVC) #pragma pack(push, 8) typedef struct { diff --git a/src/timings.cpp b/src/timings.cpp index 72abe7ea1..baa8b80da 100644 --- a/src/timings.cpp +++ b/src/timings.cpp @@ -13,13 +13,13 @@ struct Timings { #if defined(GB_SYSTEM_WINDOWS) -u64 win32_time_stamp_time_now(void) { +gb_internal u64 win32_time_stamp_time_now(void) { LARGE_INTEGER counter; QueryPerformanceCounter(&counter); return counter.QuadPart; } -u64 win32_time_stamp__freq(void) { +gb_internal u64 win32_time_stamp__freq(void) { gb_local_persist LARGE_INTEGER win32_perf_count_freq = {0}; if (!win32_perf_count_freq.QuadPart) { QueryPerformanceFrequency(&win32_perf_count_freq); @@ -33,11 +33,11 @@ u64 win32_time_stamp__freq(void) { #include -u64 osx_time_stamp_time_now(void) { +gb_internal u64 osx_time_stamp_time_now(void) { return mach_absolute_time(); } -u64 osx_time_stamp__freq(void) { +gb_internal u64 osx_time_stamp__freq(void) { mach_timebase_info_data_t data; data.numer = 0; data.denom = 0; @@ -55,14 +55,14 @@ u64 osx_time_stamp__freq(void) { #include -u64 unix_time_stamp_time_now(void) { +gb_internal u64 unix_time_stamp_time_now(void) { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); return (ts.tv_sec * 1000000000) + ts.tv_nsec; } -u64 unix_time_stamp__freq(void) { +gb_internal u64 unix_time_stamp__freq(void) { gb_local_persist u64 freq = 0; if (freq == 0) { @@ -80,7 +80,7 @@ u64 unix_time_stamp__freq(void) { #error Implement system #endif -u64 time_stamp_time_now(void) { +gb_internal u64 time_stamp_time_now(void) { #if defined(GB_SYSTEM_WINDOWS) return win32_time_stamp_time_now(); #elif defined(GB_SYSTEM_OSX) @@ -92,7 +92,7 @@ u64 time_stamp_time_now(void) { #endif } -u64 time_stamp__freq(void) { +gb_internal u64 time_stamp__freq(void) { #if defined(GB_SYSTEM_WINDOWS) return win32_time_stamp__freq(); #elif defined(GB_SYSTEM_OSX) @@ -104,44 +104,44 @@ u64 time_stamp__freq(void) { #endif } -TimeStamp make_time_stamp(String const &label) { +gb_internal TimeStamp make_time_stamp(String const &label) { TimeStamp ts = {0}; ts.start = time_stamp_time_now(); ts.label = label; return ts; } -void timings_init(Timings *t, String const &label, isize buffer_size) { +gb_internal void timings_init(Timings *t, String const &label, isize buffer_size) { array_init(&t->sections, heap_allocator(), 0, buffer_size); t->total = make_time_stamp(label); t->freq = time_stamp__freq(); } -void timings_destroy(Timings *t) { +gb_internal void timings_destroy(Timings *t) { array_free(&t->sections); } -void timings__stop_current_section(Timings *t) { +gb_internal void timings__stop_current_section(Timings *t) { if (t->sections.count > 0) { t->sections[t->sections.count-1].finish = time_stamp_time_now(); } } -void timings_start_section(Timings *t, String const &label) { +gb_internal void timings_start_section(Timings *t, String const &label) { timings__stop_current_section(t); array_add(&t->sections, make_time_stamp(label)); } -f64 time_stamp_as_s(TimeStamp const &ts, u64 freq) { +gb_internal f64 time_stamp_as_s(TimeStamp const &ts, u64 freq) { GB_ASSERT_MSG(ts.finish >= ts.start, "time_stamp_as_ms - %.*s", LIT(ts.label)); return cast(f64)(ts.finish - ts.start) / cast(f64)freq; } -f64 time_stamp_as_ms(TimeStamp const &ts, u64 freq) { +gb_internal f64 time_stamp_as_ms(TimeStamp const &ts, u64 freq) { return 1000.0*time_stamp_as_s(ts, freq); } -f64 time_stamp_as_us(TimeStamp const &ts, u64 freq) { +gb_internal f64 time_stamp_as_us(TimeStamp const &ts, u64 freq) { return 1000000.0*time_stamp_as_s(ts, freq); } @@ -160,7 +160,7 @@ enum TimingUnit { char const *timing_unit_strings[TimingUnit_COUNT] = {"s", "ms", "us"}; -f64 time_stamp(TimeStamp const &ts, u64 freq, TimingUnit unit) { +gb_internal f64 time_stamp(TimeStamp const &ts, u64 freq, TimingUnit unit) { switch (unit) { case TimingUnit_Millisecond: return time_stamp_as_ms(ts, freq); case TimingUnit_Microsecond: return time_stamp_as_us(ts, freq); @@ -169,7 +169,7 @@ f64 time_stamp(TimeStamp const &ts, u64 freq, TimingUnit unit) { } } -void timings_print_all(Timings *t, TimingUnit unit = TimingUnit_Millisecond, bool timings_are_finalized = false) { +gb_internal void timings_print_all(Timings *t, TimingUnit unit = TimingUnit_Millisecond, bool timings_are_finalized = false) { isize const SPACES_LEN = 256; char SPACES[SPACES_LEN+1] = {0}; gb_memset(SPACES, ' ', SPACES_LEN); diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp index 40bc5c220..547a864fb 100644 --- a/src/tokenizer.cpp +++ b/src/tokenizer.cpp @@ -151,10 +151,10 @@ gb_global isize max_keyword_size = 11; gb_global bool keyword_indices[16] = {}; -gb_inline u32 keyword_hash(u8 const *text, isize len) { +gb_internal gb_inline u32 keyword_hash(u8 const *text, isize len) { return fnv32a(text, len); } -void add_keyword_hash_entry(String const &s, TokenKind kind) { +gb_internal void add_keyword_hash_entry(String const &s, TokenKind kind) { max_keyword_size = gb_max(max_keyword_size, s.len); keyword_indices[s.len] = true; @@ -169,7 +169,7 @@ void add_keyword_hash_entry(String const &s, TokenKind kind) { entry->kind = kind; entry->text = s; } -void init_keyword_hash_table(void) { +gb_internal void init_keyword_hash_table(void) { for (i32 kind = Token__KeywordBegin+1; kind < Token__KeywordEnd; kind++) { add_keyword_hash_entry(token_strings[kind], cast(TokenKind)kind); } @@ -191,8 +191,8 @@ void init_keyword_hash_table(void) { gb_global Array global_file_path_strings; // index is file id gb_global Array global_files; // index is file id -String get_file_path_string(i32 index); -struct AstFile *thread_safe_get_ast_file_from_id(i32 index); +gb_internal String get_file_path_string(i32 index); +gb_internal struct AstFile *thread_safe_get_ast_file_from_id(i32 index); struct TokenPos { i32 file_id; @@ -201,7 +201,7 @@ struct TokenPos { i32 column; // starting at 1 }; -i32 token_pos_cmp(TokenPos const &a, TokenPos const &b) { +gb_internal i32 token_pos_cmp(TokenPos const &a, TokenPos const &b) { if (a.offset != b.offset) { return (a.offset < b.offset) ? -1 : +1; } @@ -214,12 +214,12 @@ i32 token_pos_cmp(TokenPos const &a, TokenPos const &b) { return string_compare(get_file_path_string(a.file_id), get_file_path_string(b.file_id)); } -bool operator==(TokenPos const &a, TokenPos const &b) { return token_pos_cmp(a, b) == 0; } -bool operator!=(TokenPos const &a, TokenPos const &b) { return token_pos_cmp(a, b) != 0; } -bool operator< (TokenPos const &a, TokenPos const &b) { return token_pos_cmp(a, b) < 0; } -bool operator<=(TokenPos const &a, TokenPos const &b) { return token_pos_cmp(a, b) <= 0; } -bool operator> (TokenPos const &a, TokenPos const &b) { return token_pos_cmp(a, b) > 0; } -bool operator>=(TokenPos const &a, TokenPos const &b) { return token_pos_cmp(a, b) >= 0; } +gb_internal gb_inline bool operator==(TokenPos const &a, TokenPos const &b) { return token_pos_cmp(a, b) == 0; } +gb_internal gb_inline bool operator!=(TokenPos const &a, TokenPos const &b) { return token_pos_cmp(a, b) != 0; } +gb_internal gb_inline bool operator< (TokenPos const &a, TokenPos const &b) { return token_pos_cmp(a, b) < 0; } +gb_internal gb_inline bool operator<=(TokenPos const &a, TokenPos const &b) { return token_pos_cmp(a, b) <= 0; } +gb_internal gb_inline bool operator> (TokenPos const &a, TokenPos const &b) { return token_pos_cmp(a, b) > 0; } +gb_internal gb_inline bool operator>=(TokenPos const &a, TokenPos const &b) { return token_pos_cmp(a, b) >= 0; } TokenPos token_pos_add_column(TokenPos pos) { @@ -243,36 +243,36 @@ struct Token { Token empty_token = {Token_Invalid}; Token blank_token = {Token_Ident, 0, {cast(u8 *)"_", 1}}; -Token make_token_ident(String s) { +gb_internal Token make_token_ident(String s) { Token t = {Token_Ident, 0, s}; return t; } -Token make_token_ident(char const *s) { +gb_internal Token make_token_ident(char const *s) { Token t = {Token_Ident, 0, make_string_c(s)}; return t; } -bool token_is_newline(Token const &tok) { +gb_internal bool token_is_newline(Token const &tok) { return tok.kind == Token_Semicolon && tok.string == "\n"; } -gb_inline bool token_is_literal(TokenKind t) { +gb_internal gb_inline bool token_is_literal(TokenKind t) { return gb_is_between(t, Token__LiteralBegin+1, Token__LiteralEnd-1); } -gb_inline bool token_is_operator(TokenKind t) { +gb_internal gb_inline bool token_is_operator(TokenKind t) { return gb_is_between(t, Token__OperatorBegin+1, Token__OperatorEnd-1); } -gb_inline bool token_is_keyword(TokenKind t) { +gb_internal gb_inline bool token_is_keyword(TokenKind t) { return gb_is_between(t, Token__KeywordBegin+1, Token__KeywordEnd-1); } -gb_inline bool token_is_comparison(TokenKind t) { +gb_internal gb_inline bool token_is_comparison(TokenKind t) { return gb_is_between(t, Token__ComparisonBegin+1, Token__ComparisonEnd-1); } -gb_inline bool token_is_shift(TokenKind t) { +gb_internal gb_inline bool token_is_shift(TokenKind t) { return t == Token_Shl || t == Token_Shr; } -gb_inline void print_token(Token t) { gb_printf("%.*s\n", LIT(t.string)); } +gb_internal gb_inline void print_token(Token t) { gb_printf("%.*s\n", LIT(t.string)); } #include "error.cpp" @@ -309,7 +309,7 @@ struct Tokenizer { }; -void tokenizer_err(Tokenizer *t, char const *msg, ...) { +gb_internal void tokenizer_err(Tokenizer *t, char const *msg, ...) { va_list va; i32 column = t->column_minus_one+1; if (column < 1) { @@ -328,7 +328,7 @@ void tokenizer_err(Tokenizer *t, char const *msg, ...) { t->error_count++; } -void tokenizer_err(Tokenizer *t, TokenPos const &pos, char const *msg, ...) { +gb_internal void tokenizer_err(Tokenizer *t, TokenPos const &pos, char const *msg, ...) { va_list va; i32 column = t->column_minus_one+1; if (column < 1) { @@ -342,7 +342,7 @@ void tokenizer_err(Tokenizer *t, TokenPos const &pos, char const *msg, ...) { t->error_count++; } -void advance_to_next_rune(Tokenizer *t) { +gb_internal void advance_to_next_rune(Tokenizer *t) { if (t->curr_rune == '\n') { t->column_minus_one = -1; t->line_count++; @@ -372,7 +372,7 @@ void advance_to_next_rune(Tokenizer *t) { } } -void init_tokenizer_with_data(Tokenizer *t, String const &fullpath, void const *data, isize size) { +gb_internal void init_tokenizer_with_data(Tokenizer *t, String const &fullpath, void const *data, isize size) { t->fullpath = fullpath; t->line_count = 1; @@ -386,7 +386,7 @@ void init_tokenizer_with_data(Tokenizer *t, String const &fullpath, void const * } } -TokenizerInitError loaded_file_error_map_to_tokenizer[LoadedFile_COUNT] = { +gb_global TokenizerInitError loaded_file_error_map_to_tokenizer[LoadedFile_COUNT] = { TokenizerInit_None, /*LoadedFile_None*/ TokenizerInit_Empty, /*LoadedFile_Empty*/ TokenizerInit_FileTooLarge, /*LoadedFile_FileTooLarge*/ @@ -395,7 +395,7 @@ TokenizerInitError loaded_file_error_map_to_tokenizer[LoadedFile_COUNT] = { TokenizerInit_Permission, /*LoadedFile_Permission*/ }; -TokenizerInitError init_tokenizer_from_fullpath(Tokenizer *t, String const &fullpath, bool copy_file_contents) { +gb_internal TokenizerInitError init_tokenizer_from_fullpath(Tokenizer *t, String const &fullpath, bool copy_file_contents) { LoadedFileError file_err = load_file_32( alloc_cstring(temporary_allocator(), fullpath), &t->loaded_file, @@ -416,7 +416,7 @@ TokenizerInitError init_tokenizer_from_fullpath(Tokenizer *t, String const &full return err; } -gb_inline i32 digit_value(Rune r) { +gb_internal gb_inline i32 digit_value(Rune r) { switch (r) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': return r - '0'; @@ -428,20 +428,20 @@ gb_inline i32 digit_value(Rune r) { return 16; // NOTE(bill): Larger than highest possible } -gb_inline void scan_mantissa(Tokenizer *t, i32 base) { +gb_internal gb_inline void scan_mantissa(Tokenizer *t, i32 base) { while (digit_value(t->curr_rune) < base || t->curr_rune == '_') { advance_to_next_rune(t); } } -u8 peek_byte(Tokenizer *t, isize offset=0) { +gb_internal u8 peek_byte(Tokenizer *t, isize offset=0) { if (t->read_curr+offset < t->end) { return t->read_curr[offset]; } return 0; } -void scan_number_to_token(Tokenizer *t, Token *token, bool seen_decimal_point) { +gb_internal void scan_number_to_token(Tokenizer *t, Token *token, bool seen_decimal_point) { token->kind = Token_Integer; token->string = {t->curr, 1}; token->pos.file_id = t->curr_file_id; @@ -566,7 +566,7 @@ end: } -bool scan_escape(Tokenizer *t) { +gb_internal bool scan_escape(Tokenizer *t) { isize len = 0; u32 base = 0, max = 0, x = 0; @@ -633,13 +633,13 @@ bool scan_escape(Tokenizer *t) { } -gb_inline void tokenizer_skip_line(Tokenizer *t) { +gb_internal gb_inline void tokenizer_skip_line(Tokenizer *t) { while (t->curr_rune != '\n' && t->curr_rune != GB_RUNE_EOF) { advance_to_next_rune(t); } } -gb_inline void tokenizer_skip_whitespace(Tokenizer *t, bool on_newline) { +gb_internal gb_inline void tokenizer_skip_whitespace(Tokenizer *t, bool on_newline) { if (on_newline) { for (;;) { switch (t->curr_rune) { @@ -666,7 +666,7 @@ gb_inline void tokenizer_skip_whitespace(Tokenizer *t, bool on_newline) { } } -void tokenizer_get_token(Tokenizer *t, Token *token, int repeat=0) { +gb_internal void tokenizer_get_token(Tokenizer *t, Token *token, int repeat=0) { tokenizer_skip_whitespace(t, t->insert_semicolon); token->kind = Token_Invalid; diff --git a/src/types.cpp b/src/types.cpp index 9bdbf8d86..7b6942525 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -2571,20 +2571,6 @@ bool lookup_subtype_polymorphic_selection(Type *dst, Type *src, Selection *sel) - -Type *strip_type_aliasing(Type *x) { - if (x == nullptr) { - return x; - } - if (x->kind == Type_Named) { - Entity *e = x->Named.type_name; - if (e != nullptr && e->kind == Entity_TypeName && e->TypeName.is_type_alias) { - return x->Named.base; - } - } - return x; -} - bool are_types_identical_internal(Type *x, Type *y, bool check_tuple_names); bool are_types_identical(Type *x, Type *y) { @@ -2605,193 +2591,156 @@ bool are_types_identical_internal(Type *x, Type *y, bool check_tuple_names) { return false; } - x = strip_type_aliasing(x); - y = strip_type_aliasing(y); + if (x->kind == Type_Named) { + Entity *e = x->Named.type_name; + if (e != nullptr && e->kind == Entity_TypeName && e->TypeName.is_type_alias) { + x = x->Named.base; + } + } + if (y->kind == Type_Named) { + Entity *e = y->Named.type_name; + if (e != nullptr && e->kind == Entity_TypeName && e->TypeName.is_type_alias) { + y = y->Named.base; + } + } + if (x->kind != y->kind) { + return false; + } switch (x->kind) { case Type_Generic: - if (y->kind == Type_Generic) { - return are_types_identical(x->Generic.specialized, y->Generic.specialized); - } - break; + return are_types_identical(x->Generic.specialized, y->Generic.specialized); case Type_Basic: - if (y->kind == Type_Basic) { - return x->Basic.kind == y->Basic.kind; - } - break; + return x->Basic.kind == y->Basic.kind; case Type_EnumeratedArray: - if (y->kind == Type_EnumeratedArray) { - return are_types_identical(x->EnumeratedArray.index, y->EnumeratedArray.index) && - are_types_identical(x->EnumeratedArray.elem, y->EnumeratedArray.elem); - } - break; + return are_types_identical(x->EnumeratedArray.index, y->EnumeratedArray.index) && + are_types_identical(x->EnumeratedArray.elem, y->EnumeratedArray.elem); case Type_Array: - if (y->kind == Type_Array) { - return (x->Array.count == y->Array.count) && are_types_identical(x->Array.elem, y->Array.elem); - } - break; + return (x->Array.count == y->Array.count) && are_types_identical(x->Array.elem, y->Array.elem); case Type_Matrix: - if (y->kind == Type_Matrix) { - return x->Matrix.row_count == y->Matrix.row_count && - x->Matrix.column_count == y->Matrix.column_count && - are_types_identical(x->Matrix.elem, y->Matrix.elem); - } - break; + return x->Matrix.row_count == y->Matrix.row_count && + x->Matrix.column_count == y->Matrix.column_count && + are_types_identical(x->Matrix.elem, y->Matrix.elem); case Type_DynamicArray: - if (y->kind == Type_DynamicArray) { - return are_types_identical(x->DynamicArray.elem, y->DynamicArray.elem); - } - break; + return are_types_identical(x->DynamicArray.elem, y->DynamicArray.elem); case Type_Slice: - if (y->kind == Type_Slice) { - return are_types_identical(x->Slice.elem, y->Slice.elem); - } - break; + return are_types_identical(x->Slice.elem, y->Slice.elem); case Type_BitSet: - if (y->kind == Type_BitSet) { - return are_types_identical(x->BitSet.elem, y->BitSet.elem) && - are_types_identical(x->BitSet.underlying, y->BitSet.underlying) && - x->BitSet.lower == y->BitSet.lower && - x->BitSet.upper == y->BitSet.upper; - } - break; + return are_types_identical(x->BitSet.elem, y->BitSet.elem) && + are_types_identical(x->BitSet.underlying, y->BitSet.underlying) && + x->BitSet.lower == y->BitSet.lower && + x->BitSet.upper == y->BitSet.upper; case Type_Enum: return x == y; // NOTE(bill): All enums are unique case Type_Union: - if (y->kind == Type_Union) { - if (x->Union.variants.count == y->Union.variants.count && - x->Union.custom_align == y->Union.custom_align && - x->Union.kind == y->Union.kind) { - // NOTE(bill): zeroth variant is nullptr - for_array(i, x->Union.variants) { - if (!are_types_identical(x->Union.variants[i], y->Union.variants[i])) { - return false; - } + if (x->Union.variants.count == y->Union.variants.count && + x->Union.custom_align == y->Union.custom_align && + x->Union.kind == y->Union.kind) { + // NOTE(bill): zeroth variant is nullptr + for_array(i, x->Union.variants) { + if (!are_types_identical(x->Union.variants[i], y->Union.variants[i])) { + return false; } - return true; } + return true; } break; case Type_Struct: - if (y->kind == Type_Struct) { - if (x->Struct.is_raw_union == y->Struct.is_raw_union && - x->Struct.fields.count == y->Struct.fields.count && - x->Struct.is_packed == y->Struct.is_packed && - x->Struct.custom_align == y->Struct.custom_align && - x->Struct.soa_kind == y->Struct.soa_kind && - x->Struct.soa_count == y->Struct.soa_count && - are_types_identical(x->Struct.soa_elem, y->Struct.soa_elem)) { - // TODO(bill); Fix the custom alignment rule - for_array(i, x->Struct.fields) { - Entity *xf = x->Struct.fields[i]; - Entity *yf = y->Struct.fields[i]; - if (xf->kind != yf->kind) { - return false; - } - if (!are_types_identical(xf->type, yf->type)) { - return false; - } - if (xf->token.string != yf->token.string) { - return false; - } - if (x->Struct.tags[i] != y->Struct.tags[i]) { - return false; - } - u64 xf_flags = (xf->flags&EntityFlags_IsSubtype); - u64 yf_flags = (yf->flags&EntityFlags_IsSubtype); - if (xf_flags != yf_flags) { - return false; - } + if (x->Struct.is_raw_union == y->Struct.is_raw_union && + x->Struct.fields.count == y->Struct.fields.count && + x->Struct.is_packed == y->Struct.is_packed && + x->Struct.custom_align == y->Struct.custom_align && + x->Struct.soa_kind == y->Struct.soa_kind && + x->Struct.soa_count == y->Struct.soa_count && + are_types_identical(x->Struct.soa_elem, y->Struct.soa_elem)) { + // TODO(bill); Fix the custom alignment rule + for_array(i, x->Struct.fields) { + Entity *xf = x->Struct.fields[i]; + Entity *yf = y->Struct.fields[i]; + if (xf->kind != yf->kind) { + return false; + } + if (!are_types_identical(xf->type, yf->type)) { + return false; + } + if (xf->token.string != yf->token.string) { + return false; + } + if (x->Struct.tags[i] != y->Struct.tags[i]) { + return false; + } + u64 xf_flags = (xf->flags&EntityFlags_IsSubtype); + u64 yf_flags = (yf->flags&EntityFlags_IsSubtype); + if (xf_flags != yf_flags) { + return false; } - return true; } + return true; } break; case Type_Pointer: - if (y->kind == Type_Pointer) { - return are_types_identical(x->Pointer.elem, y->Pointer.elem); - } - break; + return are_types_identical(x->Pointer.elem, y->Pointer.elem); case Type_MultiPointer: - if (y->kind == Type_MultiPointer) { - return are_types_identical(x->MultiPointer.elem, y->MultiPointer.elem); - } - break; + return are_types_identical(x->MultiPointer.elem, y->MultiPointer.elem); case Type_SoaPointer: - if (y->kind == Type_SoaPointer) { - return are_types_identical(x->SoaPointer.elem, y->SoaPointer.elem); - } - break; + return are_types_identical(x->SoaPointer.elem, y->SoaPointer.elem); case Type_Named: - if (y->kind == Type_Named) { - return x->Named.type_name == y->Named.type_name; - } - break; + return x->Named.type_name == y->Named.type_name; case Type_Tuple: - if (y->kind == Type_Tuple) { - if (x->Tuple.variables.count == y->Tuple.variables.count && - x->Tuple.is_packed == y->Tuple.is_packed) { - for_array(i, x->Tuple.variables) { - Entity *xe = x->Tuple.variables[i]; - Entity *ye = y->Tuple.variables[i]; - if (xe->kind != ye->kind || !are_types_identical(xe->type, ye->type)) { - return false; - } - if (check_tuple_names) { - if (xe->token.string != ye->token.string) { - return false; - } - } - if (xe->kind == Entity_Constant && !compare_exact_values(Token_CmpEq, xe->Constant.value, ye->Constant.value)) { - // NOTE(bill): This is needed for polymorphic procedures + if (x->Tuple.variables.count == y->Tuple.variables.count && + x->Tuple.is_packed == y->Tuple.is_packed) { + for_array(i, x->Tuple.variables) { + Entity *xe = x->Tuple.variables[i]; + Entity *ye = y->Tuple.variables[i]; + if (xe->kind != ye->kind || !are_types_identical(xe->type, ye->type)) { + return false; + } + if (check_tuple_names) { + if (xe->token.string != ye->token.string) { return false; } } - return true; + if (xe->kind == Entity_Constant && !compare_exact_values(Token_CmpEq, xe->Constant.value, ye->Constant.value)) { + // NOTE(bill): This is needed for polymorphic procedures + return false; + } } + return true; } break; case Type_Proc: - if (y->kind == Type_Proc) { - return x->Proc.calling_convention == y->Proc.calling_convention && - x->Proc.c_vararg == y->Proc.c_vararg && - x->Proc.variadic == y->Proc.variadic && - x->Proc.diverging == y->Proc.diverging && - x->Proc.optional_ok == y->Proc.optional_ok && - are_types_identical(x->Proc.params, y->Proc.params) && - are_types_identical(x->Proc.results, y->Proc.results); - } - break; + return x->Proc.calling_convention == y->Proc.calling_convention && + x->Proc.c_vararg == y->Proc.c_vararg && + x->Proc.variadic == y->Proc.variadic && + x->Proc.diverging == y->Proc.diverging && + x->Proc.optional_ok == y->Proc.optional_ok && + are_types_identical(x->Proc.params, y->Proc.params) && + are_types_identical(x->Proc.results, y->Proc.results); case Type_Map: - if (y->kind == Type_Map) { - return are_types_identical(x->Map.key, y->Map.key) && - are_types_identical(x->Map.value, y->Map.value); - } - break; + return are_types_identical(x->Map.key, y->Map.key) && + are_types_identical(x->Map.value, y->Map.value); case Type_SimdVector: - if (y->kind == Type_SimdVector) { - if (x->SimdVector.count == y->SimdVector.count) { - return are_types_identical(x->SimdVector.elem, y->SimdVector.elem); - } + if (x->SimdVector.count == y->SimdVector.count) { + return are_types_identical(x->SimdVector.elem, y->SimdVector.elem); } break; } diff --git a/src/unicode.cpp b/src/unicode.cpp index e33fb793b..c244a323c 100644 --- a/src/unicode.cpp +++ b/src/unicode.cpp @@ -7,7 +7,7 @@ extern "C" { #pragma warning(pop) -bool rune_is_letter(Rune r) { +gb_internal bool rune_is_letter(Rune r) { if (r < 0x80) { if (r == '_') { return true; @@ -25,14 +25,14 @@ bool rune_is_letter(Rune r) { return false; } -bool rune_is_digit(Rune r) { +gb_internal bool rune_is_digit(Rune r) { if (r < 0x80) { return (cast(u32)r - '0') < 10; } return utf8proc_category(r) == UTF8PROC_CATEGORY_ND; } -bool rune_is_letter_or_digit(Rune r) { +gb_internal bool rune_is_letter_or_digit(Rune r) { if (r < 0x80) { if (r == '_') { return true; @@ -55,7 +55,7 @@ bool rune_is_letter_or_digit(Rune r) { return false; } -bool rune_is_whitespace(Rune r) { +gb_internal bool rune_is_whitespace(Rune r) { switch (r) { case ' ': case '\t': @@ -99,7 +99,7 @@ gb_global Utf8AcceptRange const global__utf8_accept_ranges[] = { }; -isize utf8_decode(u8 const *str, isize str_len, Rune *codepoint_out) { +gb_internal isize utf8_decode(u8 const *str, isize str_len, Rune *codepoint_out) { isize width = 0; Rune codepoint = GB_RUNE_INVALID; -- cgit v1.2.3 From 056ba1ed13b36c8a85d7415f5a288a4780cb55f8 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 18 Dec 2022 21:24:45 +0000 Subject: Even more `gb_internal` everywhere --- src/checker.hpp | 84 +++++------ src/entity.cpp | 52 +++---- src/exact_value.cpp | 8 +- src/types.cpp | 428 ++++++++++++++++++++++++++-------------------------- 4 files changed, 286 insertions(+), 286 deletions(-) (limited to 'src') diff --git a/src/checker.hpp b/src/checker.hpp index 37232ea95..e1efd5b89 100644 --- a/src/checker.hpp +++ b/src/checker.hpp @@ -20,7 +20,7 @@ struct ExprInfo { ExactValue value; }; -gb_inline ExprInfo *make_expr_info(AddressingMode mode, Type *type, ExactValue const &value, bool is_lhs) { +gb_internal gb_inline ExprInfo *make_expr_info(AddressingMode mode, Type *type, ExactValue const &value, bool is_lhs) { ExprInfo *ei = gb_alloc_item(permanent_allocator(), ExprInfo); ei->mode = mode; ei->type = type; @@ -130,7 +130,7 @@ struct AttributeContext { String enable_target_feature; // will be enabled for the procedure only }; -AttributeContext make_attribute_context(String link_prefix) { +gb_internal gb_inline AttributeContext make_attribute_context(String link_prefix) { AttributeContext ac = {}; ac.link_prefix = link_prefix; return ac; @@ -139,7 +139,7 @@ AttributeContext make_attribute_context(String link_prefix) { #define DECL_ATTRIBUTE_PROC(_name) bool _name(CheckerContext *c, Ast *elem, String name, Ast *value, AttributeContext *ac) typedef DECL_ATTRIBUTE_PROC(DeclAttributeProc); -void check_decl_attributes(CheckerContext *c, Array const &attributes, DeclAttributeProc *proc, AttributeContext *ac); +gb_internal void check_decl_attributes(CheckerContext *c, Array const &attributes, DeclAttributeProc *proc, AttributeContext *ac); // DeclInfo is used to store information of certain declarations to allow for "any order" usage @@ -443,59 +443,59 @@ gb_global AstPackage *config_pkg = nullptr; // CheckerInfo API -TypeAndValue type_and_value_of_expr (Ast *expr); -Type * type_of_expr (Ast *expr); -Entity * implicit_entity_of_node(Ast *clause); -DeclInfo * decl_info_of_ident (Ast *ident); -DeclInfo * decl_info_of_entity (Entity * e); -AstFile * ast_file_of_filename (CheckerInfo *i, String filename); +gb_internal TypeAndValue type_and_value_of_expr (Ast *expr); +gb_internal Type * type_of_expr (Ast *expr); +gb_internal Entity * implicit_entity_of_node(Ast *clause); +gb_internal DeclInfo * decl_info_of_ident (Ast *ident); +gb_internal DeclInfo * decl_info_of_entity (Entity * e); +gb_internal AstFile * ast_file_of_filename (CheckerInfo *i, String filename); // IMPORTANT: Only to use once checking is done -isize type_info_index (CheckerInfo *i, Type *type, bool error_on_failure); +gb_internal isize type_info_index (CheckerInfo *i, Type *type, bool error_on_failure); // Will return nullptr if not found -Entity *entity_of_node(Ast *expr); +gb_internal Entity *entity_of_node(Ast *expr); -Entity *scope_lookup_current(Scope *s, String const &name); -Entity *scope_lookup (Scope *s, String const &name); -void scope_lookup_parent (Scope *s, String const &name, Scope **scope_, Entity **entity_); -Entity *scope_insert (Scope *s, Entity *entity, bool use_mutex=true); +gb_internal Entity *scope_lookup_current(Scope *s, String const &name); +gb_internal Entity *scope_lookup (Scope *s, String const &name); +gb_internal void scope_lookup_parent (Scope *s, String const &name, Scope **scope_, Entity **entity_); +gb_internal Entity *scope_insert (Scope *s, Entity *entity, bool use_mutex=true); -void add_type_and_value (CheckerInfo *i, Ast *expression, AddressingMode mode, Type *type, ExactValue value); -ExprInfo *check_get_expr_info (CheckerContext *c, Ast *expr); -void add_untyped (CheckerContext *c, Ast *expression, AddressingMode mode, Type *basic_type, ExactValue value); -void add_entity_use (CheckerContext *c, Ast *identifier, Entity *entity); -void add_implicit_entity (CheckerContext *c, Ast *node, Entity *e); -void add_entity_and_decl_info(CheckerContext *c, Ast *identifier, Entity *e, DeclInfo *d, bool is_exported=true); -void add_type_info_type (CheckerContext *c, Type *t); +gb_internal void add_type_and_value (CheckerInfo *i, Ast *expression, AddressingMode mode, Type *type, ExactValue value); +gb_internal ExprInfo *check_get_expr_info (CheckerContext *c, Ast *expr); +gb_internal void add_untyped (CheckerContext *c, Ast *expression, AddressingMode mode, Type *basic_type, ExactValue value); +gb_internal void add_entity_use (CheckerContext *c, Ast *identifier, Entity *entity); +gb_internal void add_implicit_entity (CheckerContext *c, Ast *node, Entity *e); +gb_internal void add_entity_and_decl_info(CheckerContext *c, Ast *identifier, Entity *e, DeclInfo *d, bool is_exported=true); +gb_internal void add_type_info_type (CheckerContext *c, Type *t); -void check_add_import_decl(CheckerContext *c, Ast *decl); -void check_add_foreign_import_decl(CheckerContext *c, Ast *decl); +gb_internal void check_add_import_decl(CheckerContext *c, Ast *decl); +gb_internal void check_add_foreign_import_decl(CheckerContext *c, Ast *decl); -void check_entity_decl(CheckerContext *c, Entity *e, DeclInfo *d, Type *named_type); -void check_const_decl(CheckerContext *c, Entity *e, Ast *type_expr, Ast *init_expr, Type *named_type); -void check_type_decl(CheckerContext *c, Entity *e, Ast *type_expr, Type *def); +gb_internal void check_entity_decl(CheckerContext *c, Entity *e, DeclInfo *d, Type *named_type); +gb_internal void check_const_decl(CheckerContext *c, Entity *e, Ast *type_expr, Ast *init_expr, Type *named_type); +gb_internal void check_type_decl(CheckerContext *c, Entity *e, Ast *type_expr, Type *def); -bool check_arity_match(CheckerContext *c, AstValueDecl *vd, bool is_global = false); -void check_collect_entities(CheckerContext *c, Slice const &nodes); -void check_collect_entities_from_when_stmt(CheckerContext *c, AstWhenStmt *ws); -void check_delayed_file_import_entity(CheckerContext *c, Ast *decl); +gb_internal bool check_arity_match(CheckerContext *c, AstValueDecl *vd, bool is_global = false); +gb_internal void check_collect_entities(CheckerContext *c, Slice const &nodes); +gb_internal void check_collect_entities_from_when_stmt(CheckerContext *c, AstWhenStmt *ws); +gb_internal void check_delayed_file_import_entity(CheckerContext *c, Ast *decl); -CheckerTypePath *new_checker_type_path(); -void destroy_checker_type_path(CheckerTypePath *tp); +gb_internal CheckerTypePath *new_checker_type_path(); +gb_internal void destroy_checker_type_path(CheckerTypePath *tp); -void check_type_path_push(CheckerContext *c, Entity *e); -Entity *check_type_path_pop (CheckerContext *c); +gb_internal void check_type_path_push(CheckerContext *c, Entity *e); +gb_internal Entity *check_type_path_pop (CheckerContext *c); -CheckerPolyPath *new_checker_poly_path(); -void destroy_checker_poly_path(CheckerPolyPath *); +gb_internal CheckerPolyPath *new_checker_poly_path(); +gb_internal void destroy_checker_poly_path(CheckerPolyPath *); -void check_poly_path_push(CheckerContext *c, Type *t); -Type *check_poly_path_pop (CheckerContext *c); +gb_internal void check_poly_path_push(CheckerContext *c, Type *t); +gb_internal Type *check_poly_path_pop (CheckerContext *c); -void init_core_context(Checker *c); -void init_mem_allocator(Checker *c); +gb_internal void init_core_context(Checker *c); +gb_internal void init_mem_allocator(Checker *c); -void add_untyped_expressions(CheckerInfo *cinfo, UntypedExprInfoMap *untyped); +gb_internal void add_untyped_expressions(CheckerInfo *cinfo, UntypedExprInfoMap *untyped); diff --git a/src/entity.cpp b/src/entity.cpp index 3d3712328..6a3a69950 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -26,7 +26,7 @@ enum EntityKind { Entity_Count, }; -String const entity_strings[] = { +gb_global String const entity_strings[] = { #define ENTITY_KIND(k) {cast(u8 *)#k, gb_size_of(#k)-1}, ENTITY_KINDS #undef ENTITY_KIND @@ -116,7 +116,7 @@ struct ParameterValue { }; }; -bool has_parameter_value(ParameterValue const ¶m_value) { +gb_internal gb_inline bool has_parameter_value(ParameterValue const ¶m_value) { if (param_value.kind != ParameterValue_Invalid) { return true; } @@ -151,7 +151,7 @@ struct TypeNameObjCMetadata { Array value_entries; }; -TypeNameObjCMetadata *create_type_name_obj_c_metadata() { +gb_internal TypeNameObjCMetadata *create_type_name_obj_c_metadata() { TypeNameObjCMetadata *md = gb_alloc_item(permanent_allocator(), TypeNameObjCMetadata); md->mutex = gb_alloc_item(permanent_allocator(), BlockingMutex); mutex_init(md->mutex); @@ -266,7 +266,7 @@ struct Entity { }; }; -bool is_entity_kind_exported(EntityKind kind, bool allow_builtin = false) { +gb_internal bool is_entity_kind_exported(EntityKind kind, bool allow_builtin = false) { switch (kind) { case Entity_Builtin: return allow_builtin; @@ -278,7 +278,7 @@ bool is_entity_kind_exported(EntityKind kind, bool allow_builtin = false) { return true; } -bool is_entity_exported(Entity *e, bool allow_builtin = false) { +gb_internal bool is_entity_exported(Entity *e, bool allow_builtin = false) { // TODO(bill): Determine the actual exportation rules for imports of entities GB_ASSERT(e != nullptr); if (!is_entity_kind_exported(e->kind, allow_builtin)) { @@ -300,7 +300,7 @@ bool is_entity_exported(Entity *e, bool allow_builtin = false) { return true; } -bool entity_has_deferred_procedure(Entity *e) { +gb_internal bool entity_has_deferred_procedure(Entity *e) { GB_ASSERT(e != nullptr); if (e->kind == Entity_Procedure) { return e->Procedure.deferred_procedure.entity != nullptr; @@ -311,7 +311,7 @@ bool entity_has_deferred_procedure(Entity *e) { gb_global std::atomic global_entity_id; -Entity *alloc_entity(EntityKind kind, Scope *scope, Token token, Type *type) { +gb_internal Entity *alloc_entity(EntityKind kind, Scope *scope, Token token, Type *type) { gbAllocator a = permanent_allocator(); Entity *entity = gb_alloc_item(a, Entity); entity->kind = kind; @@ -323,13 +323,13 @@ Entity *alloc_entity(EntityKind kind, Scope *scope, Token token, Type *type) { return entity; } -Entity *alloc_entity_variable(Scope *scope, Token token, Type *type, EntityState state = EntityState_Unresolved) { +gb_internal Entity *alloc_entity_variable(Scope *scope, Token token, Type *type, EntityState state = EntityState_Unresolved) { Entity *entity = alloc_entity(Entity_Variable, scope, token, type); entity->state = state; return entity; } -Entity *alloc_entity_using_variable(Entity *parent, Token token, Type *type, Ast *using_expr) { +gb_internal Entity *alloc_entity_using_variable(Entity *parent, Token token, Type *type, Ast *using_expr) { GB_ASSERT(parent != nullptr); token.pos = parent->token.pos; Entity *entity = alloc_entity(Entity_Variable, parent->scope, token, type); @@ -343,19 +343,19 @@ Entity *alloc_entity_using_variable(Entity *parent, Token token, Type *type, Ast } -Entity *alloc_entity_constant(Scope *scope, Token token, Type *type, ExactValue value) { +gb_internal Entity *alloc_entity_constant(Scope *scope, Token token, Type *type, ExactValue value) { Entity *entity = alloc_entity(Entity_Constant, scope, token, type); entity->Constant.value = value; return entity; } -Entity *alloc_entity_type_name(Scope *scope, Token token, Type *type, EntityState state = EntityState_Unresolved) { +gb_internal Entity *alloc_entity_type_name(Scope *scope, Token token, Type *type, EntityState state = EntityState_Unresolved) { Entity *entity = alloc_entity(Entity_TypeName, scope, token, type); entity->state = state; return entity; } -Entity *alloc_entity_param(Scope *scope, Token token, Type *type, bool is_using, bool is_value) { +gb_internal Entity *alloc_entity_param(Scope *scope, Token token, Type *type, bool is_using, bool is_value) { Entity *entity = alloc_entity_variable(scope, token, type); entity->flags |= EntityFlag_Used; entity->flags |= EntityFlag_Param; @@ -366,7 +366,7 @@ Entity *alloc_entity_param(Scope *scope, Token token, Type *type, bool is_using, } -Entity *alloc_entity_const_param(Scope *scope, Token token, Type *type, ExactValue value, bool poly_const) { +gb_internal Entity *alloc_entity_const_param(Scope *scope, Token token, Type *type, ExactValue value, bool poly_const) { Entity *entity = alloc_entity_constant(scope, token, type, value); entity->flags |= EntityFlag_Used; if (poly_const) entity->flags |= EntityFlag_PolyConst; @@ -375,7 +375,7 @@ Entity *alloc_entity_const_param(Scope *scope, Token token, Type *type, ExactVal } -Entity *alloc_entity_field(Scope *scope, Token token, Type *type, bool is_using, i32 field_index, EntityState state = EntityState_Unresolved) { +gb_internal Entity *alloc_entity_field(Scope *scope, Token token, Type *type, bool is_using, i32 field_index, EntityState state = EntityState_Unresolved) { Entity *entity = alloc_entity_variable(scope, token, type); entity->Variable.field_index = field_index; if (is_using) entity->flags |= EntityFlag_Using; @@ -384,7 +384,7 @@ Entity *alloc_entity_field(Scope *scope, Token token, Type *type, bool is_using, return entity; } -Entity *alloc_entity_array_elem(Scope *scope, Token token, Type *type, i32 field_index) { +gb_internal Entity *alloc_entity_array_elem(Scope *scope, Token token, Type *type, i32 field_index) { Entity *entity = alloc_entity_variable(scope, token, type); entity->Variable.field_index = field_index; entity->flags |= EntityFlag_Field; @@ -393,26 +393,26 @@ Entity *alloc_entity_array_elem(Scope *scope, Token token, Type *type, i32 field return entity; } -Entity *alloc_entity_procedure(Scope *scope, Token token, Type *signature_type, u64 tags) { +gb_internal Entity *alloc_entity_procedure(Scope *scope, Token token, Type *signature_type, u64 tags) { Entity *entity = alloc_entity(Entity_Procedure, scope, token, signature_type); entity->Procedure.tags = tags; return entity; } -Entity *alloc_entity_proc_group(Scope *scope, Token token, Type *type) { +gb_internal Entity *alloc_entity_proc_group(Scope *scope, Token token, Type *type) { Entity *entity = alloc_entity(Entity_ProcGroup, scope, token, type); return entity; } -Entity *alloc_entity_builtin(Scope *scope, Token token, Type *type, i32 id) { +gb_internal Entity *alloc_entity_builtin(Scope *scope, Token token, Type *type, i32 id) { Entity *entity = alloc_entity(Entity_Builtin, scope, token, type); entity->Builtin.id = id; entity->state = EntityState_Resolved; return entity; } -Entity *alloc_entity_import_name(Scope *scope, Token token, Type *type, +gb_internal Entity *alloc_entity_import_name(Scope *scope, Token token, Type *type, String path, String name, Scope *import_scope) { Entity *entity = alloc_entity(Entity_ImportName, scope, token, type); entity->ImportName.path = path; @@ -422,7 +422,7 @@ Entity *alloc_entity_import_name(Scope *scope, Token token, Type *type, return entity; } -Entity *alloc_entity_library_name(Scope *scope, Token token, Type *type, +gb_internal Entity *alloc_entity_library_name(Scope *scope, Token token, Type *type, Slice paths, String name) { Entity *entity = alloc_entity(Entity_LibraryName, scope, token, type); entity->LibraryName.paths = paths; @@ -435,12 +435,12 @@ Entity *alloc_entity_library_name(Scope *scope, Token token, Type *type, -Entity *alloc_entity_nil(String name, Type *type) { +gb_internal Entity *alloc_entity_nil(String name, Type *type) { Entity *entity = alloc_entity(Entity_Nil, nullptr, make_token_ident(name), type); return entity; } -Entity *alloc_entity_label(Scope *scope, Token token, Type *type, Ast *node, Ast *parent) { +gb_internal Entity *alloc_entity_label(Scope *scope, Token token, Type *type, Ast *node, Ast *parent) { Entity *entity = alloc_entity(Entity_Label, scope, token, type); entity->Label.node = node; entity->Label.parent = parent; @@ -448,15 +448,15 @@ Entity *alloc_entity_label(Scope *scope, Token token, Type *type, Ast *node, Ast return entity; } -Entity *alloc_entity_dummy_variable(Scope *scope, Token token) { +gb_internal Entity *alloc_entity_dummy_variable(Scope *scope, Token token) { token.string = str_lit("_"); return alloc_entity_variable(scope, token, nullptr); } -Entity *entity_from_expr(Ast *expr); +gb_internal Entity *entity_from_expr(Ast *expr); -Entity *strip_entity_wrapping(Entity *e) { +gb_internal Entity *strip_entity_wrapping(Entity *e) { if (e == nullptr) { return nullptr; } @@ -469,7 +469,7 @@ Entity *strip_entity_wrapping(Entity *e) { return e; } -Entity *strip_entity_wrapping(Ast *expr) { +gb_internal Entity *strip_entity_wrapping(Ast *expr) { Entity *e = entity_from_expr(expr); return strip_entity_wrapping(e); } diff --git a/src/exact_value.cpp b/src/exact_value.cpp index d3ea4be68..453909a15 100644 --- a/src/exact_value.cpp +++ b/src/exact_value.cpp @@ -6,7 +6,7 @@ struct Ast; struct HashKey; struct Type; struct Entity; -bool are_types_identical(Type *x, Type *y); +gb_internal bool are_types_identical(Type *x, Type *y); struct Complex128 { f64 real, imag; @@ -969,10 +969,10 @@ gb_internal bool compare_exact_values(TokenKind op, ExactValue x, ExactValue y) return false; } -Entity *strip_entity_wrapping(Ast *expr); -Entity *strip_entity_wrapping(Entity *e); +gb_internal Entity *strip_entity_wrapping(Ast *expr); +gb_internal Entity *strip_entity_wrapping(Entity *e); -gbString write_expr_to_string(gbString str, Ast *node, bool shorthand); +gb_internal gbString write_expr_to_string(gbString str, Ast *node, bool shorthand); gb_internal gbString write_exact_value_to_string(gbString str, ExactValue const &v, isize string_limit=36) { switch (v.kind) { diff --git a/src/types.cpp b/src/types.cpp index 7b6942525..2ab7374c2 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -287,7 +287,7 @@ enum TypeKind { Type_Count, }; -String const type_strings[] = { +gb_global String const type_strings[] = { {cast(u8 *)"Invalid", gb_size_of("Invalid")}, #define TYPE_KIND(k, ...) {cast(u8 *)#k, gb_size_of(#k)-1}, TYPE_KINDS @@ -368,10 +368,10 @@ enum : int { }; -bool is_type_comparable(Type *t); -bool is_type_simple_compare(Type *t); +gb_internal bool is_type_comparable(Type *t); +gb_internal bool is_type_simple_compare(Type *t); -u32 type_info_flags_of_type(Type *type) { +gb_internal u32 type_info_flags_of_type(Type *type) { if (type == nullptr) { return 0; } @@ -396,14 +396,14 @@ struct Selection { u8 swizzle_indices; // 2 bits per component, representing which swizzle index bool pseudo_field; }; -Selection empty_selection = {0}; +gb_global Selection const empty_selection = {0}; -Selection make_selection(Entity *entity, Array index, bool indirect) { +gb_internal Selection make_selection(Entity *entity, Array index, bool indirect) { Selection s = {entity, index, indirect}; return s; } -void selection_add_index(Selection *s, isize index) { +gb_internal void selection_add_index(Selection *s, isize index) { // IMPORTANT NOTE(bill): this requires a stretchy buffer/dynamic array so it requires some form // of heap allocation // TODO(bill): Find a way to use a backing buffer for initial use as the general case is probably .count<3 @@ -413,7 +413,7 @@ void selection_add_index(Selection *s, isize index) { array_add(&s->index, cast(i32)index); } -Selection selection_combine(Selection const &lhs, Selection const &rhs) { +gb_internal Selection selection_combine(Selection const &lhs, Selection const &rhs) { Selection new_sel = lhs; new_sel.indirect = lhs.indirect || rhs.indirect; new_sel.index = array_make(heap_allocator(), lhs.index.count+rhs.index.count); @@ -422,7 +422,7 @@ Selection selection_combine(Selection const &lhs, Selection const &rhs) { return new_sel; } -Selection sub_selection(Selection const &sel, isize offset) { +gb_internal Selection sub_selection(Selection const &sel, isize offset) { Selection res = {}; res.index.data = sel.index.data + offset; res.index.count = gb_max(sel.index.count - offset, 0); @@ -430,7 +430,7 @@ Selection sub_selection(Selection const &sel, isize offset) { return res; } -Selection sub_selection_with_length(Selection const &sel, isize offset, isize len) { +gb_internal Selection sub_selection_with_length(Selection const &sel, isize offset, isize len) { Selection res = {}; res.index.data = sel.index.data + offset; res.index.count = gb_max(len, gb_max(sel.index.count - offset, 0)); @@ -732,26 +732,26 @@ gb_global RecursiveMutex g_type_mutex; struct TypePath; -i64 type_size_of (Type *t); -i64 type_align_of (Type *t); -i64 type_offset_of (Type *t, i32 index); -gbString type_to_string (Type *type, bool shorthand=true); -gbString type_to_string (Type *type, gbAllocator allocator, bool shorthand=true); -i64 type_size_of_internal(Type *t, TypePath *path); -void init_map_internal_types(Type *type); -Type * bit_set_to_int(Type *t); -bool are_types_identical(Type *x, Type *y); +gb_internal i64 type_size_of (Type *t); +gb_internal i64 type_align_of (Type *t); +gb_internal i64 type_offset_of (Type *t, i32 index); +gb_internal gbString type_to_string (Type *type, bool shorthand=true); +gb_internal gbString type_to_string (Type *type, gbAllocator allocator, bool shorthand=true); +gb_internal i64 type_size_of_internal(Type *t, TypePath *path); +gb_internal void init_map_internal_types(Type *type); +gb_internal Type * bit_set_to_int(Type *t); +gb_internal bool are_types_identical(Type *x, Type *y); -bool is_type_pointer(Type *t); -bool is_type_soa_pointer(Type *t); -bool is_type_proc(Type *t); -bool is_type_slice(Type *t); -bool is_type_integer(Type *t); -bool type_set_offsets(Type *t); -Type *base_type(Type *t); +gb_internal bool is_type_pointer(Type *t); +gb_internal bool is_type_soa_pointer(Type *t); +gb_internal bool is_type_proc(Type *t); +gb_internal bool is_type_slice(Type *t); +gb_internal bool is_type_integer(Type *t); +gb_internal bool type_set_offsets(Type *t); +gb_internal Type *base_type(Type *t); -i64 type_size_of_internal(Type *t, TypePath *path); -i64 type_align_of_internal(Type *t, TypePath *path); +gb_internal i64 type_size_of_internal(Type *t, TypePath *path); +gb_internal i64 type_align_of_internal(Type *t, TypePath *path); // IMPORTANT TODO(bill): SHould this TypePath code be removed since type cycle checking is handled much earlier on? @@ -762,15 +762,15 @@ struct TypePath { }; -void type_path_init(TypePath *tp) { +gb_internal void type_path_init(TypePath *tp) { tp->path.allocator = heap_allocator(); } -void type_path_free(TypePath *tp) { +gb_internal void type_path_free(TypePath *tp) { array_free(&tp->path); } -void type_path_print_illegal_cycle(TypePath *tp, isize start_index) { +gb_internal void type_path_print_illegal_cycle(TypePath *tp, isize start_index) { GB_ASSERT(tp != nullptr); GB_ASSERT(start_index < tp->path.count); @@ -789,7 +789,7 @@ void type_path_print_illegal_cycle(TypePath *tp, isize start_index) { base_type(e->type)->failure = true; } -bool type_path_push(TypePath *tp, Type *t) { +gb_internal bool type_path_push(TypePath *tp, Type *t) { GB_ASSERT(tp != nullptr); if (t->kind != Type_Named) { return false; @@ -807,7 +807,7 @@ bool type_path_push(TypePath *tp, Type *t) { return true; } -void type_path_pop(TypePath *tp) { +gb_internal void type_path_pop(TypePath *tp) { if (tp != nullptr && tp->path.count > 0) { array_pop(&tp->path); } @@ -817,11 +817,11 @@ void type_path_pop(TypePath *tp) { #define FAILURE_SIZE 0 #define FAILURE_ALIGNMENT 0 -void init_type_mutex(void) { +gb_internal void init_type_mutex(void) { mutex_init(&g_type_mutex); } -bool type_ptr_set_exists(PtrSet *s, Type *t) { +gb_internal bool type_ptr_set_exists(PtrSet *s, Type *t) { if (ptr_set_exists(s, t)) { return true; } @@ -839,7 +839,7 @@ bool type_ptr_set_exists(PtrSet *s, Type *t) { return false; } -Type *base_type(Type *t) { +gb_internal Type *base_type(Type *t) { for (;;) { if (t == nullptr) { break; @@ -855,7 +855,7 @@ Type *base_type(Type *t) { return t; } -Type *base_enum_type(Type *t) { +gb_internal Type *base_enum_type(Type *t) { Type *bt = base_type(t); if (bt != nullptr && bt->kind == Type_Enum) { @@ -864,7 +864,7 @@ Type *base_enum_type(Type *t) { return t; } -Type *core_type(Type *t) { +gb_internal Type *core_type(Type *t) { for (;;) { if (t == nullptr) { break; @@ -886,14 +886,14 @@ Type *core_type(Type *t) { return t; } -void set_base_type(Type *t, Type *base) { +gb_internal void set_base_type(Type *t, Type *base) { if (t && t->kind == Type_Named) { t->Named.base = base; } } -Type *alloc_type(TypeKind kind) { +gb_internal Type *alloc_type(TypeKind kind) { // gbAllocator a = heap_allocator(); gbAllocator a = permanent_allocator(); Type *t = gb_alloc_item(a, Type); @@ -905,7 +905,7 @@ Type *alloc_type(TypeKind kind) { } -Type *alloc_type_generic(Scope *scope, i64 id, String name, Type *specialized) { +gb_internal Type *alloc_type_generic(Scope *scope, i64 id, String name, Type *specialized) { Type *t = alloc_type(Type_Generic); t->Generic.id = id; t->Generic.name = name; @@ -914,26 +914,26 @@ Type *alloc_type_generic(Scope *scope, i64 id, String name, Type *specialized) { return t; } -Type *alloc_type_pointer(Type *elem) { +gb_internal Type *alloc_type_pointer(Type *elem) { Type *t = alloc_type(Type_Pointer); t->Pointer.elem = elem; return t; } -Type *alloc_type_multi_pointer(Type *elem) { +gb_internal Type *alloc_type_multi_pointer(Type *elem) { Type *t = alloc_type(Type_MultiPointer); t->MultiPointer.elem = elem; return t; } -Type *alloc_type_soa_pointer(Type *elem) { +gb_internal Type *alloc_type_soa_pointer(Type *elem) { Type *t = alloc_type(Type_SoaPointer); t->SoaPointer.elem = elem; return t; } -Type *alloc_type_array(Type *elem, i64 count, Type *generic_count = nullptr) { +gb_internal Type *alloc_type_array(Type *elem, i64 count, Type *generic_count = nullptr) { if (generic_count != nullptr) { Type *t = alloc_type(Type_Array); t->Array.elem = elem; @@ -947,7 +947,7 @@ Type *alloc_type_array(Type *elem, i64 count, Type *generic_count = nullptr) { return t; } -Type *alloc_type_matrix(Type *elem, i64 row_count, i64 column_count, Type *generic_row_count = nullptr, Type *generic_column_count = nullptr) { +gb_internal Type *alloc_type_matrix(Type *elem, i64 row_count, i64 column_count, Type *generic_row_count = nullptr, Type *generic_column_count = nullptr) { if (generic_row_count != nullptr || generic_column_count != nullptr) { Type *t = alloc_type(Type_Matrix); t->Matrix.elem = elem; @@ -965,7 +965,7 @@ Type *alloc_type_matrix(Type *elem, i64 row_count, i64 column_count, Type *gener } -Type *alloc_type_enumerated_array(Type *elem, Type *index, ExactValue const *min_value, ExactValue const *max_value, TokenKind op) { +gb_internal Type *alloc_type_enumerated_array(Type *elem, Type *index, ExactValue const *min_value, ExactValue const *max_value, TokenKind op) { Type *t = alloc_type(Type_EnumeratedArray); t->EnumeratedArray.elem = elem; t->EnumeratedArray.index = index; @@ -980,37 +980,37 @@ Type *alloc_type_enumerated_array(Type *elem, Type *index, ExactValue const *min } -Type *alloc_type_slice(Type *elem) { +gb_internal Type *alloc_type_slice(Type *elem) { Type *t = alloc_type(Type_Slice); t->Array.elem = elem; return t; } -Type *alloc_type_dynamic_array(Type *elem) { +gb_internal Type *alloc_type_dynamic_array(Type *elem) { Type *t = alloc_type(Type_DynamicArray); t->DynamicArray.elem = elem; return t; } -Type *alloc_type_struct() { +gb_internal Type *alloc_type_struct() { Type *t = alloc_type(Type_Struct); return t; } -Type *alloc_type_union() { +gb_internal Type *alloc_type_union() { Type *t = alloc_type(Type_Union); return t; } -Type *alloc_type_enum() { +gb_internal Type *alloc_type_enum() { Type *t = alloc_type(Type_Enum); t->Enum.min_value = gb_alloc_item(permanent_allocator(), ExactValue); t->Enum.max_value = gb_alloc_item(permanent_allocator(), ExactValue); return t; } -Type *alloc_type_relative_pointer(Type *pointer_type, Type *base_integer) { +gb_internal Type *alloc_type_relative_pointer(Type *pointer_type, Type *base_integer) { GB_ASSERT(is_type_pointer(pointer_type)); GB_ASSERT(is_type_integer(base_integer)); Type *t = alloc_type(Type_RelativePointer); @@ -1019,7 +1019,7 @@ Type *alloc_type_relative_pointer(Type *pointer_type, Type *base_integer) { return t; } -Type *alloc_type_relative_slice(Type *slice_type, Type *base_integer) { +gb_internal Type *alloc_type_relative_slice(Type *slice_type, Type *base_integer) { GB_ASSERT(is_type_slice(slice_type)); GB_ASSERT(is_type_integer(base_integer)); Type *t = alloc_type(Type_RelativeSlice); @@ -1028,7 +1028,7 @@ Type *alloc_type_relative_slice(Type *slice_type, Type *base_integer) { return t; } -Type *alloc_type_named(String name, Type *base, Entity *type_name) { +gb_internal Type *alloc_type_named(String name, Type *base, Entity *type_name) { Type *t = alloc_type(Type_Named); t->Named.name = name; t->Named.base = base; @@ -1039,7 +1039,7 @@ Type *alloc_type_named(String name, Type *base, Entity *type_name) { return t; } -bool is_calling_convention_none(ProcCallingConvention calling_convention) { +gb_internal bool is_calling_convention_none(ProcCallingConvention calling_convention) { switch (calling_convention) { case ProcCC_None: case ProcCC_InlineAsm: @@ -1048,7 +1048,7 @@ bool is_calling_convention_none(ProcCallingConvention calling_convention) { return false; } -bool is_calling_convention_odin(ProcCallingConvention calling_convention) { +gb_internal bool is_calling_convention_odin(ProcCallingConvention calling_convention) { switch (calling_convention) { case ProcCC_Odin: case ProcCC_Contextless: @@ -1057,12 +1057,12 @@ bool is_calling_convention_odin(ProcCallingConvention calling_convention) { return false; } -Type *alloc_type_tuple() { +gb_internal Type *alloc_type_tuple() { Type *t = alloc_type(Type_Tuple); return t; } -Type *alloc_type_proc(Scope *scope, Type *params, isize param_count, Type *results, isize result_count, bool variadic, ProcCallingConvention calling_convention) { +gb_internal Type *alloc_type_proc(Scope *scope, Type *params, isize param_count, Type *results, isize result_count, bool variadic, ProcCallingConvention calling_convention) { Type *t = alloc_type(Type_Proc); if (variadic) { @@ -1087,9 +1087,9 @@ Type *alloc_type_proc(Scope *scope, Type *params, isize param_count, Type *resul return t; } -bool is_type_valid_for_keys(Type *t); +gb_internal bool is_type_valid_for_keys(Type *t); -Type *alloc_type_map(i64 count, Type *key, Type *value) { +gb_internal Type *alloc_type_map(i64 count, Type *key, Type *value) { if (key != nullptr) { GB_ASSERT(value != nullptr); } @@ -1099,14 +1099,14 @@ Type *alloc_type_map(i64 count, Type *key, Type *value) { return t; } -Type *alloc_type_bit_set() { +gb_internal Type *alloc_type_bit_set() { Type *t = alloc_type(Type_BitSet); return t; } -Type *alloc_type_simd_vector(i64 count, Type *elem, Type *generic_count=nullptr) { +gb_internal Type *alloc_type_simd_vector(i64 count, Type *elem, Type *generic_count=nullptr) { Type *t = alloc_type(Type_SimdVector); t->SimdVector.count = count; t->SimdVector.elem = elem; @@ -1119,7 +1119,7 @@ Type *alloc_type_simd_vector(i64 count, Type *elem, Type *generic_count=nullptr) //////////////////////////////////////////////////////////////// -Type *type_deref(Type *t, bool allow_multi_pointer=false) { +gb_internal Type *type_deref(Type *t, bool allow_multi_pointer=false) { if (t != nullptr) { Type *bt = base_type(t); if (bt == nullptr) { @@ -1146,13 +1146,13 @@ Type *type_deref(Type *t, bool allow_multi_pointer=false) { return t; } -bool is_type_named(Type *t) { +gb_internal bool is_type_named(Type *t) { if (t->kind == Type_Basic) { return true; } return t->kind == Type_Named; } -bool is_type_named_alias(Type *t) { +gb_internal bool is_type_named_alias(Type *t) { if (!is_type_named(t)) { return false; } @@ -1166,7 +1166,7 @@ bool is_type_named_alias(Type *t) { return e->TypeName.is_type_alias; } -bool is_type_boolean(Type *t) { +gb_internal bool is_type_boolean(Type *t) { // t = core_type(t); t = base_type(t); if (t->kind == Type_Basic) { @@ -1174,7 +1174,7 @@ bool is_type_boolean(Type *t) { } return false; } -bool is_type_integer(Type *t) { +gb_internal bool is_type_integer(Type *t) { // t = core_type(t); t = base_type(t); if (t->kind == Type_Basic) { @@ -1182,7 +1182,7 @@ bool is_type_integer(Type *t) { } return false; } -bool is_type_integer_like(Type *t) { +gb_internal bool is_type_integer_like(Type *t) { t = core_type(t); if (t->kind == Type_Basic) { return (t->Basic.flags & (BasicFlag_Integer|BasicFlag_Boolean)) != 0; @@ -1196,7 +1196,7 @@ bool is_type_integer_like(Type *t) { return false; } -bool is_type_unsigned(Type *t) { +gb_internal bool is_type_unsigned(Type *t) { t = base_type(t); // t = core_type(t); if (t->kind == Type_Basic) { @@ -1204,7 +1204,7 @@ bool is_type_unsigned(Type *t) { } return false; } -bool is_type_integer_128bit(Type *t) { +gb_internal bool is_type_integer_128bit(Type *t) { // t = core_type(t); t = base_type(t); if (t->kind == Type_Basic) { @@ -1212,7 +1212,7 @@ bool is_type_integer_128bit(Type *t) { } return false; } -bool is_type_rune(Type *t) { +gb_internal bool is_type_rune(Type *t) { // t = core_type(t); t = base_type(t); if (t->kind == Type_Basic) { @@ -1220,7 +1220,7 @@ bool is_type_rune(Type *t) { } return false; } -bool is_type_numeric(Type *t) { +gb_internal bool is_type_numeric(Type *t) { // t = core_type(t); t = base_type(t); if (t->kind == Type_Basic) { @@ -1234,21 +1234,21 @@ bool is_type_numeric(Type *t) { } return false; } -bool is_type_string(Type *t) { +gb_internal bool is_type_string(Type *t) { t = base_type(t); if (t->kind == Type_Basic) { return (t->Basic.flags & BasicFlag_String) != 0; } return false; } -bool is_type_cstring(Type *t) { +gb_internal bool is_type_cstring(Type *t) { t = base_type(t); if (t->kind == Type_Basic) { return t->Basic.kind == Basic_cstring; } return false; } -bool is_type_typed(Type *t) { +gb_internal bool is_type_typed(Type *t) { t = base_type(t); if (t == nullptr) { return false; @@ -1258,7 +1258,7 @@ bool is_type_typed(Type *t) { } return true; } -bool is_type_untyped(Type *t) { +gb_internal bool is_type_untyped(Type *t) { t = base_type(t); if (t == nullptr) { return false; @@ -1268,7 +1268,7 @@ bool is_type_untyped(Type *t) { } return false; } -bool is_type_ordered(Type *t) { +gb_internal bool is_type_ordered(Type *t) { t = core_type(t); switch (t->kind) { case Type_Basic: @@ -1280,7 +1280,7 @@ bool is_type_ordered(Type *t) { } return false; } -bool is_type_ordered_numeric(Type *t) { +gb_internal bool is_type_ordered_numeric(Type *t) { t = core_type(t); switch (t->kind) { case Type_Basic: @@ -1288,7 +1288,7 @@ bool is_type_ordered_numeric(Type *t) { } return false; } -bool is_type_constant_type(Type *t) { +gb_internal bool is_type_constant_type(Type *t) { t = core_type(t); if (t->kind == Type_Basic) { return (t->Basic.flags & BasicFlag_ConstantType) != 0; @@ -1301,110 +1301,110 @@ bool is_type_constant_type(Type *t) { } return false; } -bool is_type_float(Type *t) { +gb_internal bool is_type_float(Type *t) { t = core_type(t); if (t->kind == Type_Basic) { return (t->Basic.flags & BasicFlag_Float) != 0; } return false; } -bool is_type_complex(Type *t) { +gb_internal bool is_type_complex(Type *t) { t = core_type(t); if (t->kind == Type_Basic) { return (t->Basic.flags & BasicFlag_Complex) != 0; } return false; } -bool is_type_quaternion(Type *t) { +gb_internal bool is_type_quaternion(Type *t) { t = core_type(t); if (t->kind == Type_Basic) { return (t->Basic.flags & BasicFlag_Quaternion) != 0; } return false; } -bool is_type_complex_or_quaternion(Type *t) { +gb_internal bool is_type_complex_or_quaternion(Type *t) { t = core_type(t); if (t->kind == Type_Basic) { return (t->Basic.flags & (BasicFlag_Complex|BasicFlag_Quaternion)) != 0; } return false; } -bool is_type_f16(Type *t) { +gb_internal bool is_type_f16(Type *t) { t = core_type(t); if (t->kind == Type_Basic) { return t->Basic.kind == Basic_f16; } return false; } -bool is_type_f32(Type *t) { +gb_internal bool is_type_f32(Type *t) { t = core_type(t); if (t->kind == Type_Basic) { return t->Basic.kind == Basic_f32; } return false; } -bool is_type_f64(Type *t) { +gb_internal bool is_type_f64(Type *t) { t = core_type(t); if (t->kind == Type_Basic) { return t->Basic.kind == Basic_f64; } return false; } -bool is_type_pointer(Type *t) { +gb_internal bool is_type_pointer(Type *t) { t = base_type(t); if (t->kind == Type_Basic) { return (t->Basic.flags & BasicFlag_Pointer) != 0; } return t->kind == Type_Pointer; } -bool is_type_soa_pointer(Type *t) { +gb_internal bool is_type_soa_pointer(Type *t) { t = base_type(t); return t->kind == Type_SoaPointer; } -bool is_type_multi_pointer(Type *t) { +gb_internal bool is_type_multi_pointer(Type *t) { t = base_type(t); return t->kind == Type_MultiPointer; } -bool is_type_internally_pointer_like(Type *t) { +gb_internal bool is_type_internally_pointer_like(Type *t) { return is_type_pointer(t) || is_type_multi_pointer(t) || is_type_cstring(t) || is_type_proc(t); } -bool is_type_tuple(Type *t) { +gb_internal bool is_type_tuple(Type *t) { t = base_type(t); return t->kind == Type_Tuple; } -bool is_type_uintptr(Type *t) { +gb_internal bool is_type_uintptr(Type *t) { if (t->kind == Type_Basic) { return (t->Basic.kind == Basic_uintptr); } return false; } -bool is_type_rawptr(Type *t) { +gb_internal bool is_type_rawptr(Type *t) { if (t->kind == Type_Basic) { return t->Basic.kind == Basic_rawptr; } return false; } -bool is_type_u8(Type *t) { +gb_internal bool is_type_u8(Type *t) { if (t->kind == Type_Basic) { return t->Basic.kind == Basic_u8; } return false; } -bool is_type_array(Type *t) { +gb_internal bool is_type_array(Type *t) { t = base_type(t); return t->kind == Type_Array; } -bool is_type_enumerated_array(Type *t) { +gb_internal bool is_type_enumerated_array(Type *t) { t = base_type(t); return t->kind == Type_EnumeratedArray; } -bool is_type_matrix(Type *t) { +gb_internal bool is_type_matrix(Type *t) { t = base_type(t); return t->kind == Type_Matrix; } -i64 matrix_align_of(Type *t, struct TypePath *tp) { +gb_internal i64 matrix_align_of(Type *t, struct TypePath *tp) { t = base_type(t); GB_ASSERT(t->kind == Type_Matrix); @@ -1440,7 +1440,7 @@ i64 matrix_align_of(Type *t, struct TypePath *tp) { } -i64 matrix_type_stride_in_bytes(Type *t, struct TypePath *tp) { +gb_internal i64 matrix_type_stride_in_bytes(Type *t, struct TypePath *tp) { t = base_type(t); GB_ASSERT(t->kind == Type_Matrix); if (t->Matrix.stride_in_bytes != 0) { @@ -1469,7 +1469,7 @@ i64 matrix_type_stride_in_bytes(Type *t, struct TypePath *tp) { return stride_in_bytes; } -i64 matrix_type_stride_in_elems(Type *t) { +gb_internal i64 matrix_type_stride_in_elems(Type *t) { t = base_type(t); GB_ASSERT(t->kind == Type_Matrix); i64 stride = matrix_type_stride_in_bytes(t, nullptr); @@ -1477,7 +1477,7 @@ i64 matrix_type_stride_in_elems(Type *t) { } -i64 matrix_type_total_internal_elems(Type *t) { +gb_internal i64 matrix_type_total_internal_elems(Type *t) { t = base_type(t); GB_ASSERT(t->kind == Type_Matrix); i64 size = type_size_of(t); @@ -1485,7 +1485,7 @@ i64 matrix_type_total_internal_elems(Type *t) { return size/gb_max(elem_size, 1); } -i64 matrix_indices_to_offset(Type *t, i64 row_index, i64 column_index) { +gb_internal i64 matrix_indices_to_offset(Type *t, i64 row_index, i64 column_index) { t = base_type(t); GB_ASSERT(t->kind == Type_Matrix); GB_ASSERT(0 <= row_index && row_index < t->Matrix.row_count); @@ -1495,7 +1495,7 @@ i64 matrix_indices_to_offset(Type *t, i64 row_index, i64 column_index) { return row_index + stride_elems*column_index; } -i64 matrix_row_major_index_to_offset(Type *t, i64 index) { +gb_internal i64 matrix_row_major_index_to_offset(Type *t, i64 index) { t = base_type(t); GB_ASSERT(t->kind == Type_Matrix); @@ -1503,7 +1503,7 @@ i64 matrix_row_major_index_to_offset(Type *t, i64 index) { i64 column_index = index%t->Matrix.column_count; return matrix_indices_to_offset(t, row_index, column_index); } -i64 matrix_column_major_index_to_offset(Type *t, i64 index) { +gb_internal i64 matrix_column_major_index_to_offset(Type *t, i64 index) { t = base_type(t); GB_ASSERT(t->kind == Type_Matrix); @@ -1513,13 +1513,13 @@ i64 matrix_column_major_index_to_offset(Type *t, i64 index) { } -bool is_matrix_square(Type *t) { +gb_internal bool is_matrix_square(Type *t) { t = base_type(t); GB_ASSERT(t->kind == Type_Matrix); return t->Matrix.row_count == t->Matrix.column_count; } -bool is_type_valid_for_matrix_elems(Type *t) { +gb_internal bool is_type_valid_for_matrix_elems(Type *t) { t = base_type(t); if (is_type_integer(t)) { return true; @@ -1534,32 +1534,32 @@ bool is_type_valid_for_matrix_elems(Type *t) { return false; } -bool is_type_dynamic_array(Type *t) { +gb_internal bool is_type_dynamic_array(Type *t) { t = base_type(t); return t->kind == Type_DynamicArray; } -bool is_type_slice(Type *t) { +gb_internal bool is_type_slice(Type *t) { t = base_type(t); return t->kind == Type_Slice; } -bool is_type_proc(Type *t) { +gb_internal bool is_type_proc(Type *t) { t = base_type(t); return t->kind == Type_Proc; } -bool is_type_asm_proc(Type *t) { +gb_internal bool is_type_asm_proc(Type *t) { t = base_type(t); return t->kind == Type_Proc && t->Proc.calling_convention == ProcCC_InlineAsm; } -bool is_type_poly_proc(Type *t) { +gb_internal bool is_type_poly_proc(Type *t) { t = base_type(t); return t->kind == Type_Proc && t->Proc.is_polymorphic; } -bool is_type_simd_vector(Type *t) { +gb_internal bool is_type_simd_vector(Type *t) { t = base_type(t); return t->kind == Type_SimdVector; } -Type *base_array_type(Type *t) { +gb_internal Type *base_array_type(Type *t) { Type *bt = base_type(t); if (is_type_array(bt)) { return bt->Array.elem; @@ -1573,49 +1573,49 @@ Type *base_array_type(Type *t) { return t; } -bool is_type_generic(Type *t) { +gb_internal bool is_type_generic(Type *t) { t = base_type(t); return t->kind == Type_Generic; } -bool is_type_relative_pointer(Type *t) { +gb_internal bool is_type_relative_pointer(Type *t) { t = base_type(t); return t->kind == Type_RelativePointer; } -bool is_type_relative_slice(Type *t) { +gb_internal bool is_type_relative_slice(Type *t) { t = base_type(t); return t->kind == Type_RelativeSlice; } -bool is_type_u8_slice(Type *t) { +gb_internal bool is_type_u8_slice(Type *t) { t = base_type(t); if (t->kind == Type_Slice) { return is_type_u8(t->Slice.elem); } return false; } -bool is_type_u8_array(Type *t) { +gb_internal bool is_type_u8_array(Type *t) { t = base_type(t); if (t->kind == Type_Array) { return is_type_u8(t->Array.elem); } return false; } -bool is_type_u8_ptr(Type *t) { +gb_internal bool is_type_u8_ptr(Type *t) { t = base_type(t); if (t->kind == Type_Pointer) { return is_type_u8(t->Slice.elem); } return false; } -bool is_type_u8_multi_ptr(Type *t) { +gb_internal bool is_type_u8_multi_ptr(Type *t) { t = base_type(t); if (t->kind == Type_MultiPointer) { return is_type_u8(t->Slice.elem); } return false; } -bool is_type_rune_array(Type *t) { +gb_internal bool is_type_rune_array(Type *t) { t = base_type(t); if (t->kind == Type_Array) { return is_type_rune(t->Array.elem); @@ -1624,10 +1624,10 @@ bool is_type_rune_array(Type *t) { } -bool is_type_array_like(Type *t) { +gb_internal bool is_type_array_like(Type *t) { return is_type_array(t) || is_type_enumerated_array(t); } -i64 get_array_type_count(Type *t) { +gb_internal i64 get_array_type_count(Type *t) { Type *bt = base_type(t); if (bt->kind == Type_Array) { return bt->Array.count; @@ -1642,7 +1642,7 @@ i64 get_array_type_count(Type *t) { -Type *core_array_type(Type *t) { +gb_internal Type *core_array_type(Type *t) { for (;;) { t = base_array_type(t); switch (t->kind) { @@ -1657,7 +1657,7 @@ Type *core_array_type(Type *t) { } } -i32 type_math_rank(Type *t) { +gb_internal i32 type_math_rank(Type *t) { i32 rank = 0; for (;;) { t = base_type(t); @@ -1677,7 +1677,7 @@ i32 type_math_rank(Type *t) { } -Type *base_complex_elem_type(Type *t) { +gb_internal Type *base_complex_elem_type(Type *t) { t = core_type(t); if (t->kind == Type_Basic) { switch (t->Basic.kind) { @@ -1695,37 +1695,37 @@ Type *base_complex_elem_type(Type *t) { return t_invalid; } -bool is_type_struct(Type *t) { +gb_internal bool is_type_struct(Type *t) { t = base_type(t); return t->kind == Type_Struct; } -bool is_type_union(Type *t) { +gb_internal bool is_type_union(Type *t) { t = base_type(t); return t->kind == Type_Union; } -bool is_type_soa_struct(Type *t) { +gb_internal bool is_type_soa_struct(Type *t) { t = base_type(t); return t->kind == Type_Struct && t->Struct.soa_kind != StructSoa_None; } -bool is_type_raw_union(Type *t) { +gb_internal bool is_type_raw_union(Type *t) { t = base_type(t); return (t->kind == Type_Struct && t->Struct.is_raw_union); } -bool is_type_enum(Type *t) { +gb_internal bool is_type_enum(Type *t) { t = base_type(t); return (t->kind == Type_Enum); } -bool is_type_bit_set(Type *t) { +gb_internal bool is_type_bit_set(Type *t) { t = base_type(t); return (t->kind == Type_BitSet); } -bool is_type_map(Type *t) { +gb_internal bool is_type_map(Type *t) { t = base_type(t); return t->kind == Type_Map; } -bool is_type_union_maybe_pointer(Type *t) { +gb_internal bool is_type_union_maybe_pointer(Type *t) { t = base_type(t); if (t->kind == Type_Union && t->Union.variants.count == 1) { Type *v = t->Union.variants[0]; @@ -1735,7 +1735,7 @@ bool is_type_union_maybe_pointer(Type *t) { } -bool is_type_union_maybe_pointer_original_alignment(Type *t) { +gb_internal bool is_type_union_maybe_pointer_original_alignment(Type *t) { t = base_type(t); if (t->kind == Type_Union && t->Union.variants.count == 1) { Type *v = t->Union.variants[0]; @@ -1748,7 +1748,7 @@ bool is_type_union_maybe_pointer_original_alignment(Type *t) { -bool is_type_endian_big(Type *t) { +gb_internal bool is_type_endian_big(Type *t) { t = core_type(t); if (t->kind == Type_Basic) { if (t->Basic.flags & BasicFlag_EndianBig) { @@ -1764,7 +1764,7 @@ bool is_type_endian_big(Type *t) { } return build_context.endian_kind == TargetEndian_Big; } -bool is_type_endian_little(Type *t) { +gb_internal bool is_type_endian_little(Type *t) { t = core_type(t); if (t->kind == Type_Basic) { if (t->Basic.flags & BasicFlag_EndianLittle) { @@ -1781,7 +1781,7 @@ bool is_type_endian_little(Type *t) { return build_context.endian_kind == TargetEndian_Little; } -bool is_type_endian_platform(Type *t) { +gb_internal bool is_type_endian_platform(Type *t) { t = core_type(t); if (t->kind == Type_Basic) { return (t->Basic.flags & (BasicFlag_EndianLittle|BasicFlag_EndianBig)) == 0; @@ -1793,10 +1793,10 @@ bool is_type_endian_platform(Type *t) { return false; } -bool types_have_same_internal_endian(Type *a, Type *b) { +gb_internal bool types_have_same_internal_endian(Type *a, Type *b) { return is_type_endian_little(a) == is_type_endian_little(b); } -bool is_type_endian_specific(Type *t) { +gb_internal bool is_type_endian_specific(Type *t) { t = core_type(t); if (t->kind == Type_BitSet) { t = bit_set_to_int(t); @@ -1834,7 +1834,7 @@ bool is_type_endian_specific(Type *t) { return false; } -bool is_type_dereferenceable(Type *t) { +gb_internal bool is_type_dereferenceable(Type *t) { if (is_type_rawptr(t)) { return false; } @@ -1843,7 +1843,7 @@ bool is_type_dereferenceable(Type *t) { -bool is_type_different_to_arch_endianness(Type *t) { +gb_internal bool is_type_different_to_arch_endianness(Type *t) { switch (build_context.endian_kind) { case TargetEndian_Little: return !is_type_endian_little(t); @@ -1853,7 +1853,7 @@ bool is_type_different_to_arch_endianness(Type *t) { return false; } -Type *integer_endian_type_to_platform_type(Type *t) { +gb_internal Type *integer_endian_type_to_platform_type(Type *t) { t = core_type(t); if (t->kind == Type_BitSet) { t = bit_set_to_int(t); @@ -1893,35 +1893,35 @@ Type *integer_endian_type_to_platform_type(Type *t) { -bool is_type_any(Type *t) { +gb_internal bool is_type_any(Type *t) { t = base_type(t); return (t->kind == Type_Basic && t->Basic.kind == Basic_any); } -bool is_type_typeid(Type *t) { +gb_internal bool is_type_typeid(Type *t) { t = base_type(t); return (t->kind == Type_Basic && t->Basic.kind == Basic_typeid); } -bool is_type_untyped_nil(Type *t) { +gb_internal bool is_type_untyped_nil(Type *t) { t = base_type(t); return (t->kind == Type_Basic && t->Basic.kind == Basic_UntypedNil); } -bool is_type_untyped_undef(Type *t) { +gb_internal bool is_type_untyped_undef(Type *t) { t = base_type(t); return (t->kind == Type_Basic && t->Basic.kind == Basic_UntypedUndef); } -bool is_type_empty_union(Type *t) { +gb_internal bool is_type_empty_union(Type *t) { t = base_type(t); return t->kind == Type_Union && t->Union.variants.count == 0; } -bool is_type_empty_struct(Type *t) { +gb_internal bool is_type_empty_struct(Type *t) { t = base_type(t); return t->kind == Type_Struct && !t->Struct.is_raw_union && t->Struct.fields.count == 0; } -bool is_type_valid_for_keys(Type *t) { +gb_internal bool is_type_valid_for_keys(Type *t) { t = core_type(t); if (t->kind == Type_Generic) { return true; @@ -1932,7 +1932,7 @@ bool is_type_valid_for_keys(Type *t) { return type_size_of(t) > 0 && is_type_comparable(t); } -bool is_type_valid_bit_set_elem(Type *t) { +gb_internal bool is_type_valid_bit_set_elem(Type *t) { if (is_type_enum(t)) { return true; } @@ -1943,7 +1943,7 @@ bool is_type_valid_bit_set_elem(Type *t) { return false; } -Type *bit_set_to_int(Type *t) { +gb_internal Type *bit_set_to_int(Type *t) { GB_ASSERT(is_type_bit_set(t)); Type *bt = base_type(t); Type *underlying = bt->BitSet.underlying; @@ -1964,7 +1964,7 @@ Type *bit_set_to_int(Type *t) { return nullptr; } -bool is_type_valid_vector_elem(Type *t) { +gb_internal bool is_type_valid_vector_elem(Type *t) { t = base_type(t); if (t->kind == Type_Basic) { if (t->Basic.flags & BasicFlag_EndianLittle) { @@ -1987,7 +1987,7 @@ bool is_type_valid_vector_elem(Type *t) { } -bool is_type_indexable(Type *t) { +gb_internal bool is_type_indexable(Type *t) { Type *bt = base_type(t); switch (bt->kind) { case Type_Basic: @@ -2009,7 +2009,7 @@ bool is_type_indexable(Type *t) { return false; } -bool is_type_sliceable(Type *t) { +gb_internal bool is_type_sliceable(Type *t) { Type *bt = base_type(t); switch (bt->kind) { case Type_Basic: @@ -2029,7 +2029,7 @@ bool is_type_sliceable(Type *t) { } -bool is_type_polymorphic_record(Type *t) { +gb_internal bool is_type_polymorphic_record(Type *t) { t = base_type(t); if (t->kind == Type_Struct) { return t->Struct.is_polymorphic; @@ -2039,7 +2039,7 @@ bool is_type_polymorphic_record(Type *t) { return false; } -Scope *polymorphic_record_parent_scope(Type *t) { +gb_internal Scope *polymorphic_record_parent_scope(Type *t) { t = base_type(t); if (is_type_polymorphic_record(t)) { if (t->kind == Type_Struct) { @@ -2051,7 +2051,7 @@ Scope *polymorphic_record_parent_scope(Type *t) { return nullptr; } -bool is_type_polymorphic_record_specialized(Type *t) { +gb_internal bool is_type_polymorphic_record_specialized(Type *t) { t = base_type(t); if (t->kind == Type_Struct) { return t->Struct.is_poly_specialized; @@ -2061,7 +2061,7 @@ bool is_type_polymorphic_record_specialized(Type *t) { return false; } -bool is_type_polymorphic_record_unspecialized(Type *t) { +gb_internal bool is_type_polymorphic_record_unspecialized(Type *t) { t = base_type(t); if (t->kind == Type_Struct) { return t->Struct.is_polymorphic && !t->Struct.is_poly_specialized; @@ -2071,7 +2071,7 @@ bool is_type_polymorphic_record_unspecialized(Type *t) { return false; } -TypeTuple *get_record_polymorphic_params(Type *t) { +gb_internal TypeTuple *get_record_polymorphic_params(Type *t) { t = base_type(t); switch (t->kind) { case Type_Struct: @@ -2089,7 +2089,7 @@ TypeTuple *get_record_polymorphic_params(Type *t) { } -bool is_type_polymorphic(Type *t, bool or_specialized=false) { +gb_internal bool is_type_polymorphic(Type *t, bool or_specialized=false) { if (t == nullptr) { return false; } @@ -2248,11 +2248,11 @@ bool is_type_polymorphic(Type *t, bool or_specialized=false) { } -bool type_has_undef(Type *t) { +gb_internal gb_inline bool type_has_undef(Type *t) { return true; } -bool type_has_nil(Type *t) { +gb_internal bool type_has_nil(Type *t) { t = base_type(t); switch (t->kind) { case Type_Basic: { @@ -2297,7 +2297,7 @@ bool type_has_nil(Type *t) { return false; } -bool elem_type_can_be_constant(Type *t) { +gb_internal bool elem_type_can_be_constant(Type *t) { t = base_type(t); if (t == t_invalid) { return false; @@ -2308,7 +2308,7 @@ bool elem_type_can_be_constant(Type *t) { return true; } -bool is_type_lock_free(Type *t) { +gb_internal bool is_type_lock_free(Type *t) { t = core_type(t); if (t == t_invalid) { return false; @@ -2320,7 +2320,7 @@ bool is_type_lock_free(Type *t) { -bool is_type_comparable(Type *t) { +gb_internal bool is_type_comparable(Type *t) { t = base_type(t); switch (t->kind) { case Type_Basic: @@ -2395,7 +2395,7 @@ bool is_type_comparable(Type *t) { } // NOTE(bill): type can be easily compared using memcmp -bool is_type_simple_compare(Type *t) { +gb_internal bool is_type_simple_compare(Type *t) { t = core_type(t); switch (t->kind) { case Type_Array: @@ -2450,7 +2450,7 @@ bool is_type_simple_compare(Type *t) { return false; } -bool is_type_load_safe(Type *type) { +gb_internal bool is_type_load_safe(Type *type) { GB_ASSERT(type != nullptr); type = core_type(core_array_type(type)); switch (type->kind) { @@ -2501,7 +2501,7 @@ bool is_type_load_safe(Type *type) { return false; } -String lookup_subtype_polymorphic_field(Type *dst, Type *src) { +gb_internal String lookup_subtype_polymorphic_field(Type *dst, Type *src) { Type *prev_src = src; // Type *prev_dst = dst; src = base_type(type_deref(src)); @@ -2532,7 +2532,7 @@ String lookup_subtype_polymorphic_field(Type *dst, Type *src) { return str_lit(""); } -bool lookup_subtype_polymorphic_selection(Type *dst, Type *src, Selection *sel) { +gb_internal bool lookup_subtype_polymorphic_selection(Type *dst, Type *src, Selection *sel) { Type *prev_src = src; // Type *prev_dst = dst; src = base_type(type_deref(src)); @@ -2571,17 +2571,17 @@ bool lookup_subtype_polymorphic_selection(Type *dst, Type *src, Selection *sel) -bool are_types_identical_internal(Type *x, Type *y, bool check_tuple_names); +gb_internal bool are_types_identical_internal(Type *x, Type *y, bool check_tuple_names); -bool are_types_identical(Type *x, Type *y) { +gb_internal bool are_types_identical(Type *x, Type *y) { return are_types_identical_internal(x, y, false); } -bool are_types_identical_unique_tuples(Type *x, Type *y) { +gb_internal bool are_types_identical_unique_tuples(Type *x, Type *y) { return are_types_identical_internal(x, y, true); } -bool are_types_identical_internal(Type *x, Type *y, bool check_tuple_names) { +gb_internal bool are_types_identical_internal(Type *x, Type *y, bool check_tuple_names) { if (x == y) { return true; } @@ -2748,7 +2748,7 @@ bool are_types_identical_internal(Type *x, Type *y, bool check_tuple_names) { return false; } -Type *default_type(Type *type) { +gb_internal Type *default_type(Type *type) { if (type == nullptr) { return t_invalid; } @@ -2766,7 +2766,7 @@ Type *default_type(Type *type) { return type; } -i64 union_variant_index(Type *u, Type *v) { +gb_internal i64 union_variant_index(Type *u, Type *v) { u = base_type(u); GB_ASSERT(u->kind == Type_Union); @@ -2783,7 +2783,7 @@ i64 union_variant_index(Type *u, Type *v) { return 0; } -i64 union_tag_size(Type *u) { +gb_internal i64 union_tag_size(Type *u) { u = base_type(u); GB_ASSERT(u->kind == Type_Union); if (u->Union.tag_size > 0) { @@ -2820,7 +2820,7 @@ i64 union_tag_size(Type *u) { return u->Union.tag_size; } -Type *union_tag_type(Type *u) { +gb_internal Type *union_tag_type(Type *u) { i64 s = union_tag_size(u); switch (s) { case 0: return t_u8; @@ -2850,7 +2850,7 @@ enum ProcTypeOverloadKind { }; -ProcTypeOverloadKind are_proc_types_overload_safe(Type *x, Type *y) { +gb_internal ProcTypeOverloadKind are_proc_types_overload_safe(Type *x, Type *y) { if (x == nullptr && y == nullptr) return ProcOverload_NotProcedure; if (x == nullptr && y != nullptr) return ProcOverload_NotProcedure; if (x != nullptr && y == nullptr) return ProcOverload_NotProcedure; @@ -2917,13 +2917,13 @@ ProcTypeOverloadKind are_proc_types_overload_safe(Type *x, Type *y) { -Selection lookup_field_with_selection(Type *type_, String field_name, bool is_type, Selection sel, bool allow_blank_ident=false); +gb_internal Selection lookup_field_with_selection(Type *type_, String field_name, bool is_type, Selection sel, bool allow_blank_ident=false); -Selection lookup_field(Type *type_, String field_name, bool is_type, bool allow_blank_ident=false) { +gb_internal Selection lookup_field(Type *type_, String field_name, bool is_type, bool allow_blank_ident=false) { return lookup_field_with_selection(type_, field_name, is_type, empty_selection, allow_blank_ident); } -Selection lookup_field_from_index(Type *type, i64 index) { +gb_internal Selection lookup_field_from_index(Type *type, i64 index) { GB_ASSERT(is_type_struct(type) || is_type_union(type) || is_type_tuple(type)); type = base_type(type); @@ -2967,10 +2967,10 @@ Selection lookup_field_from_index(Type *type, i64 index) { return empty_selection; } -Entity *scope_lookup_current(Scope *s, String const &name); -bool has_type_got_objc_class_attribute(Type *t); +gb_internal Entity *scope_lookup_current(Scope *s, String const &name); +gb_internal bool has_type_got_objc_class_attribute(Type *t); -Selection lookup_field_with_selection(Type *type_, String field_name, bool is_type, Selection sel, bool allow_blank_ident) { +gb_internal Selection lookup_field_with_selection(Type *type_, String field_name, bool is_type, Selection sel, bool allow_blank_ident) { GB_ASSERT(type_ != nullptr); if (!allow_blank_ident && is_blank_ident(field_name)) { @@ -3312,7 +3312,7 @@ Selection lookup_field_with_selection(Type *type_, String field_name, bool is_ty return sel; } -bool are_struct_fields_reordered(Type *type) { +gb_internal bool are_struct_fields_reordered(Type *type) { type = base_type(type); GB_ASSERT(type->kind == Type_Struct); type_set_offsets(type); @@ -3330,7 +3330,7 @@ bool are_struct_fields_reordered(Type *type) { return false; } -Slice struct_fields_index_by_increasing_offset(gbAllocator allocator, Type *type) { +gb_internal Slice struct_fields_index_by_increasing_offset(gbAllocator allocator, Type *type) { type = base_type(type); GB_ASSERT(type->kind == Type_Struct); type_set_offsets(type); @@ -3365,12 +3365,12 @@ Slice struct_fields_index_by_increasing_offset(gbAllocator allocator, Type -i64 type_size_of_internal (Type *t, TypePath *path); -i64 type_align_of_internal(Type *t, TypePath *path); -i64 type_size_of(Type *t); -i64 type_align_of(Type *t); +gb_internal i64 type_size_of_internal (Type *t, TypePath *path); +gb_internal i64 type_align_of_internal(Type *t, TypePath *path); +gb_internal i64 type_size_of(Type *t); +gb_internal i64 type_align_of(Type *t); -i64 type_size_of_struct_pretend_is_packed(Type *ot) { +gb_internal i64 type_size_of_struct_pretend_is_packed(Type *ot) { if (ot == nullptr) { return 0; } @@ -3399,7 +3399,7 @@ i64 type_size_of_struct_pretend_is_packed(Type *ot) { } -i64 type_size_of(Type *t) { +gb_internal i64 type_size_of(Type *t) { if (t == nullptr) { return 0; } @@ -3416,7 +3416,7 @@ i64 type_size_of(Type *t) { return t->cached_size; } -i64 type_align_of(Type *t) { +gb_internal i64 type_align_of(Type *t) { if (t == nullptr) { return 1; } @@ -3435,7 +3435,7 @@ i64 type_align_of(Type *t) { } -i64 type_align_of_internal(Type *t, TypePath *path) { +gb_internal i64 type_align_of_internal(Type *t, TypePath *path) { GB_ASSERT(path != nullptr); if (t->failure) { return FAILURE_ALIGNMENT; @@ -3608,7 +3608,7 @@ i64 type_align_of_internal(Type *t, TypePath *path) { return gb_clamp(next_pow2(type_size_of_internal(t, path)), 1, build_context.max_align); } -i64 *type_set_offsets_of(Slice const &fields, bool is_packed, bool is_raw_union) { +gb_internal i64 *type_set_offsets_of(Slice const &fields, bool is_packed, bool is_raw_union) { gbAllocator a = permanent_allocator(); auto offsets = gb_alloc_array(a, i64, fields.count); i64 curr_offset = 0; @@ -3635,7 +3635,7 @@ i64 *type_set_offsets_of(Slice const &fields, bool is_packed, bool is_ return offsets; } -bool type_set_offsets(Type *t) { +gb_internal bool type_set_offsets(Type *t) { mutex_lock(&g_type_mutex); defer (mutex_unlock(&g_type_mutex)); @@ -3662,7 +3662,7 @@ bool type_set_offsets(Type *t) { return false; } -i64 type_size_of_internal(Type *t, TypePath *path) { +gb_internal i64 type_size_of_internal(Type *t, TypePath *path) { if (t->failure) { return FAILURE_SIZE; } @@ -3882,7 +3882,7 @@ i64 type_size_of_internal(Type *t, TypePath *path) { return build_context.word_size; } -i64 type_offset_of(Type *t, i32 index) { +gb_internal i64 type_offset_of(Type *t, i32 index) { t = base_type(t); if (t->kind == Type_Struct) { type_set_offsets(t); @@ -3931,7 +3931,7 @@ i64 type_offset_of(Type *t, i32 index) { } -i64 type_offset_of_from_selection(Type *type, Selection sel) { +gb_internal i64 type_offset_of_from_selection(Type *type, Selection sel) { GB_ASSERT(sel.indirect == false); Type *t = type; @@ -3979,7 +3979,7 @@ i64 type_offset_of_from_selection(Type *type, Selection sel) { return offset; } -isize check_is_assignable_to_using_subtype(Type *src, Type *dst, isize level = 0, bool src_is_ptr = false) { +gb_internal isize check_is_assignable_to_using_subtype(Type *src, Type *dst, isize level = 0, bool src_is_ptr = false) { Type *prev_src = src; src = type_deref(src); if (!src_is_ptr) { @@ -4014,7 +4014,7 @@ isize check_is_assignable_to_using_subtype(Type *src, Type *dst, isize level = 0 return 0; } -bool is_type_subtype_of(Type *src, Type *dst) { +gb_internal bool is_type_subtype_of(Type *src, Type *dst) { if (are_types_identical(src, dst)) { return true; } @@ -4023,26 +4023,26 @@ bool is_type_subtype_of(Type *src, Type *dst) { } -bool has_type_got_objc_class_attribute(Type *t) { +gb_internal bool has_type_got_objc_class_attribute(Type *t) { return t->kind == Type_Named && t->Named.type_name != nullptr && t->Named.type_name->TypeName.objc_class_name != ""; } -bool is_type_objc_object(Type *t) { +gb_internal bool is_type_objc_object(Type *t) { bool internal_check_is_assignable_to(Type *src, Type *dst); return internal_check_is_assignable_to(t, t_objc_object); } -Type *get_struct_field_type(Type *t, isize index) { +gb_internal Type *get_struct_field_type(Type *t, isize index) { t = base_type(type_deref(t)); GB_ASSERT(t->kind == Type_Struct); return t->Struct.fields[index]->type; } -Type *reduce_tuple_to_single_type(Type *original_type) { +gb_internal Type *reduce_tuple_to_single_type(Type *original_type) { if (original_type != nullptr) { Type *t = core_type(original_type); if (t->kind == Type_Tuple && t->Tuple.variables.count == 1) { @@ -4053,7 +4053,7 @@ Type *reduce_tuple_to_single_type(Type *original_type) { } -Type *alloc_type_struct_from_field_types(Type **field_types, isize field_count, bool is_packed) { +gb_internal Type *alloc_type_struct_from_field_types(Type **field_types, isize field_count, bool is_packed) { Type *t = alloc_type_struct(); t->Struct.fields = slice_make(heap_allocator(), field_count); @@ -4066,7 +4066,7 @@ Type *alloc_type_struct_from_field_types(Type **field_types, isize field_count, return t; } -Type *alloc_type_tuple_from_field_types(Type **field_types, isize field_count, bool is_packed, bool must_be_tuple) { +gb_internal Type *alloc_type_tuple_from_field_types(Type **field_types, isize field_count, bool is_packed, bool must_be_tuple) { if (field_count == 0) { return nullptr; } @@ -4086,7 +4086,7 @@ Type *alloc_type_tuple_from_field_types(Type **field_types, isize field_count, b return t; } -Type *alloc_type_proc_from_types(Type **param_types, unsigned param_count, Type *results, bool is_c_vararg, ProcCallingConvention calling_convention) { +gb_internal Type *alloc_type_proc_from_types(Type **param_types, unsigned param_count, Type *results, bool is_c_vararg, ProcCallingConvention calling_convention) { Type *params = alloc_type_tuple_from_field_types(param_types, param_count, false, true); isize results_count = 0; @@ -4105,7 +4105,7 @@ Type *alloc_type_proc_from_types(Type **param_types, unsigned param_count, Type -gbString write_type_to_string(gbString str, Type *type, bool shorthand=false) { +gb_internal gbString write_type_to_string(gbString str, Type *type, bool shorthand=false) { if (type == nullptr) { return gb_string_appendc(str, ""); } @@ -4416,14 +4416,14 @@ gbString write_type_to_string(gbString str, Type *type, bool shorthand=false) { } -gbString type_to_string(Type *type, gbAllocator allocator, bool shorthand) { +gb_internal gbString type_to_string(Type *type, gbAllocator allocator, bool shorthand) { return write_type_to_string(gb_string_make(allocator, ""), type, shorthand); } -gbString type_to_string(Type *type, bool shorthand) { +gb_internal gbString type_to_string(Type *type, bool shorthand) { return write_type_to_string(gb_string_make(heap_allocator(), ""), type, shorthand); } -gbString type_to_string_shorthand(Type *type) { +gb_internal gbString type_to_string_shorthand(Type *type) { return type_to_string(type, true); } -- cgit v1.2.3 From 690666537c8a27d3c418b38b3285899100c9a556 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 18 Dec 2022 21:46:27 +0000 Subject: Add `gb_internal` to checker --- src/check_builtin.cpp | 34 ++--- src/check_decl.cpp | 44 +++--- src/check_expr.cpp | 334 +++++++++++++++++++++--------------------- src/check_stmt.cpp | 46 +++--- src/check_type.cpp | 80 +++++----- src/checker.cpp | 393 +++++++++++++++++++++++++------------------------- src/types.cpp | 3 +- 7 files changed, 466 insertions(+), 468 deletions(-) (limited to 'src') diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp index 533929200..859fbea28 100644 --- a/src/check_builtin.cpp +++ b/src/check_builtin.cpp @@ -1,6 +1,6 @@ typedef bool (BuiltinTypeIsProc)(Type *t); -BuiltinTypeIsProc *builtin_type_is_procs[BuiltinProc__type_simple_boolean_end - BuiltinProc__type_simple_boolean_begin] = { +gb_global BuiltinTypeIsProc *builtin_type_is_procs[BuiltinProc__type_simple_boolean_end - BuiltinProc__type_simple_boolean_begin] = { nullptr, // BuiltinProc__type_simple_boolean_begin is_type_boolean, @@ -51,7 +51,7 @@ BuiltinTypeIsProc *builtin_type_is_procs[BuiltinProc__type_simple_boolean_end - }; -void check_or_else_right_type(CheckerContext *c, Ast *expr, String const &name, Type *right_type) { +gb_internal void check_or_else_right_type(CheckerContext *c, Ast *expr, String const &name, Type *right_type) { if (right_type == nullptr) { return; } @@ -62,7 +62,7 @@ void check_or_else_right_type(CheckerContext *c, Ast *expr, String const &name, } } -void check_or_else_split_types(CheckerContext *c, Operand *x, String const &name, Type **left_type_, Type **right_type_) { +gb_internal void check_or_else_split_types(CheckerContext *c, Operand *x, String const &name, Type **left_type_, Type **right_type_) { Type *left_type = nullptr; Type *right_type = nullptr; if (x->type->kind == Type_Tuple) { @@ -88,7 +88,7 @@ void check_or_else_split_types(CheckerContext *c, Operand *x, String const &name } -void check_or_else_expr_no_value_error(CheckerContext *c, String const &name, Operand const &x, Type *type_hint) { +gb_internal void check_or_else_expr_no_value_error(CheckerContext *c, String const &name, Operand const &x, Type *type_hint) { // TODO(bill): better error message gbString t = type_to_string(x.type); error(x.expr, "'%.*s' does not return a value, value is of type %s", LIT(name), t); @@ -118,7 +118,7 @@ void check_or_else_expr_no_value_error(CheckerContext *c, String const &name, Op } -void check_or_return_split_types(CheckerContext *c, Operand *x, String const &name, Type **left_type_, Type **right_type_) { +gb_internal void check_or_return_split_types(CheckerContext *c, Operand *x, String const &name, Type **left_type_, Type **right_type_) { Type *left_type = nullptr; Type *right_type = nullptr; if (x->type->kind == Type_Tuple) { @@ -144,7 +144,7 @@ void check_or_return_split_types(CheckerContext *c, Operand *x, String const &na } -bool does_require_msgSend_stret(Type *return_type) { +gb_internal bool does_require_msgSend_stret(Type *return_type) { if (return_type == nullptr) { return false; } @@ -165,7 +165,7 @@ bool does_require_msgSend_stret(Type *return_type) { return false; } -ObjcMsgKind get_objc_proc_kind(Type *return_type) { +gb_internal ObjcMsgKind get_objc_proc_kind(Type *return_type) { if (return_type == nullptr) { return ObjcMsg_normal; } @@ -189,7 +189,7 @@ ObjcMsgKind get_objc_proc_kind(Type *return_type) { return ObjcMsg_normal; } -void add_objc_proc_type(CheckerContext *c, Ast *call, Type *return_type, Slice param_types) { +gb_internal void add_objc_proc_type(CheckerContext *c, Ast *call, Type *return_type, Slice param_types) { ObjcMsgKind kind = get_objc_proc_kind(return_type); Scope *scope = create_scope(c->info, nullptr); @@ -230,7 +230,7 @@ void add_objc_proc_type(CheckerContext *c, Ast *call, Type *return_type, Sliceproc); String builtin_name = bd->name.string; @@ -1170,7 +1170,7 @@ bool cache_load_file_directive(CheckerContext *c, Ast *call, String const &origi } -bool is_valid_type_for_load(Type *type) { +gb_internal bool is_valid_type_for_load(Type *type) { if (type == t_invalid) { return false; } else if (is_type_string(type)) { @@ -1191,7 +1191,7 @@ bool is_valid_type_for_load(Type *type) { return false; } -LoadDirectiveResult check_load_directive(CheckerContext *c, Operand *operand, Ast *call, Type *type_hint, bool err_on_not_found) { +gb_internal LoadDirectiveResult check_load_directive(CheckerContext *c, Operand *operand, Ast *call, Type *type_hint, bool err_on_not_found) { ast_node(ce, CallExpr, call); ast_node(bd, BasicDirective, ce->proc); String name = bd->name.string; @@ -1256,7 +1256,7 @@ LoadDirectiveResult check_load_directive(CheckerContext *c, Operand *operand, As } -bool check_builtin_procedure_directive(CheckerContext *c, Operand *operand, Ast *call, Type *type_hint) { +gb_internal bool check_builtin_procedure_directive(CheckerContext *c, Operand *operand, Ast *call, Type *type_hint) { ast_node(ce, CallExpr, call); ast_node(bd, BasicDirective, ce->proc); String name = bd->name.string; @@ -1581,7 +1581,7 @@ bool check_builtin_procedure_directive(CheckerContext *c, Operand *operand, Ast return true; } -bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32 id, Type *type_hint) { +gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32 id, Type *type_hint) { ast_node(ce, CallExpr, call); if (ce->inlining != ProcInlining_none) { error(call, "Inlining operators are not allowed on built-in procedures"); diff --git a/src/check_decl.cpp b/src/check_decl.cpp index 18e5477d6..a976c1b73 100644 --- a/src/check_decl.cpp +++ b/src/check_decl.cpp @@ -1,7 +1,7 @@ -void check_stmt (CheckerContext *ctx, Ast *node, u32 flags); +gb_internal void check_stmt(CheckerContext *ctx, Ast *node, u32 flags); // NOTE(bill): 'content_name' is for debugging and error messages -Type *check_init_variable(CheckerContext *ctx, Entity *e, Operand *operand, String context_name) { +gb_internal Type *check_init_variable(CheckerContext *ctx, Entity *e, Operand *operand, String context_name) { if (operand->mode == Addressing_Invalid || operand->type == t_invalid || e->type == t_invalid) { @@ -110,7 +110,7 @@ Type *check_init_variable(CheckerContext *ctx, Entity *e, Operand *operand, Stri return e->type; } -void check_init_variables(CheckerContext *ctx, Entity **lhs, isize lhs_count, Slice const &inits, String context_name) { +gb_internal void check_init_variables(CheckerContext *ctx, Entity **lhs, isize lhs_count, Slice const &inits, String context_name) { if ((lhs == nullptr || lhs_count == 0) && inits.count == 0) { return; } @@ -144,7 +144,7 @@ void check_init_variables(CheckerContext *ctx, Entity **lhs, isize lhs_count, Sl } } -void check_init_constant(CheckerContext *ctx, Entity *e, Operand *operand) { +gb_internal void check_init_constant(CheckerContext *ctx, Entity *e, Operand *operand) { if (operand->mode == Addressing_Invalid || operand->type == t_invalid || e->type == t_invalid) { @@ -184,7 +184,7 @@ void check_init_constant(CheckerContext *ctx, Entity *e, Operand *operand) { } -bool is_type_distinct(Ast *node) { +gb_internal bool is_type_distinct(Ast *node) { for (;;) { if (node == nullptr) { return false; @@ -217,7 +217,7 @@ bool is_type_distinct(Ast *node) { return false; } -Ast *remove_type_alias_clutter(Ast *node) { +gb_internal Ast *remove_type_alias_clutter(Ast *node) { for (;;) { if (node == nullptr) { return nullptr; @@ -232,7 +232,7 @@ Ast *remove_type_alias_clutter(Ast *node) { } } -isize total_attribute_count(DeclInfo *decl) { +gb_internal isize total_attribute_count(DeclInfo *decl) { isize attribute_count = 0; for_array(i, decl->attributes) { Ast *attr = decl->attributes[i]; @@ -242,7 +242,7 @@ isize total_attribute_count(DeclInfo *decl) { return attribute_count; } -Type *clone_enum_type(CheckerContext *ctx, Type *original_enum_type, Type *named_type) { +gb_internal Type *clone_enum_type(CheckerContext *ctx, Type *original_enum_type, Type *named_type) { // NOTE(bill, 2022-02-05): Stupid edge case for `distinct` declarations // // X :: enum {A, B, C} @@ -288,7 +288,7 @@ Type *clone_enum_type(CheckerContext *ctx, Type *original_enum_type, Type *named return et; } -void check_type_decl(CheckerContext *ctx, Entity *e, Ast *init_expr, Type *def) { +gb_internal void check_type_decl(CheckerContext *ctx, Entity *e, Ast *init_expr, Type *def) { GB_ASSERT(e->type == nullptr); DeclInfo *decl = decl_info_of_entity(e); @@ -390,7 +390,7 @@ void check_type_decl(CheckerContext *ctx, Entity *e, Ast *init_expr, Type *def) } -void override_entity_in_scope(Entity *original_entity, Entity *new_entity) { +gb_internal void override_entity_in_scope(Entity *original_entity, Entity *new_entity) { // NOTE(bill): The original_entity's scope may not be same scope that it was inserted into // e.g. file entity inserted into its package scope String original_name = original_entity->token.string; @@ -433,7 +433,7 @@ void override_entity_in_scope(Entity *original_entity, Entity *new_entity) { -void check_const_decl(CheckerContext *ctx, Entity *e, Ast *type_expr, Ast *init, Type *named_type) { +gb_internal void check_const_decl(CheckerContext *ctx, Entity *e, Ast *type_expr, Ast *init, Type *named_type) { GB_ASSERT(e->type == nullptr); GB_ASSERT(e->kind == Entity_Constant); init = unparen_expr(init); @@ -609,12 +609,12 @@ void check_const_decl(CheckerContext *ctx, Entity *e, Ast *type_expr, Ast *init, typedef bool TypeCheckSig(Type *t); -bool sig_compare(TypeCheckSig *a, Type *x, Type *y) { +gb_internal bool sig_compare(TypeCheckSig *a, Type *x, Type *y) { x = core_type(x); y = core_type(y); return (a(x) && a(y)); } -bool sig_compare(TypeCheckSig *a, TypeCheckSig *b, Type *x, Type *y) { +gb_internal bool sig_compare(TypeCheckSig *a, TypeCheckSig *b, Type *x, Type *y) { x = core_type(x); y = core_type(y); if (a == b) { @@ -623,7 +623,7 @@ bool sig_compare(TypeCheckSig *a, TypeCheckSig *b, Type *x, Type *y) { return ((a(x) && b(y)) || (b(x) && a(y))); } -bool signature_parameter_similar_enough(Type *x, Type *y) { +gb_internal bool signature_parameter_similar_enough(Type *x, Type *y) { if (sig_compare(is_type_pointer, x, y)) { return true; } @@ -674,7 +674,7 @@ bool signature_parameter_similar_enough(Type *x, Type *y) { } -bool are_signatures_similar_enough(Type *a_, Type *b_) { +gb_internal bool are_signatures_similar_enough(Type *a_, Type *b_) { GB_ASSERT(a_->kind == Type_Proc); GB_ASSERT(b_->kind == Type_Proc); TypeProc *a = &a_->Proc; @@ -704,7 +704,7 @@ bool are_signatures_similar_enough(Type *a_, Type *b_) { return true; } -Entity *init_entity_foreign_library(CheckerContext *ctx, Entity *e) { +gb_internal Entity *init_entity_foreign_library(CheckerContext *ctx, Entity *e) { Ast *ident = nullptr; Entity **foreign_library = nullptr; @@ -747,7 +747,7 @@ Entity *init_entity_foreign_library(CheckerContext *ctx, Entity *e) { return nullptr; } -String handle_link_name(CheckerContext *ctx, Token token, String link_name, String link_prefix) { +gb_internal String handle_link_name(CheckerContext *ctx, Token token, String link_name, String link_prefix) { if (link_prefix.len > 0) { if (link_name.len > 0) { error(token, "'link_name' and 'link_prefix' cannot be used together"); @@ -764,7 +764,7 @@ String handle_link_name(CheckerContext *ctx, Token token, String link_name, Stri return link_name; } -void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) { +gb_internal void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) { GB_ASSERT(e->type == nullptr); if (d->proc_lit->kind != Ast_ProcLit) { // TOOD(bill): Better error message @@ -1121,7 +1121,7 @@ void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) { } } -void check_global_variable_decl(CheckerContext *ctx, Entity *&e, Ast *type_expr, Ast *init_expr) { +gb_internal void check_global_variable_decl(CheckerContext *ctx, Entity *&e, Ast *type_expr, Ast *init_expr) { GB_ASSERT(e->type == nullptr); GB_ASSERT(e->kind == Entity_Variable); @@ -1239,7 +1239,7 @@ void check_global_variable_decl(CheckerContext *ctx, Entity *&e, Ast *type_expr, check_rtti_type_disallowed(e->token, e->type, "A variable declaration is using a type, %s, which has been disallowed"); } -void check_proc_group_decl(CheckerContext *ctx, Entity *&pg_entity, DeclInfo *d) { +gb_internal void check_proc_group_decl(CheckerContext *ctx, Entity *&pg_entity, DeclInfo *d) { GB_ASSERT(pg_entity->kind == Entity_ProcGroup); auto *pge = &pg_entity->ProcGroup; String proc_group_name = pg_entity->token.string; @@ -1367,7 +1367,7 @@ void check_proc_group_decl(CheckerContext *ctx, Entity *&pg_entity, DeclInfo *d) } -void check_entity_decl(CheckerContext *ctx, Entity *e, DeclInfo *d, Type *named_type) { +gb_internal void check_entity_decl(CheckerContext *ctx, Entity *e, DeclInfo *d, Type *named_type) { if (e->state == EntityState_Resolved) { return; } @@ -1437,7 +1437,7 @@ struct ProcUsingVar { }; -void check_proc_body(CheckerContext *ctx_, Token token, DeclInfo *decl, Type *type, Ast *body) { +gb_internal void check_proc_body(CheckerContext *ctx_, Token token, DeclInfo *decl, Type *type, Ast *body) { if (body == nullptr) { return; } diff --git a/src/check_expr.cpp b/src/check_expr.cpp index fbc4f8b63..3003e07b6 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -17,7 +17,7 @@ enum CallArgumentError { CallArgumentError_MAX, }; -char const *CallArgumentError_strings[CallArgumentError_MAX] = { +gb_global char const *CallArgumentError_strings[CallArgumentError_MAX] = { "None", "NoneProcedureType", "WrongTypes", @@ -57,7 +57,7 @@ struct ValidIndexAndScore { i64 score; }; -int valid_index_and_score_cmp(void const *a, void const *b) { +gb_internal int valid_index_and_score_cmp(void const *a, void const *b) { i64 si = (cast(ValidIndexAndScore const *)a)->score; i64 sj = (cast(ValidIndexAndScore const *)b)->score; return sj < si ? -1 : sj > si; @@ -70,56 +70,56 @@ typedef CALL_ARGUMENT_CHECKER(CallArgumentCheckerType); -void check_expr (CheckerContext *c, Operand *operand, Ast *expression); -void check_multi_expr (CheckerContext *c, Operand *operand, Ast *expression); -void check_multi_expr_or_type (CheckerContext *c, Operand *operand, Ast *expression); -void check_multi_expr_with_type_hint(CheckerContext *c, Operand *o, Ast *e, Type *type_hint); -void check_expr_or_type (CheckerContext *c, Operand *operand, Ast *expression, Type *type_hint); -ExprKind check_expr_base (CheckerContext *c, Operand *operand, Ast *expression, Type *type_hint); -void check_expr_with_type_hint (CheckerContext *c, Operand *o, Ast *e, Type *t); -Type * check_type (CheckerContext *c, Ast *expression); -Type * check_type_expr (CheckerContext *c, Ast *expression, Type *named_type); -Type * make_optional_ok_type (Type *value, bool typed=true); -Entity * check_selector (CheckerContext *c, Operand *operand, Ast *node, Type *type_hint); -Entity * check_ident (CheckerContext *c, Operand *o, Ast *n, Type *named_type, Type *type_hint, bool allow_import_name); -Entity * find_polymorphic_record_entity (CheckerContext *c, Type *original_type, isize param_count, Array const &ordered_operands, bool *failure); -void check_not_tuple (CheckerContext *c, Operand *operand); -void convert_to_typed (CheckerContext *c, Operand *operand, Type *target_type); -gbString expr_to_string (Ast *expression); -void check_proc_body (CheckerContext *c, Token token, DeclInfo *decl, Type *type, Ast *body); -void update_untyped_expr_type (CheckerContext *c, Ast *e, Type *type, bool final); -bool check_is_terminating (Ast *node, String const &label); -bool check_has_break (Ast *stmt, String const &label, bool implicit); -void check_stmt (CheckerContext *c, Ast *node, u32 flags); -void check_stmt_list (CheckerContext *c, Slice const &stmts, u32 flags); -void check_init_constant (CheckerContext *c, Entity *e, Operand *operand); -bool check_representable_as_constant(CheckerContext *c, ExactValue in_value, Type *type, ExactValue *out_value); -bool check_procedure_type (CheckerContext *c, Type *type, Ast *proc_type_node, Array *operands = nullptr); -void check_struct_type (CheckerContext *c, Type *struct_type, Ast *node, Array *poly_operands, - Type *named_type = nullptr, Type *original_type_for_poly = nullptr); -void check_union_type (CheckerContext *c, Type *union_type, Ast *node, Array *poly_operands, - Type *named_type = nullptr, Type *original_type_for_poly = nullptr); +gb_internal void check_expr (CheckerContext *c, Operand *operand, Ast *expression); +gb_internal void check_multi_expr (CheckerContext *c, Operand *operand, Ast *expression); +gb_internal void check_multi_expr_or_type (CheckerContext *c, Operand *operand, Ast *expression); +gb_internal void check_multi_expr_with_type_hint(CheckerContext *c, Operand *o, Ast *e, Type *type_hint); +gb_internal void check_expr_or_type (CheckerContext *c, Operand *operand, Ast *expression, Type *type_hint); +gb_internal ExprKind check_expr_base (CheckerContext *c, Operand *operand, Ast *expression, Type *type_hint); +gb_internal void check_expr_with_type_hint (CheckerContext *c, Operand *o, Ast *e, Type *t); +gb_internal Type * check_type (CheckerContext *c, Ast *expression); +gb_internal Type * check_type_expr (CheckerContext *c, Ast *expression, Type *named_type); +gb_internal Type * make_optional_ok_type (Type *value, bool typed=true); +gb_internal Entity * check_selector (CheckerContext *c, Operand *operand, Ast *node, Type *type_hint); +gb_internal Entity * check_ident (CheckerContext *c, Operand *o, Ast *n, Type *named_type, Type *type_hint, bool allow_import_name); +gb_internal Entity * find_polymorphic_record_entity (CheckerContext *c, Type *original_type, isize param_count, Array const &ordered_operands, bool *failure); +gb_internal void check_not_tuple (CheckerContext *c, Operand *operand); +gb_internal void convert_to_typed (CheckerContext *c, Operand *operand, Type *target_type); +gb_internal gbString expr_to_string (Ast *expression); +gb_internal void check_proc_body (CheckerContext *c, Token token, DeclInfo *decl, Type *type, Ast *body); +gb_internal void update_untyped_expr_type (CheckerContext *c, Ast *e, Type *type, bool final); +gb_internal bool check_is_terminating (Ast *node, String const &label); +gb_internal bool check_has_break (Ast *stmt, String const &label, bool implicit); +gb_internal void check_stmt (CheckerContext *c, Ast *node, u32 flags); +gb_internal void check_stmt_list (CheckerContext *c, Slice const &stmts, u32 flags); +gb_internal void check_init_constant (CheckerContext *c, Entity *e, Operand *operand); +gb_internal bool check_representable_as_constant(CheckerContext *c, ExactValue in_value, Type *type, ExactValue *out_value); +gb_internal bool check_procedure_type (CheckerContext *c, Type *type, Ast *proc_type_node, Array *operands = nullptr); +gb_internal void check_struct_type (CheckerContext *c, Type *struct_type, Ast *node, Array *poly_operands, + Type *named_type = nullptr, Type *original_type_for_poly = nullptr); +gb_internal void check_union_type (CheckerContext *c, Type *union_type, Ast *node, Array *poly_operands, + Type *named_type = nullptr, Type *original_type_for_poly = nullptr); -CallArgumentData check_call_arguments (CheckerContext *c, Operand *operand, Type *proc_type, Ast *call); -Type * check_init_variable (CheckerContext *c, Entity *e, Operand *operand, String context_name); +gb_internal CallArgumentData check_call_arguments (CheckerContext *c, Operand *operand, Type *proc_type, Ast *call); +gb_internal Type * check_init_variable (CheckerContext *c, Entity *e, Operand *operand, String context_name); -void check_assignment_error_suggestion(CheckerContext *c, Operand *o, Type *type); -void add_map_key_type_dependencies(CheckerContext *ctx, Type *key); +gb_internal void check_assignment_error_suggestion(CheckerContext *c, Operand *o, Type *type); +gb_internal void add_map_key_type_dependencies(CheckerContext *ctx, Type *key); -Type *make_soa_struct_slice(CheckerContext *ctx, Ast *array_typ_expr, Ast *elem_expr, Type *elem); -Type *make_soa_struct_dynamic_array(CheckerContext *ctx, Ast *array_typ_expr, Ast *elem_expr, Type *elem); +gb_internal Type *make_soa_struct_slice(CheckerContext *ctx, Ast *array_typ_expr, Ast *elem_expr, Type *elem); +gb_internal Type *make_soa_struct_dynamic_array(CheckerContext *ctx, Ast *array_typ_expr, Ast *elem_expr, Type *elem); -bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32 id, Type *type_hint); +gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32 id, Type *type_hint); -void check_promote_optional_ok(CheckerContext *c, Operand *x, Type **val_type_, Type **ok_type_); +gb_internal void check_promote_optional_ok(CheckerContext *c, Operand *x, Type **val_type_, Type **ok_type_); -void check_or_else_right_type(CheckerContext *c, Ast *expr, String const &name, Type *right_type); -void check_or_else_split_types(CheckerContext *c, Operand *x, String const &name, Type **left_type_, Type **right_type_); -void check_or_else_expr_no_value_error(CheckerContext *c, String const &name, Operand const &x, Type *type_hint); -void check_or_return_split_types(CheckerContext *c, Operand *x, String const &name, Type **left_type_, Type **right_type_); +gb_internal void check_or_else_right_type(CheckerContext *c, Ast *expr, String const &name, Type *right_type); +gb_internal void check_or_else_split_types(CheckerContext *c, Operand *x, String const &name, Type **left_type_, Type **right_type_); +gb_internal void check_or_else_expr_no_value_error(CheckerContext *c, String const &name, Operand const &x, Type *type_hint); +gb_internal void check_or_return_split_types(CheckerContext *c, Operand *x, String const &name, Type **left_type_, Type **right_type_); -bool is_diverging_expr(Ast *expr); +gb_internal bool is_diverging_expr(Ast *expr); enum LoadDirectiveResult { @@ -128,7 +128,7 @@ enum LoadDirectiveResult { LoadDirective_NotFound = 2, }; -bool is_load_directive_call(Ast *call) { +gb_internal bool is_load_directive_call(Ast *call) { call = unparen_expr(call); if (call->kind != Ast_CallExpr) { return false; @@ -141,9 +141,9 @@ bool is_load_directive_call(Ast *call) { String name = bd->name.string; return name == "load"; } -LoadDirectiveResult check_load_directive(CheckerContext *c, Operand *operand, Ast *call, Type *type_hint, bool err_on_not_found); +gb_internal LoadDirectiveResult check_load_directive(CheckerContext *c, Operand *operand, Ast *call, Type *type_hint, bool err_on_not_found); -void check_did_you_mean_print(DidYouMeanAnswers *d, char const *prefix = "") { +gb_internal void check_did_you_mean_print(DidYouMeanAnswers *d, char const *prefix = "") { auto results = did_you_mean_results(d); if (results.count != 0) { error_line("\tSuggestion: Did you mean?\n"); @@ -155,7 +155,7 @@ void check_did_you_mean_print(DidYouMeanAnswers *d, char const *prefix = "") { } } -void populate_check_did_you_mean_objc_entity(StringSet *set, Entity *e, bool is_type) { +gb_internal void populate_check_did_you_mean_objc_entity(StringSet *set, Entity *e, bool is_type) { if (e->kind != Entity_TypeName) { return; } @@ -189,7 +189,7 @@ void populate_check_did_you_mean_objc_entity(StringSet *set, Entity *e, bool is_ } -void check_did_you_mean_objc_entity(String const &name, Entity *e, bool is_type, char const *prefix = "") { +gb_internal void check_did_you_mean_objc_entity(String const &name, Entity *e, bool is_type, char const *prefix = "") { ERROR_BLOCK(); GB_ASSERT(e->kind == Entity_TypeName); GB_ASSERT(e->TypeName.objc_metadata != nullptr); @@ -211,7 +211,7 @@ void check_did_you_mean_objc_entity(String const &name, Entity *e, bool is_type, check_did_you_mean_print(&d, prefix); } -void check_did_you_mean_type(String const &name, Array const &fields, char const *prefix = "") { +gb_internal void check_did_you_mean_type(String const &name, Array const &fields, char const *prefix = "") { ERROR_BLOCK(); DidYouMeanAnswers d = did_you_mean_make(heap_allocator(), fields.count, name); @@ -224,7 +224,7 @@ void check_did_you_mean_type(String const &name, Array const &fields, } -void check_did_you_mean_type(String const &name, Slice const &fields, char const *prefix = "") { +gb_internal void check_did_you_mean_type(String const &name, Slice const &fields, char const *prefix = "") { ERROR_BLOCK(); DidYouMeanAnswers d = did_you_mean_make(heap_allocator(), fields.count, name); @@ -236,7 +236,7 @@ void check_did_you_mean_type(String const &name, Slice const &fields, check_did_you_mean_print(&d, prefix); } -void check_did_you_mean_scope(String const &name, Scope *scope, char const *prefix = "") { +gb_internal void check_did_you_mean_scope(String const &name, Scope *scope, char const *prefix = "") { ERROR_BLOCK(); DidYouMeanAnswers d = did_you_mean_make(heap_allocator(), scope->elements.entries.count, name); @@ -249,7 +249,7 @@ void check_did_you_mean_scope(String const &name, Scope *scope, char const *pref check_did_you_mean_print(&d, prefix); } -Entity *entity_from_expr(Ast *expr) { +gb_internal Entity *entity_from_expr(Ast *expr) { expr = unparen_expr(expr); switch (expr->kind) { case Ast_Ident: @@ -260,7 +260,7 @@ Entity *entity_from_expr(Ast *expr) { return nullptr; } -void error_operand_not_expression(Operand *o) { +gb_internal void error_operand_not_expression(Operand *o) { if (o->mode == Addressing_Type) { gbString err = expr_to_string(o->expr); error(o->expr, "'%s' is not an expression but a type", err); @@ -269,7 +269,7 @@ void error_operand_not_expression(Operand *o) { } } -void error_operand_no_value(Operand *o) { +gb_internal void error_operand_no_value(Operand *o) { if (o->mode == Addressing_NoValue) { gbString err = expr_to_string(o->expr); Ast *x = unparen_expr(o->expr); @@ -283,7 +283,7 @@ void error_operand_no_value(Operand *o) { } } -void add_map_get_dependencies(CheckerContext *c) { +gb_internal void add_map_get_dependencies(CheckerContext *c) { if (build_context.use_static_map_calls) { add_package_dependency(c, "runtime", "map_desired_position"); add_package_dependency(c, "runtime", "map_probe_distance"); @@ -292,7 +292,7 @@ void add_map_get_dependencies(CheckerContext *c) { } } -void add_map_set_dependencies(CheckerContext *c) { +gb_internal void add_map_set_dependencies(CheckerContext *c) { init_core_source_code_location(c->checker); if (t_map_set_proc == nullptr) { @@ -308,14 +308,14 @@ void add_map_set_dependencies(CheckerContext *c) { } } -void add_map_reserve_dependencies(CheckerContext *c) { +gb_internal void add_map_reserve_dependencies(CheckerContext *c) { init_core_source_code_location(c->checker); add_package_dependency(c, "runtime", "__dynamic_map_reserve"); } -void check_scope_decls(CheckerContext *c, Slice const &nodes, isize reserve_size) { +gb_internal void check_scope_decls(CheckerContext *c, Slice const &nodes, isize reserve_size) { Scope *s = c->scope; check_collect_entities(c, nodes); @@ -337,8 +337,8 @@ void check_scope_decls(CheckerContext *c, Slice const &nodes, isize reser } } -bool find_or_generate_polymorphic_procedure(CheckerContext *old_c, Entity *base_entity, Type *type, - Array *param_operands, Ast *poly_def_node, PolyProcData *poly_proc_data) { +gb_internal bool find_or_generate_polymorphic_procedure(CheckerContext *old_c, Entity *base_entity, Type *type, + Array *param_operands, Ast *poly_def_node, PolyProcData *poly_proc_data) { /////////////////////////////////////////////////////////////////////////////// // // // TODO CLEANUP(bill): This procedure is very messy and hacky. Clean this!!! // @@ -571,24 +571,24 @@ bool find_or_generate_polymorphic_procedure(CheckerContext *old_c, Entity *base_ return true; } -bool check_polymorphic_procedure_assignment(CheckerContext *c, Operand *operand, Type *type, Ast *poly_def_node, PolyProcData *poly_proc_data) { +gb_internal bool check_polymorphic_procedure_assignment(CheckerContext *c, Operand *operand, Type *type, Ast *poly_def_node, PolyProcData *poly_proc_data) { if (operand->expr == nullptr) return false; Entity *base_entity = entity_of_node(operand->expr); if (base_entity == nullptr) return false; return find_or_generate_polymorphic_procedure(c, base_entity, type, nullptr, poly_def_node, poly_proc_data); } -bool find_or_generate_polymorphic_procedure_from_parameters(CheckerContext *c, Entity *base_entity, Array *operands, Ast *poly_def_node, PolyProcData *poly_proc_data) { +gb_internal bool find_or_generate_polymorphic_procedure_from_parameters(CheckerContext *c, Entity *base_entity, Array *operands, Ast *poly_def_node, PolyProcData *poly_proc_data) { return find_or_generate_polymorphic_procedure(c, base_entity, nullptr, operands, poly_def_node, poly_proc_data); } -bool check_type_specialization_to(CheckerContext *c, Type *specialization, Type *type, bool compound, bool modify_type); -bool is_polymorphic_type_assignable(CheckerContext *c, Type *poly, Type *source, bool compound, bool modify_type); -bool check_cast_internal(CheckerContext *c, Operand *x, Type *type); +gb_internal bool check_type_specialization_to(CheckerContext *c, Type *specialization, Type *type, bool compound, bool modify_type); +gb_internal bool is_polymorphic_type_assignable(CheckerContext *c, Type *poly, Type *source, bool compound, bool modify_type); +gb_internal bool check_cast_internal(CheckerContext *c, Operand *x, Type *type); #define MAXIMUM_TYPE_DISTANCE 10 -i64 check_distance_between_types(CheckerContext *c, Operand *operand, Type *type) { +gb_internal i64 check_distance_between_types(CheckerContext *c, Operand *operand, Type *type) { if (c == nullptr) { GB_ASSERT(operand->mode == Addressing_Value); GB_ASSERT(is_type_typed(operand->type)); @@ -887,7 +887,7 @@ i64 check_distance_between_types(CheckerContext *c, Operand *operand, Type *type } -i64 assign_score_function(i64 distance, bool is_variadic=false) { +gb_internal i64 assign_score_function(i64 distance, bool is_variadic=false) { // 3*x^2 + 1 > x^2 + x + 1 (for positive x) i64 const c = 3*MAXIMUM_TYPE_DISTANCE*MAXIMUM_TYPE_DISTANCE + 1; @@ -900,7 +900,7 @@ i64 assign_score_function(i64 distance, bool is_variadic=false) { } -bool check_is_assignable_to_with_score(CheckerContext *c, Operand *operand, Type *type, i64 *score_, bool is_variadic=false) { +gb_internal bool check_is_assignable_to_with_score(CheckerContext *c, Operand *operand, Type *type, i64 *score_, bool is_variadic=false) { i64 score = 0; i64 distance = check_distance_between_types(c, operand, type); bool ok = distance >= 0; @@ -912,19 +912,19 @@ bool check_is_assignable_to_with_score(CheckerContext *c, Operand *operand, Type } -bool check_is_assignable_to(CheckerContext *c, Operand *operand, Type *type) { +gb_internal bool check_is_assignable_to(CheckerContext *c, Operand *operand, Type *type) { i64 score = 0; return check_is_assignable_to_with_score(c, operand, type, &score); } -bool internal_check_is_assignable_to(Type *src, Type *dst) { +gb_internal bool internal_check_is_assignable_to(Type *src, Type *dst) { Operand x = {}; x.type = src; x.mode = Addressing_Value; return check_is_assignable_to(nullptr, &x, dst); } -AstPackage *get_package_of_type(Type *type) { +gb_internal AstPackage *get_package_of_type(Type *type) { for (;;) { if (type == nullptr) { return nullptr; @@ -962,7 +962,7 @@ AstPackage *get_package_of_type(Type *type) { // NOTE(bill): 'content_name' is for debugging and error messages -void check_assignment(CheckerContext *c, Operand *operand, Type *type, String context_name) { +gb_internal void check_assignment(CheckerContext *c, Operand *operand, Type *type, String context_name) { check_not_tuple(c, operand); if (operand->mode == Addressing_Invalid) { return; @@ -1110,7 +1110,7 @@ void check_assignment(CheckerContext *c, Operand *operand, Type *type, String co } } -bool polymorphic_assign_index(Type **gt_, i64 *dst_count, i64 source_count) { +gb_internal bool polymorphic_assign_index(Type **gt_, i64 *dst_count, i64 source_count) { Type *gt = *gt_; GB_ASSERT(gt->kind == Type_Generic); @@ -1139,7 +1139,7 @@ bool polymorphic_assign_index(Type **gt_, i64 *dst_count, i64 source_count) { return false; } -bool is_polymorphic_type_assignable(CheckerContext *c, Type *poly, Type *source, bool compound, bool modify_type) { +gb_internal bool is_polymorphic_type_assignable(CheckerContext *c, Type *poly, Type *source, bool compound, bool modify_type) { Operand o = {Addressing_Value}; o.type = source; switch (poly->kind) { @@ -1439,7 +1439,7 @@ bool is_polymorphic_type_assignable(CheckerContext *c, Type *poly, Type *source, return false; } -bool check_cycle(CheckerContext *c, Entity *curr, bool report) { +gb_internal bool check_cycle(CheckerContext *c, Entity *curr, bool report) { if (curr->state != EntityState_InProgress) { return false; } @@ -1461,7 +1461,7 @@ bool check_cycle(CheckerContext *c, Entity *curr, bool report) { return false; } -Entity *check_ident(CheckerContext *c, Operand *o, Ast *n, Type *named_type, Type *type_hint, bool allow_import_name) { +gb_internal Entity *check_ident(CheckerContext *c, Operand *o, Ast *n, Type *named_type, Type *type_hint, bool allow_import_name) { GB_ASSERT(n->kind == Ast_Ident); o->mode = Addressing_Invalid; o->expr = n; @@ -1630,7 +1630,7 @@ Entity *check_ident(CheckerContext *c, Operand *o, Ast *n, Type *named_type, Typ } -bool check_unary_op(CheckerContext *c, Operand *o, Token op) { +gb_internal bool check_unary_op(CheckerContext *c, Operand *o, Token op) { if (o->type == nullptr) { gbString str = expr_to_string(o->expr); error(o->expr, "Expression has no value '%s'", str); @@ -1672,7 +1672,7 @@ bool check_unary_op(CheckerContext *c, Operand *o, Token op) { return true; } -bool check_binary_op(CheckerContext *c, Operand *o, Token op) { +gb_internal bool check_binary_op(CheckerContext *c, Operand *o, Token op) { Type *main_type = o->type; // TODO(bill): Handle errors correctly @@ -1783,7 +1783,7 @@ bool check_binary_op(CheckerContext *c, Operand *o, Token op) { } -bool check_representable_as_constant(CheckerContext *c, ExactValue in_value, Type *type, ExactValue *out_value) { +gb_internal bool check_representable_as_constant(CheckerContext *c, ExactValue in_value, Type *type, ExactValue *out_value) { if (in_value.kind == ExactValue_Invalid) { // NOTE(bill): There's already been an error return true; @@ -1998,7 +1998,7 @@ bool check_representable_as_constant(CheckerContext *c, ExactValue in_value, Typ } -void check_assignment_error_suggestion(CheckerContext *c, Operand *o, Type *type) { +gb_internal void check_assignment_error_suggestion(CheckerContext *c, Operand *o, Type *type) { gbString a = expr_to_string(o->expr); gbString b = type_to_string(type); defer( @@ -2032,7 +2032,7 @@ void check_assignment_error_suggestion(CheckerContext *c, Operand *o, Type *type } } -void check_cast_error_suggestion(CheckerContext *c, Operand *o, Type *type) { +gb_internal void check_cast_error_suggestion(CheckerContext *c, Operand *o, Type *type) { gbString a = expr_to_string(o->expr); gbString b = type_to_string(type); defer( @@ -2074,7 +2074,7 @@ void check_cast_error_suggestion(CheckerContext *c, Operand *o, Type *type) { } -bool check_is_expressible(CheckerContext *ctx, Operand *o, Type *type) { +gb_internal bool check_is_expressible(CheckerContext *ctx, Operand *o, Type *type) { GB_ASSERT(o->mode == Addressing_Constant); ExactValue out_value = o->value; if (is_type_constant_type(type) && check_representable_as_constant(ctx, o->value, type, &out_value)) { @@ -2112,7 +2112,7 @@ bool check_is_expressible(CheckerContext *ctx, Operand *o, Type *type) { } } -bool check_is_not_addressable(CheckerContext *c, Operand *o) { +gb_internal bool check_is_not_addressable(CheckerContext *c, Operand *o) { if (o->mode == Addressing_OptionalOk) { Ast *expr = unselector_expr(o->expr); if (expr->kind != Ast_TypeAssertion) { @@ -2143,7 +2143,7 @@ bool check_is_not_addressable(CheckerContext *c, Operand *o) { return o->mode != Addressing_Variable && o->mode != Addressing_SoaVariable; } -void check_unary_expr(CheckerContext *c, Operand *o, Token op, Ast *node) { +gb_internal void check_unary_expr(CheckerContext *c, Operand *o, Token op, Ast *node) { switch (op.kind) { case Token_And: { // Pointer address if (check_is_not_addressable(c, o)) { @@ -2270,7 +2270,7 @@ void check_unary_expr(CheckerContext *c, Operand *o, Token op, Ast *node) { o->mode = Addressing_Value; } -void add_comparison_procedures_for_fields(CheckerContext *c, Type *t) { +gb_internal void add_comparison_procedures_for_fields(CheckerContext *c, Type *t) { if (t == nullptr) { return; } @@ -2323,7 +2323,7 @@ void add_comparison_procedures_for_fields(CheckerContext *c, Type *t) { } -void check_comparison(CheckerContext *c, Operand *x, Operand *y, TokenKind op) { +gb_internal void check_comparison(CheckerContext *c, Operand *x, Operand *y, TokenKind op) { if (x->mode == Addressing_Type && y->mode == Addressing_Type) { bool comp = are_types_identical(x->type, y->type); switch (op) { @@ -2516,7 +2516,7 @@ void check_comparison(CheckerContext *c, Operand *x, Operand *y, TokenKind op) { } -void check_shift(CheckerContext *c, Operand *x, Operand *y, Ast *node, Type *type_hint) { +gb_internal void check_shift(CheckerContext *c, Operand *x, Operand *y, Ast *node, Type *type_hint) { GB_ASSERT(node->kind == Ast_BinaryExpr); ast_node(be, BinaryExpr, node); @@ -2635,7 +2635,7 @@ void check_shift(CheckerContext *c, Operand *x, Operand *y, Ast *node, Type *typ -bool check_is_castable_to(CheckerContext *c, Operand *operand, Type *y) { +gb_internal bool check_is_castable_to(CheckerContext *c, Operand *operand, Type *y) { if (check_is_assignable_to(c, operand, y)) { return true; } @@ -2851,7 +2851,7 @@ bool check_is_castable_to(CheckerContext *c, Operand *operand, Type *y) { return false; } -bool check_cast_internal(CheckerContext *c, Operand *x, Type *type) { +gb_internal bool check_cast_internal(CheckerContext *c, Operand *x, Type *type) { bool is_const_expr = x->mode == Addressing_Constant; Type *bt = base_type(type); @@ -2886,7 +2886,7 @@ bool check_cast_internal(CheckerContext *c, Operand *x, Type *type) { } -void check_cast(CheckerContext *c, Operand *x, Type *type) { +gb_internal void check_cast(CheckerContext *c, Operand *x, Type *type) { if (!is_operand_value(*x)) { error(x->expr, "Only values can be casted"); x->mode = Addressing_Invalid; @@ -2930,7 +2930,7 @@ void check_cast(CheckerContext *c, Operand *x, Type *type) { x->type = type; } -bool check_transmute(CheckerContext *c, Ast *node, Operand *o, Type *t) { +gb_internal bool check_transmute(CheckerContext *c, Ast *node, Operand *o, Type *t) { if (!is_operand_value(*o)) { error(o->expr, "'transmute' can only be applied to values"); o->mode = Addressing_Invalid; @@ -3043,7 +3043,7 @@ bool check_transmute(CheckerContext *c, Ast *node, Operand *o, Type *t) { return true; } -bool check_binary_array_expr(CheckerContext *c, Token op, Operand *x, Operand *y) { +gb_internal bool check_binary_array_expr(CheckerContext *c, Token op, Operand *x, Operand *y) { if (is_type_array(x->type) && !is_type_array(y->type)) { if (check_is_assignable_to(c, y, x->type)) { if (check_binary_op(c, x, op)) { @@ -3054,19 +3054,19 @@ bool check_binary_array_expr(CheckerContext *c, Token op, Operand *x, Operand *y return false; } -bool is_ise_expr(Ast *node) { +gb_internal bool is_ise_expr(Ast *node) { node = unparen_expr(node); return node->kind == Ast_ImplicitSelectorExpr; } -bool can_use_other_type_as_type_hint(bool use_lhs_as_type_hint, Type *other_type) { +gb_internal bool can_use_other_type_as_type_hint(bool use_lhs_as_type_hint, Type *other_type) { if (use_lhs_as_type_hint) { // RHS in this case return other_type != nullptr && other_type != t_invalid && is_type_typed(other_type); } return false; } -Type *check_matrix_type_hint(Type *matrix, Type *type_hint) { +gb_internal Type *check_matrix_type_hint(Type *matrix, Type *type_hint) { Type *xt = base_type(matrix); if (type_hint != nullptr) { Type *th = base_type(type_hint); @@ -3086,7 +3086,7 @@ Type *check_matrix_type_hint(Type *matrix, Type *type_hint) { } -void check_binary_matrix(CheckerContext *c, Token const &op, Operand *x, Operand *y, Type *type_hint, bool use_lhs_as_type_hint) { +gb_internal void check_binary_matrix(CheckerContext *c, Token const &op, Operand *x, Operand *y, Type *type_hint, bool use_lhs_as_type_hint) { if (!check_binary_op(c, x, op)) { x->mode = Addressing_Invalid; return; @@ -3197,7 +3197,7 @@ matrix_error: } -void check_binary_expr(CheckerContext *c, Operand *x, Ast *node, Type *type_hint, bool use_lhs_as_type_hint=false) { +gb_internal void check_binary_expr(CheckerContext *c, Operand *x, Ast *node, Type *type_hint, bool use_lhs_as_type_hint=false) { GB_ASSERT(node->kind == Ast_BinaryExpr); Operand y_ = {}, *y = &y_; @@ -3563,7 +3563,7 @@ void check_binary_expr(CheckerContext *c, Operand *x, Ast *node, Type *type_hint x->mode = Addressing_Value; } -Operand make_operand_from_node(Ast *node) { +gb_internal Operand make_operand_from_node(Ast *node) { GB_ASSERT(node != nullptr); Operand x = {}; x.expr = node; @@ -3574,7 +3574,7 @@ Operand make_operand_from_node(Ast *node) { } -void update_untyped_expr_type(CheckerContext *c, Ast *e, Type *type, bool final) { +gb_internal void update_untyped_expr_type(CheckerContext *c, Ast *e, Type *type, bool final) { GB_ASSERT(e != nullptr); ExprInfo *old = check_get_expr_info(c, e); if (old == nullptr) { @@ -3689,7 +3689,7 @@ void update_untyped_expr_type(CheckerContext *c, Ast *e, Type *type, bool final) add_type_and_value(c->info, e, old->mode, type, old->value); } -void update_untyped_expr_value(CheckerContext *c, Ast *e, ExactValue value) { +gb_internal void update_untyped_expr_value(CheckerContext *c, Ast *e, ExactValue value) { GB_ASSERT(e != nullptr); ExprInfo *found = check_get_expr_info(c, e); if (found) { @@ -3697,7 +3697,7 @@ void update_untyped_expr_value(CheckerContext *c, Ast *e, ExactValue value) { } } -void convert_untyped_error(CheckerContext *c, Operand *operand, Type *target_type) { +gb_internal void convert_untyped_error(CheckerContext *c, Operand *operand, Type *target_type) { gbString expr_str = expr_to_string(operand->expr); gbString type_str = type_to_string(target_type); gbString from_type_str = type_to_string(operand->type); @@ -3728,7 +3728,7 @@ void convert_untyped_error(CheckerContext *c, Operand *operand, Type *target_typ operand->mode = Addressing_Invalid; } -ExactValue convert_exact_value_for_type(ExactValue v, Type *type) { +gb_internal ExactValue convert_exact_value_for_type(ExactValue v, Type *type) { Type *t = core_type(type); if (is_type_boolean(t)) { // v = exact_value_to_boolean(v); @@ -3746,7 +3746,7 @@ ExactValue convert_exact_value_for_type(ExactValue v, Type *type) { return v; } -void convert_to_typed(CheckerContext *c, Operand *operand, Type *target_type) { +gb_internal void convert_to_typed(CheckerContext *c, Operand *operand, Type *target_type) { GB_ASSERT_NOT_NULL(target_type); if (operand->mode == Addressing_Invalid || operand->mode == Addressing_Type || @@ -3995,7 +3995,7 @@ void convert_to_typed(CheckerContext *c, Operand *operand, Type *target_type) { operand->type = target_type; } -bool check_index_value(CheckerContext *c, Type *main_type, bool open_range, Ast *index_value, i64 max_count, i64 *value, Type *type_hint=nullptr) { +gb_internal bool check_index_value(CheckerContext *c, Type *main_type, bool open_range, Ast *index_value, i64 max_count, i64 *value, Type *type_hint=nullptr) { Operand operand = {Addressing_Invalid}; check_expr_with_type_hint(c, &operand, index_value, type_hint); if (operand.mode == Addressing_Invalid) { @@ -4121,7 +4121,7 @@ bool check_index_value(CheckerContext *c, Type *main_type, bool open_range, Ast return true; } -ExactValue get_constant_field_single(CheckerContext *c, ExactValue value, i32 index, bool *success_, bool *finish_) { +gb_internal ExactValue get_constant_field_single(CheckerContext *c, ExactValue value, i32 index, bool *success_, bool *finish_) { if (value.kind == ExactValue_String) { GB_ASSERT(0 <= index && index < value.value_string.len); u8 val = value.value_string[index]; @@ -4269,7 +4269,7 @@ ExactValue get_constant_field_single(CheckerContext *c, ExactValue value, i32 in -ExactValue get_constant_field(CheckerContext *c, Operand const *operand, Selection sel, bool *success_) { +gb_internal ExactValue get_constant_field(CheckerContext *c, Operand const *operand, Selection sel, bool *success_) { if (operand->mode != Addressing_Constant) { if (success_) *success_ = false; return empty_exact_value; @@ -4349,7 +4349,7 @@ ExactValue get_constant_field(CheckerContext *c, Operand const *operand, Selecti return empty_exact_value; } -Type *determine_swizzle_array_type(Type *original_type, Type *type_hint, isize new_count) { +gb_internal Type *determine_swizzle_array_type(Type *original_type, Type *type_hint, isize new_count) { Type *array_type = base_type(type_deref(original_type)); GB_ASSERT(array_type->kind == Type_Array || array_type->kind == Type_SimdVector); if (array_type->kind == Type_SimdVector) { @@ -4376,7 +4376,7 @@ Type *determine_swizzle_array_type(Type *original_type, Type *type_hint, isize n } -bool is_entity_declared_for_selector(Entity *entity, Scope *import_scope, bool *allow_builtin) { +gb_internal bool is_entity_declared_for_selector(Entity *entity, Scope *import_scope, bool *allow_builtin) { bool is_declared = entity != nullptr; if (is_declared) { if (entity->kind == Entity_Builtin) { @@ -4391,7 +4391,7 @@ bool is_entity_declared_for_selector(Entity *entity, Scope *import_scope, bool * } // NOTE(bill, 2022-02-03): see `check_const_decl` for why it exists reasoning -Entity *check_entity_from_ident_or_selector(CheckerContext *c, Ast *node, bool ident_only) { +gb_internal Entity *check_entity_from_ident_or_selector(CheckerContext *c, Ast *node, bool ident_only) { if (node->kind == Ast_Ident) { String name = node->Ident.token.string; return scope_lookup(c->scope, name); @@ -4471,7 +4471,7 @@ Entity *check_entity_from_ident_or_selector(CheckerContext *c, Ast *node, bool i } -Entity *check_selector(CheckerContext *c, Operand *operand, Ast *node, Type *type_hint) { +gb_internal Entity *check_selector(CheckerContext *c, Operand *operand, Ast *node, Type *type_hint) { ast_node(se, SelectorExpr, node); bool check_op_expr = true; @@ -4865,7 +4865,7 @@ Entity *check_selector(CheckerContext *c, Operand *operand, Ast *node, Type *typ return entity; } -bool is_type_normal_pointer(Type *ptr, Type **elem) { +gb_internal bool is_type_normal_pointer(Type *ptr, Type **elem) { ptr = base_type(ptr); if (is_type_pointer(ptr)) { if (is_type_rawptr(ptr)) { @@ -4877,7 +4877,7 @@ bool is_type_normal_pointer(Type *ptr, Type **elem) { return false; } -bool check_identifier_exists(Scope *s, Ast *node, bool nested = false, Scope **out_scope = nullptr) { +gb_internal bool check_identifier_exists(Scope *s, Ast *node, bool nested = false, Scope **out_scope = nullptr) { switch (node->kind) { case_ast_node(i, Ident, node); String name = i->token.string; @@ -4907,7 +4907,7 @@ bool check_identifier_exists(Scope *s, Ast *node, bool nested = false, Scope **o return false; } -isize add_dependencies_from_unpacking(CheckerContext *c, Entity **lhs, isize lhs_count, isize tuple_index, isize tuple_count) { +gb_internal isize add_dependencies_from_unpacking(CheckerContext *c, Entity **lhs, isize lhs_count, isize tuple_index, isize tuple_count) { if (lhs != nullptr && c->decl != nullptr) { mutex_lock(&c->info->deps_mutex); @@ -4930,7 +4930,7 @@ isize add_dependencies_from_unpacking(CheckerContext *c, Entity **lhs, isize lhs } -bool check_assignment_arguments(CheckerContext *ctx, Array const &lhs, Array *operands, Slice const &rhs) { +gb_internal bool check_assignment_arguments(CheckerContext *ctx, Array const &lhs, Array *operands, Slice const &rhs) { bool optional_ok = false; isize tuple_index = 0; for_array(i, rhs) { @@ -5011,7 +5011,7 @@ bool check_assignment_arguments(CheckerContext *ctx, Array const &lhs, -bool check_unpack_arguments(CheckerContext *ctx, Entity **lhs, isize lhs_count, Array *operands, Slice const &rhs, bool allow_ok, bool is_variadic) { +gb_internal bool check_unpack_arguments(CheckerContext *ctx, Entity **lhs, isize lhs_count, Array *operands, Slice const &rhs, bool allow_ok, bool is_variadic) { bool optional_ok = false; isize tuple_index = 0; for_array(i, rhs) { @@ -5104,7 +5104,7 @@ bool check_unpack_arguments(CheckerContext *ctx, Entity **lhs, isize lhs_count, } -bool is_expr_constant_zero(Ast *expr) { +gb_internal bool is_expr_constant_zero(Ast *expr) { GB_ASSERT(expr != nullptr); auto v = exact_value_to_integer(expr->tav.value); if (v.kind == ExactValue_Integer) { @@ -5113,7 +5113,7 @@ bool is_expr_constant_zero(Ast *expr) { return false; } -isize get_procedure_param_count_excluding_defaults(Type *pt, isize *param_count_) { +gb_internal isize get_procedure_param_count_excluding_defaults(Type *pt, isize *param_count_) { GB_ASSERT(pt != nullptr); GB_ASSERT(pt->kind == Type_Proc); isize param_count = 0; @@ -5167,7 +5167,7 @@ isize get_procedure_param_count_excluding_defaults(Type *pt, isize *param_count_ } -CALL_ARGUMENT_CHECKER(check_call_arguments_internal) { +gb_internal CALL_ARGUMENT_CHECKER(check_call_arguments_internal) { ast_node(ce, CallExpr, call); GB_ASSERT(is_type_proc(proc_type)); proc_type = base_type(proc_type); @@ -5406,7 +5406,7 @@ CALL_ARGUMENT_CHECKER(check_call_arguments_internal) { return err; } -bool is_call_expr_field_value(AstCallExpr *ce) { +gb_internal bool is_call_expr_field_value(AstCallExpr *ce) { GB_ASSERT(ce != nullptr); if (ce->args.count == 0) { @@ -5415,7 +5415,7 @@ bool is_call_expr_field_value(AstCallExpr *ce) { return ce->args[0]->kind == Ast_FieldValue; } -isize lookup_procedure_parameter(TypeProc *pt, String parameter_name) { +gb_internal isize lookup_procedure_parameter(TypeProc *pt, String parameter_name) { isize param_count = pt->param_count; for (isize i = 0; i < param_count; i++) { Entity *e = pt->params->Tuple.variables[i]; @@ -5429,7 +5429,7 @@ isize lookup_procedure_parameter(TypeProc *pt, String parameter_name) { } return -1; } -isize lookup_procedure_result(TypeProc *pt, String result_name) { +gb_internal isize lookup_procedure_result(TypeProc *pt, String result_name) { isize result_count = pt->result_count; for (isize i = 0; i < result_count; i++) { Entity *e = pt->results->Tuple.variables[i]; @@ -5444,7 +5444,7 @@ isize lookup_procedure_result(TypeProc *pt, String result_name) { return -1; } -CALL_ARGUMENT_CHECKER(check_named_call_arguments) { +gb_internal CALL_ARGUMENT_CHECKER(check_named_call_arguments) { ast_node(ce, CallExpr, call); GB_ASSERT(is_type_proc(proc_type)); proc_type = base_type(proc_type); @@ -5628,7 +5628,7 @@ CALL_ARGUMENT_CHECKER(check_named_call_arguments) { return err; } -Entity **populate_proc_parameter_list(CheckerContext *c, Type *proc_type, isize *lhs_count_, bool *is_variadic) { +gb_internal Entity **populate_proc_parameter_list(CheckerContext *c, Type *proc_type, isize *lhs_count_, bool *is_variadic) { Entity **lhs = nullptr; isize lhs_count = -1; @@ -5667,7 +5667,7 @@ Entity **populate_proc_parameter_list(CheckerContext *c, Type *proc_type, isize } -bool evaluate_where_clauses(CheckerContext *ctx, Ast *call_expr, Scope *scope, Slice *clauses, bool print_err) { +gb_internal bool evaluate_where_clauses(CheckerContext *ctx, Ast *call_expr, Scope *scope, Slice *clauses, bool print_err) { if (clauses != nullptr) { for (Ast *clause : *clauses) { Operand o = {}; @@ -5733,7 +5733,7 @@ bool evaluate_where_clauses(CheckerContext *ctx, Ast *call_expr, Scope *scope, S } -CallArgumentData check_call_arguments(CheckerContext *c, Operand *operand, Type *proc_type, Ast *call, Slice const &args) { +gb_internal CallArgumentData check_call_arguments(CheckerContext *c, Operand *operand, Type *proc_type, Ast *call, Slice const &args) { ast_node(ce, CallExpr, call); CallArgumentCheckerType *call_checker = check_call_arguments_internal; @@ -6262,7 +6262,7 @@ CallArgumentData check_call_arguments(CheckerContext *c, Operand *operand, Type } -isize lookup_polymorphic_record_parameter(Type *t, String parameter_name) { +gb_internal isize lookup_polymorphic_record_parameter(Type *t, String parameter_name) { if (!is_type_polymorphic_record(t)) { return -1; } @@ -6285,7 +6285,7 @@ isize lookup_polymorphic_record_parameter(Type *t, String parameter_name) { } -CallArgumentError check_polymorphic_record_type(CheckerContext *c, Operand *operand, Ast *call) { +gb_internal CallArgumentError check_polymorphic_record_type(CheckerContext *c, Operand *operand, Ast *call) { ast_node(ce, CallExpr, call); Type *original_type = operand->type; @@ -6605,7 +6605,7 @@ CallArgumentError check_polymorphic_record_type(CheckerContext *c, Operand *oper -ExprKind check_call_expr(CheckerContext *c, Operand *operand, Ast *call, Ast *proc, Slice const &args, ProcInlining inlining, Type *type_hint) { +gb_internal ExprKind check_call_expr(CheckerContext *c, Operand *operand, Ast *call, Ast *proc, Slice const &args, ProcInlining inlining, Type *type_hint) { if (proc != nullptr && proc->kind == Ast_BasicDirective) { ast_node(bd, BasicDirective, proc); @@ -6880,7 +6880,7 @@ ExprKind check_call_expr(CheckerContext *c, Operand *operand, Ast *call, Ast *pr } -void check_expr_with_type_hint(CheckerContext *c, Operand *o, Ast *e, Type *t) { +gb_internal void check_expr_with_type_hint(CheckerContext *c, Operand *o, Ast *e, Type *t) { check_expr_base(c, o, e, t); check_not_tuple(c, o); char const *err_str = nullptr; @@ -6905,7 +6905,7 @@ void check_expr_with_type_hint(CheckerContext *c, Operand *o, Ast *e, Type *t) { } } -bool check_set_index_data(Operand *o, Type *t, bool indirection, i64 *max_count, Type *original_type) { +gb_internal bool check_set_index_data(Operand *o, Type *t, bool indirection, i64 *max_count, Type *original_type) { switch (t->kind) { case Type_Basic: if (t->Basic.kind == Basic_string) { @@ -7018,7 +7018,7 @@ bool check_set_index_data(Operand *o, Type *t, bool indirection, i64 *max_count, return false; } -bool ternary_compare_types(Type *x, Type *y) { +gb_internal bool ternary_compare_types(Type *x, Type *y) { if (is_type_untyped_undef(x) && type_has_undef(y)) { return true; } else if (is_type_untyped_nil(x) && type_has_nil(y)) { @@ -7032,7 +7032,7 @@ bool ternary_compare_types(Type *x, Type *y) { } -bool check_range(CheckerContext *c, Ast *node, Operand *x, Operand *y, ExactValue *inline_for_depth_, Type *type_hint=nullptr) { +gb_internal bool check_range(CheckerContext *c, Ast *node, Operand *x, Operand *y, ExactValue *inline_for_depth_, Type *type_hint=nullptr) { if (!is_ast_range(node)) { return false; } @@ -7124,7 +7124,7 @@ bool check_range(CheckerContext *c, Ast *node, Operand *x, Operand *y, ExactValu return true; } -bool check_is_operand_compound_lit_constant(CheckerContext *c, Operand *o) { +gb_internal bool check_is_operand_compound_lit_constant(CheckerContext *c, Operand *o) { if (is_operand_nil(*o)) { return true; } @@ -7143,7 +7143,7 @@ bool check_is_operand_compound_lit_constant(CheckerContext *c, Operand *o) { } -bool attempt_implicit_selector_expr(CheckerContext *c, Operand *o, AstImplicitSelectorExpr *ise, Type *th) { +gb_internal bool attempt_implicit_selector_expr(CheckerContext *c, Operand *o, AstImplicitSelectorExpr *ise, Type *th) { if (is_type_enum(th)) { Type *enum_type = base_type(th); GB_ASSERT(enum_type->kind == Type_Enum); @@ -7182,7 +7182,7 @@ bool attempt_implicit_selector_expr(CheckerContext *c, Operand *o, AstImplicitSe return false; } -ExprKind check_implicit_selector_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { +gb_internal ExprKind check_implicit_selector_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { ast_node(ise, ImplicitSelectorExpr, node); o->type = t_invalid; @@ -7226,7 +7226,7 @@ ExprKind check_implicit_selector_expr(CheckerContext *c, Operand *o, Ast *node, } -void check_promote_optional_ok(CheckerContext *c, Operand *x, Type **val_type_, Type **ok_type_) { +gb_internal void check_promote_optional_ok(CheckerContext *c, Operand *x, Type **val_type_, Type **ok_type_) { switch (x->mode) { case Addressing_MapIndex: case Addressing_OptionalOk: @@ -7263,7 +7263,7 @@ void check_promote_optional_ok(CheckerContext *c, Operand *x, Type **val_type_, } -void check_matrix_index_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { +gb_internal void check_matrix_index_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { ast_node(ie, MatrixIndexExpr, node); check_expr(c, o, ie->expr); @@ -7336,7 +7336,7 @@ struct TypeAndToken { typedef PtrMap SeenMap; -void add_constant_switch_case(CheckerContext *ctx, SeenMap *seen, Operand operand, bool use_expr = true) { +gb_internal void add_constant_switch_case(CheckerContext *ctx, SeenMap *seen, Operand operand, bool use_expr = true) { if (operand.mode != Addressing_Constant) { return; } @@ -7378,7 +7378,7 @@ void add_constant_switch_case(CheckerContext *ctx, SeenMap *seen, Operand operan } -void add_to_seen_map(CheckerContext *ctx, SeenMap *seen, TokenKind upper_op, Operand const &x, Operand const &lhs, Operand const &rhs) { +gb_internal void add_to_seen_map(CheckerContext *ctx, SeenMap *seen, TokenKind upper_op, Operand const &x, Operand const &lhs, Operand const &rhs) { if (is_type_enum(x.type)) { // TODO(bill): Fix this logic so it's fast!!! @@ -7419,11 +7419,11 @@ void add_to_seen_map(CheckerContext *ctx, SeenMap *seen, TokenKind upper_op, Ope } } } -void add_to_seen_map(CheckerContext *ctx, SeenMap *seen, Operand const &x) { +gb_internal void add_to_seen_map(CheckerContext *ctx, SeenMap *seen, Operand const &x) { add_constant_switch_case(ctx, seen, x); } -ExprKind check_basic_directive_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { +gb_internal ExprKind check_basic_directive_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { ast_node(bd, BasicDirective, node); ExprKind kind = Expr_Expr; @@ -7477,7 +7477,7 @@ ExprKind check_basic_directive_expr(CheckerContext *c, Operand *o, Ast *node, Ty return kind; } -ExprKind check_ternary_if_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { +gb_internal ExprKind check_ternary_if_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { ExprKind kind = Expr_Expr; Operand cond = {Addressing_Invalid}; ast_node(te, TernaryIfExpr, node); @@ -7555,7 +7555,7 @@ ExprKind check_ternary_if_expr(CheckerContext *c, Operand *o, Ast *node, Type *t return kind; } -ExprKind check_ternary_when_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { +gb_internal ExprKind check_ternary_when_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { ExprKind kind = Expr_Expr; Operand cond = {}; ast_node(te, TernaryWhenExpr, node); @@ -7582,7 +7582,7 @@ ExprKind check_ternary_when_expr(CheckerContext *c, Operand *o, Ast *node, Type return kind; } -ExprKind check_or_else_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { +gb_internal ExprKind check_or_else_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { ast_node(oe, OrElseExpr, node); String name = oe->token.string; @@ -7696,7 +7696,7 @@ ExprKind check_or_else_expr(CheckerContext *c, Operand *o, Ast *node, Type *type return Expr_Expr; } -ExprKind check_or_return_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { +gb_internal ExprKind check_or_return_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { ast_node(re, OrReturnExpr, node); String name = re->token.string; @@ -7775,7 +7775,7 @@ ExprKind check_or_return_expr(CheckerContext *c, Operand *o, Ast *node, Type *ty return Expr_Expr; } -ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { +gb_internal ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { ExprKind kind = Expr_Expr; ast_node(cl, CompoundLit, node); @@ -8739,7 +8739,7 @@ ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast *node, Type * return kind; } -ExprKind check_type_assertion(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { +gb_internal ExprKind check_type_assertion(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { ExprKind kind = Expr_Expr; ast_node(ta, TypeAssertion, node); check_expr(c, o, ta->expr); @@ -8868,7 +8868,7 @@ ExprKind check_type_assertion(CheckerContext *c, Operand *o, Ast *node, Type *ty return kind; } -ExprKind check_selector_call_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { +gb_internal ExprKind check_selector_call_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { ast_node(se, SelectorCallExpr, node); // IMPORTANT NOTE(bill, 2020-05-22): This is a complete hack to get a shorthand which is extremely useful for vtables // COM APIs is a great example of where this kind of thing is extremely useful @@ -9016,7 +9016,7 @@ ExprKind check_selector_call_expr(CheckerContext *c, Operand *o, Ast *node, Type } -ExprKind check_index_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { +gb_internal ExprKind check_index_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { ExprKind kind = Expr_Expr; ast_node(ie, IndexExpr, node); check_expr(c, o, ie->expr); @@ -9140,7 +9140,7 @@ ExprKind check_index_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_h return kind; } -ExprKind check_slice_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { +gb_internal ExprKind check_slice_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { ExprKind kind = Expr_Stmt; ast_node(se, SliceExpr, node); check_expr(c, o, se->expr); @@ -9328,7 +9328,7 @@ ExprKind check_slice_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_h return kind; } -ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { +gb_internal ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { u32 prev_state_flags = c->state_flags; defer (c->state_flags = prev_state_flags); if (node->state_flags != 0) { @@ -9755,7 +9755,7 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type -ExprKind check_expr_base(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { +gb_internal ExprKind check_expr_base(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { ExprKind kind = check_expr_base_internal(c, o, node, type_hint); if (o->type != nullptr && core_type(o->type) == nullptr) { o->type = t_invalid; @@ -9777,7 +9777,7 @@ ExprKind check_expr_base(CheckerContext *c, Operand *o, Ast *node, Type *type_hi } -void check_multi_expr_or_type(CheckerContext *c, Operand *o, Ast *e) { +gb_internal void check_multi_expr_or_type(CheckerContext *c, Operand *o, Ast *e) { check_expr_base(c, o, e, nullptr); switch (o->mode) { default: @@ -9789,7 +9789,7 @@ void check_multi_expr_or_type(CheckerContext *c, Operand *o, Ast *e) { o->mode = Addressing_Invalid; } -void check_multi_expr(CheckerContext *c, Operand *o, Ast *e) { +gb_internal void check_multi_expr(CheckerContext *c, Operand *o, Ast *e) { check_expr_base(c, o, e, nullptr); switch (o->mode) { default: @@ -9804,7 +9804,7 @@ void check_multi_expr(CheckerContext *c, Operand *o, Ast *e) { o->mode = Addressing_Invalid; } -void check_multi_expr_with_type_hint(CheckerContext *c, Operand *o, Ast *e, Type *type_hint) { +gb_internal void check_multi_expr_with_type_hint(CheckerContext *c, Operand *o, Ast *e, Type *type_hint) { check_expr_base(c, o, e, type_hint); switch (o->mode) { default: @@ -9819,7 +9819,7 @@ void check_multi_expr_with_type_hint(CheckerContext *c, Operand *o, Ast *e, Type o->mode = Addressing_Invalid; } -void check_not_tuple(CheckerContext *c, Operand *o) { +gb_internal void check_not_tuple(CheckerContext *c, Operand *o) { if (o->mode == Addressing_Value) { // NOTE(bill): Tuples are not first class thus never named if (o->type->kind == Type_Tuple) { @@ -9832,13 +9832,13 @@ void check_not_tuple(CheckerContext *c, Operand *o) { } } -void check_expr(CheckerContext *c, Operand *o, Ast *e) { +gb_internal void check_expr(CheckerContext *c, Operand *o, Ast *e) { check_multi_expr(c, o, e); check_not_tuple(c, o); } -void check_expr_or_type(CheckerContext *c, Operand *o, Ast *e, Type *type_hint) { +gb_internal void check_expr_or_type(CheckerContext *c, Operand *o, Ast *e, Type *type_hint) { check_expr_base(c, o, e, type_hint); check_not_tuple(c, o); error_operand_no_value(o); @@ -9846,7 +9846,7 @@ void check_expr_or_type(CheckerContext *c, Operand *o, Ast *e, Type *type_hint) -bool is_exact_value_zero(ExactValue const &v) { +gb_internal bool is_exact_value_zero(ExactValue const &v) { switch (v.kind) { case ExactValue_Invalid: return true; @@ -9910,9 +9910,9 @@ bool is_exact_value_zero(ExactValue const &v) { -gbString write_expr_to_string(gbString str, Ast *node, bool shorthand); +gb_internal gbString write_expr_to_string(gbString str, Ast *node, bool shorthand); -gbString write_struct_fields_to_string(gbString str, Slice const ¶ms) { +gb_internal gbString write_struct_fields_to_string(gbString str, Slice const ¶ms) { for_array(i, params) { if (i > 0) { str = gb_string_appendc(str, ", "); @@ -9922,7 +9922,7 @@ gbString write_struct_fields_to_string(gbString str, Slice const ¶ms) return str; } -gbString string_append_string(gbString str, String string) { +gb_internal gbString string_append_string(gbString str, String string) { if (string.len > 0) { return gb_string_append_length(str, &string[0], string.len); } @@ -9930,13 +9930,13 @@ gbString string_append_string(gbString str, String string) { } -gbString string_append_token(gbString str, Token token) { +gb_internal gbString string_append_token(gbString str, Token token) { str = string_append_string(str, token.string); return str; } -gbString write_expr_to_string(gbString str, Ast *node, bool shorthand) { +gb_internal gbString write_expr_to_string(gbString str, Ast *node, bool shorthand) { if (node == nullptr) return str; @@ -10501,9 +10501,9 @@ gbString write_expr_to_string(gbString str, Ast *node, bool shorthand) { return str; } -gbString expr_to_string(Ast *expression) { +gb_internal gbString expr_to_string(Ast *expression) { return write_expr_to_string(gb_string_make(heap_allocator(), ""), expression, false); } -gbString expr_to_string_shorthand(Ast *expression) { +gb_internal gbString expr_to_string_shorthand(Ast *expression) { return write_expr_to_string(gb_string_make(heap_allocator(), ""), expression, true); } diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index 3fe6699ea..cae9c3537 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -1,4 +1,4 @@ -bool is_diverging_expr(Ast *expr) { +gb_internal bool is_diverging_expr(Ast *expr) { expr = unparen_expr(expr); if (expr->kind != Ast_CallExpr) { return false; @@ -23,14 +23,14 @@ bool is_diverging_expr(Ast *expr) { t = base_type(t); return t != nullptr && t->kind == Type_Proc && t->Proc.diverging; } -bool is_diverging_stmt(Ast *stmt) { +gb_internal bool is_diverging_stmt(Ast *stmt) { if (stmt->kind != Ast_ExprStmt) { return false; } return is_diverging_expr(stmt->ExprStmt.expr); } -bool contains_deferred_call(Ast *node) { +gb_internal bool contains_deferred_call(Ast *node) { if (node->viral_state_flags & ViralStateFlag_ContainsDeferredProcedure) { return true; } @@ -61,7 +61,7 @@ bool contains_deferred_call(Ast *node) { return false; } -void check_stmt_list(CheckerContext *ctx, Slice const &stmts, u32 flags) { +gb_internal void check_stmt_list(CheckerContext *ctx, Slice const &stmts, u32 flags) { if (stmts.count == 0) { return; } @@ -137,7 +137,7 @@ void check_stmt_list(CheckerContext *ctx, Slice const &stmts, u32 flags) } } -bool check_is_terminating_list(Slice const &stmts, String const &label) { +gb_internal bool check_is_terminating_list(Slice const &stmts, String const &label) { // Iterate backwards for (isize n = stmts.count-1; n >= 0; n--) { Ast *stmt = stmts[n]; @@ -155,7 +155,7 @@ bool check_is_terminating_list(Slice const &stmts, String const &label) { return false; } -bool check_has_break_list(Slice const &stmts, String const &label, bool implicit) { +gb_internal bool check_has_break_list(Slice const &stmts, String const &label, bool implicit) { for_array(i, stmts) { Ast *stmt = stmts[i]; if (check_has_break(stmt, label, implicit)) { @@ -166,7 +166,7 @@ bool check_has_break_list(Slice const &stmts, String const &label, bool i } -bool check_has_break(Ast *stmt, String const &label, bool implicit) { +gb_internal bool check_has_break(Ast *stmt, String const &label, bool implicit) { switch (stmt->kind) { case Ast_BranchStmt: if (stmt->BranchStmt.token.kind == Token_break) { @@ -225,7 +225,7 @@ bool check_has_break(Ast *stmt, String const &label, bool implicit) { // NOTE(bill): The last expression has to be a 'return' statement // TODO(bill): This is a mild hack and should be probably handled properly -bool check_is_terminating(Ast *node, String const &label) { +gb_internal bool check_is_terminating(Ast *node, String const &label) { switch (node->kind) { case_ast_node(rs, ReturnStmt, node); return true; @@ -327,7 +327,7 @@ bool check_is_terminating(Ast *node, String const &label) { -Type *check_assignment_variable(CheckerContext *ctx, Operand *lhs, Operand *rhs) { +gb_internal Type *check_assignment_variable(CheckerContext *ctx, Operand *lhs, Operand *rhs) { if (rhs->mode == Addressing_Invalid) { return nullptr; } @@ -477,8 +477,8 @@ Type *check_assignment_variable(CheckerContext *ctx, Operand *lhs, Operand *rhs) } -void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags); -void check_stmt(CheckerContext *ctx, Ast *node, u32 flags) { +gb_internal void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags); +gb_internal void check_stmt(CheckerContext *ctx, Ast *node, u32 flags) { u32 prev_state_flags = ctx->state_flags; if (node->state_flags != 0) { @@ -510,7 +510,7 @@ void check_stmt(CheckerContext *ctx, Ast *node, u32 flags) { } -void check_when_stmt(CheckerContext *ctx, AstWhenStmt *ws, u32 flags) { +gb_internal void check_when_stmt(CheckerContext *ctx, AstWhenStmt *ws, u32 flags) { Operand operand = {Addressing_Invalid}; check_expr(ctx, &operand, ws->cond); if (operand.mode != Addressing_Constant || !is_type_boolean(operand.type)) { @@ -539,7 +539,7 @@ void check_when_stmt(CheckerContext *ctx, AstWhenStmt *ws, u32 flags) { } } -void check_label(CheckerContext *ctx, Ast *label, Ast *parent) { +gb_internal void check_label(CheckerContext *ctx, Ast *label, Ast *parent) { if (label == nullptr) { return; } @@ -582,7 +582,7 @@ void check_label(CheckerContext *ctx, Ast *label, Ast *parent) { } // Returns 'true' for 'continue', 'false' for 'return' -bool check_using_stmt_entity(CheckerContext *ctx, AstUsingStmt *us, Ast *expr, bool is_selector, Entity *e) { +gb_internal bool check_using_stmt_entity(CheckerContext *ctx, AstUsingStmt *us, Ast *expr, bool is_selector, Entity *e) { if (e == nullptr) { if (is_blank_ident(expr)) { error(us->token, "'using' in a statement is not allowed with the blank identifier '_'"); @@ -704,7 +704,7 @@ bool check_using_stmt_entity(CheckerContext *ctx, AstUsingStmt *us, Ast *expr, b return true; } -void check_inline_range_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) { +gb_internal void check_inline_range_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) { ast_node(irs, UnrollRangeStmt, node); check_open_scope(ctx, node); @@ -863,7 +863,7 @@ void check_inline_range_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) { check_close_scope(ctx); } -void check_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) { +gb_internal void check_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) { ast_node(ss, SwitchStmt, node); Operand x = {}; @@ -1092,7 +1092,7 @@ enum TypeSwitchKind { TypeSwitch_Any, }; -TypeSwitchKind check_valid_type_switch_type(Type *type) { +gb_internal TypeSwitchKind check_valid_type_switch_type(Type *type) { type = type_deref(type); if (is_type_union(type)) { return TypeSwitch_Union; @@ -1103,7 +1103,7 @@ TypeSwitchKind check_valid_type_switch_type(Type *type) { return TypeSwitch_Invalid; } -void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) { +gb_internal void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) { ast_node(ss, TypeSwitchStmt, node); Operand x = {}; @@ -1318,7 +1318,7 @@ void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) { } } -void check_block_stmt_for_errors(CheckerContext *ctx, Ast *body) { +gb_internal void check_block_stmt_for_errors(CheckerContext *ctx, Ast *body) { if (body->kind != Ast_BlockStmt) { return; } @@ -1377,7 +1377,7 @@ void check_block_stmt_for_errors(CheckerContext *ctx, Ast *body) { } } -bool all_operands_valid(Array const &operands) { +gb_internal bool all_operands_valid(Array const &operands) { if (any_errors()) { for_array(i, operands) { if (operands[i].type == t_invalid) { @@ -1388,7 +1388,7 @@ bool all_operands_valid(Array const &operands) { return true; } -bool check_stmt_internal_builtin_proc_id(Ast *expr, BuiltinProcId *id_) { +gb_internal bool check_stmt_internal_builtin_proc_id(Ast *expr, BuiltinProcId *id_) { BuiltinProcId id = BuiltinProc_Invalid; Entity *e = entity_of_node(expr); if (e != nullptr && e->kind == Entity_Builtin) { @@ -1400,7 +1400,7 @@ bool check_stmt_internal_builtin_proc_id(Ast *expr, BuiltinProcId *id_) { return id != BuiltinProc_Invalid; } -bool check_expr_is_stack_variable(Ast *expr) { +gb_internal bool check_expr_is_stack_variable(Ast *expr) { /* expr = unparen_expr(expr); Entity *e = entity_of_node(expr); @@ -1419,7 +1419,7 @@ bool check_expr_is_stack_variable(Ast *expr) { return false; } -void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) { +gb_internal void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) { u32 mod_flags = flags & (~Stmt_FallthroughAllowed); switch (node->kind) { case_ast_node(_, EmptyStmt, node); case_end; diff --git a/src/check_type.cpp b/src/check_type.cpp index 62ca19c57..4634e1fbe 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -1,6 +1,6 @@ -ParameterValue handle_parameter_value(CheckerContext *ctx, Type *in_type, Type **out_type_, Ast *expr, bool allow_caller_location); +gb_internal ParameterValue handle_parameter_value(CheckerContext *ctx, Type *in_type, Type **out_type_, Ast *expr, bool allow_caller_location); -void populate_using_array_index(CheckerContext *ctx, Ast *node, AstField *field, Type *t, String name, i32 idx) { +gb_internal void populate_using_array_index(CheckerContext *ctx, Ast *node, AstField *field, Type *t, String name, i32 idx) { t = base_type(t); GB_ASSERT(t->kind == Type_Array); Entity *e = scope_lookup_current(ctx->scope, name); @@ -27,7 +27,7 @@ void populate_using_array_index(CheckerContext *ctx, Ast *node, AstField *field, } } -void populate_using_entity_scope(CheckerContext *ctx, Ast *node, AstField *field, Type *t) { +gb_internal void populate_using_entity_scope(CheckerContext *ctx, Ast *node, AstField *field, Type *t) { if (t == nullptr) { return; } @@ -81,7 +81,7 @@ void populate_using_entity_scope(CheckerContext *ctx, Ast *node, AstField *field } } -bool does_field_type_allow_using(Type *t) { +gb_internal bool does_field_type_allow_using(Type *t) { t = base_type(t); if (is_type_struct(t)) { return true; @@ -91,8 +91,8 @@ bool does_field_type_allow_using(Type *t) { return false; } -void check_struct_fields(CheckerContext *ctx, Ast *node, Slice *fields, String **tags, Slice const ¶ms, - isize init_field_capacity, Type *struct_type, String context) { +gb_internal void check_struct_fields(CheckerContext *ctx, Ast *node, Slice *fields, String **tags, Slice const ¶ms, + isize init_field_capacity, Type *struct_type, String context) { auto fields_array = array_make(heap_allocator(), 0, init_field_capacity); auto tags_array = array_make(heap_allocator(), 0, init_field_capacity); @@ -219,7 +219,7 @@ void check_struct_fields(CheckerContext *ctx, Ast *node, Slice *fields } -bool check_custom_align(CheckerContext *ctx, Ast *node, i64 *align_) { +gb_internal bool check_custom_align(CheckerContext *ctx, Ast *node, i64 *align_) { GB_ASSERT(align_ != nullptr); Operand o = {}; check_expr(ctx, &o, node); @@ -256,7 +256,7 @@ bool check_custom_align(CheckerContext *ctx, Ast *node, i64 *align_) { } -Entity *find_polymorphic_record_entity(CheckerContext *ctx, Type *original_type, isize param_count, Array const &ordered_operands, bool *failure) { +gb_internal Entity *find_polymorphic_record_entity(CheckerContext *ctx, Type *original_type, isize param_count, Array const &ordered_operands, bool *failure) { mutex_lock(&ctx->info->gen_types_mutex); defer (mutex_unlock(&ctx->info->gen_types_mutex)); @@ -320,7 +320,7 @@ Entity *find_polymorphic_record_entity(CheckerContext *ctx, Type *original_type, } -void add_polymorphic_record_entity(CheckerContext *ctx, Ast *node, Type *named_type, Type *original_type) { +gb_internal void add_polymorphic_record_entity(CheckerContext *ctx, Ast *node, Type *named_type, Type *original_type) { GB_ASSERT(is_type_named(named_type)); gbAllocator a = heap_allocator(); Scope *s = ctx->scope->parent; @@ -358,10 +358,10 @@ void add_polymorphic_record_entity(CheckerContext *ctx, Ast *node, Type *named_t mutex_unlock(&ctx->info->gen_types_mutex); } -Type *check_record_polymorphic_params(CheckerContext *ctx, Ast *polymorphic_params, - bool *is_polymorphic_, - Ast *node, Array *poly_operands, - Type *named_type, Type *original_type_for_poly) { +gb_internal Type *check_record_polymorphic_params(CheckerContext *ctx, Ast *polymorphic_params, + bool *is_polymorphic_, + Ast *node, Array *poly_operands, + Type *named_type, Type *original_type_for_poly) { Type *polymorphic_params_type = nullptr; bool can_check_fields = true; GB_ASSERT(is_polymorphic_ != nullptr); @@ -540,7 +540,7 @@ Type *check_record_polymorphic_params(CheckerContext *ctx, Ast *polymorphic_para return polymorphic_params_type; } -bool check_record_poly_operand_specialization(CheckerContext *ctx, Type *record_type, Array *poly_operands, bool *is_polymorphic_) { +gb_internal bool check_record_poly_operand_specialization(CheckerContext *ctx, Type *record_type, Array *poly_operands, bool *is_polymorphic_) { if (poly_operands == nullptr) { return false; } @@ -569,7 +569,7 @@ bool check_record_poly_operand_specialization(CheckerContext *ctx, Type *record_ } -void check_struct_type(CheckerContext *ctx, Type *struct_type, Ast *node, Array *poly_operands, Type *named_type, Type *original_type_for_poly) { +gb_internal void check_struct_type(CheckerContext *ctx, Type *struct_type, Ast *node, Array *poly_operands, Type *named_type, Type *original_type_for_poly) { GB_ASSERT(is_type_struct(struct_type)); ast_node(st, StructType, node); @@ -626,7 +626,7 @@ void check_struct_type(CheckerContext *ctx, Type *struct_type, Ast *node, Array< } } } -void check_union_type(CheckerContext *ctx, Type *union_type, Ast *node, Array *poly_operands, Type *named_type, Type *original_type_for_poly) { +gb_internal void check_union_type(CheckerContext *ctx, Type *union_type, Ast *node, Array *poly_operands, Type *named_type, Type *original_type_for_poly) { GB_ASSERT(is_type_union(union_type)); ast_node(ut, UnionType, node); @@ -709,7 +709,7 @@ void check_union_type(CheckerContext *ctx, Type *union_type, Ast *node, ArrayEnum.max_value_index = max_value_index; } -bool is_type_valid_bit_set_range(Type *t) { +gb_internal bool is_type_valid_bit_set_range(Type *t) { if (is_type_integer(t)) { return true; } @@ -861,7 +861,7 @@ bool is_type_valid_bit_set_range(Type *t) { return false; } -void check_bit_set_type(CheckerContext *c, Type *type, Type *named_type, Ast *node) { +gb_internal void check_bit_set_type(CheckerContext *c, Type *type, Type *named_type, Ast *node) { ast_node(bs, BitSetType, node); GB_ASSERT(type->kind == Type_BitSet); type->BitSet.node = node; @@ -1102,7 +1102,7 @@ void check_bit_set_type(CheckerContext *c, Type *type, Type *named_type, Ast *no } -bool check_type_specialization_to(CheckerContext *ctx, Type *specialization, Type *type, bool compound, bool modify_type) { +gb_internal bool check_type_specialization_to(CheckerContext *ctx, Type *specialization, Type *type, bool compound, bool modify_type) { if (type == nullptr || type == t_invalid) { return true; @@ -1229,7 +1229,7 @@ bool check_type_specialization_to(CheckerContext *ctx, Type *specialization, Typ } -Type *determine_type_from_polymorphic(CheckerContext *ctx, Type *poly_type, Operand const &operand) { +gb_internal Type *determine_type_from_polymorphic(CheckerContext *ctx, Type *poly_type, Operand const &operand) { bool modify_type = !ctx->no_polymorphic_errors; bool show_error = modify_type && !ctx->hide_polymorphic_errors; if (!is_operand_value(operand)) { @@ -1256,7 +1256,7 @@ Type *determine_type_from_polymorphic(CheckerContext *ctx, Type *poly_type, Oper return t_invalid; } -bool is_expr_from_a_parameter(CheckerContext *ctx, Ast *expr) { +gb_internal bool is_expr_from_a_parameter(CheckerContext *ctx, Ast *expr) { if (expr == nullptr) { return false; } @@ -1275,7 +1275,7 @@ bool is_expr_from_a_parameter(CheckerContext *ctx, Ast *expr) { } -ParameterValue handle_parameter_value(CheckerContext *ctx, Type *in_type, Type **out_type_, Ast *expr, bool allow_caller_location) { +gb_internal ParameterValue handle_parameter_value(CheckerContext *ctx, Type *in_type, Type **out_type_, Ast *expr, bool allow_caller_location) { ParameterValue param_value = {}; param_value.original_ast_expr = expr; if (expr == nullptr) { @@ -1370,7 +1370,7 @@ ParameterValue handle_parameter_value(CheckerContext *ctx, Type *in_type, Type * } -Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_params, bool *is_variadic_, isize *variadic_index_, bool *success_, isize *specialization_count_, Array *operands) { +gb_internal Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_params, bool *is_variadic_, isize *variadic_index_, bool *success_, isize *specialization_count_, Array *operands) { if (_params == nullptr) { return nullptr; } @@ -1814,7 +1814,7 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_params, bool *is return tuple; } -Type *check_get_results(CheckerContext *ctx, Scope *scope, Ast *_results) { +gb_internal Type *check_get_results(CheckerContext *ctx, Scope *scope, Ast *_results) { if (_results == nullptr) { return nullptr; } @@ -1928,7 +1928,7 @@ Type *check_get_results(CheckerContext *ctx, Scope *scope, Ast *_results) { // NOTE(bill): 'operands' is for generating non generic procedure type -bool check_procedure_type(CheckerContext *ctx, Type *type, Ast *proc_type_node, Array *operands) { +gb_internal bool check_procedure_type(CheckerContext *ctx, Type *type, Ast *proc_type_node, Array *operands) { ast_node(pt, ProcType, proc_type_node); if (ctx->polymorphic_scope == nullptr && ctx->allow_polymorphic_types) { @@ -2084,7 +2084,7 @@ bool check_procedure_type(CheckerContext *ctx, Type *type, Ast *proc_type_node, } -i64 check_array_count(CheckerContext *ctx, Operand *o, Ast *e) { +gb_internal i64 check_array_count(CheckerContext *ctx, Operand *o, Ast *e) { if (e == nullptr) { return 0; } @@ -2169,7 +2169,7 @@ i64 check_array_count(CheckerContext *ctx, Operand *o, Ast *e) { return 0; } -Type *make_optional_ok_type(Type *value, bool typed) { +gb_internal Type *make_optional_ok_type(Type *value, bool typed) { gbAllocator a = permanent_allocator(); Type *t = alloc_type_tuple(); slice_init(&t->Tuple.variables, a, 2); @@ -2185,7 +2185,7 @@ enum : i64 { MAP_CACHE_LINE_SIZE = 1 << MAP_CACHE_LINE_LOG2 }; GB_STATIC_ASSERT(MAP_CACHE_LINE_SIZE >= 64); -void map_cell_size_and_len(Type *type, i64 *size_, i64 *len_) { +gb_internal void map_cell_size_and_len(Type *type, i64 *size_, i64 *len_) { i64 elem_sz = type_size_of(type); i64 len = 1; @@ -2197,7 +2197,7 @@ void map_cell_size_and_len(Type *type, i64 *size_, i64 *len_) { if (len_) *len_ = len; } -void init_map_internal_types(Type *type) { +gb_internal void init_map_internal_types(Type *type) { GB_ASSERT(type->kind == Type_Map); GB_ASSERT(t_allocator != nullptr); if (type->Map.lookup_result_type != nullptr) return; @@ -2210,7 +2210,7 @@ void init_map_internal_types(Type *type) { type->Map.lookup_result_type = make_optional_ok_type(value); } -void add_map_key_type_dependencies(CheckerContext *ctx, Type *key) { +gb_internal void add_map_key_type_dependencies(CheckerContext *ctx, Type *key) { key = core_type(key); if (is_type_cstring(key)) { @@ -2249,7 +2249,7 @@ void add_map_key_type_dependencies(CheckerContext *ctx, Type *key) { } } -void check_map_type(CheckerContext *ctx, Type *type, Ast *node) { +gb_internal void check_map_type(CheckerContext *ctx, Type *type, Ast *node) { GB_ASSERT(type->kind == Type_Map); ast_node(mt, MapType, node); @@ -2282,7 +2282,7 @@ void check_map_type(CheckerContext *ctx, Type *type, Ast *node) { // error(node, "'map' types are not yet implemented"); } -void check_matrix_type(CheckerContext *ctx, Type **type, Ast *node) { +gb_internal void check_matrix_type(CheckerContext *ctx, Type **type, Ast *node) { ast_node(mt, MatrixType, node); Operand row = {}; @@ -2346,7 +2346,7 @@ type_assign:; -Type *make_soa_struct_internal(CheckerContext *ctx, Ast *array_typ_expr, Ast *elem_expr, Type *elem, i64 count, Type *generic_type, StructSoaKind soa_kind) { +gb_internal Type *make_soa_struct_internal(CheckerContext *ctx, Ast *array_typ_expr, Ast *elem_expr, Type *elem, i64 count, Type *generic_type, StructSoaKind soa_kind) { Type *bt_elem = base_type(elem); bool is_polymorphic = is_type_polymorphic(elem); @@ -2501,20 +2501,20 @@ Type *make_soa_struct_internal(CheckerContext *ctx, Ast *array_typ_expr, Ast *el } -Type *make_soa_struct_fixed(CheckerContext *ctx, Ast *array_typ_expr, Ast *elem_expr, Type *elem, i64 count, Type *generic_type) { +gb_internal Type *make_soa_struct_fixed(CheckerContext *ctx, Ast *array_typ_expr, Ast *elem_expr, Type *elem, i64 count, Type *generic_type) { return make_soa_struct_internal(ctx, array_typ_expr, elem_expr, elem, count, generic_type, StructSoa_Fixed); } -Type *make_soa_struct_slice(CheckerContext *ctx, Ast *array_typ_expr, Ast *elem_expr, Type *elem) { +gb_internal Type *make_soa_struct_slice(CheckerContext *ctx, Ast *array_typ_expr, Ast *elem_expr, Type *elem) { return make_soa_struct_internal(ctx, array_typ_expr, elem_expr, elem, -1, nullptr, StructSoa_Slice); } -Type *make_soa_struct_dynamic_array(CheckerContext *ctx, Ast *array_typ_expr, Ast *elem_expr, Type *elem) { +gb_internal Type *make_soa_struct_dynamic_array(CheckerContext *ctx, Ast *array_typ_expr, Ast *elem_expr, Type *elem) { return make_soa_struct_internal(ctx, array_typ_expr, elem_expr, elem, -1, nullptr, StructSoa_Dynamic); } -bool check_type_internal(CheckerContext *ctx, Ast *e, Type **type, Type *named_type) { +gb_internal bool check_type_internal(CheckerContext *ctx, Ast *e, Type **type, Type *named_type) { GB_ASSERT_NOT_NULL(type); if (e == nullptr) { *type = t_invalid; @@ -2997,7 +2997,7 @@ bool check_type_internal(CheckerContext *ctx, Ast *e, Type **type, Type *named_t return false; } -Type *check_type(CheckerContext *ctx, Ast *e) { +gb_internal Type *check_type(CheckerContext *ctx, Ast *e) { CheckerContext c = *ctx; c.type_path = new_checker_type_path(); defer (destroy_checker_type_path(c.type_path)); @@ -3005,7 +3005,7 @@ Type *check_type(CheckerContext *ctx, Ast *e) { return check_type_expr(&c, e, nullptr); } -Type *check_type_expr(CheckerContext *ctx, Ast *e, Type *named_type) { +gb_internal Type *check_type_expr(CheckerContext *ctx, Ast *e, Type *named_type) { Type *type = nullptr; bool ok = check_type_internal(ctx, e, &type, named_type); diff --git a/src/checker.cpp b/src/checker.cpp index d5222f615..e2c430dc2 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -1,12 +1,12 @@ #include "entity.cpp" #include "types.cpp" -void check_expr(CheckerContext *c, Operand *operand, Ast *expression); -void check_expr_or_type(CheckerContext *c, Operand *operand, Ast *expression, Type *type_hint=nullptr); -void add_comparison_procedures_for_fields(CheckerContext *c, Type *t); -Type *check_type(CheckerContext *ctx, Ast *e); +gb_internal void check_expr(CheckerContext *c, Operand *operand, Ast *expression); +gb_internal void check_expr_or_type(CheckerContext *c, Operand *operand, Ast *expression, Type *type_hint=nullptr); +gb_internal void add_comparison_procedures_for_fields(CheckerContext *c, Type *t); +gb_internal Type *check_type(CheckerContext *ctx, Ast *e); -bool is_operand_value(Operand o) { +gb_internal bool is_operand_value(Operand o) { switch (o.mode) { case Addressing_Value: case Addressing_Context: @@ -22,14 +22,14 @@ bool is_operand_value(Operand o) { } return false; } -bool is_operand_nil(Operand o) { +gb_internal bool is_operand_nil(Operand o) { return o.mode == Addressing_Value && o.type == t_untyped_nil; } -bool is_operand_undef(Operand o) { +gb_internal bool is_operand_undef(Operand o) { return o.mode == Addressing_Value && o.type == t_untyped_undef; } -bool check_rtti_type_disallowed(Token const &token, Type *type, char const *format) { +gb_internal bool check_rtti_type_disallowed(Token const &token, Type *type, char const *format) { if (build_context.disallow_rtti && type) { if (is_type_any(type)) { gbString t = type_to_string(type); @@ -41,12 +41,12 @@ bool check_rtti_type_disallowed(Token const &token, Type *type, char const *form return false; } -bool check_rtti_type_disallowed(Ast *expr, Type *type, char const *format) { +gb_internal bool check_rtti_type_disallowed(Ast *expr, Type *type, char const *format) { GB_ASSERT(expr != nullptr); return check_rtti_type_disallowed(ast_token(expr), type, format); } -void scope_reset(Scope *scope) { +gb_internal void scope_reset(Scope *scope) { if (scope == nullptr) return; scope->head_child.store(nullptr, std::memory_order_relaxed); @@ -54,14 +54,14 @@ void scope_reset(Scope *scope) { ptr_set_clear(&scope->imported); } -void scope_reserve(Scope *scope, isize capacity) { +gb_internal void scope_reserve(Scope *scope, isize capacity) { isize cap = 2*capacity; if (cap > scope->elements.hashes.count) { string_map_rehash(&scope->elements, capacity); } } -i32 is_scope_an_ancestor(Scope *parent, Scope *child) { +gb_internal i32 is_scope_an_ancestor(Scope *parent, Scope *child) { i32 i = 0; while (child != nullptr) { if (parent == child) { @@ -73,35 +73,35 @@ i32 is_scope_an_ancestor(Scope *parent, Scope *child) { return -1; } -void entity_graph_node_set_destroy(EntityGraphNodeSet *s) { +gb_internal void entity_graph_node_set_destroy(EntityGraphNodeSet *s) { if (s->hashes.data != nullptr) { ptr_set_destroy(s); } } -void entity_graph_node_set_add(EntityGraphNodeSet *s, EntityGraphNode *n) { +gb_internal void entity_graph_node_set_add(EntityGraphNodeSet *s, EntityGraphNode *n) { if (s->hashes.data == nullptr) { ptr_set_init(s, heap_allocator()); } ptr_set_add(s, n); } -bool entity_graph_node_set_exists(EntityGraphNodeSet *s, EntityGraphNode *n) { +gb_internal bool entity_graph_node_set_exists(EntityGraphNodeSet *s, EntityGraphNode *n) { return ptr_set_exists(s, n); } -void entity_graph_node_set_remove(EntityGraphNodeSet *s, EntityGraphNode *n) { +gb_internal void entity_graph_node_set_remove(EntityGraphNodeSet *s, EntityGraphNode *n) { ptr_set_remove(s, n); } -void entity_graph_node_destroy(EntityGraphNode *n, gbAllocator a) { +gb_internal void entity_graph_node_destroy(EntityGraphNode *n, gbAllocator a) { entity_graph_node_set_destroy(&n->pred); entity_graph_node_set_destroy(&n->succ); gb_free(a, n); } -int entity_graph_node_cmp(EntityGraphNode **data, isize i, isize j) { +gb_internal int entity_graph_node_cmp(EntityGraphNode **data, isize i, isize j) { EntityGraphNode *x = data[i]; EntityGraphNode *y = data[j]; u64 a = x->entity->order_in_src; @@ -115,7 +115,7 @@ int entity_graph_node_cmp(EntityGraphNode **data, isize i, isize j) { return +1; } -void entity_graph_node_swap(EntityGraphNode **data, isize i, isize j) { +gb_internal void entity_graph_node_swap(EntityGraphNode **data, isize i, isize j) { EntityGraphNode *x = data[i]; EntityGraphNode *y = data[j]; data[i] = y; @@ -126,42 +126,42 @@ void entity_graph_node_swap(EntityGraphNode **data, isize i, isize j) { -void import_graph_node_set_destroy(ImportGraphNodeSet *s) { +gb_internal void import_graph_node_set_destroy(ImportGraphNodeSet *s) { if (s->hashes.data != nullptr) { ptr_set_destroy(s); } } -void import_graph_node_set_add(ImportGraphNodeSet *s, ImportGraphNode *n) { +gb_internal void import_graph_node_set_add(ImportGraphNodeSet *s, ImportGraphNode *n) { if (s->hashes.data == nullptr) { ptr_set_init(s, heap_allocator()); } ptr_set_add(s, n); } -bool import_graph_node_set_exists(ImportGraphNodeSet *s, ImportGraphNode *n) { +gb_internal bool import_graph_node_set_exists(ImportGraphNodeSet *s, ImportGraphNode *n) { return ptr_set_exists(s, n); } -void import_graph_node_set_remove(ImportGraphNodeSet *s, ImportGraphNode *n) { +gb_internal void import_graph_node_set_remove(ImportGraphNodeSet *s, ImportGraphNode *n) { ptr_set_remove(s, n); } -ImportGraphNode *import_graph_node_create(gbAllocator a, AstPackage *pkg) { +gb_internal ImportGraphNode *import_graph_node_create(gbAllocator a, AstPackage *pkg) { ImportGraphNode *n = gb_alloc_item(a, ImportGraphNode); n->pkg = pkg; n->scope = pkg->scope; return n; } -void import_graph_node_destroy(ImportGraphNode *n, gbAllocator a) { +gb_internal void import_graph_node_destroy(ImportGraphNode *n, gbAllocator a) { import_graph_node_set_destroy(&n->pred); import_graph_node_set_destroy(&n->succ); gb_free(a, n); } -int import_graph_node_cmp(ImportGraphNode **data, isize i, isize j) { +gb_internal int import_graph_node_cmp(ImportGraphNode **data, isize i, isize j) { ImportGraphNode *x = data[i]; ImportGraphNode *y = data[j]; GB_ASSERT(x != y); @@ -177,7 +177,7 @@ int import_graph_node_cmp(ImportGraphNode **data, isize i, isize j) { return 0; } -void import_graph_node_swap(ImportGraphNode **data, isize i, isize j) { +gb_internal void import_graph_node_swap(ImportGraphNode **data, isize i, isize j) { ImportGraphNode *x = data[i]; ImportGraphNode *y = data[j]; data[i] = y; @@ -186,7 +186,7 @@ void import_graph_node_swap(ImportGraphNode **data, isize i, isize j) { y->index = i; } -GB_COMPARE_PROC(ast_node_cmp) { +gb_internal GB_COMPARE_PROC(ast_node_cmp) { Ast *x = *cast(Ast **)a; Ast *y = *cast(Ast **)b; Token i = ast_token(x); @@ -199,7 +199,7 @@ GB_COMPARE_PROC(ast_node_cmp) { -void init_decl_info(DeclInfo *d, Scope *scope, DeclInfo *parent) { +gb_internal void init_decl_info(DeclInfo *d, Scope *scope, DeclInfo *parent) { d->parent = parent; d->scope = scope; ptr_set_init(&d->deps, heap_allocator()); @@ -207,18 +207,18 @@ void init_decl_info(DeclInfo *d, Scope *scope, DeclInfo *parent) { array_init (&d->labels, heap_allocator()); } -DeclInfo *make_decl_info(Scope *scope, DeclInfo *parent) { +gb_internal DeclInfo *make_decl_info(Scope *scope, DeclInfo *parent) { DeclInfo *d = gb_alloc_item(permanent_allocator(), DeclInfo); init_decl_info(d, scope, parent); return d; } -void destroy_declaration_info(DeclInfo *d) { +gb_internal void destroy_declaration_info(DeclInfo *d) { ptr_set_destroy(&d->deps); array_free(&d->labels); } -bool decl_info_has_init(DeclInfo *d) { +gb_internal bool decl_info_has_init(DeclInfo *d) { if (d->init_expr != nullptr) { return true; } @@ -239,7 +239,7 @@ bool decl_info_has_init(DeclInfo *d) { -Scope *create_scope(CheckerInfo *info, Scope *parent, isize init_elements_capacity=DEFAULT_SCOPE_CAPACITY) { +gb_internal Scope *create_scope(CheckerInfo *info, Scope *parent, isize init_elements_capacity=DEFAULT_SCOPE_CAPACITY) { Scope *s = gb_alloc_item(permanent_allocator(), Scope); s->parent = parent; string_map_init(&s->elements, heap_allocator(), init_elements_capacity); @@ -260,7 +260,7 @@ Scope *create_scope(CheckerInfo *info, Scope *parent, isize init_elements_capaci return s; } -Scope *create_scope_from_file(CheckerInfo *info, AstFile *f) { +gb_internal Scope *create_scope_from_file(CheckerInfo *info, AstFile *f) { GB_ASSERT(f != nullptr); GB_ASSERT(f->pkg != nullptr); GB_ASSERT(f->pkg->scope != nullptr); @@ -276,7 +276,7 @@ Scope *create_scope_from_file(CheckerInfo *info, AstFile *f) { return s; } -Scope *create_scope_from_package(CheckerContext *c, AstPackage *pkg) { +gb_internal Scope *create_scope_from_package(CheckerContext *c, AstPackage *pkg) { GB_ASSERT(pkg != nullptr); isize total_pkg_decl_count = 0; @@ -307,7 +307,7 @@ Scope *create_scope_from_package(CheckerContext *c, AstPackage *pkg) { return s; } -void destroy_scope(Scope *scope) { +gb_internal void destroy_scope(Scope *scope) { for (auto const &entry : scope->elements) { Entity *e = entry.value; if (e->kind == Entity_Variable) { @@ -331,7 +331,7 @@ void destroy_scope(Scope *scope) { } -void add_scope(CheckerContext *c, Ast *node, Scope *scope) { +gb_internal void add_scope(CheckerContext *c, Ast *node, Scope *scope) { GB_ASSERT(node != nullptr); GB_ASSERT(scope != nullptr); scope->node = node; @@ -352,7 +352,7 @@ void add_scope(CheckerContext *c, Ast *node, Scope *scope) { } } -Scope *scope_of_node(Ast *node) { +gb_internal Scope *scope_of_node(Ast *node) { if (node == nullptr) { return nullptr; } @@ -375,7 +375,7 @@ Scope *scope_of_node(Ast *node) { } -void check_open_scope(CheckerContext *c, Ast *node) { +gb_internal void check_open_scope(CheckerContext *c, Ast *node) { node = unparen_expr(node); GB_ASSERT(node->kind == Ast_Invalid || is_ast_stmt(node) || @@ -397,12 +397,12 @@ void check_open_scope(CheckerContext *c, Ast *node) { c->state_flags |= StateFlag_bounds_check; } -void check_close_scope(CheckerContext *c) { +gb_internal void check_close_scope(CheckerContext *c) { c->scope = c->scope->parent; } -Entity *scope_lookup_current(Scope *s, String const &name) { +gb_internal Entity *scope_lookup_current(Scope *s, String const &name) { Entity **found = string_map_get(&s->elements, name); if (found) { return *found; @@ -410,7 +410,7 @@ Entity *scope_lookup_current(Scope *s, String const &name) { return nullptr; } -void scope_lookup_parent(Scope *scope, String const &name, Scope **scope_, Entity **entity_) { +gb_internal void scope_lookup_parent(Scope *scope, String const &name, Scope **scope_, Entity **entity_) { if (scope != nullptr) { bool gone_thru_proc = false; bool gone_thru_package = false; @@ -455,7 +455,7 @@ void scope_lookup_parent(Scope *scope, String const &name, Scope **scope_, Entit if (scope_) *scope_ = nullptr; } -Entity *scope_lookup(Scope *s, String const &name) { +gb_internal Entity *scope_lookup(Scope *s, String const &name) { Entity *entity = nullptr; scope_lookup_parent(s, name, nullptr, &entity); return entity; @@ -463,7 +463,7 @@ Entity *scope_lookup(Scope *s, String const &name) { -Entity *scope_insert_with_name(Scope *s, String const &name, Entity *entity, bool use_mutex=true) { +gb_internal Entity *scope_insert_with_name(Scope *s, String const &name, Entity *entity, bool use_mutex=true) { if (name == "") { return nullptr; } @@ -502,7 +502,7 @@ end:; return result; } -Entity *scope_insert(Scope *s, Entity *entity, bool use_mutex) { +gb_internal Entity *scope_insert(Scope *s, Entity *entity, bool use_mutex) { String name = entity->token.string; return scope_insert_with_name(s, name, entity, use_mutex); } @@ -528,14 +528,14 @@ struct VettedEntity { Entity *entity; Entity *other; }; -void init_vetted_entity(VettedEntity *ve, VettedEntityKind kind, Entity *entity, Entity *other=nullptr) { +gb_internal void init_vetted_entity(VettedEntity *ve, VettedEntityKind kind, Entity *entity, Entity *other=nullptr) { ve->kind = kind; ve->entity = entity; ve->other = other; } -GB_COMPARE_PROC(vetted_entity_variable_pos_cmp) { +gb_internal GB_COMPARE_PROC(vetted_entity_variable_pos_cmp) { Entity *x = (cast(VettedEntity *)a)->entity; Entity *y = (cast(VettedEntity *)b)->entity; GB_ASSERT(x != nullptr); @@ -544,7 +544,7 @@ GB_COMPARE_PROC(vetted_entity_variable_pos_cmp) { return token_pos_cmp(x->token.pos, y->token.pos); } -bool check_vet_shadowing_assignment(Checker *c, Entity *shadowed, Ast *expr) { +gb_internal bool check_vet_shadowing_assignment(Checker *c, Entity *shadowed, Ast *expr) { Ast *init = unparen_expr(expr); if (init == nullptr) { return false; @@ -568,7 +568,7 @@ bool check_vet_shadowing_assignment(Checker *c, Entity *shadowed, Ast *expr) { } -bool check_vet_shadowing(Checker *c, Entity *e, VettedEntity *ve) { +gb_internal bool check_vet_shadowing(Checker *c, Entity *e, VettedEntity *ve) { if (e->kind != Entity_Variable) { return false; } @@ -634,7 +634,7 @@ bool check_vet_shadowing(Checker *c, Entity *e, VettedEntity *ve) { return true; } -bool check_vet_unused(Checker *c, Entity *e, VettedEntity *ve) { +gb_internal bool check_vet_unused(Checker *c, Entity *e, VettedEntity *ve) { if ((e->flags&EntityFlag_Used) == 0) { switch (e->kind) { case Entity_Variable: @@ -652,7 +652,7 @@ bool check_vet_unused(Checker *c, Entity *e, VettedEntity *ve) { return false; } -void check_scope_usage(Checker *c, Scope *scope) { +gb_internal void check_scope_usage(Checker *c, Scope *scope) { bool vet_unused = true; bool vet_shadowing = true; @@ -728,12 +728,12 @@ void check_scope_usage(Checker *c, Scope *scope) { } -void add_dependency(CheckerInfo *info, DeclInfo *d, Entity *e) { +gb_internal void add_dependency(CheckerInfo *info, DeclInfo *d, Entity *e) { mutex_lock(&info->deps_mutex); ptr_set_add(&d->deps, e); mutex_unlock(&info->deps_mutex); } -void add_type_info_dependency(CheckerInfo *info, DeclInfo *d, Type *type, bool require_mutex) { +gb_internal void add_type_info_dependency(CheckerInfo *info, DeclInfo *d, Type *type, bool require_mutex) { if (d == nullptr) { return; } @@ -746,7 +746,7 @@ void add_type_info_dependency(CheckerInfo *info, DeclInfo *d, Type *type, bool r } } -AstPackage *get_core_package(CheckerInfo *info, String name) { +gb_internal AstPackage *get_core_package(CheckerInfo *info, String name) { gbAllocator a = heap_allocator(); String path = get_fullpath_core(a, name); defer (gb_free(a, path.text)); @@ -764,7 +764,7 @@ AstPackage *get_core_package(CheckerInfo *info, String name) { } -void add_package_dependency(CheckerContext *c, char const *package_name, char const *name) { +gb_internal void add_package_dependency(CheckerContext *c, char const *package_name, char const *name) { String n = make_string_c(name); AstPackage *p = get_core_package(&c->checker->info, make_string_c(package_name)); Entity *e = scope_lookup(p->scope, n); @@ -774,7 +774,7 @@ void add_package_dependency(CheckerContext *c, char const *package_name, char co add_dependency(c->info, c->decl, e); } -void try_to_add_package_dependency(CheckerContext *c, char const *package_name, char const *name) { +gb_internal void try_to_add_package_dependency(CheckerContext *c, char const *package_name, char const *name) { String n = make_string_c(name); AstPackage *p = get_core_package(&c->checker->info, make_string_c(package_name)); Entity *e = scope_lookup(p->scope, n); @@ -787,7 +787,7 @@ void try_to_add_package_dependency(CheckerContext *c, char const *package_name, } -void add_declaration_dependency(CheckerContext *c, Entity *e) { +gb_internal void add_declaration_dependency(CheckerContext *c, Entity *e) { if (e == nullptr) { return; } @@ -797,7 +797,7 @@ void add_declaration_dependency(CheckerContext *c, Entity *e) { } -Entity *add_global_entity(Entity *entity, Scope *scope=builtin_pkg->scope) { +gb_internal Entity *add_global_entity(Entity *entity, Scope *scope=builtin_pkg->scope) { String name = entity->token.string; defer (entity->state = EntityState_Resolved); @@ -810,27 +810,27 @@ Entity *add_global_entity(Entity *entity, Scope *scope=builtin_pkg->scope) { return entity; } -void add_global_constant(char const *name, Type *type, ExactValue value) { +gb_internal void add_global_constant(char const *name, Type *type, ExactValue value) { Entity *entity = alloc_entity(Entity_Constant, nullptr, make_token_ident(name), type); entity->Constant.value = value; add_global_entity(entity); } -void add_global_string_constant(char const *name, String const &value) { +gb_internal void add_global_string_constant(char const *name, String const &value) { add_global_constant(name, t_untyped_string, exact_value_string(value)); } -void add_global_bool_constant(char const *name, bool value) { +gb_internal void add_global_bool_constant(char const *name, bool value) { add_global_constant(name, t_untyped_bool, exact_value_bool(value)); } -void add_global_type_entity(String name, Type *type) { +gb_internal void add_global_type_entity(String name, Type *type) { add_global_entity(alloc_entity_type_name(nullptr, make_token_ident(name), type)); } -AstPackage *create_builtin_package(char const *name) { +gb_internal AstPackage *create_builtin_package(char const *name) { gbAllocator a = permanent_allocator(); AstPackage *pkg = gb_alloc_item(a, AstPackage); pkg->name = make_string_c(name); @@ -847,7 +847,7 @@ struct GlobalEnumValue { i64 value; }; -Slice add_global_enum_type(String const &type_name, GlobalEnumValue *values, isize value_count, Type **enum_type_ = nullptr) { +gb_internal Slice add_global_enum_type(String const &type_name, GlobalEnumValue *values, isize value_count, Type **enum_type_ = nullptr) { Scope *scope = create_scope(nullptr, builtin_pkg->scope); Entity *entity = alloc_entity_type_name(scope, make_token_ident(type_name), nullptr, EntityState_Resolved); @@ -882,7 +882,7 @@ Slice add_global_enum_type(String const &type_name, GlobalEnumValue *v return slice_from_array(fields); } -void add_global_enum_constant(Slice const &fields, char const *name, i64 value) { +gb_internal void add_global_enum_constant(Slice const &fields, char const *name, i64 value) { for (Entity *field : fields) { GB_ASSERT(field->kind == Entity_Constant); if (value == exact_value_to_i64(field->Constant.value)) { @@ -893,7 +893,7 @@ void add_global_enum_constant(Slice const &fields, char const *name, i GB_PANIC("Unfound enum value for global constant: %s %lld", name, cast(long long)value); } -Type *add_global_type_name(Scope *scope, String const &type_name, Type *backing_type) { +gb_internal Type *add_global_type_name(Scope *scope, String const &type_name, Type *backing_type) { Entity *e = alloc_entity_type_name(scope, make_token_ident(type_name), nullptr, EntityState_Resolved); Type *named_type = alloc_type_named(type_name, backing_type, e); e->type = named_type; @@ -905,7 +905,7 @@ Type *add_global_type_name(Scope *scope, String const &type_name, Type *backing_ } -void init_universal(void) { +gb_internal void init_universal(void) { BuildContext *bc = &build_context; builtin_pkg = create_builtin_package("builtin"); @@ -1122,7 +1122,7 @@ void init_universal(void) { -void init_checker_info(CheckerInfo *i) { +gb_internal void init_checker_info(CheckerInfo *i) { gbAllocator a = heap_allocator(); TIME_SECTION("checker info: general"); @@ -1180,7 +1180,7 @@ void init_checker_info(CheckerInfo *i) { string_map_init(&i->load_file_cache, a); } -void destroy_checker_info(CheckerInfo *i) { +gb_internal void destroy_checker_info(CheckerInfo *i) { array_free(&i->definitions); array_free(&i->entities); map_destroy(&i->global_untyped); @@ -1217,7 +1217,7 @@ void destroy_checker_info(CheckerInfo *i) { string_map_destroy(&i->load_file_cache); } -CheckerContext make_checker_context(Checker *c) { +gb_internal CheckerContext make_checker_context(Checker *c) { CheckerContext ctx = {}; ctx.checker = c; ctx.info = &c->info; @@ -1230,12 +1230,12 @@ CheckerContext make_checker_context(Checker *c) { ctx.poly_level = 0; return ctx; } -void destroy_checker_context(CheckerContext *ctx) { +gb_internal void destroy_checker_context(CheckerContext *ctx) { destroy_checker_type_path(ctx->type_path); destroy_checker_poly_path(ctx->poly_path); } -void add_curr_ast_file(CheckerContext *ctx, AstFile *file) { +gb_internal void add_curr_ast_file(CheckerContext *ctx, AstFile *file) { if (file != nullptr) { ctx->file = file; ctx->decl = file->pkg->decl_info; @@ -1243,7 +1243,7 @@ void add_curr_ast_file(CheckerContext *ctx, AstFile *file) { ctx->pkg = file->pkg; } } -void reset_checker_context(CheckerContext *ctx, AstFile *file, UntypedExprInfoMap *untyped) { +gb_internal void reset_checker_context(CheckerContext *ctx, AstFile *file, UntypedExprInfoMap *untyped) { if (ctx == nullptr) { return; } @@ -1258,7 +1258,7 @@ void reset_checker_context(CheckerContext *ctx, AstFile *file, UntypedExprInfoMa -void init_checker(Checker *c) { +gb_internal void init_checker(Checker *c) { gbAllocator a = heap_allocator(); TIME_SECTION("init checker info"); @@ -1278,7 +1278,7 @@ void init_checker(Checker *c) { c->builtin_ctx = make_checker_context(c); } -void destroy_checker(Checker *c) { +gb_internal void destroy_checker(Checker *c) { destroy_checker_info(&c->info); destroy_checker_context(&c->builtin_ctx); @@ -1290,7 +1290,7 @@ void destroy_checker(Checker *c) { } -TypeAndValue type_and_value_of_expr(Ast *expr) { +gb_internal TypeAndValue type_and_value_of_expr(Ast *expr) { TypeAndValue tav = {}; if (expr != nullptr) { tav = expr->tav; @@ -1298,7 +1298,7 @@ TypeAndValue type_and_value_of_expr(Ast *expr) { return tav; } -Type *type_of_expr(Ast *expr) { +gb_internal Type *type_of_expr(Ast *expr) { TypeAndValue tav = expr->tav; if (tav.mode != Addressing_Invalid) { return tav.type; @@ -1313,14 +1313,14 @@ Type *type_of_expr(Ast *expr) { return nullptr; } -Entity *implicit_entity_of_node(Ast *clause) { +gb_internal Entity *implicit_entity_of_node(Ast *clause) { if (clause != nullptr && clause->kind == Ast_CaseClause) { return clause->CaseClause.implicit_entity; } return nullptr; } -Entity *entity_of_node(Ast *expr) { +gb_internal Entity *entity_of_node(Ast *expr) { expr = unparen_expr(expr); switch (expr->kind) { case_ast_node(ident, Ident, expr); @@ -1341,25 +1341,25 @@ Entity *entity_of_node(Ast *expr) { return nullptr; } -DeclInfo *decl_info_of_entity(Entity *e) { +gb_internal DeclInfo *decl_info_of_entity(Entity *e) { if (e != nullptr) { return e->decl_info; } return nullptr; } -DeclInfo *decl_info_of_ident(Ast *ident) { +gb_internal DeclInfo *decl_info_of_ident(Ast *ident) { return decl_info_of_entity(entity_of_node(ident)); } -AstFile *ast_file_of_filename(CheckerInfo *i, String filename) { +gb_internal AstFile *ast_file_of_filename(CheckerInfo *i, String filename) { AstFile **found = string_map_get(&i->files, filename); if (found != nullptr) { return *found; } return nullptr; } -ExprInfo *check_get_expr_info(CheckerContext *c, Ast *expr) { +gb_internal ExprInfo *check_get_expr_info(CheckerContext *c, Ast *expr) { if (c->untyped != nullptr) { ExprInfo **found = map_get(c->untyped, expr); if (found) { @@ -1377,7 +1377,7 @@ ExprInfo *check_get_expr_info(CheckerContext *c, Ast *expr) { } } -void check_set_expr_info(CheckerContext *c, Ast *expr, AddressingMode mode, Type *type, ExactValue value) { +gb_internal void check_set_expr_info(CheckerContext *c, Ast *expr, AddressingMode mode, Type *type, ExactValue value) { if (c->untyped != nullptr) { map_set(c->untyped, expr, make_expr_info(mode, type, value, false)); } else { @@ -1387,7 +1387,7 @@ void check_set_expr_info(CheckerContext *c, Ast *expr, AddressingMode mode, Type } } -void check_remove_expr_info(CheckerContext *c, Ast *e) { +gb_internal void check_remove_expr_info(CheckerContext *c, Ast *e) { if (c->untyped != nullptr) { map_remove(c->untyped, e); GB_ASSERT(map_get(c->untyped, e) == nullptr); @@ -1401,7 +1401,7 @@ void check_remove_expr_info(CheckerContext *c, Ast *e) { } -isize type_info_index(CheckerInfo *info, Type *type, bool error_on_failure) { +gb_internal isize type_info_index(CheckerInfo *info, Type *type, bool error_on_failure) { type = default_type(type); if (type == t_llvm_bool) { type = t_bool; @@ -1436,7 +1436,7 @@ isize type_info_index(CheckerInfo *info, Type *type, bool error_on_failure) { } -void add_untyped(CheckerContext *c, Ast *expr, AddressingMode mode, Type *type, ExactValue value) { +gb_internal void add_untyped(CheckerContext *c, Ast *expr, AddressingMode mode, Type *type, ExactValue value) { if (expr == nullptr) { return; } @@ -1453,7 +1453,7 @@ void add_untyped(CheckerContext *c, Ast *expr, AddressingMode mode, Type *type, check_set_expr_info(c, expr, mode, type, value); } -void add_type_and_value(CheckerInfo *i, Ast *expr, AddressingMode mode, Type *type, ExactValue value) { +gb_internal void add_type_and_value(CheckerInfo *i, Ast *expr, AddressingMode mode, Type *type, ExactValue value) { if (expr == nullptr) { return; } @@ -1489,7 +1489,7 @@ void add_type_and_value(CheckerInfo *i, Ast *expr, AddressingMode mode, Type *ty mutex_unlock(&i->type_and_value_mutex); } -void add_entity_definition(CheckerInfo *i, Ast *identifier, Entity *entity) { +gb_internal void add_entity_definition(CheckerInfo *i, Ast *identifier, Entity *entity) { GB_ASSERT(identifier != nullptr); GB_ASSERT(identifier->kind == Ast_Ident); // if (is_blank_ident(identifier)) { @@ -1505,7 +1505,7 @@ void add_entity_definition(CheckerInfo *i, Ast *identifier, Entity *entity) { mpmc_enqueue(&i->definition_queue, entity); } -bool redeclaration_error(String name, Entity *prev, Entity *found) { +gb_internal bool redeclaration_error(String name, Entity *prev, Entity *found) { TokenPos pos = found->token.pos; Entity *up = found->using_parent; if (up != nullptr) { @@ -1548,7 +1548,7 @@ bool redeclaration_error(String name, Entity *prev, Entity *found) { return false; } -void add_entity_flags_from_file(CheckerContext *c, Entity *e, Scope *scope) { +gb_internal void add_entity_flags_from_file(CheckerContext *c, Entity *e, Scope *scope) { if (c->file != nullptr && (c->file->flags & AstFile_IsLazy) != 0 && scope->flags & ScopeFlag_File) { AstPackage *pkg = c->file->pkg; if (pkg->kind == Package_Init && e->kind == Entity_Procedure && e->token.string == "main") { @@ -1561,7 +1561,7 @@ void add_entity_flags_from_file(CheckerContext *c, Entity *e, Scope *scope) { } } -bool add_entity_with_name(CheckerContext *c, Scope *scope, Ast *identifier, Entity *entity, String name) { +gb_internal bool add_entity_with_name(CheckerContext *c, Scope *scope, Ast *identifier, Entity *entity, String name) { if (scope == nullptr) { return false; } @@ -1581,11 +1581,11 @@ bool add_entity_with_name(CheckerContext *c, Scope *scope, Ast *identifier, Enti } return true; } -bool add_entity(CheckerContext *c, Scope *scope, Ast *identifier, Entity *entity) { +gb_internal bool add_entity(CheckerContext *c, Scope *scope, Ast *identifier, Entity *entity) { return add_entity_with_name(c, scope, identifier, entity, entity->token.string); } -void add_entity_use(CheckerContext *c, Ast *identifier, Entity *entity) { +gb_internal void add_entity_use(CheckerContext *c, Ast *identifier, Entity *entity) { if (entity == nullptr) { return; } @@ -1622,7 +1622,7 @@ void add_entity_use(CheckerContext *c, Ast *identifier, Entity *entity) { } -bool could_entity_be_lazy(Entity *e, DeclInfo *d) { +gb_internal bool could_entity_be_lazy(Entity *e, DeclInfo *d) { if ((e->flags & EntityFlag_Lazy) == 0) { return false; } @@ -1673,7 +1673,7 @@ bool could_entity_be_lazy(Entity *e, DeclInfo *d) { return true; } -void add_entity_and_decl_info(CheckerContext *c, Ast *identifier, Entity *e, DeclInfo *d, bool is_exported) { +gb_internal void add_entity_and_decl_info(CheckerContext *c, Ast *identifier, Entity *e, DeclInfo *d, bool is_exported) { if (identifier == nullptr) { // NOTE(bill): Should only happen on errors error(e->token, "Invalid variable declaration"); @@ -1738,16 +1738,15 @@ void add_entity_and_decl_info(CheckerContext *c, Ast *identifier, Entity *e, Dec } -void add_implicit_entity(CheckerContext *c, Ast *clause, Entity *e) { +gb_internal void add_implicit_entity(CheckerContext *c, Ast *clause, Entity *e) { GB_ASSERT(clause != nullptr); GB_ASSERT(e != nullptr); GB_ASSERT(clause->kind == Ast_CaseClause); clause->CaseClause.implicit_entity = e; } -void add_type_info_type(CheckerContext *c, Type *t) { - void add_type_info_type_internal(CheckerContext *c, Type *t); - +gb_internal void add_type_info_type_internal(CheckerContext *c, Type *t); +gb_internal void add_type_info_type(CheckerContext *c, Type *t) { if (build_context.disallow_rtti) { return; } @@ -1757,7 +1756,7 @@ void add_type_info_type(CheckerContext *c, Type *t) { mutex_unlock(&c->info->type_info_mutex); } -void add_type_info_type_internal(CheckerContext *c, Type *t) { +gb_internal void add_type_info_type_internal(CheckerContext *c, Type *t) { if (t == nullptr) { return; } @@ -1982,7 +1981,7 @@ void add_type_info_type_internal(CheckerContext *c, Type *t) { gb_global bool global_procedure_body_in_worker_queue = false; -void check_procedure_later(CheckerContext *c, ProcInfo *info) { +gb_internal void check_procedure_later(CheckerContext *c, ProcInfo *info) { GB_ASSERT(info != nullptr); GB_ASSERT(info->decl != nullptr); @@ -1994,7 +1993,7 @@ void check_procedure_later(CheckerContext *c, ProcInfo *info) { mpmc_enqueue(queue, info); } -void check_procedure_later(CheckerContext *c, AstFile *file, Token token, DeclInfo *decl, Type *type, Ast *body, u64 tags) { +gb_internal void check_procedure_later(CheckerContext *c, AstFile *file, Token token, DeclInfo *decl, Type *type, Ast *body, u64 tags) { ProcInfo *info = gb_alloc_item(permanent_allocator(), ProcInfo); info->file = file; info->token = token; @@ -2006,7 +2005,7 @@ void check_procedure_later(CheckerContext *c, AstFile *file, Token token, DeclIn } -void add_min_dep_type_info(Checker *c, Type *t) { +gb_internal void add_min_dep_type_info(Checker *c, Type *t) { if (t == nullptr) { return; } @@ -2201,7 +2200,7 @@ void add_min_dep_type_info(Checker *c, Type *t) { } -void add_dependency_to_set(Checker *c, Entity *entity) { +gb_internal void add_dependency_to_set(Checker *c, Entity *entity) { if (entity == nullptr) { return; } @@ -2254,7 +2253,7 @@ void add_dependency_to_set(Checker *c, Entity *entity) { } } -void force_add_dependency_entity(Checker *c, Scope *scope, String const &name) { +gb_internal void force_add_dependency_entity(Checker *c, Scope *scope, String const &name) { Entity *e = scope_lookup(scope, name); if (e == nullptr) { return; @@ -2266,7 +2265,7 @@ void force_add_dependency_entity(Checker *c, Scope *scope, String const &name) { -void generate_minimum_dependency_set(Checker *c, Entity *start) { +gb_internal void generate_minimum_dependency_set(Checker *c, Entity *start) { isize entity_count = c->info.entities.count; isize min_dep_set_cap = next_pow2_isize(entity_count*4); // empirically determined factor @@ -2479,7 +2478,7 @@ void generate_minimum_dependency_set(Checker *c, Entity *start) { #undef FORCE_ADD_RUNTIME_ENTITIES } -bool is_entity_a_dependency(Entity *e) { +gb_internal bool is_entity_a_dependency(Entity *e) { if (e == nullptr) return false; switch (e->kind) { case Entity_Procedure: @@ -2493,7 +2492,7 @@ bool is_entity_a_dependency(Entity *e) { return false; } -Array generate_entity_dependency_graph(CheckerInfo *info, gbAllocator allocator) { +gb_internal Array generate_entity_dependency_graph(CheckerInfo *info, gbAllocator allocator) { PtrMap M = {}; map_init(&M, allocator, info->entities.count); defer (map_destroy(&M)); @@ -2612,10 +2611,10 @@ Array generate_entity_dependency_graph(CheckerInfo *info, gbA } -void check_single_global_entity(Checker *c, Entity *e, DeclInfo *d); +gb_internal void check_single_global_entity(Checker *c, Entity *e, DeclInfo *d); -Entity *find_core_entity(Checker *c, String name) { +gb_internal Entity *find_core_entity(Checker *c, String name) { Entity *e = scope_lookup_current(c->info.runtime_package->scope, name); if (e == nullptr) { compiler_error("Could not find type declaration for '%.*s'\n" @@ -2625,7 +2624,7 @@ Entity *find_core_entity(Checker *c, String name) { return e; } -Type *find_core_type(Checker *c, String name) { +gb_internal Type *find_core_type(Checker *c, String name) { Entity *e = scope_lookup_current(c->info.runtime_package->scope, name); if (e == nullptr) { compiler_error("Could not find type declaration for '%.*s'\n" @@ -2640,7 +2639,7 @@ Type *find_core_type(Checker *c, String name) { } -Entity *find_entity_in_pkg(CheckerInfo *info, String const &pkg, String const &name) { +gb_internal Entity *find_entity_in_pkg(CheckerInfo *info, String const &pkg, String const &name) { AstPackage *package = get_core_package(info, pkg); Entity *e = scope_lookup_current(package->scope, name); if (e == nullptr) { @@ -2650,7 +2649,7 @@ Entity *find_entity_in_pkg(CheckerInfo *info, String const &pkg, String const &n return e; } -Type *find_type_in_pkg(CheckerInfo *info, String const &pkg, String const &name) { +gb_internal Type *find_type_in_pkg(CheckerInfo *info, String const &pkg, String const &name) { AstPackage *package = get_core_package(info, pkg); Entity *e = scope_lookup_current(package->scope, name); if (e == nullptr) { @@ -2661,58 +2660,58 @@ Type *find_type_in_pkg(CheckerInfo *info, String const &pkg, String const &name) return e->type; } -CheckerTypePath *new_checker_type_path() { +gb_internal CheckerTypePath *new_checker_type_path() { gbAllocator a = heap_allocator(); auto *tp = gb_alloc_item(a, CheckerTypePath); array_init(tp, a, 0, 16); return tp; } -void destroy_checker_type_path(CheckerTypePath *tp) { +gb_internal void destroy_checker_type_path(CheckerTypePath *tp) { array_free(tp); gb_free(heap_allocator(), tp); } -void check_type_path_push(CheckerContext *c, Entity *e) { +gb_internal void check_type_path_push(CheckerContext *c, Entity *e) { GB_ASSERT(c->type_path != nullptr); GB_ASSERT(e != nullptr); array_add(c->type_path, e); } -Entity *check_type_path_pop(CheckerContext *c) { +gb_internal Entity *check_type_path_pop(CheckerContext *c) { GB_ASSERT(c->type_path != nullptr); return array_pop(c->type_path); } -CheckerPolyPath *new_checker_poly_path(void) { +gb_internal CheckerPolyPath *new_checker_poly_path(void) { gbAllocator a = heap_allocator(); auto *pp = gb_alloc_item(a, CheckerPolyPath); array_init(pp, a, 0, 16); return pp; } -void destroy_checker_poly_path(CheckerPolyPath *pp) { +gb_internal void destroy_checker_poly_path(CheckerPolyPath *pp) { array_free(pp); gb_free(heap_allocator(), pp); } -void check_poly_path_push(CheckerContext *c, Type *t) { +gb_internal void check_poly_path_push(CheckerContext *c, Type *t) { GB_ASSERT(c->poly_path != nullptr); GB_ASSERT(t != nullptr); GB_ASSERT(is_type_polymorphic(t)); array_add(c->poly_path, t); } -Type *check_poly_path_pop(CheckerContext *c) { +gb_internal Type *check_poly_path_pop(CheckerContext *c) { GB_ASSERT(c->poly_path != nullptr); return array_pop(c->poly_path); } -Array proc_group_entities(CheckerContext *c, Operand o) { +gb_internal Array proc_group_entities(CheckerContext *c, Operand o) { Array procs = {}; if (o.mode == Addressing_ProcGroup) { GB_ASSERT(o.proc_group != nullptr); @@ -2724,7 +2723,7 @@ Array proc_group_entities(CheckerContext *c, Operand o) { return procs; } -Array proc_group_entities_cloned(CheckerContext *c, Operand o) { +gb_internal Array proc_group_entities_cloned(CheckerContext *c, Operand o) { auto entities = proc_group_entities(c, o); if (entities.count == 0) { return {}; @@ -2735,7 +2734,7 @@ Array proc_group_entities_cloned(CheckerContext *c, Operand o) { -void init_core_type_info(Checker *c) { +gb_internal void init_core_type_info(Checker *c) { if (t_type_info != nullptr) { return; } @@ -2816,7 +2815,7 @@ void init_core_type_info(Checker *c) { t_type_info_soa_pointer_ptr = alloc_type_pointer(t_type_info_soa_pointer); } -void init_mem_allocator(Checker *c) { +gb_internal void init_mem_allocator(Checker *c) { if (t_allocator != nullptr) { return; } @@ -2825,7 +2824,7 @@ void init_mem_allocator(Checker *c) { t_allocator_error = find_core_type(c, str_lit("Allocator_Error")); } -void init_core_context(Checker *c) { +gb_internal void init_core_context(Checker *c) { if (t_context != nullptr) { return; } @@ -2833,7 +2832,7 @@ void init_core_context(Checker *c) { t_context_ptr = alloc_type_pointer(t_context); } -void init_core_source_code_location(Checker *c) { +gb_internal void init_core_source_code_location(Checker *c) { if (t_source_code_location != nullptr) { return; } @@ -2841,7 +2840,7 @@ void init_core_source_code_location(Checker *c) { t_source_code_location_ptr = alloc_type_pointer(t_source_code_location); } -void init_core_map_type(Checker *c) { +gb_internal void init_core_map_type(Checker *c) { if (t_map_info != nullptr) { return; } @@ -2855,7 +2854,7 @@ void init_core_map_type(Checker *c) { t_raw_map_ptr = alloc_type_pointer(t_raw_map); } -void init_preload(Checker *c) { +gb_internal void init_preload(Checker *c) { init_core_type_info(c); init_mem_allocator(c); init_core_context(c); @@ -2863,7 +2862,7 @@ void init_preload(Checker *c) { init_core_map_type(c); } -ExactValue check_decl_attribute_value(CheckerContext *c, Ast *value) { +gb_internal ExactValue check_decl_attribute_value(CheckerContext *c, Ast *value) { ExactValue ev = {}; if (value != nullptr) { Operand op = {}; @@ -2879,7 +2878,7 @@ ExactValue check_decl_attribute_value(CheckerContext *c, Ast *value) { return ev; } -Type *check_decl_attribute_type(CheckerContext *c, Ast *value) { +gb_internal Type *check_decl_attribute_type(CheckerContext *c, Ast *value) { if (value != nullptr) { return check_type(c, value); } @@ -2890,7 +2889,7 @@ Type *check_decl_attribute_type(CheckerContext *c, Ast *value) { #define ATTRIBUTE_USER_TAG_NAME "tag" -DECL_ATTRIBUTE_PROC(foreign_block_decl_attribute) { +gb_internal DECL_ATTRIBUTE_PROC(foreign_block_decl_attribute) { ExactValue ev = check_decl_attribute_value(c, value); if (name == ATTRIBUTE_USER_TAG_NAME) { @@ -2945,7 +2944,7 @@ DECL_ATTRIBUTE_PROC(foreign_block_decl_attribute) { return false; } -DECL_ATTRIBUTE_PROC(proc_decl_attribute) { +gb_internal DECL_ATTRIBUTE_PROC(proc_decl_attribute) { if (name == ATTRIBUTE_USER_TAG_NAME) { ExactValue ev = check_decl_attribute_value(c, value); if (ev.kind != ExactValue_String) { @@ -3242,7 +3241,7 @@ DECL_ATTRIBUTE_PROC(proc_decl_attribute) { return false; } -DECL_ATTRIBUTE_PROC(var_decl_attribute) { +gb_internal DECL_ATTRIBUTE_PROC(var_decl_attribute) { if (name == ATTRIBUTE_USER_TAG_NAME) { ExactValue ev = check_decl_attribute_value(c, value); if (ev.kind != ExactValue_String) { @@ -3367,7 +3366,7 @@ DECL_ATTRIBUTE_PROC(var_decl_attribute) { return false; } -DECL_ATTRIBUTE_PROC(const_decl_attribute) { +gb_internal DECL_ATTRIBUTE_PROC(const_decl_attribute) { if (name == ATTRIBUTE_USER_TAG_NAME) { ExactValue ev = check_decl_attribute_value(c, value); if (ev.kind != ExactValue_String) { @@ -3381,7 +3380,7 @@ DECL_ATTRIBUTE_PROC(const_decl_attribute) { return false; } -DECL_ATTRIBUTE_PROC(type_decl_attribute) { +gb_internal DECL_ATTRIBUTE_PROC(type_decl_attribute) { if (name == ATTRIBUTE_USER_TAG_NAME) { ExactValue ev = check_decl_attribute_value(c, value); if (ev.kind != ExactValue_String) { @@ -3412,7 +3411,7 @@ DECL_ATTRIBUTE_PROC(type_decl_attribute) { -void check_decl_attributes(CheckerContext *c, Array const &attributes, DeclAttributeProc *proc, AttributeContext *ac) { +gb_internal void check_decl_attributes(CheckerContext *c, Array const &attributes, DeclAttributeProc *proc, AttributeContext *ac) { if (attributes.count == 0) return; String original_link_prefix = {}; @@ -3480,7 +3479,7 @@ void check_decl_attributes(CheckerContext *c, Array const &attributes, De } -isize get_total_value_count(Slice const &values) { +gb_internal isize get_total_value_count(Slice const &values) { isize count = 0; for_array(i, values) { Type *t = type_of_expr(values[i]); @@ -3498,7 +3497,7 @@ isize get_total_value_count(Slice const &values) { return count; } -bool check_arity_match(CheckerContext *c, AstValueDecl *vd, bool is_global) { +gb_internal bool check_arity_match(CheckerContext *c, AstValueDecl *vd, bool is_global) { isize lhs = vd->names.count; isize rhs = 0; if (is_global) { @@ -3541,7 +3540,7 @@ bool check_arity_match(CheckerContext *c, AstValueDecl *vd, bool is_global) { return true; } -void check_collect_entities_from_when_stmt(CheckerContext *c, AstWhenStmt *ws) { +gb_internal void check_collect_entities_from_when_stmt(CheckerContext *c, AstWhenStmt *ws) { Operand operand = {Addressing_Invalid}; if (!ws->is_cond_determined) { check_expr(c, &operand, ws->cond); @@ -3577,7 +3576,7 @@ void check_collect_entities_from_when_stmt(CheckerContext *c, AstWhenStmt *ws) { } } -void check_builtin_attributes(CheckerContext *ctx, Entity *e, Array *attributes) { +gb_internal void check_builtin_attributes(CheckerContext *ctx, Entity *e, Array *attributes) { switch (e->kind) { case Entity_ProcGroup: case Entity_Procedure: @@ -3640,7 +3639,7 @@ void check_builtin_attributes(CheckerContext *ctx, Entity *e, Array *attr } } -void check_collect_value_decl(CheckerContext *c, Ast *decl) { +gb_internal void check_collect_value_decl(CheckerContext *c, Ast *decl) { if (decl->state_flags & StateFlag_BeenHandled) return; decl->state_flags |= StateFlag_BeenHandled; @@ -3891,7 +3890,7 @@ void check_collect_value_decl(CheckerContext *c, Ast *decl) { } } -void check_add_foreign_block_decl(CheckerContext *ctx, Ast *decl) { +gb_internal void check_add_foreign_block_decl(CheckerContext *ctx, Ast *decl) { if (decl->state_flags & StateFlag_BeenHandled) return; decl->state_flags |= StateFlag_BeenHandled; @@ -3912,7 +3911,7 @@ void check_add_foreign_block_decl(CheckerContext *ctx, Ast *decl) { check_collect_entities(&c, block->stmts); } -bool correct_single_type_alias(CheckerContext *c, Entity *e) { +gb_internal bool correct_single_type_alias(CheckerContext *c, Entity *e) { if (e->kind == Entity_Constant) { DeclInfo *d = e->decl_info; if (d != nullptr && d->init_expr != nullptr) { @@ -3927,7 +3926,7 @@ bool correct_single_type_alias(CheckerContext *c, Entity *e) { return false; } -bool correct_type_alias_in_scope_backwards(CheckerContext *c, Scope *s) { +gb_internal bool correct_type_alias_in_scope_backwards(CheckerContext *c, Scope *s) { isize n = s->elements.entries.count; bool correction = false; for (isize i = n-1; i >= 0; i--) { @@ -3935,7 +3934,7 @@ bool correct_type_alias_in_scope_backwards(CheckerContext *c, Scope *s) { } return correction; } -bool correct_type_alias_in_scope_forwards(CheckerContext *c, Scope *s) { +gb_internal bool correct_type_alias_in_scope_forwards(CheckerContext *c, Scope *s) { isize n = s->elements.entries.count; bool correction = false; for (isize i = 0; i < n; i++) { @@ -3945,7 +3944,7 @@ bool correct_type_alias_in_scope_forwards(CheckerContext *c, Scope *s) { } -void correct_type_aliases_in_scope(CheckerContext *c, Scope *s) { +gb_internal void correct_type_aliases_in_scope(CheckerContext *c, Scope *s) { // NOTE(bill, 2022-02-04): This is used to solve the problem caused by type aliases // of type aliases being "confused" as constants // @@ -3966,7 +3965,7 @@ void correct_type_aliases_in_scope(CheckerContext *c, Scope *s) { // NOTE(bill): If file_scopes == nullptr, this will act like a local scope -void check_collect_entities(CheckerContext *c, Slice const &nodes) { +gb_internal void check_collect_entities(CheckerContext *c, Slice const &nodes) { AstFile *curr_file = nullptr; if ((c->scope->flags&ScopeFlag_File) != 0) { curr_file = c->scope->file; @@ -4050,13 +4049,13 @@ void check_collect_entities(CheckerContext *c, Slice const &nodes) { } } -CheckerContext *create_checker_context(Checker *c) { +gb_internal CheckerContext *create_checker_context(Checker *c) { CheckerContext *ctx = gb_alloc_item(permanent_allocator(), CheckerContext); *ctx = make_checker_context(c); return ctx; } -void check_single_global_entity(Checker *c, Entity *e, DeclInfo *d) { +gb_internal void check_single_global_entity(Checker *c, Entity *e, DeclInfo *d) { GB_ASSERT(e != nullptr); GB_ASSERT(d != nullptr); @@ -4089,7 +4088,7 @@ void check_single_global_entity(Checker *c, Entity *e, DeclInfo *d) { check_entity_decl(ctx, e, d, nullptr); } -void check_all_global_entities(Checker *c) { +gb_internal void check_all_global_entities(Checker *c) { // NOTE(bill): This must be single threaded // Don't bother trying for_array(i, c->info.entities) { @@ -4107,7 +4106,7 @@ void check_all_global_entities(Checker *c) { } -bool is_string_an_identifier(String s) { +gb_internal bool is_string_an_identifier(String s) { isize offset = 0; if (s.len < 1) { return false; @@ -4131,7 +4130,7 @@ bool is_string_an_identifier(String s) { return offset == s.len; } -String path_to_entity_name(String name, String fullpath, bool strip_extension=true) { +gb_internal String path_to_entity_name(String name, String fullpath, bool strip_extension=true) { if (name.len != 0) { return name; } @@ -4177,7 +4176,7 @@ String path_to_entity_name(String name, String fullpath, bool strip_extension=tr #if 1 -void add_import_dependency_node(Checker *c, Ast *decl, PtrMap *M) { +gb_internal void add_import_dependency_node(Checker *c, Ast *decl, PtrMap *M) { AstPackage *parent_pkg = decl->file()->pkg; switch (decl->kind) { @@ -4242,7 +4241,7 @@ void add_import_dependency_node(Checker *c, Ast *decl, PtrMap generate_import_dependency_graph(Checker *c) { +gb_internal Array generate_import_dependency_graph(Checker *c) { PtrMap M = {}; map_init(&M, heap_allocator(), 2*c->parser->packages.count); defer (map_destroy(&M)); @@ -4285,7 +4284,7 @@ struct ImportPathItem { Ast * decl; }; -Array find_import_path(Checker *c, AstPackage *start, AstPackage *end, PtrSet *visited) { +gb_internal Array find_import_path(Checker *c, AstPackage *start, AstPackage *end, PtrSet *visited) { Array empty_path = {}; if (ptr_set_update(visited, start)) { @@ -4335,7 +4334,7 @@ Array find_import_path(Checker *c, AstPackage *start, AstPackage } #endif -String get_invalid_import_name(String input) { +gb_internal String get_invalid_import_name(String input) { isize slash = 0; for (isize i = input.len-1; i >= 0; i--) { if (input[i] == '/' || input[i] == '\\') { @@ -4347,7 +4346,7 @@ String get_invalid_import_name(String input) { return input; } -void check_add_import_decl(CheckerContext *ctx, Ast *decl) { +gb_internal void check_add_import_decl(CheckerContext *ctx, Ast *decl) { if (decl->state_flags & StateFlag_BeenHandled) return; decl->state_flags |= StateFlag_BeenHandled; @@ -4422,7 +4421,7 @@ void check_add_import_decl(CheckerContext *ctx, Ast *decl) { scope->flags |= ScopeFlag_HasBeenImported; } -DECL_ATTRIBUTE_PROC(foreign_import_decl_attribute) { +gb_internal DECL_ATTRIBUTE_PROC(foreign_import_decl_attribute) { if (name == ATTRIBUTE_USER_TAG_NAME) { ExactValue ev = check_decl_attribute_value(c, value); if (ev.kind != ExactValue_String) { @@ -4449,7 +4448,7 @@ DECL_ATTRIBUTE_PROC(foreign_import_decl_attribute) { return false; } -void check_add_foreign_import_decl(CheckerContext *ctx, Ast *decl) { +gb_internal void check_add_foreign_import_decl(CheckerContext *ctx, Ast *decl) { if (decl->state_flags & StateFlag_BeenHandled) return; decl->state_flags |= StateFlag_BeenHandled; @@ -4515,10 +4514,10 @@ void check_add_foreign_import_decl(CheckerContext *ctx, Ast *decl) { } // Returns true if a new package is present -bool collect_file_decls(CheckerContext *ctx, Slice const &decls); -bool collect_file_decls_from_when_stmt(CheckerContext *ctx, AstWhenStmt *ws); +gb_internal bool collect_file_decls(CheckerContext *ctx, Slice const &decls); +gb_internal bool collect_file_decls_from_when_stmt(CheckerContext *ctx, AstWhenStmt *ws); -bool collect_when_stmt_from_file(CheckerContext *ctx, AstWhenStmt *ws) { +gb_internal bool collect_when_stmt_from_file(CheckerContext *ctx, AstWhenStmt *ws) { Operand operand = {Addressing_Invalid}; if (!ws->is_cond_determined) { check_expr(ctx, &operand, ws->cond); @@ -4557,7 +4556,7 @@ bool collect_when_stmt_from_file(CheckerContext *ctx, AstWhenStmt *ws) { return false; } -bool collect_file_decls_from_when_stmt(CheckerContext *ctx, AstWhenStmt *ws) { +gb_internal bool collect_file_decls_from_when_stmt(CheckerContext *ctx, AstWhenStmt *ws) { Operand operand = {Addressing_Invalid}; if (!ws->is_cond_determined) { check_expr(ctx, &operand, ws->cond); @@ -4594,7 +4593,7 @@ bool collect_file_decls_from_when_stmt(CheckerContext *ctx, AstWhenStmt *ws) { } -bool collect_file_decl(CheckerContext *ctx, Ast *decl) { +gb_internal bool collect_file_decl(CheckerContext *ctx, Ast *decl) { GB_ASSERT(ctx->scope->flags&ScopeFlag_File); AstFile *curr_file = ctx->scope->file; @@ -4658,7 +4657,7 @@ bool collect_file_decl(CheckerContext *ctx, Ast *decl) { return false; } -bool collect_file_decls(CheckerContext *ctx, Slice const &decls) { +gb_internal bool collect_file_decls(CheckerContext *ctx, Slice const &decls) { GB_ASSERT(ctx->scope->flags&ScopeFlag_File); for_array(i, decls) { @@ -4671,7 +4670,7 @@ bool collect_file_decls(CheckerContext *ctx, Slice const &decls) { return false; } -GB_COMPARE_PROC(sort_file_by_name) { +gb_internal GB_COMPARE_PROC(sort_file_by_name) { AstFile const *x = *cast(AstFile const **)a; AstFile const *y = *cast(AstFile const **)b; String x_name = filename_from_path(x->fullpath); @@ -4679,7 +4678,7 @@ GB_COMPARE_PROC(sort_file_by_name) { return string_compare(x_name, y_name); } -void check_create_file_scopes(Checker *c) { +gb_internal void check_create_file_scopes(Checker *c) { for_array(i, c->parser->packages) { AstPackage *pkg = c->parser->packages[i]; isize total_pkg_decl_count = 0; @@ -4705,7 +4704,7 @@ struct ThreadProcCheckerSection { }; -void check_with_workers(Checker *c, WorkerTaskProc *proc, isize total_count) { +gb_internal void check_with_workers(Checker *c, WorkerTaskProc *proc, isize total_count) { isize thread_count = gb_max(build_context.thread_count, 1); isize worker_count = thread_count-1; // NOTE(bill): The main thread will also be used for work if (!build_context.threaded_checker) { @@ -4744,7 +4743,7 @@ void check_with_workers(Checker *c, WorkerTaskProc *proc, isize total_count) { } -WORKER_TASK_PROC(thread_proc_collect_entities) { +gb_internal WORKER_TASK_PROC(thread_proc_collect_entities) { auto *cs = cast(ThreadProcCheckerSection *)data; Checker *c = cs->checker; CheckerContext collect_entity_ctx = make_checker_context(c); @@ -4775,11 +4774,11 @@ WORKER_TASK_PROC(thread_proc_collect_entities) { } -void check_collect_entities_all(Checker *c) { +gb_internal void check_collect_entities_all(Checker *c) { check_with_workers(c, thread_proc_collect_entities, c->info.files.entries.count); } -void check_export_entities_in_pkg(CheckerContext *ctx, AstPackage *pkg, UntypedExprInfoMap *untyped) { +gb_internal void check_export_entities_in_pkg(CheckerContext *ctx, AstPackage *pkg, UntypedExprInfoMap *untyped) { if (pkg->files.count != 0) { AstPackageExportedEntity item = {}; while (mpmc_dequeue(&pkg->exported_entity_queue, &item)) { @@ -4793,7 +4792,7 @@ void check_export_entities_in_pkg(CheckerContext *ctx, AstPackage *pkg, UntypedE } } -WORKER_TASK_PROC(thread_proc_check_export_entities) { +gb_internal WORKER_TASK_PROC(thread_proc_check_export_entities) { auto cs = cast(ThreadProcCheckerSection *)data; Checker *c = cs->checker; @@ -4815,11 +4814,11 @@ WORKER_TASK_PROC(thread_proc_check_export_entities) { return 0; } -void check_export_entities(Checker *c) { +gb_internal void check_export_entities(Checker *c) { check_with_workers(c, thread_proc_check_export_entities, c->info.packages.entries.count); } -void check_import_entities(Checker *c) { +gb_internal void check_import_entities(Checker *c) { Array dep_graph = generate_import_dependency_graph(c); defer ({ for_array(i, dep_graph) { @@ -4961,9 +4960,9 @@ void check_import_entities(Checker *c) { } -Array find_entity_path(Entity *start, Entity *end, PtrSet *visited = nullptr); +gb_internal Array find_entity_path(Entity *start, Entity *end, PtrSet *visited = nullptr); -bool find_entity_path_tuple(Type *tuple, Entity *end, PtrSet *visited, Array *path_) { +gb_internal bool find_entity_path_tuple(Type *tuple, Entity *end, PtrSet *visited, Array *path_) { GB_ASSERT(path_ != nullptr); if (tuple == nullptr) { return false; @@ -4995,7 +4994,7 @@ bool find_entity_path_tuple(Type *tuple, Entity *end, PtrSet *visited, return false; } -Array find_entity_path(Entity *start, Entity *end, PtrSet *visited) { +gb_internal Array find_entity_path(Entity *start, Entity *end, PtrSet *visited) { PtrSet visited_ = {}; bool made_visited = false; if (visited == nullptr) { @@ -5047,7 +5046,7 @@ Array find_entity_path(Entity *start, Entity *end, PtrSet *v } -void calculate_global_init_order(Checker *c) { +gb_internal void calculate_global_init_order(Checker *c) { CheckerInfo *info = &c->info; TIME_SECTION("calculate_global_init_order: generate entity dependency graph"); @@ -5122,7 +5121,7 @@ void calculate_global_init_order(Checker *c) { } -bool check_proc_info(Checker *c, ProcInfo *pi, UntypedExprInfoMap *untyped, ProcBodyQueue *procs_to_check_queue) { +gb_internal bool check_proc_info(Checker *c, ProcInfo *pi, UntypedExprInfoMap *untyped, ProcBodyQueue *procs_to_check_queue) { if (pi == nullptr) { return false; } @@ -5201,9 +5200,9 @@ bool check_proc_info(Checker *c, ProcInfo *pi, UntypedExprInfoMap *untyped, Proc GB_STATIC_ASSERT(sizeof(isize) == sizeof(void *)); -bool consume_proc_info_queue(Checker *c, ProcInfo *pi, ProcBodyQueue *q, UntypedExprInfoMap *untyped); +gb_internal bool consume_proc_info_queue(Checker *c, ProcInfo *pi, ProcBodyQueue *q, UntypedExprInfoMap *untyped); -void check_unchecked_bodies(Checker *c) { +gb_internal void check_unchecked_bodies(Checker *c) { // NOTE(2021-02-26, bill): Sanity checker // This is a partial hack to make sure all procedure bodies have been checked // even ones which should not exist, due to the multithreaded nature of the parser @@ -5255,7 +5254,7 @@ void check_unchecked_bodies(Checker *c) { } -void check_test_procedures(Checker *c) { +gb_internal void check_test_procedures(Checker *c) { if (build_context.test_names.entries.count == 0) { return; } @@ -5290,7 +5289,7 @@ void check_test_procedures(Checker *c) { gb_global std::atomic total_bodies_checked; -bool consume_proc_info_queue(Checker *c, ProcInfo *pi, ProcBodyQueue *q, UntypedExprInfoMap *untyped) { +gb_internal bool consume_proc_info_queue(Checker *c, ProcInfo *pi, ProcBodyQueue *q, UntypedExprInfoMap *untyped) { GB_ASSERT(pi->decl != nullptr); if (pi->decl->parent && pi->decl->parent->entity) { Entity *parent = pi->decl->parent->entity; @@ -5318,7 +5317,7 @@ struct ThreadProcBodyData { ThreadProcBodyData *all_data; }; -WORKER_TASK_PROC(thread_proc_body) { +gb_internal WORKER_TASK_PROC(thread_proc_body) { ThreadProcBodyData *bd = cast(ThreadProcBodyData *)data; Checker *c = bd->checker; GB_ASSERT(c != nullptr); @@ -5338,7 +5337,7 @@ WORKER_TASK_PROC(thread_proc_body) { return 0; } -void check_procedure_bodies(Checker *c) { +gb_internal void check_procedure_bodies(Checker *c) { GB_ASSERT(c != nullptr); u32 thread_count = cast(u32)gb_max(build_context.thread_count, 1); @@ -5414,7 +5413,7 @@ void check_procedure_bodies(Checker *c) { global_procedure_body_in_worker_queue = false; } -void add_untyped_expressions(CheckerInfo *cinfo, UntypedExprInfoMap *untyped) { +gb_internal void add_untyped_expressions(CheckerInfo *cinfo, UntypedExprInfoMap *untyped) { if (untyped == nullptr) { return; } @@ -5428,7 +5427,7 @@ void add_untyped_expressions(CheckerInfo *cinfo, UntypedExprInfoMap *untyped) { map_clear(untyped); } -void check_deferred_procedures(Checker *c) { +gb_internal void check_deferred_procedures(Checker *c) { for (Entity *src = nullptr; mpmc_dequeue(&c->procs_with_deferred_to_check, &src); /**/) { GB_ASSERT(src->kind == Entity_Procedure); @@ -5581,7 +5580,7 @@ void check_deferred_procedures(Checker *c) { } -void check_unique_package_names(Checker *c) { +gb_internal void check_unique_package_names(Checker *c) { StringMap pkgs = {}; // Key: package name string_map_init(&pkgs, heap_allocator(), 2*c->info.packages.entries.count); defer (string_map_destroy(&pkgs)); @@ -5614,7 +5613,7 @@ void check_unique_package_names(Checker *c) { } } -void check_add_entities_from_queues(Checker *c) { +gb_internal void check_add_entities_from_queues(Checker *c) { isize cap = c->info.entities.count + c->info.entity_queue.count.load(std::memory_order_relaxed); array_reserve(&c->info.entities, cap); for (Entity *e; mpmc_dequeue(&c->info.entity_queue, &e); /**/) { @@ -5622,7 +5621,7 @@ void check_add_entities_from_queues(Checker *c) { } } -void check_add_definitions_from_queues(Checker *c) { +gb_internal void check_add_definitions_from_queues(Checker *c) { isize cap = c->info.definitions.count + c->info.definition_queue.count.load(std::memory_order_relaxed); array_reserve(&c->info.definitions, cap); for (Entity *e; mpmc_dequeue(&c->info.definition_queue, &e); /**/) { @@ -5630,12 +5629,12 @@ void check_add_definitions_from_queues(Checker *c) { } } -void check_merge_queues_into_arrays(Checker *c) { +gb_internal void check_merge_queues_into_arrays(Checker *c) { check_add_entities_from_queues(c); check_add_definitions_from_queues(c); } -GB_COMPARE_PROC(init_procedures_cmp) { +gb_internal GB_COMPARE_PROC(init_procedures_cmp) { int cmp = 0; Entity *x = *(Entity **)a; Entity *y = *(Entity **)b; @@ -5673,11 +5672,11 @@ GB_COMPARE_PROC(init_procedures_cmp) { } -void check_sort_init_procedures(Checker *c) { +gb_internal void check_sort_init_procedures(Checker *c) { gb_sort_array(c->info.init_procedures.data, c->info.init_procedures.count, init_procedures_cmp); } -void add_type_info_for_type_definitions(Checker *c) { +gb_internal void add_type_info_for_type_definitions(Checker *c) { for_array(i, c->info.definitions) { Entity *e = c->info.definitions[i]; if (e->kind == Entity_TypeName && e->type != nullptr) { @@ -5689,7 +5688,7 @@ void add_type_info_for_type_definitions(Checker *c) { } } -void check_parsed_files(Checker *c) { +gb_internal void check_parsed_files(Checker *c) { TIME_SECTION("map full filepaths to scope"); add_type_info_type(&c->builtin_ctx, t_invalid); diff --git a/src/types.cpp b/src/types.cpp index 2ab7374c2..c8e24f01d 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -4029,9 +4029,8 @@ gb_internal bool has_type_got_objc_class_attribute(Type *t) { +gb_internal bool internal_check_is_assignable_to(Type *src, Type *dst); gb_internal bool is_type_objc_object(Type *t) { - bool internal_check_is_assignable_to(Type *src, Type *dst); - return internal_check_is_assignable_to(t, t_objc_object); } -- cgit v1.2.3 From 66ce990e0b9072a49943b37630c8597713a5c6ae Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 18 Dec 2022 21:51:04 +0000 Subject: `gb_internal` to docs and other auxiliary files --- src/bug_report.cpp | 12 +++++----- src/docs.cpp | 21 ++++++++--------- src/docs_format.cpp | 4 ++-- src/docs_writer.cpp | 68 ++++++++++++++++++++++++++--------------------------- src/query_data.cpp | 46 ++++++++++++++++++------------------ 5 files changed, 75 insertions(+), 76 deletions(-) (limited to 'src') diff --git a/src/bug_report.cpp b/src/bug_report.cpp index f4f1b51be..fbf616efb 100644 --- a/src/bug_report.cpp +++ b/src/bug_report.cpp @@ -30,7 +30,7 @@ NOTE(Jeroen): This prints the Windows product edition only, to be called from `print_platform_details`. */ #if defined(GB_SYSTEM_WINDOWS) -void report_windows_product_type(DWORD ProductType) { +gb_internal void report_windows_product_type(DWORD ProductType) { switch (ProductType) { case PRODUCT_ULTIMATE: gb_printf("Ultimate"); @@ -154,7 +154,7 @@ void report_windows_product_type(DWORD ProductType) { } #endif -void odin_cpuid(int leaf, int result[]) { +gb_internal void odin_cpuid(int leaf, int result[]) { #if defined(GB_CPU_ARM) return; @@ -169,7 +169,7 @@ void odin_cpuid(int leaf, int result[]) { #endif } -void report_cpu_info() { +gb_internal void report_cpu_info() { gb_printf("\tCPU: "); #if defined(GB_CPU_X86) @@ -220,7 +220,7 @@ void report_cpu_info() { /* Report the amount of installed RAM. */ -void report_ram_info() { +gb_internal void report_ram_info() { gb_printf("\tRAM: "); #if defined(GB_SYSTEM_WINDOWS) @@ -271,7 +271,7 @@ void report_ram_info() { #endif } -void report_os_info() { +gb_internal void report_os_info() { gb_printf("\tOS: "); #if defined(GB_SYSTEM_WINDOWS) @@ -966,7 +966,7 @@ void report_os_info() { } // NOTE(Jeroen): `odin report` prints some system information for easier bug reporting. -void print_bug_report_help() { +gb_internal void print_bug_report_help() { gb_printf("Where to find more information and get into contact when you encounter a bug:\n\n"); gb_printf("\tWebsite: https://odin-lang.org\n"); gb_printf("\tGitHub: https://github.com/odin-lang/Odin/issues\n"); diff --git a/src/docs.cpp b/src/docs.cpp index b07181e28..33b1e8361 100644 --- a/src/docs.cpp +++ b/src/docs.cpp @@ -28,7 +28,7 @@ gb_global char const *print_entity_names[Entity_Count] = { }; -GB_COMPARE_PROC(cmp_entities_for_printing) { +gb_internal GB_COMPARE_PROC(cmp_entities_for_printing) { GB_ASSERT(a != nullptr); GB_ASSERT(b != nullptr); Entity *x = *cast(Entity **)a; @@ -56,7 +56,7 @@ GB_COMPARE_PROC(cmp_entities_for_printing) { return res; } -GB_COMPARE_PROC(cmp_ast_package_by_name) { +gb_internal GB_COMPARE_PROC(cmp_ast_package_by_name) { GB_ASSERT(a != nullptr); GB_ASSERT(b != nullptr); AstPackage *x = *cast(AstPackage **)a; @@ -67,7 +67,7 @@ GB_COMPARE_PROC(cmp_ast_package_by_name) { #include "docs_format.cpp" #include "docs_writer.cpp" -void print_doc_line(i32 indent, String const &data) { +gb_internal void print_doc_line(i32 indent, String const &data) { while (indent --> 0) { gb_printf("\t"); } @@ -75,7 +75,7 @@ void print_doc_line(i32 indent, String const &data) { gb_printf("\n"); } -void print_doc_line(i32 indent, char const *fmt, ...) { +gb_internal void print_doc_line(i32 indent, char const *fmt, ...) { while (indent --> 0) { gb_printf("\t"); } @@ -85,7 +85,7 @@ void print_doc_line(i32 indent, char const *fmt, ...) { va_end(va); gb_printf("\n"); } -void print_doc_line_no_newline(i32 indent, char const *fmt, ...) { +gb_internal void print_doc_line_no_newline(i32 indent, char const *fmt, ...) { while (indent --> 0) { gb_printf("\t"); } @@ -94,7 +94,7 @@ void print_doc_line_no_newline(i32 indent, char const *fmt, ...) { gb_printf_va(fmt, va); va_end(va); } -void print_doc_line_no_newline(i32 indent, String const &data) { +gb_internal void print_doc_line_no_newline(i32 indent, String const &data) { while (indent --> 0) { gb_printf("\t"); } @@ -102,7 +102,7 @@ void print_doc_line_no_newline(i32 indent, String const &data) { } -bool print_doc_comment_group_string(i32 indent, CommentGroup *g) { +gb_internal bool print_doc_comment_group_string(i32 indent, CommentGroup *g) { if (g == nullptr) { return false; } @@ -191,7 +191,7 @@ bool print_doc_comment_group_string(i32 indent, CommentGroup *g) { -void print_doc_expr(Ast *expr) { +gb_internal void print_doc_expr(Ast *expr) { gbString s = nullptr; if (build_context.cmd_doc_flags & CmdDocFlag_Short) { s = expr_to_string_shorthand(expr); @@ -202,8 +202,7 @@ void print_doc_expr(Ast *expr) { gb_string_free(s); } - -void print_doc_package(CheckerInfo *info, AstPackage *pkg) { +gb_internal void print_doc_package(CheckerInfo *info, AstPackage *pkg) { if (pkg == nullptr) { return; } @@ -320,7 +319,7 @@ void print_doc_package(CheckerInfo *info, AstPackage *pkg) { } -void generate_documentation(Checker *c) { +gb_internal void generate_documentation(Checker *c) { CheckerInfo *info = &c->info; if (build_context.cmd_doc_flags & CmdDocFlag_DocFormat) { diff --git a/src/docs_format.cpp b/src/docs_format.cpp index b13b8b364..34114f08e 100644 --- a/src/docs_format.cpp +++ b/src/docs_format.cpp @@ -27,14 +27,14 @@ struct OdinDocHeaderBase { }; template -Slice from_array(OdinDocHeaderBase *base, OdinDocArray const &a) { +gb_internal Slice from_array(OdinDocHeaderBase *base, OdinDocArray const &a) { Slice s = {}; s.data = cast(T *)(cast(uintptr)base + cast(uintptr)a.offset); s.count = cast(isize)a.length; return s; } -String from_string(OdinDocHeaderBase *base, OdinDocString const &s) { +gb_internal String from_string(OdinDocHeaderBase *base, OdinDocString const &s) { String str = {}; str.text = cast(u8 *)(cast(uintptr)base + cast(uintptr)s.offset); str.len = cast(isize)s.length; diff --git a/src/docs_writer.cpp b/src/docs_writer.cpp index b7b17cb1a..bab97158d 100644 --- a/src/docs_writer.cpp +++ b/src/docs_writer.cpp @@ -11,7 +11,7 @@ enum OdinDocWriterState { OdinDocWriterState_Writing, }; -char const* OdinDocWriterState_strings[] { +gb_global char const* OdinDocWriterState_strings[] { "preparing", "writing ", }; @@ -40,17 +40,17 @@ struct OdinDocWriter { OdinDocWriterItemTracker blob; }; -OdinDocEntityIndex odin_doc_add_entity(OdinDocWriter *w, Entity *e); -OdinDocTypeIndex odin_doc_type(OdinDocWriter *w, Type *type); +gb_internal OdinDocEntityIndex odin_doc_add_entity(OdinDocWriter *w, Entity *e); +gb_internal OdinDocTypeIndex odin_doc_type(OdinDocWriter *w, Type *type); template -void odin_doc_writer_item_tracker_init(OdinDocWriterItemTracker *t, isize size) { +gb_internal void odin_doc_writer_item_tracker_init(OdinDocWriterItemTracker *t, isize size) { t->len = size; t->cap = size; } -void odin_doc_writer_prepare(OdinDocWriter *w) { +gb_internal void odin_doc_writer_prepare(OdinDocWriter *w) { w->state = OdinDocWriterState_Preparing; gbAllocator a = heap_allocator(); @@ -70,7 +70,7 @@ void odin_doc_writer_prepare(OdinDocWriter *w) { } -void odin_doc_writer_destroy(OdinDocWriter *w) { +gb_internal void odin_doc_writer_destroy(OdinDocWriter *w) { gb_free(heap_allocator(), w->data); string_map_destroy(&w->string_cache); @@ -83,7 +83,7 @@ void odin_doc_writer_destroy(OdinDocWriter *w) { template -void odin_doc_writer_tracker_size(isize *offset, OdinDocWriterItemTracker *t, isize alignment=1) { +gb_internal void odin_doc_writer_tracker_size(isize *offset, OdinDocWriterItemTracker *t, isize alignment=1) { isize size = t->cap*gb_size_of(T); isize align = gb_max(gb_align_of(T), alignment); *offset = align_formula_isize(*offset, align); @@ -91,7 +91,7 @@ void odin_doc_writer_tracker_size(isize *offset, OdinDocWriterItemTracker *t, *offset += size; } -isize odin_doc_writer_calc_total_size(OdinDocWriter *w) { +gb_internal isize odin_doc_writer_calc_total_size(OdinDocWriter *w) { isize total_size = gb_size_of(OdinDocHeader); odin_doc_writer_tracker_size(&total_size, &w->files); odin_doc_writer_tracker_size(&total_size, &w->pkgs); @@ -102,7 +102,7 @@ isize odin_doc_writer_calc_total_size(OdinDocWriter *w) { return total_size; } -void odin_doc_writer_start_writing(OdinDocWriter *w) { +gb_internal void odin_doc_writer_start_writing(OdinDocWriter *w) { w->state = OdinDocWriterState_Writing; string_map_clear(&w->string_cache); @@ -118,7 +118,7 @@ void odin_doc_writer_start_writing(OdinDocWriter *w) { w->header = cast(OdinDocHeader *)w->data; } -u32 hash_data_after_header(OdinDocHeaderBase *base, void *data, isize data_len) { +gb_internal u32 hash_data_after_header(OdinDocHeaderBase *base, void *data, isize data_len) { u8 *start = cast(u8 *)data; u8 *end = start + base->total_size; start += base->header_size; @@ -132,13 +132,13 @@ u32 hash_data_after_header(OdinDocHeaderBase *base, void *data, isize data_len) template -void odin_doc_writer_assign_tracker(OdinDocArray *array, OdinDocWriterItemTracker const &t) { +gb_internal void odin_doc_writer_assign_tracker(OdinDocArray *array, OdinDocWriterItemTracker const &t) { array->offset = cast(u32)t.offset; array->length = cast(u32)t.len; } -void odin_doc_writer_end_writing(OdinDocWriter *w) { +gb_internal void odin_doc_writer_end_writing(OdinDocWriter *w) { OdinDocHeader *h = w->header; gb_memmove(h->base.magic, OdinDocHeader_MagicString, gb_strlen(OdinDocHeader_MagicString)); @@ -156,7 +156,7 @@ void odin_doc_writer_end_writing(OdinDocWriter *w) { } template -u32 odin_doc_write_item(OdinDocWriter *w, OdinDocWriterItemTracker *t, T const *item, T **dst=nullptr) { +gb_internal u32 odin_doc_write_item(OdinDocWriter *w, OdinDocWriterItemTracker *t, T const *item, T **dst=nullptr) { if (w->state == OdinDocWriterState_Preparing) { t->cap += 1; if (dst) *dst = nullptr; @@ -175,7 +175,7 @@ u32 odin_doc_write_item(OdinDocWriter *w, OdinDocWriterItemTracker *t, T cons } template -T *odin_doc_get_item(OdinDocWriter *w, OdinDocWriterItemTracker *t, u32 index) { +gb_internal T *odin_doc_get_item(OdinDocWriter *w, OdinDocWriterItemTracker *t, u32 index) { if (w->state != OdinDocWriterState_Writing) { return nullptr; } @@ -184,7 +184,7 @@ T *odin_doc_get_item(OdinDocWriter *w, OdinDocWriterItemTracker *t, u32 index return cast(T *)data; } -OdinDocString odin_doc_write_string_without_cache(OdinDocWriter *w, String const &str) { +gb_internal OdinDocString odin_doc_write_string_without_cache(OdinDocWriter *w, String const &str) { OdinDocString res = {}; if (w->state == OdinDocWriterState_Preparing) { @@ -204,7 +204,7 @@ OdinDocString odin_doc_write_string_without_cache(OdinDocWriter *w, String const return res; } -OdinDocString odin_doc_write_string(OdinDocWriter *w, String const &str) { +gb_internal OdinDocString odin_doc_write_string(OdinDocWriter *w, String const &str) { OdinDocString *c = string_map_get(&w->string_cache, str); if (c != nullptr) { if (w->state == OdinDocWriterState_Writing) { @@ -223,7 +223,7 @@ OdinDocString odin_doc_write_string(OdinDocWriter *w, String const &str) { template -OdinDocArray odin_write_slice(OdinDocWriter *w, T *data, isize len) { +gb_internal OdinDocArray odin_write_slice(OdinDocWriter *w, T *data, isize len) { GB_ASSERT(gb_align_of(T) <= 4); if (len <= 0) { return {0, 0}; @@ -249,12 +249,12 @@ OdinDocArray odin_write_slice(OdinDocWriter *w, T *data, isize len) { template -OdinDocArray odin_write_item_as_slice(OdinDocWriter *w, T data) { +gb_internal OdinDocArray odin_write_item_as_slice(OdinDocWriter *w, T data) { return odin_write_slice(w, &data, 1); } -OdinDocPosition odin_doc_token_pos_cast(OdinDocWriter *w, TokenPos const &pos) { +gb_internal OdinDocPosition odin_doc_token_pos_cast(OdinDocWriter *w, TokenPos const &pos) { OdinDocFileIndex file_index = 0; if (pos.file_id != 0) { AstFile *file = global_files[pos.file_id]; @@ -273,7 +273,7 @@ OdinDocPosition odin_doc_token_pos_cast(OdinDocWriter *w, TokenPos const &pos) { return doc_pos; } -bool odin_doc_append_comment_group_string(Array *buf, CommentGroup *g) { +gb_internal bool odin_doc_append_comment_group_string(Array *buf, CommentGroup *g) { if (g == nullptr) { return false; } @@ -361,7 +361,7 @@ bool odin_doc_append_comment_group_string(Array *buf, CommentGroup *g) { return false; } -OdinDocString odin_doc_pkg_doc_string(OdinDocWriter *w, AstPackage *pkg) { +gb_internal OdinDocString odin_doc_pkg_doc_string(OdinDocWriter *w, AstPackage *pkg) { if (pkg == nullptr) { return {}; } @@ -378,7 +378,7 @@ OdinDocString odin_doc_pkg_doc_string(OdinDocWriter *w, AstPackage *pkg) { return odin_doc_write_string_without_cache(w, make_string(buf.data, buf.count)); } -OdinDocString odin_doc_comment_group_string(OdinDocWriter *w, CommentGroup *g) { +gb_internal OdinDocString odin_doc_comment_group_string(OdinDocWriter *w, CommentGroup *g) { if (g == nullptr) { return {}; } @@ -389,7 +389,7 @@ OdinDocString odin_doc_comment_group_string(OdinDocWriter *w, CommentGroup *g) { return odin_doc_write_string_without_cache(w, make_string(buf.data, buf.count)); } -OdinDocString odin_doc_expr_string(OdinDocWriter *w, Ast *expr) { +gb_internal OdinDocString odin_doc_expr_string(OdinDocWriter *w, Ast *expr) { if (expr == nullptr) { return {}; } @@ -402,7 +402,7 @@ OdinDocString odin_doc_expr_string(OdinDocWriter *w, Ast *expr) { return odin_doc_write_string(w, make_string(cast(u8 *)s, gb_string_length(s))); } -OdinDocArray odin_doc_attributes(OdinDocWriter *w, Array const &attributes) { +gb_internal OdinDocArray odin_doc_attributes(OdinDocWriter *w, Array const &attributes) { isize count = 0; for_array(i, attributes) { Ast *attr = attributes[i]; @@ -448,7 +448,7 @@ OdinDocArray odin_doc_attributes(OdinDocWriter *w, Array odin_doc_where_clauses(OdinDocWriter *w, Slice const &where_clauses) { +gb_internal OdinDocArray odin_doc_where_clauses(OdinDocWriter *w, Slice const &where_clauses) { if (where_clauses.count == 0) { return {}; } @@ -462,17 +462,17 @@ OdinDocArray odin_doc_where_clauses(OdinDocWriter *w, Slice odin_doc_type_as_slice(OdinDocWriter *w, Type *type) { +gb_internal OdinDocArray odin_doc_type_as_slice(OdinDocWriter *w, Type *type) { OdinDocTypeIndex index = odin_doc_type(w, type); return odin_write_item_as_slice(w, index); } -OdinDocArray odin_doc_add_entity_as_slice(OdinDocWriter *w, Entity *e) { +gb_internal OdinDocArray odin_doc_add_entity_as_slice(OdinDocWriter *w, Entity *e) { OdinDocEntityIndex index = odin_doc_add_entity(w, e); return odin_write_item_as_slice(w, index); } -OdinDocTypeIndex odin_doc_type(OdinDocWriter *w, Type *type) { +gb_internal OdinDocTypeIndex odin_doc_type(OdinDocWriter *w, Type *type) { if (type == nullptr) { return 0; } @@ -750,7 +750,7 @@ OdinDocTypeIndex odin_doc_type(OdinDocWriter *w, Type *type) { } return type_index; } -OdinDocEntityIndex odin_doc_add_entity(OdinDocWriter *w, Entity *e) { +gb_internal OdinDocEntityIndex odin_doc_add_entity(OdinDocWriter *w, Entity *e) { if (e == nullptr) { return 0; } @@ -911,7 +911,7 @@ OdinDocEntityIndex odin_doc_add_entity(OdinDocWriter *w, Entity *e) { return doc_entity_index; } -void odin_doc_update_entities(OdinDocWriter *w) { +gb_internal void odin_doc_update_entities(OdinDocWriter *w) { { // NOTE(bill): Double pass, just in case entities are created on odin_doc_type auto entities = array_make(heap_allocator(), 0, w->entity_cache.entries.count); @@ -966,7 +966,7 @@ void odin_doc_update_entities(OdinDocWriter *w) { -OdinDocArray odin_doc_add_pkg_entries(OdinDocWriter *w, AstPackage *pkg) { +gb_internal OdinDocArray odin_doc_add_pkg_entries(OdinDocWriter *w, AstPackage *pkg) { if (pkg->scope == nullptr) { return {}; } @@ -1016,7 +1016,7 @@ OdinDocArray odin_doc_add_pkg_entries(OdinDocWriter *w, AstPa } -void odin_doc_write_docs(OdinDocWriter *w) { +gb_internal void odin_doc_write_docs(OdinDocWriter *w) { auto pkgs = array_make(heap_allocator(), 0, w->info->packages.entries.count); defer (array_free(&pkgs)); for (auto const &entry : w->info->packages) { @@ -1091,7 +1091,7 @@ void odin_doc_write_docs(OdinDocWriter *w) { } -void odin_doc_write_to_file(OdinDocWriter *w, char const *filename) { +gb_internal void odin_doc_write_to_file(OdinDocWriter *w, char const *filename) { gbFile f = {}; gbFileError err = gb_file_open_mode(&f, gbFileMode_Write, filename); if (err != gbFileError_None) { @@ -1106,7 +1106,7 @@ void odin_doc_write_to_file(OdinDocWriter *w, char const *filename) { } } -void odin_doc_write(CheckerInfo *info, char const *filename) { +gb_internal void odin_doc_write(CheckerInfo *info, char const *filename) { OdinDocWriter w_ = {}; OdinDocWriter *w = &w_; defer (odin_doc_writer_destroy(w)); diff --git a/src/query_data.cpp b/src/query_data.cpp index ebf955fd4..86487a058 100644 --- a/src/query_data.cpp +++ b/src/query_data.cpp @@ -1,7 +1,7 @@ struct QueryValue; struct QueryValuePair; -gbAllocator query_value_allocator = {}; +gb_global gbAllocator query_value_allocator = {}; enum QueryKind { Query_Invalid, @@ -189,16 +189,16 @@ struct QueryValueMap : QueryValue { return v; \ } -DEF_QUERY_PROC(QueryValueString, String const &, query_value_string); -DEF_QUERY_PROC(QueryValueBoolean, bool, query_value_boolean); -DEF_QUERY_PROC(QueryValueInteger, i64, query_value_integer); -DEF_QUERY_PROC(QueryValueFloat, f64, query_value_float); -DEF_QUERY_PROC(QueryValueArray, Array const &, query_value_array); -DEF_QUERY_PROC(QueryValueMap, Array const &, query_value_map); -DEF_QUERY_PROC0(QueryValueArray, query_value_array); -DEF_QUERY_PROC0(QueryValueMap, query_value_map); +gb_internal DEF_QUERY_PROC(QueryValueString, String const &, query_value_string); +gb_internal DEF_QUERY_PROC(QueryValueBoolean, bool, query_value_boolean); +gb_internal DEF_QUERY_PROC(QueryValueInteger, i64, query_value_integer); +gb_internal DEF_QUERY_PROC(QueryValueFloat, f64, query_value_float); +gb_internal DEF_QUERY_PROC(QueryValueArray, Array const &, query_value_array); +gb_internal DEF_QUERY_PROC(QueryValueMap, Array const &, query_value_map); +gb_internal DEF_QUERY_PROC0(QueryValueArray, query_value_array); +gb_internal DEF_QUERY_PROC0(QueryValueMap, query_value_map); -isize qprintf(bool format, isize indent, char const *fmt, ...) { +gb_internal isize qprintf(bool format, isize indent, char const *fmt, ...) { if (format) while (indent --> 0) { gb_printf("\t"); } @@ -209,7 +209,7 @@ isize qprintf(bool format, isize indent, char const *fmt, ...) { return res; } -bool qv_valid_char(u8 c) { +gb_internal bool qv_valid_char(u8 c) { if (c >= 0x80) { return false; } @@ -227,7 +227,7 @@ bool qv_valid_char(u8 c) { return true; } -void print_query_data_as_json(QueryValue *value, bool format = true, isize indent = 0) { +gb_internal void print_query_data_as_json(QueryValue *value, bool format = true, isize indent = 0) { if (value == nullptr) { gb_printf("null"); return; @@ -359,7 +359,7 @@ void print_query_data_as_json(QueryValue *value, bool format = true, isize inden -int query_data_package_compare(void const *a, void const *b) { +gb_internal int query_data_package_compare(void const *a, void const *b) { AstPackage *x = *cast(AstPackage *const *)a; AstPackage *y = *cast(AstPackage *const *)b; @@ -377,7 +377,7 @@ int query_data_package_compare(void const *a, void const *b) { return 0; } -int query_data_definition_compare(void const *a, void const *b) { +gb_internal int query_data_definition_compare(void const *a, void const *b) { Entity *x = *cast(Entity *const *)a; Entity *y = *cast(Entity *const *)b; @@ -399,7 +399,7 @@ int query_data_definition_compare(void const *a, void const *b) { return string_compare(x->token.string, y->token.string); } -int entity_name_compare(void const *a, void const *b) { +gb_internal int entity_name_compare(void const *a, void const *b) { Entity *x = *cast(Entity *const *)a; Entity *y = *cast(Entity *const *)b; if (x == y) { @@ -413,10 +413,10 @@ int entity_name_compare(void const *a, void const *b) { } -void generate_and_print_query_data_global_definitions(Checker *c, Timings *timings); -void generate_and_print_query_data_go_to_definitions(Checker *c); +gb_internal void generate_and_print_query_data_global_definitions(Checker *c, Timings *timings); +gb_internal void generate_and_print_query_data_go_to_definitions(Checker *c); -void generate_and_print_query_data(Checker *c, Timings *timings) { +gb_internal void generate_and_print_query_data(Checker *c, Timings *timings) { query_value_allocator = heap_allocator(); switch (build_context.query_data_set_settings.kind) { case QueryDataSet_GlobalDefinitions: @@ -429,7 +429,7 @@ void generate_and_print_query_data(Checker *c, Timings *timings) { } -void generate_and_print_query_data_global_definitions(Checker *c, Timings *timings) { +gb_internal void generate_and_print_query_data_global_definitions(Checker *c, Timings *timings) { auto *root = query_value_map(); if (global_error_collector.errors.count > 0) { @@ -805,7 +805,7 @@ struct BinaryArray { }; template -Array binary_array_from_data(BinaryArray ba, void *data) { +gb_internal Array binary_array_from_data(BinaryArray ba, void *data) { Array res = {}; res.data = cast(T *)(cast(u8 *)data + ba.offset); res.count = ba.length; @@ -841,7 +841,7 @@ struct GoToDefFileMap { }; -int go_to_def_file_map_compare(void const *a, void const *b) { +gb_internal int go_to_def_file_map_compare(void const *a, void const *b) { GoToDefFileMap const *x = cast(GoToDefFileMap const *)a; GoToDefFileMap const *y = cast(GoToDefFileMap const *)b; if (x == y) { @@ -859,7 +859,7 @@ int go_to_def_file_map_compare(void const *a, void const *b) { return 0; } -int quick_ident_compare(void const *a, void const *b) { +gb_internal int quick_ident_compare(void const *a, void const *b) { Ast *x = *cast(Ast **)a; Ast *y = *cast(Ast **)b; @@ -873,7 +873,7 @@ int quick_ident_compare(void const *a, void const *b) { } -void generate_and_print_query_data_go_to_definitions(Checker *c) { +gb_internal void generate_and_print_query_data_go_to_definitions(Checker *c) { GB_ASSERT(c->info.allow_identifier_uses); gbAllocator a = query_value_allocator; -- cgit v1.2.3 From 6cdec65ca1fd13a4d86d83a6715cbaaff7115cd7 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 18 Dec 2022 22:32:05 +0000 Subject: `gb_internal` LLVM backend --- src/llvm_abi.cpp | 154 ++++++++++++------------ src/llvm_backend.cpp | 70 +++++------ src/llvm_backend.hpp | 274 +++++++++++++++++++++---------------------- src/llvm_backend_const.cpp | 60 +++++----- src/llvm_backend_debug.cpp | 44 +++---- src/llvm_backend_expr.cpp | 80 ++++++------- src/llvm_backend_general.cpp | 182 ++++++++++++++-------------- src/llvm_backend_opt.cpp | 32 ++--- src/llvm_backend_proc.cpp | 55 +++++---- src/llvm_backend_stmt.cpp | 90 +++++++------- src/llvm_backend_type.cpp | 20 ++-- src/llvm_backend_utility.cpp | 194 +++++++++++++++--------------- 12 files changed, 627 insertions(+), 628 deletions(-) (limited to 'src') diff --git a/src/llvm_abi.cpp b/src/llvm_abi.cpp index 166fcb3ee..7b82fddeb 100644 --- a/src/llvm_abi.cpp +++ b/src/llvm_abi.cpp @@ -18,21 +18,21 @@ struct lbArgType { }; -i64 lb_sizeof(LLVMTypeRef type); -i64 lb_alignof(LLVMTypeRef type); +gb_internal i64 lb_sizeof(LLVMTypeRef type); +gb_internal i64 lb_alignof(LLVMTypeRef type); -lbArgType lb_arg_type_direct(LLVMTypeRef type, LLVMTypeRef cast_type, LLVMTypeRef pad_type, LLVMAttributeRef attr) { +gb_internal lbArgType lb_arg_type_direct(LLVMTypeRef type, LLVMTypeRef cast_type, LLVMTypeRef pad_type, LLVMAttributeRef attr) { return lbArgType{lbArg_Direct, type, cast_type, pad_type, attr, nullptr, 0, false}; } -lbArgType lb_arg_type_direct(LLVMTypeRef type) { +gb_internal lbArgType lb_arg_type_direct(LLVMTypeRef type) { return lb_arg_type_direct(type, nullptr, nullptr, nullptr); } -lbArgType lb_arg_type_indirect(LLVMTypeRef type, LLVMAttributeRef attr) { +gb_internal lbArgType lb_arg_type_indirect(LLVMTypeRef type, LLVMAttributeRef attr) { return lbArgType{lbArg_Indirect, type, nullptr, nullptr, attr, nullptr, 0, false}; } -lbArgType lb_arg_type_indirect_byval(LLVMContextRef c, LLVMTypeRef type) { +gb_internal lbArgType lb_arg_type_indirect_byval(LLVMContextRef c, LLVMTypeRef type) { i64 alignment = lb_alignof(type); alignment = gb_max(alignment, 8); @@ -41,7 +41,7 @@ lbArgType lb_arg_type_indirect_byval(LLVMContextRef c, LLVMTypeRef type) { return lbArgType{lbArg_Indirect, type, nullptr, nullptr, byval_attr, align_attr, alignment, true}; } -lbArgType lb_arg_type_ignore(LLVMTypeRef type) { +gb_internal lbArgType lb_arg_type_ignore(LLVMTypeRef type) { return lbArgType{lbArg_Ignore, type, nullptr, nullptr, nullptr, nullptr, 0, false}; } @@ -55,24 +55,24 @@ struct lbFunctionType { isize original_arg_count; }; -gbAllocator lb_function_type_args_allocator(void) { +gb_internal gbAllocator lb_function_type_args_allocator(void) { return heap_allocator(); } -i64 llvm_align_formula(i64 off, i64 a) { +gb_internal gb_inline i64 llvm_align_formula(i64 off, i64 a) { return (off + a - 1) / a * a; } -bool lb_is_type_kind(LLVMTypeRef type, LLVMTypeKind kind) { +gb_internal bool lb_is_type_kind(LLVMTypeRef type, LLVMTypeKind kind) { if (type == nullptr) { return false; } return LLVMGetTypeKind(type) == kind; } -LLVMTypeRef lb_function_type_to_llvm_raw(lbFunctionType *ft, bool is_var_arg) { +gb_internal LLVMTypeRef lb_function_type_to_llvm_raw(lbFunctionType *ft, bool is_var_arg) { unsigned arg_count = cast(unsigned)ft->args.count; unsigned offset = 0; @@ -130,7 +130,7 @@ LLVMTypeRef lb_function_type_to_llvm_raw(lbFunctionType *ft, bool is_var_arg) { // } -void lb_add_function_type_attributes(LLVMValueRef fn, lbFunctionType *ft, ProcCallingConvention calling_convention) { +gb_internal void lb_add_function_type_attributes(LLVMValueRef fn, lbFunctionType *ft, ProcCallingConvention calling_convention) { if (ft == nullptr) { return; } @@ -201,7 +201,7 @@ void lb_add_function_type_attributes(LLVMValueRef fn, lbFunctionType *ft, ProcCa } -i64 lb_sizeof(LLVMTypeRef type) { +gb_internal i64 lb_sizeof(LLVMTypeRef type) { LLVMTypeKind kind = LLVMGetTypeKind(type); switch (kind) { case LLVMVoidTypeKind: @@ -267,7 +267,7 @@ i64 lb_sizeof(LLVMTypeRef type) { return 0; } -i64 lb_alignof(LLVMTypeRef type) { +gb_internal i64 lb_alignof(LLVMTypeRef type) { LLVMTypeKind kind = LLVMGetTypeKind(type); switch (kind) { case LLVMVoidTypeKind: @@ -333,7 +333,7 @@ typedef LB_ABI_INFO(lbAbiInfoType); typedef LB_ABI_COMPUTE_RETURN_TYPE(lbAbiComputeReturnType); -lbArgType lb_abi_modify_return_is_tuple(lbFunctionType *ft, LLVMContextRef c, LLVMTypeRef return_type, lbAbiComputeReturnType *compute_return_type) { +gb_internal lbArgType lb_abi_modify_return_is_tuple(lbFunctionType *ft, LLVMContextRef c, LLVMTypeRef return_type, lbAbiComputeReturnType *compute_return_type) { GB_ASSERT(return_type != nullptr); GB_ASSERT(compute_return_type != nullptr); @@ -370,10 +370,10 @@ lbArgType lb_abi_modify_return_is_tuple(lbFunctionType *ft, LLVMContextRef c, LL // NOTE(bill): I hate `namespace` in C++ but this is just because I don't want to prefix everything namespace lbAbi386 { - Array compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count); - LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type); + gb_internal Array compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count); + gb_internal LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type); - LB_ABI_INFO(abi_info) { + gb_internal LB_ABI_INFO(abi_info) { lbFunctionType *ft = gb_alloc_item(permanent_allocator(), lbFunctionType); ft->ctx = c; ft->args = compute_arg_types(c, arg_types, arg_count); @@ -382,7 +382,7 @@ namespace lbAbi386 { return ft; } - lbArgType non_struct(LLVMContextRef c, LLVMTypeRef type, bool is_return) { + gb_internal lbArgType non_struct(LLVMContextRef c, LLVMTypeRef type, bool is_return) { if (!is_return && lb_sizeof(type) > 8) { return lb_arg_type_indirect(type, nullptr); } @@ -409,7 +409,7 @@ namespace lbAbi386 { return lb_arg_type_direct(type, nullptr, nullptr, attr); } - Array compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count) { + gb_internal Array compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count) { auto args = array_make(lb_function_type_args_allocator(), arg_count); for (unsigned i = 0; i < arg_count; i++) { @@ -429,7 +429,7 @@ namespace lbAbi386 { return args; } - LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type) { + gb_internal LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type) { if (!return_is_defined) { return lb_arg_type_direct(LLVMVoidTypeInContext(c)); } else if (lb_is_type_kind(return_type, LLVMStructTypeKind) || lb_is_type_kind(return_type, LLVMArrayTypeKind)) { @@ -451,10 +451,10 @@ namespace lbAbi386 { }; namespace lbAbiAmd64Win64 { - Array compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count); - LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type); + gb_internal Array compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count); + gb_internal LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type); - LB_ABI_INFO(abi_info) { + gb_internal LB_ABI_INFO(abi_info) { lbFunctionType *ft = gb_alloc_item(permanent_allocator(), lbFunctionType); ft->ctx = c; ft->args = compute_arg_types(c, arg_types, arg_count); @@ -463,7 +463,7 @@ namespace lbAbiAmd64Win64 { return ft; } - Array compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count) { + gb_internal Array compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count) { auto args = array_make(lb_function_type_args_allocator(), arg_count); for (unsigned i = 0; i < arg_count; i++) { @@ -489,7 +489,7 @@ namespace lbAbiAmd64Win64 { return args; } - LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type) { + gb_internal LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type) { if (!return_is_defined) { return lb_arg_type_direct(LLVMVoidTypeInContext(c)); } else if (lb_is_type_kind(return_type, LLVMStructTypeKind) || lb_is_type_kind(return_type, LLVMArrayTypeKind)) { @@ -530,7 +530,7 @@ namespace lbAbiAmd64SysV { RegClass_Memory, }; - bool is_sse(RegClass reg_class) { + gb_internal bool is_sse(RegClass reg_class) { switch (reg_class) { case RegClass_SSEFs: case RegClass_SSEFv: @@ -546,7 +546,7 @@ namespace lbAbiAmd64SysV { return false; } - void all_mem(Array *cs) { + gb_internal void all_mem(Array *cs) { for_array(i, *cs) { (*cs)[i] = RegClass_Memory; } @@ -558,14 +558,14 @@ namespace lbAbiAmd64SysV { Amd64TypeAttribute_StructRect, }; - LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type); - void classify_with(LLVMTypeRef t, Array *cls, i64 ix, i64 off); - void fixup(LLVMTypeRef t, Array *cls); - lbArgType amd64_type(LLVMContextRef c, LLVMTypeRef type, Amd64TypeAttributeKind attribute_kind, ProcCallingConvention calling_convention); - Array classify(LLVMTypeRef t); - LLVMTypeRef llreg(LLVMContextRef c, Array const ®_classes); + gb_internal LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type); + gb_internal void classify_with(LLVMTypeRef t, Array *cls, i64 ix, i64 off); + gb_internal void fixup(LLVMTypeRef t, Array *cls); + gb_internal lbArgType amd64_type(LLVMContextRef c, LLVMTypeRef type, Amd64TypeAttributeKind attribute_kind, ProcCallingConvention calling_convention); + gb_internal Array classify(LLVMTypeRef t); + gb_internal LLVMTypeRef llreg(LLVMContextRef c, Array const ®_classes); - LB_ABI_INFO(abi_info) { + gb_internal LB_ABI_INFO(abi_info) { lbFunctionType *ft = gb_alloc_item(permanent_allocator(), lbFunctionType); ft->ctx = c; ft->calling_convention = calling_convention; @@ -584,7 +584,7 @@ namespace lbAbiAmd64SysV { return ft; } - bool is_mem_cls(Array const &cls, Amd64TypeAttributeKind attribute_kind) { + gb_internal bool is_mem_cls(Array const &cls, Amd64TypeAttributeKind attribute_kind) { if (attribute_kind == Amd64TypeAttribute_ByVal) { if (cls.count == 0) { return false; @@ -600,7 +600,7 @@ namespace lbAbiAmd64SysV { return false; } - bool is_register(LLVMTypeRef type) { + gb_internal bool is_register(LLVMTypeRef type) { LLVMTypeKind kind = LLVMGetTypeKind(type); i64 sz = lb_sizeof(type); if (sz == 0) { @@ -617,7 +617,7 @@ namespace lbAbiAmd64SysV { return false; } - bool is_llvm_type_slice_like(LLVMTypeRef type) { + gb_internal bool is_llvm_type_slice_like(LLVMTypeRef type) { if (!lb_is_type_kind(type, LLVMStructTypeKind)) { return false; } @@ -633,7 +633,7 @@ namespace lbAbiAmd64SysV { } - lbArgType amd64_type(LLVMContextRef c, LLVMTypeRef type, Amd64TypeAttributeKind attribute_kind, ProcCallingConvention calling_convention) { + gb_internal lbArgType amd64_type(LLVMContextRef c, LLVMTypeRef type, Amd64TypeAttributeKind attribute_kind, ProcCallingConvention calling_convention) { if (is_register(type)) { LLVMAttributeRef attribute = nullptr; if (type == LLVMInt1TypeInContext(c)) { @@ -668,7 +668,7 @@ namespace lbAbiAmd64SysV { } } - lbArgType non_struct(LLVMContextRef c, LLVMTypeRef type) { + gb_internal lbArgType non_struct(LLVMContextRef c, LLVMTypeRef type) { LLVMAttributeRef attr = nullptr; LLVMTypeRef i1 = LLVMInt1TypeInContext(c); if (type == i1) { @@ -677,7 +677,7 @@ namespace lbAbiAmd64SysV { return lb_arg_type_direct(type, nullptr, nullptr, attr); } - Array classify(LLVMTypeRef t) { + gb_internal Array classify(LLVMTypeRef t) { i64 sz = lb_sizeof(t); i64 words = (sz + 7)/8; auto reg_classes = array_make(heap_allocator(), cast(isize)words); @@ -690,7 +690,7 @@ namespace lbAbiAmd64SysV { return reg_classes; } - void unify(Array *cls, i64 i, RegClass const newv) { + gb_internal void unify(Array *cls, i64 i, RegClass const newv) { RegClass const oldv = (*cls)[cast(isize)i]; if (oldv == newv) { return; @@ -726,7 +726,7 @@ namespace lbAbiAmd64SysV { (*cls)[cast(isize)i] = to_write; } - void fixup(LLVMTypeRef t, Array *cls) { + gb_internal void fixup(LLVMTypeRef t, Array *cls) { i64 i = 0; i64 e = cls->count; if (e > 2 && (lb_is_type_kind(t, LLVMStructTypeKind) || @@ -773,7 +773,7 @@ namespace lbAbiAmd64SysV { } } - unsigned llvec_len(Array const ®_classes, isize offset) { + gb_internal unsigned llvec_len(Array const ®_classes, isize offset) { unsigned len = 1; for (isize i = offset; i < reg_classes.count; i++) { if (reg_classes[i] != RegClass_SSEUp) { @@ -785,7 +785,7 @@ namespace lbAbiAmd64SysV { } - LLVMTypeRef llreg(LLVMContextRef c, Array const ®_classes) { + gb_internal LLVMTypeRef llreg(LLVMContextRef c, Array const ®_classes) { auto types = array_make(heap_allocator(), 0, reg_classes.count); for (isize i = 0; i < reg_classes.count; /**/) { RegClass reg_class = reg_classes[i]; @@ -854,7 +854,7 @@ namespace lbAbiAmd64SysV { return LLVMStructTypeInContext(c, types.data, cast(unsigned)types.count, false); } - void classify_with(LLVMTypeRef t, Array *cls, i64 ix, i64 off) { + gb_internal void classify_with(LLVMTypeRef t, Array *cls, i64 ix, i64 off) { i64 t_align = lb_alignof(t); i64 t_size = lb_sizeof(t); @@ -955,7 +955,7 @@ namespace lbAbiAmd64SysV { } } - LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type) { + gb_internal LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type) { if (!return_is_defined) { return lb_arg_type_direct(LLVMVoidTypeInContext(c)); } else if (lb_is_type_kind(return_type, LLVMStructTypeKind)) { @@ -980,11 +980,11 @@ namespace lbAbiAmd64SysV { namespace lbAbiArm64 { - Array compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count); - LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type); - bool is_homogenous_aggregate(LLVMContextRef c, LLVMTypeRef type, LLVMTypeRef *base_type_, unsigned *member_count_); + gb_internal Array compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count); + gb_internal LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type); + gb_internal bool is_homogenous_aggregate(LLVMContextRef c, LLVMTypeRef type, LLVMTypeRef *base_type_, unsigned *member_count_); - LB_ABI_INFO(abi_info) { + gb_internal LB_ABI_INFO(abi_info) { lbFunctionType *ft = gb_alloc_item(permanent_allocator(), lbFunctionType); ft->ctx = c; ft->ret = compute_return_type(ft, c, return_type, return_is_defined, return_is_tuple); @@ -993,7 +993,7 @@ namespace lbAbiArm64 { return ft; } - bool is_register(LLVMTypeRef type) { + gb_internal bool is_register(LLVMTypeRef type) { LLVMTypeKind kind = LLVMGetTypeKind(type); switch (kind) { case LLVMIntegerTypeKind: @@ -1006,7 +1006,7 @@ namespace lbAbiArm64 { return false; } - lbArgType non_struct(LLVMContextRef c, LLVMTypeRef type) { + gb_internal lbArgType non_struct(LLVMContextRef c, LLVMTypeRef type) { LLVMAttributeRef attr = nullptr; LLVMTypeRef i1 = LLVMInt1TypeInContext(c); if (type == i1) { @@ -1015,7 +1015,7 @@ namespace lbAbiArm64 { return lb_arg_type_direct(type, nullptr, nullptr, attr); } - bool is_homogenous_array(LLVMContextRef c, LLVMTypeRef type, LLVMTypeRef *base_type_, unsigned *member_count_) { + gb_internal bool is_homogenous_array(LLVMContextRef c, LLVMTypeRef type, LLVMTypeRef *base_type_, unsigned *member_count_) { GB_ASSERT(lb_is_type_kind(type, LLVMArrayTypeKind)); unsigned len = LLVMGetArrayLength(type); if (len == 0) { @@ -1032,7 +1032,7 @@ namespace lbAbiArm64 { } return false; } - bool is_homogenous_struct(LLVMContextRef c, LLVMTypeRef type, LLVMTypeRef *base_type_, unsigned *member_count_) { + gb_internal bool is_homogenous_struct(LLVMContextRef c, LLVMTypeRef type, LLVMTypeRef *base_type_, unsigned *member_count_) { GB_ASSERT(lb_is_type_kind(type, LLVMStructTypeKind)); unsigned elem_count = LLVMCountStructElementTypes(type); if (elem_count == 0) { @@ -1075,7 +1075,7 @@ namespace lbAbiArm64 { } - bool is_homogenous_aggregate(LLVMContextRef c, LLVMTypeRef type, LLVMTypeRef *base_type_, unsigned *member_count_) { + gb_internal bool is_homogenous_aggregate(LLVMContextRef c, LLVMTypeRef type, LLVMTypeRef *base_type_, unsigned *member_count_) { LLVMTypeKind kind = LLVMGetTypeKind(type); switch (kind) { case LLVMFloatTypeKind: @@ -1091,11 +1091,11 @@ namespace lbAbiArm64 { return false; } - unsigned is_homogenous_aggregate_small_enough(LLVMTypeRef base_type, unsigned member_count) { + gb_internal unsigned is_homogenous_aggregate_small_enough(LLVMTypeRef base_type, unsigned member_count) { return (member_count <= 4); } - LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type) { + gb_internal LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type) { LLVMTypeRef homo_base_type = nullptr; unsigned homo_member_count = 0; @@ -1142,7 +1142,7 @@ namespace lbAbiArm64 { } } - Array compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count) { + gb_internal Array compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count) { auto args = array_make(lb_function_type_args_allocator(), arg_count); for (unsigned i = 0; i < arg_count; i++) { @@ -1188,12 +1188,12 @@ namespace lbAbiWasm { The approach taken optimizes for passing things in multiple registers/arguments if possible rather than by pointer. */ - Array compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count); - LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type); + gb_internal Array compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count); + gb_internal LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type); enum {MAX_DIRECT_STRUCT_SIZE = 32}; - LB_ABI_INFO(abi_info) { + gb_internal LB_ABI_INFO(abi_info) { lbFunctionType *ft = gb_alloc_item(permanent_allocator(), lbFunctionType); ft->ctx = c; ft->args = compute_arg_types(c, arg_types, arg_count); @@ -1202,7 +1202,7 @@ namespace lbAbiWasm { return ft; } - lbArgType non_struct(LLVMContextRef c, LLVMTypeRef type, bool is_return) { + gb_internal lbArgType non_struct(LLVMContextRef c, LLVMTypeRef type, bool is_return) { if (!is_return && type == LLVMIntTypeInContext(c, 128)) { LLVMTypeRef cast_type = LLVMVectorType(LLVMInt64TypeInContext(c), 2); return lb_arg_type_direct(type, cast_type, nullptr, nullptr); @@ -1220,7 +1220,7 @@ namespace lbAbiWasm { return lb_arg_type_direct(type, nullptr, nullptr, attr); } - bool is_basic_register_type(LLVMTypeRef type) { + gb_internal bool is_basic_register_type(LLVMTypeRef type) { switch (LLVMGetTypeKind(type)) { case LLVMHalfTypeKind: case LLVMFloatTypeKind: @@ -1233,7 +1233,7 @@ namespace lbAbiWasm { return false; } - bool type_can_be_direct(LLVMTypeRef type) { + gb_internal bool type_can_be_direct(LLVMTypeRef type) { LLVMTypeKind kind = LLVMGetTypeKind(type); i64 sz = lb_sizeof(type); if (sz == 0) { @@ -1259,7 +1259,7 @@ namespace lbAbiWasm { return false; } - lbArgType is_struct(LLVMContextRef c, LLVMTypeRef type) { + gb_internal lbArgType is_struct(LLVMContextRef c, LLVMTypeRef type) { LLVMTypeKind kind = LLVMGetTypeKind(type); GB_ASSERT(kind == LLVMArrayTypeKind || kind == LLVMStructTypeKind); @@ -1274,7 +1274,7 @@ namespace lbAbiWasm { } - Array compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count) { + gb_internal Array compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count) { auto args = array_make(lb_function_type_args_allocator(), arg_count); for (unsigned i = 0; i < arg_count; i++) { @@ -1289,7 +1289,7 @@ namespace lbAbiWasm { return args; } - LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type) { + gb_internal LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type) { if (!return_is_defined) { return lb_arg_type_direct(LLVMVoidTypeInContext(c)); } else if (lb_is_type_kind(return_type, LLVMStructTypeKind) || lb_is_type_kind(return_type, LLVMArrayTypeKind)) { @@ -1315,10 +1315,10 @@ namespace lbAbiWasm { } namespace lbAbiArm32 { - Array compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count, ProcCallingConvention calling_convention); - lbArgType compute_return_type(LLVMContextRef c, LLVMTypeRef return_type, bool return_is_defined); + gb_internal Array compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count, ProcCallingConvention calling_convention); + gb_internal lbArgType compute_return_type(LLVMContextRef c, LLVMTypeRef return_type, bool return_is_defined); - LB_ABI_INFO(abi_info) { + gb_internal LB_ABI_INFO(abi_info) { lbFunctionType *ft = gb_alloc_item(permanent_allocator(), lbFunctionType); ft->ctx = c; ft->args = compute_arg_types(c, arg_types, arg_count, calling_convention); @@ -1327,7 +1327,7 @@ namespace lbAbiArm32 { return ft; } - bool is_register(LLVMTypeRef type, bool is_return) { + gb_internal bool is_register(LLVMTypeRef type, bool is_return) { LLVMTypeKind kind = LLVMGetTypeKind(type); switch (kind) { case LLVMHalfTypeKind: @@ -1346,7 +1346,7 @@ namespace lbAbiArm32 { return false; } - lbArgType non_struct(LLVMContextRef c, LLVMTypeRef type, bool is_return) { + gb_internal lbArgType non_struct(LLVMContextRef c, LLVMTypeRef type, bool is_return) { LLVMAttributeRef attr = nullptr; LLVMTypeRef i1 = LLVMInt1TypeInContext(c); if (type == i1) { @@ -1355,7 +1355,7 @@ namespace lbAbiArm32 { return lb_arg_type_direct(type, nullptr, nullptr, attr); } - Array compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count, ProcCallingConvention calling_convention) { + gb_internal Array compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count, ProcCallingConvention calling_convention) { auto args = array_make(lb_function_type_args_allocator(), arg_count); for (unsigned i = 0; i < arg_count; i++) { @@ -1380,7 +1380,7 @@ namespace lbAbiArm32 { return args; } - lbArgType compute_return_type(LLVMContextRef c, LLVMTypeRef return_type, bool return_is_defined) { + gb_internal lbArgType compute_return_type(LLVMContextRef c, LLVMTypeRef return_type, bool return_is_defined) { if (!return_is_defined) { return lb_arg_type_direct(LLVMVoidTypeInContext(c)); } else if (!is_register(return_type, true)) { @@ -1397,7 +1397,7 @@ namespace lbAbiArm32 { }; -LB_ABI_INFO(lb_get_abi_info_internal) { +gb_internal LB_ABI_INFO(lb_get_abi_info_internal) { switch (calling_convention) { case ProcCC_None: case ProcCC_InlineAsm: @@ -1451,7 +1451,7 @@ LB_ABI_INFO(lb_get_abi_info_internal) { } -LB_ABI_INFO(lb_get_abi_info) { +gb_internal LB_ABI_INFO(lb_get_abi_info) { lbFunctionType *ft = lb_get_abi_info_internal( c, arg_types, arg_count, diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index 0a44b0939..ca4b3b683 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -22,7 +22,7 @@ #include "llvm_backend_proc.cpp" -void lb_add_foreign_library_path(lbModule *m, Entity *e) { +gb_internal void lb_add_foreign_library_path(lbModule *m, Entity *e) { if (e == nullptr) { return; } @@ -36,7 +36,7 @@ void lb_add_foreign_library_path(lbModule *m, Entity *e) { mutex_unlock(&m->gen->foreign_mutex); } -GB_COMPARE_PROC(foreign_library_cmp) { +gb_internal GB_COMPARE_PROC(foreign_library_cmp) { int cmp = 0; Entity *x = *(Entity **)a; Entity *y = *(Entity **)b; @@ -78,7 +78,7 @@ GB_COMPARE_PROC(foreign_library_cmp) { return i32_cmp(x->token.pos.offset, y->token.pos.offset); } -void lb_set_entity_from_other_modules_linkage_correctly(lbModule *other_module, Entity *e, String const &name) { +gb_internal void lb_set_entity_from_other_modules_linkage_correctly(lbModule *other_module, Entity *e, String const &name) { if (other_module == nullptr) { return; } @@ -95,7 +95,7 @@ void lb_set_entity_from_other_modules_linkage_correctly(lbModule *other_module, } } -void lb_emit_init_context(lbProcedure *p, lbAddr addr) { +gb_internal void lb_emit_init_context(lbProcedure *p, lbAddr addr) { GB_ASSERT(addr.kind == lbAddr_Context); GB_ASSERT(addr.ctx.sel.index.count == 0); @@ -104,7 +104,7 @@ void lb_emit_init_context(lbProcedure *p, lbAddr addr) { lb_emit_runtime_call(p, "__init_context", args); } -lbContextData *lb_push_context_onto_stack_from_implicit_parameter(lbProcedure *p) { +gb_internal lbContextData *lb_push_context_onto_stack_from_implicit_parameter(lbProcedure *p) { Type *pt = base_type(p->type); GB_ASSERT(pt->kind == Type_Proc); GB_ASSERT(pt->Proc.calling_convention == ProcCC_Odin); @@ -131,7 +131,7 @@ lbContextData *lb_push_context_onto_stack_from_implicit_parameter(lbProcedure *p return cd; } -lbContextData *lb_push_context_onto_stack(lbProcedure *p, lbAddr ctx) { +gb_internal lbContextData *lb_push_context_onto_stack(lbProcedure *p, lbAddr ctx) { ctx.kind = lbAddr_Context; lbContextData *cd = array_add_and_get(&p->context_stack); cd->ctx = ctx; @@ -140,7 +140,7 @@ lbContextData *lb_push_context_onto_stack(lbProcedure *p, lbAddr ctx) { } -lbValue lb_equal_proc_for_type(lbModule *m, Type *type) { +gb_internal lbValue lb_equal_proc_for_type(lbModule *m, Type *type) { type = base_type(type); GB_ASSERT(is_type_comparable(type)); @@ -279,7 +279,7 @@ lbValue lb_equal_proc_for_type(lbModule *m, Type *type) { return {compare_proc->value, compare_proc->type}; } -lbValue lb_simple_compare_hash(lbProcedure *p, Type *type, lbValue data, lbValue seed) { +gb_internal lbValue lb_simple_compare_hash(lbProcedure *p, Type *type, lbValue data, lbValue seed) { GB_ASSERT_MSG(is_type_simple_compare(type), "%s", type_to_string(type)); auto args = array_make(permanent_allocator(), 3); @@ -289,11 +289,11 @@ lbValue lb_simple_compare_hash(lbProcedure *p, Type *type, lbValue data, lbValue return lb_emit_runtime_call(p, "default_hasher", args); } -void lb_add_callsite_force_inline(lbProcedure *p, lbValue ret_value) { +gb_internal void lb_add_callsite_force_inline(lbProcedure *p, lbValue ret_value) { LLVMAddCallSiteAttribute(ret_value.value, LLVMAttributeIndex_FunctionIndex, lb_create_enum_attribute(p->module->ctx, "alwaysinline")); } -lbValue lb_hasher_proc_for_type(lbModule *m, Type *type) { +gb_internal lbValue lb_hasher_proc_for_type(lbModule *m, Type *type) { type = core_type(type); GB_ASSERT_MSG(is_type_valid_for_keys(type), "%s", type_to_string(type)); @@ -458,7 +458,7 @@ lbValue lb_hasher_proc_for_type(lbModule *m, Type *type) { } -lbValue lb_map_get_proc_for_type(lbModule *m, Type *type) { +gb_internal lbValue lb_map_get_proc_for_type(lbModule *m, Type *type) { GB_ASSERT(build_context.use_static_map_calls); type = base_type(type); GB_ASSERT(type->kind == Type_Map); @@ -605,13 +605,13 @@ lbValue lb_map_get_proc_for_type(lbModule *m, Type *type) { return {p->value, p->type}; } -void lb_debug_print(lbProcedure *p, String const &str) { +gb_internal void lb_debug_print(lbProcedure *p, String const &str) { auto args = array_make(heap_allocator(), 1); args[0] = lb_const_string(p->module, str); lb_emit_runtime_call(p, "print_string", args); } -lbValue lb_map_set_proc_for_type(lbModule *m, Type *type) { +gb_internal lbValue lb_map_set_proc_for_type(lbModule *m, Type *type) { GB_ASSERT(build_context.use_static_map_calls); type = base_type(type); GB_ASSERT(type->kind == Type_Map); @@ -731,7 +731,7 @@ lbValue lb_map_set_proc_for_type(lbModule *m, Type *type) { } -lbValue lb_generate_anonymous_proc_lit(lbModule *m, String const &prefix_name, Ast *expr, lbProcedure *parent) { +gb_internal lbValue lb_generate_anonymous_proc_lit(lbModule *m, String const &prefix_name, Ast *expr, lbProcedure *parent) { lbProcedure **found = map_get(&m->gen->anonymous_proc_lits, expr); if (found) { return lb_find_procedure_value_from_entity(m, (*found)->entity); @@ -778,7 +778,7 @@ lbValue lb_generate_anonymous_proc_lit(lbModule *m, String const &prefix_name, A } -lbValue lb_gen_map_cell_info_ptr(lbModule *m, Type *type) { +gb_internal lbValue lb_gen_map_cell_info_ptr(lbModule *m, Type *type) { lbAddr *found = map_get(&m->map_cell_info_map, type); if (found) { return found->addr; @@ -802,7 +802,7 @@ lbValue lb_gen_map_cell_info_ptr(lbModule *m, Type *type) { return addr.addr; } -lbValue lb_gen_map_info_ptr(lbModule *m, Type *map_type) { +gb_internal lbValue lb_gen_map_info_ptr(lbModule *m, Type *map_type) { map_type = base_type(map_type); GB_ASSERT(map_type->kind == Type_Map); @@ -833,7 +833,7 @@ lbValue lb_gen_map_info_ptr(lbModule *m, Type *map_type) { return addr.addr; } -lbValue lb_const_hash(lbModule *m, lbValue key, Type *key_type) { +gb_internal lbValue lb_const_hash(lbModule *m, lbValue key, Type *key_type) { if (true) { return {}; } @@ -880,7 +880,7 @@ lbValue lb_const_hash(lbModule *m, lbValue key, Type *key_type) { return hashed_key; } -lbValue lb_gen_map_key_hash(lbProcedure *p, lbValue key, Type *key_type, lbValue *key_ptr_) { +gb_internal lbValue lb_gen_map_key_hash(lbProcedure *p, lbValue key, Type *key_type, lbValue *key_ptr_) { lbValue key_ptr = lb_address_from_load_or_generate_local(p, key); key_ptr = lb_emit_conv(p, key_ptr, t_rawptr); @@ -899,7 +899,7 @@ lbValue lb_gen_map_key_hash(lbProcedure *p, lbValue key, Type *key_type, lbValue return hashed_key; } -lbValue lb_internal_dynamic_map_get_ptr(lbProcedure *p, lbValue const &map_ptr, lbValue const &key) { +gb_internal lbValue lb_internal_dynamic_map_get_ptr(lbProcedure *p, lbValue const &map_ptr, lbValue const &key) { Type *map_type = base_type(type_deref(map_ptr.type)); GB_ASSERT(map_type->kind == Type_Map); @@ -928,8 +928,8 @@ lbValue lb_internal_dynamic_map_get_ptr(lbProcedure *p, lbValue const &map_ptr, return lb_emit_conv(p, ptr, alloc_type_pointer(map_type->Map.value)); } -void lb_internal_dynamic_map_set(lbProcedure *p, lbValue const &map_ptr, Type *map_type, - lbValue const &map_key, lbValue const &map_value, Ast *node) { +gb_internal void lb_internal_dynamic_map_set(lbProcedure *p, lbValue const &map_ptr, Type *map_type, + lbValue const &map_key, lbValue const &map_value, Ast *node) { map_type = base_type(map_type); GB_ASSERT(map_type->kind == Type_Map); @@ -962,7 +962,7 @@ void lb_internal_dynamic_map_set(lbProcedure *p, lbValue const &map_ptr, Type *m } } -lbValue lb_dynamic_map_reserve(lbProcedure *p, lbValue const &map_ptr, isize const capacity, TokenPos const &pos) { +gb_internal lbValue lb_dynamic_map_reserve(lbProcedure *p, lbValue const &map_ptr, isize const capacity, TokenPos const &pos) { GB_ASSERT(!build_context.no_dynamic_literals); String proc_name = {}; @@ -986,7 +986,7 @@ struct lbGlobalVariable { bool is_initialized; }; -lbProcedure *lb_create_startup_type_info(lbModule *m) { +gb_internal lbProcedure *lb_create_startup_type_info(lbModule *m) { if (build_context.disallow_rtti) { return nullptr; } @@ -1020,7 +1020,7 @@ lbProcedure *lb_create_startup_type_info(lbModule *m) { return p; } -lbProcedure *lb_create_objc_names(lbModule *main_module) { +gb_internal lbProcedure *lb_create_objc_names(lbModule *main_module) { if (build_context.metrics.os != TargetOs_darwin) { return nullptr; } @@ -1031,7 +1031,7 @@ lbProcedure *lb_create_objc_names(lbModule *main_module) { return p; } -void lb_finalize_objc_names(lbProcedure *p) { +gb_internal void lb_finalize_objc_names(lbProcedure *p) { if (p == nullptr) { return; } @@ -1066,7 +1066,7 @@ void lb_finalize_objc_names(lbProcedure *p) { } -lbProcedure *lb_create_startup_runtime(lbModule *main_module, lbProcedure *startup_type_info, lbProcedure *objc_names, Array &global_variables) { // Startup Runtime +gb_internal lbProcedure *lb_create_startup_runtime(lbModule *main_module, lbProcedure *startup_type_info, lbProcedure *objc_names, Array &global_variables) { // Startup Runtime LLVMPassManagerRef default_function_pass_manager = LLVMCreateFunctionPassManagerForModule(main_module->mod); lb_populate_function_pass_manager(main_module, default_function_pass_manager, false, build_context.optimization_level); LLVMFinalizeFunctionPassManager(default_function_pass_manager); @@ -1181,7 +1181,7 @@ lbProcedure *lb_create_startup_runtime(lbModule *main_module, lbProcedure *start } -lbProcedure *lb_create_main_procedure(lbModule *m, lbProcedure *startup_runtime) { +gb_internal lbProcedure *lb_create_main_procedure(lbModule *m, lbProcedure *startup_runtime) { LLVMPassManagerRef default_function_pass_manager = LLVMCreateFunctionPassManagerForModule(m->mod); lb_populate_function_pass_manager(m, default_function_pass_manager, false, build_context.optimization_level); LLVMFinalizeFunctionPassManager(default_function_pass_manager); @@ -1331,7 +1331,7 @@ lbProcedure *lb_create_main_procedure(lbModule *m, lbProcedure *startup_runtime) return p; } -String lb_filepath_ll_for_module(lbModule *m) { +gb_internal String lb_filepath_ll_for_module(lbModule *m) { String path = concatenate3_strings(permanent_allocator(), build_context.build_paths[BuildPath_Output].basename, STR_LIT("/"), @@ -1347,7 +1347,7 @@ String lb_filepath_ll_for_module(lbModule *m) { return path; } -String lb_filepath_obj_for_module(lbModule *m) { +gb_internal String lb_filepath_obj_for_module(lbModule *m) { String path = concatenate3_strings(permanent_allocator(), build_context.build_paths[BuildPath_Output].basename, STR_LIT("/"), @@ -1397,7 +1397,7 @@ String lb_filepath_obj_for_module(lbModule *m) { } -bool lb_is_module_empty(lbModule *m) { +gb_internal bool lb_is_module_empty(lbModule *m) { if (LLVMGetFirstFunction(m->mod) == nullptr && LLVMGetFirstGlobal(m->mod) == nullptr) { return true; @@ -1426,7 +1426,7 @@ struct lbLLVMEmitWorker { lbModule *m; }; -WORKER_TASK_PROC(lb_llvm_emit_worker_proc) { +gb_internal WORKER_TASK_PROC(lb_llvm_emit_worker_proc) { GB_ASSERT(MULTITHREAD_OBJECT_GENERATION); char *llvm_error = nullptr; @@ -1441,7 +1441,7 @@ WORKER_TASK_PROC(lb_llvm_emit_worker_proc) { return 0; } -WORKER_TASK_PROC(lb_llvm_function_pass_worker_proc) { +gb_internal WORKER_TASK_PROC(lb_llvm_function_pass_worker_proc) { GB_ASSERT(MULTITHREAD_OBJECT_GENERATION); auto m = cast(lbModule *)data; @@ -1526,7 +1526,7 @@ struct lbLLVMModulePassWorkerData { LLVMTargetMachineRef target_machine; }; -WORKER_TASK_PROC(lb_llvm_module_pass_worker_proc) { +gb_internal WORKER_TASK_PROC(lb_llvm_module_pass_worker_proc) { auto wd = cast(lbLLVMModulePassWorkerData *)data; LLVMPassManagerRef module_pass_manager = LLVMCreatePassManager(); lb_populate_module_pass_manager(wd->target_machine, module_pass_manager, build_context.optimization_level); @@ -1535,7 +1535,7 @@ WORKER_TASK_PROC(lb_llvm_module_pass_worker_proc) { } -void lb_generate_procedure(lbModule *m, lbProcedure *p) { +gb_internal void lb_generate_procedure(lbModule *m, lbProcedure *p) { if (p->is_done) { return; } @@ -1575,7 +1575,7 @@ void lb_generate_procedure(lbModule *m, lbProcedure *p) { } -void lb_generate_code(lbGenerator *gen) { +gb_internal void lb_generate_code(lbGenerator *gen) { TIME_SECTION("LLVM Initializtion"); isize thread_count = gb_max(build_context.thread_count, 1); diff --git a/src/llvm_backend.hpp b/src/llvm_backend.hpp index a85056579..9f7caa3bb 100644 --- a/src/llvm_backend.hpp +++ b/src/llvm_backend.hpp @@ -322,197 +322,197 @@ struct lbProcedure { #define LLVMBuildPtrDiff2(Builder__, Ty__, LHS__, RHS__, Name__) LLVMBuildPtrDiff(Builder__, LHS__, RHS__, Name__) #endif -bool lb_init_generator(lbGenerator *gen, Checker *c); +gb_internal bool lb_init_generator(lbGenerator *gen, Checker *c); -String lb_mangle_name(lbModule *m, Entity *e); -String lb_get_entity_name(lbModule *m, Entity *e, String name = {}); +gb_internal String lb_mangle_name(lbModule *m, Entity *e); +gb_internal String lb_get_entity_name(lbModule *m, Entity *e, String name = {}); -LLVMAttributeRef lb_create_enum_attribute(LLVMContextRef ctx, char const *name, u64 value=0); -LLVMAttributeRef lb_create_enum_attribute_with_type(LLVMContextRef ctx, char const *name, LLVMTypeRef type); -void lb_add_proc_attribute_at_index(lbProcedure *p, isize index, char const *name, u64 value); -void lb_add_proc_attribute_at_index(lbProcedure *p, isize index, char const *name); -lbProcedure *lb_create_procedure(lbModule *module, Entity *entity, bool ignore_body=false); -void lb_end_procedure(lbProcedure *p); +gb_internal LLVMAttributeRef lb_create_enum_attribute(LLVMContextRef ctx, char const *name, u64 value=0); +gb_internal LLVMAttributeRef lb_create_enum_attribute_with_type(LLVMContextRef ctx, char const *name, LLVMTypeRef type); +gb_internal void lb_add_proc_attribute_at_index(lbProcedure *p, isize index, char const *name, u64 value); +gb_internal void lb_add_proc_attribute_at_index(lbProcedure *p, isize index, char const *name); +gb_internal lbProcedure *lb_create_procedure(lbModule *module, Entity *entity, bool ignore_body=false); +gb_internal void lb_end_procedure(lbProcedure *p); -LLVMTypeRef lb_type(lbModule *m, Type *type); -LLVMTypeRef llvm_get_element_type(LLVMTypeRef type); +gb_internal LLVMTypeRef lb_type(lbModule *m, Type *type); +gb_internal LLVMTypeRef llvm_get_element_type(LLVMTypeRef type); -lbBlock *lb_create_block(lbProcedure *p, char const *name, bool append=false); +gb_internal lbBlock *lb_create_block(lbProcedure *p, char const *name, bool append=false); -lbValue lb_const_nil(lbModule *m, Type *type); -lbValue lb_const_undef(lbModule *m, Type *type); -lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_local=true); -lbValue lb_const_bool(lbModule *m, Type *type, bool value); -lbValue lb_const_int(lbModule *m, Type *type, u64 value); +gb_internal lbValue lb_const_nil(lbModule *m, Type *type); +gb_internal lbValue lb_const_undef(lbModule *m, Type *type); +gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_local=true); +gb_internal lbValue lb_const_bool(lbModule *m, Type *type, bool value); +gb_internal lbValue lb_const_int(lbModule *m, Type *type, u64 value); -lbAddr lb_addr(lbValue addr); -Type *lb_addr_type(lbAddr const &addr); -LLVMTypeRef llvm_addr_type(lbModule *module, lbValue addr_val); -void lb_addr_store(lbProcedure *p, lbAddr addr, lbValue value); -lbValue lb_addr_load(lbProcedure *p, lbAddr const &addr); -lbValue lb_emit_load(lbProcedure *p, lbValue v); -void lb_emit_store(lbProcedure *p, lbValue ptr, lbValue value); +gb_internal lbAddr lb_addr(lbValue addr); +gb_internal Type *lb_addr_type(lbAddr const &addr); +gb_internal LLVMTypeRef llvm_addr_type(lbModule *module, lbValue addr_val); +gb_internal void lb_addr_store(lbProcedure *p, lbAddr addr, lbValue value); +gb_internal lbValue lb_addr_load(lbProcedure *p, lbAddr const &addr); +gb_internal lbValue lb_emit_load(lbProcedure *p, lbValue v); +gb_internal void lb_emit_store(lbProcedure *p, lbValue ptr, lbValue value); -void lb_build_stmt(lbProcedure *p, Ast *stmt); -lbValue lb_build_expr(lbProcedure *p, Ast *expr); -lbAddr lb_build_addr(lbProcedure *p, Ast *expr); -void lb_build_stmt_list(lbProcedure *p, Array const &stmts); +gb_internal void lb_build_stmt(lbProcedure *p, Ast *stmt); +gb_internal lbValue lb_build_expr(lbProcedure *p, Ast *expr); +gb_internal lbAddr lb_build_addr(lbProcedure *p, Ast *expr); +gb_internal void lb_build_stmt_list(lbProcedure *p, Array const &stmts); -lbValue lb_emit_epi(lbProcedure *p, lbValue const &value, isize index); -lbValue lb_emit_epi(lbModule *m, lbValue const &value, isize index); -lbValue lb_emit_array_epi(lbModule *m, lbValue s, isize index); -lbValue lb_emit_struct_ep(lbProcedure *p, lbValue s, i32 index); -lbValue lb_emit_struct_ev(lbProcedure *p, lbValue s, i32 index); -lbValue lb_emit_tuple_ev(lbProcedure *p, lbValue value, i32 index); -lbValue lb_emit_array_epi(lbProcedure *p, lbValue value, isize index); -lbValue lb_emit_array_ep(lbProcedure *p, lbValue s, lbValue index); -lbValue lb_emit_deep_field_gep(lbProcedure *p, lbValue e, Selection sel); -lbValue lb_emit_deep_field_ev(lbProcedure *p, lbValue e, Selection sel); +gb_internal lbValue lb_emit_epi(lbProcedure *p, lbValue const &value, isize index); +gb_internal lbValue lb_emit_epi(lbModule *m, lbValue const &value, isize index); +gb_internal lbValue lb_emit_array_epi(lbModule *m, lbValue s, isize index); +gb_internal lbValue lb_emit_struct_ep(lbProcedure *p, lbValue s, i32 index); +gb_internal lbValue lb_emit_struct_ev(lbProcedure *p, lbValue s, i32 index); +gb_internal lbValue lb_emit_tuple_ev(lbProcedure *p, lbValue value, i32 index); +gb_internal lbValue lb_emit_array_epi(lbProcedure *p, lbValue value, isize index); +gb_internal lbValue lb_emit_array_ep(lbProcedure *p, lbValue s, lbValue index); +gb_internal lbValue lb_emit_deep_field_gep(lbProcedure *p, lbValue e, Selection sel); +gb_internal lbValue lb_emit_deep_field_ev(lbProcedure *p, lbValue e, Selection sel); -lbValue lb_emit_matrix_ep(lbProcedure *p, lbValue s, lbValue row, lbValue column); -lbValue lb_emit_matrix_epi(lbProcedure *p, lbValue s, isize row, isize column); -lbValue lb_emit_matrix_ev(lbProcedure *p, lbValue s, isize row, isize column); +gb_internal lbValue lb_emit_matrix_ep(lbProcedure *p, lbValue s, lbValue row, lbValue column); +gb_internal lbValue lb_emit_matrix_epi(lbProcedure *p, lbValue s, isize row, isize column); +gb_internal lbValue lb_emit_matrix_ev(lbProcedure *p, lbValue s, isize row, isize column); -lbValue lb_emit_arith(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type); -lbValue lb_emit_byte_swap(lbProcedure *p, lbValue value, Type *end_type); -void lb_emit_defer_stmts(lbProcedure *p, lbDeferExitKind kind, lbBlock *block); -lbValue lb_emit_transmute(lbProcedure *p, lbValue value, Type *t); -lbValue lb_emit_comp(lbProcedure *p, TokenKind op_kind, lbValue left, lbValue right); -lbValue lb_emit_call(lbProcedure *p, lbValue value, Array const &args, ProcInlining inlining = ProcInlining_none); -lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t); -lbValue lb_emit_comp_against_nil(lbProcedure *p, TokenKind op_kind, lbValue x); +gb_internal lbValue lb_emit_arith(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type); +gb_internal lbValue lb_emit_byte_swap(lbProcedure *p, lbValue value, Type *end_type); +gb_internal void lb_emit_defer_stmts(lbProcedure *p, lbDeferExitKind kind, lbBlock *block); +gb_internal lbValue lb_emit_transmute(lbProcedure *p, lbValue value, Type *t); +gb_internal lbValue lb_emit_comp(lbProcedure *p, TokenKind op_kind, lbValue left, lbValue right); +gb_internal lbValue lb_emit_call(lbProcedure *p, lbValue value, Array const &args, ProcInlining inlining = ProcInlining_none); +gb_internal lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t); +gb_internal lbValue lb_emit_comp_against_nil(lbProcedure *p, TokenKind op_kind, lbValue x); -void lb_emit_jump(lbProcedure *p, lbBlock *target_block); -void lb_emit_if(lbProcedure *p, lbValue cond, lbBlock *true_block, lbBlock *false_block); -void lb_start_block(lbProcedure *p, lbBlock *b); +gb_internal void lb_emit_jump(lbProcedure *p, lbBlock *target_block); +gb_internal void lb_emit_if(lbProcedure *p, lbValue cond, lbBlock *true_block, lbBlock *false_block); +gb_internal void lb_start_block(lbProcedure *p, lbBlock *b); -lbValue lb_build_call_expr(lbProcedure *p, Ast *expr); +gb_internal lbValue lb_build_call_expr(lbProcedure *p, Ast *expr); -lbAddr lb_find_or_generate_context_ptr(lbProcedure *p); -lbContextData *lb_push_context_onto_stack(lbProcedure *p, lbAddr ctx); -lbContextData *lb_push_context_onto_stack_from_implicit_parameter(lbProcedure *p); +gb_internal lbAddr lb_find_or_generate_context_ptr(lbProcedure *p); +gb_internal lbContextData *lb_push_context_onto_stack(lbProcedure *p, lbAddr ctx); +gb_internal lbContextData *lb_push_context_onto_stack_from_implicit_parameter(lbProcedure *p); -lbAddr lb_add_global_generated(lbModule *m, Type *type, lbValue value={}, Entity **entity_=nullptr); -lbAddr lb_add_local(lbProcedure *p, Type *type, Entity *e=nullptr, bool zero_init=true, bool force_no_init=false); +gb_internal lbAddr lb_add_global_generated(lbModule *m, Type *type, lbValue value={}, Entity **entity_=nullptr); +gb_internal lbAddr lb_add_local(lbProcedure *p, Type *type, Entity *e=nullptr, bool zero_init=true, bool force_no_init=false); -void lb_add_foreign_library_path(lbModule *m, Entity *e); +gb_internal void lb_add_foreign_library_path(lbModule *m, Entity *e); -lbValue lb_typeid(lbModule *m, Type *type); +gb_internal lbValue lb_typeid(lbModule *m, Type *type); -lbValue lb_address_from_load_or_generate_local(lbProcedure *p, lbValue value); -lbValue lb_address_from_load(lbProcedure *p, lbValue value); -void lb_add_defer_node(lbProcedure *p, isize scope_index, Ast *stmt); -lbAddr lb_add_local_generated(lbProcedure *p, Type *type, bool zero_init); +gb_internal lbValue lb_address_from_load_or_generate_local(lbProcedure *p, lbValue value); +gb_internal lbValue lb_address_from_load(lbProcedure *p, lbValue value); +gb_internal void lb_add_defer_node(lbProcedure *p, isize scope_index, Ast *stmt); +gb_internal lbAddr lb_add_local_generated(lbProcedure *p, Type *type, bool zero_init); -lbValue lb_emit_runtime_call(lbProcedure *p, char const *c_name, Array const &args); +gb_internal lbValue lb_emit_runtime_call(lbProcedure *p, char const *c_name, Array const &args); -lbValue lb_emit_ptr_offset(lbProcedure *p, lbValue ptr, lbValue index); -lbValue lb_string_elem(lbProcedure *p, lbValue string); -lbValue lb_string_len(lbProcedure *p, lbValue string); -lbValue lb_cstring_len(lbProcedure *p, lbValue value); -lbValue lb_array_elem(lbProcedure *p, lbValue array_ptr); -lbValue lb_slice_elem(lbProcedure *p, lbValue slice); -lbValue lb_slice_len(lbProcedure *p, lbValue slice); -lbValue lb_dynamic_array_elem(lbProcedure *p, lbValue da); -lbValue lb_dynamic_array_len(lbProcedure *p, lbValue da); -lbValue lb_dynamic_array_cap(lbProcedure *p, lbValue da); -lbValue lb_dynamic_array_allocator(lbProcedure *p, lbValue da); -lbValue lb_map_len(lbProcedure *p, lbValue value); -lbValue lb_map_cap(lbProcedure *p, lbValue value); -lbValue lb_soa_struct_len(lbProcedure *p, lbValue value); -void lb_emit_increment(lbProcedure *p, lbValue addr); -lbValue lb_emit_select(lbProcedure *p, lbValue cond, lbValue x, lbValue y); +gb_internal lbValue lb_emit_ptr_offset(lbProcedure *p, lbValue ptr, lbValue index); +gb_internal lbValue lb_string_elem(lbProcedure *p, lbValue string); +gb_internal lbValue lb_string_len(lbProcedure *p, lbValue string); +gb_internal lbValue lb_cstring_len(lbProcedure *p, lbValue value); +gb_internal lbValue lb_array_elem(lbProcedure *p, lbValue array_ptr); +gb_internal lbValue lb_slice_elem(lbProcedure *p, lbValue slice); +gb_internal lbValue lb_slice_len(lbProcedure *p, lbValue slice); +gb_internal lbValue lb_dynamic_array_elem(lbProcedure *p, lbValue da); +gb_internal lbValue lb_dynamic_array_len(lbProcedure *p, lbValue da); +gb_internal lbValue lb_dynamic_array_cap(lbProcedure *p, lbValue da); +gb_internal lbValue lb_dynamic_array_allocator(lbProcedure *p, lbValue da); +gb_internal lbValue lb_map_len(lbProcedure *p, lbValue value); +gb_internal lbValue lb_map_cap(lbProcedure *p, lbValue value); +gb_internal lbValue lb_soa_struct_len(lbProcedure *p, lbValue value); +gb_internal void lb_emit_increment(lbProcedure *p, lbValue addr); +gb_internal lbValue lb_emit_select(lbProcedure *p, lbValue cond, lbValue x, lbValue y); -lbValue lb_emit_mul_add(lbProcedure *p, lbValue a, lbValue b, lbValue c, Type *t); +gb_internal lbValue lb_emit_mul_add(lbProcedure *p, lbValue a, lbValue b, lbValue c, Type *t); -void lb_fill_slice(lbProcedure *p, lbAddr const &slice, lbValue base_elem, lbValue len); +gb_internal void lb_fill_slice(lbProcedure *p, lbAddr const &slice, lbValue base_elem, lbValue len); -lbValue lb_type_info(lbModule *m, Type *type); +gb_internal lbValue lb_type_info(lbModule *m, Type *type); -lbValue lb_find_or_add_entity_string(lbModule *m, String const &str); -lbValue lb_generate_anonymous_proc_lit(lbModule *m, String const &prefix_name, Ast *expr, lbProcedure *parent = nullptr); +gb_internal lbValue lb_find_or_add_entity_string(lbModule *m, String const &str); +gb_internal lbValue lb_generate_anonymous_proc_lit(lbModule *m, String const &prefix_name, Ast *expr, lbProcedure *parent = nullptr); -bool lb_is_const(lbValue value); -bool lb_is_const_or_global(lbValue value); -bool lb_is_const_nil(lbValue value); -String lb_get_const_string(lbModule *m, lbValue value); +gb_internal bool lb_is_const(lbValue value); +gb_internal bool lb_is_const_or_global(lbValue value); +gb_internal bool lb_is_const_nil(lbValue value); +gb_internal String lb_get_const_string(lbModule *m, lbValue value); -lbValue lb_generate_local_array(lbProcedure *p, Type *elem_type, i64 count, bool zero_init=true); -lbValue lb_generate_global_array(lbModule *m, Type *elem_type, i64 count, String prefix, i64 id); -lbValue lb_gen_map_key_hash(lbProcedure *p, lbValue key, Type *key_type, lbValue *key_ptr_); -lbValue lb_gen_map_cell_info_ptr(lbModule *m, Type *type); -lbValue lb_gen_map_info_ptr(lbModule *m, Type *map_type); +gb_internal lbValue lb_generate_local_array(lbProcedure *p, Type *elem_type, i64 count, bool zero_init=true); +gb_internal lbValue lb_generate_global_array(lbModule *m, Type *elem_type, i64 count, String prefix, i64 id); +gb_internal lbValue lb_gen_map_key_hash(lbProcedure *p, lbValue key, Type *key_type, lbValue *key_ptr_); +gb_internal lbValue lb_gen_map_cell_info_ptr(lbModule *m, Type *type); +gb_internal lbValue lb_gen_map_info_ptr(lbModule *m, Type *map_type); -lbValue lb_internal_dynamic_map_get_ptr(lbProcedure *p, lbValue const &map_ptr, lbValue const &key); -void lb_internal_dynamic_map_set(lbProcedure *p, lbValue const &map_ptr, Type *map_type, lbValue const &map_key, lbValue const &map_value, Ast *node); -lbValue lb_dynamic_map_reserve(lbProcedure *p, lbValue const &map_ptr, isize const capacity, TokenPos const &pos); +gb_internal lbValue lb_internal_dynamic_map_get_ptr(lbProcedure *p, lbValue const &map_ptr, lbValue const &key); +gb_internal void lb_internal_dynamic_map_set(lbProcedure *p, lbValue const &map_ptr, Type *map_type, lbValue const &map_key, lbValue const &map_value, Ast *node); +gb_internal lbValue lb_dynamic_map_reserve(lbProcedure *p, lbValue const &map_ptr, isize const capacity, TokenPos const &pos); -lbValue lb_find_procedure_value_from_entity(lbModule *m, Entity *e); -lbValue lb_find_value_from_entity(lbModule *m, Entity *e); +gb_internal lbValue lb_find_procedure_value_from_entity(lbModule *m, Entity *e); +gb_internal lbValue lb_find_value_from_entity(lbModule *m, Entity *e); -void lb_store_type_case_implicit(lbProcedure *p, Ast *clause, lbValue value); -lbAddr lb_store_range_stmt_val(lbProcedure *p, Ast *stmt_val, lbValue value); -lbValue lb_emit_source_code_location_const(lbProcedure *p, String const &procedure, TokenPos const &pos); +gb_internal void lb_store_type_case_implicit(lbProcedure *p, Ast *clause, lbValue value); +gb_internal lbAddr lb_store_range_stmt_val(lbProcedure *p, Ast *stmt_val, lbValue value); +gb_internal lbValue lb_emit_source_code_location_const(lbProcedure *p, String const &procedure, TokenPos const &pos); -lbValue lb_handle_param_value(lbProcedure *p, Type *parameter_type, ParameterValue const ¶m_value, TokenPos const &pos); +gb_internal lbValue lb_handle_param_value(lbProcedure *p, Type *parameter_type, ParameterValue const ¶m_value, TokenPos const &pos); -lbValue lb_equal_proc_for_type(lbModule *m, Type *type); -lbValue lb_hasher_proc_for_type(lbModule *m, Type *type); -lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t); +gb_internal lbValue lb_equal_proc_for_type(lbModule *m, Type *type); +gb_internal lbValue lb_hasher_proc_for_type(lbModule *m, Type *type); +gb_internal lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t); -LLVMMetadataRef lb_debug_type(lbModule *m, Type *type); +gb_internal LLVMMetadataRef lb_debug_type(lbModule *m, Type *type); -lbValue lb_emit_count_ones(lbProcedure *p, lbValue x, Type *type); -lbValue lb_emit_count_zeros(lbProcedure *p, lbValue x, Type *type); -lbValue lb_emit_count_trailing_zeros(lbProcedure *p, lbValue x, Type *type); -lbValue lb_emit_count_leading_zeros(lbProcedure *p, lbValue x, Type *type); -lbValue lb_emit_reverse_bits(lbProcedure *p, lbValue x, Type *type); +gb_internal lbValue lb_emit_count_ones(lbProcedure *p, lbValue x, Type *type); +gb_internal lbValue lb_emit_count_zeros(lbProcedure *p, lbValue x, Type *type); +gb_internal lbValue lb_emit_count_trailing_zeros(lbProcedure *p, lbValue x, Type *type); +gb_internal lbValue lb_emit_count_leading_zeros(lbProcedure *p, lbValue x, Type *type); +gb_internal lbValue lb_emit_reverse_bits(lbProcedure *p, lbValue x, Type *type); -lbValue lb_emit_bit_set_card(lbProcedure *p, lbValue x); +gb_internal lbValue lb_emit_bit_set_card(lbProcedure *p, lbValue x); -void lb_mem_zero_addr(lbProcedure *p, LLVMValueRef ptr, Type *type); +gb_internal void lb_mem_zero_addr(lbProcedure *p, LLVMValueRef ptr, Type *type); -void lb_build_nested_proc(lbProcedure *p, AstProcLit *pd, Entity *e); -lbValue lb_emit_logical_binary_expr(lbProcedure *p, TokenKind op, Ast *left, Ast *right, Type *type); -lbValue lb_build_cond(lbProcedure *p, Ast *cond, lbBlock *true_block, lbBlock *false_block); +gb_internal void lb_build_nested_proc(lbProcedure *p, AstProcLit *pd, Entity *e); +gb_internal lbValue lb_emit_logical_binary_expr(lbProcedure *p, TokenKind op, Ast *left, Ast *right, Type *type); +gb_internal lbValue lb_build_cond(lbProcedure *p, Ast *cond, lbBlock *true_block, lbBlock *false_block); -LLVMValueRef llvm_const_named_struct(lbModule *m, Type *t, LLVMValueRef *values, isize value_count_); -LLVMValueRef llvm_const_named_struct_internal(LLVMTypeRef t, LLVMValueRef *values, isize value_count_); -void lb_set_entity_from_other_modules_linkage_correctly(lbModule *other_module, Entity *e, String const &name); +gb_internal LLVMValueRef llvm_const_named_struct(lbModule *m, Type *t, LLVMValueRef *values, isize value_count_); +gb_internal LLVMValueRef llvm_const_named_struct_internal(LLVMTypeRef t, LLVMValueRef *values, isize value_count_); +gb_internal void lb_set_entity_from_other_modules_linkage_correctly(lbModule *other_module, Entity *e, String const &name); -lbValue lb_expr_untyped_const_to_typed(lbModule *m, Ast *expr, Type *t); -bool lb_is_expr_untyped_const(Ast *expr); +gb_internal lbValue lb_expr_untyped_const_to_typed(lbModule *m, Ast *expr, Type *t); +gb_internal bool lb_is_expr_untyped_const(Ast *expr); -LLVMValueRef llvm_alloca(lbProcedure *p, LLVMTypeRef llvm_type, isize alignment, char const *name = ""); +gb_internal LLVMValueRef llvm_alloca(lbProcedure *p, LLVMTypeRef llvm_type, isize alignment, char const *name = ""); -void lb_mem_zero_ptr(lbProcedure *p, LLVMValueRef ptr, Type *type, unsigned alignment); +gb_internal void lb_mem_zero_ptr(lbProcedure *p, LLVMValueRef ptr, Type *type, unsigned alignment); -void lb_emit_init_context(lbProcedure *p, lbAddr addr); +gb_internal void lb_emit_init_context(lbProcedure *p, lbAddr addr); -lbStructFieldRemapping lb_get_struct_remapping(lbModule *m, Type *t); -LLVMTypeRef lb_type_padding_filler(lbModule *m, i64 padding, i64 padding_align); +gb_internal lbStructFieldRemapping lb_get_struct_remapping(lbModule *m, Type *t); +gb_internal LLVMTypeRef lb_type_padding_filler(lbModule *m, i64 padding, i64 padding_align); -LLVMValueRef llvm_basic_shuffle(lbProcedure *p, LLVMValueRef vector, LLVMValueRef mask); +gb_internal LLVMValueRef llvm_basic_shuffle(lbProcedure *p, LLVMValueRef vector, LLVMValueRef mask); -LLVMValueRef lb_call_intrinsic(lbProcedure *p, const char *name, LLVMValueRef* args, unsigned arg_count, LLVMTypeRef* types, unsigned type_count); -void lb_mem_copy_overlapping(lbProcedure *p, lbValue dst, lbValue src, lbValue len, bool is_volatile=false); -void lb_mem_copy_non_overlapping(lbProcedure *p, lbValue dst, lbValue src, lbValue len, bool is_volatile=false); -LLVMValueRef lb_mem_zero_ptr_internal(lbProcedure *p, LLVMValueRef ptr, LLVMValueRef len, unsigned alignment, bool is_volatile); +gb_internal LLVMValueRef lb_call_intrinsic(lbProcedure *p, const char *name, LLVMValueRef* args, unsigned arg_count, LLVMTypeRef* types, unsigned type_count); +gb_internal void lb_mem_copy_overlapping(lbProcedure *p, lbValue dst, lbValue src, lbValue len, bool is_volatile=false); +gb_internal void lb_mem_copy_non_overlapping(lbProcedure *p, lbValue dst, lbValue src, lbValue len, bool is_volatile=false); +gb_internal LLVMValueRef lb_mem_zero_ptr_internal(lbProcedure *p, LLVMValueRef ptr, LLVMValueRef len, unsigned alignment, bool is_volatile); -i64 lb_max_zero_init_size(void) { +gb_internal gb_inline i64 lb_max_zero_init_size(void) { return cast(i64)(4*build_context.word_size); } -LLVMTypeRef OdinLLVMGetArrayElementType(LLVMTypeRef type); -LLVMTypeRef OdinLLVMGetVectorElementType(LLVMTypeRef type); +gb_internal LLVMTypeRef OdinLLVMGetArrayElementType(LLVMTypeRef type); +gb_internal LLVMTypeRef OdinLLVMGetVectorElementType(LLVMTypeRef type); #define LB_STARTUP_RUNTIME_PROC_NAME "__$startup_runtime" #define LB_STARTUP_TYPE_INFO_PROC_NAME "__$startup_type_info" @@ -632,7 +632,7 @@ enum : LLVMAttributeIndex { }; -char const *llvm_linkage_strings[] = { +gb_global char const *llvm_linkage_strings[] = { "external linkage", "available externally linkage", "link once any linkage", diff --git a/src/llvm_backend_const.cpp b/src/llvm_backend_const.cpp index dff5298c5..ee564bbf1 100644 --- a/src/llvm_backend_const.cpp +++ b/src/llvm_backend_const.cpp @@ -1,4 +1,4 @@ -bool lb_is_const(lbValue value) { +gb_internal bool lb_is_const(lbValue value) { LLVMValueRef v = value.value; if (is_type_untyped_nil(value.type) || is_type_untyped_undef(value.type)) { // TODO(bill): Is this correct behaviour? @@ -10,7 +10,7 @@ bool lb_is_const(lbValue value) { return false; } -bool lb_is_const_or_global(lbValue value) { +gb_internal bool lb_is_const_or_global(lbValue value) { if (lb_is_const(value)) { return true; } @@ -29,7 +29,7 @@ bool lb_is_const_or_global(lbValue value) { } -bool lb_is_elem_const(Ast *elem, Type *elem_type) { +gb_internal bool lb_is_elem_const(Ast *elem, Type *elem_type) { if (!elem_type_can_be_constant(elem_type)) { return false; } @@ -42,7 +42,7 @@ bool lb_is_elem_const(Ast *elem, Type *elem_type) { } -bool lb_is_const_nil(lbValue value) { +gb_internal bool lb_is_const_nil(lbValue value) { LLVMValueRef v = value.value; if (LLVMIsConstant(v)) { if (LLVMIsAConstantAggregateZero(v)) { @@ -55,7 +55,7 @@ bool lb_is_const_nil(lbValue value) { } -bool lb_is_expr_constant_zero(Ast *expr) { +gb_internal bool lb_is_expr_constant_zero(Ast *expr) { GB_ASSERT(expr != nullptr); auto v = exact_value_to_integer(expr->tav.value); if (v.kind == ExactValue_Integer) { @@ -64,7 +64,7 @@ bool lb_is_expr_constant_zero(Ast *expr) { return false; } -String lb_get_const_string(lbModule *m, lbValue value) { +gb_internal String lb_get_const_string(lbModule *m, lbValue value) { GB_ASSERT(lb_is_const(value)); GB_ASSERT(LLVMIsConstant(value.value)); @@ -92,7 +92,7 @@ String lb_get_const_string(lbModule *m, lbValue value) { } -LLVMValueRef llvm_const_cast(LLVMValueRef val, LLVMTypeRef dst) { +gb_internal LLVMValueRef llvm_const_cast(LLVMValueRef val, LLVMTypeRef dst) { LLVMTypeRef src = LLVMTypeOf(val); if (src == dst) { return val; @@ -116,7 +116,7 @@ LLVMValueRef llvm_const_cast(LLVMValueRef val, LLVMTypeRef dst) { } -lbValue lb_const_ptr_cast(lbModule *m, lbValue value, Type *t) { +gb_internal lbValue lb_const_ptr_cast(lbModule *m, lbValue value, Type *t) { GB_ASSERT(is_type_internally_pointer_like(value.type)); GB_ASSERT(is_type_internally_pointer_like(t)); GB_ASSERT(lb_is_const(value)); @@ -127,7 +127,7 @@ lbValue lb_const_ptr_cast(lbModule *m, lbValue value, Type *t) { return res; } -LLVMValueRef llvm_const_named_struct(lbModule *m, Type *t, LLVMValueRef *values, isize value_count_) { +gb_internal LLVMValueRef llvm_const_named_struct(lbModule *m, Type *t, LLVMValueRef *values, isize value_count_) { LLVMTypeRef struct_type = lb_type(m, t); GB_ASSERT(LLVMGetTypeKind(struct_type) == LLVMStructTypeKind); @@ -157,7 +157,7 @@ LLVMValueRef llvm_const_named_struct(lbModule *m, Type *t, LLVMValueRef *values, return llvm_const_named_struct_internal(struct_type, values_with_padding, values_with_padding_count); } -LLVMValueRef llvm_const_named_struct_internal(LLVMTypeRef t, LLVMValueRef *values, isize value_count_) { +gb_internal LLVMValueRef llvm_const_named_struct_internal(LLVMTypeRef t, LLVMValueRef *values, isize value_count_) { unsigned value_count = cast(unsigned)value_count_; unsigned elem_count = LLVMCountStructElementTypes(t); GB_ASSERT_MSG(value_count == elem_count, "%s %u %u", LLVMPrintTypeToString(t), value_count, elem_count); @@ -168,7 +168,7 @@ LLVMValueRef llvm_const_named_struct_internal(LLVMTypeRef t, LLVMValueRef *value return LLVMConstNamedStruct(t, values, value_count); } -LLVMValueRef llvm_const_array(LLVMTypeRef elem_type, LLVMValueRef *values, isize value_count_) { +gb_internal LLVMValueRef llvm_const_array(LLVMTypeRef elem_type, LLVMValueRef *values, isize value_count_) { unsigned value_count = cast(unsigned)value_count_; for (unsigned i = 0; i < value_count; i++) { values[i] = llvm_const_cast(values[i], elem_type); @@ -176,7 +176,7 @@ LLVMValueRef llvm_const_array(LLVMTypeRef elem_type, LLVMValueRef *values, isize return LLVMConstArray(elem_type, values, value_count); } -LLVMValueRef llvm_const_slice(lbModule *m, lbValue data, lbValue len) { +gb_internal LLVMValueRef llvm_const_slice(lbModule *m, lbValue data, lbValue len) { GB_ASSERT(is_type_pointer(data.type) || is_type_multi_pointer(data.type)); GB_ASSERT(are_types_identical(len.type, t_int)); LLVMValueRef vals[2] = { @@ -187,38 +187,38 @@ LLVMValueRef llvm_const_slice(lbModule *m, lbValue data, lbValue len) { } -lbValue lb_const_nil(lbModule *m, Type *type) { +gb_internal lbValue lb_const_nil(lbModule *m, Type *type) { LLVMValueRef v = LLVMConstNull(lb_type(m, type)); return lbValue{v, type}; } -lbValue lb_const_undef(lbModule *m, Type *type) { +gb_internal lbValue lb_const_undef(lbModule *m, Type *type) { LLVMValueRef v = LLVMGetUndef(lb_type(m, type)); return lbValue{v, type}; } -lbValue lb_const_int(lbModule *m, Type *type, u64 value) { +gb_internal lbValue lb_const_int(lbModule *m, Type *type, u64 value) { lbValue res = {}; res.value = LLVMConstInt(lb_type(m, type), cast(unsigned long long)value, !is_type_unsigned(type)); res.type = type; return res; } -lbValue lb_const_string(lbModule *m, String const &value) { +gb_internal lbValue lb_const_string(lbModule *m, String const &value) { return lb_const_value(m, t_string, exact_value_string(value)); } -lbValue lb_const_bool(lbModule *m, Type *type, bool value) { +gb_internal lbValue lb_const_bool(lbModule *m, Type *type, bool value) { lbValue res = {}; res.value = LLVMConstInt(lb_type(m, type), value, false); res.type = type; return res; } -LLVMValueRef lb_const_f16(lbModule *m, f32 f, Type *type=t_f16) { +gb_internal LLVMValueRef lb_const_f16(lbModule *m, f32 f, Type *type=t_f16) { GB_ASSERT(type_size_of(type) == 2); u16 u = f32_to_f16(f); @@ -229,7 +229,7 @@ LLVMValueRef lb_const_f16(lbModule *m, f32 f, Type *type=t_f16) { return LLVMConstBitCast(i, lb_type(m, type)); } -LLVMValueRef lb_const_f32(lbModule *m, f32 f, Type *type=t_f32) { +gb_internal LLVMValueRef lb_const_f32(lbModule *m, f32 f, Type *type=t_f32) { GB_ASSERT(type_size_of(type) == 4); u32 u = bit_cast(f); if (is_type_different_to_arch_endianness(type)) { @@ -241,7 +241,7 @@ LLVMValueRef lb_const_f32(lbModule *m, f32 f, Type *type=t_f32) { -bool lb_is_expr_untyped_const(Ast *expr) { +gb_internal bool lb_is_expr_untyped_const(Ast *expr) { auto const &tv = type_and_value_of_expr(expr); if (is_type_untyped(tv.type)) { return tv.value.kind != ExactValue_Invalid; @@ -250,13 +250,13 @@ bool lb_is_expr_untyped_const(Ast *expr) { } -lbValue lb_expr_untyped_const_to_typed(lbModule *m, Ast *expr, Type *t) { +gb_internal lbValue lb_expr_untyped_const_to_typed(lbModule *m, Ast *expr, Type *t) { GB_ASSERT(is_type_typed(t)); auto const &tv = type_and_value_of_expr(expr); return lb_const_value(m, t, tv.value); } -lbValue lb_emit_source_code_location_const(lbProcedure *p, String const &procedure, TokenPos const &pos) { +gb_internal lbValue lb_emit_source_code_location_const(lbProcedure *p, String const &procedure, TokenPos const &pos) { lbModule *m = p->module; LLVMValueRef fields[4] = {}; @@ -271,7 +271,7 @@ lbValue lb_emit_source_code_location_const(lbProcedure *p, String const &procedu return res; } -lbValue lb_emit_source_code_location_const(lbProcedure *p, Ast *node) { +gb_internal lbValue lb_emit_source_code_location_const(lbProcedure *p, Ast *node) { String proc_name = {}; if (p->entity) { proc_name = p->entity->token.string; @@ -284,7 +284,7 @@ lbValue lb_emit_source_code_location_const(lbProcedure *p, Ast *node) { } -lbValue lb_emit_source_code_location_as_global_ptr(lbProcedure *p, String const &procedure, TokenPos const &pos) { +gb_internal lbValue lb_emit_source_code_location_as_global_ptr(lbProcedure *p, String const &procedure, TokenPos const &pos) { lbValue loc = lb_emit_source_code_location_const(p, procedure, pos); lbAddr addr = lb_add_global_generated(p->module, loc.type, loc, nullptr); lb_make_global_private_const(addr); @@ -292,24 +292,24 @@ lbValue lb_emit_source_code_location_as_global_ptr(lbProcedure *p, String const } -lbValue lb_emit_source_code_location_as_global_ptr(lbProcedure *p, Ast *node) { +gb_internal lbValue lb_emit_source_code_location_as_global_ptr(lbProcedure *p, Ast *node) { lbValue loc = lb_emit_source_code_location_const(p, node); lbAddr addr = lb_add_global_generated(p->module, loc.type, loc, nullptr); lb_make_global_private_const(addr); return addr.addr; } -lbValue lb_emit_source_code_location_as_global(lbProcedure *p, String const &procedure, TokenPos const &pos) { +gb_internal lbValue lb_emit_source_code_location_as_global(lbProcedure *p, String const &procedure, TokenPos const &pos) { return lb_emit_load(p, lb_emit_source_code_location_as_global_ptr(p, procedure, pos)); } -lbValue lb_emit_source_code_location_as_global(lbProcedure *p, Ast *node) { +gb_internal lbValue lb_emit_source_code_location_as_global(lbProcedure *p, Ast *node) { return lb_emit_load(p, lb_emit_source_code_location_as_global_ptr(p, node)); } -LLVMValueRef lb_build_constant_array_values(lbModule *m, Type *type, Type *elem_type, isize count, LLVMValueRef *values, bool allow_local) { +gb_internal LLVMValueRef lb_build_constant_array_values(lbModule *m, Type *type, Type *elem_type, isize count, LLVMValueRef *values, bool allow_local) { bool is_local = allow_local && m->curr_procedure != nullptr; bool is_const = true; if (is_local) { @@ -341,7 +341,7 @@ LLVMValueRef lb_build_constant_array_values(lbModule *m, Type *type, Type *elem_ return llvm_const_array(lb_type(m, elem_type), values, cast(unsigned int)count); } -LLVMValueRef lb_big_int_to_llvm(lbModule *m, Type *original_type, BigInt const *a) { +gb_internal LLVMValueRef lb_big_int_to_llvm(lbModule *m, Type *original_type, BigInt const *a) { if (big_int_is_zero(a)) { return LLVMConstNull(lb_type(m, original_type)); } @@ -387,7 +387,7 @@ LLVMValueRef lb_big_int_to_llvm(lbModule *m, Type *original_type, BigInt const * } -lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_local) { +gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_local) { LLVMContextRef ctx = m->ctx; type = default_type(type); diff --git a/src/llvm_backend_debug.cpp b/src/llvm_backend_debug.cpp index 65cefcd39..849416579 100644 --- a/src/llvm_backend_debug.cpp +++ b/src/llvm_backend_debug.cpp @@ -1,4 +1,4 @@ -LLVMMetadataRef lb_get_llvm_metadata(lbModule *m, void *key) { +gb_internal LLVMMetadataRef lb_get_llvm_metadata(lbModule *m, void *key) { if (key == nullptr) { return nullptr; } @@ -8,20 +8,20 @@ LLVMMetadataRef lb_get_llvm_metadata(lbModule *m, void *key) { } return nullptr; } -void lb_set_llvm_metadata(lbModule *m, void *key, LLVMMetadataRef value) { +gb_internal void lb_set_llvm_metadata(lbModule *m, void *key, LLVMMetadataRef value) { if (key != nullptr) { map_set(&m->debug_values, key, value); } } -LLVMMetadataRef lb_get_llvm_file_metadata_from_node(lbModule *m, Ast *node) { +gb_internal LLVMMetadataRef lb_get_llvm_file_metadata_from_node(lbModule *m, Ast *node) { if (node == nullptr) { return nullptr; } return lb_get_llvm_metadata(m, node->file()); } -LLVMMetadataRef lb_get_current_debug_scope(lbProcedure *p) { +gb_internal LLVMMetadataRef lb_get_current_debug_scope(lbProcedure *p) { GB_ASSERT_MSG(p->debug_info != nullptr, "missing debug information for %.*s", LIT(p->name)); for (isize i = p->scope_stack.count-1; i >= 0; i--) { @@ -34,21 +34,21 @@ LLVMMetadataRef lb_get_current_debug_scope(lbProcedure *p) { return p->debug_info; } -LLVMMetadataRef lb_debug_location_from_token_pos(lbProcedure *p, TokenPos pos) { +gb_internal LLVMMetadataRef lb_debug_location_from_token_pos(lbProcedure *p, TokenPos pos) { LLVMMetadataRef scope = lb_get_current_debug_scope(p); GB_ASSERT_MSG(scope != nullptr, "%.*s", LIT(p->name)); return LLVMDIBuilderCreateDebugLocation(p->module->ctx, cast(unsigned)pos.line, cast(unsigned)pos.column, scope, nullptr); } -LLVMMetadataRef lb_debug_location_from_ast(lbProcedure *p, Ast *node) { +gb_internal LLVMMetadataRef lb_debug_location_from_ast(lbProcedure *p, Ast *node) { GB_ASSERT(node != nullptr); return lb_debug_location_from_token_pos(p, ast_token(node).pos); } -LLVMMetadataRef lb_debug_end_location_from_ast(lbProcedure *p, Ast *node) { +gb_internal LLVMMetadataRef lb_debug_end_location_from_ast(lbProcedure *p, Ast *node) { GB_ASSERT(node != nullptr); return lb_debug_location_from_token_pos(p, ast_end_token(node).pos); } -LLVMMetadataRef lb_debug_type_internal_proc(lbModule *m, Type *type) { +gb_internal LLVMMetadataRef lb_debug_type_internal_proc(lbModule *m, Type *type) { i64 size = type_size_of(type); // Check size gb_unused(size); @@ -93,7 +93,7 @@ LLVMMetadataRef lb_debug_type_internal_proc(lbModule *m, Type *type) { return LLVMDIBuilderCreateSubroutineType(m->debug_builder, file, parameters, parameter_count, flags); } -LLVMMetadataRef lb_debug_struct_field(lbModule *m, String const &name, Type *type, u64 offset_in_bits) { +gb_internal LLVMMetadataRef lb_debug_struct_field(lbModule *m, String const &name, Type *type, u64 offset_in_bits) { unsigned field_line = 1; LLVMDIFlags field_flags = LLVMDIFlagZero; @@ -107,7 +107,7 @@ LLVMMetadataRef lb_debug_struct_field(lbModule *m, String const &name, Type *typ field_flags, lb_debug_type(m, type) ); } -LLVMMetadataRef lb_debug_basic_struct(lbModule *m, String const &name, u64 size_in_bits, u32 align_in_bits, LLVMMetadataRef *elements, unsigned element_count) { +gb_internal LLVMMetadataRef lb_debug_basic_struct(lbModule *m, String const &name, u64 size_in_bits, u32 align_in_bits, LLVMMetadataRef *elements, unsigned element_count) { AstPackage *pkg = m->info->runtime_package; GB_ASSERT(pkg->files.count != 0); LLVMMetadataRef file = lb_get_llvm_metadata(m, pkg->files[0]); @@ -117,7 +117,7 @@ LLVMMetadataRef lb_debug_basic_struct(lbModule *m, String const &name, u64 size_ } -LLVMMetadataRef lb_debug_type_basic_type(lbModule *m, String const &name, u64 size_in_bits, LLVMDWARFTypeEncoding encoding, LLVMDIFlags flags = LLVMDIFlagZero) { +gb_internal LLVMMetadataRef lb_debug_type_basic_type(lbModule *m, String const &name, u64 size_in_bits, LLVMDWARFTypeEncoding encoding, LLVMDIFlags flags = LLVMDIFlagZero) { LLVMMetadataRef basic_type = LLVMDIBuilderCreateBasicType(m->debug_builder, cast(char const *)name.text, name.len, size_in_bits, encoding, flags); #if 1 LLVMMetadataRef final_decl = LLVMDIBuilderCreateTypedef(m->debug_builder, basic_type, cast(char const *)name.text, name.len, nullptr, 0, nullptr, cast(u32)size_in_bits); @@ -127,7 +127,7 @@ LLVMMetadataRef lb_debug_type_basic_type(lbModule *m, String const &name, u64 si #endif } -LLVMMetadataRef lb_debug_type_internal(lbModule *m, Type *type) { +gb_internal LLVMMetadataRef lb_debug_type_internal(lbModule *m, Type *type) { i64 size = type_size_of(type); // Check size gb_unused(size); @@ -474,7 +474,7 @@ LLVMMetadataRef lb_debug_type_internal(lbModule *m, Type *type) { return nullptr; } -LLVMMetadataRef lb_get_base_scope_metadata(lbModule *m, Scope *scope) { +gb_internal LLVMMetadataRef lb_get_base_scope_metadata(lbModule *m, Scope *scope) { LLVMMetadataRef found = nullptr; for (;;) { if (scope == nullptr) { @@ -496,7 +496,7 @@ LLVMMetadataRef lb_get_base_scope_metadata(lbModule *m, Scope *scope) { } } -LLVMMetadataRef lb_debug_type(lbModule *m, Type *type) { +gb_internal LLVMMetadataRef lb_debug_type(lbModule *m, Type *type) { GB_ASSERT(type != nullptr); LLVMMetadataRef found = lb_get_llvm_metadata(m, type); if (found != nullptr) { @@ -615,7 +615,7 @@ LLVMMetadataRef lb_debug_type(lbModule *m, Type *type) { return dt; } -void lb_debug_complete_types(lbModule *m) { +gb_internal void lb_debug_complete_types(lbModule *m) { /* unsigned const word_size = cast(unsigned)build_context.word_size; */ unsigned const word_bits = cast(unsigned)(8*build_context.word_size); @@ -962,7 +962,7 @@ void lb_debug_complete_types(lbModule *m) { -void lb_add_debug_local_variable(lbProcedure *p, LLVMValueRef ptr, Type *type, Token const &token) { +gb_internal void lb_add_debug_local_variable(lbProcedure *p, LLVMValueRef ptr, Type *type, Token const &token) { if (p->debug_info == nullptr) { return; } @@ -1024,7 +1024,7 @@ void lb_add_debug_local_variable(lbProcedure *p, LLVMValueRef ptr, Type *type, T LLVMDIBuilderInsertDeclareAtEnd(m->debug_builder, storage, var_info, llvm_expr, llvm_debug_loc, block); } -void lb_add_debug_param_variable(lbProcedure *p, LLVMValueRef ptr, Type *type, Token const &token, unsigned arg_number, lbBlock *block, lbArgKind arg_kind) { +gb_internal void lb_add_debug_param_variable(lbProcedure *p, LLVMValueRef ptr, Type *type, Token const &token, unsigned arg_number, lbBlock *block, lbArgKind arg_kind) { if (p->debug_info == nullptr) { return; } @@ -1097,7 +1097,7 @@ void lb_add_debug_param_variable(lbProcedure *p, LLVMValueRef ptr, Type *type, T } -void lb_add_debug_context_variable(lbProcedure *p, lbAddr const &ctx) { +gb_internal void lb_add_debug_context_variable(lbProcedure *p, lbAddr const &ctx) { if (!p->debug_info || !p->body) { return; } @@ -1125,7 +1125,7 @@ void lb_add_debug_context_variable(lbProcedure *p, lbAddr const &ctx) { } -String debug_info_mangle_constant_name(Entity *e, bool *did_allocate_) { +gb_internal String debug_info_mangle_constant_name(Entity *e, bool *did_allocate_) { String name = e->token.string; if (e->pkg && e->pkg->name.len > 0) { // NOTE(bill): C++ NONSENSE FOR DEBUG SHITE! @@ -1135,7 +1135,7 @@ String debug_info_mangle_constant_name(Entity *e, bool *did_allocate_) { return name; } -void add_debug_info_global_variable_expr(lbModule *m, String const &name, LLVMMetadataRef dtype, LLVMMetadataRef expr) { +gb_internal void add_debug_info_global_variable_expr(lbModule *m, String const &name, LLVMMetadataRef dtype, LLVMMetadataRef expr) { LLVMMetadataRef scope = nullptr; LLVMMetadataRef file = nullptr; unsigned line = 0; @@ -1151,7 +1151,7 @@ void add_debug_info_global_variable_expr(lbModule *m, String const &name, LLVMMe expr, decl, 8/*AlignInBits*/); } -void add_debug_info_for_global_constant_internal_i64(lbModule *m, Entity *e, LLVMMetadataRef dtype, i64 v) { +gb_internal void add_debug_info_for_global_constant_internal_i64(lbModule *m, Entity *e, LLVMMetadataRef dtype, i64 v) { LLVMMetadataRef expr = LLVMDIBuilderCreateConstantValueExpression(m->debug_builder, v); bool did_allocate = false; @@ -1167,7 +1167,7 @@ void add_debug_info_for_global_constant_internal_i64(lbModule *m, Entity *e, LLV } } -void add_debug_info_for_global_constant_from_entity(lbGenerator *gen, Entity *e) { +gb_internal void add_debug_info_for_global_constant_from_entity(lbGenerator *gen, Entity *e) { if (e == nullptr || e->kind != Entity_Constant) { return; } diff --git a/src/llvm_backend_expr.cpp b/src/llvm_backend_expr.cpp index 2c1bfecd6..d574caf4c 100644 --- a/src/llvm_backend_expr.cpp +++ b/src/llvm_backend_expr.cpp @@ -1,6 +1,6 @@ -lbValue lb_emit_arith_matrix(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type, bool component_wise); +gb_internal lbValue lb_emit_arith_matrix(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type, bool component_wise); -lbValue lb_emit_logical_binary_expr(lbProcedure *p, TokenKind op, Ast *left, Ast *right, Type *type) { +gb_internal lbValue lb_emit_logical_binary_expr(lbProcedure *p, TokenKind op, Ast *left, Ast *right, Type *type) { lbModule *m = p->module; lbBlock *rhs = lb_create_block(p, "logical.cmp.rhs"); @@ -113,7 +113,7 @@ lbValue lb_emit_logical_binary_expr(lbProcedure *p, TokenKind op, Ast *left, Ast } -lbValue lb_emit_unary_arith(lbProcedure *p, TokenKind op, lbValue x, Type *type) { +gb_internal lbValue lb_emit_unary_arith(lbProcedure *p, TokenKind op, lbValue x, Type *type) { switch (op) { case Token_Add: return x; @@ -283,7 +283,7 @@ lbValue lb_emit_unary_arith(lbProcedure *p, TokenKind op, lbValue x, Type *type) return res; } -bool lb_try_direct_vector_arith(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type, lbValue *res_) { +gb_internal bool lb_try_direct_vector_arith(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type, lbValue *res_) { GB_ASSERT(is_type_array_like(type)); Type *elem_type = base_array_type(type); @@ -418,7 +418,7 @@ bool lb_try_direct_vector_arith(lbProcedure *p, TokenKind op, lbValue lhs, lbVal } -lbValue lb_emit_arith_array(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type) { +gb_internal lbValue lb_emit_arith_array(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type) { GB_ASSERT(is_type_array_like(lhs.type) || is_type_array_like(rhs.type)); lhs = lb_emit_conv(p, lhs, type); @@ -490,7 +490,7 @@ lbValue lb_emit_arith_array(lbProcedure *p, TokenKind op, lbValue lhs, lbValue r } } -bool lb_is_matrix_simdable(Type *t) { +gb_internal bool lb_is_matrix_simdable(Type *t) { Type *mt = base_type(t); GB_ASSERT(mt->kind == Type_Matrix); @@ -534,7 +534,7 @@ bool lb_is_matrix_simdable(Type *t) { } -LLVMValueRef lb_matrix_to_vector(lbProcedure *p, lbValue matrix) { +gb_internal LLVMValueRef lb_matrix_to_vector(lbProcedure *p, lbValue matrix) { Type *mt = base_type(matrix.type); GB_ASSERT(mt->kind == Type_Matrix); LLVMTypeRef elem_type = lb_type(p->module, mt->Matrix.elem); @@ -554,7 +554,7 @@ LLVMValueRef lb_matrix_to_vector(lbProcedure *p, lbValue matrix) { #endif } -LLVMValueRef lb_matrix_trimmed_vector_mask(lbProcedure *p, Type *mt) { +gb_internal LLVMValueRef lb_matrix_trimmed_vector_mask(lbProcedure *p, Type *mt) { mt = base_type(mt); GB_ASSERT(mt->kind == Type_Matrix); @@ -574,7 +574,7 @@ LLVMValueRef lb_matrix_trimmed_vector_mask(lbProcedure *p, Type *mt) { return mask; } -LLVMValueRef lb_matrix_to_trimmed_vector(lbProcedure *p, lbValue m) { +gb_internal LLVMValueRef lb_matrix_to_trimmed_vector(lbProcedure *p, lbValue m) { LLVMValueRef vector = lb_matrix_to_vector(p, m); Type *mt = base_type(m.type); @@ -592,7 +592,7 @@ LLVMValueRef lb_matrix_to_trimmed_vector(lbProcedure *p, lbValue m) { } -lbValue lb_emit_matrix_tranpose(lbProcedure *p, lbValue m, Type *type) { +gb_internal lbValue lb_emit_matrix_tranpose(lbProcedure *p, lbValue m, Type *type) { if (is_type_array(m.type)) { i32 rank = type_math_rank(m.type); if (rank == 2) { @@ -669,7 +669,7 @@ lbValue lb_emit_matrix_tranpose(lbProcedure *p, lbValue m, Type *type) { return lb_addr_load(p, res); } -lbValue lb_matrix_cast_vector_to_type(lbProcedure *p, LLVMValueRef vector, Type *type) { +gb_internal lbValue lb_matrix_cast_vector_to_type(lbProcedure *p, LLVMValueRef vector, Type *type) { lbAddr res = lb_add_local_generated(p, type, true); LLVMValueRef res_ptr = res.addr.value; unsigned alignment = cast(unsigned)gb_max(type_align_of(type), lb_alignof(LLVMTypeOf(vector))); @@ -681,7 +681,7 @@ lbValue lb_matrix_cast_vector_to_type(lbProcedure *p, LLVMValueRef vector, Type return lb_addr_load(p, res); } -lbValue lb_emit_matrix_flatten(lbProcedure *p, lbValue m, Type *type) { +gb_internal lbValue lb_emit_matrix_flatten(lbProcedure *p, lbValue m, Type *type) { if (is_type_array(m.type)) { // no-op m.type = type; @@ -710,7 +710,7 @@ lbValue lb_emit_matrix_flatten(lbProcedure *p, lbValue m, Type *type) { } -lbValue lb_emit_outer_product(lbProcedure *p, lbValue a, lbValue b, Type *type) { +gb_internal lbValue lb_emit_outer_product(lbProcedure *p, lbValue a, lbValue b, Type *type) { Type *mt = base_type(type); Type *at = base_type(a.type); Type *bt = base_type(b.type); @@ -741,7 +741,7 @@ lbValue lb_emit_outer_product(lbProcedure *p, lbValue a, lbValue b, Type *type) } -lbValue lb_emit_matrix_mul(lbProcedure *p, lbValue lhs, lbValue rhs, Type *type) { +gb_internal lbValue lb_emit_matrix_mul(lbProcedure *p, lbValue lhs, lbValue rhs, Type *type) { // TODO(bill): Handle edge case for f16 types on x86(-64) platforms Type *xt = base_type(lhs.type); @@ -828,7 +828,7 @@ lbValue lb_emit_matrix_mul(lbProcedure *p, lbValue lhs, lbValue rhs, Type *type) } } -lbValue lb_emit_matrix_mul_vector(lbProcedure *p, lbValue lhs, lbValue rhs, Type *type) { +gb_internal lbValue lb_emit_matrix_mul_vector(lbProcedure *p, lbValue lhs, lbValue rhs, Type *type) { // TODO(bill): Handle edge case for f16 types on x86(-64) platforms Type *mt = base_type(lhs.type); @@ -897,7 +897,7 @@ lbValue lb_emit_matrix_mul_vector(lbProcedure *p, lbValue lhs, lbValue rhs, Type return lb_addr_load(p, res); } -lbValue lb_emit_vector_mul_matrix(lbProcedure *p, lbValue lhs, lbValue rhs, Type *type) { +gb_internal lbValue lb_emit_vector_mul_matrix(lbProcedure *p, lbValue lhs, lbValue rhs, Type *type) { // TODO(bill): Handle edge case for f16 types on x86(-64) platforms Type *mt = base_type(rhs.type); @@ -984,7 +984,7 @@ lbValue lb_emit_vector_mul_matrix(lbProcedure *p, lbValue lhs, lbValue rhs, Type -lbValue lb_emit_arith_matrix(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type, bool component_wise) { +gb_internal lbValue lb_emit_arith_matrix(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type, bool component_wise) { GB_ASSERT(is_type_matrix(lhs.type) || is_type_matrix(rhs.type)); if (op == Token_Mul && !component_wise) { @@ -1056,7 +1056,7 @@ lbValue lb_emit_arith_matrix(lbProcedure *p, TokenKind op, lbValue lhs, lbValue -lbValue lb_emit_arith(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type) { +gb_internal lbValue lb_emit_arith(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type) { if (is_type_array_like(lhs.type) || is_type_array_like(rhs.type)) { return lb_emit_arith_array(p, op, lhs, rhs, type); } else if (is_type_matrix(lhs.type) || is_type_matrix(rhs.type)) { @@ -1325,7 +1325,7 @@ handle_op: return {}; } -lbValue lb_build_binary_expr(lbProcedure *p, Ast *expr) { +gb_internal lbValue lb_build_binary_expr(lbProcedure *p, Ast *expr) { ast_node(be, BinaryExpr, expr); TypeAndValue tv = type_and_value_of_expr(expr); @@ -1472,7 +1472,7 @@ lbValue lb_build_binary_expr(lbProcedure *p, Ast *expr) { return {}; } -lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t) { +gb_internal lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t) { lbModule *m = p->module; t = reduce_tuple_to_single_type(t); @@ -2202,7 +2202,7 @@ lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t) { return {}; } -lbValue lb_compare_records(lbProcedure *p, TokenKind op_kind, lbValue left, lbValue right, Type *type) { +gb_internal lbValue lb_compare_records(lbProcedure *p, TokenKind op_kind, lbValue left, lbValue right, Type *type) { GB_ASSERT((is_type_struct(type) || is_type_union(type)) && is_type_comparable(type)); lbValue left_ptr = lb_address_from_load_or_generate_local(p, left); lbValue right_ptr = lb_address_from_load_or_generate_local(p, right); @@ -2230,7 +2230,7 @@ lbValue lb_compare_records(lbProcedure *p, TokenKind op_kind, lbValue left, lbVa -lbValue lb_emit_comp(lbProcedure *p, TokenKind op_kind, lbValue left, lbValue right) { +gb_internal lbValue lb_emit_comp(lbProcedure *p, TokenKind op_kind, lbValue left, lbValue right) { Type *a = core_type(left.type); Type *b = core_type(right.type); @@ -2642,7 +2642,7 @@ lbValue lb_emit_comp(lbProcedure *p, TokenKind op_kind, lbValue left, lbValue ri -lbValue lb_emit_comp_against_nil(lbProcedure *p, TokenKind op_kind, lbValue x) { +gb_internal lbValue lb_emit_comp_against_nil(lbProcedure *p, TokenKind op_kind, lbValue x) { lbValue res = {}; res.type = t_llvm_bool; Type *t = x.type; @@ -2803,7 +2803,7 @@ lbValue lb_emit_comp_against_nil(lbProcedure *p, TokenKind op_kind, lbValue x) { return {}; } -lbValue lb_make_soa_pointer(lbProcedure *p, Type *type, lbValue const &addr, lbValue const &index) { +gb_internal lbValue lb_make_soa_pointer(lbProcedure *p, Type *type, lbValue const &addr, lbValue const &index) { lbAddr v = lb_add_local_generated(p, type, false); lbValue ptr = lb_emit_struct_ep(p, v.addr, 0); lbValue idx = lb_emit_struct_ep(p, v.addr, 1); @@ -2813,7 +2813,7 @@ lbValue lb_make_soa_pointer(lbProcedure *p, Type *type, lbValue const &addr, lbV return lb_addr_load(p, v); } -lbValue lb_build_unary_and(lbProcedure *p, Ast *expr) { +gb_internal lbValue lb_build_unary_and(lbProcedure *p, Ast *expr) { ast_node(ue, UnaryExpr, expr); auto tv = type_and_value_of_expr(expr); @@ -3023,8 +3023,8 @@ lbValue lb_build_unary_and(lbProcedure *p, Ast *expr) { return lb_build_addr_ptr(p, ue->expr); } -lbValue lb_build_expr_internal(lbProcedure *p, Ast *expr); -lbValue lb_build_expr(lbProcedure *p, Ast *expr) { +gb_internal lbValue lb_build_expr_internal(lbProcedure *p, Ast *expr); +gb_internal lbValue lb_build_expr(lbProcedure *p, Ast *expr) { u16 prev_state_flags = p->state_flags; defer (p->state_flags = prev_state_flags); @@ -3080,7 +3080,7 @@ lbValue lb_build_expr(lbProcedure *p, Ast *expr) { return res; } -lbValue lb_build_expr_internal(lbProcedure *p, Ast *expr) { +gb_internal lbValue lb_build_expr_internal(lbProcedure *p, Ast *expr) { lbModule *m = p->module; expr = unparen_expr(expr); @@ -3355,10 +3355,10 @@ lbValue lb_build_expr_internal(lbProcedure *p, Ast *expr) { return {}; } -lbAddr lb_get_soa_variable_addr(lbProcedure *p, Entity *e) { +gb_internal lbAddr lb_get_soa_variable_addr(lbProcedure *p, Entity *e) { return map_must_get(&p->module->soa_values, e); } -lbValue lb_get_using_variable(lbProcedure *p, Entity *e) { +gb_internal lbValue lb_get_using_variable(lbProcedure *p, Entity *e) { GB_ASSERT(e->kind == Entity_Variable && e->flags & EntityFlag_Using); String name = e->token.string; Entity *parent = e->using_parent; @@ -3393,7 +3393,7 @@ lbValue lb_get_using_variable(lbProcedure *p, Entity *e) { -lbAddr lb_build_addr_from_entity(lbProcedure *p, Entity *e, Ast *expr) { +gb_internal lbAddr lb_build_addr_from_entity(lbProcedure *p, Entity *e, Ast *expr) { GB_ASSERT(e != nullptr); if (e->kind == Entity_Constant) { Type *t = default_type(type_of_expr(expr)); @@ -3427,7 +3427,7 @@ lbAddr lb_build_addr_from_entity(lbProcedure *p, Entity *e, Ast *expr) { return lb_addr(v); } -lbAddr lb_build_array_swizzle_addr(lbProcedure *p, AstCallExpr *ce, TypeAndValue const &tv) { +gb_internal lbAddr lb_build_array_swizzle_addr(lbProcedure *p, AstCallExpr *ce, TypeAndValue const &tv) { isize index_count = ce->args.count-1; lbAddr addr = lb_build_addr(p, ce->args[0]); if (index_count == 0) { @@ -3463,8 +3463,8 @@ lbAddr lb_build_array_swizzle_addr(lbProcedure *p, AstCallExpr *ce, TypeAndValue } -lbAddr lb_build_addr_internal(lbProcedure *p, Ast *expr); -lbAddr lb_build_addr(lbProcedure *p, Ast *expr) { +gb_internal lbAddr lb_build_addr_internal(lbProcedure *p, Ast *expr); +gb_internal lbAddr lb_build_addr(lbProcedure *p, Ast *expr) { expr = unparen_expr(expr); // IMPORTANT NOTE(bill): @@ -3489,7 +3489,7 @@ lbAddr lb_build_addr(lbProcedure *p, Ast *expr) { return addr; } -void lb_build_addr_compound_lit_populate(lbProcedure *p, Slice const &elems, Array *temp_data, Type *compound_type) { +gb_internal void lb_build_addr_compound_lit_populate(lbProcedure *p, Slice const &elems, Array *temp_data, Type *compound_type) { Type *bt = base_type(compound_type); Type *et = nullptr; switch (bt->kind) { @@ -3595,7 +3595,7 @@ void lb_build_addr_compound_lit_populate(lbProcedure *p, Slice const &ele } } } -void lb_build_addr_compound_lit_assign_array(lbProcedure *p, Array const &temp_data) { +gb_internal void lb_build_addr_compound_lit_assign_array(lbProcedure *p, Array const &temp_data) { for_array(i, temp_data) { auto td = temp_data[i]; if (td.value.value != nullptr) { @@ -3614,7 +3614,7 @@ void lb_build_addr_compound_lit_assign_array(lbProcedure *p, Arrayexpr)); @@ -3833,7 +3833,7 @@ lbAddr lb_build_addr_index_expr(lbProcedure *p, Ast *expr) { } -lbAddr lb_build_addr_slice_expr(lbProcedure *p, Ast *expr) { +gb_internal lbAddr lb_build_addr_slice_expr(lbProcedure *p, Ast *expr) { ast_node(se, SliceExpr, expr); lbValue low = lb_const_int(p->module, t_int, 0); @@ -4031,7 +4031,7 @@ lbAddr lb_build_addr_slice_expr(lbProcedure *p, Ast *expr) { } -lbAddr lb_build_addr_compound_lit(lbProcedure *p, Ast *expr) { +gb_internal lbAddr lb_build_addr_compound_lit(lbProcedure *p, Ast *expr) { ast_node(cl, CompoundLit, expr); Type *type = type_of_expr(expr); @@ -4383,7 +4383,7 @@ lbAddr lb_build_addr_compound_lit(lbProcedure *p, Ast *expr) { } -lbAddr lb_build_addr_internal(lbProcedure *p, Ast *expr) { +gb_internal lbAddr lb_build_addr_internal(lbProcedure *p, Ast *expr) { switch (expr->kind) { case_ast_node(i, Implicit, expr); lbAddr v = {}; diff --git a/src/llvm_backend_general.cpp b/src/llvm_backend_general.cpp index 3ca98845a..f30038da8 100644 --- a/src/llvm_backend_general.cpp +++ b/src/llvm_backend_general.cpp @@ -1,4 +1,4 @@ -void lb_add_debug_local_variable(lbProcedure *p, LLVMValueRef ptr, Type *type, Token const &token); +gb_internal void lb_add_debug_local_variable(lbProcedure *p, LLVMValueRef ptr, Type *type, Token const &token); gb_global Entity *lb_global_type_info_data_entity = {}; gb_global lbAddr lb_global_type_info_member_types = {}; @@ -15,7 +15,7 @@ gb_global isize lb_global_type_info_member_usings_index = 0; gb_global isize lb_global_type_info_member_tags_index = 0; -void lb_init_module(lbModule *m, Checker *c) { +gb_internal void lb_init_module(lbModule *m, Checker *c) { m->info = &c->info; gbString module_name = gb_string_make(heap_allocator(), "odin_package"); @@ -82,7 +82,7 @@ void lb_init_module(lbModule *m, Checker *c) { } -bool lb_init_generator(lbGenerator *gen, Checker *c) { +gb_internal bool lb_init_generator(lbGenerator *gen, Checker *c) { if (global_error_collector.count != 0) { return false; } @@ -164,7 +164,7 @@ bool lb_init_generator(lbGenerator *gen, Checker *c) { -lbValue lb_global_type_info_data_ptr(lbModule *m) { +gb_internal lbValue lb_global_type_info_data_ptr(lbModule *m) { lbValue v = lb_find_value_from_entity(m, lb_global_type_info_data_entity); return v; } @@ -187,7 +187,7 @@ struct lbCompoundLitElemTempData { }; -lbLoopData lb_loop_start(lbProcedure *p, isize count, Type *index_type=t_i32) { +gb_internal lbLoopData lb_loop_start(lbProcedure *p, isize count, Type *index_type=t_i32) { lbLoopData data = {}; lbValue max = lb_const_int(p->module, t_int, count); @@ -210,7 +210,7 @@ lbLoopData lb_loop_start(lbProcedure *p, isize count, Type *index_type=t_i32) { return data; } -void lb_loop_end(lbProcedure *p, lbLoopData const &data) { +gb_internal void lb_loop_end(lbProcedure *p, lbLoopData const &data) { if (data.idx_addr.addr.value != nullptr) { lb_emit_increment(p, data.idx_addr.addr); lb_emit_jump(p, data.loop); @@ -219,19 +219,19 @@ void lb_loop_end(lbProcedure *p, lbLoopData const &data) { } -void lb_make_global_private_const(LLVMValueRef global_data) { +gb_internal void lb_make_global_private_const(LLVMValueRef global_data) { LLVMSetLinkage(global_data, LLVMPrivateLinkage); LLVMSetUnnamedAddress(global_data, LLVMGlobalUnnamedAddr); LLVMSetGlobalConstant(global_data, true); } -void lb_make_global_private_const(lbAddr const &addr) { +gb_internal void lb_make_global_private_const(lbAddr const &addr) { lb_make_global_private_const(addr.addr.value); } // This emits a GEP at 0, index -lbValue lb_emit_epi(lbProcedure *p, lbValue const &value, isize index) { +gb_internal lbValue lb_emit_epi(lbProcedure *p, lbValue const &value, isize index) { GB_ASSERT(is_type_pointer(value.type)); Type *type = type_deref(value.type); @@ -251,7 +251,7 @@ lbValue lb_emit_epi(lbProcedure *p, lbValue const &value, isize index) { return res; } // This emits a GEP at 0, index -lbValue lb_emit_epi(lbModule *m, lbValue const &value, isize index) { +gb_internal lbValue lb_emit_epi(lbModule *m, lbValue const &value, isize index) { GB_ASSERT(is_type_pointer(value.type)); GB_ASSERT(LLVMIsConstant(value.value)); Type *type = type_deref(value.type); @@ -269,17 +269,17 @@ lbValue lb_emit_epi(lbModule *m, lbValue const &value, isize index) { -LLVMValueRef llvm_zero(lbModule *m) { +gb_internal LLVMValueRef llvm_zero(lbModule *m) { return LLVMConstInt(lb_type(m, t_int), 0, false); } -LLVMValueRef llvm_zero32(lbModule *m) { +gb_internal LLVMValueRef llvm_zero32(lbModule *m) { return LLVMConstInt(lb_type(m, t_i32), 0, false); } -LLVMValueRef llvm_one(lbModule *m) { +gb_internal LLVMValueRef llvm_one(lbModule *m) { return LLVMConstInt(lb_type(m, t_i32), 1, false); } -LLVMValueRef llvm_alloca(lbProcedure *p, LLVMTypeRef llvm_type, isize alignment, char const *name) { +gb_internal LLVMValueRef llvm_alloca(lbProcedure *p, LLVMTypeRef llvm_type, isize alignment, char const *name) { LLVMPositionBuilderAtEnd(p->builder, p->decl_block->block); LLVMValueRef val = LLVMBuildAlloca(p->builder, llvm_type, name); @@ -290,20 +290,20 @@ LLVMValueRef llvm_alloca(lbProcedure *p, LLVMTypeRef llvm_type, isize alignment, return val; } -lbValue lb_zero(lbModule *m, Type *t) { +gb_internal lbValue lb_zero(lbModule *m, Type *t) { lbValue v = {}; v.value = LLVMConstInt(lb_type(m, t), 0, false); v.type = t; return v; } -LLVMValueRef llvm_cstring(lbModule *m, String const &str) { +gb_internal LLVMValueRef llvm_cstring(lbModule *m, String const &str) { lbValue v = lb_find_or_add_entity_string(m, str); unsigned indices[1] = {0}; return LLVMConstExtractValue(v.value, indices, gb_count_of(indices)); } -bool lb_is_instr_terminating(LLVMValueRef instr) { +gb_internal bool lb_is_instr_terminating(LLVMValueRef instr) { if (instr != nullptr) { LLVMOpcode op = LLVMGetInstructionOpcode(instr); switch (op) { @@ -322,7 +322,7 @@ bool lb_is_instr_terminating(LLVMValueRef instr) { -lbModule *lb_pkg_module(lbGenerator *gen, AstPackage *pkg) { +gb_internal lbModule *lb_pkg_module(lbGenerator *gen, AstPackage *pkg) { auto *found = map_get(&gen->modules, pkg); if (found) { return *found; @@ -331,7 +331,7 @@ lbModule *lb_pkg_module(lbGenerator *gen, AstPackage *pkg) { } -lbAddr lb_addr(lbValue addr) { +gb_internal lbAddr lb_addr(lbValue addr) { lbAddr v = {lbAddr_Default, addr}; if (addr.type != nullptr && is_type_relative_pointer(type_deref(addr.type))) { GB_ASSERT(is_type_pointer(addr.type)); @@ -344,7 +344,7 @@ lbAddr lb_addr(lbValue addr) { } -lbAddr lb_addr_map(lbValue addr, lbValue map_key, Type *map_type, Type *map_result) { +gb_internal lbAddr lb_addr_map(lbValue addr, lbValue map_key, Type *map_type, Type *map_result) { GB_ASSERT(is_type_pointer(addr.type)); Type *mt = type_deref(addr.type); GB_ASSERT(is_type_map(mt)); @@ -357,14 +357,14 @@ lbAddr lb_addr_map(lbValue addr, lbValue map_key, Type *map_type, Type *map_resu } -lbAddr lb_addr_soa_variable(lbValue addr, lbValue index, Ast *index_expr) { +gb_internal lbAddr lb_addr_soa_variable(lbValue addr, lbValue index, Ast *index_expr) { lbAddr v = {lbAddr_SoaVariable, addr}; v.soa.index = index; v.soa.index_expr = index_expr; return v; } -lbAddr lb_addr_swizzle(lbValue addr, Type *array_type, u8 swizzle_count, u8 swizzle_indices[4]) { +gb_internal lbAddr lb_addr_swizzle(lbValue addr, Type *array_type, u8 swizzle_count, u8 swizzle_indices[4]) { GB_ASSERT(is_type_array(array_type)); GB_ASSERT(1 < swizzle_count && swizzle_count <= 4); lbAddr v = {lbAddr_Swizzle, addr}; @@ -374,7 +374,7 @@ lbAddr lb_addr_swizzle(lbValue addr, Type *array_type, u8 swizzle_count, u8 swiz return v; } -lbAddr lb_addr_swizzle_large(lbValue addr, Type *array_type, Slice const &swizzle_indices) { +gb_internal lbAddr lb_addr_swizzle_large(lbValue addr, Type *array_type, Slice const &swizzle_indices) { GB_ASSERT_MSG(is_type_array(array_type), "%s", type_to_string(array_type)); lbAddr v = {lbAddr_SwizzleLarge, addr}; v.swizzle_large.type = array_type; @@ -382,7 +382,7 @@ lbAddr lb_addr_swizzle_large(lbValue addr, Type *array_type, Slice const &s return v; } -Type *lb_addr_type(lbAddr const &addr) { +gb_internal Type *lb_addr_type(lbAddr const &addr) { if (addr.addr.value == nullptr) { return nullptr; } @@ -411,7 +411,7 @@ Type *lb_addr_type(lbAddr const &addr) { return type_deref(addr.addr.type); } -lbValue lb_addr_get_ptr(lbProcedure *p, lbAddr const &addr) { +gb_internal lbValue lb_addr_get_ptr(lbProcedure *p, lbAddr const &addr) { if (addr.addr.value == nullptr) { GB_PANIC("Illegal addr -> nullptr"); return {}; @@ -462,12 +462,12 @@ lbValue lb_addr_get_ptr(lbProcedure *p, lbAddr const &addr) { } -lbValue lb_build_addr_ptr(lbProcedure *p, Ast *expr) { +gb_internal lbValue lb_build_addr_ptr(lbProcedure *p, Ast *expr) { lbAddr addr = lb_build_addr(p, expr); return lb_addr_get_ptr(p, addr); } -void lb_emit_bounds_check(lbProcedure *p, Token token, lbValue index, lbValue len) { +gb_internal void lb_emit_bounds_check(lbProcedure *p, Token token, lbValue index, lbValue len) { if (build_context.no_bounds_check) { return; } @@ -492,7 +492,7 @@ void lb_emit_bounds_check(lbProcedure *p, Token token, lbValue index, lbValue le lb_emit_runtime_call(p, "bounds_check_error", args); } -void lb_emit_matrix_bounds_check(lbProcedure *p, Token token, lbValue row_index, lbValue column_index, lbValue row_count, lbValue column_count) { +gb_internal void lb_emit_matrix_bounds_check(lbProcedure *p, Token token, lbValue row_index, lbValue column_index, lbValue row_count, lbValue column_count) { if (build_context.no_bounds_check) { return; } @@ -522,7 +522,7 @@ void lb_emit_matrix_bounds_check(lbProcedure *p, Token token, lbValue row_index, } -void lb_emit_multi_pointer_slice_bounds_check(lbProcedure *p, Token token, lbValue low, lbValue high) { +gb_internal void lb_emit_multi_pointer_slice_bounds_check(lbProcedure *p, Token token, lbValue low, lbValue high) { if (build_context.no_bounds_check) { return; } @@ -547,7 +547,7 @@ void lb_emit_multi_pointer_slice_bounds_check(lbProcedure *p, Token token, lbVal lb_emit_runtime_call(p, "multi_pointer_slice_expr_error", args); } -void lb_emit_slice_bounds_check(lbProcedure *p, Token token, lbValue low, lbValue high, lbValue len, bool lower_value_used) { +gb_internal void lb_emit_slice_bounds_check(lbProcedure *p, Token token, lbValue low, lbValue high, lbValue len, bool lower_value_used) { if (build_context.no_bounds_check) { return; } @@ -585,14 +585,14 @@ void lb_emit_slice_bounds_check(lbProcedure *p, Token token, lbValue low, lbValu } } -unsigned lb_try_get_alignment(LLVMValueRef addr_ptr, unsigned default_alignment) { +gb_internal unsigned lb_try_get_alignment(LLVMValueRef addr_ptr, unsigned default_alignment) { if (LLVMIsAGlobalValue(addr_ptr) || LLVMIsAAllocaInst(addr_ptr) || LLVMIsALoadInst(addr_ptr)) { return LLVMGetAlignment(addr_ptr); } return default_alignment; } -bool lb_try_update_alignment(LLVMValueRef addr_ptr, unsigned alignment) { +gb_internal bool lb_try_update_alignment(LLVMValueRef addr_ptr, unsigned alignment) { if (LLVMIsAGlobalValue(addr_ptr) || LLVMIsAAllocaInst(addr_ptr) || LLVMIsALoadInst(addr_ptr)) { if (LLVMGetAlignment(addr_ptr) < alignment) { if (LLVMIsAAllocaInst(addr_ptr) || LLVMIsAGlobalValue(addr_ptr)) { @@ -604,15 +604,15 @@ bool lb_try_update_alignment(LLVMValueRef addr_ptr, unsigned alignment) { return false; } -bool lb_try_update_alignment(lbValue ptr, unsigned alignment) { +gb_internal bool lb_try_update_alignment(lbValue ptr, unsigned alignment) { return lb_try_update_alignment(ptr.value, alignment); } -bool lb_can_try_to_inline_array_arith(Type *t) { +gb_internal bool lb_can_try_to_inline_array_arith(Type *t) { return type_size_of(t) <= build_context.max_simd_align; } -bool lb_try_vector_cast(lbModule *m, lbValue ptr, LLVMTypeRef *vector_type_) { +gb_internal bool lb_try_vector_cast(lbModule *m, lbValue ptr, LLVMTypeRef *vector_type_) { Type *array_type = base_type(type_deref(ptr.type)); GB_ASSERT(is_type_array_like(array_type)); i64 count = get_array_type_count(array_type); @@ -647,7 +647,7 @@ bool lb_try_vector_cast(lbModule *m, lbValue ptr, LLVMTypeRef *vector_type_) { return false; } -void lb_addr_store(lbProcedure *p, lbAddr addr, lbValue value) { +gb_internal void lb_addr_store(lbProcedure *p, lbAddr addr, lbValue value) { if (addr.addr.value == nullptr) { return; } @@ -874,7 +874,7 @@ void lb_addr_store(lbProcedure *p, lbAddr addr, lbValue value) { lb_emit_store(p, addr.addr, value); } -void lb_const_store(lbValue ptr, lbValue value) { +gb_internal void lb_const_store(lbValue ptr, lbValue value) { GB_ASSERT(lb_is_const(ptr)); GB_ASSERT(lb_is_const(value)); GB_ASSERT(is_type_pointer(ptr.type)); @@ -882,7 +882,7 @@ void lb_const_store(lbValue ptr, lbValue value) { } -bool lb_is_type_proc_recursive(Type *t) { +gb_internal bool lb_is_type_proc_recursive(Type *t) { for (;;) { if (t == nullptr) { return false; @@ -902,7 +902,7 @@ bool lb_is_type_proc_recursive(Type *t) { } } -void lb_emit_store(lbProcedure *p, lbValue ptr, lbValue value) { +gb_internal void lb_emit_store(lbProcedure *p, lbValue ptr, lbValue value) { GB_ASSERT(value.value != nullptr); Type *a = type_deref(ptr.type); @@ -978,11 +978,11 @@ void lb_emit_store(lbProcedure *p, lbValue ptr, lbValue value) { } } -LLVMTypeRef llvm_addr_type(lbModule *module, lbValue addr_val) { +gb_internal LLVMTypeRef llvm_addr_type(lbModule *module, lbValue addr_val) { return lb_type(module, type_deref(addr_val.type)); } -lbValue lb_emit_load(lbProcedure *p, lbValue value) { +gb_internal lbValue lb_emit_load(lbProcedure *p, lbValue value) { GB_ASSERT(value.value != nullptr); if (is_type_multi_pointer(value.type)) { Type *vt = base_type(value.type); @@ -1003,7 +1003,7 @@ lbValue lb_emit_load(lbProcedure *p, lbValue value) { return lbValue{v, t}; } -lbValue lb_addr_load(lbProcedure *p, lbAddr const &addr) { +gb_internal lbValue lb_addr_load(lbProcedure *p, lbAddr const &addr) { GB_ASSERT(addr.addr.value != nullptr); @@ -1243,11 +1243,11 @@ lbValue lb_addr_load(lbProcedure *p, lbAddr const &addr) { return lb_emit_load(p, addr.addr); } -lbValue lb_const_union_tag(lbModule *m, Type *u, Type *v) { +gb_internal lbValue lb_const_union_tag(lbModule *m, Type *u, Type *v) { return lb_const_value(m, union_tag_type(u), exact_value_i64(union_variant_index(u, v))); } -lbValue lb_emit_union_tag_ptr(lbProcedure *p, lbValue u) { +gb_internal lbValue lb_emit_union_tag_ptr(lbProcedure *p, lbValue u) { Type *t = u.type; GB_ASSERT_MSG(is_type_pointer(t) && is_type_union(type_deref(t)), "%s", type_to_string(t)); @@ -1269,14 +1269,14 @@ lbValue lb_emit_union_tag_ptr(lbProcedure *p, lbValue u) { return tag_ptr; } -lbValue lb_emit_union_tag_value(lbProcedure *p, lbValue u) { +gb_internal lbValue lb_emit_union_tag_value(lbProcedure *p, lbValue u) { lbValue ptr = lb_address_from_load_or_generate_local(p, u); lbValue tag_ptr = lb_emit_union_tag_ptr(p, ptr); return lb_emit_load(p, tag_ptr); } -void lb_emit_store_union_variant_tag(lbProcedure *p, lbValue parent, Type *variant_type) { +gb_internal void lb_emit_store_union_variant_tag(lbProcedure *p, lbValue parent, Type *variant_type) { Type *t = type_deref(parent.type); if (is_type_union_maybe_pointer(t) || type_size_of(t) == 0) { @@ -1287,7 +1287,7 @@ void lb_emit_store_union_variant_tag(lbProcedure *p, lbValue parent, Type *varia } } -void lb_emit_store_union_variant(lbProcedure *p, lbValue parent, lbValue variant, Type *variant_type) { +gb_internal void lb_emit_store_union_variant(lbProcedure *p, lbValue parent, lbValue variant, Type *variant_type) { Type *pt = base_type(type_deref(parent.type)); GB_ASSERT(pt->kind == Type_Union); if (pt->Union.kind == UnionType_shared_nil) { @@ -1320,14 +1320,14 @@ void lb_emit_store_union_variant(lbProcedure *p, lbValue parent, lbValue variant } -void lb_clone_struct_type(LLVMTypeRef dst, LLVMTypeRef src) { +gb_internal void lb_clone_struct_type(LLVMTypeRef dst, LLVMTypeRef src) { unsigned field_count = LLVMCountStructElementTypes(src); LLVMTypeRef *fields = gb_alloc_array(temporary_allocator(), LLVMTypeRef, field_count); LLVMGetStructElementTypes(src, fields); LLVMStructSetBody(dst, fields, field_count, LLVMIsPackedStruct(src)); } -LLVMTypeRef lb_alignment_prefix_type_hack(lbModule *m, i64 alignment) { +gb_internal LLVMTypeRef lb_alignment_prefix_type_hack(lbModule *m, i64 alignment) { switch (alignment) { case 1: return LLVMArrayType(lb_type(m, t_u8), 0); @@ -1342,7 +1342,7 @@ LLVMTypeRef lb_alignment_prefix_type_hack(lbModule *m, i64 alignment) { } } -String lb_mangle_name(lbModule *m, Entity *e) { +gb_internal String lb_mangle_name(lbModule *m, Entity *e) { String name = e->token.string; AstPackage *pkg = e->pkg; @@ -1384,7 +1384,7 @@ String lb_mangle_name(lbModule *m, Entity *e) { return mangled_name; } -String lb_set_nested_type_name_ir_mangled_name(Entity *e, lbProcedure *p) { +gb_internal String lb_set_nested_type_name_ir_mangled_name(Entity *e, lbProcedure *p) { // NOTE(bill, 2020-03-08): A polymorphic procedure may take a nested type declaration // and as a result, the declaration does not have time to determine what it should be @@ -1440,7 +1440,7 @@ String lb_set_nested_type_name_ir_mangled_name(Entity *e, lbProcedure *p) { } } -String lb_get_entity_name(lbModule *m, Entity *e, String default_name) { +gb_internal String lb_get_entity_name(lbModule *m, Entity *e, String default_name) { if (e != nullptr && e->kind == Entity_TypeName && e->TypeName.ir_mangled_name.len != 0) { return e->TypeName.ir_mangled_name; } @@ -1488,7 +1488,7 @@ String lb_get_entity_name(lbModule *m, Entity *e, String default_name) { } -LLVMTypeRef lb_type_internal_for_procedures_raw(lbModule *m, Type *type) { +gb_internal LLVMTypeRef lb_type_internal_for_procedures_raw(lbModule *m, Type *type) { Type *original_type = type; type = base_type(original_type); GB_ASSERT(type->kind == Type_Proc); @@ -1607,7 +1607,7 @@ LLVMTypeRef lb_type_internal_for_procedures_raw(lbModule *m, Type *type) { return new_abi_fn_type; } -LLVMTypeRef lb_type_internal(lbModule *m, Type *type) { +gb_internal LLVMTypeRef lb_type_internal(lbModule *m, Type *type) { LLVMContextRef ctx = m->ctx; i64 size = type_size_of(type); // Check size gb_unused(size); @@ -2145,7 +2145,7 @@ LLVMTypeRef lb_type_internal(lbModule *m, Type *type) { return LLVMInt32TypeInContext(ctx); } -LLVMTypeRef lb_type(lbModule *m, Type *type) { +gb_internal LLVMTypeRef lb_type(lbModule *m, Type *type) { type = default_type(type); LLVMTypeRef *found = map_get(&m->types, type); @@ -2164,7 +2164,7 @@ LLVMTypeRef lb_type(lbModule *m, Type *type) { return llvm_type; } -lbFunctionType *lb_get_function_type(lbModule *m, Type *pt) { +gb_internal lbFunctionType *lb_get_function_type(lbModule *m, Type *pt) { lbFunctionType **ft_found = nullptr; ft_found = map_get(&m->function_type_map, pt); if (!ft_found) { @@ -2177,7 +2177,7 @@ lbFunctionType *lb_get_function_type(lbModule *m, Type *pt) { return *ft_found; } -void lb_ensure_abi_function_type(lbModule *m, lbProcedure *p) { +gb_internal void lb_ensure_abi_function_type(lbModule *m, lbProcedure *p) { if (p->abi_function_type != nullptr) { return; } @@ -2192,20 +2192,20 @@ void lb_ensure_abi_function_type(lbModule *m, lbProcedure *p) { GB_ASSERT(p->abi_function_type != nullptr); } -void lb_add_entity(lbModule *m, Entity *e, lbValue val) { +gb_internal void lb_add_entity(lbModule *m, Entity *e, lbValue val) { if (e != nullptr) { map_set(&m->values, e, val); } } -void lb_add_member(lbModule *m, String const &name, lbValue val) { +gb_internal void lb_add_member(lbModule *m, String const &name, lbValue val) { if (name.len > 0) { string_map_set(&m->members, name, val); } } -void lb_add_member(lbModule *m, StringHashKey const &key, lbValue val) { +gb_internal void lb_add_member(lbModule *m, StringHashKey const &key, lbValue val) { string_map_set(&m->members, key, val); } -void lb_add_procedure_value(lbModule *m, lbProcedure *p) { +gb_internal void lb_add_procedure_value(lbModule *m, lbProcedure *p) { if (p->entity != nullptr) { map_set(&m->procedure_values, p->value, p->entity); } @@ -2214,7 +2214,7 @@ void lb_add_procedure_value(lbModule *m, lbProcedure *p) { -LLVMAttributeRef lb_create_enum_attribute_with_type(LLVMContextRef ctx, char const *name, LLVMTypeRef type) { +gb_internal LLVMAttributeRef lb_create_enum_attribute_with_type(LLVMContextRef ctx, char const *name, LLVMTypeRef type) { unsigned kind = 0; String s = make_string_c(name); @@ -2243,7 +2243,7 @@ LLVMAttributeRef lb_create_enum_attribute_with_type(LLVMContextRef ctx, char con #endif } -LLVMAttributeRef lb_create_enum_attribute(LLVMContextRef ctx, char const *name, u64 value) { +gb_internal LLVMAttributeRef lb_create_enum_attribute(LLVMContextRef ctx, char const *name, u64 value) { String s = make_string_c(name); // NOTE(2021-02-25, bill); All this attributes require a type associated with them @@ -2264,23 +2264,23 @@ LLVMAttributeRef lb_create_enum_attribute(LLVMContextRef ctx, char const *name, return LLVMCreateEnumAttribute(ctx, kind, value); } -void lb_add_proc_attribute_at_index(lbProcedure *p, isize index, char const *name, u64 value) { +gb_internal void lb_add_proc_attribute_at_index(lbProcedure *p, isize index, char const *name, u64 value) { LLVMAttributeRef attr = lb_create_enum_attribute(p->module->ctx, name, value); GB_ASSERT(attr != nullptr); LLVMAddAttributeAtIndex(p->value, cast(unsigned)index, attr); } -void lb_add_proc_attribute_at_index(lbProcedure *p, isize index, char const *name) { +gb_internal void lb_add_proc_attribute_at_index(lbProcedure *p, isize index, char const *name) { lb_add_proc_attribute_at_index(p, index, name, 0); } -void lb_add_attribute_to_proc(lbModule *m, LLVMValueRef proc_value, char const *name, u64 value=0) { +gb_internal void lb_add_attribute_to_proc(lbModule *m, LLVMValueRef proc_value, char const *name, u64 value=0) { LLVMAddAttributeAtIndex(proc_value, LLVMAttributeIndex_FunctionIndex, lb_create_enum_attribute(m->ctx, name, value)); } -void lb_add_edge(lbBlock *from, lbBlock *to) { +gb_internal void lb_add_edge(lbBlock *from, lbBlock *to) { LLVMValueRef instr = LLVMGetLastInstruction(from->block); if (instr == nullptr || !LLVMIsATerminatorInst(instr)) { array_add(&from->succs, to); @@ -2289,7 +2289,7 @@ void lb_add_edge(lbBlock *from, lbBlock *to) { } -lbBlock *lb_create_block(lbProcedure *p, char const *name, bool append) { +gb_internal lbBlock *lb_create_block(lbProcedure *p, char const *name, bool append) { lbBlock *b = gb_alloc_item(permanent_allocator(), lbBlock); b->block = LLVMCreateBasicBlockInContext(p->module->ctx, name); b->appended = false; @@ -2309,7 +2309,7 @@ lbBlock *lb_create_block(lbProcedure *p, char const *name, bool append) { return b; } -void lb_emit_jump(lbProcedure *p, lbBlock *target_block) { +gb_internal void lb_emit_jump(lbProcedure *p, lbBlock *target_block) { if (p->curr_block == nullptr) { return; } @@ -2323,7 +2323,7 @@ void lb_emit_jump(lbProcedure *p, lbBlock *target_block) { p->curr_block = nullptr; } -void lb_emit_if(lbProcedure *p, lbValue cond, lbBlock *true_block, lbBlock *false_block) { +gb_internal void lb_emit_if(lbProcedure *p, lbValue cond, lbBlock *true_block, lbBlock *false_block) { lbBlock *b = p->curr_block; if (b == nullptr) { return; @@ -2342,20 +2342,20 @@ void lb_emit_if(lbProcedure *p, lbValue cond, lbBlock *true_block, lbBlock *fals } -gb_inline LLVMTypeRef OdinLLVMGetInternalElementType(LLVMTypeRef type) { +gb_internal gb_inline LLVMTypeRef OdinLLVMGetInternalElementType(LLVMTypeRef type) { return LLVMGetElementType(type); } -LLVMTypeRef OdinLLVMGetArrayElementType(LLVMTypeRef type) { +gb_internal LLVMTypeRef OdinLLVMGetArrayElementType(LLVMTypeRef type) { GB_ASSERT(lb_is_type_kind(type, LLVMArrayTypeKind)); return OdinLLVMGetInternalElementType(type); } -LLVMTypeRef OdinLLVMGetVectorElementType(LLVMTypeRef type) { +gb_internal LLVMTypeRef OdinLLVMGetVectorElementType(LLVMTypeRef type) { GB_ASSERT(lb_is_type_kind(type, LLVMVectorTypeKind)); return OdinLLVMGetInternalElementType(type); } -LLVMValueRef OdinLLVMBuildTransmute(lbProcedure *p, LLVMValueRef val, LLVMTypeRef dst_type) { +gb_internal LLVMValueRef OdinLLVMBuildTransmute(lbProcedure *p, LLVMValueRef val, LLVMTypeRef dst_type) { LLVMContextRef ctx = p->module->ctx; LLVMTypeRef src_type = LLVMTypeOf(val); @@ -2445,7 +2445,7 @@ general_end:; -LLVMValueRef lb_find_or_add_entity_string_ptr(lbModule *m, String const &str) { +gb_internal LLVMValueRef lb_find_or_add_entity_string_ptr(lbModule *m, String const &str) { StringHashKey key = string_hash_string(str); LLVMValueRef *found = string_map_get(&m->const_strings, key); if (found != nullptr) { @@ -2477,7 +2477,7 @@ LLVMValueRef lb_find_or_add_entity_string_ptr(lbModule *m, String const &str) { } } -lbValue lb_find_or_add_entity_string(lbModule *m, String const &str) { +gb_internal lbValue lb_find_or_add_entity_string(lbModule *m, String const &str) { LLVMValueRef ptr = nullptr; if (str.len != 0) { ptr = lb_find_or_add_entity_string_ptr(m, str); @@ -2493,7 +2493,7 @@ lbValue lb_find_or_add_entity_string(lbModule *m, String const &str) { return res; } -lbValue lb_find_or_add_entity_string_byte_slice(lbModule *m, String const &str) { +gb_internal lbValue lb_find_or_add_entity_string_byte_slice(lbModule *m, String const &str) { LLVMValueRef indices[2] = {llvm_zero(m), llvm_zero(m)}; LLVMValueRef data = LLVMConstStringInContext(m->ctx, cast(char const *)str.text, @@ -2529,7 +2529,7 @@ lbValue lb_find_or_add_entity_string_byte_slice(lbModule *m, String const &str) res.type = t_u8_slice; return res; } -lbValue lb_find_or_add_entity_string_byte_slice_with_type(lbModule *m, String const &str, Type *slice_type) { +gb_internal lbValue lb_find_or_add_entity_string_byte_slice_with_type(lbModule *m, String const &str, Type *slice_type) { GB_ASSERT(is_type_slice(slice_type)); LLVMValueRef indices[2] = {llvm_zero(m), llvm_zero(m)}; LLVMValueRef data = LLVMConstStringInContext(m->ctx, @@ -2579,7 +2579,7 @@ lbValue lb_find_or_add_entity_string_byte_slice_with_type(lbModule *m, String co -lbValue lb_find_ident(lbProcedure *p, lbModule *m, Entity *e, Ast *expr) { +gb_internal lbValue lb_find_ident(lbProcedure *p, lbModule *m, Entity *e, Ast *expr) { if (e->flags & EntityFlag_Param) { // NOTE(bill): Bypass the stack copied variable for // direct parameters as there is no need for the direct load @@ -2633,7 +2633,7 @@ lbValue lb_find_ident(lbProcedure *p, lbModule *m, Entity *e, Ast *expr) { } -lbValue lb_find_procedure_value_from_entity(lbModule *m, Entity *e) { +gb_internal lbValue lb_find_procedure_value_from_entity(lbModule *m, Entity *e) { GB_ASSERT(is_type_proc(e->type)); e = strip_entity_wrapping(e); GB_ASSERT(e != nullptr); @@ -2668,7 +2668,7 @@ lbValue lb_find_procedure_value_from_entity(lbModule *m, Entity *e) { } -lbAddr lb_add_global_generated(lbModule *m, Type *type, lbValue value, Entity **entity_) { +gb_internal lbAddr lb_add_global_generated(lbModule *m, Type *type, lbValue value, Entity **entity_) { GB_ASSERT(type != nullptr); type = default_type(type); @@ -2700,23 +2700,23 @@ lbAddr lb_add_global_generated(lbModule *m, Type *type, lbValue value, Entity ** return lb_addr(g); } -lbValue lb_find_runtime_value(lbModule *m, String const &name) { +gb_internal lbValue lb_find_runtime_value(lbModule *m, String const &name) { AstPackage *p = m->info->runtime_package; Entity *e = scope_lookup_current(p->scope, name); return lb_find_value_from_entity(m, e); } -lbValue lb_find_package_value(lbModule *m, String const &pkg, String const &name) { +gb_internal lbValue lb_find_package_value(lbModule *m, String const &pkg, String const &name) { Entity *e = find_entity_in_pkg(m->info, pkg, name); return lb_find_value_from_entity(m, e); } -lbValue lb_generate_local_array(lbProcedure *p, Type *elem_type, i64 count, bool zero_init) { +gb_internal lbValue lb_generate_local_array(lbProcedure *p, Type *elem_type, i64 count, bool zero_init) { lbAddr addr = lb_add_local_generated(p, alloc_type_array(elem_type, count), zero_init); return lb_addr_get_ptr(p, addr); } -lbValue lb_find_value_from_entity(lbModule *m, Entity *e) { +gb_internal lbValue lb_find_value_from_entity(lbModule *m, Entity *e) { e = strip_entity_wrapping(e); GB_ASSERT(e != nullptr); @@ -2788,7 +2788,7 @@ lbValue lb_find_value_from_entity(lbModule *m, Entity *e) { return {}; } -lbValue lb_generate_global_array(lbModule *m, Type *elem_type, i64 count, String prefix, i64 id) { +gb_internal lbValue lb_generate_global_array(lbModule *m, Type *elem_type, i64 count, String prefix, i64 id) { Token token = {Token_Ident}; isize name_len = prefix.len + 1 + 20; @@ -2813,7 +2813,7 @@ lbValue lb_generate_global_array(lbModule *m, Type *elem_type, i64 count, String -lbValue lb_build_cond(lbProcedure *p, Ast *cond, lbBlock *true_block, lbBlock *false_block) { +gb_internal lbValue lb_build_cond(lbProcedure *p, Ast *cond, lbBlock *true_block, lbBlock *false_block) { GB_ASSERT(cond != nullptr); GB_ASSERT(true_block != nullptr); GB_ASSERT(false_block != nullptr); @@ -2868,7 +2868,7 @@ lbValue lb_build_cond(lbProcedure *p, Ast *cond, lbBlock *true_block, lbBlock *f } -lbAddr lb_add_local(lbProcedure *p, Type *type, Entity *e, bool zero_init, bool force_no_init) { +gb_internal lbAddr lb_add_local(lbProcedure *p, Type *type, Entity *e, bool zero_init, bool force_no_init) { GB_ASSERT(p->decl_block != p->curr_block); LLVMPositionBuilderAtEnd(p->builder, p->decl_block->block); @@ -2917,18 +2917,18 @@ lbAddr lb_add_local(lbProcedure *p, Type *type, Entity *e, bool zero_init, bool return lb_addr(val); } -lbAddr lb_add_local_generated(lbProcedure *p, Type *type, bool zero_init) { +gb_internal lbAddr lb_add_local_generated(lbProcedure *p, Type *type, bool zero_init) { return lb_add_local(p, type, nullptr, zero_init); } -lbAddr lb_add_local_generated_temp(lbProcedure *p, Type *type, i64 min_alignment) { +gb_internal lbAddr lb_add_local_generated_temp(lbProcedure *p, Type *type, i64 min_alignment) { lbAddr res = lb_add_local(p, type, nullptr, false, true); lb_try_update_alignment(res.addr, cast(unsigned)min_alignment); return res; } -void lb_set_linkage_from_entity_flags(lbModule *m, LLVMValueRef value, u64 flags) { +gb_internal void lb_set_linkage_from_entity_flags(lbModule *m, LLVMValueRef value, u64 flags) { if (flags & EntityFlag_CustomLinkage_Internal) { LLVMSetLinkage(value, LLVMInternalLinkage); } else if (flags & EntityFlag_CustomLinkage_Strong) { diff --git a/src/llvm_backend_opt.cpp b/src/llvm_backend_opt.cpp index e2f51b868..533264e62 100644 --- a/src/llvm_backend_opt.cpp +++ b/src/llvm_backend_opt.cpp @@ -32,12 +32,12 @@ **************************************************************************/ -void lb_populate_function_pass_manager(lbModule *m, LLVMPassManagerRef fpm, bool ignore_memcpy_pass, i32 optimization_level); -void lb_add_function_simplifcation_passes(LLVMPassManagerRef mpm, i32 optimization_level); -void lb_populate_module_pass_manager(LLVMTargetMachineRef target_machine, LLVMPassManagerRef mpm, i32 optimization_level); -void lb_populate_function_pass_manager_specific(lbModule *m, LLVMPassManagerRef fpm, i32 optimization_level); +gb_internal void lb_populate_function_pass_manager(lbModule *m, LLVMPassManagerRef fpm, bool ignore_memcpy_pass, i32 optimization_level); +gb_internal void lb_add_function_simplifcation_passes(LLVMPassManagerRef mpm, i32 optimization_level); +gb_internal void lb_populate_module_pass_manager(LLVMTargetMachineRef target_machine, LLVMPassManagerRef mpm, i32 optimization_level); +gb_internal void lb_populate_function_pass_manager_specific(lbModule *m, LLVMPassManagerRef fpm, i32 optimization_level); -LLVMBool lb_must_preserve_predicate_callback(LLVMValueRef value, void *user_data) { +gb_internal LLVMBool lb_must_preserve_predicate_callback(LLVMValueRef value, void *user_data) { lbModule *m = cast(lbModule *)user_data; if (m == nullptr) { return false; @@ -55,7 +55,7 @@ LLVMBool lb_must_preserve_predicate_callback(LLVMValueRef value, void *user_data #define LLVM_ADD_CONSTANT_VALUE_PASS(fpm) #endif -void lb_basic_populate_function_pass_manager(LLVMPassManagerRef fpm, i32 optimization_level) { +gb_internal void lb_basic_populate_function_pass_manager(LLVMPassManagerRef fpm, i32 optimization_level) { if (false && optimization_level == 0 && build_context.ODIN_DEBUG) { LLVMAddMergedLoadStoreMotionPass(fpm); } else { @@ -68,7 +68,7 @@ void lb_basic_populate_function_pass_manager(LLVMPassManagerRef fpm, i32 optimiz } } -void lb_populate_function_pass_manager(lbModule *m, LLVMPassManagerRef fpm, bool ignore_memcpy_pass, i32 optimization_level) { +gb_internal void lb_populate_function_pass_manager(lbModule *m, LLVMPassManagerRef fpm, bool ignore_memcpy_pass, i32 optimization_level) { // NOTE(bill): Treat -opt:3 as if it was -opt:2 // TODO(bill): Determine which opt definitions should exist in the first place optimization_level = gb_clamp(optimization_level, 0, 2); @@ -102,7 +102,7 @@ void lb_populate_function_pass_manager(lbModule *m, LLVMPassManagerRef fpm, bool #endif } -void lb_populate_function_pass_manager_specific(lbModule *m, LLVMPassManagerRef fpm, i32 optimization_level) { +gb_internal void lb_populate_function_pass_manager_specific(lbModule *m, LLVMPassManagerRef fpm, i32 optimization_level) { // NOTE(bill): Treat -opt:3 as if it was -opt:2 // TODO(bill): Determine which opt definitions should exist in the first place optimization_level = gb_clamp(optimization_level, 0, 2); @@ -141,7 +141,7 @@ void lb_populate_function_pass_manager_specific(lbModule *m, LLVMPassManagerRef #endif } -void lb_add_function_simplifcation_passes(LLVMPassManagerRef mpm, i32 optimization_level) { +gb_internal void lb_add_function_simplifcation_passes(LLVMPassManagerRef mpm, i32 optimization_level) { LLVMAddCFGSimplificationPass(mpm); LLVMAddJumpThreadingPass(mpm); @@ -177,7 +177,7 @@ void lb_add_function_simplifcation_passes(LLVMPassManagerRef mpm, i32 optimizati } -void lb_populate_module_pass_manager(LLVMTargetMachineRef target_machine, LLVMPassManagerRef mpm, i32 optimization_level) { +gb_internal void lb_populate_module_pass_manager(LLVMTargetMachineRef target_machine, LLVMPassManagerRef mpm, i32 optimization_level) { // NOTE(bill): Treat -opt:3 as if it was -opt:2 // TODO(bill): Determine which opt definitions should exist in the first place @@ -266,7 +266,7 @@ void lb_populate_module_pass_manager(LLVMTargetMachineRef target_machine, LLVMPa optimization of Odin programs **************************************************************************/ -void lb_run_remove_dead_instruction_pass(lbProcedure *p) { +gb_internal void lb_run_remove_dead_instruction_pass(lbProcedure *p) { isize removal_count = 0; isize pass_count = 0; isize const max_pass_count = 10; @@ -358,7 +358,7 @@ void lb_run_remove_dead_instruction_pass(lbProcedure *p) { } -void lb_run_function_pass_manager(LLVMPassManagerRef fpm, lbProcedure *p) { +gb_internal void lb_run_function_pass_manager(LLVMPassManagerRef fpm, lbProcedure *p) { LLVMRunFunctionPassManager(fpm, p->value); // NOTE(bill): LLVMAddDCEPass doesn't seem to be exported in the official DLL's for LLVM // which means we cannot rely upon it @@ -367,7 +367,7 @@ void lb_run_function_pass_manager(LLVMPassManagerRef fpm, lbProcedure *p) { lb_run_remove_dead_instruction_pass(p); } -void llvm_delete_function(LLVMValueRef func) { +gb_internal void llvm_delete_function(LLVMValueRef func) { // for (LLVMBasicBlockRef block = LLVMGetFirstBasicBlock(func); block != nullptr; /**/) { // LLVMBasicBlockRef curr_block = block; // block = LLVMGetNextBasicBlock(block); @@ -382,7 +382,7 @@ void llvm_delete_function(LLVMValueRef func) { LLVMDeleteFunction(func); } -void lb_append_to_compiler_used(lbModule *m, LLVMValueRef func) { +gb_internal void lb_append_to_compiler_used(lbModule *m, LLVMValueRef func) { LLVMValueRef global = LLVMGetNamedGlobal(m->mod, "llvm.compiler.used"); LLVMValueRef *constants; @@ -419,7 +419,7 @@ void lb_append_to_compiler_used(lbModule *m, LLVMValueRef func) { LLVMSetInitializer(global, initializer); } -void lb_run_remove_unused_function_pass(lbModule *m) { +gb_internal void lb_run_remove_unused_function_pass(lbModule *m) { isize removal_count = 0; isize pass_count = 0; isize const max_pass_count = 10; @@ -470,7 +470,7 @@ void lb_run_remove_unused_function_pass(lbModule *m) { } -void lb_run_remove_unused_globals_pass(lbModule *m) { +gb_internal void lb_run_remove_unused_globals_pass(lbModule *m) { isize removal_count = 0; isize pass_count = 0; isize const max_pass_count = 10; diff --git a/src/llvm_backend_proc.cpp b/src/llvm_backend_proc.cpp index 597efb0ba..0789fb2c1 100644 --- a/src/llvm_backend_proc.cpp +++ b/src/llvm_backend_proc.cpp @@ -1,5 +1,4 @@ -LLVMValueRef lb_call_intrinsic(lbProcedure *p, const char *name, LLVMValueRef* args, unsigned arg_count, LLVMTypeRef* types, unsigned type_count) -{ +gb_internal LLVMValueRef lb_call_intrinsic(lbProcedure *p, const char *name, LLVMValueRef* args, unsigned arg_count, LLVMTypeRef* types, unsigned type_count) { unsigned id = LLVMLookupIntrinsicID(name, gb_strlen(name)); GB_ASSERT_MSG(id != 0, "Unable to find %s", name); LLVMValueRef ip = LLVMGetIntrinsicDeclaration(p->module->mod, id, types, type_count); @@ -7,7 +6,7 @@ LLVMValueRef lb_call_intrinsic(lbProcedure *p, const char *name, LLVMValueRef* a return LLVMBuildCall2(p->builder, call_type, ip, args, arg_count, ""); } -void lb_mem_copy_overlapping(lbProcedure *p, lbValue dst, lbValue src, lbValue len, bool is_volatile) { +gb_internal void lb_mem_copy_overlapping(lbProcedure *p, lbValue dst, lbValue src, lbValue len, bool is_volatile) { dst = lb_emit_conv(p, dst, t_rawptr); src = lb_emit_conv(p, src, t_rawptr); len = lb_emit_conv(p, len, t_int); @@ -36,7 +35,7 @@ void lb_mem_copy_overlapping(lbProcedure *p, lbValue dst, lbValue src, lbValue l -void lb_mem_copy_non_overlapping(lbProcedure *p, lbValue dst, lbValue src, lbValue len, bool is_volatile) { +gb_internal void lb_mem_copy_non_overlapping(lbProcedure *p, lbValue dst, lbValue src, lbValue len, bool is_volatile) { dst = lb_emit_conv(p, dst, t_rawptr); src = lb_emit_conv(p, src, t_rawptr); len = lb_emit_conv(p, len, t_int); @@ -65,7 +64,7 @@ void lb_mem_copy_non_overlapping(lbProcedure *p, lbValue dst, lbValue src, lbVal } -lbProcedure *lb_create_procedure(lbModule *m, Entity *entity, bool ignore_body) { +gb_internal lbProcedure *lb_create_procedure(lbModule *m, Entity *entity, bool ignore_body) { GB_ASSERT(entity != nullptr); GB_ASSERT(entity->kind == Entity_Procedure); if (!entity->Procedure.is_foreign) { @@ -320,7 +319,7 @@ lbProcedure *lb_create_procedure(lbModule *m, Entity *entity, bool ignore_body) return p; } -lbProcedure *lb_create_dummy_procedure(lbModule *m, String link_name, Type *type) { +gb_internal lbProcedure *lb_create_dummy_procedure(lbModule *m, String link_name, Type *type) { { lbValue *found = string_map_get(&m->members, link_name); GB_ASSERT_MSG(found == nullptr, "failed to create dummy procedure for: %.*s", LIT(link_name)); @@ -384,7 +383,7 @@ lbProcedure *lb_create_dummy_procedure(lbModule *m, String link_name, Type *type } -lbValue lb_value_param(lbProcedure *p, Entity *e, Type *abi_type, i32 index, lbParamPasskind *kind_) { +gb_internal lbValue lb_value_param(lbProcedure *p, Entity *e, Type *abi_type, i32 index, lbParamPasskind *kind_) { lbParamPasskind kind = lbParamPass_Value; if (e != nullptr && !are_types_identical(abi_type, e->type)) { @@ -427,7 +426,7 @@ lbValue lb_value_param(lbProcedure *p, Entity *e, Type *abi_type, i32 index, lbP -void lb_start_block(lbProcedure *p, lbBlock *b) { +gb_internal void lb_start_block(lbProcedure *p, lbBlock *b) { GB_ASSERT(b != nullptr); if (!b->appended) { b->appended = true; @@ -437,7 +436,7 @@ void lb_start_block(lbProcedure *p, lbBlock *b) { p->curr_block = b; } -void lb_set_debug_position_to_procedure_begin(lbProcedure *p) { +gb_internal void lb_set_debug_position_to_procedure_begin(lbProcedure *p) { if (p->debug_info == nullptr) { return; } @@ -454,7 +453,7 @@ void lb_set_debug_position_to_procedure_begin(lbProcedure *p) { } } -void lb_set_debug_position_to_procedure_end(lbProcedure *p) { +gb_internal void lb_set_debug_position_to_procedure_end(lbProcedure *p) { if (p->debug_info == nullptr) { return; } @@ -471,7 +470,7 @@ void lb_set_debug_position_to_procedure_end(lbProcedure *p) { } } -void lb_begin_procedure_body(lbProcedure *p) { +gb_internal void lb_begin_procedure_body(lbProcedure *p) { DeclInfo *decl = decl_info_of_entity(p->entity); if (decl != nullptr) { for_array(i, decl->labels) { @@ -686,7 +685,7 @@ void lb_begin_procedure_body(lbProcedure *p) { lb_start_block(p, p->entry_block); } -void lb_end_procedure_body(lbProcedure *p) { +gb_internal void lb_end_procedure_body(lbProcedure *p) { lb_set_debug_position_to_procedure_begin(p); LLVMPositionBuilderAtEnd(p->builder, p->decl_block->block); @@ -720,11 +719,11 @@ void lb_end_procedure_body(lbProcedure *p) { p->curr_block = nullptr; p->state_flags = 0; } -void lb_end_procedure(lbProcedure *p) { +gb_internal void lb_end_procedure(lbProcedure *p) { LLVMDisposeBuilder(p->builder); } -void lb_build_nested_proc(lbProcedure *p, AstProcLit *pd, Entity *e) { +gb_internal void lb_build_nested_proc(lbProcedure *p, AstProcLit *pd, Entity *e) { GB_ASSERT(pd->body != nullptr); lbModule *m = p->module; auto *min_dep_set = &m->info->minimum_dependency_set; @@ -766,7 +765,7 @@ void lb_build_nested_proc(lbProcedure *p, AstProcLit *pd, Entity *e) { -Array lb_value_to_array(lbProcedure *p, lbValue value) { +gb_internal Array lb_value_to_array(lbProcedure *p, lbValue value) { Array array = {}; Type *t = base_type(value.type); if (t == nullptr) { @@ -783,7 +782,7 @@ Array lb_value_to_array(lbProcedure *p, lbValue value) { -lbValue lb_emit_call_internal(lbProcedure *p, lbValue value, lbValue return_ptr, Array const &processed_args, Type *abi_rt, lbAddr context_ptr, ProcInlining inlining) { +gb_internal lbValue lb_emit_call_internal(lbProcedure *p, lbValue value, lbValue return_ptr, Array const &processed_args, Type *abi_rt, lbAddr context_ptr, ProcInlining inlining) { GB_ASSERT(p->module->ctx == LLVMGetTypeContext(LLVMTypeOf(value.value))); unsigned arg_count = cast(unsigned)processed_args.count; @@ -892,20 +891,20 @@ lbValue lb_emit_call_internal(lbProcedure *p, lbValue value, lbValue return_ptr, } -lbValue lb_lookup_runtime_procedure(lbModule *m, String const &name) { +gb_internal lbValue lb_lookup_runtime_procedure(lbModule *m, String const &name) { AstPackage *pkg = m->info->runtime_package; Entity *e = scope_lookup_current(pkg->scope, name); return lb_find_procedure_value_from_entity(m, e); } -lbValue lb_emit_runtime_call(lbProcedure *p, char const *c_name, Array const &args) { +gb_internal lbValue lb_emit_runtime_call(lbProcedure *p, char const *c_name, Array const &args) { String name = make_string_c(c_name); lbValue proc = lb_lookup_runtime_procedure(p->module, name); return lb_emit_call(p, proc, args); } -lbValue lb_emit_conjugate(lbProcedure *p, lbValue val, Type *type) { +gb_internal lbValue lb_emit_conjugate(lbProcedure *p, lbValue val, Type *type) { lbValue res = {}; Type *t = val.type; if (is_type_complex(t)) { @@ -956,7 +955,7 @@ lbValue lb_emit_conjugate(lbProcedure *p, lbValue val, Type *type) { return lb_emit_load(p, res); } -lbValue lb_emit_call(lbProcedure *p, lbValue value, Array const &args, ProcInlining inlining) { +gb_internal lbValue lb_emit_call(lbProcedure *p, lbValue value, Array const &args, ProcInlining inlining) { lbModule *m = p->module; Type *pt = base_type(value.type); @@ -1166,7 +1165,7 @@ lbValue lb_emit_call(lbProcedure *p, lbValue value, Array const &args, return result; } -LLVMValueRef llvm_splat_float(i64 count, LLVMTypeRef type, f64 value) { +gb_internal LLVMValueRef llvm_splat_float(i64 count, LLVMTypeRef type, f64 value) { LLVMValueRef v = LLVMConstReal(type, value); LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, count); for (i64 i = 0; i < count; i++) { @@ -1174,7 +1173,7 @@ LLVMValueRef llvm_splat_float(i64 count, LLVMTypeRef type, f64 value) { } return LLVMConstVector(values, cast(unsigned)count); } -LLVMValueRef llvm_splat_int(i64 count, LLVMTypeRef type, i64 value, bool is_signed=false) { +gb_internal LLVMValueRef llvm_splat_int(i64 count, LLVMTypeRef type, i64 value, bool is_signed=false) { LLVMValueRef v = LLVMConstInt(type, value, is_signed); LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, count); for (i64 i = 0; i < count; i++) { @@ -1184,7 +1183,7 @@ LLVMValueRef llvm_splat_int(i64 count, LLVMTypeRef type, i64 value, bool is_sign } -lbValue lb_build_builtin_simd_proc(lbProcedure *p, Ast *expr, TypeAndValue const &tv, BuiltinProcId builtin_id) { +gb_internal lbValue lb_build_builtin_simd_proc(lbProcedure *p, Ast *expr, TypeAndValue const &tv, BuiltinProcId builtin_id) { ast_node(ce, CallExpr, expr); lbModule *m = p->module; @@ -1600,7 +1599,7 @@ lbValue lb_build_builtin_simd_proc(lbProcedure *p, Ast *expr, TypeAndValue const } -lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValue const &tv, BuiltinProcId id) { +gb_internal lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValue const &tv, BuiltinProcId id) { ast_node(ce, CallExpr, expr); if (BuiltinProc__simd_begin < id && id < BuiltinProc__simd_end) { @@ -2980,7 +2979,7 @@ lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValue const &tv, } -lbValue lb_handle_param_value(lbProcedure *p, Type *parameter_type, ParameterValue const ¶m_value, TokenPos const &pos) { +gb_internal lbValue lb_handle_param_value(lbProcedure *p, Type *parameter_type, ParameterValue const ¶m_value, TokenPos const &pos) { switch (param_value.kind) { case ParameterValue_Constant: if (is_type_constant_type(parameter_type)) { @@ -3015,9 +3014,9 @@ lbValue lb_handle_param_value(lbProcedure *p, Type *parameter_type, ParameterVal } -lbValue lb_build_call_expr_internal(lbProcedure *p, Ast *expr); +gb_internal lbValue lb_build_call_expr_internal(lbProcedure *p, Ast *expr); -lbValue lb_build_call_expr(lbProcedure *p, Ast *expr) { +gb_internal lbValue lb_build_call_expr(lbProcedure *p, Ast *expr) { expr = unparen_expr(expr); ast_node(ce, CallExpr, expr); @@ -3030,7 +3029,7 @@ lbValue lb_build_call_expr(lbProcedure *p, Ast *expr) { } return res; } -lbValue lb_build_call_expr_internal(lbProcedure *p, Ast *expr) { +gb_internal lbValue lb_build_call_expr_internal(lbProcedure *p, Ast *expr) { lbModule *m = p->module; TypeAndValue tv = type_and_value_of_expr(expr); diff --git a/src/llvm_backend_stmt.cpp b/src/llvm_backend_stmt.cpp index 46144aa00..66c422071 100644 --- a/src/llvm_backend_stmt.cpp +++ b/src/llvm_backend_stmt.cpp @@ -1,4 +1,4 @@ -void lb_build_constant_value_decl(lbProcedure *p, AstValueDecl *vd) { +gb_internal void lb_build_constant_value_decl(lbProcedure *p, AstValueDecl *vd) { if (vd == nullptr || vd->is_mutable) { return; } @@ -105,7 +105,7 @@ void lb_build_constant_value_decl(lbProcedure *p, AstValueDecl *vd) { } -void lb_build_stmt_list(lbProcedure *p, Slice const &stmts) { +gb_internal void lb_build_stmt_list(lbProcedure *p, Slice const &stmts) { for_array(i, stmts) { Ast *stmt = stmts[i]; switch (stmt->kind) { @@ -125,7 +125,7 @@ void lb_build_stmt_list(lbProcedure *p, Slice const &stmts) { -lbBranchBlocks lb_lookup_branch_blocks(lbProcedure *p, Ast *ident) { +gb_internal lbBranchBlocks lb_lookup_branch_blocks(lbProcedure *p, Ast *ident) { GB_ASSERT(ident->kind == Ast_Ident); Entity *e = entity_of_node(ident); GB_ASSERT(e->kind == Entity_Label); @@ -142,7 +142,7 @@ lbBranchBlocks lb_lookup_branch_blocks(lbProcedure *p, Ast *ident) { } -lbTargetList *lb_push_target_list(lbProcedure *p, Ast *label, lbBlock *break_, lbBlock *continue_, lbBlock *fallthrough_) { +gb_internal lbTargetList *lb_push_target_list(lbProcedure *p, Ast *label, lbBlock *break_, lbBlock *continue_, lbBlock *fallthrough_) { lbTargetList *tl = gb_alloc_item(permanent_allocator(), lbTargetList); tl->prev = p->target_list; tl->break_ = break_; @@ -170,11 +170,11 @@ lbTargetList *lb_push_target_list(lbProcedure *p, Ast *label, lbBlock *break_, l return tl; } -void lb_pop_target_list(lbProcedure *p) { +gb_internal void lb_pop_target_list(lbProcedure *p) { p->target_list = p->target_list->prev; } -void lb_open_scope(lbProcedure *p, Scope *s) { +gb_internal void lb_open_scope(lbProcedure *p, Scope *s) { lbModule *m = p->module; if (m->debug_builder) { LLVMMetadataRef curr_metadata = lb_get_llvm_metadata(m, s); @@ -211,7 +211,7 @@ void lb_open_scope(lbProcedure *p, Scope *s) { } -void lb_close_scope(lbProcedure *p, lbDeferExitKind kind, lbBlock *block, bool pop_stack=true) { +gb_internal void lb_close_scope(lbProcedure *p, lbDeferExitKind kind, lbBlock *block, bool pop_stack=true) { lb_emit_defer_stmts(p, kind, block); GB_ASSERT(p->scope_index > 0); @@ -230,7 +230,7 @@ void lb_close_scope(lbProcedure *p, lbDeferExitKind kind, lbBlock *block, bool p array_pop(&p->scope_stack); } -void lb_build_when_stmt(lbProcedure *p, AstWhenStmt *ws) { +gb_internal void lb_build_when_stmt(lbProcedure *p, AstWhenStmt *ws) { TypeAndValue tv = type_and_value_of_expr(ws->cond); GB_ASSERT(is_type_boolean(tv.type)); GB_ASSERT(tv.value.kind == ExactValue_Bool); @@ -253,8 +253,8 @@ void lb_build_when_stmt(lbProcedure *p, AstWhenStmt *ws) { -void lb_build_range_indexed(lbProcedure *p, lbValue expr, Type *val_type, lbValue count_ptr, - lbValue *val_, lbValue *idx_, lbBlock **loop_, lbBlock **done_) { +gb_internal void lb_build_range_indexed(lbProcedure *p, lbValue expr, Type *val_type, lbValue count_ptr, + lbValue *val_, lbValue *idx_, lbBlock **loop_, lbBlock **done_) { lbModule *m = p->module; lbValue count = {}; @@ -342,7 +342,7 @@ void lb_build_range_indexed(lbProcedure *p, lbValue expr, Type *val_type, lbValu if (done_) *done_ = done; } -lbValue lb_map_cell_index_static(lbProcedure *p, Type *type, lbValue cells_ptr, lbValue index) { +gb_internal lbValue lb_map_cell_index_static(lbProcedure *p, Type *type, lbValue cells_ptr, lbValue index) { i64 size, len; i64 elem_sz = type_size_of(type); map_cell_size_and_len(type, &size, &len); @@ -378,7 +378,7 @@ lbValue lb_map_cell_index_static(lbProcedure *p, Type *type, lbValue cells_ptr, return lb_emit_ptr_offset(p, elems_ptr, data_index); } -void lb_map_kvh_data_static(lbProcedure *p, lbValue map_value, lbValue *ks_, lbValue *vs_, lbValue *hs_) { +gb_internal void lb_map_kvh_data_static(lbProcedure *p, lbValue map_value, lbValue *ks_, lbValue *vs_, lbValue *hs_) { lbValue capacity = lb_map_cap(p, map_value); lbValue ks = lb_map_data_uintptr(p, map_value); lbValue vs = {}; @@ -388,7 +388,7 @@ void lb_map_kvh_data_static(lbProcedure *p, lbValue map_value, lbValue *ks_, lbV if (hs_) *hs_ = hs; } -lbValue lb_map_hash_is_valid(lbProcedure *p, lbValue hash) { +gb_internal lbValue lb_map_hash_is_valid(lbProcedure *p, lbValue hash) { // N :: size_of(uintptr)*8 - 1 // (hash != 0) & (hash>>N == 0) @@ -404,8 +404,8 @@ lbValue lb_map_hash_is_valid(lbProcedure *p, lbValue hash) { return lb_emit_arith(p, Token_And, not_deleted, not_empty, t_uintptr); } -void lb_build_range_map(lbProcedure *p, lbValue expr, Type *val_type, - lbValue *val_, lbValue *key_, lbBlock **loop_, lbBlock **done_) { +gb_internal void lb_build_range_map(lbProcedure *p, lbValue expr, Type *val_type, + lbValue *val_, lbValue *key_, lbBlock **loop_, lbBlock **done_) { lbModule *m = p->module; Type *type = base_type(type_deref(expr.type)); @@ -466,8 +466,8 @@ void lb_build_range_map(lbProcedure *p, lbValue expr, Type *val_type, -void lb_build_range_string(lbProcedure *p, lbValue expr, Type *val_type, - lbValue *val_, lbValue *idx_, lbBlock **loop_, lbBlock **done_) { +gb_internal void lb_build_range_string(lbProcedure *p, lbValue expr, Type *val_type, + lbValue *val_, lbValue *idx_, lbBlock **loop_, lbBlock **done_) { lbModule *m = p->module; lbValue count = lb_const_int(m, t_int, 0); Type *expr_type = base_type(expr.type); @@ -526,8 +526,8 @@ void lb_build_range_string(lbProcedure *p, lbValue expr, Type *val_type, } -void lb_build_range_interval(lbProcedure *p, AstBinaryExpr *node, - AstRangeStmt *rs, Scope *scope) { +gb_internal void lb_build_range_interval(lbProcedure *p, AstBinaryExpr *node, + AstRangeStmt *rs, Scope *scope) { bool ADD_EXTRA_WRAPPING_CHECK = true; lbModule *m = p->module; @@ -630,7 +630,7 @@ void lb_build_range_interval(lbProcedure *p, AstBinaryExpr *node, lb_start_block(p, done); } -void lb_build_range_enum(lbProcedure *p, Type *enum_type, Type *val_type, lbValue *val_, lbValue *idx_, lbBlock **loop_, lbBlock **done_) { +gb_internal void lb_build_range_enum(lbProcedure *p, Type *enum_type, Type *val_type, lbValue *val_, lbValue *idx_, lbBlock **loop_, lbBlock **done_) { lbModule *m = p->module; Type *t = enum_type; @@ -683,8 +683,8 @@ void lb_build_range_enum(lbProcedure *p, Type *enum_type, Type *val_type, lbValu if (done_) *done_ = done; } -void lb_build_range_tuple(lbProcedure *p, Ast *expr, Type *val0_type, Type *val1_type, - lbValue *val0_, lbValue *val1_, lbBlock **loop_, lbBlock **done_) { +gb_internal void lb_build_range_tuple(lbProcedure *p, Ast *expr, Type *val0_type, Type *val1_type, + lbValue *val0_, lbValue *val1_, lbBlock **loop_, lbBlock **done_) { lbBlock *loop = lb_create_block(p, "for.tuple.loop"); lb_emit_jump(p, loop); lb_start_block(p, loop); @@ -709,7 +709,7 @@ void lb_build_range_tuple(lbProcedure *p, Ast *expr, Type *val0_type, Type *val1 if (done_) *done_ = done; } -void lb_build_range_stmt_struct_soa(lbProcedure *p, AstRangeStmt *rs, Scope *scope) { +gb_internal void lb_build_range_stmt_struct_soa(lbProcedure *p, AstRangeStmt *rs, Scope *scope) { Ast *expr = unparen_expr(rs->expr); TypeAndValue tav = type_and_value_of_expr(expr); @@ -778,7 +778,7 @@ void lb_build_range_stmt_struct_soa(lbProcedure *p, AstRangeStmt *rs, Scope *sco } -void lb_build_range_stmt(lbProcedure *p, AstRangeStmt *rs, Scope *scope) { +gb_internal void lb_build_range_stmt(lbProcedure *p, AstRangeStmt *rs, Scope *scope) { Ast *expr = unparen_expr(rs->expr); if (is_ast_range(expr)) { @@ -923,7 +923,7 @@ void lb_build_range_stmt(lbProcedure *p, AstRangeStmt *rs, Scope *scope) { lb_start_block(p, done); } -void lb_build_unroll_range_stmt(lbProcedure *p, AstUnrollRangeStmt *rs, Scope *scope) { +gb_internal void lb_build_unroll_range_stmt(lbProcedure *p, AstUnrollRangeStmt *rs, Scope *scope) { lbModule *m = p->module; lb_open_scope(p, scope); // Open scope here @@ -1089,7 +1089,7 @@ void lb_build_unroll_range_stmt(lbProcedure *p, AstUnrollRangeStmt *rs, Scope *s lb_close_scope(p, lbDeferExit_Default, nullptr); } -bool lb_switch_stmt_can_be_trivial_jump_table(AstSwitchStmt *ss, bool *default_found_) { +gb_internal bool lb_switch_stmt_can_be_trivial_jump_table(AstSwitchStmt *ss, bool *default_found_) { if (ss->tag == nullptr) { return false; } @@ -1138,7 +1138,7 @@ bool lb_switch_stmt_can_be_trivial_jump_table(AstSwitchStmt *ss, bool *default_f } -void lb_build_switch_stmt(lbProcedure *p, AstSwitchStmt *ss, Scope *scope) { +gb_internal void lb_build_switch_stmt(lbProcedure *p, AstSwitchStmt *ss, Scope *scope) { lb_open_scope(p, scope); if (ss->init != nullptr) { @@ -1300,7 +1300,7 @@ void lb_build_switch_stmt(lbProcedure *p, AstSwitchStmt *ss, Scope *scope) { lb_close_scope(p, lbDeferExit_Default, done); } -void lb_store_type_case_implicit(lbProcedure *p, Ast *clause, lbValue value) { +gb_internal void lb_store_type_case_implicit(lbProcedure *p, Ast *clause, lbValue value) { Entity *e = implicit_entity_of_node(clause); GB_ASSERT(e != nullptr); if (e->flags & EntityFlag_Value) { @@ -1315,7 +1315,7 @@ void lb_store_type_case_implicit(lbProcedure *p, Ast *clause, lbValue value) { } } -lbAddr lb_store_range_stmt_val(lbProcedure *p, Ast *stmt_val, lbValue value) { +gb_internal lbAddr lb_store_range_stmt_val(lbProcedure *p, Ast *stmt_val, lbValue value) { Entity *e = entity_of_node(stmt_val); if (e == nullptr) { return {}; @@ -1335,7 +1335,7 @@ lbAddr lb_store_range_stmt_val(lbProcedure *p, Ast *stmt_val, lbValue value) { return addr; } -void lb_type_case_body(lbProcedure *p, Ast *label, Ast *clause, lbBlock *body, lbBlock *done) { +gb_internal void lb_type_case_body(lbProcedure *p, Ast *label, Ast *clause, lbBlock *body, lbBlock *done) { ast_node(cc, CaseClause, clause); lb_push_target_list(p, label, done, nullptr, nullptr); @@ -1346,7 +1346,7 @@ void lb_type_case_body(lbProcedure *p, Ast *label, Ast *clause, lbBlock *body, l lb_emit_jump(p, done); } -void lb_build_type_switch_stmt(lbProcedure *p, AstTypeSwitchStmt *ss) { +gb_internal void lb_build_type_switch_stmt(lbProcedure *p, AstTypeSwitchStmt *ss) { lbModule *m = p->module; lb_open_scope(p, ss->scope); @@ -1480,7 +1480,7 @@ void lb_build_type_switch_stmt(lbProcedure *p, AstTypeSwitchStmt *ss) { } -void lb_build_static_variables(lbProcedure *p, AstValueDecl *vd) { +gb_internal void lb_build_static_variables(lbProcedure *p, AstValueDecl *vd) { for_array(i, vd->names) { lbValue value = {}; if (vd->values.count > 0) { @@ -1543,7 +1543,7 @@ void lb_build_static_variables(lbProcedure *p, AstValueDecl *vd) { lb_add_member(p->module, mangled_name, global_val); } } -void lb_append_tuple_values(lbProcedure *p, Array *dst_values, lbValue src_value) { +gb_internal void lb_append_tuple_values(lbProcedure *p, Array *dst_values, lbValue src_value) { Type *t = src_value.type; if (t->kind == Type_Tuple) { lbTupleFix *tf = map_get(&p->tuple_fix_map, src_value.value); @@ -1563,7 +1563,7 @@ void lb_append_tuple_values(lbProcedure *p, Array *dst_values, lbValue } -void lb_build_assignment(lbProcedure *p, Array &lvals, Slice const &values) { +gb_internal void lb_build_assignment(lbProcedure *p, Array &lvals, Slice const &values) { if (values.count == 0) { return; } @@ -1584,7 +1584,7 @@ void lb_build_assignment(lbProcedure *p, Array &lvals, Slice cons } } -void lb_build_return_stmt_internal(lbProcedure *p, lbValue res) { +gb_internal void lb_build_return_stmt_internal(lbProcedure *p, lbValue res) { lbFunctionType *ft = lb_get_function_type(p->module, p->type); bool return_by_pointer = ft->ret.kind == lbArg_Indirect; bool split_returns = ft->multiple_return_original_type != nullptr; @@ -1621,7 +1621,7 @@ void lb_build_return_stmt_internal(lbProcedure *p, lbValue res) { LLVMBuildRet(p->builder, ret_val); } } -void lb_build_return_stmt(lbProcedure *p, Slice const &return_results) { +gb_internal void lb_build_return_stmt(lbProcedure *p, Slice const &return_results) { lb_ensure_abi_function_type(p->module, p); lbValue res = {}; @@ -1765,7 +1765,7 @@ void lb_build_return_stmt(lbProcedure *p, Slice const &return_results) { lb_build_return_stmt_internal(p, res); } -void lb_build_if_stmt(lbProcedure *p, Ast *node) { +gb_internal void lb_build_if_stmt(lbProcedure *p, Ast *node) { ast_node(is, IfStmt, node); lb_open_scope(p, is->scope); // Scope #1 defer (lb_close_scope(p, lbDeferExit_Default, nullptr)); @@ -1852,7 +1852,7 @@ void lb_build_if_stmt(lbProcedure *p, Ast *node) { lb_start_block(p, done); } -void lb_build_for_stmt(lbProcedure *p, Ast *node) { +gb_internal void lb_build_for_stmt(lbProcedure *p, Ast *node) { ast_node(fs, ForStmt, node); lb_open_scope(p, fs->scope); // Open Scope here @@ -1912,7 +1912,7 @@ void lb_build_for_stmt(lbProcedure *p, Ast *node) { lb_close_scope(p, lbDeferExit_Default, nullptr); } -void lb_build_assign_stmt_array(lbProcedure *p, TokenKind op, lbAddr const &lhs, lbValue const &value) { +gb_internal void lb_build_assign_stmt_array(lbProcedure *p, TokenKind op, lbAddr const &lhs, lbValue const &value) { GB_ASSERT(op != Token_Eq); Type *lhs_type = lb_addr_type(lhs); @@ -2055,7 +2055,7 @@ void lb_build_assign_stmt_array(lbProcedure *p, TokenKind op, lbAddr const &lhs, lb_loop_end(p, loop_data); } } -void lb_build_assign_stmt(lbProcedure *p, AstAssignStmt *as) { +gb_internal void lb_build_assign_stmt(lbProcedure *p, AstAssignStmt *as) { if (as->op.kind == Token_Eq) { auto lvals = array_make(permanent_allocator(), 0, as->lhs.count); @@ -2113,7 +2113,7 @@ void lb_build_assign_stmt(lbProcedure *p, AstAssignStmt *as) { } -void lb_build_stmt(lbProcedure *p, Ast *node) { +gb_internal void lb_build_stmt(lbProcedure *p, Ast *node) { Ast *prev_stmt = p->curr_stmt; defer (p->curr_stmt = prev_stmt); p->curr_stmt = node; @@ -2308,7 +2308,7 @@ void lb_build_stmt(lbProcedure *p, Ast *node) { -void lb_build_defer_stmt(lbProcedure *p, lbDefer const &d) { +gb_internal void lb_build_defer_stmt(lbProcedure *p, lbDefer const &d) { if (p->curr_block == nullptr) { return; } @@ -2337,7 +2337,7 @@ void lb_build_defer_stmt(lbProcedure *p, lbDefer const &d) { } } -void lb_emit_defer_stmts(lbProcedure *p, lbDeferExitKind kind, lbBlock *block) { +gb_internal void lb_emit_defer_stmts(lbProcedure *p, lbDeferExitKind kind, lbBlock *block) { isize count = p->defer_stmts.count; isize i = count; while (i --> 0) { @@ -2364,7 +2364,7 @@ void lb_emit_defer_stmts(lbProcedure *p, lbDeferExitKind kind, lbBlock *block) { } } -void lb_add_defer_node(lbProcedure *p, isize scope_index, Ast *stmt) { +gb_internal void lb_add_defer_node(lbProcedure *p, isize scope_index, Ast *stmt) { Type *pt = base_type(p->type); GB_ASSERT(pt->kind == Type_Proc); if (pt->Proc.calling_convention == ProcCC_Odin) { @@ -2379,7 +2379,7 @@ void lb_add_defer_node(lbProcedure *p, isize scope_index, Ast *stmt) { d->stmt = stmt; } -void lb_add_defer_proc(lbProcedure *p, isize scope_index, lbValue deferred, Array const &result_as_args) { +gb_internal void lb_add_defer_proc(lbProcedure *p, isize scope_index, lbValue deferred, Array const &result_as_args) { Type *pt = base_type(p->type); GB_ASSERT(pt->kind == Type_Proc); if (pt->Proc.calling_convention == ProcCC_Odin) { diff --git a/src/llvm_backend_type.cpp b/src/llvm_backend_type.cpp index 307d9304b..26bb614e6 100644 --- a/src/llvm_backend_type.cpp +++ b/src/llvm_backend_type.cpp @@ -1,4 +1,4 @@ -isize lb_type_info_index(CheckerInfo *info, Type *type, bool err_on_not_found=true) { +gb_internal isize lb_type_info_index(CheckerInfo *info, Type *type, bool err_on_not_found=true) { auto *set = &info->minimum_dependency_type_info_set; isize index = type_info_index(info, type, err_on_not_found); if (index >= 0) { @@ -13,7 +13,7 @@ isize lb_type_info_index(CheckerInfo *info, Type *type, bool err_on_not_found=tr return -1; } -lbValue lb_typeid(lbModule *m, Type *type) { +gb_internal lbValue lb_typeid(lbModule *m, Type *type) { GB_ASSERT(!build_context.disallow_rtti); type = default_type(type); @@ -90,7 +90,7 @@ lbValue lb_typeid(lbModule *m, Type *type) { return res; } -lbValue lb_type_info(lbModule *m, Type *type) { +gb_internal lbValue lb_type_info(lbModule *m, Type *type) { GB_ASSERT(!build_context.disallow_rtti); type = default_type(type); @@ -102,36 +102,36 @@ lbValue lb_type_info(lbModule *m, Type *type) { return lb_emit_array_epi(m, data, index); } -LLVMTypeRef lb_get_procedure_raw_type(lbModule *m, Type *type) { +gb_internal LLVMTypeRef lb_get_procedure_raw_type(lbModule *m, Type *type) { return lb_type_internal_for_procedures_raw(m, type); } -lbValue lb_type_info_member_types_offset(lbProcedure *p, isize count) { +gb_internal lbValue lb_type_info_member_types_offset(lbProcedure *p, isize count) { GB_ASSERT(p->module == &p->module->gen->default_module); lbValue offset = lb_emit_array_epi(p, lb_global_type_info_member_types.addr, lb_global_type_info_member_types_index); lb_global_type_info_member_types_index += cast(i32)count; return offset; } -lbValue lb_type_info_member_names_offset(lbProcedure *p, isize count) { +gb_internal lbValue lb_type_info_member_names_offset(lbProcedure *p, isize count) { GB_ASSERT(p->module == &p->module->gen->default_module); lbValue offset = lb_emit_array_epi(p, lb_global_type_info_member_names.addr, lb_global_type_info_member_names_index); lb_global_type_info_member_names_index += cast(i32)count; return offset; } -lbValue lb_type_info_member_offsets_offset(lbProcedure *p, isize count) { +gb_internal lbValue lb_type_info_member_offsets_offset(lbProcedure *p, isize count) { GB_ASSERT(p->module == &p->module->gen->default_module); lbValue offset = lb_emit_array_epi(p, lb_global_type_info_member_offsets.addr, lb_global_type_info_member_offsets_index); lb_global_type_info_member_offsets_index += cast(i32)count; return offset; } -lbValue lb_type_info_member_usings_offset(lbProcedure *p, isize count) { +gb_internal lbValue lb_type_info_member_usings_offset(lbProcedure *p, isize count) { GB_ASSERT(p->module == &p->module->gen->default_module); lbValue offset = lb_emit_array_epi(p, lb_global_type_info_member_usings.addr, lb_global_type_info_member_usings_index); lb_global_type_info_member_usings_index += cast(i32)count; return offset; } -lbValue lb_type_info_member_tags_offset(lbProcedure *p, isize count) { +gb_internal lbValue lb_type_info_member_tags_offset(lbProcedure *p, isize count) { GB_ASSERT(p->module == &p->module->gen->default_module); lbValue offset = lb_emit_array_epi(p, lb_global_type_info_member_tags.addr, lb_global_type_info_member_tags_index); lb_global_type_info_member_tags_index += cast(i32)count; @@ -139,7 +139,7 @@ lbValue lb_type_info_member_tags_offset(lbProcedure *p, isize count) { } -void lb_setup_type_info_data(lbProcedure *p) { // NOTE(bill): Setup type_info data +gb_internal void lb_setup_type_info_data(lbProcedure *p) { // NOTE(bill): Setup type_info data if (build_context.disallow_rtti) { return; } diff --git a/src/llvm_backend_utility.cpp b/src/llvm_backend_utility.cpp index 3ae9aba8f..94b900278 100644 --- a/src/llvm_backend_utility.cpp +++ b/src/llvm_backend_utility.cpp @@ -1,6 +1,6 @@ -lbValue lb_lookup_runtime_procedure(lbModule *m, String const &name); +gb_internal lbValue lb_lookup_runtime_procedure(lbModule *m, String const &name); -bool lb_is_type_aggregate(Type *t) { +gb_internal bool lb_is_type_aggregate(Type *t) { t = base_type(t); switch (t->kind) { case Type_Basic: @@ -39,7 +39,7 @@ bool lb_is_type_aggregate(Type *t) { return false; } -void lb_emit_unreachable(lbProcedure *p) { +gb_internal void lb_emit_unreachable(lbProcedure *p) { LLVMValueRef instr = LLVMGetLastInstruction(p->curr_block->block); if (instr == nullptr || !lb_is_instr_terminating(instr)) { lb_call_intrinsic(p, "llvm.trap", nullptr, 0, nullptr, 0); @@ -47,7 +47,7 @@ void lb_emit_unreachable(lbProcedure *p) { } } -lbValue lb_correct_endianness(lbProcedure *p, lbValue value) { +gb_internal lbValue lb_correct_endianness(lbProcedure *p, lbValue value) { Type *src = core_type(value.type); GB_ASSERT(is_type_integer(src) || is_type_float(src)); if (is_type_different_to_arch_endianness(src)) { @@ -57,7 +57,7 @@ lbValue lb_correct_endianness(lbProcedure *p, lbValue value) { return value; } -LLVMValueRef lb_mem_zero_ptr_internal(lbProcedure *p, LLVMValueRef ptr, LLVMValueRef len, unsigned alignment, bool is_volatile) { +gb_internal LLVMValueRef lb_mem_zero_ptr_internal(lbProcedure *p, LLVMValueRef ptr, LLVMValueRef len, unsigned alignment, bool is_volatile) { bool is_inlinable = false; i64 const_len = 0; @@ -103,7 +103,7 @@ LLVMValueRef lb_mem_zero_ptr_internal(lbProcedure *p, LLVMValueRef ptr, LLVMValu } -void lb_mem_zero_ptr(lbProcedure *p, LLVMValueRef ptr, Type *type, unsigned alignment) { +gb_internal void lb_mem_zero_ptr(lbProcedure *p, LLVMValueRef ptr, Type *type, unsigned alignment) { LLVMTypeRef llvm_type = lb_type(p->module, type); LLVMTypeKind kind = LLVMGetTypeKind(llvm_type); @@ -123,7 +123,7 @@ void lb_mem_zero_ptr(lbProcedure *p, LLVMValueRef ptr, Type *type, unsigned alig } } -lbValue lb_emit_select(lbProcedure *p, lbValue cond, lbValue x, lbValue y) { +gb_internal lbValue lb_emit_select(lbProcedure *p, lbValue cond, lbValue x, lbValue y) { cond = lb_emit_conv(p, cond, t_llvm_bool); lbValue res = {}; res.value = LLVMBuildSelect(p->builder, cond.value, x.value, y.value, ""); @@ -131,19 +131,19 @@ lbValue lb_emit_select(lbProcedure *p, lbValue cond, lbValue x, lbValue y) { return res; } -lbValue lb_emit_min(lbProcedure *p, Type *t, lbValue x, lbValue y) { +gb_internal lbValue lb_emit_min(lbProcedure *p, Type *t, lbValue x, lbValue y) { x = lb_emit_conv(p, x, t); y = lb_emit_conv(p, y, t); return lb_emit_select(p, lb_emit_comp(p, Token_Lt, x, y), x, y); } -lbValue lb_emit_max(lbProcedure *p, Type *t, lbValue x, lbValue y) { +gb_internal lbValue lb_emit_max(lbProcedure *p, Type *t, lbValue x, lbValue y) { x = lb_emit_conv(p, x, t); y = lb_emit_conv(p, y, t); return lb_emit_select(p, lb_emit_comp(p, Token_Gt, x, y), x, y); } -lbValue lb_emit_clamp(lbProcedure *p, Type *t, lbValue x, lbValue min, lbValue max) { +gb_internal lbValue lb_emit_clamp(lbProcedure *p, Type *t, lbValue x, lbValue min, lbValue max) { lbValue z = {}; z = lb_emit_max(p, t, x, min); z = lb_emit_min(p, t, z, max); @@ -152,7 +152,7 @@ lbValue lb_emit_clamp(lbProcedure *p, Type *t, lbValue x, lbValue min, lbValue m -lbValue lb_emit_string(lbProcedure *p, lbValue str_elem, lbValue str_len) { +gb_internal lbValue lb_emit_string(lbProcedure *p, lbValue str_elem, lbValue str_len) { if (false && lb_is_const(str_elem) && lb_is_const(str_len)) { LLVMValueRef values[2] = { str_elem.value, @@ -171,7 +171,7 @@ lbValue lb_emit_string(lbProcedure *p, lbValue str_elem, lbValue str_len) { } -lbValue lb_emit_transmute(lbProcedure *p, lbValue value, Type *t) { +gb_internal lbValue lb_emit_transmute(lbProcedure *p, lbValue value, Type *t) { Type *src_type = value.type; if (are_types_identical(t, src_type)) { return value; @@ -259,7 +259,7 @@ lbValue lb_emit_transmute(lbProcedure *p, lbValue value, Type *t) { return res; } -lbValue lb_copy_value_to_ptr(lbProcedure *p, lbValue val, Type *new_type, i64 alignment) { +gb_internal lbValue lb_copy_value_to_ptr(lbProcedure *p, lbValue val, Type *new_type, i64 alignment) { i64 type_alignment = type_align_of(new_type); if (alignment < type_alignment) { alignment = type_alignment; @@ -274,7 +274,7 @@ lbValue lb_copy_value_to_ptr(lbProcedure *p, lbValue val, Type *new_type, i64 al } -lbValue lb_soa_zip(lbProcedure *p, AstCallExpr *ce, TypeAndValue const &tv) { +gb_internal lbValue lb_soa_zip(lbProcedure *p, AstCallExpr *ce, TypeAndValue const &tv) { GB_ASSERT(ce->args.count > 0); auto slices = slice_make(temporary_allocator(), ce->args.count); @@ -305,7 +305,7 @@ lbValue lb_soa_zip(lbProcedure *p, AstCallExpr *ce, TypeAndValue const &tv) { return lb_addr_load(p, res); } -lbValue lb_soa_unzip(lbProcedure *p, AstCallExpr *ce, TypeAndValue const &tv) { +gb_internal lbValue lb_soa_unzip(lbProcedure *p, AstCallExpr *ce, TypeAndValue const &tv) { GB_ASSERT(ce->args.count == 1); lbValue arg = lb_build_expr(p, ce->args[0]); @@ -331,7 +331,7 @@ lbValue lb_soa_unzip(lbProcedure *p, AstCallExpr *ce, TypeAndValue const &tv) { return lb_addr_load(p, res); } -void lb_emit_try_lhs_rhs(lbProcedure *p, Ast *arg, TypeAndValue const &tv, lbValue *lhs_, lbValue *rhs_) { +gb_internal void lb_emit_try_lhs_rhs(lbProcedure *p, Ast *arg, TypeAndValue const &tv, lbValue *lhs_, lbValue *rhs_) { lbValue lhs = {}; lbValue rhs = {}; @@ -360,7 +360,7 @@ void lb_emit_try_lhs_rhs(lbProcedure *p, Ast *arg, TypeAndValue const &tv, lbVal } -lbValue lb_emit_try_has_value(lbProcedure *p, lbValue rhs) { +gb_internal lbValue lb_emit_try_has_value(lbProcedure *p, lbValue rhs) { lbValue has_value = {}; if (is_type_boolean(rhs.type)) { has_value = rhs; @@ -373,7 +373,7 @@ lbValue lb_emit_try_has_value(lbProcedure *p, lbValue rhs) { } -lbValue lb_emit_or_else(lbProcedure *p, Ast *arg, Ast *else_expr, TypeAndValue const &tv) { +gb_internal lbValue lb_emit_or_else(lbProcedure *p, Ast *arg, Ast *else_expr, TypeAndValue const &tv) { if (arg->state_flags & StateFlag_DirectiveWasFalse) { return lb_build_expr(p, else_expr); } @@ -435,10 +435,10 @@ lbValue lb_emit_or_else(lbProcedure *p, Ast *arg, Ast *else_expr, TypeAndValue c } } -void lb_build_return_stmt(lbProcedure *p, Slice const &return_results); -void lb_build_return_stmt_internal(lbProcedure *p, lbValue res); +gb_internal void lb_build_return_stmt(lbProcedure *p, Slice const &return_results); +gb_internal void lb_build_return_stmt_internal(lbProcedure *p, lbValue res); -lbValue lb_emit_or_return(lbProcedure *p, Ast *arg, TypeAndValue const &tv) { +gb_internal lbValue lb_emit_or_return(lbProcedure *p, Ast *arg, TypeAndValue const &tv) { lbValue lhs = {}; lbValue rhs = {}; lb_emit_try_lhs_rhs(p, arg, tv, &lhs, &rhs); @@ -479,7 +479,7 @@ lbValue lb_emit_or_return(lbProcedure *p, Ast *arg, TypeAndValue const &tv) { } -void lb_emit_increment(lbProcedure *p, lbValue addr) { +gb_internal void lb_emit_increment(lbProcedure *p, lbValue addr) { GB_ASSERT(is_type_pointer(addr.type)); Type *type = type_deref(addr.type); lbValue v_one = lb_const_value(p->module, type, exact_value_i64(1)); @@ -487,7 +487,7 @@ void lb_emit_increment(lbProcedure *p, lbValue addr) { } -lbValue lb_emit_byte_swap(lbProcedure *p, lbValue value, Type *end_type) { +gb_internal lbValue lb_emit_byte_swap(lbProcedure *p, lbValue value, Type *end_type) { GB_ASSERT(type_size_of(value.type) == type_size_of(end_type)); if (type_size_of(value.type) < 2) { @@ -526,7 +526,7 @@ lbValue lb_emit_byte_swap(lbProcedure *p, lbValue value, Type *end_type) { -lbValue lb_emit_count_ones(lbProcedure *p, lbValue x, Type *type) { +gb_internal lbValue lb_emit_count_ones(lbProcedure *p, lbValue x, Type *type) { x = lb_emit_conv(p, x, type); char const *name = "llvm.ctpop"; @@ -539,7 +539,7 @@ lbValue lb_emit_count_ones(lbProcedure *p, lbValue x, Type *type) { return res; } -lbValue lb_emit_count_zeros(lbProcedure *p, lbValue x, Type *type) { +gb_internal lbValue lb_emit_count_zeros(lbProcedure *p, lbValue x, Type *type) { Type *elem = base_array_type(type); i64 sz = 8*type_size_of(elem); lbValue size = lb_const_int(p->module, elem, cast(u64)sz); @@ -550,7 +550,7 @@ lbValue lb_emit_count_zeros(lbProcedure *p, lbValue x, Type *type) { -lbValue lb_emit_count_trailing_zeros(lbProcedure *p, lbValue x, Type *type) { +gb_internal lbValue lb_emit_count_trailing_zeros(lbProcedure *p, lbValue x, Type *type) { x = lb_emit_conv(p, x, type); char const *name = "llvm.cttz"; @@ -566,7 +566,7 @@ lbValue lb_emit_count_trailing_zeros(lbProcedure *p, lbValue x, Type *type) { return res; } -lbValue lb_emit_count_leading_zeros(lbProcedure *p, lbValue x, Type *type) { +gb_internal lbValue lb_emit_count_leading_zeros(lbProcedure *p, lbValue x, Type *type) { x = lb_emit_conv(p, x, type); char const *name = "llvm.ctlz"; @@ -584,7 +584,7 @@ lbValue lb_emit_count_leading_zeros(lbProcedure *p, lbValue x, Type *type) { -lbValue lb_emit_reverse_bits(lbProcedure *p, lbValue x, Type *type) { +gb_internal lbValue lb_emit_reverse_bits(lbProcedure *p, lbValue x, Type *type) { x = lb_emit_conv(p, x, type); char const *name = "llvm.bitreverse"; @@ -599,7 +599,7 @@ lbValue lb_emit_reverse_bits(lbProcedure *p, lbValue x, Type *type) { } -lbValue lb_emit_bit_set_card(lbProcedure *p, lbValue x) { +gb_internal lbValue lb_emit_bit_set_card(lbProcedure *p, lbValue x) { GB_ASSERT(is_type_bit_set(x.type)); Type *underlying = bit_set_to_int(x.type); lbValue card = lb_emit_count_ones(p, x, underlying); @@ -607,7 +607,7 @@ lbValue lb_emit_bit_set_card(lbProcedure *p, lbValue x) { } -lbValue lb_emit_union_cast_only_ok_check(lbProcedure *p, lbValue value, Type *type, TokenPos pos) { +gb_internal lbValue lb_emit_union_cast_only_ok_check(lbProcedure *p, lbValue value, Type *type, TokenPos pos) { GB_ASSERT(is_type_tuple(type)); lbModule *m = p->module; @@ -654,7 +654,7 @@ lbValue lb_emit_union_cast_only_ok_check(lbProcedure *p, lbValue value, Type *ty return lb_addr_load(p, v); } -lbValue lb_emit_union_cast(lbProcedure *p, lbValue value, Type *type, TokenPos pos) { +gb_internal lbValue lb_emit_union_cast(lbProcedure *p, lbValue value, Type *type, TokenPos pos) { lbModule *m = p->module; Type *src_type = value.type; @@ -753,7 +753,7 @@ lbValue lb_emit_union_cast(lbProcedure *p, lbValue value, Type *type, TokenPos p return lb_addr_load(p, v); } -lbAddr lb_emit_any_cast_addr(lbProcedure *p, lbValue value, Type *type, TokenPos pos) { +gb_internal lbAddr lb_emit_any_cast_addr(lbProcedure *p, lbValue value, Type *type, TokenPos pos) { lbModule *m = p->module; Type *src_type = value.type; @@ -826,13 +826,13 @@ lbAddr lb_emit_any_cast_addr(lbProcedure *p, lbValue value, Type *type, TokenPos } return v; } -lbValue lb_emit_any_cast(lbProcedure *p, lbValue value, Type *type, TokenPos pos) { +gb_internal lbValue lb_emit_any_cast(lbProcedure *p, lbValue value, Type *type, TokenPos pos) { return lb_addr_load(p, lb_emit_any_cast_addr(p, value, type, pos)); } -lbAddr lb_find_or_generate_context_ptr(lbProcedure *p) { +gb_internal lbAddr lb_find_or_generate_context_ptr(lbProcedure *p) { if (p->context_stack.count > 0) { return p->context_stack[p->context_stack.count-1].ctx; } @@ -850,7 +850,7 @@ lbAddr lb_find_or_generate_context_ptr(lbProcedure *p) { return c; } -lbValue lb_address_from_load_or_generate_local(lbProcedure *p, lbValue value) { +gb_internal lbValue lb_address_from_load_or_generate_local(lbProcedure *p, lbValue value) { if (LLVMIsALoadInst(value.value)) { lbValue res = {}; res.value = LLVMGetOperand(value.value, 0); @@ -864,7 +864,7 @@ lbValue lb_address_from_load_or_generate_local(lbProcedure *p, lbValue value) { lb_addr_store(p, res, value); return res.addr; } -lbValue lb_address_from_load(lbProcedure *p, lbValue value) { +gb_internal lbValue lb_address_from_load(lbProcedure *p, lbValue value) { if (LLVMIsALoadInst(value.value)) { lbValue res = {}; res.value = LLVMGetOperand(value.value, 0); @@ -877,7 +877,7 @@ lbValue lb_address_from_load(lbProcedure *p, lbValue value) { } -lbStructFieldRemapping lb_get_struct_remapping(lbModule *m, Type *t) { +gb_internal lbStructFieldRemapping lb_get_struct_remapping(lbModule *m, Type *t) { t = base_type(t); LLVMTypeRef struct_type = lb_type(m, t); auto *field_remapping = map_get(&m->struct_field_remapping, cast(void *)struct_type); @@ -888,7 +888,7 @@ lbStructFieldRemapping lb_get_struct_remapping(lbModule *m, Type *t) { return *field_remapping; } -i32 lb_convert_struct_index(lbModule *m, Type *t, i32 index) { +gb_internal i32 lb_convert_struct_index(lbModule *m, Type *t, i32 index) { if (t->kind == Type_Struct) { auto field_remapping = lb_get_struct_remapping(m, t); index = field_remapping[index]; @@ -896,7 +896,7 @@ i32 lb_convert_struct_index(lbModule *m, Type *t, i32 index) { return index; } -LLVMTypeRef lb_type_padding_filler(lbModule *m, i64 padding, i64 padding_align) { +gb_internal LLVMTypeRef lb_type_padding_filler(lbModule *m, i64 padding, i64 padding_align) { // NOTE(bill): limit to `[N x u64]` to prevent ABI issues padding_align = gb_clamp(padding_align, 1, 8); if (padding % padding_align == 0) { @@ -921,7 +921,7 @@ LLVMTypeRef lb_type_padding_filler(lbModule *m, i64 padding, i64 padding_align) } -char const *llvm_type_kinds[] = { +gb_global char const *llvm_type_kinds[] = { "LLVMVoidTypeKind", "LLVMHalfTypeKind", "LLVMFloatTypeKind", @@ -973,7 +973,7 @@ gb_internal lbValue lb_emit_struct_ep_internal(lbProcedure *p, lbValue s, i32 in } } -lbValue lb_emit_tuple_ep(lbProcedure *p, lbValue ptr, i32 index) { +gb_internal lbValue lb_emit_tuple_ep(lbProcedure *p, lbValue ptr, i32 index) { Type *t = type_deref(ptr.type); GB_ASSERT(is_type_tuple(t)); Type *result_type = t->Tuple.variables[index]->type; @@ -991,7 +991,7 @@ lbValue lb_emit_tuple_ep(lbProcedure *p, lbValue ptr, i32 index) { } -lbValue lb_emit_struct_ep(lbProcedure *p, lbValue s, i32 index) { +gb_internal lbValue lb_emit_struct_ep(lbProcedure *p, lbValue s, i32 index) { GB_ASSERT(is_type_pointer(s.type)); Type *t = base_type(type_deref(s.type)); Type *result_type = nullptr; @@ -1074,7 +1074,7 @@ lbValue lb_emit_struct_ep(lbProcedure *p, lbValue s, i32 index) { return lb_emit_struct_ep_internal(p, s, index, result_type); } -lbValue lb_emit_tuple_ev(lbProcedure *p, lbValue value, i32 index) { +gb_internal lbValue lb_emit_tuple_ev(lbProcedure *p, lbValue value, i32 index) { Type *t = value.type; GB_ASSERT(is_type_tuple(t)); Type *result_type = t->Tuple.variables[index]->type; @@ -1104,7 +1104,7 @@ lbValue lb_emit_tuple_ev(lbProcedure *p, lbValue value, i32 index) { return res; } -lbValue lb_emit_struct_ev(lbProcedure *p, lbValue s, i32 index) { +gb_internal lbValue lb_emit_struct_ev(lbProcedure *p, lbValue s, i32 index) { Type *t = base_type(s.type); if (is_type_tuple(t)) { return lb_emit_tuple_ev(p, s, index); @@ -1223,7 +1223,7 @@ lbValue lb_emit_struct_ev(lbProcedure *p, lbValue s, i32 index) { return res; } -lbValue lb_emit_deep_field_gep(lbProcedure *p, lbValue e, Selection sel) { +gb_internal lbValue lb_emit_deep_field_gep(lbProcedure *p, lbValue e, Selection sel) { GB_ASSERT(sel.index.count > 0); Type *type = type_deref(e.type); @@ -1311,14 +1311,14 @@ lbValue lb_emit_deep_field_gep(lbProcedure *p, lbValue e, Selection sel) { } -lbValue lb_emit_deep_field_ev(lbProcedure *p, lbValue e, Selection sel) { +gb_internal lbValue lb_emit_deep_field_ev(lbProcedure *p, lbValue e, Selection sel) { lbValue ptr = lb_address_from_load_or_generate_local(p, e); lbValue res = lb_emit_deep_field_gep(p, ptr, sel); return lb_emit_load(p, res); } -lbValue lb_emit_array_ep(lbProcedure *p, lbValue s, lbValue index) { +gb_internal lbValue lb_emit_array_ep(lbProcedure *p, lbValue s, lbValue index) { Type *t = s.type; GB_ASSERT_MSG(is_type_pointer(t), "%s", type_to_string(t)); Type *st = base_type(type_deref(t)); @@ -1341,7 +1341,7 @@ lbValue lb_emit_array_ep(lbProcedure *p, lbValue s, lbValue index) { return res; } -lbValue lb_emit_array_epi(lbProcedure *p, lbValue s, isize index) { +gb_internal lbValue lb_emit_array_epi(lbProcedure *p, lbValue s, isize index) { Type *t = s.type; GB_ASSERT(is_type_pointer(t)); Type *st = base_type(type_deref(t)); @@ -1349,7 +1349,7 @@ lbValue lb_emit_array_epi(lbProcedure *p, lbValue s, isize index) { GB_ASSERT(0 <= index); return lb_emit_epi(p, s, index); } -lbValue lb_emit_array_epi(lbModule *m, lbValue s, isize index) { +gb_internal lbValue lb_emit_array_epi(lbModule *m, lbValue s, isize index) { Type *t = s.type; GB_ASSERT(is_type_pointer(t)); Type *st = base_type(type_deref(t)); @@ -1358,7 +1358,7 @@ lbValue lb_emit_array_epi(lbModule *m, lbValue s, isize index) { return lb_emit_epi(m, s, index); } -lbValue lb_emit_ptr_offset(lbProcedure *p, lbValue ptr, lbValue index) { +gb_internal lbValue lb_emit_ptr_offset(lbProcedure *p, lbValue ptr, lbValue index) { index = lb_emit_conv(p, index, t_int); LLVMValueRef indices[1] = {index.value}; lbValue res = {}; @@ -1373,7 +1373,7 @@ lbValue lb_emit_ptr_offset(lbProcedure *p, lbValue ptr, lbValue index) { return res; } -lbValue lb_emit_matrix_epi(lbProcedure *p, lbValue s, isize row, isize column) { +gb_internal lbValue lb_emit_matrix_epi(lbProcedure *p, lbValue s, isize row, isize column) { Type *t = s.type; GB_ASSERT(is_type_pointer(t)); Type *mt = base_type(type_deref(t)); @@ -1391,7 +1391,7 @@ lbValue lb_emit_matrix_epi(lbProcedure *p, lbValue s, isize row, isize column) { return lb_emit_epi(p, s, offset); } -lbValue lb_emit_matrix_ep(lbProcedure *p, lbValue s, lbValue row, lbValue column) { +gb_internal lbValue lb_emit_matrix_ep(lbProcedure *p, lbValue s, lbValue row, lbValue column) { Type *t = s.type; GB_ASSERT(is_type_pointer(t)); Type *mt = base_type(type_deref(t)); @@ -1423,7 +1423,7 @@ lbValue lb_emit_matrix_ep(lbProcedure *p, lbValue s, lbValue row, lbValue column } -lbValue lb_emit_matrix_ev(lbProcedure *p, lbValue s, isize row, isize column) { +gb_internal lbValue lb_emit_matrix_ev(lbProcedure *p, lbValue s, isize row, isize column) { Type *st = base_type(s.type); GB_ASSERT_MSG(is_type_matrix(st), "%s", type_to_string(st)); @@ -1433,14 +1433,14 @@ lbValue lb_emit_matrix_ev(lbProcedure *p, lbValue s, isize row, isize column) { } -void lb_fill_slice(lbProcedure *p, lbAddr const &slice, lbValue base_elem, lbValue len) { +gb_internal void lb_fill_slice(lbProcedure *p, lbAddr const &slice, lbValue base_elem, lbValue len) { Type *t = lb_addr_type(slice); GB_ASSERT(is_type_slice(t)); lbValue ptr = lb_addr_get_ptr(p, slice); lb_emit_store(p, lb_emit_struct_ep(p, ptr, 0), base_elem); lb_emit_store(p, lb_emit_struct_ep(p, ptr, 1), len); } -void lb_fill_string(lbProcedure *p, lbAddr const &string, lbValue base_elem, lbValue len) { +gb_internal void lb_fill_string(lbProcedure *p, lbAddr const &string, lbValue base_elem, lbValue len) { Type *t = lb_addr_type(string); GB_ASSERT(is_type_string(t)); lbValue ptr = lb_addr_get_ptr(p, string); @@ -1448,18 +1448,18 @@ void lb_fill_string(lbProcedure *p, lbAddr const &string, lbValue base_elem, lbV lb_emit_store(p, lb_emit_struct_ep(p, ptr, 1), len); } -lbValue lb_string_elem(lbProcedure *p, lbValue string) { +gb_internal lbValue lb_string_elem(lbProcedure *p, lbValue string) { Type *t = base_type(string.type); GB_ASSERT(t->kind == Type_Basic && t->Basic.kind == Basic_string); return lb_emit_struct_ev(p, string, 0); } -lbValue lb_string_len(lbProcedure *p, lbValue string) { +gb_internal lbValue lb_string_len(lbProcedure *p, lbValue string) { Type *t = base_type(string.type); GB_ASSERT_MSG(t->kind == Type_Basic && t->Basic.kind == Basic_string, "%s", type_to_string(t)); return lb_emit_struct_ev(p, string, 1); } -lbValue lb_cstring_len(lbProcedure *p, lbValue value) { +gb_internal lbValue lb_cstring_len(lbProcedure *p, lbValue value) { GB_ASSERT(is_type_cstring(value.type)); auto args = array_make(permanent_allocator(), 1); args[0] = lb_emit_conv(p, value, t_cstring); @@ -1467,43 +1467,43 @@ lbValue lb_cstring_len(lbProcedure *p, lbValue value) { } -lbValue lb_array_elem(lbProcedure *p, lbValue array_ptr) { +gb_internal lbValue lb_array_elem(lbProcedure *p, lbValue array_ptr) { Type *t = type_deref(array_ptr.type); GB_ASSERT(is_type_array(t)); return lb_emit_struct_ep(p, array_ptr, 0); } -lbValue lb_slice_elem(lbProcedure *p, lbValue slice) { +gb_internal lbValue lb_slice_elem(lbProcedure *p, lbValue slice) { GB_ASSERT(is_type_slice(slice.type)); return lb_emit_struct_ev(p, slice, 0); } -lbValue lb_slice_len(lbProcedure *p, lbValue slice) { +gb_internal lbValue lb_slice_len(lbProcedure *p, lbValue slice) { GB_ASSERT(is_type_slice(slice.type) || is_type_relative_slice(slice.type)); return lb_emit_struct_ev(p, slice, 1); } -lbValue lb_dynamic_array_elem(lbProcedure *p, lbValue da) { +gb_internal lbValue lb_dynamic_array_elem(lbProcedure *p, lbValue da) { GB_ASSERT(is_type_dynamic_array(da.type)); return lb_emit_struct_ev(p, da, 0); } -lbValue lb_dynamic_array_len(lbProcedure *p, lbValue da) { +gb_internal lbValue lb_dynamic_array_len(lbProcedure *p, lbValue da) { GB_ASSERT(is_type_dynamic_array(da.type)); return lb_emit_struct_ev(p, da, 1); } -lbValue lb_dynamic_array_cap(lbProcedure *p, lbValue da) { +gb_internal lbValue lb_dynamic_array_cap(lbProcedure *p, lbValue da) { GB_ASSERT(is_type_dynamic_array(da.type)); return lb_emit_struct_ev(p, da, 2); } -lbValue lb_dynamic_array_allocator(lbProcedure *p, lbValue da) { +gb_internal lbValue lb_dynamic_array_allocator(lbProcedure *p, lbValue da) { GB_ASSERT(is_type_dynamic_array(da.type)); return lb_emit_struct_ev(p, da, 3); } -lbValue lb_map_len(lbProcedure *p, lbValue value) { +gb_internal lbValue lb_map_len(lbProcedure *p, lbValue value) { GB_ASSERT_MSG(is_type_map(value.type) || are_types_identical(value.type, t_raw_map), "%s", type_to_string(value.type)); lbValue len = lb_emit_struct_ev(p, value, 1); return lb_emit_conv(p, len, t_int); } -lbValue lb_map_len_ptr(lbProcedure *p, lbValue map_ptr) { +gb_internal lbValue lb_map_len_ptr(lbProcedure *p, lbValue map_ptr) { Type *type = map_ptr.type; GB_ASSERT(is_type_pointer(type)); type = type_deref(type); @@ -1511,7 +1511,7 @@ lbValue lb_map_len_ptr(lbProcedure *p, lbValue map_ptr) { return lb_emit_struct_ep(p, map_ptr, 1); } -lbValue lb_map_cap(lbProcedure *p, lbValue value) { +gb_internal lbValue lb_map_cap(lbProcedure *p, lbValue value) { GB_ASSERT_MSG(is_type_map(value.type) || are_types_identical(value.type, t_raw_map), "%s", type_to_string(value.type)); lbValue zero = lb_const_int(p->module, t_uintptr, 0); lbValue one = lb_const_int(p->module, t_uintptr, 1); @@ -1525,7 +1525,7 @@ lbValue lb_map_cap(lbProcedure *p, lbValue value) { return lb_emit_conv(p, lb_emit_select(p, cmp, zero, cap), t_int); } -lbValue lb_map_data_uintptr(lbProcedure *p, lbValue value) { +gb_internal lbValue lb_map_data_uintptr(lbProcedure *p, lbValue value) { GB_ASSERT(is_type_map(value.type) || are_types_identical(value.type, t_raw_map)); lbValue data = lb_emit_struct_ev(p, value, 0); u64 mask_value = 0; @@ -1539,7 +1539,7 @@ lbValue lb_map_data_uintptr(lbProcedure *p, lbValue value) { } -lbValue lb_soa_struct_len(lbProcedure *p, lbValue value) { +gb_internal lbValue lb_soa_struct_len(lbProcedure *p, lbValue value) { Type *t = base_type(value.type); bool is_ptr = false; if (is_type_pointer(t)) { @@ -1572,7 +1572,7 @@ lbValue lb_soa_struct_len(lbProcedure *p, lbValue value) { return lb_emit_struct_ev(p, value, cast(i32)n); } -lbValue lb_soa_struct_cap(lbProcedure *p, lbValue value) { +gb_internal lbValue lb_soa_struct_cap(lbProcedure *p, lbValue value) { Type *t = base_type(value.type); bool is_ptr = false; @@ -1604,7 +1604,7 @@ lbValue lb_soa_struct_cap(lbProcedure *p, lbValue value) { return lb_emit_struct_ev(p, value, cast(i32)n); } -lbValue lb_emit_mul_add(lbProcedure *p, lbValue a, lbValue b, lbValue c, Type *t) { +gb_internal lbValue lb_emit_mul_add(lbProcedure *p, lbValue a, lbValue b, lbValue c, Type *t) { lbModule *m = p->module; a = lb_emit_conv(p, a, t); @@ -1647,7 +1647,7 @@ lbValue lb_emit_mul_add(lbProcedure *p, lbValue a, lbValue b, lbValue c, Type *t } } -LLVMValueRef llvm_mask_iota(lbModule *m, unsigned start, unsigned count) { +gb_internal LLVMValueRef llvm_mask_iota(lbModule *m, unsigned start, unsigned count) { auto iota = slice_make(temporary_allocator(), count); for (unsigned i = 0; i < count; i++) { iota[i] = lb_const_int(m, t_u32, start+i).value; @@ -1655,7 +1655,7 @@ LLVMValueRef llvm_mask_iota(lbModule *m, unsigned start, unsigned count) { return LLVMConstVector(iota.data, count); } -LLVMValueRef llvm_mask_zero(lbModule *m, unsigned count) { +gb_internal LLVMValueRef llvm_mask_zero(lbModule *m, unsigned count) { return LLVMConstNull(LLVMVectorType(lb_type(m, t_u32), count)); } @@ -1663,16 +1663,16 @@ LLVMValueRef llvm_mask_zero(lbModule *m, unsigned count) { // #define LLVM_VECTOR_DUMMY_VALUE(type) LLVMConstNull((type)) -LLVMValueRef llvm_basic_shuffle(lbProcedure *p, LLVMValueRef vector, LLVMValueRef mask) { +gb_internal LLVMValueRef llvm_basic_shuffle(lbProcedure *p, LLVMValueRef vector, LLVMValueRef mask) { return LLVMBuildShuffleVector(p->builder, vector, LLVM_VECTOR_DUMMY_VALUE(LLVMTypeOf(vector)), mask, ""); } -LLVMValueRef llvm_basic_const_shuffle(LLVMValueRef vector, LLVMValueRef mask) { +gb_internal LLVMValueRef llvm_basic_const_shuffle(LLVMValueRef vector, LLVMValueRef mask) { return LLVMConstShuffleVector(vector, LLVM_VECTOR_DUMMY_VALUE(LLVMTypeOf(vector)), mask); } -LLVMValueRef llvm_vector_broadcast(lbProcedure *p, LLVMValueRef value, unsigned count) { +gb_internal LLVMValueRef llvm_vector_broadcast(lbProcedure *p, LLVMValueRef value, unsigned count) { GB_ASSERT(count > 0); if (LLVMIsConstant(value)) { LLVMValueRef single = LLVMConstVector(&value, 1); @@ -1692,7 +1692,7 @@ LLVMValueRef llvm_vector_broadcast(lbProcedure *p, LLVMValueRef value, unsigned return llvm_basic_shuffle(p, single, mask); } -LLVMValueRef llvm_vector_shuffle_reduction(lbProcedure *p, LLVMValueRef value, LLVMOpcode op_code) { +gb_internal LLVMValueRef llvm_vector_shuffle_reduction(lbProcedure *p, LLVMValueRef value, LLVMOpcode op_code) { LLVMTypeRef original_vector_type = LLVMTypeOf(value); GB_ASSERT(LLVMGetTypeKind(original_vector_type) == LLVMVectorTypeKind); @@ -1719,7 +1719,7 @@ LLVMValueRef llvm_vector_shuffle_reduction(lbProcedure *p, LLVMValueRef value, L return LLVMBuildExtractElement(p->builder, value, v_zero32, ""); } -LLVMValueRef llvm_vector_expand_to_power_of_two(lbProcedure *p, LLVMValueRef value) { +gb_internal LLVMValueRef llvm_vector_expand_to_power_of_two(lbProcedure *p, LLVMValueRef value) { LLVMTypeRef vector_type = LLVMTypeOf(value); unsigned len = LLVMGetVectorSize(vector_type); if (len == 1) { @@ -1734,7 +1734,7 @@ LLVMValueRef llvm_vector_expand_to_power_of_two(lbProcedure *p, LLVMValueRef val return LLVMBuildShuffleVector(p->builder, value, LLVMConstNull(vector_type), mask, ""); } -LLVMValueRef llvm_vector_reduce_add(lbProcedure *p, LLVMValueRef value) { +gb_internal LLVMValueRef llvm_vector_reduce_add(lbProcedure *p, LLVMValueRef value) { LLVMTypeRef type = LLVMTypeOf(value); GB_ASSERT(LLVMGetTypeKind(type) == LLVMVectorTypeKind); LLVMTypeRef elem = OdinLLVMGetVectorElementType(type); @@ -1810,7 +1810,7 @@ LLVMValueRef llvm_vector_reduce_add(lbProcedure *p, LLVMValueRef value) { #endif } -LLVMValueRef llvm_vector_add(lbProcedure *p, LLVMValueRef a, LLVMValueRef b) { +gb_internal LLVMValueRef llvm_vector_add(lbProcedure *p, LLVMValueRef a, LLVMValueRef b) { GB_ASSERT(LLVMTypeOf(a) == LLVMTypeOf(b)); LLVMTypeRef elem = OdinLLVMGetVectorElementType(LLVMTypeOf(a)); @@ -1821,7 +1821,7 @@ LLVMValueRef llvm_vector_add(lbProcedure *p, LLVMValueRef a, LLVMValueRef b) { return LLVMBuildFAdd(p->builder, a, b, ""); } -LLVMValueRef llvm_vector_mul(lbProcedure *p, LLVMValueRef a, LLVMValueRef b) { +gb_internal LLVMValueRef llvm_vector_mul(lbProcedure *p, LLVMValueRef a, LLVMValueRef b) { GB_ASSERT(LLVMTypeOf(a) == LLVMTypeOf(b)); LLVMTypeRef elem = OdinLLVMGetVectorElementType(LLVMTypeOf(a)); @@ -1833,11 +1833,11 @@ LLVMValueRef llvm_vector_mul(lbProcedure *p, LLVMValueRef a, LLVMValueRef b) { } -LLVMValueRef llvm_vector_dot(lbProcedure *p, LLVMValueRef a, LLVMValueRef b) { +gb_internal LLVMValueRef llvm_vector_dot(lbProcedure *p, LLVMValueRef a, LLVMValueRef b) { return llvm_vector_reduce_add(p, llvm_vector_mul(p, a, b)); } -LLVMValueRef llvm_vector_mul_add(lbProcedure *p, LLVMValueRef a, LLVMValueRef b, LLVMValueRef c) { +gb_internal LLVMValueRef llvm_vector_mul_add(lbProcedure *p, LLVMValueRef a, LLVMValueRef b, LLVMValueRef c) { LLVMTypeRef t = LLVMTypeOf(a); GB_ASSERT(t == LLVMTypeOf(b)); @@ -1871,7 +1871,7 @@ LLVMValueRef llvm_vector_mul_add(lbProcedure *p, LLVMValueRef a, LLVMValueRef b, } } -LLVMValueRef llvm_get_inline_asm(LLVMTypeRef func_type, String const &str, String const &clobbers, bool has_side_effects=true, bool is_align_stack=false, LLVMInlineAsmDialect dialect=LLVMInlineAsmDialectATT) { +gb_internal LLVMValueRef llvm_get_inline_asm(LLVMTypeRef func_type, String const &str, String const &clobbers, bool has_side_effects=true, bool is_align_stack=false, LLVMInlineAsmDialect dialect=LLVMInlineAsmDialectATT) { return LLVMGetInlineAsm(func_type, cast(char *)str.text, cast(size_t)str.len, cast(char *)clobbers.text, cast(size_t)clobbers.len, @@ -1884,7 +1884,7 @@ LLVMValueRef llvm_get_inline_asm(LLVMTypeRef func_type, String const &str, Strin } -void lb_set_wasm_import_attributes(LLVMValueRef value, Entity *entity, String import_name) { +gb_internal void lb_set_wasm_import_attributes(LLVMValueRef value, Entity *entity, String import_name) { if (!is_arch_wasm()) { return; } @@ -1906,7 +1906,7 @@ void lb_set_wasm_import_attributes(LLVMValueRef value, Entity *entity, String im } -void lb_set_wasm_export_attributes(LLVMValueRef value, String export_name) { +gb_internal void lb_set_wasm_export_attributes(LLVMValueRef value, String export_name) { if (!is_arch_wasm()) { return; } @@ -1918,7 +1918,7 @@ void lb_set_wasm_export_attributes(LLVMValueRef value, String export_name) { -lbAddr lb_handle_objc_find_or_register_selector(lbProcedure *p, String const &name) { +gb_internal lbAddr lb_handle_objc_find_or_register_selector(lbProcedure *p, String const &name) { lbAddr *found = string_map_get(&p->module->objc_selectors, name); if (found) { return *found; @@ -1938,7 +1938,7 @@ lbAddr lb_handle_objc_find_or_register_selector(lbProcedure *p, String const &na } } -lbValue lb_handle_objc_find_selector(lbProcedure *p, Ast *expr) { +gb_internal lbValue lb_handle_objc_find_selector(lbProcedure *p, Ast *expr) { ast_node(ce, CallExpr, expr); auto tav = ce->args[0]->tav; @@ -1947,7 +1947,7 @@ lbValue lb_handle_objc_find_selector(lbProcedure *p, Ast *expr) { return lb_addr_load(p, lb_handle_objc_find_or_register_selector(p, name)); } -lbValue lb_handle_objc_register_selector(lbProcedure *p, Ast *expr) { +gb_internal lbValue lb_handle_objc_register_selector(lbProcedure *p, Ast *expr) { ast_node(ce, CallExpr, expr); lbModule *m = p->module; @@ -1964,7 +1964,7 @@ lbValue lb_handle_objc_register_selector(lbProcedure *p, Ast *expr) { return lb_addr_load(p, dst); } -lbAddr lb_handle_objc_find_or_register_class(lbProcedure *p, String const &name) { +gb_internal lbAddr lb_handle_objc_find_or_register_class(lbProcedure *p, String const &name) { lbAddr *found = string_map_get(&p->module->objc_classes, name); if (found) { return *found; @@ -1984,7 +1984,7 @@ lbAddr lb_handle_objc_find_or_register_class(lbProcedure *p, String const &name) } } -lbValue lb_handle_objc_find_class(lbProcedure *p, Ast *expr) { +gb_internal lbValue lb_handle_objc_find_class(lbProcedure *p, Ast *expr) { ast_node(ce, CallExpr, expr); auto tav = ce->args[0]->tav; @@ -1993,7 +1993,7 @@ lbValue lb_handle_objc_find_class(lbProcedure *p, Ast *expr) { return lb_addr_load(p, lb_handle_objc_find_or_register_class(p, name)); } -lbValue lb_handle_objc_register_class(lbProcedure *p, Ast *expr) { +gb_internal lbValue lb_handle_objc_register_class(lbProcedure *p, Ast *expr) { ast_node(ce, CallExpr, expr); lbModule *m = p->module; @@ -2013,7 +2013,7 @@ lbValue lb_handle_objc_register_class(lbProcedure *p, Ast *expr) { } -lbValue lb_handle_objc_id(lbProcedure *p, Ast *expr) { +gb_internal lbValue lb_handle_objc_id(lbProcedure *p, Ast *expr) { TypeAndValue const &tav = type_and_value_of_expr(expr); if (tav.mode == Addressing_Type) { Type *type = tav.type; @@ -2044,7 +2044,7 @@ lbValue lb_handle_objc_id(lbProcedure *p, Ast *expr) { return lb_build_expr(p, expr); } -lbValue lb_handle_objc_send(lbProcedure *p, Ast *expr) { +gb_internal lbValue lb_handle_objc_send(lbProcedure *p, Ast *expr) { ast_node(ce, CallExpr, expr); lbModule *m = p->module; @@ -2087,7 +2087,7 @@ lbValue lb_handle_objc_send(lbProcedure *p, Ast *expr) { -LLVMAtomicOrdering llvm_atomic_ordering_from_odin(ExactValue const &value) { +gb_internal LLVMAtomicOrdering llvm_atomic_ordering_from_odin(ExactValue const &value) { GB_ASSERT(value.kind == ExactValue_Integer); i64 v = exact_value_to_i64(value); switch (v) { @@ -2103,7 +2103,7 @@ LLVMAtomicOrdering llvm_atomic_ordering_from_odin(ExactValue const &value) { } -LLVMAtomicOrdering llvm_atomic_ordering_from_odin(Ast *expr) { +gb_internal LLVMAtomicOrdering llvm_atomic_ordering_from_odin(Ast *expr) { ExactValue value = type_and_value_of_expr(expr).value; return llvm_atomic_ordering_from_odin(value); } -- cgit v1.2.3 From c1f5be24e28c41efbbbe6d116d533b55d48bbf82 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 18 Dec 2022 22:49:10 +0000 Subject: Remove dead code in the compiler --- build.bat | 1 + src/build_settings.cpp | 6 +- src/check_decl.cpp | 10 - src/check_expr.cpp | 24 - src/check_stmt.cpp | 6 - src/checker.cpp | 140 ++---- src/checker.hpp | 8 - src/common.cpp | 9 + src/docs.cpp | 9 - src/entity.cpp | 8 - src/exact_value.cpp | 86 ++-- src/llvm_backend.cpp | 10 +- src/llvm_backend_debug.cpp | 6 - src/llvm_backend_general.cpp | 68 --- src/llvm_backend_opt.cpp | 20 +- src/llvm_backend_proc.cpp | 88 ++-- src/llvm_backend_stmt.cpp | 10 - src/llvm_backend_utility.cpp | 12 - src/main.cpp | 77 +--- src/parser.cpp | 36 -- src/parser.hpp | 5 - src/parser_pos.cpp | 2 - src/query_data.cpp | 1030 ------------------------------------------ src/range_cache.cpp | 18 +- src/string.cpp | 14 - src/string_map.cpp | 2 - src/threading.cpp | 50 +- src/types.cpp | 75 --- 28 files changed, 169 insertions(+), 1661 deletions(-) delete mode 100644 src/query_data.cpp (limited to 'src') diff --git a/build.bat b/build.bat index 7391bd95f..d7a89fe20 100644 --- a/build.bat +++ b/build.bat @@ -62,6 +62,7 @@ if %release_mode% EQU 0 ( rem Debug set compiler_warnings= ^ -W4 -WX ^ -wd4100 -wd4101 -wd4127 -wd4146 ^ + -wd4505 ^ -wd4456 -wd4457 set compiler_includes= ^ diff --git a/src/build_settings.cpp b/src/build_settings.cpp index d66db8099..7d796d775 100644 --- a/src/build_settings.cpp +++ b/src/build_settings.cpp @@ -149,7 +149,6 @@ enum CommandKind : u32 { Command_run = 1<<0, Command_build = 1<<1, Command_check = 1<<3, - Command_query = 1<<4, Command_doc = 1<<5, Command_version = 1<<6, Command_test = 1<<7, @@ -157,7 +156,7 @@ enum CommandKind : u32 { Command_strip_semicolon = 1<<8, Command_bug_report = 1<<9, - Command__does_check = Command_run|Command_build|Command_check|Command_query|Command_doc|Command_test|Command_strip_semicolon, + Command__does_check = Command_run|Command_build|Command_check|Command_doc|Command_test|Command_strip_semicolon, Command__does_build = Command_run|Command_build|Command_test, Command_all = ~(u32)0, }; @@ -166,7 +165,6 @@ gb_global char const *odin_command_strings[32] = { "run", "build", "check", - "query", "doc", "version", "test", @@ -316,8 +314,6 @@ struct BuildContext { u32 cmd_doc_flags; Array extra_packages; - QueryDataSetSettings query_data_set_settings; - StringSet test_names; gbAffinity affinity; diff --git a/src/check_decl.cpp b/src/check_decl.cpp index a976c1b73..d982a69fc 100644 --- a/src/check_decl.cpp +++ b/src/check_decl.cpp @@ -232,16 +232,6 @@ gb_internal Ast *remove_type_alias_clutter(Ast *node) { } } -gb_internal isize total_attribute_count(DeclInfo *decl) { - isize attribute_count = 0; - for_array(i, decl->attributes) { - Ast *attr = decl->attributes[i]; - if (attr->kind != Ast_Attribute) continue; - attribute_count += attr->Attribute.elems.count; - } - return attribute_count; -} - gb_internal Type *clone_enum_type(CheckerContext *ctx, Type *original_enum_type, Type *named_type) { // NOTE(bill, 2022-02-05): Stupid edge case for `distinct` declarations // diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 3003e07b6..ed1ddd1f1 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -5103,16 +5103,6 @@ gb_internal bool check_unpack_arguments(CheckerContext *ctx, Entity **lhs, isize return optional_ok; } - -gb_internal bool is_expr_constant_zero(Ast *expr) { - GB_ASSERT(expr != nullptr); - auto v = exact_value_to_integer(expr->tav.value); - if (v.kind == ExactValue_Integer) { - return big_int_cmp_zero(&v.value_integer) == 0; - } - return false; -} - gb_internal isize get_procedure_param_count_excluding_defaults(Type *pt, isize *param_count_) { GB_ASSERT(pt != nullptr); GB_ASSERT(pt->kind == Type_Proc); @@ -5429,20 +5419,6 @@ gb_internal isize lookup_procedure_parameter(TypeProc *pt, String parameter_name } return -1; } -gb_internal isize lookup_procedure_result(TypeProc *pt, String result_name) { - isize result_count = pt->result_count; - for (isize i = 0; i < result_count; i++) { - Entity *e = pt->results->Tuple.variables[i]; - String name = e->token.string; - if (is_blank_ident(name)) { - continue; - } - if (name == result_name) { - return i; - } - } - return -1; -} gb_internal CALL_ARGUMENT_CHECKER(check_named_call_arguments) { ast_node(ce, CallExpr, call); diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index cae9c3537..73adbed8b 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -1520,12 +1520,6 @@ gb_internal void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) } case_end; - case_ast_node(ts, TagStmt, node); - // TODO(bill): Tag Statements - error(node, "Tag statements are not supported yet"); - check_stmt(ctx, ts->stmt, flags); - case_end; - case_ast_node(as, AssignStmt, node); switch (as->op.kind) { case Token_Eq: { diff --git a/src/checker.cpp b/src/checker.cpp index e2c430dc2..f130a965f 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -61,18 +61,6 @@ gb_internal void scope_reserve(Scope *scope, isize capacity) { } } -gb_internal i32 is_scope_an_ancestor(Scope *parent, Scope *child) { - i32 i = 0; - while (child != nullptr) { - if (parent == child) { - return i; - } - child = child->parent; - i++; - } - return -1; -} - gb_internal void entity_graph_node_set_destroy(EntityGraphNodeSet *s) { if (s->hashes.data != nullptr) { ptr_set_destroy(s); @@ -86,9 +74,9 @@ gb_internal void entity_graph_node_set_add(EntityGraphNodeSet *s, EntityGraphNod ptr_set_add(s, n); } -gb_internal bool entity_graph_node_set_exists(EntityGraphNodeSet *s, EntityGraphNode *n) { - return ptr_set_exists(s, n); -} +// gb_internal bool entity_graph_node_set_exists(EntityGraphNodeSet *s, EntityGraphNode *n) { +// return ptr_set_exists(s, n); +// } gb_internal void entity_graph_node_set_remove(EntityGraphNodeSet *s, EntityGraphNode *n) { ptr_set_remove(s, n); @@ -139,13 +127,13 @@ gb_internal void import_graph_node_set_add(ImportGraphNodeSet *s, ImportGraphNod ptr_set_add(s, n); } -gb_internal bool import_graph_node_set_exists(ImportGraphNodeSet *s, ImportGraphNode *n) { - return ptr_set_exists(s, n); -} +// gb_internal bool import_graph_node_set_exists(ImportGraphNodeSet *s, ImportGraphNode *n) { +// return ptr_set_exists(s, n); +// } -gb_internal void import_graph_node_set_remove(ImportGraphNodeSet *s, ImportGraphNode *n) { - ptr_set_remove(s, n); -} +// gb_internal void import_graph_node_set_remove(ImportGraphNodeSet *s, ImportGraphNode *n) { +// ptr_set_remove(s, n); +// } gb_internal ImportGraphNode *import_graph_node_create(gbAllocator a, AstPackage *pkg) { ImportGraphNode *n = gb_alloc_item(a, ImportGraphNode); @@ -186,15 +174,6 @@ gb_internal void import_graph_node_swap(ImportGraphNode **data, isize i, isize j y->index = i; } -gb_internal GB_COMPARE_PROC(ast_node_cmp) { - Ast *x = *cast(Ast **)a; - Ast *y = *cast(Ast **)b; - Token i = ast_token(x); - Token j = ast_token(y); - return token_pos_cmp(i.pos, j.pos); -} - - @@ -213,27 +192,27 @@ gb_internal DeclInfo *make_decl_info(Scope *scope, DeclInfo *parent) { return d; } -gb_internal void destroy_declaration_info(DeclInfo *d) { - ptr_set_destroy(&d->deps); - array_free(&d->labels); -} +// gb_internal void destroy_declaration_info(DeclInfo *d) { +// ptr_set_destroy(&d->deps); +// array_free(&d->labels); +// } -gb_internal bool decl_info_has_init(DeclInfo *d) { - if (d->init_expr != nullptr) { - return true; - } - if (d->proc_lit != nullptr) { - switch (d->proc_lit->kind) { - case_ast_node(pl, ProcLit, d->proc_lit); - if (pl->body != nullptr) { - return true; - } - case_end; - } - } +// gb_internal bool decl_info_has_init(DeclInfo *d) { +// if (d->init_expr != nullptr) { +// return true; +// } +// if (d->proc_lit != nullptr) { +// switch (d->proc_lit->kind) { +// case_ast_node(pl, ProcLit, d->proc_lit); +// if (pl->body != nullptr) { +// return true; +// } +// case_end; +// } +// } - return false; -} +// return false; +// } @@ -528,11 +507,6 @@ struct VettedEntity { Entity *entity; Entity *other; }; -gb_internal void init_vetted_entity(VettedEntity *ve, VettedEntityKind kind, Entity *entity, Entity *other=nullptr) { - ve->kind = kind; - ve->entity = entity; - ve->other = other; -} gb_internal GB_COMPARE_PROC(vetted_entity_variable_pos_cmp) { @@ -1144,7 +1118,7 @@ gb_internal void init_checker_info(CheckerInfo *i) { - i->allow_identifier_uses = build_context.query_data_set_settings.kind == QueryDataSet_GoToDefinitions; + i->allow_identifier_uses = false; if (i->allow_identifier_uses) { array_init(&i->identifier_uses, a); } @@ -1226,13 +1200,10 @@ gb_internal CheckerContext make_checker_context(Checker *c) { ctx.type_path = new_checker_type_path(); ctx.type_level = 0; - ctx.poly_path = new_checker_poly_path(); - ctx.poly_level = 0; return ctx; } gb_internal void destroy_checker_context(CheckerContext *ctx) { destroy_checker_type_path(ctx->type_path); - destroy_checker_poly_path(ctx->poly_path); } gb_internal void add_curr_ast_file(CheckerContext *ctx, AstFile *file) { @@ -1348,17 +1319,17 @@ gb_internal DeclInfo *decl_info_of_entity(Entity *e) { return nullptr; } -gb_internal DeclInfo *decl_info_of_ident(Ast *ident) { - return decl_info_of_entity(entity_of_node(ident)); -} +// gb_internal DeclInfo *decl_info_of_ident(Ast *ident) { +// return decl_info_of_entity(entity_of_node(ident)); +// } -gb_internal AstFile *ast_file_of_filename(CheckerInfo *i, String filename) { - AstFile **found = string_map_get(&i->files, filename); - if (found != nullptr) { - return *found; - } - return nullptr; -} +// gb_internal AstFile *ast_file_of_filename(CheckerInfo *i, String filename) { +// AstFile **found = string_map_get(&i->files, filename); +// if (found != nullptr) { +// return *found; +// } +// return nullptr; +// } gb_internal ExprInfo *check_get_expr_info(CheckerContext *c, Ast *expr) { if (c->untyped != nullptr) { ExprInfo **found = map_get(c->untyped, expr); @@ -2684,32 +2655,6 @@ gb_internal Entity *check_type_path_pop(CheckerContext *c) { } -gb_internal CheckerPolyPath *new_checker_poly_path(void) { - gbAllocator a = heap_allocator(); - auto *pp = gb_alloc_item(a, CheckerPolyPath); - array_init(pp, a, 0, 16); - return pp; -} - -gb_internal void destroy_checker_poly_path(CheckerPolyPath *pp) { - array_free(pp); - gb_free(heap_allocator(), pp); -} - - -gb_internal void check_poly_path_push(CheckerContext *c, Type *t) { - GB_ASSERT(c->poly_path != nullptr); - GB_ASSERT(t != nullptr); - GB_ASSERT(is_type_polymorphic(t)); - array_add(c->poly_path, t); -} - -gb_internal Type *check_poly_path_pop(CheckerContext *c) { - GB_ASSERT(c->poly_path != nullptr); - return array_pop(c->poly_path); -} - - gb_internal Array proc_group_entities(CheckerContext *c, Operand o) { Array procs = {}; @@ -2878,13 +2823,6 @@ gb_internal ExactValue check_decl_attribute_value(CheckerContext *c, Ast *value) return ev; } -gb_internal Type *check_decl_attribute_type(CheckerContext *c, Ast *value) { - if (value != nullptr) { - return check_type(c, value); - } - return nullptr; -} - #define ATTRIBUTE_USER_TAG_NAME "tag" diff --git a/src/checker.hpp b/src/checker.hpp index e1efd5b89..58f6a027c 100644 --- a/src/checker.hpp +++ b/src/checker.hpp @@ -397,8 +397,6 @@ struct CheckerContext { CheckerTypePath *type_path; isize type_level; // TODO(bill): Actually handle correctly - CheckerPolyPath *poly_path; - isize poly_level; // TODO(bill): Actually handle correctly UntypedExprInfoMap *untyped; @@ -489,12 +487,6 @@ gb_internal void destroy_checker_type_path(CheckerTypePath *tp); gb_internal void check_type_path_push(CheckerContext *c, Entity *e); gb_internal Entity *check_type_path_pop (CheckerContext *c); -gb_internal CheckerPolyPath *new_checker_poly_path(); -gb_internal void destroy_checker_poly_path(CheckerPolyPath *); - -gb_internal void check_poly_path_push(CheckerContext *c, Type *t); -gb_internal Type *check_poly_path_pop (CheckerContext *c); - gb_internal void init_core_context(Checker *c); gb_internal void init_mem_allocator(Checker *c); diff --git a/src/common.cpp b/src/common.cpp index 09203e633..3624446f1 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -50,6 +50,10 @@ gb_internal void debugf(char const *fmt, ...); #include "string.cpp" #include "range_cache.cpp" +#if defined(GB_SYSTEM_WINDOWS) + #pragma warning(push) + #pragma warning(disable: 4505) +#endif gb_internal gb_inline bool is_power_of_two(i64 x) { if (x <= 0) { @@ -900,3 +904,8 @@ gb_internal Slice did_you_mean_results(DidYouMeanAnswers *d) } return slice_array(d->distances, 0, count); } + + +#if defined(GB_SYSTEM_WINDOWS) + #pragma warning(pop) +#endif \ No newline at end of file diff --git a/src/docs.cpp b/src/docs.cpp index 33b1e8361..b1efa2b46 100644 --- a/src/docs.cpp +++ b/src/docs.cpp @@ -85,15 +85,6 @@ gb_internal void print_doc_line(i32 indent, char const *fmt, ...) { va_end(va); gb_printf("\n"); } -gb_internal void print_doc_line_no_newline(i32 indent, char const *fmt, ...) { - while (indent --> 0) { - gb_printf("\t"); - } - va_list va; - va_start(va, fmt); - gb_printf_va(fmt, va); - va_end(va); -} gb_internal void print_doc_line_no_newline(i32 indent, String const &data) { while (indent --> 0) { gb_printf("\t"); diff --git a/src/entity.cpp b/src/entity.cpp index 6a3a69950..0605a293a 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -404,14 +404,6 @@ gb_internal Entity *alloc_entity_proc_group(Scope *scope, Token token, Type *typ return entity; } - -gb_internal Entity *alloc_entity_builtin(Scope *scope, Token token, Type *type, i32 id) { - Entity *entity = alloc_entity(Entity_Builtin, scope, token, type); - entity->Builtin.id = id; - entity->state = EntityState_Resolved; - return entity; -} - gb_internal Entity *alloc_entity_import_name(Scope *scope, Token token, Type *type, String path, String name, Scope *import_scope) { Entity *entity = alloc_entity(Entity_ImportName, scope, token, type); diff --git a/src/exact_value.cpp b/src/exact_value.cpp index 453909a15..f4c85505d 100644 --- a/src/exact_value.cpp +++ b/src/exact_value.cpp @@ -15,16 +15,6 @@ struct Quaternion256 { f64 imag, jmag, kmag, real; }; -gb_internal Quaternion256 quaternion256_inverse(Quaternion256 x) { - f64 invmag2 = 1.0 / (x.real*x.real + x.imag*x.imag + x.jmag*x.jmag + x.kmag*x.kmag); - x.real = +x.real * invmag2; - x.imag = -x.imag * invmag2; - x.jmag = -x.jmag * invmag2; - x.kmag = -x.kmag * invmag2; - return x; -} - - enum ExactValueKind { ExactValue_Invalid = 0, @@ -453,44 +443,44 @@ gb_internal ExactValue exact_value_kmag(ExactValue v) { return r; } -gb_internal ExactValue exact_value_make_imag(ExactValue v) { - switch (v.kind) { - case ExactValue_Integer: - return exact_value_complex(0, exact_value_to_float(v).value_float); - case ExactValue_Float: - return exact_value_complex(0, v.value_float); - default: - GB_PANIC("Expected an integer or float type for 'exact_value_make_imag'"); - } - ExactValue r = {ExactValue_Invalid}; - return r; -} - -gb_internal ExactValue exact_value_make_jmag(ExactValue v) { - switch (v.kind) { - case ExactValue_Integer: - return exact_value_quaternion(0, 0, exact_value_to_float(v).value_float, 0); - case ExactValue_Float: - return exact_value_quaternion(0, 0, v.value_float, 0); - default: - GB_PANIC("Expected an integer or float type for 'exact_value_make_imag'"); - } - ExactValue r = {ExactValue_Invalid}; - return r; -} - -gb_internal ExactValue exact_value_make_kmag(ExactValue v) { - switch (v.kind) { - case ExactValue_Integer: - return exact_value_quaternion(0, 0, 0, exact_value_to_float(v).value_float); - case ExactValue_Float: - return exact_value_quaternion(0, 0, 0, v.value_float); - default: - GB_PANIC("Expected an integer or float type for 'exact_value_make_imag'"); - } - ExactValue r = {ExactValue_Invalid}; - return r; -} +// gb_internal ExactValue exact_value_make_imag(ExactValue v) { +// switch (v.kind) { +// case ExactValue_Integer: +// return exact_value_complex(0, exact_value_to_float(v).value_float); +// case ExactValue_Float: +// return exact_value_complex(0, v.value_float); +// default: +// GB_PANIC("Expected an integer or float type for 'exact_value_make_imag'"); +// } +// ExactValue r = {ExactValue_Invalid}; +// return r; +// } + +// gb_internal ExactValue exact_value_make_jmag(ExactValue v) { +// switch (v.kind) { +// case ExactValue_Integer: +// return exact_value_quaternion(0, 0, exact_value_to_float(v).value_float, 0); +// case ExactValue_Float: +// return exact_value_quaternion(0, 0, v.value_float, 0); +// default: +// GB_PANIC("Expected an integer or float type for 'exact_value_make_jmag'"); +// } +// ExactValue r = {ExactValue_Invalid}; +// return r; +// } + +// gb_internal ExactValue exact_value_make_kmag(ExactValue v) { +// switch (v.kind) { +// case ExactValue_Integer: +// return exact_value_quaternion(0, 0, 0, exact_value_to_float(v).value_float); +// case ExactValue_Float: +// return exact_value_quaternion(0, 0, 0, v.value_float); +// default: +// GB_PANIC("Expected an integer or float type for 'exact_value_make_kmag'"); +// } +// ExactValue r = {ExactValue_Invalid}; +// return r; +// } gb_internal i64 exact_value_to_i64(ExactValue v) { v = exact_value_to_integer(v); diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index ca4b3b683..c5bc96eb9 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -605,11 +605,11 @@ gb_internal lbValue lb_map_get_proc_for_type(lbModule *m, Type *type) { return {p->value, p->type}; } -gb_internal void lb_debug_print(lbProcedure *p, String const &str) { - auto args = array_make(heap_allocator(), 1); - args[0] = lb_const_string(p->module, str); - lb_emit_runtime_call(p, "print_string", args); -} +// gb_internal void lb_debug_print(lbProcedure *p, String const &str) { +// auto args = array_make(heap_allocator(), 1); +// args[0] = lb_const_string(p->module, str); +// lb_emit_runtime_call(p, "print_string", args); +// } gb_internal lbValue lb_map_set_proc_for_type(lbModule *m, Type *type) { GB_ASSERT(build_context.use_static_map_calls); diff --git a/src/llvm_backend_debug.cpp b/src/llvm_backend_debug.cpp index 849416579..55c4370a2 100644 --- a/src/llvm_backend_debug.cpp +++ b/src/llvm_backend_debug.cpp @@ -14,12 +14,6 @@ gb_internal void lb_set_llvm_metadata(lbModule *m, void *key, LLVMMetadataRef va } } -gb_internal LLVMMetadataRef lb_get_llvm_file_metadata_from_node(lbModule *m, Ast *node) { - if (node == nullptr) { - return nullptr; - } - return lb_get_llvm_metadata(m, node->file()); -} gb_internal LLVMMetadataRef lb_get_current_debug_scope(lbProcedure *p) { GB_ASSERT_MSG(p->debug_info != nullptr, "missing debug information for %.*s", LIT(p->name)); diff --git a/src/llvm_backend_general.cpp b/src/llvm_backend_general.cpp index f30038da8..e5aa95f10 100644 --- a/src/llvm_backend_general.cpp +++ b/src/llvm_backend_general.cpp @@ -272,12 +272,6 @@ gb_internal lbValue lb_emit_epi(lbModule *m, lbValue const &value, isize index) gb_internal LLVMValueRef llvm_zero(lbModule *m) { return LLVMConstInt(lb_type(m, t_int), 0, false); } -gb_internal LLVMValueRef llvm_zero32(lbModule *m) { - return LLVMConstInt(lb_type(m, t_i32), 0, false); -} -gb_internal LLVMValueRef llvm_one(lbModule *m) { - return LLVMConstInt(lb_type(m, t_i32), 1, false); -} gb_internal LLVMValueRef llvm_alloca(lbProcedure *p, LLVMTypeRef llvm_type, isize alignment, char const *name) { LLVMPositionBuilderAtEnd(p->builder, p->decl_block->block); @@ -874,14 +868,6 @@ gb_internal void lb_addr_store(lbProcedure *p, lbAddr addr, lbValue value) { lb_emit_store(p, addr.addr, value); } -gb_internal void lb_const_store(lbValue ptr, lbValue value) { - GB_ASSERT(lb_is_const(ptr)); - GB_ASSERT(lb_is_const(value)); - GB_ASSERT(is_type_pointer(ptr.type)); - LLVMSetInitializer(ptr.value, value.value); -} - - gb_internal bool lb_is_type_proc_recursive(Type *t) { for (;;) { if (t == nullptr) { @@ -1327,21 +1313,6 @@ gb_internal void lb_clone_struct_type(LLVMTypeRef dst, LLVMTypeRef src) { LLVMStructSetBody(dst, fields, field_count, LLVMIsPackedStruct(src)); } -gb_internal LLVMTypeRef lb_alignment_prefix_type_hack(lbModule *m, i64 alignment) { - switch (alignment) { - case 1: - return LLVMArrayType(lb_type(m, t_u8), 0); - case 2: - return LLVMArrayType(lb_type(m, t_u16), 0); - case 4: - return LLVMArrayType(lb_type(m, t_u32), 0); - case 8: - return LLVMArrayType(lb_type(m, t_u64), 0); - default: case 16: - return LLVMArrayType(LLVMVectorType(lb_type(m, t_u32), 4), 0); - } -} - gb_internal String lb_mangle_name(lbModule *m, Entity *e) { String name = e->token.string; @@ -2202,9 +2173,6 @@ gb_internal void lb_add_member(lbModule *m, String const &name, lbValue val) { string_map_set(&m->members, name, val); } } -gb_internal void lb_add_member(lbModule *m, StringHashKey const &key, lbValue val) { - string_map_set(&m->members, key, val); -} gb_internal void lb_add_procedure_value(lbModule *m, lbProcedure *p) { if (p->entity != nullptr) { map_set(&m->procedure_values, p->value, p->entity); @@ -2493,42 +2461,6 @@ gb_internal lbValue lb_find_or_add_entity_string(lbModule *m, String const &str) return res; } -gb_internal lbValue lb_find_or_add_entity_string_byte_slice(lbModule *m, String const &str) { - LLVMValueRef indices[2] = {llvm_zero(m), llvm_zero(m)}; - LLVMValueRef data = LLVMConstStringInContext(m->ctx, - cast(char const *)str.text, - cast(unsigned)str.len, - false); - - - char *name = nullptr; - { - isize max_len = 7+8+1; - name = gb_alloc_array(permanent_allocator(), char, max_len); - u32 id = m->gen->global_array_index.fetch_add(1); - isize len = gb_snprintf(name, max_len, "csbs$%x", id); - len -= 1; - } - LLVMTypeRef type = LLVMTypeOf(data); - LLVMValueRef global_data = LLVMAddGlobal(m->mod, type, name); - LLVMSetInitializer(global_data, data); - lb_make_global_private_const(global_data); - LLVMSetAlignment(global_data, 1); - - LLVMValueRef ptr = nullptr; - if (str.len != 0) { - ptr = LLVMConstInBoundsGEP2(type, global_data, indices, 2); - } else { - ptr = LLVMConstNull(lb_type(m, t_u8_ptr)); - } - LLVMValueRef len = LLVMConstInt(lb_type(m, t_int), str.len, true); - LLVMValueRef values[2] = {ptr, len}; - - lbValue res = {}; - res.value = llvm_const_named_struct(m, t_u8_slice, values, 2); - res.type = t_u8_slice; - return res; -} gb_internal lbValue lb_find_or_add_entity_string_byte_slice_with_type(lbModule *m, String const &str, Type *slice_type) { GB_ASSERT(is_type_slice(slice_type)); LLVMValueRef indices[2] = {llvm_zero(m), llvm_zero(m)}; diff --git a/src/llvm_backend_opt.cpp b/src/llvm_backend_opt.cpp index 533264e62..fd6d94361 100644 --- a/src/llvm_backend_opt.cpp +++ b/src/llvm_backend_opt.cpp @@ -37,16 +37,16 @@ gb_internal void lb_add_function_simplifcation_passes(LLVMPassManagerRef mpm, i3 gb_internal void lb_populate_module_pass_manager(LLVMTargetMachineRef target_machine, LLVMPassManagerRef mpm, i32 optimization_level); gb_internal void lb_populate_function_pass_manager_specific(lbModule *m, LLVMPassManagerRef fpm, i32 optimization_level); -gb_internal LLVMBool lb_must_preserve_predicate_callback(LLVMValueRef value, void *user_data) { - lbModule *m = cast(lbModule *)user_data; - if (m == nullptr) { - return false; - } - if (value == nullptr) { - return false; - } - return LLVMIsAAllocaInst(value) != nullptr; -} +// gb_internal LLVMBool lb_must_preserve_predicate_callback(LLVMValueRef value, void *user_data) { +// lbModule *m = cast(lbModule *)user_data; +// if (m == nullptr) { +// return false; +// } +// if (value == nullptr) { +// return false; +// } +// return LLVMIsAAllocaInst(value) != nullptr; +// } #if LLVM_VERSION_MAJOR < 12 diff --git a/src/llvm_backend_proc.cpp b/src/llvm_backend_proc.cpp index 0789fb2c1..384d29ca7 100644 --- a/src/llvm_backend_proc.cpp +++ b/src/llvm_backend_proc.cpp @@ -383,46 +383,46 @@ gb_internal lbProcedure *lb_create_dummy_procedure(lbModule *m, String link_name } -gb_internal lbValue lb_value_param(lbProcedure *p, Entity *e, Type *abi_type, i32 index, lbParamPasskind *kind_) { - lbParamPasskind kind = lbParamPass_Value; - - if (e != nullptr && !are_types_identical(abi_type, e->type)) { - if (is_type_pointer(abi_type)) { - GB_ASSERT(e->kind == Entity_Variable); - Type *av = core_type(type_deref(abi_type)); - if (are_types_identical(av, core_type(e->type))) { - kind = lbParamPass_Pointer; - if (e->flags&EntityFlag_Value) { - kind = lbParamPass_ConstRef; - } - } else { - kind = lbParamPass_BitCast; - } - } else if (is_type_integer(abi_type)) { - kind = lbParamPass_Integer; - } else if (abi_type == t_llvm_bool) { - kind = lbParamPass_Value; - } else if (is_type_boolean(abi_type)) { - kind = lbParamPass_Integer; - } else if (is_type_simd_vector(abi_type)) { - kind = lbParamPass_BitCast; - } else if (is_type_float(abi_type)) { - kind = lbParamPass_BitCast; - } else if (is_type_tuple(abi_type)) { - kind = lbParamPass_Tuple; - } else if (is_type_proc(abi_type)) { - kind = lbParamPass_Value; - } else { - GB_PANIC("Invalid abi type pass kind %s", type_to_string(abi_type)); - } - } - - if (kind_) *kind_ = kind; - lbValue res = {}; - res.value = LLVMGetParam(p->value, cast(unsigned)index); - res.type = abi_type; - return res; -} +// gb_internal lbValue lb_value_param(lbProcedure *p, Entity *e, Type *abi_type, i32 index, lbParamPasskind *kind_) { +// lbParamPasskind kind = lbParamPass_Value; + +// if (e != nullptr && !are_types_identical(abi_type, e->type)) { +// if (is_type_pointer(abi_type)) { +// GB_ASSERT(e->kind == Entity_Variable); +// Type *av = core_type(type_deref(abi_type)); +// if (are_types_identical(av, core_type(e->type))) { +// kind = lbParamPass_Pointer; +// if (e->flags&EntityFlag_Value) { +// kind = lbParamPass_ConstRef; +// } +// } else { +// kind = lbParamPass_BitCast; +// } +// } else if (is_type_integer(abi_type)) { +// kind = lbParamPass_Integer; +// } else if (abi_type == t_llvm_bool) { +// kind = lbParamPass_Value; +// } else if (is_type_boolean(abi_type)) { +// kind = lbParamPass_Integer; +// } else if (is_type_simd_vector(abi_type)) { +// kind = lbParamPass_BitCast; +// } else if (is_type_float(abi_type)) { +// kind = lbParamPass_BitCast; +// } else if (is_type_tuple(abi_type)) { +// kind = lbParamPass_Tuple; +// } else if (is_type_proc(abi_type)) { +// kind = lbParamPass_Value; +// } else { +// GB_PANIC("Invalid abi type pass kind %s", type_to_string(abi_type)); +// } +// } + +// if (kind_) *kind_ = kind; +// lbValue res = {}; +// res.value = LLVMGetParam(p->value, cast(unsigned)index); +// res.type = abi_type; +// return res; +// } @@ -1165,14 +1165,6 @@ gb_internal lbValue lb_emit_call(lbProcedure *p, lbValue value, Array c return result; } -gb_internal LLVMValueRef llvm_splat_float(i64 count, LLVMTypeRef type, f64 value) { - LLVMValueRef v = LLVMConstReal(type, value); - LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, count); - for (i64 i = 0; i < count; i++) { - values[i] = v; - } - return LLVMConstVector(values, cast(unsigned)count); -} gb_internal LLVMValueRef llvm_splat_int(i64 count, LLVMTypeRef type, i64 value, bool is_signed=false) { LLVMValueRef v = LLVMConstInt(type, value, is_signed); LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, count); diff --git a/src/llvm_backend_stmt.cpp b/src/llvm_backend_stmt.cpp index 66c422071..6400a8a9d 100644 --- a/src/llvm_backend_stmt.cpp +++ b/src/llvm_backend_stmt.cpp @@ -378,16 +378,6 @@ gb_internal lbValue lb_map_cell_index_static(lbProcedure *p, Type *type, lbValue return lb_emit_ptr_offset(p, elems_ptr, data_index); } -gb_internal void lb_map_kvh_data_static(lbProcedure *p, lbValue map_value, lbValue *ks_, lbValue *vs_, lbValue *hs_) { - lbValue capacity = lb_map_cap(p, map_value); - lbValue ks = lb_map_data_uintptr(p, map_value); - lbValue vs = {}; - lbValue hs = {}; - if (ks_) *ks_ = ks; - if (vs_) *vs_ = vs; - if (hs_) *hs_ = hs; -} - gb_internal lbValue lb_map_hash_is_valid(lbProcedure *p, lbValue hash) { // N :: size_of(uintptr)*8 - 1 // (hash != 0) & (hash>>N == 0) diff --git a/src/llvm_backend_utility.cpp b/src/llvm_backend_utility.cpp index 94b900278..dbed32b82 100644 --- a/src/llvm_backend_utility.cpp +++ b/src/llvm_backend_utility.cpp @@ -599,14 +599,6 @@ gb_internal lbValue lb_emit_reverse_bits(lbProcedure *p, lbValue x, Type *type) } -gb_internal lbValue lb_emit_bit_set_card(lbProcedure *p, lbValue x) { - GB_ASSERT(is_type_bit_set(x.type)); - Type *underlying = bit_set_to_int(x.type); - lbValue card = lb_emit_count_ones(p, x, underlying); - return lb_emit_conv(p, card, t_int); -} - - gb_internal lbValue lb_emit_union_cast_only_ok_check(lbProcedure *p, lbValue value, Type *type, TokenPos pos) { GB_ASSERT(is_type_tuple(type)); lbModule *m = p->module; @@ -1493,10 +1485,6 @@ gb_internal lbValue lb_dynamic_array_cap(lbProcedure *p, lbValue da) { GB_ASSERT(is_type_dynamic_array(da.type)); return lb_emit_struct_ev(p, da, 2); } -gb_internal lbValue lb_dynamic_array_allocator(lbProcedure *p, lbValue da) { - GB_ASSERT(is_type_dynamic_array(da.type)); - return lb_emit_struct_ev(p, da, 3); -} gb_internal lbValue lb_map_len(lbProcedure *p, lbValue value) { GB_ASSERT_MSG(is_type_map(value.type) || are_types_identical(value.type, t_raw_map), "%s", type_to_string(value.type)); diff --git a/src/main.cpp b/src/main.cpp index 614130bb6..c7250aa8b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,7 +3,14 @@ #include "common.cpp" #include "timings.cpp" #include "tokenizer.cpp" +#if defined(GB_SYSTEM_WINDOWS) + #pragma warning(push) + #pragma warning(disable: 4505) +#endif #include "big_int.cpp" +#if defined(GB_SYSTEM_WINDOWS) + #pragma warning(pop) +#endif #include "exact_value.cpp" #include "build_settings.cpp" @@ -58,7 +65,6 @@ gb_global Timings global_timings = {0}; #endif #endif -#include "query_data.cpp" #include "bug_report.cpp" // NOTE(bill): 'name' is used in debugging and profiling modes @@ -573,7 +579,6 @@ gb_internal void usage(String argv0) { print_usage_line(1, " one must contain the program's entry point, all must be in the same package."); print_usage_line(1, "run same as 'build', but also then runs the newly compiled executable."); print_usage_line(1, "check parse, and type check a directory of .odin files"); - print_usage_line(1, "query parse, type check, and output a .json file containing information about the program"); print_usage_line(1, "strip-semicolon parse, type check, and remove unneeded semicolons from the entire program"); print_usage_line(1, "test build and runs procedures with the attribute @(test) in the initial package"); print_usage_line(1, "doc generate documentation on a directory of .odin files"); @@ -817,12 +822,6 @@ gb_internal bool parse_build_flags(Array args) { add_flag(&build_flags, BuildFlag_UseStaticMapCalls, str_lit("use-static-map-calls"), BuildFlagParam_None, Command__does_check); - - add_flag(&build_flags, BuildFlag_Compact, str_lit("compact"), BuildFlagParam_None, Command_query); - add_flag(&build_flags, BuildFlag_GlobalDefinitions, str_lit("global-definitions"), BuildFlagParam_None, Command_query); - add_flag(&build_flags, BuildFlag_GoToDefinitions, str_lit("go-to-definitions"), BuildFlagParam_None, Command_query); - - add_flag(&build_flags, BuildFlag_Short, str_lit("short"), BuildFlagParam_None, Command_doc); add_flag(&build_flags, BuildFlag_AllPackages, str_lit("all-packages"), BuildFlagParam_None, Command_doc); add_flag(&build_flags, BuildFlag_DocFormat, str_lit("doc-format"), BuildFlagParam_None, Command_doc); @@ -1445,39 +1444,6 @@ gb_internal bool parse_build_flags(Array args) { build_context.strict_style_init_only = true; break; } - case BuildFlag_Compact: { - if (!build_context.query_data_set_settings.ok) { - gb_printf_err("Invalid use of -compact flag, only allowed with 'odin query'\n"); - bad_flags = true; - } else { - build_context.query_data_set_settings.compact = true; - } - break; - } - case BuildFlag_GlobalDefinitions: { - if (!build_context.query_data_set_settings.ok) { - gb_printf_err("Invalid use of -global-definitions flag, only allowed with 'odin query'\n"); - bad_flags = true; - } else if (build_context.query_data_set_settings.kind != QueryDataSet_Invalid) { - gb_printf_err("Invalid use of -global-definitions flag, a previous flag for 'odin query' was set\n"); - bad_flags = true; - } else { - build_context.query_data_set_settings.kind = QueryDataSet_GlobalDefinitions; - } - break; - } - case BuildFlag_GoToDefinitions: { - if (!build_context.query_data_set_settings.ok) { - gb_printf_err("Invalid use of -go-to-definitions flag, only allowed with 'odin query'\n"); - bad_flags = true; - } else if (build_context.query_data_set_settings.kind != QueryDataSet_Invalid) { - gb_printf_err("Invalid use of -global-definitions flag, a previous flag for 'odin query' was set\n"); - bad_flags = true; - } else { - build_context.query_data_set_settings.kind = QueryDataSet_GoToDefinitions; - } - break; - } case BuildFlag_Short: build_context.cmd_doc_flags |= CmdDocFlag_Short; break; @@ -1638,16 +1604,6 @@ gb_internal bool parse_build_flags(Array args) { gb_printf_err("`-export-timings:` requires `-show-timings` or `-show-more-timings` to be present\n"); bad_flags = true; } - - if (build_context.query_data_set_settings.ok) { - if (build_context.query_data_set_settings.kind == QueryDataSet_Invalid) { - gb_printf_err("'odin query' requires a flag determining the kind of query data set to be returned\n"); - gb_printf_err("\t-global-definitions : outputs a JSON file of global definitions\n"); - gb_printf_err("\t-go-to-definitions : outputs a OGTD binary file of go to definitions for identifiers within an Odin project\n"); - bad_flags = true; - } - } - return !bad_flags; } @@ -1931,8 +1887,6 @@ gb_internal void print_show_help(String const arg0, String const &command) { print_usage_line(3, "odin check filename.odin -file # Type check single-file package, must contain entry point."); } else if (command == "test") { print_usage_line(1, "test Build ands runs procedures with the attribute @(test) in the initial package"); - } else if (command == "query") { - print_usage_line(1, "query [experimental] Parse, type check, and output a .json file containing information about the program"); } else if (command == "doc") { print_usage_line(1, "doc generate documentation from a directory of .odin files"); print_usage_line(2, "Examples:"); @@ -2627,15 +2581,6 @@ int main(int arg_count, char const **arg_ptr) { build_context.command_kind = Command_strip_semicolon; build_context.no_output_files = true; init_filename = args[2]; - } else if (command == "query") { - if (args.count < 3) { - usage(args[0]); - return 1; - } - build_context.command_kind = Command_query; - build_context.no_output_files = true; - build_context.query_data_set_settings.ok = true; - init_filename = args[2]; } else if (command == "doc") { if (args.count < 3) { usage(args[0]); @@ -2824,12 +2769,8 @@ int main(int arg_count, char const **arg_ptr) { print_show_unused(checker); } - if (build_context.query_data_set_settings.ok) { - generate_and_print_query_data(checker, &global_timings); - } else { - if (build_context.show_timings) { - show_timings(checker, &global_timings); - } + if (build_context.show_timings) { + show_timings(checker, &global_timings); } if (global_error_collector.count != 0) { diff --git a/src/parser.cpp b/src/parser.cpp index 1606f5b47..2ccdac7fa 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -237,9 +237,6 @@ gb_internal Ast *clone_ast(Ast *node) { case Ast_ExprStmt: n->ExprStmt.expr = clone_ast(n->ExprStmt.expr); break; - case Ast_TagStmt: - n->TagStmt.stmt = clone_ast(n->TagStmt.stmt); - break; case Ast_AssignStmt: n->AssignStmt.lhs = clone_ast_array(n->AssignStmt.lhs); n->AssignStmt.rhs = clone_ast_array(n->AssignStmt.rhs); @@ -497,14 +494,6 @@ gb_internal Ast *ast_tag_expr(AstFile *f, Token token, Token name, Ast *expr) { return result; } -gb_internal Ast *ast_tag_stmt(AstFile *f, Token token, Token name, Ast *stmt) { - Ast *result = alloc_ast_node(f, Ast_TagStmt); - result->TagStmt.token = token; - result->TagStmt.name = name; - result->TagStmt.stmt = stmt; - return result; -} - gb_internal Ast *ast_unary_expr(AstFile *f, Token op, Ast *expr) { Ast *result = alloc_ast_node(f, Ast_UnaryExpr); result->UnaryExpr.op = op; @@ -1308,16 +1297,6 @@ gb_internal Token advance_token(AstFile *f) { return prev; } -gb_internal bool peek_token_kind(AstFile *f, TokenKind kind) { - for (isize i = f->curr_token_index+1; i < f->tokens.count; i++) { - Token tok = f->tokens[i]; - if (kind != Token_Comment && tok.kind == Token_Comment) { - continue; - } - return tok.kind == kind; - } - return false; -} gb_internal Token peek_token(AstFile *f) { for (isize i = f->curr_token_index+1; i < f->tokens.count; i++) { @@ -1440,17 +1419,6 @@ gb_internal Token expect_operator(AstFile *f) { return prev; } -gb_internal Token expect_keyword(AstFile *f) { - Token prev = f->curr_token; - if (!gb_is_between(prev.kind, Token__KeywordBegin+1, Token__KeywordEnd-1)) { - String p = token_to_string(prev); - syntax_error(f->curr_token, "Expected a keyword, got '%.*s'", - LIT(p)); - } - advance_token(f); - return prev; -} - gb_internal bool allow_token(AstFile *f, TokenKind kind) { Token prev = f->curr_token; if (prev.kind == kind) { @@ -1957,10 +1925,6 @@ gb_internal bool ast_on_same_line(Token const &x, Ast *yp) { return x.pos.line == y.pos.line; } -gb_internal bool ast_on_same_line(Ast *x, Ast *y) { - return ast_on_same_line(ast_token(x), y); -} - gb_internal Ast *parse_force_inlining_operand(AstFile *f, Token token) { Ast *expr = parse_unary_expr(f, false); Ast *e = strip_or_return_expr(expr); diff --git a/src/parser.hpp b/src/parser.hpp index a2d2c038e..f7b3e51ae 100644 --- a/src/parser.hpp +++ b/src/parser.hpp @@ -457,11 +457,6 @@ AST_KIND(_StmtBegin, "", bool) \ AST_KIND(BadStmt, "bad statement", struct { Token begin, end; }) \ AST_KIND(EmptyStmt, "empty statement", struct { Token token; }) \ AST_KIND(ExprStmt, "expression statement", struct { Ast *expr; } ) \ - AST_KIND(TagStmt, "tag statement", struct { \ - Token token; \ - Token name; \ - Ast * stmt; \ - }) \ AST_KIND(AssignStmt, "assign statement", struct { \ Token op; \ Slice lhs, rhs; \ diff --git a/src/parser_pos.cpp b/src/parser_pos.cpp index 19a525e2e..fb7f0c9c2 100644 --- a/src/parser_pos.cpp +++ b/src/parser_pos.cpp @@ -53,7 +53,6 @@ gb_internal Token ast_token(Ast *node) { case Ast_BadStmt: return node->BadStmt.begin; case Ast_EmptyStmt: return node->EmptyStmt.token; case Ast_ExprStmt: return ast_token(node->ExprStmt.expr); - case Ast_TagStmt: return node->TagStmt.token; case Ast_AssignStmt: return node->AssignStmt.op; case Ast_BlockStmt: return node->BlockStmt.open; case Ast_IfStmt: return node->IfStmt.token; @@ -197,7 +196,6 @@ Token ast_end_token(Ast *node) { case Ast_BadStmt: return node->BadStmt.end; case Ast_EmptyStmt: return node->EmptyStmt.token; case Ast_ExprStmt: return ast_end_token(node->ExprStmt.expr); - case Ast_TagStmt: return ast_end_token(node->TagStmt.stmt); case Ast_AssignStmt: if (node->AssignStmt.rhs.count > 0) { return ast_end_token(node->AssignStmt.rhs[node->AssignStmt.rhs.count-1]); diff --git a/src/query_data.cpp b/src/query_data.cpp deleted file mode 100644 index 86487a058..000000000 --- a/src/query_data.cpp +++ /dev/null @@ -1,1030 +0,0 @@ -struct QueryValue; -struct QueryValuePair; - -gb_global gbAllocator query_value_allocator = {}; - -enum QueryKind { - Query_Invalid, - Query_String, - Query_Boolean, - Query_Integer, - Query_Float, - Query_Array, - Query_Map, -}; - -struct QueryValuePair { - String key; - QueryValue *value; -}; - - -struct QueryValue { - QueryKind kind; - bool packed; -}; - -struct QueryValueString : QueryValue { - QueryValueString(String const &v) { - kind = Query_String; - value = v; - packed = false; - } - String value; -}; - -struct QueryValueBoolean : QueryValue { - QueryValueBoolean(bool v) { - kind = Query_Boolean; - value = v; - packed = false; - } - bool value; -}; - -struct QueryValueInteger : QueryValue { - QueryValueInteger(i64 v) { - kind = Query_Integer; - value = v; - packed = false; - } - i64 value; -}; - -struct QueryValueFloat : QueryValue { - QueryValueFloat(f64 v) { - kind = Query_Float; - value = v; - packed = false; - } - f64 value; -}; - -struct QueryValueArray : QueryValue { - QueryValueArray() { - kind = Query_Array; - array_init(&value, query_value_allocator); - packed = false; - } - QueryValueArray(Array const &v) { - kind = Query_Array; - value = v; - packed = false; - } - Array value; - - void reserve(isize cap) { - array_reserve(&value, cap); - } - void add(QueryValue *v) { - array_add(&value, v); - } - void add(char const *v) { - add(make_string_c(cast(char *)v)); - } - void add(String const &v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueString); - *val = QueryValueString(v); - add(val); - } - void add(bool v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueBoolean); - *val = QueryValueBoolean(v); - add(val); - } - void add(i64 v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueInteger); - *val = QueryValueInteger(v); - add(val); - } - void add(f64 v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueFloat); - *val = QueryValueFloat(v); - add(val); - } -}; - -struct QueryValueMap : QueryValue { - QueryValueMap() { - kind = Query_Map; - array_init(&value, query_value_allocator); - packed = false; - } - QueryValueMap(Array const &v) { - kind = Query_Map; - value = v; - packed = false; - } - Array value; - - - void reserve(isize cap) { - array_reserve(&value, cap); - } - void add(char const *k, QueryValue *v) { - add(make_string_c(cast(char *)k), v); - } - void add(String const &k, QueryValue *v) { - QueryValuePair kv = {k, v}; - array_add(&value, kv); - } - - void add(char const *k, String const &v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueString); - *val = QueryValueString(v); - add(k, val); - } - void add(char const *k, char const *v) { - add(k, make_string_c(cast(char *)v)); - } - void add(char const *k, bool v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueBoolean); - *val = QueryValueBoolean(v); - add(k, val); - } - void add(char const *k, i64 v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueInteger); - *val = QueryValueInteger(v); - add(k, val); - } - void add(char const *k, f64 v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueFloat); - *val = QueryValueFloat(v); - add(k, val); - } - void add(String const &k, String const &v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueString); - *val = QueryValueString(v); - add(k, val); - } - void add(String const &k, char const *v) { - add(k, make_string_c(cast(char *)v)); - } - void add(String const &k, bool v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueBoolean); - *val = QueryValueBoolean(v); - add(k, val); - } - void add(String const &k, i64 v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueInteger); - *val = QueryValueInteger(v); - add(k, val); - } - void add(String const &k, f64 v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueFloat); - *val = QueryValueFloat(v); - add(k, val); - } -}; - - -#define DEF_QUERY_PROC(TYPE, VALUETYPE, NAME) TYPE *NAME(VALUETYPE value) { \ - auto v = gb_alloc_item(query_value_allocator, TYPE); \ - *v = TYPE(value); \ - return v; \ -} -#define DEF_QUERY_PROC0(TYPE, NAME) TYPE *NAME() { \ - auto v = gb_alloc_item(query_value_allocator, TYPE); \ - *v = TYPE(); \ - return v; \ -} - -gb_internal DEF_QUERY_PROC(QueryValueString, String const &, query_value_string); -gb_internal DEF_QUERY_PROC(QueryValueBoolean, bool, query_value_boolean); -gb_internal DEF_QUERY_PROC(QueryValueInteger, i64, query_value_integer); -gb_internal DEF_QUERY_PROC(QueryValueFloat, f64, query_value_float); -gb_internal DEF_QUERY_PROC(QueryValueArray, Array const &, query_value_array); -gb_internal DEF_QUERY_PROC(QueryValueMap, Array const &, query_value_map); -gb_internal DEF_QUERY_PROC0(QueryValueArray, query_value_array); -gb_internal DEF_QUERY_PROC0(QueryValueMap, query_value_map); - -gb_internal isize qprintf(bool format, isize indent, char const *fmt, ...) { - if (format) while (indent --> 0) { - gb_printf("\t"); - } - va_list va; - va_start(va, fmt); - isize res = gb_printf_va(fmt, va); - va_end(va); - return res; -} - -gb_internal bool qv_valid_char(u8 c) { - if (c >= 0x80) { - return false; - } - - switch (c) { - case '\"': - case '\n': - case '\r': - case '\t': - case '\v': - case '\f': - return false; - } - - return true; -} - -gb_internal void print_query_data_as_json(QueryValue *value, bool format = true, isize indent = 0) { - if (value == nullptr) { - gb_printf("null"); - return; - } - switch (value->kind) { - case Query_String: { - auto v = cast(QueryValueString *)value; - String name = v->value; - isize extra = 0; - for (isize i = 0; i < name.len; i++) { - u8 c = name[i]; - if (!qv_valid_char(c)) { - extra += 5; - } - } - - if (extra == 0) { - gb_printf("\"%.*s\"", LIT(name)); - return; - } - - char const hex_table[] = "0123456789ABCDEF"; - isize buf_len = name.len + extra + 2 + 1; - - u8 *buf = gb_alloc_array(temporary_allocator(), u8, buf_len); - - isize j = 0; - - for (isize i = 0; i < name.len; i++) { - u8 c = name[i]; - if (qv_valid_char(c)) { - buf[j+0] = c; - j += 1; - } else if (c == '"') { - buf[j+0] = '\\'; - buf[j+1] = '\"'; - j += 2; - } else { - switch (c) { - case '\n': buf[j+0] = '\\'; buf[j+1] = 'n'; j += 2; break; - case '\r': buf[j+0] = '\\'; buf[j+1] = 'r'; j += 2; break; - case '\t': buf[j+0] = '\\'; buf[j+1] = 't'; j += 2; break; - case '\v': buf[j+0] = '\\'; buf[j+1] = 'v'; j += 2; break; - case '\f': - default: - buf[j+0] = '\\'; - buf[j+1] = hex_table[0]; - buf[j+2] = hex_table[0]; - buf[j+3] = hex_table[c >> 4]; - buf[j+4] = hex_table[c & 0x0f]; - j += 5; - break; - } - } - } - - gb_printf("\"%s\"", buf); - return; - } - case Query_Boolean: { - auto v = cast(QueryValueBoolean *)value; - if (v->value) { - gb_printf("true"); - } else { - gb_printf("false"); - } - return; - } - case Query_Integer: { - auto v = cast(QueryValueInteger *)value; - gb_printf("%lld", cast(long long)v->value); - return; - } - case Query_Float: { - auto v = cast(QueryValueFloat *)value; - gb_printf("%f", v->value); - return; - } - case Query_Array: { - auto v = cast(QueryValueArray *)value; - if (v->value.count > 0) { - bool ff = format && !v->packed; - gb_printf("["); - if (ff) gb_printf("\n"); - for_array(i, v->value) { - qprintf(ff, indent+1, ""); - print_query_data_as_json(v->value[i], ff, indent+1); - if (i < v->value.count-1) { - gb_printf(","); - if (!ff && format) { - gb_printf(" "); - } - } - if (ff) gb_printf("\n"); - } - qprintf(ff, indent, "]"); - } else { - gb_printf("[]"); - } - return; - } - case Query_Map: { - auto v = cast(QueryValueMap *)value; - if (v->value.count > 0) { - bool ff = format && !v->packed; - gb_printf("{"); - if (ff) gb_printf("\n"); - for_array(i, v->value) { - auto kv = v->value[i]; - qprintf(ff, indent+1, "\"%.*s\":", LIT(kv.key)); - if (format) gb_printf(" "); - print_query_data_as_json(kv.value, ff, indent+1); - if (i < v->value.count-1) { - gb_printf(","); - if (!ff && format) { - gb_printf(" "); - } - } - if (ff) gb_printf("\n"); - } - qprintf(ff, indent, "}"); - } else { - gb_printf("{}"); - } - return; - } - } -} - - - -gb_internal int query_data_package_compare(void const *a, void const *b) { - AstPackage *x = *cast(AstPackage *const *)a; - AstPackage *y = *cast(AstPackage *const *)b; - - if (x == y) { - return 0; - } - - if (x != nullptr && y != nullptr) { - return string_compare(x->name, y->name); - } else if (x != nullptr && y == nullptr) { - return -1; - } else if (x == nullptr && y != nullptr) { - return +1; - } - return 0; -} - -gb_internal int query_data_definition_compare(void const *a, void const *b) { - Entity *x = *cast(Entity *const *)a; - Entity *y = *cast(Entity *const *)b; - - if (x == y) { - return 0; - } else if (x != nullptr && y == nullptr) { - return -1; - } else if (x == nullptr && y != nullptr) { - return +1; - } - - if (x->pkg != y->pkg) { - i32 res = query_data_package_compare(&x->pkg, &y->pkg); - if (res != 0) { - return res; - } - } - - return string_compare(x->token.string, y->token.string); -} - -gb_internal int entity_name_compare(void const *a, void const *b) { - Entity *x = *cast(Entity *const *)a; - Entity *y = *cast(Entity *const *)b; - if (x == y) { - return 0; - } else if (x != nullptr && y == nullptr) { - return -1; - } else if (x == nullptr && y != nullptr) { - return +1; - } - return string_compare(x->token.string, y->token.string); -} - - -gb_internal void generate_and_print_query_data_global_definitions(Checker *c, Timings *timings); -gb_internal void generate_and_print_query_data_go_to_definitions(Checker *c); - -gb_internal void generate_and_print_query_data(Checker *c, Timings *timings) { - query_value_allocator = heap_allocator(); - switch (build_context.query_data_set_settings.kind) { - case QueryDataSet_GlobalDefinitions: - generate_and_print_query_data_global_definitions(c, timings); - return; - case QueryDataSet_GoToDefinitions: - generate_and_print_query_data_go_to_definitions(c); - return; - } -} - - -gb_internal void generate_and_print_query_data_global_definitions(Checker *c, Timings *timings) { - auto *root = query_value_map(); - - if (global_error_collector.errors.count > 0) { - auto *errors = query_value_array(); - root->add("errors", errors); - for_array(i, global_error_collector.errors) { - String err = string_trim_whitespace(global_error_collector.errors[i]); - errors->add(err); - } - - } - - { // Packages - auto *packages = query_value_array(); - root->add("packages", packages); - - auto sorted_packages = array_make(query_value_allocator, 0, c->info.packages.entries.count); - defer (array_free(&sorted_packages)); - - for (auto const &entry : c->info.packages) { - AstPackage *pkg = entry.value; - if (pkg != nullptr) { - array_add(&sorted_packages, pkg); - } - } - gb_sort_array(sorted_packages.data, sorted_packages.count, query_data_package_compare); - packages->reserve(sorted_packages.count); - - for_array(i, sorted_packages) { - AstPackage *pkg = sorted_packages[i]; - String name = pkg->name; - String fullpath = pkg->fullpath; - - auto *files = query_value_array(); - files->reserve(pkg->files.count); - for_array(j, pkg->files) { - AstFile *f = pkg->files[j]; - files->add(f->fullpath); - } - - auto *package = query_value_map(); - package->reserve(3); - packages->add(package); - - package->add("name", pkg->name); - package->add("fullpath", pkg->fullpath); - package->add("files", files); - } - } - - if (c->info.definitions.count > 0) { - auto *definitions = query_value_array(); - root->add("definitions", definitions); - - auto sorted_definitions = array_make(query_value_allocator, 0, c->info.definitions.count); - defer (array_free(&sorted_definitions)); - - for_array(i, c->info.definitions) { - Entity *e = c->info.definitions[i]; - String name = e->token.string; - if (is_blank_ident(name)) { - continue; - } - if ((e->scope->flags & (ScopeFlag_Pkg|ScopeFlag_File)) == 0) { - continue; - } - if (e->parent_proc_decl != nullptr) { - continue; - } - switch (e->kind) { - case Entity_Builtin: - case Entity_Nil: - case Entity_Label: - continue; - } - if (e->pkg == nullptr) { - continue; - } - if (e->token.pos.line == 0) { - continue; - } - if (e->kind == Entity_Procedure) { - Type *t = base_type(e->type); - if (t->kind != Type_Proc) { - continue; - } - if (t->Proc.is_poly_specialized) { - continue; - } - } - if (e->kind == Entity_TypeName) { - Type *t = base_type(e->type); - if (t->kind == Type_Struct) { - if (t->Struct.is_poly_specialized) { - continue; - } - } - if (t->kind == Type_Union) { - if (t->Union.is_poly_specialized) { - continue; - } - } - } - - array_add(&sorted_definitions, e); - } - - gb_sort_array(sorted_definitions.data, sorted_definitions.count, query_data_definition_compare); - definitions->reserve(sorted_definitions.count); - - for_array(i, sorted_definitions) { - Entity *e = sorted_definitions[i]; - String name = e->token.string; - - auto *def = query_value_map(); - def->reserve(16); - definitions->add(def); - - def->add("package", e->pkg->name); - def->add("name", name); - def->add("filepath", get_file_path_string(e->token.pos.file_id)); - def->add("line", cast(i64)e->token.pos.line); - def->add("column", cast(i64)e->token.pos.column); - def->add("file_offset", cast(i64)e->token.pos.offset); - - switch (e->kind) { - case Entity_Constant: def->add("kind", str_lit("constant")); break; - case Entity_Variable: def->add("kind", str_lit("variable")); break; - case Entity_TypeName: def->add("kind", str_lit("type name")); break; - case Entity_Procedure: def->add("kind", str_lit("procedure")); break; - case Entity_ProcGroup: def->add("kind", str_lit("procedure group")); break; - case Entity_ImportName: def->add("kind", str_lit("import name")); break; - case Entity_LibraryName: def->add("kind", str_lit("library name")); break; - default: GB_PANIC("Invalid entity kind to be added"); - } - - - if (e->type != nullptr && e->type != t_invalid) { - Type *t = e->type; - Type *bt = t; - - switch (e->kind) { - case Entity_TypeName: - if (!e->TypeName.is_type_alias) { - bt = base_type(t); - } - break; - } - - { - gbString str = type_to_string(t); - String type_str = make_string(cast(u8 *)str, gb_string_length(str)); - def->add("type", type_str); - } - if (t != bt) { - gbString str = type_to_string(bt); - String type_str = make_string(cast(u8 *)str, gb_string_length(str)); - def->add("base_type", type_str); - } - { - String type_kind = {}; - Type *bt = base_type(t); - switch (bt->kind) { - case Type_Pointer: type_kind = str_lit("pointer"); break; - case Type_Array: type_kind = str_lit("array"); break; - case Type_Slice: type_kind = str_lit("slice"); break; - case Type_DynamicArray: type_kind = str_lit("dynamic array"); break; - case Type_Map: type_kind = str_lit("map"); break; - case Type_Struct: type_kind = str_lit("struct"); break; - case Type_Union: type_kind = str_lit("union"); break; - case Type_Enum: type_kind = str_lit("enum"); break; - case Type_Proc: type_kind = str_lit("procedure"); break; - case Type_BitSet: type_kind = str_lit("bit set"); break; - case Type_SimdVector: type_kind = str_lit("simd vector"); break; - - case Type_Generic: - case Type_Tuple: - GB_PANIC("Invalid definition type"); - break; - } - if (type_kind.len > 0) { - def->add("type_kind", type_kind); - } - } - } - - if (e->kind == Entity_TypeName) { - def->add("size", type_size_of(e->type)); - def->add("align", type_align_of(e->type)); - - - if (is_type_struct(e->type)) { - auto *data = query_value_map(); - data->reserve(6); - - def->add("data", data); - - Type *t = base_type(e->type); - GB_ASSERT(t->kind == Type_Struct); - - if (t->Struct.is_polymorphic) { - data->add("polymorphic", cast(bool)t->Struct.is_polymorphic); - } - if (t->Struct.is_poly_specialized) { - data->add("polymorphic_specialized", cast(bool)t->Struct.is_poly_specialized); - } - if (t->Struct.is_packed) { - data->add("packed", cast(bool)t->Struct.is_packed); - } - if (t->Struct.is_raw_union) { - data->add("raw_union", cast(bool)t->Struct.is_raw_union); - } - - auto *fields = query_value_array(); - data->add("fields", fields); - fields->reserve(t->Struct.fields.count); - fields->packed = true; - - for_array(j, t->Struct.fields) { - Entity *e = t->Struct.fields[j]; - String name = e->token.string; - if (is_blank_ident(name)) { - continue; - } - - fields->add(name); - } - } else if (is_type_union(e->type)) { - auto *data = query_value_map(); - data->reserve(4); - - def->add("data", data); - Type *t = base_type(e->type); - GB_ASSERT(t->kind == Type_Union); - - if (t->Union.is_polymorphic) { - data->add("polymorphic", cast(bool)t->Union.is_polymorphic); - } - if (t->Union.is_poly_specialized) { - data->add("polymorphic_specialized", cast(bool)t->Union.is_poly_specialized); - } - - auto *variants = query_value_array(); - variants->reserve(t->Union.variants.count); - data->add("variants", variants); - - for_array(j, t->Union.variants) { - Type *vt = t->Union.variants[j]; - - gbString str = type_to_string(vt); - String type_str = make_string(cast(u8 *)str, gb_string_length(str)); - variants->add(type_str); - } - } - } - - if (e->kind == Entity_Procedure) { - Type *t = base_type(e->type); - GB_ASSERT(t->kind == Type_Proc); - - bool is_polymorphic = t->Proc.is_polymorphic; - bool is_poly_specialized = t->Proc.is_poly_specialized; - bool ok = is_polymorphic || is_poly_specialized; - if (ok) { - auto *data = query_value_map(); - data->reserve(4); - - def->add("data", data); - if (is_polymorphic) { - data->add("polymorphic", cast(bool)is_polymorphic); - } - if (is_poly_specialized) { - data->add("polymorphic_specialized", cast(bool)is_poly_specialized); - } - } - } - - if (e->kind == Entity_ProcGroup) { - auto *procedures = query_value_array(); - procedures->reserve(e->ProcGroup.entities.count); - - for_array(j, e->ProcGroup.entities) { - Entity *p = e->ProcGroup.entities[j]; - - auto *procedure = query_value_map(); - procedure->reserve(2); - procedure->packed = true; - - procedures->add(procedure); - - procedure->add("package", p->pkg->name); - procedure->add("name", p->token.string); - } - def->add("procedures", procedures); - } - - DeclInfo *di = e->decl_info; - if (di != nullptr) { - if (di->is_using) { - def->add("using", query_value_boolean(true)); - } - } - } - } - - if (build_context.show_timings) { - Timings *t = timings; - timings__stop_current_section(t); - t->total.finish = time_stamp_time_now(); - isize max_len = gb_min(36, t->total.label.len); - for_array(i, t->sections) { - TimeStamp ts = t->sections[i]; - max_len = gb_max(max_len, ts.label.len); - } - t->total_time_seconds = time_stamp_as_s(t->total, t->freq); - - auto *tims = query_value_map(); - tims->reserve(8); - root->add("timings", tims); - tims->add("time_unit", str_lit("s")); - - tims->add(t->total.label, cast(f64)t->total_time_seconds); - - - Parser *p = c->parser; - if (p != nullptr) { - isize lines = p->total_line_count; - isize tokens = p->total_token_count; - isize files = 0; - isize packages = p->packages.count; - isize total_file_size = 0; - for_array(i, p->packages) { - files += p->packages[i]->files.count; - for_array(j, p->packages[i]->files) { - AstFile *file = p->packages[i]->files[j]; - total_file_size += file->tokenizer.end - file->tokenizer.start; - } - } - - tims->add("total_lines", cast(i64)lines); - tims->add("total_tokens", cast(i64)tokens); - tims->add("total_files", cast(i64)files); - tims->add("total_packages", cast(i64)packages); - tims->add("total_file_size", cast(i64)total_file_size); - - auto *sections = query_value_map(); - sections->reserve(t->sections.count); - tims->add("sections", sections); - for_array(i, t->sections) { - TimeStamp ts = t->sections[i]; - f64 section_time = time_stamp_as_s(ts, t->freq); - - auto *section = query_value_map(); - section->reserve(2); - sections->add(ts.label, section); - section->add("time", cast(f64)section_time); - section->add("total_fraction", cast(f64)(section_time/t->total_time_seconds)); - } - } - } - - - print_query_data_as_json(root, !build_context.query_data_set_settings.compact); - gb_printf("\n"); -} - - - -template -struct BinaryArray { - u32 offset; // Offset in bytes from the top of the file - u32 length; // Number of elements in array of type T -}; - -template -gb_internal Array binary_array_from_data(BinaryArray ba, void *data) { - Array res = {}; - res.data = cast(T *)(cast(u8 *)data + ba.offset); - res.count = ba.length; - res.capacity = ba.length; - return res; -} - -typedef BinaryArray BinaryString; - -struct GoToDefIdent { - u64 use_offset; // offset of identifier use in bytes from the start of the file that contains it - u32 len; // length in bytes of the identifier - u32 def_file_id; - u64 def_offset; // offset of entity definition in bytes from the start of the file that contains it -}; - -struct GoToDefFile { - u32 id; - BinaryString path; - BinaryArray idents; -}; - -struct GoToDefHeader { - u8 magic[4]; // ogtd (odin-go-to-definitions) - u32 version; // 1 - BinaryArray files; -}; - -struct GoToDefFileMap { - AstFile *f; - u32 id; - Array idents; -}; - - -gb_internal int go_to_def_file_map_compare(void const *a, void const *b) { - GoToDefFileMap const *x = cast(GoToDefFileMap const *)a; - GoToDefFileMap const *y = cast(GoToDefFileMap const *)b; - if (x == y) { - return 0; - } else if (x != nullptr && y == nullptr) { - return -1; - } else if (x == nullptr && y != nullptr) { - return +1; - } - if (x->f->id < y->f->id) { - return -1; - } else if (x->f->id > y->f->id) { - return +1; - } - return 0; -} - -gb_internal int quick_ident_compare(void const *a, void const *b) { - Ast *x = *cast(Ast **)a; - Ast *y = *cast(Ast **)b; - - // NOTE(bill): This assumes that the file is same - if (x->Ident.token.pos.offset < y->Ident.token.pos.offset) { - return -1; - } else if (x->Ident.token.pos.offset > y->Ident.token.pos.offset) { - return +1; - } - return 0; -} - - -gb_internal void generate_and_print_query_data_go_to_definitions(Checker *c) { - GB_ASSERT(c->info.allow_identifier_uses); - - gbAllocator a = query_value_allocator; - - isize file_path_memory_needed = 0; - auto files = array_make(a, 0, c->info.files.entries.count); - for (auto const &entry : c->info.files) { - AstFile *f = entry.value; - file_path_memory_needed += f->fullpath.len+1; // add NUL terminator - - - GoToDefFileMap x = {}; - x.f = f; - array_init(&x.idents, a); - array_add(&files, x); - } - gb_sort_array(files.data, files.count, go_to_def_file_map_compare); - - auto file_id_map_to_index = array_make(a, files[files.count-1].f->id + 1); - for_array(i, file_id_map_to_index) { - file_id_map_to_index[i] = -1; - } - for_array(i, files) { - file_id_map_to_index[files[i].f->id] = i; - } - - - - for_array(i, c->info.identifier_uses) { - Ast *ast = c->info.identifier_uses[i]; - GB_ASSERT(ast->kind == Ast_Ident); - TokenPos pos = ast->Ident.token.pos; - Entity *e = ast->Ident.entity; - if (e == nullptr) { - continue; - } - - - AstFile **use_file_found = string_map_get(&c->info.files, get_file_path_string(pos.file_id)); - GB_ASSERT(use_file_found != nullptr); - AstFile *use_file = *use_file_found; - GB_ASSERT(use_file != nullptr); - - if (e->scope == nullptr) { - GB_ASSERT(e->flags & EntityFlag_Field); - continue; - } - if (e->scope->flags & ScopeFlag_Global) { - continue; - } - - isize idx = file_id_map_to_index[use_file->id]; - if (idx >= 0) { - array_add(&files[idx].idents, ast); - } else { - // TODO(bill): Handle invalid map case? - } - } - - for_array(i, files) { - GoToDefFileMap *f = &files[i]; - gb_sort_array(f->idents.data, f->idents.count, quick_ident_compare); - // gb_printf_err("%lld %.*s -> %lld\n", f->f->id, LIT(f->f->fullpath), f->idents.count); - } - - - - isize data_min_size = 0; - - u32 header_offset = cast(u32)data_min_size; gb_unused(header_offset); - data_min_size += gb_size_of(GoToDefHeader); - data_min_size = align_formula_isize(data_min_size, 8); - - u32 file_offset = cast(u32)data_min_size; - data_min_size += gb_size_of(GoToDefFile) * files.count; - data_min_size = align_formula_isize(data_min_size, 8); - - u32 file_path_offset = cast(u32)data_min_size; - data_min_size += file_path_memory_needed; - data_min_size = align_formula_isize(data_min_size, 8); - - u32 idents_offset = cast(u32)data_min_size; - data_min_size += gb_size_of(GoToDefIdent) * c->info.identifier_uses.count; - - - auto data = array_make(a, 0, data_min_size); - defer (array_free(&data)); - - GoToDefHeader header = {}; - gb_memmove(header.magic, "ogtd", 4); - header.version = 1; - header.files.length = cast(u32)files.count; - header.files.offset = file_offset; - - array_add_elems(&data, cast(u8 *)&header, gb_size_of(header)); - - array_resize(&data, data_min_size); - - auto binary_files = binary_array_from_data(header.files, data.data); - - u32 file_path_offset_index = file_path_offset; - u32 idents_offset_index = idents_offset; - for_array(i, files) { - GoToDefFileMap *f_map = &files[i]; - AstFile *f = f_map->f; - binary_files[i].id = cast(u32)f->id; - - binary_files[i].path.offset = file_path_offset_index; - binary_files[i].path.length = cast(u32)f->fullpath.len; - - binary_files[i].idents.offset = idents_offset_index; - binary_files[i].idents.length = cast(u32)f_map->idents.count; - - auto path = binary_array_from_data(binary_files[i].path, data.data); - gb_memmove(path.data, f->fullpath.text, f->fullpath.len); - path.data[f->fullpath.len] = 0; - - - auto idents = binary_array_from_data(binary_files[i].idents, data.data); - for_array(j, f_map->idents) { - Ast *ast = f_map->idents[j]; - GB_ASSERT(ast->kind == Ast_Ident); - - Entity *e = ast->Ident.entity; - TokenPos def = e->token.pos; - AstFile *def_file = e->file; - - if (def_file == nullptr) { - auto *def_file_found = string_map_get(&c->info.files, get_file_path_string(e->token.pos.file_id)); - if (def_file_found == nullptr) { - continue; - } - def_file = *def_file_found; - } - - isize file_index = file_id_map_to_index[def_file->id]; - GB_ASSERT(file_index >= 0); - - idents[j].use_offset = cast(u64)ast->Ident.token.pos.offset; - idents[j].len = cast(u32)ast->Ident.token.string.len; - idents[j].def_file_id = cast(u32)def_file->id; - idents[j].def_offset = cast(u64)e->token.pos.offset; - - // gb_printf_err("%llu %llu %llu %llu\n", idents[j].len, idents[j].use_offset, idents[j].def_file_id, idents[j].def_offset); - } - - file_path_offset_index += cast(u32)(f->fullpath.len + 1); - idents_offset_index += cast(u32)(f_map->idents.count * gb_size_of(GoToDefIdent)); - } - - - gb_file_write(gb_file_get_standard(gbFileStandard_Output), data.data, data.count*gb_size_of(*data.data)); -} - diff --git a/src/range_cache.cpp b/src/range_cache.cpp index 1f98c4b9e..fc85e2a2e 100644 --- a/src/range_cache.cpp +++ b/src/range_cache.cpp @@ -59,12 +59,12 @@ gb_internal bool range_cache_add_range(RangeCache *c, i64 lo, i64 hi) { } -gb_internal bool range_cache_index_exists(RangeCache *c, i64 index) { - for_array(i, c->ranges) { - RangeValue v = c->ranges[i]; - if (v.lo <= index && index <= v.hi) { - return true; - } - } - return false; -} +// gb_internal bool range_cache_index_exists(RangeCache *c, i64 index) { +// for_array(i, c->ranges) { +// RangeValue v = c->ranges[i]; +// if (v.lo <= index && index <= v.hi) { +// return true; +// } +// } +// return false; +// } diff --git a/src/string.cpp b/src/string.cpp index aeb31c7b0..8cce0f1ef 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -89,14 +89,6 @@ gb_internal char *alloc_cstring(gbAllocator a, String s) { return c_str; } -gb_internal char *cstring_duplicate(gbAllocator a, char const *s) { - isize len = gb_strlen(s); - char *c_str = gb_alloc_array(a, char, len+1); - gb_memmove(c_str, s, len); - c_str[len] = '\0'; - return c_str; -} - gb_internal gb_inline bool str_eq_ignore_case(String const &a, String const &b) { @@ -166,12 +158,6 @@ gb_internal isize string_index_byte(String const &s, u8 x) { return -1; } -gb_internal GB_COMPARE_PROC(string_cmp_proc) { - String x = *(String *)a; - String y = *(String *)b; - return string_compare(x, y); -} - gb_internal gb_inline bool str_eq(String const &a, String const &b) { if (a.len != b.len) return false; return memcmp(a.text, b.text, a.len) == 0; diff --git a/src/string_map.cpp b/src/string_map.cpp index e289d4c9b..9f9374ece 100644 --- a/src/string_map.cpp +++ b/src/string_map.cpp @@ -18,8 +18,6 @@ gb_internal gb_inline bool string_hash_key_equal(StringHashKey const &a, StringH } return false; } -gb_internal bool operator==(StringHashKey const &a, StringHashKey const &b) { return string_hash_key_equal(a, b); } -gb_internal bool operator!=(StringHashKey const &a, StringHashKey const &b) { return !string_hash_key_equal(a, b); } template struct StringMapEntry { diff --git a/src/threading.cpp b/src/threading.cpp index 511d1b477..b74d087b4 100644 --- a/src/threading.cpp +++ b/src/threading.cpp @@ -1,6 +1,10 @@ #if defined(GB_SYSTEM_LINUX) #include #endif +#if defined(GB_SYSTEM_WINDOWS) + #pragma warning(push) + #pragma warning(disable: 4505) +#endif struct BlockingMutex; struct RecursiveMutex; @@ -269,48 +273,6 @@ struct MutexGuard { } #endif - - -struct Barrier { - BlockingMutex mutex; - Condition cond; - isize index; - isize generation_id; - isize thread_count; -}; - -gb_internal void barrier_init(Barrier *b, isize thread_count) { - mutex_init(&b->mutex); - condition_init(&b->cond); - b->index = 0; - b->generation_id = 0; - b->thread_count = 0; -} - -gb_internal void barrier_destroy(Barrier *b) { - condition_destroy(&b->cond); - mutex_destroy(&b->mutex); -} - -// Returns true if it is the leader -gb_internal bool barrier_wait(Barrier *b) { - mutex_lock(&b->mutex); - defer (mutex_unlock(&b->mutex)); - isize local_gen = b->generation_id; - b->index += 1; - if (b->index < b->thread_count) { - while (local_gen == b->generation_id && b->index < b->thread_count) { - condition_wait(&b->cond, &b->mutex); - } - return false; - } - b->index = 0; - b->generation_id += 1; - condition_broadcast(&b->cond); - return true; -} - - gb_internal u32 thread_current_id(void) { @@ -494,3 +456,7 @@ gb_internal void thread_set_name(Thread *t, char const *name) { #endif } + +#if defined(GB_SYSTEM_WINDOWS) + #pragma warning(pop) +#endif \ No newline at end of file diff --git a/src/types.cpp b/src/types.cpp index c8e24f01d..b1d3883c6 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -430,15 +430,6 @@ gb_internal Selection sub_selection(Selection const &sel, isize offset) { return res; } -gb_internal Selection sub_selection_with_length(Selection const &sel, isize offset, isize len) { - Selection res = {}; - res.index.data = sel.index.data + offset; - res.index.count = gb_max(len, gb_max(sel.index.count - offset, 0)); - res.index.capacity = res.index.count; - return res; -} - - gb_global Type basic_types[] = { {Type_Basic, {Basic_Invalid, 0, 0, STR_LIT("invalid type")}}, @@ -1089,15 +1080,6 @@ gb_internal Type *alloc_type_proc(Scope *scope, Type *params, isize param_count, gb_internal bool is_type_valid_for_keys(Type *t); -gb_internal Type *alloc_type_map(i64 count, Type *key, Type *value) { - if (key != nullptr) { - GB_ASSERT(value != nullptr); - } - Type *t = alloc_type(Type_Map); - t->Map.key = key; - t->Map.value = value; - return t; -} gb_internal Type *alloc_type_bit_set() { Type *t = alloc_type(Type_BitSet); @@ -1152,19 +1134,6 @@ gb_internal bool is_type_named(Type *t) { } return t->kind == Type_Named; } -gb_internal bool is_type_named_alias(Type *t) { - if (!is_type_named(t)) { - return false; - } - Entity *e = t->Named.type_name; - if (e == nullptr) { - return false; - } - if (e->kind != Entity_TypeName) { - return false; - } - return e->TypeName.is_type_alias; -} gb_internal bool is_type_boolean(Type *t) { // t = core_type(t); @@ -1329,27 +1298,6 @@ gb_internal bool is_type_complex_or_quaternion(Type *t) { } return false; } -gb_internal bool is_type_f16(Type *t) { - t = core_type(t); - if (t->kind == Type_Basic) { - return t->Basic.kind == Basic_f16; - } - return false; -} -gb_internal bool is_type_f32(Type *t) { - t = core_type(t); - if (t->kind == Type_Basic) { - return t->Basic.kind == Basic_f32; - } - return false; -} -gb_internal bool is_type_f64(Type *t) { - t = core_type(t); - if (t->kind == Type_Basic) { - return t->Basic.kind == Basic_f64; - } - return false; -} gb_internal bool is_type_pointer(Type *t) { t = base_type(t); if (t->kind == Type_Basic) { @@ -1550,10 +1498,6 @@ gb_internal bool is_type_asm_proc(Type *t) { t = base_type(t); return t->kind == Type_Proc && t->Proc.calling_convention == ProcCC_InlineAsm; } -gb_internal bool is_type_poly_proc(Type *t) { - t = base_type(t); - return t->kind == Type_Proc && t->Proc.is_polymorphic; -} gb_internal bool is_type_simd_vector(Type *t) { t = base_type(t); return t->kind == Type_SimdVector; @@ -1915,11 +1859,6 @@ gb_internal bool is_type_empty_union(Type *t) { t = base_type(t); return t->kind == Type_Union && t->Union.variants.count == 0; } -gb_internal bool is_type_empty_struct(Type *t) { - t = base_type(t); - return t->kind == Type_Struct && !t->Struct.is_raw_union && t->Struct.fields.count == 0; -} - gb_internal bool is_type_valid_for_keys(Type *t) { t = core_type(t); @@ -4051,20 +3990,6 @@ gb_internal Type *reduce_tuple_to_single_type(Type *original_type) { return original_type; } - -gb_internal Type *alloc_type_struct_from_field_types(Type **field_types, isize field_count, bool is_packed) { - Type *t = alloc_type_struct(); - t->Struct.fields = slice_make(heap_allocator(), field_count); - - Scope *scope = nullptr; - for_array(i, t->Struct.fields) { - t->Struct.fields[i] = alloc_entity_field(scope, blank_token, field_types[i], false, cast(i32)i, EntityState_Resolved); - } - t->Struct.is_packed = is_packed; - - return t; -} - gb_internal Type *alloc_type_tuple_from_field_types(Type **field_types, isize field_count, bool is_packed, bool must_be_tuple) { if (field_count == 0) { return nullptr; -- cgit v1.2.3 From ca8b148fdc6318c68018903c34f801b943b1a7fc Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 18 Dec 2022 22:52:18 +0000 Subject: Add `gb_internal` to path procedures --- src/path.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/path.cpp b/src/path.cpp index 6f83c39ea..500a40cc2 100644 --- a/src/path.cpp +++ b/src/path.cpp @@ -1,7 +1,7 @@ /* Path handling utilities. */ -String remove_extension_from_path(String const &s) { +gb_internal String remove_extension_from_path(String const &s) { for (isize i = s.len-1; i >= 0; i--) { if (s[i] == '.') { return substring(s, 0, i); @@ -10,7 +10,7 @@ String remove_extension_from_path(String const &s) { return s; } -String remove_directory_from_path(String const &s) { +gb_internal String remove_directory_from_path(String const &s) { isize len = 0; for (isize i = s.len-1; i >= 0; i--) { if (s[i] == '/' || @@ -22,9 +22,9 @@ String remove_directory_from_path(String const &s) { return substring(s, s.len-len, s.len); } -bool path_is_directory(String path); +gb_internal bool path_is_directory(String path); -String directory_from_path(String const &s) { +gb_internal String directory_from_path(String const &s) { if (path_is_directory(s)) { return s; } @@ -43,7 +43,7 @@ String directory_from_path(String const &s) { } #if defined(GB_SYSTEM_WINDOWS) - bool path_is_directory(String path) { + gb_internal bool path_is_directory(String path) { gbAllocator a = heap_allocator(); String16 wstr = string_to_string16(a, path); defer (gb_free(a, wstr.text)); @@ -55,7 +55,7 @@ String directory_from_path(String const &s) { } #else - bool path_is_directory(String path) { + gb_internal bool path_is_directory(String path) { gbAllocator a = heap_allocator(); char *copy = cast(char *)copy_string(a, path).text; defer (gb_free(a, copy)); @@ -69,7 +69,7 @@ String directory_from_path(String const &s) { #endif -String path_to_full_path(gbAllocator a, String path) { +gb_internal String path_to_full_path(gbAllocator a, String path) { gbAllocator ha = heap_allocator(); char *path_c = gb_alloc_str_len(ha, cast(char *)path.text, path.len); defer (gb_free(ha, path_c)); @@ -93,7 +93,7 @@ struct Path { }; // NOTE(Jeroen): Naively turns a Path into a string. -String path_to_string(gbAllocator a, Path path) { +gb_internal String path_to_string(gbAllocator a, Path path) { if (path.basename.len + path.name.len + path.ext.len == 0) { return make_string(nullptr, 0); } @@ -121,7 +121,7 @@ String path_to_string(gbAllocator a, Path path) { } // NOTE(Jeroen): Naively turns a Path into a string, then normalizes it using `path_to_full_path`. -String path_to_full_path(gbAllocator a, Path path) { +gb_internal String path_to_full_path(gbAllocator a, Path path) { String temp = path_to_string(heap_allocator(), path); defer (gb_free(heap_allocator(), temp.text)); @@ -130,7 +130,7 @@ String path_to_full_path(gbAllocator a, Path path) { // NOTE(Jeroen): Takes a path like "odin" or "W:\Odin", turns it into a full path, // and then breaks it into its components to make a Path. -Path path_from_string(gbAllocator a, String const &path) { +gb_internal Path path_from_string(gbAllocator a, String const &path) { Path res = {}; if (path.len == 0) return res; @@ -161,7 +161,7 @@ Path path_from_string(gbAllocator a, String const &path) { } // NOTE(Jeroen): Takes a path String and returns the last path element. -String last_path_element(String const &path) { +gb_internal String last_path_element(String const &path) { isize count = 0; u8 * start = (u8 *)(&path.text[path.len - 1]); for (isize length = path.len; length > 0 && path.text[length - 1] != '/'; length--) { @@ -177,7 +177,7 @@ String last_path_element(String const &path) { return STR_LIT(""); } -bool path_is_directory(Path path) { +gb_internal bool path_is_directory(Path path) { String path_string = path_to_full_path(heap_allocator(), path); defer (gb_free(heap_allocator(), path_string.text)); @@ -204,7 +204,7 @@ enum ReadDirectoryError { ReadDirectory_COUNT, }; -i64 get_file_size(String path) { +gb_internal i64 get_file_size(String path) { char *c_str = alloc_cstring(heap_allocator(), path); defer (gb_free(heap_allocator(), c_str)); @@ -219,7 +219,7 @@ i64 get_file_size(String path) { #if defined(GB_SYSTEM_WINDOWS) -ReadDirectoryError read_directory(String path, Array *fi) { +gb_internal ReadDirectoryError read_directory(String path, Array *fi) { GB_ASSERT(fi != nullptr); gbAllocator a = heap_allocator(); @@ -314,7 +314,7 @@ ReadDirectoryError read_directory(String path, Array *fi) { #include -ReadDirectoryError read_directory(String path, Array *fi) { +gb_internal ReadDirectoryError read_directory(String path, Array *fi) { GB_ASSERT(fi != nullptr); gbAllocator a = heap_allocator(); -- cgit v1.2.3 From e27046098b12a678e9680d73d315b4c7c19c2101 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 18 Dec 2022 22:58:34 +0000 Subject: Add missing `gb_internal` --- src/build_settings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/build_settings.cpp b/src/build_settings.cpp index 7d796d775..630cec601 100644 --- a/src/build_settings.cpp +++ b/src/build_settings.cpp @@ -720,7 +720,7 @@ gb_internal String internal_odin_root_dir(void) { #include -String path_to_fullpath(gbAllocator a, String s); +gb_internal String path_to_fullpath(gbAllocator a, String s); gb_internal String internal_odin_root_dir(void) { String path = global_module_path; -- cgit v1.2.3 From 2a8fa8612de858d40b0812913817c8550db11630 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 18 Dec 2022 23:24:34 +0000 Subject: Use `fetch_add` rather than `+=` --- src/common_memory.cpp | 4 ++-- src/parser.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/common_memory.cpp b/src/common_memory.cpp index 63b7c24ef..c8a62756a 100644 --- a/src/common_memory.cpp +++ b/src/common_memory.cpp @@ -165,11 +165,11 @@ gb_internal void platform_virtual_memory_protect(void *memory, isize size); gb_printf_err("Total Usage: %lld bytes\n", cast(long long)global_platform_memory_total_usage); GB_ASSERT_MSG(pmblock != nullptr, "Out of Virtual Memory, oh no..."); } - global_platform_memory_total_usage += total_size; + global_platform_memory_total_usage.fetch_add(total_size); return pmblock; } gb_internal void platform_virtual_memory_free(PlatformMemoryBlock *block) { - global_platform_memory_total_usage -= block->total_size; + global_platform_memory_total_usage.fetch_sub(block->total_size); GB_ASSERT(VirtualFree(block, 0, MEM_RELEASE)); } gb_internal void platform_virtual_memory_protect(void *memory, isize size) { diff --git a/src/parser.cpp b/src/parser.cpp index 2ccdac7fa..520f123d8 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -72,7 +72,7 @@ gb_internal Ast *alloc_ast_node(AstFile *f, AstKind kind) { node->kind = kind; node->file_id = f ? f->id : 0; - global_total_node_memory_allocated += size; + global_total_node_memory_allocated.fetch_add(size); return node; } -- cgit v1.2.3 From 01b508f18222a34ee8b47ede54798dc877d93e81 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 18 Dec 2022 23:26:44 +0000 Subject: Use `usize` for bounds checking in `Array` and `Slice` (compiler) --- src/array.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/array.cpp b/src/array.cpp index c633078f6..f1a1f93e2 100644 --- a/src/array.cpp +++ b/src/array.cpp @@ -10,14 +10,14 @@ struct Array { T &operator[](isize index) { #if !defined(NO_ARRAY_BOUNDS_CHECK) - GB_ASSERT_MSG(0 <= index && index < count, "Index %td is out of bounds ranges 0..<%td", index, count); + GB_ASSERT_MSG(cast(usize)index < cast(usize)count, "Index %td is out of bounds ranges 0..<%td", index, count); #endif return data[index]; } T const &operator[](isize index) const { #if !defined(NO_ARRAY_BOUNDS_CHECK) - GB_ASSERT_MSG(0 <= index && index < count, "Index %td is out of bounds ranges 0..<%td", index, count); + GB_ASSERT_MSG(cast(usize)index < cast(usize)count, "Index %td is out of bounds ranges 0..<%td", index, count); #endif return data[index]; } @@ -58,14 +58,14 @@ struct Slice { gb_inline T &operator[](isize index) { #if !defined(NO_ARRAY_BOUNDS_CHECK) - GB_ASSERT_MSG(0 <= index && index < count, "Index %td is out of bounds ranges 0..<%td", index, count); + GB_ASSERT_MSG(cast(usize)index < cast(usize)count, "Index %td is out of bounds ranges 0..<%td", index, count); #endif return data[index]; } gb_inline T const &operator[](isize index) const { #if !defined(NO_ARRAY_BOUNDS_CHECK) - GB_ASSERT_MSG(0 <= index && index < count, "Index %td is out of bounds ranges 0..<%td", index, count); + GB_ASSERT_MSG(cast(usize)index < cast(usize)count, "Index %td is out of bounds ranges 0..<%td", index, count); #endif return data[index]; } -- cgit v1.2.3 From a13e2f4578eb5557afb8bc6b21930032bedbbb43 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 19 Dec 2022 00:29:40 +0000 Subject: Fix minor race condition --- src/checker.cpp | 48 ++++++++++++++++++++++++++++++++++++++---------- src/checker.hpp | 5 +++++ 2 files changed, 43 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/checker.cpp b/src/checker.cpp index f130a965f..7cafcea2e 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -184,6 +184,7 @@ gb_internal void init_decl_info(DeclInfo *d, Scope *scope, DeclInfo *parent) { ptr_set_init(&d->deps, heap_allocator()); ptr_set_init(&d->type_info_deps, heap_allocator()); array_init (&d->labels, heap_allocator()); + mutex_init(&d->proc_checked_mutex); } gb_internal DeclInfo *make_decl_info(Scope *scope, DeclInfo *parent) { @@ -193,6 +194,7 @@ gb_internal DeclInfo *make_decl_info(Scope *scope, DeclInfo *parent) { } // gb_internal void destroy_declaration_info(DeclInfo *d) { +// mutex_destroy(&d->proc_checked_mutex); // ptr_set_destroy(&d->deps); // array_free(&d->labels); // } @@ -1200,30 +1202,51 @@ gb_internal CheckerContext make_checker_context(Checker *c) { ctx.type_path = new_checker_type_path(); ctx.type_level = 0; + mutex_init(&ctx.mutex); return ctx; } gb_internal void destroy_checker_context(CheckerContext *ctx) { + mutex_destroy(&ctx->mutex); destroy_checker_type_path(ctx->type_path); } -gb_internal void add_curr_ast_file(CheckerContext *ctx, AstFile *file) { +gb_internal bool add_curr_ast_file(CheckerContext *ctx, AstFile *file) { if (file != nullptr) { ctx->file = file; ctx->decl = file->pkg->decl_info; ctx->scope = file->scope; ctx->pkg = file->pkg; + return true; } + return false; } gb_internal void reset_checker_context(CheckerContext *ctx, AstFile *file, UntypedExprInfoMap *untyped) { if (ctx == nullptr) { return; } - destroy_checker_context(ctx); + GB_ASSERT(ctx->checker != nullptr); + mutex_lock(&ctx->mutex); + auto *queue = ctx->procs_to_check_queue; - *ctx = make_checker_context(ctx->checker); + auto type_path = ctx->type_path; + array_clear(type_path); + + zero_size(&ctx->pkg, gb_size_of(CheckerContext) - gb_offset_of(CheckerContext, pkg)); + + ctx->file = nullptr; + ctx->scope = builtin_pkg->scope; + ctx->pkg = builtin_pkg; + ctx->decl = nullptr; + + ctx->type_path = type_path; + ctx->type_level = 0; + add_curr_ast_file(ctx, file); + ctx->procs_to_check_queue = queue; ctx->untyped = untyped; + + mutex_unlock(&ctx->mutex); } @@ -5067,11 +5090,14 @@ gb_internal bool check_proc_info(Checker *c, ProcInfo *pi, UntypedExprInfoMap *u return false; } Entity *e = pi->decl->entity; - if (pi->decl->proc_checked) { - if (e != nullptr) { - GB_ASSERT(e->flags & EntityFlag_ProcBodyChecked); + + MUTEX_GUARD_BLOCK(&pi->decl->proc_checked_mutex) { + if (pi->decl->proc_checked) { + if (e != nullptr) { + GB_ASSERT(e->flags & EntityFlag_ProcBodyChecked); + } + return true; } - return true; } CheckerContext ctx = make_checker_context(c); @@ -5128,10 +5154,12 @@ gb_internal bool check_proc_info(Checker *c, ProcInfo *pi, UntypedExprInfoMap *u } check_proc_body(&ctx, pi->token, pi->decl, pi->type, pi->body); - if (e != nullptr) { - e->flags |= EntityFlag_ProcBodyChecked; + MUTEX_GUARD_BLOCK(&pi->decl->proc_checked_mutex) { + if (e != nullptr) { + e->flags |= EntityFlag_ProcBodyChecked; + } + pi->decl->proc_checked = true; } - pi->decl->proc_checked = true; add_untyped_expressions(&c->info, ctx.untyped); return true; } diff --git a/src/checker.hpp b/src/checker.hpp index 58f6a027c..6799503cd 100644 --- a/src/checker.hpp +++ b/src/checker.hpp @@ -158,6 +158,7 @@ struct DeclInfo { bool is_using; bool where_clauses_evaluated; bool proc_checked; + BlockingMutex proc_checked_mutex; isize defer_used; bool defer_use_checked; @@ -377,13 +378,17 @@ struct CheckerInfo { }; struct CheckerContext { + // Order matters here + BlockingMutex mutex; Checker * checker; CheckerInfo * info; + AstPackage * pkg; AstFile * file; Scope * scope; DeclInfo * decl; + // Order doesn't matter after this u32 state_flags; bool in_defer; // TODO(bill): Actually handle correctly Type * type_hint; -- cgit v1.2.3 From 0edda2bea769303166eaab2965f6cfb8b2bd807c Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 20 Dec 2022 12:46:33 +0000 Subject: Clarify ThreadPool interface; Move `import_mutex` guarding to just the string set --- src/parser.cpp | 14 ++++++-------- src/thread_pool.cpp | 12 ++++++++++++ 2 files changed, 18 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/parser.cpp b/src/parser.cpp index 520f123d8..eb006cb24 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -4966,14 +4966,12 @@ gb_internal void parser_add_foreign_file_to_process(Parser *p, AstPackage *pkg, gb_internal AstPackage *try_add_import_path(Parser *p, String const &path, String const &rel_path, TokenPos pos, PackageKind kind = Package_Normal) { String const FILE_EXT = str_lit(".odin"); - mutex_lock(&p->import_mutex); - defer (mutex_unlock(&p->import_mutex)); - - if (string_set_exists(&p->imported_files, path)) { - return nullptr; + MUTEX_GUARD_BLOCK(&p->import_mutex) { + if (string_set_exists(&p->imported_files, path)) { + return nullptr; + } + string_set_add(&p->imported_files, path); } - string_set_add(&p->imported_files, path); - AstPackage *pkg = gb_alloc_item(permanent_allocator(), AstPackage); pkg->kind = kind; @@ -4991,8 +4989,8 @@ gb_internal AstPackage *try_add_import_path(Parser *p, String const &path, Strin fi.is_dir = false; pkg->is_single_file = true; - parser_add_file_to_process(p, pkg, fi, pos); parser_add_package(p, pkg); + parser_add_file_to_process(p, pkg, fi, pos); return pkg; } diff --git a/src/thread_pool.cpp b/src/thread_pool.cpp index 1b3e74fbe..eca4d37ab 100644 --- a/src/thread_pool.cpp +++ b/src/thread_pool.cpp @@ -1,14 +1,25 @@ // thread_pool.cpp +struct WorkerTask; +struct ThreadPool; + #define WORKER_TASK_PROC(name) isize name(void *data) typedef WORKER_TASK_PROC(WorkerTaskProc); +gb_internal void thread_pool_init(ThreadPool *pool, gbAllocator const &a, isize thread_count, char const *worker_name); +gb_internal void thread_pool_destroy(ThreadPool *pool); +gb_internal bool thread_pool_add_task(ThreadPool *pool, WorkerTaskProc *proc, void *data); +gb_internal void thread_pool_wait(ThreadPool *pool); + + struct WorkerTask { WorkerTask * next; WorkerTaskProc *do_work; void * data; + ThreadPool * pool; }; + struct ThreadPool { gbAllocator allocator; BlockingMutex mutex; @@ -89,6 +100,7 @@ gb_internal bool thread_pool_add_task(ThreadPool *pool, WorkerTaskProc *proc, vo GB_PANIC("Out of memory"); return false; } + task->pool = pool; task->do_work = proc; task->data = data; -- cgit v1.2.3 From a0e3a99dd165858136dd0d60759b08b22f81cfa2 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 20 Dec 2022 14:07:14 +0000 Subject: Remove need for `semaphore` in `Thread` --- src/thread_pool.cpp | 7 +------ src/threading.cpp | 41 ++++++++++++++--------------------------- 2 files changed, 15 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/thread_pool.cpp b/src/thread_pool.cpp index eca4d37ab..ba150bb6f 100644 --- a/src/thread_pool.cpp +++ b/src/thread_pool.cpp @@ -45,12 +45,7 @@ gb_internal void thread_pool_init(ThreadPool *pool, gbAllocator const &a, isize slice_init(&pool->threads, a, thread_count); for_array(i, pool->threads) { Thread *t = &pool->threads[i]; - thread_init(t); - } - - for_array(i, pool->threads) { - Thread *t = &pool->threads[i]; - thread_start(t, thread_pool_thread_proc, pool); + thread_init_and_start(t, thread_pool_thread_proc, pool); } } diff --git a/src/threading.cpp b/src/threading.cpp index b74d087b4..30e9071d8 100644 --- a/src/threading.cpp +++ b/src/threading.cpp @@ -27,7 +27,6 @@ struct Thread { isize user_index; isize volatile return_value; - Semaphore * semaphore; isize stack_size; std::atomic is_running; }; @@ -60,10 +59,9 @@ gb_internal void condition_wait_with_timeout(Condition *c, BlockingMutex *m, u32 gb_internal u32 thread_current_id(void); -gb_internal void thread_init (Thread *t); +gb_internal void thread_init_and_start (Thread *t, ThreadProc *proc, void *data); +gb_internal void thread_init_and_start_with_stack(Thread *t, ThreadProc *proc, void *data, isize stack_size); gb_internal void thread_destroy (Thread *t); -gb_internal void thread_start (Thread *t, ThreadProc *proc, void *data); -gb_internal void thread_start_with_stack(Thread *t, ThreadProc *proc, void *data, isize stack_size); gb_internal void thread_join (Thread *t); gb_internal bool thread_is_running (Thread const *t); gb_internal void thread_set_name (Thread *t, char const *name); @@ -328,27 +326,12 @@ gb_internal gb_inline void yield(void) { #endif } - -gb_internal void thread_init(Thread *t) { - gb_zero_item(t); -#if defined(GB_SYSTEM_WINDOWS) - t->win32_handle = INVALID_HANDLE_VALUE; -#else - t->posix_handle = 0; -#endif - t->semaphore = gb_alloc_item(heap_allocator(), Semaphore); - semaphore_init(t->semaphore); -} - gb_internal void thread_destroy(Thread *t) { thread_join(t); - semaphore_destroy(t->semaphore); - gb_free(heap_allocator(), t->semaphore); } -gb_internal void gb__thread_run(Thread *t) { - semaphore_release(t->semaphore); +gb_internal void private__thread_run(Thread *t) { t->return_value = t->proc(t); } @@ -356,7 +339,7 @@ gb_internal void gb__thread_run(Thread *t) { gb_internal DWORD __stdcall internal_thread_proc(void *arg) { Thread *t = cast(Thread *)arg; t->is_running.store(true); - gb__thread_run(t); + private__thread_run(t); return 0; } #else @@ -370,14 +353,20 @@ gb_internal void gb__thread_run(Thread *t) { Thread *t = cast(Thread *)arg; t->is_running.store(true); - gb__thread_run(t); + private__thread_run(t); return NULL; } #endif -gb_internal void thread_start(Thread *t, ThreadProc *proc, void *user_data) { thread_start_with_stack(t, proc, user_data, 0); } +gb_internal void thread_init_and_start(Thread *t, ThreadProc *proc, void *user_data) { thread_init_and_start_with_stack(t, proc, user_data, 0); } -gb_internal void thread_start_with_stack(Thread *t, ThreadProc *proc, void *user_data, isize stack_size) { +gb_internal void thread_init_and_start_with_stack(Thread *t, ThreadProc *proc, void *user_data, isize stack_size) { + gb_zero_item(t); +#if defined(GB_SYSTEM_WINDOWS) + t->win32_handle = INVALID_HANDLE_VALUE; +#else + t->posix_handle = 0; +#endif GB_ASSERT(!t->is_running.load()); GB_ASSERT(proc != NULL); t->proc = proc; @@ -391,16 +380,14 @@ gb_internal void thread_start_with_stack(Thread *t, ThreadProc *proc, void *user { pthread_attr_t attr; pthread_attr_init(&attr); + defer (pthread_attr_destroy(&attr)); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); if (stack_size != 0) { pthread_attr_setstacksize(&attr, stack_size); } pthread_create(&t->posix_handle, &attr, internal_thread_proc, t); - pthread_attr_destroy(&attr); } #endif - - semaphore_wait(t->semaphore); } gb_internal void thread_join(Thread *t) { -- cgit v1.2.3 From 134c7db4d21e80751833ed45fb4ace5d0ae3b7d2 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 20 Dec 2022 14:08:24 +0000 Subject: Combine join and destroy for threads --- src/thread_pool.cpp | 9 ++------- src/threading.cpp | 10 ++-------- 2 files changed, 4 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/thread_pool.cpp b/src/thread_pool.cpp index ba150bb6f..a1ee11523 100644 --- a/src/thread_pool.cpp +++ b/src/thread_pool.cpp @@ -57,14 +57,9 @@ gb_internal void thread_pool_destroy(ThreadPool *pool) { for_array(i, pool->threads) { Thread *t = &pool->threads[i]; - thread_join(t); + thread_join_and_destroy(t); } - - for_array(i, pool->threads) { - Thread *t = &pool->threads[i]; - thread_destroy(t); - } - + gb_free(pool->allocator, pool->threads.data); mutex_destroy(&pool->mutex); condition_destroy(&pool->task_cond); diff --git a/src/threading.cpp b/src/threading.cpp index 30e9071d8..e92ed5e31 100644 --- a/src/threading.cpp +++ b/src/threading.cpp @@ -61,8 +61,7 @@ gb_internal u32 thread_current_id(void); gb_internal void thread_init_and_start (Thread *t, ThreadProc *proc, void *data); gb_internal void thread_init_and_start_with_stack(Thread *t, ThreadProc *proc, void *data, isize stack_size); -gb_internal void thread_destroy (Thread *t); -gb_internal void thread_join (Thread *t); +gb_internal void thread_join_and_destroy(Thread *t); gb_internal bool thread_is_running (Thread const *t); gb_internal void thread_set_name (Thread *t, char const *name); @@ -326,11 +325,6 @@ gb_internal gb_inline void yield(void) { #endif } -gb_internal void thread_destroy(Thread *t) { - thread_join(t); -} - - gb_internal void private__thread_run(Thread *t) { t->return_value = t->proc(t); } @@ -390,7 +384,7 @@ gb_internal void thread_init_and_start_with_stack(Thread *t, ThreadProc *proc, v #endif } -gb_internal void thread_join(Thread *t) { +gb_internal void thread_join_and_destroy(Thread *t) { if (!t->is_running.load()) { return; } -- cgit v1.2.3 From 8fc9566a837fbd3fe52f3f1b5e766e122b3c2de2 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 20 Dec 2022 14:19:55 +0000 Subject: Use `*_set_update` where possible --- src/check_builtin.cpp | 4 +--- src/check_stmt.cpp | 3 +-- src/checker.cpp | 7 ++----- src/parser.cpp | 3 +-- src/string_set.cpp | 52 +++++++++++++++++++++++++-------------------------- src/types.cpp | 2 +- 6 files changed, 32 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp index 859fbea28..1c13b6b5e 100644 --- a/src/check_builtin.cpp +++ b/src/check_builtin.cpp @@ -3126,13 +3126,11 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As } - if (string_set_exists(&name_set, name)) { + if (string_set_update(&name_set, name)) { error(op.expr, "Field argument name '%.*s' already exists", LIT(name)); } else { array_add(&types, arg_type->Slice.elem); array_add(&names, name); - - string_set_add(&name_set, name); } } diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index 73adbed8b..cf111e84c 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -1237,7 +1237,7 @@ gb_internal void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_ GB_PANIC("Unknown type to type switch statement"); } - if (type_ptr_set_exists(&seen, y.type)) { + if (type_ptr_set_update(&seen, y.type)) { TokenPos pos = cc->token.pos; gbString expr_str = expr_to_string(y.expr); error(y.expr, @@ -1248,7 +1248,6 @@ gb_internal void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_ gb_string_free(expr_str); break; } - ptr_set_add(&seen, y.type); } } diff --git a/src/checker.cpp b/src/checker.cpp index 7cafcea2e..14a0e5f4c 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -3414,11 +3414,9 @@ gb_internal void check_decl_attributes(CheckerContext *c, Array const &at continue; } - if (string_set_exists(&set, name)) { + if (string_set_update(&set, name)) { error(elem, "Previous declaration of '%.*s'", LIT(name)); continue; - } else { - string_set_add(&set, name); } if (!proc(c, elem, name, value, ac)) { @@ -4969,10 +4967,9 @@ gb_internal Array find_entity_path(Entity *start, Entity *end, PtrSet< Array empty_path = {}; - if (ptr_set_exists(visited, start)) { + if (ptr_set_update(visited, start)) { return empty_path; } - ptr_set_add(visited, start); DeclInfo *decl = start->decl_info; if (decl) { diff --git a/src/parser.cpp b/src/parser.cpp index eb006cb24..ad22ce5ff 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -4967,10 +4967,9 @@ gb_internal AstPackage *try_add_import_path(Parser *p, String const &path, Strin String const FILE_EXT = str_lit(".odin"); MUTEX_GUARD_BLOCK(&p->import_mutex) { - if (string_set_exists(&p->imported_files, path)) { + if (string_set_update(&p->imported_files, path)) { return nullptr; } - string_set_add(&p->imported_files, path); } AstPackage *pkg = gb_alloc_item(permanent_allocator(), AstPackage); diff --git a/src/string_set.cpp b/src/string_set.cpp index fce98ec75..1c97d253e 100644 --- a/src/string_set.cpp +++ b/src/string_set.cpp @@ -10,18 +10,18 @@ struct StringSet { }; -void string_set_init (StringSet *s, gbAllocator a, isize capacity = 16); -void string_set_destroy(StringSet *s); -void string_set_add (StringSet *s, String const &str); -bool string_set_update (StringSet *s, String const &str); // returns true if it previously existed -bool string_set_exists (StringSet *s, String const &str); -void string_set_remove (StringSet *s, String const &str); -void string_set_clear (StringSet *s); -void string_set_grow (StringSet *s); -void string_set_rehash (StringSet *s, isize new_count); - - -gb_inline void string_set_init(StringSet *s, gbAllocator a, isize capacity) { +gb_internal void string_set_init (StringSet *s, gbAllocator a, isize capacity = 16); +gb_internal void string_set_destroy(StringSet *s); +gb_internal void string_set_add (StringSet *s, String const &str); +gb_internal bool string_set_update (StringSet *s, String const &str); // returns true if it previously existed +gb_internal bool string_set_exists (StringSet *s, String const &str); +gb_internal void string_set_remove (StringSet *s, String const &str); +gb_internal void string_set_clear (StringSet *s); +gb_internal void string_set_grow (StringSet *s); +gb_internal void string_set_rehash (StringSet *s, isize new_count); + + +gb_internal gb_inline void string_set_init(StringSet *s, gbAllocator a, isize capacity) { capacity = next_pow2_isize(gb_max(16, capacity)); slice_init(&s->hashes, a, capacity); @@ -31,7 +31,7 @@ gb_inline void string_set_init(StringSet *s, gbAllocator a, isize capacity) { } } -gb_inline void string_set_destroy(StringSet *s) { +gb_internal gb_inline void string_set_destroy(StringSet *s) { slice_free(&s->hashes, s->entries.allocator); array_free(&s->entries); } @@ -82,13 +82,13 @@ gb_internal b32 string_set__full(StringSet *s) { return 0.75f * s->hashes.count <= s->entries.count; } -gb_inline void string_set_grow(StringSet *s) { +gb_internal gb_inline void string_set_grow(StringSet *s) { isize new_count = gb_max(s->hashes.count<<1, 16); string_set_rehash(s, new_count); } -void string_set_reset_entries(StringSet *s) { +gb_internal void string_set_reset_entries(StringSet *s) { for (isize i = 0; i < s->hashes.count; i++) { s->hashes.data[i] = MAP_SENTINEL; } @@ -105,7 +105,7 @@ void string_set_reset_entries(StringSet *s) { } } -void string_set_reserve(StringSet *s, isize cap) { +gb_internal void string_set_reserve(StringSet *s, isize cap) { array_reserve(&s->entries, cap); if (s->entries.count*2 < s->hashes.count) { return; @@ -115,7 +115,7 @@ void string_set_reserve(StringSet *s, isize cap) { } -void string_set_rehash(StringSet *s, isize new_count) { +gb_internal void string_set_rehash(StringSet *s, isize new_count) { string_set_reserve(s, new_count); } @@ -125,7 +125,7 @@ gb_inline bool string_set_exists(StringSet *s, String const &str) { return index != MAP_SENTINEL; } -void string_set_add(StringSet *s, String const &str) { +gb_internal void string_set_add(StringSet *s, String const &str) { MapIndex index; MapFindResult fr; StringHashKey key = string_hash_string(str); @@ -150,7 +150,7 @@ void string_set_add(StringSet *s, String const &str) { } } -bool string_set_update(StringSet *s, String const &str) { +gb_internal bool string_set_update(StringSet *s, String const &str) { bool exists = false; MapIndex index; MapFindResult fr; @@ -179,7 +179,7 @@ bool string_set_update(StringSet *s, String const &str) { } -void string_set__erase(StringSet *s, MapFindResult fr) { +gb_internal void string_set__erase(StringSet *s, MapFindResult fr) { MapFindResult last; if (fr.entry_prev == MAP_SENTINEL) { s->hashes[fr.hash_index] = s->entries[fr.entry_index].next; @@ -201,7 +201,7 @@ void string_set__erase(StringSet *s, MapFindResult fr) { } } -void string_set_remove(StringSet *s, String const &str) { +gb_internal void string_set_remove(StringSet *s, String const &str) { StringHashKey key = string_hash_string(str); MapFindResult fr = string_set__find(s, key); if (fr.entry_index != MAP_SENTINEL) { @@ -209,7 +209,7 @@ void string_set_remove(StringSet *s, String const &str) { } } -gb_inline void string_set_clear(StringSet *s) { +gb_internal gb_inline void string_set_clear(StringSet *s) { array_clear(&s->entries); for_array(i, s->hashes) { s->hashes.data[i] = MAP_SENTINEL; @@ -218,18 +218,18 @@ gb_inline void string_set_clear(StringSet *s) { -StringSetEntry *begin(StringSet &m) { +gb_internal StringSetEntry *begin(StringSet &m) { return m.entries.data; } -StringSetEntry const *begin(StringSet const &m) { +gb_internal StringSetEntry const *begin(StringSet const &m) { return m.entries.data; } -StringSetEntry *end(StringSet &m) { +gb_internal StringSetEntry *end(StringSet &m) { return m.entries.data + m.entries.count; } -StringSetEntry const *end(StringSet const &m) { +gb_internal StringSetEntry const *end(StringSet const &m) { return m.entries.data + m.entries.count; } \ No newline at end of file diff --git a/src/types.cpp b/src/types.cpp index b1d3883c6..890098ad0 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -812,7 +812,7 @@ gb_internal void init_type_mutex(void) { mutex_init(&g_type_mutex); } -gb_internal bool type_ptr_set_exists(PtrSet *s, Type *t) { +gb_internal bool type_ptr_set_update(PtrSet *s, Type *t) { if (ptr_set_exists(s, t)) { return true; } -- cgit v1.2.3 From eb0775ad53e9651ca01ad236dd3fe83786f0cecc Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 20 Dec 2022 14:45:01 +0000 Subject: Move `mutex` use around in thread pool --- src/thread_pool.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/thread_pool.cpp b/src/thread_pool.cpp index a1ee11523..6df991d7d 100644 --- a/src/thread_pool.cpp +++ b/src/thread_pool.cpp @@ -83,10 +83,8 @@ gb_internal void thread_pool_queue_push(ThreadPool *pool, WorkerTask *task) { gb_internal bool thread_pool_add_task(ThreadPool *pool, WorkerTaskProc *proc, void *data) { GB_ASSERT(proc != nullptr); - mutex_lock(&pool->mutex); WorkerTask *task = gb_alloc_item(permanent_allocator(), WorkerTask); if (task == nullptr) { - mutex_unlock(&pool->mutex); GB_PANIC("Out of memory"); return false; } @@ -94,9 +92,10 @@ gb_internal bool thread_pool_add_task(ThreadPool *pool, WorkerTaskProc *proc, vo task->do_work = proc; task->data = data; + mutex_lock(&pool->mutex); thread_pool_queue_push(pool, task); GB_ASSERT(pool->ready >= 0); - pool->ready++; + pool->ready.fetch_add(1); condition_broadcast(&pool->task_cond); mutex_unlock(&pool->mutex); return true; @@ -111,7 +110,7 @@ gb_internal void thread_pool_wait(ThreadPool *pool) { if (pool->threads.count == 0) { while (!thread_pool_queue_empty(pool)) { thread_pool_do_task(thread_pool_queue_pop(pool)); - --pool->ready; + pool->ready.fetch_sub(1); } GB_ASSERT(pool->ready == 0); return; -- cgit v1.2.3 From 44caa96d50574131e3615958eedc881e68c90905 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 20 Dec 2022 14:56:44 +0000 Subject: Set the file's filename and directory in `init_ast_file` --- src/llvm_backend.cpp | 7 ++----- src/parser.cpp | 6 ++++-- src/parser.hpp | 5 +++++ 3 files changed, 11 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index c5bc96eb9..146cb2944 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -1740,12 +1740,9 @@ gb_internal void lb_generate_code(lbGenerator *gen) { if (m->debug_builder) { // Debug Info for (auto const &file_entry : info->files) { AstFile *f = file_entry.value; - String fullpath = f->fullpath; - String filename = remove_directory_from_path(fullpath); - String directory = directory_from_path(fullpath); LLVMMetadataRef res = LLVMDIBuilderCreateFile(m->debug_builder, - cast(char const *)filename.text, filename.len, - cast(char const *)directory.text, directory.len); + cast(char const *)f->filename.text, f->filename.len, + cast(char const *)f->directory.text, f->directory.len); lb_set_llvm_metadata(m, f, res); } diff --git a/src/parser.cpp b/src/parser.cpp index ad22ce5ff..436498c51 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -4768,8 +4768,10 @@ gb_internal Array parse_stmt_list(AstFile *f) { gb_internal ParseFileError init_ast_file(AstFile *f, String const &fullpath, TokenPos *err_pos) { GB_ASSERT(f != nullptr); - f->fullpath = string_trim_whitespace(fullpath); // Just in case - set_file_path_string(f->id, fullpath); + f->fullpath = string_trim_whitespace(fullpath); // Just in case + f->filename = remove_directory_from_path(f->fullpath); + f->directory = directory_from_path(f->fullpath); + set_file_path_string(f->id, f->fullpath); thread_safe_set_ast_file_from_id(f->id, f); if (!string_ends_with(f->fullpath, str_lit(".odin"))) { return ParseFile_WrongExtension; diff --git a/src/parser.hpp b/src/parser.hpp index f7b3e51ae..7d292ffce 100644 --- a/src/parser.hpp +++ b/src/parser.hpp @@ -99,7 +99,11 @@ struct AstFile { Scope * scope; Ast * pkg_decl; + String fullpath; + String filename; + String directory; + Tokenizer tokenizer; Array tokens; isize curr_token_index; @@ -109,6 +113,7 @@ struct AstFile { Token package_token; String package_name; + // >= 0: In Expression // < 0: In Control Clause // NOTE(bill): Used to prevent type literals in control clauses -- cgit v1.2.3 From 3040361faca44fd8b1c8a5a7bb86c73a1c46e08f Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 20 Dec 2022 14:59:00 +0000 Subject: Correct `type_ptr_set_update` and `type_ptr_set_exists` --- src/types.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src') diff --git a/src/types.cpp b/src/types.cpp index 890098ad0..c113525d6 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -816,6 +816,14 @@ gb_internal bool type_ptr_set_update(PtrSet *s, Type *t) { if (ptr_set_exists(s, t)) { return true; } + ptr_set_add(s, t); + return false; +} + +gb_internal bool type_ptr_set_exists(PtrSet *s, Type *t) { + if (ptr_set_exists(s, t)) { + return true; + } // TODO(bill, 2019-10-05): This is very slow and it's probably a lot // faster to cache types correctly -- cgit v1.2.3 From e98f1a28e68e82753728f58b3465793192b74f9d Mon Sep 17 00:00:00 2001 From: gingerBill Date: Thu, 22 Dec 2022 11:53:13 +0000 Subject: Change `tav` to be a pointer internally --- src/check_expr.cpp | 68 ++++++++++++++++++++++---------------------- src/check_stmt.cpp | 10 +++---- src/check_type.cpp | 4 +-- src/checker.cpp | 22 +++++++------- src/llvm_backend_const.cpp | 56 ++++++++++++++++++------------------ src/llvm_backend_expr.cpp | 32 ++++++++++----------- src/llvm_backend_proc.cpp | 20 ++++++------- src/llvm_backend_stmt.cpp | 34 +++++++++++----------- src/llvm_backend_utility.cpp | 12 ++++---- src/parser.cpp | 8 ++++-- src/parser.hpp | 7 +++-- 11 files changed, 140 insertions(+), 133 deletions(-) (limited to 'src') diff --git a/src/check_expr.cpp b/src/check_expr.cpp index ed1ddd1f1..654dec051 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -2119,7 +2119,7 @@ gb_internal bool check_is_not_addressable(CheckerContext *c, Operand *o) { return true; } ast_node(ta, TypeAssertion, expr); - TypeAndValue tv = ta->expr->tav; + TypeAndValue tv = ta->expr->tav(); if (is_type_pointer(tv.type)) { return false; } @@ -2590,7 +2590,7 @@ gb_internal void check_shift(CheckerContext *c, Operand *x, Operand *y, Ast *nod TokenPos pos = ast_token(x->expr).pos; if (x_is_untyped) { if (x->expr != nullptr) { - x->expr->tav.is_lhs = true; + x->expr->tav().is_lhs = true; } x->mode = Addressing_Value; if (type_hint) { @@ -3567,9 +3567,9 @@ gb_internal Operand make_operand_from_node(Ast *node) { GB_ASSERT(node != nullptr); Operand x = {}; x.expr = node; - x.mode = node->tav.mode; - x.type = node->tav.type; - x.value = node->tav.value; + x.mode = node->tav().mode; + x.type = node->tav().type; + x.value = node->tav().value; return x; } @@ -3579,8 +3579,8 @@ gb_internal void update_untyped_expr_type(CheckerContext *c, Ast *e, Type *type, ExprInfo *old = check_get_expr_info(c, e); if (old == nullptr) { if (type != nullptr && type != t_invalid) { - if (e->tav.type == nullptr || e->tav.type == t_invalid) { - add_type_and_value(c->info, e, e->tav.mode, type ? type : e->tav.type, e->tav.value); + if (e->tav().type == nullptr || e->tav().type == t_invalid) { + add_type_and_value(c->info, e, e->tav().mode, type ? type : e->tav().type, e->tav().value); if (e->kind == Ast_TernaryIfExpr) { update_untyped_expr_type(c, e->TernaryIfExpr.x, type, final); update_untyped_expr_type(c, e->TernaryIfExpr.y, type, final); @@ -4146,7 +4146,7 @@ gb_internal ExactValue get_constant_field_single(CheckerContext *c, ExactValue v } if (cl->elems[0]->kind == Ast_FieldValue) { - if (is_type_struct(node->tav.type)) { + if (is_type_struct(node->tav().type)) { bool found = false; for_array(i, cl->elems) { Ast *elem = cl->elems[i]; @@ -4155,10 +4155,10 @@ gb_internal ExactValue get_constant_field_single(CheckerContext *c, ExactValue v } ast_node(fv, FieldValue, elem); String name = fv->field->Ident.token.string; - Selection sub_sel = lookup_field(node->tav.type, name, false); + Selection sub_sel = lookup_field(node->tav().type, name, false); defer (array_free(&sub_sel.index)); if (sub_sel.index[0] == index) { - value = fv->value->tav.value; + value = fv->value->tav().value; found = true; break; } @@ -4167,7 +4167,7 @@ gb_internal ExactValue get_constant_field_single(CheckerContext *c, ExactValue v // Use the zero value if it is not found value = {}; } - } else if (is_type_array(node->tav.type) || is_type_enumerated_array(node->tav.type)) { + } else if (is_type_array(node->tav().type) || is_type_enumerated_array(node->tav().type)) { for_array(i, cl->elems) { Ast *elem = cl->elems[i]; if (elem->kind != Ast_FieldValue) { @@ -4176,8 +4176,8 @@ gb_internal ExactValue get_constant_field_single(CheckerContext *c, ExactValue v ast_node(fv, FieldValue, elem); if (is_ast_range(fv->field)) { ast_node(ie, BinaryExpr, fv->field); - TypeAndValue lo_tav = ie->left->tav; - TypeAndValue hi_tav = ie->right->tav; + TypeAndValue lo_tav = ie->left->tav(); + TypeAndValue hi_tav = ie->right->tav(); GB_ASSERT(lo_tav.mode == Addressing_Constant); GB_ASSERT(hi_tav.mode == Addressing_Constant); @@ -4187,39 +4187,39 @@ gb_internal ExactValue get_constant_field_single(CheckerContext *c, ExactValue v i64 corrected_index = index; - if (is_type_enumerated_array(node->tav.type)) { - Type *bt = base_type(node->tav.type); + if (is_type_enumerated_array(node->tav().type)) { + Type *bt = base_type(node->tav().type); GB_ASSERT(bt->kind == Type_EnumeratedArray); corrected_index = index + exact_value_to_i64(*bt->EnumeratedArray.min_value); } if (op != Token_RangeHalf) { if (lo <= corrected_index && corrected_index <= hi) { - TypeAndValue tav = fv->value->tav; + TypeAndValue tav = fv->value->tav(); if (success_) *success_ = true; if (finish_) *finish_ = false; return tav.value; } } else { if (lo <= corrected_index && corrected_index < hi) { - TypeAndValue tav = fv->value->tav; + TypeAndValue tav = fv->value->tav(); if (success_) *success_ = true; if (finish_) *finish_ = false; return tav.value; } } } else { - TypeAndValue index_tav = fv->field->tav; + TypeAndValue index_tav = fv->field->tav(); GB_ASSERT(index_tav.mode == Addressing_Constant); ExactValue index_value = index_tav.value; - if (is_type_enumerated_array(node->tav.type)) { - Type *bt = base_type(node->tav.type); + if (is_type_enumerated_array(node->tav().type)) { + Type *bt = base_type(node->tav().type); GB_ASSERT(bt->kind == Type_EnumeratedArray); index_value = exact_value_sub(index_value, *bt->EnumeratedArray.min_value); } i64 field_index = exact_value_to_i64(index_value); if (index == field_index) { - TypeAndValue tav = fv->value->tav; + TypeAndValue tav = fv->value->tav(); if (success_) *success_ = true; if (finish_) *finish_ = false; return tav.value;; @@ -4241,7 +4241,7 @@ gb_internal ExactValue get_constant_field_single(CheckerContext *c, ExactValue v return value; } - TypeAndValue tav = cl->elems[index]->tav; + TypeAndValue tav = cl->elems[index]->tav(); if (tav.mode == Addressing_Constant) { if (success_) *success_ = true; if (finish_) *finish_ = false; @@ -8663,7 +8663,7 @@ gb_internal ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast * Ast *e = cl->elems[i]; GB_ASSERT(e->kind != Ast_FieldValue); - TypeAndValue tav = e->tav; + TypeAndValue tav = e->tav(); if (tav.mode != Addressing_Constant) { continue; } @@ -8863,9 +8863,9 @@ gb_internal ExprKind check_selector_call_expr(CheckerContext *c, Operand *o, Ast if (se->modified_call) { // Prevent double evaluation o->expr = node; - o->type = node->tav.type; - o->value = node->tav.value; - o->mode = node->tav.mode; + o->type = node->tav().type; + o->value = node->tav().value; + o->mode = node->tav().mode; return Expr_Expr; } @@ -8927,9 +8927,9 @@ gb_internal ExprKind check_selector_call_expr(CheckerContext *c, Operand *o, Ast } Operand y = {}; - y.mode = first_arg->tav.mode; - y.type = first_arg->tav.type; - y.value = first_arg->tav.value; + y.mode = first_arg->tav().mode; + y.type = first_arg->tav().type; + y.value = first_arg->tav().value; if (check_is_assignable_to(c, &y, first_type)) { // Do nothing, it's valid @@ -9385,7 +9385,7 @@ gb_internal ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast case_ast_node(bl, BasicLit, node); Type *t = t_invalid; - switch (node->tav.value.kind) { + switch (node->tav().value.kind) { case ExactValue_String: t = t_untyped_string; break; case ExactValue_Float: t = t_untyped_float; break; case ExactValue_Complex: t = t_untyped_complex; break; @@ -9403,7 +9403,7 @@ gb_internal ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast o->mode = Addressing_Constant; o->type = t; - o->value = node->tav.value; + o->value = node->tav().value; case_end; case_ast_node(bd, BasicDirective, node); @@ -9859,12 +9859,12 @@ gb_internal bool is_exact_value_zero(ExactValue const &v) { } else { for_array(i, cl->elems) { Ast *elem = cl->elems[i]; - if (elem->tav.mode != Addressing_Constant) { - // if (elem->tav.value.kind != ExactValue_Invalid) { + if (elem->tav().mode != Addressing_Constant) { + // if (elem->tav().value.kind != ExactValue_Invalid) { return false; // } } - if (!is_exact_value_zero(elem->tav.value)) { + if (!is_exact_value_zero(elem->tav().value)) { return false; } } diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index cf111e84c..7ba23ac67 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -8,7 +8,7 @@ gb_internal bool is_diverging_expr(Ast *expr) { return name == "panic"; } Ast *proc = unparen_expr(expr->CallExpr.proc); - TypeAndValue tv = proc->tav; + TypeAndValue tv = proc->tav(); if (tv.mode == Addressing_Builtin) { Entity *e = entity_of_node(proc); BuiltinProcId id = BuiltinProc_Invalid; @@ -250,7 +250,7 @@ gb_internal bool check_is_terminating(Ast *node, String const &label) { case_ast_node(ws, WhenStmt, node); // TODO(bill): Is this logic correct for when statements? - auto const &tv = ws->cond->tav; + auto const &tv = ws->cond->tav(); if (tv.mode != Addressing_Constant) { // NOTE(bill): Check the things regardless as a bug occurred earlier if (ws->else_stmt != nullptr) { @@ -411,7 +411,7 @@ gb_internal Type *check_assignment_variable(CheckerContext *ctx, Operand *lhs, O Ast *ln = unparen_expr(lhs->expr); if (ln->kind == Ast_IndexExpr) { Ast *x = ln->IndexExpr.expr; - TypeAndValue tav = x->tav; + TypeAndValue tav = x->tav(); GB_ASSERT(tav.mode != Addressing_Invalid); if (tav.mode != Addressing_Variable) { if (!is_type_pointer(tav.type)) { @@ -1497,7 +1497,7 @@ gb_internal void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) break; } - switch (be->left->tav.mode) { + switch (be->left->tav().mode) { case Addressing_Context: case Addressing_Variable: case Addressing_MapIndex: @@ -2331,7 +2331,7 @@ gb_internal void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) error(e->token, "A static variable declaration with a default value must be constant"); } else { Ast *value = vd->values[i]; - if (value->tav.mode != Addressing_Constant) { + if (value->tav().mode != Addressing_Constant) { error(e->token, "A static variable declaration with a default value must be constant"); } } diff --git a/src/check_type.cpp b/src/check_type.cpp index 4634e1fbe..3d4bab3e2 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -2569,8 +2569,8 @@ gb_internal bool check_type_internal(CheckerContext *ctx, Ast *e, Type **type, T case_end; case_ast_node(tt, TypeidType, e); - e->tav.mode = Addressing_Type; - e->tav.type = t_typeid; + e->tav().mode = Addressing_Type; + e->tav().type = t_typeid; *type = t_typeid; set_base_type(named_type, *type); return true; diff --git a/src/checker.cpp b/src/checker.cpp index 14a0e5f4c..0f64c6ae9 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -1287,13 +1287,13 @@ gb_internal void destroy_checker(Checker *c) { gb_internal TypeAndValue type_and_value_of_expr(Ast *expr) { TypeAndValue tav = {}; if (expr != nullptr) { - tav = expr->tav; + tav = expr->tav(); } return tav; } gb_internal Type *type_of_expr(Ast *expr) { - TypeAndValue tav = expr->tav; + TypeAndValue tav = expr->tav(); if (tav.mode != Addressing_Invalid) { return tav.type; } @@ -1462,20 +1462,20 @@ gb_internal void add_type_and_value(CheckerInfo *i, Ast *expr, AddressingMode mo Ast *prev_expr = nullptr; while (prev_expr != expr) { prev_expr = expr; - expr->tav.mode = mode; - if (type != nullptr && expr->tav.type != nullptr && - is_type_any(type) && is_type_untyped(expr->tav.type)) { + expr->tav().mode = mode; + if (type != nullptr && expr->tav().type != nullptr && + is_type_any(type) && is_type_untyped(expr->tav().type)) { // ignore } else { - expr->tav.type = type; + expr->tav().type = type; } if (mode == Addressing_Constant || mode == Addressing_Invalid) { - expr->tav.value = value; + expr->tav().value = value; } else if (mode == Addressing_Value && is_type_typeid(type)) { - expr->tav.value = value; + expr->tav().value = value; } else if (mode == Addressing_Value && is_type_proc(type)) { - expr->tav.value = value; + expr->tav().value = value; } expr = unparen_expr(expr); @@ -3635,8 +3635,8 @@ gb_internal void check_collect_value_decl(CheckerContext *c, Ast *decl) { if (value != nullptr) { if (value->kind == Ast_BasicLit && value->BasicLit.token.kind == Token_String) { String v = {}; - if (value->tav.value.kind == ExactValue_String) { - v = value->tav.value.value_string; + if (value->tav().value.kind == ExactValue_String) { + v = value->tav().value.value_string; } if (v == "file") { kind = EntityVisiblity_PrivateToFile; diff --git a/src/llvm_backend_const.cpp b/src/llvm_backend_const.cpp index ee564bbf1..6c5bb153f 100644 --- a/src/llvm_backend_const.cpp +++ b/src/llvm_backend_const.cpp @@ -57,7 +57,7 @@ gb_internal bool lb_is_const_nil(lbValue value) { gb_internal bool lb_is_expr_constant_zero(Ast *expr) { GB_ASSERT(expr != nullptr); - auto v = exact_value_to_integer(expr->tav.value); + auto v = exact_value_to_integer(expr->tav().value); if (v.kind == ExactValue_Integer) { return big_int_cmp_zero(&v.value_integer) == 0; } @@ -720,8 +720,8 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo ast_node(fv, FieldValue, elem); if (is_ast_range(fv->field)) { ast_node(ie, BinaryExpr, fv->field); - TypeAndValue lo_tav = ie->left->tav; - TypeAndValue hi_tav = ie->right->tav; + TypeAndValue lo_tav = ie->left->tav(); + TypeAndValue hi_tav = ie->right->tav(); GB_ASSERT(lo_tav.mode == Addressing_Constant); GB_ASSERT(hi_tav.mode == Addressing_Constant); @@ -732,7 +732,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo hi += 1; } if (lo == i) { - TypeAndValue tav = fv->value->tav; + TypeAndValue tav = fv->value->tav(); LLVMValueRef val = lb_const_value(m, elem_type, tav.value, allow_local).value; for (i64 k = lo; k < hi; k++) { values[value_index++] = val; @@ -743,11 +743,11 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo break; } } else { - TypeAndValue index_tav = fv->field->tav; + TypeAndValue index_tav = fv->field->tav(); GB_ASSERT(index_tav.mode == Addressing_Constant); i64 index = exact_value_to_i64(index_tav.value); if (index == i) { - TypeAndValue tav = fv->value->tav; + TypeAndValue tav = fv->value->tav(); LLVMValueRef val = lb_const_value(m, elem_type, tav.value, allow_local).value; values[value_index++] = val; found = true; @@ -769,7 +769,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, cast(isize)type->Array.count); for (isize i = 0; i < elem_count; i++) { - TypeAndValue tav = cl->elems[i]->tav; + TypeAndValue tav = cl->elems[i]->tav(); GB_ASSERT(tav.mode != Addressing_Invalid); values[i] = lb_const_value(m, elem_type, tav.value, allow_local).value; } @@ -804,8 +804,8 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo ast_node(fv, FieldValue, elem); if (is_ast_range(fv->field)) { ast_node(ie, BinaryExpr, fv->field); - TypeAndValue lo_tav = ie->left->tav; - TypeAndValue hi_tav = ie->right->tav; + TypeAndValue lo_tav = ie->left->tav(); + TypeAndValue hi_tav = ie->right->tav(); GB_ASSERT(lo_tav.mode == Addressing_Constant); GB_ASSERT(hi_tav.mode == Addressing_Constant); @@ -816,7 +816,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo hi += 1; } if (lo == i) { - TypeAndValue tav = fv->value->tav; + TypeAndValue tav = fv->value->tav(); LLVMValueRef val = lb_const_value(m, elem_type, tav.value, allow_local).value; for (i64 k = lo; k < hi; k++) { values[value_index++] = val; @@ -827,11 +827,11 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo break; } } else { - TypeAndValue index_tav = fv->field->tav; + TypeAndValue index_tav = fv->field->tav(); GB_ASSERT(index_tav.mode == Addressing_Constant); i64 index = exact_value_to_i64(index_tav.value); if (index == i) { - TypeAndValue tav = fv->value->tav; + TypeAndValue tav = fv->value->tav(); LLVMValueRef val = lb_const_value(m, elem_type, tav.value, allow_local).value; values[value_index++] = val; found = true; @@ -853,7 +853,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, cast(isize)type->EnumeratedArray.count); for (isize i = 0; i < elem_count; i++) { - TypeAndValue tav = cl->elems[i]->tav; + TypeAndValue tav = cl->elems[i]->tav(); GB_ASSERT(tav.mode != Addressing_Invalid); values[i] = lb_const_value(m, elem_type, tav.value, allow_local).value; } @@ -887,8 +887,8 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo ast_node(fv, FieldValue, elem); if (is_ast_range(fv->field)) { ast_node(ie, BinaryExpr, fv->field); - TypeAndValue lo_tav = ie->left->tav; - TypeAndValue hi_tav = ie->right->tav; + TypeAndValue lo_tav = ie->left->tav(); + TypeAndValue hi_tav = ie->right->tav(); GB_ASSERT(lo_tav.mode == Addressing_Constant); GB_ASSERT(hi_tav.mode == Addressing_Constant); @@ -899,7 +899,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo hi += 1; } if (lo == i) { - TypeAndValue tav = fv->value->tav; + TypeAndValue tav = fv->value->tav(); LLVMValueRef val = lb_const_value(m, elem_type, tav.value, allow_local).value; for (i64 k = lo; k < hi; k++) { values[value_index++] = val; @@ -910,11 +910,11 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo break; } } else { - TypeAndValue index_tav = fv->field->tav; + TypeAndValue index_tav = fv->field->tav(); GB_ASSERT(index_tav.mode == Addressing_Constant); i64 index = exact_value_to_i64(index_tav.value); if (index == i) { - TypeAndValue tav = fv->value->tav; + TypeAndValue tav = fv->value->tav(); LLVMValueRef val = lb_const_value(m, elem_type, tav.value, allow_local).value; values[value_index++] = val; found = true; @@ -932,7 +932,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo return res; } else { for (isize i = 0; i < elem_count; i++) { - TypeAndValue tav = cl->elems[i]->tav; + TypeAndValue tav = cl->elems[i]->tav(); GB_ASSERT(tav.mode != Addressing_Invalid); values[i] = lb_const_value(m, elem_type, tav.value, allow_local).value; } @@ -974,7 +974,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo ast_node(fv, FieldValue, cl->elems[i]); String name = fv->field->Ident.token.string; - TypeAndValue tav = fv->value->tav; + TypeAndValue tav = fv->value->tav(); GB_ASSERT(tav.mode != Addressing_Invalid); Selection sel = lookup_field(type, name, false); @@ -989,7 +989,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo } else { for_array(i, cl->elems) { Entity *f = type->Struct.fields[i]; - TypeAndValue tav = cl->elems[i]->tav; + TypeAndValue tav = cl->elems[i]->tav(); ExactValue val = {}; if (tav.mode != Addressing_Invalid) { val = tav.value; @@ -1073,7 +1073,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo Ast *e = cl->elems[i]; GB_ASSERT(e->kind != Ast_FieldValue); - TypeAndValue tav = e->tav; + TypeAndValue tav = e->tav(); if (tav.mode != Addressing_Constant) { continue; } @@ -1106,8 +1106,8 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo ast_node(fv, FieldValue, elem); if (is_ast_range(fv->field)) { ast_node(ie, BinaryExpr, fv->field); - TypeAndValue lo_tav = ie->left->tav; - TypeAndValue hi_tav = ie->right->tav; + TypeAndValue lo_tav = ie->left->tav(); + TypeAndValue hi_tav = ie->right->tav(); GB_ASSERT(lo_tav.mode == Addressing_Constant); GB_ASSERT(hi_tav.mode == Addressing_Constant); @@ -1122,7 +1122,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo GB_ASSERT(lo <= hi); - TypeAndValue tav = fv->value->tav; + TypeAndValue tav = fv->value->tav(); LLVMValueRef val = lb_const_value(m, elem_type, tav.value, allow_local).value; for (i64 k = lo; k < hi; k++) { i64 offset = matrix_row_major_index_to_offset(type, k); @@ -1130,11 +1130,11 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo values[offset] = val; } } else { - TypeAndValue index_tav = fv->field->tav; + TypeAndValue index_tav = fv->field->tav(); GB_ASSERT(index_tav.mode == Addressing_Constant); i64 index = exact_value_to_i64(index_tav.value); GB_ASSERT(index < max_count); - TypeAndValue tav = fv->value->tav; + TypeAndValue tav = fv->value->tav(); LLVMValueRef val = lb_const_value(m, elem_type, tav.value, allow_local).value; i64 offset = matrix_row_major_index_to_offset(type, index); GB_ASSERT(values[offset] == nullptr); @@ -1156,7 +1156,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, cast(isize)total_count); for_array(i, cl->elems) { - TypeAndValue tav = cl->elems[i]->tav; + TypeAndValue tav = cl->elems[i]->tav(); GB_ASSERT(tav.mode != Addressing_Invalid); i64 offset = matrix_row_major_index_to_offset(type, i); values[offset] = lb_const_value(m, elem_type, tav.value, allow_local).value; diff --git a/src/llvm_backend_expr.cpp b/src/llvm_backend_expr.cpp index d574caf4c..794ed7720 100644 --- a/src/llvm_backend_expr.cpp +++ b/src/llvm_backend_expr.cpp @@ -1330,7 +1330,7 @@ gb_internal lbValue lb_build_binary_expr(lbProcedure *p, Ast *expr) { TypeAndValue tv = type_and_value_of_expr(expr); - if (is_type_matrix(be->left->tav.type) || is_type_matrix(be->right->tav.type)) { + if (is_type_matrix(be->left->tav().type) || is_type_matrix(be->right->tav().type)) { lbValue left = lb_build_expr(p, be->left); lbValue right = lb_build_expr(p, be->right); return lb_emit_arith_matrix(p, be->op.kind, left, right, default_type(tv.type), false); @@ -1372,12 +1372,12 @@ gb_internal lbValue lb_build_binary_expr(lbProcedure *p, Ast *expr) { case Token_CmpEq: case Token_NotEq: - if (is_type_untyped_nil(be->right->tav.type)) { + if (is_type_untyped_nil(be->right->tav().type)) { lbValue left = lb_build_expr(p, be->left); lbValue cmp = lb_emit_comp_against_nil(p, be->op.kind, left); Type *type = default_type(tv.type); return lb_emit_conv(p, cmp, type); - } else if (is_type_untyped_nil(be->left->tav.type)) { + } else if (is_type_untyped_nil(be->left->tav().type)) { lbValue right = lb_build_expr(p, be->right); lbValue cmp = lb_emit_comp_against_nil(p, be->op.kind, right); Type *type = default_type(tv.type); @@ -1392,11 +1392,11 @@ gb_internal lbValue lb_build_binary_expr(lbProcedure *p, Ast *expr) { lbValue left = {}; lbValue right = {}; - if (be->left->tav.mode == Addressing_Type) { - left = lb_typeid(p->module, be->left->tav.type); + if (be->left->tav().mode == Addressing_Type) { + left = lb_typeid(p->module, be->left->tav().type); } - if (be->right->tav.mode == Addressing_Type) { - right = lb_typeid(p->module, be->right->tav.type); + if (be->right->tav().mode == Addressing_Type) { + right = lb_typeid(p->module, be->right->tav().type); } if (left.value == nullptr) left = lb_build_expr(p, be->left); if (right.value == nullptr) right = lb_build_expr(p, be->right); @@ -3093,7 +3093,7 @@ gb_internal lbValue lb_build_expr_internal(lbProcedure *p, Ast *expr) { if (tv.value.kind != ExactValue_Invalid) { // NOTE(bill): The commented out code below is just for debug purposes only // if (is_type_untyped(type)) { - // gb_printf_err("%s %s : %s @ %p\n", token_pos_to_string(expr_pos), expr_to_string(expr), type_to_string(expr->tav.type), expr); + // gb_printf_err("%s %s : %s @ %p\n", token_pos_to_string(expr_pos), expr_to_string(expr), type_to_string(expr->tav().type), expr); // GB_PANIC("%s\n", type_to_string(tv.type)); // } @@ -3514,8 +3514,8 @@ gb_internal void lb_build_addr_compound_lit_populate(lbProcedure *p, Slicefield)) { ast_node(ie, BinaryExpr, fv->field); - TypeAndValue lo_tav = ie->left->tav; - TypeAndValue hi_tav = ie->right->tav; + TypeAndValue lo_tav = ie->left->tav(); + TypeAndValue hi_tav = ie->right->tav(); GB_ASSERT(lo_tav.mode == Addressing_Constant); GB_ASSERT(hi_tav.mode == Addressing_Constant); @@ -3556,7 +3556,7 @@ gb_internal void lb_build_addr_compound_lit_populate(lbProcedure *p, Slicefield->tav; + auto tav = fv->field->tav(); GB_ASSERT(tav.mode == Addressing_Constant); i64 index = exact_value_to_i64(tav.value); @@ -3632,7 +3632,7 @@ gb_internal lbAddr lb_build_addr_index_expr(lbProcedure *p, Ast *expr) { return lb_addr_soa_variable(val, index, ie->index); } - if (ie->expr->tav.mode == Addressing_SoaVariable) { + if (ie->expr->tav().mode == Addressing_SoaVariable) { // SOA Structures for slices/dynamic arrays GB_ASSERT(is_type_pointer(type_of_expr(ie->expr))); @@ -4451,8 +4451,8 @@ gb_internal lbAddr lb_build_addr_internal(lbProcedure *p, Ast *expr) { a = lb_addr_get_ptr(p, addr); } - GB_ASSERT(is_type_array(expr->tav.type)); - return lb_addr_swizzle(a, expr->tav.type, swizzle_count, swizzle_indices); + GB_ASSERT(is_type_array(expr->tav().type)); + return lb_addr_swizzle(a, expr->tav().type, swizzle_count, swizzle_indices); } Selection sel = lookup_field(type, selector, false); @@ -4621,7 +4621,7 @@ gb_internal lbAddr lb_build_addr_internal(lbProcedure *p, Ast *expr) { case_ast_node(ce, CallExpr, expr); BuiltinProcId builtin_id = BuiltinProc_Invalid; - if (ce->proc->tav.mode == Addressing_Builtin) { + if (ce->proc->tav().mode == Addressing_Builtin) { Entity *e = entity_of_node(ce->proc); if (e != nullptr) { builtin_id = cast(BuiltinProcId)e->Builtin.id; @@ -4629,7 +4629,7 @@ gb_internal lbAddr lb_build_addr_internal(lbProcedure *p, Ast *expr) { builtin_id = BuiltinProc_DIRECTIVE; } } - auto const &tv = expr->tav; + auto const &tv = expr->tav(); if (builtin_id == BuiltinProc_swizzle && is_type_array(tv.type)) { // NOTE(bill, 2021-08-09): `swizzle` has some bizarre semantics so it needs to be diff --git a/src/llvm_backend_proc.cpp b/src/llvm_backend_proc.cpp index 384d29ca7..546d49027 100644 --- a/src/llvm_backend_proc.cpp +++ b/src/llvm_backend_proc.cpp @@ -1516,7 +1516,7 @@ gb_internal lbValue lb_build_builtin_simd_proc(lbProcedure *p, Ast *expr, TypeAn BigInt bi_count = {}; big_int_from_i64(&bi_count, count); - TypeAndValue const &tv = ce->args[1]->tav; + TypeAndValue const &tv = ce->args[1]->tav(); ExactValue val = exact_value_to_integer(tv.value); GB_ASSERT(val.kind == ExactValue_Integer); BigInt *bi = &val.value_integer; @@ -2428,16 +2428,16 @@ gb_internal lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValu case BuiltinProc_type_equal_proc: - return lb_equal_proc_for_type(p->module, ce->args[0]->tav.type); + return lb_equal_proc_for_type(p->module, ce->args[0]->tav().type); case BuiltinProc_type_hasher_proc: - return lb_hasher_proc_for_type(p->module, ce->args[0]->tav.type); + return lb_hasher_proc_for_type(p->module, ce->args[0]->tav().type); case BuiltinProc_type_map_info: - return lb_gen_map_info_ptr(p->module, ce->args[0]->tav.type); + return lb_gen_map_info_ptr(p->module, ce->args[0]->tav().type); case BuiltinProc_type_map_cell_info: - return lb_gen_map_cell_info_ptr(p->module, ce->args[0]->tav.type); + return lb_gen_map_cell_info_ptr(p->module, ce->args[0]->tav().type); case BuiltinProc_fixed_point_mul: @@ -2505,7 +2505,7 @@ gb_internal lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValu case BuiltinProc_prefetch_write_data: { lbValue ptr = lb_emit_conv(p, lb_build_expr(p, ce->args[0]), t_rawptr); - unsigned long long locality = cast(unsigned long long)exact_value_to_i64(ce->args[1]->tav.value); + unsigned long long locality = cast(unsigned long long)exact_value_to_i64(ce->args[1]->tav().value); unsigned long long rw = 0; unsigned long long cache = 0; switch (id) { @@ -3060,8 +3060,8 @@ gb_internal lbValue lb_build_call_expr_internal(lbProcedure *p, Ast *expr) { } } - if (proc_expr->tav.mode == Addressing_Constant) { - ExactValue v = proc_expr->tav.value; + if (proc_expr->tav().mode == Addressing_Constant) { + ExactValue v = proc_expr->tav().value; switch (v.kind) { case ExactValue_Integer: { @@ -3070,7 +3070,7 @@ gb_internal lbValue lb_build_call_expr_internal(lbProcedure *p, Ast *expr) { x.value = LLVMConstInt(lb_type(m, t_uintptr), u, false); x.type = t_uintptr; x = lb_emit_conv(p, x, t_rawptr); - value = lb_emit_conv(p, x, proc_expr->tav.type); + value = lb_emit_conv(p, x, proc_expr->tav().type); break; } case ExactValue_Pointer: @@ -3080,7 +3080,7 @@ gb_internal lbValue lb_build_call_expr_internal(lbProcedure *p, Ast *expr) { x.value = LLVMConstInt(lb_type(m, t_uintptr), u, false); x.type = t_uintptr; x = lb_emit_conv(p, x, t_rawptr); - value = lb_emit_conv(p, x, proc_expr->tav.type); + value = lb_emit_conv(p, x, proc_expr->tav().type); break; } } diff --git a/src/llvm_backend_stmt.cpp b/src/llvm_backend_stmt.cpp index 6400a8a9d..e0e991b4d 100644 --- a/src/llvm_backend_stmt.cpp +++ b/src/llvm_backend_stmt.cpp @@ -952,11 +952,11 @@ gb_internal void lb_build_unroll_range_stmt(lbProcedure *p, AstUnrollRangeStmt * TokenKind op = expr->BinaryExpr.op.kind; Ast *start_expr = expr->BinaryExpr.left; Ast *end_expr = expr->BinaryExpr.right; - GB_ASSERT(start_expr->tav.mode == Addressing_Constant); - GB_ASSERT(end_expr->tav.mode == Addressing_Constant); + GB_ASSERT(start_expr->tav().mode == Addressing_Constant); + GB_ASSERT(end_expr->tav().mode == Addressing_Constant); - ExactValue start = start_expr->tav.value; - ExactValue end = end_expr->tav.value; + ExactValue start = start_expr->tav().value; + ExactValue end = end_expr->tav().value; if (op != Token_RangeHalf) { // .. [start, end] (or ..=) ExactValue index = exact_value_i64(0); for (ExactValue val = start; @@ -1006,16 +1006,16 @@ gb_internal void lb_build_unroll_range_stmt(lbProcedure *p, AstUnrollRangeStmt * if (val0_type) val0_addr = lb_build_addr(p, rs->val0); if (val1_type) val1_addr = lb_build_addr(p, rs->val1); - GB_ASSERT(expr->tav.mode == Addressing_Constant); + GB_ASSERT(expr->tav().mode == Addressing_Constant); - Type *t = base_type(expr->tav.type); + Type *t = base_type(expr->tav().type); switch (t->kind) { case Type_Basic: GB_ASSERT(is_type_string(t)); { - ExactValue value = expr->tav.value; + ExactValue value = expr->tav().value; GB_ASSERT(value.kind == ExactValue_String); String str = value.value_string; Rune codepoint = 0; @@ -1109,7 +1109,7 @@ gb_internal bool lb_switch_stmt_can_be_trivial_jump_table(AstSwitchStmt *ss, boo if (is_ast_range(expr)) { return false; } - if (expr->tav.mode == Addressing_Type) { + if (expr->tav().mode == Addressing_Type) { GB_ASSERT(is_typeid); continue; } @@ -1209,12 +1209,12 @@ gb_internal void lb_build_switch_stmt(lbProcedure *p, AstSwitchStmt *ss, Scope * if (switch_instr != nullptr) { lbValue on_val = {}; - if (expr->tav.mode == Addressing_Type) { + if (expr->tav().mode == Addressing_Type) { GB_ASSERT(is_type_typeid(tag.type)); - lbValue e = lb_typeid(p->module, expr->tav.type); + lbValue e = lb_typeid(p->module, expr->tav().type); on_val = lb_emit_conv(p, e, tag.type); } else { - GB_ASSERT(expr->tav.mode == Addressing_Constant); + GB_ASSERT(expr->tav().mode == Addressing_Constant); GB_ASSERT(!is_ast_range(expr)); on_val = lb_build_expr(p, expr); @@ -1245,9 +1245,9 @@ gb_internal void lb_build_switch_stmt(lbProcedure *p, AstSwitchStmt *ss, Scope * lbValue cond_rhs = lb_emit_comp(p, op, tag, rhs); cond = lb_emit_arith(p, Token_And, cond_lhs, cond_rhs, t_bool); } else { - if (expr->tav.mode == Addressing_Type) { + if (expr->tav().mode == Addressing_Type) { GB_ASSERT(is_type_typeid(tag.type)); - lbValue e = lb_typeid(p->module, expr->tav.type); + lbValue e = lb_typeid(p->module, expr->tav().type); e = lb_emit_conv(p, e, tag.type); cond = lb_emit_comp(p, Token_CmpEq, tag, e); } else { @@ -1476,11 +1476,11 @@ gb_internal void lb_build_static_variables(lbProcedure *p, AstValueDecl *vd) { if (vd->values.count > 0) { GB_ASSERT(vd->names.count == vd->values.count); Ast *ast_value = vd->values[i]; - GB_ASSERT(ast_value->tav.mode == Addressing_Constant || - ast_value->tav.mode == Addressing_Invalid); + GB_ASSERT(ast_value->tav().mode == Addressing_Constant || + ast_value->tav().mode == Addressing_Invalid); bool allow_local = false; - value = lb_const_value(p->module, ast_value->tav.type, ast_value->tav.value, allow_local); + value = lb_const_value(p->module, ast_value->tav().type, ast_value->tav().value, allow_local); } Ast *ident = vd->names[i]; @@ -2068,7 +2068,7 @@ gb_internal void lb_build_assign_stmt(lbProcedure *p, AstAssignStmt *as) { op_ += Token_Add - Token_AddEq; // Convert += to + TokenKind op = cast(TokenKind)op_; if (op == Token_CmpAnd || op == Token_CmpOr) { - Type *type = as->lhs[0]->tav.type; + Type *type = as->lhs[0]->tav().type; lbValue new_value = lb_emit_logical_binary_expr(p, op, as->lhs[0], as->rhs[0], type); lbAddr lhs = lb_build_addr(p, as->lhs[0]); diff --git a/src/llvm_backend_utility.cpp b/src/llvm_backend_utility.cpp index dbed32b82..6abcdfc04 100644 --- a/src/llvm_backend_utility.cpp +++ b/src/llvm_backend_utility.cpp @@ -1929,7 +1929,7 @@ gb_internal lbAddr lb_handle_objc_find_or_register_selector(lbProcedure *p, Stri gb_internal lbValue lb_handle_objc_find_selector(lbProcedure *p, Ast *expr) { ast_node(ce, CallExpr, expr); - auto tav = ce->args[0]->tav; + auto tav = ce->args[0]->tav(); GB_ASSERT(tav.value.kind == ExactValue_String); String name = tav.value.value_string; return lb_addr_load(p, lb_handle_objc_find_or_register_selector(p, name)); @@ -1939,7 +1939,7 @@ gb_internal lbValue lb_handle_objc_register_selector(lbProcedure *p, Ast *expr) ast_node(ce, CallExpr, expr); lbModule *m = p->module; - auto tav = ce->args[0]->tav; + auto tav = ce->args[0]->tav(); GB_ASSERT(tav.value.kind == ExactValue_String); String name = tav.value.value_string; lbAddr dst = lb_handle_objc_find_or_register_selector(p, name); @@ -1975,7 +1975,7 @@ gb_internal lbAddr lb_handle_objc_find_or_register_class(lbProcedure *p, String gb_internal lbValue lb_handle_objc_find_class(lbProcedure *p, Ast *expr) { ast_node(ce, CallExpr, expr); - auto tav = ce->args[0]->tav; + auto tav = ce->args[0]->tav(); GB_ASSERT(tav.value.kind == ExactValue_String); String name = tav.value.value_string; return lb_addr_load(p, lb_handle_objc_find_or_register_class(p, name)); @@ -1985,7 +1985,7 @@ gb_internal lbValue lb_handle_objc_register_class(lbProcedure *p, Ast *expr) { ast_node(ce, CallExpr, expr); lbModule *m = p->module; - auto tav = ce->args[0]->tav; + auto tav = ce->args[0]->tav(); GB_ASSERT(tav.value.kind == ExactValue_String); String name = tav.value.value_string; lbAddr dst = lb_handle_objc_find_or_register_class(p, name); @@ -2045,8 +2045,8 @@ gb_internal lbValue lb_handle_objc_send(lbProcedure *p, Ast *expr) { lbValue id = lb_handle_objc_id(p, ce->args[1]); Ast *sel_expr = ce->args[2]; - GB_ASSERT(sel_expr->tav.value.kind == ExactValue_String); - lbValue sel = lb_addr_load(p, lb_handle_objc_find_or_register_selector(p, sel_expr->tav.value.value_string)); + GB_ASSERT(sel_expr->tav().value.kind == ExactValue_String); + lbValue sel = lb_addr_load(p, lb_handle_objc_find_or_register_selector(p, sel_expr->tav().value.value_string)); array_add(&args, id); array_add(&args, sel); diff --git a/src/parser.cpp b/src/parser.cpp index 436498c51..42d8f62cf 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -71,6 +71,7 @@ gb_internal Ast *alloc_ast_node(AstFile *f, AstKind kind) { Ast *node = cast(Ast *)gb_alloc(a, size); node->kind = kind; node->file_id = f ? f->id : 0; + node->tav_ = gb_alloc_item(a, TypeAndValue); global_total_node_memory_allocated.fetch_add(size); @@ -106,6 +107,9 @@ gb_internal Ast *clone_ast(Ast *node) { AstFile *f = node->thread_safe_file(); Ast *n = alloc_ast_node(f, node->kind); gb_memmove(n, node, ast_node_size(node->kind)); + TypeAndValue *new_tav = gb_alloc_item(ast_allocator(f), TypeAndValue); + *new_tav = *node->tav_; + n->tav_ = new_tav; switch (n->kind) { default: GB_PANIC("Unhandled Ast %.*s", LIT(ast_strings[n->kind])); break; @@ -650,8 +654,8 @@ gb_internal String string_value_from_token(AstFile *f, Token const &token) { gb_internal Ast *ast_basic_lit(AstFile *f, Token basic_lit) { Ast *result = alloc_ast_node(f, Ast_BasicLit); result->BasicLit.token = basic_lit; - result->tav.mode = Addressing_Constant; - result->tav.value = exact_value_from_token(f, basic_lit); + result->tav().mode = Addressing_Constant; + result->tav().value = exact_value_from_token(f, basic_lit); return result; } diff --git a/src/parser.hpp b/src/parser.hpp index 7d292ffce..e3d6b42d8 100644 --- a/src/parser.hpp +++ b/src/parser.hpp @@ -754,7 +754,7 @@ struct AstCommonStuff { u8 state_flags; u8 viral_state_flags; i32 file_id; - TypeAndValue tav; // TODO(bill): Make this a pointer to minimize 'Ast' size + TypeAndValue *tav_; // TODO(bill): Make this a pointer to minimize 'Ast' size }; struct Ast { @@ -762,7 +762,7 @@ struct Ast { u8 state_flags; u8 viral_state_flags; i32 file_id; - TypeAndValue tav; // TODO(bill): Make this a pointer to minimize 'Ast' size + TypeAndValue *tav_; // TODO(bill): Make this a pointer to minimize 'Ast' size // IMPORTANT NOTE(bill): This must be at the end since the AST is allocated to be size of the variant union { @@ -771,6 +771,9 @@ struct Ast { #undef AST_KIND }; + gb_inline TypeAndValue &tav() const { + return *this->tav_; + } // NOTE(bill): I know I dislike methods but this is hopefully a temporary thing // for refactoring purposes -- cgit v1.2.3 From 9b278db9934913367a8e186b9c6aa9c03017f3d4 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Thu, 22 Dec 2022 12:01:41 +0000 Subject: Revert "Change `tav` to be a pointer internally" This reverts commit e98f1a28e68e82753728f58b3465793192b74f9d. --- src/check_expr.cpp | 68 ++++++++++++++++++++++---------------------- src/check_stmt.cpp | 10 +++---- src/check_type.cpp | 4 +-- src/checker.cpp | 22 +++++++------- src/llvm_backend_const.cpp | 56 ++++++++++++++++++------------------ src/llvm_backend_expr.cpp | 32 ++++++++++----------- src/llvm_backend_proc.cpp | 20 ++++++------- src/llvm_backend_stmt.cpp | 34 +++++++++++----------- src/llvm_backend_utility.cpp | 12 ++++---- src/parser.cpp | 8 ++---- src/parser.hpp | 7 ++--- 11 files changed, 133 insertions(+), 140 deletions(-) (limited to 'src') diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 654dec051..ed1ddd1f1 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -2119,7 +2119,7 @@ gb_internal bool check_is_not_addressable(CheckerContext *c, Operand *o) { return true; } ast_node(ta, TypeAssertion, expr); - TypeAndValue tv = ta->expr->tav(); + TypeAndValue tv = ta->expr->tav; if (is_type_pointer(tv.type)) { return false; } @@ -2590,7 +2590,7 @@ gb_internal void check_shift(CheckerContext *c, Operand *x, Operand *y, Ast *nod TokenPos pos = ast_token(x->expr).pos; if (x_is_untyped) { if (x->expr != nullptr) { - x->expr->tav().is_lhs = true; + x->expr->tav.is_lhs = true; } x->mode = Addressing_Value; if (type_hint) { @@ -3567,9 +3567,9 @@ gb_internal Operand make_operand_from_node(Ast *node) { GB_ASSERT(node != nullptr); Operand x = {}; x.expr = node; - x.mode = node->tav().mode; - x.type = node->tav().type; - x.value = node->tav().value; + x.mode = node->tav.mode; + x.type = node->tav.type; + x.value = node->tav.value; return x; } @@ -3579,8 +3579,8 @@ gb_internal void update_untyped_expr_type(CheckerContext *c, Ast *e, Type *type, ExprInfo *old = check_get_expr_info(c, e); if (old == nullptr) { if (type != nullptr && type != t_invalid) { - if (e->tav().type == nullptr || e->tav().type == t_invalid) { - add_type_and_value(c->info, e, e->tav().mode, type ? type : e->tav().type, e->tav().value); + if (e->tav.type == nullptr || e->tav.type == t_invalid) { + add_type_and_value(c->info, e, e->tav.mode, type ? type : e->tav.type, e->tav.value); if (e->kind == Ast_TernaryIfExpr) { update_untyped_expr_type(c, e->TernaryIfExpr.x, type, final); update_untyped_expr_type(c, e->TernaryIfExpr.y, type, final); @@ -4146,7 +4146,7 @@ gb_internal ExactValue get_constant_field_single(CheckerContext *c, ExactValue v } if (cl->elems[0]->kind == Ast_FieldValue) { - if (is_type_struct(node->tav().type)) { + if (is_type_struct(node->tav.type)) { bool found = false; for_array(i, cl->elems) { Ast *elem = cl->elems[i]; @@ -4155,10 +4155,10 @@ gb_internal ExactValue get_constant_field_single(CheckerContext *c, ExactValue v } ast_node(fv, FieldValue, elem); String name = fv->field->Ident.token.string; - Selection sub_sel = lookup_field(node->tav().type, name, false); + Selection sub_sel = lookup_field(node->tav.type, name, false); defer (array_free(&sub_sel.index)); if (sub_sel.index[0] == index) { - value = fv->value->tav().value; + value = fv->value->tav.value; found = true; break; } @@ -4167,7 +4167,7 @@ gb_internal ExactValue get_constant_field_single(CheckerContext *c, ExactValue v // Use the zero value if it is not found value = {}; } - } else if (is_type_array(node->tav().type) || is_type_enumerated_array(node->tav().type)) { + } else if (is_type_array(node->tav.type) || is_type_enumerated_array(node->tav.type)) { for_array(i, cl->elems) { Ast *elem = cl->elems[i]; if (elem->kind != Ast_FieldValue) { @@ -4176,8 +4176,8 @@ gb_internal ExactValue get_constant_field_single(CheckerContext *c, ExactValue v ast_node(fv, FieldValue, elem); if (is_ast_range(fv->field)) { ast_node(ie, BinaryExpr, fv->field); - TypeAndValue lo_tav = ie->left->tav(); - TypeAndValue hi_tav = ie->right->tav(); + TypeAndValue lo_tav = ie->left->tav; + TypeAndValue hi_tav = ie->right->tav; GB_ASSERT(lo_tav.mode == Addressing_Constant); GB_ASSERT(hi_tav.mode == Addressing_Constant); @@ -4187,39 +4187,39 @@ gb_internal ExactValue get_constant_field_single(CheckerContext *c, ExactValue v i64 corrected_index = index; - if (is_type_enumerated_array(node->tav().type)) { - Type *bt = base_type(node->tav().type); + if (is_type_enumerated_array(node->tav.type)) { + Type *bt = base_type(node->tav.type); GB_ASSERT(bt->kind == Type_EnumeratedArray); corrected_index = index + exact_value_to_i64(*bt->EnumeratedArray.min_value); } if (op != Token_RangeHalf) { if (lo <= corrected_index && corrected_index <= hi) { - TypeAndValue tav = fv->value->tav(); + TypeAndValue tav = fv->value->tav; if (success_) *success_ = true; if (finish_) *finish_ = false; return tav.value; } } else { if (lo <= corrected_index && corrected_index < hi) { - TypeAndValue tav = fv->value->tav(); + TypeAndValue tav = fv->value->tav; if (success_) *success_ = true; if (finish_) *finish_ = false; return tav.value; } } } else { - TypeAndValue index_tav = fv->field->tav(); + TypeAndValue index_tav = fv->field->tav; GB_ASSERT(index_tav.mode == Addressing_Constant); ExactValue index_value = index_tav.value; - if (is_type_enumerated_array(node->tav().type)) { - Type *bt = base_type(node->tav().type); + if (is_type_enumerated_array(node->tav.type)) { + Type *bt = base_type(node->tav.type); GB_ASSERT(bt->kind == Type_EnumeratedArray); index_value = exact_value_sub(index_value, *bt->EnumeratedArray.min_value); } i64 field_index = exact_value_to_i64(index_value); if (index == field_index) { - TypeAndValue tav = fv->value->tav(); + TypeAndValue tav = fv->value->tav; if (success_) *success_ = true; if (finish_) *finish_ = false; return tav.value;; @@ -4241,7 +4241,7 @@ gb_internal ExactValue get_constant_field_single(CheckerContext *c, ExactValue v return value; } - TypeAndValue tav = cl->elems[index]->tav(); + TypeAndValue tav = cl->elems[index]->tav; if (tav.mode == Addressing_Constant) { if (success_) *success_ = true; if (finish_) *finish_ = false; @@ -8663,7 +8663,7 @@ gb_internal ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast * Ast *e = cl->elems[i]; GB_ASSERT(e->kind != Ast_FieldValue); - TypeAndValue tav = e->tav(); + TypeAndValue tav = e->tav; if (tav.mode != Addressing_Constant) { continue; } @@ -8863,9 +8863,9 @@ gb_internal ExprKind check_selector_call_expr(CheckerContext *c, Operand *o, Ast if (se->modified_call) { // Prevent double evaluation o->expr = node; - o->type = node->tav().type; - o->value = node->tav().value; - o->mode = node->tav().mode; + o->type = node->tav.type; + o->value = node->tav.value; + o->mode = node->tav.mode; return Expr_Expr; } @@ -8927,9 +8927,9 @@ gb_internal ExprKind check_selector_call_expr(CheckerContext *c, Operand *o, Ast } Operand y = {}; - y.mode = first_arg->tav().mode; - y.type = first_arg->tav().type; - y.value = first_arg->tav().value; + y.mode = first_arg->tav.mode; + y.type = first_arg->tav.type; + y.value = first_arg->tav.value; if (check_is_assignable_to(c, &y, first_type)) { // Do nothing, it's valid @@ -9385,7 +9385,7 @@ gb_internal ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast case_ast_node(bl, BasicLit, node); Type *t = t_invalid; - switch (node->tav().value.kind) { + switch (node->tav.value.kind) { case ExactValue_String: t = t_untyped_string; break; case ExactValue_Float: t = t_untyped_float; break; case ExactValue_Complex: t = t_untyped_complex; break; @@ -9403,7 +9403,7 @@ gb_internal ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast o->mode = Addressing_Constant; o->type = t; - o->value = node->tav().value; + o->value = node->tav.value; case_end; case_ast_node(bd, BasicDirective, node); @@ -9859,12 +9859,12 @@ gb_internal bool is_exact_value_zero(ExactValue const &v) { } else { for_array(i, cl->elems) { Ast *elem = cl->elems[i]; - if (elem->tav().mode != Addressing_Constant) { - // if (elem->tav().value.kind != ExactValue_Invalid) { + if (elem->tav.mode != Addressing_Constant) { + // if (elem->tav.value.kind != ExactValue_Invalid) { return false; // } } - if (!is_exact_value_zero(elem->tav().value)) { + if (!is_exact_value_zero(elem->tav.value)) { return false; } } diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index 7ba23ac67..cf111e84c 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -8,7 +8,7 @@ gb_internal bool is_diverging_expr(Ast *expr) { return name == "panic"; } Ast *proc = unparen_expr(expr->CallExpr.proc); - TypeAndValue tv = proc->tav(); + TypeAndValue tv = proc->tav; if (tv.mode == Addressing_Builtin) { Entity *e = entity_of_node(proc); BuiltinProcId id = BuiltinProc_Invalid; @@ -250,7 +250,7 @@ gb_internal bool check_is_terminating(Ast *node, String const &label) { case_ast_node(ws, WhenStmt, node); // TODO(bill): Is this logic correct for when statements? - auto const &tv = ws->cond->tav(); + auto const &tv = ws->cond->tav; if (tv.mode != Addressing_Constant) { // NOTE(bill): Check the things regardless as a bug occurred earlier if (ws->else_stmt != nullptr) { @@ -411,7 +411,7 @@ gb_internal Type *check_assignment_variable(CheckerContext *ctx, Operand *lhs, O Ast *ln = unparen_expr(lhs->expr); if (ln->kind == Ast_IndexExpr) { Ast *x = ln->IndexExpr.expr; - TypeAndValue tav = x->tav(); + TypeAndValue tav = x->tav; GB_ASSERT(tav.mode != Addressing_Invalid); if (tav.mode != Addressing_Variable) { if (!is_type_pointer(tav.type)) { @@ -1497,7 +1497,7 @@ gb_internal void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) break; } - switch (be->left->tav().mode) { + switch (be->left->tav.mode) { case Addressing_Context: case Addressing_Variable: case Addressing_MapIndex: @@ -2331,7 +2331,7 @@ gb_internal void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) error(e->token, "A static variable declaration with a default value must be constant"); } else { Ast *value = vd->values[i]; - if (value->tav().mode != Addressing_Constant) { + if (value->tav.mode != Addressing_Constant) { error(e->token, "A static variable declaration with a default value must be constant"); } } diff --git a/src/check_type.cpp b/src/check_type.cpp index 3d4bab3e2..4634e1fbe 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -2569,8 +2569,8 @@ gb_internal bool check_type_internal(CheckerContext *ctx, Ast *e, Type **type, T case_end; case_ast_node(tt, TypeidType, e); - e->tav().mode = Addressing_Type; - e->tav().type = t_typeid; + e->tav.mode = Addressing_Type; + e->tav.type = t_typeid; *type = t_typeid; set_base_type(named_type, *type); return true; diff --git a/src/checker.cpp b/src/checker.cpp index 0f64c6ae9..14a0e5f4c 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -1287,13 +1287,13 @@ gb_internal void destroy_checker(Checker *c) { gb_internal TypeAndValue type_and_value_of_expr(Ast *expr) { TypeAndValue tav = {}; if (expr != nullptr) { - tav = expr->tav(); + tav = expr->tav; } return tav; } gb_internal Type *type_of_expr(Ast *expr) { - TypeAndValue tav = expr->tav(); + TypeAndValue tav = expr->tav; if (tav.mode != Addressing_Invalid) { return tav.type; } @@ -1462,20 +1462,20 @@ gb_internal void add_type_and_value(CheckerInfo *i, Ast *expr, AddressingMode mo Ast *prev_expr = nullptr; while (prev_expr != expr) { prev_expr = expr; - expr->tav().mode = mode; - if (type != nullptr && expr->tav().type != nullptr && - is_type_any(type) && is_type_untyped(expr->tav().type)) { + expr->tav.mode = mode; + if (type != nullptr && expr->tav.type != nullptr && + is_type_any(type) && is_type_untyped(expr->tav.type)) { // ignore } else { - expr->tav().type = type; + expr->tav.type = type; } if (mode == Addressing_Constant || mode == Addressing_Invalid) { - expr->tav().value = value; + expr->tav.value = value; } else if (mode == Addressing_Value && is_type_typeid(type)) { - expr->tav().value = value; + expr->tav.value = value; } else if (mode == Addressing_Value && is_type_proc(type)) { - expr->tav().value = value; + expr->tav.value = value; } expr = unparen_expr(expr); @@ -3635,8 +3635,8 @@ gb_internal void check_collect_value_decl(CheckerContext *c, Ast *decl) { if (value != nullptr) { if (value->kind == Ast_BasicLit && value->BasicLit.token.kind == Token_String) { String v = {}; - if (value->tav().value.kind == ExactValue_String) { - v = value->tav().value.value_string; + if (value->tav.value.kind == ExactValue_String) { + v = value->tav.value.value_string; } if (v == "file") { kind = EntityVisiblity_PrivateToFile; diff --git a/src/llvm_backend_const.cpp b/src/llvm_backend_const.cpp index 6c5bb153f..ee564bbf1 100644 --- a/src/llvm_backend_const.cpp +++ b/src/llvm_backend_const.cpp @@ -57,7 +57,7 @@ gb_internal bool lb_is_const_nil(lbValue value) { gb_internal bool lb_is_expr_constant_zero(Ast *expr) { GB_ASSERT(expr != nullptr); - auto v = exact_value_to_integer(expr->tav().value); + auto v = exact_value_to_integer(expr->tav.value); if (v.kind == ExactValue_Integer) { return big_int_cmp_zero(&v.value_integer) == 0; } @@ -720,8 +720,8 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo ast_node(fv, FieldValue, elem); if (is_ast_range(fv->field)) { ast_node(ie, BinaryExpr, fv->field); - TypeAndValue lo_tav = ie->left->tav(); - TypeAndValue hi_tav = ie->right->tav(); + TypeAndValue lo_tav = ie->left->tav; + TypeAndValue hi_tav = ie->right->tav; GB_ASSERT(lo_tav.mode == Addressing_Constant); GB_ASSERT(hi_tav.mode == Addressing_Constant); @@ -732,7 +732,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo hi += 1; } if (lo == i) { - TypeAndValue tav = fv->value->tav(); + TypeAndValue tav = fv->value->tav; LLVMValueRef val = lb_const_value(m, elem_type, tav.value, allow_local).value; for (i64 k = lo; k < hi; k++) { values[value_index++] = val; @@ -743,11 +743,11 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo break; } } else { - TypeAndValue index_tav = fv->field->tav(); + TypeAndValue index_tav = fv->field->tav; GB_ASSERT(index_tav.mode == Addressing_Constant); i64 index = exact_value_to_i64(index_tav.value); if (index == i) { - TypeAndValue tav = fv->value->tav(); + TypeAndValue tav = fv->value->tav; LLVMValueRef val = lb_const_value(m, elem_type, tav.value, allow_local).value; values[value_index++] = val; found = true; @@ -769,7 +769,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, cast(isize)type->Array.count); for (isize i = 0; i < elem_count; i++) { - TypeAndValue tav = cl->elems[i]->tav(); + TypeAndValue tav = cl->elems[i]->tav; GB_ASSERT(tav.mode != Addressing_Invalid); values[i] = lb_const_value(m, elem_type, tav.value, allow_local).value; } @@ -804,8 +804,8 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo ast_node(fv, FieldValue, elem); if (is_ast_range(fv->field)) { ast_node(ie, BinaryExpr, fv->field); - TypeAndValue lo_tav = ie->left->tav(); - TypeAndValue hi_tav = ie->right->tav(); + TypeAndValue lo_tav = ie->left->tav; + TypeAndValue hi_tav = ie->right->tav; GB_ASSERT(lo_tav.mode == Addressing_Constant); GB_ASSERT(hi_tav.mode == Addressing_Constant); @@ -816,7 +816,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo hi += 1; } if (lo == i) { - TypeAndValue tav = fv->value->tav(); + TypeAndValue tav = fv->value->tav; LLVMValueRef val = lb_const_value(m, elem_type, tav.value, allow_local).value; for (i64 k = lo; k < hi; k++) { values[value_index++] = val; @@ -827,11 +827,11 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo break; } } else { - TypeAndValue index_tav = fv->field->tav(); + TypeAndValue index_tav = fv->field->tav; GB_ASSERT(index_tav.mode == Addressing_Constant); i64 index = exact_value_to_i64(index_tav.value); if (index == i) { - TypeAndValue tav = fv->value->tav(); + TypeAndValue tav = fv->value->tav; LLVMValueRef val = lb_const_value(m, elem_type, tav.value, allow_local).value; values[value_index++] = val; found = true; @@ -853,7 +853,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, cast(isize)type->EnumeratedArray.count); for (isize i = 0; i < elem_count; i++) { - TypeAndValue tav = cl->elems[i]->tav(); + TypeAndValue tav = cl->elems[i]->tav; GB_ASSERT(tav.mode != Addressing_Invalid); values[i] = lb_const_value(m, elem_type, tav.value, allow_local).value; } @@ -887,8 +887,8 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo ast_node(fv, FieldValue, elem); if (is_ast_range(fv->field)) { ast_node(ie, BinaryExpr, fv->field); - TypeAndValue lo_tav = ie->left->tav(); - TypeAndValue hi_tav = ie->right->tav(); + TypeAndValue lo_tav = ie->left->tav; + TypeAndValue hi_tav = ie->right->tav; GB_ASSERT(lo_tav.mode == Addressing_Constant); GB_ASSERT(hi_tav.mode == Addressing_Constant); @@ -899,7 +899,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo hi += 1; } if (lo == i) { - TypeAndValue tav = fv->value->tav(); + TypeAndValue tav = fv->value->tav; LLVMValueRef val = lb_const_value(m, elem_type, tav.value, allow_local).value; for (i64 k = lo; k < hi; k++) { values[value_index++] = val; @@ -910,11 +910,11 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo break; } } else { - TypeAndValue index_tav = fv->field->tav(); + TypeAndValue index_tav = fv->field->tav; GB_ASSERT(index_tav.mode == Addressing_Constant); i64 index = exact_value_to_i64(index_tav.value); if (index == i) { - TypeAndValue tav = fv->value->tav(); + TypeAndValue tav = fv->value->tav; LLVMValueRef val = lb_const_value(m, elem_type, tav.value, allow_local).value; values[value_index++] = val; found = true; @@ -932,7 +932,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo return res; } else { for (isize i = 0; i < elem_count; i++) { - TypeAndValue tav = cl->elems[i]->tav(); + TypeAndValue tav = cl->elems[i]->tav; GB_ASSERT(tav.mode != Addressing_Invalid); values[i] = lb_const_value(m, elem_type, tav.value, allow_local).value; } @@ -974,7 +974,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo ast_node(fv, FieldValue, cl->elems[i]); String name = fv->field->Ident.token.string; - TypeAndValue tav = fv->value->tav(); + TypeAndValue tav = fv->value->tav; GB_ASSERT(tav.mode != Addressing_Invalid); Selection sel = lookup_field(type, name, false); @@ -989,7 +989,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo } else { for_array(i, cl->elems) { Entity *f = type->Struct.fields[i]; - TypeAndValue tav = cl->elems[i]->tav(); + TypeAndValue tav = cl->elems[i]->tav; ExactValue val = {}; if (tav.mode != Addressing_Invalid) { val = tav.value; @@ -1073,7 +1073,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo Ast *e = cl->elems[i]; GB_ASSERT(e->kind != Ast_FieldValue); - TypeAndValue tav = e->tav(); + TypeAndValue tav = e->tav; if (tav.mode != Addressing_Constant) { continue; } @@ -1106,8 +1106,8 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo ast_node(fv, FieldValue, elem); if (is_ast_range(fv->field)) { ast_node(ie, BinaryExpr, fv->field); - TypeAndValue lo_tav = ie->left->tav(); - TypeAndValue hi_tav = ie->right->tav(); + TypeAndValue lo_tav = ie->left->tav; + TypeAndValue hi_tav = ie->right->tav; GB_ASSERT(lo_tav.mode == Addressing_Constant); GB_ASSERT(hi_tav.mode == Addressing_Constant); @@ -1122,7 +1122,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo GB_ASSERT(lo <= hi); - TypeAndValue tav = fv->value->tav(); + TypeAndValue tav = fv->value->tav; LLVMValueRef val = lb_const_value(m, elem_type, tav.value, allow_local).value; for (i64 k = lo; k < hi; k++) { i64 offset = matrix_row_major_index_to_offset(type, k); @@ -1130,11 +1130,11 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo values[offset] = val; } } else { - TypeAndValue index_tav = fv->field->tav(); + TypeAndValue index_tav = fv->field->tav; GB_ASSERT(index_tav.mode == Addressing_Constant); i64 index = exact_value_to_i64(index_tav.value); GB_ASSERT(index < max_count); - TypeAndValue tav = fv->value->tav(); + TypeAndValue tav = fv->value->tav; LLVMValueRef val = lb_const_value(m, elem_type, tav.value, allow_local).value; i64 offset = matrix_row_major_index_to_offset(type, index); GB_ASSERT(values[offset] == nullptr); @@ -1156,7 +1156,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, cast(isize)total_count); for_array(i, cl->elems) { - TypeAndValue tav = cl->elems[i]->tav(); + TypeAndValue tav = cl->elems[i]->tav; GB_ASSERT(tav.mode != Addressing_Invalid); i64 offset = matrix_row_major_index_to_offset(type, i); values[offset] = lb_const_value(m, elem_type, tav.value, allow_local).value; diff --git a/src/llvm_backend_expr.cpp b/src/llvm_backend_expr.cpp index 794ed7720..d574caf4c 100644 --- a/src/llvm_backend_expr.cpp +++ b/src/llvm_backend_expr.cpp @@ -1330,7 +1330,7 @@ gb_internal lbValue lb_build_binary_expr(lbProcedure *p, Ast *expr) { TypeAndValue tv = type_and_value_of_expr(expr); - if (is_type_matrix(be->left->tav().type) || is_type_matrix(be->right->tav().type)) { + if (is_type_matrix(be->left->tav.type) || is_type_matrix(be->right->tav.type)) { lbValue left = lb_build_expr(p, be->left); lbValue right = lb_build_expr(p, be->right); return lb_emit_arith_matrix(p, be->op.kind, left, right, default_type(tv.type), false); @@ -1372,12 +1372,12 @@ gb_internal lbValue lb_build_binary_expr(lbProcedure *p, Ast *expr) { case Token_CmpEq: case Token_NotEq: - if (is_type_untyped_nil(be->right->tav().type)) { + if (is_type_untyped_nil(be->right->tav.type)) { lbValue left = lb_build_expr(p, be->left); lbValue cmp = lb_emit_comp_against_nil(p, be->op.kind, left); Type *type = default_type(tv.type); return lb_emit_conv(p, cmp, type); - } else if (is_type_untyped_nil(be->left->tav().type)) { + } else if (is_type_untyped_nil(be->left->tav.type)) { lbValue right = lb_build_expr(p, be->right); lbValue cmp = lb_emit_comp_against_nil(p, be->op.kind, right); Type *type = default_type(tv.type); @@ -1392,11 +1392,11 @@ gb_internal lbValue lb_build_binary_expr(lbProcedure *p, Ast *expr) { lbValue left = {}; lbValue right = {}; - if (be->left->tav().mode == Addressing_Type) { - left = lb_typeid(p->module, be->left->tav().type); + if (be->left->tav.mode == Addressing_Type) { + left = lb_typeid(p->module, be->left->tav.type); } - if (be->right->tav().mode == Addressing_Type) { - right = lb_typeid(p->module, be->right->tav().type); + if (be->right->tav.mode == Addressing_Type) { + right = lb_typeid(p->module, be->right->tav.type); } if (left.value == nullptr) left = lb_build_expr(p, be->left); if (right.value == nullptr) right = lb_build_expr(p, be->right); @@ -3093,7 +3093,7 @@ gb_internal lbValue lb_build_expr_internal(lbProcedure *p, Ast *expr) { if (tv.value.kind != ExactValue_Invalid) { // NOTE(bill): The commented out code below is just for debug purposes only // if (is_type_untyped(type)) { - // gb_printf_err("%s %s : %s @ %p\n", token_pos_to_string(expr_pos), expr_to_string(expr), type_to_string(expr->tav().type), expr); + // gb_printf_err("%s %s : %s @ %p\n", token_pos_to_string(expr_pos), expr_to_string(expr), type_to_string(expr->tav.type), expr); // GB_PANIC("%s\n", type_to_string(tv.type)); // } @@ -3514,8 +3514,8 @@ gb_internal void lb_build_addr_compound_lit_populate(lbProcedure *p, Slicefield)) { ast_node(ie, BinaryExpr, fv->field); - TypeAndValue lo_tav = ie->left->tav(); - TypeAndValue hi_tav = ie->right->tav(); + TypeAndValue lo_tav = ie->left->tav; + TypeAndValue hi_tav = ie->right->tav; GB_ASSERT(lo_tav.mode == Addressing_Constant); GB_ASSERT(hi_tav.mode == Addressing_Constant); @@ -3556,7 +3556,7 @@ gb_internal void lb_build_addr_compound_lit_populate(lbProcedure *p, Slicefield->tav(); + auto tav = fv->field->tav; GB_ASSERT(tav.mode == Addressing_Constant); i64 index = exact_value_to_i64(tav.value); @@ -3632,7 +3632,7 @@ gb_internal lbAddr lb_build_addr_index_expr(lbProcedure *p, Ast *expr) { return lb_addr_soa_variable(val, index, ie->index); } - if (ie->expr->tav().mode == Addressing_SoaVariable) { + if (ie->expr->tav.mode == Addressing_SoaVariable) { // SOA Structures for slices/dynamic arrays GB_ASSERT(is_type_pointer(type_of_expr(ie->expr))); @@ -4451,8 +4451,8 @@ gb_internal lbAddr lb_build_addr_internal(lbProcedure *p, Ast *expr) { a = lb_addr_get_ptr(p, addr); } - GB_ASSERT(is_type_array(expr->tav().type)); - return lb_addr_swizzle(a, expr->tav().type, swizzle_count, swizzle_indices); + GB_ASSERT(is_type_array(expr->tav.type)); + return lb_addr_swizzle(a, expr->tav.type, swizzle_count, swizzle_indices); } Selection sel = lookup_field(type, selector, false); @@ -4621,7 +4621,7 @@ gb_internal lbAddr lb_build_addr_internal(lbProcedure *p, Ast *expr) { case_ast_node(ce, CallExpr, expr); BuiltinProcId builtin_id = BuiltinProc_Invalid; - if (ce->proc->tav().mode == Addressing_Builtin) { + if (ce->proc->tav.mode == Addressing_Builtin) { Entity *e = entity_of_node(ce->proc); if (e != nullptr) { builtin_id = cast(BuiltinProcId)e->Builtin.id; @@ -4629,7 +4629,7 @@ gb_internal lbAddr lb_build_addr_internal(lbProcedure *p, Ast *expr) { builtin_id = BuiltinProc_DIRECTIVE; } } - auto const &tv = expr->tav(); + auto const &tv = expr->tav; if (builtin_id == BuiltinProc_swizzle && is_type_array(tv.type)) { // NOTE(bill, 2021-08-09): `swizzle` has some bizarre semantics so it needs to be diff --git a/src/llvm_backend_proc.cpp b/src/llvm_backend_proc.cpp index 546d49027..384d29ca7 100644 --- a/src/llvm_backend_proc.cpp +++ b/src/llvm_backend_proc.cpp @@ -1516,7 +1516,7 @@ gb_internal lbValue lb_build_builtin_simd_proc(lbProcedure *p, Ast *expr, TypeAn BigInt bi_count = {}; big_int_from_i64(&bi_count, count); - TypeAndValue const &tv = ce->args[1]->tav(); + TypeAndValue const &tv = ce->args[1]->tav; ExactValue val = exact_value_to_integer(tv.value); GB_ASSERT(val.kind == ExactValue_Integer); BigInt *bi = &val.value_integer; @@ -2428,16 +2428,16 @@ gb_internal lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValu case BuiltinProc_type_equal_proc: - return lb_equal_proc_for_type(p->module, ce->args[0]->tav().type); + return lb_equal_proc_for_type(p->module, ce->args[0]->tav.type); case BuiltinProc_type_hasher_proc: - return lb_hasher_proc_for_type(p->module, ce->args[0]->tav().type); + return lb_hasher_proc_for_type(p->module, ce->args[0]->tav.type); case BuiltinProc_type_map_info: - return lb_gen_map_info_ptr(p->module, ce->args[0]->tav().type); + return lb_gen_map_info_ptr(p->module, ce->args[0]->tav.type); case BuiltinProc_type_map_cell_info: - return lb_gen_map_cell_info_ptr(p->module, ce->args[0]->tav().type); + return lb_gen_map_cell_info_ptr(p->module, ce->args[0]->tav.type); case BuiltinProc_fixed_point_mul: @@ -2505,7 +2505,7 @@ gb_internal lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValu case BuiltinProc_prefetch_write_data: { lbValue ptr = lb_emit_conv(p, lb_build_expr(p, ce->args[0]), t_rawptr); - unsigned long long locality = cast(unsigned long long)exact_value_to_i64(ce->args[1]->tav().value); + unsigned long long locality = cast(unsigned long long)exact_value_to_i64(ce->args[1]->tav.value); unsigned long long rw = 0; unsigned long long cache = 0; switch (id) { @@ -3060,8 +3060,8 @@ gb_internal lbValue lb_build_call_expr_internal(lbProcedure *p, Ast *expr) { } } - if (proc_expr->tav().mode == Addressing_Constant) { - ExactValue v = proc_expr->tav().value; + if (proc_expr->tav.mode == Addressing_Constant) { + ExactValue v = proc_expr->tav.value; switch (v.kind) { case ExactValue_Integer: { @@ -3070,7 +3070,7 @@ gb_internal lbValue lb_build_call_expr_internal(lbProcedure *p, Ast *expr) { x.value = LLVMConstInt(lb_type(m, t_uintptr), u, false); x.type = t_uintptr; x = lb_emit_conv(p, x, t_rawptr); - value = lb_emit_conv(p, x, proc_expr->tav().type); + value = lb_emit_conv(p, x, proc_expr->tav.type); break; } case ExactValue_Pointer: @@ -3080,7 +3080,7 @@ gb_internal lbValue lb_build_call_expr_internal(lbProcedure *p, Ast *expr) { x.value = LLVMConstInt(lb_type(m, t_uintptr), u, false); x.type = t_uintptr; x = lb_emit_conv(p, x, t_rawptr); - value = lb_emit_conv(p, x, proc_expr->tav().type); + value = lb_emit_conv(p, x, proc_expr->tav.type); break; } } diff --git a/src/llvm_backend_stmt.cpp b/src/llvm_backend_stmt.cpp index e0e991b4d..6400a8a9d 100644 --- a/src/llvm_backend_stmt.cpp +++ b/src/llvm_backend_stmt.cpp @@ -952,11 +952,11 @@ gb_internal void lb_build_unroll_range_stmt(lbProcedure *p, AstUnrollRangeStmt * TokenKind op = expr->BinaryExpr.op.kind; Ast *start_expr = expr->BinaryExpr.left; Ast *end_expr = expr->BinaryExpr.right; - GB_ASSERT(start_expr->tav().mode == Addressing_Constant); - GB_ASSERT(end_expr->tav().mode == Addressing_Constant); + GB_ASSERT(start_expr->tav.mode == Addressing_Constant); + GB_ASSERT(end_expr->tav.mode == Addressing_Constant); - ExactValue start = start_expr->tav().value; - ExactValue end = end_expr->tav().value; + ExactValue start = start_expr->tav.value; + ExactValue end = end_expr->tav.value; if (op != Token_RangeHalf) { // .. [start, end] (or ..=) ExactValue index = exact_value_i64(0); for (ExactValue val = start; @@ -1006,16 +1006,16 @@ gb_internal void lb_build_unroll_range_stmt(lbProcedure *p, AstUnrollRangeStmt * if (val0_type) val0_addr = lb_build_addr(p, rs->val0); if (val1_type) val1_addr = lb_build_addr(p, rs->val1); - GB_ASSERT(expr->tav().mode == Addressing_Constant); + GB_ASSERT(expr->tav.mode == Addressing_Constant); - Type *t = base_type(expr->tav().type); + Type *t = base_type(expr->tav.type); switch (t->kind) { case Type_Basic: GB_ASSERT(is_type_string(t)); { - ExactValue value = expr->tav().value; + ExactValue value = expr->tav.value; GB_ASSERT(value.kind == ExactValue_String); String str = value.value_string; Rune codepoint = 0; @@ -1109,7 +1109,7 @@ gb_internal bool lb_switch_stmt_can_be_trivial_jump_table(AstSwitchStmt *ss, boo if (is_ast_range(expr)) { return false; } - if (expr->tav().mode == Addressing_Type) { + if (expr->tav.mode == Addressing_Type) { GB_ASSERT(is_typeid); continue; } @@ -1209,12 +1209,12 @@ gb_internal void lb_build_switch_stmt(lbProcedure *p, AstSwitchStmt *ss, Scope * if (switch_instr != nullptr) { lbValue on_val = {}; - if (expr->tav().mode == Addressing_Type) { + if (expr->tav.mode == Addressing_Type) { GB_ASSERT(is_type_typeid(tag.type)); - lbValue e = lb_typeid(p->module, expr->tav().type); + lbValue e = lb_typeid(p->module, expr->tav.type); on_val = lb_emit_conv(p, e, tag.type); } else { - GB_ASSERT(expr->tav().mode == Addressing_Constant); + GB_ASSERT(expr->tav.mode == Addressing_Constant); GB_ASSERT(!is_ast_range(expr)); on_val = lb_build_expr(p, expr); @@ -1245,9 +1245,9 @@ gb_internal void lb_build_switch_stmt(lbProcedure *p, AstSwitchStmt *ss, Scope * lbValue cond_rhs = lb_emit_comp(p, op, tag, rhs); cond = lb_emit_arith(p, Token_And, cond_lhs, cond_rhs, t_bool); } else { - if (expr->tav().mode == Addressing_Type) { + if (expr->tav.mode == Addressing_Type) { GB_ASSERT(is_type_typeid(tag.type)); - lbValue e = lb_typeid(p->module, expr->tav().type); + lbValue e = lb_typeid(p->module, expr->tav.type); e = lb_emit_conv(p, e, tag.type); cond = lb_emit_comp(p, Token_CmpEq, tag, e); } else { @@ -1476,11 +1476,11 @@ gb_internal void lb_build_static_variables(lbProcedure *p, AstValueDecl *vd) { if (vd->values.count > 0) { GB_ASSERT(vd->names.count == vd->values.count); Ast *ast_value = vd->values[i]; - GB_ASSERT(ast_value->tav().mode == Addressing_Constant || - ast_value->tav().mode == Addressing_Invalid); + GB_ASSERT(ast_value->tav.mode == Addressing_Constant || + ast_value->tav.mode == Addressing_Invalid); bool allow_local = false; - value = lb_const_value(p->module, ast_value->tav().type, ast_value->tav().value, allow_local); + value = lb_const_value(p->module, ast_value->tav.type, ast_value->tav.value, allow_local); } Ast *ident = vd->names[i]; @@ -2068,7 +2068,7 @@ gb_internal void lb_build_assign_stmt(lbProcedure *p, AstAssignStmt *as) { op_ += Token_Add - Token_AddEq; // Convert += to + TokenKind op = cast(TokenKind)op_; if (op == Token_CmpAnd || op == Token_CmpOr) { - Type *type = as->lhs[0]->tav().type; + Type *type = as->lhs[0]->tav.type; lbValue new_value = lb_emit_logical_binary_expr(p, op, as->lhs[0], as->rhs[0], type); lbAddr lhs = lb_build_addr(p, as->lhs[0]); diff --git a/src/llvm_backend_utility.cpp b/src/llvm_backend_utility.cpp index 6abcdfc04..dbed32b82 100644 --- a/src/llvm_backend_utility.cpp +++ b/src/llvm_backend_utility.cpp @@ -1929,7 +1929,7 @@ gb_internal lbAddr lb_handle_objc_find_or_register_selector(lbProcedure *p, Stri gb_internal lbValue lb_handle_objc_find_selector(lbProcedure *p, Ast *expr) { ast_node(ce, CallExpr, expr); - auto tav = ce->args[0]->tav(); + auto tav = ce->args[0]->tav; GB_ASSERT(tav.value.kind == ExactValue_String); String name = tav.value.value_string; return lb_addr_load(p, lb_handle_objc_find_or_register_selector(p, name)); @@ -1939,7 +1939,7 @@ gb_internal lbValue lb_handle_objc_register_selector(lbProcedure *p, Ast *expr) ast_node(ce, CallExpr, expr); lbModule *m = p->module; - auto tav = ce->args[0]->tav(); + auto tav = ce->args[0]->tav; GB_ASSERT(tav.value.kind == ExactValue_String); String name = tav.value.value_string; lbAddr dst = lb_handle_objc_find_or_register_selector(p, name); @@ -1975,7 +1975,7 @@ gb_internal lbAddr lb_handle_objc_find_or_register_class(lbProcedure *p, String gb_internal lbValue lb_handle_objc_find_class(lbProcedure *p, Ast *expr) { ast_node(ce, CallExpr, expr); - auto tav = ce->args[0]->tav(); + auto tav = ce->args[0]->tav; GB_ASSERT(tav.value.kind == ExactValue_String); String name = tav.value.value_string; return lb_addr_load(p, lb_handle_objc_find_or_register_class(p, name)); @@ -1985,7 +1985,7 @@ gb_internal lbValue lb_handle_objc_register_class(lbProcedure *p, Ast *expr) { ast_node(ce, CallExpr, expr); lbModule *m = p->module; - auto tav = ce->args[0]->tav(); + auto tav = ce->args[0]->tav; GB_ASSERT(tav.value.kind == ExactValue_String); String name = tav.value.value_string; lbAddr dst = lb_handle_objc_find_or_register_class(p, name); @@ -2045,8 +2045,8 @@ gb_internal lbValue lb_handle_objc_send(lbProcedure *p, Ast *expr) { lbValue id = lb_handle_objc_id(p, ce->args[1]); Ast *sel_expr = ce->args[2]; - GB_ASSERT(sel_expr->tav().value.kind == ExactValue_String); - lbValue sel = lb_addr_load(p, lb_handle_objc_find_or_register_selector(p, sel_expr->tav().value.value_string)); + GB_ASSERT(sel_expr->tav.value.kind == ExactValue_String); + lbValue sel = lb_addr_load(p, lb_handle_objc_find_or_register_selector(p, sel_expr->tav.value.value_string)); array_add(&args, id); array_add(&args, sel); diff --git a/src/parser.cpp b/src/parser.cpp index 42d8f62cf..436498c51 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -71,7 +71,6 @@ gb_internal Ast *alloc_ast_node(AstFile *f, AstKind kind) { Ast *node = cast(Ast *)gb_alloc(a, size); node->kind = kind; node->file_id = f ? f->id : 0; - node->tav_ = gb_alloc_item(a, TypeAndValue); global_total_node_memory_allocated.fetch_add(size); @@ -107,9 +106,6 @@ gb_internal Ast *clone_ast(Ast *node) { AstFile *f = node->thread_safe_file(); Ast *n = alloc_ast_node(f, node->kind); gb_memmove(n, node, ast_node_size(node->kind)); - TypeAndValue *new_tav = gb_alloc_item(ast_allocator(f), TypeAndValue); - *new_tav = *node->tav_; - n->tav_ = new_tav; switch (n->kind) { default: GB_PANIC("Unhandled Ast %.*s", LIT(ast_strings[n->kind])); break; @@ -654,8 +650,8 @@ gb_internal String string_value_from_token(AstFile *f, Token const &token) { gb_internal Ast *ast_basic_lit(AstFile *f, Token basic_lit) { Ast *result = alloc_ast_node(f, Ast_BasicLit); result->BasicLit.token = basic_lit; - result->tav().mode = Addressing_Constant; - result->tav().value = exact_value_from_token(f, basic_lit); + result->tav.mode = Addressing_Constant; + result->tav.value = exact_value_from_token(f, basic_lit); return result; } diff --git a/src/parser.hpp b/src/parser.hpp index e3d6b42d8..7d292ffce 100644 --- a/src/parser.hpp +++ b/src/parser.hpp @@ -754,7 +754,7 @@ struct AstCommonStuff { u8 state_flags; u8 viral_state_flags; i32 file_id; - TypeAndValue *tav_; // TODO(bill): Make this a pointer to minimize 'Ast' size + TypeAndValue tav; // TODO(bill): Make this a pointer to minimize 'Ast' size }; struct Ast { @@ -762,7 +762,7 @@ struct Ast { u8 state_flags; u8 viral_state_flags; i32 file_id; - TypeAndValue *tav_; // TODO(bill): Make this a pointer to minimize 'Ast' size + TypeAndValue tav; // TODO(bill): Make this a pointer to minimize 'Ast' size // IMPORTANT NOTE(bill): This must be at the end since the AST is allocated to be size of the variant union { @@ -771,9 +771,6 @@ struct Ast { #undef AST_KIND }; - gb_inline TypeAndValue &tav() const { - return *this->tav_; - } // NOTE(bill): I know I dislike methods but this is hopefully a temporary thing // for refactoring purposes -- cgit v1.2.3 From c53b2198a86fff66225a53f22693d9b3bf6c28e5 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Thu, 22 Dec 2022 12:02:14 +0000 Subject: Add minor comment --- src/parser.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/parser.hpp b/src/parser.hpp index 7d292ffce..df882cc0f 100644 --- a/src/parser.hpp +++ b/src/parser.hpp @@ -754,7 +754,7 @@ struct AstCommonStuff { u8 state_flags; u8 viral_state_flags; i32 file_id; - TypeAndValue tav; // TODO(bill): Make this a pointer to minimize 'Ast' size + TypeAndValue tav; // NOTE(bill): Making this a pointer is slower }; struct Ast { @@ -762,7 +762,7 @@ struct Ast { u8 state_flags; u8 viral_state_flags; i32 file_id; - TypeAndValue tav; // TODO(bill): Make this a pointer to minimize 'Ast' size + TypeAndValue tav; // NOTE(bill): Making this a pointer is slower // IMPORTANT NOTE(bill): This must be at the end since the AST is allocated to be size of the variant union { -- cgit v1.2.3 From 41b32f0da4b40295771e2a9a521b89464d98201b Mon Sep 17 00:00:00 2001 From: gingerBill Date: Thu, 22 Dec 2022 12:45:23 +0000 Subject: Clean up mutex usage in the parser --- src/parser.cpp | 62 ++++++++++++++++++++++++++++------------------------------ src/parser.hpp | 51 ++++++++++++++++++++++++++--------------------- 2 files changed, 59 insertions(+), 54 deletions(-) (limited to 'src') diff --git a/src/parser.cpp b/src/parser.cpp index 436498c51..cb9713985 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -4858,13 +4858,10 @@ gb_internal bool init_parser(Parser *p) { GB_ASSERT(p != nullptr); string_set_init(&p->imported_files, heap_allocator()); array_init(&p->packages, heap_allocator()); - array_init(&p->package_imports, heap_allocator()); - mutex_init(&p->wait_mutex); - mutex_init(&p->import_mutex); - mutex_init(&p->file_add_mutex); + mutex_init(&p->imported_files_mutex); mutex_init(&p->file_decl_mutex); mutex_init(&p->packages_mutex); - mpmc_init(&p->file_error_queue, heap_allocator(), 1024); + mutex_init(&p->file_error_mutex); return true; } @@ -4879,20 +4876,12 @@ gb_internal void destroy_parser(Parser *p) { array_free(&pkg->files); array_free(&pkg->foreign_files); } -#if 0 - for_array(i, p->package_imports) { - // gb_free(heap_allocator(), p->package_imports[i].text); - } -#endif array_free(&p->packages); - array_free(&p->package_imports); string_set_destroy(&p->imported_files); - mutex_destroy(&p->wait_mutex); - mutex_destroy(&p->import_mutex); - mutex_destroy(&p->file_add_mutex); + mutex_destroy(&p->imported_files_mutex); mutex_destroy(&p->file_decl_mutex); mutex_destroy(&p->packages_mutex); - mpmc_destroy(&p->file_error_queue); + mutex_destroy(&p->file_error_mutex); } @@ -4909,7 +4898,18 @@ gb_internal WORKER_TASK_PROC(parser_worker_proc) { ParserWorkerData *wd = cast(ParserWorkerData *)data; ParseFileError err = process_imported_file(wd->parser, wd->imported_file); if (err != ParseFile_None) { - mpmc_enqueue(&wd->parser->file_error_queue, err); + auto *node = gb_alloc_item(permanent_allocator(), ParseFileErrorNode); + node->err = err; + + mutex_lock(&wd->parser->file_error_mutex); + if (wd->parser->file_error_tail != nullptr) { + wd->parser->file_error_tail->next = node; + } + wd->parser->file_error_tail = node; + if (wd->parser->file_error_head == nullptr) { + wd->parser->file_error_head = node; + } + mutex_unlock(&wd->parser->file_error_mutex); } return cast(isize)err; } @@ -4926,7 +4926,6 @@ gb_internal void parser_add_file_to_process(Parser *p, AstPackage *pkg, FileInfo gb_internal WORKER_TASK_PROC(foreign_file_worker_proc) { ForeignFileWorkerData *wd = cast(ForeignFileWorkerData *)data; - Parser *p = wd->parser; ImportedFile *imp = &wd->imported_file; AstPackage *pkg = imp->pkg; @@ -4946,9 +4945,9 @@ gb_internal WORKER_TASK_PROC(foreign_file_worker_proc) { // TODO(bill): Actually do something with it break; } - mutex_lock(&p->file_add_mutex); + mutex_lock(&pkg->foreign_files_mutex); array_add(&pkg->foreign_files, foreign_file); - mutex_unlock(&p->file_add_mutex); + mutex_unlock(&pkg->foreign_files_mutex); return 0; } @@ -4968,7 +4967,7 @@ gb_internal void parser_add_foreign_file_to_process(Parser *p, AstPackage *pkg, gb_internal AstPackage *try_add_import_path(Parser *p, String const &path, String const &rel_path, TokenPos pos, PackageKind kind = Package_Normal) { String const FILE_EXT = str_lit(".odin"); - MUTEX_GUARD_BLOCK(&p->import_mutex) { + MUTEX_GUARD_BLOCK(&p->imported_files_mutex) { if (string_set_update(&p->imported_files, path)) { return nullptr; } @@ -4979,6 +4978,9 @@ gb_internal AstPackage *try_add_import_path(Parser *p, String const &path, Strin pkg->fullpath = path; array_init(&pkg->files, heap_allocator()); pkg->foreign_files.allocator = heap_allocator(); + mutex_init(&pkg->files_mutex); + mutex_init(&pkg->foreign_files_mutex); + // NOTE(bill): Single file initial package if (kind == Package_Init && string_ends_with(path, FILE_EXT)) { @@ -5716,10 +5718,9 @@ gb_internal ParseFileError process_imported_file(Parser *p, ImportedFile importe } if (parse_file(p, file)) { - mutex_lock(&p->file_add_mutex); - defer (mutex_unlock(&p->file_add_mutex)); - - array_add(&pkg->files, file); + MUTEX_GUARD_BLOCK(&pkg->files_mutex) { + array_add(&pkg->files, file); + } if (pkg->name.len == 0) { pkg->name = file->package_name; @@ -5733,8 +5734,8 @@ gb_internal ParseFileError process_imported_file(Parser *p, ImportedFile importe } } - p->total_line_count += file->tokenizer.line_count; - p->total_token_count += file->tokens.count; + p->total_line_count.fetch_add(file->tokenizer.line_count); + p->total_token_count.fetch_add(file->tokens.count); } return ParseFile_None; @@ -5771,9 +5772,6 @@ gb_internal ParseFileError parse_packages(Parser *p, String init_filename) { { // Add these packages serially and then process them parallel - mutex_lock(&p->wait_mutex); - defer (mutex_unlock(&p->wait_mutex)); - TokenPos init_pos = {}; { String s = get_fullpath_core(heap_allocator(), str_lit("runtime")); @@ -5808,9 +5806,9 @@ gb_internal ParseFileError parse_packages(Parser *p, String init_filename) { global_thread_pool_wait(); - for (ParseFileError err = ParseFile_None; mpmc_dequeue(&p->file_error_queue, &err); /**/) { - if (err != ParseFile_None) { - return err; + for (ParseFileErrorNode *node = p->file_error_head; node != nullptr; node = node->next) { + if (node->err != ParseFile_None) { + return node->err; } } diff --git a/src/parser.hpp b/src/parser.hpp index df882cc0f..4357573c9 100644 --- a/src/parser.hpp +++ b/src/parser.hpp @@ -62,15 +62,6 @@ enum PackageKind { Package_Init, }; -struct ImportedPackage { - PackageKind kind; - String path; - String rel_path; - TokenPos pos; // import - isize index; -}; - - struct ImportedFile { AstPackage *pkg; FileInfo fi; @@ -182,6 +173,9 @@ struct AstPackage { bool is_single_file; isize order; + BlockingMutex files_mutex; + BlockingMutex foreign_files_mutex; + MPMCQueue exported_entity_queue; // NOTE(bill): Created/set in checker @@ -191,20 +185,33 @@ struct AstPackage { }; +struct ParseFileErrorNode { + ParseFileErrorNode *next, *prev; + ParseFileError err; +}; + struct Parser { - String init_fullpath; - StringSet imported_files; // fullpath - Array packages; - Array package_imports; - isize file_to_process_count; - isize total_token_count; - isize total_line_count; - BlockingMutex wait_mutex; - BlockingMutex import_mutex; - BlockingMutex file_add_mutex; - BlockingMutex file_decl_mutex; - BlockingMutex packages_mutex; - MPMCQueue file_error_queue; + String init_fullpath; + + StringSet imported_files; // fullpath + BlockingMutex imported_files_mutex; + + Array packages; + BlockingMutex packages_mutex; + + std::atomic file_to_process_count; + std::atomic total_token_count; + std::atomic total_line_count; + + // TODO(bill): What should this mutex be per? + // * Parser + // * Package + // * File + BlockingMutex file_decl_mutex; + + BlockingMutex file_error_mutex; + ParseFileErrorNode * file_error_head; + ParseFileErrorNode * file_error_tail; }; struct ParserWorkerData { -- cgit v1.2.3 From ffa14c3aad5472aab32711c2500c67df9a368601 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Thu, 22 Dec 2022 12:58:23 +0000 Subject: Remove need the MPMC in single threaded case --- src/checker.cpp | 20 +++++++++++--------- src/parser.cpp | 2 +- src/parser.hpp | 5 ++--- 3 files changed, 14 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/checker.cpp b/src/checker.cpp index 14a0e5f4c..29e4b6667 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -3941,7 +3941,7 @@ gb_internal void check_collect_entities(CheckerContext *c, Slice const &n if (c->collect_delayed_decls) { if (decl->state_flags & StateFlag_BeenHandled) return; decl->state_flags |= StateFlag_BeenHandled; - mpmc_enqueue(&curr_file->delayed_decls_queues[AstDelayQueue_Expr], expr); + array_add(&curr_file->delayed_decls_queues[AstDelayQueue_Expr], expr); } continue; } @@ -3969,7 +3969,7 @@ gb_internal void check_collect_entities(CheckerContext *c, Slice const &n continue; } // Will be handled later - mpmc_enqueue(&curr_file->delayed_decls_queues[AstDelayQueue_Import], decl); + array_add(&curr_file->delayed_decls_queues[AstDelayQueue_Import], decl); case_end; case_ast_node(fl, ForeignImportDecl, decl); @@ -4607,7 +4607,7 @@ gb_internal bool collect_file_decl(CheckerContext *ctx, Ast *decl) { if (es->expr->kind == Ast_CallExpr) { ast_node(ce, CallExpr, es->expr); if (ce->proc->kind == Ast_BasicDirective) { - mpmc_enqueue(&curr_file->delayed_decls_queues[AstDelayQueue_Expr], es->expr); + array_add(&curr_file->delayed_decls_queues[AstDelayQueue_Expr], es->expr); } } case_end; @@ -4861,9 +4861,10 @@ gb_internal void check_import_entities(Checker *c) { ctx.collect_delayed_decls = true; // Check import declarations first to simplify things - for (Ast *id = nullptr; mpmc_dequeue(&f->delayed_decls_queues[AstDelayQueue_Import], &id); /**/) { - check_add_import_decl(&ctx, id); + for (Ast *decl : f->delayed_decls_queues[AstDelayQueue_Import]) { + check_add_import_decl(&ctx, decl); } + array_clear(&f->delayed_decls_queues[AstDelayQueue_Import]); if (collect_file_decls(&ctx, f->decls)) { check_export_entities_in_pkg(&ctx, pkg, &untyped); @@ -4889,10 +4890,10 @@ gb_internal void check_import_entities(Checker *c) { AstFile *f = pkg->files[i]; reset_checker_context(&ctx, f, &untyped); - auto *q = &f->delayed_decls_queues[AstDelayQueue_Import]; - for (Ast *decl = nullptr; mpmc_dequeue(q, &decl); /**/) { + for (Ast *decl : f->delayed_decls_queues[AstDelayQueue_Import]) { check_add_import_decl(&ctx, decl); } + array_clear(&f->delayed_decls_queues[AstDelayQueue_Import]); add_untyped_expressions(ctx.info, &untyped); } @@ -4908,11 +4909,12 @@ gb_internal void check_import_entities(Checker *c) { AstFile *f = pkg->files[i]; reset_checker_context(&ctx, f, &untyped); - auto *q = &f->delayed_decls_queues[AstDelayQueue_Expr]; - for (Ast *expr = nullptr; mpmc_dequeue(q, &expr); /**/) { + for (Ast *expr : f->delayed_decls_queues[AstDelayQueue_Expr]) { Operand o = {}; check_expr(&ctx, &o, expr); } + array_clear(&f->delayed_decls_queues[AstDelayQueue_Expr]); + add_untyped_expressions(ctx.info, &untyped); } } diff --git a/src/parser.cpp b/src/parser.cpp index cb9713985..e07f26004 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -5651,7 +5651,7 @@ gb_internal bool parse_file(Parser *p, AstFile *f) { f->time_to_parse = cast(f64)(end-start)/cast(f64)time_stamp__freq(); for (int i = 0; i < AstDelayQueue_COUNT; i++) { - mpmc_init(f->delayed_decls_queues+i, heap_allocator(), f->delayed_decl_count); + array_init(f->delayed_decls_queues+i, heap_allocator(), 0, f->delayed_decl_count); } diff --git a/src/parser.hpp b/src/parser.hpp index 4357573c9..c33739ebe 100644 --- a/src/parser.hpp +++ b/src/parser.hpp @@ -132,9 +132,8 @@ struct AstFile { CommentGroup *docs; // current docs Array comments; // All the comments! - // TODO(bill): make this a basic queue as it does not require - // any multiple thread capabilities - MPMCQueue delayed_decls_queues[AstDelayQueue_COUNT]; + // This is effectively a queue but does not require any multi-threading capabilities + Array delayed_decls_queues[AstDelayQueue_COUNT]; #define PARSER_MAX_FIX_COUNT 6 isize fix_count; -- cgit v1.2.3 From 00823ca88c870d49186dbcaa21c54384c0b9364f Mon Sep 17 00:00:00 2001 From: gingerBill Date: Thu, 22 Dec 2022 13:03:34 +0000 Subject: Remove a few `TODO`s --- src/build_settings.cpp | 3 +-- src/check_builtin.cpp | 7 ++----- src/check_decl.cpp | 8 -------- src/checker.cpp | 9 ++------- src/checker.hpp | 4 ++-- 5 files changed, 7 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/build_settings.cpp b/src/build_settings.cpp index 630cec601..080e9dddc 100644 --- a/src/build_settings.cpp +++ b/src/build_settings.cpp @@ -394,7 +394,7 @@ gb_global TargetMetrics target_darwin_arm64 = { TargetArch_arm64, 8, 8, 16, str_lit("arm64-apple-macosx11.0.0"), - str_lit("e-m:o-i64:64-i128:128-n32:64-S128"), // TODO(bill): Is this correct? + str_lit("e-m:o-i64:64-i128:128-n32:64-S128"), }; gb_global TargetMetrics target_freebsd_i386 = { @@ -585,7 +585,6 @@ struct LibraryCollections { gb_global Array library_collections = {0}; gb_internal void add_library_collection(String name, String path) { - // TODO(bill): Check the path is valid and a directory LibraryCollections lc = {name, string_trim_whitespace(path)}; array_add(&library_collections, lc); } diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp index 1c13b6b5e..99d956f5e 100644 --- a/src/check_builtin.cpp +++ b/src/check_builtin.cpp @@ -89,7 +89,6 @@ gb_internal void check_or_else_split_types(CheckerContext *c, Operand *x, String gb_internal void check_or_else_expr_no_value_error(CheckerContext *c, String const &name, Operand const &x, Type *type_hint) { - // TODO(bill): better error message gbString t = type_to_string(x.type); error(x.expr, "'%.*s' does not return a value, value is of type %s", LIT(name), t); if (is_type_union(type_deref(x.type))) { @@ -2559,7 +2558,7 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As if (is_type_struct(type)) { isize variable_count = type->Struct.fields.count; slice_init(&tuple->Tuple.variables, a, variable_count); - // TODO(bill): Should I copy each of the entities or is this good enough? + // NOTE(bill): don't copy the entities, this should be good enough gb_memmove_array(tuple->Tuple.variables.data, type->Struct.fields.data, variable_count); } else if (is_type_array(type)) { isize variable_count = cast(isize)type->Array.count; @@ -3766,9 +3765,7 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As mp_err err = mp_pack(rop, max_count, &written, MP_LSB_FIRST, size, endian, nails, &x.value.value_integer); GB_ASSERT(err == MP_OKAY); - if (id == BuiltinProc_reverse_bits) { - // TODO(bill): Should this even be allowed at compile time? - } else { + if (id != BuiltinProc_reverse_bits) { u64 v = 0; switch (id) { case BuiltinProc_count_ones: diff --git a/src/check_decl.cpp b/src/check_decl.cpp index d982a69fc..59beae56d 100644 --- a/src/check_decl.cpp +++ b/src/check_decl.cpp @@ -10,7 +10,6 @@ gb_internal Type *check_init_variable(CheckerContext *ctx, Entity *e, Operand *o gbString expr_str = expr_to_string(operand->expr); // TODO(bill): is this a good enough error message? - // TODO(bill): Actually allow built in procedures to be passed around and thus be created on use error(operand->expr, "Cannot assign built-in procedure '%s' in %.*s", expr_str, @@ -122,13 +121,6 @@ gb_internal void check_init_variables(CheckerContext *ctx, Entity **lhs, isize l check_unpack_arguments(ctx, lhs, lhs_count, &operands, inits, true, false); isize rhs_count = operands.count; - for_array(i, operands) { - if (operands[i].mode == Addressing_Invalid) { - // TODO(bill): Should I ignore invalid parameters? - // rhs_count--; - } - } - isize max = gb_min(lhs_count, rhs_count); for (isize i = 0; i < max; i++) { Entity *e = lhs[i]; diff --git a/src/checker.cpp b/src/checker.cpp index 29e4b6667..b78da2827 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -404,7 +404,6 @@ gb_internal void scope_lookup_parent(Scope *scope, String const &name, Scope **s if (found) { Entity *e = *found; if (gone_thru_proc) { - // IMPORTANT TODO(bill): Is this correct?! if (e->kind == Entity_Label) { continue; } @@ -1409,8 +1408,7 @@ gb_internal isize type_info_index(CheckerInfo *info, Type *type, bool error_on_f entry_index = *found_entry_index; } if (entry_index < 0) { - // NOTE(bill): Do manual search - // TODO(bill): This is O(n) and can be very slow + // NOTE(bill): Do manual linear search for (auto const &e : info->type_info_map) { if (are_types_identical_unique_tuples(e.key, type)) { entry_index = e.value; @@ -2350,7 +2348,7 @@ gb_internal void generate_minimum_dependency_set(Checker *c, Entity *start) { for_array(i, c->info.definitions) { Entity *e = c->info.definitions[i]; - if (e->scope == builtin_pkg->scope) { // TODO(bill): is the check enough? + if (e->scope == builtin_pkg->scope) { if (e->type == nullptr) { add_dependency_to_set(c, e); } @@ -3965,7 +3963,6 @@ gb_internal void check_collect_entities(CheckerContext *c, Slice const &n if (curr_file == nullptr) { error(decl, "import declarations are only allowed in the file scope"); // NOTE(bill): _Should_ be caught by the parser - // TODO(bill): Better error handling if it isn't continue; } // Will be handled later @@ -3976,7 +3973,6 @@ gb_internal void check_collect_entities(CheckerContext *c, Slice const &n if ((c->scope->flags&ScopeFlag_File) == 0) { error(decl, "%.*s declarations are only allowed in the file scope", LIT(fl->token.string)); // NOTE(bill): _Should_ be caught by the parser - // TODO(bill): Better error handling if it isn't continue; } check_add_foreign_import_decl(c, decl); @@ -4167,7 +4163,6 @@ gb_internal void add_import_dependency_node(Checker *c, Ast *decl, PtrMapsucc, m); import_graph_node_set_add(&m->pred, n); ptr_set_add(&m->scope->imported, n->scope); diff --git a/src/checker.hpp b/src/checker.hpp index 6799503cd..1d6019b79 100644 --- a/src/checker.hpp +++ b/src/checker.hpp @@ -390,7 +390,7 @@ struct CheckerContext { // Order doesn't matter after this u32 state_flags; - bool in_defer; // TODO(bill): Actually handle correctly + bool in_defer; Type * type_hint; String proc_name; @@ -401,7 +401,7 @@ struct CheckerContext { ForeignContext foreign_context; CheckerTypePath *type_path; - isize type_level; // TODO(bill): Actually handle correctly + isize type_level; UntypedExprInfoMap *untyped; -- cgit v1.2.3