| author | |
| committer | |
| log | fbe5737c84c783cd31e6e2d595fc47eb782c5e3c |
| tree | 177994e0311f406f95273af408dd13b942acc921 |
| parent | c0bdcc7417a23d338dc1df6bd74b30fe6e3d1a1a |
| signature |
8 files changed, 94 insertions(+), 47 deletions(-)
CMakeLists.txt+11-3| ... | @@ -390,7 +390,7 @@ if(MSVC) | ... | @@ -390,7 +390,7 @@ if(MSVC) |
| 390 | ) | 390 | ) |
| 391 | else() | 391 | else() |
| 392 | set_target_properties(embedded_softfloat PROPERTIES | 392 | set_target_properties(embedded_softfloat PROPERTIES |
| 393 | COMPILE_FLAGS "-std=c99" | 393 | COMPILE_FLAGS "-std=c99 -O3" |
| 394 | ) | 394 | ) |
| 395 | endif() | 395 | endif() |
| 396 | target_include_directories(embedded_softfloat PUBLIC | 396 | target_include_directories(embedded_softfloat PUBLIC |
| ... | @@ -407,10 +407,9 @@ set(ZIG_SOURCES | ... | @@ -407,10 +407,9 @@ set(ZIG_SOURCES |
| 407 | "${CMAKE_SOURCE_DIR}/src/ast_render.cpp" | 407 | "${CMAKE_SOURCE_DIR}/src/ast_render.cpp" |
| 408 | "${CMAKE_SOURCE_DIR}/src/bigfloat.cpp" | 408 | "${CMAKE_SOURCE_DIR}/src/bigfloat.cpp" |
| 409 | "${CMAKE_SOURCE_DIR}/src/bigint.cpp" | 409 | "${CMAKE_SOURCE_DIR}/src/bigint.cpp" |
| 410 | "${CMAKE_SOURCE_DIR}/src/blake2b.cpp" | ||
| 411 | "${CMAKE_SOURCE_DIR}/src/buffer.cpp" | 410 | "${CMAKE_SOURCE_DIR}/src/buffer.cpp" |
| 412 | "${CMAKE_SOURCE_DIR}/src/cache_hash.cpp" | ||
| 413 | "${CMAKE_SOURCE_DIR}/src/c_tokenizer.cpp" | 411 | "${CMAKE_SOURCE_DIR}/src/c_tokenizer.cpp" |
| 412 | "${CMAKE_SOURCE_DIR}/src/cache_hash.cpp" | ||
| 414 | "${CMAKE_SOURCE_DIR}/src/codegen.cpp" | 413 | "${CMAKE_SOURCE_DIR}/src/codegen.cpp" |
| 415 | "${CMAKE_SOURCE_DIR}/src/errmsg.cpp" | 414 | "${CMAKE_SOURCE_DIR}/src/errmsg.cpp" |
| 416 | "${CMAKE_SOURCE_DIR}/src/error.cpp" | 415 | "${CMAKE_SOURCE_DIR}/src/error.cpp" |
| ... | @@ -426,6 +425,9 @@ set(ZIG_SOURCES | ... | @@ -426,6 +425,9 @@ set(ZIG_SOURCES |
| 426 | "${CMAKE_SOURCE_DIR}/src/util.cpp" | 425 | "${CMAKE_SOURCE_DIR}/src/util.cpp" |
| 427 | "${CMAKE_SOURCE_DIR}/src/translate_c.cpp" | 426 | "${CMAKE_SOURCE_DIR}/src/translate_c.cpp" |
| 428 | ) | 427 | ) |
| 428 | set(ZIG_SOURCES_O3 | ||
| 429 | "${CMAKE_SOURCE_DIR}/src/blake2b.cpp" | ||
| 430 | ) | ||
| 429 | set(ZIG_CPP_SOURCES | 431 | set(ZIG_CPP_SOURCES |
| 430 | "${CMAKE_SOURCE_DIR}/src/zig_llvm.cpp" | 432 | "${CMAKE_SOURCE_DIR}/src/zig_llvm.cpp" |
| 431 | "${CMAKE_SOURCE_DIR}/src/windows_sdk.cpp" | 433 | "${CMAKE_SOURCE_DIR}/src/windows_sdk.cpp" |
| ... | @@ -813,6 +815,11 @@ set_target_properties(zig_cpp PROPERTIES | ... | @@ -813,6 +815,11 @@ set_target_properties(zig_cpp PROPERTIES |
| 813 | COMPILE_FLAGS ${EXE_CFLAGS} | 815 | COMPILE_FLAGS ${EXE_CFLAGS} |
| 814 | ) | 816 | ) |
| 815 | 817 | ||
| 818 | add_library(zig_O3 STATIC ${ZIG_SOURCES_O3}) | ||
| 819 | set_target_properties(zig_O3 PROPERTIES | ||
| 820 | COMPILE_FLAGS "${EXE_CFLAGS} -O3" | ||
| 821 | ) | ||
| 822 | |||
| 816 | add_executable(zig ${ZIG_SOURCES}) | 823 | add_executable(zig ${ZIG_SOURCES}) |
| 817 | set_target_properties(zig PROPERTIES | 824 | set_target_properties(zig PROPERTIES |
| 818 | COMPILE_FLAGS ${EXE_CFLAGS} | 825 | COMPILE_FLAGS ${EXE_CFLAGS} |
| ... | @@ -821,6 +828,7 @@ set_target_properties(zig PROPERTIES | ... | @@ -821,6 +828,7 @@ set_target_properties(zig PROPERTIES |
| 821 | 828 | ||
| 822 | target_link_libraries(zig LINK_PUBLIC | 829 | target_link_libraries(zig LINK_PUBLIC |
| 823 | zig_cpp | 830 | zig_cpp |
| 831 | zig_O3 | ||
| 824 | ${SOFTFLOAT_LIBRARIES} | 832 | ${SOFTFLOAT_LIBRARIES} |
| 825 | ${CLANG_LIBRARIES} | 833 | ${CLANG_LIBRARIES} |
| 826 | ${LLD_LIBRARIES} | 834 | ${LLD_LIBRARIES} |
src/all_types.hpp+4| ... | @@ -10,6 +10,7 @@ | ... | @@ -10,6 +10,7 @@ |
| 10 | 10 | ||
| 11 | #include "list.hpp" | 11 | #include "list.hpp" |
| 12 | #include "buffer.hpp" | 12 | #include "buffer.hpp" |
| 13 | #include "cache_hash.hpp" | ||
| 13 | #include "zig_llvm.h" | 14 | #include "zig_llvm.h" |
| 14 | #include "hash_map.hpp" | 15 | #include "hash_map.hpp" |
| 15 | #include "errmsg.hpp" | 16 | #include "errmsg.hpp" |
| ... | @@ -1613,7 +1614,10 @@ struct CodeGen { | ... | @@ -1613,7 +1614,10 @@ struct CodeGen { |
| 1613 | ZigType *entry_promise; | 1614 | ZigType *entry_promise; |
| 1614 | } builtin_types; | 1615 | } builtin_types; |
| 1615 | 1616 | ||
| 1617 | CacheHash cache_hash; | ||
| 1618 | |||
| 1616 | //////////////////////////// Participates in Input Parameter Cache Hash | 1619 | //////////////////////////// Participates in Input Parameter Cache Hash |
| 1620 | Buf *compiler_id; | ||
| 1617 | ZigList<LinkLib *> link_libs_list; | 1621 | ZigList<LinkLib *> link_libs_list; |
| 1618 | // add -framework [name] args to linker | 1622 | // add -framework [name] args to linker |
| 1619 | ZigList<Buf *> darwin_frameworks; | 1623 | ZigList<Buf *> darwin_frameworks; |
src/cache_hash.cpp+4| ... | @@ -6,6 +6,7 @@ | ... | @@ -6,6 +6,7 @@ |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | #include "cache_hash.hpp" | 8 | #include "cache_hash.hpp" |
| 9 | #include "all_types.hpp" | ||
| 9 | #include "buffer.hpp" | 10 | #include "buffer.hpp" |
| 10 | #include "os.hpp" | 11 | #include "os.hpp" |
| 11 | 12 | ||
| ... | @@ -219,6 +220,9 @@ Error cache_hit(CacheHash *ch, Buf *out_digest) { | ... | @@ -219,6 +220,9 @@ Error cache_hit(CacheHash *ch, Buf *out_digest) { |
| 219 | 220 | ||
| 220 | buf_append_str(ch->manifest_file_path, ".txt"); | 221 | buf_append_str(ch->manifest_file_path, ".txt"); |
| 221 | 222 | ||
| 223 | if ((err = os_make_path(ch->manifest_dir))) | ||
| 224 | return err; | ||
| 225 | |||
| 222 | if ((err = os_file_open_lock_rw(ch->manifest_file_path, &ch->manifest_file))) | 226 | if ((err = os_file_open_lock_rw(ch->manifest_file_path, &ch->manifest_file))) |
| 223 | return err; | 227 | return err; |
| 224 | 228 |
src/cache_hash.hpp+2-1| ... | @@ -8,10 +8,11 @@ | ... | @@ -8,10 +8,11 @@ |
| 8 | #ifndef ZIG_CACHE_HASH_HPP | 8 | #ifndef ZIG_CACHE_HASH_HPP |
| 9 | #define ZIG_CACHE_HASH_HPP | 9 | #define ZIG_CACHE_HASH_HPP |
| 10 | 10 | ||
| 11 | #include "all_types.hpp" | ||
| 12 | #include "blake2.h" | 11 | #include "blake2.h" |
| 13 | #include "os.hpp" | 12 | #include "os.hpp" |
| 14 | 13 | ||
| 14 | struct LinkLib; | ||
| 15 | |||
| 15 | struct CacheHashFile { | 16 | struct CacheHashFile { |
| 16 | Buf *path; | 17 | Buf *path; |
| 17 | OsTimeStamp mtime; | 18 | OsTimeStamp mtime; |
src/codegen.cpp+55-36| ... | @@ -88,12 +88,13 @@ static const char *symbols_that_llvm_depends_on[] = { | ... | @@ -88,12 +88,13 @@ static const char *symbols_that_llvm_depends_on[] = { |
| 88 | }; | 88 | }; |
| 89 | 89 | ||
| 90 | CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out_type, BuildMode build_mode, | 90 | CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out_type, BuildMode build_mode, |
| 91 | Buf *zig_lib_dir) | 91 | Buf *zig_lib_dir, Buf *compiler_id) |
| 92 | { | 92 | { |
| 93 | CodeGen *g = allocate<CodeGen>(1); | 93 | CodeGen *g = allocate<CodeGen>(1); |
| 94 | 94 | ||
| 95 | codegen_add_time_event(g, "Initialize"); | 95 | codegen_add_time_event(g, "Initialize"); |
| 96 | 96 | ||
| 97 | g->compiler_id = compiler_id; | ||
| 97 | g->zig_lib_dir = zig_lib_dir; | 98 | g->zig_lib_dir = zig_lib_dir; |
| 98 | 99 | ||
| 99 | g->zig_std_dir = buf_alloc(); | 100 | g->zig_std_dir = buf_alloc(); |
| ... | @@ -7675,44 +7676,62 @@ void codegen_add_time_event(CodeGen *g, const char *name) { | ... | @@ -7675,44 +7676,62 @@ void codegen_add_time_event(CodeGen *g, const char *name) { |
| 7675 | } | 7676 | } |
| 7676 | 7677 | ||
| 7677 | 7678 | ||
| 7678 | //// Called before init() | 7679 | // Called before init() |
| 7679 | //static bool build_with_cache(CodeGen *g) { | 7680 | static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) { |
| 7680 | // // TODO zig exe & dynamic libraries | 7681 | Error err; |
| 7681 | // // should be in main.cpp I think. only needs to happen | 7682 | |
| 7682 | // // once on startup. | 7683 | CacheHash *ch = &g->cache_hash; |
| 7683 | // | 7684 | cache_init(ch, manifest_dir); |
| 7684 | // CacheHash comp; | 7685 | |
| 7685 | // cache_init(&comp); | 7686 | cache_buf(ch, g->compiler_id); |
| 7686 | // | 7687 | cache_buf(ch, g->root_out_name); |
| 7687 | // add_cache_buf(&blake, g->root_out_name); | 7688 | cache_file(ch, get_resolved_root_src_path(g)); // Root source file |
| 7688 | // add_cache_buf_opt(&blake, get_resolved_root_src_path(g)); // Root source file | 7689 | cache_list_of_link_lib(ch, g->link_libs_list.items, g->link_libs_list.length); |
| 7689 | // add_cache_list_of_link_lib(&blake, g->link_libs_list.items, g->link_libs_list.length); | 7690 | cache_list_of_buf(ch, g->darwin_frameworks.items, g->darwin_frameworks.length); |
| 7690 | // add_cache_list_of_buf(&blake, g->darwin_frameworks.items, g->darwin_frameworks.length); | 7691 | cache_list_of_buf(ch, g->rpath_list.items, g->rpath_list.length); |
| 7691 | // add_cache_list_of_buf(&blake, g->rpath_list.items, g->rpath_list.length); | 7692 | cache_int(ch, g->emit_file_type); |
| 7692 | // add_cache_int(&blake, g->emit_file_type); | 7693 | cache_int(ch, g->build_mode); |
| 7693 | // add_cache_int(&blake, g->build_mode); | 7694 | cache_int(ch, g->out_type); |
| 7694 | // add_cache_int(&blake, g->out_type); | 7695 | // TODO the rest of the struct CodeGen fields |
| 7695 | // // TODO the rest of the struct CodeGen fields | 7696 | |
| 7696 | // | 7697 | buf_resize(digest, 0); |
| 7697 | // uint8_t bin_digest[48]; | 7698 | if ((err = cache_hit(ch, digest))) |
| 7698 | // rc = blake2b_final(&blake, bin_digest, 48); | 7699 | return err; |
| 7699 | // assert(rc == 0); | 7700 | |
| 7700 | // | 7701 | return ErrorNone; |
| 7701 | // Buf b64_digest = BUF_INIT; | 7702 | } |
| 7702 | // buf_resize(&b64_digest, 64); | ||
| 7703 | // base64_encode(buf_to_slice(&b64_digest), {bin_digest, 48}); | ||
| 7704 | // | ||
| 7705 | // fprintf(stderr, "input params hash: %s\n", buf_ptr(&b64_digest)); | ||
| 7706 | // // TODO next look for a manifest file that has all the files from the input parameters | ||
| 7707 | // // use that to construct the real hash, which looks up the output directory and another manifest file | ||
| 7708 | // | ||
| 7709 | // return false; | ||
| 7710 | //} | ||
| 7711 | 7703 | ||
| 7712 | void codegen_build(CodeGen *g) { | 7704 | void codegen_build(CodeGen *g) { |
| 7705 | Error err; | ||
| 7713 | assert(g->out_type != OutTypeUnknown); | 7706 | assert(g->out_type != OutTypeUnknown); |
| 7714 | //if (build_with_cache(g)) | 7707 | |
| 7715 | // return; | 7708 | Buf app_data_dir = BUF_INIT; |
| 7709 | if ((err = os_get_app_data_dir(&app_data_dir, "zig"))) { | ||
| 7710 | fprintf(stderr, "Unable to get app data dir: %s\n", err_str(err)); | ||
| 7711 | exit(1); | ||
| 7712 | } | ||
| 7713 | Buf *stage1_dir = buf_alloc(); | ||
| 7714 | os_path_join(&app_data_dir, buf_create_from_str("stage1"), stage1_dir); | ||
| 7715 | |||
| 7716 | Buf *manifest_dir = buf_alloc(); | ||
| 7717 | os_path_join(stage1_dir, buf_create_from_str("build"), manifest_dir); | ||
| 7718 | |||
| 7719 | Buf digest = BUF_INIT; | ||
| 7720 | if ((err = check_cache(g, manifest_dir, &digest))) { | ||
| 7721 | fprintf(stderr, "Unable to check cache: %s\n", err_str(err)); | ||
| 7722 | exit(1); | ||
| 7723 | } | ||
| 7724 | if (buf_len(&digest) != 0) { | ||
| 7725 | Buf *artifact_dir = buf_alloc(); | ||
| 7726 | os_path_join(stage1_dir, buf_create_from_str("artifact"), artifact_dir); | ||
| 7727 | |||
| 7728 | Buf *this_artifact_dir = buf_alloc(); | ||
| 7729 | os_path_join(artifact_dir, &digest, this_artifact_dir); | ||
| 7730 | |||
| 7731 | fprintf(stderr, "copy artifacts from %s\n", buf_ptr(this_artifact_dir)); | ||
| 7732 | return; | ||
| 7733 | } | ||
| 7734 | |||
| 7716 | init(g); | 7735 | init(g); |
| 7717 | 7736 | ||
| 7718 | codegen_add_time_event(g, "Semantic Analysis"); | 7737 | codegen_add_time_event(g, "Semantic Analysis"); |
src/codegen.hpp+1-1| ... | @@ -15,7 +15,7 @@ | ... | @@ -15,7 +15,7 @@ |
| 15 | #include <stdio.h> | 15 | #include <stdio.h> |
| 16 | 16 | ||
| 17 | CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out_type, BuildMode build_mode, | 17 | CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out_type, BuildMode build_mode, |
| 18 | Buf *zig_lib_dir); | 18 | Buf *zig_lib_dir, Buf *compiler_id); |
| 19 | 19 | ||
| 20 | void codegen_set_clang_argv(CodeGen *codegen, const char **args, size_t len); | 20 | void codegen_set_clang_argv(CodeGen *codegen, const char **args, size_t len); |
| 21 | void codegen_set_llvm_argv(CodeGen *codegen, const char **args, size_t len); | 21 | void codegen_set_llvm_argv(CodeGen *codegen, const char **args, size_t len); |
src/link.cpp+1-1| ... | @@ -34,7 +34,7 @@ static const char *get_libc_static_file(CodeGen *g, const char *file) { | ... | @@ -34,7 +34,7 @@ static const char *get_libc_static_file(CodeGen *g, const char *file) { |
| 34 | static Buf *build_o_raw(CodeGen *parent_gen, const char *oname, Buf *full_path) { | 34 | static Buf *build_o_raw(CodeGen *parent_gen, const char *oname, Buf *full_path) { |
| 35 | ZigTarget *child_target = parent_gen->is_native_target ? nullptr : &parent_gen->zig_target; | 35 | ZigTarget *child_target = parent_gen->is_native_target ? nullptr : &parent_gen->zig_target; |
| 36 | CodeGen *child_gen = codegen_create(full_path, child_target, OutTypeObj, parent_gen->build_mode, | 36 | CodeGen *child_gen = codegen_create(full_path, child_target, OutTypeObj, parent_gen->build_mode, |
| 37 | parent_gen->zig_lib_dir); | 37 | parent_gen->zig_lib_dir, parent_gen->compiler_id); |
| 38 | 38 | ||
| 39 | child_gen->want_h_file = false; | 39 | child_gen->want_h_file = false; |
| 40 | child_gen->verbose_tokenize = parent_gen->verbose_tokenize; | 40 | child_gen->verbose_tokenize = parent_gen->verbose_tokenize; |
src/main.cpp+16-5| ... | @@ -274,8 +274,6 @@ static Error get_compiler_id(Buf **result) { | ... | @@ -274,8 +274,6 @@ static Error get_compiler_id(Buf **result) { |
| 274 | Buf *manifest_dir = buf_alloc(); | 274 | Buf *manifest_dir = buf_alloc(); |
| 275 | os_path_join(stage1_dir, buf_create_from_str("exe"), manifest_dir); | 275 | os_path_join(stage1_dir, buf_create_from_str("exe"), manifest_dir); |
| 276 | 276 | ||
| 277 | if ((err = os_make_path(manifest_dir))) | ||
| 278 | return err; | ||
| 279 | CacheHash cache_hash; | 277 | CacheHash cache_hash; |
| 280 | CacheHash *ch = &cache_hash; | 278 | CacheHash *ch = &cache_hash; |
| 281 | cache_init(ch, manifest_dir); | 279 | cache_init(ch, manifest_dir); |
| ... | @@ -432,8 +430,14 @@ int main(int argc, char **argv) { | ... | @@ -432,8 +430,14 @@ int main(int argc, char **argv) { |
| 432 | Buf *build_runner_path = buf_alloc(); | 430 | Buf *build_runner_path = buf_alloc(); |
| 433 | os_path_join(special_dir, buf_create_from_str("build_runner.zig"), build_runner_path); | 431 | os_path_join(special_dir, buf_create_from_str("build_runner.zig"), build_runner_path); |
| 434 | 432 | ||
| 433 | Buf *compiler_id; | ||
| 434 | if ((err = get_compiler_id(&compiler_id))) { | ||
| 435 | fprintf(stderr, "Unable to determine compiler id: %s\n", err_str(err)); | ||
| 436 | return EXIT_FAILURE; | ||
| 437 | } | ||
| 435 | 438 | ||
| 436 | CodeGen *g = codegen_create(build_runner_path, nullptr, OutTypeExe, BuildModeDebug, zig_lib_dir_buf); | 439 | CodeGen *g = codegen_create(build_runner_path, nullptr, OutTypeExe, BuildModeDebug, zig_lib_dir_buf, |
| 440 | compiler_id); | ||
| 437 | codegen_set_out_name(g, buf_create_from_str("build")); | 441 | codegen_set_out_name(g, buf_create_from_str("build")); |
| 438 | 442 | ||
| 439 | Buf *build_file_buf = buf_create_from_str(build_file); | 443 | Buf *build_file_buf = buf_create_from_str(build_file); |
| ... | @@ -796,7 +800,7 @@ int main(int argc, char **argv) { | ... | @@ -796,7 +800,7 @@ int main(int argc, char **argv) { |
| 796 | switch (cmd) { | 800 | switch (cmd) { |
| 797 | case CmdBuiltin: { | 801 | case CmdBuiltin: { |
| 798 | Buf *zig_lib_dir_buf = resolve_zig_lib_dir(); | 802 | Buf *zig_lib_dir_buf = resolve_zig_lib_dir(); |
| 799 | CodeGen *g = codegen_create(nullptr, target, out_type, build_mode, zig_lib_dir_buf); | 803 | CodeGen *g = codegen_create(nullptr, target, out_type, build_mode, zig_lib_dir_buf, nullptr); |
| 800 | Buf *builtin_source = codegen_generate_builtin_source(g); | 804 | Buf *builtin_source = codegen_generate_builtin_source(g); |
| 801 | if (fwrite(buf_ptr(builtin_source), 1, buf_len(builtin_source), stdout) != buf_len(builtin_source)) { | 805 | if (fwrite(buf_ptr(builtin_source), 1, buf_len(builtin_source), stdout) != buf_len(builtin_source)) { |
| 802 | fprintf(stderr, "unable to write to stdout: %s\n", strerror(ferror(stdout))); | 806 | fprintf(stderr, "unable to write to stdout: %s\n", strerror(ferror(stdout))); |
| ... | @@ -871,7 +875,14 @@ int main(int argc, char **argv) { | ... | @@ -871,7 +875,14 @@ int main(int argc, char **argv) { |
| 871 | 875 | ||
| 872 | Buf *zig_lib_dir_buf = resolve_zig_lib_dir(); | 876 | Buf *zig_lib_dir_buf = resolve_zig_lib_dir(); |
| 873 | 877 | ||
| 874 | CodeGen *g = codegen_create(zig_root_source_file, target, out_type, build_mode, zig_lib_dir_buf); | 878 | Buf *compiler_id; |
| 879 | if ((err = get_compiler_id(&compiler_id))) { | ||
| 880 | fprintf(stderr, "Unable to determine compiler id: %s\n", err_str(err)); | ||
| 881 | return EXIT_FAILURE; | ||
| 882 | } | ||
| 883 | |||
| 884 | CodeGen *g = codegen_create(zig_root_source_file, target, out_type, build_mode, zig_lib_dir_buf, | ||
| 885 | compiler_id); | ||
| 875 | codegen_set_out_name(g, buf_out_name); | 886 | codegen_set_out_name(g, buf_out_name); |
| 876 | codegen_set_lib_version(g, ver_major, ver_minor, ver_patch); | 887 | codegen_set_lib_version(g, ver_major, ver_minor, ver_patch); |
| 877 | codegen_set_is_test(g, cmd == CmdTest); | 888 | codegen_set_is_test(g, cmd == CmdTest); |