Skip to content

Commit 63dff8b

Browse files
committed
Project Full project re-factor, fix many bugs, compile errors, etc
1 parent 1af847b commit 63dff8b

File tree

91 files changed

+3995
-2670
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+3995
-2670
lines changed

.github/workflows/c-cpp.yml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@ jobs:
1010
mac-build:
1111
runs-on: macos-latest
1212
steps:
13+
- name: Install Dependencies
14+
run: |
15+
brew update --preinstall
16+
brew install llvm ninja cmake lld
17+
echo "/opt/homebrew/opt/llvm/bin" >> $GITHUB_PATH
1318
- uses: actions/checkout@v4
14-
- name: make
15-
run: make
19+
with:
20+
submodules: 'recursive'
21+
- name: Make
22+
run: |
23+
cmake --preset debug
24+
cmake --preset release
1625
17-
linux-build:
18-
runs-on: ubuntu-latest
19-
steps:
20-
- uses: actions/checkout@v4
21-
- name: make
22-
run: make
26+
cd build_debug && ninja
27+
cd ../build_release && ninja

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
compile_commands.json
1818

1919
build/
20-
build-linux/
20+
build_debug/
21+
build_release/
22+
2123
bin/
2224
obj/
2325
tests/

CMakeLists.txt

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.5.0)
1+
cmake_minimum_required(VERSION 3.10.0)
22
project(ktool)
33

44
#Bring the headers into the project
@@ -12,26 +12,41 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
1212
file(GLOB_RECURSE SOURCES "src/*.cpp")
1313

1414
add_executable(ktool ${SOURCES})
15+
set_target_properties (ktool PROPERTIES
16+
CXX_STANDARD 23
17+
CXX_STANDARD_REQUIRED TRUE
18+
CXX_EXTENSIONS TRUE
19+
)
20+
21+
set(CMAKE_CXX_CLANG_TIDY
22+
clang-tidy;
23+
-header-filter=include;
24+
-checks=*;)
25+
1526
target_compile_options(ktool PUBLIC
16-
-Wall -Wextra -pedantic -Wsign-conversion -Wredundant-decls
27+
-Wall -Wextra -stdlib=libc++ -pedantic -Wsign-conversion -Wredundant-decls
1728
-Wstrict-overflow=5 -Wundef -Wnull-dereference -funsigned-char
1829
-fno-exceptions -Wcast-align -Wfloat-equal -Wredundant-decls
1930
-Wstrict-overflow=5 -Wundef -Wnull-dereference -funsigned-char -Wformat=2
2031
-DBUILD_KERNEL -Wno-address-of-packed-member)
2132

22-
set_property(TARGET ktool PROPERTY CXX_STANDARD 20)
23-
set(CMAKE_CXX_CLANG_TIDY
24-
clang-tidy;
25-
-header-filter=include;
26-
-checks=*;)
33+
target_link_options(ktool PUBLIC -stdlib=libc++)
34+
target_link_options(ktool PUBLIC -fuse-ld=lld)
2735

2836
if (NOT CMAKE_BUILD_TYPE)
2937
set(CMAKE_BUILD_TYPE Debug)
3038
endif()
3139

3240
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
3341
set_target_properties(ktool PROPERTIES OUTPUT_NAME "ktool_debug")
34-
target_link_options(ktool PRIVATE "-fsanitize=undefined")
42+
target_compile_options(ktool PRIVATE
43+
"-fsanitize=address" "-fsanitize=undefined")
44+
target_link_options(ktool PRIVATE
45+
"-fsanitize=address" "-fsanitize=undefined")
46+
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
47+
set_target_properties(ktool PROPERTIES OUTPUT_NAME "ktool_release")
48+
target_compile_options(ktool PRIVATE "-O3" "-Wno-unused-parameter" "-Wno-gnu-statement-expression-from-macro-expansion")
49+
target_link_options(ktool PRIVATE "-O3")
3550
endif()
3651

3752
install(TARGETS ktool DESTINATION ${CMAKE_INSTALL_PREFIX})

