finished initial pass on generating single-header with gen_c11.c (still need to review it)

This commit is contained in:
2025-02-10 23:39:17 -05:00
parent a2938ef3fa
commit a5af8b3d80
8 changed files with 266 additions and 59 deletions
+7
View File
@@ -0,0 +1,7 @@
/*
▀██ ██▀ ▀██▀▀█▄ ▀██▀ ▀██ ██▀ ▀██▀▀█▄ ▀██▀
███ ███ ██ ██ ██ ███ ███ ██ ██ ██
█▀█▄▄▀██ ██ ██ ██ █▀█▄▄▀██ ██▄▄▄█▀ ██
█ ▀█▀ ██ ██ ██ ██ █ ▀█▀ ██ ██ ██
▄█▄ █ ▄██▄ ▄██▄▄▄█▀ ▄██▄ ▄█▄ █ ▄██▄ ▄██▄ ▄██▄▄▄▄▄█
*/
+7
View File
@@ -0,0 +1,7 @@
/*
▀██ ██▀ ▀██▀▀█▄ ▀██
███ ███ ██ ██ ▄▄▄▄ ▄▄▄▄ ██ ▄▄
█▀█▄▄▀██ ██ ██ ▄█▄▄▄██ ██▄ ▀ ██ ▄▀
█ ▀█▀ ██ ██ ██ ██ ▄ ▀█▄▄ ██▀█▄
▄█▄ █ ▄██▄ ▄██▄▄▄█▀ ▀█▄▄▄▀ █▀▄▄█▀ ▄██▄ ██▄
*/
+7
View File
@@ -0,0 +1,7 @@
/*
▄▄█▀▀██ ▄█▀▀▀▄█
▄█▀ ██ ██▄▄ ▀
██ ██ ▀▀███▄
▀█▄ ██ ▄ ▀██
▀▀█▄▄▄█▀ █▀▄▄▄▄█▀
*/
+19
View File
@@ -0,0 +1,19 @@
/*
╔────────────────────────────────────────────────────────────────────────────────────────────────────────────╗
│ │
│ 88b d88 88 88 │
│ 888b d888 ,d 88 88 │
│ 88`8b d8'88 88 88 88 │
│ 88 `8b d8' 88 ,adPPYba, MM88MMM ,adPPYYba, ,adPPYb,88 ,adPPYba, ,adPPYba, 88 ,d8 │
│ 88 `8b d8' 88 a8P_____88 88 "" `Y8 a8" `Y88 a8P_____88 I8[ "" 88 ,a8" │
│ 88 `8b d8' 88 8PP""""""" 88 ,adPPPPP88 8b 88 8PP""""""" `"Y8ba, 8888[ │
│ 88 `888' 88 "8b, ,aa 88, 88, ,88 "8a, ,d88 "8b, ,aa aa ]8I 88`"Yba, │
│ 88 `8' 88 `"Ybbd8"' "Y888 `"8bbdP"Y8 `"8bbdP"Y8 `"Ybbd8"' `"YbbdP"' 88 `Y8a │
│ │
╚────────────────────────────────────────────────────────────────────────────────────────────────────────────╝
/ \-------------------------,
\_,| |
| Segregated C11 |
| ,-----------------------
\_/______________________/
*/
+196 -59
View File
@@ -2,8 +2,12 @@
#include "gen_common.h"
#ifndef PRINT_SECTION_REGION_PRAGMAS
#define PRINT_SECTION_REGION_PRAGMAS 1
#ifndef GENERATE_SEGREGATED
#define GENERATE_SEGEREGATED 1
#endif
#ifndef GENERATE_SINGLEHEADER
#define GENERATE_SINGLEHEADER 1
#endif
#define path_refactor_script path_gen_c11 "c11.refactor"
@@ -15,15 +19,6 @@ gen_Code refactor_and_format( gen_Code code ) {
return code_refactor_and_format(code, path_scratch_file, path_refactor_script, path_format_style );
}
#define str_fmt(fmt, ...) gen_strbuilder_to_str(gen_strbuilder_fmt_buf(gen_get_context()->Allocator_Temp, fmt, __VA_ARGS__))
void print_section(gen_Builder* builder, gen_Code code, gen_Str label) {
if (PRINT_SECTION_REGION_PRAGMAS) gen_builder_print(builder, gen_def_pragma(str_fmt("region %S", label)) );
gen_builder_print(builder, code);
if (PRINT_SECTION_REGION_PRAGMAS) gen_builder_print(builder, gen_def_pragma(str_fmt("endregion %S", label)) );
gen_builder_print(builder, gen_fmt_newline);
}
int main()
{
gen_Context ctx = {0};
@@ -35,14 +30,12 @@ int main()
"// This file was generated automatially by metadesk's gen_c11.c "
"(See: https://github.com/Ed94/metadesk/tree/master)\n\n"
);
gen_Str roll_own_dependencies_guard_start = lit(
"\n"
"//! If its desired to roll your own dependencies, define MD_ROLL_OWN_DEPENDENCIES before including this file.\n"
"#ifndef MD_ROLL_OWN_DEPENDENCIES\n"
"\n"
);
gen_Str roll_own_dependencies_guard_end = lit(
"\n"
"// MD_ROLL_OWN_DEPENDENCIES\n"
@@ -50,6 +43,11 @@ int main()
"\n"
);
gen_Code banner_base = gen_scan_file(path_gen_c11 "banner_base.h");
gen_Code banner_os = gen_scan_file(path_gen_c11 "banner_os.h");
gen_Code banner_mdesk = gen_scan_file(path_gen_c11 "banner_mdesk.h");
gen_Code banner_md_impl = gen_scan_file(path_gen_c11 "banner_md_impl.h");
gen_Code tp_stb_sprintf_h = gen_scan_file(path_third_party "stb/stb_sprintf.h");
gen_Code base_context_cracking_h = gen_scan_file(path_base "context_cracking.h");
@@ -84,6 +82,27 @@ int main()
gen_Code os_linux_includes_h = gen_scan_file(path_os_linux "os_linux_includes.h");
gen_Code os_linux_h = gen_scan_file(path_os_linux "os_linux.h");
gen_Code mdesk_h = gen_scan_file(path_mdesk "mdesk.h");
gen_Code base_platfom_c = gen_scan_file(path_base "platform.c");
gen_Code base_debug_c = gen_scan_file(path_base "debug.c");
gen_Code base_memory_substrate_c = gen_scan_file(path_base "memory_substrate.c");
gen_Code base_arena_c = gen_scan_file(path_base "arena.c");
gen_Code base_strings_c = gen_scan_file(path_base "strings.c");
gen_Code base_text_c = gen_scan_file(path_base "text.c");
gen_Code base_thread_context_c = gen_scan_file(path_base "thread_context.c");
gen_Code base_markup_c = gen_scan_file(path_base "markup.c");
gen_Code base_command_line_c = gen_scan_file(path_base "command_line.c");
gen_Code base_logger_c = gen_scan_file(path_base "logger.c");
gen_Code base_entry_point_c = gen_scan_file(path_base "entry_point.c");
gen_Code base_time_c = gen_scan_file(path_base "time.c");
gen_Code os_win32_c = gen_scan_file(path_os_win32 "os_win32.c");
gen_Code os_linux_c = gen_scan_file(path_os_linux "os_linux.c");
gen_Code os_os_c = gen_scan_file(path_os "os.c");
gen_Code mdesk_c = gen_scan_file(path_mdesk "mdesk.c");
#pragma region Refactored / Formatted
gen_Code r_tp_stb_sprintf_h = refactor(tp_stb_sprintf_h);
@@ -118,25 +137,39 @@ int main()
gen_Code r_os_win32_h = refactor(os_win32_h);
gen_Code r_os_linux_includes_h = refactor(os_linux_includes_h);
gen_Code r_os_linux_h = refactor(os_linux_h);
gen_Code r_mdesk_h = refactor(mdesk_h);
gen_Code r_base_platform_c = refactor(base_platfom_c);
gen_Code r_base_debug_c = refactor(base_debug_c);
gen_Code r_base_memory_substrate_c = refactor(base_memory_substrate_c);
gen_Code r_base_arena_c = refactor(base_arena_c);
gen_Code r_base_strings_c = refactor(base_strings_c);
gen_Code r_base_text_c = refactor(base_text_c);
gen_Code r_base_thread_context_c = refactor(base_thread_context_c);
gen_Code r_base_markup_c = refactor(base_markup_c);
gen_Code r_base_command_line_c = refactor(base_command_line_c);
gen_Code r_base_logger_c = refactor(base_logger_c);
gen_Code r_base_entry_point_c = refactor(base_entry_point_c);
gen_Code r_base_time_c = refactor(base_time_c);
gen_Code r_os_win32_c = refactor(os_win32_c);
gen_Code r_os_linux_c = refactor(os_linux_c);
gen_Code r_os_c = refactor(os_os_c);
gen_Code r_mdesk_c = refactor(mdesk_c);
#pragma endregion Refactored / Formatted
// Singleheader
if (GENERATE_SINGLEHEADER)
{
#define builder header
gen_Builder header_ = gen_builder_open(path_gen "metadesk_singleheader.h");
gen_Builder* header = & header_;
#define print(code) gen_builder_print(header, code);
#define print_fmt(fmt, ...) gen_builder_print_fmt(header, fmt, __VA_ARGS__)
#define new_line() gen_builder_print(header, gen_fmt_newline)
#define pragma_region(label) print(gen_def_pragma(str_fmt("region %S", lit(label))))
#define pragma_endregion(label) print(gen_def_pragma(str_fmt("endregion %S", lit(label))))
#define define gen_def_define
#define preprocess_cond(type, expr) gen_def_preprocess_cond(type, expr)
gen_Str implementation_guard_start = lit(
// "#pragma region METADESK IMPLEMENTATION GUARD\n"
"#if defined(MD_IMPLEMENTATION) && ! defined(MD_IMPLEMENTED)\n"
"#define MD_IMPLEMENTED\n"
// "#define MD_IMPLEMENTED\n"
);
gen_Str implementation_guard_end = lit(
"// END: MD_IMPLEMENTATION\n"
@@ -146,66 +179,170 @@ int main()
// Header files
print_fmt("%S", generation_notice);
print_fmt("%S", lit("#pragma once\n\n"));
preprocess_ifndef("METADESK_HEADER");
define(lit("METADESK_HEADER"), MT_Statement);
new_line();
print(gen_scan_file(path_gen_c11 "header_start.h"));
print_fmt("%S", generation_notice);
print(gen_scan_file(path_gen_c11 "banner_singleheader.h"));
new_line();
pragma_region("Base");
print(gen_scan_file(path_gen_c11 "base_banner.h"));
new_line();
print(banner_base);
new_line();
print_section(header, r_base_context_cracking_h, lit("Context Cracking"));
print_section(header, r_base_platform_h, lit("platform"));
print_section(header, r_base_linkage_h, lit("Linkage"));
print_section(header, r_base_macros_h, lit("Macros"));
print_section(header, r_base_generic_macros_h, lit("_Generic Macros"));
print_section(header, r_base_profiling_h, lit("Profiling"));
print_section(r_base_context_cracking_h, lit("Context Cracking"));
print_section(r_base_platform_h, lit("platform"));
print_section(r_base_linkage_h, lit("Linkage"));
print_section(r_base_macros_h, lit("Macros"));
print_section(r_base_generic_macros_h, lit("_Generic Macros"));
print_section(r_base_profiling_h, lit("Profiling"));
print_fmt("%S", implementation_guard_start);
new_line();
define(lit("STB_SPRINTF_IMPLEMENTATION"), MT_Statement);
print_fmt("%S", implementation_guard_start);
print(gen_def_define(lit("STB_SPRINTF_DECORATE(name)"), MT_Expression, .content = lit("md_##name")));
define(lit("STB_SPRINTF_DECORATE(name)"), MT_Expression, .content = lit("md_##name"), .flags = MF_Functional);
// print();
print(preprocess_cond(PreprocessCond_If, lit("MD_BUILD_STATIC"))); new_line(); {
preprocess_if("MD_BUILD_STATIC"); {
define(lit("STB_BUILD_STATIC"), MT_Statement);
}
print(gen_preprocess_endif);
preprocess_endif();
new_line();
print_section(header, r_tp_stb_sprintf_h, lit("STB snprintf Header"));
print_section(r_tp_stb_sprintf_h, lit("STB snprintf Header"));
print_fmt("%S", implementation_guard_end);
new_line();
print_section(header, r_base_base_types_h, lit("Types"));
print_section(header, r_base_ring_h, lit("Ring"));
print_section(header, r_base_debug_h, lit("Debug"));
print_section(header, r_base_memory_h, lit("Memory"));
print_section(header, r_base_memory_substrate_h, lit("Memory Substrate"));
print_section(header, r_base_arena_h, lit("Arena"));
print_section(header, r_base_space_h, lit("Space"));
print_section(header, r_base_math_h, lit("Math"));
print_section(header, r_base_sort_h, lit("Sort"));
print_section(header, r_base_toolchain_h, lit("Toolchain"));
print_section(header, r_base_time_h, lit("Time"));
print_section(header, r_base_strings_h, lit("strings"));
print_section(header, r_base_text_h, lit("Text"));
print_section(header, r_base_thread_context_h, lit("Thread Context"));
print_section(header, r_base_command_line_h, lit("Command Line"));
print_section(header, r_base_markup_h, lit("Markup"));
print_section(header, r_base_logger_h, lit("Logger"));
print_section(header, r_base_entry_point_h, lit("Entry Point"));
print_section(header, r_base_file_h, lit("File"));
print_section(r_base_base_types_h, lit("Types"));
print_section(r_base_ring_h, lit("Ring"));
print_section(r_base_debug_h, lit("Debug"));
print_section(r_base_memory_h, lit("Memory"));
print_section(r_base_memory_substrate_h, lit("Memory Substrate"));
print_section(r_base_arena_h, lit("Arena"));
print_section(r_base_space_h, lit("Space"));
print_section(r_base_math_h, lit("Math"));
print_section(r_base_sort_h, lit("Sort"));
print_section(r_base_toolchain_h, lit("Toolchain"));
print_section(r_base_time_h, lit("Time"));
print_section(r_base_strings_h, lit("strings"));
print_section(r_base_text_h, lit("Text"));
print_section(r_base_thread_context_h, lit("Thread Context"));
print_section(r_base_command_line_h, lit("Command Line"));
print_section(r_base_markup_h, lit("Markup"));
print_section(r_base_logger_h, lit("Logger"));
print_section(r_base_entry_point_h, lit("Entry Point"));
print_section(r_base_file_h, lit("File"));
pragma_endregion("Base");
new_line();
pragma_region("Operating System");
print(banner_os);
new_line();
print_section(r_os_h, lit("OS"));
preprocess_if("!defined(MD_OS_FEATURE_GRAPHICAL)"); {
define(lit("MD_OS_FEATURE_GRAPHICAL"), MT_Expression, .content = lit("0") );
}
preprocess_endif();
new_line();
preprocess_if("!defined(MD_OS_GFX_STUB)"); {
define(lit("MD_OS_GFX_STUB"), MT_Expression, .content = lit("0") );
}
preprocess_endif();
new_line();
preprocess_if("MD_OS_WINDOWS"); {
print_section(r_os_win32_includes_h, lit("Win32 Includes"));
print_section(r_os_win32_h, lit("OS Win32"));
}
comment("#if MD_OS_WINDOWS"); new_line();
preprocess_elif("MD_OS_LINUX"); {
print_section(r_os_linux_includes_h, lit("Linux Includes"));
print_section(r_os_linux_h, lit("OS Linux"));
}
comment("#elif OS_LINUX");
preprocess_endif();
pragma_endregion("Operting System")
new_line();
pragma_region("MDesk")
print(banner_mdesk);
new_line();
print(r_mdesk_h);
pragma_endregion("MDesk")
new_line();
comment("END: METADESK_HEADER")
preprocess_endif();
// Source files
print(banner_md_impl);
print_fmt("%S", implementation_guard_start);
define(lit("MD_IMPLEMENED"), MT_Statement);
new_line();
pragma_region("Base");
print(banner_base);
new_line();
print_section(r_base_platform_c, lit("Platform"));
print_section(r_base_memory_substrate_c, lit("Memory Substrate"));
print_section(r_base_arena_c, lit("Arena"));
print_section(r_base_strings_c, lit("Strings"));
print_section(r_base_text_c, lit("Text"));
print_section(r_base_thread_context_c, lit("Thread Context"));
print_section(r_base_markup_c, lit("Markup"));
print_section(r_base_command_line_c, lit("Command Line"));
print_section(r_base_logger_c, lit("Logger"));
print_section(r_base_entry_point_c, lit("Entry Point"));
print_section(r_base_time_c, lit("Time"));
pragma_endregion("Base");
new_line();
pragma_region("Operating System");
print(banner_os);
new_line();
preprocess_if("MD_OS_WINDOWS"); {
print(r_os_win32_c)
}
preprocess_elif("MD_OS_LINUX"); {
print(r_os_linux_c);
}
preprocess_endif();
print(r_os_c);;
pragma_endregion("Operating System");
new_line();
pragma_region("MDesk");
print(banner_mdesk);
new_line();
print(r_mdesk_c);
pragma_endregion("MDesk");
new_line();
print_fmt("%S", implementation_guard_end);
new_line();
gen_builder_write(header);
#undef builder
}
// Segregated
if (GENERATE_SEGEREGATED)
{
}
+30
View File
@@ -26,10 +26,40 @@
#define path_scratch_file path_gen "scratch.h"
#define path_format_style path_bin ".clang-format "
// Codegen DSL
#define lit gen_txt
#define nullptr gen_nullptr
// #define args
#define str_fmt(fmt, ...) gen_strbuilder_to_str(gen_strbuilder_fmt_buf(gen_get_context()->Allocator_Temp, fmt, __VA_ARGS__))
#define print(code) gen_builder_print(builder, code);
#define print_fmt(fmt, ...) gen_builder_print_fmt(builder, fmt, __VA_ARGS__)
#define new_line() gen_builder_print(builder, gen_fmt_newline)
#define pragma_region(label) print(gen_def_pragma(str_fmt("region %S", lit(label))))
#define pragma_endregion(label) print(gen_def_pragma(str_fmt("endregion %S", lit(label))))
#define define(id, type, ...) print(gen_def__define(id, type, &(gen_Opts_def_define){ __VA_ARGS__ }))
#define comment(content) print(gen_def_comment(lit(content)))
#define include gen_def_include
#define preprocess_cond(type, expr) gen_def_preprocess_cond(type, expr)
#define preprocess_if(expr) print(preprocess_cond(PreprocessCond_If, lit(expr))); new_line()
#define preprocess_ifndef(expr) print(preprocess_cond(PreprocessCond_IfNotDef, lit(expr))); new_line()
#define preprocess_elif(expr) print(preprocess_cond(PreprocessCond_ElIf, lit(expr))); new_line()
#define preprocess_endif() print(gen_preprocess_endif)
#ifndef PRINT_SECTION_REGION_PRAGMAS
#define PRINT_SECTION_REGION_PRAGMAS 1
#endif
#define print_section(code, label) print__section(builder, code, label)
void print__section(gen_Builder* builder, gen_Code code, gen_Str label) {
if (PRINT_SECTION_REGION_PRAGMAS) gen_builder_print(builder, gen_def_pragma(str_fmt("region %S", label)) );
gen_builder_print(builder, code);
if (PRINT_SECTION_REGION_PRAGMAS) gen_builder_print(builder, gen_def_pragma(str_fmt("endregion %S", label)) );
gen_builder_print(builder, gen_fmt_newline);
}
void register_library_macros()
{
// These in the same order as metadesk.h