-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ff5088
commit ccee48b
Showing
14 changed files
with
837 additions
and
625 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
//===- assign_resolver.hpp --------------------------------------------===// | ||
// | ||
// Copyright (c) 2024 Junjie Shen | ||
// | ||
// see https://github.com/shenjunjiekoda/knight/blob/main/LICENSE for | ||
// license information. | ||
// | ||
//===------------------------------------------------------------------===// | ||
// | ||
// This header defines the assign resolver. | ||
// | ||
//===------------------------------------------------------------------===// | ||
|
||
#pragma once | ||
|
||
#include "dfa/analysis/core/symbol_resolver.hpp" | ||
#include "dfa/analysis_context.hpp" | ||
namespace knight::dfa { | ||
|
||
namespace internal { | ||
|
||
constexpr unsigned AssignmentContextAlignment = 64U; | ||
|
||
struct alignas(AssignmentContextAlignment) | ||
AssignmentContext { // NOLINT(altera-struct-pack-align) | ||
std::optional< const TypedRegion* > treg = std::nullopt; | ||
std::optional< const clang::Stmt* > stmt = std::nullopt; | ||
std::optional< const clang::Expr* > rhs_expr = std::nullopt; | ||
SExprRef lhs_sexpr{}; | ||
SExprRef rhs_sexpr{}; | ||
clang::BinaryOperator::Opcode op = clang::BinaryOperator::Opcode::BO_Assign; | ||
}; // struct AssignmentContext | ||
|
||
} // namespace internal | ||
|
||
class AssignResolver { | ||
private: | ||
AnalysisContext* m_ctx; | ||
const SymbolResolver* m_sym_resolver; | ||
|
||
public: | ||
AssignResolver(AnalysisContext* ctx, const SymbolResolver* sym_resolver) | ||
: m_ctx(ctx), m_sym_resolver(sym_resolver) {} | ||
|
||
public: | ||
[[nodiscard]] ProgramStateRef resolve(internal::AssignmentContext) const; | ||
|
||
private: | ||
void handle_int_assign(internal::AssignmentContext assign_ctx, | ||
SymbolRef res_sym, | ||
bool is_direct_assign, | ||
clang::BinaryOperator::Opcode op, | ||
ProgramStateRef& state, | ||
SExprRef& binary_sexpr) const; | ||
void handle_ptr_assign(internal::AssignmentContext assign_ctx, | ||
SymbolRef res_sym, | ||
bool is_direct_assign, | ||
clang::BinaryOperator::Opcode op, | ||
ProgramStateRef& state, | ||
SExprRef& binary_sexpr) const; | ||
}; // class AssignResolver | ||
|
||
} // namespace knight::dfa |
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,69 @@ | ||
//===- binary_op_resolver.hpp ------------------------------------------===// | ||
// | ||
// Copyright (c) 2024 Junjie Shen | ||
// | ||
// see https://github.com/shenjunjiekoda/knight/blob/main/LICENSE for | ||
// license information. | ||
// | ||
//===------------------------------------------------------------------===// | ||
// | ||
// This header defines the uanry op resolver. | ||
// | ||
//===------------------------------------------------------------------===// | ||
|
||
#pragma once | ||
|
||
#include "clang/AST/Expr.h" | ||
#include "dfa/analysis/core/symbol_resolver.hpp" | ||
#include "dfa/analysis/core/unary_op_resolver.hpp" | ||
#include "dfa/analysis_context.hpp" | ||
|
||
namespace knight::dfa { | ||
|
||
namespace internal { | ||
|
||
constexpr unsigned BinaryOperationContextAlignment = 128U; | ||
|
||
struct alignas(BinaryOperationContextAlignment) BinaryOperationContext { | ||
clang::BinaryOperator::Opcode op{}; | ||
// lhs_expr has value or lhs_sexpr has value | ||
std::optional< const clang::Expr* > lhs_expr; | ||
std::optional< SExprRef > lhs_sexpr; | ||
|
||
// rhs_expr has value or rhs_sexpr has value | ||
std::optional< const clang::Expr* > rhs_expr; | ||
std::optional< SExprRef > rhs_sexpr; | ||
|
||
clang::QualType result_type; | ||
const clang::Stmt* result_stmt{}; | ||
}; // struct BinaryOperationContext | ||
|
||
} // namespace internal | ||
|
||
class BinaryOpResolver { | ||
friend class UnaryOpResolver; | ||
|
||
private: | ||
AnalysisContext* m_ctx; | ||
const SymbolResolver* m_sym_resolver; | ||
|
||
public: | ||
explicit BinaryOpResolver(AnalysisContext* ctx, | ||
const SymbolResolver* sym_resolver) | ||
: m_ctx(ctx), m_sym_resolver(sym_resolver) {} | ||
|
||
public: | ||
void resolve(const clang::BinaryOperator*) const; | ||
|
||
private: | ||
void handle_binary_operation(internal::BinaryOperationContext) const; | ||
void handle_assign_binary_operation(internal::BinaryOperationContext) const; | ||
void handle_int_binary_operation(internal::BinaryOperationContext) const; | ||
void handle_int_non_assign_binary_operation( | ||
internal::BinaryOperationContext) const; | ||
void handle_ref_binary_operation(internal::BinaryOperationContext) const; | ||
void handle_ptr_binary_operation(internal::BinaryOperationContext) const; | ||
|
||
}; // class BinaryOpResolver | ||
|
||
} // namespace knight::dfa |
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
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,41 @@ | ||
//===- unary_op_resolver.hpp ------------------------------------------===// | ||
// | ||
// Copyright (c) 2024 Junjie Shen | ||
// | ||
// see https://github.com/shenjunjiekoda/knight/blob/main/LICENSE for | ||
// license information. | ||
// | ||
//===------------------------------------------------------------------===// | ||
// | ||
// This header defines the uanry op resolver. | ||
// | ||
//===------------------------------------------------------------------===// | ||
|
||
#pragma once | ||
|
||
#include "clang/AST/Expr.h" | ||
#include "dfa/analysis/core/symbol_resolver.hpp" | ||
#include "dfa/analysis_context.hpp" | ||
|
||
namespace knight::dfa { | ||
|
||
class UnaryOpResolver { | ||
private: | ||
AnalysisContext* m_ctx; | ||
const SymbolResolver* m_sym_resolver; | ||
|
||
public: | ||
explicit UnaryOpResolver(AnalysisContext* ctx, | ||
const SymbolResolver* sym_resolver) | ||
: m_ctx(ctx), m_sym_resolver(sym_resolver) {} | ||
|
||
public: | ||
void resolve(const clang::UnaryOperator*) const; | ||
|
||
private: | ||
void handle_int_unary_operation(const clang::UnaryOperator*) const; | ||
void handle_ptr_unary_operation(const clang::UnaryOperator*) const; | ||
|
||
}; // class UnaryOpResolver | ||
|
||
} // namespace knight::dfa |
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
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
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
Oops, something went wrong.