This commit makes it possible to obtain pointers to `extern` variables at comptime. - `ir_get_var_ptr` employs several checks to determine if the given variable is eligible for obtaining its pointer at comptime. This commit alters these checks to consider `extern` variables, which have runtime values, as eligible. - After this change, it's now possible for `render_const_val` to be called for `extern` variables. This commit modifies `render_const_val` to suppress the value generation for `extern` variables. - `do_code_gen` now creates `ZigValue::llvm_global` of `extern` variables before iterating through module-level variables so that other module-level variables can refer to them. This solution is incomplete since there are several cases still failing: - `global_var.array[n..m]` - `&global_var.array[i]` - `&global_var.inner_struct.value` - `&global_array[i]` Closes #5349
28 lines
727 B
Zig
28 lines
727 B
Zig
export var global_var: usize = 2;
|
|
export const global_const: usize = 422;
|
|
|
|
const TheStruct = @import("./types.zig").TheStruct;
|
|
export var global_var_struct = TheStruct{
|
|
.value = 2,
|
|
.array = [_]u32{ 1, 2, 3, 4 },
|
|
.p_value = &@as(u32, 3),
|
|
.inner = .{ .value = 4 },
|
|
};
|
|
export const global_const_struct = TheStruct{
|
|
.value = 422,
|
|
.array = [_]u32{ 5, 6, 7, 8 },
|
|
.p_value = &@as(u32, 423),
|
|
.inner = .{ .value = 424 },
|
|
};
|
|
|
|
const TheUnion = @import("./types.zig").TheUnion;
|
|
export var global_var_union = TheUnion{
|
|
.U32 = 10,
|
|
};
|
|
export const global_const_union = TheUnion{
|
|
.U32 = 20,
|
|
};
|
|
|
|
export var global_var_array = [4]u32{ 1, 2, 3, 4 };
|
|
export const global_const_array = [4]u32{ 5, 6, 7, 8 };
|