2019-11-07 06:40:59 -08:00
|
|
|
const std = @import("std");
|
|
|
|
const Target = std.Target;
|
|
|
|
const llvm = @import("llvm.zig");
|
move types from builtin to std
* All the data types from `@import("builtin")` are moved to
`@import("std").builtin`. The target-related types are moved
to `std.Target`. This allows the data types to have methods, such as
`std.Target.current.isDarwin()`.
* `std.os.windows.subsystem` is moved to
`std.Target.current.subsystem`.
* Remove the concept of the panic package from the compiler
implementation. Instead, `std.builtin.panic` is always the panic
function. It checks for `@hasDecl(@import("root"), "panic")`,
or else provides a default implementation.
This is an important step for multibuilds (#3028). Without this change,
the types inside the builtin namespace look like different types, when
trying to merge builds with different target settings. With this change,
Zig can figure out that, e.g., `std.builtin.Os` (the enum type) from one
compilation and `std.builtin.Os` from another compilation are the same
type, even if the target OS value differs.
2019-10-23 15:43:24 -07:00
|
|
|
|
2019-11-26 00:27:51 -08:00
|
|
|
pub fn getDarwinArchString(self: Target) [:0]const u8 {
|
2020-03-17 20:03:45 -07:00
|
|
|
switch (self.cpu.arch) {
|
2019-11-06 14:14:15 -08:00
|
|
|
.aarch64 => return "arm64",
|
|
|
|
.thumb,
|
|
|
|
.arm,
|
|
|
|
=> return "arm",
|
|
|
|
.powerpc => return "ppc",
|
|
|
|
.powerpc64 => return "ppc64",
|
|
|
|
.powerpc64le => return "ppc64le",
|
2019-11-26 00:27:51 -08:00
|
|
|
// @tagName should be able to return sentinel terminated slice
|
2019-11-26 00:34:38 -08:00
|
|
|
else => @panic("TODO https://github.com/ziglang/zig/issues/3779"), //return @tagName(arch),
|
2019-11-06 14:14:15 -08:00
|
|
|
}
|
|
|
|
}
|
2019-11-07 06:40:59 -08:00
|
|
|
|
2020-04-01 09:44:45 -07:00
|
|
|
pub fn llvmTargetFromTriple(triple: [:0]const u8) !*llvm.Target {
|
2019-11-07 06:40:59 -08:00
|
|
|
var result: *llvm.Target = undefined;
|
2019-11-24 18:12:01 -08:00
|
|
|
var err_msg: [*:0]u8 = undefined;
|
2020-04-01 09:44:45 -07:00
|
|
|
if (llvm.GetTargetFromTriple(triple, &result, &err_msg) != 0) {
|
|
|
|
std.debug.warn("triple: {s} error: {s}\n", .{ triple, err_msg });
|
2019-11-07 06:40:59 -08:00
|
|
|
return error.UnsupportedTarget;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn initializeAllTargets() void {
|
|
|
|
llvm.InitializeAllTargets();
|
|
|
|
llvm.InitializeAllTargetInfos();
|
|
|
|
llvm.InitializeAllTargetMCs();
|
|
|
|
llvm.InitializeAllAsmPrinters();
|
|
|
|
llvm.InitializeAllAsmParsers();
|
|
|
|
}
|
2020-03-17 20:03:45 -07:00
|
|
|
|
2020-04-01 09:44:45 -07:00
|
|
|
pub fn getLLVMTriple(allocator: *std.mem.Allocator, target: std.Target) ![:0]u8 {
|
|
|
|
var result = try std.ArrayListSentineled(u8, 0).initSize(allocator, 0);
|
|
|
|
defer result.deinit();
|
2020-03-17 20:03:45 -07:00
|
|
|
|
|
|
|
try result.outStream().print(
|
|
|
|
"{}-unknown-{}-{}",
|
|
|
|
.{ @tagName(target.cpu.arch), @tagName(target.os.tag), @tagName(target.abi) },
|
|
|
|
);
|
|
|
|
|
2020-04-01 09:44:45 -07:00
|
|
|
return result.toOwnedSlice();
|
2020-03-17 20:03:45 -07:00
|
|
|
}
|