Skip to content

Commit

Permalink
Merge pull request #709 from ehaas/zig-updates
Browse files Browse the repository at this point in the history
Zig updates
  • Loading branch information
Vexu authored May 19, 2024
2 parents e8f011e + d94d24a commit d8b689d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 18 deletions.
24 changes: 12 additions & 12 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn addFuzzStep(b: *Build, target: std.Build.ResolvedTarget, afl_clang_lto_path:
const fuzz_step = b.step("fuzz", "Build executable for fuzz testing.");
const fuzz_lib = b.addStaticLibrary(.{
.name = "fuzz-lib",
.root_source_file = .{ .path = "test/fuzz/fuzz_lib.zig" },
.root_source_file = b.path("test/fuzz/fuzz_lib.zig"),
.optimize = .Debug,
.target = target,
.single_threaded = true,
Expand All @@ -23,7 +23,7 @@ fn addFuzzStep(b: *Build, target: std.Build.ResolvedTarget, afl_clang_lto_path:

fuzz_lib.root_module.addImport("aro", aro_module);
const fuzz_compile = b.addSystemCommand(&.{afl_clang_lto_path});
fuzz_compile.addFileArg(.{ .path = "test/fuzz/main.c" });
fuzz_compile.addFileArg(b.path("test/fuzz/main.c"));
fuzz_compile.addArg("-o");
const fuzz_exe = fuzz_compile.addOutputFileArg("arofuzz");
const fuzz_install = b.addInstallBinFile(fuzz_exe, "arofuzz");
Expand Down Expand Up @@ -122,10 +122,10 @@ pub fn build(b: *Build) !void {
const aro_options_module = aro_options.createModule();

const zig_module = b.createModule(.{
.root_source_file = .{ .path = "deps/zig/lib.zig" },
.root_source_file = b.path("deps/zig/lib.zig"),
});
const aro_backend = b.addModule("aro_backend", .{
.root_source_file = .{ .path = "src/backend.zig" },
.root_source_file = b.path("src/backend.zig"),
.imports = &.{
.{
.name = "zig",
Expand All @@ -138,7 +138,7 @@ pub fn build(b: *Build) !void {
},
});
const aro_module = b.addModule("aro", .{
.root_source_file = .{ .path = "src/aro.zig" },
.root_source_file = b.path("src/aro.zig"),
.imports = &.{
.{
.name = "system_defaults",
Expand All @@ -159,14 +159,14 @@ pub fn build(b: *Build) !void {
});

b.installDirectory(.{
.source_dir = .{ .path = "include" },
.source_dir = b.path("include"),
.install_dir = .prefix,
.install_subdir = "include",
});

const exe = b.addExecutable(.{
.name = "arocc",
.root_source_file = .{ .path = "src/main.zig" },
.root_source_file = b.path("src/main.zig"),
.optimize = mode,
.target = target,
.single_threaded = true,
Expand All @@ -186,8 +186,8 @@ pub fn build(b: *Build) !void {
else
&[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" };

exe.addIncludePath(.{ .path = tracy_path });
exe.addCSourceFile(.{ .file = .{ .path = client_cpp }, .flags = tracy_c_flags });
exe.addIncludePath(b.path(tracy_path));
exe.addCSourceFile(.{ .file = b.path(client_cpp), .flags = tracy_c_flags });
exe.linkLibCpp();
exe.linkLibC();

Expand All @@ -203,7 +203,7 @@ pub fn build(b: *Build) !void {

const tests_step = b.step("test", "Run all tests");

var unit_tests = b.addTest(.{ .root_source_file = .{ .path = "src/aro.zig" } });
var unit_tests = b.addTest(.{ .root_source_file = b.path("src/aro.zig") });
for (aro_module.import_table.keys(), aro_module.import_table.values()) |name, module| {
unit_tests.root_module.addImport(name, module);
}
Expand All @@ -212,7 +212,7 @@ pub fn build(b: *Build) !void {

const integration_tests = b.addExecutable(.{
.name = "test-runner",
.root_source_file = .{ .path = "test/runner.zig" },
.root_source_file = b.path("test/runner.zig"),
.optimize = mode,
.target = target,
});
Expand All @@ -227,7 +227,7 @@ pub fn build(b: *Build) !void {

const record_tests = b.addExecutable(.{
.name = "record-runner",
.root_source_file = .{ .path = "test/record_runner.zig" },
.root_source_file = b.path("test/record_runner.zig"),
.optimize = mode,
.target = target,
});
Expand Down
2 changes: 1 addition & 1 deletion build/GenerateDef.zig
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn create(owner: *std.Build, options: Options) std.Build.Module.Import {
.generated_file = .{ .step = &self.step },
};
const module = self.step.owner.createModule(.{
.root_source_file = .{ .generated = &self.generated_file },
.root_source_file = .{ .generated = .{ .file = &self.generated_file } },
});
return .{
.module = module,
Expand Down
2 changes: 1 addition & 1 deletion src/aro/Compilation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ pub fn float80Type(comp: *const Compilation) ?Type {
}

/// Smallest integer type with at least N bits
fn intLeastN(comp: *const Compilation, bits: usize, signedness: std.builtin.Signedness) Type {
pub fn intLeastN(comp: *const Compilation, bits: usize, signedness: std.builtin.Signedness) Type {
if (bits == 64 and (comp.target.isDarwin() or comp.target.isWasm())) {
// WebAssembly and Darwin use `long long` for `int_least64_t` and `int_fast64_t`.
return .{ .specifier = if (signedness == .signed) .long_long else .ulong_long };
Expand Down
13 changes: 9 additions & 4 deletions src/aro/Type.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1109,10 +1109,15 @@ pub fn alignof(ty: Type, comp: *const Compilation) u29 {
.long_long => comp.target.c_type_alignment(.longlong),
.ulong_long => comp.target.c_type_alignment(.ulonglong),

.bit_int => @min(
std.math.ceilPowerOfTwoPromote(u16, (ty.data.int.bits +| 7) / 8),
comp.target.maxIntAlignment(),
),
.bit_int => {
// https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2709.pdf
// _BitInt(N) types align with existing calling conventions. They have the same size and alignment as the
// smallest basic type that can contain them. Types that are larger than __int64_t are conceptually treated
// as struct of register size chunks. The number of chunks is the smallest number that can contain the type.
if (ty.data.int.bits > 64) return 8;
const basic_type = comp.intLeastN(ty.data.int.bits, ty.data.int.signedness);
return basic_type.alignof(comp);
},

.float => comp.target.c_type_alignment(.float),
.double => comp.target.c_type_alignment(.double),
Expand Down
5 changes: 5 additions & 0 deletions src/aro/target.zig
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ pub fn get32BitArchVariant(target: std.Target) ?std.Target {
.wasm32,
.renderscript32,
.aarch64_32,
.spirv,
.spirv32,
.loongarch32,
.dxil,
Expand Down Expand Up @@ -591,6 +592,7 @@ pub fn get64BitArchVariant(target: std.Target) ?std.Target {
.riscv32 => copy.cpu.arch = .riscv64,
.sparc => copy.cpu.arch = .sparc64,
.spir => copy.cpu.arch = .spir64,
.spirv => copy.cpu.arch = .spirv64,
.spirv32 => copy.cpu.arch = .spirv64,
.thumb => copy.cpu.arch = .aarch64,
.thumbeb => copy.cpu.arch = .aarch64_be,
Expand Down Expand Up @@ -659,6 +661,7 @@ pub fn toLLVMTriple(target: std.Target, buf: []u8) []const u8 {
.hsail64 => "hsail64",
.spir => "spir",
.spir64 => "spir64",
.spirv => "spirv",
.spirv32 => "spirv32",
.spirv64 => "spirv64",
.kalimba => "kalimba",
Expand Down Expand Up @@ -717,6 +720,8 @@ pub fn toLLVMTriple(target: std.Target, buf: []u8) []const u8 {
.driverkit => "driverkit",
.shadermodel => "shadermodel",
.liteos => "liteos",
.visionos => "xros",
.serenity => "serenity",
.opencl,
.glsl450,
.vulkan,
Expand Down

0 comments on commit d8b689d

Please sign in to comment.