Remove dead code in the compiler

This commit is contained in:
gingerBill
2022-12-18 22:49:10 +00:00
parent 6cdec65ca1
commit c1f5be24e2
28 changed files with 165 additions and 1657 deletions

View File

@@ -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= ^

View File

@@ -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<String> extra_packages;
QueryDataSetSettings query_data_set_settings;
StringSet test_names;
gbAffinity affinity;

View File

@@ -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
//

View File

@@ -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);

View File

@@ -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: {

View File

@@ -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<Entity *> proc_group_entities(CheckerContext *c, Operand o) {
Array<Entity *> 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"

View File

@@ -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);

View File

@@ -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<DistanceAndTarget> did_you_mean_results(DidYouMeanAnswers *d)
}
return slice_array(d->distances, 0, count);
}
#if defined(GB_SYSTEM_WINDOWS)
#pragma warning(pop)
#endif

View File

@@ -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");

View File

@@ -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);

View File

@@ -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_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_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_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_kmag'");
// }
// ExactValue r = {ExactValue_Invalid};
// return r;
// }
gb_internal i64 exact_value_to_i64(ExactValue v) {
v = exact_value_to_integer(v);

View File

@@ -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<lbValue>(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<lbValue>(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);

View File

@@ -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));

View File

@@ -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)};

View File

@@ -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

View File

@@ -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;
// 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 (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;
}
// 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<lbValue> 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);

View File

@@ -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)

View File

@@ -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));

View File

@@ -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<String> 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<String> 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<String> args) {
gb_printf_err("`-export-timings:<format>` 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) {

View File

@@ -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);

View File

@@ -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<Ast *> lhs, rhs; \

View File

@@ -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]);

File diff suppressed because it is too large Load Diff

View File

@@ -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;
// }

View File

@@ -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;

View File

@@ -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 <typename T>
struct StringMapEntry {

View File

@@ -1,6 +1,10 @@
#if defined(GB_SYSTEM_LINUX)
#include <signal.h>
#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

View File

@@ -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<Entity *>(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;