diff --git a/.gitignore b/.gitignore
index 3104310..7603f81 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,6 @@
.idea
-build/*
+**/build/*
.vs
**/*.gen.*
diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json
index 7d9f8e2..8c69c10 100644
--- a/.vscode/c_cpp_properties.json
+++ b/.vscode/c_cpp_properties.json
@@ -12,8 +12,10 @@
"GEN_TIME"
],
"windowsSdkVersion": "10.0.19041.0",
- "compilerPath": "C:/Users/Ed/scoop/apps/llvm/current/bin/clang++.exe",
- "intelliSenseMode": "windows-clang-x64",
+ // "compilerPath": "C:/Users/Ed/scoop/apps/llvm/current/bin/clang++.exe",
+ "compilerPath": "C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\cl.exe",
+ "intelliSenseMode": "msvc-x64",
+ // "intelliSenseMode": "windows-clang-x64",
"compileCommands": "${workspaceFolder}/project/build/compile_commands.json"
}
],
diff --git a/.vscode/launch.json b/.vscode/launch.json
index 73b31b1..0cde1a5 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -27,7 +27,7 @@
"type": "cppvsdbg",
"request": "launch",
"name": "Debug bootstrap vsdbg",
- "program": "${workspaceFolder}/project/build/gencpp_bootstrap.exe",
+ "program": "${workspaceFolder}/project/build/bootstrap.exe",
"args": [],
"cwd": "${workspaceFolder}/project/",
"visualizerFile": "${workspaceFolder}/scripts/gencpp.natvis"
diff --git a/docs/Parsing.md b/docs/Parsing.md
index 20b4e19..9a538bd 100644
--- a/docs/Parsing.md
+++ b/docs/Parsing.md
@@ -40,7 +40,6 @@ The keywords supported for the preprocessor are:
* ifdef
* elif
* endif
-* undef
* pragma
Each directive `#` line is considered one preproecessor unit, and will be treated as one Preprocessor AST. *These ASTs will be considered members or entries of braced scope they reside within*.
diff --git a/gencpp.vcxproj b/gencpp.vcxproj
index 0887f2c..1167e0d 100644
--- a/gencpp.vcxproj
+++ b/gencpp.vcxproj
@@ -98,6 +98,7 @@
+
@@ -111,6 +112,8 @@
+
+
@@ -119,6 +122,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -132,6 +148,15 @@
+
+
+
+
+
+
+
+
+
@@ -140,6 +165,10 @@
+
+
+
+
@@ -157,6 +186,9 @@
+
+
+
@@ -166,6 +198,15 @@
+
+
+
+
+
+
+
+
+
@@ -176,6 +217,14 @@
+
+
+
+
+
+
+
+
diff --git a/gencpp.vcxproj.filters b/gencpp.vcxproj.filters
index 4d7e755..b9da6b1 100644
--- a/gencpp.vcxproj.filters
+++ b/gencpp.vcxproj.filters
@@ -18,18 +18,9 @@
Source Files
-
- Source Files
-
-
- Source Files
-
Source Files
-
- Source Files
-
Source Files
@@ -60,9 +51,6 @@
Source Files
-
- Source Files
-
Source Files
@@ -75,32 +63,116 @@
Source Files
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
Header Files
-
- Header Files
-
Header Files
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
Header Files
@@ -137,18 +209,6 @@
Header Files
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
-
- Header Files
-
Header Files
@@ -170,9 +230,6 @@
Header Files
-
- Header Files
-
Header Files
@@ -215,6 +272,117 @@
Header Files
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
@@ -229,6 +397,7 @@
+
diff --git a/project/auxillary/builder.cpp b/project/auxillary/builder.cpp
index 968bd69..694d81c 100644
--- a/project/auxillary/builder.cpp
+++ b/project/auxillary/builder.cpp
@@ -12,6 +12,7 @@ Builder Builder::open( char const* path )
result.Buffer = String::make_reserve( GlobalAllocator, Builder_StrBufferReserve );
+ // log_fmt("$Builder - Opened file: %s\n", result.File.filename );
return result;
}
@@ -22,7 +23,11 @@ void Builder::pad_lines( s32 num )
void Builder::print( Code code )
{
- Buffer.append( code->to_string() );
+ String str = code->to_string();
+ const sw len = str.length();
+
+ // log_fmt( "%s - print: %.*s\n", File.filename, len > 80 ? 80 : len, str.Data );
+ Buffer.append( str );
}
void Builder::print_fmt( char const* fmt, ... )
@@ -35,6 +40,7 @@ void Builder::print_fmt( char const* fmt, ... )
res = str_fmt_va( buf, count_of( buf ) - 1, fmt, va ) - 1;
va_end( va );
+ // log_fmt( "$%s - print_fmt: %.*s\n", File.filename, res > 80 ? 80 : res, buf );
Buffer.append( buf, res );
}
@@ -43,8 +49,9 @@ void Builder::write()
bool result = file_write( & File, Buffer, Buffer.length() );
if ( result == false )
- log_failure("gen::File::write - Failed to write to file: %s", file_name( & File ) );
+ log_failure("gen::File::write - Failed to write to file: %s\n", file_name( & File ) );
+ log_fmt( "Generated: %s\n", File.filename );
file_close( & File );
Buffer.free();
}
diff --git a/project/gen.bootstrap.cpp b/project/bootstrap.cpp
similarity index 100%
rename from project/gen.bootstrap.cpp
rename to project/bootstrap.cpp
diff --git a/project/components/ast.hpp b/project/components/ast.hpp
index aebdecc..af5e014 100644
--- a/project/components/ast.hpp
+++ b/project/components/ast.hpp
@@ -214,7 +214,7 @@ struct AST
- sizeof(ModuleFlag)
- sizeof(u32)
)
- / sizeof(SpecifierT) -1; // -1 for 4 extra bytes
+ / sizeof(SpecifierT) - 1; // -1 for 4 extra bytes
union {
struct
diff --git a/project/components/interface.parsing.cpp b/project/components/interface.parsing.cpp
index 790d4c9..74c8d77 100644
--- a/project/components/interface.parsing.cpp
+++ b/project/components/interface.parsing.cpp
@@ -1409,7 +1409,7 @@ CodeAttributes parse_attributes()
using namespace Parser;
push_scope();
- Token start;
+ Token start = NullToken;
s32 len = 0;
if ( check(TokType::Attribute_Open) )
@@ -3186,7 +3186,7 @@ CodeConstructor parse_constructor()
{
eat( TokType::Assign_Classifer );
- Token initializer_list_tok;
+ Token initializer_list_tok = NullToken;
s32 level = 0;
while ( left && ( currtok.Type != TokType::BraceCurly_Open || level > 0 ) )
diff --git a/project/dependencies/debug.hpp b/project/dependencies/debug.hpp
index e53d4aa..d9750e8 100644
--- a/project/dependencies/debug.hpp
+++ b/project/dependencies/debug.hpp
@@ -34,22 +34,22 @@ s32 assert_crash( char const* condition );
void process_exit( u32 code );
#if Build_Debug
- #define GEN_FATAL( fmt, ... ) \
+ #define GEN_FATAL( ... ) \
do \
{ \
local_persist thread_local \
char buf[GEN_PRINTF_MAXLEN] = { 0 }; \
\
- str_fmt(buf, GEN_PRINTF_MAXLEN, fmt, __VA_ARGS__); \
+ str_fmt(buf, GEN_PRINTF_MAXLEN, __VA_ARGS__); \
GEN_PANIC(buf); \
} \
while (0)
#else
-# define GEN_FATAL( fmt, ... ) \
+# define GEN_FATAL( ... ) \
do \
{ \
- str_fmt_out_err( fmt, __VA_ARGS__ ); \
+ str_fmt_out_err( __VA_ARGS__ ); \
process_exit(1); \
} \
while (0)
diff --git a/project/dependencies/macros.hpp b/project/dependencies/macros.hpp
index 5774303..9eba24d 100644
--- a/project/dependencies/macros.hpp
+++ b/project/dependencies/macros.hpp
@@ -40,7 +40,7 @@
#define scast( Type, Value ) static_cast< Type >( Value )
// Num Arguments (Varadics)
-#if defined(__GNUC__) || defined(__clang__)
+// #if defined(__GNUC__) || defined(__clang__)
// Supports 0-50 arguments
#define num_args_impl( _0, \
_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \
@@ -72,37 +72,37 @@
0 \
)
-#else
+// #else
// Supports 1-50 arguments
-#define num_args_impl( \
- _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \
- _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \
- _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \
- _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \
- _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, \
- _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, \
- _61, _62, _63, _64, _65, _66, _67, _68, _69, _70, \
- _71, _72, _73, _74, _75, _76, _77, _78, _79, _80, \
- _81, _82, _83, _84, _85, _86, _87, _88, _89, _90, \
- _91, _92, _93, _94, _95, _96, _97, _98, _99, _100, \
- N, ... \
- ) N
+// #define num_args_impl( \
+// _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \
+// _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \
+// _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \
+// _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \
+// _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, \
+// _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, \
+// _61, _62, _63, _64, _65, _66, _67, _68, _69, _70, \
+// _71, _72, _73, _74, _75, _76, _77, _78, _79, _80, \
+// _81, _82, _83, _84, _85, _86, _87, _88, _89, _90, \
+// _91, _92, _93, _94, _95, _96, _97, _98, _99, _100, \
+// N, ... \
+// ) N
-#define num_args(...) \
- num_args_impl( __VA_ARGS__, \
- 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, \
- 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, \
- 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, \
- 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, \
- 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, \
- 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, \
- 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, \
- 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, \
- 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, \
- 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, \
- 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 \
- )
-#endif
+// #define num_args(...) \
+// num_args_impl( __VA_ARGS__, \
+// 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, \
+// 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, \
+// 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, \
+// 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, \
+// 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, \
+// 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, \
+// 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, \
+// 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, \
+// 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, \
+// 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, \
+// 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 \
+// )
+// // #endif
// Stringizing
#define stringize_va( ... ) #__VA_ARGS__
diff --git a/project/helpers/helper.hpp b/project/helpers/helper.hpp
index 890adf3..3913d3b 100644
--- a/project/helpers/helper.hpp
+++ b/project/helpers/helper.hpp
@@ -61,7 +61,7 @@ CodeBody gen_ecode( char const* path )
CodeBody gen_eoperator( char const* path )
{
- char scratch_mem[kilobytes(1)];
+ char scratch_mem[kilobytes(4)];
Arena scratch = Arena::init_from_memory( scratch_mem, sizeof(scratch_mem) );
file_read_contents( scratch, zero_terminate, path );
@@ -116,7 +116,7 @@ CodeBody gen_eoperator( char const* path )
CodeBody gen_especifier( char const* path )
{
- char scratch_mem[kilobytes(1)];
+ char scratch_mem[kilobytes(4)];
Arena scratch = Arena::init_from_memory( scratch_mem, sizeof(scratch_mem) );
file_read_contents( scratch, zero_terminate, path );
diff --git a/project/meson.build b/project/meson.build
deleted file mode 100644
index a9b2d09..0000000
--- a/project/meson.build
+++ /dev/null
@@ -1,18 +0,0 @@
-project( 'gencpp_bootstrap', 'c', 'cpp', default_options : ['buildtype=debug'] )
-
-includes = include_directories(
-[
-'../project',
-])
-
-sources = [ 'gen.bootstrap.cpp' ]
-
-if get_option('buildtype').startswith('debug')
-
- add_project_arguments('-DBuild_Debug', language : ['c', 'cpp'])
-
-endif
-
-add_project_arguments('-DGEN_TIME', language : ['c', 'cpp'])
-
-executable( 'gencpp_bootstrap', sources, include_directories : includes )
diff --git a/scripts/Readme.md b/scripts/Readme.md
index a4aee11..cbb5d08 100644
--- a/scripts/Readme.md
+++ b/scripts/Readme.md
@@ -27,13 +27,18 @@ IF they are changed the following files would need adjustment:
**`clean.ps1`**
Remove any generated content from the repository.
-**`bootstrap.ps1`**
-Generate a version of gencpp where components are inlined directly to `gen.` and `gen. `
-Any heavily preprocessed code is not inlined and are instead generated using the code in the `helpers` directory.
+**`build.ps1`**
+Build bootstrap, singleheader, or tests. Supports MSVC or clang, release or debug.
-**`singleheader.ps1`**
-Generate a single-header version of the library where all code that would normally good in the usual four files (see bootstrap) are inlined into a single `gen.hpp` file.
-As with the bootstrap, any heavily preprocessed code is not inlined and instead generated with helper code.
+```
+args:
+ bootstrap
+ singleheader
+ test
+ clang
+ msvc
+ release
+```
**`test.gen.build.ps1`**
Build the metaprogram for generating the test code.
@@ -46,3 +51,6 @@ Build and run metaprogram, build test program.
**`test.run.ps1`**
Build and run metaprogram, build and run test program.
+
+
+*Note: My env is Windows 11 with MSVC 2022 and clang 16.0.6*
diff --git a/scripts/bootstrap.ci.ps1 b/scripts/bootstrap.ci.ps1
deleted file mode 100644
index 5a8bdd4..0000000
--- a/scripts/bootstrap.ci.ps1
+++ /dev/null
@@ -1,78 +0,0 @@
-[string] $type = $null
-[string] $test = $false
-
-foreach ( $arg in $args )
-{
- if ( $arg -eq "test" )
- {
- $test = $true
- }
- else
- {
- $type = $arg
- }
-}
-
-$path_root = git rev-parse --show-toplevel
-$path_project = Join-Path $path_root project
-$path_project_build = Join-Path $path_project build
-$path_project_gen = Join-Path $path_project gen
-
-write-host "`n`nBuilding gencpp bootstrap`n"
-
-if ( -not( Test-Path $path_project_build) )
-{
-# Generate build files for bootstrap
-Push-Location $path_project
- $args_meson = @()
- $args_meson += "setup"
- $args_meson += $path_project_build
-
- & meson $args_meson
-Pop-Location
-}
-
-# Compile bootstrap
-Push-Location $path_root
- $args_ninja = @()
- $args_ninja += "-C"
- $args_ninja += $path_project_build
-
- & ninja $args_ninja
-Pop-Location
-
-Push-location $path_project
- if ( -not(Test-Path($path_project_gen) )) {
- New-Item -ItemType Directory -Path $path_project_gen
- }
-
- # Run bootstrap
- $gencpp_bootstrap = Join-Path $path_project_build gencpp_bootstrap.exe
-
- Write-Host `nRunning gencpp bootstrap...
- & $gencpp_bootstrap
-
- # Format generated gencpp
- Write-Host `nBeginning format...
- $formatParams = @(
- '-i' # In-place
- '-style=file:../scripts/.clang-format'
- '-verbose'
- )
-
- $include = @(
- 'gen.hpp', 'gen.cpp',
- 'gen.dep.hpp', 'gen.dep.cpp',
- 'gen.builder.hpp', 'gen.builder.cpp'
- 'gen.scanner.hpp', 'gen.scanner.cpp'
- )
- $exclude = $null
-
- $targetFiles = @(Get-ChildItem -Recurse -Path $path_project_gen -Include $include -Exclude $exclude | Select-Object -ExpandProperty FullName)
-
- clang-format $formatParams $targetFiles
- Write-Host "`nFormatting complete"
-Pop-Location
-
-# Build and run validation
-
diff --git a/scripts/bootstrap.ps1 b/scripts/bootstrap.ps1
deleted file mode 100644
index 0819482..0000000
--- a/scripts/bootstrap.ps1
+++ /dev/null
@@ -1,2 +0,0 @@
-cls
-Invoke-Expression "& $(Join-Path $PSScriptRoot 'bootstrap.ci.ps1') $args"
diff --git a/scripts/build.ps1 b/scripts/build.ps1
new file mode 100644
index 0000000..d3aef76
--- /dev/null
+++ b/scripts/build.ps1
@@ -0,0 +1,367 @@
+Import-Module ./helpers/target_arch.psm1
+
+cls
+
+#region Arguments
+ $compiler = $null
+[bool] $release = $false
+[bool] $bootstrap = $false
+[bool] $singleheader = $false
+[bool] $tests = $false
+
+[array] $compilers = @( "clang", "gcc", "msvc" )
+
+# This is a really lazy way of parsing the args, could use actual params down the line...
+
+if ( $args ) { $args | ForEach-Object {
+ switch ($_){
+ { $_ -in $compilers } { $compiler = $_; break }
+ "release" { $release = $true }
+ "bootstrap" { $bootstrap = $true }
+ "singleheader" { $singleheader = $true }
+ "tests" { $tests = $true }
+ }
+}}
+#endregion Arguments
+
+#region Building
+write-host "Building gencpp with $compiler"
+
+Invoke-Expression "& $(join-path $PSScriptRoot 'helpers/devshell.ps1') -arch x64"
+
+$path_root = git rev-parse --show-toplevel
+$path_build = Join-Path $path_root build
+$path_project = Join-Path $path_root project
+$path_scripts = Join-Path $path_root scripts
+$path_singleheader = Join-Path $path_root singleheader
+$path_test = Join-Path $path_root test
+
+write-host "Build Type: $(if ($release) {"Release"} else {"Debug"} )"
+
+if ( $compiler -eq $null ) {
+ write-host "No compilier specified, assuming clang available"
+ $compiler = "clang"
+}
+
+Push-Location $path_root
+
+function run-compiler
+{
+ param( $compiler, $executable, $path_build, $path_gen, $compiler_args )
+
+ write-host "`nBuilding $executable"
+ write-host "Compiler config:"
+ $compiler_args | ForEach-Object {
+ write-host $_ -ForegroundColor Cyan
+ }
+
+ if ( -not(Test-Path($path_build) )) {
+ New-Item -ItemType Directory -Path $path_build
+ }
+ if ( -not(Test-Path($path_gen) )) {
+ New-Item -ItemType Directory -Path $path_gen
+ }
+
+ $time_taken = Measure-Command {
+ & $compiler $compiler_args
+ | ForEach-Object {
+ $color = 'White'
+ switch ($_){
+ { $_ -match "error" } { $color = 'Red' ; break }
+ { $_ -match "warning" } { $color = 'Yellow'; break }
+ }
+ write-host `t $_ -ForegroundColor $color
+ }
+ }
+ write-host "$executable built in $($time_taken.TotalMilliseconds) ms"
+}
+
+if ( $compiler -match "clang" )
+{
+ $target_arch = Get-TargetArchClang
+
+ $flag_compile_only = '-c'
+ $flag_debug = '-g'
+ $flag_debug_codeview = '-gcodeview'
+ $flag_define = '-D'
+ $flag_include = '-I'
+ $flag_library = '-l'
+ $flag_library_path = '-L'
+ $flag_path_output = '-o'
+ $flag_preprocess_non_intergrated = '-no-integrated-cpp'
+ $flag_profiling_debug = '-fdebug-info-for-profiling'
+ $flag_target_arch = '-target'
+ $flag_x_linker = '-Xlinker'
+ $flag_machine_32 = '/machine:X64'
+ $flag_machine_64 = '/machine:X64'
+ $flag_win_linker = '-Wl,'
+ $flag_win_subsystem_console = '/SUBSYSTEM:CONSOLE'
+ $flag_win_machine_32 = '/MACHINE:X86'
+ $flag_win_machine_64 = '/MACHINE:X64'
+
+ # $library_paths = @(
+ # 'C:\Windows\System32'
+
+ # )
+
+ if ( $bootstrap )
+ {
+ $path_build = join-path $path_project build
+ $path_gen = join-path $path_project gen
+
+ $include = $path_project
+ $unit = join-path $path_project "bootstrap.cpp"
+ $executable = join-path $path_build "bootstrap.exe"
+
+ $compiler_args = @(
+ $flag_target_arch, $target_arch,
+ $flag_preprocess_non_intergrated,
+ $( $flag_define + 'GEN_TIME' ),
+ $flag_path_output, $executable,
+ $( $flag_include + $include )
+ )
+ if ( $release -eq $false ) {
+ $compiler_args += $( $flag_define + 'Build_Debug' )
+ $compiler_args += $flag_debug, $flag_debug_codeview, $flag_profiling_debug
+ }
+
+ $linker_args = @(
+ $flag_x_linker,
+ # $( $flag_linker + $flag_win_subsystem_console ),
+ $( $flag_linker + $flag_machine_64 )
+ )
+ $libraries = @(
+ 'Kernel32', # For Windows API
+ # 'msvcrt', # For the C Runtime (Dynamically Linked)
+ 'libucrt',
+ 'libcmt' # For the C Runtime (Static Linkage)
+ )
+ $compiler_args += $linker_args
+ $compiler_args += $libraries | ForEach-Object { $flag_library + $_ }
+
+ $compiler_args += $unit
+ run-compiler clang $executable $path_build $path_gen $compiler_args
+
+ Push-Location $path_project
+ if ( Test-Path($executable) ) {
+ write-host "`nRunning bootstrap"
+ $time_taken = Measure-Command { & $executable
+ | ForEach-Object {
+ write-host `t $_ -ForegroundColor Green
+ }
+ }
+ write-host "`nBootstrap completed in $($time_taken.TotalMilliseconds) ms"
+ }
+ Pop-Location
+ }
+
+ if ( $singleheader )
+ {
+ $path_build = join-path $path_singleheader build
+ $path_gen = join-path $path_singleheader gen
+
+ $include = $path_project
+ $unit = join-path $path_singleheader "singleheader.cpp"
+ $executable = join-path $path_build "singleheader.exe"
+
+ $compiler_args = @(
+ $flag_target_arch, $target_arch,
+ $flag_preprocess_non_intergrated,
+ $( $flag_define + 'GEN_TIME' ),
+ $flag_path_output, $executable,
+ $( $flag_include + $include )
+ )
+ if ( $release -eq $false ) {
+ $compiler_args += $( $flag_define + 'Build_Debug' )
+ $compiler_args += $flag_debug, $flag_debug_codeview, $flag_profiling_debug
+ }
+
+ $compiler_args += $unit
+ run-compiler clang $executable $path_build $path_gen $compiler_args
+
+ Push-Location $path_singleheader
+ if ( Test-Path($executable) ) {
+ write-host "`nRunning singleheader generator"
+ $time_taken = Measure-Command { & $executable
+ | ForEach-Object {
+ write-host `t $_ -ForegroundColor Green
+ }
+ }
+ write-host "`nSingleheader generator completed in $($time_taken.TotalMilliseconds) ms"
+ }
+ Pop-Location
+ }
+
+ if ( $test )
+ {
+ # ... [your test compilation code here]
+ }
+}
+
+if ( $compiler -match "msvc" )
+{
+ $flag_debug = '/Zi'
+ $flag_define = '/D'
+ $flag_include = '/I'
+ $flag_full_src_path = '/FC'
+ $flag_nologo = '/nologo'
+ $flag_linker = '/link'
+ $flag_out_name = '/OUT:'
+ $flag_path_interm = '/Fo'
+ $flag_path_debug = '/Fd'
+ $flag_path_output = '/Fe'
+ $flag_preprocess_conform = '/Zc:preprocessor'
+
+ [array] $compiler_args = $null
+
+ if ( $bootstrap )
+ {
+ $path_build = join-path $path_project build
+ $path_gen = join-path $path_project gen
+
+ $include = $path_project
+ $unit = join-path $path_project "bootstrap.cpp"
+ $executable = join-path $path_build "bootstrap.exe"
+
+
+ $compiler_args = @(
+ $flag_nologo,
+ $flag_debug,
+ $flag_preprocess_conform,
+ $( $flag_define + 'GEN_TIME' ),
+ $flag_full_src_path,
+ $( $flag_path_interm + $path_build + '\' ),
+ $( $flag_path_output + $path_build + '\' ),
+ $( $flag_include + $include )
+ )
+
+ if ( $release -eq $false ) {
+ $compiler_args += $( $flag_define + 'Build_Debug' )
+ $compiler_args += $( $flag_path_debug + $path_build + '\' )
+ }
+
+ $compiler_args += $unit
+ run-compiler cl $executable $path_build $path_gen $compiler_args
+
+ Push-Location $path_project
+ if ( Test-Path($executable) ) {
+ write-host "`nRunning bootstrap"
+ $time_taken = Measure-Command { & $executable
+ | ForEach-Object {
+ write-host `t $_ -ForegroundColor Green
+ }
+ }
+ write-host "`nBootstrap completed in $($time_taken.TotalMilliseconds) ms"
+ }
+ Pop-Location
+ }
+
+ if ( $singleheader )
+ {
+ $path_build = join-path $path_singleheader build
+ $path_gen = join-path $path_singleheader gen
+
+ $include = $path_project
+ $unit = join-path $path_singleheader "singleheader.cpp"
+ $executable = join-path $path_build "singleheader.exe"
+
+ $compiler_args = @(
+ $flag_nologo,
+ $flag_debug,
+ $flag_preprocess_conform,
+ $( $flag_define + 'GEN_TIME' ),
+ $flag_full_src_path,
+ $( $flag_path_interm + $path_build + '\' ),
+ $( $flag_path_output + $path_build + '\' ),
+ $( $flag_include + $include )
+ )
+
+ if ( $release -eq $false ) {
+ $compiler_args += $( $flag_define + 'Build_Debug' )
+ $compiler_args += $( $flag_path_debug + $path_build + '\' )
+ }
+
+ $compiler_args += $unit
+ run-compiler cl $executable $path_build $path_gen $compiler_args
+
+ Push-Location $path_singleheader
+ if ( Test-Path($executable) ) {
+ write-host "`nRunning singleheader generator"
+ $time_taken = Measure-Command { & $executable
+ | ForEach-Object {
+ write-host `t $_ -ForegroundColor Green
+ }
+ }
+ write-host "`nSingleheader generator completed in $($time_taken.TotalMilliseconds) ms"
+ }
+ Pop-Location
+ }
+
+ if ( $test )
+ {
+
+ }
+}
+#pragma endregion Building
+
+#pragma region Formatting
+if ( $bootstrap -and (Test-Path (Join-Path $path_project "gen/gen.hpp")) )
+{
+ $path_gen = join-path $path_project gen
+
+ # Format generated gencpp
+ Write-Host "`nBeginning format"
+ $formatParams = @(
+ '-i' # In-place
+ '-style=file:./scripts/.clang-format'
+ '-verbose'
+ )
+
+ $include = @(
+ 'gen.hpp', 'gen.cpp',
+ 'gen.dep.hpp', 'gen.dep.cpp',
+ 'gen.builder.hpp', 'gen.builder.cpp'
+ 'gen.scanner.hpp', 'gen.scanner.cpp'
+ )
+ $exclude = $null
+
+ $targetFiles = @(Get-ChildItem -Recurse -Path $path_gen -Include $include -Exclude $exclude | Select-Object -ExpandProperty FullName)
+
+ $time_taken = Measure-Command {
+ clang-format $formatParams $targetFiles
+ }
+ Write-Host "`nFormatting complete in $($time_taken.TotalMilliseconds) ms"
+}
+
+if ( $singleheader )
+{
+ $path_gen = join-path $path_singleheader gen
+
+ # Format generated gencpp
+ Write-Host "`nBeginning format"
+ $formatParams = @(
+ '-i' # In-place
+ '-style=file:./scripts/.clang-format'
+ '-verbose'
+ )
+
+ $include = @(
+ 'gen.hpp'
+ )
+ $exclude = $null
+
+ $targetFiles = @(Get-ChildItem -Recurse -Path $path_gen -Include $include -Exclude $exclude | Select-Object -ExpandProperty FullName)
+
+ $time_taken = Measure-Command {
+ clang-format $formatParams $targetFiles
+ }
+ Write-Host "`nFormatting complete in $($time_taken.TotalMilliseconds) ms"
+}
+
+if ( $test )
+{
+
+}
+#pragma endregion Formatting
+
+Pop-Location # $path_root
diff --git a/scripts/msvc/devshell.ps1 b/scripts/helpers/devshell.ps1
similarity index 81%
rename from scripts/msvc/devshell.ps1
rename to scripts/helpers/devshell.ps1
index 531bdfa..ed6c203 100644
--- a/scripts/msvc/devshell.ps1
+++ b/scripts/helpers/devshell.ps1
@@ -1,3 +1,8 @@
+param (
+ [ValidateSet("x64", "x86", "arm", "arm64")]
+ [string]$arch = "x64"
+)
+
$ErrorActionPreference = "Stop"
# Use vswhere to find the latest Visual Studio installation
@@ -17,6 +22,9 @@ if ( -not (Test-Path $vs_devshell) ) {
exit 1
}
+# Set the target architecture based on the parameter
+$env:VSCMD_ARG_TGT_ARCH=$arch
+
# Launch the Visual Studio Developer Shell
Push-Location
& $vs_devshell @args
diff --git a/scripts/helpers/target_arch.psm1 b/scripts/helpers/target_arch.psm1
new file mode 100644
index 0000000..e6d388b
--- /dev/null
+++ b/scripts/helpers/target_arch.psm1
@@ -0,0 +1,25 @@
+# target_arch.psm1
+
+function Get-TargetArchClang {
+ # Get the target architecture by querying clang itself
+ $output = & clang -v 2>&1
+ foreach ($line in $output) {
+ if ($line -like "*Target:*") {
+ $clangTarget = ($line -split ':')[1].Trim()
+ return $clangTarget
+ }
+ }
+ throw "Clang target architecture could not be determined."
+}
+
+function Get-TargetArchMSVC {
+ # Assuming you've set the Visual Studio environment variables using `vcvarsall.bat`
+ # This looks for the `VSCMD_ARG_TGT_ARCH` environment variable which Visual Studio sets to indicate the target architecture.
+ $arch = $env:VSCMD_ARG_TGT_ARCH
+ if (-not $arch) {
+ throw "MSVC target architecture could not be determined. Ensure you've initialized the Visual Studio environment."
+ }
+ return $arch
+}
+
+Export-ModuleMember -Function Get-TargetArchClang, Get-TargetArchMSVC
diff --git a/scripts/msvc/build_msvc.ps1 b/scripts/msvc/build_msvc.ps1
deleted file mode 100644
index fc69ddb..0000000
--- a/scripts/msvc/build_msvc.ps1
+++ /dev/null
@@ -1,16 +0,0 @@
-cls
-
-if ( -not( Test-Path $path_build ) ) {
- New-Item -ItemType Directory -Path $path_build | Out-Null
-}
-if ( -not( Test-Path $path_build_interm ) ) {
- New-Item -ItemType Directory -Path $path_build_interm | Out-Null
-}
-
-$path_root = git rev-parse --show-toplevel
-$path_build = Join-Path $path_root build
-$path_gen = Join-Path $path_test gen
-$path_gen_build = Join-Path $path_gen build
-$path_scripts = Join-Path $path_root scripts
-$path_test = Join-Path $path_root test
-$path_test_build = Join-Path $path_test build
diff --git a/scripts/singleheader.ci.ps1 b/scripts/singleheader.ci.ps1
deleted file mode 100644
index 0c1ec49..0000000
--- a/scripts/singleheader.ci.ps1
+++ /dev/null
@@ -1,73 +0,0 @@
-[string] $type = $null
-[string] $test = $false
-
-foreach ( $arg in $args )
-{
- if ( $arg -eq "test" )
- {
- $test = $true
- }
- else
- {
- $type = $arg
- }
-}
-
-$path_root = git rev-parse --show-toplevel
-$path_singleheader = Join-Path $path_root singleheader
-$path_singleheader_build = Join-Path $path_singleheader build
-$path_singleheader_gen = Join-Path $path_singleheader gen
-
-write-host "`n`nBuilding gencpp singleheader`n"
-
-if ( -not( Test-Path $path_singleheader_build) )
-{
-# Generate build files for meta-program
-Push-Location $path_singleheader
- $args_meson = @()
- $args_meson += "setup"
- $args_meson += $path_singleheader_build
-
- & meson $args_meson
-Pop-Location
-}
-
-# Compile meta-program
-Push-Location $path_root
- $args_ninja = @()
- $args_ninja += "-C"
- $args_ninja += $path_singleheader_build
-
- & ninja $args_ninja
-Pop-Location
-
-Push-location $path_singleheader
- if ( -not(Test-Path($path_singleheader_gen) )) {
- New-Item -ItemType Directory -Path $path_singleheader_gen
- }
-
- # Run meta-program
- $gencpp_singleheader = Join-Path $path_singleheader_build gencpp_singleheader.exe
-
- Write-Host `nRunning gencpp singleheader...
- & $gencpp_singleheader
-
- # Format generated files
- Write-Host `nBeginning format...
- $formatParams = @(
- '-i' # In-place
- '-style=file:../scripts/.clang-format'
- '-verbose'
- )
-
- $include = @('gen.hpp')
- $exclude = $null
-
- $targetFiles = @(Get-ChildItem -Recurse -Path $path_project -Include $include -Exclude $exclude | Select-Object -ExpandProperty FullName)
-
- clang-format $formatParams $targetFiles
- Write-Host "`nFormatting complete"
-Pop-Location
-
-# Build and run validation
-
diff --git a/scripts/singleheader.ps1 b/scripts/singleheader.ps1
deleted file mode 100644
index 4e1c249..0000000
--- a/scripts/singleheader.ps1
+++ /dev/null
@@ -1,2 +0,0 @@
-cls
-Invoke-Expression "& $(Join-Path $PSScriptRoot 'singleheader.ci.ps1') $args"
diff --git a/singleheader/meson.build b/singleheader/meson.build
deleted file mode 100644
index 828f1ae..0000000
--- a/singleheader/meson.build
+++ /dev/null
@@ -1,18 +0,0 @@
-project( 'gencpp_singleheader', 'c', 'cpp', default_options : ['buildtype=debug'] )
-
-includes = include_directories(
-[
-'../project',
-])
-
-sources = [ 'gen.singleheader.cpp' ]
-
-if get_option('buildtype').startswith('debug')
-
- add_project_arguments('-DBuild_Debug', language : ['c', 'cpp'])
-
-endif
-
-add_project_arguments('-DGEN_TIME', language : ['c', 'cpp'])
-
-executable( 'gencpp_singleheader', sources, include_directories : includes )
diff --git a/singleheader/gen.singleheader.cpp b/singleheader/singleheader.cpp
similarity index 100%
rename from singleheader/gen.singleheader.cpp
rename to singleheader/singleheader.cpp