Moved auxiliary functions to a new module

This commit is contained in:
Eric-Paul Ickhorn 2023-11-29 19:17:00 +01:00
parent 5b4c28a350
commit dd5f43fd7f
16 changed files with 170 additions and 22 deletions

View File

@ -1,6 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
INCLUDE_STATEMENTS="-I core-parser/inc/ -I core-parser/exports/"
INVOCATION_PATH=`pwd` INVOCATION_PATH=`pwd`
function build_checks() { function build_checks() {
@ -20,15 +19,36 @@ function build_checks() {
done done
} }
function create_archive() { function compile_utility() {
ar -rvs .build/libparcel.a .build/objects/*.o
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/ echo "======== COMPILING CORE PARSER LIBRARY ========"
rm .build/libparcel.a
mkdir -p .build/objects 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/") for source_file in $(find "core-parser/src/")
do do
if [[ ! -f $source_file ]] then if [[ ! -f $source_file ]] then
@ -37,26 +57,47 @@ function compile_sources() {
# Cut out the prefix (core-parser/src/) # Cut out the prefix (core-parser/src/)
BASENAME=`echo $source_file | cut -c '17-'` BASENAME=`echo $source_file | cut -c '17-'`
echo "==== COMPILING $source_file ====" echo "---- Compiling '$source_file' ----"
gcc -c $COMPILATION_FLAGS -o .build/objects/$BASENAME.o $source_file $INCLUDE_STATEMENTS 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 done
} }
function build_debug() { function build_debug() {
COMPILATION_FLAGS="-g2 -Wall -Wextra -D__PAC_DEBUG__" COMPILATION_FLAGS="-g2 -Wall -Wextra -D__PAC_DEBUG__"
compile_sources compile_utility
create_archive 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() { function build_release() {
COMPILATION_FLAGS="-O2 -Wall -D__PAC_RELEASE__" COMPILATION_FLAGS="-O2 -Wall -D__PAC_RELEASE__"
compile_sources compile_utility
create_archive 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() { function clean() {
rm -R .build/objects/*.o rm -R .build/objects/*.o
rm .build/libparcel.a rm .build/libparcel-parser.a
rm .build/libparcel-utility.a
} }
case $1 in case $1 in

View File

@ -2,7 +2,7 @@
#ifndef PARCEL_AST_H #ifndef PARCEL_AST_H
#define PARCEL_AST_H #define PARCEL_AST_H
#include <utility.h> #include <parcel/utility/utility.h>
#include <logger.h> #include <logger.h>
#include <tokenizer.h> #include <tokenizer.h>

View File

@ -2,7 +2,7 @@
#ifndef PARCEL_LOGGER_H #ifndef PARCEL_LOGGER_H
#define PARCEL_LOGGER_H #define PARCEL_LOGGER_H
#include <utility.h> #include <parcel/utility/utility.h>
typedef enum typedef enum
{ {

View File

@ -2,7 +2,7 @@
#ifndef PARCEL_H #ifndef PARCEL_H
#define PARCEL_H #define PARCEL_H
#include <utility.h> #include <parcel/utility/utility.h>
#include <logger.h> #include <logger.h>
typedef struct pac_grammar pac_grammar_s; typedef struct pac_grammar pac_grammar_s;

View File

@ -2,7 +2,7 @@
#ifndef PARCEL_TOKENIZER_H #ifndef PARCEL_TOKENIZER_H
#define PARCEL_TOKENIZER_H #define PARCEL_TOKENIZER_H
#include <utility.h> #include <parcel/utility/utility.h>
typedef struct pac_token pac_token_s; typedef struct pac_token pac_token_s;
typedef struct pac_tlist pac_tlist_s; // Token List typedef struct pac_tlist pac_tlist_s; // Token List

View File

@ -0,0 +1,25 @@
#ifndef PAC_ALLOCATION_H
#define PAC_ALLOCATION_H
#include <parcel/utility/basic_types.h>
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

View File

@ -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

View File

@ -0,0 +1,11 @@
#ifndef PAC_MEMORY_H
#define PAC_MEMORY_H
#include <parcel/utility/basic_types.h>
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

View File

@ -0,0 +1,14 @@
#ifndef PAC_RUNES_H
#define PAC_RUNES_H
#include <parcel/utility/basic_types.h>
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

View File

@ -0,0 +1,9 @@
#ifndef PAC_STRING_H
#define PAC_STRING_H
#include <parcel/utility/basic_types.h>
usz_t pac_string_length (const char *string);
#endif // PAC_STRING_H

View File

@ -0,0 +1,11 @@
#ifndef PARCEL_UTILITY_H
#define PARCEL_UTILITY_H
#include <parcel/utility/allocation.h>
#include <parcel/utility/basic_types.h>
#include <parcel/utility/runes.h>
#include <parcel/utility/memory.h>
#include <parcel/utility/string.h>
#endif // PARCEL_UTILITY_H

View File

@ -1,6 +1,6 @@
#ifndef TN_UTIL_TYPES_H #ifndef PAC_UTILITY_H
#define TN_UTIL_TYPES_H #define PAC_UTILITY_H
typedef signed char i8_t; typedef signed char i8_t;
typedef signed short i16_t; typedef signed short i16_t;
@ -18,7 +18,7 @@ typedef double f64_t;
typedef u32_t rune_t; typedef u32_t rune_t;
typedef u8_t bool_t; typedef u8_t bool_t;
#ifdef __TN_OLD_PROCESSOR__ #ifdef __PAC_32_BIT__
typedef u32_t usz_t; typedef u32_t usz_t;
typedef i32_t isz_t; typedef i32_t isz_t;
#else #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); void * pac_arena_alloc (pac_arena_s *arena, usz_t length);
#endif // Include Guard (TN_UTIL_TYPES_H) #endif // PAC_UTILITY_H

3
utility/src/string.c Normal file
View File

@ -0,0 +1,3 @@
#include <utility.h>