authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-02-10 16:35:07-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-02-10 16:35:07-07:00
logb64260469105f786c7144c2ac4bbb4c777cc6fa8
tree22a0e9fa437573c199453184eb2014e4e95ead32
parent1ff2edf67ef7a5d434697bb494247b76f34f6c84

targets command shows which ones are native


4 files changed, 62 insertions(+), 19 deletions(-)

doc/langref.md+27-15
...@@ -242,7 +242,11 @@ TODO...@@ -242,7 +242,11 @@ TODO
242242
243TODO243TODO
244244
245### Error Type245### Pure Error Type
246
247TODO
248
249### Error Union Type
246250
247TODO251TODO
248252
...@@ -334,35 +338,43 @@ TODO...@@ -334,35 +338,43 @@ TODO
334338
335Built-in functions are prefixed with `@`.339Built-in functions are prefixed with `@`.
336340
337### Typeof341### @typeof
338342
339TODO343`@typeof(expression)`
340344
341### Sizeof345### @sizeof
342346
343TODO347`@sizeof(type)`
344348
345### Overflow Arithmetic349### Overflow Arithmetic
346350
347Overflow arithmetic functions have defined behavior on overflow or underflow. TODO what is that behaviour?351Overflow arithmetic functions have defined behavior on overflow or underflow.
348352
349The functions take an integer (TODO float?) type, two variables of the specified type, and a pointer to a variable of the specified type where the result is stored. The functions return a boolean value: true of overflow/underflow occurred, false otherwise.353The functions take an integer type, two variables of the specified type, and a
354pointer to a variable of the specified type where the result is stored. The
355functions return a boolean value: true of overflow/underflow occurred, false
356otherwise.
350357
351```358```
352Function Operation359Function Operation
353bool add_with_overflow(T: type, a: T, b: T, x: &T) *x = a + b360@add_with_overflow(T: type, a: T, b: T, x: &T) -> bool *x = a + b
354bool sub_with_overflow(T: type, a: T, b: T, x: &T) *x = a - b361@sub_with_overflow(T: type, a: T, b: T, x: &T) -> bool *x = a - b
355bool mul_with_overflow(T: type, a: T, b: T, x: &T) *x = a * b362@mul_with_overflow(T: type, a: T, b: T, x: &T) -> bool *x = a * b
356```363```
357364
358### Memory Operations365### @memset
359366
360TODO memset and memcpy367`@memset(dest, char, len)`
361368
362### Value Count369### @memcpy
363370
364TODO371`@memcpy(dest, source, len)`
372
373### @member_count
374
375`@member_count(enum_type)`
365376
366### Max and Min Value377### Max and Min Value
367378
368TODO379`@max_value(type)`
380`@min_value(type)`
src/main.cpp+17-4
...@@ -43,16 +43,27 @@ static int usage(const char *arg0) {...@@ -43,16 +43,27 @@ static int usage(const char *arg0) {
43}43}
4444
45static int print_target_list(FILE *f) {45static int print_target_list(FILE *f) {
46 ZigLLVM_ArchType native_arch_type;
47 ZigLLVM_SubArchType native_sub_arch_type;
48 ZigLLVM_VendorType native_vendor_type;
49 ZigLLVM_OSType native_os_type;
50 ZigLLVM_EnvironmentType native_environ_type;
51
52 ZigLLVMGetNativeTarget(&native_arch_type, &native_sub_arch_type, &native_vendor_type,
53 &native_os_type, &native_environ_type);
54
46 fprintf(f, "Architectures:\n");55 fprintf(f, "Architectures:\n");
47 int arch_count = target_arch_count();56 int arch_count = target_arch_count();
48 int sub_arch_count = target_sub_arch_count();57 int sub_arch_count = target_sub_arch_count();
49 for (int arch_i = 0; arch_i < arch_count; arch_i += 1) {58 for (int arch_i = 0; arch_i < arch_count; arch_i += 1) {
50 const ArchType *arch = get_target_arch(arch_i);59 const ArchType *arch = get_target_arch(arch_i);
51 fprintf(f, " %s\n", ZigLLVMGetArchTypeName(arch->llvm_arch));60 const char *native_str = (native_arch_type == arch->llvm_arch) ? " (native)" : "";
61 fprintf(f, " %s%s\n", ZigLLVMGetArchTypeName(arch->llvm_arch), native_str);
52 for (int sub_arch_i = 0; sub_arch_i < sub_arch_count; sub_arch_i += 1) {62 for (int sub_arch_i = 0; sub_arch_i < sub_arch_count; sub_arch_i += 1) {
53 const SubArchType *sub_arch = get_target_sub_arch(sub_arch_i);63 const SubArchType *sub_arch = get_target_sub_arch(sub_arch_i);
54 if (sub_arch->arch == arch->llvm_arch) {64 if (sub_arch->arch == arch->llvm_arch) {
55 fprintf(f, " %s\n", sub_arch->name);65 const char *native_str = (native_sub_arch_type == sub_arch->sub_arch) ? " (native)" : "";
66 fprintf(f, " %s%s\n", sub_arch->name, native_str);
56 }67 }
57 }68 }
58 }69 }
...@@ -61,14 +72,16 @@ static int print_target_list(FILE *f) {...@@ -61,14 +72,16 @@ static int print_target_list(FILE *f) {
61 int os_count = target_os_count();72 int os_count = target_os_count();
62 for (int i = 0; i < os_count; i += 1) {73 for (int i = 0; i < os_count; i += 1) {
63 const OsType *os_type = get_target_os(i);74 const OsType *os_type = get_target_os(i);
64 fprintf(f, " %s\n", get_target_os_name(os_type));75 const char *native_str = (native_os_type == os_type->llvm_os) ? " (native)" : "";
76 fprintf(f, " %s%s\n", get_target_os_name(os_type), native_str);
65 }77 }
6678
67 fprintf(f, "\nABIs:\n");79 fprintf(f, "\nABIs:\n");
68 int environ_count = target_environ_count();80 int environ_count = target_environ_count();
69 for (int i = 0; i < environ_count; i += 1) {81 for (int i = 0; i < environ_count; i += 1) {
70 const EnvironmentType *environ_type = get_target_environ(i);82 const EnvironmentType *environ_type = get_target_environ(i);
71 fprintf(f, " %s\n", ZigLLVMGetEnvironmentTypeName(environ_type->llvm_environment));83 const char *native_str = (native_environ_type == environ_type->llvm_environment) ? " (native)" : "";
84 fprintf(f, " %s%s\n", ZigLLVMGetEnvironmentTypeName(environ_type->llvm_environment), native_str);
72 }85 }
7386
74 return EXIT_SUCCESS;87 return EXIT_SUCCESS;
src/zig_llvm.cpp+15
...@@ -536,6 +536,21 @@ const char *ZigLLVMGetEnvironmentTypeName(ZigLLVM_EnvironmentType environ) {...@@ -536,6 +536,21 @@ const char *ZigLLVMGetEnvironmentTypeName(ZigLLVM_EnvironmentType environ) {
536 return Triple::getEnvironmentTypeName((Triple::EnvironmentType)environ);536 return Triple::getEnvironmentTypeName((Triple::EnvironmentType)environ);
537}537}
538538
539void ZigLLVMGetNativeTarget(ZigLLVM_ArchType *arch_type, ZigLLVM_SubArchType *sub_arch_type,
540 ZigLLVM_VendorType *vendor_type, ZigLLVM_OSType *os_type, ZigLLVM_EnvironmentType *environ_type)
541{
542 char *native_triple = LLVMGetDefaultTargetTriple();
543 Triple triple(native_triple);
544
545 *arch_type = (ZigLLVM_ArchType)triple.getArch();
546 *sub_arch_type = (ZigLLVM_SubArchType)triple.getSubArch();
547 *vendor_type = (ZigLLVM_VendorType)triple.getVendor();
548 *os_type = (ZigLLVM_OSType)triple.getOS();
549 *environ_type = (ZigLLVM_EnvironmentType)triple.getEnvironment();
550
551 free(native_triple);
552}
553
539//------------------------------------554//------------------------------------
540555
541#include "buffer.hpp"556#include "buffer.hpp"
src/zig_llvm.hpp+3
...@@ -288,6 +288,9 @@ const char *ZigLLVMGetVendorTypeName(ZigLLVM_VendorType vendor);...@@ -288,6 +288,9 @@ const char *ZigLLVMGetVendorTypeName(ZigLLVM_VendorType vendor);
288const char *ZigLLVMGetOSTypeName(ZigLLVM_OSType os);288const char *ZigLLVMGetOSTypeName(ZigLLVM_OSType os);
289const char *ZigLLVMGetEnvironmentTypeName(ZigLLVM_EnvironmentType environ);289const char *ZigLLVMGetEnvironmentTypeName(ZigLLVM_EnvironmentType environ);
290290
291void ZigLLVMGetNativeTarget(ZigLLVM_ArchType *arch_type, ZigLLVM_SubArchType *sub_arch_type,
292 ZigLLVM_VendorType *vendor_type, ZigLLVM_OSType *os_type, ZigLLVM_EnvironmentType *environ_type);
293
291294
292/*295/*
293 * This stuff is not LLVM API but it depends on the LLVM C++ API so we put it here.296 * This stuff is not LLVM API but it depends on the LLVM C++ API so we put it here.