From dd5f43fd7f6c1e394b42ea49130faa0902a880f1 Mon Sep 17 00:00:00 2001 From: Eric-Paul Ickhorn Date: Wed, 29 Nov 2023 19:17:00 +0100 Subject: [PATCH] Moved auxiliary functions to a new module --- build.bash | 69 +++++++++++++++---- core-parser/inc/ast.h | 2 +- core-parser/inc/logger.h | 2 +- core-parser/inc/parcel.h | 2 +- core-parser/inc/tokenizer.h | 2 +- utility/exports/parcel/utility/allocation.h | 25 +++++++ utility/exports/parcel/utility/basic_types.h | 34 +++++++++ utility/exports/parcel/utility/memory.h | 11 +++ utility/exports/parcel/utility/runes.h | 14 ++++ utility/exports/parcel/utility/string.h | 9 +++ utility/exports/parcel/utility/utility.h | 11 +++ {core-parser => utility}/inc/utility.h | 8 +-- {core-parser => utility}/src/allocator.c | 0 .../src/utility.c => utility/src/memory.c | 0 {core-parser => utility}/src/runes.c | 0 utility/src/string.c | 3 + 16 files changed, 170 insertions(+), 22 deletions(-) create mode 100644 utility/exports/parcel/utility/allocation.h create mode 100644 utility/exports/parcel/utility/basic_types.h create mode 100644 utility/exports/parcel/utility/memory.h create mode 100644 utility/exports/parcel/utility/runes.h create mode 100644 utility/exports/parcel/utility/string.h create mode 100644 utility/exports/parcel/utility/utility.h rename {core-parser => utility}/inc/utility.h (94%) rename {core-parser => utility}/src/allocator.c (100%) rename core-parser/src/utility.c => utility/src/memory.c (100%) rename {core-parser => utility}/src/runes.c (100%) create mode 100644 utility/src/string.c diff --git a/build.bash b/build.bash index 3827170..a02c738 100755 --- a/build.bash +++ b/build.bash @@ -1,6 +1,5 @@ #!/usr/bin/env bash -INCLUDE_STATEMENTS="-I core-parser/inc/ -I core-parser/exports/" INVOCATION_PATH=`pwd` function build_checks() { @@ -20,15 +19,36 @@ function build_checks() { done } -function create_archive() { - ar -rvs .build/libparcel.a .build/objects/*.o +function compile_utility() { + + echo "======== COMPILING UTILITY LIBRARY ========" + + rm -r .build/objects/utility/ + mkdir -p .build/objects/utility/ + for source_file in $(find "utility/src/") + do + if [[ ! -f $source_file ]] then + continue + fi + + # Cut out the prefix (utility/src/) + BASENAME=`echo $source_file | cut -c '13-'` + echo "---- Compiling '$source_file' ----" + + gcc -c $COMPILATION_FLAGS \ + -o .build/objects/utility/$BASENAME.o $source_file \ + \ + -I utility/inc/ -I utility/exports/ + done } -function compile_sources() { +function compile_core_parser() { - rm -r .build/objects/ - rm .build/libparcel.a - mkdir -p .build/objects + echo "======== COMPILING CORE PARSER LIBRARY ========" + + rm -r .build/objects/core-parser + rm .build/libparcel-parser.a + mkdir -p .build/objects/core-parser/ for source_file in $(find "core-parser/src/") do if [[ ! -f $source_file ]] then @@ -37,26 +57,47 @@ function compile_sources() { # Cut out the prefix (core-parser/src/) BASENAME=`echo $source_file | cut -c '17-'` - echo "==== COMPILING $source_file ====" - gcc -c $COMPILATION_FLAGS -o .build/objects/$BASENAME.o $source_file $INCLUDE_STATEMENTS + echo "---- Compiling '$source_file' ----" + gcc -c $COMPILATION_FLAGS \ + -o .build/objects/core-parser/$BASENAME.o $source_file \ + \ + -I core-parser/inc/ -I core-parser/exports/ \ + -I utility/exports/ done } function build_debug() { + COMPILATION_FLAGS="-g2 -Wall -Wextra -D__PAC_DEBUG__" - compile_sources - create_archive + compile_utility + compile_core_parser + + ar -rvs .build/libparcel-parser.a \ + .build/objects/core-parser/*.o + + ar -rvs .build/libparcel-utility.a \ + .build/objects/utility/*.o + } function build_release() { + COMPILATION_FLAGS="-O2 -Wall -D__PAC_RELEASE__" - compile_sources - create_archive + compile_utility + compile_core_parser + + ar -rvs .build/libparcel.a \ + .build/objects/core-parser/*.o \ + + ar -rvs .build/libparcel-utility.a \ + .build/objects/utility/*.o + } function clean() { rm -R .build/objects/*.o - rm .build/libparcel.a + rm .build/libparcel-parser.a + rm .build/libparcel-utility.a } case $1 in diff --git a/core-parser/inc/ast.h b/core-parser/inc/ast.h index 2b9db07..f7af012 100644 --- a/core-parser/inc/ast.h +++ b/core-parser/inc/ast.h @@ -2,7 +2,7 @@ #ifndef PARCEL_AST_H #define PARCEL_AST_H -#include +#include #include #include diff --git a/core-parser/inc/logger.h b/core-parser/inc/logger.h index 0f251d8..7b145af 100644 --- a/core-parser/inc/logger.h +++ b/core-parser/inc/logger.h @@ -2,7 +2,7 @@ #ifndef PARCEL_LOGGER_H #define PARCEL_LOGGER_H -#include +#include typedef enum { diff --git a/core-parser/inc/parcel.h b/core-parser/inc/parcel.h index ea55489..2d9e4e6 100644 --- a/core-parser/inc/parcel.h +++ b/core-parser/inc/parcel.h @@ -2,7 +2,7 @@ #ifndef PARCEL_H #define PARCEL_H -#include +#include #include typedef struct pac_grammar pac_grammar_s; diff --git a/core-parser/inc/tokenizer.h b/core-parser/inc/tokenizer.h index defe28c..9179104 100644 --- a/core-parser/inc/tokenizer.h +++ b/core-parser/inc/tokenizer.h @@ -2,7 +2,7 @@ #ifndef PARCEL_TOKENIZER_H #define PARCEL_TOKENIZER_H -#include +#include typedef struct pac_token pac_token_s; typedef struct pac_tlist pac_tlist_s; // Token List diff --git a/utility/exports/parcel/utility/allocation.h b/utility/exports/parcel/utility/allocation.h new file mode 100644 index 0000000..46cff8a --- /dev/null +++ b/utility/exports/parcel/utility/allocation.h @@ -0,0 +1,25 @@ + +#ifndef PAC_ALLOCATION_H +#define PAC_ALLOCATION_H + +#include + +typedef struct pac_arena pac_arena_s; + +struct pac_arena +{ + usz_t len_allocation; + usz_t offset; + void *allocation; + pac_arena_s *continuation; +}; + +pac_arena_s pac_create_arena (usz_t size); +void pac_delete_arena (pac_arena_s arena); + +pac_arena_s * pac_new_arena (usz_t size); +void pac_free_arena (pac_arena_s *arena); + +void * pac_arena_alloc (pac_arena_s *arena, usz_t length); + +#endif // PAC_ALLOCATION_H diff --git a/utility/exports/parcel/utility/basic_types.h b/utility/exports/parcel/utility/basic_types.h new file mode 100644 index 0000000..410d411 --- /dev/null +++ b/utility/exports/parcel/utility/basic_types.h @@ -0,0 +1,34 @@ + +#ifndef PAC_BASIC_TYPES_H +#define PAC_BASIC_TYPES_H + +typedef signed char i8_t; +typedef signed short i16_t; +typedef signed int i32_t; +typedef signed long i64_t; + +typedef unsigned char u8_t; +typedef unsigned short u16_t; +typedef unsigned int u32_t; +typedef unsigned long u64_t; + +typedef float f32_t; +typedef double f64_t; + +typedef u32_t rune_t; +typedef u8_t bool_t; + +#ifdef __PAC_32_BIT__ +typedef u32_t usz_t; +typedef i32_t isz_t; +#else +typedef u64_t usz_t; +typedef i64_t isz_t; +#endif + +#define NULL ((void *) 0) +#define TRUE ((bool_t) 1) +#define FALSE ((bool_t) 0) + + +#endif // PAC_BASIC_TYPES_H diff --git a/utility/exports/parcel/utility/memory.h b/utility/exports/parcel/utility/memory.h new file mode 100644 index 0000000..0b7e76c --- /dev/null +++ b/utility/exports/parcel/utility/memory.h @@ -0,0 +1,11 @@ + +#ifndef PAC_MEMORY_H +#define PAC_MEMORY_H + +#include + +void pac_memory_copy (void *destination, void *source, usz_t length); +void pac_memory_fill (void *region, usz_t len_region, u8_t byte); +void pac_memory_zero (void *region, usz_t len_region); + +#endif // PAC_MEMORY_H diff --git a/utility/exports/parcel/utility/runes.h b/utility/exports/parcel/utility/runes.h new file mode 100644 index 0000000..26a3ce4 --- /dev/null +++ b/utility/exports/parcel/utility/runes.h @@ -0,0 +1,14 @@ + +#ifndef PAC_RUNES_H +#define PAC_RUNES_H + +#include + +bool_t pac_rune_is_lower_letter (rune_t rune); +bool_t pac_rune_is_upper_letter (rune_t rune); +bool_t pac_rune_is_letter (rune_t rune); +bool_t pac_rune_is_digit (rune_t rune); +bool_t pac_rune_is_blank (rune_t rune); +bool_t pac_rune_is_sign (rune_t rune); + +#endif // PAC_RUNES_H diff --git a/utility/exports/parcel/utility/string.h b/utility/exports/parcel/utility/string.h new file mode 100644 index 0000000..e2953c8 --- /dev/null +++ b/utility/exports/parcel/utility/string.h @@ -0,0 +1,9 @@ + +#ifndef PAC_STRING_H +#define PAC_STRING_H + +#include + +usz_t pac_string_length (const char *string); + +#endif // PAC_STRING_H diff --git a/utility/exports/parcel/utility/utility.h b/utility/exports/parcel/utility/utility.h new file mode 100644 index 0000000..bd40477 --- /dev/null +++ b/utility/exports/parcel/utility/utility.h @@ -0,0 +1,11 @@ + +#ifndef PARCEL_UTILITY_H +#define PARCEL_UTILITY_H + +#include +#include +#include +#include +#include + +#endif // PARCEL_UTILITY_H diff --git a/core-parser/inc/utility.h b/utility/inc/utility.h similarity index 94% rename from core-parser/inc/utility.h rename to utility/inc/utility.h index ccb25fb..13fe1a7 100644 --- a/core-parser/inc/utility.h +++ b/utility/inc/utility.h @@ -1,6 +1,6 @@ -#ifndef TN_UTIL_TYPES_H -#define TN_UTIL_TYPES_H +#ifndef PAC_UTILITY_H +#define PAC_UTILITY_H typedef signed char i8_t; typedef signed short i16_t; @@ -18,7 +18,7 @@ typedef double f64_t; typedef u32_t rune_t; typedef u8_t bool_t; -#ifdef __TN_OLD_PROCESSOR__ +#ifdef __PAC_32_BIT__ typedef u32_t usz_t; typedef i32_t isz_t; #else @@ -68,4 +68,4 @@ pac_arena_s * pac_new_arena (usz_t size); void * pac_arena_alloc (pac_arena_s *arena, usz_t length); -#endif // Include Guard (TN_UTIL_TYPES_H) +#endif // PAC_UTILITY_H diff --git a/core-parser/src/allocator.c b/utility/src/allocator.c similarity index 100% rename from core-parser/src/allocator.c rename to utility/src/allocator.c diff --git a/core-parser/src/utility.c b/utility/src/memory.c similarity index 100% rename from core-parser/src/utility.c rename to utility/src/memory.c diff --git a/core-parser/src/runes.c b/utility/src/runes.c similarity index 100% rename from core-parser/src/runes.c rename to utility/src/runes.c diff --git a/utility/src/string.c b/utility/src/string.c new file mode 100644 index 0000000..c5c2d17 --- /dev/null +++ b/utility/src/string.c @@ -0,0 +1,3 @@ +#include + +