CMakePresets.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"version": 2,
3+
"cmakeMinimumRequired": {
4+
"major": 3,
5+
"minor": 5,
6+
"patch": 0
7+
},
8+
"configurePresets": [
9+
{
10+
"name": "base",
11+
"generator": "Ninja",
12+
"binaryDir": "${sourceDir}/build"
13+
},
14+
{
15+
"name": "debug",
16+
"displayName": "Debug",
17+
"binaryDir": "${sourceDir}/build_debug",
18+
"generator": "Ninja",
19+
"cacheVariables": {
20+
"CMAKE_BUILD_TYPE": "Debug",
21+
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
22+
"CMAKE_CXX_FLAGS_INIT": "$env{CXX_FLAGS}"
23+
},
24+
"inherits": ["base"]
25+
},
26+
{
27+
"name": "release",
28+
"displayName": "Release",
29+
"binaryDir": "${sourceDir}/build_release",
30+
"generator": "Ninja",
31+
"cacheVariables": {
32+
"CMAKE_BUILD_TYPE": "Release",
33+
"CMAKE_CXX_FLAGS_INIT": "$env{CXX_FLAGS} -O3 -Wno-unused-parameter -Wunused-variable"
34+
},
35+
"inherits": ["base"]
36+
}
37+
]
38+
}

ide/ktool.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
F36E81482C29E5E000DFBF9B /* FlagsIterator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = FlagsIterator.h; path = ../include/ADT/FlagsIterator.h; sourceTree = "<group>"; };
8383
F36E81492C29E5F100DFBF9B /* List.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = List.h; path = ../include/ADT/List.h; sourceTree = "<group>"; };
8484
F36E814A2C29E5F100DFBF9B /* Maximizer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Maximizer.h; path = ../include/ADT/Maximizer.h; sourceTree = "<group>"; };
85-
F36E814B2C29E5F900DFBF9B /* PointerOrError.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = PointerOrError.h; path = ../include/ADT/PointerOrError.h; sourceTree = "<group>"; };
85+
F36E814B2C29E5F900DFBF9B /* ExpectedPointer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ExpectedPointer.h; path = ../include/ADT/ExpectedPointer.h; sourceTree = "<group>"; };
8686
F36E814C2C29E60700DFBF9B /* Tree.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Tree.h; path = ../include/ADT/Tree.h; sourceTree = "<group>"; };
8787
F36E814D2C29E60700DFBF9B /* Trie.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Trie.h; path = ../include/ADT/Trie.h; sourceTree = "<group>"; };
8888
F36E814E2C29E63400DFBF9B /* Trie.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Trie.cpp; path = ../src/ADT/Trie.cpp; sourceTree = "<group>"; };
@@ -329,7 +329,7 @@
329329
F36E81492C29E5F100DFBF9B /* List.h */,
330330
F36E814A2C29E5F100DFBF9B /* Maximizer.h */,
331331
F39FAE8A2929C1B50057DC6F /* MemoryMap.h */,
332-
F36E814B2C29E5F900DFBF9B /* PointerOrError.h */,
332+
F36E814B2C29E5F900DFBF9B /* ExpectedPointer.h */,
333333
F3AD81F828ECBD74005DE822 /* Range.h */,
334334
F30BB524292A267000AF300B /* SwitchEndian.h */,
335335
F36E814C2C29E60700DFBF9B /* Tree.h */,

include/ADT/DeVirtualizer.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ namespace ADT {
1818
void **EndOut = nullptr) const noexcept -> void * = 0;
1919

2020
[[nodiscard]] virtual auto
21-
getMapForRange(const ADT::Range &Range,
22-
bool IgnoreSectionBounds = false) const noexcept
21+
getMapForVmRange(const ADT::Range &Range,
22+
bool IgnoreSectionBounds = false) const noexcept
2323
-> std::optional<ADT::MemoryMap> = 0;
2424

