Skip to content

Commit

Permalink
Removed some redundant and useless logging macros
Browse files Browse the repository at this point in the history
  • Loading branch information
iWas-Coder committed Dec 9, 2024
1 parent 3c26f55 commit d22827d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 35 deletions.
4 changes: 1 addition & 3 deletions carbon.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,7 @@ CARBON_API u32 carbon_crypto_crc32(const u8 *in, const usz in_size);
#define CARBON_COLOR_MAGENTA "\033[1;35m"
#define CARBON_COLOR_CYAN "\033[1;36m"

#define CARBON_INFO_RAW(msg, ...) carbon_print(msg, ##__VA_ARGS__)
#define CARBON_INFO(msg, ...) carbon_println(msg, ##__VA_ARGS__)
#define CARBON_INFO_COLOR(color, msg, ...) CARBON_INFO(color msg CARBON_COLOR_RESET, ##__VA_ARGS__)
#define CARBON_INFO_COLOR(color, msg, ...) carbon_println(color msg CARBON_COLOR_RESET, ##__VA_ARGS__)
#define CARBON_INFO_FQDN(msg, ...) CARBON_INFO_COLOR(CARBON_COLOR_YELLOW, "[*] " __FILE__ ":" CARBON_EXPAND_AND_QUOTE(__LINE__) " (%s) :: " msg, __func__, ##__VA_ARGS__)
#define CARBON_WARNING(msg, ...) CARBON_INFO_COLOR(CARBON_COLOR_MAGENTA, "[?] " __FILE__ ":" CARBON_EXPAND_AND_QUOTE(__LINE__) " (%s) :: " msg, __func__, ##__VA_ARGS__)

Expand Down
4 changes: 2 additions & 2 deletions src/carbon_nn.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ void carbon_nn_fit(CBN_NeuralNet nn, usz iters, CBN_Matrix train, f32 lr) {
}

