Clang format
This commit is contained in:
209
core_main.cpp
209
core_main.cpp
@@ -93,138 +93,137 @@ Ideas
|
||||
|
||||
#include "core_compiler_includes.cpp"
|
||||
|
||||
const U32 COMPILE_NULL = 0x0;
|
||||
const U32 COMPILE_PRINT_STATS = 0x1;
|
||||
const U32 COMPILE_NULL = 0x0;
|
||||
const U32 COMPILE_PRINT_STATS = 0x1;
|
||||
const U32 COMPILE_PRINT_ALLOCATOR_STATS_BEFORE_DESTROY = 0x2;
|
||||
const U32 COMPILE_AND_RUN = 0x4;
|
||||
const U32 COMPILE_TESTING = 0x8;
|
||||
const U32 COMPILE_AND_RUN = 0x4;
|
||||
const U32 COMPILE_TESTING = 0x8;
|
||||
|
||||
static void compile_file(Allocator *allocator, String filename, U32 compile_flags = COMPILE_NULL) {
|
||||
if (is_flag_set(compile_flags, COMPILE_AND_RUN)) {
|
||||
printf("%s - ", filename.str);
|
||||
}
|
||||
String result = compile_file_to_string(allocator, filename);
|
||||
if (is_flag_set(compile_flags, COMPILE_AND_RUN)) {
|
||||
printf("%s - ", filename.str);
|
||||
}
|
||||
String result = compile_file_to_string(allocator, filename);
|
||||
|
||||
B32 r = os_write_file("program.c"_s, result);
|
||||
assert(r);
|
||||
F64 total_compiler_time = os_time() - pctx->time.start;
|
||||
printf("%f - ", total_compiler_time);
|
||||
B32 r = os_write_file("program.c"_s, result);
|
||||
assert(r);
|
||||
F64 total_compiler_time = os_time() - pctx->time.start;
|
||||
printf("%f - ", total_compiler_time);
|
||||
|
||||
Arena *scratch = pctx->scratch;
|
||||
Scratch_Scope _scope(scratch);
|
||||
Arena *scratch = pctx->scratch;
|
||||
Scratch_Scope _scope(scratch);
|
||||
|
||||
F64 begin = os_time();
|
||||
String_Builder builder = {scratch};
|
||||
builder.addf("clang program.c -Wall -Wno-unused-function -Wno-parentheses-equality -g -o a" OS_EXE " ");
|
||||
For(pctx->files_to_link) {
|
||||
builder.addf("-l%Q ", it->intern_val);
|
||||
}
|
||||
String compiler_call = string_flatten(scratch, &builder);
|
||||
F64 begin = os_time();
|
||||
String_Builder builder = {scratch};
|
||||
builder.addf("clang program.c -Wall -Wno-unused-function -Wno-parentheses-equality -g -o a" OS_EXE " ");
|
||||
For(pctx->files_to_link) {
|
||||
builder.addf("-l%Q ", it->intern_val);
|
||||
}
|
||||
String compiler_call = string_flatten(scratch, &builder);
|
||||
|
||||
system((const char *)compiler_call.str);
|
||||
F64 end = os_time();
|
||||
system((const char *)compiler_call.str);
|
||||
F64 end = os_time();
|
||||
|
||||
if (is_flag_set(compile_flags, COMPILE_PRINT_STATS)) {
|
||||
printf("total = %f\n", os_time() - pctx->time.start);
|
||||
printf("core_total = %f\n", pctx->time.total);
|
||||
printf("clang = %f\n", end - begin);
|
||||
printf("parsing = %f\n", pctx->time.parsing);
|
||||
printf("typecheck = %f\n", pctx->time.typechecking);
|
||||
printf("generatin = %f\n", pctx->time.code_generation);
|
||||
}
|
||||
if (is_flag_set(compile_flags, COMPILE_PRINT_STATS)) {
|
||||
printf("total = %f\n", os_time() - pctx->time.start);
|
||||
printf("core_total = %f\n", pctx->time.total);
|
||||
printf("clang = %f\n", end - begin);
|
||||
printf("parsing = %f\n", pctx->time.parsing);
|
||||
printf("typecheck = %f\n", pctx->time.typechecking);
|
||||
printf("generatin = %f\n", pctx->time.code_generation);
|
||||
}
|
||||
|
||||
if (is_flag_set(compile_flags, COMPILE_PRINT_ALLOCATOR_STATS_BEFORE_DESTROY)) {
|
||||
// @! Allocator stats
|
||||
}
|
||||
if (is_flag_set(compile_flags, COMPILE_PRINT_ALLOCATOR_STATS_BEFORE_DESTROY)) {
|
||||
// @! Allocator stats
|
||||
}
|
||||
|
||||
if (is_flag_set(compile_flags, COMPILE_AND_RUN)) {
|
||||
String testing = compile_flags & COMPILE_TESTING ? "testing"_s : ""_s;
|
||||
if (is_flag_set(compile_flags, COMPILE_AND_RUN)) {
|
||||
String testing = compile_flags & COMPILE_TESTING ? "testing"_s : ""_s;
|
||||
#if OS_WINDOWS
|
||||
String sys = string_fmt(scratch, "a.exe %Q", testing);
|
||||
String sys = string_fmt(scratch, "a.exe %Q", testing);
|
||||
#else
|
||||
String sys = string_fmt(scratch, "./a.out %Q", testing);
|
||||
String sys = string_fmt(scratch, "./a.out %Q", testing);
|
||||
#endif
|
||||
int result = system((char *)sys.str);
|
||||
assert(result != -1);
|
||||
if (result == 0) {
|
||||
printf(PRINTF_GREEN "OK!" PRINTF_RESET);
|
||||
int result = system((char *)sys.str);
|
||||
assert(result != -1);
|
||||
if (result == 0) {
|
||||
printf(PRINTF_GREEN "OK!" PRINTF_RESET);
|
||||
}
|
||||
if (result != 0) {
|
||||
printf(PRINTF_RED "ERROR!" PRINTF_RESET);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
if (result != 0) {
|
||||
printf(PRINTF_RED "ERROR!" PRINTF_RESET);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argument_count, char **arguments){
|
||||
Arena arena = {};
|
||||
Arena scratch = {};
|
||||
arena_init(&arena, "Pernament arena"_s);
|
||||
arena_init(&scratch, "Pernament scratch arena"_s);
|
||||
int main(int argument_count, char **arguments) {
|
||||
Arena arena = {};
|
||||
Arena scratch = {};
|
||||
arena_init(&arena, "Pernament arena"_s);
|
||||
arena_init(&scratch, "Pernament scratch arena"_s);
|
||||
|
||||
Array<String> args = {&scratch};
|
||||
for(int i = 1; i < argument_count; i+=1){
|
||||
String arg = string_from_cstring(arguments[i]);
|
||||
args.add(arg);
|
||||
}
|
||||
Array<String> args = {&scratch};
|
||||
for (int i = 1; i < argument_count; i += 1) {
|
||||
String arg = string_from_cstring(arguments[i]);
|
||||
args.add(arg);
|
||||
}
|
||||
|
||||
if(!args.len){
|
||||
printf("Please specify a file to compile!");
|
||||
return 0;
|
||||
}
|
||||
if (!args.len) {
|
||||
printf("Please specify a file to compile!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool enable_color_codes = false;
|
||||
bool enable_color_codes = false;
|
||||
#if OS_UNIX
|
||||
enable_color_codes = true;
|
||||
enable_color_codes = true;
|
||||
#endif
|
||||
#if OS_WINDOWS
|
||||
// Set output mode to handle virtual terminal sequences
|
||||
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
if (hOut != INVALID_HANDLE_VALUE) {
|
||||
DWORD dwMode = 0;
|
||||
if (GetConsoleMode(hOut, &dwMode)) {
|
||||
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
|
||||
if (SetConsoleMode(hOut, dwMode)) {
|
||||
enable_color_codes = true;
|
||||
}
|
||||
else{
|
||||
printf("Failed to enable colored terminal output C\n");
|
||||
}
|
||||
// Set output mode to handle virtual terminal sequences
|
||||
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
if (hOut != INVALID_HANDLE_VALUE) {
|
||||
DWORD dwMode = 0;
|
||||
if (GetConsoleMode(hOut, &dwMode)) {
|
||||
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
|
||||
if (SetConsoleMode(hOut, dwMode)) {
|
||||
enable_color_codes = true;
|
||||
}
|
||||
else {
|
||||
printf("Failed to enable colored terminal output C\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("Failed to enable colored terminal output B\n");
|
||||
}
|
||||
}
|
||||
else{
|
||||
printf("Failed to enable colored terminal output B\n");
|
||||
else {
|
||||
printf("Failed to enable colored terminal output A\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("Failed to enable colored terminal output A\n");
|
||||
}
|
||||
|
||||
test_os_memory();
|
||||
test_os_memory();
|
||||
#endif
|
||||
|
||||
(void)enable_color_codes;
|
||||
For(args){
|
||||
(void)enable_color_codes;
|
||||
For(args) {
|
||||
|
||||
if(it == "-testing"_s){
|
||||
Scratch_Scope _scope(&scratch);
|
||||
Array<OS_File_Info> examples = os_list_dir(&scratch, &scratch, "examples"_s);
|
||||
Array<OS_File_Info> tests = os_list_dir(&scratch, &scratch, "tests"_s);
|
||||
For(examples){
|
||||
if(it.is_directory) continue;
|
||||
compile_file(&arena, it.absolute_path, COMPILE_AND_RUN | COMPILE_TESTING);
|
||||
}
|
||||
For(tests){
|
||||
if(it.is_directory) continue;
|
||||
compile_file(&arena, it.absolute_path, COMPILE_AND_RUN | COMPILE_TESTING);
|
||||
}
|
||||
if (it == "-testing"_s) {
|
||||
Scratch_Scope _scope(&scratch);
|
||||
Array<OS_File_Info> examples = os_list_dir(&scratch, &scratch, "examples"_s);
|
||||
Array<OS_File_Info> tests = os_list_dir(&scratch, &scratch, "tests"_s);
|
||||
For(examples) {
|
||||
if (it.is_directory) continue;
|
||||
compile_file(&arena, it.absolute_path, COMPILE_AND_RUN | COMPILE_TESTING);
|
||||
}
|
||||
For(tests) {
|
||||
if (it.is_directory) continue;
|
||||
compile_file(&arena, it.absolute_path, COMPILE_AND_RUN | COMPILE_TESTING);
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
String program_name = string_from_cstring(arguments[1]);
|
||||
compile_file(&arena, program_name, COMPILE_PRINT_STATS);
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
String program_name = string_from_cstring(arguments[1]);
|
||||
compile_file(&arena, program_name, COMPILE_PRINT_STATS);
|
||||
}
|
||||
|
||||
}
|
||||
printf("End of program\n");
|
||||
return 0;
|
||||
printf("End of program\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user