From cc6c7bf21f1e0e13a463481be33a4280cc9f9971 Mon Sep 17 00:00:00 2001 From: Jake Hillion Date: Tue, 24 Oct 2023 07:36:13 -0700 Subject: [PATCH] compiler: update to c++20 --- CMakeLists.txt | 5 ----- oi/OICompiler.cpp | 2 +- oi/OICompiler.h | 28 ++++++++++++++-------------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 95816b3..28ccdf4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/oi/OICompiler.cpp b/oi/OICompiler.cpp index 1aafd1f..d036b33 100644 --- a/oi/OICompiler.cpp +++ b/oi/OICompiler.cpp @@ -121,7 +121,7 @@ OICompiler::Disassembler::operator()() { }; offset += instSize; - funcText.remove_prefix(instSize); + funcText = funcText.subspan(instSize); return inst; } diff --git a/oi/OICompiler.h b/oi/OICompiler.h index d730191..b08528c 100644 --- a/oi/OICompiler.h +++ b/oi/OICompiler.h @@ -20,7 +20,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -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 - using Span = std::basic_string_view; - /** * 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 opcodes; + std::span opcodes; std::string_view disassembly; }; @@ -125,7 +119,7 @@ class OICompiler { private: uintptr_t offset = 0; - Span funcText; + std::span funcText; std::array disassemblyBuffer; }; @@ -212,10 +206,16 @@ std::optional> 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( - 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)) {