void carbon_nn_print(CBN_NeuralNet nn, const char *name) {
CARBON_INFO("%s = [", name);
carbon_println("%s = [", name);
for (usz i = 0; i < nn.arch_count - 1; ++i) {
carbon_math_mat_print(nn.ws[i], carbon_string_fmt("ws%zu", i));
carbon_math_row_print(nn.bs[i], carbon_string_fmt("bs%zu", i));
}
CARBON_INFO("];");
carbon_println("];");
}
22 changes: 11 additions & 11 deletions src/carbon_test_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ void carbon_test_manager_argparse(i32 argc, char **argv) {
return;
}
if (argc == 2 && (!carbon_string_cmp(argv[1], "-h") || !carbon_string_cmp(argv[1], "--help"))) {
CARBON_INFO_RAW(help_msg, argv[0], CARBON_JUNIT_XML_OUT_FILENAME, CARBON_NAME);
carbon_print(help_msg, argv[0], CARBON_JUNIT_XML_OUT_FILENAME, CARBON_NAME);
exit(0);
}
if (argc == 2 && (!carbon_string_cmp(argv[1], "-v") || !carbon_string_cmp(argv[1], "--version"))) {
CARBON_INFO_RAW(version_msg, CARBON_NAME, CARBON_VERSION);
carbon_print(version_msg, CARBON_NAME, CARBON_VERSION);
exit(0);
}
CARBON_ERROR("unrecognized option\n Try '%s --help' for more information.", argv[0]);
Expand Down Expand Up @@ -106,7 +106,7 @@ void carbon_test_manager_rebuild(const char *bin_file, const char *src_file) {
carbon_fs_rename(bin_file_old, bin_file), carbon_test_manager__cleanup_and_exit();
}
CARBON_INFO_COLOR(CARBON_COLOR_YELLOW, "[*] Binary rebuilt successfully (`%s`)", bin_file);
CARBON_INFO("=======================================");
carbon_println("=======================================");
// 4. Replace current binary with new one (execvp)
char *argv[4];
memset(argv, 0, 4 * sizeof(char *));
Expand Down Expand Up @@ -177,7 +177,7 @@ void carbon_test_manager_cleanup(CBN_Suite *s) {

u8 carbon_test_manager_run_s(CBN_Suite *s) {
CARBON_INFO_COLOR(CARBON_COLOR_CYAN, "*** %s (%s) ***", CARBON_NAME, CARBON_VERSION);
CARBON_INFO("=======================================");
carbon_println("=======================================");
if (!s->tests || !s->n) {
CARBON_ERROR("`(Suite *) s` has not been initialized");
return EXIT_FAILURE;
Expand All @@ -187,7 +187,7 @@ u8 carbon_test_manager_run_s(CBN_Suite *s) {
else CARBON_INFO_COLOR(CARBON_COLOR_YELLOW, "[*] Output to ./%s", carbon_test_manager__cmd_args.output ?: CARBON_JUNIT_XML_OUT_FILENAME);
CARBON_INFO_COLOR(CARBON_COLOR_YELLOW, "[*] Compiler is " CARBON_COMPILER_VERSION);
CARBON_INFO_COLOR(CARBON_COLOR_YELLOW, "[*] Compiled on %s at %s", __DATE__, __TIME__);
CARBON_INFO("=======================================");
carbon_println("=======================================");
usz passed = 0, failed = 0;
CBN_List junit_testcase_infos = carbon_list_create(sizeof(CBN_JUnitTestcase));
CBN_Clock clk = carbon_clock_start();
Expand Down Expand Up @@ -224,12 +224,12 @@ u8 carbon_test_manager_run_s(CBN_Suite *s) {
status = EXIT_FAILURE;
}
else {
if (!((i32) clk.elapsed)) CARBON_INFO_RAW("=========== " CARBON_COLOR_GREEN "%zu passed in %uμs" CARBON_COLOR_RESET " ===========\n",
passed,
total_time_micro);
else CARBON_INFO_RAW("=========== " CARBON_COLOR_GREEN "%zu passed in %.2fs" CARBON_COLOR_RESET " ===========\n",
passed,
clk.elapsed);
if (!((i32) clk.elapsed)) carbon_print("=========== " CARBON_COLOR_GREEN "%zu passed in %uμs" CARBON_COLOR_RESET " ===========\n",
passed,
total_time_micro);
else carbon_print("=========== " CARBON_COLOR_GREEN "%zu passed in %.2fs" CARBON_COLOR_RESET " ===========\n",
passed,
clk.elapsed);
}
if (!carbon_test_manager__cmd_args.no_output) carbon_junit_output(junit_testcase_infos, carbon_test_manager__cmd_args.output, failed, clk.elapsed);
carbon_list_destroy(&junit_testcase_infos);
Expand Down
38 changes: 19 additions & 19 deletions src/make.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ static inline void call_cmd(const char *cmd) {
}

static inline void rm_dash_r(const char *path) {
CARBON_INFO(" RM %s", path);
carbon_println(" RM %s", path);
call_cmd(carbon_string_fmt("rm -rf %s", path));
}

static inline void cp_dash_r(const char *origin, const char *dest) {
CARBON_INFO(" CP %s -> %s", origin, dest);
carbon_println(" CP %s -> %s", origin, dest);
call_cmd(carbon_string_fmt("cp -r %s %s", origin, dest));
}

Expand Down Expand Up @@ -85,7 +85,7 @@ static void rebuild_myself(const char **host_argv) {
#endif
"-o", (char *) bin, 0
};
CARBON_INFO(" CCLD %s", __FILE__);
carbon_println(" CCLD %s", __FILE__);
if (-1 == execvp(argv[0], argv)) {
CARBON_ERROR("unable to execvp from child process");
exit(1);
Expand All @@ -96,7 +96,7 @@ static void rebuild_myself(const char **host_argv) {
CARBON_ERROR("errors detected during rebuild");
exit(1);
}
CARBON_INFO(" EXEC %s", bin);
carbon_println(" EXEC %s", bin);
if (-1 == execvp(bin, (char **) host_argv)) {
CARBON_ERROR("unable to execvp rebuilt binary");
exit(1);
Expand All @@ -109,7 +109,7 @@ static void run_tests(void) {
CBN_PatternMatchedFiles cxx_files = carbon_fs_pattern_match("test/*.cc");
CBN_StrBuilder cmd = {0};
carbon_fs_pattern_match_foreach(c_files) {
CARBON_INFO(" CC %s", it.f);
carbon_println(" CC %s", it.f);
carbon_string_strip_substr(it.f, ".c");
carbon_strbuilder_add_cstr(&cmd, CARBON_C_COMPILER " -I . " C_STD " " WARNS " -fPIE ");
#ifdef CARBON_MAKE_USE_SANITIZERS
Expand All @@ -122,7 +122,7 @@ static void run_tests(void) {
carbon_strbuilder_free(&cmd);
}
carbon_fs_pattern_match_foreach(cxx_files) {
CARBON_INFO(" CXX %s", it.f);
carbon_println(" CXX %s", it.f);
carbon_string_strip_substr(it.f, ".cc");
carbon_strbuilder_add_cstr(&cmd, CARBON_CXX_COMPILER " -I . " CXX_STD " " WARNS " -fPIE ");
#ifdef CARBON_MAKE_USE_SANITIZERS
Expand All @@ -134,7 +134,7 @@ static void run_tests(void) {
call_cmd(carbon_strview_to_cstr(carbon_strview_from_strbuilder(&cmd)));
carbon_strbuilder_free(&cmd);
}
CARBON_INFO(" LD " TESTBIN);
carbon_println(" LD " TESTBIN);
carbon_strbuilder_add_cstr(&cmd, CARBON_CXX_COMPILER " ");
#ifdef CARBON_MAKE_USE_SANITIZERS
carbon_strbuilder_add_cstr(&cmd, "-fsanitize=address,undefined ");
Expand All @@ -149,37 +149,37 @@ static void run_tests(void) {
call_cmd(carbon_strview_to_cstr(carbon_strview_from_strbuilder(&cmd)));
carbon_strbuilder_free(&cmd);
rm_dash_r("test/*.o");
CARBON_INFO("+ " TESTBIN " -n");
carbon_println("+ " TESTBIN " -n");
call_cmd(TESTBIN " -n");
}

static void build(void) {
CARBON_INFO(" MKDIR " WORKDIR);
carbon_println(" MKDIR " WORKDIR);
if (!carbon_fs_create_directory(WORKDIR)) exit_gracefully();
CBN_PatternMatchedFiles c_files = carbon_fs_pattern_match("src/carbon_*.c");
CBN_PatternMatchedFiles cxx_files = carbon_fs_pattern_match("src/carbon_*.cc");
CBN_PatternMatchedFiles objc_files = carbon_fs_pattern_match("src/carbon_*.m");
carbon_fs_pattern_match_foreach(c_files) {
CARBON_INFO(" CC %s", it.f);
carbon_println(" CC %s", it.f);
carbon_string_strip_substr(it.f, "src/");
carbon_string_strip_substr(it.f, ".c");
call_cmd(carbon_string_fmt(CARBON_C_COMPILER " -I . " C_STD " " WARNS " -fPIC -pipe -Os -c src/%s.c -o %s/%s.o", it.f, WORKDIR, it.f));
}
carbon_fs_pattern_match_foreach(cxx_files) {
CARBON_INFO(" CXX %s", it.f);
carbon_println(" CXX %s", it.f);
carbon_string_strip_substr(it.f, "src/");
carbon_string_strip_substr(it.f, ".cc");
call_cmd(carbon_string_fmt(CARBON_CXX_COMPILER " -I . " CXX_STD " " WARNS " -fPIC -pipe -Os -c src/%s.cc -o %s/%s.o", it.f, WORKDIR, it.f));
}
carbon_fs_pattern_match_foreach(objc_files) {
CARBON_INFO(" OBJC %s", it.f);
carbon_println(" OBJC %s", it.f);
carbon_string_strip_substr(it.f, "src/");
carbon_string_strip_substr(it.f, ".m");
call_cmd(carbon_string_fmt(CARBON_C_COMPILER " -I . " C_STD " " WARNS " -fPIC -pipe -Os -c src/%s.m -o %s/%s.o", it.f, WORKDIR, it.f));
}
CARBON_INFO(" AR libcarbon.a");
carbon_println(" AR libcarbon.a");
call_cmd("ar -rcs " WORKDIR "/libcarbon.a " WORKDIR "/*.o");
CARBON_INFO(" LD libcarbon.so");
carbon_println(" LD libcarbon.so");
CBN_StrBuilder cmd = {0};
carbon_strbuilder_add_cstr(&cmd, CARBON_C_COMPILER " -pipe -Os " WORKDIR "/*.o -shared ");
#ifdef __APPLE__
Expand All @@ -197,21 +197,21 @@ static void package(void) {
cp_dash_r("COPYING carbon.h", WORKDIR);
#undef dir
#define dir "src"
CARBON_INFO(" MKDIR " WORKDIR "/" dir);
carbon_println(" MKDIR " WORKDIR "/" dir);
if (!carbon_fs_create_directory(WORKDIR "/" dir)) exit_gracefully();
cp_dash_r(dir "/carbon_*", WORKDIR "/" dir);
#undef dir
#define dir "vendor/stb_image"
CARBON_INFO(" MKDIR " WORKDIR "/" dir);
carbon_println(" MKDIR " WORKDIR "/" dir);
if (!carbon_fs_create_directories(WORKDIR "/" dir)) exit_gracefully();
cp_dash_r(dir "/*", WORKDIR "/" dir);
#undef dir
#define dir "vendor/stb_image_write"
CARBON_INFO(" MKDIR " WORKDIR "/" dir);
carbon_println(" MKDIR " WORKDIR "/" dir);
if (!carbon_fs_create_directories(WORKDIR "/" dir)) exit_gracefully();
cp_dash_r(dir "/*", WORKDIR "/" dir);
#undef dir
CARBON_INFO(" GZIP " WORKDIR ".tgz");
carbon_println(" GZIP " WORKDIR ".tgz");
call_cmd("tar -zcf " WORKDIR ".tgz " WORKDIR);
rm_dash_r(WORKDIR);
}
Expand All @@ -234,7 +234,7 @@ int main(int argc, char **argv) {
}
if (argc == 2) {
if (!carbon_string_cmp(argv[1], "help")) {
CARBON_INFO_RAW(help_msg, argv[0], CARBON_NAME);
carbon_print(help_msg, argv[0], CARBON_NAME);
return 0;
}
else if (!carbon_string_cmp(argv[1], "clean")) {
Expand Down

0 comments on commit d22827d

Please sign in to comment.