Darwin -> MacOSX, added Zen. See #438

This commit is contained in:
Andrea Orru 2018-01-06 23:10:53 -05:00
parent dde7cc52d2
commit e932919e68
15 changed files with 341 additions and 132 deletions

View File

@ -38,7 +38,7 @@ pub const Target = union(enum) {
pub fn isDarwin(self: &const Target) -> bool {
return switch (self.getOs()) {
builtin.Os.darwin, builtin.Os.ios, builtin.Os.macosx => true,
builtin.Os.ios, builtin.Os.macosx => true,
else => false,
};
}

View File

@ -32,7 +32,7 @@ ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg) {
// failed semantic analysis, which isn't supposed to happen
ErrorMsg *err = add_node_error(g, node->owner->c_import_node,
buf_sprintf("compiler bug: @cImport generated invalid zig code"));
add_error_note(g, err, node, msg);
g->errors.append(err);
@ -2425,7 +2425,7 @@ static void resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {
qual_str = "extern";
break;
}
AstNode *source_node = (decl_node->data.container_decl.init_arg_expr != nullptr) ?
AstNode *source_node = (decl_node->data.container_decl.init_arg_expr != nullptr) ?
decl_node->data.container_decl.init_arg_expr : decl_node;
add_node_error(g, source_node,
buf_sprintf("%s union does not support enum tag type", qual_str));
@ -2599,17 +2599,17 @@ void add_fn_export(CodeGen *g, FnTableEntry *fn_table_entry, Buf *symbol_name, G
g->windows_subsystem_windows = false;
g->windows_subsystem_console = true;
} else if (buf_eql_str(symbol_name, "WinMain") &&
g->zig_target.os == ZigLLVM_Win32)
g->zig_target.os == OsWindows)
{
g->have_winmain = true;
g->windows_subsystem_windows = true;
g->windows_subsystem_console = false;
} else if (buf_eql_str(symbol_name, "WinMainCRTStartup") &&
g->zig_target.os == ZigLLVM_Win32)
g->zig_target.os == OsWindows)
{
g->have_winmain_crt_startup = true;
} else if (buf_eql_str(symbol_name, "DllMainCRTStartup") &&
g->zig_target.os == ZigLLVM_Win32)
g->zig_target.os == OsWindows)
{
g->have_dllmain_crt_startup = true;
}
@ -3994,7 +3994,7 @@ void find_libc_include_path(CodeGen *g) {
if (!g->libc_include_dir || buf_len(g->libc_include_dir) == 0) {
ZigWindowsSDK *sdk = get_windows_sdk(g);
if (g->zig_target.os == ZigLLVM_Win32) {
if (g->zig_target.os == OsWindows) {
if (os_get_win32_ucrt_include_path(sdk, g->libc_include_dir)) {
zig_panic("Unable to determine libc include path.");
}
@ -4010,9 +4010,9 @@ void find_libc_include_path(CodeGen *g) {
void find_libc_lib_path(CodeGen *g) {
// later we can handle this better by reporting an error via the normal mechanism
if (!g->libc_lib_dir || buf_len(g->libc_lib_dir) == 0 ||
(g->zig_target.os == ZigLLVM_Win32 && (g->msvc_lib_dir == nullptr || g->kernel32_lib_dir == nullptr)))
(g->zig_target.os == OsWindows && (g->msvc_lib_dir == nullptr || g->kernel32_lib_dir == nullptr)))
{
if (g->zig_target.os == ZigLLVM_Win32) {
if (g->zig_target.os == OsWindows) {
ZigWindowsSDK *sdk = get_windows_sdk(g);
Buf* vc_lib_dir = buf_alloc();
@ -4039,7 +4039,7 @@ void find_libc_lib_path(CodeGen *g) {
}
if (!g->libc_static_lib_dir || buf_len(g->libc_static_lib_dir) == 0) {
if ((g->zig_target.os == ZigLLVM_Win32) && (g->msvc_lib_dir != NULL)) {
if ((g->zig_target.os == OsWindows) && (g->msvc_lib_dir != NULL)) {
return;
}
else {

View File

@ -42,7 +42,7 @@ static void init_darwin_native(CodeGen *g) {
g->mmacosx_version_min = buf_create_from_str(osx_target);
} else if (ios_target) {
g->mios_version_min = buf_create_from_str(ios_target);
} else if (g->zig_target.os != ZigLLVM_IOS) {
} else if (g->zig_target.os != OsIOS) {
g->mmacosx_version_min = buf_create_from_str("10.10");
}
}
@ -136,9 +136,8 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out
g->each_lib_rpath = true;
#endif
if (g->zig_target.os == ZigLLVM_Darwin ||
g->zig_target.os == ZigLLVM_MacOSX ||
g->zig_target.os == ZigLLVM_IOS)
if (g->zig_target.os == OsMacOSX ||
g->zig_target.os == OsIOS)
{
init_darwin_native(g);
}
@ -146,9 +145,8 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out
}
// On Darwin/MacOS/iOS, we always link libSystem which contains libc.
if (g->zig_target.os == ZigLLVM_Darwin ||
g->zig_target.os == ZigLLVM_MacOSX ||
g->zig_target.os == ZigLLVM_IOS)
if (g->zig_target.os == OsMacOSX ||
g->zig_target.os == OsIOS)
{
g->libc_link_lib = create_link_lib(buf_create_from_str("c"));
g->link_libs_list.append(g->libc_link_lib);
@ -363,7 +361,7 @@ static LLVMCallConv get_llvm_cc(CodeGen *g, CallingConvention cc) {
g->zig_target.arch.arch == ZigLLVM_x86_64)
{
// cold calling convention is not supported on windows
if (g->zig_target.os == ZigLLVM_Win32) {
if (g->zig_target.os == OsWindows) {
return LLVMCCallConv;
} else {
return LLVMColdCallConv;
@ -386,7 +384,7 @@ static LLVMCallConv get_llvm_cc(CodeGen *g, CallingConvention cc) {
}
static void add_uwtable_attr(CodeGen *g, LLVMValueRef fn_val) {
if (g->zig_target.os == ZigLLVM_Win32) {
if (g->zig_target.os == OsWindows) {
addLLVMFnAttr(fn_val, "uwtable");
}
}
@ -559,7 +557,7 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {
}
// Note: byval is disabled on windows due to an LLVM bug:
// https://github.com/zig-lang/zig/issues/536
if (is_byval && g->zig_target.os != ZigLLVM_Win32) {
if (is_byval && g->zig_target.os != OsWindows) {
addLLVMArgAttr(fn_table_entry->llvm_value, (unsigned)gen_index, "byval");
}
}
@ -2371,7 +2369,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
FnGenParamInfo *gen_info = &fn_type->data.fn.gen_param_info[param_i];
// Note: byval is disabled on windows due to an LLVM bug:
// https://github.com/zig-lang/zig/issues/536
if (gen_info->is_byval && g->zig_target.os != ZigLLVM_Win32) {
if (gen_info->is_byval && g->zig_target.os != OsWindows) {
addLLVMCallsiteAttr(result, (unsigned)gen_info->gen_index, "byval");
}
}
@ -5094,7 +5092,7 @@ static void define_builtin_compile_vars(CodeGen *g) {
buf_appendf(contents, "pub const Os = enum {\n");
uint32_t field_count = (uint32_t)target_os_count();
for (uint32_t i = 0; i < field_count; i += 1) {
ZigLLVM_OSType os_type = get_target_os(i);
Os os_type = get_target_os(i);
const char *name = get_target_os_name(os_type);
buf_appendf(contents, " %s,\n", name);
@ -5304,7 +5302,7 @@ static void init(CodeGen *g) {
// LLVM creates invalid binaries on Windows sometimes.
// See https://github.com/zig-lang/zig/issues/508
// As a workaround we do not use target native features on Windows.
if (g->zig_target.os == ZigLLVM_Win32) {
if (g->zig_target.os == OsWindows) {
target_specific_cpu_args = "";
target_specific_features = "";
} else {
@ -5524,13 +5522,13 @@ static void gen_root_source(CodeGen *g) {
}
report_errors_and_maybe_exit(g);
if (!g->is_test_build && g->zig_target.os != ZigLLVM_UnknownOS &&
if (!g->is_test_build && g->zig_target.os != OsFreestanding &&
!g->have_c_main && !g->have_winmain && !g->have_winmain_crt_startup &&
((g->have_pub_main && g->out_type == OutTypeObj) || g->out_type == OutTypeExe))
{
g->bootstrap_import = add_special_code(g, create_bootstrap_pkg(g, g->root_package), "bootstrap.zig");
}
if (g->zig_target.os == ZigLLVM_Win32 && !g->have_dllmain_crt_startup && g->out_type == OutTypeLib) {
if (g->zig_target.os == OsWindows && !g->have_dllmain_crt_startup && g->out_type == OutTypeLib) {
g->bootstrap_import = add_special_code(g, create_bootstrap_pkg(g, g->root_package), "bootstrap_lib.zig");
}

View File

@ -644,7 +644,7 @@ static void get_darwin_platform(LinkJob *lj, DarwinPlatform *platform) {
platform->kind = MacOS;
} else if (g->mios_version_min) {
platform->kind = IPhoneOS;
} else if (g->zig_target.os == ZigLLVM_MacOSX || g->zig_target.os == ZigLLVM_Darwin) {
} else if (g->zig_target.os == OsMacOSX) {
platform->kind = MacOS;
g->mmacosx_version_min = buf_create_from_str("10.10");
} else {

View File

@ -120,7 +120,7 @@ static int print_target_list(FILE *f) {
fprintf(f, "\nOperating Systems:\n");
size_t os_count = target_os_count();
for (size_t i = 0; i < os_count; i += 1) {
ZigLLVM_OSType os_type = get_target_os(i);
Os os_type = get_target_os(i);
const char *native_str = (native.os == os_type) ? " (native)" : "";
fprintf(f, " %s%s\n", get_target_os_name(os_type), native_str);
}

View File

@ -105,39 +105,39 @@ static const ZigLLVM_VendorType vendor_list[] = {
ZigLLVM_SUSE,
};
static const ZigLLVM_OSType os_list[] = {
ZigLLVM_UnknownOS,
ZigLLVM_Ananas,
ZigLLVM_CloudABI,
ZigLLVM_Darwin,
ZigLLVM_DragonFly,
ZigLLVM_FreeBSD,
ZigLLVM_Fuchsia,
ZigLLVM_IOS,
ZigLLVM_KFreeBSD,
ZigLLVM_Linux,
ZigLLVM_Lv2,
ZigLLVM_MacOSX,
ZigLLVM_NetBSD,
ZigLLVM_OpenBSD,
ZigLLVM_Solaris,
ZigLLVM_Win32,
ZigLLVM_Haiku,
ZigLLVM_Minix,
ZigLLVM_RTEMS,
ZigLLVM_NaCl,
ZigLLVM_CNK,
ZigLLVM_Bitrig,
ZigLLVM_AIX,
ZigLLVM_CUDA,
ZigLLVM_NVCL,
ZigLLVM_AMDHSA,
ZigLLVM_PS4,
ZigLLVM_ELFIAMCU,
ZigLLVM_TvOS,
ZigLLVM_WatchOS,
ZigLLVM_Mesa3D,
ZigLLVM_Contiki,
static const Os os_list[] = {
OsFreestanding,
OsAnanas,
OsCloudABI,
OsDragonFly,
OsFreeBSD,
OsFuchsia,
OsIOS,
OsKFreeBSD,
OsLinux,
OsLv2, // PS3
OsMacOSX,
OsNetBSD,
OsOpenBSD,
OsSolaris,
OsWindows,
OsHaiku,
OsMinix,
OsRTEMS,
OsNaCl, // Native Client
OsCNK, // BG/P Compute-Node Kernel
OsBitrig,
OsAIX,
OsCUDA, // NVIDIA CUDA
OsNVCL, // NVIDIA OpenCL
OsAMDHSA, // AMD HSA Runtime
OsPS4,
OsELFIAMCU,
OsTvOS, // Apple tvOS
OsWatchOS, // Apple watchOS
OsMesa3D,
OsContiki,
OsZen,
};
static const ZigLLVM_EnvironmentType environ_list[] = {
@ -209,12 +209,187 @@ ZigLLVM_VendorType get_target_vendor(size_t index) {
size_t target_os_count(void) {
return array_length(os_list);
}
ZigLLVM_OSType get_target_os(size_t index) {
Os get_target_os(size_t index) {
return os_list[index];
}
const char *get_target_os_name(ZigLLVM_OSType os_type) {
return (os_type == ZigLLVM_UnknownOS) ? "freestanding" : ZigLLVMGetOSTypeName(os_type);
static ZigLLVM_OSType get_llvm_os_type(Os os_type) {
switch (os_type) {
case OsFreestanding:
case OsZen:
return ZigLLVM_UnknownOS;
case OsAnanas:
return ZigLLVM_Ananas;
case OsCloudABI:
return ZigLLVM_CloudABI;
case OsDragonFly:
return ZigLLVM_DragonFly;
case OsFreeBSD:
return ZigLLVM_FreeBSD;
case OsFuchsia:
return ZigLLVM_Fuchsia;
case OsIOS:
return ZigLLVM_IOS;
case OsKFreeBSD:
return ZigLLVM_KFreeBSD;
case OsLinux:
return ZigLLVM_Linux;
case OsLv2:
return ZigLLVM_Lv2;
case OsMacOSX:
return ZigLLVM_MacOSX;
case OsNetBSD:
return ZigLLVM_NetBSD;
case OsOpenBSD:
return ZigLLVM_OpenBSD;
case OsSolaris:
return ZigLLVM_Solaris;
case OsWindows:
return ZigLLVM_Win32;
case OsHaiku:
return ZigLLVM_Haiku;
case OsMinix:
return ZigLLVM_Minix;
case OsRTEMS:
return ZigLLVM_RTEMS;
case OsNaCl:
return ZigLLVM_NaCl;
case OsCNK:
return ZigLLVM_CNK;
case OsBitrig:
return ZigLLVM_Bitrig;
case OsAIX:
return ZigLLVM_AIX;
case OsCUDA:
return ZigLLVM_CUDA;
case OsNVCL:
return ZigLLVM_NVCL;
case OsAMDHSA:
return ZigLLVM_AMDHSA;
case OsPS4:
return ZigLLVM_PS4;
case OsELFIAMCU:
return ZigLLVM_ELFIAMCU;
case OsTvOS:
return ZigLLVM_TvOS;
case OsWatchOS:
return ZigLLVM_WatchOS;
case OsMesa3D:
return ZigLLVM_Mesa3D;
case OsContiki:
return ZigLLVM_Contiki;
}
zig_unreachable();
}
static Os get_zig_os_type(ZigLLVM_OSType os_type) {
switch (os_type) {
case ZigLLVM_UnknownOS:
return OsFreestanding;
case ZigLLVM_Ananas:
return OsAnanas;
case ZigLLVM_CloudABI:
return OsCloudABI;
case ZigLLVM_DragonFly:
return OsDragonFly;
case ZigLLVM_FreeBSD:
return OsFreeBSD;
case ZigLLVM_Fuchsia:
return OsFuchsia;
case ZigLLVM_IOS:
return OsIOS;
case ZigLLVM_KFreeBSD:
return OsKFreeBSD;
case ZigLLVM_Linux:
return OsLinux;
case ZigLLVM_Lv2:
return OsLv2;
case ZigLLVM_Darwin:
case ZigLLVM_MacOSX:
return OsMacOSX;
case ZigLLVM_NetBSD:
return OsNetBSD;
case ZigLLVM_OpenBSD:
return OsOpenBSD;
case ZigLLVM_Solaris:
return OsSolaris;
case ZigLLVM_Win32:
return OsWindows;
case ZigLLVM_Haiku:
return OsHaiku;
case ZigLLVM_Minix:
return OsMinix;
case ZigLLVM_RTEMS:
return OsRTEMS;
case ZigLLVM_NaCl:
return OsNaCl;
case ZigLLVM_CNK:
return OsCNK;
case ZigLLVM_Bitrig:
return OsBitrig;
case ZigLLVM_AIX:
return OsAIX;
case ZigLLVM_CUDA:
return OsCUDA;
case ZigLLVM_NVCL:
return OsNVCL;
case ZigLLVM_AMDHSA:
return OsAMDHSA;
case ZigLLVM_PS4:
return OsPS4;
case ZigLLVM_ELFIAMCU:
return OsELFIAMCU;
case ZigLLVM_TvOS:
return OsTvOS;
case ZigLLVM_WatchOS:
return OsWatchOS;
case ZigLLVM_Mesa3D:
return OsMesa3D;
case ZigLLVM_Contiki:
return OsContiki;
}
zig_unreachable();
}
const char *get_target_os_name(Os os_type) {
switch (os_type) {
case OsFreestanding:
return "freestanding";
case OsZen:
return "zen";
case OsAnanas:
case OsCloudABI:
case OsDragonFly:
case OsFreeBSD:
case OsFuchsia:
case OsIOS:
case OsKFreeBSD:
case OsLinux:
case OsLv2: // PS3
case OsMacOSX:
case OsNetBSD:
case OsOpenBSD:
case OsSolaris:
case OsWindows:
case OsHaiku:
case OsMinix:
case OsRTEMS:
case OsNaCl: // Native Client
case OsCNK: // BG/P Compute-Node Kernel
case OsBitrig:
case OsAIX:
case OsCUDA: // NVIDIA CUDA
case OsNVCL: // NVIDIA OpenCL
case OsAMDHSA: // AMD HSA Runtime
case OsPS4:
case OsELFIAMCU:
case OsTvOS: // Apple tvOS
case OsWatchOS: // Apple watchOS
case OsMesa3D:
case OsContiki:
return ZigLLVMGetOSTypeName(get_llvm_os_type(os_type));
}
zig_unreachable();
}
size_t target_environ_count(void) {
@ -225,20 +400,22 @@ ZigLLVM_EnvironmentType get_target_environ(size_t index) {
}
void get_native_target(ZigTarget *target) {
ZigLLVM_OSType os_type;
ZigLLVMGetNativeTarget(
&target->arch.arch,
&target->arch.sub_arch,
&target->vendor,
&target->os,
&os_type,
&target->env_type,
&target->oformat);
target->os = get_zig_os_type(os_type);
}
void get_unknown_target(ZigTarget *target) {
target->arch.arch = ZigLLVM_UnknownArch;
target->arch.sub_arch = ZigLLVM_NoSubArch;
target->vendor = ZigLLVM_UnknownVendor;
target->os = ZigLLVM_UnknownOS;
target->os = OsFreestanding;
target->env_type = ZigLLVM_UnknownEnvironment;
target->oformat = ZigLLVM_UnknownObjectFormat;
}
@ -265,9 +442,9 @@ int parse_target_arch(const char *str, ArchType *out_arch) {
return ErrorFileNotFound;
}
int parse_target_os(const char *str, ZigLLVM_OSType *out_os) {
int parse_target_os(const char *str, Os *out_os) {
for (size_t i = 0; i < array_length(os_list); i += 1) {
ZigLLVM_OSType os = os_list[i];
Os os = os_list[i];
const char *os_name = get_target_os_name(os);
if (strcmp(os_name, str) == 0) {
*out_os = os;
@ -304,15 +481,14 @@ void get_target_triple(Buf *triple, const ZigTarget *target) {
buf_resize(triple, 0);
buf_appendf(triple, "%s-%s-%s-%s", arch_name,
ZigLLVMGetVendorTypeName(target->vendor),
ZigLLVMGetOSTypeName(target->os),
ZigLLVMGetOSTypeName(get_llvm_os_type(target->os)),
ZigLLVMGetEnvironmentTypeName(target->env_type));
}
static bool is_os_darwin(ZigTarget *target) {
switch (target->os) {
case ZigLLVM_Darwin:
case ZigLLVM_IOS:
case ZigLLVM_MacOSX:
case OsMacOSX:
case OsIOS:
return true;
default:
return false;
@ -333,7 +509,7 @@ void resolve_target_object_format(ZigTarget *target) {
case ZigLLVM_x86_64:
if (is_os_darwin(target)) {
target->oformat = ZigLLVM_MachO;
} else if (target->os == ZigLLVM_Win32) {
} else if (target->os == OsWindows) {
target->oformat = ZigLLVM_COFF;
} else {
target->oformat = ZigLLVM_ELF;
@ -463,7 +639,7 @@ static int get_arch_pointer_bit_width(ZigLLVM_ArchType arch) {
uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
switch (target->os) {
case ZigLLVM_UnknownOS:
case OsFreestanding:
switch (id) {
case CIntTypeShort:
case CIntTypeUShort:
@ -480,9 +656,9 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
case CIntTypeCount:
zig_unreachable();
}
case ZigLLVM_Linux:
case ZigLLVM_Darwin:
case ZigLLVM_MacOSX:
case OsLinux:
case OsMacOSX:
case OsZen:
switch (id) {
case CIntTypeShort:
case CIntTypeUShort:
@ -499,7 +675,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
case CIntTypeCount:
zig_unreachable();
}
case ZigLLVM_Win32:
case OsWindows:
switch (id) {
case CIntTypeShort:
case CIntTypeUShort:
@ -515,40 +691,40 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
case CIntTypeCount:
zig_unreachable();
}
case ZigLLVM_Ananas:
case ZigLLVM_CloudABI:
case ZigLLVM_DragonFly:
case ZigLLVM_FreeBSD:
case ZigLLVM_IOS:
case ZigLLVM_KFreeBSD:
case ZigLLVM_Lv2:
case ZigLLVM_NetBSD:
case ZigLLVM_OpenBSD:
case ZigLLVM_Solaris:
case ZigLLVM_Haiku:
case ZigLLVM_Minix:
case ZigLLVM_RTEMS:
case ZigLLVM_NaCl:
case ZigLLVM_CNK:
case ZigLLVM_Bitrig:
case ZigLLVM_AIX:
case ZigLLVM_CUDA:
case ZigLLVM_NVCL:
case ZigLLVM_AMDHSA:
case ZigLLVM_PS4:
case ZigLLVM_ELFIAMCU:
case ZigLLVM_TvOS:
case ZigLLVM_WatchOS:
case ZigLLVM_Mesa3D:
case ZigLLVM_Fuchsia:
case ZigLLVM_Contiki:
case OsAnanas:
case OsCloudABI:
case OsDragonFly:
case OsFreeBSD:
case OsIOS:
case OsKFreeBSD:
case OsLv2:
case OsNetBSD:
case OsOpenBSD:
case OsSolaris:
case OsHaiku:
case OsMinix:
case OsRTEMS:
case OsNaCl:
case OsCNK:
case OsBitrig:
case OsAIX:
case OsCUDA:
case OsNVCL:
case OsAMDHSA:
case OsPS4:
case OsELFIAMCU:
case OsTvOS:
case OsWatchOS:
case OsMesa3D:
case OsFuchsia:
case OsContiki:
zig_panic("TODO c type size in bits for this target");
}
zig_unreachable();
}
const char *target_o_file_ext(ZigTarget *target) {
if (target->env_type == ZigLLVM_MSVC || target->os == ZigLLVM_Win32) {
if (target->env_type == ZigLLVM_MSVC || target->os == OsWindows) {
return ".obj";
} else {
return ".o";
@ -564,7 +740,7 @@ const char *target_llvm_ir_file_ext(ZigTarget *target) {
}
const char *target_exe_file_ext(ZigTarget *target) {
if (target->os == ZigLLVM_Win32) {
if (target->os == OsWindows) {
return ".exe";
} else {
return "";
@ -664,12 +840,12 @@ bool target_can_exec(const ZigTarget *host_target, const ZigTarget *guest_target
return true;
}
if (guest_target->os == ZigLLVM_Win32 && host_target->os == ZigLLVM_Win32 &&
if (guest_target->os == OsWindows && host_target->os == OsWindows &&
host_target->arch.arch == ZigLLVM_x86_64 && guest_target->arch.arch == ZigLLVM_x86)
{
// 64-bit windows can run 32-bit programs
return true;
}
return false;
}

View File

@ -17,10 +17,45 @@ struct ArchType {
ZigLLVM_SubArchType sub_arch;
};
enum Os {
OsFreestanding,
OsAnanas,
OsCloudABI,
OsDragonFly,
OsFreeBSD,
OsFuchsia,
OsIOS,
OsKFreeBSD,
OsLinux,
OsLv2, // PS3
OsMacOSX,
OsNetBSD,
OsOpenBSD,
OsSolaris,
OsWindows,
OsHaiku,
OsMinix,
OsRTEMS,
OsNaCl, // Native Client
OsCNK, // BG/P Compute-Node Kernel
OsBitrig,
OsAIX,
OsCUDA, // NVIDIA CUDA
OsNVCL, // NVIDIA OpenCL
OsAMDHSA, // AMD HSA Runtime
OsPS4,
OsELFIAMCU,
OsTvOS, // Apple tvOS
OsWatchOS, // Apple watchOS
OsMesa3D,
OsContiki,
OsZen,
};
struct ZigTarget {
ArchType arch;
ZigLLVM_VendorType vendor;
ZigLLVM_OSType os;
Os os;
ZigLLVM_EnvironmentType env_type;
ZigLLVM_ObjectFormatType oformat;
};
@ -46,8 +81,8 @@ size_t target_vendor_count(void);
ZigLLVM_VendorType get_target_vendor(size_t index);
size_t target_os_count(void);
ZigLLVM_OSType get_target_os(size_t index);
const char *get_target_os_name(ZigLLVM_OSType os_type);
Os get_target_os(size_t index);
const char *get_target_os_name(Os os_type);
size_t target_environ_count(void);
ZigLLVM_EnvironmentType get_target_environ(size_t index);
@ -61,7 +96,7 @@ void get_native_target(ZigTarget *target);
void get_unknown_target(ZigTarget *target);
int parse_target_arch(const char *str, ArchType *arch);
int parse_target_os(const char *str, ZigLLVM_OSType *os);
int parse_target_os(const char *str, Os *os);
int parse_target_environ(const char *str, ZigLLVM_EnvironmentType *env_type);
void init_all_targets(void);

View File

@ -800,7 +800,7 @@ const Target = union(enum) {
pub fn isDarwin(self: &const Target) -> bool {
return switch (self.getOs()) {
builtin.Os.darwin, builtin.Os.ios, builtin.Os.macosx => true,
builtin.Os.ios, builtin.Os.macosx => true,
else => false,
};
}
@ -1011,7 +1011,7 @@ pub const LibExeObjStep = struct {
self.out_filename = self.builder.fmt("lib{}.a", self.name);
} else {
switch (self.target.getOs()) {
builtin.Os.darwin, builtin.Os.ios, builtin.Os.macosx => {
builtin.Os.ios, builtin.Os.macosx => {
self.out_filename = self.builder.fmt("lib{}.{d}.{d}.{d}.dylib",
self.name, self.version.major, self.version.minor, self.version.patch);
self.major_only_filename = self.builder.fmt("lib{}.{d}.dylib", self.name, self.version.major);

View File

@ -4,7 +4,7 @@ const Os = builtin.Os;
pub use switch(builtin.os) {
Os.linux => @import("linux.zig"),
Os.windows => @import("windows.zig"),
Os.darwin, Os.macosx, Os.ios => @import("darwin.zig"),
Os.macosx, Os.ios => @import("darwin.zig"),
else => empty_import,
};
const empty_import = @import("../empty.zig");

View File

@ -49,7 +49,7 @@ pub const IncrementingAllocator = struct {
fn init(capacity: usize) -> %IncrementingAllocator {
switch (builtin.os) {
Os.linux, Os.darwin, Os.macosx, Os.ios => {
Os.linux, Os.macosx, Os.ios => {
const p = os.posix;
const addr = p.mmap(null, capacity, p.PROT_READ|p.PROT_WRITE,
p.MAP_PRIVATE|p.MAP_ANONYMOUS|p.MAP_NORESERVE, -1, 0);
@ -87,7 +87,7 @@ pub const IncrementingAllocator = struct {
fn deinit(self: &IncrementingAllocator) {
switch (builtin.os) {
Os.linux, Os.darwin, Os.macosx, Os.ios => {
Os.linux, Os.macosx, Os.ios => {
_ = os.posix.munmap(self.bytes.ptr, self.bytes.len);
},
Os.windows => {

View File

@ -3,7 +3,7 @@ const builtin = @import("builtin");
const Os = builtin.Os;
const system = switch(builtin.os) {
Os.linux => @import("os/linux.zig"),
Os.darwin, Os.macosx, Os.ios => @import("os/darwin.zig"),
Os.macosx, Os.ios => @import("os/darwin.zig"),
Os.windows => @import("os/windows/index.zig"),
else => @compileError("Unsupported OS"),
};
@ -190,7 +190,7 @@ pub const File = struct {
pub fn seekForward(self: &File, amount: isize) -> %void {
switch (builtin.os) {
Os.linux, Os.darwin => {
Os.linux, Os.macosx, Os.ios => {
const result = system.lseek(self.handle, amount, system.SEEK_CUR);
const err = system.getErrno(result);
if (err > 0) {
@ -210,7 +210,7 @@ pub const File = struct {
pub fn seekTo(self: &File, pos: usize) -> %void {
switch (builtin.os) {
Os.linux, Os.darwin => {
Os.linux, Os.macosx, Os.ios => {
const result = system.lseek(self.handle, @bitCast(isize, pos), system.SEEK_SET);
const err = system.getErrno(result);
if (err > 0) {
@ -230,7 +230,7 @@ pub const File = struct {
pub fn getPos(self: &File) -> %usize {
switch (builtin.os) {
Os.linux, Os.darwin => {
Os.linux, Os.macosx, Os.ios => {
const result = system.lseek(self.handle, 0, system.SEEK_CUR);
const err = system.getErrno(result);
if (err > 0) {

View File

@ -11,7 +11,7 @@ pub const UserInfo = struct {
/// POSIX function which gets a uid from username.
pub fn getUserInfo(name: []const u8) -> %UserInfo {
return switch (builtin.os) {
Os.linux, Os.darwin, Os.macosx, Os.ios => posixGetUserInfo(name),
Os.linux, Os.macosx, Os.ios => posixGetUserInfo(name),
else => @compileError("Unsupported OS"),
};
}

View File

@ -9,7 +9,7 @@ pub const darwin = @import("darwin.zig");
pub const linux = @import("linux.zig");
pub const posix = switch(builtin.os) {
Os.linux => linux,
Os.darwin, Os.macosx, Os.ios => darwin,
Os.macosx, Os.ios => darwin,
else => @compileError("Unsupported OS"),
};
@ -89,7 +89,7 @@ pub fn getRandomBytes(buf: []u8) -> %void {
}
return;
},
Os.darwin, Os.macosx, Os.ios => {
Os.macosx, Os.ios => {
const fd = %return posixOpen("/dev/urandom", posix.O_RDONLY|posix.O_CLOEXEC,
0, null);
defer close(fd);
@ -130,7 +130,7 @@ pub coldcc fn abort() -> noreturn {
c.abort();
}
switch (builtin.os) {
Os.linux, Os.darwin, Os.macosx, Os.ios => {
Os.linux, Os.macosx, Os.ios => {
_ = posix.raise(posix.SIGABRT);
_ = posix.raise(posix.SIGKILL);
while (true) {}
@ -151,7 +151,7 @@ pub coldcc fn exit(status: i32) -> noreturn {
c.exit(status);
}
switch (builtin.os) {
Os.linux, Os.darwin, Os.macosx, Os.ios => {
Os.linux, Os.macosx, Os.ios => {
posix.exit(status);
},
Os.windows => {
@ -1104,7 +1104,7 @@ pub fn readLink(allocator: &Allocator, pathname: []const u8) -> %[]u8 {
pub fn sleep(seconds: usize, nanoseconds: usize) {
switch(builtin.os) {
Os.linux, Os.darwin, Os.macosx, Os.ios => {
Os.linux, Os.macosx, Os.ios => {
posixSleep(u63(seconds), u63(nanoseconds));
},
Os.windows => {
@ -1537,7 +1537,7 @@ pub fn openSelfExe() -> %io.File {
Os.linux => {
return io.File.openRead("/proc/self/exe", null);
},
Os.darwin => {
Os.macosx, Os.ios => {
@panic("TODO: openSelfExe on Darwin");
},
else => @compileError("Unsupported OS"),
@ -1577,7 +1577,7 @@ pub fn selfExePath(allocator: &mem.Allocator) -> %[]u8 {
%return out_path.resize(new_len);
}
},
Os.darwin, Os.macosx, Os.ios => {
Os.macosx, Os.ios => {
var u32_len: u32 = 0;
const ret1 = c._NSGetExecutablePath(undefined, &u32_len);
assert(ret1 != 0);
@ -1605,7 +1605,7 @@ pub fn selfExeDirPath(allocator: &mem.Allocator) -> %[]u8 {
const dir = path.dirname(full_exe_path);
return allocator.shrink(u8, full_exe_path, dir.len);
},
Os.windows, Os.darwin, Os.macosx, Os.ios => {
Os.windows, Os.macosx, Os.ios => {
const self_exe_path = %return selfExePath(allocator);
%defer allocator.free(self_exe_path);
const dirname = os.path.dirname(self_exe_path);

View File

@ -1137,7 +1137,7 @@ pub fn real(allocator: &Allocator, pathname: []const u8) -> %[]u8 {
return allocator.shrink(u8, buf, final_len);
}
},
Os.darwin, Os.macosx, Os.ios => {
Os.macosx, Os.ios => {
// TODO instead of calling the libc function here, port the implementation
// to Zig, and then remove the NameTooLong error possibility.
const pathname_buf = %return allocator.alloc(u8, pathname.len + 1);

View File

@ -33,7 +33,7 @@ const test_targets = []TestTarget {
.environ = builtin.Environ.gnu,
},
TestTarget {
.os = builtin.Os.darwin,
.os = builtin.Os.macosx,
.arch = builtin.Arch.x86_64,
.environ = builtin.Environ.unknown,
},