Skip to content

Commit

Permalink
[0.0.23] Upgrade LLVM to 19.1.4
Browse files Browse the repository at this point in the history
         Added base implementation of CodeEvaluator class which able to evaluate constexpr code.
         Small refactoring in CodeAnalyzer.
         Fixed possible bug with id0.hpp file when it contents could be corrupted. Used better approach from LLVM with virtual files.
  • Loading branch information
DronCode committed Nov 30, 2024
1 parent b2d4bad commit 598e831
Show file tree
Hide file tree
Showing 11 changed files with 642 additions and 287 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
cxx: "cl",
boost_toolset: msvc,
cmake_generator: "Visual Studio 17 2022",
llvm_tag: "llvmorg-18.1.8",
llvm_tag: "llvmorg-19.1.4",
python_version: "3.10",
os_version: "2022",
artifact_id: "RG3_Windows"
Expand All @@ -35,7 +35,7 @@ jobs:
cxx: "g++-13",
boost_toolset: gcc,
cmake_generator: "Ninja",
llvm_tag: "llvmorg-18.1.8",
llvm_tag: "llvmorg-19.1.4",
python_version: "3.10",
os_version: "24.04",
artifact_id: "RG3_Linux"
Expand All @@ -48,7 +48,7 @@ jobs:
cxx: "clang++",
boost_toolset: gcc,
cmake_generator: "Ninja",
llvm_tag: "llvmorg-18.1.8",
llvm_tag: "llvmorg-19.1.4",
python_version: "3.10",
os_version: "13",
artifact_id: "RG3_macOS"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include <clang/Frontend/FrontendActions.h>
#include <RG3/LLVM/CodeEvaluator.h>
#include <unordered_map>
#include <unordered_set>
#include <string>



namespace rg3::llvm::actions
{
struct CollectConstexprVariableEvalResultAction : public clang::ASTFrontendAction
{
std::unordered_set<std::string> aExpectedVariables {};
std::unordered_map<std::string, VariableValue>* pEvaluatedVariables { nullptr };

std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(clang::CompilerInstance& /*compilerInstance*/, clang::StringRef /*file*/) override;
};
}
42 changes: 42 additions & 0 deletions LLVM/include/RG3/LLVM/CodeEvaluator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once

#include <RG3/LLVM/CompilerConfigDetector.h>
#include <RG3/LLVM/CompilerConfig.h>
#include <RG3/LLVM/CodeAnalyzer.h>
#include <unordered_map>
#include <optional>
#include <variant>
#include <cstdint>
#include <string>
#include <vector>


namespace rg3::llvm
{
using VariableValue = std::variant<bool, std::int64_t, std::uint64_t, float, double, std::string>;

struct CodeEvaluateResult
{
AnalyzerResult::CompilerIssuesVector vIssues;
std::unordered_map<std::string, VariableValue> mOutputs;

explicit operator bool() const noexcept;
};

class CodeEvaluator
{
public:
CodeEvaluator();
CodeEvaluator(CompilerConfig compilerConfig);

void setCompilerEnvironment(const CompilerEnvironment& env);
CompilerConfig& getCompilerConfig();

CodeEvaluateResult evaluateCode(const std::string& sCode, const std::vector<std::string>& aCaptureOutputVariables);

private:
std::optional<CompilerEnvironment> m_env;
CompilerConfig m_compilerConfig;
std::string m_sSourceCode {};
};
}
23 changes: 23 additions & 0 deletions LLVM/include/RG3/LLVM/CompilerInstanceFactory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include <clang/Frontend/CompilerInstance.h>

#include <RG3/LLVM/CompilerConfigDetector.h>
#include <RG3/LLVM/CompilerConfig.h>

#include <filesystem>
#include <variant>
#include <string>


namespace rg3::llvm
{
struct CompilerInstanceFactory
{
static void makeInstance(
clang::CompilerInstance* pOutInstance,
const std::variant<std::filesystem::path, std::string>& sInput,
const CompilerConfig& sCompilerConfig,
const CompilerEnvironment* pCompilerEnv = nullptr);
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include <clang/AST/ASTConsumer.h>
#include <RG3/LLVM/CodeEvaluator.h>
#include <unordered_map>
#include <unordered_set>
#include <string>


namespace rg3::llvm::consumers
{
struct CollectConstexprVariableEvalResult : public clang::ASTConsumer
{
std::unordered_set<std::string> aExpectedVariables {};
std::unordered_map<std::string, VariableValue>* pEvaluatedVariables { nullptr };

public:
CollectConstexprVariableEvalResult();

void HandleTranslationUnit(clang::ASTContext& ctx) override;
};
}
15 changes: 15 additions & 0 deletions LLVM/source/Actions/CollectConstexprVariableEvalResultAction.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <RG3/LLVM/Actions/CollectConstexprVariableEvalResultAction.h>
#include <RG3/LLVM/Consumers/CollectConstexprVariableEvalResult.h>


namespace rg3::llvm::actions
{
std::unique_ptr<clang::ASTConsumer> CollectConstexprVariableEvalResultAction::CreateASTConsumer(clang::CompilerInstance&, clang::StringRef)
{
auto pConsumer = std::make_unique<consumers::CollectConstexprVariableEvalResult>();
pConsumer->aExpectedVariables = aExpectedVariables;
pConsumer->pEvaluatedVariables = pEvaluatedVariables;

return std::move(pConsumer);
}
}
Loading

0 comments on commit 598e831

Please sign in to comment.