mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-05 03:01:38 -07:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c454ede184 | |||
| d854c5003c | |||
| 66d8776b83 | |||
| ba6ecf35cf | |||
| 10cc9cf661 | |||
| 2db971eedd | |||
| 1775e80b41 | |||
| e4a93619db | |||
| 4d14b3bcb4 | |||
| 9f4f5f9346 | |||
| 0fae31fb54 |
@@ -17,10 +17,13 @@ if %release_mode% EQU 0 ( rem Debug
|
||||
set compiler_warnings= ^
|
||||
-W4 -WX ^
|
||||
-wd4100 -wd4101 -wd4127 -wd4189 ^
|
||||
-wd4201 -wd4204 -wd4244 ^
|
||||
-wd4306 ^
|
||||
-wd4456 -wd4457 -wd4480 ^
|
||||
-wd4505 -wd4512 -wd4550
|
||||
-wd4201 ^
|
||||
-wd4512
|
||||
rem -wd4100 -wd4101 -wd4127 -wd4189 ^
|
||||
rem -wd4201 -wd4204 -wd4244 ^
|
||||
rem -wd4306 ^
|
||||
rem -wd4456 -wd4457 -wd4480 ^
|
||||
rem -wd4505 -wd4512 -wd4550
|
||||
|
||||
set compiler_includes=
|
||||
set libs= ^
|
||||
@@ -38,7 +41,6 @@ if %release_mode% EQU 0 ( rem Debug
|
||||
set compiler_settings=%compiler_includes% %compiler_flags% %compiler_warnings%
|
||||
set linker_settings=%libs% %linker_flags%
|
||||
|
||||
|
||||
del *.pdb > NUL 2> NUL
|
||||
del *.ilk > NUL 2> NUL
|
||||
|
||||
|
||||
+27
-27
@@ -108,13 +108,13 @@ S_ISUID :: 0004000; // Set user id on execution
|
||||
S_ISGID :: 0002000; // Set group id on execution
|
||||
S_ISVTX :: 0001000; // Directory restrcted delete
|
||||
|
||||
S_ISLNK :: proc(m: u32) -> bool #inline {return (m & S_IFMT) == S_IFLNK; }
|
||||
S_ISREG :: proc(m: u32) -> bool #inline {return (m & S_IFMT) == S_IFREG; }
|
||||
S_ISDIR :: proc(m: u32) -> bool #inline {return (m & S_IFMT) == S_IFDIR; }
|
||||
S_ISCHR :: proc(m: u32) -> bool #inline {return (m & S_IFMT) == S_IFCHR; }
|
||||
S_ISBLK :: proc(m: u32) -> bool #inline {return (m & S_IFMT) == S_IFBLK; }
|
||||
S_ISFIFO :: proc(m: u32) -> bool #inline {return (m & S_IFMT) == S_IFIFO; }
|
||||
S_ISSOCK :: proc(m: u32) -> bool #inline {return (m & S_IFMT) == S_IFSOCK;}
|
||||
S_ISLNK :: proc(m: u32) -> bool #inline do return (m & S_IFMT) == S_IFLNK;
|
||||
S_ISREG :: proc(m: u32) -> bool #inline do return (m & S_IFMT) == S_IFREG;
|
||||
S_ISDIR :: proc(m: u32) -> bool #inline do return (m & S_IFMT) == S_IFDIR;
|
||||
S_ISCHR :: proc(m: u32) -> bool #inline do return (m & S_IFMT) == S_IFCHR;
|
||||
S_ISBLK :: proc(m: u32) -> bool #inline do return (m & S_IFMT) == S_IFBLK;
|
||||
S_ISFIFO :: proc(m: u32) -> bool #inline do return (m & S_IFMT) == S_IFIFO;
|
||||
S_ISSOCK :: proc(m: u32) -> bool #inline do return (m & S_IFMT) == S_IFSOCK;
|
||||
|
||||
R_OK :: 4; // Test for read permission
|
||||
W_OK :: 2; // Test for write permission
|
||||
@@ -122,28 +122,28 @@ X_OK :: 1; // Test for execute permission
|
||||
F_OK :: 0; // Test for file existance
|
||||
|
||||
foreign libc {
|
||||
unix_open :: proc(path: ^u8, mode: int) -> Handle #link_name "open" ---;
|
||||
unix_close :: proc(handle: Handle) #link_name "close" ---;
|
||||
unix_read :: proc(handle: Handle, buffer: rawptr, count: int) -> int #link_name "read" ---;
|
||||
unix_write :: proc(handle: Handle, buffer: rawptr, count: int) -> int #link_name "write" ---;
|
||||
unix_lseek :: proc(fs: Handle, offset: int, whence: int) -> int #link_name "lseek" ---;
|
||||
unix_gettid :: proc() -> u64 #link_name "gettid" ---;
|
||||
unix_stat :: proc(path: ^u8, stat: ^Stat) -> int #link_name "stat" ---;
|
||||
unix_access :: proc(path: ^u8, mask: int) -> int #link_name "access" ---;
|
||||
unix_open :: proc(path: ^u8, mode: int) -> Handle #link_name "open" ---;
|
||||
unix_close :: proc(handle: Handle) #link_name "close" ---;
|
||||
unix_read :: proc(handle: Handle, buffer: rawptr, count: int) -> int #link_name "read" ---;
|
||||
unix_write :: proc(handle: Handle, buffer: rawptr, count: int) -> int #link_name "write" ---;
|
||||
unix_lseek :: proc(fs: Handle, offset: int, whence: int) -> int #link_name "lseek" ---;
|
||||
unix_gettid :: proc() -> u64 #link_name "gettid" ---;
|
||||
unix_stat :: proc(path: ^u8, stat: ^Stat) -> int #link_name "stat" ---;
|
||||
unix_access :: proc(path: ^u8, mask: int) -> int #link_name "access" ---;
|
||||
|
||||
unix_malloc :: proc(size: int) -> rawptr #link_name "malloc" ---;
|
||||
unix_free :: proc(ptr: rawptr) #link_name "free" ---;
|
||||
unix_realloc :: proc(ptr: rawptr, size: int) -> rawptr #link_name "realloc" ---;
|
||||
unix_getenv :: proc(^u8) -> ^u8 #link_name "getenv" ---;
|
||||
unix_malloc :: proc(size: int) -> rawptr #link_name "malloc" ---;
|
||||
unix_free :: proc(ptr: rawptr) #link_name "free" ---;
|
||||
unix_realloc :: proc(ptr: rawptr, size: int) -> rawptr #link_name "realloc" ---;
|
||||
unix_getenv :: proc(^u8) -> ^u8 #link_name "getenv" ---;
|
||||
|
||||
unix_exit :: proc(status: int) #link_name "exit" ---;
|
||||
unix_exit :: proc(status: int) #link_name "exit" ---;
|
||||
}
|
||||
|
||||
foreign dl {
|
||||
unix_dlopen :: proc(filename: ^u8, flags: int) -> rawptr #link_name "dlopen" ---;
|
||||
unix_dlsym :: proc(handle: rawptr, symbol: ^u8) -> (proc() #cc_c) #link_name "dlsym" ---;
|
||||
unix_dlclose :: proc(handle: rawptr) -> int #link_name "dlclose" ---;
|
||||
unix_dlerror :: proc() -> ^u8 #link_name "dlerror" ---;
|
||||
unix_dlopen :: proc(filename: ^u8, flags: int) -> rawptr #link_name "dlopen" ---;
|
||||
unix_dlsym :: proc(handle: rawptr, symbol: ^u8) -> (proc() #cc_c) #link_name "dlsym" ---;
|
||||
unix_dlclose :: proc(handle: rawptr) -> int #link_name "dlclose" ---;
|
||||
unix_dlerror :: proc() -> ^u8 #link_name "dlerror" ---;
|
||||
}
|
||||
|
||||
// TODO(zangent): Change this to just `open` when Bill fixes overloading.
|
||||
@@ -187,10 +187,10 @@ read :: proc(fd: Handle, data: []u8) -> (int, Errno) {
|
||||
return bytes_read, 0;
|
||||
}
|
||||
|
||||
seek :: proc(fd: Handle, offset: int, whence: int) -> (int, Errno) {
|
||||
seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
|
||||
assert(fd != -1);
|
||||
|
||||
final_offset := unix_lseek(fd, offset, whence);
|
||||
final_offset := i64(unix_lseek(fd, offset, whence));
|
||||
if(final_offset == -1) {
|
||||
return 0, 1;
|
||||
}
|
||||
@@ -201,7 +201,7 @@ file_size :: proc(fd: Handle) -> (i64, Errno) {
|
||||
prev, _ := seek(fd, 0, SEEK_CUR);
|
||||
size, err := seek(fd, 0, SEEK_END);
|
||||
seek(fd, prev, SEEK_SET);
|
||||
return size, err;
|
||||
return i64(size), err;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+28
-19
@@ -19,6 +19,7 @@ struct BuildContext {
|
||||
bool generate_docs;
|
||||
i32 optimization_level;
|
||||
bool show_timings;
|
||||
bool keep_temp_files;
|
||||
|
||||
gbAffinity affinity;
|
||||
isize thread_count;
|
||||
@@ -57,7 +58,7 @@ String odin_root_dir(void) {
|
||||
|
||||
len = 0;
|
||||
for (;;) {
|
||||
len = GetModuleFileNameW(nullptr, &path_buf[0], path_buf.count);
|
||||
len = GetModuleFileNameW(nullptr, &path_buf[0], cast(int)path_buf.count);
|
||||
if (len == 0) {
|
||||
return make_string(nullptr, 0);
|
||||
}
|
||||
@@ -68,12 +69,15 @@ String odin_root_dir(void) {
|
||||
}
|
||||
len += 1; // NOTE(bill): It needs an extra 1 for some reason
|
||||
|
||||
gb_mutex_lock(&string_buffer_mutex);
|
||||
defer (gb_mutex_unlock(&string_buffer_mutex));
|
||||
|
||||
tmp = gb_temp_arena_memory_begin(&string_buffer_arena);
|
||||
defer (gb_temp_arena_memory_end(tmp));
|
||||
|
||||
text = gb_alloc_array(string_buffer_allocator, wchar_t, len+1);
|
||||
|
||||
GetModuleFileNameW(nullptr, text, len);
|
||||
GetModuleFileNameW(nullptr, text, cast(int)len);
|
||||
path = string16_to_string(heap_allocator(), make_string16(text, len));
|
||||
|
||||
for (i = path.len-1; i >= 0; i--) {
|
||||
@@ -87,7 +91,6 @@ String odin_root_dir(void) {
|
||||
global_module_path = path;
|
||||
global_module_path_set = true;
|
||||
|
||||
gb_temp_arena_memory_end(tmp);
|
||||
|
||||
array_free(&path_buf);
|
||||
|
||||
@@ -123,8 +126,12 @@ String odin_root_dir(void) {
|
||||
}
|
||||
}
|
||||
|
||||
gb_mutex_lock(&string_buffer_mutex);
|
||||
defer (gb_mutex_unlock(&string_buffer_mutex));
|
||||
|
||||
tmp = gb_temp_arena_memory_begin(&string_buffer_arena);
|
||||
defer (gb_temp_arena_memory_end(tmp));
|
||||
|
||||
text = gb_alloc_array(string_buffer_allocator, u8, len + 1);
|
||||
gb_memmove(text, &path_buf[0], len);
|
||||
|
||||
@@ -140,7 +147,6 @@ String odin_root_dir(void) {
|
||||
global_module_path = path;
|
||||
global_module_path_set = true;
|
||||
|
||||
gb_temp_arena_memory_end(tmp);
|
||||
|
||||
// array_free(&path_buf);
|
||||
|
||||
@@ -181,6 +187,8 @@ String odin_root_dir(void) {
|
||||
array_resize(&path_buf, 2*path_buf.count + 300);
|
||||
}
|
||||
|
||||
gb_mutex_lock(&string_buffer_mutex);
|
||||
defer (gb_mutex_unlock(&string_buffer_mutex));
|
||||
|
||||
tmp = gb_temp_arena_memory_begin(&string_buffer_arena);
|
||||
defer (gb_temp_arena_memory_end(tmp));
|
||||
@@ -210,27 +218,28 @@ String odin_root_dir(void) {
|
||||
String path_to_fullpath(gbAllocator a, String s) {
|
||||
String result = {};
|
||||
gb_mutex_lock(&string_buffer_mutex);
|
||||
{
|
||||
gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&string_buffer_arena);
|
||||
String16 string16 = string_to_string16(string_buffer_allocator, s);
|
||||
defer (gb_mutex_unlock(&string_buffer_mutex));
|
||||
|
||||
DWORD len = GetFullPathNameW(&string16[0], 0, nullptr, nullptr);
|
||||
if (len != 0) {
|
||||
wchar_t *text = gb_alloc_array(string_buffer_allocator, wchar_t, len+1);
|
||||
GetFullPathNameW(&string16[0], len, text, nullptr);
|
||||
text[len] = 0;
|
||||
result = string16_to_string(a, make_string16(text, len));
|
||||
}
|
||||
gb_temp_arena_memory_end(tmp);
|
||||
gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&string_buffer_arena);
|
||||
String16 string16 = string_to_string16(string_buffer_allocator, s);
|
||||
|
||||
DWORD len = GetFullPathNameW(&string16[0], 0, nullptr, nullptr);
|
||||
if (len != 0) {
|
||||
wchar_t *text = gb_alloc_array(string_buffer_allocator, wchar_t, len+1);
|
||||
GetFullPathNameW(&string16[0], len, text, nullptr);
|
||||
text[len] = 0;
|
||||
result = string16_to_string(a, make_string16(text, len));
|
||||
}
|
||||
gb_mutex_unlock(&string_buffer_mutex);
|
||||
gb_temp_arena_memory_end(tmp);
|
||||
return result;
|
||||
}
|
||||
#elif defined(GB_SYSTEM_OSX) || defined(GB_SYSTEM_UNIX)
|
||||
String path_to_fullpath(gbAllocator a, String s) {
|
||||
char *p = realpath(cast(char *)&s[0], 0);
|
||||
char *p;
|
||||
gb_mutex_lock(&string_buffer_mutex);
|
||||
p = realpath(cast(char *)s.text, 0);
|
||||
gb_mutex_unlock(&string_buffer_mutex);
|
||||
if(p == nullptr) return make_string_c("");
|
||||
|
||||
return make_string_c(p);
|
||||
}
|
||||
#else
|
||||
@@ -274,7 +283,7 @@ String get_fullpath_core(gbAllocator a, String path) {
|
||||
}
|
||||
|
||||
|
||||
String const ODIN_VERSION = str_lit("0.6.0");
|
||||
String const ODIN_VERSION = str_lit("0.6.1a");
|
||||
|
||||
void init_build_context(void) {
|
||||
BuildContext *bc = &build_context;
|
||||
|
||||
+15
-15
@@ -494,7 +494,7 @@ i64 check_distance_between_types(Checker *c, Operand *operand, Type *type) {
|
||||
Type *bfv = base_type(operand->type);
|
||||
i32 bits = bfv->BitFieldValue.bits;
|
||||
i32 size = next_pow2((bits+7)/8);
|
||||
i32 dst_size = type_size_of(c->allocator, type);
|
||||
i32 dst_size = cast(i32)type_size_of(c->allocator, type);
|
||||
i32 diff = gb_abs(dst_size - size);
|
||||
// TODO(bill): figure out a decent rule here
|
||||
return 1;
|
||||
@@ -1279,7 +1279,7 @@ void check_struct_type(Checker *c, Type *struct_type, AstNode *node, Array<Opera
|
||||
gb_sort_array(reordered_fields.data, fields.count, cmp_reorder_struct_fields);
|
||||
|
||||
for_array(i, fields) {
|
||||
reordered_fields[i]->Variable.field_index = i;
|
||||
reordered_fields[i]->Variable.field_index = cast(i32)i;
|
||||
}
|
||||
|
||||
struct_type->Struct.fields = reordered_fields;
|
||||
@@ -1564,7 +1564,7 @@ void check_enum_type(Checker *c, Type *enum_type, Type *named_type, AstNode *nod
|
||||
|
||||
|
||||
enum_type->Enum.fields = fields.data;
|
||||
enum_type->Enum.field_count = fields.count;
|
||||
enum_type->Enum.field_count = cast(i32)fields.count;
|
||||
|
||||
enum_type->Enum.count = make_entity_constant(c->allocator, c->context.scope,
|
||||
make_token_ident(str_lit("count")), t_int, exact_value_i64(fields.count));
|
||||
@@ -1622,7 +1622,7 @@ void check_bit_field_type(Checker *c, Type *bit_field_type, Type *named_type, As
|
||||
continue;
|
||||
}
|
||||
|
||||
Type *value_type = make_type_bit_field_value(c->allocator, bits);
|
||||
Type *value_type = make_type_bit_field_value(c->allocator, cast(i32)bits);
|
||||
Entity *e = make_entity_variable(c->allocator, bit_field_type->BitField.scope, ident->Ident.token, value_type, false);
|
||||
e->identifier = ident;
|
||||
e->flags |= EntityFlag_BitFieldValue;
|
||||
@@ -1638,16 +1638,16 @@ void check_bit_field_type(Checker *c, Type *bit_field_type, Type *named_type, As
|
||||
|
||||
fields [field_count] = e;
|
||||
offsets[field_count] = curr_offset;
|
||||
sizes [field_count] = bits;
|
||||
sizes [field_count] = cast(i32)bits;
|
||||
field_count++;
|
||||
|
||||
curr_offset += bits;
|
||||
curr_offset += cast(i32)bits;
|
||||
}
|
||||
}
|
||||
GB_ASSERT(field_count <= bft->fields.count);
|
||||
|
||||
bit_field_type->BitField.fields = fields;
|
||||
bit_field_type->BitField.field_count = field_count;
|
||||
bit_field_type->BitField.field_count = cast(i32)field_count;
|
||||
bit_field_type->BitField.sizes = sizes;
|
||||
bit_field_type->BitField.offsets = offsets;
|
||||
|
||||
@@ -2180,7 +2180,7 @@ Type *check_get_params(Checker *c, Scope *scope, AstNode *_params, bool *is_vari
|
||||
if (scope != nullptr) {
|
||||
for_array(i, scope->elements.entries) {
|
||||
Entity *e = scope->elements.entries[i].value;
|
||||
if (e->kind == Type_Named) {
|
||||
if (e->kind == Entity_TypeName) {
|
||||
Type *t = e->type;
|
||||
if (t->kind == Type_Generic &&
|
||||
t->Generic.specialized != nullptr) {
|
||||
@@ -2523,9 +2523,9 @@ bool check_procedure_type(Checker *c, Type *type, AstNode *proc_type_node, Array
|
||||
type->Proc.node = proc_type_node;
|
||||
type->Proc.scope = c->context.scope;
|
||||
type->Proc.params = params;
|
||||
type->Proc.param_count = param_count;
|
||||
type->Proc.param_count = cast(i32)param_count;
|
||||
type->Proc.results = results;
|
||||
type->Proc.result_count = result_count;
|
||||
type->Proc.result_count = cast(i32)result_count;
|
||||
type->Proc.variadic = variadic;
|
||||
type->Proc.calling_convention = pt->calling_convention;
|
||||
type->Proc.is_polymorphic = pt->generic;
|
||||
@@ -3341,12 +3341,12 @@ bool check_representable_as_constant(Checker *c, ExactValue in_value, Type *type
|
||||
i64 s = 8*type_size_of(c->allocator, type);
|
||||
u128 umax = U128_NEG_ONE;
|
||||
if (s < 128) {
|
||||
umax = u128_sub(u128_shl(U128_ONE, s), U128_ONE);
|
||||
umax = u128_sub(u128_shl(U128_ONE, cast(u32)s), U128_ONE);
|
||||
} else {
|
||||
// IMPORTANT TODO(bill): I NEED A PROPER BIG NUMBER LIBRARY THAT CAN SUPPORT 128 bit floats
|
||||
s = 128;
|
||||
}
|
||||
i128 imax = i128_shl(I128_ONE, s-1ll);
|
||||
i128 imax = i128_shl(I128_ONE, cast(u32)s-1);
|
||||
|
||||
switch (type->Basic.kind) {
|
||||
case Basic_rune:
|
||||
@@ -4399,8 +4399,8 @@ void convert_to_typed(Checker *c, Operand *operand, Type *target_type, i32 level
|
||||
defer (gb_temp_arena_memory_end(tmp));
|
||||
isize count = t->Union.variants.count;
|
||||
ValidIndexAndScore *valids = gb_alloc_array(c->tmp_allocator, ValidIndexAndScore, count);
|
||||
i32 valid_count = 0;
|
||||
i32 first_success_index = -1;
|
||||
isize valid_count = 0;
|
||||
isize first_success_index = -1;
|
||||
for_array(i, t->Union.variants) {
|
||||
Type *vt = t->Union.variants[i];
|
||||
i64 score = 0;
|
||||
@@ -5693,7 +5693,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
|
||||
gbAllocator a = c->allocator;
|
||||
|
||||
Type *tuple = make_type_tuple(a);
|
||||
i32 variable_count = type->Struct.fields.count;
|
||||
isize variable_count = type->Struct.fields.count;
|
||||
array_init_count(&tuple->Tuple.variables, a, variable_count);
|
||||
// TODO(bill): Should I copy each of the entities or is this good enough?
|
||||
gb_memcopy_array(tuple->Tuple.variables.data, type->Struct.fields_in_src_order.data, variable_count);
|
||||
|
||||
+3
-3
@@ -4,7 +4,7 @@ void check_stmt_list(Checker *c, Array<AstNode *> stmts, u32 flags) {
|
||||
}
|
||||
|
||||
if (flags&Stmt_CheckScopeDecls) {
|
||||
check_scope_decls(c, stmts, 1.2*stmts.count);
|
||||
check_scope_decls(c, stmts, cast(isize)(1.2*stmts.count));
|
||||
}
|
||||
|
||||
bool ft_ok = (flags & Stmt_FallthroughAllowed) != 0;
|
||||
@@ -265,9 +265,9 @@ Type *check_assignment_variable(Checker *c, Operand *rhs, AstNode *lhs_node) {
|
||||
u128 u = *cast(u128 *)&i;
|
||||
u128 umax = U128_NEG_ONE;
|
||||
if (lhs_bits < 128) {
|
||||
umax = u128_sub(u128_shl(U128_ONE, lhs_bits), U128_ONE);
|
||||
umax = u128_sub(u128_shl(U128_ONE, cast(u32)lhs_bits), U128_ONE);
|
||||
}
|
||||
i128 imax = i128_shl(I128_ONE, lhs_bits-1ll);
|
||||
i128 imax = i128_shl(I128_ONE, cast(u32)lhs_bits-1);
|
||||
|
||||
bool ok = false;
|
||||
ok = !(u128_lt(u, U128_ZERO) || u128_gt(u, umax));
|
||||
|
||||
+1
-1
@@ -267,7 +267,7 @@ struct DelayedDecl {
|
||||
};
|
||||
|
||||
struct CheckerFileNode {
|
||||
i32 id;
|
||||
isize id;
|
||||
Array<i32> wheres;
|
||||
Array<i32> whats;
|
||||
i32 score; // Higher the score, the better
|
||||
|
||||
+95
-3
@@ -12,9 +12,78 @@
|
||||
|
||||
#include <math.h>
|
||||
|
||||
GB_ALLOCATOR_PROC(heap_allocator_proc);
|
||||
|
||||
gbAllocator heap_allocator(void) {
|
||||
return gb_heap_allocator();
|
||||
gbAllocator a;
|
||||
a.proc = heap_allocator_proc;
|
||||
a.data = NULL;
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
GB_ALLOCATOR_PROC(heap_allocator_proc) {
|
||||
void *ptr = NULL;
|
||||
gb_unused(allocator_data);
|
||||
gb_unused(old_size);
|
||||
// TODO(bill): Throughly test!
|
||||
switch (type) {
|
||||
#if defined(GB_COMPILER_MSVC)
|
||||
case gbAllocation_Alloc:
|
||||
ptr = _aligned_malloc(size, alignment);
|
||||
if (flags & gbAllocatorFlag_ClearToZero)
|
||||
gb_zero_size(ptr, size);
|
||||
break;
|
||||
case gbAllocation_Free:
|
||||
_aligned_free(old_memory);
|
||||
break;
|
||||
case gbAllocation_Resize:
|
||||
ptr = _aligned_realloc(old_memory, size, alignment);
|
||||
break;
|
||||
|
||||
#elif defined(GB_SYSTEM_LINUX)
|
||||
// TODO(bill): *nix version that's decent
|
||||
case gbAllocation_Alloc: {
|
||||
ptr = aligned_alloc(alignment, size);
|
||||
// ptr = malloc(size+alignment);
|
||||
|
||||
if (flags & gbAllocatorFlag_ClearToZero) {
|
||||
gb_zero_size(ptr, size);
|
||||
}
|
||||
} break;
|
||||
|
||||
case gbAllocation_Free: {
|
||||
free(old_memory);
|
||||
} break;
|
||||
|
||||
case gbAllocation_Resize: {
|
||||
// ptr = realloc(old_memory, size);
|
||||
ptr = gb_default_resize_align(heap_allocator(), old_memory, old_size, size, alignment);
|
||||
} break;
|
||||
#else
|
||||
// TODO(bill): *nix version that's decent
|
||||
case gbAllocation_Alloc: {
|
||||
posix_memalign(&ptr, alignment, size);
|
||||
|
||||
if (flags & gbAllocatorFlag_ClearToZero) {
|
||||
gb_zero_size(ptr, size);
|
||||
}
|
||||
} break;
|
||||
|
||||
case gbAllocation_Free: {
|
||||
free(old_memory);
|
||||
} break;
|
||||
|
||||
case gbAllocation_Resize: {
|
||||
ptr = gb_default_resize_align(heap_allocator(), old_memory, old_size, size, alignment);
|
||||
} break;
|
||||
#endif
|
||||
|
||||
case gbAllocation_FreeAll:
|
||||
break;
|
||||
}
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
#include "unicode.cpp"
|
||||
@@ -199,7 +268,19 @@ gbAllocator pool_allocator(Pool *pool) {
|
||||
|
||||
|
||||
|
||||
|
||||
i32 next_pow2(i32 n) {
|
||||
if (n <= 0) {
|
||||
return 0;
|
||||
}
|
||||
n--;
|
||||
n |= n >> 1;
|
||||
n |= n >> 2;
|
||||
n |= n >> 4;
|
||||
n |= n >> 8;
|
||||
n |= n >> 16;
|
||||
n++;
|
||||
return n;
|
||||
}
|
||||
i64 next_pow2(i64 n) {
|
||||
if (n <= 0) {
|
||||
return 0;
|
||||
@@ -215,6 +296,17 @@ i64 next_pow2(i64 n) {
|
||||
return n;
|
||||
}
|
||||
|
||||
i32 prev_pow2(i32 n) {
|
||||
if (n <= 0) {
|
||||
return 0;
|
||||
}
|
||||
n |= n >> 1;
|
||||
n |= n >> 2;
|
||||
n |= n >> 4;
|
||||
n |= n >> 8;
|
||||
n |= n >> 16;
|
||||
return n - (n >> 1);
|
||||
}
|
||||
i64 prev_pow2(i64 n) {
|
||||
if (n <= 0) {
|
||||
return 0;
|
||||
@@ -310,7 +402,7 @@ f64 gb_sqrt(f64 x) {
|
||||
wchar_t **command_line_to_wargv(wchar_t *cmd_line, int *_argc) {
|
||||
u32 i, j;
|
||||
|
||||
u32 len = string16_len(cmd_line);
|
||||
u32 len = cast(u32)string16_len(cmd_line);
|
||||
i = ((len+2)/2)*gb_size_of(void *) + gb_size_of(void *);
|
||||
|
||||
wchar_t **argv = cast(wchar_t **)GlobalAlloc(GMEM_FIXED, i + (len+2)*gb_size_of(wchar_t));
|
||||
|
||||
+12
-12
@@ -504,19 +504,19 @@ ExactValue exact_binary_operator_value(TokenKind op, ExactValue x, ExactValue y)
|
||||
i128 b = y.value_integer;
|
||||
i128 c = I128_ZERO;
|
||||
switch (op) {
|
||||
case Token_Add: c = a + b; break;
|
||||
case Token_Sub: c = a - b; break;
|
||||
case Token_Mul: c = a * b; break;
|
||||
case Token_Add: c = a + b; break;
|
||||
case Token_Sub: c = a - b; break;
|
||||
case Token_Mul: c = a * b; break;
|
||||
case Token_Quo: return exact_value_float(fmod(i128_to_f64(a), i128_to_f64(b)));
|
||||
case Token_QuoEq: c = a / b; break; // NOTE(bill): Integer division
|
||||
case Token_Mod: c = a % b; break;
|
||||
case Token_ModMod: c = ((a % b) + b) % b; break;
|
||||
case Token_And: c = a & b; break;
|
||||
case Token_Or: c = a | b; break;
|
||||
case Token_Xor: c = a ^ b; break;
|
||||
case Token_AndNot: c = i128_and_not(a, b); break;
|
||||
case Token_Shl: c = a << i128_to_u64(b); break;
|
||||
case Token_Shr: c = a >> i128_to_u64(b); break;
|
||||
case Token_QuoEq: c = a / b; break; // NOTE(bill): Integer division
|
||||
case Token_Mod: c = a % b; break;
|
||||
case Token_ModMod: c = ((a % b) + b) % b; break;
|
||||
case Token_And: c = a & b; break;
|
||||
case Token_Or: c = a | b; break;
|
||||
case Token_Xor: c = a ^ b; break;
|
||||
case Token_AndNot: c = i128_and_not(a, b); break;
|
||||
case Token_Shl: c = a << cast(u32)i128_to_u64(b); break;
|
||||
case Token_Shr: c = a >> cast(u32)i128_to_u64(b); break;
|
||||
default: goto error;
|
||||
}
|
||||
|
||||
|
||||
+36
-62
@@ -1,4 +1,4 @@
|
||||
/* gb.h - v0.30 - Ginger Bill's C Helper Library - public domain
|
||||
/* gb.h - v0.31 - Ginger Bill's C Helper Library - public domain
|
||||
- no warranty implied; use at your own risk
|
||||
|
||||
This is a single header file with a bunch of useful stuff
|
||||
@@ -58,6 +58,7 @@ TODOS
|
||||
- More date & time functions
|
||||
|
||||
VERSION HISTORY
|
||||
0.31 - Add gb_file_remove
|
||||
0.30 - Changes to gbThread (and gbMutex on Windows)
|
||||
0.29 - Add extras for gbString
|
||||
0.28 - Handle UCS2 correctly in Win32 part
|
||||
@@ -929,19 +930,13 @@ GB_DEF void gb_semaphore_wait (gbSemaphore *s);
|
||||
|
||||
|
||||
// Mutex
|
||||
// TODO(bill): Should this be replaced with a CRITICAL_SECTION on win32 or is the better?
|
||||
typedef struct gbMutex {
|
||||
#if defined(GB_SYSTEM_WINDOWS)
|
||||
typedef struct gbMutex {
|
||||
CRITICAL_SECTION win32_critical_section;
|
||||
} gbMutex;
|
||||
#else
|
||||
typedef struct gbMutex {
|
||||
gbSemaphore semaphore;
|
||||
gbAtomic32 counter;
|
||||
gbAtomic32 owner;
|
||||
i32 recursion;
|
||||
} gbMutex;
|
||||
pthread_mutex_t pthread_mutex;
|
||||
#endif
|
||||
} gbMutex;
|
||||
|
||||
GB_DEF void gb_mutex_init (gbMutex *m);
|
||||
GB_DEF void gb_mutex_destroy (gbMutex *m);
|
||||
@@ -985,7 +980,7 @@ typedef struct gbThread {
|
||||
} gbThread;
|
||||
|
||||
GB_DEF void gb_thread_init (gbThread *t);
|
||||
GB_DEF void gb_thread_destory (gbThread *t);
|
||||
GB_DEF void gb_thread_destroy (gbThread *t);
|
||||
GB_DEF void gb_thread_start (gbThread *t, gbThreadProc *proc, void *data);
|
||||
GB_DEF void gb_thread_start_with_stack(gbThread *t, gbThreadProc *proc, void *data, isize stack_size);
|
||||
GB_DEF void gb_thread_join (gbThread *t);
|
||||
@@ -2056,6 +2051,7 @@ GB_DEF b32 gb_file_exists (char const *filepath);
|
||||
GB_DEF gbFileTime gb_file_last_write_time(char const *filepath);
|
||||
GB_DEF b32 gb_file_copy (char const *existing_filename, char const *new_filename, b32 fail_if_exists);
|
||||
GB_DEF b32 gb_file_move (char const *existing_filename, char const *new_filename);
|
||||
GB_DEF b32 gb_file_remove (char const *filename);
|
||||
|
||||
|
||||
#ifndef GB_PATH_SEPARATOR
|
||||
@@ -4606,12 +4602,7 @@ gb_inline void gb_mutex_init(gbMutex *m) {
|
||||
#if defined(GB_SYSTEM_WINDOWS)
|
||||
InitializeCriticalSection(&m->win32_critical_section);
|
||||
#else
|
||||
// NOTE(bill): THIS IS FUCKING AWESOME THAT THIS "MUTEX" IS FAST AND RECURSIVE TOO!
|
||||
// NOTE(bill): WHO THE FUCK NEEDS A NORMAL MUTEX NOW?!?!?!?!
|
||||
gb_atomic32_store(&m->counter, 0);
|
||||
gb_atomic32_store(&m->owner, gb_thread_current_id());
|
||||
gb_semaphore_init(&m->semaphore);
|
||||
m->recursion = 0;
|
||||
pthread_mutex_init(&m->pthread_mutex, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -4619,7 +4610,7 @@ gb_inline void gb_mutex_destroy(gbMutex *m) {
|
||||
#if defined(GB_SYSTEM_WINDOWS)
|
||||
DeleteCriticalSection(&m->win32_critical_section);
|
||||
#else
|
||||
gb_semaphore_destroy(&m->semaphore);
|
||||
pthread_mutex_destroy(&m->pthread_mutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -4627,15 +4618,7 @@ gb_inline void gb_mutex_lock(gbMutex *m) {
|
||||
#if defined(GB_SYSTEM_WINDOWS)
|
||||
EnterCriticalSection(&m->win32_critical_section);
|
||||
#else
|
||||
i32 thread_id = cast(i32)gb_thread_current_id();
|
||||
if (gb_atomic32_fetch_add(&m->counter, 1) > 0) {
|
||||
if (thread_id != gb_atomic32_load(&m->owner)) {
|
||||
gb_semaphore_wait(&m->semaphore);
|
||||
}
|
||||
}
|
||||
|
||||
gb_atomic32_store(&m->owner, thread_id);
|
||||
m->recursion++;
|
||||
pthread_mutex_lock(&m->pthread_mutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -4643,22 +4626,7 @@ gb_inline b32 gb_mutex_try_lock(gbMutex *m) {
|
||||
#if defined(GB_SYSTEM_WINDOWS)
|
||||
return TryEnterCriticalSection(&m->win32_critical_section) != 0;
|
||||
#else
|
||||
i32 thread_id = cast(i32)gb_thread_current_id();
|
||||
if (gb_atomic32_load(&m->owner) == thread_id) {
|
||||
gb_atomic32_fetch_add(&m->counter, 1);
|
||||
} else {
|
||||
i32 expected = 0;
|
||||
if (gb_atomic32_load(&m->counter) != 0) {
|
||||
return false;
|
||||
}
|
||||
if (!gb_atomic32_compare_exchange(&m->counter, expected, 1)) {
|
||||
return false;
|
||||
}
|
||||
gb_atomic32_store(&m->owner, thread_id);
|
||||
}
|
||||
|
||||
m->recursion++;
|
||||
return true;
|
||||
return pthread_mutex_trylock(&m->pthread_mutex) == 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -4666,19 +4634,7 @@ gb_inline void gb_mutex_unlock(gbMutex *m) {
|
||||
#if defined(GB_SYSTEM_WINDOWS)
|
||||
LeaveCriticalSection(&m->win32_critical_section);
|
||||
#else
|
||||
i32 recursion;
|
||||
i32 thread_id = cast(i32)gb_thread_current_id();
|
||||
|
||||
GB_ASSERT(thread_id == gb_atomic32_load(&m->owner));
|
||||
|
||||
recursion = --m->recursion;
|
||||
if (recursion == 0)
|
||||
gb_atomic32_store(&m->owner, thread_id);
|
||||
|
||||
if (gb_atomic32_fetch_add(&m->counter, -1) > 1) {
|
||||
if (recursion == 0)
|
||||
gb_semaphore_release(&m->semaphore);
|
||||
}
|
||||
pthread_mutex_unlock(&m->pthread_mutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -4698,7 +4654,7 @@ void gb_thread_init(gbThread *t) {
|
||||
gb_semaphore_init(&t->semaphore);
|
||||
}
|
||||
|
||||
void gb_thread_destory(gbThread *t) {
|
||||
void gb_thread_destroy(gbThread *t) {
|
||||
if (t->is_running) gb_thread_join(t);
|
||||
gb_semaphore_destroy(&t->semaphore);
|
||||
}
|
||||
@@ -7472,13 +7428,13 @@ u64 gb_murmur64_seed(void const *data_, isize len, u64 seed) {
|
||||
if (w_len_) *w_len_ = w_len;
|
||||
return NULL;
|
||||
}
|
||||
w_len = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, text, len, NULL, 0);
|
||||
w_len = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, text, cast(int)len, NULL, 0);
|
||||
if (w_len == 0) {
|
||||
if (w_len_) *w_len_ = w_len;
|
||||
return NULL;
|
||||
}
|
||||
w_text = gb_alloc_array(a, wchar_t, w_len+1);
|
||||
w_len1 = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, text, len, w_text, w_len);
|
||||
w_len1 = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, text, cast(int)len, w_text, cast(int)w_len);
|
||||
if (w_len1 == 0) {
|
||||
gb_free(a, w_text);
|
||||
if (w_len_) *w_len_ = 0;
|
||||
@@ -7977,6 +7933,19 @@ gb_inline b32 gb_file_move(char const *existing_filename, char const *new_filena
|
||||
return result;
|
||||
}
|
||||
|
||||
b32 gb_file_remove(char const *filename) {
|
||||
wchar_t *w_filename = NULL;
|
||||
gbAllocator a = gb_heap_allocator();
|
||||
b32 result = false;
|
||||
w_filename = gb__alloc_utf8_to_ucs2(a, filename, NULL);
|
||||
if (w_filename == NULL) {
|
||||
return false;
|
||||
}
|
||||
result = DeleteFileW(w_filename);
|
||||
gb_free(a, w_filename);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#else
|
||||
@@ -8022,6 +7991,11 @@ gb_inline b32 gb_file_move(char const *existing_filename, char const *new_filena
|
||||
return false;
|
||||
}
|
||||
|
||||
b32 gb_file_remove(char const *filename) {
|
||||
return remove(filename) == 0;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -8126,17 +8100,17 @@ char *gb_path_get_full_name(gbAllocator a, char const *path) {
|
||||
return NULL;
|
||||
}
|
||||
w_fullpath = gb_alloc_array(gb_heap_allocator(), wchar_t, w_len+1);
|
||||
GetFullPathNameW(w_path, w_len, w_fullpath, NULL);
|
||||
GetFullPathNameW(w_path, cast(int)w_len, w_fullpath, NULL);
|
||||
w_fullpath[w_len] = 0;
|
||||
gb_free(gb_heap_allocator(), w_path);
|
||||
|
||||
new_len = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, w_fullpath, w_len, NULL, 0, NULL, NULL);
|
||||
new_len = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, w_fullpath, cast(int)w_len, NULL, 0, NULL, NULL);
|
||||
if (new_len == 0) {
|
||||
gb_free(gb_heap_allocator(), w_fullpath);
|
||||
return NULL;
|
||||
}
|
||||
new_path = gb_alloc_array(a, char, new_len+1);
|
||||
new_len1 = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, w_fullpath, w_len, new_path, new_len, NULL, NULL);
|
||||
new_len1 = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, w_fullpath, cast(int)w_len, new_path, cast(int)new_len, NULL, NULL);
|
||||
if (new_len1 == 0) {
|
||||
gb_free(gb_heap_allocator(), w_fullpath);
|
||||
gb_free(a, new_path);
|
||||
|
||||
+38
-38
@@ -13,7 +13,7 @@ struct irModule {
|
||||
gbAllocator tmp_allocator;
|
||||
// bool generate_debug_info;
|
||||
|
||||
u32 stmt_state_flags;
|
||||
u64 stmt_state_flags;
|
||||
|
||||
// String source_filename;
|
||||
String layout;
|
||||
@@ -442,7 +442,7 @@ irAddr ir_addr_map(irValue *addr, irValue *map_key, Type *map_type, Type *map_re
|
||||
return v;
|
||||
}
|
||||
|
||||
irAddr ir_addr_bit_field(irValue *addr, isize bit_field_value_index) {
|
||||
irAddr ir_addr_bit_field(irValue *addr, i32 bit_field_value_index) {
|
||||
irAddr v = {irAddr_BitField, addr};
|
||||
v.bit_field_value_index = bit_field_value_index;
|
||||
return v;
|
||||
@@ -3435,7 +3435,7 @@ irValue *ir_type_info(irProcedure *proc, Type *type) {
|
||||
|
||||
type = default_type(type);
|
||||
|
||||
i32 entry_index = type_info_index(info, type);
|
||||
i32 entry_index = cast(i32)type_info_index(info, type);
|
||||
|
||||
// gb_printf_err("%d %s\n", entry_index, type_to_string(type));
|
||||
|
||||
@@ -3613,7 +3613,7 @@ String ir_mangle_name(irGen *s, String path, Entity *e) {
|
||||
cast(char *)new_name, max_len,
|
||||
"%.*s-%u.%.*s",
|
||||
cast(int)base_len, base,
|
||||
file->id,
|
||||
cast(u32)file->id,
|
||||
LIT(name));
|
||||
}
|
||||
if (require_suffix_id) {
|
||||
@@ -4454,7 +4454,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
|
||||
Entity *field = t->Struct.fields_in_src_order[src_index];
|
||||
i32 field_index = field->Variable.field_index;
|
||||
irValue *f = ir_emit_struct_ev(proc, s, field_index);
|
||||
irValue *ep = ir_emit_struct_ep(proc, tuple, src_index);
|
||||
irValue *ep = ir_emit_struct_ep(proc, tuple, cast(i32)src_index);
|
||||
ir_emit_store(proc, ep, f);
|
||||
}
|
||||
return ir_emit_load(proc, tuple);
|
||||
@@ -4901,7 +4901,7 @@ irValue *ir_build_expr(irProcedure *proc, AstNode *expr) {
|
||||
if (at->kind == Type_Tuple) {
|
||||
for_array(i, at->Tuple.variables) {
|
||||
Entity *e = at->Tuple.variables[i];
|
||||
irValue *v = ir_emit_struct_ev(proc, a, i);
|
||||
irValue *v = ir_emit_struct_ev(proc, a, cast(i32)i);
|
||||
args[arg_index++] = v;
|
||||
}
|
||||
} else {
|
||||
@@ -5001,7 +5001,7 @@ irValue *ir_build_expr(irProcedure *proc, AstNode *expr) {
|
||||
irValue *base_array = ir_add_local_generated(proc, make_type_array(allocator, elem_type, slice_len));
|
||||
|
||||
for (isize i = type->param_count-1, j = 0; i < arg_count; i++, j++) {
|
||||
irValue *addr = ir_emit_array_epi(proc, base_array, j);
|
||||
irValue *addr = ir_emit_array_epi(proc, base_array, cast(i32)j);
|
||||
ir_emit_store(proc, addr, args[i]);
|
||||
}
|
||||
|
||||
@@ -5497,7 +5497,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
|
||||
isize index_count = bt->Vector.count;
|
||||
irValue *elem_val = ir_build_expr(proc, cl->elems[0]);
|
||||
for (isize i = 0; i < index_count; i++) {
|
||||
ir_emit_store(proc, ir_emit_array_epi(proc, v, i), elem_val);
|
||||
ir_emit_store(proc, ir_emit_array_epi(proc, v, cast(i32)i), elem_val);
|
||||
}
|
||||
} else if (cl->elems.count > 0) {
|
||||
ir_emit_store(proc, v, ir_add_module_constant(proc->module, type, exact_value_compound(expr)));
|
||||
@@ -5510,7 +5510,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
|
||||
Type *t = ir_type(field_expr);
|
||||
GB_ASSERT(t->kind != Type_Tuple);
|
||||
irValue *ev = ir_emit_conv(proc, field_expr, et);
|
||||
irValue *gep = ir_emit_array_epi(proc, v, i);
|
||||
irValue *gep = ir_emit_array_epi(proc, v, cast(i32)i);
|
||||
ir_emit_store(proc, gep, ev);
|
||||
}
|
||||
}
|
||||
@@ -5556,7 +5556,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
|
||||
GB_ASSERT(ir_type(field_expr)->kind != Type_Tuple);
|
||||
|
||||
irValue *fv = ir_emit_conv(proc, field_expr, ft);
|
||||
irValue *gep = ir_emit_struct_ep(proc, v, index);
|
||||
irValue *gep = ir_emit_struct_ep(proc, v, cast(i32)index);
|
||||
ir_emit_store(proc, gep, fv);
|
||||
}
|
||||
}
|
||||
@@ -5585,7 +5585,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
|
||||
for_array(field_index, cl->elems) {
|
||||
AstNode *f = cl->elems[field_index];
|
||||
irValue *value = ir_emit_conv(proc, ir_build_expr(proc, f), elem);
|
||||
irValue *ep = ir_emit_array_epi(proc, items, field_index);
|
||||
irValue *ep = ir_emit_array_epi(proc, items, cast(i32)field_index);
|
||||
ir_emit_store(proc, ep, value);
|
||||
}
|
||||
|
||||
@@ -5633,7 +5633,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
|
||||
Type *t = ir_type(field_expr);
|
||||
GB_ASSERT(t->kind != Type_Tuple);
|
||||
irValue *ev = ir_emit_conv(proc, field_expr, et);
|
||||
irValue *gep = ir_emit_array_epi(proc, v, i);
|
||||
irValue *gep = ir_emit_array_epi(proc, v, cast(i32)i);
|
||||
ir_emit_store(proc, gep, ev);
|
||||
}
|
||||
}
|
||||
@@ -5703,7 +5703,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
|
||||
|
||||
Type *ft = field_types[index];
|
||||
irValue *fv = ir_emit_conv(proc, field_expr, ft);
|
||||
irValue *gep = ir_emit_struct_ep(proc, v, index);
|
||||
irValue *gep = ir_emit_struct_ep(proc, v, cast(i32)index);
|
||||
ir_emit_store(proc, gep, fv);
|
||||
}
|
||||
}
|
||||
@@ -5936,11 +5936,11 @@ void ir_build_stmt_list(irProcedure *proc, Array<AstNode *> stmts) {
|
||||
|
||||
void ir_build_stmt_internal(irProcedure *proc, AstNode *node);
|
||||
void ir_build_stmt(irProcedure *proc, AstNode *node) {
|
||||
u32 prev_stmt_state_flags = proc->module->stmt_state_flags;
|
||||
u64 prev_stmt_state_flags = proc->module->stmt_state_flags;
|
||||
|
||||
if (node->stmt_state_flags != 0) {
|
||||
u32 in = node->stmt_state_flags;
|
||||
u32 out = proc->module->stmt_state_flags;
|
||||
u64 in = node->stmt_state_flags;
|
||||
u64 out = proc->module->stmt_state_flags;
|
||||
|
||||
if (in & StmtStateFlag_bounds_check) {
|
||||
out |= StmtStateFlag_bounds_check;
|
||||
@@ -6285,7 +6285,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
|
||||
if (t->kind == Type_Tuple) {
|
||||
for_array(i, t->Tuple.variables) {
|
||||
Entity *e = t->Tuple.variables[i];
|
||||
irValue *v = ir_emit_struct_ev(proc, init, i);
|
||||
irValue *v = ir_emit_struct_ev(proc, init, cast(i32)i);
|
||||
array_add(&inits, v);
|
||||
}
|
||||
} else {
|
||||
@@ -6350,7 +6350,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
|
||||
if (t->kind == Type_Tuple) {
|
||||
for_array(i, t->Tuple.variables) {
|
||||
Entity *e = t->Tuple.variables[i];
|
||||
irValue *v = ir_emit_struct_ev(proc, init, i);
|
||||
irValue *v = ir_emit_struct_ev(proc, init, cast(i32)i);
|
||||
array_add(&inits, v);
|
||||
}
|
||||
} else {
|
||||
@@ -6445,7 +6445,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
|
||||
Type *ret_type = proc->type->Proc.results;
|
||||
v = ir_add_local_generated(proc, ret_type);
|
||||
for_array(i, results) {
|
||||
irValue *field = ir_emit_struct_ep(proc, v, i);
|
||||
irValue *field = ir_emit_struct_ep(proc, v, cast(i32)i);
|
||||
irValue *res = results[i];
|
||||
ir_emit_store(proc, field, res);
|
||||
}
|
||||
@@ -6481,7 +6481,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
|
||||
if (t->kind == Type_Tuple) {
|
||||
for_array(i, t->Tuple.variables) {
|
||||
Entity *e = t->Tuple.variables[i];
|
||||
irValue *v = ir_emit_struct_ev(proc, res, i);
|
||||
irValue *v = ir_emit_struct_ev(proc, res, cast(i32)i);
|
||||
array_add(&results, v);
|
||||
total_index++;
|
||||
}
|
||||
@@ -6509,7 +6509,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
|
||||
for_array(i, results) {
|
||||
Entity *e = tuple->variables[i];
|
||||
irValue *res = ir_emit_conv(proc, results[i], e->type);
|
||||
irValue *field = ir_emit_struct_ep(proc, v, i);
|
||||
irValue *field = ir_emit_struct_ep(proc, v, cast(i32)i);
|
||||
ir_emit_store(proc, field, res);
|
||||
}
|
||||
|
||||
@@ -7111,7 +7111,7 @@ void ir_number_proc_registers(irProcedure *proc) {
|
||||
i32 reg_index = 0;
|
||||
for_array(i, proc->blocks) {
|
||||
irBlock *b = proc->blocks[i];
|
||||
b->index = i;
|
||||
b->index = cast(i32)i;
|
||||
for_array(j, b->instrs) {
|
||||
irValue *value = b->instrs[j];
|
||||
GB_ASSERT_MSG(value->kind == irValue_Instr, "%.*s", LIT(proc->name));
|
||||
@@ -7255,11 +7255,11 @@ void ir_build_proc(irValue *value, irProcedure *parent) {
|
||||
}
|
||||
|
||||
if (proc->body != nullptr) {
|
||||
u32 prev_stmt_state_flags = proc->module->stmt_state_flags;
|
||||
u64 prev_stmt_state_flags = proc->module->stmt_state_flags;
|
||||
|
||||
if (proc->tags != 0) {
|
||||
u32 in = proc->tags;
|
||||
u32 out = proc->module->stmt_state_flags;
|
||||
u64 in = proc->tags;
|
||||
u64 out = proc->module->stmt_state_flags;
|
||||
if (in & ProcTag_bounds_check) {
|
||||
out |= StmtStateFlag_bounds_check;
|
||||
out &= ~StmtStateFlag_no_bounds_check;
|
||||
@@ -7483,22 +7483,22 @@ irValue *ir_get_type_info_ptr(irProcedure *proc, Type *type) {
|
||||
|
||||
irValue *ir_type_info_member_types_offset(irProcedure *proc, isize count) {
|
||||
irValue *offset = ir_emit_array_epi(proc, ir_global_type_info_member_types, ir_global_type_info_member_types_index);
|
||||
ir_global_type_info_member_types_index += count;
|
||||
ir_global_type_info_member_types_index += cast(i32)count;
|
||||
return offset;
|
||||
}
|
||||
irValue *ir_type_info_member_names_offset(irProcedure *proc, isize count) {
|
||||
irValue *offset = ir_emit_array_epi(proc, ir_global_type_info_member_names, ir_global_type_info_member_names_index);
|
||||
ir_global_type_info_member_names_index += count;
|
||||
ir_global_type_info_member_names_index += cast(i32)count;
|
||||
return offset;
|
||||
}
|
||||
irValue *ir_type_info_member_offsets_offset(irProcedure *proc, isize count) {
|
||||
irValue *offset = ir_emit_array_epi(proc, ir_global_type_info_member_offsets, ir_global_type_info_member_offsets_index);
|
||||
ir_global_type_info_member_offsets_index += count;
|
||||
ir_global_type_info_member_offsets_index += cast(i32)count;
|
||||
return offset;
|
||||
}
|
||||
irValue *ir_type_info_member_usings_offset(irProcedure *proc, isize count) {
|
||||
irValue *offset = ir_emit_array_epi(proc, ir_global_type_info_member_usings, ir_global_type_info_member_usings_index);
|
||||
ir_global_type_info_member_usings_index += count;
|
||||
ir_global_type_info_member_usings_index += cast(i32)count;
|
||||
return offset;
|
||||
}
|
||||
|
||||
@@ -7706,7 +7706,7 @@ void ir_gen_tree(irGen *s) {
|
||||
for_array(i, m->debug_info.entries) {
|
||||
auto *entry = &m->debug_info.entries[i];
|
||||
irDebugInfo *di = entry->value;
|
||||
di->id = i;
|
||||
di->id = cast(i32)i;
|
||||
if (di->kind == irDebugInfo_Proc) {
|
||||
all_proc_max_count++;
|
||||
}
|
||||
@@ -7942,7 +7942,7 @@ void ir_gen_tree(irGen *s) {
|
||||
isize entry_index = type_info_index(info, t);
|
||||
|
||||
irValue *tag = nullptr;
|
||||
irValue *ti_ptr = ir_emit_array_epi(proc, ir_global_type_info_data, entry_index);
|
||||
irValue *ti_ptr = ir_emit_array_epi(proc, ir_global_type_info_data, cast(i32)entry_index);
|
||||
irValue *variant_ptr = ir_emit_struct_ep(proc, ti_ptr, 2);
|
||||
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, ti_ptr, 0), ir_const_int(a, type_size_of(a, t)));
|
||||
@@ -8134,8 +8134,8 @@ void ir_gen_tree(irGen *s) {
|
||||
}
|
||||
|
||||
for (isize i = 0; i < count; i++) {
|
||||
irValue *name_ep = ir_emit_array_epi(proc, name_array, i);
|
||||
irValue *value_ep = ir_emit_array_epi(proc, value_array, i);
|
||||
irValue *name_ep = ir_emit_array_epi(proc, name_array, cast(i32)i);
|
||||
irValue *value_ep = ir_emit_array_epi(proc, value_array, cast(i32)i);
|
||||
|
||||
ExactValue value = fields[i]->Constant.value;
|
||||
irValue *v = ir_value_constant(a, t->Enum.base_type, value);
|
||||
@@ -8202,7 +8202,7 @@ void ir_gen_tree(irGen *s) {
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 7), is_custom_align);
|
||||
}
|
||||
|
||||
i32 count = t->Struct.fields.count;
|
||||
isize count = t->Struct.fields.count;
|
||||
|
||||
irValue *memory_types = ir_type_info_member_types_offset (proc, count);
|
||||
irValue *memory_names = ir_type_info_member_names_offset (proc, count);
|
||||
@@ -8271,9 +8271,9 @@ void ir_gen_tree(irGen *s) {
|
||||
Entity *f = fields[i];
|
||||
GB_ASSERT(f->type != nullptr);
|
||||
GB_ASSERT(f->type->kind == Type_BitFieldValue);
|
||||
irValue *name_ep = ir_emit_array_epi(proc, name_array, i);
|
||||
irValue *bit_ep = ir_emit_array_epi(proc, bit_array, i);
|
||||
irValue *offset_ep = ir_emit_array_epi(proc, offset_array, i);
|
||||
irValue *name_ep = ir_emit_array_epi(proc, name_array, cast(i32)i);
|
||||
irValue *bit_ep = ir_emit_array_epi(proc, bit_array, cast(i32)i);
|
||||
irValue *offset_ep = ir_emit_array_epi(proc, offset_array, cast(i32)i);
|
||||
|
||||
ir_emit_store(proc, name_ep, ir_const_string(a, f->token.string));
|
||||
ir_emit_store(proc, bit_ep, ir_const_u32(a, f->type->BitFieldValue.bits));
|
||||
@@ -8336,7 +8336,7 @@ void ir_gen_tree(irGen *s) {
|
||||
for_array(i, m->debug_info.entries) {
|
||||
auto *entry = &m->debug_info.entries[i];
|
||||
irDebugInfo *di = entry->value;
|
||||
di->id = i;
|
||||
di->id = cast(i32)i;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -172,7 +172,7 @@ void ir_remove_dead_blocks(irProcedure *proc) {
|
||||
continue;
|
||||
}
|
||||
// NOTE(bill): Swap order
|
||||
b->index = j;
|
||||
b->index = cast(i32)j;
|
||||
proc->blocks[j++] = b;
|
||||
}
|
||||
proc->blocks.count = j;
|
||||
@@ -373,7 +373,7 @@ void ir_opt_build_dom_tree(irProcedure *proc) {
|
||||
|
||||
gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&proc->module->tmp_arena);
|
||||
|
||||
isize n = proc->blocks.count;
|
||||
i32 n = cast(i32)proc->blocks.count;
|
||||
irBlock **buf = gb_alloc_array(proc->module->tmp_allocator, irBlock *, 5*n);
|
||||
|
||||
irLTState lt = {0};
|
||||
|
||||
+1
-1
@@ -686,7 +686,7 @@ void ir_print_exact_value(irFileBuffer *f, irModule *m, ExactValue value, Type *
|
||||
ir_write_string(f, "zeroinitializer");
|
||||
} else {
|
||||
if (is_type_struct(type)) {
|
||||
i32 value_count = type->Struct.fields.count;
|
||||
i32 value_count = cast(i32)type->Struct.fields.count;
|
||||
if (type->Struct.is_packed) ir_write_byte(f, '<');
|
||||
ir_write_byte(f, '{');
|
||||
if (type->Struct.custom_align > 0) {
|
||||
|
||||
+37
-4
@@ -174,6 +174,7 @@ enum BuildFlagKind {
|
||||
BuildFlag_OptimizationLevel,
|
||||
BuildFlag_ShowTimings,
|
||||
BuildFlag_ThreadCount,
|
||||
BuildFlag_KeepTempFiles,
|
||||
|
||||
BuildFlag_COUNT,
|
||||
};
|
||||
@@ -204,9 +205,10 @@ void add_flag(Array<BuildFlag> *build_flags, BuildFlagKind kind, String name, Bu
|
||||
bool parse_build_flags(Array<String> args) {
|
||||
Array<BuildFlag> build_flags = {};
|
||||
array_init(&build_flags, heap_allocator(), BuildFlag_COUNT);
|
||||
add_flag(&build_flags, BuildFlag_OptimizationLevel, str_lit("opt"), BuildFlagParam_Integer);
|
||||
add_flag(&build_flags, BuildFlag_ShowTimings, str_lit("show-timings"), BuildFlagParam_None);
|
||||
add_flag(&build_flags, BuildFlag_ThreadCount, str_lit("thread-count"), BuildFlagParam_Integer);
|
||||
add_flag(&build_flags, BuildFlag_OptimizationLevel, str_lit("opt"), BuildFlagParam_Integer);
|
||||
add_flag(&build_flags, BuildFlag_ShowTimings, str_lit("show-timings"), BuildFlagParam_None);
|
||||
add_flag(&build_flags, BuildFlag_ThreadCount, str_lit("thread-count"), BuildFlagParam_Integer);
|
||||
add_flag(&build_flags, BuildFlag_KeepTempFiles, str_lit("keep-temp-files"), BuildFlagParam_None);
|
||||
|
||||
|
||||
Array<String> flag_args = args;
|
||||
@@ -350,6 +352,10 @@ bool parse_build_flags(Array<String> args) {
|
||||
build_context.thread_count = count;
|
||||
}
|
||||
} break;
|
||||
case BuildFlag_KeepTempFiles:
|
||||
GB_ASSERT(value.kind == ExactValue_Invalid);
|
||||
build_context.keep_temp_files = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -404,6 +410,30 @@ void show_timings(Checker *c, Timings *t) {
|
||||
}
|
||||
}
|
||||
|
||||
void remove_temp_files(String output_base) {
|
||||
if (build_context.keep_temp_files) return;
|
||||
|
||||
Array<u8> data = {};
|
||||
array_init_count(&data, heap_allocator(), output_base.len + 10);
|
||||
defer (array_free(&data));
|
||||
|
||||
isize n = output_base.len;
|
||||
gb_memcopy(data.data, output_base.text, n);
|
||||
#define EXT_REMOVE(s) do { \
|
||||
gb_memcopy(data.data+n, s, gb_size_of(s)); \
|
||||
gb_file_remove(cast(char *)data.data); \
|
||||
} while (0)
|
||||
EXT_REMOVE(".ll");
|
||||
EXT_REMOVE(".bc");
|
||||
#if defined(GB_SYSTEM_WINDOWS)
|
||||
EXT_REMOVE(".obj");
|
||||
#else
|
||||
EXT_REMOVE(".o");
|
||||
#endif
|
||||
|
||||
#undef EXT_REMOVE
|
||||
}
|
||||
|
||||
int main(int arg_count, char **arg_ptr) {
|
||||
if (arg_count < 2) {
|
||||
usage(make_string_c(arg_ptr[0]));
|
||||
@@ -542,7 +572,7 @@ int main(int arg_count, char **arg_ptr) {
|
||||
|
||||
String output_name = ir_gen.output_name;
|
||||
String output_base = ir_gen.output_base;
|
||||
int base_name_len = output_base.len;
|
||||
int base_name_len = cast(int)output_base.len;
|
||||
|
||||
build_context.optimization_level = gb_clamp(build_context.optimization_level, 0, 3);
|
||||
|
||||
@@ -642,6 +672,7 @@ int main(int arg_count, char **arg_ptr) {
|
||||
show_timings(&checker, &timings);
|
||||
}
|
||||
|
||||
remove_temp_files(output_base);
|
||||
|
||||
if (run_output) {
|
||||
system_exec_command_line_app("odin run", false, "%.*s.exe", LIT(output_base));
|
||||
@@ -748,6 +779,8 @@ int main(int arg_count, char **arg_ptr) {
|
||||
show_timings(&checker, &timings);
|
||||
}
|
||||
|
||||
remove_temp_files(output_base);
|
||||
|
||||
if (run_output) {
|
||||
system_exec_command_line_app("odin run", false, "%.*s", LIT(output_base));
|
||||
}
|
||||
|
||||
+33
-32
@@ -36,7 +36,7 @@ struct ImportedFile {
|
||||
|
||||
|
||||
struct AstFile {
|
||||
i32 id;
|
||||
isize id;
|
||||
gbArena arena;
|
||||
Tokenizer tokenizer;
|
||||
Array<Token> tokens;
|
||||
@@ -79,11 +79,10 @@ struct Parser {
|
||||
String init_fullpath;
|
||||
Array<AstFile> files;
|
||||
Array<ImportedFile> imports;
|
||||
isize curr_import_index;
|
||||
gbAtomic32 import_index;
|
||||
isize total_token_count;
|
||||
isize total_line_count;
|
||||
gbMutex mutex;
|
||||
gbMutex file_add_mutex;
|
||||
gbMutex file_decl_mutex;
|
||||
};
|
||||
|
||||
enum ProcTag {
|
||||
@@ -1574,7 +1573,7 @@ AstNode *ast_foreign_library_spec(AstFile *f, Token filepath, Token library_name
|
||||
|
||||
|
||||
bool next_token0(AstFile *f) {
|
||||
Token prev = f->curr_token;
|
||||
// Token prev = f->curr_token;
|
||||
if (f->curr_token_index+1 < f->tokens.count) {
|
||||
f->curr_token = f->tokens[++f->curr_token_index];
|
||||
return true;
|
||||
@@ -1675,10 +1674,9 @@ TokenKind look_ahead_token_kind(AstFile *f, isize amount) {
|
||||
Token expect_token(AstFile *f, TokenKind kind) {
|
||||
Token prev = f->curr_token;
|
||||
if (prev.kind != kind) {
|
||||
String c = token_strings[kind];
|
||||
String p = token_strings[prev.kind];
|
||||
syntax_error(f->curr_token, "Expected `%.*s`, got `%.*s`",
|
||||
LIT(token_strings[kind]),
|
||||
LIT(token_strings[prev.kind]));
|
||||
syntax_error(f->curr_token, "Expected `%.*s`, got `%.*s`", LIT(c), LIT(p));
|
||||
if (prev.kind == Token_EOF) {
|
||||
gb_exit(1);
|
||||
}
|
||||
@@ -4813,7 +4811,8 @@ void destroy_ast_file(AstFile *f) {
|
||||
bool init_parser(Parser *p) {
|
||||
array_init(&p->files, heap_allocator());
|
||||
array_init(&p->imports, heap_allocator());
|
||||
gb_mutex_init(&p->mutex);
|
||||
gb_mutex_init(&p->file_add_mutex);
|
||||
gb_mutex_init(&p->file_decl_mutex);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -4829,14 +4828,12 @@ void destroy_parser(Parser *p) {
|
||||
#endif
|
||||
array_free(&p->files);
|
||||
array_free(&p->imports);
|
||||
gb_mutex_destroy(&p->mutex);
|
||||
gb_mutex_destroy(&p->file_add_mutex);
|
||||
gb_mutex_destroy(&p->file_decl_mutex);
|
||||
}
|
||||
|
||||
// NOTE(bill): Returns true if it's added
|
||||
bool try_add_import_path(Parser *p, String path, String rel_path, TokenPos pos) {
|
||||
gb_mutex_lock(&p->mutex);
|
||||
defer (gb_mutex_unlock(&p->mutex));
|
||||
|
||||
if (build_context.generate_docs) {
|
||||
return false;
|
||||
}
|
||||
@@ -4922,8 +4919,9 @@ void parse_setup_file_decls(Parser *p, AstFile *f, String base_dir, Array<AstNod
|
||||
String collection_name = {};
|
||||
String oirignal_string = id->relpath.string;
|
||||
String file_str = id->relpath.string;
|
||||
gbAllocator allocator = heap_allocator(); // TODO(bill): Change this allocator
|
||||
gbAllocator a = heap_allocator(); // TODO(bill): Change this allocator
|
||||
String import_file = {};
|
||||
String rel_path = {};
|
||||
|
||||
if (!is_import_path_valid(file_str)) {
|
||||
if (id->is_import) {
|
||||
@@ -4936,11 +4934,13 @@ void parse_setup_file_decls(Parser *p, AstFile *f, String base_dir, Array<AstNod
|
||||
continue;
|
||||
}
|
||||
|
||||
gb_mutex_lock(&p->file_decl_mutex);
|
||||
defer (gb_mutex_unlock(&p->file_decl_mutex));
|
||||
|
||||
String rel_path = get_fullpath_relative(allocator, base_dir, file_str);
|
||||
rel_path = get_fullpath_relative(a, base_dir, file_str);
|
||||
import_file = rel_path;
|
||||
if (!gb_file_exists(cast(char *)rel_path.text)) { // NOTE(bill): This should be null terminated
|
||||
String abs_path = get_fullpath_core(allocator, file_str);
|
||||
String abs_path = get_fullpath_core(a, file_str);
|
||||
if (gb_file_exists(cast(char *)abs_path.text)) {
|
||||
import_file = abs_path;
|
||||
}
|
||||
@@ -5040,13 +5040,11 @@ ParseFileError parse_import(Parser *p, ImportedFile imported_file) {
|
||||
}
|
||||
parse_file(p, &file);
|
||||
|
||||
{
|
||||
gb_mutex_lock(&p->mutex);
|
||||
file.id = imported_file.index;
|
||||
array_add(&p->files, file);
|
||||
p->total_line_count += file.tokenizer.line_count;
|
||||
gb_mutex_unlock(&p->mutex);
|
||||
}
|
||||
gb_mutex_lock(&p->file_add_mutex);
|
||||
file.id = imported_file.index;
|
||||
array_add(&p->files, file);
|
||||
p->total_line_count += file.tokenizer.line_count;
|
||||
gb_mutex_unlock(&p->file_add_mutex);
|
||||
|
||||
|
||||
return ParseFile_None;
|
||||
@@ -5092,7 +5090,8 @@ ParseFileError parse_files(Parser *p, String init_filename) {
|
||||
p->init_fullpath = init_fullpath;
|
||||
|
||||
|
||||
#if USE_THREADED_PARSER
|
||||
// IMPORTANT TODO(bill): Figure out why this doesn't work on *nix sometimes
|
||||
#if USE_THREADED_PARSER && defined(GB_SYSTEM_WINDOWS)
|
||||
isize thread_count = gb_max(build_context.thread_count, 1);
|
||||
if (thread_count > 1) {
|
||||
Array<gbThread> worker_threads = {};
|
||||
@@ -5103,6 +5102,7 @@ ParseFileError parse_files(Parser *p, String init_filename) {
|
||||
gbThread *t = &worker_threads[i];
|
||||
gb_thread_init(t);
|
||||
}
|
||||
isize curr_import_index = 0;
|
||||
|
||||
// NOTE(bill): Make sure that these are in parsed in this order
|
||||
for (isize i = 0; i < shared_file_count; i++) {
|
||||
@@ -5110,7 +5110,7 @@ ParseFileError parse_files(Parser *p, String init_filename) {
|
||||
if (err != ParseFile_None) {
|
||||
return err;
|
||||
}
|
||||
p->curr_import_index++;
|
||||
curr_import_index++;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
@@ -5119,25 +5119,26 @@ ParseFileError parse_files(Parser *p, String init_filename) {
|
||||
gbThread *t = &worker_threads[i];
|
||||
if (gb_thread_is_running(t)) {
|
||||
are_any_alive = true;
|
||||
} else if (p->curr_import_index < p->imports.count) {
|
||||
if (t->return_value != 0) {
|
||||
} else if (curr_import_index < p->imports.count) {
|
||||
auto err = cast(ParseFileError)t->return_value;
|
||||
if (err != ParseFile_None) {
|
||||
for_array(i, worker_threads) {
|
||||
gb_thread_destory(&worker_threads[i]);
|
||||
gb_thread_destroy(&worker_threads[i]);
|
||||
}
|
||||
return cast(ParseFileError)t->return_value;
|
||||
return err;
|
||||
}
|
||||
t->user_index = p->curr_import_index++;
|
||||
t->user_index = curr_import_index++;
|
||||
gb_thread_start(t, parse_worker_file_proc, p);
|
||||
are_any_alive = true;
|
||||
}
|
||||
}
|
||||
if (!are_any_alive && p->curr_import_index >= p->imports.count) {
|
||||
if (!are_any_alive && curr_import_index >= p->imports.count) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for_array(i, worker_threads) {
|
||||
gb_thread_destory(&worker_threads[i]);
|
||||
gb_thread_destroy(&worker_threads[i]);
|
||||
}
|
||||
} else {
|
||||
for_array(i, p->imports) {
|
||||
|
||||
+7
-7
@@ -1640,18 +1640,18 @@ ssaValue *ssa_build_expr(ssaProc *p, AstNode *expr) {
|
||||
|
||||
i64 s = 8*type_size_of(p->allocator, t);
|
||||
switch (s) {
|
||||
case 8: return ssa_const_i8 (p, tv.type, i128_to_i64(tv.value.value_integer));
|
||||
case 16: return ssa_const_i16(p, tv.type, i128_to_i64(tv.value.value_integer));
|
||||
case 32: return ssa_const_i32(p, tv.type, i128_to_i64(tv.value.value_integer));
|
||||
case 64: return ssa_const_i64(p, tv.type, i128_to_i64(tv.value.value_integer));
|
||||
case 8: return ssa_const_i8 (p, tv.type, cast (i8)i128_to_i64(tv.value.value_integer));
|
||||
case 16: return ssa_const_i16(p, tv.type, cast(i16)i128_to_i64(tv.value.value_integer));
|
||||
case 32: return ssa_const_i32(p, tv.type, cast(i32)i128_to_i64(tv.value.value_integer));
|
||||
case 64: return ssa_const_i64(p, tv.type, cast(i64)i128_to_i64(tv.value.value_integer));
|
||||
default: GB_PANIC("Unknown integer size");
|
||||
}
|
||||
} else if (is_type_float(t)) {
|
||||
GB_ASSERT(tv.value.kind == ExactValue_Float);
|
||||
i64 s = 8*type_size_of(p->allocator, t);
|
||||
switch (s) {
|
||||
case 32: return ssa_const_f32(p, tv.type, tv.value.value_float);
|
||||
case 64: return ssa_const_f64(p, tv.type, tv.value.value_float);
|
||||
case 32: return ssa_const_f32(p, tv.type, cast(f32)tv.value.value_float);
|
||||
case 64: return ssa_const_f64(p, tv.type, cast(f64)tv.value.value_float);
|
||||
default: GB_PANIC("Unknown float size");
|
||||
}
|
||||
}
|
||||
@@ -2556,7 +2556,7 @@ String ssa_mangle_name(ssaModule *m, String path, Entity *e) {
|
||||
cast(char *)new_name, max_len,
|
||||
"%.*s-%u.%.*s",
|
||||
cast(int)base_len, base,
|
||||
file->id,
|
||||
cast(u32)file->id,
|
||||
LIT(name));
|
||||
if (is_overloaded) {
|
||||
char *str = cast(char *)new_name + new_name_len-1;
|
||||
|
||||
+4
-5
@@ -196,7 +196,6 @@ gb_inline bool str_has_prefix(String s, String prefix) {
|
||||
gb_inline isize string_extension_position(String str) {
|
||||
isize dot_pos = -1;
|
||||
isize i = str.len;
|
||||
bool seen_dot = false;
|
||||
while (i --> 0) {
|
||||
if (str[i] == GB_PATH_SEPARATOR)
|
||||
break;
|
||||
@@ -317,14 +316,14 @@ String16 string_to_string16(gbAllocator a, String s) {
|
||||
return make_string16(nullptr, 0);
|
||||
}
|
||||
|
||||
len = convert_multibyte_to_widechar(cast(char *)s.text, s.len, nullptr, 0);
|
||||
len = convert_multibyte_to_widechar(cast(char *)s.text, cast(int)s.len, nullptr, 0);
|
||||
if (len == 0) {
|
||||
return make_string16(nullptr, 0);
|
||||
}
|
||||
|
||||
text = gb_alloc_array(a, wchar_t, len+1);
|
||||
|
||||
len1 = convert_multibyte_to_widechar(cast(char *)s.text, s.len, text, len);
|
||||
len1 = convert_multibyte_to_widechar(cast(char *)s.text, cast(int)s.len, text, cast(int)len);
|
||||
if (len1 == 0) {
|
||||
gb_free(a, text);
|
||||
return make_string16(nullptr, 0);
|
||||
@@ -343,7 +342,7 @@ String string16_to_string(gbAllocator a, String16 s) {
|
||||
return make_string(nullptr, 0);
|
||||
}
|
||||
|
||||
len = convert_widechar_to_multibyte(s.text, s.len, nullptr, 0);
|
||||
len = convert_widechar_to_multibyte(s.text, cast(int)s.len, nullptr, 0);
|
||||
if (len == 0) {
|
||||
return make_string(nullptr, 0);
|
||||
}
|
||||
@@ -351,7 +350,7 @@ String string16_to_string(gbAllocator a, String16 s) {
|
||||
|
||||
text = gb_alloc_array(a, u8, len+1);
|
||||
|
||||
len1 = convert_widechar_to_multibyte(s.text, s.len, cast(char *)text, len);
|
||||
len1 = convert_widechar_to_multibyte(s.text, cast(int)s.len, cast(char *)text, cast(int)len);
|
||||
if (len1 == 0) {
|
||||
gb_free(a, text);
|
||||
return make_string(nullptr, 0);
|
||||
|
||||
+6
-6
@@ -551,9 +551,9 @@ Type *make_type_proc(gbAllocator a, Scope *scope, Type *params, isize param_coun
|
||||
|
||||
t->Proc.scope = scope;
|
||||
t->Proc.params = params;
|
||||
t->Proc.param_count = param_count;
|
||||
t->Proc.param_count = cast(i32)param_count;
|
||||
t->Proc.results = results;
|
||||
t->Proc.result_count = result_count;
|
||||
t->Proc.result_count = cast(i32)result_count;
|
||||
t->Proc.variadic = variadic;
|
||||
t->Proc.calling_convention = calling_convention;
|
||||
return t;
|
||||
@@ -1400,7 +1400,7 @@ Selection lookup_field_from_index(gbAllocator a, Type *type, i64 index) {
|
||||
GB_ASSERT(is_type_struct(type) || is_type_union(type) || is_type_tuple(type));
|
||||
type = base_type(type);
|
||||
|
||||
i64 max_count = 0;
|
||||
isize max_count = 0;
|
||||
switch (type->kind) {
|
||||
case Type_Struct: max_count = type->Struct.fields.count; break;
|
||||
case Type_Tuple: max_count = type->Tuple.variables.count; break;
|
||||
@@ -1419,7 +1419,7 @@ Selection lookup_field_from_index(gbAllocator a, Type *type, i64 index) {
|
||||
if (f->Variable.field_src_index == index) {
|
||||
Array<i32> sel_array = {0};
|
||||
array_init_count(&sel_array, a, 1);
|
||||
sel_array[0] = i;
|
||||
sel_array[0] = cast(i32)i;
|
||||
return make_selection(f, sel_array, false);
|
||||
}
|
||||
}
|
||||
@@ -1431,7 +1431,7 @@ Selection lookup_field_from_index(gbAllocator a, Type *type, i64 index) {
|
||||
if (i == index) {
|
||||
Array<i32> sel_array = {0};
|
||||
array_init_count(&sel_array, a, 1);
|
||||
sel_array[0] = i;
|
||||
sel_array[0] = cast(i32)i;
|
||||
return make_selection(f, sel_array, false);
|
||||
}
|
||||
}
|
||||
@@ -2192,7 +2192,7 @@ i64 type_offset_of_from_selection(gbAllocator allocator, Type *type, Selection s
|
||||
Type *t = type;
|
||||
i64 offset = 0;
|
||||
for_array(i, sel.index) {
|
||||
isize index = sel.index[i];
|
||||
i32 index = sel.index[i];
|
||||
t = base_type(t);
|
||||
offset += type_offset_of(allocator, t, index);
|
||||
if (t->kind == Type_Struct && !t->Struct.is_raw_union) {
|
||||
|
||||
Reference in New Issue
Block a user