authorgravatar for andrea@orru.ioAndrea Orru <andrea@orru.io> 2018-01-06 23:10:53-05:00
committergravatar for andrea@orru.ioAndrea Orru <andrea@orru.io> 2018-01-06 23:10:53-05:00
loge932919e680aa6b6ef910e1c4ad969ac1ce0c46d
tree6bd041ade12f4889ecd82584c99dee2f380dbd47
parentdde7cc52d2f4780587b37604889c4568b8d79c62

Darwin -> MacOSX, added Zen. See #438


15 files changed, 341 insertions(+), 132 deletions(-)

src-self-hosted/target.zig+1-1
......@@ -38,7 +38,7 @@ pub const Target = union(enum) {
3838
3939 pub fn isDarwin(self: &const Target) -> bool {
4040 return switch (self.getOs()) {
41 builtin.Os.darwin, builtin.Os.ios, builtin.Os.macosx => true,
41 builtin.Os.ios, builtin.Os.macosx => true,
4242 else => false,
4343 };
4444 }
src/analyze.cpp+9-9
......@@ -32,7 +32,7 @@ ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg) {
3232 // failed semantic analysis, which isn't supposed to happen
3333 ErrorMsg *err = add_node_error(g, node->owner->c_import_node,
3434 buf_sprintf("compiler bug: @cImport generated invalid zig code"));
35
35
3636 add_error_note(g, err, node, msg);
3737
3838 g->errors.append(err);
......@@ -2425,7 +2425,7 @@ static void resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {
24252425 qual_str = "extern";
24262426 break;
24272427 }
2428 AstNode *source_node = (decl_node->data.container_decl.init_arg_expr != nullptr) ?
2428 AstNode *source_node = (decl_node->data.container_decl.init_arg_expr != nullptr) ?
24292429 decl_node->data.container_decl.init_arg_expr : decl_node;
24302430 add_node_error(g, source_node,
24312431 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
25992599 g->windows_subsystem_windows = false;
26002600 g->windows_subsystem_console = true;
26012601 } else if (buf_eql_str(symbol_name, "WinMain") &&
2602 g->zig_target.os == ZigLLVM_Win32)
2602 g->zig_target.os == OsWindows)
26032603 {
26042604 g->have_winmain = true;
26052605 g->windows_subsystem_windows = true;
26062606 g->windows_subsystem_console = false;
26072607 } else if (buf_eql_str(symbol_name, "WinMainCRTStartup") &&
2608 g->zig_target.os == ZigLLVM_Win32)
2608 g->zig_target.os == OsWindows)
26092609 {
26102610 g->have_winmain_crt_startup = true;
26112611 } else if (buf_eql_str(symbol_name, "DllMainCRTStartup") &&
2612 g->zig_target.os == ZigLLVM_Win32)
2612 g->zig_target.os == OsWindows)
26132613 {
26142614 g->have_dllmain_crt_startup = true;
26152615 }
......@@ -3994,7 +3994,7 @@ void find_libc_include_path(CodeGen *g) {
39943994 if (!g->libc_include_dir || buf_len(g->libc_include_dir) == 0) {
39953995 ZigWindowsSDK *sdk = get_windows_sdk(g);
39963996
3997 if (g->zig_target.os == ZigLLVM_Win32) {
3997 if (g->zig_target.os == OsWindows) {
39983998 if (os_get_win32_ucrt_include_path(sdk, g->libc_include_dir)) {
39993999 zig_panic("Unable to determine libc include path.");
40004000 }
......@@ -4010,9 +4010,9 @@ void find_libc_include_path(CodeGen *g) {
40104010void find_libc_lib_path(CodeGen *g) {
40114011 // later we can handle this better by reporting an error via the normal mechanism
40124012 if (!g->libc_lib_dir || buf_len(g->libc_lib_dir) == 0 ||
4013 (g->zig_target.os == ZigLLVM_Win32 && (g->msvc_lib_dir == nullptr || g->kernel32_lib_dir == nullptr)))
4013 (g->zig_target.os == OsWindows && (g->msvc_lib_dir == nullptr || g->kernel32_lib_dir == nullptr)))
40144014 {
4015 if (g->zig_target.os == ZigLLVM_Win32) {
4015 if (g->zig_target.os == OsWindows) {
40164016 ZigWindowsSDK *sdk = get_windows_sdk(g);
40174017
40184018 Buf* vc_lib_dir = buf_alloc();
......@@ -4039,7 +4039,7 @@ void find_libc_lib_path(CodeGen *g) {
40394039 }
40404040
40414041 if (!g->libc_static_lib_dir || buf_len(g->libc_static_lib_dir) == 0) {
4042 if ((g->zig_target.os == ZigLLVM_Win32) && (g->msvc_lib_dir != NULL)) {
4042 if ((g->zig_target.os == OsWindows) && (g->msvc_lib_dir != NULL)) {
40434043 return;
40444044 }
40454045 else {
src/codegen.cpp+13-15
......@@ -42,7 +42,7 @@ static void init_darwin_native(CodeGen *g) {
4242 g->mmacosx_version_min = buf_create_from_str(osx_target);
4343 } else if (ios_target) {
4444 g->mios_version_min = buf_create_from_str(ios_target);
45 } else if (g->zig_target.os != ZigLLVM_IOS) {
45 } else if (g->zig_target.os != OsIOS) {
4646 g->mmacosx_version_min = buf_create_from_str("10.10");
4747 }
4848}
......@@ -136,9 +136,8 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out
136136 g->each_lib_rpath = true;
137137#endif
138138
139 if (g->zig_target.os == ZigLLVM_Darwin ||
140 g->zig_target.os == ZigLLVM_MacOSX ||
141 g->zig_target.os == ZigLLVM_IOS)
139 if (g->zig_target.os == OsMacOSX ||
140 g->zig_target.os == OsIOS)
142141 {
143142 init_darwin_native(g);
144143 }
......@@ -146,9 +145,8 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out
146145 }
147146
148147 // On Darwin/MacOS/iOS, we always link libSystem which contains libc.
149 if (g->zig_target.os == ZigLLVM_Darwin ||
150 g->zig_target.os == ZigLLVM_MacOSX ||
151 g->zig_target.os == ZigLLVM_IOS)
148 if (g->zig_target.os == OsMacOSX ||
149 g->zig_target.os == OsIOS)
152150 {
153151 g->libc_link_lib = create_link_lib(buf_create_from_str("c"));
154152 g->link_libs_list.append(g->libc_link_lib);
......@@ -363,7 +361,7 @@ static LLVMCallConv get_llvm_cc(CodeGen *g, CallingConvention cc) {
363361 g->zig_target.arch.arch == ZigLLVM_x86_64)
364362 {
365363 // cold calling convention is not supported on windows
366 if (g->zig_target.os == ZigLLVM_Win32) {
364 if (g->zig_target.os == OsWindows) {
367365 return LLVMCCallConv;
368366 } else {
369367 return LLVMColdCallConv;
......@@ -386,7 +384,7 @@ static LLVMCallConv get_llvm_cc(CodeGen *g, CallingConvention cc) {
386384}
387385
388386static void add_uwtable_attr(CodeGen *g, LLVMValueRef fn_val) {
389 if (g->zig_target.os == ZigLLVM_Win32) {
387 if (g->zig_target.os == OsWindows) {
390388 addLLVMFnAttr(fn_val, "uwtable");
391389 }
392390}
......@@ -559,7 +557,7 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {
559557 }
560558 // Note: byval is disabled on windows due to an LLVM bug:
561559 // https://github.com/zig-lang/zig/issues/536
562 if (is_byval && g->zig_target.os != ZigLLVM_Win32) {
560 if (is_byval && g->zig_target.os != OsWindows) {
563561 addLLVMArgAttr(fn_table_entry->llvm_value, (unsigned)gen_index, "byval");
564562 }
565563 }
......@@ -2371,7 +2369,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
23712369 FnGenParamInfo *gen_info = &fn_type->data.fn.gen_param_info[param_i];
23722370 // Note: byval is disabled on windows due to an LLVM bug:
23732371 // https://github.com/zig-lang/zig/issues/536
2374 if (gen_info->is_byval && g->zig_target.os != ZigLLVM_Win32) {
2372 if (gen_info->is_byval && g->zig_target.os != OsWindows) {
23752373 addLLVMCallsiteAttr(result, (unsigned)gen_info->gen_index, "byval");
23762374 }
23772375 }
......@@ -5094,7 +5092,7 @@ static void define_builtin_compile_vars(CodeGen *g) {
50945092 buf_appendf(contents, "pub const Os = enum {\n");
50955093 uint32_t field_count = (uint32_t)target_os_count();
50965094 for (uint32_t i = 0; i < field_count; i += 1) {
5097 ZigLLVM_OSType os_type = get_target_os(i);
5095 Os os_type = get_target_os(i);
50985096 const char *name = get_target_os_name(os_type);
50995097 buf_appendf(contents, " %s,\n", name);
51005098
......@@ -5304,7 +5302,7 @@ static void init(CodeGen *g) {
53045302 // LLVM creates invalid binaries on Windows sometimes.
53055303 // See https://github.com/zig-lang/zig/issues/508
53065304 // As a workaround we do not use target native features on Windows.
5307 if (g->zig_target.os == ZigLLVM_Win32) {
5305 if (g->zig_target.os == OsWindows) {
53085306 target_specific_cpu_args = "";
53095307 target_specific_features = "";
53105308 } else {
......@@ -5524,13 +5522,13 @@ static void gen_root_source(CodeGen *g) {
55245522 }
55255523 report_errors_and_maybe_exit(g);
55265524
5527 if (!g->is_test_build && g->zig_target.os != ZigLLVM_UnknownOS &&
5525 if (!g->is_test_build && g->zig_target.os != OsFreestanding &&
55285526 !g->have_c_main && !g->have_winmain && !g->have_winmain_crt_startup &&
55295527 ((g->have_pub_main && g->out_type == OutTypeObj) || g->out_type == OutTypeExe))
55305528 {
55315529 g->bootstrap_import = add_special_code(g, create_bootstrap_pkg(g, g->root_package), "bootstrap.zig");
55325530 }
5533 if (g->zig_target.os == ZigLLVM_Win32 && !g->have_dllmain_crt_startup && g->out_type == OutTypeLib) {
5531 if (g->zig_target.os == OsWindows && !g->have_dllmain_crt_startup && g->out_type == OutTypeLib) {
55345532 g->bootstrap_import = add_special_code(g, create_bootstrap_pkg(g, g->root_package), "bootstrap_lib.zig");
55355533 }
55365534
src/link.cpp+1-1
......@@ -644,7 +644,7 @@ static void get_darwin_platform(LinkJob *lj, DarwinPlatform *platform) {
644644 platform->kind = MacOS;
645645 } else if (g->mios_version_min) {
646646 platform->kind = IPhoneOS;
647 } else if (g->zig_target.os == ZigLLVM_MacOSX || g->zig_target.os == ZigLLVM_Darwin) {
647 } else if (g->zig_target.os == OsMacOSX) {
648648 platform->kind = MacOS;
649649 g->mmacosx_version_min = buf_create_from_str("10.10");
650650 } else {
src/main.cpp+1-1
......@@ -120,7 +120,7 @@ static int print_target_list(FILE *f) {
120120 fprintf(f, "\nOperating Systems:\n");
121121 size_t os_count = target_os_count();
122122 for (size_t i = 0; i < os_count; i += 1) {
123 ZigLLVM_OSType os_type = get_target_os(i);
123 Os os_type = get_target_os(i);
124124 const char *native_str = (native.os == os_type) ? " (native)" : "";
125125 fprintf(f, " %s%s\n", get_target_os_name(os_type), native_str);
126126 }
src/target.cpp+257-81
......@@ -105,39 +105,39 @@ static const ZigLLVM_VendorType vendor_list[] = {
105105 ZigLLVM_SUSE,
106106};
107107
108static const ZigLLVM_OSType os_list[] = {
109 ZigLLVM_UnknownOS,
110 ZigLLVM_Ananas,
111 ZigLLVM_CloudABI,
112 ZigLLVM_Darwin,
113 ZigLLVM_DragonFly,
114 ZigLLVM_FreeBSD,
115 ZigLLVM_Fuchsia,
116 ZigLLVM_IOS,
117 ZigLLVM_KFreeBSD,
118 ZigLLVM_Linux,
119 ZigLLVM_Lv2,
120 ZigLLVM_MacOSX,
121 ZigLLVM_NetBSD,
122 ZigLLVM_OpenBSD,
123 ZigLLVM_Solaris,
124 ZigLLVM_Win32,
125 ZigLLVM_Haiku,
126 ZigLLVM_Minix,
127 ZigLLVM_RTEMS,
128 ZigLLVM_NaCl,
129 ZigLLVM_CNK,
130 ZigLLVM_Bitrig,
131 ZigLLVM_AIX,
132 ZigLLVM_CUDA,
133 ZigLLVM_NVCL,
134 ZigLLVM_AMDHSA,
135 ZigLLVM_PS4,
136 ZigLLVM_ELFIAMCU,
137 ZigLLVM_TvOS,
138 ZigLLVM_WatchOS,
139 ZigLLVM_Mesa3D,
140 ZigLLVM_Contiki,
108static const Os os_list[] = {
109 OsFreestanding,
110 OsAnanas,
111 OsCloudABI,
112 OsDragonFly,
113 OsFreeBSD,
114 OsFuchsia,
115 OsIOS,
116 OsKFreeBSD,
117 OsLinux,
118 OsLv2, // PS3
119 OsMacOSX,
120 OsNetBSD,
121 OsOpenBSD,
122 OsSolaris,
123 OsWindows,
124 OsHaiku,
125 OsMinix,
126 OsRTEMS,
127 OsNaCl, // Native Client
128 OsCNK, // BG/P Compute-Node Kernel
129 OsBitrig,
130 OsAIX,
131 OsCUDA, // NVIDIA CUDA
132 OsNVCL, // NVIDIA OpenCL
133 OsAMDHSA, // AMD HSA Runtime
134 OsPS4,
135 OsELFIAMCU,
136 OsTvOS, // Apple tvOS
137 OsWatchOS, // Apple watchOS
138 OsMesa3D,
139 OsContiki,
140 OsZen,
141141};
142142
143143static const ZigLLVM_EnvironmentType environ_list[] = {
......@@ -209,12 +209,187 @@ ZigLLVM_VendorType get_target_vendor(size_t index) {
209209size_t target_os_count(void) {
210210 return array_length(os_list);
211211}
212ZigLLVM_OSType get_target_os(size_t index) {
212Os get_target_os(size_t index) {
213213 return os_list[index];
214214}
215215
216const char *get_target_os_name(ZigLLVM_OSType os_type) {
217 return (os_type == ZigLLVM_UnknownOS) ? "freestanding" : ZigLLVMGetOSTypeName(os_type);
216static ZigLLVM_OSType get_llvm_os_type(Os os_type) {
217 switch (os_type) {
218 case OsFreestanding:
219 case OsZen:
220 return ZigLLVM_UnknownOS;
221 case OsAnanas:
222 return ZigLLVM_Ananas;
223 case OsCloudABI:
224 return ZigLLVM_CloudABI;
225 case OsDragonFly:
226 return ZigLLVM_DragonFly;
227 case OsFreeBSD:
228 return ZigLLVM_FreeBSD;
229 case OsFuchsia:
230 return ZigLLVM_Fuchsia;
231 case OsIOS:
232 return ZigLLVM_IOS;
233 case OsKFreeBSD:
234 return ZigLLVM_KFreeBSD;
235 case OsLinux:
236 return ZigLLVM_Linux;
237 case OsLv2:
238 return ZigLLVM_Lv2;
239 case OsMacOSX:
240 return ZigLLVM_MacOSX;
241 case OsNetBSD:
242 return ZigLLVM_NetBSD;
243 case OsOpenBSD:
244 return ZigLLVM_OpenBSD;
245 case OsSolaris:
246 return ZigLLVM_Solaris;
247 case OsWindows:
248 return ZigLLVM_Win32;
249 case OsHaiku:
250 return ZigLLVM_Haiku;
251 case OsMinix:
252 return ZigLLVM_Minix;
253 case OsRTEMS:
254 return ZigLLVM_RTEMS;
255 case OsNaCl:
256 return ZigLLVM_NaCl;
257 case OsCNK:
258 return ZigLLVM_CNK;
259 case OsBitrig:
260 return ZigLLVM_Bitrig;
261 case OsAIX:
262 return ZigLLVM_AIX;
263 case OsCUDA:
264 return ZigLLVM_CUDA;
265 case OsNVCL:
266 return ZigLLVM_NVCL;
267 case OsAMDHSA:
268 return ZigLLVM_AMDHSA;
269 case OsPS4:
270 return ZigLLVM_PS4;
271 case OsELFIAMCU:
272 return ZigLLVM_ELFIAMCU;
273 case OsTvOS:
274 return ZigLLVM_TvOS;
275 case OsWatchOS:
276 return ZigLLVM_WatchOS;
277 case OsMesa3D:
278 return ZigLLVM_Mesa3D;
279 case OsContiki:
280 return ZigLLVM_Contiki;
281 }
282 zig_unreachable();
283}
284
285static Os get_zig_os_type(ZigLLVM_OSType os_type) {
286 switch (os_type) {
287 case ZigLLVM_UnknownOS:
288 return OsFreestanding;
289 case ZigLLVM_Ananas:
290 return OsAnanas;
291 case ZigLLVM_CloudABI:
292 return OsCloudABI;
293 case ZigLLVM_DragonFly:
294 return OsDragonFly;
295 case ZigLLVM_FreeBSD:
296 return OsFreeBSD;
297 case ZigLLVM_Fuchsia:
298 return OsFuchsia;
299 case ZigLLVM_IOS:
300 return OsIOS;
301 case ZigLLVM_KFreeBSD:
302 return OsKFreeBSD;
303 case ZigLLVM_Linux:
304 return OsLinux;
305 case ZigLLVM_Lv2:
306 return OsLv2;
307 case ZigLLVM_Darwin:
308 case ZigLLVM_MacOSX:
309 return OsMacOSX;
310 case ZigLLVM_NetBSD:
311 return OsNetBSD;
312 case ZigLLVM_OpenBSD:
313 return OsOpenBSD;
314 case ZigLLVM_Solaris:
315 return OsSolaris;
316 case ZigLLVM_Win32:
317 return OsWindows;
318 case ZigLLVM_Haiku:
319 return OsHaiku;
320 case ZigLLVM_Minix:
321 return OsMinix;
322 case ZigLLVM_RTEMS:
323 return OsRTEMS;
324 case ZigLLVM_NaCl:
325 return OsNaCl;
326 case ZigLLVM_CNK:
327 return OsCNK;
328 case ZigLLVM_Bitrig:
329 return OsBitrig;
330 case ZigLLVM_AIX:
331 return OsAIX;
332 case ZigLLVM_CUDA:
333 return OsCUDA;
334 case ZigLLVM_NVCL:
335 return OsNVCL;
336 case ZigLLVM_AMDHSA:
337 return OsAMDHSA;
338 case ZigLLVM_PS4:
339 return OsPS4;
340 case ZigLLVM_ELFIAMCU:
341 return OsELFIAMCU;
342 case ZigLLVM_TvOS:
343 return OsTvOS;
344 case ZigLLVM_WatchOS:
345 return OsWatchOS;
346 case ZigLLVM_Mesa3D:
347 return OsMesa3D;
348 case ZigLLVM_Contiki:
349 return OsContiki;
350 }
351 zig_unreachable();
352}
353
354const char *get_target_os_name(Os os_type) {
355 switch (os_type) {
356 case OsFreestanding:
357 return "freestanding";
358 case OsZen:
359 return "zen";
360 case OsAnanas:
361 case OsCloudABI:
362 case OsDragonFly:
363 case OsFreeBSD:
364 case OsFuchsia:
365 case OsIOS:
366 case OsKFreeBSD:
367 case OsLinux:
368 case OsLv2: // PS3
369 case OsMacOSX:
370 case OsNetBSD:
371 case OsOpenBSD:
372 case OsSolaris:
373 case OsWindows:
374 case OsHaiku:
375 case OsMinix:
376 case OsRTEMS:
377 case OsNaCl: // Native Client
378 case OsCNK: // BG/P Compute-Node Kernel
379 case OsBitrig:
380 case OsAIX:
381 case OsCUDA: // NVIDIA CUDA
382 case OsNVCL: // NVIDIA OpenCL
383 case OsAMDHSA: // AMD HSA Runtime
384 case OsPS4:
385 case OsELFIAMCU:
386 case OsTvOS: // Apple tvOS
387 case OsWatchOS: // Apple watchOS
388 case OsMesa3D:
389 case OsContiki:
390 return ZigLLVMGetOSTypeName(get_llvm_os_type(os_type));
391 }
392 zig_unreachable();
218393}
219394
220395size_t target_environ_count(void) {
......@@ -225,20 +400,22 @@ ZigLLVM_EnvironmentType get_target_environ(size_t index) {
225400}
226401
227402void get_native_target(ZigTarget *target) {
403 ZigLLVM_OSType os_type;
228404 ZigLLVMGetNativeTarget(
229405 &target->arch.arch,
230406 &target->arch.sub_arch,
231407 &target->vendor,
232 &target->os,
408 &os_type,
233409 &target->env_type,
234410 &target->oformat);
411 target->os = get_zig_os_type(os_type);
235412}
236413
237414void get_unknown_target(ZigTarget *target) {
238415 target->arch.arch = ZigLLVM_UnknownArch;
239416 target->arch.sub_arch = ZigLLVM_NoSubArch;
240417 target->vendor = ZigLLVM_UnknownVendor;
241 target->os = ZigLLVM_UnknownOS;
418 target->os = OsFreestanding;
242419 target->env_type = ZigLLVM_UnknownEnvironment;
243420 target->oformat = ZigLLVM_UnknownObjectFormat;
244421}
......@@ -265,9 +442,9 @@ int parse_target_arch(const char *str, ArchType *out_arch) {
265442 return ErrorFileNotFound;
266443}
267444
268int parse_target_os(const char *str, ZigLLVM_OSType *out_os) {
445int parse_target_os(const char *str, Os *out_os) {
269446 for (size_t i = 0; i < array_length(os_list); i += 1) {
270 ZigLLVM_OSType os = os_list[i];
447 Os os = os_list[i];
271448 const char *os_name = get_target_os_name(os);
272449 if (strcmp(os_name, str) == 0) {
273450 *out_os = os;
......@@ -304,15 +481,14 @@ void get_target_triple(Buf *triple, const ZigTarget *target) {
304481 buf_resize(triple, 0);
305482 buf_appendf(triple, "%s-%s-%s-%s", arch_name,
306483 ZigLLVMGetVendorTypeName(target->vendor),
307 ZigLLVMGetOSTypeName(target->os),
484 ZigLLVMGetOSTypeName(get_llvm_os_type(target->os)),
308485 ZigLLVMGetEnvironmentTypeName(target->env_type));
309486}
310487
311488static bool is_os_darwin(ZigTarget *target) {
312489 switch (target->os) {
313 case ZigLLVM_Darwin:
314 case ZigLLVM_IOS:
315 case ZigLLVM_MacOSX:
490 case OsMacOSX:
491 case OsIOS:
316492 return true;
317493 default:
318494 return false;
......@@ -333,7 +509,7 @@ void resolve_target_object_format(ZigTarget *target) {
333509 case ZigLLVM_x86_64:
334510 if (is_os_darwin(target)) {
335511 target->oformat = ZigLLVM_MachO;
336 } else if (target->os == ZigLLVM_Win32) {
512 } else if (target->os == OsWindows) {
337513 target->oformat = ZigLLVM_COFF;
338514 } else {
339515 target->oformat = ZigLLVM_ELF;
......@@ -463,7 +639,7 @@ static int get_arch_pointer_bit_width(ZigLLVM_ArchType arch) {
463639
464640uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
465641 switch (target->os) {
466 case ZigLLVM_UnknownOS:
642 case OsFreestanding:
467643 switch (id) {
468644 case CIntTypeShort:
469645 case CIntTypeUShort:
......@@ -480,9 +656,9 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
480656 case CIntTypeCount:
481657 zig_unreachable();
482658 }
483 case ZigLLVM_Linux:
484 case ZigLLVM_Darwin:
485 case ZigLLVM_MacOSX:
659 case OsLinux:
660 case OsMacOSX:
661 case OsZen:
486662 switch (id) {
487663 case CIntTypeShort:
488664 case CIntTypeUShort:
......@@ -499,7 +675,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
499675 case CIntTypeCount:
500676 zig_unreachable();
501677 }
502 case ZigLLVM_Win32:
678 case OsWindows:
503679 switch (id) {
504680 case CIntTypeShort:
505681 case CIntTypeUShort:
......@@ -515,40 +691,40 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
515691 case CIntTypeCount:
516692 zig_unreachable();
517693 }
518 case ZigLLVM_Ananas:
519 case ZigLLVM_CloudABI:
520 case ZigLLVM_DragonFly:
521 case ZigLLVM_FreeBSD:
522 case ZigLLVM_IOS:
523 case ZigLLVM_KFreeBSD:
524 case ZigLLVM_Lv2:
525 case ZigLLVM_NetBSD:
526 case ZigLLVM_OpenBSD:
527 case ZigLLVM_Solaris:
528 case ZigLLVM_Haiku:
529 case ZigLLVM_Minix:
530 case ZigLLVM_RTEMS:
531 case ZigLLVM_NaCl:
532 case ZigLLVM_CNK:
533 case ZigLLVM_Bitrig:
534 case ZigLLVM_AIX:
535 case ZigLLVM_CUDA:
536 case ZigLLVM_NVCL:
537 case ZigLLVM_AMDHSA:
538 case ZigLLVM_PS4:
539 case ZigLLVM_ELFIAMCU:
540 case ZigLLVM_TvOS:
541 case ZigLLVM_WatchOS:
542 case ZigLLVM_Mesa3D:
543 case ZigLLVM_Fuchsia:
544 case ZigLLVM_Contiki:
694 case OsAnanas:
695 case OsCloudABI:
696 case OsDragonFly:
697 case OsFreeBSD:
698 case OsIOS:
699 case OsKFreeBSD:
700 case OsLv2:
701 case OsNetBSD:
702 case OsOpenBSD:
703 case OsSolaris:
704 case OsHaiku:
705 case OsMinix:
706 case OsRTEMS:
707 case OsNaCl:
708 case OsCNK:
709 case OsBitrig:
710 case OsAIX:
711 case OsCUDA:
712 case OsNVCL:
713 case OsAMDHSA:
714 case OsPS4:
715 case OsELFIAMCU:
716 case OsTvOS:
717 case OsWatchOS:
718 case OsMesa3D:
719 case OsFuchsia:
720 case OsContiki:
545721 zig_panic("TODO c type size in bits for this target");
546722 }
547723 zig_unreachable();
548724}
549725
550726const char *target_o_file_ext(ZigTarget *target) {
551 if (target->env_type == ZigLLVM_MSVC || target->os == ZigLLVM_Win32) {
727 if (target->env_type == ZigLLVM_MSVC || target->os == OsWindows) {
552728 return ".obj";
553729 } else {
554730 return ".o";
......@@ -564,7 +740,7 @@ const char *target_llvm_ir_file_ext(ZigTarget *target) {
564740}
565741
566742const char *target_exe_file_ext(ZigTarget *target) {
567 if (target->os == ZigLLVM_Win32) {
743 if (target->os == OsWindows) {
568744 return ".exe";
569745 } else {
570746 return "";
......@@ -664,12 +840,12 @@ bool target_can_exec(const ZigTarget *host_target, const ZigTarget *guest_target
664840 return true;
665841 }
666842
667 if (guest_target->os == ZigLLVM_Win32 && host_target->os == ZigLLVM_Win32 &&
843 if (guest_target->os == OsWindows && host_target->os == OsWindows &&
668844 host_target->arch.arch == ZigLLVM_x86_64 && guest_target->arch.arch == ZigLLVM_x86)
669845 {
670846 // 64-bit windows can run 32-bit programs
671847 return true;
672848 }
673
849
674850 return false;
675851}
src/target.hpp+39-4
......@@ -17,10 +17,45 @@ struct ArchType {
1717 ZigLLVM_SubArchType sub_arch;
1818};
1919
20enum Os {
21 OsFreestanding,
22 OsAnanas,
23 OsCloudABI,
24 OsDragonFly,
25 OsFreeBSD,
26 OsFuchsia,
27 OsIOS,
28 OsKFreeBSD,
29 OsLinux,
30 OsLv2, // PS3
31 OsMacOSX,
32 OsNetBSD,
33 OsOpenBSD,
34 OsSolaris,
35 OsWindows,
36 OsHaiku,
37 OsMinix,
38 OsRTEMS,
39 OsNaCl, // Native Client
40 OsCNK, // BG/P Compute-Node Kernel
41 OsBitrig,
42 OsAIX,
43 OsCUDA, // NVIDIA CUDA
44 OsNVCL, // NVIDIA OpenCL
45 OsAMDHSA, // AMD HSA Runtime
46 OsPS4,
47 OsELFIAMCU,
48 OsTvOS, // Apple tvOS
49 OsWatchOS, // Apple watchOS
50 OsMesa3D,
51 OsContiki,
52 OsZen,
53};
54
2055struct ZigTarget {
2156 ArchType arch;
2257 ZigLLVM_VendorType vendor;
23 ZigLLVM_OSType os;
58 Os os;
2459 ZigLLVM_EnvironmentType env_type;
2560 ZigLLVM_ObjectFormatType oformat;
2661};
......@@ -46,8 +81,8 @@ size_t target_vendor_count(void);
4681ZigLLVM_VendorType get_target_vendor(size_t index);
4782
4883size_t target_os_count(void);
49ZigLLVM_OSType get_target_os(size_t index);
50const char *get_target_os_name(ZigLLVM_OSType os_type);
84Os get_target_os(size_t index);
85const char *get_target_os_name(Os os_type);
5186
5287size_t target_environ_count(void);
5388ZigLLVM_EnvironmentType get_target_environ(size_t index);
......@@ -61,7 +96,7 @@ void get_native_target(ZigTarget *target);
6196void get_unknown_target(ZigTarget *target);
6297
6398int parse_target_arch(const char *str, ArchType *arch);
64int parse_target_os(const char *str, ZigLLVM_OSType *os);
99int parse_target_os(const char *str, Os *os);
65100int parse_target_environ(const char *str, ZigLLVM_EnvironmentType *env_type);
66101
67102void init_all_targets(void);
std/build.zig+2-2
......@@ -800,7 +800,7 @@ const Target = union(enum) {
800800
801801 pub fn isDarwin(self: &const Target) -> bool {
802802 return switch (self.getOs()) {
803 builtin.Os.darwin, builtin.Os.ios, builtin.Os.macosx => true,
803 builtin.Os.ios, builtin.Os.macosx => true,
804804 else => false,
805805 };
806806 }
......@@ -1011,7 +1011,7 @@ pub const LibExeObjStep = struct {
10111011 self.out_filename = self.builder.fmt("lib{}.a", self.name);
10121012 } else {
10131013 switch (self.target.getOs()) {
1014 builtin.Os.darwin, builtin.Os.ios, builtin.Os.macosx => {
1014 builtin.Os.ios, builtin.Os.macosx => {
10151015 self.out_filename = self.builder.fmt("lib{}.{d}.{d}.{d}.dylib",
10161016 self.name, self.version.major, self.version.minor, self.version.patch);
10171017 self.major_only_filename = self.builder.fmt("lib{}.{d}.dylib", self.name, self.version.major);
std/c/index.zig+1-1
......@@ -4,7 +4,7 @@ const Os = builtin.Os;
44pub use switch(builtin.os) {
55 Os.linux => @import("linux.zig"),
66 Os.windows => @import("windows.zig"),
7 Os.darwin, Os.macosx, Os.ios => @import("darwin.zig"),
7 Os.macosx, Os.ios => @import("darwin.zig"),
88 else => empty_import,
99};
1010const empty_import = @import("../empty.zig");
std/heap.zig+2-2
......@@ -49,7 +49,7 @@ pub const IncrementingAllocator = struct {
4949
5050 fn init(capacity: usize) -> %IncrementingAllocator {
5151 switch (builtin.os) {
52 Os.linux, Os.darwin, Os.macosx, Os.ios => {
52 Os.linux, Os.macosx, Os.ios => {
5353 const p = os.posix;
5454 const addr = p.mmap(null, capacity, p.PROT_READ|p.PROT_WRITE,
5555 p.MAP_PRIVATE|p.MAP_ANONYMOUS|p.MAP_NORESERVE, -1, 0);
......@@ -87,7 +87,7 @@ pub const IncrementingAllocator = struct {
8787
8888 fn deinit(self: &IncrementingAllocator) {
8989 switch (builtin.os) {
90 Os.linux, Os.darwin, Os.macosx, Os.ios => {
90 Os.linux, Os.macosx, Os.ios => {
9191 _ = os.posix.munmap(self.bytes.ptr, self.bytes.len);
9292 },
9393 Os.windows => {
std/io.zig+4-4
......@@ -3,7 +3,7 @@ const builtin = @import("builtin");
33const Os = builtin.Os;
44const system = switch(builtin.os) {
55 Os.linux => @import("os/linux.zig"),
6 Os.darwin, Os.macosx, Os.ios => @import("os/darwin.zig"),
6 Os.macosx, Os.ios => @import("os/darwin.zig"),
77 Os.windows => @import("os/windows/index.zig"),
88 else => @compileError("Unsupported OS"),
99};
......@@ -190,7 +190,7 @@ pub const File = struct {
190190
191191 pub fn seekForward(self: &File, amount: isize) -> %void {
192192 switch (builtin.os) {
193 Os.linux, Os.darwin => {
193 Os.linux, Os.macosx, Os.ios => {
194194 const result = system.lseek(self.handle, amount, system.SEEK_CUR);
195195 const err = system.getErrno(result);
196196 if (err > 0) {
......@@ -210,7 +210,7 @@ pub const File = struct {
210210
211211 pub fn seekTo(self: &File, pos: usize) -> %void {
212212 switch (builtin.os) {
213 Os.linux, Os.darwin => {
213 Os.linux, Os.macosx, Os.ios => {
214214 const result = system.lseek(self.handle, @bitCast(isize, pos), system.SEEK_SET);
215215 const err = system.getErrno(result);
216216 if (err > 0) {
......@@ -230,7 +230,7 @@ pub const File = struct {
230230
231231 pub fn getPos(self: &File) -> %usize {
232232 switch (builtin.os) {
233 Os.linux, Os.darwin => {
233 Os.linux, Os.macosx, Os.ios => {
234234 const result = system.lseek(self.handle, 0, system.SEEK_CUR);
235235 const err = system.getErrno(result);
236236 if (err > 0) {
std/os/get_user_id.zig+1-1
......@@ -11,7 +11,7 @@ pub const UserInfo = struct {
1111/// POSIX function which gets a uid from username.
1212pub fn getUserInfo(name: []const u8) -> %UserInfo {
1313 return switch (builtin.os) {
14 Os.linux, Os.darwin, Os.macosx, Os.ios => posixGetUserInfo(name),
14 Os.linux, Os.macosx, Os.ios => posixGetUserInfo(name),
1515 else => @compileError("Unsupported OS"),
1616 };
1717}
std/os/index.zig+8-8
......@@ -9,7 +9,7 @@ pub const darwin = @import("darwin.zig");
99pub const linux = @import("linux.zig");
1010pub const posix = switch(builtin.os) {
1111 Os.linux => linux,
12 Os.darwin, Os.macosx, Os.ios => darwin,
12 Os.macosx, Os.ios => darwin,
1313 else => @compileError("Unsupported OS"),
1414};
1515
......@@ -89,7 +89,7 @@ pub fn getRandomBytes(buf: []u8) -> %void {
8989 }
9090 return;
9191 },
92 Os.darwin, Os.macosx, Os.ios => {
92 Os.macosx, Os.ios => {
9393 const fd = %return posixOpen("/dev/urandom", posix.O_RDONLY|posix.O_CLOEXEC,
9494 0, null);
9595 defer close(fd);
......@@ -130,7 +130,7 @@ pub coldcc fn abort() -> noreturn {
130130 c.abort();
131131 }
132132 switch (builtin.os) {
133 Os.linux, Os.darwin, Os.macosx, Os.ios => {
133 Os.linux, Os.macosx, Os.ios => {
134134 _ = posix.raise(posix.SIGABRT);
135135 _ = posix.raise(posix.SIGKILL);
136136 while (true) {}
......@@ -151,7 +151,7 @@ pub coldcc fn exit(status: i32) -> noreturn {
151151 c.exit(status);
152152 }
153153 switch (builtin.os) {
154 Os.linux, Os.darwin, Os.macosx, Os.ios => {
154 Os.linux, Os.macosx, Os.ios => {
155155 posix.exit(status);
156156 },
157157 Os.windows => {
......@@ -1104,7 +1104,7 @@ pub fn readLink(allocator: &Allocator, pathname: []const u8) -> %[]u8 {
11041104
11051105pub fn sleep(seconds: usize, nanoseconds: usize) {
11061106 switch(builtin.os) {
1107 Os.linux, Os.darwin, Os.macosx, Os.ios => {
1107 Os.linux, Os.macosx, Os.ios => {
11081108 posixSleep(u63(seconds), u63(nanoseconds));
11091109 },
11101110 Os.windows => {
......@@ -1537,7 +1537,7 @@ pub fn openSelfExe() -> %io.File {
15371537 Os.linux => {
15381538 return io.File.openRead("/proc/self/exe", null);
15391539 },
1540 Os.darwin => {
1540 Os.macosx, Os.ios => {
15411541 @panic("TODO: openSelfExe on Darwin");
15421542 },
15431543 else => @compileError("Unsupported OS"),
......@@ -1577,7 +1577,7 @@ pub fn selfExePath(allocator: &mem.Allocator) -> %[]u8 {
15771577 %return out_path.resize(new_len);
15781578 }
15791579 },
1580 Os.darwin, Os.macosx, Os.ios => {
1580 Os.macosx, Os.ios => {
15811581 var u32_len: u32 = 0;
15821582 const ret1 = c._NSGetExecutablePath(undefined, &u32_len);
15831583 assert(ret1 != 0);
......@@ -1605,7 +1605,7 @@ pub fn selfExeDirPath(allocator: &mem.Allocator) -> %[]u8 {
16051605 const dir = path.dirname(full_exe_path);
16061606 return allocator.shrink(u8, full_exe_path, dir.len);
16071607 },
1608 Os.windows, Os.darwin, Os.macosx, Os.ios => {
1608 Os.windows, Os.macosx, Os.ios => {
16091609 const self_exe_path = %return selfExePath(allocator);
16101610 %defer allocator.free(self_exe_path);
16111611 const dirname = os.path.dirname(self_exe_path);
std/os/path.zig+1-1
......@@ -1137,7 +1137,7 @@ pub fn real(allocator: &Allocator, pathname: []const u8) -> %[]u8 {
11371137 return allocator.shrink(u8, buf, final_len);
11381138 }
11391139 },
1140 Os.darwin, Os.macosx, Os.ios => {
1140 Os.macosx, Os.ios => {
11411141 // TODO instead of calling the libc function here, port the implementation
11421142 // to Zig, and then remove the NameTooLong error possibility.
11431143 const pathname_buf = %return allocator.alloc(u8, pathname.len + 1);
test/tests.zig+1-1
......@@ -33,7 +33,7 @@ const test_targets = []TestTarget {
3333 .environ = builtin.Environ.gnu,
3434 },
3535 TestTarget {
36 .os = builtin.Os.darwin,
36 .os = builtin.Os.macosx,
3737 .arch = builtin.Arch.x86_64,
3838 .environ = builtin.Environ.unknown,
3939 },