| author | |
| committer | |
| log | b64260469105f786c7144c2ac4bbb4c777cc6fa8 |
| tree | 22a0e9fa437573c199453184eb2014e4e95ead32 |
| parent | 1ff2edf67ef7a5d434697bb494247b76f34f6c84 |
4 files changed, 62 insertions(+), 19 deletions(-)
doc/langref.md+27-15| ... | @@ -242,7 +242,11 @@ TODO | ... | @@ -242,7 +242,11 @@ TODO |
| 242 | 242 | ||
| 243 | TODO | 243 | TODO |
| 244 | 244 | ||
| 245 | ### Error Type | 245 | ### Pure Error Type |
| 246 | |||
| 247 | TODO | ||
| 248 | |||
| 249 | ### Error Union Type | ||
| 246 | 250 | ||
| 247 | TODO | 251 | TODO |
| 248 | 252 | ||
| ... | @@ -334,35 +338,43 @@ TODO | ... | @@ -334,35 +338,43 @@ TODO |
| 334 | 338 | ||
| 335 | Built-in functions are prefixed with `@`. | 339 | Built-in functions are prefixed with `@`. |
| 336 | 340 | ||
| 337 | ### Typeof | 341 | ### @typeof |
| 338 | 342 | ||
| 339 | TODO | 343 | `@typeof(expression)` |
| 340 | 344 | ||
| 341 | ### Sizeof | 345 | ### @sizeof |
| 342 | 346 | ||
| 343 | TODO | 347 | `@sizeof(type)` |
| 344 | 348 | ||
| 345 | ### Overflow Arithmetic | 349 | ### Overflow Arithmetic |
| 346 | 350 | ||
| 347 | Overflow arithmetic functions have defined behavior on overflow or underflow. TODO what is that behaviour? | 351 | Overflow arithmetic functions have defined behavior on overflow or underflow. |
| 348 | 352 | ||
| 349 | 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. | 353 | The functions take an integer type, two variables of the specified type, and a |
| 354 | pointer to a variable of the specified type where the result is stored. The | ||
| 355 | functions return a boolean value: true of overflow/underflow occurred, false | ||
| 356 | otherwise. | ||
| 350 | 357 | ||
| 351 | ``` | 358 | ``` |
| 352 | Function Operation | 359 | Function Operation |
| 353 | bool add_with_overflow(T: type, a: T, b: T, x: &T) *x = a + b | 360 | @add_with_overflow(T: type, a: T, b: T, x: &T) -> bool *x = a + b |
| 354 | bool sub_with_overflow(T: type, a: T, b: T, x: &T) *x = a - b | 361 | @sub_with_overflow(T: type, a: T, b: T, x: &T) -> bool *x = a - b |
| 355 | bool mul_with_overflow(T: type, a: T, b: T, x: &T) *x = a * b | 362 | @mul_with_overflow(T: type, a: T, b: T, x: &T) -> bool *x = a * b |
| 356 | ``` | 363 | ``` |
| 357 | 364 | ||
| 358 | ### Memory Operations | 365 | ### @memset |
| 359 | 366 | ||
| 360 | TODO memset and memcpy | 367 | `@memset(dest, char, len)` |
| 361 | 368 | ||
| 362 | ### Value Count | 369 | ### @memcpy |
| 363 | 370 | ||
| 364 | TODO | 371 | `@memcpy(dest, source, len)` |
| 372 | |||
| 373 | ### @member_count | ||
| 374 | |||
| 375 | `@member_count(enum_type)` | ||
| 365 | 376 | ||
| 366 | ### Max and Min Value | 377 | ### Max and Min Value |
| 367 | 378 | ||
| 368 | TODO | 379 | `@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 | } |
| 44 | 44 | ||
| 45 | static int print_target_list(FILE *f) { | 45 | static 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 | } |
| 66 | 78 | ||
| 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 | } |
| 73 | 86 | ||
| 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 | } |
| 538 | 538 | ||
| 539 | void 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 | //------------------------------------ |
| 540 | 555 | ||
| 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); |
| 288 | const char *ZigLLVMGetOSTypeName(ZigLLVM_OSType os); | 288 | const char *ZigLLVMGetOSTypeName(ZigLLVM_OSType os); |
| 289 | const char *ZigLLVMGetEnvironmentTypeName(ZigLLVM_EnvironmentType environ); | 289 | const char *ZigLLVMGetEnvironmentTypeName(ZigLLVM_EnvironmentType environ); |
| 290 | 290 | ||
| 291 | void ZigLLVMGetNativeTarget(ZigLLVM_ArchType *arch_type, ZigLLVM_SubArchType *sub_arch_type, | ||
| 292 | ZigLLVM_VendorType *vendor_type, ZigLLVM_OSType *os_type, ZigLLVM_EnvironmentType *environ_type); | ||
| 293 | |||
| 291 | 294 | ||
| 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. |