Skip to content

Commit

Permalink
Added initial support of C++23/26 for LLVM 17.x.
Browse files Browse the repository at this point in the history
Added ClangRuntime class into Python side.
  • Loading branch information
DronCode committed Jan 21, 2024
1 parent 3263b06 commit 7b88185
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 6 deletions.
3 changes: 1 addition & 2 deletions LLVM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ project(RG3_LLVM)
# ------- Boost
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost COMPONENTS system filesystem REQUIRED)
message(STATUS "Found boost ${BOOST_VERSION}")

# ------- LLVM BACKEND
find_package(LLVM REQUIRED CONFIG)
find_package(CLANG REQUIRED CONFIG)
message(STATUS "Found CLANG ${LLVM_VERSION}")
message(STATUS "Found CLANG ${LLVM_VERSION} (${LLVM_DIR})")

# ------- RG3 LLVM
file(GLOB_RECURSE RG3_LLVM_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp")
Expand Down
7 changes: 6 additions & 1 deletion LLVM/include/RG3/LLVM/Compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace rg3::llvm
{
enum class CxxStandard : int { CC_11 = 11, CC_14 = 14, CC_17 = 17, CC_20 = 20, CC_23 = 23, CC_DEFAULT = CC_11 };
enum class CxxStandard : int { CC_11 = 11, CC_14 = 14, CC_17 = 17, CC_20 = 20, CC_23 = 23, CC_26 = 26, CC_DEFAULT = CC_11 };
enum class IncludeKind : int { IK_PROJECT = 0, IK_SYSTEM, IK_SYSROOT, IK_THIRD_PARTY, IK_DEFAULT = IK_PROJECT };


Expand All @@ -21,4 +21,9 @@ namespace rg3::llvm
};

using IncludeVector = std::vector<IncludeInfo>;

struct ClangRuntimeInfo
{
static std::string getRuntimeInfo();
};
}
18 changes: 17 additions & 1 deletion LLVM/source/CodeAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,25 @@ namespace rg3::llvm
break;
case CxxStandard::CC_20:
langOptions->CPlusPlus20 = 1;
langOptions->CPlusPlus2b = 1;
langKind = clang::LangStandard::Kind::lang_cxx20;
break;
#if LLVM_VERSION_MAJOR >= 17
case CxxStandard::CC_23:
langOptions->CPlusPlus23 = 1;
langKind = clang::LangStandard::Kind::lang_cxx23;
break;
case CxxStandard::CC_26:
langOptions->CPlusPlus26 = 1;
langKind = clang::LangStandard::Kind::lang_cxx26;
break;
#else
case CxxStandard::CC_23:
case CxxStandard::CC_26:
assert(false && "Unsupported Cxx standard! Used C++20 instead!");
langOptions->CPlusPlus20 = 1;
langKind = clang::LangStandard::Kind::lang_cxx20;
break;
#endif
default:
langOptions->CPlusPlus11 = 1;
langKind = clang::LangStandard::Kind::lang_cxx11;
Expand Down
12 changes: 12 additions & 0 deletions LLVM/source/Compiler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <RG3/LLVM/Compiler.h>

#include <llvm/Config/llvm-config.h>


namespace rg3::llvm
{
std::string ClangRuntimeInfo::getRuntimeInfo()
{
return std::format("Clang {} built for {}", LLVM_VERSION_STRING, LLVM_HOST_TRIPLE);
}
}
1 change: 0 additions & 1 deletion PyBind/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ set(Boost_USE_STATIC_LIBS ON)
# ------- LLVM BACKEND
find_package(PythonLibs 3.10 REQUIRED)
find_package(Boost COMPONENTS python filesystem REQUIRED)
message(STATUS "Found boost ${BOOST_VERSION}")

# ------- RG3 PyBind frontend
file(GLOB_RECURSE RG3_PYBIND_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp")
Expand Down
13 changes: 13 additions & 0 deletions PyBind/include/RG3/PyBind/PyClangRuntime.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#define BOOST_PYTHON_STATIC_LIB
#include <boost/python.hpp>


namespace rg3::pybind
{
struct PyClangRuntime
{
static boost::python::str getRuntimeInfo();
};
}
5 changes: 5 additions & 0 deletions PyBind/rg3py.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,8 @@ class CppCompilerIssue:

class CppTypeReference:
def __init__(self, path: str): ...


class ClangRuntime:
@staticmethod
def get_version() -> str: ...
7 changes: 6 additions & 1 deletion PyBind/source/PyBind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <RG3/PyBind/PyTypeClass.h>
#include <RG3/PyBind/PyTag.h>
#include <RG3/PyBind/PyAnalyzerContext.h>
#include <RG3/PyBind/PyClangRuntime.h>



Expand Down Expand Up @@ -192,7 +193,6 @@ BOOST_PYTHON_MODULE(rg3py)
&rg3::pybind::PyCodeAnalyzerBuilder::isNonRuntimeTypesAllowedToBeCollected,
&rg3::pybind::PyCodeAnalyzerBuilder::setAllowToCollectNonRuntimeTypes,
"Allow to ignore @runtime tag near type decl")

.add_property("definitions",
&rg3::pybind::PyCodeAnalyzerBuilder::getCompilerDefinitions,
&rg3::pybind::PyCodeAnalyzerBuilder::setCompilerDefinitions,
Expand Down Expand Up @@ -230,4 +230,9 @@ BOOST_PYTHON_MODULE(rg3py)
// Functions
.def("analyze", &rg3::pybind::PyAnalyzerContext::analyze)
;

class_<rg3::pybind::PyClangRuntime, boost::noncopyable>("ClangRuntime")
.def("get_version", &rg3::pybind::PyClangRuntime::getRuntimeInfo)
.staticmethod("get_version")
;
}
13 changes: 13 additions & 0 deletions PyBind/source/PyClangRuntime.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <RG3/PyBind/PyClangRuntime.h>

#include <RG3/LLVM/Compiler.h>


namespace rg3::pybind
{
boost::python::str PyClangRuntime::getRuntimeInfo()
{
const auto str = rg3::llvm::ClangRuntimeInfo::getRuntimeInfo();
return str.c_str();
}
}

0 comments on commit 7b88185

Please sign in to comment.