did some reorganization, build script changes

Moved header and source to code

Changed all build scripts to just be powershell (preferred)
Added clang format (but forgot that you cannot format zpl because it hangs clang format)

Code changes:
* Removed long names just using short names (there is an issue with the opts_compile...)
* Removed zpl.refactored.h (its generated now when `.\build.ps1 test` is run
* Modified zpl.h to just have the radix sort modification.
This commit is contained in:
Edward R. Gonzalez 2023-03-13 20:17:12 -04:00
parent 9129b5a9fc
commit aec095a9f0
18 changed files with 326 additions and 18431 deletions

3
.gitignore vendored
View File

@ -1,2 +1,5 @@
.idea .idea
build/* build/*
zpl.refactored.h

10
.vscode/launch.json vendored
View File

@ -10,15 +10,15 @@
"request": "launch", "request": "launch",
"program": "${workspaceFolder}/build/refactor.exe", "program": "${workspaceFolder}/build/refactor.exe",
"args": [ "args": [
"-source=./thirdparty/zpl.h", "-src=./thirdparty/zpl.h",
"-destination=./Test/zpl.refactored.h", "-dst=./Test/zpl.refactored.h",
"-specification=./Test/zpl.h.refactor" "-spec=./Test/zpl.h.refactor"
], ],
"stopAtEntry": false, "stopAtEntry": false,
"cwd": "${workspaceRoot}", "cwd": "${workspaceRoot}",
"environment": [], "environment": [],
"console": "externalTerminal" "console": "integratedTerminal"
} }
{ {
"name": "Refactor refactor.c", "name": "Refactor refactor.c",
@ -34,7 +34,7 @@
"stopAtEntry": false, "stopAtEntry": false,
"cwd": "${workspaceRoot}", "cwd": "${workspaceRoot}",
"environment": [], "environment": [],
"console": "externalTerminal" "console": "integratedTerminal"
} }
] ]
} }

View File

@ -4,9 +4,9 @@ A code identifier refactoring app. Intended for c/c++ like identifiers.
Parameters : Parameters :
* `-source`, `-src` : Source file to refactor * `-src` : Source file to refactor
* `-destination`, `-dst` : Destination file after the refactor (omit to use the same as source) * `-dst` : Destination file after the refactor (omit to use the same as source)
* `-specification`, `-spec` : Specification containing rules to use for the refactor. * `-spec` : Specification containing rules to use for the refactor.
Syntax : Syntax :
@ -20,7 +20,7 @@ Syntax :
TODO: TODO:
* Possibly come up with a better name. * Possibly come up with a better name.
* Cleanup memory usage (it hogs quite a bit or what it does..) * Cleanup memory usage (it hogs quite a bit for what it does..)
* Split lines of file and refactor it that way instead (better debug, problably negligable performance loss, worst case can have both depending on build type) * Split lines of file and refactor it that way instead (better debug, problably negligable performance loss, worst case can have both depending on build type)
* Accept multiple files at once `-files`

94
Test/.clang-format Normal file
View File

@ -0,0 +1,94 @@
# Format Style Options - Created with Clang Power Tools
---
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: AcrossComments
AlignConsecutiveBitFields: AcrossComments
AlignConsecutiveDeclarations: AcrossComments
AlignConsecutiveMacros: AcrossComments
AlignEscapedNewlines: Right
AlignOperands: DontAlign
AlignTrailingComments: false
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortLambdasOnASingleLine: None
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: true
BitFieldColonSpacing: Both
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BeforeLambdaBody: false
BeforeWhile: false
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Allman
BreakBeforeInheritanceComma: true
BreakInheritanceList: BeforeColon
BreakBeforeConceptDeclarations: true
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
ColumnLimit: 180
CompactNamespaces: true
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth : 4
ContinuationIndentWidth: 4
DeriveLineEnding: true
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
IncludeBlocks: Preserve
IndentCaseBlocks: true
IndentCaseLabels: true
IndentExternBlock: Indent
IndentGotoLabels: false
IndentPPDirectives: None
IndentRequires: false
IndentWidth: 4
IndentWrappedFunctionNames: false
Language: Cpp
NamespaceIndentation: All
PointerAlignment: Left
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: true
SpaceAfterTemplateKeyword: true
SpaceAroundPointerQualifiers: After
SpaceBeforeCaseColon: true
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: true
SpaceInEmptyParentheses: false
SpacesInAngles: true
SpacesInCStyleCastParentheses: false
SpacesInConditionalStatement: true
SpacesInParentheses: true
SpacesInSquareBrackets: true
Standard: c++17
TabWidth: 4
UseTab: ForIndentation
...

View File

@ -1,4 +1,3 @@
project( 'refactor', 'c', 'cpp', default_options : ['buildtype=debug'] ) project( 'refactor', 'c', 'cpp', default_options : ['buildtype=debug'] )
# add_global_arguments('-E', language : 'cpp') # add_global_arguments('-E', language : 'cpp')
@ -10,4 +9,3 @@ if get_option('buildtype').startswith('debug')
endif endif
executable( 'refactor', 'refactor.refactored.cpp' ) executable( 'refactor', 'refactor.refactored.cpp' )

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +0,0 @@
@echo off
if not exist build\nul (
meson setup build
)
echo:
ninja -C build

View File

@ -1,5 +0,0 @@
@echo off
if exist build\nul (
@RD /S /Q "build"
)

View File

@ -1,15 +0,0 @@
project( 'refactor', 'c', 'cpp', default_options : ['buildtype=debug'] )
include_thirdparty = include_directories( '../thirdparty' )
# add_global_arguments('-E', language : 'cpp')
if get_option('buildtype').startswith('debug')
add_project_arguments('-DBuild_Debug', language : 'cpp')
endif
executable( 'refactor', 'refactor.cpp', include_directories : include_thirdparty )

View File

@ -39,7 +39,6 @@
// # define ZPL_MODULE_THREADING // # define ZPL_MODULE_THREADING
// # define ZPL_MODULE_JOBS // # define ZPL_MODULE_JOBS
// # define ZPL_MODULE_PARSER // # define ZPL_MODULE_PARSER
// extern "C" {
#include "zpl.h" #include "zpl.h"
// } // }

View File

@ -699,9 +699,9 @@ void parse_options( int num, char** arguments )
{ {
zpl_opts opts; zpl_opts opts;
zpl_opts_init( & opts, g_allocator, "refactor"); zpl_opts_init( & opts, g_allocator, "refactor");
zpl_opts_add( & opts, "source" , "src" , "File to refactor" , ZPL_OPTS_STRING); zpl_opts_add( & opts, "src" , "src" , "File to refactor" , ZPL_OPTS_STRING);
zpl_opts_add( & opts, "destination" , "dst" , "File post refactor" , ZPL_OPTS_STRING); zpl_opts_add( & opts, "dst" , "dst" , "File post refactor" , ZPL_OPTS_STRING);
zpl_opts_add( & opts, "specification", "spec", "Specification for refactoring", ZPL_OPTS_STRING); zpl_opts_add( & opts, "spec", "spec", "Specification for refactoring", ZPL_OPTS_STRING);
if (zpl_opts_compile( & opts, num, arguments)) if (zpl_opts_compile( & opts, num, arguments))
{ {
@ -759,6 +759,9 @@ int main( int num, char** arguments)
refactor(); refactor();
log_fmt("\n");
zpl_printf("Refacotred: %s using %s\n", File::Source, Spec::File);
Spec:: cleanup(); Spec:: cleanup();
File:: cleanup(); File:: cleanup();
Memory::cleanup(); Memory::cleanup();

87
scripts/build.ps1 Normal file
View File

@ -0,0 +1,87 @@
cls
[string] $type = $null
[string] $test = $false
foreach ( $arg in $args )
{
if ( $arg -eq "test" )
{
$test = $true
}
else
{
$type = $arg
}
}
#region Regular Build
write-host "Building project`n"
$path_root = git rev-parse --show-toplevel
$path_build = Join-Path $path_root build
$path_scripts = Join-Path $path_root scripts
if ( -not( Test-Path $path_build ) )
{
$args_meson = @()
$args_meson += "setup"
$args_meson += $path_build
Start-Process meson $args_meson -NoNewWindow -Wait -WorkingDirectory $path_scripts
}
if ( $type )
{
$args_meson = @()
$args_meson += "configure"
$args_meson += $path_build
$args_meson += "--buildtype $($type)"
Start-Process meson $args_meson -NoNewWindow -Wait -WorkingDirectory $path_scripts
}
#endregion Regular Build
#region Test Build
write-host "`n`nBuilding Test`n"
if ( -not( Test-Path $path_build ) )
{
return;
}
$args_ninja = @()
$args_ninja += "-C"
$args_ninja += $path_build
Start-Process ninja $args_ninja -Wait -NoNewWindow -WorkingDirectory $path_root
# Refactor thirdparty libraries
& .\refactor_and_format.ps1
if ( $test -eq $false )
{
return;
}
$path_test = Join-Path $path_root test
$path_test_build = Join-Path $path_test build
if ( -not( Test-Path $path_test_build ) )
{
$args_meson = @()
$args_meson += "setup"
$args_meson += $path_test_build
Start-Process meson $args_meson -NoNewWindow -Wait -WorkingDirectory $path_scripts
}
$args_ninja = @()
$args_ninja += "-C"
$args_ninja += $path_build
Start-Process ninja $args_ninja -Wait -NoNewWindow -WorkingDirectory $path_test
#endregion Test Build

14
scripts/clean.ps1 Normal file
View File

@ -0,0 +1,14 @@
$path_root = git rev-parse --show-toplevel
$path_build = Join-Path $path_root build
$path_test = Join-Path $path_root test
$path_test_build = Join-Path $path_test build
if ( Test-Path $path_build )
{
Remove-Item $path_build -Recurse
}
if ( Test-Path $path_test_build )
{
Remove-Item $path_test_build -Recurse
}

12
scripts/get_sources.ps1 Normal file
View File

@ -0,0 +1,12 @@
[string[]] $include = '*.c', '*.cc', '*.cpp'
# [stirng[]] $exclude =
$path_root = git rev-parse --show-toplevel
$path_proj = Join-Path $path_root project
$files = Get-ChildItem -Recurse -Path $path_proj -Include $include -Exclude $exclude
$sources = $files | Select-Object -ExpandProperty FullName | Resolve-Path -Relative
$sources = $sources.Replace( '\', '/' )
return $sources

19
scripts/meson.build Normal file
View File

@ -0,0 +1,19 @@
project( 'refactor', 'c', 'cpp', default_options : ['buildtype=debug'] )
# add_global_arguments('-E', language : 'cpp')
includes = include_directories(
[ '../project'
, '../thirdparty'
])
get_sources = files('./get_sources.ps1')
sources = files(run_command('powershell', get_sources, check: true).stdout().strip().split('\n'))
if get_option('buildtype').startswith('debug')
add_project_arguments('-DBuild_Debug', language : ['c', 'cpp'])
endif
executable( 'refactor', sources, include_directories : includes )

View File

@ -0,0 +1,63 @@
[string[]] $include = '*.h', '*.hh', '*.hpp', '*.c', '*.cc', '*.cpp'
[string[]] $exclude = '*.g.*', '*.refactor', 'bloat.refactored.hpp', 'refactor.refactored.cpp'
$path_root = git rev-parse --show-toplevel
$path_build = Join-Path $path_root build
$path_test = Join-Path $path_root test
$path_thirdparty = Join-Path $path_root thirdparty
$file_spec = Join-Path $path_test zpl.refactor
$refactor = Join-Path $path_build refactor.exe
# Gather the files to be formatted.
$targetFiles = @(Get-ChildItem -Recurse -Path $path_thirdparty -Include $include -Exclude $exclude | Select-Object -ExpandProperty FullName)
write-host "Beginning refactor...`n"
$refactors = @(@())
foreach ( $file in $targetFiles )
{
$destination = Join-Path $path_test (Split-Path $file -leaf)
$destination = $destination.Replace( '.h', '.refactored.h' )
$refactorParams = @(
"-src=$($file)",
"-dst=$($destination)"
"-spec=$($file_spec)"
)
$refactors += (Start-Process $refactor $refactorParams -NoNewWindow -PassThru)
}
foreach ( $process in $refactors )
{
if ( $process )
{
$process.WaitForExit()
}
}
Write-Host "`nRefactoring complete`n`n"
# Can't format zpl library... (It hangs clang format)
if ( $false )
{
Write-Host "Beginning format...`n"
# Format the files.
$formatParams = @(
'-i' # In-place
'-style=file' # Search for a .clang-format file in the parent directory of the source file.
'-verbose'
)
$targetFiles = @(Get-ChildItem -Recurse -Path $path_test -Include $include -Exclude $exclude | Select-Object -ExpandProperty FullName)
clang-format $formatParams $targetFiles
Write-Host "`nFormatting complete"
}

34
thirdparty/zpl.h vendored
View File

@ -6052,12 +6052,12 @@ License:
// NOTE: the count of temp == count of items // NOTE: the count of temp == count of items
#define zpl_radix_sort(Type) zpl_radix_sort_##Type #define zpl_radix_sort(Type) zpl_radix_sort_##Type
#define ZPL_RADIX_SORT_PROC(Type) void zpl_radix_sort(Type)(zpl_##Type * items, zpl_##Type * temp, zpl_isize count) #define ZPL_RADIX_SORT_PROC(Type) void zpl_radix_sort(Type)(Type * items, Type * temp, zpl_isize count)
ZPL_DEF ZPL_RADIX_SORT_PROC(u8); ZPL_DEF ZPL_RADIX_SORT_PROC(zpl_u8);
ZPL_DEF ZPL_RADIX_SORT_PROC(u16); ZPL_DEF ZPL_RADIX_SORT_PROC(zpl_u16);
ZPL_DEF ZPL_RADIX_SORT_PROC(u32); ZPL_DEF ZPL_RADIX_SORT_PROC(zpl_u32);
ZPL_DEF ZPL_RADIX_SORT_PROC(u64); ZPL_DEF ZPL_RADIX_SORT_PROC(zpl_u64);
//! Performs binary search on an array. //! Performs binary search on an array.
@ -12063,16 +12063,16 @@ License:
#define ZPL_RADIX_SORT_PROC_GEN(Type) \ #define ZPL_RADIX_SORT_PROC_GEN(Type) \
ZPL_RADIX_SORT_PROC(Type) { \ ZPL_RADIX_SORT_PROC(Type) { \
zpl_##Type *source = items; \ Type *source = items; \
zpl_##Type *dest = temp; \ Type *dest = temp; \
zpl_isize byte_index, i, byte_max = 8 * zpl_size_of(zpl_##Type); \ zpl_isize byte_index, i, byte_max = 8 * zpl_size_of(Type); \
for (byte_index = 0; byte_index < byte_max; byte_index += 8) { \ for (byte_index = 0; byte_index < byte_max; byte_index += 8) { \
zpl_isize offsets[256] = { 0 }; \ zpl_isize offsets[256] = { 0 }; \
zpl_isize total = 0; \ zpl_isize total = 0; \
/* NOTE: First pass - count how many of each key */ \ /* NOTE: First pass - count how many of each key */ \
for (i = 0; i < count; i++) { \ for (i = 0; i < count; i++) { \
zpl_##Type radix_value = source[i]; \ Type radix_value = source[i]; \
zpl_##Type radix_piece = (radix_value >> byte_index) & 0xff; \ Type radix_piece = (radix_value >> byte_index) & 0xff; \
offsets[radix_piece]++; \ offsets[radix_piece]++; \
} \ } \
/* NOTE: Change counts to offsets */ \ /* NOTE: Change counts to offsets */ \
@ -12083,18 +12083,18 @@ License:
} \ } \
/* NOTE: Second pass - place elements into the right location */ \ /* NOTE: Second pass - place elements into the right location */ \
for (i = 0; i < count; i++) { \ for (i = 0; i < count; i++) { \
zpl_##Type radix_value = source[i]; \ Type radix_value = source[i]; \
zpl_##Type radix_piece = (radix_value >> byte_index) & 0xff; \ Type radix_piece = (radix_value >> byte_index) & 0xff; \
dest[offsets[radix_piece]++] = source[i]; \ dest[offsets[radix_piece]++] = source[i]; \
} \ } \
zpl_swap(zpl_##Type *, source, dest); \ zpl_swap(Type *, source, dest); \
} \ } \
} }
ZPL_RADIX_SORT_PROC_GEN(u8); ZPL_RADIX_SORT_PROC_GEN(zpl_u8);
ZPL_RADIX_SORT_PROC_GEN(u16); ZPL_RADIX_SORT_PROC_GEN(zpl_u16);
ZPL_RADIX_SORT_PROC_GEN(u32); ZPL_RADIX_SORT_PROC_GEN(zpl_u32);
ZPL_RADIX_SORT_PROC_GEN(u64); ZPL_RADIX_SORT_PROC_GEN(zpl_u64);
void zpl_shuffle(void *base, zpl_isize count, zpl_isize size) { void zpl_shuffle(void *base, zpl_isize count, zpl_isize size) {
zpl_u8 *a; zpl_u8 *a;