2525
template <typename T>
@@ -29,7 +29,7 @@ namespace ADT {
2929
T **const EndOut = nullptr) const noexcept
3030
{
3131
return static_cast<T *>(
32-
getPtrForAddress(
32+
this->getPtrForAddress(
3333
Address,
3434
IgnoreSectionBounds,
3535
reinterpret_cast<void **>(
@@ -40,13 +40,13 @@ namespace ADT {
4040
getStringAtAddress(
4141
const uint64_t Address,
4242
const bool IgnoreSectionBounds = false) const noexcept
43-
-> std::optional<std::string_view>
43+
-> std::optional<std::string_view>
4444
{
4545
auto End = static_cast<const char *>(nullptr);
4646
const auto Ptr =
47-
getDataAtAddress<const char>(Address,
48-
IgnoreSectionBounds,
49-
&End);
47+
this->getDataAtAddress<const char>(Address,
48+
IgnoreSectionBounds,
49+
&End);
5050

5151
if (Ptr == nullptr) {
5252
return std::nullopt;

include/ADT/FileMap.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
//
77

88
#pragma once
9+
#include <expected>
910

1011
#include "FlagsBase.h"
1112
#include "MemoryMap.h"
12-
#include "PointerOrError.h"
1313
#include "Range.h"
1414

1515
namespace ADT {
@@ -47,11 +47,9 @@ namespace ADT {
4747

4848
static auto
4949
Open(const char *Path, Prot Prot) noexcept
50-
-> PointerOrError<FileMap, OpenError>;
50+
-> std::expected<FileMap *, OpenError>;
5151

5252
explicit FileMap(const FileMap &FileMap) noexcept = delete;
53-
FileMap(FileMap &&FileMap) noexcept = default;
54-
5553
~FileMap() noexcept;
5654

5755
[[nodiscard]] constexpr auto size() const noexcept { return Size; }
@@ -60,9 +58,9 @@ namespace ADT {
6058
uint64_t Size = sizeof(T),
6159
bool Verify = true>
6260

63-
[[nodiscard]] constexpr auto base() const noexcept {
61+
[[nodiscard]] constexpr auto base() const noexcept -> T* {
6462
if constexpr (Verify) {
65-
if (size() < Size) {
63+
if (this->size() < Size) {
6664
return nullptr;
6765
}
6866
}
@@ -71,11 +69,11 @@ namespace ADT {
7169
}
7270

7371
[[nodiscard]] constexpr auto range() const noexcept {
74-
return Range::FromSize(0, Size);
72+
return Range::FromSize(0, this->size());
7573
}
7674

7775
[[nodiscard]] constexpr auto map() const noexcept {
78-
return MemoryMap(Base, Size);
76+
return MemoryMap(this->base<void, 1>(), this->size());
7977
}
8078
};
8179

include/ADT/FlagsBase.h

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
#pragma once
99

10-
#include <assert.h>
1110
#include <concepts>
1211
#include <cstdint>
1312

13+
#include "Utils/Assert.h"
1414
#include "Utils/Misc.h"
1515

1616
namespace ADT {
@@ -21,72 +21,72 @@ namespace ADT {
2121

2222
template <typename E>
2323
constexpr auto addMask(const E Mask) noexcept {
24-
Flags |= static_cast<T>(Mask);
24+
this->Flags |= static_cast<T>(Mask);
2525
}
2626

2727
template <typename E>
2828
constexpr auto removeMask(const E Mask) noexcept {
29-
Flags &= ~static_cast<T>(Mask);
29+
this->Flags &= ~static_cast<T>(Mask);
3030
}
3131

3232
template <typename E, typename S, typename V>
3333
constexpr void
3434
setValueForMask(const E Mask, const S Shift, const V Value) noexcept {
35-
removeMask(Mask);
36-
addMask(static_cast<T>(Value) << static_cast<T>(Shift));
35+
this->removeMask(Mask);
36+
this->addMask(static_cast<T>(Value) << static_cast<T>(Shift));
3737
}
3838

3939
template <typename E>
4040
[[nodiscard]] constexpr auto valueForMask(const E Mask) const noexcept {
41-
return Flags & static_cast<T>(Mask);
41+
return this->Flags & static_cast<T>(Mask);
4242
}
4343

4444
template <typename E>
4545
[[nodiscard]] constexpr auto has(const E Mask) const noexcept {
46-
return valueForMask(Mask) != 0;
46+
return this->valueForMask(Mask) != 0;
4747
}
4848
public:
4949
constexpr FlagsBase() noexcept = default;
5050
constexpr FlagsBase(const T Flags) noexcept : Flags(Flags) {}
5151

5252
[[nodiscard]]
5353
constexpr auto operator|(const FlagsBase<T> Mask) const noexcept {
54-
return Flags | Mask;
54+
return this->Flags | Mask;
5555
}
5656

5757
[[nodiscard]]
5858
constexpr auto operator&(const FlagsBase<T> Mask) const noexcept {
59-
return Flags & Mask;
59+
return this->Flags & Mask;
6060
}
6161

6262
constexpr auto operator|=(const FlagsBase<T> Mask) const noexcept
6363
-> decltype(*this)
6464
{
65-
Flags |= Mask;
65+
this->Flags |= Mask;
6666
return *this;
6767
}
6868

6969
constexpr auto operator&=(const FlagsBase<T> Mask) const noexcept
7070
-> decltype(*this)
7171
{
72-
Flags &= Mask;
72+
this->Flags &= Mask;
7373
return *this;
7474
}
7575

7676
[[nodiscard]] constexpr auto operator~() const noexcept {
77-
return FlagsBase(~Flags);
77+
return FlagsBase(~this->Flags);
7878
}
7979

8080
[[nodiscard]] constexpr auto empty() const noexcept {
81-
return Flags == 0;
81+
return this->Flags == 0;
8282
}
8383

8484
[[nodiscard]] constexpr auto value() const noexcept {
85-
return Flags;
85+
return this->Flags;
8686
}
8787

8888
constexpr auto clear() noexcept -> decltype(*this) {
89-
Flags = 0;
89+
this->Flags = 0;
9090
return *this;
9191
}
9292

@@ -116,6 +116,7 @@ namespace ADT {
116116
{
117117
assert(!Utils::IndexOutOfBounds(Index, bit_sizeof(T)));
118118

119+
auto Flags = this->Flags;
119120
if constexpr (sizeof(T) == sizeof(long long)) {
120121
return __builtin_popcountll(Flags >> Index);
121122
} else if constexpr (sizeof(T) == sizeof(long)) {
@@ -131,15 +132,15 @@ namespace ADT {
131132
{
132133
assert(BitCount <= bit_sizeof(T));
133134

134-
Flags >>= BitCount;
135+
this->Flags >>= BitCount;
135136
return *this;
136137
}
137138

138139
[[nodiscard]] constexpr
139140
auto operator<=>(const FlagsBase<T> &Rhs) const noexcept = default;
140141

141142
[[nodiscard]] constexpr auto operator<=>(const T Rhs) const noexcept {
142-
return Flags <=> Rhs;
143+
return this->Flags <=> Rhs;
143144
}
144145
};
145146
}
@@ -181,17 +182,17 @@ namespace ADT {
181182
} \
182183
\
183184
[[maybe_unused]] [[nodiscard]] \
184-
constexpr static auto operator==(std::underlying_type_t<ENUM> Num,\
185-
const ENUM Mask) noexcept\
185+
constexpr static auto operator<=>(std::underlying_type_t<ENUM> Num,\
186+
const ENUM Mask) noexcept\
186187
{ \
187-
return Num == static_cast<std::underlying_type_t<ENUM>>(Mask); \
188+
return Num <=> static_cast<std::underlying_type_t<ENUM>>(Mask); \
188189
} \
189190
\
190191
[[maybe_unused]] [[nodiscard]] \
191-
constexpr static auto operator==(const ENUM Mask,\
192-
std::underlying_type_t<ENUM> Num) noexcept\
192+
constexpr static auto operator<=>(const ENUM Mask,\
193+
std::underlying_type_t<ENUM> Num) noexcept\
193194
{ \
194-
return Num == static_cast<std::underlying_type_t<ENUM>>(Mask); \
195+
return Num <=> static_cast<std::underlying_type_t<ENUM>>(Mask); \
195196
} \
196197
\
197198
[[maybe_unused]] [[nodiscard]] \

0 commit comments

Comments
 (0)