Rename BaseModule to Module

This commit is contained in:
IlushaShurupov 2023-06-29 19:20:58 +03:00
parent 479c3fa667
commit 47a7809398
18 changed files with 10 additions and 8 deletions

26
Module/private/Assert.cpp Normal file
View file

@ -0,0 +1,26 @@
#include "Assert.hpp"
#include <cstdio>
#include <cstdlib>
using namespace tp;
void tp::_assert_(const char* exp, const char* file, int line) {
if (!exp) {
exp = "no info";
}
printf("\nERROR: Assertion Failure - %s -- %s:%i\n", exp, file, line);
#ifdef ENV_BUILD_DEBUG
DEBUG_BREAK(true);
#else
exit(1);
#endif
}
void tp::terminate(tp::alni code) {
exit((int)code);
}

46
Module/private/Common.cpp Normal file
View file

@ -0,0 +1,46 @@
#include "Common.hpp"
namespace tp {
ualni next2pow(ualni v) {
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
v |= v >> 16;
v |= v >> 32;
return v + 1;
}
uhalni next2pow(uhalni v) {
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
v |= v >> 16;
return v + 1;
}
ufalni next2pow(ufalni v) {
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
return v + 1;
}
ualni hash(const char* bytes) {
unsigned long hash = 5381;
int c;
while ((c = *bytes++)) {
hash = ((hash << 5) + hash) + c;
}
return hash;
}
ualni hash(alni bytes) { return abs(bytes); }
ualni hash(alnf bytes) { return (alni)(abs(bytes)); }
ualni hash(halni bytes) { return hash(alni(bytes)); }
ualni hash(uhalni bytes) { return hash(alni(bytes)); }
ualni hash(ualni bytes) { return hash(alni(bytes)); }
}

View file

@ -0,0 +1,21 @@
#include "Environment.hpp"
#include <iostream>
const char* ArchString[] = { "UNDEF", "INTEL", "ARM" };
const char* BuildTypeString[] = { "UNDEF", "DEBUG", "RELEASE" };
const char* ToolchainString[] = { "UNDEF", "GNU", "LLVM", "MSVC" };
const char* OSString[] = { "UNDEF", "LINUX", "WINDOWS", "ANDROID", "IOS" };
const char* ArchWidthString[] = { "UNDEF", "X64", "X32" };
const tp::Environment tp::gEnvironment;
void tp::Environment::log() const {
std::cout << "ARCH : " << ArchString[(int)mArch] << "\n";
std::cout << "WIDTH : " << ArchWidthString[(int)mWidth] << "\n";
std::cout << "CURRENT OS : " << OSString[(int)mOS] << "\n";
std::cout << "TOOLCHAIN : " << ToolchainString[(int)mToolchain] << "\n";
std::cout << "BUILD TYPE : " << BuildTypeString[(int)mBuildType] << "\n";
}

81
Module/private/Module.cpp Normal file
View file

@ -0,0 +1,81 @@
#include "Module.hpp"
#include <iostream>
using namespace tp;
static bool init(const ModuleManifest* self) {
gEnvironment.log();
return true;
}
static ModuleManifest* deps[] = { nullptr };
ModuleManifest tp::gModuleBase = ModuleManifest("Common", init, nullptr, deps);
ModuleManifest::ModuleManifest(const char* aModuleName, ModuleInit aInit, ModuleDeinit aDeinit, ModuleManifest** aDependencies) {
mInit = aInit;
mDeinit = aDeinit;
mDependencies = aDependencies;
mModuleName = aModuleName;
}
bool ModuleManifest::isInitialized() const {
return mInitialized;
}
bool ModuleManifest::initialize() {
mInitCount++;
if (isInitialized()) {
return true;
}
mInitialized = true;
for (auto module = mDependencies; module && *module; module++) {
mInitialized &= (*module)->initialize();
}
std::cout << "====== Initializing \"" << mModuleName << "\"\n";
if (mInit) mInitialized &= mInit(this);
if (!mInitialized) {
std::cout << "Failed to Initialize.\n";
}
return mInitialized;
}
void ModuleManifest::deinitialize() {
mInitCount--;
if (mInitCount > 0) {
return;
}
if (!isInitialized()) {
return;
}
if (mDeinit) mDeinit(this);
mInitialized = false;
auto len = 0;
for (auto module = mDependencies; module && *module; module++) {
len++;
}
for (auto i = 0; i < len; i++) {
auto module = mDependencies + (len - i - 1);
if ((*module)->isInitialized()) {
(*module)->deinitialize();
}
}
}
const char *ModuleManifest::getName() const {
return mModuleName;
}