aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-01-25 22:01:22 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-01-25 22:04:01 -0700
commitf0ddc7f7a2e2fba2515dfb4f3ad06ea56646eba7 (patch)
tree45f70c9e463de4113c1ac64ba689582736a260b9 /src/main.zig
parent618055db50c5354a17f9eefc2cee77ec2de96f6a (diff)
downloadzig-f0ddc7f7a2e2fba2515dfb4f3ad06ea56646eba7.tar.gz
zig-f0ddc7f7a2e2fba2515dfb4f3ad06ea56646eba7.zip
translate-c: update for new function pointer semantics
After #10656, function pointers are represented with e.g. `*const fn()void` rather than `fn()void`. This commit adds code to translate-c to emit different code depending on whether the output zig source code is intended to be compiled with stage1 or stage2. Ideally we will have stage1 and stage2 support the exact same Zig language, but for now they diverge because I would rather focus on finishing and shipping stage2 than implementing the features in stage1.
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/main.zig b/src/main.zig
index 64a478c813..3f74a64c36 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -2601,7 +2601,8 @@ fn buildOutputType(
return std.io.getStdOut().writeAll(try comp.generateBuiltinZigSource(arena));
}
if (arg_mode == .translate_c) {
- return cmdTranslateC(comp, arena, have_enable_cache);
+ const stage1_mode = use_stage1 orelse build_options.is_stage1;
+ return cmdTranslateC(comp, arena, have_enable_cache, stage1_mode);
}
const hook: AfterUpdateHook = blk: {
@@ -2997,7 +2998,7 @@ fn freePkgTree(gpa: Allocator, pkg: *Package, free_parent: bool) void {
}
}
-fn cmdTranslateC(comp: *Compilation, arena: Allocator, enable_cache: bool) !void {
+fn cmdTranslateC(comp: *Compilation, arena: Allocator, enable_cache: bool, stage1_mode: bool) !void {
if (!build_options.have_llvm)
fatal("cannot translate-c: compiler built without LLVM extensions", .{});
@@ -3010,6 +3011,7 @@ fn cmdTranslateC(comp: *Compilation, arena: Allocator, enable_cache: bool) !void
defer if (enable_cache) man.deinit();
man.hash.add(@as(u16, 0xb945)); // Random number to distinguish translate-c from compiling C objects
+ man.hash.add(stage1_mode);
man.hashCSource(c_source_file) catch |err| {
fatal("unable to process '{s}': {s}", .{ c_source_file.src_path, @errorName(err) });
};
@@ -3061,6 +3063,7 @@ fn cmdTranslateC(comp: *Compilation, arena: Allocator, enable_cache: bool) !void
new_argv.ptr + new_argv.len,
&clang_errors,
c_headers_dir_path_z,
+ stage1_mode,
) catch |err| switch (err) {
error.OutOfMemory => return error.OutOfMemory,
error.ASTUnitFailure => fatal("clang API returned errors but due to a clang bug, it is not exposing the errors for zig to see. For more details: https://github.com/ziglang/zig/issues/4455", .{}),