Skip to content

Commit

Permalink
fix release 0.2.0 (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
sole2 authored Nov 14, 2022
1 parent a13e5be commit 9273a02
Show file tree
Hide file tree
Showing 112 changed files with 256,770 additions and 702 deletions.
103,613 changes: 103,613 additions & 0 deletions helper/external/libc.a.json

Large diffs are not rendered by default.

150,366 changes: 150,366 additions & 0 deletions helper/external/libglib-2.0.a.json

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions include/ftg/astirmap/ASTDefNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@ class ASTDefNode {
ASTDefNode(clang::CXXCtorInitializer &CCI, clang::ASTUnit &U);

LocIndex getLocIndex() const;
const clang::SourceLocation &getSourceLocation() const;
const ASTNode &getAssignee() const;
const ASTNode *getAssigned() const;
const ASTNode *getNodeForType() const;
friend llvm::raw_ostream &operator<<(llvm::raw_ostream &, const ASTDefNode &);

private:
clang::SourceLocation SourceLoc;
LocIndex SourceLoc;
std::unique_ptr<ASTNode> Assignee;
std::unique_ptr<ASTNode> Assigned;
};

} // namespace ftg

#endif // FTG_ASTIRMAP_
#endif // FTG_ASTIRMAP_ASTDEFNODE_H
22 changes: 10 additions & 12 deletions include/ftg/astirmap/ASTNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define FTG_ASTIRMAP_ASTNODE_H

