mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Make source code compile with 32 bit (but not build 32 bit code)
This commit is contained in:
+2
-2
@@ -64,7 +64,7 @@ murmur32 :: proc(data: []byte) -> u32 {
|
|||||||
c2_32: u32 : 0x1b873593;
|
c2_32: u32 : 0x1b873593;
|
||||||
|
|
||||||
h1: u32 = 0;
|
h1: u32 = 0;
|
||||||
nblocks := uintptr(len(data)/4);
|
nblocks := len(data)/4;
|
||||||
p := &data[0];
|
p := &data[0];
|
||||||
p1 := mem.ptr_offset(p, 4*nblocks);
|
p1 := mem.ptr_offset(p, 4*nblocks);
|
||||||
|
|
||||||
@@ -187,7 +187,7 @@ murmur64 :: proc(data: []byte) -> u64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO(bill): Fix this
|
// TODO(bill): Fix this
|
||||||
#no_bounds_check data8 := slice_to_bytes(data32[i..])[..3];
|
#no_bounds_check data8 := mem.slice_to_bytes(data32[i..])[..3];
|
||||||
switch len {
|
switch len {
|
||||||
case 3:
|
case 3:
|
||||||
h2 ~= u32(data8[2]) << 16;
|
h2 ~= u32(data8[2]) << 16;
|
||||||
|
|||||||
+1
-1
@@ -235,7 +235,7 @@ pool_alloc :: proc(using pool: ^Pool, bytes: int) -> rawptr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
memory := current_pos;
|
memory := current_pos;
|
||||||
current_pos = ptr_offset((^byte)(current_pos), uintptr(bytes));
|
current_pos = ptr_offset((^byte)(current_pos), bytes);
|
||||||
bytes_left -= bytes;
|
bytes_left -= bytes;
|
||||||
return memory;
|
return memory;
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -62,16 +62,16 @@ compare :: proc "contextless" (a, b: []byte) -> int {
|
|||||||
}
|
}
|
||||||
compare_byte_ptrs :: proc "contextless" (a, b: ^byte, n: int) -> int {
|
compare_byte_ptrs :: proc "contextless" (a, b: ^byte, n: int) -> int {
|
||||||
pa :: ptr_offset;
|
pa :: ptr_offset;
|
||||||
for i in 0..uintptr(n) do switch {
|
for i in 0..n do switch {
|
||||||
case pa(a, i)^ < pa(b, i)^: return -1;
|
case pa(a, i)^ < pa(b, i)^: return -1;
|
||||||
case pa(a, i)^ > pa(b, i)^: return +1;
|
case pa(a, i)^ > pa(b, i)^: return +1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ptr_offset :: proc "contextless" (ptr: $P/^$T, n: uintptr) -> P {
|
ptr_offset :: proc "contextless" (ptr: $P/^$T, n: int) -> P {
|
||||||
new := uintptr(ptr) + size_of(T)*n;
|
new := int(uintptr(ptr)) + size_of(T)*n;
|
||||||
return P(new);
|
return P(uintptr(new));
|
||||||
}
|
}
|
||||||
|
|
||||||
ptr_sub :: proc "contextless" (a, b: $P/^$T) -> int {
|
ptr_sub :: proc "contextless" (a, b: $P/^$T) -> int {
|
||||||
@@ -143,7 +143,7 @@ allocation_header_fill :: proc(header: ^AllocationHeader, data: rawptr, size: in
|
|||||||
ptr := cast(^uint)(ptr_offset(header, 1));
|
ptr := cast(^uint)(ptr_offset(header, 1));
|
||||||
n := ptr_sub(cast(^uint)data, ptr);
|
n := ptr_sub(cast(^uint)data, ptr);
|
||||||
|
|
||||||
for i in 0..uintptr(n) {
|
for i in 0..n {
|
||||||
ptr_offset(ptr, i)^ = ~uint(0);
|
ptr_offset(ptr, i)^ = ~uint(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -374,7 +374,7 @@ append :: proc(array: ^$T/[dynamic]$E, args: ...E, loc := #caller_location) -> i
|
|||||||
a := (^mem.Raw_Dynamic_Array)(array);
|
a := (^mem.Raw_Dynamic_Array)(array);
|
||||||
data := (^E)(a.data);
|
data := (^E)(a.data);
|
||||||
assert(data != nil);
|
assert(data != nil);
|
||||||
mem.copy(mem.ptr_offset(data, uintptr(a.len)), &args[0], size_of(E) * arg_len);
|
mem.copy(mem.ptr_offset(data, a.len), &args[0], size_of(E) * arg_len);
|
||||||
a.len += arg_len;
|
a.len += arg_len;
|
||||||
}
|
}
|
||||||
return len(array);
|
return len(array);
|
||||||
|
|||||||
@@ -528,8 +528,6 @@ void init_build_context(void) {
|
|||||||
bc->opt_flags = str_lit(" ");
|
bc->opt_flags = str_lit(" ");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
gbString llc_flags = gb_string_make_reserve(heap_allocator(), 64);
|
gbString llc_flags = gb_string_make_reserve(heap_allocator(), 64);
|
||||||
if (bc->ODIN_DEBUG) {
|
if (bc->ODIN_DEBUG) {
|
||||||
llc_flags = gb_string_appendc(llc_flags, "-debug-compile ");
|
llc_flags = gb_string_appendc(llc_flags, "-debug-compile ");
|
||||||
|
|||||||
+1
-1
@@ -137,7 +137,7 @@ bool check_custom_align(CheckerContext *ctx, AstNode *node, i64 *align_) {
|
|||||||
if (is_type_untyped(type) || is_type_integer(type)) {
|
if (is_type_untyped(type) || is_type_integer(type)) {
|
||||||
if (o.value.kind == ExactValue_Integer) {
|
if (o.value.kind == ExactValue_Integer) {
|
||||||
i64 align = o.value.value_integer;
|
i64 align = o.value.value_integer;
|
||||||
if (align < 1 || !gb_is_power_of_two(align)) {
|
if (align < 1 || !gb_is_power_of_two(cast(isize)align)) {
|
||||||
error(node, "#align must be a power of 2, got %lld", align);
|
error(node, "#align must be a power of 2, got %lld", align);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-9
@@ -3332,7 +3332,7 @@ irValue *ir_emit_conv(irProcedure *proc, irValue *value, Type *t) {
|
|||||||
Type *elem = dst->Array.elem;
|
Type *elem = dst->Array.elem;
|
||||||
irValue *e = ir_emit_conv(proc, value, elem);
|
irValue *e = ir_emit_conv(proc, value, elem);
|
||||||
irValue *v = ir_add_local_generated(proc, t);
|
irValue *v = ir_add_local_generated(proc, t);
|
||||||
isize index_count = dst->Array.count;
|
isize index_count = cast(isize)dst->Array.count;
|
||||||
|
|
||||||
for (i32 i = 0; i < index_count; i++) {
|
for (i32 i = 0; i < index_count; i++) {
|
||||||
irValue *elem = ir_emit_array_epi(proc, v, i);
|
irValue *elem = ir_emit_array_epi(proc, v, i);
|
||||||
@@ -5222,13 +5222,13 @@ irValue *ir_build_expr_internal(irProcedure *proc, AstNode *expr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
i64 param_count = 0;
|
isize param_count = 0;
|
||||||
if (pt->params) {
|
if (pt->params) {
|
||||||
GB_ASSERT(pt->params->kind == Type_Tuple);
|
GB_ASSERT(pt->params->kind == Type_Tuple);
|
||||||
param_count = pt->params->Tuple.variables.count;
|
param_count = pt->params->Tuple.variables.count;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto args = array_make<irValue *>(proc->module->allocator, gb_max(param_count, arg_count));
|
auto args = array_make<irValue *>(proc->module->allocator, cast(isize)gb_max(param_count, arg_count));
|
||||||
isize variadic_index = pt->variadic_index;
|
isize variadic_index = pt->variadic_index;
|
||||||
bool variadic = pt->variadic && variadic_index >= 0;
|
bool variadic = pt->variadic && variadic_index >= 0;
|
||||||
bool vari_expand = ce->ellipsis.pos.line != 0;
|
bool vari_expand = ce->ellipsis.pos.line != 0;
|
||||||
@@ -5272,7 +5272,7 @@ irValue *ir_build_expr_internal(irProcedure *proc, AstNode *expr) {
|
|||||||
GB_ASSERT(param_count < 1000000);
|
GB_ASSERT(param_count < 1000000);
|
||||||
|
|
||||||
if (arg_count < param_count) {
|
if (arg_count < param_count) {
|
||||||
isize end = param_count;
|
isize end = cast(isize)param_count;
|
||||||
if (variadic) {
|
if (variadic) {
|
||||||
end = variadic_index;
|
end = variadic_index;
|
||||||
}
|
}
|
||||||
@@ -5328,7 +5328,7 @@ irValue *ir_build_expr_internal(irProcedure *proc, AstNode *expr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (i64 i = 0; i < param_count; i++) {
|
for (isize i = 0; i < param_count; i++) {
|
||||||
Entity *e = param_tuple->variables[i];
|
Entity *e = param_tuple->variables[i];
|
||||||
if (e->kind == Entity_Variable) {
|
if (e->kind == Entity_Variable) {
|
||||||
GB_ASSERT(args[i] != nullptr);
|
GB_ASSERT(args[i] != nullptr);
|
||||||
@@ -5376,7 +5376,7 @@ irValue *ir_build_expr_internal(irProcedure *proc, AstNode *expr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
i64 final_count = param_count;
|
isize final_count = param_count;
|
||||||
if (is_c_vararg) {
|
if (is_c_vararg) {
|
||||||
final_count = arg_count;
|
final_count = arg_count;
|
||||||
}
|
}
|
||||||
@@ -7993,7 +7993,7 @@ void ir_setup_type_info_data(irProcedure *proc) { // NOTE(bill): Setup type_info
|
|||||||
irValue *gep = ir_get_type_info_ptr(proc, t->Array.elem);
|
irValue *gep = ir_get_type_info_ptr(proc, t->Array.elem);
|
||||||
ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 0), gep);
|
ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 0), gep);
|
||||||
|
|
||||||
isize ez = type_size_of(t->Array.elem);
|
i64 ez = type_size_of(t->Array.elem);
|
||||||
irValue *elem_size = ir_emit_struct_ep(proc, tag, 1);
|
irValue *elem_size = ir_emit_struct_ep(proc, tag, 1);
|
||||||
ir_emit_store(proc, elem_size, ir_const_int(a, ez));
|
ir_emit_store(proc, elem_size, ir_const_int(a, ez));
|
||||||
|
|
||||||
@@ -8008,7 +8008,7 @@ void ir_setup_type_info_data(irProcedure *proc) { // NOTE(bill): Setup type_info
|
|||||||
irValue *gep = ir_get_type_info_ptr(proc, t->DynamicArray.elem);
|
irValue *gep = ir_get_type_info_ptr(proc, t->DynamicArray.elem);
|
||||||
ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 0), gep);
|
ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 0), gep);
|
||||||
|
|
||||||
isize ez = type_size_of(t->DynamicArray.elem);
|
i64 ez = type_size_of(t->DynamicArray.elem);
|
||||||
irValue *elem_size = ir_emit_struct_ep(proc, tag, 1);
|
irValue *elem_size = ir_emit_struct_ep(proc, tag, 1);
|
||||||
ir_emit_store(proc, elem_size, ir_const_int(a, ez));
|
ir_emit_store(proc, elem_size, ir_const_int(a, ez));
|
||||||
break;
|
break;
|
||||||
@@ -8019,7 +8019,7 @@ void ir_setup_type_info_data(irProcedure *proc) { // NOTE(bill): Setup type_info
|
|||||||
irValue *gep = ir_get_type_info_ptr(proc, t->Slice.elem);
|
irValue *gep = ir_get_type_info_ptr(proc, t->Slice.elem);
|
||||||
ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 0), gep);
|
ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 0), gep);
|
||||||
|
|
||||||
isize ez = type_size_of(t->Slice.elem);
|
i64 ez = type_size_of(t->Slice.elem);
|
||||||
irValue *elem_size = ir_emit_struct_ep(proc, tag, 1);
|
irValue *elem_size = ir_emit_struct_ep(proc, tag, 1);
|
||||||
ir_emit_store(proc, elem_size, ir_const_int(a, ez));
|
ir_emit_store(proc, elem_size, ir_const_int(a, ez));
|
||||||
break;
|
break;
|
||||||
|
|||||||
+4
-4
@@ -1601,7 +1601,7 @@ Selection lookup_field_from_index(Type *type, i64 index) {
|
|||||||
case Type_BitField: {
|
case Type_BitField: {
|
||||||
auto sel_array = array_make<i32>(a, 1);
|
auto sel_array = array_make<i32>(a, 1);
|
||||||
sel_array[0] = cast(i32)index;
|
sel_array[0] = cast(i32)index;
|
||||||
return make_selection(type->BitField.fields[index], sel_array, false);
|
return make_selection(type->BitField.fields[cast(isize)index], sel_array, false);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2163,7 +2163,7 @@ i64 type_size_of_internal(Type *t, TypePath *path) {
|
|||||||
}
|
}
|
||||||
align = type_align_of_internal(t, path);
|
align = type_align_of_internal(t, path);
|
||||||
type_set_offsets(t);
|
type_set_offsets(t);
|
||||||
size = t->Tuple.offsets[count-1] + type_size_of_internal(t->Tuple.variables[count-1]->type, path);
|
size = t->Tuple.offsets[cast(isize)count-1] + type_size_of_internal(t->Tuple.variables[cast(isize)count-1]->type, path);
|
||||||
return align_formula(size, align);
|
return align_formula(size, align);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
@@ -2233,7 +2233,7 @@ i64 type_size_of_internal(Type *t, TypePath *path) {
|
|||||||
return FAILURE_SIZE;
|
return FAILURE_SIZE;
|
||||||
}
|
}
|
||||||
type_set_offsets(t);
|
type_set_offsets(t);
|
||||||
size = t->Struct.offsets[count-1] + type_size_of_internal(t->Struct.fields[count-1]->type, path);
|
size = t->Struct.offsets[cast(isize)count-1] + type_size_of_internal(t->Struct.fields[cast(isize)count-1]->type, path);
|
||||||
return align_formula(size, align);
|
return align_formula(size, align);
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
@@ -2243,7 +2243,7 @@ i64 type_size_of_internal(Type *t, TypePath *path) {
|
|||||||
i64 end = 0;
|
i64 end = 0;
|
||||||
if (t->BitField.fields.count > 0) {
|
if (t->BitField.fields.count > 0) {
|
||||||
i64 last = t->BitField.fields.count-1;
|
i64 last = t->BitField.fields.count-1;
|
||||||
end = t->BitField.offsets[last] + t->BitField.sizes[last];
|
end = t->BitField.offsets[cast(isize)last] + t->BitField.sizes[cast(isize)last];
|
||||||
}
|
}
|
||||||
i64 bits = align_formula(end, align);
|
i64 bits = align_formula(end, align);
|
||||||
GB_ASSERT((bits%8) == 0);
|
GB_ASSERT((bits%8) == 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user