This commit is contained in:
parent
c8302a4fef
commit
6de7753b4c
@ -8,6 +8,7 @@ set(FREESTANDING_SOURCES
|
|||||||
src/SystemError.cpp
|
src/SystemError.cpp
|
||||||
src/Bitmap.cpp
|
src/Bitmap.cpp
|
||||||
src/Stack.cpp
|
src/Stack.cpp
|
||||||
|
src/Alloc.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
@ -28,24 +29,24 @@ target_compile_options(luna-freestanding PRIVATE -nostdlib -mcmodel=kernel)
|
|||||||
target_include_directories(luna-freestanding PUBLIC include/)
|
target_include_directories(luna-freestanding PUBLIC include/)
|
||||||
set_target_properties(luna-freestanding PROPERTIES CXX_STANDARD 20)
|
set_target_properties(luna-freestanding PROPERTIES CXX_STANDARD 20)
|
||||||
|
|
||||||
add_library(luna ${SOURCES})
|
#add_library(luna ${SOURCES})
|
||||||
target_compile_options(luna PRIVATE -Wall -Wextra -Werror -Wvla)
|
#target_compile_options(luna PRIVATE -Wall -Wextra -Werror -Wvla)
|
||||||
target_compile_options(luna PRIVATE -Wdisabled-optimization -Wformat=2 -Winit-self)
|
#target_compile_options(luna PRIVATE -Wdisabled-optimization -Wformat=2 -Winit-self)
|
||||||
target_compile_options(luna PRIVATE -Wmissing-include-dirs -Wswitch-default -Wcast-qual -Wundef)
|
#target_compile_options(luna PRIVATE -Wmissing-include-dirs -Wswitch-default -Wcast-qual -Wundef)
|
||||||
target_compile_options(luna PRIVATE -Wcast-align -Wwrite-strings -Wlogical-op -Wredundant-decls -Wshadow -Wconversion)
|
#target_compile_options(luna PRIVATE -Wcast-align -Wwrite-strings -Wlogical-op -Wredundant-decls -Wshadow -Wconversion)
|
||||||
target_compile_options(luna PRIVATE -fno-asynchronous-unwind-tables -fno-omit-frame-pointer)
|
#target_compile_options(luna PRIVATE -fno-asynchronous-unwind-tables -fno-omit-frame-pointer)
|
||||||
target_include_directories(luna PUBLIC include/)
|
#target_include_directories(luna PUBLIC include/)
|
||||||
set_target_properties(luna PROPERTIES CXX_STANDARD 20)
|
#set_target_properties(luna PROPERTIES CXX_STANDARD 20)
|
||||||
|
|
||||||
if("${ARCH}" MATCHES "x86_64")
|
if("${ARCH}" MATCHES "x86_64")
|
||||||
target_compile_options(luna-freestanding PRIVATE -mno-red-zone)
|
target_compile_options(luna-freestanding PRIVATE -mno-red-zone)
|
||||||
target_compile_options(luna-freestanding PRIVATE -mno-80387 -mno-mmx -mno-sse -mno-sse2)
|
target_compile_options(luna-freestanding PRIVATE -mno-80387 -mno-mmx -mno-sse -mno-sse2)
|
||||||
target_compile_definitions(luna-freestanding PUBLIC ARCH_X86_64)
|
target_compile_definitions(luna-freestanding PUBLIC ARCH_X86_64)
|
||||||
target_compile_definitions(luna PUBLIC ARCH_X86_64)
|
#target_compile_definitions(luna PUBLIC ARCH_X86_64)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(LUNA_DEBUG_SYMBOLS)
|
if(LUNA_DEBUG_SYMBOLS)
|
||||||
message(STATUS "Building Luna with debug symbols")
|
message(STATUS "Building Luna with debug symbols")
|
||||||
target_compile_options(luna PRIVATE -ggdb)
|
#target_compile_options(luna PRIVATE -ggdb)
|
||||||
target_compile_options(luna-freestanding PRIVATE -ggdb)
|
target_compile_options(luna-freestanding PRIVATE -ggdb)
|
||||||
endif()
|
endif()
|
@ -1,6 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <luna/Result.h>
|
#include <luna/Result.h>
|
||||||
|
|
||||||
|
[[nodiscard]] void* raw_malloc(usize);
|
||||||
|
void raw_free(void*);
|
||||||
|
|
||||||
template <typename T, class... Args> [[nodiscard]] Result<T*> make(Args... args)
|
template <typename T, class... Args> [[nodiscard]] Result<T*> make(Args... args)
|
||||||
{
|
{
|
||||||
T* const result = new T(args...);
|
T* const result = new T(args...);
|
||||||
|
25
luna/src/Alloc.cpp
Normal file
25
luna/src/Alloc.cpp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#include <luna/Alloc.h>
|
||||||
|
|
||||||
|
#ifndef USE_FREESTANDING
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
[[nodiscard]] void* raw_malloc(usize size)
|
||||||
|
{
|
||||||
|
#ifdef USE_FREESTANDING
|
||||||
|
char* const rc = new char[size];
|
||||||
|
return (void*)rc;
|
||||||
|
#else
|
||||||
|
return malloc(size);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void raw_free(void* ptr)
|
||||||
|
{
|
||||||
|
#ifdef USE_FREESTANDING
|
||||||
|
char* const arr = (char*)ptr;
|
||||||
|
delete[] arr;
|
||||||
|
#else
|
||||||
|
return free(ptr);
|
||||||
|
#endif
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user