Skip to content

Commit

Permalink
format the code and fix some minor bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ZHYfeng committed Jul 6, 2023
1 parent b956d50 commit 8f713c1
Show file tree
Hide file tree
Showing 28 changed files with 6,048 additions and 5,833 deletions.
File renamed without changes.
838 changes: 430 additions & 408 deletions lib/AnalysisLib/T_function.cpp

Large diffs are not rendered by default.

147 changes: 76 additions & 71 deletions lib/AnalysisLib/T_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,104 +5,109 @@
#ifndef INC_2021_TEMPLATE_T_FUNCTION_H
#define INC_2021_TEMPLATE_T_FUNCTION_H

#include "../ToolLib/basic.h"
#include "../KnowledgeLib/knowledge.h"
#include "../ToolLib/basic.h"

namespace sd {
class T_module;

// init and exit T_function number
enum callee_type {
callee_baisc = 0,
callee_not_isDeclaration,
callee_isDeclaration,
callee_indirect,
function_pointer,
};
class T_module;

class T_function;
// init and exit T_function number
enum callee_type {
callee_baisc = 0,
callee_not_isDeclaration,
callee_isDeclaration,
callee_indirect,
function_pointer,
};

class callee {
public:
llvm::Instruction *i{};
callee_type ct = callee_type::callee_baisc;
// for callee_not_isDeclaration and callee_isDeclaration
T_function *tf{};
// for callee_indirect and function_pointer
std::set<T_function *> *tf_set{};
// whether this callee is checked by k function
bool checked = false;
};
class T_function;

class T_function {
public:
explicit T_function(llvm::Function *f);
class callee {
public:
llvm::Instruction *i{};
callee_type ct = callee_type::callee_baisc;
// for callee_not_isDeclaration and callee_isDeclaration
T_function *tf{};
// for callee_indirect and function_pointer
std::set<T_function *> *tf_set{};
// whether this callee is checked by k function
bool checked = false;
};

virtual ~T_function();
class T_function {
public:
explicit T_function(llvm::Function *f);

[[nodiscard]] std::string get_name() const;
virtual ~T_function();

void check();
[[nodiscard]] std::string get_name() const;

void check(knowledge *k);
void check();

bool check_call(checker *c, llvm::CallInst *cs);
void check(knowledge *k);

void check_function_pointer(llvm::Instruction *i);
bool check_call(checker *c, llvm::CallInst *cs);

void check_function_pointer(llvm::Value *v, llvm::SmallPtrSet<const llvm::GlobalValue *, 3> &visited);
void check_function_pointer(llvm::Instruction *i);

callee *add_callee(llvm::Instruction *i, callee_type ct, T_function *tf = nullptr);
void check_function_pointer(
llvm::Value *v, llvm::SmallPtrSet<const llvm::GlobalValue *, 3> &visited);

callee *add_callee(llvm::Instruction *i, callee_type ct, std::set<T_function *> &tf);
callee *add_callee(llvm::Instruction *i, callee_type ct,
T_function *tf = nullptr);

void add_checker_result(checker *c, llvm::Instruction *i);
callee *add_callee(llvm::Instruction *i, callee_type ct,
std::set<T_function *> &tf);

void add_callee_checker_results(llvm::Instruction *i, T_function *t_f);
void add_checker_result(checker *c, llvm::Instruction *i);

void reset();
void add_callee_checker_results(llvm::Instruction *i, T_function *t_f);

// calculate path
llvm::DominatorTree *dominator_tree{};
void reset();

uint64_t calculate_path(llvm::BasicBlock *start_node, llvm::BasicBlock *end_node,
std::vector<llvm::BasicBlock *> *path);
// calculate path
llvm::DominatorTree *dominator_tree{};

uint64_t calculate_path(llvm::BasicBlock *start_node, std::set<llvm::BasicBlock *> *end_node,
std::vector<llvm::BasicBlock *> *path);
uint64_t calculate_path(llvm::BasicBlock *start_node,
llvm::BasicBlock *end_node,
std::vector<llvm::BasicBlock *> *path);

uint64_t calculate_path(std::set<llvm::Instruction *> *pass_node_i,
std::vector<llvm::BasicBlock *> *path);
uint64_t calculate_path(llvm::BasicBlock *start_node,
std::set<llvm::BasicBlock *> *end_node,
std::vector<llvm::BasicBlock *> *path);

uint64_t calculate_path(std::set<llvm::Instruction *> *pass_node_i,
std::vector<uint64_t> *path);
uint64_t calculate_path(std::set<llvm::Instruction *> *pass_node_i,
std::vector<llvm::BasicBlock *> *path);

public:
// for itself
llvm::Function *llvm_function;
T_module *t_module{};
uint64_t calculate_path(std::set<llvm::Instruction *> *pass_node_i,
std::vector<uint64_t> *path);

std::vector<callee *> all_callee;
// not include function pointers
std::map<llvm::Instruction *, callee *> all_callee_map;
// used for finding function pointers
std::set<T_function *> current_function_pointer;
public:
// for itself
llvm::Function *llvm_function;
T_module *t_module{};

// for caller
std::set<sd::T_function *> caller_not_isDeclaration;
std::set<sd::T_function *> caller_indirect;
std::set<sd::T_function *> caller_pointer;
std::vector<callee *> all_callee;
// not include function pointers
std::map<llvm::Instruction *, callee *> all_callee_map;
// used for finding function pointers
std::set<T_function *> current_function_pointer;

// checker results in current function
std::vector<sd::checker_result *> checker_results;
// for caller
std::set<sd::T_function *> caller_not_isDeclaration;
std::set<sd::T_function *> caller_indirect;
std::set<sd::T_function *> caller_pointer;

// number of checker, could be used for recursive check_callee analysis
int64_t num_checkers_check_callee;
int64_t num_checkers_check_caller;
// order is from caller to callee
std::map<llvm::Instruction *, std::set<sd::T_function *> *> all_callee_checker_results;
};
}
// checker results in current function
std::vector<sd::checker_result *> checker_results;

// number of checker, could be used for recursive check_callee analysis
int64_t num_checkers_check_callee;
int64_t num_checkers_check_caller;
// order is from caller to callee
std::map<llvm::Instruction *, std::set<sd::T_function *> *>
all_callee_checker_results;
};
} // namespace sd

#endif //INC_2021_TEMPLATE_T_FUNCTION_H
#endif // INC_2021_TEMPLATE_T_FUNCTION_H
Loading

0 comments on commit 8f713c1

Please sign in to comment.