diff --git a/.gitignore b/.gitignore
index c2fb7842..5e9c1021 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,7 +7,3 @@
*.pdb
.vs/*
unused/
-
-# Build / output directories
-build/
-out/
diff --git a/.natvis b/.natvis
index a20fc2dd..cc38eaa2 100644
--- a/.natvis
+++ b/.natvis
@@ -4,7 +4,13 @@
{text, [len] s} ({len})
<NULL>
- text, [len]
+ text, [len] s
+
+
+
+ {text, [len] su} ({len})
+ <NULL>
+ text, [len] su
@@ -24,7 +30,6 @@
-
bits: [{cur_bit} / {data_nbits}], bytes: [{cur_bit / 8} / {data_nbits / 8}]
@@ -35,4 +40,27 @@
-
\ No newline at end of file
+
+ {text, [len] s} ({len})
+ <NULL>
+ text, [len]
+
+
+
+ pos: {pos}, capacity: [{capacity} / {reserved}]
+
+ - base, [pos] s
+ - base, [pos+100] s
+
+
+
+
+ start: {start_pos}, arena: {{{*arena}}}
+
+ - (arena->base + start_pos), [arena->pos - start_pos] s
+ - (arena->base + start_pos), [arena->pos - start_pos + 100] s
+ - arena->pos - start_pos
+
+
+
+
diff --git a/build.c b/build.c
index a94a01ef..44a343e3 100644
--- a/build.c
+++ b/build.c
@@ -1,59 +1,6 @@
#define Rtc 1
#include "buildit.h"
-#include
-
-/* Capabilities:
- *
- * Run commands. Return result of command.
- *
- *
- */
-
-/* ========================== *
- * Globals
- * ========================== */
-
-/* ========================== *
- * Args
- * ========================== */
-
-#define ARGS_XLIST(X) \
- X(CLANG, "clang", "Compile with clang") \
- X(MSVC, "msvc", "Compile with msvc") \
- X(RTC, "rtc", "Should the build compile with runtime checks enabled (asserts, asan, etc.) - Requires crtlib") \
- X(ASAN, "asan", "Should the build compile with the address sanitizer enabled (asserts, asan, etc.) - Requires crtlib") \
- X(CRTLIB, "crtlib", "Should the build link with the CRTLIB") \
- X(DEBINFO, "debinfo", "Should the build compile with debug info") \
- X(DEVELOPER, "developer", "Should the build compile with developer mode enabled") \
- X(PROFILING, "profiling", "Should the build compile with profiling enabled - Requires crtlib, clang") \
- X(UNOPTIMIZED, "unoptimized", "Should the build compile with optimization disabled")
-
-/* Make args global variables */
-#define X(id, str, desc) bool id = 0;
-ARGS_XLIST(X)
-#undef X
-
-/* Setup arg table */
-#define X(id, str, desc) _ARGID_ ## id,
-enum ArgId {
- ARGS_XLIST(X)
- ARGS_COUNT
-};
-#undef X
-
-typedef struct ArgEntry ArgEntry;
-struct ArgEntry {
- String name;
- bool *var;
-};
-
-#define X(id, str, desc) [_ARGID_ ## id] = { .name = Lit(str), .var = &id },
-ArgEntry arg_entries[ARGS_COUNT] = {
- ARGS_XLIST(X)
-};
-#undef X
-
/* ========================== *
* Util
* ========================== */
@@ -67,28 +14,30 @@ void Error(String msg)
* Compile command
* ========================== */
-typedef struct CompileCommandListNode CompileCommandListNode;
-struct CompileCommandListNode {
- String comp_command;
+typedef struct StepListNode StepListNode;
+struct StepListNode {
+ String name;
+ String cmd;
String link_file_path;
- Bool silent_if_success;
- CompileCommandListNode *next;
- CompileCommandListNode *prev;
+ Bool silence_output_if_success;
+ StepListNode *next;
+ StepListNode *prev;
};
-typedef struct CompileCommandList CompileCommandList;
-struct CompileCommandList {
- CompileCommandListNode *first;
- CompileCommandListNode *last;
+typedef struct StepList StepList;
+struct StepList {
+ StepListNode *first;
+ StepListNode *last;
Size count;
};
-void CompileCommandListAppend(Arena *arena, CompileCommandList *l, String comp_command, String link_file_path, Bool silent_if_success)
+void StepListAppend(Arena *arena, StepList *l, String name, String cmd, String link_file_path, Bool silence_output_if_success)
{
- CompileCommandListNode *n = ArenaPush(arena, CompileCommandListNode);
- n->comp_command = comp_command;
+ StepListNode *n = ArenaPush(arena, StepListNode);
+ n->name = name;
+ n->cmd = cmd;
n->link_file_path = link_file_path;
- n->silent_if_success = silent_if_success;
+ n->silence_output_if_success = silence_output_if_success;
DllPushBack(l->first, l->last, n);
++l->count;
}
@@ -125,77 +74,62 @@ void RcIncludeListAppend(Arena *arena, RcIncludeList *l, D_Tag tag, String rc_ty
* Build
* ========================== */
-void OnBuild(StringList args_list)
+void OnBuild(StringList cli_args)
{
Arena arena = ArenaAlloc(Gigabyte(64));
/* ========================== *
- * Unpack command line args
+ * Read args
* ========================== */
- for (StringListNode *n = args_list.first; n; n = n->next) {
- String arg_name = n->string;
- for (int i = 0; i < ArrayCount(arg_entries); ++i) {
- ArgEntry *entry = &arg_entries[i];
- if (StringEqual(arg_name, entry->name)) {
- *entry->var = 1;
+ String arg_outdir = Lit("build");
+ Bool arg_msvc = false;
+ Bool arg_rtc = false;
+ Bool arg_asan = false;
+ Bool arg_crtlib = false;
+ Bool arg_debinfo = false;
+ Bool arg_developer = false;
+ Bool arg_profiling = false;
+ Bool arg_unoptimized = false;
+
+ {
+ typedef enum ArgState {
+ ArgState_None,
+ ArgState_OutputDir
+ } ArgState;
+
+ ArgState arg_state = ArgState_None;
+ for (StringListNode *n = cli_args.first; n; n = n->next) {
+ String arg = n->string;
+ if (n != cli_args.first) {
+ switch (arg_state) {
+ case ArgState_OutputDir:
+ {
+ arg_outdir = arg;
+ arg_state = ArgState_None;
+ } break;
+
+ default:
+ {
+ if (StringEqual(arg, Lit("-O"))) arg_state = ArgState_OutputDir;
+ if (StringEqual(arg, Lit("-clang"))) arg_msvc = false;
+ if (StringEqual(arg, Lit("-msvc"))) arg_msvc = true;
+ if (StringEqual(arg, Lit("-rtc"))) arg_rtc = true;
+ if (StringEqual(arg, Lit("-asan"))) arg_asan = true;
+ if (StringEqual(arg, Lit("-crtlib"))) arg_crtlib = true;
+ if (StringEqual(arg, Lit("-debinfo"))) arg_debinfo = true;
+ if (StringEqual(arg, Lit("-developer"))) arg_developer = true;
+ if (StringEqual(arg, Lit("-profiling"))) arg_profiling = true;
+ if (StringEqual(arg, Lit("-unoptimized"))) arg_unoptimized = true;
+ } break;
+ }
}
}
}
- if (MSVC && CLANG) {
- Error(Lit("Msvc & clang arguments cannot both be set"));
- OS_Exit(1);
- } else if (!(MSVC || CLANG)) {
- CLANG = 1;
- }
-
- if (MSVC) CLANG = 0;
- if (CLANG) MSVC = 0;
-
- /* ========================== *
- * Determine output dir
- * ========================== */
-
- String out_obj_dir_path = { 0 };
- String out_inc_dir_path = { 0 };
- String out_bin_dir_path = { 0 };
- {
- StringList out_dir_path_parts = { 0 };
- if (CLANG) {
- StringListAppend(&arena, &out_dir_path_parts, Lit("clang"));
- } else if (MSVC) {
- StringListAppend(&arena, &out_dir_path_parts, Lit("msvc"));
- }a
- if (DEVELOPER) {
- StringListAppend(&arena, &out_dir_path_parts, Lit("developer"));
- } else if (MSVC) {
- StringListAppend(&arena, &out_dir_path_parts, Lit("user"));
- }
- if (RTC) {
- StringListAppend(&arena, &out_dir_path_parts, Lit("rtc"));
- }
- if (ASAN) {
- StringListAppend(&arena, &out_dir_path_parts, Lit("asan"));
- }
- if (CRTLIB) {
- StringListAppend(&arena, &out_dir_path_parts, Lit("crtlib"));
- }
- if (DEBINFO) {
- StringListAppend(&arena, &out_dir_path_parts, Lit("debinfo"));
- }
- if (PROFILING) {
- StringListAppend(&arena, &out_dir_path_parts, Lit("profiling"));
- }
- if (UNOPTIMIZED) {
- StringListAppend(&arena, &out_dir_path_parts, Lit("unoptimized"));
- }
-
- String out_dir_name = StringFromStringList(&arena, Lit("-"), out_dir_path_parts);
- out_obj_dir_path = OS_GetAbsPath(&arena, StringF(&arena, Lit("build/%F/obj/"), FmtStr(out_dir_name)));
- out_inc_dir_path = OS_GetAbsPath(&arena, StringF(&arena, Lit("build/%F/inc/"), FmtStr(out_dir_name)));
- out_bin_dir_path = OS_GetAbsPath(&arena, StringF(&arena, Lit("build/%F/bin/"), FmtStr(out_dir_name)));
- }
+ String out_obj_dir_path = OS_GetAbsPath(&arena, StringF(&arena, Lit("%F/obj/"), FmtStr(arg_outdir)));
+ String out_inc_dir_path = OS_GetAbsPath(&arena, StringF(&arena, Lit("%F/inc/"), FmtStr(arg_outdir)));
+ String out_bin_dir_path = OS_GetAbsPath(&arena, StringF(&arena, Lit("%F/bin/"), FmtStr(arg_outdir)));
if (!OS_DirExists(out_obj_dir_path)) {
OS_CreateDirAtAbsPath(out_obj_dir_path);
@@ -207,18 +141,47 @@ void OnBuild(StringList args_list)
OS_CreateDirAtAbsPath(out_bin_dir_path);
}
+ SH_Print(Lit("------------------------------\n"));
+ if (arg_msvc) {
+ SH_Print(Lit("* Compiler: Msvc *\n"));
+ } else {
+ SH_Print(Lit("* Compiler: Clang *\n"));
+ }
+ if (arg_asan) SH_Print(Lit("Asan Enabled\n"));
+ if (arg_profiling) SH_Print(Lit("Profiling\n"));
+ if (arg_developer) SH_Print(Lit("Developer build enabled\n"));
+ SH_PrintF(Lit("Building to \"%F\"\n"), FmtStr(out_bin_dir_path));
+ SH_Print(Lit("------------------------------\n\n"));
+
/* ========================== *
* Constants
* ========================== */
- CompileCommandList compile_command_list = { 0 };
+ StepList compile_command_list = { 0 };
- String obj_file_extension = PlatformWindows ? Lit("obj") : Lit("o");
+ String obj_file_extension = Lit("obj");
D_Tag executable = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/PowerPlay.exe"), FmtStr(out_bin_dir_path)));
+ D_Tag pdb = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/PowerPlay.pdb"), FmtStr(out_bin_dir_path)));
+ D_Tag pch_header = D_FileTagFromPath(&arena, Lit("src/common.h"));
+ D_Tag pch_c_output = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/common.c.pch"), FmtStr(out_obj_dir_path)));
+ D_Tag pch_c_obj_output = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/common.c.obj"), FmtStr(out_obj_dir_path)));
+ D_Tag pch_cpp_output = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/common.cpp.pch"), FmtStr(out_obj_dir_path)));
+ D_Tag pch_cpp_obj_output = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/common.cpp.obj"), FmtStr(out_obj_dir_path)));
+
+#if 0
+#if 1
+ D_Tag pch_h_input = D_FileTagFromPath(&arena, Lit("src/common.h"));
+ D_Tag pch_c_src_gen = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/common.c"), FmtStr(out_obj_dir_path)));
+ D_Tag pch_cpp_src_gen = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/common.cpp"), FmtStr(out_obj_dir_path)));
+ D_Tag pch_c_output = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/common.c.pch"), FmtStr(out_obj_dir_path)));
+ D_Tag pch_cpp_output = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/common.cpp.pch"), FmtStr(out_obj_dir_path)));
+#else
D_Tag pch_input = D_FileTagFromPath(&arena, Lit("src/common.h"));
D_Tag pch_c_output = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/common_c.pch"), FmtStr(out_obj_dir_path)));
D_Tag pch_cpp_output = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/common_cpp.pch"), FmtStr(out_obj_dir_path)));
+#endif
+#endif
/* ========================== *
* Determine compiler args
@@ -231,7 +194,7 @@ void OnBuild(StringList args_list)
String final_link_args_fmt = { 0 };
{
- StringList warnings = { 0 };
+ StringList compile_warnings = { 0 };
StringList compile_and_link_args = { 0 };
StringList compile_args = { 0 };
@@ -240,30 +203,42 @@ void OnBuild(StringList args_list)
StringList pch_c_compile_args = { 0 };
StringList pch_cpp_compile_args = { 0 };
+ StringList link_warnings = { 0 };
StringList link_args = { 0 };
- if (CLANG) {
-#if 1
+ if (arg_msvc) {
+ /* Msvc */
+ StringListAppend(&arena, &c_compile_args, Lit("cl.exe /nologo /c \"%F\" /Fo\"%F\""));
+ StringListAppend(&arena, &cpp_compile_args, Lit("cl.exe /nologo /c \"%F\" /Fo\"%F\""));
+ StringListAppend(&arena, &pch_c_compile_args, Lit("cl.exe /nologo /c /Yc\"%F\" \"%F\""));
+ StringListAppend(&arena, &pch_cpp_compile_args, Lit("cl.exe /nologo /c /Yc\"%F\" \"%F\""));
+
+ StringListAppend(&arena, &c_compile_args, StringF(&arena, Lit("/Yu\"%F\" /FI\"%F\" /Fp\"%F\""), FmtStr(pch_header.full_path), FmtStr(pch_header.full_path), FmtStr(pch_c_output.full_path)));
+ StringListAppend(&arena, &cpp_compile_args, StringF(&arena, Lit("/Yu\"%F\" /FI\"%F\" /Fp\"%F\""), FmtStr(pch_header.full_path), FmtStr(pch_header.full_path), FmtStr(pch_cpp_output.full_path)));
+ StringListAppend(&arena, &pch_c_compile_args, StringF(&arena, Lit("/FI\"%F\" /Fp\"%F\" /Fo\"%F\""), FmtStr(pch_header.full_path), FmtStr(pch_c_output.full_path), FmtStr(pch_c_obj_output.full_path)));
+ StringListAppend(&arena, &pch_cpp_compile_args, StringF(&arena, Lit("/FI\"%F\" /Fp\"%F\" /Fo\"%F\""), FmtStr(pch_header.full_path), FmtStr(pch_cpp_output.full_path), FmtStr(pch_cpp_obj_output.full_path)));
+
+ StringListAppend(&arena, &link_args, Lit("link.exe /nologo %F"));
+ StringListAppend(&arena, &link_args, StringF(&arena, Lit("/OUT:\"%F\" /PDB:\"%F\" /DEBUG:FULL /OPT:REF /OPT:ICF /NODEFAULTLIB:LIBCMT"), FmtStr(executable.full_path), FmtStr(pdb.full_path)));
+
+ String warnings = Lit("/WX /Wall "
+ "/wd4820 /wd4201 /wd5220 /wd4514 /wd4244 /wd5045 /wd4242 /wd4061 /wd4189 /wd4723 /wd5246");
+ StringListAppend(&arena, &compile_warnings, warnings);
+ StringListAppend(&arena, &link_warnings, Lit("/WX"));
+
+ StringListAppend(&arena, &compile_args, StringF(&arena, Lit("/Fd\"%F\\\""), FmtStr(out_bin_dir_path)));
+ } else {
+ /* Clang */
StringListAppend(&arena, &c_compile_args, Lit("clang -xc -std=c99 -c %F -o %F"));
- StringListAppend(&arena, &pch_c_compile_args, Lit("clang -xc-header -std=c99 -c %F -o %F"));
StringListAppend(&arena, &cpp_compile_args, Lit("clang -xc++ -std=c++20 -c %F -o %F"));
+ StringListAppend(&arena, &pch_c_compile_args, Lit("clang -xc-header -std=c99 -c %F -o %F"));
StringListAppend(&arena, &pch_cpp_compile_args, Lit("clang -xc++-header -std=c++20 -c %F -o %F"));
- StringListAppend(&arena, &link_args, Lit("clang %F -o %F"));
-#else
- StringListAppend(&arena, &compile_args, Lit("clang -c"));
- StringListAppend(&arena, &link_args, Lit("lld-link"));
+ StringListAppend(&arena, &c_compile_args, StringF(&arena, Lit("-include-pch %F"), FmtStr(pch_c_output.full_path)));
+ StringListAppend(&arena, &cpp_compile_args, StringF(&arena, Lit("-include-pch %F"), FmtStr(pch_cpp_output.full_path)));
- StringListAppend(&arena, &c_compile_args, Lit("-std=c99"));
- StringListAppend(&arena, &pch_c_compile_args, Lit("-x c-header -std=c99"));
- StringListAppend(&arena, &cpp_compile_args, Lit("-std=c++20"));
- StringListAppend(&arena, &pch_cpp_compile_args, Lit("-x c++-header -std=c++20"));
-
- StringListAppend(&arena, &compile_args, Lit("-o %F %F"));
- StringListAppend(&arena, &link_args, Lit("%F"));
-#endif
-
- //"-fuse-ld=lld-link"
+ StringListAppend(&arena, &link_args, Lit("clang %F"));
+ StringListAppend(&arena, &link_args, StringF(&arena, Lit("-o \"%F\""), FmtStr(executable.full_path)));
StringListAppend(&arena,
&compile_and_link_args,
@@ -275,40 +250,38 @@ void OnBuild(StringList args_list)
"-msse4.1 "
"-msse4.2 "));
- StringListAppend(&arena,
- &warnings,
- Lit("-Weverything -Werror "
- "-Wframe-larger-than=65536 "
- "-Wno-unused-macros -Wno-gnu-zero-variadic-macro-arguments -Wno-documentation "
- "-Wno-old-style-cast -Wno-conversion -Wno-sign-conversion "
- "-Wno-declaration-after-statement -Wno-extra-semi -Wno-extra-semi-stmt "
- "-Wno-bad-function-cast -Wno-class-varargs -Wno-unreachable-code-break "
- "-Wno-cast-align -Wno-float-equal -Wno-zero-as-null-pointer-constant "
- "-Wno-cast-qual -Wno-missing-noreturn -Wno-missing-field-initializers "
- "-Wno-missing-braces -Wno-initializer-overrides "
- "-Wno-c99-extensions -Wno-c++98-compat-pedantic -Wno-c++98-compat "
- "-Wno-switch-enum -Wno-switch-default "
- "-Wno-reserved-identifier -Wno-reserved-macro-identifier "
- "-Wno-unsafe-buffer-usage -Wno-writable-strings "
- ""
- "-Wno-double-promotion"));
-
+ String warnings = Lit("-Weverything -Werror "
+ "-Wframe-larger-than=65536 "
+ "-Wno-unused-macros -Wno-gnu-zero-variadic-macro-arguments -Wno-documentation "
+ "-Wno-old-style-cast -Wno-conversion -Wno-sign-conversion "
+ "-Wno-declaration-after-statement -Wno-extra-semi -Wno-extra-semi-stmt "
+ "-Wno-bad-function-cast -Wno-class-varargs -Wno-unreachable-code-break "
+ "-Wno-cast-align -Wno-float-equal -Wno-zero-as-null-pointer-constant "
+ "-Wno-cast-qual -Wno-missing-noreturn -Wno-missing-field-initializers "
+ "-Wno-missing-braces -Wno-initializer-overrides "
+ "-Wno-c99-extensions -Wno-c++98-compat-pedantic -Wno-c++98-compat "
+ "-Wno-switch-enum -Wno-switch-default "
+ "-Wno-reserved-identifier -Wno-reserved-macro-identifier "
+ "-Wno-unsafe-buffer-usage -Wno-writable-strings "
+ ""
+ "-Wno-c11-extensions -Wno-gnu-anonymous-struct -Wno-nested-anon-types "
+ ""
+ "-Wno-double-promotion");
/* -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-parameter */
- /* Pre-compiled header */
- StringListAppend(&arena, &c_compile_args, StringF(&arena, Lit("-include-pch %F"), FmtStr(pch_c_output.full_path)));
- StringListAppend(&arena, &cpp_compile_args, StringF(&arena, Lit("-include-pch %F"), FmtStr(pch_cpp_output.full_path)));
+ StringListAppend(&arena, &compile_warnings, warnings);
+ StringListAppend(&arena, &link_warnings, warnings);
}
/* RTC */
- if (RTC) {
- if (!CRTLIB) {
+ if (arg_rtc) {
+ if (!arg_crtlib) {
Error(Lit("CRTLIB (C runtime library) Must be enabled when compiling with RTC (runtime checks)"));
OS_Exit(1);
}
- StringListAppend(&arena, &compile_and_link_args, Lit("-DRTC=1"));
- if (MSVC) {
- if (!ASAN) {
+ StringListAppend(&arena, &compile_args, Lit("-DRTC=1"));
+ if (arg_msvc) {
+ if (!arg_asan) {
/* Enable /RTC option (not compatible with ASAN) */
StringListAppend(&arena, &compile_and_link_args, Lit("/RTCcsu"));
}
@@ -320,21 +293,21 @@ void OnBuild(StringList args_list)
}
/* CRTLIB */
- if (CRTLIB) {
- StringListAppend(&arena, &compile_and_link_args, Lit("-DCRTLIB=1"));
+ if (arg_crtlib) {
+ StringListAppend(&arena, &compile_args, Lit("-DCRTLIB=1"));
String crt_libs = { 0 };
- if (MSVC) {
- crt_libs = RTC ?
+ if (arg_msvc) {
+ crt_libs = arg_rtc ?
Lit("msvcrtd.lib ucrtd.lib msvcprtd.lib vcruntimed.lib") :
Lit("msvcrt.lib ucrt.lib msvcprt.lib vcruntime.lib");
} else {
- crt_libs = RTC ?
+ crt_libs = arg_rtc ?
Lit("-lmsvcrtd -lucrtd -lmsvcprtd -lvcruntimed") :
Lit("-lmsvcrt -lucrt -lmsvcprt -lvcruntime");
}
StringListAppend(&arena, &link_args, crt_libs);
} else {
- if (MSVC) {
+ if (arg_msvc) {
/* TODO */
Error(Lit("TODO\n"));
OS_Exit(1);
@@ -344,73 +317,88 @@ void OnBuild(StringList args_list)
}
/* Optimization */
- if (UNOPTIMIZED) {
- StringListAppend(&arena, &compile_and_link_args, Lit("-DUNOPTIMIZED=1"));
- StringListAppend(&arena, &compile_and_link_args, MSVC ? Lit("/Od") : Lit("-O0"));
+ if (arg_unoptimized) {
+ StringListAppend(&arena, &compile_args, Lit("-DUNOPTIMIZED=1"));
+ if (arg_msvc) {
+ StringListAppend(&arena, &compile_args, Lit("/Od"));
+ } else {
+ StringListAppend(&arena, &compile_and_link_args, Lit("-O0"));
+ }
} else {
- StringListAppend(&arena, &compile_and_link_args, MSVC ? Lit("/O2 /LTCG") : Lit("-O3 -flto"));
+ if (arg_msvc) {
+ StringListAppend(&arena, &compile_args, Lit("/O2"));
+ StringListAppend(&arena, &link_args, Lit("/LTCG"));
+ } else {
+ StringListAppend(&arena, &compile_and_link_args, Lit("-O3 -flto"));
+ }
}
/* Debug info */
- if (DEBINFO) {
- StringListAppend(&arena, &compile_and_link_args, Lit("-DDEBINFO=1"));
- StringListAppend(&arena, &compile_and_link_args, MSVC ? Lit("/Zi") : Lit("-g"));
+ if (arg_debinfo) {
+ StringListAppend(&arena, &compile_args, Lit("-DDEBINFO=1"));
+ if (arg_msvc) {
+ StringListAppend(&arena, &compile_args, Lit("/Zi"));
+ } else {
+ StringListAppend(&arena, &compile_and_link_args, Lit("-g"));
+ }
}
/* Address sanitizer */
- if (ASAN) {
- if (!CRTLIB) {
+ if (arg_asan) {
+ if (!arg_crtlib) {
Error(Lit("CRTLIB (C runtime library) Must be enabled when compiling with asan enabled"));
OS_Exit(1);
}
- StringListAppend(&arena, &compile_and_link_args, Lit("-DASAN=1"));
- if (MSVC) {
- /* TODO: Copy asan libs */
- StringListAppend(&arena, &compile_and_link_args, Lit("/fsanitize=address"));
+ StringListAppend(&arena, &compile_args, Lit("-DASAN=1"));
+ if (arg_msvc) {
+ StringListAppend(&arena, &compile_args, Lit("/fsanitize=address"));
} else {
StringListAppend(&arena, &compile_and_link_args, Lit("-fsanitize=address -shared-libasan"));
}
}
/* Developer mode */
- if (DEVELOPER) {
- StringListAppend(&arena, &compile_and_link_args, Lit("-DDEVELOPER=1"));
+ if (arg_developer) {
+ StringListAppend(&arena, &compile_args, Lit("-DDEVELOPER=1"));
}
/* Profiling */
- if (PROFILING) {
- if (!CRTLIB) {
+ if (arg_profiling) {
+ if (!arg_crtlib) {
Error(Lit("CRTLIB (C runtime library) Must be enabled when compiling with profiling enabled"));
OS_Exit(1);
}
- if (MSVC) {
+ if (arg_msvc) {
Error(Lit("MSVC not supported with profiling enabled (Profiling relies on Clang attributes)"));
OS_Exit(1);
}
- StringListAppend(&arena, &compile_and_link_args, Lit("-DPROFILING=1"));
+ StringListAppend(&arena, &compile_args, Lit("-DPROFILING=1"));
/* Tracy flags */
- StringListAppend(&arena, &compile_and_link_args, Lit("-DTRACY_ENABLE=1"));
- StringListAppend(&arena, &compile_and_link_args, Lit("-DTRACY_CALLSTACK=5"));
- StringListAppend(&arena, &compile_and_link_args, Lit("-DTRACY_NO_SAMPLING -DTRACY_NO_SYSTEM_TRACING -DTRACY_NO_CALLSTACK"));
- /* Disable warnings when compiling tracy client */
- warnings = (StringList) { 0 };
+ StringListAppend(&arena, &compile_args, Lit("-DTRACY_ENABLE=1"));
+ StringListAppend(&arena, &compile_args, Lit("-DTRACY_CALLSTACK=5"));
+ StringListAppend(&arena, &compile_args, Lit("-DTRACY_NO_SAMPLING -DTRACY_NO_SYSTEM_TRACING -DTRACY_NO_CALLSTACK"));
+ /* Disable compile_warnings when compiling tracy client */
+ compile_warnings = (StringList) { 0 };
+ link_warnings = (StringList) { 0 };
}
- String incbin_dir = StringReplace(&arena, out_inc_dir_path, Lit("\\"), Lit("/"));
- StringListAppend(&arena, &compile_and_link_args, StringF(&arena, Lit("-DINCBIN_DIR=\"%F\""), FmtStr(incbin_dir)));
+ if (!arg_msvc) {
+ String incbin_dir = StringReplace(&arena, out_inc_dir_path, Lit("\\"), Lit("/"));
+ StringListAppend(&arena, &compile_args, StringF(&arena, Lit("-DINCBIN_DIR_RAW=\"%F\""), FmtStr(incbin_dir)));
+ }
- final_c_compile_args_fmt = StringFromStringLists(&arena, Lit(" "), c_compile_args, compile_args, compile_and_link_args, warnings);
- final_cpp_compile_args_fmt = StringFromStringLists(&arena, Lit(" "), cpp_compile_args, compile_args, compile_and_link_args, warnings);
- final_pch_c_compile_args_fmt = StringFromStringLists(&arena, Lit(" "), pch_c_compile_args, compile_args, compile_and_link_args);
- final_pch_cpp_compile_args_fmt = StringFromStringLists(&arena, Lit(" "), pch_cpp_compile_args, compile_args, compile_and_link_args);
- final_link_args_fmt = StringFromStringLists(&arena, Lit(" "), link_args, compile_and_link_args, warnings);
+ final_c_compile_args_fmt = StringFromStringLists(&arena, Lit(" "), c_compile_args, compile_warnings, compile_and_link_args, compile_args);
+ final_cpp_compile_args_fmt = StringFromStringLists(&arena, Lit(" "), cpp_compile_args, compile_warnings, compile_and_link_args, compile_args);
+ final_pch_c_compile_args_fmt = StringFromStringLists(&arena, Lit(" "), pch_c_compile_args, compile_warnings, compile_and_link_args, compile_args);
+ final_pch_cpp_compile_args_fmt = StringFromStringLists(&arena, Lit(" "), pch_cpp_compile_args, compile_warnings, compile_and_link_args, compile_args);
+ final_link_args_fmt = StringFromStringLists(&arena, Lit(" "), link_args, link_warnings, compile_and_link_args);
}
/* ========================== *
* Generate embeddable tar files
* ========================== */
- bool embed_in_rc = !!MSVC;
+ Bool embed_in_rc = !!arg_msvc;
D_Tag res_dir = D_DirTagFromPath(&arena, Lit("res"));
D_Tag shaders_dir = D_DirTagFromPath(&arena, Lit("src/shaders"));
@@ -428,11 +416,12 @@ void OnBuild(StringList args_list)
}
if (D_IsDirty(shaders_tar)) {
String tar_cmd = StringF(&arena, Lit("cd %F && tar cvf %F ."), FmtStr(shaders_dir.full_path), FmtStr(shaders_tar.full_path));
- CompileCommandListAppend(&arena, &compile_command_list, tar_cmd, (String) { 0 }, true);
+ String step_name = StringF(&arena, Lit("Generating archive: %F"), FmtStr(D_GetName(shaders_tar)));
+ StepListAppend(&arena, &compile_command_list, step_name, tar_cmd, (String) { 0 }, true);
}
/* Generate res tar */
- if (!DEVELOPER) {
+ if (!arg_developer) {
D_Tag res_tar = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/res.tar"), FmtStr(out_inc_dir_path)));
D_AddDependency(res_tar, res_dir);
if (embed_in_rc) {
@@ -442,7 +431,8 @@ void OnBuild(StringList args_list)
}
if (D_IsDirty(res_tar)) {
String tar_cmd = StringF(&arena, Lit("cd %F && tar cvf %F ."), FmtStr(res_dir.full_path), FmtStr(res_tar.full_path));
- CompileCommandListAppend(&arena, &compile_command_list, tar_cmd, (String) { 0 }, true);
+ String step_name = StringF(&arena, Lit("Archiving %F"), FmtStr(D_GetName(res_tar)));
+ StepListAppend(&arena, &compile_command_list, step_name, tar_cmd, (String) { 0 }, true);
}
}
@@ -451,7 +441,7 @@ void OnBuild(StringList args_list)
* ========================== */
if (PlatformWindows) {
- D_Tag rc_file = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/rc.rc"), FmtStr(out_obj_dir_path)));;
+ D_Tag rc_file = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/rc.rc"), FmtStr(out_inc_dir_path)));;
/* Add icon file to rc list */
{
@@ -474,31 +464,53 @@ void OnBuild(StringList args_list)
}
/* Append rc -> res compile command */
- D_Tag rc_res_file = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/rc.res"), FmtStr(out_obj_dir_path)));;
+ D_Tag rc_res_file = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F/rc.res"), FmtStr(out_obj_dir_path)));
String rc_compile_cmd = { 0 };
- if (MSVC) {
- rc_compile_cmd = StringF(&arena, Lit("rc %F"), FmtStr(rc_file.full_path));
+ if (arg_msvc) {
+ rc_compile_cmd = StringF(&arena, Lit("rc /fo\"%F\" \"%F\""), FmtStr(rc_res_file.full_path), FmtStr(rc_file.full_path));
} else {
- rc_compile_cmd = StringF(&arena, Lit("llvm-rc %F"), FmtStr(rc_file.full_path));
+ rc_compile_cmd = StringF(&arena, Lit("llvm-rc /fo\"%F\" \"%F\""), FmtStr(rc_res_file.full_path), FmtStr(rc_file.full_path));
}
- CompileCommandListAppend(&arena, &compile_command_list, rc_compile_cmd, rc_res_file.full_path, true);
+ StepListAppend(&arena, &compile_command_list, D_GetName(rc_file), rc_compile_cmd, rc_res_file.full_path, true);
}
}
+
/* ========================== *
- * Add pch compile commands
+ * PCH compile commands
* ========================== */
- {
+ if (arg_msvc) {
/* C */
{
- String comp_cmd = StringF(&arena, final_pch_c_compile_args_fmt, FmtStr(pch_input.full_path), FmtStr(pch_c_output.full_path));
- CompileCommandListAppend(&arena, &compile_command_list, comp_cmd, (String) { 0 }, true);
+ D_Tag c_src = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F.c"), FmtStr(pch_c_output.full_path)));
+ D_ClearWrite(c_src, Lit(""));
+ String comp_cmd = StringF(&arena, final_pch_c_compile_args_fmt, FmtStr(pch_header.full_path), FmtStr(c_src.full_path));
+ String link_file = pch_c_obj_output.full_path;
+ String step_name = StringF(&arena, Lit("%F (c pch)"), FmtStr(D_GetName(pch_header)));
+ StepListAppend(&arena, &compile_command_list, step_name, comp_cmd, link_file, true);
}
/* Cpp */
{
- String comp_cmd = StringF(&arena, final_pch_cpp_compile_args_fmt, FmtStr(pch_input.full_path), FmtStr(pch_cpp_output.full_path));
- CompileCommandListAppend(&arena, &compile_command_list, comp_cmd, (String) { 0 }, true);
+ D_Tag cpp_src = D_FileTagFromPath(&arena, StringF(&arena, Lit("%F.cpp"), FmtStr(pch_cpp_output.full_path)));
+ D_ClearWrite(cpp_src, Lit(""));
+ String comp_cmd = StringF(&arena, final_pch_cpp_compile_args_fmt, FmtStr(pch_header.full_path), FmtStr(cpp_src.full_path));
+ String link_file = pch_cpp_obj_output.full_path;
+ String step_name = StringF(&arena, Lit("%F (cpp pch)"), FmtStr(D_GetName(pch_header)));
+ StepListAppend(&arena, &compile_command_list, step_name, comp_cmd, link_file, true);
+ }
+ } else {
+ /* C */
+ {
+ String comp_cmd = StringF(&arena, final_pch_c_compile_args_fmt, FmtStr(pch_header.full_path), FmtStr(pch_c_output.full_path));
+ String step_name = StringF(&arena, Lit("%F (c pch)"), FmtStr(D_GetName(pch_header)));
+ StepListAppend(&arena, &compile_command_list, step_name, comp_cmd, (String) { 0 }, true);
+ }
+ /* Cpp */
+ {
+ String comp_cmd = StringF(&arena, final_pch_cpp_compile_args_fmt, FmtStr(pch_header.full_path), FmtStr(pch_cpp_output.full_path));
+ String step_name = StringF(&arena, Lit("%F (cpp pch)"), FmtStr(D_GetName(pch_header)));
+ StepListAppend(&arena, &compile_command_list, step_name, comp_cmd, (String) { 0 }, true);
}
}
@@ -512,13 +524,13 @@ void OnBuild(StringList args_list)
for (D_TagListNode *n = src_files.first; n; n = n->next) {
D_Tag file = n->tag;
- bool include = !file.is_dir;
+ Bool include = !file.is_dir;
if (!include) continue;
String name = D_GetName(file);
String extension = D_GetExtension(file);
- bool is_c = StringEqual(extension, Lit("c"));
- bool is_cpp = !is_c && StringEqual(extension, Lit("cpp"));
+ Bool is_c = StringEqual(extension, Lit("c"));
+ Bool is_cpp = !is_c && StringEqual(extension, Lit("cpp"));
include = (is_c || is_cpp) && D_IsDirty(file);
if (!include) continue;
@@ -545,10 +557,7 @@ void OnBuild(StringList args_list)
String obj_file_path = { 0 };
{
- String name_no_extension = name;
- if ((extension.len + 1) <= name.len) {
- name_no_extension.len -= extension.len + 1;
- }
+ String name_no_extension = StringPathNoExtension(name);
obj_file_path = StringF(&arena, Lit("%F/%F.%F"), FmtStr(out_obj_dir_path), FmtStr(name_no_extension), FmtStr(obj_file_extension));
obj_file_path = OS_GetAbsPath(&arena, obj_file_path);
}
@@ -556,7 +565,7 @@ void OnBuild(StringList args_list)
String comp_cmd_fmt = is_c ? final_c_compile_args_fmt : final_cpp_compile_args_fmt;
String comp_cmd = StringF(&arena, comp_cmd_fmt, FmtStr(file.full_path), FmtStr(obj_file_path));
- CompileCommandListAppend(&arena, &compile_command_list, comp_cmd, obj_file_path, true);
+ StepListAppend(&arena, &compile_command_list, name, comp_cmd, obj_file_path, true);
}
/* ========================== *
@@ -564,24 +573,26 @@ void OnBuild(StringList args_list)
* ========================== */
if (compile_command_list.first) {
+ Bool success = true;
StringList link_files = { 0 };
/* Compile */
Size comp_i = 0;
Size comp_count = compile_command_list.count;
- for (CompileCommandListNode *n = compile_command_list.first; n; n = n->next) {
+ for (StepListNode *n = compile_command_list.first; n; n = n->next) {
++comp_i;
- String comp_cmd = n->comp_command;
+ String comp_cmd = n->cmd;
if (comp_cmd.len > 0 ) {
- //SH_PrintF(Lit("[Comp %F/%F] %F\n"), FmtI64(comp_i), FmtI64(comp_count), FmtStr(comp_cmd));
- SH_PrintF(Lit("[Comp %F/%F]\n"), FmtI64(comp_i), FmtI64(comp_count));
+ SH_PrintF(Lit("[%F/%F] %F\n"), FmtI64(comp_i), FmtI64(comp_count), FmtStr(n->name));
+ //SH_PrintF(Lit("%F\n"), FmtStr(comp_cmd));
SH_CommandResult result = SH_RunCommandCaptureOutput(&arena, comp_cmd, true);
- if (!n->silent_if_success || result.error != 0) {
- SH_PrintF(Lit("%F\n"), result.output);
+ if (!n->silence_output_if_success || result.error != 0) {
+ SH_PrintF(Lit("%F\n"), FmtStr(result.output));
}
if (result.error != 0) {
- Error(Lit("Compilation failed"));
- OS_Exit(1);
+ Assert(false);
+ success = false;
+ break;
}
}
String link_file_path = n->link_file_path;
@@ -591,18 +602,31 @@ void OnBuild(StringList args_list)
}
/* Link */
- {
- String link_files_str = StringFromStringList(&arena, Lit(" "), link_files);
- String link_cmd = StringF(&arena, final_link_args_fmt, FmtStr(link_files_str), FmtStr(executable.full_path));
+ if (success) {
+ String link_files_str = { 0 };
+ {
+ StringList link_files_quoted_list = { 0 };
+ for (StringListNode *n = link_files.first; n; n = n->next) {
+ String path = StringF(&arena, Lit("\"%F\""), FmtStr(n->string));
+ StringListAppend(&arena, &link_files_quoted_list, path);
+ }
+ link_files_str = StringFromStringList(&arena, Lit(" "), link_files_quoted_list);
+ }
+
+ String link_cmd = StringF(&arena, final_link_args_fmt, FmtStr(link_files_str));
//SH_PrintF(Lit("[Link] %F\n"), FmtStr(link_cmd));
SH_Print(Lit("Linking...\n"));
SH_CommandResult result = SH_RunCommandCaptureOutput(&arena, link_cmd, false);
if (result.error != 0) {
- Error(Lit("Linking failed"));
- OS_Exit(1);
+ Assert(false);
+ success = false;
}
D_SetDirty(executable);
}
+ if (!success) {
+ Error(Lit("Build failed"));
+ OS_Exit(1);
+ }
} else {
/* Nothing to build */
SH_Print(Lit("Nothing to build"));
diff --git a/src/app.c b/src/app.c
index a47565fd..d98e4df9 100644
--- a/src/app.c
+++ b/src/app.c
@@ -200,6 +200,8 @@ void app_entry_point(void)
sys_window_update_settings(&window, &window_settings);
scratch_end(scratch);
+
+ settings_path.text[0] = 'a';
}
/* Startup systems */
diff --git a/src/ase.c b/src/ase.c
index a51d42bd..109a392f 100644
--- a/src/ase.c
+++ b/src/ase.c
@@ -249,7 +249,7 @@ INTERNAL void inflate(u8 *dest, u8 *encoded)
u32 cm = consume_bits(&bb, 4);
u32 cinfo = consume_bits(&bb, 4);
ASSERT(cm == 8);
- ASSERT(cinfo = 7);
+ ASSERT(cinfo == 7);
u32 fcheck = consume_bits(&bb, 5);
u32 fdict = consume_bits(&bb, 1);
diff --git a/src/atomic.h b/src/atomic.h
index 899358ab..e8cb47e3 100644
--- a/src/atomic.h
+++ b/src/atomic.h
@@ -3,36 +3,36 @@
#if PLATFORM_WINDOWS
-FORCE_INLINE i32 atomic_i32_eval(struct atomic_i32 *x) { return _InterlockedOr((volatile long *)&x->_v, 0); }
-FORCE_INLINE i32 atomic_i32_inc_eval(struct atomic_i32 *x) { return _InterlockedIncrement((volatile long *)&x->_v); }
-FORCE_INLINE i32 atomic_i32_dec_eval(struct atomic_i32 *x) { return _InterlockedDecrement((volatile long *)&x->_v); }
-FORCE_INLINE i32 atomic_i32_eval_add(struct atomic_i32 *x, i32 a) { return _InterlockedExchangeAdd((volatile long *)&x->_v, a); }
-FORCE_INLINE i32 atomic_i32_eval_exchange(struct atomic_i32 *x, i32 e) { return _InterlockedExchange((volatile long *)&x->_v, e); }
-FORCE_INLINE i32 atomic_i32_eval_compare_exchange(struct atomic_i32 *x, i32 c, i32 e) { return _InterlockedCompareExchange((volatile long *)&x->_v, e, c); }
+FORCE_INLINE i32 atomic_i32_eval(struct atomic_i32 *x) { return (i32)_InterlockedOr((volatile long *)&x->_v, 0); }
+FORCE_INLINE i32 atomic_i32_inc_eval(struct atomic_i32 *x) { return (i32)_InterlockedIncrement((volatile long *)&x->_v); }
+FORCE_INLINE i32 atomic_i32_dec_eval(struct atomic_i32 *x) { return (i32)_InterlockedDecrement((volatile long *)&x->_v); }
+FORCE_INLINE i32 atomic_i32_eval_add(struct atomic_i32 *x, i32 a) { return (i32)_InterlockedExchangeAdd((volatile long *)&x->_v, a); }
+FORCE_INLINE i32 atomic_i32_eval_exchange(struct atomic_i32 *x, i32 e) { return (i32)_InterlockedExchange((volatile long *)&x->_v, e); }
+FORCE_INLINE i32 atomic_i32_eval_compare_exchange(struct atomic_i32 *x, i32 c, i32 e) { return (i32)_InterlockedCompareExchange((volatile long *)&x->_v, e, c); }
FORCE_INLINE volatile i32 *atomic_i32_raw(struct atomic_i32 *x) { return &x->_v; }
-FORCE_INLINE i64 atomic_i64_eval(struct atomic_i64 *x) { return _InterlockedOr64(&x->_v, 0); }
-FORCE_INLINE i64 atomic_i64_inc_eval(struct atomic_i64 *x) { return _InterlockedIncrement64(&x->_v); }
-FORCE_INLINE i64 atomic_i64_dec_eval(struct atomic_i64 *x) { return _InterlockedDecrement64(&x->_v); }
-FORCE_INLINE i64 atomic_i64_eval_add(struct atomic_i64 *x, i64 a) { return _InterlockedExchangeAdd64(&x->_v, a); }
-FORCE_INLINE i64 atomic_i64_eval_exchange(struct atomic_i64 *x, i64 e) { return _InterlockedExchange64(&x->_v, e); }
-FORCE_INLINE i64 atomic_i64_eval_compare_exchange(struct atomic_i64 *x, i64 c, i64 e) { return _InterlockedCompareExchange64(&x->_v, e, c); }
+FORCE_INLINE i64 atomic_i64_eval(struct atomic_i64 *x) { return (i64)_InterlockedOr64(&x->_v, 0); }
+FORCE_INLINE i64 atomic_i64_inc_eval(struct atomic_i64 *x) { return (i64)_InterlockedIncrement64(&x->_v); }
+FORCE_INLINE i64 atomic_i64_dec_eval(struct atomic_i64 *x) { return (i64)_InterlockedDecrement64(&x->_v); }
+FORCE_INLINE i64 atomic_i64_eval_add(struct atomic_i64 *x, i64 a) { return (i64)_InterlockedExchangeAdd64(&x->_v, a); }
+FORCE_INLINE i64 atomic_i64_eval_exchange(struct atomic_i64 *x, i64 e) { return (i64)_InterlockedExchange64(&x->_v, e); }
+FORCE_INLINE i64 atomic_i64_eval_compare_exchange(struct atomic_i64 *x, i64 c, i64 e) { return (i64)_InterlockedCompareExchange64(&x->_v, e, c); }
FORCE_INLINE volatile i64 *atomic_i64_raw(struct atomic_i64 *x) { return &x->_v; }
-FORCE_INLINE u32 atomic_u32_eval(struct atomic_u32 *x) { return _InterlockedExchangeAdd((volatile long *)&x->_v, 0); }
-FORCE_INLINE u32 atomic_u32_inc_eval(struct atomic_u32 *x) { return _InterlockedIncrement((volatile long *)&x->_v); }
-FORCE_INLINE u32 atomic_u32_dec_eval(struct atomic_u32 *x) { return _InterlockedDecrement((volatile long *)&x->_v); }
-FORCE_INLINE u32 atomic_u32_eval_add(struct atomic_u32 *x, u32 a) { return _InterlockedExchangeAdd((volatile long *)&x->_v, a); }
-FORCE_INLINE u32 atomic_u32_eval_exchange(struct atomic_u32 *x, u32 e) { return _InterlockedExchange((volatile long *)&x->_v, e); }
-FORCE_INLINE u32 atomic_u32_eval_compare_exchange(struct atomic_u32 *x, u32 c, u32 e) { return _InterlockedCompareExchange((volatile long *)&x->_v, e, c); }
+FORCE_INLINE u32 atomic_u32_eval(struct atomic_u32 *x) { return (u32)_InterlockedExchangeAdd((volatile long *)&x->_v, 0); }
+FORCE_INLINE u32 atomic_u32_inc_eval(struct atomic_u32 *x) { return (u32)_InterlockedIncrement((volatile long *)&x->_v); }
+FORCE_INLINE u32 atomic_u32_dec_eval(struct atomic_u32 *x) { return (u32)_InterlockedDecrement((volatile long *)&x->_v); }
+FORCE_INLINE u32 atomic_u32_eval_add(struct atomic_u32 *x, u32 a) { return (u32)_InterlockedExchangeAdd((volatile long *)&x->_v, (long)a); }
+FORCE_INLINE u32 atomic_u32_eval_exchange(struct atomic_u32 *x, u32 e) { return (u32)_InterlockedExchange((volatile long *)&x->_v, (long)e); }
+FORCE_INLINE u32 atomic_u32_eval_compare_exchange(struct atomic_u32 *x, u32 c, u32 e) { return (u32)_InterlockedCompareExchange((volatile long *)&x->_v, (long)e, (long)c); }
FORCE_INLINE volatile u32 *atomic_u32_raw(struct atomic_u32 *x) { return &x->_v; }
-FORCE_INLINE u64 atomic_u64_eval(struct atomic_u64 *x) { return _InterlockedOr64((volatile i64 *)&x->_v, 0); }
-FORCE_INLINE u64 atomic_u64_inc_eval(struct atomic_u64 *x) { return _InterlockedIncrement64((volatile i64 *)&x->_v); }
-FORCE_INLINE u64 atomic_u64_dec_eval(struct atomic_u64 *x) { return _InterlockedDecrement64((volatile i64 *)&x->_v); }
-FORCE_INLINE u64 atomic_u64_eval_add(struct atomic_u64 *x, u64 a) { return _InterlockedExchangeAdd64((volatile i64 *)&x->_v, a); }
-FORCE_INLINE u64 atomic_u64_eval_exchange(struct atomic_u64 *x, u64 e) { return _InterlockedExchange64((volatile i64 *)&x->_v, e); }
-FORCE_INLINE u64 atomic_u64_eval_compare_exchange(struct atomic_u64 *x, u64 c, u64 e) { return _InterlockedCompareExchange64((volatile i64 *)&x->_v, e, c); }
+FORCE_INLINE u64 atomic_u64_eval(struct atomic_u64 *x) { return (u64)_InterlockedOr64((volatile i64 *)&x->_v, 0); }
+FORCE_INLINE u64 atomic_u64_inc_eval(struct atomic_u64 *x) { return (u64)_InterlockedIncrement64((volatile i64 *)&x->_v); }
+FORCE_INLINE u64 atomic_u64_dec_eval(struct atomic_u64 *x) { return (u64)_InterlockedDecrement64((volatile i64 *)&x->_v); }
+FORCE_INLINE u64 atomic_u64_eval_add(struct atomic_u64 *x, u64 a) { return (u64)_InterlockedExchangeAdd64((volatile i64 *)&x->_v, (i64)a); }
+FORCE_INLINE u64 atomic_u64_eval_exchange(struct atomic_u64 *x, u64 e) { return (u64)_InterlockedExchange64((volatile i64 *)&x->_v, (i64)e); }
+FORCE_INLINE u64 atomic_u64_eval_compare_exchange(struct atomic_u64 *x, u64 c, u64 e) { return (u64)_InterlockedCompareExchange64((volatile i64 *)&x->_v, (i64)e, (i64)c); }
FORCE_INLINE volatile u64 *atomic_u64_raw(struct atomic_u64 *x) { return &x->_v; }
FORCE_INLINE void *atomic_ptr_eval(struct atomic_ptr *x) { return (void *)_InterlockedOr64((volatile i64 *)&x->_v, 0); }
diff --git a/src/common.h b/src/common.h
index bb6a5e22..348ac1af 100644
--- a/src/common.h
+++ b/src/common.h
@@ -68,8 +68,10 @@ extern "C" {
# define RUN_TESTS 0
#endif
-#ifndef INCBIN_DIR
+#ifndef INCBIN_DIR_RAW
# define INCBIN_DIR ""
+#else
+# define INCBIN_DIR STRINGIZE(INCBIN_DIR_RAW)
#endif
/* ========================== *
@@ -217,19 +219,20 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
#define TERABYTE(n) (n*GIGABYTE(1024ULL))
/* typeof */
-#if LANGUAGE_CPP || (__STDC_VERSION__ < 202311L)
-# if COMPILER_MSVC
+
+#if COMPILER_MSVC
/* Typeof not supported in MSVC */
# define typeof(type) ASSERT(false)
# define TYPEOF_DEFINED 0
-# else
+#else
+# if LANGUAGE_CPP || (__STDC_VERSION__ < 202311L)
# define typeof(type) __typeof__(type)
# define TYPEOF_DEFINED 1
# endif
#endif
/* alignof */
-#if LANGUAGE_C && (__STDC_VERSION__ < 202311L)
+#if COMPILER_MSVC || (LANGUAGE_C && (__STDC_VERSION__ < 202311L))
# define alignof(type) __alignof(type)
#endif
@@ -289,6 +292,11 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t);
#define CAT1(a, b) a ## b
#define CAT(a, b) CAT1(a, b)
+/* Stringize */
+#define STRINGIZE2(x) #x
+#define STRINGIZE(x) STRINGIZE2(x)
+
+
#if 0
/* ========================== *
* Bit utils
@@ -374,7 +382,7 @@ INLINE u128 u128_xor_u8(u128 a, u8 b) { return U128(a.hi, a.lo ^ b); }
/* https://www.codeproject.com/Tips/784635/UInt-Bit-Operations */
-u128 u128_mul(u128 a, u128 b)
+INLINE u128 u128_mul(u128 a, u128 b)
{
u64 a1 = (a.lo & 0xffffffff);
u64 b1 = (b.lo & 0xffffffff);
diff --git a/src/common.pch b/src/common.pch
new file mode 100644
index 00000000..9a701929
Binary files /dev/null and b/src/common.pch differ
diff --git a/src/draw.c b/src/draw.c
index d542acca..9713c00a 100644
--- a/src/draw.c
+++ b/src/draw.c
@@ -93,7 +93,7 @@ INTERNAL void draw_solid_poly_internal(struct renderer_canvas *canvas, struct v2
struct texture_shader_vertex *vertices = NULL;
vidx *indices = NULL;
- size_t idx_offset = renderer_canvas_push_vertices(canvas, (u8 **)&vertices, &indices, array.count, num_indices);
+ u32 idx_offset = renderer_canvas_push_vertices(canvas, (u8 **)&vertices, &indices, array.count, num_indices);
/* Fill vertices */
for (u32 i = 0; i < array.count; ++i) {
diff --git a/src/inc.c b/src/inc.c
index f1e71f2d..7fabad7c 100644
--- a/src/inc.c
+++ b/src/inc.c
@@ -7,14 +7,14 @@
* an embedded file. */
#if RESOURCES_EMBEDDED
-INCBIN_INCLUDE(res_tar, INCBINSTR(INCBIN_DIR) "/res.tar");
+INCBIN_INCLUDE(res_tar, INCBIN_DIR "res.tar");
struct buffer inc_res_tar(void)
{
return INCBIN_GET(res_tar);
}
#endif
-INCBIN_INCLUDE(shaders_tar, INCBINSTR(INCBIN_DIR) "/shaders.tar");
+INCBIN_INCLUDE(shaders_tar, INCBIN_DIR "shaders.tar");
struct buffer inc_shaders_tar(void)
{
return INCBIN_GET(shaders_tar);
diff --git a/src/incbin.c b/src/incbin.c
index 0c7cca8e..1d294f9f 100644
--- a/src/incbin.c
+++ b/src/incbin.c
@@ -16,7 +16,7 @@
struct rc_search_params {
/* In */
- struct string16 name;
+ struct string name_lower;
/* Out */
b32 found;
struct buffer data;
@@ -25,12 +25,15 @@ struct rc_search_params {
/* Find first resource with `type` and return the data in `udata`. */
INTERNAL BOOL CALLBACK enum_func(HMODULE module, LPCWSTR type, LPCWSTR wstr_entry_name, LONG_PTR udata)
{
+ struct temp_arena scratch = scratch_begin_no_conflict();
+
struct rc_search_params *params = (struct rc_search_params *)udata;
- struct string16 entry_name = string16_from_wstr((LPWSTR)wstr_entry_name);
- u64 cmp_size = min_u64(entry_name.len, params->name.len) * 2;
- b32 match = MEMCMP(entry_name.text, params->name.text, cmp_size) == 0;
- if (match) {
+ struct string entry_name_lower = string_lower(scratch.arena, string_from_wstr(scratch.arena, (LPWSTR)wstr_entry_name));
+
+ params->found = false;
+ params->data = BUFFER(0, 0);
+ if (string_eq(entry_name_lower, params->name_lower)) {
HRSRC hres = FindResourceW(module, wstr_entry_name, type);
if (hres) {
HGLOBAL hg = LoadResource(module, hres);
@@ -38,14 +41,12 @@ INTERNAL BOOL CALLBACK enum_func(HMODULE module, LPCWSTR type, LPCWSTR wstr_entr
params->found = true;
params->data.size = SizeofResource(module, hres);
params->data.data = LockResource(hg);
- return true;
}
}
}
- params->found = false;
- params->data = BUFFER(0, 0);
- return false;
+ scratch_end(scratch);
+ return params->found;
}
struct buffer _incbin_get(struct _incbin_rc_resource *inc)
@@ -56,13 +57,13 @@ struct buffer _incbin_get(struct _incbin_rc_resource *inc)
}
if (state == INCBIN_STATE_UNSEARCHED) {
- enum inc_state v = atomic_i32_eval_compare_exchange(&inc->state, state, INCBIN_STATE_SEARCHING) == state;
+ enum inc_state v = atomic_i32_eval_compare_exchange(&inc->state, state, INCBIN_STATE_SEARCHING);
if (v == state) {
struct temp_arena scratch = scratch_begin_no_conflict();
{
/* Search */
- struct string16 name16 = string16_from_string(scratch.arena, inc->rc_name);
- struct rc_search_params params = { .name = name16 };
+ struct string name_lower = string_lower(scratch.arena, inc->rc_name);
+ struct rc_search_params params = { .name_lower = name_lower };
EnumResourceNamesW(NULL, RT_RCDATA, &enum_func, (LONG_PTR)¶ms);
if (!params.found) {
sys_panic(string_format(scratch.arena,
diff --git a/src/math.h b/src/math.h
index 067444cc..8301ef64 100644
--- a/src/math.h
+++ b/src/math.h
@@ -121,13 +121,13 @@ INLINE f64 math_fabs64(f64 f)
INLINE i32 math_fsign(f32 f)
{
u32 sign_bit = (*(u32 *)&f >> 31) & 1;
- return 1 + -(sign_bit << 1);
+ return 1 + -((i32)(sign_bit << 1));
}
INLINE i64 math_fsign64(f64 f)
{
u64 sign_bit = (*(u64 *)&f >> 63) & 1;
- return 1 + -(sign_bit << 1);
+ return 1 + -((i64)(sign_bit << 1));
}
/* ========================== *
@@ -221,8 +221,8 @@ INLINE u64 math_pow_u64(u64 base, u8 exp)
* https://github.com/freebsd/freebsd-src/blob/main/lib/msun/src/e_logf.c */
INLINE f32 math_ln(f32 x)
{
- LOCAL_PERSIST const f32 ln2_hi = 6.9313812256e-01;
- LOCAL_PERSIST const f32 ln2_lo = 9.0580006145e-06;
+ LOCAL_PERSIST const f32 ln2_hi = 6.9313812256e-01f;
+ LOCAL_PERSIST const f32 ln2_lo = 9.0580006145e-06f;
i32 x_int = *(u32 *)&x;
@@ -291,13 +291,13 @@ INLINE f32 math_ln(f32 x)
INLINE f32 math_exp(f32 x)
{
LOCAL_PERSIST const f32 half[2] = { 0.5, -0.5 };
- LOCAL_PERSIST const f32 o_threshold = 8.8721679688e+01;
- LOCAL_PERSIST const f32 u_threshold = -1.0397208405e+02;
- LOCAL_PERSIST const f32 ln2_hi[2] = { 6.9314575195e-01, -6.9314575195e-01 };
- LOCAL_PERSIST const f32 ln2_lo[2] = { 1.4286067653e-06, -1.4286067653e-06 };
- LOCAL_PERSIST const f32 inv_ln2 = 1.4426950216e+00;
- LOCAL_PERSIST const f32 huge = 1.0e+30;
- LOCAL_PERSIST const f32 two_m100 = 7.8886090522e-31;
+ LOCAL_PERSIST const f32 o_threshold = 8.8721679688e+01f;
+ LOCAL_PERSIST const f32 u_threshold = -1.0397208405e+02f;
+ LOCAL_PERSIST const f32 ln2_hi[2] = { 6.9314575195e-01f, -6.9314575195e-01f };
+ LOCAL_PERSIST const f32 ln2_lo[2] = { 1.4286067653e-06f, -1.4286067653e-06f };
+ LOCAL_PERSIST const f32 inv_ln2 = 1.4426950216e+00f;
+ LOCAL_PERSIST const f32 huge = 1.0e+30f;
+ LOCAL_PERSIST const f32 two_m100 = 7.8886090522e-31f;
u32 x_uint = *(u32 *)&x;
i32 x_sign_bit = (x_uint >> 31) & 1;
@@ -308,7 +308,7 @@ INLINE f32 math_exp(f32 x)
if (x_uint > 0x7f800000) {
return x + x; /* NaN */
} else if (x_uint == 0x7f800000) {
- return (x_sign_bit == 0) ? x : 0.0;
+ return (x_sign_bit == 0) ? x : 0.0f;
}
if (x > o_threshold) {
/* Overflow */
@@ -329,7 +329,7 @@ INLINE f32 math_exp(f32 x)
lo = ln2_lo[x_sign_bit];
k = 1 - x_sign_bit - x_sign_bit;
} else {
- k = inv_ln2 * x + half[x_sign_bit];
+ k = (i32)(inv_ln2 * x + half[x_sign_bit]);
hi = x - (f32)k * ln2_hi[0];
lo = (f32)k * ln2_lo[0];
}
@@ -421,7 +421,7 @@ INLINE f32 math_rsqrt_fast(f32 x)
*/
INLINE f32 math_sin(f32 x)
{
- const f32 c = 0.225;
+ const f32 c = 0.225f;
x -= (TAU * math_trunc(x / TAU)); /* [0, TAU] */
x += (TAU * (x < -PI)) - (TAU * (x > PI)); /* [-PI, PI] */
f32 y = (4.0f/PI) * x + (-4.0f/(PI*PI)) * x * math_fabs(x);
diff --git a/src/mixer.c b/src/mixer.c
index 5e79cdf9..26b93224 100644
--- a/src/mixer.c
+++ b/src/mixer.c
@@ -415,7 +415,7 @@ struct mixed_pcm_f32 mixer_update(struct arena *arena, u64 frame_count)
/* If sound pos = listener pos, pretend sound is close in front of listener. */
if (v2_eq(listener_pos, pos)) {
- pos = v2_add(listener_pos, v2_mul(listener_dir, 0.001));
+ pos = v2_add(listener_pos, v2_mul(listener_dir, 0.001f));
}
struct v2 sound_rel = v2_sub(pos, listener_pos);
struct v2 sound_rel_dir = v2_norm(sound_rel);
diff --git a/src/mp3_mmf.c b/src/mp3_mmf.c
index ef12aabe..3b8e10a3 100644
--- a/src/mp3_mmf.c
+++ b/src/mp3_mmf.c
@@ -6,15 +6,19 @@
#include "arena.h"
#include "playback.h"
-#define COBJMACROS
-#define WIN32_LEAN_AND_MEAN
-#define UNICODE
-#include
-#include
-#include
-#include
-#include
-#include
+
+
+#pragma warning(push, 0)
+# define COBJMACROS
+# define WIN32_LEAN_AND_MEAN
+# define UNICODE
+# include
+# include
+# include
+# include
+# include
+# include
+#pragma warning(pop)
#pragma comment(lib, "mfplat")
#pragma comment(lib, "mfreadwrite")
diff --git a/src/renderer_d3d11.c b/src/renderer_d3d11.c
index 45ee3cd1..db6414c6 100644
--- a/src/renderer_d3d11.c
+++ b/src/renderer_d3d11.c
@@ -9,16 +9,16 @@
#include "tar.h"
#include "sprite.h"
-#define UNICODE
-#include
-#define CINTERFACE
-#define COBJMACROS
-#include
-#include
-#include
-#include
-#undef CINTERFACE
-#undef COBJMACROS
+#pragma warning(push, 0)
+# define UNICODE
+# define CINTERFACE
+# define COBJMACROS
+# include
+# include
+# include
+# include
+# include
+#pragma warning(pop)
#pragma comment(lib, "d3d11")
#pragma comment(lib, "dxguid")
diff --git a/src/string.c b/src/string.c
index 04493e49..7cd6283c 100644
--- a/src/string.c
+++ b/src/string.c
@@ -280,6 +280,23 @@ struct string string_indent(struct arena *arena, struct string str, u32 indent)
};
}
+struct string string_lower(struct arena *arena, struct string str)
+{
+ struct string res = { 0 };
+ res.text = arena_push_array(arena, u8, str.len);
+ res.len = str.len;
+
+ for (u64 i = 0; i < str.len; ++i) {
+ u8 c = str.text[i];
+ if (65 <= c && c <= 90) {
+ c += 32;
+ }
+ res.text[i] = c;
+ }
+
+ return res;
+}
+
b32 string_eq(struct string str1, struct string str2)
{
b32 eq = true;
diff --git a/src/string.h b/src/string.h
index 3aa463a2..97a35219 100644
--- a/src/string.h
+++ b/src/string.h
@@ -26,6 +26,7 @@ struct string string_repeat(struct arena *arena, struct string src, u64 count);
struct string string_cat(struct arena *arena, struct string str1, struct string str2);
struct string_array string_split(struct arena *arena, struct string str, struct string delim);
struct string string_indent(struct arena *arena, struct string str, u32 indent);
+struct string string_lower(struct arena *arena, struct string str);
b32 string_eq(struct string str1, struct string str2);
b32 string_contains(struct string str, struct string substring);
b32 string_starts_with(struct string str, struct string substring);
diff --git a/src/sys_win32.c b/src/sys_win32.c
index 28ac891b..d8db7314 100644
--- a/src/sys_win32.c
+++ b/src/sys_win32.c
@@ -12,13 +12,15 @@
#include "thread_local.h"
#include "uni.h"
-#define UNICODE
-#include
-#include
-#include
-#include
-#include
-#include
+#pragma warning(push, 0)
+# define UNICODE
+# include
+# include
+# include
+# include
+# include
+# include
+#pragma warning(pop)
#pragma comment(lib, "kernel32")
#pragma comment(lib, "user32")
diff --git a/src/ttf_dwrite.cpp b/src/ttf_dwrite.cpp
index f452e822..0ebf6f3e 100644
--- a/src/ttf_dwrite.cpp
+++ b/src/ttf_dwrite.cpp
@@ -12,8 +12,10 @@ extern "C"
#include "font.h"
}
-#include
-#include
+#pragma warning(push, 0)
+# include
+# include
+#pragma warning(pop)
#pragma comment(lib, "dwrite")
#pragma comment(lib, "gdi32")
@@ -65,7 +67,7 @@ struct ttf_startup_receipt ttf_startup(void)
#if COMPILER_CLANG
# pragma clang diagnostic pop
#endif
- if (error) {
+ if (error != S_OK) {
sys_panic(STR("Error creating DWrite factory"));
}
@@ -141,7 +143,7 @@ struct ttf_decode_result ttf_decode(struct arena *arena, struct buffer encoded,
/* Render target */
IDWriteBitmapRenderTarget *render_target = NULL;
/* FIXME: errors when point_size too high */
- error = dwrite_gdi_interop->CreateBitmapRenderTarget(0, raster_target_w, raster_target_h, &render_target);
+ error = dwrite_gdi_interop->CreateBitmapRenderTarget(0, (UINT32)raster_target_w, (UINT32)raster_target_h, &render_target);
render_target->SetPixelsPerDip(1.0);
/* Clear the render target */
@@ -244,15 +246,15 @@ struct ttf_decode_result ttf_decode(struct arena *arena, struct buffer encoded,
glyph->atlas_rect.height = (f32)tex_h;
/* Fill atlas */
- u64 in_pitch = dib.dsBm.bmWidthBytes / 4;
+ u64 in_pitch = (u64)dib.dsBm.bmWidthBytes / 4;
u32 *in_data = (u32 *)dib.dsBm.bmBits;
u32 *out_data = atlas_memory;
for (i32 y = 0; y < tex_h; ++y) {
u64 out_y = out_offset_y + y;
- u64 in_y = bounding_box.top + y;
+ u64 in_y = (u64)bounding_box.top + y;
for (i32 x = 0; x < tex_w; ++x) {
u64 out_x = out_offset_x + x;
- u64 in_x = bounding_box.left + x;
+ u64 in_x = (u64)bounding_box.left + x;
u32 *out_pixel = out_data + (out_x + (out_y * atlas_w));
u32 *in_pixel = in_data + (in_x + (in_y * in_pitch));
*out_pixel = RGBA_32(0xFF, 0xFF, 0xFF, *in_pixel & 0xFF);
@@ -262,7 +264,7 @@ struct ttf_decode_result ttf_decode(struct arena *arena, struct buffer encoded,
/* Grow row height */
if ((u32)tex_h > row_height) {
- row_height = tex_h;
+ row_height = (u32)tex_h;
}
/* Clear the render target */
diff --git a/src/user.c b/src/user.c
index fb517e78..e9300563 100644
--- a/src/user.c
+++ b/src/user.c
@@ -359,7 +359,7 @@ INTERNAL void debug_draw_xform(struct xform xf)
struct v2 y_ray = xform_basis_mul_v2(G.world_view, xform_get_up(xf));
struct quad quad = quad_from_rect(RECT(0, 0, 1, -1));
- quad = quad_mul_xform(quad_scale(quad, 0.075), xf);
+ quad = quad_mul_xform(quad_scale(quad, 0.075f), xf);
draw_solid_arrow_ray(G.viewport_canvas, pos, x_ray, thickness, arrowhead_len, color_x);
draw_solid_arrow_ray(G.viewport_canvas, pos, y_ray, thickness, arrowhead_len, color_y);
diff --git a/src/work.c b/src/work.c
index 902a69d5..ee642b28 100644
--- a/src/work.c
+++ b/src/work.c
@@ -156,7 +156,7 @@ INTERNAL APP_EXIT_CALLBACK_FUNC_DEF(work_shutdown)
sys_condition_variable_broadcast(&G.cv);
}
sys_mutex_unlock(&G.mutex);
- for (struct worker *worker = G.worker_head; (worker = worker->next);) {
+ for (struct worker *worker = G.worker_head; worker; worker = worker->next) {
sys_thread_wait_release(&worker->thread);
}
}