| author | |
| committer | |
| log | 57ea6e8c9f204be6d38177024d3b8f1aba4e05b2 |
| tree | 0a9897aab096767288688216aa68d3809e2d77fe |
| parent | 67021e2bfff0b9caea432fd996031ab880afdbc5 |
15 files changed, 299 insertions(+), 222 deletions(-)
.gitignore+1-7| ... | ... | @@ -1,9 +1,3 @@ |
| 1 | 1 | zig-cache/ |
| 2 | 2 | build/ |
| 3 | build-release/ | |
| 4 | build-windows/ | |
| 5 | build-llvm4-debug/ | |
| 6 | build-llvm5-debug/ | |
| 7 | /.cproject | |
| 8 | /.project | |
| 9 | /.settings/ | |
| 3 | build-*/ |
CMakeLists.txt+25-99| ... | ... | @@ -26,86 +26,11 @@ option(ZIG_TEST_COVERAGE "Build Zig with test coverage instrumentation" OFF) |
| 26 | 26 | # git log -p -- deps/lld |
| 27 | 27 | option(ZIG_FORCE_EXTERNAL_LLD "If your system has the LLD patches use it instead of the embedded LLD" OFF) |
| 28 | 28 | |
| 29 | find_package(LLVM REQUIRED CONFIG) | |
| 29 | find_package(llvm) | |
| 30 | 30 | include_directories(${LLVM_INCLUDE_DIRS}) |
| 31 | 31 | |
| 32 | # TODO: this currently doesn't work, it currently defines UNICODE but zig | |
| 33 | # uses MBCS | |
| 34 | #add_definitions(${LLVM_DEFINITIONS}) | |
| 35 | ||
| 36 | link_directories(${LLVM_LIBRARY_DIRS}) | |
| 37 | llvm_map_components_to_libnames(LLVM_LIBRARIES | |
| 38 | LTO | |
| 39 | Symbolize | |
| 40 | XCoreDisassembler | |
| 41 | XCoreCodeGen | |
| 42 | XCoreAsmPrinter | |
| 43 | SystemZDisassembler | |
| 44 | SystemZCodeGen | |
| 45 | SystemZAsmParser | |
| 46 | SystemZAsmPrinter | |
| 47 | SparcDisassembler | |
| 48 | SparcCodeGen | |
| 49 | SparcAsmParser | |
| 50 | SparcAsmPrinter | |
| 51 | PowerPCDisassembler | |
| 52 | PowerPCCodeGen | |
| 53 | PowerPCAsmParser | |
| 54 | PowerPCAsmPrinter | |
| 55 | NVPTXCodeGen | |
| 56 | NVPTXAsmPrinter | |
| 57 | MSP430CodeGen | |
| 58 | MSP430AsmPrinter | |
| 59 | MipsDisassembler | |
| 60 | MipsCodeGen | |
| 61 | MipsAsmParser | |
| 62 | MipsAsmPrinter | |
| 63 | LanaiDisassembler | |
| 64 | LanaiCodeGen | |
| 65 | LanaiAsmParser | |
| 66 | LanaiAsmPrinter | |
| 67 | HexagonDisassembler | |
| 68 | HexagonCodeGen | |
| 69 | HexagonAsmParser | |
| 70 | BPFDisassembler | |
| 71 | BPFCodeGen | |
| 72 | BPFAsmPrinter | |
| 73 | ARMDisassembler | |
| 74 | ARMCodeGen | |
| 75 | ARMAsmParser | |
| 76 | ARMAsmPrinter | |
| 77 | AMDGPUDisassembler | |
| 78 | AMDGPUCodeGen | |
| 79 | AMDGPUAsmParser | |
| 80 | AMDGPUAsmPrinter | |
| 81 | AArch64Disassembler | |
| 82 | AArch64CodeGen | |
| 83 | AArch64AsmParser | |
| 84 | AArch64AsmPrinter | |
| 85 | LibDriver | |
| 86 | X86Disassembler | |
| 87 | X86AsmParser | |
| 88 | X86CodeGen | |
| 89 | X86AsmPrinter | |
| 90 | Core | |
| 91 | ) | |
| 92 | ||
| 93 | find_package(CLANG REQUIRED CONFIG) | |
| 32 | find_package(clang) | |
| 94 | 33 | include_directories(${CLANG_INCLUDE_DIRS}) |
| 95 | set(CLANG_LIBRARIES | |
| 96 | clangFrontend | |
| 97 | clangDriver | |
| 98 | clangSerialization | |
| 99 | clangSema | |
| 100 | clangAnalysis | |
| 101 | clangAST | |
| 102 | clangParse | |
| 103 | clangSema | |
| 104 | clangBasic | |
| 105 | clangEdit | |
| 106 | clangLex | |
| 107 | ) | |
| 108 | ||
| 109 | 34 | |
| 110 | 35 | if(ZIG_FORCE_EXTERNAL_LLD) |
| 111 | 36 | find_package(lld) |
| ... | ... | @@ -203,21 +128,21 @@ else() |
| 203 | 128 | add_library(embedded_lld_lib ${EMBEDDED_LLD_LIB_SOURCES}) |
| 204 | 129 | add_library(embedded_lld_elf ${EMBEDDED_LLD_ELF_SOURCES}) |
| 205 | 130 | add_library(embedded_lld_coff ${EMBEDDED_LLD_COFF_SOURCES}) |
| 206 | if(MINGW) | |
| 207 | set(UNIQUE_COMPILE_FLAGS "-fno-exceptions -fno-rtti -Wno-comment") | |
| 208 | elseif(MSVC) | |
| 209 | set(UNIQUE_COMPILE_FLAGS "-D_MSVC") | |
| 131 | if(MSVC) | |
| 132 | set(ZIG_LLD_COMPILE_FLAGS "-std=c++11") | |
| 133 | else() | |
| 134 | set(ZIG_LLD_COMPILE_FLAGS "-std=c++11 -fno-exceptions -fno-rtti -Wno-comment") | |
| 210 | 135 | endif() |
| 211 | 136 | set_target_properties(embedded_lld_lib PROPERTIES |
| 212 | COMPILE_FLAGS "-std=c++11 ${UNIQUE_COMPILE_FLAGS}" | |
| 137 | COMPILE_FLAGS ${ZIG_LLD_COMPILE_FLAGS} | |
| 213 | 138 | LINK_FLAGS " " |
| 214 | 139 | ) |
| 215 | 140 | set_target_properties(embedded_lld_elf PROPERTIES |
| 216 | COMPILE_FLAGS "-std=c++11 ${UNIQUE_COMPILE_FLAGS}" | |
| 141 | COMPILE_FLAGS ${ZIG_LLD_COMPILE_FLAGS} | |
| 217 | 142 | LINK_FLAGS " " |
| 218 | 143 | ) |
| 219 | 144 | set_target_properties(embedded_lld_coff PROPERTIES |
| 220 | COMPILE_FLAGS "-std=c++11 ${UNIQUE_COMPILE_FLAGS}" | |
| 145 | COMPILE_FLAGS ${ZIG_LLD_COMPILE_FLAGS} | |
| 221 | 146 | LINK_FLAGS " " |
| 222 | 147 | ) |
| 223 | 148 | target_include_directories(embedded_lld_lib PUBLIC |
| ... | ... | @@ -289,17 +214,20 @@ include_directories( |
| 289 | 214 | "${CMAKE_SOURCE_DIR}/src" |
| 290 | 215 | ) |
| 291 | 216 | |
| 292 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") | |
| 293 | if(MINGW) | |
| 294 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Werror -Wno-error=format= -Wno-error=format -Wno-error=format-extra-args") | |
| 217 | if(MSVC) | |
| 218 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -W4") | |
| 219 | elseif(MINGW) | |
| 220 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Werror -Wno-error=format= -Wno-error=format -Wno-error=format-extra-args") | |
| 221 | else() | |
| 222 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Werror -Wall") | |
| 295 | 223 | endif() |
| 296 | 224 | |
| 297 | set(EXE_CFLAGS "-std=c++11") | |
| 298 | if(MINGW) | |
| 299 | set(EXE_CFLAGS "${EXE_CFLAGS} -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D_GNU_SOURCE -fno-exceptions -fno-rtti -Werror=strict-prototypes -Werror=old-style-definition -Werror=type-limits -Wno-missing-braces") | |
| 300 | elseif(MSVC) | |
| 301 | set(EXE_CFLAGS "${EXE_CFLAGS} -D_MSVC") | |
| 225 | if(MSVC) | |
| 226 | set(EXE_CFLAGS "-std=c++11") | |
| 227 | else() | |
| 228 | set(EXE_CFLAGS "-std=c++11 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D_GNU_SOURCE -fno-exceptions -fno-rtti -Werror=strict-prototypes -Werror=old-style-definition -Werror=type-limits -Wno-missing-braces") | |
| 302 | 229 | endif() |
| 230 | ||
| 303 | 231 | set(EXE_LDFLAGS " ") |
| 304 | 232 | if(ZIG_TEST_COVERAGE) |
| 305 | 233 | set(EXE_CFLAGS "${EXE_CFLAGS} -fprofile-arcs -ftest-coverage") |
| ... | ... | @@ -312,9 +240,6 @@ set_target_properties(zig PROPERTIES |
| 312 | 240 | LINK_FLAGS ${EXE_LDFLAGS} |
| 313 | 241 | ) |
| 314 | 242 | |
| 315 | if(MINGW) | |
| 316 | set(PLATFORM_LIBRARIES quadmath) | |
| 317 | endif() | |
| 318 | 243 | target_link_libraries(zig LINK_PUBLIC |
| 319 | 244 | ${CLANG_LIBRARIES} |
| 320 | 245 | ${LLD_LIBRARIES} |
| ... | ... | @@ -322,11 +247,12 @@ target_link_libraries(zig LINK_PUBLIC |
| 322 | 247 | ${CMAKE_THREAD_LIBS_INIT} |
| 323 | 248 | ${PLATFORM_LIBRARIES} |
| 324 | 249 | ) |
| 325 | if(MINGW OR MSVC) | |
| 326 | target_link_libraries(zig LINK_PUBLIC version) | |
| 327 | endif() | |
| 328 | 250 | if(MSVC) |
| 329 | target_link_libraries(zig LINK_PUBLIC "C:/Program Files (x86)/Microsoft Visual Studio 14.0/DIA SDK/lib/diaguids.lib") | |
| 251 | target_link_libraries(zig LINK_PUBLIC version) | |
| 252 | elseif(MINGW) | |
| 253 | target_link_libraries(zig LINK_PUBLIC version quadmath) | |
| 254 | else() | |
| 255 | target_link_libraries(zig LINK_PUBLIC quadmath) | |
| 330 | 256 | endif() |
| 331 | 257 | install(TARGETS zig DESTINATION bin) |
| 332 | 258 |
cmake/Findclang.cmake created+63| ... | ... | @@ -0,0 +1,63 @@ |
| 1 | # Copyright (c) 2016 Andrew Kelley | |
| 2 | # This file is MIT licensed. | |
| 3 | # See http://opensource.org/licenses/MIT | |
| 4 | ||
| 5 | # CLANG_FOUND | |
| 6 | # CLANG_INCLUDE_DIRS | |
| 7 | # CLANG_LIBRARIES | |
| 8 | ||
| 9 | if(MSVC) | |
| 10 | find_package(CLANG REQUIRED CONFIG) | |
| 11 | ||
| 12 | set(CLANG_LIBRARIES | |
| 13 | clangFrontend | |
| 14 | clangDriver | |
| 15 | clangSerialization | |
| 16 | clangSema | |
| 17 | clangAnalysis | |
| 18 | clangAST | |
| 19 | clangParse | |
| 20 | clangSema | |
| 21 | clangBasic | |
| 22 | clangEdit | |
| 23 | clangLex | |
| 24 | ) | |
| 25 | ||
| 26 | else() | |
| 27 | find_path(CLANG_INCLUDE_DIRS NAMES clang/Frontend/ASTUnit.h | |
| 28 | PATHS | |
| 29 | /usr/lib/llvm/5/include | |
| 30 | /usr/lib/llvm-5.0/include | |
| 31 | /mingw64/include) | |
| 32 | ||
| 33 | macro(FIND_AND_ADD_CLANG_LIB _libname_) | |
| 34 | string(TOUPPER ${_libname_} _prettylibname_) | |
| 35 | find_library(CLANG_${_prettylibname_}_LIB NAMES ${_libname_} | |
| 36 | PATHS | |
| 37 | /usr/lib/llvm/5/lib | |
| 38 | /usr/lib/llvm-5.0/lib | |
| 39 | /mingw64/lib | |
| 40 | /c/msys64/mingw64/lib | |
| 41 | c:\\msys64\\mingw64\\lib) | |
| 42 | if(CLANG_${_prettylibname_}_LIB) | |
| 43 | set(CLANG_LIBRARIES ${CLANG_LIBRARIES} ${CLANG_${_prettylibname_}_LIB}) | |
| 44 | endif() | |
| 45 | endmacro(FIND_AND_ADD_CLANG_LIB) | |
| 46 | ||
| 47 | FIND_AND_ADD_CLANG_LIB(clangFrontend) | |
| 48 | FIND_AND_ADD_CLANG_LIB(clangDriver) | |
| 49 | FIND_AND_ADD_CLANG_LIB(clangSerialization) | |
| 50 | FIND_AND_ADD_CLANG_LIB(clangSema) | |
| 51 | FIND_AND_ADD_CLANG_LIB(clangAnalysis) | |
| 52 | FIND_AND_ADD_CLANG_LIB(clangAST) | |
| 53 | FIND_AND_ADD_CLANG_LIB(clangParse) | |
| 54 | FIND_AND_ADD_CLANG_LIB(clangSema) | |
| 55 | FIND_AND_ADD_CLANG_LIB(clangBasic) | |
| 56 | FIND_AND_ADD_CLANG_LIB(clangEdit) | |
| 57 | FIND_AND_ADD_CLANG_LIB(clangLex) | |
| 58 | endif() | |
| 59 | ||
| 60 | include(FindPackageHandleStandardArgs) | |
| 61 | find_package_handle_standard_args(CLANG DEFAULT_MSG CLANG_LIBRARIES CLANG_INCLUDE_DIRS) | |
| 62 | ||
| 63 | mark_as_advanced(CLANG_INCLUDE_DIRS CLANG_LIBRARIES) |
cmake/Findllvm.cmake created+116| ... | ... | @@ -0,0 +1,116 @@ |
| 1 | # Copyright (c) 2014 Andrew Kelley | |
| 2 | # This file is MIT licensed. | |
| 3 | # See http://opensource.org/licenses/MIT | |
| 4 | ||
| 5 | # LLVM_FOUND | |
| 6 | # LLVM_INCLUDE_DIRS | |
| 7 | # LLVM_LIBRARIES | |
| 8 | # LLVM_LIBDIRS | |
| 9 | ||
| 10 | if(MSVC) | |
| 11 | find_package(LLVM REQUIRED CONFIG) | |
| 12 | ||
| 13 | # TODO: this currently doesn't work, it currently defines UNICODE but zig | |
| 14 | # uses MBCS | |
| 15 | #add_definitions(${LLVM_DEFINITIONS}) | |
| 16 | ||
| 17 | link_directories(${LLVM_LIBRARY_DIRS}) | |
| 18 | llvm_map_components_to_libnames(LLVM_LIBRARIES | |
| 19 | LTO | |
| 20 | Symbolize | |
| 21 | XCoreDisassembler | |
| 22 | XCoreCodeGen | |
| 23 | XCoreAsmPrinter | |
| 24 | SystemZDisassembler | |
| 25 | SystemZCodeGen | |
| 26 | SystemZAsmParser | |
| 27 | SystemZAsmPrinter | |
| 28 | SparcDisassembler | |
| 29 | SparcCodeGen | |
| 30 | SparcAsmParser | |
| 31 | SparcAsmPrinter | |
| 32 | PowerPCDisassembler | |
| 33 | PowerPCCodeGen | |
| 34 | PowerPCAsmParser | |
| 35 | PowerPCAsmPrinter | |
| 36 | NVPTXCodeGen | |
| 37 | NVPTXAsmPrinter | |
| 38 | MSP430CodeGen | |
| 39 | MSP430AsmPrinter | |
| 40 | MipsDisassembler | |
| 41 | MipsCodeGen | |
| 42 | MipsAsmParser | |
| 43 | MipsAsmPrinter | |
| 44 | LanaiDisassembler | |
| 45 | LanaiCodeGen | |
| 46 | LanaiAsmParser | |
| 47 | LanaiAsmPrinter | |
| 48 | HexagonDisassembler | |
| 49 | HexagonCodeGen | |
| 50 | HexagonAsmParser | |
| 51 | BPFDisassembler | |
| 52 | BPFCodeGen | |
| 53 | BPFAsmPrinter | |
| 54 | ARMDisassembler | |
| 55 | ARMCodeGen | |
| 56 | ARMAsmParser | |
| 57 | ARMAsmPrinter | |
| 58 | AMDGPUDisassembler | |
| 59 | AMDGPUCodeGen | |
| 60 | AMDGPUAsmParser | |
| 61 | AMDGPUAsmPrinter | |
| 62 | AArch64Disassembler | |
| 63 | AArch64CodeGen | |
| 64 | AArch64AsmParser | |
| 65 | AArch64AsmPrinter | |
| 66 | LibDriver | |
| 67 | X86Disassembler | |
| 68 | X86AsmParser | |
| 69 | X86CodeGen | |
| 70 | X86AsmPrinter | |
| 71 | Core | |
| 72 | ) | |
| 73 | ||
| 74 | else() | |
| 75 | find_program(LLVM_CONFIG_EXE | |
| 76 | NAMES llvm-config-5.0 llvm-config | |
| 77 | PATHS | |
| 78 | "/mingw64/bin" | |
| 79 | "/c/msys64/mingw64/bin" | |
| 80 | "c:/msys64/mingw64/bin" | |
| 81 | "C:/Libraries/llvm-5.0.0/bin") | |
| 82 | ||
| 83 | execute_process( | |
| 84 | COMMAND ${LLVM_CONFIG_EXE} --libs | |
| 85 | OUTPUT_VARIABLE LLVM_LIBRARIES | |
| 86 | OUTPUT_STRIP_TRAILING_WHITESPACE) | |
| 87 | ||
| 88 | execute_process( | |
| 89 | COMMAND ${LLVM_CONFIG_EXE} --system-libs | |
| 90 | OUTPUT_VARIABLE LLVM_SYSTEM_LIBS | |
| 91 | OUTPUT_STRIP_TRAILING_WHITESPACE) | |
| 92 | ||
| 93 | execute_process( | |
| 94 | COMMAND ${LLVM_CONFIG_EXE} --libdir | |
| 95 | OUTPUT_VARIABLE LLVM_LIBDIRS | |
| 96 | OUTPUT_STRIP_TRAILING_WHITESPACE) | |
| 97 | ||
| 98 | execute_process( | |
| 99 | COMMAND ${LLVM_CONFIG_EXE} --includedir | |
| 100 | OUTPUT_VARIABLE LLVM_INCLUDE_DIRS | |
| 101 | OUTPUT_STRIP_TRAILING_WHITESPACE) | |
| 102 | ||
| 103 | find_library(LLVM_LIBRARY NAMES LLVM) | |
| 104 | ||
| 105 | set(LLVM_LIBRARIES ${LLVM_LIBRARIES} ${LLVM_SYSTEM_LIBS}) | |
| 106 | ||
| 107 | if(LLVM_LIBRARY) | |
| 108 | set(LLVM_LIBRARIES ${LLVM_LIBRARY}) | |
| 109 | endif() | |
| 110 | endif() | |
| 111 | ||
| 112 | ||
| 113 | include(FindPackageHandleStandardArgs) | |
| 114 | find_package_handle_standard_args(LLVM DEFAULT_MSG LLVM_LIBRARIES LLVM_INCLUDE_DIRS) | |
| 115 | ||
| 116 | mark_as_advanced(LLVM_INCLUDE_DIRS LLVM_LIBRARIES LLVM_LIBDIRS) |
src/bigfloat.hpp+2-5| ... | ... | @@ -13,11 +13,8 @@ |
| 13 | 13 | #include <stdint.h> |
| 14 | 14 | #include <stddef.h> |
| 15 | 15 | |
| 16 | #if defined(_MSVC) | |
| 17 | /* | |
| 18 | * For now this is a placeholder until a better solution comes along to | |
| 19 | * support 128-bit floats with MSVC. | |
| 20 | */ | |
| 16 | #if defined(_MSC_VER) | |
| 17 | // TODO support 128 bit floats with msvc | |
| 21 | 18 | typedef long double __float128; |
| 22 | 19 | #endif |
| 23 | 20 |
src/bigint.cpp+14-23| ... | ... | @@ -377,39 +377,30 @@ void bigint_read_twos_complement(BigInt *dest, const uint8_t *buf, size_t bit_co |
| 377 | 377 | } |
| 378 | 378 | } |
| 379 | 379 | |
| 380 | #if defined(_MSVC) | |
| 381 | /* | |
| 382 | * Inneficient implmentations for now | |
| 383 | */ | |
| 380 | #if defined(_MSC_VER) | |
| 384 | 381 | static bool add_u64_overflow(uint64_t op1, uint64_t op2, uint64_t *result) { |
| 385 | 382 | *result = op1 + op2; |
| 386 | if(*result - op2 != op1) { | |
| 387 | return true; // overflow | |
| 388 | } | |
| 389 | return false; // no overflow | |
| 383 | return *result < op1 || *result < op2; | |
| 390 | 384 | } |
| 391 | 385 | |
| 392 | 386 | static bool sub_u64_overflow(uint64_t op1, uint64_t op2, uint64_t *result) { |
| 393 | 387 | *result = op1 - op2; |
| 394 | if(*result > op1) | |
| 395 | { | |
| 396 | return true; // overflow | |
| 397 | } | |
| 398 | return false; // no overflow | |
| 388 | return *result > op1; | |
| 399 | 389 | } |
| 400 | 390 | |
| 401 | 391 | bool mul_u64_overflow(uint64_t op1, uint64_t op2, uint64_t *result) { |
| 402 | 392 | *result = op1 * op2; |
| 403 | if(op1 <= op2) { | |
| 404 | if(*result / op1 != op2) { | |
| 405 | return true; // overflow | |
| 406 | } | |
| 407 | } else { | |
| 408 | if(*result / op2 != op1) { | |
| 409 | return true; // overflow | |
| 410 | } | |
| 411 | } | |
| 412 | return false; // no overflow | |
| 393 | ||
| 394 | if (op1 == 0 || op2 == 0) | |
| 395 | return false; | |
| 396 | ||
| 397 | if (op1 > UINT64_MAX / op2) | |
| 398 | return true; | |
| 399 | ||
| 400 | if (op2 > UINT64_MAX / op1) | |
| 401 | return true; | |
| 402 | ||
| 403 | return false; | |
| 413 | 404 | } |
| 414 | 405 | #else |
| 415 | 406 | static bool add_u64_overflow(uint64_t op1, uint64_t op2, uint64_t *result) { |
src/bigint.hpp+1-1| ... | ... | @@ -11,7 +11,7 @@ |
| 11 | 11 | #include <stdint.h> |
| 12 | 12 | #include <stddef.h> |
| 13 | 13 | |
| 14 | #if defined(_MSVC) | |
| 14 | #if defined(_MSC_VER) | |
| 15 | 15 | // TEMPORARY WORKAROUND FOR MSVC NOT SUPPORTING __int128 |
| 16 | 16 | typedef long long int128_t; |
| 17 | 17 | typedef unsigned long long uint128_t; |
src/buffer.hpp+2-2| ... | ... | @@ -24,7 +24,7 @@ struct Buf { |
| 24 | 24 | }; |
| 25 | 25 | |
| 26 | 26 | Buf *buf_sprintf(const char *format, ...) |
| 27 | ATTRIBUTE_FORMAT(printf, 1, 2); | |
| 27 | ATTRIBUTE_PRINTF(1, 2); | |
| 28 | 28 | Buf *buf_vprintf(const char *format, va_list ap); |
| 29 | 29 | |
| 30 | 30 | static inline size_t buf_len(Buf *buf) { |
| ... | ... | @@ -124,7 +124,7 @@ static inline void buf_append_char(Buf *buf, uint8_t c) { |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | void buf_appendf(Buf *buf, const char *format, ...) |
| 127 | ATTRIBUTE_FORMAT(printf, 2, 3); | |
| 127 | ATTRIBUTE_PRINTF(2, 3); | |
| 128 | 128 | |
| 129 | 129 | static inline bool buf_eql_mem(Buf *buf, const char *mem, size_t mem_len) { |
| 130 | 130 | assert(buf->list.length); |
src/codegen.cpp+1-14| ... | ... | @@ -5194,8 +5194,7 @@ void codegen_add_object(CodeGen *g, Buf *object_path) { |
| 5194 | 5194 | g->link_objects.append(object_path); |
| 5195 | 5195 | } |
| 5196 | 5196 | |
| 5197 | #if defined(_MSVC) | |
| 5198 | // MSVC doesn't seem to support "designators" for array initialization | |
| 5197 | // Must be coordinated with with CIntType enum | |
| 5199 | 5198 | static const char *c_int_type_names[] = { |
| 5200 | 5199 | "short", |
| 5201 | 5200 | "unsigned short", |
| ... | ... | @@ -5206,18 +5205,6 @@ static const char *c_int_type_names[] = { |
| 5206 | 5205 | "long long", |
| 5207 | 5206 | "unsigned long long", |
| 5208 | 5207 | }; |
| 5209 | #else | |
| 5210 | static const char *c_int_type_names[] = { | |
| 5211 | [CIntTypeShort] = "short", | |
| 5212 | [CIntTypeUShort] = "unsigned short", | |
| 5213 | [CIntTypeInt] = "int", | |
| 5214 | [CIntTypeUInt] = "unsigned int", | |
| 5215 | [CIntTypeLong] = "long", | |
| 5216 | [CIntTypeULong] = "unsigned long", | |
| 5217 | [CIntTypeLongLong] = "long long", | |
| 5218 | [CIntTypeULongLong] = "unsigned long long", | |
| 5219 | }; | |
| 5220 | #endif | |
| 5221 | 5208 | |
| 5222 | 5209 | static void get_c_type(CodeGen *g, TypeTableEntry *type_entry, Buf *out_buf) { |
| 5223 | 5210 | assert(type_entry); |
src/parsec.cpp+1-1| ... | ... | @@ -56,7 +56,7 @@ static AstNode *resolve_enum_decl(Context *c, const EnumDecl *enum_decl); |
| 56 | 56 | static AstNode *resolve_typedef_decl(Context *c, const TypedefNameDecl *typedef_decl); |
| 57 | 57 | |
| 58 | 58 | |
| 59 | ATTRIBUTE_FORMAT(printf, 3, 4) | |
| 59 | ATTRIBUTE_PRINTF(3, 4) | |
| 60 | 60 | static void emit_warning(Context *c, const SourceLocation &sl, const char *format, ...) { |
| 61 | 61 | if (!c->warnings_on) { |
| 62 | 62 | return; |
src/parser.cpp+5-5| ... | ... | @@ -24,8 +24,8 @@ struct ParseContext { |
| 24 | 24 | Buf *void_buf; |
| 25 | 25 | }; |
| 26 | 26 | |
| 27 | ATTRIBUTE_FORMAT(printf, 4, 5) | |
| 28 | LLVM_ATTRIBUTE_NORETURN | |
| 27 | ATTRIBUTE_PRINTF(4, 5) | |
| 28 | ATTRIBUTE_NORETURN | |
| 29 | 29 | static void ast_asm_error(ParseContext *pc, AstNode *node, size_t offset, const char *format, ...) { |
| 30 | 30 | assert(node->type == NodeTypeAsmExpr); |
| 31 | 31 | |
| ... | ... | @@ -46,8 +46,8 @@ static void ast_asm_error(ParseContext *pc, AstNode *node, size_t offset, const |
| 46 | 46 | exit(EXIT_FAILURE); |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | ATTRIBUTE_FORMAT(printf, 3, 4) | |
| 50 | LLVM_ATTRIBUTE_NORETURN | |
| 49 | ATTRIBUTE_PRINTF(3, 4) | |
| 50 | ATTRIBUTE_NORETURN | |
| 51 | 51 | static void ast_error(ParseContext *pc, Token *token, const char *format, ...) { |
| 52 | 52 | va_list ap; |
| 53 | 53 | va_start(ap, format); |
| ... | ... | @@ -205,7 +205,7 @@ static void ast_buf_from_token(ParseContext *pc, Token *token, Buf *buf) { |
| 205 | 205 | } |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | LLVM_ATTRIBUTE_NORETURN | |
| 208 | ATTRIBUTE_NORETURN | |
| 209 | 209 | static void ast_invalid_token_error(ParseContext *pc, Token *token) { |
| 210 | 210 | Buf token_value = BUF_INIT; |
| 211 | 211 | ast_buf_from_token(pc, token, &token_value); |
src/parser.hpp+1-1| ... | ... | @@ -12,7 +12,7 @@ |
| 12 | 12 | #include "tokenizer.hpp" |
| 13 | 13 | #include "errmsg.hpp" |
| 14 | 14 | |
| 15 | ATTRIBUTE_FORMAT(printf, 2, 3) | |
| 15 | ATTRIBUTE_PRINTF(2, 3) | |
| 16 | 16 | void ast_token_error(Token *token, const char *format, ...); |
| 17 | 17 | |
| 18 | 18 |
src/quadmath.hpp+31-33| ... | ... | @@ -8,46 +8,44 @@ |
| 8 | 8 | #ifndef ZIG_QUADMATH_HPP |
| 9 | 9 | #define ZIG_QUADMATH_HPP |
| 10 | 10 | |
| 11 | #if defined(_MSVC) | |
| 12 | #include <stdlib.h> | |
| 13 | #include <stdio.h> | |
| 14 | #include <stdarg.h> | |
| 15 | #include <cmath> | |
| 16 | #endif | |
| 11 | #if defined(_MSC_VER) | |
| 12 | #include <stdlib.h> | |
| 13 | #include <stdio.h> | |
| 14 | #include <stdarg.h> | |
| 15 | #include <cmath> | |
| 16 | ||
| 17 | static inline __float128 fmodq(__float128 a, __float128 b) { | |
| 18 | return fmodl(a, b); | |
| 19 | } | |
| 20 | ||
| 21 | static inline __float128 ceilq(__float128 a) { | |
| 22 | return ceill(a); | |
| 23 | } | |
| 24 | ||
| 25 | static inline __float128 floorq(__float128 a) { | |
| 26 | return floorl(a); | |
| 27 | } | |
| 28 | ||
| 29 | static inline __float128 strtoflt128(const char *s, char **sp) { | |
| 30 | return strtold(s, sp); | |
| 31 | } | |
| 32 | ||
| 33 | static inline int quadmath_snprintf(char *s, size_t size, const char *format, ...) { | |
| 34 | va_list args; | |
| 35 | va_start(format, args); | |
| 36 | int result = vsnprintf(s, size, format, args); | |
| 37 | va_end(args); | |
| 38 | return result; | |
| 39 | } | |
| 17 | 40 | |
| 18 | extern "C" { | |
| 19 | #if defined(_MSVC) | |
| 20 | static __float128 fmodq(__float128 a, __float128 b) | |
| 21 | { | |
| 22 | return fmod(a, b); | |
| 23 | } | |
| 24 | static __float128 ceilq(__float128 a) | |
| 25 | { | |
| 26 | return ceil(a); | |
| 27 | } | |
| 28 | static __float128 floorq(__float128 a) | |
| 29 | { | |
| 30 | return floor(a); | |
| 31 | } | |
| 32 | static __float128 strtoflt128(const char *s, char **sp) | |
| 33 | { | |
| 34 | return strtold(s, sp); | |
| 35 | } | |
| 36 | static int quadmath_snprintf(char *s, size_t size, const char *format, ...) | |
| 37 | { | |
| 38 | va_list args; | |
| 39 | va_start(format, args); | |
| 40 | int result = vsnprintf(s, size, format, args); | |
| 41 | va_end(args); | |
| 42 | return result; | |
| 43 | } | |
| 44 | 41 | #else |
| 42 | extern "C" { | |
| 45 | 43 | __float128 fmodq(__float128 a, __float128 b); |
| 46 | 44 | __float128 ceilq(__float128 a); |
| 47 | 45 | __float128 floorq(__float128 a); |
| 48 | 46 | __float128 strtoflt128 (const char *s, char **sp); |
| 49 | 47 | int quadmath_snprintf (char *s, size_t size, const char *format, ...); |
| 50 | #endif | |
| 51 | 48 | } |
| 49 | #endif | |
| 52 | 50 | |
| 53 | 51 | #endif |
src/tokenizer.cpp+1-1| ... | ... | @@ -234,7 +234,7 @@ struct Tokenize { |
| 234 | 234 | BigInt significand; |
| 235 | 235 | }; |
| 236 | 236 | |
| 237 | ATTRIBUTE_FORMAT(printf, 2, 3) | |
| 237 | ATTRIBUTE_PRINTF(2, 3) | |
| 238 | 238 | static void tokenize_error(Tokenize *t, const char *format, ...) { |
| 239 | 239 | t->state = TokenizeStateError; |
| 240 | 240 |
src/util.hpp+35-30| ... | ... | @@ -12,52 +12,57 @@ |
| 12 | 12 | #include <stdint.h> |
| 13 | 13 | #include <string.h> |
| 14 | 14 | #include <assert.h> |
| 15 | #include <llvm/Support/Compiler.h> | |
| 16 | 15 | |
| 17 | 16 | #include <new> |
| 18 | 17 | |
| 19 | #if defined(_MSVC) | |
| 20 | #define ATTRIBUTE_COLD | |
| 21 | #define ATTRIBUTE_FORMAT(args) | |
| 22 | static inline uint32_t popcnt(unsigned long long x) | |
| 23 | { | |
| 24 | x -= ((x >> 1) & 0x55555555); | |
| 25 | x = (((x >> 2) & 0x33333333) + (x & 0x33333333)); | |
| 26 | x = (((x >> 4) + x) & 0x0f0f0f0f); | |
| 27 | x += (x >> 8); | |
| 28 | x += (x >> 16); | |
| 29 | return x & 0x0000003f; | |
| 30 | } | |
| 31 | static inline uint32_t clzll(unsigned long long x) | |
| 32 | { | |
| 33 | x |= (x >> 1); | |
| 34 | x |= (x >> 2); | |
| 35 | x |= (x >> 4); | |
| 36 | x |= (x >> 8); | |
| 37 | x |= (x >> 16); | |
| 38 | return 32 - popcnt(x); | |
| 39 | } | |
| 18 | #if defined(_MSC_VER) | |
| 19 | ||
| 20 | #include <intrin.h> | |
| 21 | ||
| 22 | #define ATTRIBUTE_COLD __declspec(noinline) | |
| 23 | #define ATTRIBUTE_PRINTF(a, b) | |
| 24 | #define ATTRIBUTE_RETURNS_NOALIAS __declspec(restrict) | |
| 25 | #define ATTRIBUTE_NORETURN __declspec(noreturn) | |
| 26 | ||
| 27 | static inline int clzll(unsigned long long mask) { | |
| 28 | unsigned long lz; | |
| 29 | #if defined(_WIN64) | |
| 30 | if (_BitScanReverse64(&lz, mask)) | |
| 31 | return static_cast<int>(63-lz); | |
| 32 | zig_unreachable(); | |
| 40 | 33 | #else |
| 41 | #define ATTRIBUTE_COLD __attribute__((cold)) | |
| 42 | #define ATTRIBUTE_FORMAT(args) __attribute__((format (args))) | |
| 43 | #define clzll(x) __builtin_clzll(x) | |
| 34 | if (_BitScanReverse(&lz, mask >> 32)) | |
| 35 | lz += 32; | |
| 36 | else | |
| 37 | _BitScanReverse(&lz, mask & 0xffffffff); | |
| 38 | return 63 - lz; | |
| 39 | #endif | |
| 40 | } | |
| 41 | #else | |
| 42 | ||
| 43 | #define ATTRIBUTE_COLD __attribute__((cold)) | |
| 44 | #define ATTRIBUTE_PRINTF(a, b) __attribute__((format(printf, a, b))) | |
| 45 | #define ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__)) | |
| 46 | #define ATTRIBUTE_NORETURN __attribute__((noreturn)) | |
| 47 | #define clzll(x) __builtin_clzll(x) | |
| 48 | ||
| 44 | 49 | #endif |
| 45 | 50 | |
| 46 | 51 | #define BREAKPOINT __asm("int $0x03") |
| 47 | 52 | |
| 48 | LLVM_ATTRIBUTE_NOINLINE | |
| 49 | 53 | ATTRIBUTE_COLD |
| 50 | ATTRIBUTE_FORMAT(printf, 1, 2) | |
| 54 | ATTRIBUTE_NORETURN | |
| 55 | ATTRIBUTE_PRINTF(1, 2) | |
| 51 | 56 | void zig_panic(const char *format, ...); |
| 52 | 57 | |
| 53 | 58 | ATTRIBUTE_COLD |
| 54 | LLVM_ATTRIBUTE_NOINLINE | |
| 59 | ATTRIBUTE_NORETURN | |
| 55 | 60 | static inline void zig_unreachable(void) { |
| 56 | 61 | zig_panic("unreachable"); |
| 57 | 62 | } |
| 58 | 63 | |
| 59 | 64 | template<typename T> |
| 60 | LLVM_ATTRIBUTE_RETURNS_NOALIAS static inline T *allocate_nonzero(size_t count) { | |
| 65 | ATTRIBUTE_RETURNS_NOALIAS static inline T *allocate_nonzero(size_t count) { | |
| 61 | 66 | T *ptr = reinterpret_cast<T*>(malloc(count * sizeof(T))); |
| 62 | 67 | if (!ptr) |
| 63 | 68 | zig_panic("allocation failed"); |
| ... | ... | @@ -65,7 +70,7 @@ LLVM_ATTRIBUTE_RETURNS_NOALIAS static inline T *allocate_nonzero(size_t count) { |
| 65 | 70 | } |
| 66 | 71 | |
| 67 | 72 | template<typename T> |
| 68 | LLVM_ATTRIBUTE_RETURNS_NOALIAS static inline T *allocate(size_t count) { | |
| 73 | ATTRIBUTE_RETURNS_NOALIAS static inline T *allocate(size_t count) { | |
| 69 | 74 | T *ptr = reinterpret_cast<T*>(calloc(count, sizeof(T))); |
| 70 | 75 | if (!ptr) |
| 71 | 76 | zig_panic("allocation failed"); |