diff --git a/op-finder/OperationFinder.cpp b/op-finder/OperationFinder.cpp index 94f2cc2..431efc2 100644 --- a/op-finder/OperationFinder.cpp +++ b/op-finder/OperationFinder.cpp @@ -30,6 +30,7 @@ void OperationFinder::processArithmetic(const clang::BinaryOperator* op, const c log.line = line_number; log.operation = getOpcode(op).str(); log.current_for_loops = _for_loop_stack; + log.is_fallthrough = _in_fallthrough; _processExpressionTypes(log, op, op->getLHS(), op->getRHS()); @@ -56,6 +57,7 @@ void OperationFinder::processUnaryArithmetic(const clang::UnaryOperator* op, con log.line = line_number; log.operation = getOpcode(op).str(); log.current_for_loops = _for_loop_stack; + log.is_fallthrough = _in_fallthrough; _processExpressionTypes(log, op, lhs, nullptr); @@ -64,6 +66,16 @@ void OperationFinder::processUnaryArithmetic(const clang::UnaryOperator* op, con llvm::outs() << "\n"; } +void OperationFinder::fallthroughBranchEntered() +{ + _in_fallthrough = true; +} + +void OperationFinder::fallthroughBranchExited() +{ + _in_fallthrough = false; +} + void OperationFinder::forLoopEntered() { _for_loop_stack.push_back(_next_for_loop_id); diff --git a/op-finder/OperationFinder.hpp b/op-finder/OperationFinder.hpp index 1ac2ef5..9a06dee 100644 --- a/op-finder/OperationFinder.hpp +++ b/op-finder/OperationFinder.hpp @@ -17,6 +17,9 @@ public: void processArithmetic(const clang::BinaryOperator* op, const clang::SourceManager& source_manager); void processUnaryArithmetic(const clang::UnaryOperator* op, const clang::SourceManager& source_manager); + void fallthroughBranchEntered(); + void fallthroughBranchExited(); + void forLoopEntered(); void forLoopExited(); @@ -24,6 +27,7 @@ private: void _processExpressionTypes(OperationLog& log, const clang::Expr* source, const clang::Expr* op1, const clang::Expr* op2); int _next_for_loop_id = 0; + bool _in_fallthrough = false; std::vector _for_loop_stack; IOperationOutput* _storage; }; diff --git a/op-finder/OperationFinderAstVisitor.cpp b/op-finder/OperationFinderAstVisitor.cpp index 8d7249d..4d3e178 100644 --- a/op-finder/OperationFinderAstVisitor.cpp +++ b/op-finder/OperationFinderAstVisitor.cpp @@ -52,6 +52,7 @@ bool OperationFinderAstVisitor::dataTraverseStmtPre(clang::Stmt* stmt) if (loop->getInit()) { _loop_init = loop->getInit(); + _op_finder->fallthroughBranchEntered(); } else { @@ -69,6 +70,7 @@ bool OperationFinderAstVisitor::dataTraverseStmtPost(clang::Stmt* stmt) if (_loop_init && _loop_init == stmt) { _op_finder->forLoopEntered(); + _op_finder->fallthroughBranchExited(); _loop_init = nullptr; } else if (clang::dyn_cast(stmt)) diff --git a/op-finder/OperationLog.hpp b/op-finder/OperationLog.hpp index b17e819..cc549f0 100644 --- a/op-finder/OperationLog.hpp +++ b/op-finder/OperationLog.hpp @@ -14,6 +14,7 @@ struct OperationLog std::string operand_lhs; std::string operand_rhs; std::string operand_result; + bool is_fallthrough; std::vector current_for_loops; }; @@ -35,6 +36,7 @@ inline void to_json(nlohmann::json& j, const OperationLog& l) {"operand_lhs", l.operand_lhs}, {"operand_rhs", l.operand_rhs}, {"operand_result", l.operand_result}, + {"is_fallthrough", l.is_fallthrough}, {"current_for_loops", l.current_for_loops} }; } @@ -46,6 +48,7 @@ inline void from_json(const nlohmann::json& j, OperationLog& l) 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); + j.at("is_fallthrough").get_to(l.is_fallthrough); j.at("current_for_loops").get_to(l.current_for_loops); }