| author | |
| committer | |
| log | 6fece14cfbb852c108c2094ae0879da76f2f445e |
| tree | c2cde629583a94556d65dbc376e0809124550828 |
| parent | 2a25398c869fcdefe8b6508974a5c463ca833520 |
Now the self-hosted compiler re-uses the same C++ code for interfacing
with LLVM as the C++ code.
It also links against the same LLD library files.22 files changed, 736 insertions(+), 461 deletions(-)
CMakeLists.txt+9-13| ... | @@ -49,6 +49,8 @@ option(ZIG_FORCE_EXTERNAL_LLD "If your system has the LLD patches use it instead | ... | @@ -49,6 +49,8 @@ option(ZIG_FORCE_EXTERNAL_LLD "If your system has the LLD patches use it instead |
| 49 | find_package(llvm) | 49 | find_package(llvm) |
| 50 | find_package(clang) | 50 | find_package(clang) |
| 51 | 51 | ||
| 52 | set(ZIG_CPP_LIB_DIR "${CMAKE_BINARY_DIR}/zig_cpp") | ||
| 53 | |||
| 52 | if(ZIG_FORCE_EXTERNAL_LLD) | 54 | if(ZIG_FORCE_EXTERNAL_LLD) |
| 53 | find_package(lld) | 55 | find_package(lld) |
| 54 | include_directories(${LLVM_INCLUDE_DIRS}) | 56 | include_directories(${LLVM_INCLUDE_DIRS}) |
| ... | @@ -192,6 +194,7 @@ else() | ... | @@ -192,6 +194,7 @@ else() |
| 192 | embedded_lld_coff | 194 | embedded_lld_coff |
| 193 | embedded_lld_lib | 195 | embedded_lld_lib |
| 194 | ) | 196 | ) |
| 197 | install(TARGETS embedded_lld_elf embedded_lld_coff embedded_lld_lib DESTINATION "${ZIG_CPP_LIB_DIR}") | ||
| 195 | endif() | 198 | endif() |
| 196 | 199 | ||
| 197 | # No patches have been applied to SoftFloat-3d | 200 | # No patches have been applied to SoftFloat-3d |
| ... | @@ -345,6 +348,8 @@ set(ZIG_SOURCES | ... | @@ -345,6 +348,8 @@ set(ZIG_SOURCES |
| 345 | "${CMAKE_SOURCE_DIR}/src/tokenizer.cpp" | 348 | "${CMAKE_SOURCE_DIR}/src/tokenizer.cpp" |
| 346 | "${CMAKE_SOURCE_DIR}/src/util.cpp" | 349 | "${CMAKE_SOURCE_DIR}/src/util.cpp" |
| 347 | "${CMAKE_SOURCE_DIR}/src/translate_c.cpp" | 350 | "${CMAKE_SOURCE_DIR}/src/translate_c.cpp" |
| 351 | ) | ||
| 352 | set(ZIG_CPP_SOURCES | ||
| 348 | "${CMAKE_SOURCE_DIR}/src/zig_llvm.cpp" | 353 | "${CMAKE_SOURCE_DIR}/src/zig_llvm.cpp" |
| 349 | ) | 354 | ) |
| 350 | 355 | ||
| ... | @@ -390,6 +395,8 @@ if(ZIG_TEST_COVERAGE) | ... | @@ -390,6 +395,8 @@ if(ZIG_TEST_COVERAGE) |
| 390 | set(EXE_LDFLAGS "${EXE_LDFLAGS} -fprofile-arcs -ftest-coverage") | 395 | set(EXE_LDFLAGS "${EXE_LDFLAGS} -fprofile-arcs -ftest-coverage") |
| 391 | endif() | 396 | endif() |
| 392 | 397 | ||
| 398 | add_library(zig_cpp STATIC ${ZIG_CPP_SOURCES}) | ||
| 399 | |||
| 393 | add_executable(zig ${ZIG_SOURCES}) | 400 | add_executable(zig ${ZIG_SOURCES}) |
| 394 | set_target_properties(zig PROPERTIES | 401 | set_target_properties(zig PROPERTIES |
| 395 | COMPILE_FLAGS ${EXE_CFLAGS} | 402 | COMPILE_FLAGS ${EXE_CFLAGS} |
| ... | @@ -397,6 +404,7 @@ set_target_properties(zig PROPERTIES | ... | @@ -397,6 +404,7 @@ set_target_properties(zig PROPERTIES |
| 397 | ) | 404 | ) |
| 398 | 405 | ||
| 399 | target_link_libraries(zig LINK_PUBLIC | 406 | target_link_libraries(zig LINK_PUBLIC |
| 407 | zig_cpp | ||
| 400 | ${SOFTFLOAT_LIBRARIES} | 408 | ${SOFTFLOAT_LIBRARIES} |
| 401 | ${CLANG_LIBRARIES} | 409 | ${CLANG_LIBRARIES} |
| 402 | ${LLD_LIBRARIES} | 410 | ${LLD_LIBRARIES} |
| ... | @@ -407,6 +415,7 @@ if(MSVC OR MINGW) | ... | @@ -407,6 +415,7 @@ if(MSVC OR MINGW) |
| 407 | target_link_libraries(zig LINK_PUBLIC version) | 415 | target_link_libraries(zig LINK_PUBLIC version) |
| 408 | endif() | 416 | endif() |
| 409 | install(TARGETS zig DESTINATION bin) | 417 | install(TARGETS zig DESTINATION bin) |
| 418 | install(TARGETS zig_cpp DESTINATION "${ZIG_CPP_LIB_DIR}") | ||
| 410 | 419 | ||
| 411 | install(FILES "${CMAKE_SOURCE_DIR}/c_headers/__clang_cuda_builtin_vars.h" DESTINATION "${C_HEADERS_DEST}") | 420 | install(FILES "${CMAKE_SOURCE_DIR}/c_headers/__clang_cuda_builtin_vars.h" DESTINATION "${C_HEADERS_DEST}") |
| 412 | install(FILES "${CMAKE_SOURCE_DIR}/c_headers/__clang_cuda_cmath.h" DESTINATION "${C_HEADERS_DEST}") | 421 | install(FILES "${CMAKE_SOURCE_DIR}/c_headers/__clang_cuda_cmath.h" DESTINATION "${C_HEADERS_DEST}") |
| ... | @@ -619,16 +628,3 @@ install(FILES "${CMAKE_SOURCE_DIR}/std/special/compiler_rt/udivti3.zig" DESTINAT | ... | @@ -619,16 +628,3 @@ install(FILES "${CMAKE_SOURCE_DIR}/std/special/compiler_rt/udivti3.zig" DESTINAT |
| 619 | install(FILES "${CMAKE_SOURCE_DIR}/std/special/compiler_rt/umodti3.zig" DESTINATION "${ZIG_STD_DEST}/special/compiler_rt") | 628 | install(FILES "${CMAKE_SOURCE_DIR}/std/special/compiler_rt/umodti3.zig" DESTINATION "${ZIG_STD_DEST}/special/compiler_rt") |
| 620 | install(FILES "${CMAKE_SOURCE_DIR}/std/special/panic.zig" DESTINATION "${ZIG_STD_DEST}/special") | 629 | install(FILES "${CMAKE_SOURCE_DIR}/std/special/panic.zig" DESTINATION "${ZIG_STD_DEST}/special") |
| 621 | install(FILES "${CMAKE_SOURCE_DIR}/std/special/test_runner.zig" DESTINATION "${ZIG_STD_DEST}/special") | 630 | install(FILES "${CMAKE_SOURCE_DIR}/std/special/test_runner.zig" DESTINATION "${ZIG_STD_DEST}/special") |
| 622 | |||
| 623 | if (ZIG_TEST_COVERAGE) | ||
| 624 | add_custom_target(coverage | ||
| 625 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR} | ||
| 626 | COMMAND lcov --directory . --zerocounters --rc lcov_branch_coverage=1 | ||
| 627 | COMMAND ./zig build --build-file ../build.zig test | ||
| 628 | COMMAND lcov --directory . --capture --output-file coverage.info --rc lcov_branch_coverage=1 | ||
| 629 | COMMAND lcov --remove coverage.info '/usr/*' --output-file coverage.info.cleaned --rc lcov_branch_coverage=1 | ||
| 630 | COMMAND genhtml -o coverage coverage.info.cleaned --rc lcov_branch_coverage=1 | ||
| 631 | COMMAND rm coverage.info coverage.info.cleaned | ||
| 632 | ) | ||
| 633 | endif() | ||
| 634 |
README.md+10-20| ... | @@ -26,7 +26,7 @@ clarity. | ... | @@ -26,7 +26,7 @@ clarity. |
| 26 | always compiled against statically in source form. Compile units do not | 26 | always compiled against statically in source form. Compile units do not |
| 27 | depend on libc unless explicitly linked. | 27 | depend on libc unless explicitly linked. |
| 28 | * Nullable type instead of null pointers. | 28 | * Nullable type instead of null pointers. |
| 29 | * Tagged union type instead of raw unions. | 29 | * Safe unions, tagged unions, and C ABI compatible unions. |
| 30 | * Generics so that one can write efficient data structures that work for any | 30 | * Generics so that one can write efficient data structures that work for any |
| 31 | data type. | 31 | data type. |
| 32 | * No header files required. Top level declarations are entirely | 32 | * No header files required. Top level declarations are entirely |
| ... | @@ -35,7 +35,7 @@ clarity. | ... | @@ -35,7 +35,7 @@ clarity. |
| 35 | * Partial compile-time function evaluation with eliminates the need for | 35 | * Partial compile-time function evaluation with eliminates the need for |
| 36 | a preprocessor or macros. | 36 | a preprocessor or macros. |
| 37 | * The binaries produced by Zig have complete debugging information so you can, | 37 | * The binaries produced by Zig have complete debugging information so you can, |
| 38 | for example, use GDB to debug your software. | 38 | for example, use GDB or MSVC to debug your software. |
| 39 | * Built-in unit tests with `zig test`. | 39 | * Built-in unit tests with `zig test`. |
| 40 | * Friendly toward package maintainers. Reproducible build, bootstrapping | 40 | * Friendly toward package maintainers. Reproducible build, bootstrapping |
| 41 | process carefully documented. Issues filed by package maintainers are | 41 | process carefully documented. Issues filed by package maintainers are |
| ... | @@ -78,10 +78,10 @@ that counts as "freestanding" for the purposes of this table. | ... | @@ -78,10 +78,10 @@ that counts as "freestanding" for the purposes of this table. |
| 78 | 78 | ||
| 79 | ### Wanted: Windows Developers | 79 | ### Wanted: Windows Developers |
| 80 | 80 | ||
| 81 | Help get the tests passing on Windows, flesh out the standard library for | 81 | Flesh out the standard library for Windows, streamline Zig installation and |
| 82 | Windows, streamline Zig installation and distribution for Windows. Work with | 82 | distribution for Windows. Work with LLVM and LLD teams to improve |
| 83 | LLVM and LLD teams to improve PDB/CodeView/MSVC debugging. Implement stack traces | 83 | PDB/CodeView/MSVC debugging. Implement stack traces for Windows in the MinGW |
| 84 | for Windows in the MinGW environment and the MSVC environment. | 84 | environment and the MSVC environment. |
| 85 | 85 | ||
| 86 | ### Wanted: MacOS and iOS Developers | 86 | ### Wanted: MacOS and iOS Developers |
| 87 | 87 | ||
| ... | @@ -178,6 +178,10 @@ Dependencies are the same as Stage 1, except now you have a working zig compiler | ... | @@ -178,6 +178,10 @@ Dependencies are the same as Stage 1, except now you have a working zig compiler |
| 178 | bin/zig build --build-file ../build.zig --prefix $(pwd)/stage2 install | 178 | bin/zig build --build-file ../build.zig --prefix $(pwd)/stage2 install |
| 179 | ``` | 179 | ``` |
| 180 | 180 | ||
| 181 | This produces `./stage2/bin/zig` which can be used for testing and development. | ||
| 182 | Once it is feature complete, it will be used to build stage 3 - the final compiler | ||
| 183 | binary. | ||
| 184 | |||
| 181 | ### Stage 3: Rebuild Self-Hosted Zig Using the Self-Hosted Compiler | 185 | ### Stage 3: Rebuild Self-Hosted Zig Using the Self-Hosted Compiler |
| 182 | 186 | ||
| 183 | This is the actual compiler binary that we will install to the system. | 187 | This is the actual compiler binary that we will install to the system. |
| ... | @@ -194,20 +198,6 @@ This is the actual compiler binary that we will install to the system. | ... | @@ -194,20 +198,6 @@ This is the actual compiler binary that we will install to the system. |
| 194 | ./stage2/bin/zig build --build-file ../build.zig install -Drelease-fast | 198 | ./stage2/bin/zig build --build-file ../build.zig install -Drelease-fast |
| 195 | ``` | 199 | ``` |
| 196 | 200 | ||
| 197 | ### Test Coverage | ||
| 198 | |||
| 199 | To see test coverage in Zig, configure with `-DZIG_TEST_COVERAGE=ON` as an | ||
| 200 | additional parameter to the Debug build. | ||
| 201 | |||
| 202 | You must have `lcov` installed and available. | ||
| 203 | |||
| 204 | Then `make coverage`. | ||
| 205 | |||
| 206 | With GCC you will get a nice HTML view of the coverage data. With clang, | ||
| 207 | the last step will fail, but you can execute | ||
| 208 | `llvm-cov gcov $(find CMakeFiles/ -name "*.gcda")` and then inspect the | ||
| 209 | produced .gcov files. | ||
| 210 | |||
| 211 | ### Related Projects | 201 | ### Related Projects |
| 212 | 202 | ||
| 213 | * [zig-mode](https://github.com/AndreaOrru/zig-mode) - Emacs integration | 203 | * [zig-mode](https://github.com/AndreaOrru/zig-mode) - Emacs integration |
build.zig+28-1| ... | @@ -1,3 +1,4 @@ | ... | @@ -1,3 +1,4 @@ |
| 1 | const builtin = @import("builtin"); | ||
| 1 | const std = @import("std"); | 2 | const std = @import("std"); |
| 2 | const Builder = std.build.Builder; | 3 | const Builder = std.build.Builder; |
| 3 | const tests = @import("test/tests.zig"); | 4 | const tests = @import("test/tests.zig"); |
| ... | @@ -33,11 +34,32 @@ pub fn build(b: &Builder) { | ... | @@ -33,11 +34,32 @@ pub fn build(b: &Builder) { |
| 33 | docs_step.dependOn(&docgen_home_cmd.step); | 34 | docs_step.dependOn(&docgen_home_cmd.step); |
| 34 | 35 | ||
| 35 | if (findLLVM(b)) |llvm| { | 36 | if (findLLVM(b)) |llvm| { |
| 37 | // find the stage0 build artifacts because we're going to re-use config.h and zig_cpp library | ||
| 38 | const build_info = b.exec([][]const u8{b.zig_exe, "BUILD_INFO"}); | ||
| 39 | var build_info_it = mem.split(build_info, "\n"); | ||
| 40 | const cmake_binary_dir = ??build_info_it.next(); | ||
| 41 | const cxx_compiler = ??build_info_it.next(); | ||
| 42 | |||
| 36 | var exe = b.addExecutable("zig", "src-self-hosted/main.zig"); | 43 | var exe = b.addExecutable("zig", "src-self-hosted/main.zig"); |
| 37 | exe.setBuildMode(mode); | 44 | exe.setBuildMode(mode); |
| 38 | exe.linkSystemLibrary("c"); | 45 | exe.addIncludeDir("src"); |
| 46 | exe.addIncludeDir(cmake_binary_dir); | ||
| 47 | addCppLib(b, exe, cmake_binary_dir, "libzig_cpp"); | ||
| 48 | addCppLib(b, exe, cmake_binary_dir, "libembedded_lld_elf"); | ||
| 49 | addCppLib(b, exe, cmake_binary_dir, "libembedded_lld_coff"); | ||
| 50 | addCppLib(b, exe, cmake_binary_dir, "libembedded_lld_lib"); | ||
| 39 | dependOnLib(exe, llvm); | 51 | dependOnLib(exe, llvm); |
| 40 | 52 | ||
| 53 | if (!exe.target.isWindows()) { | ||
| 54 | const libstdcxx_path_padded = b.exec([][]const u8{cxx_compiler, "-print-file-name=libstdc++.a"}); | ||
| 55 | const libstdcxx_path = ??mem.split(libstdcxx_path_padded, "\n").next(); | ||
| 56 | exe.addObjectFile(libstdcxx_path); | ||
| 57 | |||
| 58 | exe.linkSystemLibrary("pthread"); | ||
| 59 | } | ||
| 60 | |||
| 61 | exe.linkSystemLibrary("c"); | ||
| 62 | |||
| 41 | b.default_step.dependOn(&exe.step); | 63 | b.default_step.dependOn(&exe.step); |
| 42 | b.default_step.dependOn(docs_step); | 64 | b.default_step.dependOn(docs_step); |
| 43 | 65 | ||
| ... | @@ -91,6 +113,11 @@ fn dependOnLib(lib_exe_obj: &std.build.LibExeObjStep, dep: &const LibraryDep) { | ... | @@ -91,6 +113,11 @@ fn dependOnLib(lib_exe_obj: &std.build.LibExeObjStep, dep: &const LibraryDep) { |
| 91 | } | 113 | } |
| 92 | } | 114 | } |
| 93 | 115 | ||
| 116 | fn addCppLib(b: &Builder, lib_exe_obj: &std.build.LibExeObjStep, cmake_binary_dir: []const u8, lib_name: []const u8) { | ||
| 117 | lib_exe_obj.addObjectFile(%%os.path.join(b.allocator, cmake_binary_dir, "zig_cpp", | ||
| 118 | b.fmt("{}{}", lib_name, lib_exe_obj.target.libFileExt()))); | ||
| 119 | } | ||
| 120 | |||
| 94 | const LibraryDep = struct { | 121 | const LibraryDep = struct { |
| 95 | libdirs: ArrayList([]const u8), | 122 | libdirs: ArrayList([]const u8), |
| 96 | libs: ArrayList([]const u8), | 123 | libs: ArrayList([]const u8), |
src-self-hosted/c.zig+2-5| ... | @@ -1,7 +1,4 @@ | ... | @@ -1,7 +1,4 @@ |
| 1 | pub use @cImport({ | 1 | pub use @cImport({ |
| 2 | @cInclude("llvm-c/Core.h"); | 2 | @cInclude("config.h"); |
| 3 | @cInclude("llvm-c/Analysis.h"); | 3 | @cInclude("zig_llvm.h"); |
| 4 | @cInclude("llvm-c/Target.h"); | ||
| 5 | @cInclude("llvm-c/Initialization.h"); | ||
| 6 | @cInclude("llvm-c/TargetMachine.h"); | ||
| 7 | }); | 4 | }); |
src-self-hosted/ir.zig created+112| ... | @@ -0,0 +1,112 @@ | ||
| 1 | const Scope = @import("scope.zig").Scope; | ||
| 2 | |||
| 3 | pub const Instruction = struct { | ||
| 4 | id: Id, | ||
| 5 | scope: &Scope, | ||
| 6 | |||
| 7 | pub const Id = enum { | ||
| 8 | Br, | ||
| 9 | CondBr, | ||
| 10 | SwitchBr, | ||
| 11 | SwitchVar, | ||
| 12 | SwitchTarget, | ||
| 13 | Phi, | ||
| 14 | UnOp, | ||
| 15 | BinOp, | ||
| 16 | DeclVar, | ||
| 17 | LoadPtr, | ||
| 18 | StorePtr, | ||
| 19 | FieldPtr, | ||
| 20 | StructFieldPtr, | ||
| 21 | UnionFieldPtr, | ||
| 22 | ElemPtr, | ||
| 23 | VarPtr, | ||
| 24 | Call, | ||
| 25 | Const, | ||
| 26 | Return, | ||
| 27 | Cast, | ||
| 28 | ContainerInitList, | ||
| 29 | ContainerInitFields, | ||
| 30 | StructInit, | ||
| 31 | UnionInit, | ||
| 32 | Unreachable, | ||
| 33 | TypeOf, | ||
| 34 | ToPtrType, | ||
| 35 | PtrTypeChild, | ||
| 36 | SetDebugSafety, | ||
| 37 | SetFloatMode, | ||
| 38 | ArrayType, | ||
| 39 | SliceType, | ||
| 40 | Asm, | ||
| 41 | SizeOf, | ||
| 42 | TestNonNull, | ||
| 43 | UnwrapMaybe, | ||
| 44 | MaybeWrap, | ||
| 45 | UnionTag, | ||
| 46 | Clz, | ||
| 47 | Ctz, | ||
| 48 | Import, | ||
| 49 | CImport, | ||
| 50 | CInclude, | ||
| 51 | CDefine, | ||
| 52 | CUndef, | ||
| 53 | ArrayLen, | ||
| 54 | Ref, | ||
| 55 | MinValue, | ||
| 56 | MaxValue, | ||
| 57 | CompileErr, | ||
| 58 | CompileLog, | ||
| 59 | ErrName, | ||
| 60 | EmbedFile, | ||
| 61 | Cmpxchg, | ||
| 62 | Fence, | ||
| 63 | Truncate, | ||
| 64 | IntType, | ||
| 65 | BoolNot, | ||
| 66 | Memset, | ||
| 67 | Memcpy, | ||
| 68 | Slice, | ||
| 69 | MemberCount, | ||
| 70 | MemberType, | ||
| 71 | MemberName, | ||
| 72 | Breakpoint, | ||
| 73 | ReturnAddress, | ||
| 74 | FrameAddress, | ||
| 75 | AlignOf, | ||
| 76 | OverflowOp, | ||
| 77 | TestErr, | ||
| 78 | UnwrapErrCode, | ||
| 79 | UnwrapErrPayload, | ||
| 80 | ErrWrapCode, | ||
| 81 | ErrWrapPayload, | ||
| 82 | FnProto, | ||
| 83 | TestComptime, | ||
| 84 | PtrCast, | ||
| 85 | BitCast, | ||
| 86 | WidenOrShorten, | ||
| 87 | IntToPtr, | ||
| 88 | PtrToInt, | ||
| 89 | IntToEnum, | ||
| 90 | IntToErr, | ||
| 91 | ErrToInt, | ||
| 92 | CheckSwitchProngs, | ||
| 93 | CheckStatementIsVoid, | ||
| 94 | TypeName, | ||
| 95 | CanImplicitCast, | ||
| 96 | DeclRef, | ||
| 97 | Panic, | ||
| 98 | TagName, | ||
| 99 | TagType, | ||
| 100 | FieldParentPtr, | ||
| 101 | OffsetOf, | ||
| 102 | TypeId, | ||
| 103 | SetEvalBranchQuota, | ||
| 104 | PtrTypeOf, | ||
| 105 | AlignCast, | ||
| 106 | OpaqueType, | ||
| 107 | SetAlignStack, | ||
| 108 | ArgType, | ||
| 109 | Export, | ||
| 110 | }; | ||
| 111 | |||
| 112 | }; | ||
src-self-hosted/main.zig+6-1| ... | @@ -12,6 +12,7 @@ const ErrColor = Module.ErrColor; | ... | @@ -12,6 +12,7 @@ const ErrColor = Module.ErrColor; |
| 12 | const Emit = Module.Emit; | 12 | const Emit = Module.Emit; |
| 13 | const builtin = @import("builtin"); | 13 | const builtin = @import("builtin"); |
| 14 | const ArrayList = std.ArrayList; | 14 | const ArrayList = std.ArrayList; |
| 15 | const c = @import("c.zig"); | ||
| 15 | 16 | ||
| 16 | error InvalidCommandLineArguments; | 17 | error InvalidCommandLineArguments; |
| 17 | error ZigLibDirNotFound; | 18 | error ZigLibDirNotFound; |
| ... | @@ -462,7 +463,11 @@ pub fn main2() -> %void { | ... | @@ -462,7 +463,11 @@ pub fn main2() -> %void { |
| 462 | else => unreachable, | 463 | else => unreachable, |
| 463 | } | 464 | } |
| 464 | }, | 465 | }, |
| 465 | Cmd.Version => @panic("TODO zig version"), | 466 | Cmd.Version => { |
| 467 | var stdout_file = %return io.getStdErr(); | ||
| 468 | %return stdout_file.write(std.cstr.toSliceConst(c.ZIG_VERSION_STRING)); | ||
| 469 | %return stdout_file.write("\n"); | ||
| 470 | }, | ||
| 466 | Cmd.Targets => @panic("TODO zig targets"), | 471 | Cmd.Targets => @panic("TODO zig targets"), |
| 467 | } | 472 | } |
| 468 | } | 473 | } |
src-self-hosted/module.zig+7| ... | @@ -199,6 +199,13 @@ pub const Module = struct { | ... | @@ -199,6 +199,13 @@ pub const Module = struct { |
| 199 | } | 199 | } |
| 200 | 200 | ||
| 201 | pub fn build(self: &Module) -> %void { | 201 | pub fn build(self: &Module) -> %void { |
| 202 | if (self.llvm_argv.len != 0) { | ||
| 203 | var c_compatible_args = %return std.cstr.NullTerminated2DArray.fromSlices(self.allocator, | ||
| 204 | [][]const []const u8 { [][]const u8{"zig (LLVM option parsing)"}, self.llvm_argv, }); | ||
| 205 | defer c_compatible_args.deinit(); | ||
| 206 | c.ZigLLVMParseCommandLineOptions(self.llvm_argv.len + 1, c_compatible_args.ptr); | ||
| 207 | } | ||
| 208 | |||
| 202 | const root_src_path = self.root_src_path ?? @panic("TODO handle null root src path"); | 209 | const root_src_path = self.root_src_path ?? @panic("TODO handle null root src path"); |
| 203 | const root_src_real_path = os.path.real(self.allocator, root_src_path) %% |err| { | 210 | const root_src_real_path = os.path.real(self.allocator, root_src_path) %% |err| { |
| 204 | %return printError("unable to open '{}': {}", root_src_path, err); | 211 | %return printError("unable to open '{}': {}", root_src_path, err); |
src-self-hosted/scope.zig created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | pub const Scope = struct { | ||
| 2 | id: Id, | ||
| 3 | parent: &Scope, | ||
| 4 | |||
| 5 | pub const Id = enum { | ||
| 6 | Decls, | ||
| 7 | Block, | ||
| 8 | Defer, | ||
| 9 | DeferExpr, | ||
| 10 | VarDecl, | ||
| 11 | CImport, | ||
| 12 | Loop, | ||
| 13 | FnDef, | ||
| 14 | CompTime, | ||
| 15 | }; | ||
| 16 | }; | ||
src/all_types.hpp+1-1| ... | @@ -10,7 +10,7 @@ | ... | @@ -10,7 +10,7 @@ |
| 10 | 10 | ||
| 11 | #include "list.hpp" | 11 | #include "list.hpp" |
| 12 | #include "buffer.hpp" | 12 | #include "buffer.hpp" |
| 13 | #include "zig_llvm.hpp" | 13 | #include "zig_llvm.h" |
| 14 | #include "hash_map.hpp" | 14 | #include "hash_map.hpp" |
| 15 | #include "errmsg.hpp" | 15 | #include "errmsg.hpp" |
| 16 | #include "bigint.hpp" | 16 | #include "bigint.hpp" |
src/analyze.cpp+1-1| ... | @@ -14,7 +14,7 @@ | ... | @@ -14,7 +14,7 @@ |
| 14 | #include "os.hpp" | 14 | #include "os.hpp" |
| 15 | #include "parser.hpp" | 15 | #include "parser.hpp" |
| 16 | #include "softfloat.hpp" | 16 | #include "softfloat.hpp" |
| 17 | #include "zig_llvm.hpp" | 17 | #include "zig_llvm.h" |
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | static const size_t default_backward_branch_quota = 1000; | 20 | static const size_t default_backward_branch_quota = 1000; |
src/codegen.cpp+1-1| ... | @@ -17,7 +17,7 @@ | ... | @@ -17,7 +17,7 @@ |
| 17 | #include "os.hpp" | 17 | #include "os.hpp" |
| 18 | #include "translate_c.hpp" | 18 | #include "translate_c.hpp" |
| 19 | #include "target.hpp" | 19 | #include "target.hpp" |
| 20 | #include "zig_llvm.hpp" | 20 | #include "zig_llvm.h" |
| 21 | 21 | ||
| 22 | #include <stdio.h> | 22 | #include <stdio.h> |
| 23 | #include <errno.h> | 23 | #include <errno.h> |
src/config.h.in+4| ... | @@ -24,4 +24,8 @@ | ... | @@ -24,4 +24,8 @@ |
| 24 | // Only used for running tests before installing. | 24 | // Only used for running tests before installing. |
| 25 | #define ZIG_TEST_DIR "@CMAKE_SOURCE_DIR@/test" | 25 | #define ZIG_TEST_DIR "@CMAKE_SOURCE_DIR@/test" |
| 26 | 26 | ||
| 27 | // Used for communicating build information to self hosted build. | ||
| 28 | #define ZIG_CMAKE_BINARY_DIR "@CMAKE_BINARY_DIR@" | ||
| 29 | #define ZIG_CXX_COMPILER "@CMAKE_CXX_COMPILER@" | ||
| 30 | |||
| 27 | #endif | 31 | #endif |
src/link.cpp+12-2| ... | @@ -351,6 +351,16 @@ static void coff_append_machine_arg(CodeGen *g, ZigList<const char *> *list) { | ... | @@ -351,6 +351,16 @@ static void coff_append_machine_arg(CodeGen *g, ZigList<const char *> *list) { |
| 351 | } | 351 | } |
| 352 | } | 352 | } |
| 353 | 353 | ||
| 354 | static void link_diag_callback(void *context, const char *ptr, size_t len) { | ||
| 355 | Buf *diag = reinterpret_cast<Buf *>(context); | ||
| 356 | buf_append_mem(diag, ptr, len); | ||
| 357 | } | ||
| 358 | |||
| 359 | static bool zig_lld_link(ZigLLVM_ObjectFormatType oformat, const char **args, size_t arg_count, Buf *diag) { | ||
| 360 | buf_resize(diag, 0); | ||
| 361 | return ZigLLDLink(oformat, args, arg_count, link_diag_callback, diag); | ||
| 362 | } | ||
| 363 | |||
| 354 | static void construct_linker_job_coff(LinkJob *lj) { | 364 | static void construct_linker_job_coff(LinkJob *lj) { |
| 355 | CodeGen *g = lj->codegen; | 365 | CodeGen *g = lj->codegen; |
| 356 | 366 | ||
| ... | @@ -515,7 +525,7 @@ static void construct_linker_job_coff(LinkJob *lj) { | ... | @@ -515,7 +525,7 @@ static void construct_linker_job_coff(LinkJob *lj) { |
| 515 | gen_lib_args.append(buf_ptr(buf_sprintf("-DEF:%s", buf_ptr(def_path)))); | 525 | gen_lib_args.append(buf_ptr(buf_sprintf("-DEF:%s", buf_ptr(def_path)))); |
| 516 | gen_lib_args.append(buf_ptr(buf_sprintf("-OUT:%s", buf_ptr(generated_lib_path)))); | 526 | gen_lib_args.append(buf_ptr(buf_sprintf("-OUT:%s", buf_ptr(generated_lib_path)))); |
| 517 | Buf diag = BUF_INIT; | 527 | Buf diag = BUF_INIT; |
| 518 | if (!ZigLLDLink(g->zig_target.oformat, gen_lib_args.items, gen_lib_args.length, &diag)) { | 528 | if (!zig_lld_link(g->zig_target.oformat, gen_lib_args.items, gen_lib_args.length, &diag)) { |
| 519 | fprintf(stderr, "%s\n", buf_ptr(&diag)); | 529 | fprintf(stderr, "%s\n", buf_ptr(&diag)); |
| 520 | exit(1); | 530 | exit(1); |
| 521 | } | 531 | } |
| ... | @@ -930,7 +940,7 @@ void codegen_link(CodeGen *g, const char *out_file) { | ... | @@ -930,7 +940,7 @@ void codegen_link(CodeGen *g, const char *out_file) { |
| 930 | Buf diag = BUF_INIT; | 940 | Buf diag = BUF_INIT; |
| 931 | 941 | ||
| 932 | codegen_add_time_event(g, "LLVM Link"); | 942 | codegen_add_time_event(g, "LLVM Link"); |
| 933 | if (!ZigLLDLink(g->zig_target.oformat, lj.args.items, lj.args.length, &diag)) { | 943 | if (!zig_lld_link(g->zig_target.oformat, lj.args.items, lj.args.length, &diag)) { |
| 934 | fprintf(stderr, "%s\n", buf_ptr(&diag)); | 944 | fprintf(stderr, "%s\n", buf_ptr(&diag)); |
| 935 | exit(1); | 945 | exit(1); |
| 936 | } | 946 | } |
src/main.cpp+5| ... | @@ -266,6 +266,11 @@ static void add_package(CodeGen *g, CliPkg *cli_pkg, PackageTableEntry *pkg) { | ... | @@ -266,6 +266,11 @@ static void add_package(CodeGen *g, CliPkg *cli_pkg, PackageTableEntry *pkg) { |
| 266 | } | 266 | } |
| 267 | 267 | ||
| 268 | int main(int argc, char **argv) { | 268 | int main(int argc, char **argv) { |
| 269 | if (argc == 2 && strcmp(argv[1], "BUILD_INFO") == 0) { | ||
| 270 | printf("%s\n%s\n", ZIG_CMAKE_BINARY_DIR, ZIG_CXX_COMPILER); | ||
| 271 | return 0; | ||
| 272 | } | ||
| 273 | |||
| 269 | os_init(); | 274 | os_init(); |
| 270 | 275 | ||
| 271 | char *arg0 = argv[0]; | 276 | char *arg0 = argv[0]; |
src/os.hpp+1-1| ... | @@ -11,7 +11,7 @@ | ... | @@ -11,7 +11,7 @@ |
| 11 | #include "list.hpp" | 11 | #include "list.hpp" |
| 12 | #include "buffer.hpp" | 12 | #include "buffer.hpp" |
| 13 | #include "error.hpp" | 13 | #include "error.hpp" |
| 14 | #include "zig_llvm.hpp" | 14 | #include "zig_llvm.h" |
| 15 | 15 | ||
| 16 | #include <stdio.h> | 16 | #include <stdio.h> |
| 17 | #include <inttypes.h> | 17 | #include <inttypes.h> |
src/target.hpp+1-1| ... | @@ -8,7 +8,7 @@ | ... | @@ -8,7 +8,7 @@ |
| 8 | #ifndef ZIG_TARGET_HPP | 8 | #ifndef ZIG_TARGET_HPP |
| 9 | #define ZIG_TARGET_HPP | 9 | #define ZIG_TARGET_HPP |
| 10 | 10 | ||
| 11 | #include <zig_llvm.hpp> | 11 | #include <zig_llvm.h> |
| 12 | 12 | ||
| 13 | struct Buf; | 13 | struct Buf; |
| 14 | 14 |
src/util.hpp-2| ... | @@ -13,8 +13,6 @@ | ... | @@ -13,8 +13,6 @@ |
| 13 | #include <string.h> | 13 | #include <string.h> |
| 14 | #include <assert.h> | 14 | #include <assert.h> |
| 15 | 15 | ||
| 16 | #include <new> | ||
| 17 | |||
| 18 | #if defined(_MSC_VER) | 16 | #if defined(_MSC_VER) |
| 19 | 17 | ||
| 20 | #include <intrin.h> | 18 | #include <intrin.h> |
src/zig_llvm.cpp+65-29| ... | @@ -13,7 +13,7 @@ | ... | @@ -13,7 +13,7 @@ |
| 13 | * 3. Prevent C++ from infecting the rest of the project. | 13 | * 3. Prevent C++ from infecting the rest of the project. |
| 14 | */ | 14 | */ |
| 15 | 15 | ||
| 16 | #include "zig_llvm.hpp" | 16 | #include "zig_llvm.h" |
| 17 | 17 | ||
| 18 | #include <llvm/Analysis/TargetLibraryInfo.h> | 18 | #include <llvm/Analysis/TargetLibraryInfo.h> |
| 19 | #include <llvm/Analysis/TargetTransformInfo.h> | 19 | #include <llvm/Analysis/TargetTransformInfo.h> |
| ... | @@ -39,8 +39,35 @@ | ... | @@ -39,8 +39,35 @@ |
| 39 | 39 | ||
| 40 | #include <lld/Driver/Driver.h> | 40 | #include <lld/Driver/Driver.h> |
| 41 | 41 | ||
| 42 | #include <new> | ||
| 43 | |||
| 44 | #include <stdlib.h> | ||
| 45 | |||
| 46 | #if defined(_MSC_VER) | ||
| 47 | #define ATTRIBUTE_RETURNS_NOALIAS __declspec(restrict) | ||
| 48 | #else | ||
| 49 | #define ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__)) | ||
| 50 | #endif | ||
| 51 | |||
| 42 | using namespace llvm; | 52 | using namespace llvm; |
| 43 | 53 | ||
| 54 | template<typename T, typename... Args> | ||
| 55 | ATTRIBUTE_RETURNS_NOALIAS static inline T * create(Args... args) { | ||
| 56 | T * ptr = reinterpret_cast<T*>(malloc(sizeof(T))); | ||
| 57 | if (ptr == nullptr) | ||
| 58 | return nullptr; | ||
| 59 | new (ptr) T(args...); | ||
| 60 | return ptr; | ||
| 61 | } | ||
| 62 | |||
| 63 | template<typename T> | ||
| 64 | static inline void destroy(T * ptr) { | ||
| 65 | if (ptr != nullptr) { | ||
| 66 | ptr[0].~T(); | ||
| 67 | } | ||
| 68 | free(ptr); | ||
| 69 | } | ||
| 70 | |||
| 44 | void ZigLLVMInitializeLoopStrengthReducePass(LLVMPassRegistryRef R) { | 71 | void ZigLLVMInitializeLoopStrengthReducePass(LLVMPassRegistryRef R) { |
| 45 | initializeLoopStrengthReducePass(*unwrap(R)); | 72 | initializeLoopStrengthReducePass(*unwrap(R)); |
| 46 | } | 73 | } |
| ... | @@ -50,8 +77,7 @@ void ZigLLVMInitializeLowerIntrinsicsPass(LLVMPassRegistryRef R) { | ... | @@ -50,8 +77,7 @@ void ZigLLVMInitializeLowerIntrinsicsPass(LLVMPassRegistryRef R) { |
| 50 | } | 77 | } |
| 51 | 78 | ||
| 52 | char *ZigLLVMGetHostCPUName(void) { | 79 | char *ZigLLVMGetHostCPUName(void) { |
| 53 | std::string str = sys::getHostCPUName(); | 80 | return strdup((const char *)sys::getHostCPUName().bytes_begin()); |
| 54 | return strdup(str.c_str()); | ||
| 55 | } | 81 | } |
| 56 | 82 | ||
| 57 | char *ZigLLVMGetNativeFeatures(void) { | 83 | char *ZigLLVMGetNativeFeatures(void) { |
| ... | @@ -63,11 +89,11 @@ char *ZigLLVMGetNativeFeatures(void) { | ... | @@ -63,11 +89,11 @@ char *ZigLLVMGetNativeFeatures(void) { |
| 63 | features.AddFeature(F.first(), F.second); | 89 | features.AddFeature(F.first(), F.second); |
| 64 | } | 90 | } |
| 65 | 91 | ||
| 66 | return strdup(features.getString().c_str()); | 92 | return strdup((const char *)StringRef(features.getString()).bytes_begin()); |
| 67 | } | 93 | } |
| 68 | 94 | ||
| 69 | static void addDiscriminatorsPass(const PassManagerBuilder &Builder, legacy::PassManagerBase &PM) { | 95 | static void addDiscriminatorsPass(const PassManagerBuilder &Builder, legacy::PassManagerBase &PM) { |
| 70 | PM.add(createAddDiscriminatorsPass()); | 96 | PM.add(createAddDiscriminatorsPass()); |
| 71 | } | 97 | } |
| 72 | 98 | ||
| 73 | #ifndef NDEBUG | 99 | #ifndef NDEBUG |
| ... | @@ -82,7 +108,7 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM | ... | @@ -82,7 +108,7 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM |
| 82 | std::error_code EC; | 108 | std::error_code EC; |
| 83 | raw_fd_ostream dest(filename, EC, sys::fs::F_None); | 109 | raw_fd_ostream dest(filename, EC, sys::fs::F_None); |
| 84 | if (EC) { | 110 | if (EC) { |
| 85 | *error_message = strdup(EC.message().c_str()); | 111 | *error_message = strdup((const char *)StringRef(EC.message()).bytes_begin()); |
| 86 | return true; | 112 | return true; |
| 87 | } | 113 | } |
| 88 | TargetMachine* target_machine = reinterpret_cast<TargetMachine*>(targ_machine_ref); | 114 | TargetMachine* target_machine = reinterpret_cast<TargetMachine*>(targ_machine_ref); |
| ... | @@ -90,7 +116,7 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM | ... | @@ -90,7 +116,7 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM |
| 90 | 116 | ||
| 91 | Module* module = unwrap(module_ref); | 117 | Module* module = unwrap(module_ref); |
| 92 | 118 | ||
| 93 | PassManagerBuilder *PMBuilder = new PassManagerBuilder(); | 119 | PassManagerBuilder *PMBuilder = create<PassManagerBuilder>(); |
| 94 | PMBuilder->OptLevel = target_machine->getOptLevel(); | 120 | PMBuilder->OptLevel = target_machine->getOptLevel(); |
| 95 | PMBuilder->SizeLevel = 0; | 121 | PMBuilder->SizeLevel = 0; |
| 96 | 122 | ||
| ... | @@ -123,7 +149,7 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM | ... | @@ -123,7 +149,7 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM |
| 123 | 149 | ||
| 124 | // Set up the per-function pass manager. | 150 | // Set up the per-function pass manager. |
| 125 | legacy::FunctionPassManager FPM = legacy::FunctionPassManager(module); | 151 | legacy::FunctionPassManager FPM = legacy::FunctionPassManager(module); |
| 126 | FPM.add(new TargetLibraryInfoWrapperPass(tlii)); | 152 | FPM.add(create<TargetLibraryInfoWrapperPass>(tlii)); |
| 127 | FPM.add(createTargetTransformInfoWrapperPass(target_machine->getTargetIRAnalysis())); | 153 | FPM.add(createTargetTransformInfoWrapperPass(target_machine->getTargetIRAnalysis())); |
| 128 | if (assertions_on) { | 154 | if (assertions_on) { |
| 129 | FPM.add(createVerifierPass()); | 155 | FPM.add(createVerifierPass()); |
| ... | @@ -415,7 +441,10 @@ unsigned ZigLLVMTag_DW_union_type(void) { | ... | @@ -415,7 +441,10 @@ unsigned ZigLLVMTag_DW_union_type(void) { |
| 415 | } | 441 | } |
| 416 | 442 | ||
| 417 | ZigLLVMDIBuilder *ZigLLVMCreateDIBuilder(LLVMModuleRef module, bool allow_unresolved) { | 443 | ZigLLVMDIBuilder *ZigLLVMCreateDIBuilder(LLVMModuleRef module, bool allow_unresolved) { |
| 418 | DIBuilder *di_builder = new DIBuilder(*unwrap(module), allow_unresolved); | 444 | DIBuilder *di_builder = reinterpret_cast<DIBuilder*>(malloc(sizeof(DIBuilder))); |
| 445 | if (di_builder == nullptr) | ||
| 446 | return nullptr; | ||
| 447 | new (di_builder) DIBuilder(*unwrap(module), allow_unresolved); | ||
| 419 | return reinterpret_cast<ZigLLVMDIBuilder *>(di_builder); | 448 | return reinterpret_cast<ZigLLVMDIBuilder *>(di_builder); |
| 420 | } | 449 | } |
| 421 | 450 | ||
| ... | @@ -617,7 +646,7 @@ void ZigLLVMAddFunctionAttrCold(LLVMValueRef fn_ref) { | ... | @@ -617,7 +646,7 @@ void ZigLLVMAddFunctionAttrCold(LLVMValueRef fn_ref) { |
| 617 | func->setAttributes(new_attr_set); | 646 | func->setAttributes(new_attr_set); |
| 618 | } | 647 | } |
| 619 | 648 | ||
| 620 | void ZigLLVMParseCommandLineOptions(int argc, const char *const *argv) { | 649 | void ZigLLVMParseCommandLineOptions(size_t argc, const char *const *argv) { |
| 621 | llvm::cl::ParseCommandLineOptions(argc, argv); | 650 | llvm::cl::ParseCommandLineOptions(argc, argv); |
| 622 | } | 651 | } |
| 623 | 652 | ||
| ... | @@ -771,29 +800,35 @@ LLVMValueRef ZigLLVMBuildAShrExact(LLVMBuilderRef builder, LLVMValueRef LHS, LLV | ... | @@ -771,29 +800,35 @@ LLVMValueRef ZigLLVMBuildAShrExact(LLVMBuilderRef builder, LLVMValueRef LHS, LLV |
| 771 | } | 800 | } |
| 772 | 801 | ||
| 773 | 802 | ||
| 774 | #include "buffer.hpp" | 803 | class MyOStream: public raw_ostream { |
| 804 | public: | ||
| 805 | MyOStream(void (*_append_diagnostic)(void *, const char *, size_t), void *_context) : | ||
| 806 | raw_ostream(true), append_diagnostic(_append_diagnostic), context(_context), pos(0) { | ||
| 807 | |||
| 808 | } | ||
| 809 | void write_impl(const char *ptr, size_t len) override { | ||
| 810 | append_diagnostic(context, ptr, len); | ||
| 811 | pos += len; | ||
| 812 | } | ||
| 813 | uint64_t current_pos() const override { | ||
| 814 | return pos; | ||
| 815 | } | ||
| 816 | void (*append_diagnostic)(void *, const char *, size_t); | ||
| 817 | void *context; | ||
| 818 | size_t pos; | ||
| 819 | }; | ||
| 820 | |||
| 775 | 821 | ||
| 776 | bool ZigLLDLink(ZigLLVM_ObjectFormatType oformat, const char **args, size_t arg_count, Buf *diag_buf) { | 822 | bool ZigLLDLink(ZigLLVM_ObjectFormatType oformat, const char **args, size_t arg_count, |
| 823 | void (*append_diagnostic)(void *, const char *, size_t), void *context) | ||
| 824 | { | ||
| 777 | ArrayRef<const char *> array_ref_args(args, arg_count); | 825 | ArrayRef<const char *> array_ref_args(args, arg_count); |
| 778 | 826 | ||
| 779 | buf_resize(diag_buf, 0); | 827 | MyOStream diag(append_diagnostic, context); |
| 780 | class MyOStream: public raw_ostream { | ||
| 781 | public: | ||
| 782 | MyOStream(Buf *_diag_buf) : raw_ostream(true), diag_buf(_diag_buf) { | ||
| 783 | |||
| 784 | } | ||
| 785 | void write_impl(const char *ptr, size_t len) override { | ||
| 786 | buf_append_mem(diag_buf, ptr, len); | ||
| 787 | } | ||
| 788 | uint64_t current_pos() const override { | ||
| 789 | return buf_len(diag_buf); | ||
| 790 | } | ||
| 791 | Buf *diag_buf; | ||
| 792 | } diag(diag_buf); | ||
| 793 | 828 | ||
| 794 | switch (oformat) { | 829 | switch (oformat) { |
| 795 | case ZigLLVM_UnknownObjectFormat: | 830 | case ZigLLVM_UnknownObjectFormat: |
| 796 | zig_unreachable(); | 831 | assert(false); // unreachable |
| 797 | 832 | ||
| 798 | case ZigLLVM_COFF: | 833 | case ZigLLVM_COFF: |
| 799 | return lld::coff::link(array_ref_args, false, diag); | 834 | return lld::coff::link(array_ref_args, false, diag); |
| ... | @@ -805,7 +840,8 @@ bool ZigLLDLink(ZigLLVM_ObjectFormatType oformat, const char **args, size_t arg_ | ... | @@ -805,7 +840,8 @@ bool ZigLLDLink(ZigLLVM_ObjectFormatType oformat, const char **args, size_t arg_ |
| 805 | return lld::mach_o::link(array_ref_args, diag); | 840 | return lld::mach_o::link(array_ref_args, diag); |
| 806 | 841 | ||
| 807 | case ZigLLVM_Wasm: | 842 | case ZigLLVM_Wasm: |
| 808 | zig_panic("ZigLLDLink for Wasm"); | 843 | assert(false); // TODO ZigLLDLink for Wasm |
| 809 | } | 844 | } |
| 810 | zig_unreachable(); | 845 | assert(false); // unreachable |
| 846 | abort(); | ||
| 811 | } | 847 | } |
src/zig_llvm.h created+394| ... | @@ -0,0 +1,394 @@ | ||
| 1 | /* | ||
| 2 | * Copyright (c) 2015 Andrew Kelley | ||
| 3 | * | ||
| 4 | * This file is part of zig, which is MIT licensed. | ||
| 5 | * See http://opensource.org/licenses/MIT | ||
| 6 | */ | ||
| 7 | |||
| 8 | #ifndef ZIG_ZIG_LLVM_HPP | ||
| 9 | #define ZIG_ZIG_LLVM_HPP | ||
| 10 | |||
| 11 | #include <stdbool.h> | ||
| 12 | #include <stddef.h> | ||
| 13 | #include <llvm-c/Core.h> | ||
| 14 | #include <llvm-c/Analysis.h> | ||
| 15 | #include <llvm-c/Target.h> | ||
| 16 | #include <llvm-c/Initialization.h> | ||
| 17 | #include <llvm-c/TargetMachine.h> | ||
| 18 | |||
| 19 | #ifdef __cplusplus | ||
| 20 | #define ZIG_EXTERN_C extern "C" | ||
| 21 | #else | ||
| 22 | #define ZIG_EXTERN_C | ||
| 23 | #endif | ||
| 24 | |||
| 25 | struct ZigLLVMDIType; | ||
| 26 | struct ZigLLVMDIBuilder; | ||
| 27 | struct ZigLLVMDICompileUnit; | ||
| 28 | struct ZigLLVMDIScope; | ||
| 29 | struct ZigLLVMDIFile; | ||
| 30 | struct ZigLLVMDILexicalBlock; | ||
| 31 | struct ZigLLVMDISubprogram; | ||
| 32 | struct ZigLLVMDISubroutineType; | ||
| 33 | struct ZigLLVMDILocalVariable; | ||
| 34 | struct ZigLLVMDIGlobalVariable; | ||
| 35 | struct ZigLLVMDILocation; | ||
| 36 | struct ZigLLVMDIEnumerator; | ||
| 37 | struct ZigLLVMInsertionPoint; | ||
| 38 | |||
| 39 | ZIG_EXTERN_C void ZigLLVMInitializeLoopStrengthReducePass(LLVMPassRegistryRef R); | ||
| 40 | ZIG_EXTERN_C void ZigLLVMInitializeLowerIntrinsicsPass(LLVMPassRegistryRef R); | ||
| 41 | |||
| 42 | /// Caller must free memory. | ||
| 43 | ZIG_EXTERN_C char *ZigLLVMGetHostCPUName(void); | ||
| 44 | ZIG_EXTERN_C char *ZigLLVMGetNativeFeatures(void); | ||
| 45 | |||
| 46 | // We use a custom enum here since LLVM does not expose LLVMIr as an emit | ||
| 47 | // output through the same mechanism as assembly/binary. | ||
| 48 | enum ZigLLVM_EmitOutputType { | ||
| 49 | ZigLLVM_EmitAssembly, | ||
| 50 | ZigLLVM_EmitBinary, | ||
| 51 | ZigLLVM_EmitLLVMIr, | ||
| 52 | }; | ||
| 53 | |||
| 54 | ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref, | ||
| 55 | const char *filename, enum ZigLLVM_EmitOutputType output_type, char **error_message, bool is_debug); | ||
| 56 | |||
| 57 | enum ZigLLVM_FnInline { | ||
| 58 | ZigLLVM_FnInlineAuto, | ||
| 59 | ZigLLVM_FnInlineAlways, | ||
| 60 | ZigLLVM_FnInlineNever, | ||
| 61 | }; | ||
| 62 | ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *Args, | ||
| 63 | unsigned NumArgs, unsigned CC, enum ZigLLVM_FnInline fn_inline, const char *Name); | ||
| 64 | |||
| 65 | ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildCmpXchg(LLVMBuilderRef builder, LLVMValueRef ptr, LLVMValueRef cmp, | ||
| 66 | LLVMValueRef new_val, LLVMAtomicOrdering success_ordering, | ||
| 67 | LLVMAtomicOrdering failure_ordering); | ||
| 68 | |||
| 69 | ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildNSWShl(LLVMBuilderRef builder, LLVMValueRef LHS, LLVMValueRef RHS, | ||
| 70 | const char *name); | ||
| 71 | ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildNUWShl(LLVMBuilderRef builder, LLVMValueRef LHS, LLVMValueRef RHS, | ||
| 72 | const char *name); | ||
| 73 | ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildLShrExact(LLVMBuilderRef builder, LLVMValueRef LHS, LLVMValueRef RHS, | ||
| 74 | const char *name); | ||
| 75 | ZIG_EXTERN_C LLVMValueRef ZigLLVMBuildAShrExact(LLVMBuilderRef builder, LLVMValueRef LHS, LLVMValueRef RHS, | ||
| 76 | const char *name); | ||
| 77 | |||
| 78 | ZIG_EXTERN_C struct ZigLLVMDIType *ZigLLVMCreateDebugPointerType(struct ZigLLVMDIBuilder *dibuilder, | ||
| 79 | struct ZigLLVMDIType *pointee_type, uint64_t size_in_bits, uint64_t align_in_bits, const char *name); | ||
| 80 | |||
| 81 | ZIG_EXTERN_C struct ZigLLVMDIType *ZigLLVMCreateDebugBasicType(struct ZigLLVMDIBuilder *dibuilder, const char *name, | ||
| 82 | uint64_t size_in_bits, unsigned encoding); | ||
| 83 | |||
| 84 | ZIG_EXTERN_C struct ZigLLVMDIType *ZigLLVMCreateDebugArrayType(struct ZigLLVMDIBuilder *dibuilder, | ||
| 85 | uint64_t size_in_bits, uint64_t align_in_bits, struct ZigLLVMDIType *elem_type, | ||
| 86 | int elem_count); | ||
| 87 | |||
| 88 | ZIG_EXTERN_C struct ZigLLVMDIEnumerator *ZigLLVMCreateDebugEnumerator(struct ZigLLVMDIBuilder *dibuilder, | ||
| 89 | const char *name, int64_t val); | ||
| 90 | |||
| 91 | ZIG_EXTERN_C struct ZigLLVMDIType *ZigLLVMCreateDebugEnumerationType(struct ZigLLVMDIBuilder *dibuilder, | ||
| 92 | struct ZigLLVMDIScope *scope, const char *name, struct ZigLLVMDIFile *file, unsigned line_number, | ||
| 93 | uint64_t size_in_bits, uint64_t align_in_bits, struct ZigLLVMDIEnumerator **enumerator_array, | ||
| 94 | int enumerator_array_len, struct ZigLLVMDIType *underlying_type, const char *unique_id); | ||
| 95 | |||
| 96 | ZIG_EXTERN_C struct ZigLLVMDIType *ZigLLVMCreateDebugStructType(struct ZigLLVMDIBuilder *dibuilder, | ||
| 97 | struct ZigLLVMDIScope *scope, const char *name, struct ZigLLVMDIFile *file, unsigned line_number, | ||
| 98 | uint64_t size_in_bits, uint64_t align_in_bits, unsigned flags, struct ZigLLVMDIType *derived_from, | ||
| 99 | struct ZigLLVMDIType **types_array, int types_array_len, unsigned run_time_lang, | ||
| 100 | struct ZigLLVMDIType *vtable_holder, const char *unique_id); | ||
| 101 | |||
| 102 | ZIG_EXTERN_C struct ZigLLVMDIType *ZigLLVMCreateDebugUnionType(struct ZigLLVMDIBuilder *dibuilder, | ||
| 103 | struct ZigLLVMDIScope *scope, const char *name, struct ZigLLVMDIFile *file, unsigned line_number, | ||
| 104 | uint64_t size_in_bits, uint64_t align_in_bits, unsigned flags, struct ZigLLVMDIType **types_array, | ||
| 105 | int types_array_len, unsigned run_time_lang, const char *unique_id); | ||
| 106 | |||
| 107 | ZIG_EXTERN_C struct ZigLLVMDIType *ZigLLVMCreateDebugMemberType(struct ZigLLVMDIBuilder *dibuilder, | ||
| 108 | struct ZigLLVMDIScope *scope, const char *name, struct ZigLLVMDIFile *file, unsigned line, | ||
| 109 | uint64_t size_in_bits, uint64_t align_in_bits, uint64_t offset_in_bits, unsigned flags, | ||
| 110 | struct ZigLLVMDIType *type); | ||
| 111 | |||
| 112 | ZIG_EXTERN_C struct ZigLLVMDIType *ZigLLVMCreateReplaceableCompositeType(struct ZigLLVMDIBuilder *dibuilder, | ||
| 113 | unsigned tag, const char *name, struct ZigLLVMDIScope *scope, struct ZigLLVMDIFile *file, unsigned line); | ||
| 114 | |||
| 115 | ZIG_EXTERN_C struct ZigLLVMDIType *ZigLLVMCreateDebugForwardDeclType(struct ZigLLVMDIBuilder *dibuilder, unsigned tag, | ||
| 116 | const char *name, struct ZigLLVMDIScope *scope, struct ZigLLVMDIFile *file, unsigned line); | ||
| 117 | |||
| 118 | ZIG_EXTERN_C void ZigLLVMReplaceTemporary(struct ZigLLVMDIBuilder *dibuilder, struct ZigLLVMDIType *type, | ||
| 119 | struct ZigLLVMDIType *replacement); | ||
| 120 | |||
| 121 | ZIG_EXTERN_C void ZigLLVMReplaceDebugArrays(struct ZigLLVMDIBuilder *dibuilder, struct ZigLLVMDIType *type, | ||
| 122 | struct ZigLLVMDIType **types_array, int types_array_len); | ||
| 123 | |||
| 124 | ZIG_EXTERN_C struct ZigLLVMDIType *ZigLLVMCreateSubroutineType(struct ZigLLVMDIBuilder *dibuilder_wrapped, | ||
| 125 | struct ZigLLVMDIType **types_array, int types_array_len, unsigned flags); | ||
| 126 | |||
| 127 | ZIG_EXTERN_C unsigned ZigLLVMEncoding_DW_ATE_unsigned(void); | ||
| 128 | ZIG_EXTERN_C unsigned ZigLLVMEncoding_DW_ATE_signed(void); | ||
| 129 | ZIG_EXTERN_C unsigned ZigLLVMEncoding_DW_ATE_float(void); | ||
| 130 | ZIG_EXTERN_C unsigned ZigLLVMEncoding_DW_ATE_boolean(void); | ||
| 131 | ZIG_EXTERN_C unsigned ZigLLVMEncoding_DW_ATE_unsigned_char(void); | ||
| 132 | ZIG_EXTERN_C unsigned ZigLLVMEncoding_DW_ATE_signed_char(void); | ||
| 133 | ZIG_EXTERN_C unsigned ZigLLVMLang_DW_LANG_C99(void); | ||
| 134 | ZIG_EXTERN_C unsigned ZigLLVMTag_DW_variable(void); | ||
| 135 | ZIG_EXTERN_C unsigned ZigLLVMTag_DW_structure_type(void); | ||
| 136 | ZIG_EXTERN_C unsigned ZigLLVMTag_DW_union_type(void); | ||
| 137 | |||
| 138 | ZIG_EXTERN_C struct ZigLLVMDIBuilder *ZigLLVMCreateDIBuilder(LLVMModuleRef module, bool allow_unresolved); | ||
| 139 | ZIG_EXTERN_C void ZigLLVMAddModuleDebugInfoFlag(LLVMModuleRef module); | ||
| 140 | ZIG_EXTERN_C void ZigLLVMAddModuleCodeViewFlag(LLVMModuleRef module); | ||
| 141 | |||
| 142 | ZIG_EXTERN_C void ZigLLVMSetCurrentDebugLocation(LLVMBuilderRef builder, int line, int column, | ||
| 143 | struct ZigLLVMDIScope *scope); | ||
| 144 | ZIG_EXTERN_C void ZigLLVMClearCurrentDebugLocation(LLVMBuilderRef builder); | ||
| 145 | |||
| 146 | ZIG_EXTERN_C struct ZigLLVMDIScope *ZigLLVMLexicalBlockToScope(struct ZigLLVMDILexicalBlock *lexical_block); | ||
| 147 | ZIG_EXTERN_C struct ZigLLVMDIScope *ZigLLVMCompileUnitToScope(struct ZigLLVMDICompileUnit *compile_unit); | ||
| 148 | ZIG_EXTERN_C struct ZigLLVMDIScope *ZigLLVMFileToScope(struct ZigLLVMDIFile *difile); | ||
| 149 | ZIG_EXTERN_C struct ZigLLVMDIScope *ZigLLVMSubprogramToScope(struct ZigLLVMDISubprogram *subprogram); | ||
| 150 | ZIG_EXTERN_C struct ZigLLVMDIScope *ZigLLVMTypeToScope(struct ZigLLVMDIType *type); | ||
| 151 | |||
| 152 | ZIG_EXTERN_C struct ZigLLVMDILocalVariable *ZigLLVMCreateAutoVariable(struct ZigLLVMDIBuilder *dbuilder, | ||
| 153 | struct ZigLLVMDIScope *scope, const char *name, struct ZigLLVMDIFile *file, unsigned line_no, | ||
| 154 | struct ZigLLVMDIType *type, bool always_preserve, unsigned flags); | ||
| 155 | |||
| 156 | ZIG_EXTERN_C struct ZigLLVMDIGlobalVariable *ZigLLVMCreateGlobalVariable(struct ZigLLVMDIBuilder *dbuilder, | ||
| 157 | struct ZigLLVMDIScope *scope, const char *name, const char *linkage_name, struct ZigLLVMDIFile *file, | ||
| 158 | unsigned line_no, struct ZigLLVMDIType *di_type, bool is_local_to_unit); | ||
| 159 | |||
| 160 | ZIG_EXTERN_C struct ZigLLVMDILocalVariable *ZigLLVMCreateParameterVariable(struct ZigLLVMDIBuilder *dbuilder, | ||
| 161 | struct ZigLLVMDIScope *scope, const char *name, struct ZigLLVMDIFile *file, unsigned line_no, | ||
| 162 | struct ZigLLVMDIType *type, bool always_preserve, unsigned flags, unsigned arg_no); | ||
| 163 | |||
| 164 | ZIG_EXTERN_C struct ZigLLVMDILexicalBlock *ZigLLVMCreateLexicalBlock(struct ZigLLVMDIBuilder *dbuilder, | ||
| 165 | struct ZigLLVMDIScope *scope, struct ZigLLVMDIFile *file, unsigned line, unsigned col); | ||
| 166 | |||
| 167 | ZIG_EXTERN_C struct ZigLLVMDICompileUnit *ZigLLVMCreateCompileUnit(struct ZigLLVMDIBuilder *dibuilder, | ||
| 168 | unsigned lang, struct ZigLLVMDIFile *difile, const char *producer, | ||
| 169 | bool is_optimized, const char *flags, unsigned runtime_version, const char *split_name, | ||
| 170 | uint64_t dwo_id, bool emit_debug_info); | ||
| 171 | |||
| 172 | ZIG_EXTERN_C struct ZigLLVMDIFile *ZigLLVMCreateFile(struct ZigLLVMDIBuilder *dibuilder, const char *filename, | ||
| 173 | const char *directory); | ||
| 174 | |||
| 175 | ZIG_EXTERN_C struct ZigLLVMDISubprogram *ZigLLVMCreateFunction(struct ZigLLVMDIBuilder *dibuilder, | ||
| 176 | struct ZigLLVMDIScope *scope, const char *name, const char *linkage_name, struct ZigLLVMDIFile *file, | ||
| 177 | unsigned lineno, struct ZigLLVMDIType *fn_di_type, bool is_local_to_unit, bool is_definition, | ||
| 178 | unsigned scope_line, unsigned flags, bool is_optimized, struct ZigLLVMDISubprogram *decl_subprogram); | ||
| 179 | |||
| 180 | ZIG_EXTERN_C void ZigLLVMFnSetSubprogram(LLVMValueRef fn, struct ZigLLVMDISubprogram *subprogram); | ||
| 181 | |||
| 182 | ZIG_EXTERN_C void ZigLLVMDIBuilderFinalize(struct ZigLLVMDIBuilder *dibuilder); | ||
| 183 | |||
| 184 | ZIG_EXTERN_C LLVMValueRef ZigLLVMInsertDeclareAtEnd(struct ZigLLVMDIBuilder *dibuilder, LLVMValueRef storage, | ||
| 185 | struct ZigLLVMDILocalVariable *var_info, struct ZigLLVMDILocation *debug_loc, | ||
| 186 | LLVMBasicBlockRef basic_block_ref); | ||
| 187 | |||
| 188 | ZIG_EXTERN_C LLVMValueRef ZigLLVMInsertDeclare(struct ZigLLVMDIBuilder *dibuilder, LLVMValueRef storage, | ||
| 189 | struct ZigLLVMDILocalVariable *var_info, struct ZigLLVMDILocation *debug_loc, LLVMValueRef insert_before_instr); | ||
| 190 | ZIG_EXTERN_C struct ZigLLVMDILocation *ZigLLVMGetDebugLoc(unsigned line, unsigned col, struct ZigLLVMDIScope *scope); | ||
| 191 | |||
| 192 | ZIG_EXTERN_C void ZigLLVMSetFastMath(LLVMBuilderRef builder_wrapped, bool on_state); | ||
| 193 | |||
| 194 | ZIG_EXTERN_C void ZigLLVMAddFunctionAttr(LLVMValueRef fn, const char *attr_name, const char *attr_value); | ||
| 195 | ZIG_EXTERN_C void ZigLLVMAddFunctionAttrCold(LLVMValueRef fn); | ||
| 196 | |||
| 197 | ZIG_EXTERN_C void ZigLLVMParseCommandLineOptions(size_t argc, const char *const *argv); | ||
| 198 | |||
| 199 | |||
| 200 | // copied from include/llvm/ADT/Triple.h | ||
| 201 | |||
| 202 | enum ZigLLVM_ArchType { | ||
| 203 | ZigLLVM_UnknownArch, | ||
| 204 | |||
| 205 | ZigLLVM_arm, // ARM (little endian): arm, armv.*, xscale | ||
| 206 | ZigLLVM_armeb, // ARM (big endian): armeb | ||
| 207 | ZigLLVM_aarch64, // AArch64 (little endian): aarch64 | ||
| 208 | ZigLLVM_aarch64_be, // AArch64 (big endian): aarch64_be | ||
| 209 | ZigLLVM_avr, // AVR: Atmel AVR microcontroller | ||
| 210 | ZigLLVM_bpfel, // eBPF or extended BPF or 64-bit BPF (little endian) | ||
| 211 | ZigLLVM_bpfeb, // eBPF or extended BPF or 64-bit BPF (big endian) | ||
| 212 | ZigLLVM_hexagon, // Hexagon: hexagon | ||
| 213 | ZigLLVM_mips, // MIPS: mips, mipsallegrex | ||
| 214 | ZigLLVM_mipsel, // MIPSEL: mipsel, mipsallegrexel | ||
| 215 | ZigLLVM_mips64, // MIPS64: mips64 | ||
| 216 | ZigLLVM_mips64el, // MIPS64EL: mips64el | ||
| 217 | ZigLLVM_msp430, // MSP430: msp430 | ||
| 218 | ZigLLVM_nios2, // NIOSII: nios2 | ||
| 219 | ZigLLVM_ppc, // PPC: powerpc | ||
| 220 | ZigLLVM_ppc64, // PPC64: powerpc64, ppu | ||
| 221 | ZigLLVM_ppc64le, // PPC64LE: powerpc64le | ||
| 222 | ZigLLVM_r600, // R600: AMD GPUs HD2XXX - HD6XXX | ||
| 223 | ZigLLVM_amdgcn, // AMDGCN: AMD GCN GPUs | ||
| 224 | ZigLLVM_riscv32, // RISC-V (32-bit): riscv32 | ||
| 225 | ZigLLVM_riscv64, // RISC-V (64-bit): riscv64 | ||
| 226 | ZigLLVM_sparc, // Sparc: sparc | ||
| 227 | ZigLLVM_sparcv9, // Sparcv9: Sparcv9 | ||
| 228 | ZigLLVM_sparcel, // Sparc: (endianness = little). NB: 'Sparcle' is a CPU variant | ||
| 229 | ZigLLVM_systemz, // SystemZ: s390x | ||
| 230 | ZigLLVM_tce, // TCE (http://tce.cs.tut.fi/): tce | ||
| 231 | ZigLLVM_tcele, // TCE little endian (http://tce.cs.tut.fi/): tcele | ||
| 232 | ZigLLVM_thumb, // Thumb (little endian): thumb, thumbv.* | ||
| 233 | ZigLLVM_thumbeb, // Thumb (big endian): thumbeb | ||
| 234 | ZigLLVM_x86, // X86: i[3-9]86 | ||
| 235 | ZigLLVM_x86_64, // X86-64: amd64, x86_64 | ||
| 236 | ZigLLVM_xcore, // XCore: xcore | ||
| 237 | ZigLLVM_nvptx, // NVPTX: 32-bit | ||
| 238 | ZigLLVM_nvptx64, // NVPTX: 64-bit | ||
| 239 | ZigLLVM_le32, // le32: generic little-endian 32-bit CPU (PNaCl) | ||
| 240 | ZigLLVM_le64, // le64: generic little-endian 64-bit CPU (PNaCl) | ||
| 241 | ZigLLVM_amdil, // AMDIL | ||
| 242 | ZigLLVM_amdil64, // AMDIL with 64-bit pointers | ||
| 243 | ZigLLVM_hsail, // AMD HSAIL | ||
| 244 | ZigLLVM_hsail64, // AMD HSAIL with 64-bit pointers | ||
| 245 | ZigLLVM_spir, // SPIR: standard portable IR for OpenCL 32-bit version | ||
| 246 | ZigLLVM_spir64, // SPIR: standard portable IR for OpenCL 64-bit version | ||
| 247 | ZigLLVM_kalimba, // Kalimba: generic kalimba | ||
| 248 | ZigLLVM_shave, // SHAVE: Movidius vector VLIW processors | ||
| 249 | ZigLLVM_lanai, // Lanai: Lanai 32-bit | ||
| 250 | ZigLLVM_wasm32, // WebAssembly with 32-bit pointers | ||
| 251 | ZigLLVM_wasm64, // WebAssembly with 64-bit pointers | ||
| 252 | ZigLLVM_renderscript32, // 32-bit RenderScript | ||
| 253 | ZigLLVM_renderscript64, // 64-bit RenderScript | ||
| 254 | |||
| 255 | ZigLLVM_LastArchType = ZigLLVM_renderscript64 | ||
| 256 | }; | ||
| 257 | |||
| 258 | enum ZigLLVM_SubArchType { | ||
| 259 | ZigLLVM_NoSubArch, | ||
| 260 | |||
| 261 | ZigLLVM_ARMSubArch_v8_2a, | ||
| 262 | ZigLLVM_ARMSubArch_v8_1a, | ||
| 263 | ZigLLVM_ARMSubArch_v8, | ||
| 264 | ZigLLVM_ARMSubArch_v8r, | ||
| 265 | ZigLLVM_ARMSubArch_v8m_baseline, | ||
| 266 | ZigLLVM_ARMSubArch_v8m_mainline, | ||
| 267 | ZigLLVM_ARMSubArch_v7, | ||
| 268 | ZigLLVM_ARMSubArch_v7em, | ||
| 269 | ZigLLVM_ARMSubArch_v7m, | ||
| 270 | ZigLLVM_ARMSubArch_v7s, | ||
| 271 | ZigLLVM_ARMSubArch_v7k, | ||
| 272 | ZigLLVM_ARMSubArch_v7ve, | ||
| 273 | ZigLLVM_ARMSubArch_v6, | ||
| 274 | ZigLLVM_ARMSubArch_v6m, | ||
| 275 | ZigLLVM_ARMSubArch_v6k, | ||
| 276 | ZigLLVM_ARMSubArch_v6t2, | ||
| 277 | ZigLLVM_ARMSubArch_v5, | ||
| 278 | ZigLLVM_ARMSubArch_v5te, | ||
| 279 | ZigLLVM_ARMSubArch_v4t, | ||
| 280 | |||
| 281 | ZigLLVM_KalimbaSubArch_v3, | ||
| 282 | ZigLLVM_KalimbaSubArch_v4, | ||
| 283 | ZigLLVM_KalimbaSubArch_v5, | ||
| 284 | }; | ||
| 285 | |||
| 286 | enum ZigLLVM_VendorType { | ||
| 287 | ZigLLVM_UnknownVendor, | ||
| 288 | |||
| 289 | ZigLLVM_Apple, | ||
| 290 | ZigLLVM_PC, | ||
| 291 | ZigLLVM_SCEI, | ||
| 292 | ZigLLVM_BGP, | ||
| 293 | ZigLLVM_BGQ, | ||
| 294 | ZigLLVM_Freescale, | ||
| 295 | ZigLLVM_IBM, | ||
| 296 | ZigLLVM_ImaginationTechnologies, | ||
| 297 | ZigLLVM_MipsTechnologies, | ||
| 298 | ZigLLVM_NVIDIA, | ||
| 299 | ZigLLVM_CSR, | ||
| 300 | ZigLLVM_Myriad, | ||
| 301 | ZigLLVM_AMD, | ||
| 302 | ZigLLVM_Mesa, | ||
| 303 | ZigLLVM_SUSE, | ||
| 304 | |||
| 305 | ZigLLVM_LastVendorType = ZigLLVM_SUSE | ||
| 306 | }; | ||
| 307 | |||
| 308 | enum ZigLLVM_OSType { | ||
| 309 | ZigLLVM_UnknownOS, | ||
| 310 | |||
| 311 | ZigLLVM_Ananas, | ||
| 312 | ZigLLVM_CloudABI, | ||
| 313 | ZigLLVM_Darwin, | ||
| 314 | ZigLLVM_DragonFly, | ||
| 315 | ZigLLVM_FreeBSD, | ||
| 316 | ZigLLVM_Fuchsia, | ||
| 317 | ZigLLVM_IOS, | ||
| 318 | ZigLLVM_KFreeBSD, | ||
| 319 | ZigLLVM_Linux, | ||
| 320 | ZigLLVM_Lv2, // PS3 | ||
| 321 | ZigLLVM_MacOSX, | ||
| 322 | ZigLLVM_NetBSD, | ||
| 323 | ZigLLVM_OpenBSD, | ||
| 324 | ZigLLVM_Solaris, | ||
| 325 | ZigLLVM_Win32, | ||
| 326 | ZigLLVM_Haiku, | ||
| 327 | ZigLLVM_Minix, | ||
| 328 | ZigLLVM_RTEMS, | ||
| 329 | ZigLLVM_NaCl, // Native Client | ||
| 330 | ZigLLVM_CNK, // BG/P Compute-Node Kernel | ||
| 331 | ZigLLVM_Bitrig, | ||
| 332 | ZigLLVM_AIX, | ||
| 333 | ZigLLVM_CUDA, // NVIDIA CUDA | ||
| 334 | ZigLLVM_NVCL, // NVIDIA OpenCL | ||
| 335 | ZigLLVM_AMDHSA, // AMD HSA Runtime | ||
| 336 | ZigLLVM_PS4, | ||
| 337 | ZigLLVM_ELFIAMCU, | ||
| 338 | ZigLLVM_TvOS, // Apple tvOS | ||
| 339 | ZigLLVM_WatchOS, // Apple watchOS | ||
| 340 | ZigLLVM_Mesa3D, | ||
| 341 | ZigLLVM_Contiki, | ||
| 342 | |||
| 343 | ZigLLVM_LastOSType = ZigLLVM_Contiki | ||
| 344 | }; | ||
| 345 | |||
| 346 | enum ZigLLVM_EnvironmentType { | ||
| 347 | ZigLLVM_UnknownEnvironment, | ||
| 348 | |||
| 349 | ZigLLVM_GNU, | ||
| 350 | ZigLLVM_GNUABI64, | ||
| 351 | ZigLLVM_GNUEABI, | ||
| 352 | ZigLLVM_GNUEABIHF, | ||
| 353 | ZigLLVM_GNUX32, | ||
| 354 | ZigLLVM_CODE16, | ||
| 355 | ZigLLVM_EABI, | ||
| 356 | ZigLLVM_EABIHF, | ||
| 357 | ZigLLVM_Android, | ||
| 358 | ZigLLVM_Musl, | ||
| 359 | ZigLLVM_MuslEABI, | ||
| 360 | ZigLLVM_MuslEABIHF, | ||
| 361 | |||
| 362 | ZigLLVM_MSVC, | ||
| 363 | ZigLLVM_Itanium, | ||
| 364 | ZigLLVM_Cygnus, | ||
| 365 | ZigLLVM_AMDOpenCL, | ||
| 366 | ZigLLVM_CoreCLR, | ||
| 367 | ZigLLVM_OpenCL, | ||
| 368 | |||
| 369 | ZigLLVM_LastEnvironmentType = ZigLLVM_OpenCL | ||
| 370 | }; | ||
| 371 | |||
| 372 | enum ZigLLVM_ObjectFormatType { | ||
| 373 | ZigLLVM_UnknownObjectFormat, | ||
| 374 | |||
| 375 | ZigLLVM_COFF, | ||
| 376 | ZigLLVM_ELF, | ||
| 377 | ZigLLVM_MachO, | ||
| 378 | ZigLLVM_Wasm, | ||
| 379 | }; | ||
| 380 | |||
| 381 | ZIG_EXTERN_C const char *ZigLLVMGetArchTypeName(enum ZigLLVM_ArchType arch); | ||
| 382 | ZIG_EXTERN_C const char *ZigLLVMGetSubArchTypeName(enum ZigLLVM_SubArchType sub_arch); | ||
| 383 | ZIG_EXTERN_C const char *ZigLLVMGetVendorTypeName(enum ZigLLVM_VendorType vendor); | ||
| 384 | ZIG_EXTERN_C const char *ZigLLVMGetOSTypeName(enum ZigLLVM_OSType os); | ||
| 385 | ZIG_EXTERN_C const char *ZigLLVMGetEnvironmentTypeName(enum ZigLLVM_EnvironmentType env_type); | ||
| 386 | |||
| 387 | ZIG_EXTERN_C bool ZigLLDLink(enum ZigLLVM_ObjectFormatType oformat, const char **args, size_t arg_count, | ||
| 388 | void (*append_diagnostic)(void *, const char *, size_t), void *context); | ||
| 389 | |||
| 390 | ZIG_EXTERN_C void ZigLLVMGetNativeTarget(enum ZigLLVM_ArchType *arch_type, enum ZigLLVM_SubArchType *sub_arch_type, | ||
| 391 | enum ZigLLVM_VendorType *vendor_type, enum ZigLLVM_OSType *os_type, enum ZigLLVM_EnvironmentType *environ_type, | ||
| 392 | enum ZigLLVM_ObjectFormatType *oformat); | ||
| 393 | |||
| 394 | #endif | ||
src/zig_llvm.hpp deleted-383| ... | @@ -1,383 +0,0 @@ | ||
| 1 | /* | ||
| 2 | * Copyright (c) 2015 Andrew Kelley | ||
| 3 | * | ||
| 4 | * This file is part of zig, which is MIT licensed. | ||
| 5 | * See http://opensource.org/licenses/MIT | ||
| 6 | */ | ||
| 7 | |||
| 8 | #ifndef ZIG_ZIG_LLVM_HPP | ||
| 9 | #define ZIG_ZIG_LLVM_HPP | ||
| 10 | |||
| 11 | #include <llvm-c/Core.h> | ||
| 12 | #include <llvm-c/Analysis.h> | ||
| 13 | #include <llvm-c/Target.h> | ||
| 14 | #include <llvm-c/Initialization.h> | ||
| 15 | #include <llvm-c/TargetMachine.h> | ||
| 16 | |||
| 17 | struct ZigLLVMDIType; | ||
| 18 | struct ZigLLVMDIBuilder; | ||
| 19 | struct ZigLLVMDICompileUnit; | ||
| 20 | struct ZigLLVMDIScope; | ||
| 21 | struct ZigLLVMDIFile; | ||
| 22 | struct ZigLLVMDILexicalBlock; | ||
| 23 | struct ZigLLVMDISubprogram; | ||
| 24 | struct ZigLLVMDISubroutineType; | ||
| 25 | struct ZigLLVMDILocalVariable; | ||
| 26 | struct ZigLLVMDIGlobalVariable; | ||
| 27 | struct ZigLLVMDILocation; | ||
| 28 | struct ZigLLVMDIEnumerator; | ||
| 29 | struct ZigLLVMInsertionPoint; | ||
| 30 | |||
| 31 | void ZigLLVMInitializeLoopStrengthReducePass(LLVMPassRegistryRef R); | ||
| 32 | void ZigLLVMInitializeLowerIntrinsicsPass(LLVMPassRegistryRef R); | ||
| 33 | |||
| 34 | char *ZigLLVMGetHostCPUName(void); | ||
| 35 | char *ZigLLVMGetNativeFeatures(void); | ||
| 36 | |||
| 37 | // We use a custom enum here since LLVM does not expose LLVMIr as an emit | ||
| 38 | // output through the same mechanism as assembly/binary. | ||
| 39 | enum ZigLLVM_EmitOutputType { | ||
| 40 | ZigLLVM_EmitAssembly, | ||
| 41 | ZigLLVM_EmitBinary, | ||
| 42 | ZigLLVM_EmitLLVMIr, | ||
| 43 | }; | ||
| 44 | |||
| 45 | bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref, | ||
| 46 | const char *filename, ZigLLVM_EmitOutputType output_type, char **error_message, bool is_debug); | ||
| 47 | |||
| 48 | enum ZigLLVM_FnInline { | ||
| 49 | ZigLLVM_FnInlineAuto, | ||
| 50 | ZigLLVM_FnInlineAlways, | ||
| 51 | ZigLLVM_FnInlineNever, | ||
| 52 | }; | ||
| 53 | LLVMValueRef ZigLLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *Args, | ||
| 54 | unsigned NumArgs, unsigned CC, ZigLLVM_FnInline fn_inline, const char *Name); | ||
| 55 | |||
| 56 | LLVMValueRef ZigLLVMBuildCmpXchg(LLVMBuilderRef builder, LLVMValueRef ptr, LLVMValueRef cmp, | ||
| 57 | LLVMValueRef new_val, LLVMAtomicOrdering success_ordering, | ||
| 58 | LLVMAtomicOrdering failure_ordering); | ||
| 59 | |||
| 60 | LLVMValueRef ZigLLVMBuildNSWShl(LLVMBuilderRef builder, LLVMValueRef LHS, LLVMValueRef RHS, | ||
| 61 | const char *name); | ||
| 62 | LLVMValueRef ZigLLVMBuildNUWShl(LLVMBuilderRef builder, LLVMValueRef LHS, LLVMValueRef RHS, | ||
| 63 | const char *name); | ||
| 64 | LLVMValueRef ZigLLVMBuildLShrExact(LLVMBuilderRef builder, LLVMValueRef LHS, LLVMValueRef RHS, | ||
| 65 | const char *name); | ||
| 66 | LLVMValueRef ZigLLVMBuildAShrExact(LLVMBuilderRef builder, LLVMValueRef LHS, LLVMValueRef RHS, | ||
| 67 | const char *name); | ||
| 68 | |||
| 69 | ZigLLVMDIType *ZigLLVMCreateDebugPointerType(ZigLLVMDIBuilder *dibuilder, ZigLLVMDIType *pointee_type, | ||
| 70 | uint64_t size_in_bits, uint64_t align_in_bits, const char *name); | ||
| 71 | |||
| 72 | ZigLLVMDIType *ZigLLVMCreateDebugBasicType(ZigLLVMDIBuilder *dibuilder, const char *name, | ||
| 73 | uint64_t size_in_bits, unsigned encoding); | ||
| 74 | |||
| 75 | ZigLLVMDIType *ZigLLVMCreateDebugArrayType(ZigLLVMDIBuilder *dibuilder, | ||
| 76 | uint64_t size_in_bits, uint64_t align_in_bits, ZigLLVMDIType *elem_type, | ||
| 77 | int elem_count); | ||
| 78 | |||
| 79 | ZigLLVMDIEnumerator *ZigLLVMCreateDebugEnumerator(ZigLLVMDIBuilder *dibuilder, const char *name, int64_t val); | ||
| 80 | |||
| 81 | ZigLLVMDIType *ZigLLVMCreateDebugEnumerationType(ZigLLVMDIBuilder *dibuilder, ZigLLVMDIScope *scope, | ||
| 82 | const char *name, ZigLLVMDIFile *file, unsigned line_number, uint64_t size_in_bits, | ||
| 83 | uint64_t align_in_bits, ZigLLVMDIEnumerator **enumerator_array, int enumerator_array_len, | ||
| 84 | ZigLLVMDIType *underlying_type, const char *unique_id); | ||
| 85 | |||
| 86 | ZigLLVMDIType *ZigLLVMCreateDebugStructType(ZigLLVMDIBuilder *dibuilder, ZigLLVMDIScope *scope, | ||
| 87 | const char *name, ZigLLVMDIFile *file, unsigned line_number, uint64_t size_in_bits, | ||
| 88 | uint64_t align_in_bits, unsigned flags, ZigLLVMDIType *derived_from, | ||
| 89 | ZigLLVMDIType **types_array, int types_array_len, unsigned run_time_lang, ZigLLVMDIType *vtable_holder, | ||
| 90 | const char *unique_id); | ||
| 91 | |||
| 92 | ZigLLVMDIType *ZigLLVMCreateDebugUnionType(ZigLLVMDIBuilder *dibuilder, ZigLLVMDIScope *scope, | ||
| 93 | const char *name, ZigLLVMDIFile *file, unsigned line_number, uint64_t size_in_bits, | ||
| 94 | uint64_t align_in_bits, unsigned flags, ZigLLVMDIType **types_array, int types_array_len, | ||
| 95 | unsigned run_time_lang, const char *unique_id); | ||
| 96 | |||
| 97 | ZigLLVMDIType *ZigLLVMCreateDebugMemberType(ZigLLVMDIBuilder *dibuilder, ZigLLVMDIScope *scope, | ||
| 98 | const char *name, ZigLLVMDIFile *file, unsigned line, uint64_t size_in_bits, | ||
| 99 | uint64_t align_in_bits, uint64_t offset_in_bits, unsigned flags, ZigLLVMDIType *type); | ||
| 100 | |||
| 101 | ZigLLVMDIType *ZigLLVMCreateReplaceableCompositeType(ZigLLVMDIBuilder *dibuilder, unsigned tag, | ||
| 102 | const char *name, ZigLLVMDIScope *scope, ZigLLVMDIFile *file, unsigned line); | ||
| 103 | |||
| 104 | ZigLLVMDIType *ZigLLVMCreateDebugForwardDeclType(ZigLLVMDIBuilder *dibuilder, unsigned tag, | ||
| 105 | const char *name, ZigLLVMDIScope *scope, ZigLLVMDIFile *file, unsigned line); | ||
| 106 | |||
| 107 | void ZigLLVMReplaceTemporary(ZigLLVMDIBuilder *dibuilder, ZigLLVMDIType *type, | ||
| 108 | ZigLLVMDIType *replacement); | ||
| 109 | |||
| 110 | void ZigLLVMReplaceDebugArrays(ZigLLVMDIBuilder *dibuilder, ZigLLVMDIType *type, | ||
| 111 | ZigLLVMDIType **types_array, int types_array_len); | ||
| 112 | |||
| 113 | ZigLLVMDIType *ZigLLVMCreateSubroutineType(ZigLLVMDIBuilder *dibuilder_wrapped, | ||
| 114 | ZigLLVMDIType **types_array, int types_array_len, unsigned flags); | ||
| 115 | |||
| 116 | unsigned ZigLLVMEncoding_DW_ATE_unsigned(void); | ||
| 117 | unsigned ZigLLVMEncoding_DW_ATE_signed(void); | ||
| 118 | unsigned ZigLLVMEncoding_DW_ATE_float(void); | ||
| 119 | unsigned ZigLLVMEncoding_DW_ATE_boolean(void); | ||
| 120 | unsigned ZigLLVMEncoding_DW_ATE_unsigned_char(void); | ||
| 121 | unsigned ZigLLVMEncoding_DW_ATE_signed_char(void); | ||
| 122 | unsigned ZigLLVMLang_DW_LANG_C99(void); | ||
| 123 | unsigned ZigLLVMTag_DW_variable(void); | ||
| 124 | unsigned ZigLLVMTag_DW_structure_type(void); | ||
| 125 | unsigned ZigLLVMTag_DW_union_type(void); | ||
| 126 | |||
| 127 | ZigLLVMDIBuilder *ZigLLVMCreateDIBuilder(LLVMModuleRef module, bool allow_unresolved); | ||
| 128 | void ZigLLVMAddModuleDebugInfoFlag(LLVMModuleRef module); | ||
| 129 | void ZigLLVMAddModuleCodeViewFlag(LLVMModuleRef module); | ||
| 130 | |||
| 131 | void ZigLLVMSetCurrentDebugLocation(LLVMBuilderRef builder, int line, int column, ZigLLVMDIScope *scope); | ||
| 132 | void ZigLLVMClearCurrentDebugLocation(LLVMBuilderRef builder); | ||
| 133 | |||
| 134 | ZigLLVMDIScope *ZigLLVMLexicalBlockToScope(ZigLLVMDILexicalBlock *lexical_block); | ||
| 135 | ZigLLVMDIScope *ZigLLVMCompileUnitToScope(ZigLLVMDICompileUnit *compile_unit); | ||
| 136 | ZigLLVMDIScope *ZigLLVMFileToScope(ZigLLVMDIFile *difile); | ||
| 137 | ZigLLVMDIScope *ZigLLVMSubprogramToScope(ZigLLVMDISubprogram *subprogram); | ||
| 138 | ZigLLVMDIScope *ZigLLVMTypeToScope(ZigLLVMDIType *type); | ||
| 139 | |||
| 140 | ZigLLVMDILocalVariable *ZigLLVMCreateAutoVariable(ZigLLVMDIBuilder *dbuilder, | ||
| 141 | ZigLLVMDIScope *scope, const char *name, ZigLLVMDIFile *file, unsigned line_no, | ||
| 142 | ZigLLVMDIType *type, bool always_preserve, unsigned flags); | ||
| 143 | |||
| 144 | ZigLLVMDIGlobalVariable *ZigLLVMCreateGlobalVariable(ZigLLVMDIBuilder *dbuilder, | ||
| 145 | ZigLLVMDIScope *scope, const char *name, const char *linkage_name, ZigLLVMDIFile *file, | ||
| 146 | unsigned line_no, ZigLLVMDIType *di_type, bool is_local_to_unit); | ||
| 147 | |||
| 148 | ZigLLVMDILocalVariable *ZigLLVMCreateParameterVariable(ZigLLVMDIBuilder *dbuilder, | ||
| 149 | ZigLLVMDIScope *scope, const char *name, ZigLLVMDIFile *file, unsigned line_no, | ||
| 150 | ZigLLVMDIType *type, bool always_preserve, unsigned flags, unsigned arg_no); | ||
| 151 | |||
| 152 | ZigLLVMDILexicalBlock *ZigLLVMCreateLexicalBlock(ZigLLVMDIBuilder *dbuilder, ZigLLVMDIScope *scope, | ||
| 153 | ZigLLVMDIFile *file, unsigned line, unsigned col); | ||
| 154 | |||
| 155 | ZigLLVMDICompileUnit *ZigLLVMCreateCompileUnit(ZigLLVMDIBuilder *dibuilder, | ||
| 156 | unsigned lang, ZigLLVMDIFile *difile, const char *producer, | ||
| 157 | bool is_optimized, const char *flags, unsigned runtime_version, const char *split_name, | ||
| 158 | uint64_t dwo_id, bool emit_debug_info); | ||
| 159 | |||
| 160 | ZigLLVMDIFile *ZigLLVMCreateFile(ZigLLVMDIBuilder *dibuilder, const char *filename, const char *directory); | ||
| 161 | |||
| 162 | ZigLLVMDISubprogram *ZigLLVMCreateFunction(ZigLLVMDIBuilder *dibuilder, ZigLLVMDIScope *scope, | ||
| 163 | const char *name, const char *linkage_name, ZigLLVMDIFile *file, unsigned lineno, | ||
| 164 | ZigLLVMDIType *fn_di_type, bool is_local_to_unit, bool is_definition, unsigned scope_line, | ||
| 165 | unsigned flags, bool is_optimized, ZigLLVMDISubprogram *decl_subprogram); | ||
| 166 | |||
| 167 | void ZigLLVMFnSetSubprogram(LLVMValueRef fn, ZigLLVMDISubprogram *subprogram); | ||
| 168 | |||
| 169 | void ZigLLVMDIBuilderFinalize(ZigLLVMDIBuilder *dibuilder); | ||
| 170 | |||
| 171 | LLVMValueRef ZigLLVMInsertDeclareAtEnd(ZigLLVMDIBuilder *dibuilder, LLVMValueRef storage, | ||
| 172 | ZigLLVMDILocalVariable *var_info, ZigLLVMDILocation *debug_loc, LLVMBasicBlockRef basic_block_ref); | ||
| 173 | LLVMValueRef ZigLLVMInsertDeclare(ZigLLVMDIBuilder *dibuilder, LLVMValueRef storage, | ||
| 174 | ZigLLVMDILocalVariable *var_info, ZigLLVMDILocation *debug_loc, LLVMValueRef insert_before_instr); | ||
| 175 | ZigLLVMDILocation *ZigLLVMGetDebugLoc(unsigned line, unsigned col, ZigLLVMDIScope *scope); | ||
| 176 | |||
| 177 | void ZigLLVMSetFastMath(LLVMBuilderRef builder_wrapped, bool on_state); | ||
| 178 | |||
| 179 | void ZigLLVMAddFunctionAttr(LLVMValueRef fn, const char *attr_name, const char *attr_value); | ||
| 180 | void ZigLLVMAddFunctionAttrCold(LLVMValueRef fn); | ||
| 181 | |||
| 182 | void ZigLLVMParseCommandLineOptions(int argc, const char *const *argv); | ||
| 183 | |||
| 184 | |||
| 185 | // copied from include/llvm/ADT/Triple.h | ||
| 186 | |||
| 187 | enum ZigLLVM_ArchType { | ||
| 188 | ZigLLVM_UnknownArch, | ||
| 189 | |||
| 190 | ZigLLVM_arm, // ARM (little endian): arm, armv.*, xscale | ||
| 191 | ZigLLVM_armeb, // ARM (big endian): armeb | ||
| 192 | ZigLLVM_aarch64, // AArch64 (little endian): aarch64 | ||
| 193 | ZigLLVM_aarch64_be, // AArch64 (big endian): aarch64_be | ||
| 194 | ZigLLVM_avr, // AVR: Atmel AVR microcontroller | ||
| 195 | ZigLLVM_bpfel, // eBPF or extended BPF or 64-bit BPF (little endian) | ||
| 196 | ZigLLVM_bpfeb, // eBPF or extended BPF or 64-bit BPF (big endian) | ||
| 197 | ZigLLVM_hexagon, // Hexagon: hexagon | ||
| 198 | ZigLLVM_mips, // MIPS: mips, mipsallegrex | ||
| 199 | ZigLLVM_mipsel, // MIPSEL: mipsel, mipsallegrexel | ||
| 200 | ZigLLVM_mips64, // MIPS64: mips64 | ||
| 201 | ZigLLVM_mips64el, // MIPS64EL: mips64el | ||
| 202 | ZigLLVM_msp430, // MSP430: msp430 | ||
| 203 | ZigLLVM_nios2, // NIOSII: nios2 | ||
| 204 | ZigLLVM_ppc, // PPC: powerpc | ||
| 205 | ZigLLVM_ppc64, // PPC64: powerpc64, ppu | ||
| 206 | ZigLLVM_ppc64le, // PPC64LE: powerpc64le | ||
| 207 | ZigLLVM_r600, // R600: AMD GPUs HD2XXX - HD6XXX | ||
| 208 | ZigLLVM_amdgcn, // AMDGCN: AMD GCN GPUs | ||
| 209 | ZigLLVM_riscv32, // RISC-V (32-bit): riscv32 | ||
| 210 | ZigLLVM_riscv64, // RISC-V (64-bit): riscv64 | ||
| 211 | ZigLLVM_sparc, // Sparc: sparc | ||
| 212 | ZigLLVM_sparcv9, // Sparcv9: Sparcv9 | ||
| 213 | ZigLLVM_sparcel, // Sparc: (endianness = little). NB: 'Sparcle' is a CPU variant | ||
| 214 | ZigLLVM_systemz, // SystemZ: s390x | ||
| 215 | ZigLLVM_tce, // TCE (http://tce.cs.tut.fi/): tce | ||
| 216 | ZigLLVM_tcele, // TCE little endian (http://tce.cs.tut.fi/): tcele | ||
| 217 | ZigLLVM_thumb, // Thumb (little endian): thumb, thumbv.* | ||
| 218 | ZigLLVM_thumbeb, // Thumb (big endian): thumbeb | ||
| 219 | ZigLLVM_x86, // X86: i[3-9]86 | ||
| 220 | ZigLLVM_x86_64, // X86-64: amd64, x86_64 | ||
| 221 | ZigLLVM_xcore, // XCore: xcore | ||
| 222 | ZigLLVM_nvptx, // NVPTX: 32-bit | ||
| 223 | ZigLLVM_nvptx64, // NVPTX: 64-bit | ||
| 224 | ZigLLVM_le32, // le32: generic little-endian 32-bit CPU (PNaCl) | ||
| 225 | ZigLLVM_le64, // le64: generic little-endian 64-bit CPU (PNaCl) | ||
| 226 | ZigLLVM_amdil, // AMDIL | ||
| 227 | ZigLLVM_amdil64, // AMDIL with 64-bit pointers | ||
| 228 | ZigLLVM_hsail, // AMD HSAIL | ||
| 229 | ZigLLVM_hsail64, // AMD HSAIL with 64-bit pointers | ||
| 230 | ZigLLVM_spir, // SPIR: standard portable IR for OpenCL 32-bit version | ||
| 231 | ZigLLVM_spir64, // SPIR: standard portable IR for OpenCL 64-bit version | ||
| 232 | ZigLLVM_kalimba, // Kalimba: generic kalimba | ||
| 233 | ZigLLVM_shave, // SHAVE: Movidius vector VLIW processors | ||
| 234 | ZigLLVM_lanai, // Lanai: Lanai 32-bit | ||
| 235 | ZigLLVM_wasm32, // WebAssembly with 32-bit pointers | ||
| 236 | ZigLLVM_wasm64, // WebAssembly with 64-bit pointers | ||
| 237 | ZigLLVM_renderscript32, // 32-bit RenderScript | ||
| 238 | ZigLLVM_renderscript64, // 64-bit RenderScript | ||
| 239 | |||
| 240 | ZigLLVM_LastArchType = ZigLLVM_renderscript64 | ||
| 241 | }; | ||
| 242 | |||
| 243 | enum ZigLLVM_SubArchType { | ||
| 244 | ZigLLVM_NoSubArch, | ||
| 245 | |||
| 246 | ZigLLVM_ARMSubArch_v8_2a, | ||
| 247 | ZigLLVM_ARMSubArch_v8_1a, | ||
| 248 | ZigLLVM_ARMSubArch_v8, | ||
| 249 | ZigLLVM_ARMSubArch_v8r, | ||
| 250 | ZigLLVM_ARMSubArch_v8m_baseline, | ||
| 251 | ZigLLVM_ARMSubArch_v8m_mainline, | ||
| 252 | ZigLLVM_ARMSubArch_v7, | ||
| 253 | ZigLLVM_ARMSubArch_v7em, | ||
| 254 | ZigLLVM_ARMSubArch_v7m, | ||
| 255 | ZigLLVM_ARMSubArch_v7s, | ||
| 256 | ZigLLVM_ARMSubArch_v7k, | ||
| 257 | ZigLLVM_ARMSubArch_v7ve, | ||
| 258 | ZigLLVM_ARMSubArch_v6, | ||
| 259 | ZigLLVM_ARMSubArch_v6m, | ||
| 260 | ZigLLVM_ARMSubArch_v6k, | ||
| 261 | ZigLLVM_ARMSubArch_v6t2, | ||
| 262 | ZigLLVM_ARMSubArch_v5, | ||
| 263 | ZigLLVM_ARMSubArch_v5te, | ||
| 264 | ZigLLVM_ARMSubArch_v4t, | ||
| 265 | |||
| 266 | ZigLLVM_KalimbaSubArch_v3, | ||
| 267 | ZigLLVM_KalimbaSubArch_v4, | ||
| 268 | ZigLLVM_KalimbaSubArch_v5, | ||
| 269 | }; | ||
| 270 | |||
| 271 | enum ZigLLVM_VendorType { | ||
| 272 | ZigLLVM_UnknownVendor, | ||
| 273 | |||
| 274 | ZigLLVM_Apple, | ||
| 275 | ZigLLVM_PC, | ||
| 276 | ZigLLVM_SCEI, | ||
| 277 | ZigLLVM_BGP, | ||
| 278 | ZigLLVM_BGQ, | ||
| 279 | ZigLLVM_Freescale, | ||
| 280 | ZigLLVM_IBM, | ||
| 281 | ZigLLVM_ImaginationTechnologies, | ||
| 282 | ZigLLVM_MipsTechnologies, | ||
| 283 | ZigLLVM_NVIDIA, | ||
| 284 | ZigLLVM_CSR, | ||
| 285 | ZigLLVM_Myriad, | ||
| 286 | ZigLLVM_AMD, | ||
| 287 | ZigLLVM_Mesa, | ||
| 288 | ZigLLVM_SUSE, | ||
| 289 | |||
| 290 | ZigLLVM_LastVendorType = ZigLLVM_SUSE | ||
| 291 | }; | ||
| 292 | |||
| 293 | enum ZigLLVM_OSType { | ||
| 294 | ZigLLVM_UnknownOS, | ||
| 295 | |||
| 296 | ZigLLVM_Ananas, | ||
| 297 | ZigLLVM_CloudABI, | ||
| 298 | ZigLLVM_Darwin, | ||
| 299 | ZigLLVM_DragonFly, | ||
| 300 | ZigLLVM_FreeBSD, | ||
| 301 | ZigLLVM_Fuchsia, | ||
| 302 | ZigLLVM_IOS, | ||
| 303 | ZigLLVM_KFreeBSD, | ||
| 304 | ZigLLVM_Linux, | ||
| 305 | ZigLLVM_Lv2, // PS3 | ||
| 306 | ZigLLVM_MacOSX, | ||
| 307 | ZigLLVM_NetBSD, | ||
| 308 | ZigLLVM_OpenBSD, | ||
| 309 | ZigLLVM_Solaris, | ||
| 310 | ZigLLVM_Win32, | ||
| 311 | ZigLLVM_Haiku, | ||
| 312 | ZigLLVM_Minix, | ||
| 313 | ZigLLVM_RTEMS, | ||
| 314 | ZigLLVM_NaCl, // Native Client | ||
| 315 | ZigLLVM_CNK, // BG/P Compute-Node Kernel | ||
| 316 | ZigLLVM_Bitrig, | ||
| 317 | ZigLLVM_AIX, | ||
| 318 | ZigLLVM_CUDA, // NVIDIA CUDA | ||
| 319 | ZigLLVM_NVCL, // NVIDIA OpenCL | ||
| 320 | ZigLLVM_AMDHSA, // AMD HSA Runtime | ||
| 321 | ZigLLVM_PS4, | ||
| 322 | ZigLLVM_ELFIAMCU, | ||
| 323 | ZigLLVM_TvOS, // Apple tvOS | ||
| 324 | ZigLLVM_WatchOS, // Apple watchOS | ||
| 325 | ZigLLVM_Mesa3D, | ||
| 326 | ZigLLVM_Contiki, | ||
| 327 | |||
| 328 | ZigLLVM_LastOSType = ZigLLVM_Contiki | ||
| 329 | }; | ||
| 330 | |||
| 331 | enum ZigLLVM_EnvironmentType { | ||
| 332 | ZigLLVM_UnknownEnvironment, | ||
| 333 | |||
| 334 | ZigLLVM_GNU, | ||
| 335 | ZigLLVM_GNUABI64, | ||
| 336 | ZigLLVM_GNUEABI, | ||
| 337 | ZigLLVM_GNUEABIHF, | ||
| 338 | ZigLLVM_GNUX32, | ||
| 339 | ZigLLVM_CODE16, | ||
| 340 | ZigLLVM_EABI, | ||
| 341 | ZigLLVM_EABIHF, | ||
| 342 | ZigLLVM_Android, | ||
| 343 | ZigLLVM_Musl, | ||
| 344 | ZigLLVM_MuslEABI, | ||
| 345 | ZigLLVM_MuslEABIHF, | ||
| 346 | |||
| 347 | ZigLLVM_MSVC, | ||
| 348 | ZigLLVM_Itanium, | ||
| 349 | ZigLLVM_Cygnus, | ||
| 350 | ZigLLVM_AMDOpenCL, | ||
| 351 | ZigLLVM_CoreCLR, | ||
| 352 | ZigLLVM_OpenCL, | ||
| 353 | |||
| 354 | ZigLLVM_LastEnvironmentType = ZigLLVM_OpenCL | ||
| 355 | }; | ||
| 356 | |||
| 357 | enum ZigLLVM_ObjectFormatType { | ||
| 358 | ZigLLVM_UnknownObjectFormat, | ||
| 359 | |||
| 360 | ZigLLVM_COFF, | ||
| 361 | ZigLLVM_ELF, | ||
| 362 | ZigLLVM_MachO, | ||
| 363 | ZigLLVM_Wasm, | ||
| 364 | }; | ||
| 365 | |||
| 366 | const char *ZigLLVMGetArchTypeName(ZigLLVM_ArchType arch); | ||
| 367 | const char *ZigLLVMGetSubArchTypeName(ZigLLVM_SubArchType sub_arch); | ||
| 368 | const char *ZigLLVMGetVendorTypeName(ZigLLVM_VendorType vendor); | ||
| 369 | const char *ZigLLVMGetOSTypeName(ZigLLVM_OSType os); | ||
| 370 | const char *ZigLLVMGetEnvironmentTypeName(ZigLLVM_EnvironmentType env_type); | ||
| 371 | |||
| 372 | /* | ||
| 373 | * This stuff is not LLVM API but it depends on the LLVM C++ API so we put it here. | ||
| 374 | */ | ||
| 375 | struct Buf; | ||
| 376 | |||
| 377 | bool ZigLLDLink(ZigLLVM_ObjectFormatType oformat, const char **args, size_t arg_count, Buf *diag); | ||
| 378 | |||
| 379 | void ZigLLVMGetNativeTarget(ZigLLVM_ArchType *arch_type, ZigLLVM_SubArchType *sub_arch_type, | ||
| 380 | ZigLLVM_VendorType *vendor_type, ZigLLVM_OSType *os_type, ZigLLVM_EnvironmentType *environ_type, | ||
| 381 | ZigLLVM_ObjectFormatType *oformat); | ||
| 382 | |||
| 383 | #endif | ||
std/build.zig+7| ... | @@ -784,6 +784,13 @@ const Target = union(enum) { | ... | @@ -784,6 +784,13 @@ const Target = union(enum) { |
| 784 | }; | 784 | }; |
| 785 | } | 785 | } |
| 786 | 786 | ||
| 787 | pub fn libFileExt(self: &const Target) -> []const u8 { | ||
| 788 | return switch (self.getOs()) { | ||
| 789 | builtin.Os.windows => ".lib", | ||
| 790 | else => ".a", | ||
| 791 | }; | ||
| 792 | } | ||
| 793 | |||
| 787 | pub fn getOs(self: &const Target) -> builtin.Os { | 794 | pub fn getOs(self: &const Target) -> builtin.Os { |
| 788 | return switch (*self) { | 795 | return switch (*self) { |
| 789 | Target.Native => builtin.os, | 796 | Target.Native => builtin.os, |
std/cstr.zig+54| ... | @@ -48,3 +48,57 @@ pub fn addNullByte(allocator: &mem.Allocator, slice: []const u8) -> %[]u8 { | ... | @@ -48,3 +48,57 @@ pub fn addNullByte(allocator: &mem.Allocator, slice: []const u8) -> %[]u8 { |
| 48 | result[slice.len] = 0; | 48 | result[slice.len] = 0; |
| 49 | return result; | 49 | return result; |
| 50 | } | 50 | } |
| 51 | |||
| 52 | pub const NullTerminated2DArray = struct { | ||
| 53 | allocator: &mem.Allocator, | ||
| 54 | byte_count: usize, | ||
| 55 | ptr: ?&?&u8, | ||
| 56 | |||
| 57 | /// Takes N lists of strings, concatenates the lists together, and adds a null terminator | ||
| 58 | /// Caller must deinit result | ||
| 59 | pub fn fromSlices(allocator: &mem.Allocator, slices: []const []const []const u8) -> %NullTerminated2DArray { | ||
| 60 | var new_len: usize = 1; // 1 for the list null | ||
| 61 | var byte_count: usize = 0; | ||
| 62 | for (slices) |slice| { | ||
| 63 | new_len += slice.len; | ||
| 64 | for (slice) |inner| { | ||
| 65 | byte_count += inner.len; | ||
| 66 | } | ||
| 67 | byte_count += slice.len; // for the null terminators of inner | ||
| 68 | } | ||
| 69 | |||
| 70 | const index_size = @sizeOf(usize) * new_len; // size of the ptrs | ||
| 71 | byte_count += index_size; | ||
| 72 | |||
| 73 | const buf = %return allocator.alignedAlloc(u8, @alignOf(?&u8), byte_count); | ||
| 74 | %defer allocator.free(buf); | ||
| 75 | |||
| 76 | var write_index = index_size; | ||
| 77 | const index_buf = ([]?&u8)(buf); | ||
| 78 | |||
| 79 | var i: usize = 0; | ||
| 80 | for (slices) |slice| { | ||
| 81 | for (slice) |inner| { | ||
| 82 | index_buf[i] = &buf[write_index]; | ||
| 83 | i += 1; | ||
| 84 | mem.copy(u8, buf[write_index..], inner); | ||
| 85 | write_index += inner.len; | ||
| 86 | buf[write_index] = 0; | ||
| 87 | write_index += 1; | ||
| 88 | } | ||
| 89 | } | ||
| 90 | index_buf[i] = null; | ||
| 91 | |||
| 92 | return NullTerminated2DArray { | ||
| 93 | .allocator = allocator, | ||
| 94 | .byte_count = byte_count, | ||
| 95 | .ptr = @ptrCast(?&?&u8, buf.ptr), | ||
| 96 | }; | ||
| 97 | } | ||
| 98 | |||
| 99 | pub fn deinit(self: &NullTerminated2DArray) { | ||
| 100 | const buf = @ptrCast(&u8, self.ptr); | ||
| 101 | self.allocator.free(buf[0..self.byte_count]); | ||
| 102 | } | ||
| 103 | }; | ||
| 104 |