mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-11-09 21:24:14 +00:00
compiler: update to c++20
This commit is contained in:
parent
fcb50df611
commit
cc6c7bf21f
@ -251,11 +251,6 @@ if (STATIC_LINK)
|
||||
set_property(TARGET glog PROPERTY INTERFACE_LINK_LIBRARIES "gflags_static")
|
||||
endif()
|
||||
|
||||
# FIXME: LLVM 12's source code is not compatible with C++20.
|
||||
# We should check with the compiler team if we could apply a fix to our LLVM.
|
||||
# In the meantime, we can compile OICompiler with C++17.
|
||||
set_source_files_properties(oi/OICompiler.cpp PROPERTIES COMPILE_FLAGS -std=c++17 SKIP_PRECOMPILE_HEADERS ON)
|
||||
|
||||
|
||||
|
||||
## OI Dependencies (linked to by output libraries and executables)
|
||||
|
@ -121,7 +121,7 @@ OICompiler::Disassembler::operator()() {
|
||||
};
|
||||
|
||||
offset += instSize;
|
||||
funcText.remove_prefix(instSize);
|
||||
funcText = funcText.subspan(instSize);
|
||||
|
||||
return inst;
|
||||
}
|
||||
|
@ -20,7 +20,9 @@
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <ranges>
|
||||
#include <set>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <unordered_map>
|
||||
@ -89,14 +91,6 @@ class OICompiler {
|
||||
*/
|
||||
class Disassembler {
|
||||
public:
|
||||
/*
|
||||
* Please forgive me :(
|
||||
* We have to remain compatible with C++17 for OICompiler.cpp
|
||||
* So we use std::basic_string_view instead of std::span.
|
||||
*/
|
||||
template <typename T>
|
||||
using Span = std::basic_string_view<T>;
|
||||
|
||||
/**
|
||||
* Instruction holds the information returned by the disassembler.
|
||||
* The fields are valid until a new Instruction struct has been
|
||||
@ -106,7 +100,7 @@ class OICompiler {
|
||||
*/
|
||||
struct Instruction {
|
||||
uintptr_t offset;
|
||||
Span<uint8_t> opcodes;
|
||||
std::span<const uint8_t> opcodes;
|
||||
std::string_view disassembly;
|
||||
};
|
||||
|
||||
@ -125,7 +119,7 @@ class OICompiler {
|
||||
|
||||
private:
|
||||
uintptr_t offset = 0;
|
||||
Span<uint8_t> funcText;
|
||||
std::span<const uint8_t> funcText;
|
||||
std::array<char, 128> disassemblyBuffer;
|
||||
};
|
||||
|
||||
@ -212,10 +206,16 @@ std::optional<std::vector<uintptr_t>> OICompiler::locateOpcodes(
|
||||
while (auto inst = DG()) {
|
||||
auto it = std::find_if(
|
||||
std::begin(needles), std::end(needles), [&](const auto& needle) {
|
||||
// Inst->opcodes.starts_with(needle);
|
||||
return 0 ==
|
||||
inst->opcodes.find(OICompiler::Disassembler::Span<uint8_t>(
|
||||
std::data(needle), std::size(needle)));
|
||||
// std::ranges::starts_with(inst->opcodes, needle)
|
||||
if (std::ranges::size(needle) > std::ranges::size(inst->opcodes))
|
||||
return false;
|
||||
auto it1 = std::ranges::begin(inst->opcodes);
|
||||
auto it2 = std::ranges::begin(needle);
|
||||
for (; it2 != std::ranges::end(needle); ++it1, ++it2) {
|
||||
if (*it1 != *it2)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
if (it != std::end(needles)) {
|
||||
|
Loading…
Reference in New Issue
Block a user