Improved build system
Added new entries to .gitignore Moved away from source directory as central spot for all source code
This commit is contained in:
31
CoreLib/Makefile
Normal file
31
CoreLib/Makefile
Normal file
@ -0,0 +1,31 @@
|
||||
CPP = ${HOME}/opt/cross/bin/i686-elf-g++
|
||||
CFLAGS = -ffreestanding -Og -ggdb -Wall -Wextra
|
||||
|
||||
BUILD_DIR = ../build/CoreLib
|
||||
OBJ_FOLDER = ../bin/CoreLib
|
||||
OUTPUTFILE = $(BUILD_DIR)/libCoreLib.a
|
||||
|
||||
OFILES = $(OBJ_FOLDER)/memory.o $(OBJ_FOLDER)/path.o $(OBJ_FOLDER)/stack.o $(OBJ_FOLDER)/string.o $(OBJ_FOLDER)/stringview.o
|
||||
|
||||
.phony: all
|
||||
all: $(OUTPUTFILE)
|
||||
cp *.h $(BUILD_DIR)/include/CoreLib
|
||||
|
||||
$(OUTPUTFILE): $(OFILES)
|
||||
ar -rc $(OUTPUTFILE) $(OFILES)
|
||||
|
||||
$(OBJ_FOLDER)/memory.o: Memory.cpp
|
||||
$(CPP) -c Memory.cpp -o $(OBJ_FOLDER)/memory.o $(CFLAGS)
|
||||
|
||||
$(OBJ_FOLDER)/path.o: Path.cpp
|
||||
$(CPP) -c Path.cpp -o $(OBJ_FOLDER)/path.o $(CFLAGS)
|
||||
|
||||
$(OBJ_FOLDER)/stack.o: Stack.cpp
|
||||
$(CPP) -c Stack.cpp -o $(OBJ_FOLDER)/stack.o $(CFLAGS)
|
||||
|
||||
$(OBJ_FOLDER)/string.o: String.cpp
|
||||
$(CPP) -c String.cpp -o $(OBJ_FOLDER)/string.o $(CFLAGS)
|
||||
|
||||
$(OBJ_FOLDER)/stringview.o: StringView.cpp
|
||||
$(CPP) -c StringView.cpp -o $(OBJ_FOLDER)/stringview.o $(CFLAGS)
|
||||
|
58
CoreLib/Memory.cpp
Normal file
58
CoreLib/Memory.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
//
|
||||
// Created by nigel on 19/02/23.
|
||||
//
|
||||
#include "Memory.h"
|
||||
|
||||
void* memset (void* ptr, int value, size_t num)
|
||||
{
|
||||
for( int i = 0; i < num; i++ )
|
||||
{
|
||||
unsigned char* data = (unsigned char*)ptr+ i;
|
||||
*data = (unsigned char)value;
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
int memcmp( const void* ptr1, const void* ptr2, size_t num)
|
||||
{
|
||||
const unsigned char * cs = (const unsigned char*) ptr1;
|
||||
const unsigned char * ct = (const unsigned char*) ptr2;
|
||||
|
||||
|
||||
for (int i = 0 ; i < num ; i++, cs++, ct++ ){
|
||||
if( *cs < *ct){
|
||||
return -1;
|
||||
} else if( *cs > *ct){
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
size_t strlen(const char* str) {
|
||||
size_t len = 0;
|
||||
while(str[len]){
|
||||
len++;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
int strncmp ( const char* str1, const char* str2, size_t num ){
|
||||
for( int i = 0; i < num ; i++){
|
||||
|
||||
if( str1[i] < str2[i]){
|
||||
return -1;
|
||||
}
|
||||
|
||||
if( str1[i] > str2[i] ){
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
12
CoreLib/Memory.h
Normal file
12
CoreLib/Memory.h
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
void* memset (void* ptr, int value, size_t num);
|
||||
|
||||
int memcmp( const void* ptr1, const void* ptr2, size_t num);
|
||||
|
||||
size_t strlen(const char* str);
|
||||
|
||||
int strncmp ( const char* str1, const char* str2, size_t num );
|
24
CoreLib/Path.cpp
Normal file
24
CoreLib/Path.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
//
|
||||
// Created by nigel on 19/02/23.
|
||||
//
|
||||
#include "Path.h"
|
||||
|
||||
Path::Path(String path)
|
||||
: path(path)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
StringView Path::getbasename()
|
||||
{
|
||||
unsigned int path_length = path.length();
|
||||
int i = path_length;
|
||||
while (path[i] != '/')
|
||||
i--;
|
||||
|
||||
return {path,static_cast<unsigned int>(i +1), path_length};
|
||||
}
|
||||
|
||||
char* Path::str() {
|
||||
return path.str();
|
||||
}
|
22
CoreLib/Path.h
Normal file
22
CoreLib/Path.h
Normal file
@ -0,0 +1,22 @@
|
||||
//
|
||||
// Created by nigel on 19/02/23.
|
||||
//
|
||||
#pragma once
|
||||
#include <stddef.h>
|
||||
#include "StringView.h"
|
||||
|
||||
|
||||
class Path{
|
||||
public:
|
||||
explicit Path(String path);
|
||||
|
||||
StringView getbasename();
|
||||
|
||||
char* str();
|
||||
|
||||
private:
|
||||
String path;
|
||||
|
||||
};
|
||||
|
||||
|
3
CoreLib/Stack.cpp
Normal file
3
CoreLib/Stack.cpp
Normal file
@ -0,0 +1,3 @@
|
||||
//
|
||||
// Created by nigel on 19/02/23.
|
||||
//
|
73
CoreLib/Stack.h
Normal file
73
CoreLib/Stack.h
Normal file
@ -0,0 +1,73 @@
|
||||
#pragma once
|
||||
#include "../kernel/memory/KernelHeap.h"
|
||||
#include <stdint.h>
|
||||
|
||||
template <typename T>
|
||||
class Stack {
|
||||
public:
|
||||
inline Stack() {
|
||||
elements = (T[MAX_STACK_SIZE]) malloc(MAX_STACK_SIZE * sizeof(T));
|
||||
num = 0;
|
||||
|
||||
}
|
||||
|
||||
inline void Push(T element){
|
||||
num++;
|
||||
if(num > MAX_STACK_SIZE)
|
||||
grow();
|
||||
|
||||
element[num] = element;
|
||||
}
|
||||
|
||||
|
||||
inline T Pop()
|
||||
{
|
||||
T temp = elements[num];
|
||||
num --;
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
inline bool isEmpty()
|
||||
{
|
||||
return num == 0;
|
||||
}
|
||||
|
||||
inline bool isFull()
|
||||
{
|
||||
return num == MAX_STACK_SIZE;
|
||||
}
|
||||
|
||||
|
||||
inline int count()
|
||||
{
|
||||
return num;
|
||||
}
|
||||
|
||||
inline ~Stack()
|
||||
{
|
||||
free(elements);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
unsigned int MAX_STACK_SIZE;
|
||||
T[MAX_STACK_SIZE] elements;
|
||||
unsigned int num;
|
||||
|
||||
inline void grow (){
|
||||
MAX_STACK_SIZE = MAX_STACK_SIZE + (int)(MAX_STACK_SIZE / 4);
|
||||
T[] new_elements =(T[MAX_STACK_SIZE]) malloc(MAX_STACK_SIZE * sizeof(T));
|
||||
|
||||
for ( int i = 0; i < num ; i++){
|
||||
new_elements[i] = elements[i];
|
||||
}
|
||||
free(elements);
|
||||
elements = new_elements;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
39
CoreLib/String.cpp
Normal file
39
CoreLib/String.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
#include "String.h"
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
String::String(char* characters)
|
||||
: chars(characters)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
char* String::str(){
|
||||
return chars;
|
||||
}
|
||||
|
||||
unsigned int String::length ()
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
while ( chars[i] != '\0'){
|
||||
i++;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
// Returns a null character if size exceeds limits
|
||||
char String::operator[] (size_t idx)
|
||||
{
|
||||
if( idx > this->length())
|
||||
return '\0';
|
||||
|
||||
return chars[idx];
|
||||
}
|
||||
|
||||
const char String::operator[](size_t idx) const {
|
||||
return (const char) chars[idx];
|
||||
}
|
||||
|
18
CoreLib/String.h
Normal file
18
CoreLib/String.h
Normal file
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include <stddef.h>
|
||||
|
||||
class String {
|
||||
public:
|
||||
String(char* characters);
|
||||
String(String&) = default;
|
||||
unsigned int length();
|
||||
|
||||
char* str ();
|
||||
char operator[](size_t index) ;
|
||||
const char operator[](size_t idx) const;
|
||||
|
||||
protected:
|
||||
char* chars;
|
||||
|
||||
|
||||
};
|
14
CoreLib/StringView.cpp
Normal file
14
CoreLib/StringView.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
//
|
||||
// Created by nigel on 19/02/23.
|
||||
//
|
||||
#include "StringView.h"
|
||||
|
||||
StringView::StringView(String string, unsigned int start, unsigned int end)
|
||||
: String(string), begin(start), end(end)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
char* StringView::str(){
|
||||
//TODO: Not implemented
|
||||
}
|
14
CoreLib/StringView.h
Normal file
14
CoreLib/StringView.h
Normal file
@ -0,0 +1,14 @@
|
||||
//
|
||||
// Created by nigel on 19/02/23.
|
||||
//
|
||||
#pragma once
|
||||
#include "String.h"
|
||||
|
||||
class StringView : String {
|
||||
public:
|
||||
StringView(String string, unsigned int start, unsigned int end );
|
||||
char* str ();
|
||||
private:
|
||||
unsigned int begin;
|
||||
unsigned int end;
|
||||
};
|
Reference in New Issue
Block a user