gen_c11.c: generates base

This commit is contained in:
ed
2025-02-10 21:48:46 -05:00
parent 5d8850af55
commit a2938ef3fa
11 changed files with 170 additions and 39 deletions
+7
View File
@@ -0,0 +1,7 @@
/*
▀██▀▀█▄
██ ██ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄
██▀▀▀█▄ ▀▀ ▄██ ██▄ ▀ ▄█▄▄▄██
██ ██ ▄█▀ ██ ▄ ▀█▄▄ ██
▄██▄▄▄█▀ ▀█▄▄▀█▀ █▀▄▄█▀ ▀█▄▄▄▀
*/
+5 -8
View File
@@ -38,12 +38,12 @@ word expect, md_expect
word likely, md_likely
word unlikely, md_unlikely
word ccast, word md_ccast
word pcast, word md_pcast
word rcast, word md_rcast
word scast, word md_scast
word ccast, md_ccast
word pcast, md_pcast
word rcast, md_rcast
word scast, md_scast
// word typeof, word md_typeof
// word typeof, md_typeof
word enum_underlying, md_enum_underlying
word nullptr, md_nullptr
@@ -1078,9 +1078,6 @@ word tag_count_from_node, md_tag_count_from_node
namespace string_from_children_, md_string_from_children_
word tree_match, md_tree_match
word node_match, md_node_match
namespace tree_copy_, md_tree_copy_
word tree_copy, md_treecopy
namespace tokenize_from_text_, md_tokenize_from_text_
+120 -13
View File
@@ -2,7 +2,11 @@
#include "gen_common.h"
#define path_refactor_script "./c11.refactor"
#ifndef PRINT_SECTION_REGION_PRAGMAS
#define PRINT_SECTION_REGION_PRAGMAS 1
#endif
#define path_refactor_script path_gen_c11 "c11.refactor"
gen_Code refactor( gen_Code code ) {
return code_refactor_and_format(code, path_scratch_file, path_refactor_script, nullptr );
@@ -11,6 +15,15 @@ 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};
@@ -65,35 +78,129 @@ int main()
gen_Code base_entry_point_h = gen_scan_file(path_base "entry_point.h");
gen_Code base_file_h = gen_scan_file(path_base "file.h");
gen_Code os_h = gen_scan_file(path_os "os.h");
gen_Code os_win32_includes_h = gen_scan_file(path_os_win32 "os_win32_includes.h");
gen_Code os_win32_h = gen_scan_file(path_os_win32 "os_win32.h");
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 os_h = gen_scan_file(path_os "os.h");
gen_Code os_win32_includes_h = gen_scan_file(path_os_win32 "os_win32_includes.h");
gen_Code os_win32_h = gen_scan_file(path_os_win32 "os_win32.h");
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");
#pragma region Refactored / Formatted
gen_Code r_tp_stb_sprintf_h = refactor(tp_stb_sprintf_h);
gen_Code r_base_context_cracking_h = refactor(base_context_cracking_h);
gen_Code r_base_platform_h = refactor(base_platform_h);
gen_Code r_base_linkage_h = refactor(base_linkage_h);
gen_Code r_base_macros_h = refactor(base_macros_h);
gen_Code r_base_generic_macros_h = refactor(base_generic_macros_h);
gen_Code r_base_profiling_h = refactor(base_profiling_h);
gen_Code r_base_base_types_h = refactor(base_base_types_h);
gen_Code r_base_ring_h = refactor(base_ring_h);
gen_Code r_base_debug_h = refactor(base_debug_h);
gen_Code r_base_memory_h = refactor(base_memory_h);
gen_Code r_base_memory_substrate_h = refactor(base_memory_substrate_h);
gen_Code r_base_arena_h = refactor(base_arena_h);
gen_Code r_base_space_h = refactor(base_space_h);
gen_Code r_base_math_h = refactor_and_format(base_math_h);
gen_Code r_base_sort_h = refactor(base_sort_h);
gen_Code r_base_toolchain_h = refactor(base_toolchain_h);
gen_Code r_base_time_h = refactor(base_time_h);
gen_Code r_base_strings_h = refactor_and_format(base_strings_h);
gen_Code r_base_text_h = refactor(base_text_h);
gen_Code r_base_thread_context_h = refactor(base_thread_context_h);
gen_Code r_base_command_line_h = refactor(base_command_line_h);
gen_Code r_base_markup_h = refactor(base_markup_h);
gen_Code r_base_logger_h = refactor(base_logger_h);
gen_Code r_base_entry_point_h = refactor(base_entry_point_h);
gen_Code r_base_file_h = refactor(base_file_h);
gen_Code r_os_h = refactor(os_h);
gen_Code r_os_win32_includes_h = refactor(os_win32_includes_h);
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);
#pragma endregion Refactored / Formatted
// Singleheader
{
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(
"\n"
"#pragma region METADESK IMPLEMENTATION GUARD\n"
// "#pragma region METADESK IMPLEMENTATION GUARD\n"
"#if defined(MD_IMPLEMENTATION) && ! defined(MD_IMPLEMENTED)\n"
"#define MD_IMPLEMENTED\n"
"\n"
);
gen_Str implementation_guard_end = lit(
"\n"
"// END: MD_IMPLEMENTATION\n"
"#endif\n"
"#pragma endregion METADESK IMPLEMENTATION GUARD\n"
"\n"
// "#pragma endregion METADESK IMPLEMENTATION GUARD\n"
);
// Header files
gen_builder_print_fmt(header, "%S", generation_notice);
print_fmt("%S", generation_notice);
print_fmt("%S", lit("#pragma once\n\n"));
print(gen_scan_file(path_gen_c11 "header_start.h"));
new_line();
pragma_region("Base");
print(gen_scan_file(path_gen_c11 "base_banner.h"));
new_line();
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"));
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")));
// print();
print(preprocess_cond(PreprocessCond_If, lit("MD_BUILD_STATIC"))); new_line(); {
define(lit("STB_BUILD_STATIC"), MT_Statement);
}
print(gen_preprocess_endif);
new_line();
print_section(header, 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"));
pragma_endregion("Base");
gen_builder_write(header);
}
+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 │
│ │
╚────────────────────────────────────────────────────────────────────────────────────────────────────────────╝
/ \-------------------------,
\_,| |
| Single-header C11 |
| ,-----------------------
\_/______________________/
*/