[ox] Add StringView, Writer system, Preloader system

This commit is contained in:
2022-11-30 01:45:11 -06:00
parent 98f35140fe
commit cbb496c59f
64 changed files with 2343 additions and 417 deletions

126
deps/ox/src/ox/preloader/platspecs.hpp vendored Normal file
View File

@@ -0,0 +1,126 @@
/*
* Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved.
*/
#pragma once
#include <ox/std/serialize.hpp>
#include <ox/std/typetraits.hpp>
#include "alignmentcatcher.hpp"
#include "sizecatcher.hpp"
namespace ox {
struct NativePlatSpec {
using PtrType = uintptr_t;
using size_t = std::size_t;
static constexpr auto PtrAlign = alignof(void*);
static constexpr PtrType RomStart = 0x08000000;
template<typename T>
[[nodiscard]]
static constexpr auto alignOf(const T &v) noexcept {
if constexpr(ox::is_integral_v<T>) {
return alignof(T);
} else if constexpr(ox::is_pointer_v<T>) {
return PtrAlign;
} else {
AlignmentCatcher<NativePlatSpec> c;
oxAssert(model(c.interface(), &v), "Could not get alignment for type");
return c.biggestAlignment;
}
}
[[nodiscard]]
static constexpr auto correctEndianness(auto v) noexcept {
return v;
}
};
struct GbaPlatSpec {
using PtrType = uint32_t;
using size_t = uint32_t;
static constexpr auto PtrAlign = 4;
static constexpr PtrType RomStart = 0x08000000;
[[nodiscard]]
static constexpr std::size_t alignOf(const bool) noexcept {
return 1;
}
[[nodiscard]]
static constexpr std::size_t alignOf(const uint8_t) noexcept {
return 1;
}
[[nodiscard]]
static constexpr std::size_t alignOf(const uint16_t) noexcept {
return 2;
}
[[nodiscard]]
static constexpr std::size_t alignOf(const uint32_t) noexcept {
return 4;
}
[[nodiscard]]
static constexpr std::size_t alignOf(const uint64_t) noexcept {
return 8;
}
[[nodiscard]]
static constexpr std::size_t alignOf(const int8_t) noexcept {
return 1;
}
[[nodiscard]]
static constexpr std::size_t alignOf(const int16_t) noexcept {
return 2;
}
[[nodiscard]]
static constexpr std::size_t alignOf(const int32_t) noexcept {
return 4;
}
[[nodiscard]]
static constexpr std::size_t alignOf(const int64_t) noexcept {
return 8;
}
[[nodiscard]]
static constexpr std::size_t alignOf(auto*) noexcept {
return 4;
}
[[nodiscard]]
static constexpr std::size_t alignOf(const auto*) noexcept {
return 4;
}
[[nodiscard]]
static constexpr std::size_t alignOf(const auto &v) noexcept {
AlignmentCatcher<GbaPlatSpec> c;
oxAssert(model(c.interface(), &v), "Could not get alignment for type");
return c.biggestAlignment;
}
[[nodiscard]]
static constexpr auto correctEndianness(auto v) noexcept {
return ox::toLittleEndian(v);
}
};
template<typename PlatSpec, typename T>
[[nodiscard]]
constexpr std::size_t alignOf(const T &t) noexcept {
return PlatSpec::alignOf(t);
}
template<typename PlatSpec, typename T>
constexpr auto alignOf_v = alignOf<PlatSpec>(static_cast<T*>(nullptr));
}