#include "ftg/astirmap/LocIndex.h"
#include "ftg/utils/LLVMUtil.h"
#include "clang/AST/ASTTypeTraits.h"
#include "clang/AST/Stmt.h"
#include "clang/Basic/SourceManager.h"
Expand All @@ -13,10 +14,9 @@ class ASTNode {
public:
enum nodeType { DECL, STMT, PARAM, CALL, CTORINIT };

ASTNode(nodeType Type, clang::ast_type_traits::DynTypedNode Node,
clang::ASTUnit &Unit);
ASTNode(nodeType Type, DynTypedNode Node, clang::ASTUnit &Unit);
const LocIndex &getIndex() const;
const clang::ast_type_traits::DynTypedNode &getNode() const;
const DynTypedNode &getNode() const;
nodeType getNodeType() const;
size_t getOffset() const;
unsigned getLength() const;
Expand All @@ -26,7 +26,7 @@ class ASTNode {
friend llvm::raw_ostream &operator<<(llvm::raw_ostream &, const ASTNode &);

private:
clang::ast_type_traits::DynTypedNode Node;
DynTypedNode Node;
LocIndex Index;
nodeType NodeType;
size_t Offset = 0;
Expand All @@ -35,18 +35,16 @@ class ASTNode {
clang::ASTUnit &Unit;

clang::SourceLocation
getBeginLoc(const clang::ast_type_traits::DynTypedNode &Node,
getBeginLoc(const DynTypedNode &Node,
const clang::SourceManager &SrcManager) const;
clang::SourceLocation
getEndLoc(const clang::ast_type_traits::DynTypedNode &Node,
const clang::SourceLocation &BeginLoc,
const clang::SourceManager &SrcManager) const;
clang::SourceLocation getEndLoc(const DynTypedNode &Node,
const clang::SourceLocation &BeginLoc,
const clang::SourceManager &SrcManager) const;
std::pair<unsigned, unsigned>
getLengthAndOffset(const clang::ast_type_traits::DynTypedNode &Node,
getLengthAndOffset(const DynTypedNode &Node,
const clang::SourceLocation &BeginLoc,
const clang::SourceManager &SrcManager) const;
clang::QualType
getType(const clang::ast_type_traits::DynTypedNode &Node) const;
clang::QualType getType(const DynTypedNode &Node) const;
};

} // namespace ftg
Expand Down
1 change: 1 addition & 0 deletions include/ftg/astirmap/CalledFunctionMacroMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define FTG_ASTIRMAP_CALLEDFUNCTIONMACROMAPPER_H

#include "MacroMapper.h"
#include <set>

namespace ftg {

Expand Down
3 changes: 2 additions & 1 deletion include/ftg/astirmap/DebugInfoMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "ftg/astirmap/ASTIRMap.h"
#include "ftg/astirmap/MacroMapper.h"
#include "ftg/sourceloader/SourceCollection.h"
#include <set>

namespace ftg {

Expand Down Expand Up @@ -60,4 +61,4 @@ class DebugInfoMap : public ASTIRMap {

} // namespace ftg

#endif // FTG_ASTIRMAP_ASTINFOMAP_H
#endif // FTG_ASTIRMAP_DEBUGINFOMAP_H
4 changes: 0 additions & 4 deletions include/ftg/astirmap/IRNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ class IRNode {
LocIndex Index;
std::string Name;

std::string getFullPath(const llvm::DebugLoc &Loc) const;
std::string getFullPath(const llvm::DIGlobalVariable &G) const;
std::string getFullPath(const llvm::DIFile &F) const;
void setIndex(const llvm::AllocaInst &I);
void setIndex(const llvm::GlobalValue &G);
void setIndex(const llvm::Instruction &I);
};

} // namespace ftg
Expand Down
14 changes: 12 additions & 2 deletions include/ftg/astirmap/LocIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,38 @@
#define FTG_ASTIRMAP_LOCINDEX_H

#include "clang/Basic/SourceManager.h"
#include "llvm/IR/Instructions.h"
#include <string>

namespace ftg {

class LocIndex {
public:
LocIndex();
LocIndex(std::string Path, size_t Line, size_t Column);
LocIndex(std::string Path, size_t Line, size_t Column,
bool FromMacro = false);
LocIndex(const clang::SourceManager &, const clang::SourceLocation &);

static LocIndex of(const llvm::AllocaInst &AI);
static LocIndex of(const llvm::Instruction &I);

std::string getPath() const;
size_t getLine() const;
size_t getColumn() const;
std::string getIDAsString() const;
bool isExpandedFromMacro() const;

bool operator<(const LocIndex &) const;
bool operator!=(const LocIndex &) const;
bool operator==(const LocIndex &Index) const;

protected:
private:
std::string Path;
size_t Line;
size_t Column;
bool FromMacro;

static std::string getFullPath(const llvm::DebugLoc &Loc);
};

} // namespace ftg
Expand Down
24 changes: 24 additions & 0 deletions include/ftg/indcallsolver/GlobalInitializerSolver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef FTG_INDCALLSOLVER_GLOBALINITIALIZERSOLVER_H
#define FTG_INDCALLSOLVER_GLOBALINITIALIZERSOLVER_H

#include "ftg/indcallsolver/GlobalInitializerSolverHandler.h"
#include "ftg/indcallsolver/IndCallSolver.h"
#include <llvm/IR/InstrTypes.h>
#include <llvm/IR/Module.h>
#include <set>

namespace ftg {

class GlobalInitializerSolver : public IndCallSolver {
public:
GlobalInitializerSolver(GlobalInitializerSolverHandler &&Handler);
std::set<const llvm::Function *>
solve(const llvm::CallBase &CB) const override;

private:
GlobalInitializerSolverHandler Handler;
};

} // namespace ftg

#endif // FTG_INDCALLSOLVER_GLOBALINITIALIZERSOLVER_H
30 changes: 30 additions & 0 deletions include/ftg/indcallsolver/GlobalInitializerSolverHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef FTG_INDCALLSOLVER_GLOBALINITIALIZERSOLVERHANDLER_H
#define FTG_INDCALLSOLVER_GLOBALINITIALIZERSOLVERHANDLER_H

#include "ftg/indcallsolver/LLVMWalkHandler.h"
#include <set>

namespace ftg {

class GlobalInitializerSolverHandler
: public LLVMWalkHandler<llvm::GlobalVariable> {
public:
GlobalInitializerSolverHandler() = default;
GlobalInitializerSolverHandler(GlobalInitializerSolverHandler &&Handler);
void handle(const llvm::GlobalVariable &GV) override;
std::set<const llvm::Function *> get(const llvm::Type *Ty,
unsigned Idx) const;

private:
struct MapKey {
const llvm::Type *Ty;
unsigned Idx;
MapKey(const llvm::Type *Ty, unsigned Idx);
bool operator<(const MapKey &Key) const;
};
std::map<MapKey, std::set<const llvm::Function *>> Map;
};

} // namespace ftg

#endif // FTG_INDCALLSOLVER_GLOBALINITIALIZERSOLVERHANDLER_H
6 changes: 3 additions & 3 deletions include/ftg/indcallsolver/IndCallSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
#define FTG_INDCALLSOLVER_INDCALLSOLVER_H

#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Module.h"
#include <set>

namespace ftg {

class IndCallSolver {

public:
virtual ~IndCallSolver() = default;
virtual void solve(llvm::Module &M) = 0;
virtual llvm::Function *getCalledFunction(llvm::CallBase &CB) = 0;
virtual std::set<const llvm::Function *>
solve(const llvm::CallBase &CB) const = 0;
};

} // namespace ftg
Expand Down
25 changes: 25 additions & 0 deletions include/ftg/indcallsolver/IndCallSolverMgr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef FTG_INDCALLSOLVER_INDCALLSOLVERMGR_H
#define FTG_INDCALLSOLVER_INDCALLSOLVERMGR_H

#include "ftg/indcallsolver/IndCallSolver.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/InstrTypes.h"
#include <set>

namespace ftg {

class IndCallSolverMgr {

public:
void solve(llvm::Module &M);
const llvm::Function *getCalledFunction(const llvm::CallBase &CB) const;
virtual std::set<const llvm::Function *>
getCalledFunctions(const llvm::CallBase &CB) const;

private:
std::vector<std::unique_ptr<IndCallSolver>> Solvers;
};

} // namespace ftg

#endif // FTG_INDCALLSOLVER_INDCALLSOLVERMGR_H
27 changes: 27 additions & 0 deletions include/ftg/indcallsolver/IndCallSolverUtil.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef FTG_INDCALLSOLVER_INDCALLSOLVERUTIL_HPP
#define FTG_INDCALLSOLVER_INDCALLSOLVERUTIL_HPP

#include <llvm/IR/Instructions.h>

namespace ftg {

static inline const llvm::MDNode *getTBAA(const llvm::Instruction *I) {
const auto *ExprI = I;
while (ExprI && (llvm::isa<llvm::LoadInst>(ExprI) ||
llvm::isa<llvm::GetElementPtrInst>(ExprI))) {
const auto *TBAA = ExprI->getMetadata(llvm::LLVMContext::MD_tbaa);
if (TBAA)
return TBAA;

const auto *Op = ExprI->getOperand(0);
if (!Op)
break;

ExprI = llvm::dyn_cast_or_null<llvm::Instruction>(Op->stripPointerCasts());
}
return nullptr;
}

} // namespace ftg

#endif // FTG_INDCALLSOLVER_INDCALLSOLVERUTIL_HPP
15 changes: 15 additions & 0 deletions include/ftg/indcallsolver/LLVMWalkHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef FTG_INDCALLSOLVER_LLVMWALKHANDLER_H
#define FTG_INDCALLSOLVER_LLVMWALKHANDLER_H

#include <llvm/IR/GlobalVariable.h>

namespace ftg {

template <typename T> class LLVMWalkHandler {
public:
virtual void handle(const T &IR) = 0;
};

} // namespace ftg

#endif // FTG_INDCALLSOLVER_LLVMWALKHANDLER_H
22 changes: 22 additions & 0 deletions include/ftg/indcallsolver/LLVMWalker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef FTG_INDCALLSOLVER_LLVMWALKER_H
#define FTG_INDCALLSOLVER_LLVMWALKER_H

#include "ftg/indcallsolver/LLVMWalkHandler.h"
#include <llvm/IR/Module.h>

namespace ftg {

class LLVMWalker {
public:
void addHandler(LLVMWalkHandler<llvm::GlobalVariable> *Handler);
void addHandler(LLVMWalkHandler<llvm::Instruction> *Handler);
void walk(const llvm::Module &M);

private:
std::vector<LLVMWalkHandler<llvm::GlobalVariable> *> GVHandlers;
std::vector<LLVMWalkHandler<llvm::Instruction> *> InstHandlers;
};

} // namespace ftg

#endif // FTG_INDCALLSOLVER_LLVMWALKER_H
25 changes: 25 additions & 0 deletions include/ftg/indcallsolver/TBAASimpleSolver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef FTG_INDCALLSOLVER_TBAASIMPLESOLVER_H
#define FTG_INDCALLSOLVER_TBAASIMPLESOLVER_H

#include "ftg/indcallsolver/IndCallSolver.h"
#include "ftg/indcallsolver/TBAASimpleSolverHandler.h"
#include <llvm/IR/InstrTypes.h>
#include <llvm/IR/Module.h>
#include <set>

namespace ftg {

class TBAASimpleSolver : public IndCallSolver {
public:
TBAASimpleSolver() = default;
TBAASimpleSolver(TBAASimpleSolverHandler &&Handler);
std::set<const llvm::Function *>
solve(const llvm::CallBase &CB) const override;

private:
TBAASimpleSolverHandler Handler;
};

} // namespace ftg

#endif // FTG_INDCALLSOLVER_TBAASIMPLESOLVER_H
31 changes: 31 additions & 0 deletions include/ftg/indcallsolver/TBAASimpleSolverHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef FTG_INDCALLSOLVER_TBAASIMPLESOLVERHANDLER_H
#define FTG_INDCALLSOLVER_TBAASIMPLESOLVERHANDLER_H

#include "ftg/indcallsolver/LLVMWalkHandler.h"
#include <llvm/IR/Instruction.h>
#include <map>
#include <set>

namespace ftg {

class TBAASimpleSolverHandler : public LLVMWalkHandler<llvm::Instruction> {
public:
TBAASimpleSolverHandler() = default;
TBAASimpleSolverHandler(TBAASimpleSolverHandler &&Handler);
std::set<const llvm::Function *> get(const llvm::MDNode *Node,
const llvm::Type *Ty) const;
void handle(const llvm::Instruction &I) override;

private:
struct MapKey {
const llvm::MDNode *Node;
const llvm::Type *Ty;
MapKey(const llvm::MDNode *Node, const llvm::Type *Ty);
bool operator<(const MapKey &Key) const;
};
std::map<MapKey, std::set<const llvm::Function *>> Map;
};

} // namespace ftg

#endif // FTG_INDCALLSOLVER_TBAASIMPLESOLVERHANDLER_H
Loading

0 comments on commit 9273a02

Please sign in to comment.