From 8590560006c4d632430e31aa046f90e6bb13d6ba Mon Sep 17 00:00:00 2001 From: Aditi Date: Sun, 8 May 2022 15:35:24 +0530 Subject: [PATCH] func ptr api --- include/Token/Token.h | 6 +++++- lib/Token/Token.cpp | 28 +++++++++++++++++++--------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/include/Token/Token.h b/include/Token/Token.h index 54aa0c1..42aaa20 100644 --- a/include/Token/Token.h +++ b/include/Token/Token.h @@ -14,7 +14,7 @@ namespace spatial { -enum opTokenTy {isArray, isAlloca, isOpBitcast, isPhiGEPOpd, isIcmpGEPOpd, isOneGEPIndx, isFunArg}; +enum opTokenTy {isArray, isAlloca, isOpBitcast, isPhiGEPOpd, isIcmpGEPOpd, isOneGEPIndx, isFunPtr, isFunArg}; class Token { private: @@ -95,6 +95,8 @@ class Token { bool getIsIcmpGEPOpd(); void setIsOneGEPIndx(); bool getIsOneGEPIndx(); + void setIsFunPtr(); + bool getIsFunPtr(); void setIsFunArg(); bool getIsFunArg(); @@ -105,6 +107,8 @@ class Token { void setNullToken(); llvm::Type* getTy(); void setTy(llvm::Type*); + void setFunction(llvm::Function*); + llvm::Function* getFunction(); }; } // namespace spatial diff --git a/lib/Token/Token.cpp b/lib/Token/Token.cpp index 23ed5f3..e07695a 100644 --- a/lib/Token/Token.cpp +++ b/lib/Token/Token.cpp @@ -3,7 +3,7 @@ namespace spatial { Token::Token() { - this->TyLength = 7; + this->TyLength = 8; this->opTokenTy = llvm::BitVector(this->TyLength, false); } @@ -48,13 +48,15 @@ void Token::set(std::string S, unsigned int Kind, std::string Index, this->Func = Func; } -Token::Token(llvm::Value *Val, std::string Index) { - this->TyLength = 7; +Token::Token(llvm::Value *Val, std::string Index) { + this->TyLength = 8; this->opTokenTy = llvm::BitVector(this->TyLength, false); if (llvm::Argument *Arg = llvm::dyn_cast(Val)) { set(Arg, /* Kind = */ 2, Index, Arg->getParent()); + this->setIsGlobal(); + this->setIsFunArg(); } else { // If Val is GEPOperator, it must be coming from load/store if (llvm::GEPOperator *GOP = llvm::dyn_cast(Val)) { @@ -82,7 +84,7 @@ Token::Token(llvm::Value *Val, std::string Index) { } Token::Token(llvm::GEPOperator *GOP, llvm::Function *Func, std::string Index) { - this->TyLength = 7; + this->TyLength = 8; this->opTokenTy = llvm::BitVector(this->TyLength, false); llvm::Value *Val = GOP->getPointerOperand(); @@ -91,25 +93,25 @@ Token::Token(llvm::GEPOperator *GOP, llvm::Function *Func, std::string Index) { } Token::Token(llvm::Argument *Arg, std::string Index) { - this->TyLength = 7; + this->TyLength = 8; this->opTokenTy = llvm::BitVector(this->TyLength, false); set(Arg, /* Kind = */ 2, Index, Arg->getParent()); } Token::Token(llvm::Type *Ty, std::string Index) { - this->TyLength = 7; + this->TyLength = 8; this->opTokenTy = llvm::BitVector(this->TyLength, false); set(Ty, /* Kind = */ 1, Index); } Token::Token(std::string S, llvm::Function *Func, std::string Index) { - this->TyLength = 7; + this->TyLength = 8; this->opTokenTy = llvm::BitVector(this->TyLength, false); set(S, /* Kind = */ 3, Index, Func); } Token::Token(Token *A) { - this->TyLength = 7; + this->TyLength = 8; this->opTokenTy = llvm::BitVector(this->TyLength, false); unsigned int Kind = A->Kind; if (Kind == 0) { @@ -364,12 +366,15 @@ void Token::operator=(const Token &TheToken) { bool Token::getIsOneGEPIndx() { return opTokenTy.test(isOneGEPIndx); } + void Token::setIsFunPtr() { this->opTokenTy.set(isFunPtr); } + + bool Token::getIsFunPtr() { return opTokenTy.test(isFunPtr); } + void Token::setIsFunArg() { this->opTokenTy.set(isFunArg); } bool Token::getIsFunArg() { return opTokenTy.test(isFunArg); } - template std::vector Token::getGEPArrayIndex(GOP *G) { std::vector Idx; for (int i = 2; i < G->getNumOperands(); i++) { @@ -393,4 +398,9 @@ template std::vector Token::getGEPArrayIndex(llvm::GEPOp llvm::Type* Token::getTy() { return this->Ty;} void Token::setTy(llvm::Type* type) { this->Ty = type;} + + void Token::setFunction(llvm::Function* F) { this->Func = F; } + + llvm::Function* Token::getFunction() { return this->Func; } + } // namespace spatial