Commit b642604691

Andrew Kelley <superjoe30@gmail.com>
2016-02-11 00:35:07
targets command shows which ones are native
1 parent 1ff2edf
doc/langref.md
@@ -242,7 +242,11 @@ TODO
 
 TODO
 
-### Error Type
+### Pure Error Type
+
+TODO
+
+### Error Union Type
 
 TODO
 
@@ -334,35 +338,43 @@ TODO
 
 Built-in functions are prefixed with `@`.
 
-### Typeof
+### @typeof
 
-TODO
+`@typeof(expression)`
 
-### Sizeof
+### @sizeof
 
-TODO
+`@sizeof(type)`
 
 ### Overflow Arithmetic
 
-Overflow arithmetic functions have defined behavior on overflow or underflow. TODO what is that behaviour?
+Overflow arithmetic functions have defined behavior on overflow or underflow.
 
-The 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.
+The functions take an integer 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.
 
 ```
 Function                                                  Operation
-bool add_with_overflow(T: type, a: T, b: T, x: &T)        *x = a + b
-bool sub_with_overflow(T: type, a: T, b: T, x: &T)        *x = a - b
-bool mul_with_overflow(T: type, a: T, b: T, x: &T)        *x = a * b
+@add_with_overflow(T: type, a: T, b: T, x: &T) -> bool    *x = a + b
+@sub_with_overflow(T: type, a: T, b: T, x: &T) -> bool    *x = a - b
+@mul_with_overflow(T: type, a: T, b: T, x: &T) -> bool    *x = a * b
 ```
 
-### Memory Operations
+### @memset
 
-TODO memset and memcpy
+`@memset(dest, char, len)`
 
-### Value Count
+### @memcpy
 
-TODO
+`@memcpy(dest, source, len)`
+
+### @member_count
+
+`@member_count(enum_type)`
 
 ### Max and Min Value
 
-TODO
+`@max_value(type)`
+`@min_value(type)`
src/main.cpp
@@ -43,16 +43,27 @@ static int usage(const char *arg0) {
 }
 
 static int print_target_list(FILE *f) {
+    ZigLLVM_ArchType native_arch_type;
+    ZigLLVM_SubArchType native_sub_arch_type;
+    ZigLLVM_VendorType native_vendor_type;
+    ZigLLVM_OSType native_os_type;
+    ZigLLVM_EnvironmentType native_environ_type;
+
+    ZigLLVMGetNativeTarget(&native_arch_type, &native_sub_arch_type, &native_vendor_type,
+            &native_os_type, &native_environ_type);
+
     fprintf(f, "Architectures:\n");
     int arch_count = target_arch_count();
     int sub_arch_count = target_sub_arch_count();
     for (int arch_i = 0; arch_i < arch_count; arch_i += 1) {
         const ArchType *arch = get_target_arch(arch_i);
-        fprintf(f, "  %s\n", ZigLLVMGetArchTypeName(arch->llvm_arch));
+        const char *native_str = (native_arch_type == arch->llvm_arch) ? " (native)" : "";
+        fprintf(f, "  %s%s\n", ZigLLVMGetArchTypeName(arch->llvm_arch), native_str);
         for (int sub_arch_i = 0; sub_arch_i  < sub_arch_count; sub_arch_i += 1) {
             const SubArchType *sub_arch = get_target_sub_arch(sub_arch_i);
             if (sub_arch->arch == arch->llvm_arch) {
-                fprintf(f, "    %s\n", sub_arch->name);
+                const char *native_str = (native_sub_arch_type == sub_arch->sub_arch) ? " (native)" : "";
+                fprintf(f, "    %s%s\n", sub_arch->name, native_str);
             }
         }
     }
@@ -61,14 +72,16 @@ static int print_target_list(FILE *f) {
     int os_count = target_os_count();
     for (int i = 0; i < os_count; i += 1) {
         const OsType *os_type = get_target_os(i);
-        fprintf(f, "  %s\n", get_target_os_name(os_type));
+        const char *native_str = (native_os_type == os_type->llvm_os) ? " (native)" : "";
+        fprintf(f, "  %s%s\n", get_target_os_name(os_type), native_str);
     }
 
     fprintf(f, "\nABIs:\n");
     int environ_count = target_environ_count();
     for (int i = 0; i < environ_count; i += 1) {
         const EnvironmentType *environ_type = get_target_environ(i);
-        fprintf(f, "  %s\n", ZigLLVMGetEnvironmentTypeName(environ_type->llvm_environment));
+        const char *native_str = (native_environ_type == environ_type->llvm_environment) ? " (native)" : "";
+        fprintf(f, "  %s%s\n", ZigLLVMGetEnvironmentTypeName(environ_type->llvm_environment), native_str);
     }
 
     return EXIT_SUCCESS;
src/zig_llvm.cpp
@@ -536,6 +536,21 @@ const char *ZigLLVMGetEnvironmentTypeName(ZigLLVM_EnvironmentType environ) {
     return Triple::getEnvironmentTypeName((Triple::EnvironmentType)environ);
 }
 
+void ZigLLVMGetNativeTarget(ZigLLVM_ArchType *arch_type, ZigLLVM_SubArchType *sub_arch_type,
+        ZigLLVM_VendorType *vendor_type, ZigLLVM_OSType *os_type, ZigLLVM_EnvironmentType *environ_type)
+{
+    char *native_triple = LLVMGetDefaultTargetTriple();
+    Triple triple(native_triple);
+
+    *arch_type = (ZigLLVM_ArchType)triple.getArch();
+    *sub_arch_type = (ZigLLVM_SubArchType)triple.getSubArch();
+    *vendor_type = (ZigLLVM_VendorType)triple.getVendor();
+    *os_type = (ZigLLVM_OSType)triple.getOS();
+    *environ_type = (ZigLLVM_EnvironmentType)triple.getEnvironment();
+
+    free(native_triple);
+}
+
 //------------------------------------
 
 #include "buffer.hpp"
src/zig_llvm.hpp
@@ -288,6 +288,9 @@ const char *ZigLLVMGetVendorTypeName(ZigLLVM_VendorType vendor);
 const char *ZigLLVMGetOSTypeName(ZigLLVM_OSType os);
 const char *ZigLLVMGetEnvironmentTypeName(ZigLLVM_EnvironmentType environ);
 
+void ZigLLVMGetNativeTarget(ZigLLVM_ArchType *arch_type, ZigLLVM_SubArchType *sub_arch_type,
+        ZigLLVM_VendorType *vendor_type, ZigLLVM_OSType *os_type, ZigLLVM_EnvironmentType *environ_type);
+
 
 /*
  * This stuff is not LLVM API but it depends on the LLVM C++ API so we put it here.