Compare commits
No commits in common. "dcbd9555d537b79107c352deed3cd3bb2dde5bc0" and "dd80cb179e71f8759ae374bfe7c9a5a439b27958" have entirely different histories.
dcbd9555d5
...
dd80cb179e
|
@ -1,2 +0,0 @@
|
|||
core
|
||||
platform
|
90
build.bash
90
build.bash
|
@ -1,71 +1,34 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Get the absolute repository root path and go there
|
||||
cd $(dirname "$(pwd)/$0")
|
||||
REPOSITORY_FOLDER=$(pwd)
|
||||
|
||||
|
||||
# Configuration Values start here
|
||||
|
||||
PROJECT_NAME="librr"
|
||||
PROJECT_ROOT=`pwd`
|
||||
GCC_ARGUMENTS="-std=c11 -Wall"
|
||||
|
||||
MAIN_OBJECTS_FOLDER="$REPOSITORY_FOLDER/.build/objects"
|
||||
|
||||
# End of configuration values
|
||||
|
||||
|
||||
|
||||
# Constants not meant for configuration
|
||||
|
||||
CONFIG_FILE_INCLUDE_PATHS="build-config/include_paths.txt"
|
||||
MODULE_LIST_PATH="build-config/modules.txt"
|
||||
|
||||
|
||||
|
||||
function get_include_path_configuration {
|
||||
MODULE_NAME=$1
|
||||
|
||||
INCLUDE_CONFIG_PATH="$REPOSITORY_FOLDER/$MODULE_NAME/$CONFIG_FILE_INCLUDE_PATHS"
|
||||
INCLUDE_STATEMENTS="-I $REPOSITORY_FOLDER/$MODULE_NAME/inc-c/ -I $REPOSITORY_FOLDER/$MODULE_NAME/exports/"
|
||||
if [[ ! -f $INCLUDE_CONFIG_PATH ]]
|
||||
then
|
||||
return
|
||||
fi
|
||||
|
||||
for LINE in $(cat $INCLUDE_CONFIG_PATH)
|
||||
do
|
||||
INCLUDE_STATEMENTS="$INCLUDE_STATEMENTS -I $REPOSITORY_FOLDER/$LINE"
|
||||
done
|
||||
}
|
||||
MODULES=(
|
||||
"core"
|
||||
"platform"
|
||||
)
|
||||
|
||||
# Arguments:
|
||||
# 1) Module name / folder name in project root (May not include slashes)
|
||||
function compile_single_module() {
|
||||
MODULE_NAME=$1
|
||||
# 1) Path to the module
|
||||
# 2) Include Statements
|
||||
function compile_folder() {
|
||||
|
||||
ENTRY_WORKING_DIR=$(pwd)
|
||||
printf "\n\n\n"
|
||||
echo "|================> Module Separator <================|"
|
||||
echo "> Name: $MODULE_NAME "
|
||||
echo "> Path: $REPOSITORY_FOLDER/$MODULE_NAME"
|
||||
echo " "
|
||||
get_include_path_configuration $MODULE_NAME
|
||||
|
||||
MODULE_OBJECTS_FOLDER="$MAIN_OBJECTS_FOLDER/$MODULE_NAME"
|
||||
mkdir -p $MODULE_OBJECTS_FOLDER
|
||||
cd $REPOSITORY_FOLDER/$1
|
||||
OBJECTS_FOLDER="$PROJECT_ROOT/.build/objects/$1"
|
||||
mkdir -p $OBJECTS_FOLDER
|
||||
cd $PROJECT_ROOT/$1
|
||||
|
||||
cd src-c/
|
||||
for SOURCE_FILE in $(find . -mindepth 1)
|
||||
for SOURCE_FILE in $(find .)
|
||||
do
|
||||
# Create all subfolders of this module's source folder
|
||||
if [[ -d $SOURCE_FILE ]] then
|
||||
mkdir -p $MODULE_OBJECTS_FOLDER/$SOURCE_FILE
|
||||
continue
|
||||
# Create every folder except of the source root folder (src-c/).
|
||||
if [[ $SOURCE_FILE != "." ]] then
|
||||
if [[ -d $SOURCE_FILE ]] then
|
||||
mkdir $SOURCE_FILE
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
|
||||
# If this is not a regular file, quietly ignore it.
|
||||
|
||||
if [[ ! -f $SOURCE_FILE ]] then
|
||||
continue
|
||||
fi
|
||||
|
@ -73,20 +36,17 @@ function compile_single_module() {
|
|||
# Cut out the ./ at the front of the path
|
||||
SOURCE_FILE=$(echo $SOURCE_FILE | cut -c 3-)
|
||||
|
||||
echo "==> File: $SOURCE_FILE"
|
||||
gcc -c $GCC_ARGUMENTS -o $MODULE_OBJECTS_FOLDER/$SOURCE_FILE.o $SOURCE_FILE $INCLUDE_STATEMENTS
|
||||
echo "==== Building '$SOURCE_FILE' ===="
|
||||
gcc -c $GCC_ARGUMENTS -o $OBJECTS_FOLDER/$SOURCE_FILE.o $SOURCE_FILE $2
|
||||
done
|
||||
|
||||
OBJECT_FILES=$(find $MODULE_OBJECTS_FOLDER -mindepth 1 -type f)
|
||||
ar -rvs $REPOSITORY_FOLDER/.build/$PROJECT_NAME-$MODULE_NAME.a $OBJECT_FILES
|
||||
cd $ENTRY_WORKING_DIR
|
||||
ar -rvs $PROJECT_ROOT/.build/$PROJECT_NAME-$1.a $OBJECTS_FOLDER/*.o
|
||||
cd $PROJECT_ROOT
|
||||
}
|
||||
|
||||
function compile_all_modules() {
|
||||
for MODULE_PATH in $(cat $MODULE_LIST_PATH)
|
||||
do
|
||||
compile_single_module $MODULE_PATH
|
||||
done
|
||||
compile_folder "core" "-I $PROJECT_ROOT/core/exports/"
|
||||
compile_folder "platform" "-I $PROJECT_ROOT/core/exports/ -I $PROJECT_ROOT/platform/exports/"
|
||||
}
|
||||
|
||||
case $1 in
|
||||
|
|
|
@ -4,6 +4,15 @@
|
|||
|
||||
#include <librr/types.h>
|
||||
|
||||
typedef struct rr_arena rr_arena_s;
|
||||
|
||||
struct rr_arena
|
||||
{
|
||||
usz_t capacity;
|
||||
usz_t offset;
|
||||
char *allocation;
|
||||
};
|
||||
|
||||
/// @brief Tests if two memory regions overlap partially or completely.
|
||||
/// @param block1 Block to check for overlapping with block2.
|
||||
// If the address of this block is higher than that of block2, the blocks will be swapped internally.
|
||||
|
@ -11,7 +20,7 @@
|
|||
/// @param block2 The second block to check for overlapping.
|
||||
/// @param length2 The length of the second block.
|
||||
/// @return Whether the two blocks overlap.
|
||||
bool_t rr_mem_overlap(const void *block1, usz_t length1, const void *block2, usz_t length2);
|
||||
bool_t rr_mem_overlap(void *block1, usz_t length1, void *block2, usz_t length2);
|
||||
|
||||
/// @brief Checks if two memory blocks contain the equal data.
|
||||
/// @param block1 Address of the data to be checked for equality with 'block2'
|
||||
|
@ -19,7 +28,7 @@ bool_t rr_mem_overlap(const void *block1, usz_t length1, const void *block2, usz
|
|||
/// this should be the correct data to be checked against.
|
||||
/// @param count How many bytes will be checked.
|
||||
/// @return Whether the two memory regions are equal.
|
||||
bool_t rr_memequ(const void *block1, const void *block2, usz_t count);
|
||||
bool_t rr_memequ(void *block1, void *block2, usz_t count);
|
||||
|
||||
/// @brief Sets all bytes in a memory region all to one byte.
|
||||
/// @param destination Address to the memory region to fill with one byte.
|
||||
|
@ -34,13 +43,19 @@ void rr_memset(void *destination, usz_t count, u8_t value);
|
|||
/// @param sequence Sequence of bytes which will be written to destination.
|
||||
/// @param len_sequence Length of 'sequence'.
|
||||
/// @return The number of attempted or partial repetitions which have been performed.
|
||||
usz_t rr_memrep(void *destination, usz_t num_bytes, const void *sequence, usz_t len_sequence);
|
||||
usz_t rr_memrep(void *destination, usz_t num_bytes, void *sequence, usz_t len_sequence);
|
||||
|
||||
/// @brief Copies a given number of bytes from a source memory region to a destination memory region.
|
||||
/// @attention The source and the destination cannot overlap!
|
||||
/// @param destination Memory region to which to write.
|
||||
/// @param source Memory region from which to read the bytes to write into the destination.
|
||||
/// @param num_bytes Number of bytes to copy from the source to the destination.
|
||||
void rr_memcopy(void *destination, const void *source, usz_t num_bytes);
|
||||
void rr_memcopy(void *destination, void *source, usz_t num_bytes);
|
||||
|
||||
rr_arena_s rr_new_arena(usz_t capacity);
|
||||
void rr_delete_arena(rr_arena_s *arena);
|
||||
|
||||
void * rr_arena_alloc(rr_arena_s *arena, usz_t length);
|
||||
char * rr_arena_clone_string(rr_arena_s *arena, char *string);
|
||||
|
||||
#endif // RR_MEMORY_H
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
#include <librr/memory.h>
|
||||
#include <librr/strutil.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
bool_t rr_mem_overlap(const void *block1, usz_t length1, const void *block2, usz_t length2)
|
||||
bool_t rr_mem_overlap(void *block1, usz_t length1, void *block2, usz_t length2)
|
||||
{
|
||||
// Make block1 always be before block2
|
||||
if(block1 > block2)
|
||||
{
|
||||
const void *block_backup = block2;
|
||||
void *block_backup = block2;
|
||||
usz_t length_backup = length2;
|
||||
block2 = block1;
|
||||
length2 = length1;
|
||||
|
@ -25,10 +27,10 @@ bool_t rr_mem_overlap(const void *block1, usz_t length1, const void *block2, usz
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
bool_t rr_memequ(const void *block1, const void *block2, usz_t count)
|
||||
bool_t rr_memequ(void *block1, void *block2, usz_t count)
|
||||
{
|
||||
const u8_t *block1_8 = block1;
|
||||
const u8_t *block2_8 = block2;
|
||||
u8_t *block1_8 = block1;
|
||||
u8_t *block2_8 = block2;
|
||||
for(usz_t index = 0; index < count; ++index)
|
||||
if(block1_8[index] != block2_8[index]) return FALSE;
|
||||
return TRUE;
|
||||
|
@ -41,22 +43,62 @@ void rr_memset(void *destination, usz_t count, u8_t value)
|
|||
destination_8[index] = value;
|
||||
}
|
||||
|
||||
usz_t rr_memrep(void *destination, usz_t num_bytes, const void *sequence, usz_t len_sequence)
|
||||
usz_t rr_memrep(void *destination, usz_t num_bytes, void *sequence, usz_t len_sequence)
|
||||
{
|
||||
if(rr_mem_overlap(destination, num_bytes, sequence, len_sequence)) return 0;
|
||||
u8_t *destination_8 = destination;
|
||||
const u8_t *sequence_8 = sequence;
|
||||
u8_t *sequence_8 = sequence;
|
||||
for(usz_t index = 0; index < num_bytes; ++index)
|
||||
destination_8[index] = sequence_8[index % len_sequence];
|
||||
return (num_bytes / len_sequence) // How many full repetitions are performed
|
||||
+ ((num_bytes % len_sequence) != 0); // One more if a partial repetiton is done
|
||||
}
|
||||
|
||||
void rr_memcopy(void *destination, const void *source, usz_t num_bytes)
|
||||
void rr_memcopy(void *destination, void *source, usz_t num_bytes)
|
||||
{
|
||||
if(rr_mem_overlap(destination, num_bytes, source, num_bytes)) return;
|
||||
u8_t *destination_8 = destination;
|
||||
const u8_t *source_8 = source;
|
||||
u8_t *source_8 = source;
|
||||
for(usz_t index = 0; index < num_bytes; ++index)
|
||||
destination_8[index] = source_8[index];
|
||||
}
|
||||
|
||||
|
||||
|
||||
rr_arena_s rr_new_arena(usz_t capacity)
|
||||
{
|
||||
rr_arena_s arena;
|
||||
arena.capacity = capacity;
|
||||
arena.offset = 0;
|
||||
arena.allocation = malloc(capacity);
|
||||
return arena;
|
||||
}
|
||||
|
||||
void rr_delete_arena(rr_arena_s *arena)
|
||||
{
|
||||
if(arena->allocation == NULL) return;
|
||||
free(arena->allocation);
|
||||
arena->allocation = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void * rr_arena_alloc(rr_arena_s *arena, usz_t length)
|
||||
{
|
||||
if((arena->offset + length) > arena->capacity)
|
||||
return NULL;
|
||||
|
||||
void *block = &arena->allocation[arena->offset];
|
||||
arena->offset += length;
|
||||
return block;
|
||||
}
|
||||
|
||||
char * rr_arena_clone_string(rr_arena_s *arena, char *string)
|
||||
{
|
||||
usz_t len_string = rr_measure_string(string);
|
||||
char *cloned_string = rr_arena_alloc(arena, len_string+1);
|
||||
rr_memcopy(cloned_string, string, len_string);
|
||||
cloned_string[len_string] = 0x00;
|
||||
|
||||
return cloned_string;
|
||||
}
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
core/exports/
|
|
@ -1,22 +0,0 @@
|
|||
|
||||
#ifndef RR_ARENA_ALLOCATOR_H
|
||||
#define RR_ARENA_ALLOCATOR_H
|
||||
|
||||
#include <librr/types.h>
|
||||
|
||||
typedef struct rr_arena rr_arena_s;
|
||||
|
||||
struct rr_arena
|
||||
{
|
||||
usz_t capacity;
|
||||
usz_t offset;
|
||||
char *allocation;
|
||||
};
|
||||
|
||||
rr_arena_s rr_new_arena(usz_t capacity);
|
||||
void rr_delete_arena(rr_arena_s *arena);
|
||||
|
||||
void * rr_arena_alloc(rr_arena_s *arena, usz_t length);
|
||||
char * rr_arena_clone_string(rr_arena_s *arena, const char *string);
|
||||
|
||||
#endif // RR_ARENA_ALLOCATOR_H
|
|
@ -1,41 +0,0 @@
|
|||
#include <alloc/arena.h>
|
||||
|
||||
rr_arena_s rr_new_arena(usz_t capacity)
|
||||
{
|
||||
rr_arena_s arena;
|
||||
arena.capacity = capacity;
|
||||
arena.offset = 0;
|
||||
arena.allocation = malloc(capacity);
|
||||
return arena;
|
||||
}
|
||||
|
||||
void rr_delete_arena(rr_arena_s *arena)
|
||||
{
|
||||
if(arena->allocation == NULL) return;
|
||||
free(arena->allocation);
|
||||
arena->allocation = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void * rr_arena_alloc(rr_arena_s *arena, usz_t length)
|
||||
{
|
||||
if((arena->offset + length) > arena->capacity)
|
||||
return NULL;
|
||||
|
||||
void *block = &arena->allocation[arena->offset];
|
||||
arena->offset += length;
|
||||
return block;
|
||||
}
|
||||
|
||||
char * rr_arena_clone_string(rr_arena_s *arena, char *string)
|
||||
{
|
||||
usz_t len_string = rr_measure_string(string);
|
||||
char *cloned_string = rr_arena_alloc(arena, len_string+1);
|
||||
if(cloned_string == NULL)
|
||||
return NULL;
|
||||
rr_memcopy(cloned_string, string, len_string);
|
||||
cloned_string[len_string] = 0x00;
|
||||
|
||||
return cloned_string;
|
||||
}
|
Loading…
Reference in New Issue