Compare commits
No commits in common. "b609c48bfe83e7d91ee55fb0dc9f24285adf2f9d" and "6f3dce5972deb5080b9d980a031a8a0faf16f919" have entirely different histories.
b609c48bfe
...
6f3dce5972
@ -1,66 +0,0 @@
|
||||
# Generated from CLion C/C++ Code Style settings
|
||||
BasedOnStyle: LLVM
|
||||
AccessModifierOffset: -2
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveAssignments: false
|
||||
AlignOperands: true
|
||||
AllowAllArgumentsOnNextLine: false
|
||||
AllowAllConstructorInitializersOnNextLine: false
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AllowShortBlocksOnASingleLine: Always
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: Always
|
||||
AllowShortLambdasOnASingleLine: All
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
BreakBeforeBraces: Custom
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: true
|
||||
AfterControlStatement: Always
|
||||
AfterEnum: true
|
||||
AfterFunction: true
|
||||
AfterNamespace: true
|
||||
AfterUnion: true
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: false
|
||||
SplitEmptyRecord: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakInheritanceList: BeforeComma
|
||||
ColumnLimit: 0
|
||||
CompactNamespaces: false
|
||||
ContinuationIndentWidth: 8
|
||||
IndentCaseLabels: true
|
||||
IndentPPDirectives: None
|
||||
IndentWidth: 2
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
MaxEmptyLinesToKeep: 2
|
||||
NamespaceIndentation: None
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PointerAlignment: Left
|
||||
ReflowComments: false
|
||||
SpaceAfterCStyleCast: true
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: false
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 0
|
||||
SpacesInAngles: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInContainerLiterals: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
TabWidth: 2
|
||||
UseTab: Never
|
||||
8
.idea/.gitignore
generated
vendored
8
.idea/.gitignore
generated
vendored
@ -1,8 +0,0 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
1
.idea/.name
generated
1
.idea/.name
generated
@ -1 +0,0 @@
|
||||
C Analyzer
|
||||
2
.idea/analyzer.git.iml
generated
2
.idea/analyzer.git.iml
generated
@ -1,2 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module classpath="CMake" type="CPP_MODULE" version="4" />
|
||||
54
.idea/codeStyles/Project.xml
generated
54
.idea/codeStyles/Project.xml
generated
@ -1,54 +0,0 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<Objective-C>
|
||||
<option name="INDENT_NAMESPACE_MEMBERS" value="0" />
|
||||
<option name="INDENT_C_STRUCT_MEMBERS" value="2" />
|
||||
<option name="INDENT_CLASS_MEMBERS" value="2" />
|
||||
<option name="INDENT_INSIDE_CODE_BLOCK" value="2" />
|
||||
<option name="NAMESPACE_BRACE_PLACEMENT" value="2" />
|
||||
<option name="FUNCTION_BRACE_PLACEMENT" value="2" />
|
||||
<option name="BLOCK_BRACE_PLACEMENT" value="2" />
|
||||
<option name="SUPERCLASS_LIST_COMMA_ON_NEXT_LINE" value="true" />
|
||||
<option name="SPACE_WITHIN_EMPTY_BRACES" value="true" />
|
||||
<option name="SPACE_BEFORE_POINTER_IN_DECLARATION" value="false" />
|
||||
<option name="SPACE_AFTER_POINTER_IN_DECLARATION" value="true" />
|
||||
<option name="SPACE_BEFORE_REFERENCE_IN_DECLARATION" value="false" />
|
||||
<option name="SPACE_AFTER_REFERENCE_IN_DECLARATION" value="true" />
|
||||
</Objective-C>
|
||||
<Objective-C-extensions>
|
||||
<extensions>
|
||||
<pair source="cpp" header="hpp" fileNamingConvention="PASCAL_CASE" />
|
||||
<pair source="c" header="h" fileNamingConvention="NONE" />
|
||||
<pair source="cu" header="cuh" fileNamingConvention="NONE" />
|
||||
</extensions>
|
||||
<rules>
|
||||
<rule entity="NAMESPACE" visibility="ANY" specifier="ANY" prefix="" style="CAMEL_CASE" suffix="" />
|
||||
<rule entity="MACRO" visibility="ANY" specifier="ANY" prefix="" style="SCREAMING_SNAKE_CASE" suffix="" />
|
||||
<rule entity="CLASS" visibility="ANY" specifier="ANY" prefix="" style="PASCAL_CASE" suffix="" />
|
||||
<rule entity="STRUCT" visibility="ANY" specifier="ANY" prefix="" style="PASCAL_CASE" suffix="" />
|
||||
<rule entity="ENUM" visibility="ANY" specifier="ANY" prefix="" style="PASCAL_CASE" suffix="" />
|
||||
<rule entity="ENUMERATOR" visibility="ANY" specifier="ANY" prefix="" style="PASCAL_CASE" suffix="" />
|
||||
<rule entity="TYPEDEF" visibility="ANY" specifier="ANY" prefix="" style="PASCAL_CASE" suffix="" />
|
||||
<rule entity="UNION" visibility="ANY" specifier="ANY" prefix="" style="PASCAL_CASE" suffix="" />
|
||||
<rule entity="CLASS_MEMBER_FUNCTION" visibility="ANY" specifier="ANY" prefix="" style="CAMEL_CASE" suffix="" />
|
||||
<rule entity="STRUCT_MEMBER_FUNCTION" visibility="ANY" specifier="ANY" prefix="" style="CAMEL_CASE" suffix="" />
|
||||
<rule entity="CLASS_MEMBER_FIELD" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||
<rule entity="STRUCT_MEMBER_FIELD" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||
<rule entity="GLOBAL_FUNCTION" visibility="ANY" specifier="ANY" prefix="" style="PASCAL_CASE" suffix="" />
|
||||
<rule entity="GLOBAL_VARIABLE" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||
<rule entity="PARAMETER" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||
<rule entity="LOCAL_VARIABLE" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||
<rule entity="CLASS_MEMBER_FIELD,STRUCT_MEMBER_FIELD" visibility="PROTECTED,PRIVATE" specifier="ANY" prefix="_" style="SNAKE_CASE" suffix="" />
|
||||
<rule entity="CLASS_MEMBER_FUNCTION,STRUCT_MEMBER_FUNCTION" visibility="PROTECTED,PRIVATE" specifier="ANY" prefix="_" style="PASCAL_CASE" suffix="" />
|
||||
</rules>
|
||||
</Objective-C-extensions>
|
||||
<codeStyleSettings language="ObjectiveC">
|
||||
<option name="BRACE_STYLE" value="2" />
|
||||
<option name="CLASS_BRACE_STYLE" value="2" />
|
||||
<indentOptions>
|
||||
<option name="INDENT_SIZE" value="2" />
|
||||
<option name="TAB_SIZE" value="2" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
||||
5
.idea/codeStyles/codeStyleConfig.xml
generated
5
.idea/codeStyles/codeStyleConfig.xml
generated
@ -1,5 +0,0 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
||||
</state>
|
||||
</component>
|
||||
4
.idea/misc.xml
generated
4
.idea/misc.xml
generated
@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
|
||||
</project>
|
||||
8
.idea/modules.xml
generated
8
.idea/modules.xml
generated
@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/analyzer.git.iml" filepath="$PROJECT_DIR$/.idea/analyzer.git.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/vcs.xml
generated
6
.idea/vcs.xml
generated
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
25447
dependencies/nlohmann/json.hpp
vendored
25447
dependencies/nlohmann/json.hpp
vendored
File diff suppressed because it is too large
Load Diff
@ -20,13 +20,10 @@ llvm_map_components_to_libnames(llvm_libs support option core)
|
||||
add_executable(op-finder
|
||||
main.cpp
|
||||
OperationFinder.cpp
|
||||
OperationStorage.cpp
|
||||
)
|
||||
|
||||
target_include_directories(op-finder
|
||||
PRIVATE
|
||||
${LLVM_INCLUDE_DIRS}
|
||||
${PROJECT_SOURCE_DIR}/dependencies
|
||||
PRIVATE ${LLVM_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
target_compile_definitions(op-finder
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
#include "OperationFinder.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
using namespace clang;
|
||||
using namespace clang::ast_matchers;
|
||||
@ -49,32 +50,17 @@ SourceLocation ResolveOperationSourceLocation(const SourceManager& source_manage
|
||||
return original;
|
||||
}
|
||||
|
||||
template<typename TOp>
|
||||
std::tuple<std::string, unsigned int, unsigned int> resolveLocations(const TOp* op, const SourceManager& source_manager)
|
||||
{
|
||||
const auto& loc = ResolveOperationSourceLocation(source_manager, op->getBeginLoc());
|
||||
|
||||
return {
|
||||
source_manager.getFilename(loc).str(),
|
||||
source_manager.getSpellingLineNumber(loc),
|
||||
source_manager.getSpellingColumnNumber(loc)
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
OperationFinder::OperationFinder(const std::string& output_dir)
|
||||
: _storage(output_dir)
|
||||
{ }
|
||||
|
||||
void OperationFinder::addMatcher(MatchFinder &finder)
|
||||
{
|
||||
finder.addMatcher(traverse(TK_IgnoreUnlessSpelledInSource, ArithmeticMatcher), this);
|
||||
finder.addMatcher(traverse(TK_IgnoreUnlessSpelledInSource, AssignmentMatcher), this);
|
||||
//finder.addMatcher(traverse(TK_IgnoreUnlessSpelledInSource, CompoundMatcher), this);
|
||||
finder.addMatcher(traverse(TK_IgnoreUnlessSpelledInSource, UnaryArithmeticMatcher), this);
|
||||
}
|
||||
|
||||
void OperationFinder::run(const MatchFinder::MatchResult& result)
|
||||
void OperationFinder::run(const MatchFinder::MatchResult &result)
|
||||
{
|
||||
if (result.Nodes.getNodeAs<clang::BinaryOperator>("assignment"))
|
||||
{
|
||||
@ -84,6 +70,10 @@ void OperationFinder::run(const MatchFinder::MatchResult& result)
|
||||
{
|
||||
_processArithmetic(result);
|
||||
}
|
||||
else if (result.Nodes.getNodeAs<clang::CompoundStmt>("compound_stmt"))
|
||||
{
|
||||
_processCompoundStmt(result);
|
||||
}
|
||||
else if (result.Nodes.getNodeAs<clang::UnaryOperator>("unary_arithmetic"))
|
||||
{
|
||||
_processUnaryArithmetic(result);
|
||||
@ -96,20 +86,15 @@ void OperationFinder::_processAssignment(const clang::ast_matchers::MatchFinder:
|
||||
|
||||
assert(op);
|
||||
|
||||
const auto [file_name, line_number, column_number] = resolveLocations(op, *result.SourceManager);
|
||||
const auto& source_manager = *result.SourceManager;
|
||||
const auto& loc = ResolveOperationSourceLocation(source_manager, op->getBeginLoc());
|
||||
|
||||
llvm::outs() << file_name << ":"
|
||||
<< line_number << ":"
|
||||
<< column_number << ":"
|
||||
llvm::outs() << source_manager.getFilename(loc) << ":"
|
||||
<< source_manager.getSpellingLineNumber(loc) << ":"
|
||||
<< source_manager.getSpellingColumnNumber(loc) << ":"
|
||||
<< "Assignment: Assigned to: ";
|
||||
|
||||
OperationStorage::Log log;
|
||||
log.line = line_number;
|
||||
log.operation = "=";
|
||||
|
||||
_processExpressionTypes(log, op, op->getLHS(), op->getRHS());
|
||||
|
||||
_storage.pushOperation(file_name, log);
|
||||
_processExpressionTypes(op, op->getLHS(), op->getRHS());
|
||||
|
||||
llvm::outs() << "\n";
|
||||
}
|
||||
@ -120,20 +105,39 @@ void OperationFinder::_processArithmetic(const MatchFinder::MatchResult& result)
|
||||
|
||||
assert(op);
|
||||
|
||||
const auto [file_name, line_number, column_number] = resolveLocations(op, *result.SourceManager);
|
||||
const auto& source_manager = *result.SourceManager;
|
||||
const auto& loc = ResolveOperationSourceLocation(source_manager, op->getBeginLoc());
|
||||
|
||||
llvm::outs() << file_name << ":"
|
||||
<< line_number << ":"
|
||||
<< column_number << ":"
|
||||
<< "Binary arithmetic: Type: " << getOpcode(op) << " LHS: ";
|
||||
llvm::outs() << source_manager.getFilename(loc) << ":"
|
||||
<< source_manager.getSpellingLineNumber(loc) << ":"
|
||||
<< source_manager.getSpellingColumnNumber(loc) << ":"
|
||||
<< "Arithmetic: Type: " << getOpcode(op) << " LHS: ";
|
||||
|
||||
OperationStorage::Log log;
|
||||
log.line = line_number;
|
||||
log.operation = getOpcode(op).str();
|
||||
_processExpressionTypes(op, op->getLHS(), op->getRHS());
|
||||
|
||||
_processExpressionTypes(log, op, op->getLHS(), op->getRHS());
|
||||
llvm::outs() << "\n";
|
||||
}
|
||||
|
||||
_storage.pushOperation(file_name, log);
|
||||
void OperationFinder::_processCompoundStmt(const clang::ast_matchers::MatchFinder::MatchResult& result)
|
||||
{
|
||||
const CompoundStmt* stmt = result.Nodes.getNodeAs<CompoundStmt>("compound_stmt");
|
||||
|
||||
assert(stmt);
|
||||
|
||||
const CompoundAssignOperator* op = dyn_cast<CompoundAssignOperator>(stmt->getStmtExprResult());
|
||||
|
||||
if (!op || !op->isCompoundAssignmentOp())
|
||||
return;
|
||||
|
||||
const auto& source_manager = *result.SourceManager;
|
||||
const auto& loc = ResolveOperationSourceLocation(source_manager, op->getBeginLoc());
|
||||
|
||||
llvm::outs() << source_manager.getFilename(loc) << ":"
|
||||
<< source_manager.getSpellingLineNumber(loc) << ":"
|
||||
<< source_manager.getSpellingColumnNumber(loc) << ":"
|
||||
<< "Compound assignment: Op code: " << getOpcode(op) << " ";
|
||||
|
||||
_processExpressionTypes(op, op->getLHS(), op->getRHS());
|
||||
|
||||
llvm::outs() << "\n";
|
||||
}
|
||||
@ -146,28 +150,22 @@ void OperationFinder::_processUnaryArithmetic(const MatchFinder::MatchResult &re
|
||||
assert(op);
|
||||
assert(lhs);
|
||||
|
||||
const auto [file_name, line_number, column_number] = resolveLocations(op, *result.SourceManager);
|
||||
const auto& source_manager = *result.SourceManager;
|
||||
const auto& loc = ResolveOperationSourceLocation(source_manager, op->getBeginLoc());
|
||||
|
||||
llvm::outs() << file_name << ":"
|
||||
<< line_number << ":"
|
||||
<< column_number << ":"
|
||||
llvm::outs() << source_manager.getFilename(loc) << ":"
|
||||
<< source_manager.getSpellingLineNumber(loc) << ":"
|
||||
<< source_manager.getSpellingColumnNumber(loc) << ":"
|
||||
<< "Unary arithmetic: Type: " << getOpcode(op) << " LHS: ";
|
||||
|
||||
OperationStorage::Log log;
|
||||
log.line = line_number;
|
||||
log.operation = getOpcode(op).str();
|
||||
|
||||
_processExpressionTypes(log, op, lhs, nullptr);
|
||||
|
||||
_storage.pushOperation(file_name, log);
|
||||
_processExpressionTypes(op, lhs, nullptr);
|
||||
|
||||
llvm::outs() << "\n";
|
||||
}
|
||||
|
||||
void OperationFinder::_processExpressionTypes(OperationStorage::Log& log, const Expr* source, const Expr* op1, const Expr* op2)
|
||||
void OperationFinder::_processExpressionTypes(const Expr* source, const Expr* op1, const Expr* op2)
|
||||
{
|
||||
|
||||
auto printTypeName = [](const QualType& t) -> std::string
|
||||
auto printTypeName = [](const QualType& t) -> void
|
||||
{
|
||||
if (t->isTypedefNameType())
|
||||
{
|
||||
@ -176,32 +174,28 @@ void OperationFinder::_processExpressionTypes(OperationStorage::Log& log, const
|
||||
llvm::outs() << "Typedef type: " << t.getAsString()
|
||||
<< ", underlying: " << tdt->desugar().getAsString()
|
||||
<< ".";
|
||||
|
||||
return tdt->desugar().getAsString();
|
||||
}
|
||||
else if (t->isBuiltinType())
|
||||
{
|
||||
llvm::outs() << "Builtin type: " << t.getAsString() << ".";
|
||||
return t.getAsString();
|
||||
}
|
||||
else
|
||||
{
|
||||
llvm::outs() << "Other type: " << t.getAsString() << ".";
|
||||
return t.getAsString();
|
||||
}
|
||||
};
|
||||
|
||||
llvm::outs() << "Expression types:\n\tExpression eval type: ";
|
||||
log.operand_result = printTypeName(source->getType());
|
||||
printTypeName(source->getType());
|
||||
|
||||
if (op1)
|
||||
{
|
||||
llvm::outs() << "\n\tLHS eval type: ";
|
||||
log.operand_lhs = printTypeName(op1->getType());
|
||||
printTypeName(op1->getType());
|
||||
}
|
||||
if (op2)
|
||||
{
|
||||
llvm::outs() << "\n\tRHS eval type: ";
|
||||
log.operand_rhs = printTypeName(op2->getType());
|
||||
printTypeName(op2->getType());
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,24 +8,19 @@
|
||||
#include <clang/ASTMatchers/ASTMatchers.h>
|
||||
#include <clang/ASTMatchers/ASTMatchFinder.h>
|
||||
|
||||
#include "OperationStorage.hpp"
|
||||
|
||||
class OperationFinder : public clang::ast_matchers::MatchFinder::MatchCallback
|
||||
{
|
||||
public:
|
||||
OperationFinder(const std::string& output_dir);
|
||||
|
||||
void addMatcher(clang::ast_matchers::MatchFinder& finder);
|
||||
|
||||
void run(const clang::ast_matchers::MatchFinder::MatchResult& result) override;
|
||||
virtual void run(const clang::ast_matchers::MatchFinder::MatchResult& result) override;
|
||||
private:
|
||||
void _processAssignment(const clang::ast_matchers::MatchFinder::MatchResult& result);
|
||||
void _processArithmetic(const clang::ast_matchers::MatchFinder::MatchResult& result);
|
||||
void _processCompoundStmt(const clang::ast_matchers::MatchFinder::MatchResult& result);
|
||||
void _processUnaryArithmetic(const clang::ast_matchers::MatchFinder::MatchResult& result);
|
||||
|
||||
void _processExpressionTypes(OperationStorage::Log& log, const clang::Expr* source, const clang::Expr* op1, const clang::Expr* op2);
|
||||
|
||||
OperationStorage _storage;
|
||||
void _processExpressionTypes(const clang::Expr* source, const clang::Expr* op1, const clang::Expr* op2);
|
||||
};
|
||||
|
||||
#endif //LLVM_PROTO_OPERATIONFINDER_HPP
|
||||
|
||||
@ -1,64 +0,0 @@
|
||||
//
|
||||
// Created by erki on 28.02.21.
|
||||
//
|
||||
|
||||
#include "OperationStorage.hpp"
|
||||
|
||||
#include <fstream>
|
||||
#include <filesystem>
|
||||
|
||||
#include <llvm/Support/CommandLine.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
void to_json(nlohmann::json& j, const OperationStorage::Log& l)
|
||||
{
|
||||
j = nlohmann::json{
|
||||
{"operation", l.operation},
|
||||
{"line", l.line},
|
||||
{"operand_lhs", l.operand_lhs},
|
||||
{"operand_rhs", l.operand_rhs},
|
||||
{"operand_result", l.operand_result}
|
||||
};
|
||||
}
|
||||
|
||||
void from_json(const nlohmann::json& j, OperationStorage::Log& l)
|
||||
{
|
||||
j.at("operation").get_to(l.operation);
|
||||
j.at("line").get_to(l.line);
|
||||
j.at("operand_lhs").get_to(l.operand_lhs);
|
||||
j.at("operand_rhs").get_to(l.operand_rhs);
|
||||
j.at("operand_result").get_to(l.operand_result);
|
||||
}
|
||||
|
||||
OperationStorage::OperationStorage(const std::string& output_filename)
|
||||
: _output_filename(output_filename)
|
||||
{ }
|
||||
|
||||
OperationStorage::~OperationStorage()
|
||||
{
|
||||
_dumpToFile();
|
||||
}
|
||||
|
||||
void OperationStorage::pushOperation(const std::string& filename, const Log& op)
|
||||
{
|
||||
auto it = _operations.find(filename);
|
||||
|
||||
if (it == _operations.end())
|
||||
it = _operations.insert({ filename, {} }).first;
|
||||
|
||||
it->second.push_back(op);
|
||||
}
|
||||
|
||||
const std::unordered_map<std::string, std::vector<OperationStorage::Log>>& OperationStorage::getOperations() const
|
||||
{
|
||||
return _operations;
|
||||
}
|
||||
|
||||
void OperationStorage::_dumpToFile()
|
||||
{
|
||||
nlohmann::json json = _operations;
|
||||
|
||||
std::ofstream file(_output_filename);
|
||||
|
||||
file << json;
|
||||
}
|
||||
@ -1,39 +0,0 @@
|
||||
//
|
||||
// Created by erki on 28.02.21.
|
||||
//
|
||||
|
||||
#ifndef C_ANALYZER_OPERATIONSTORAGE_HPP
|
||||
#define C_ANALYZER_OPERATIONSTORAGE_HPP
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
class OperationStorage
|
||||
{
|
||||
public:
|
||||
struct Log
|
||||
{
|
||||
std::string operation;
|
||||
unsigned int line;
|
||||
std::string operand_lhs;
|
||||
std::string operand_rhs;
|
||||
std::string operand_result;
|
||||
};
|
||||
|
||||
OperationStorage() = delete;
|
||||
OperationStorage(const OperationStorage&) = delete;
|
||||
|
||||
explicit OperationStorage(const std::string& output_filename);
|
||||
~OperationStorage();
|
||||
|
||||
void pushOperation(const std::string& filename, const Log& op);
|
||||
[[nodiscard]] const std::unordered_map<std::string, std::vector<Log>>& getOperations() const;
|
||||
private:
|
||||
std::unordered_map<std::string, std::vector<Log>> _operations;
|
||||
std::string _output_filename;
|
||||
|
||||
void _dumpToFile();
|
||||
};
|
||||
|
||||
#endif //C_ANALYZER_OPERATIONSTORAGE_HPP
|
||||
@ -13,20 +13,15 @@ using namespace llvm;
|
||||
|
||||
// Apply a custom category to all command-line options so that they are the
|
||||
// only ones displayed.
|
||||
static llvm::cl::OptionCategory MyToolCategory("op-finder options");
|
||||
|
||||
static llvm::cl::opt<std::string> OutputFile("o", cl::desc("File to output the JSON to."),
|
||||
cl::cat(MyToolCategory));
|
||||
static llvm::cl::OptionCategory MyToolCategory("opcounter options");
|
||||
|
||||
// CommonOptionsParser declares HelpMessage with a description of the common
|
||||
// command-line options related to the compilation database and input files.
|
||||
// It's nice to have this help message in all tools.
|
||||
static llvm::cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
|
||||
static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
|
||||
|
||||
// A help message for this specific tool can be added afterwards.
|
||||
static llvm::cl::extrahelp MoreHelp("\nThe program takes the input <source0> ... files, parses their\n"
|
||||
"AST and outputs a singular file containing a list of all noteworthy operations\n"
|
||||
"for later analysis.\n");
|
||||
static cl::extrahelp MoreHelp("\nMore help text...\n");
|
||||
|
||||
int main(int argc, const char** argv)
|
||||
{
|
||||
@ -42,7 +37,7 @@ int main(int argc, const char** argv)
|
||||
ClangTool Tool(OptionsParser.getCompilations(),
|
||||
OptionsParser.getSourcePathList());
|
||||
|
||||
OperationFinder op_finder(OutputFile.getValue());
|
||||
OperationFinder op_finder;
|
||||
MatchFinder finder;
|
||||
|
||||
op_finder.addMatcher(finder);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user