cbe: implement stdbool.h reserved identifiers
Also remove the legalize pass from zig1.
This commit is contained in:
@@ -164,13 +164,14 @@ pub const Features = std.enums.EnumSet(Feature);
|
||||
pub const Error = std.mem.Allocator.Error;
|
||||
|
||||
pub fn legalize(air: *Air, pt: Zcu.PerThread, features: *const Features) Error!void {
|
||||
dev.check(.legalize);
|
||||
assert(!features.bits.eql(.initEmpty())); // backend asked to run legalize, but no features were enabled
|
||||
var l: Legalize = .{
|
||||
.pt = pt,
|
||||
.air_instructions = air.instructions.toMultiArrayList(),
|
||||
.air_extra = air.extra,
|
||||
.features = features,
|
||||
};
|
||||
if (l.features.bits.eql(.initEmpty())) return;
|
||||
defer air.* = l.getTmpAir();
|
||||
const main_extra = l.extraData(Air.Block, l.air_extra.items[@intFromEnum(Air.ExtraIndex.main_block)]);
|
||||
try l.legalizeBody(main_extra.end, main_extra.data.body_len);
|
||||
@@ -845,6 +846,7 @@ inline fn replaceInst(l: *Legalize, inst: Air.Inst.Index, tag: Air.Inst.Tag, dat
|
||||
|
||||
const Air = @import("../Air.zig");
|
||||
const assert = std.debug.assert;
|
||||
const dev = @import("../dev.zig");
|
||||
const Legalize = @This();
|
||||
const std = @import("std");
|
||||
const Type = @import("../Type.zig");
|
||||
|
||||
@@ -1741,7 +1741,9 @@ pub fn linkerUpdateFunc(pt: Zcu.PerThread, func_index: InternPool.Index, air: *A
|
||||
return;
|
||||
}
|
||||
|
||||
try air.legalize(pt, @import("../codegen.zig").legalizeFeatures(pt, nav_index));
|
||||
legalize: {
|
||||
try air.legalize(pt, @import("../codegen.zig").legalizeFeatures(pt, nav_index) orelse break :legalize);
|
||||
}
|
||||
|
||||
var liveness = try Air.Liveness.analyze(gpa, air.*, ip);
|
||||
defer liveness.deinit(gpa);
|
||||
|
||||
@@ -40,8 +40,8 @@ const gp = abi.RegisterClass.gp;
|
||||
|
||||
const InnerError = CodeGenError || error{OutOfRegisters};
|
||||
|
||||
pub inline fn legalizeFeatures(_: *const std.Target) *const Air.Legalize.Features {
|
||||
return comptime &.initEmpty();
|
||||
pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features {
|
||||
return null;
|
||||
}
|
||||
|
||||
gpa: Allocator,
|
||||
|
||||
@@ -41,8 +41,8 @@ const gp = abi.RegisterClass.gp;
|
||||
|
||||
const InnerError = CodeGenError || error{OutOfRegisters};
|
||||
|
||||
pub inline fn legalizeFeatures(_: *const std.Target) *const Air.Legalize.Features {
|
||||
return comptime &.initEmpty();
|
||||
pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features {
|
||||
return null;
|
||||
}
|
||||
|
||||
gpa: Allocator,
|
||||
|
||||
@@ -10,8 +10,8 @@ const Zcu = @import("../../Zcu.zig");
|
||||
const assert = std.debug.assert;
|
||||
const log = std.log.scoped(.codegen);
|
||||
|
||||
pub inline fn legalizeFeatures(_: *const std.Target) *const Air.Legalize.Features {
|
||||
return comptime &.initEmpty();
|
||||
pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features {
|
||||
return null;
|
||||
}
|
||||
|
||||
pub fn generate(
|
||||
|
||||
@@ -51,8 +51,8 @@ const Instruction = encoding.Instruction;
|
||||
|
||||
const InnerError = CodeGenError || error{OutOfRegisters};
|
||||
|
||||
pub inline fn legalizeFeatures(_: *const std.Target) *const Air.Legalize.Features {
|
||||
return comptime &.initEmpty();
|
||||
pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features {
|
||||
return null;
|
||||
}
|
||||
|
||||
pt: Zcu.PerThread,
|
||||
|
||||
@@ -41,8 +41,8 @@ const Self = @This();
|
||||
|
||||
const InnerError = CodeGenError || error{OutOfRegisters};
|
||||
|
||||
pub inline fn legalizeFeatures(_: *const std.Target) *const Air.Legalize.Features {
|
||||
return comptime &.initEmpty();
|
||||
pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features {
|
||||
return null;
|
||||
}
|
||||
|
||||
const RegisterView = enum(u1) {
|
||||
|
||||
@@ -31,8 +31,8 @@ const libcFloatSuffix = target_util.libcFloatSuffix;
|
||||
const compilerRtFloatAbbrev = target_util.compilerRtFloatAbbrev;
|
||||
const compilerRtIntAbbrev = target_util.compilerRtIntAbbrev;
|
||||
|
||||
pub inline fn legalizeFeatures(_: *const std.Target) *const Air.Legalize.Features {
|
||||
return comptime &.initEmpty();
|
||||
pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features {
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Reference to the function declaration the code
|
||||
|
||||
@@ -27,9 +27,22 @@ pub const CodeGenError = GenerateSymbolError || error{
|
||||
CodegenFail,
|
||||
};
|
||||
|
||||
fn devFeatureForBackend(comptime backend: std.builtin.CompilerBackend) dev.Feature {
|
||||
comptime assert(mem.startsWith(u8, @tagName(backend), "stage2_"));
|
||||
return @field(dev.Feature, @tagName(backend)["stage2_".len..] ++ "_backend");
|
||||
fn devFeatureForBackend(backend: std.builtin.CompilerBackend) dev.Feature {
|
||||
return switch (backend) {
|
||||
.other, .stage1 => unreachable,
|
||||
.stage2_aarch64 => .aarch64_backend,
|
||||
.stage2_arm => .arm_backend,
|
||||
.stage2_c => .c_backend,
|
||||
.stage2_llvm => .llvm_backend,
|
||||
.stage2_powerpc => .powerpc_backend,
|
||||
.stage2_riscv64 => .riscv64_backend,
|
||||
.stage2_sparc64 => .sparc64_backend,
|
||||
.stage2_spirv64 => .spirv64_backend,
|
||||
.stage2_wasm => .wasm_backend,
|
||||
.stage2_x86 => .x86_backend,
|
||||
.stage2_x86_64 => .x86_64_backend,
|
||||
_ => unreachable,
|
||||
};
|
||||
}
|
||||
|
||||
fn importBackend(comptime backend: std.builtin.CompilerBackend) type {
|
||||
@@ -49,10 +62,10 @@ fn importBackend(comptime backend: std.builtin.CompilerBackend) type {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn legalizeFeatures(pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) *const Air.Legalize.Features {
|
||||
pub fn legalizeFeatures(pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) ?*const Air.Legalize.Features {
|
||||
const zcu = pt.zcu;
|
||||
const target = &zcu.navFileScope(nav_index).mod.?.resolved_target.result;
|
||||
return switch (target_util.zigBackend(target.*, zcu.comp.config.use_llvm)) {
|
||||
switch (target_util.zigBackend(target.*, zcu.comp.config.use_llvm)) {
|
||||
else => unreachable,
|
||||
inline .stage2_llvm,
|
||||
.stage2_c,
|
||||
@@ -65,8 +78,11 @@ pub fn legalizeFeatures(pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) *con
|
||||
.stage2_sparc64,
|
||||
.stage2_spirv64,
|
||||
.stage2_powerpc,
|
||||
=> |backend| importBackend(backend).legalizeFeatures(target),
|
||||
};
|
||||
=> |backend| {
|
||||
dev.check(devFeatureForBackend(backend));
|
||||
return importBackend(backend).legalizeFeatures(target);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generateFunction(
|
||||
|
||||
@@ -20,8 +20,8 @@ const Alignment = InternPool.Alignment;
|
||||
const BigIntLimb = std.math.big.Limb;
|
||||
const BigInt = std.math.big.int;
|
||||
|
||||
pub inline fn legalizeFeatures(_: *const std.Target) *const Air.Legalize.Features {
|
||||
return comptime &.initEmpty();
|
||||
pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features {
|
||||
return null;
|
||||
}
|
||||
|
||||
pub const CType = @import("c/Type.zig");
|
||||
@@ -210,7 +210,6 @@ const reserved_idents = std.StaticStringMap(void).initComptime(.{
|
||||
.{ "atomic_ushort", {} },
|
||||
.{ "atomic_wchar_t", {} },
|
||||
.{ "auto", {} },
|
||||
.{ "bool", {} },
|
||||
.{ "break", {} },
|
||||
.{ "case", {} },
|
||||
.{ "char", {} },
|
||||
@@ -270,6 +269,11 @@ const reserved_idents = std.StaticStringMap(void).initComptime(.{
|
||||
.{ "va_end", {} },
|
||||
.{ "va_copy", {} },
|
||||
|
||||
// stdbool.h
|
||||
.{ "bool", {} },
|
||||
.{ "false", {} },
|
||||
.{ "true", {} },
|
||||
|
||||
// stddef.h
|
||||
.{ "offsetof", {} },
|
||||
|
||||
|
||||
@@ -36,8 +36,8 @@ const compilerRtIntAbbrev = target_util.compilerRtIntAbbrev;
|
||||
|
||||
const Error = error{ OutOfMemory, CodegenFail };
|
||||
|
||||
pub inline fn legalizeFeatures(_: *const std.Target) *const Air.Legalize.Features {
|
||||
return comptime &.initEmpty();
|
||||
pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features {
|
||||
return null;
|
||||
}
|
||||
|
||||
fn subArchName(features: std.Target.Cpu.Feature.Set, arch: anytype, mappings: anytype) ?[]const u8 {
|
||||
|
||||
@@ -28,8 +28,8 @@ const SpvAssembler = @import("spirv/Assembler.zig");
|
||||
|
||||
const InstMap = std.AutoHashMapUnmanaged(Air.Inst.Index, IdRef);
|
||||
|
||||
pub inline fn legalizeFeatures(_: *const std.Target) *const Air.Legalize.Features {
|
||||
return comptime &.initEmpty();
|
||||
pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features {
|
||||
return null;
|
||||
}
|
||||
|
||||
pub const zig_call_abi_ver = 3;
|
||||
|
||||
@@ -67,6 +67,7 @@ pub const Env = enum {
|
||||
.incremental,
|
||||
.ast_gen,
|
||||
.sema,
|
||||
.legalize,
|
||||
.llvm_backend,
|
||||
.c_backend,
|
||||
.wasm_backend,
|
||||
@@ -144,6 +145,7 @@ pub const Env = enum {
|
||||
.build_command,
|
||||
.stdio_listen,
|
||||
.incremental,
|
||||
.legalize,
|
||||
.x86_64_backend,
|
||||
.elf_linker,
|
||||
=> true,
|
||||
@@ -222,6 +224,7 @@ pub const Feature = enum {
|
||||
incremental,
|
||||
ast_gen,
|
||||
sema,
|
||||
legalize,
|
||||
|
||||
llvm_backend,
|
||||
c_backend,
|
||||
|
||||
Reference in New Issue
Block a user