-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
11 changed files
with
642 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
LLVM/include/RG3/LLVM/Actions/CollectConstexprVariableEvalResultAction.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; | ||
} |
22 changes: 22 additions & 0 deletions
22
LLVM/include/RG3/LLVM/Consumers/CollectConstexprVariableEvalResult.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
15
LLVM/source/Actions/CollectConstexprVariableEvalResultAction.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.