Skip to content

Commit

Permalink
Got a few more LLVM 11 upgrades in
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewQuijano committed Jul 9, 2024
1 parent 5cafe83 commit ab95b05
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions tools/lavaTool/src/lavaFnTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,16 @@ using namespace clang::ast_matchers;

using namespace std;


static llvm::raw_null_ostream null_ostream;
static llvm::raw_ostream &null_ostream = llvm::nulls();
#define debug(flag) ((DEBUG_FLAGS & (flag)) ? llvm::errs() : null_ostream)



static cl::OptionCategory LavaFnCategory("LAVA Function diagnosis");
static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
static cl::extrahelp MoreHelp(
"\nIdentify all fn defs, prototypes, calls for later use by LAVA.\n");

static void printVersion() {
errs() << "LavaFnTool Version -- " << LAVA_VER << "\n";
void printVersion(llvm::raw_ostream &OS) {
OS << "LavaFnTool Version -- " << LAVA_VER << "\n";
}

ofstream outfile;
Expand All @@ -56,7 +53,7 @@ void spit_fun_decl(const FunctionDecl *fundecl) {
outfile << " params: \n";
for (auto p : fundecl->parameters()) {
QualType ot = p->getOriginalType();
const Type *otp = ot.getTypePtr();
const clang::Type *otp = ot.getTypePtr();
if (otp->isFunctionType() || otp->isFunctionPointerType()) {
spit_type(" - param: fnptr ", ot);
}
Expand All @@ -68,8 +65,8 @@ void spit_fun_decl(const FunctionDecl *fundecl) {


void spit_source_locs(const char *spaces, const Expr *expr, const SourceManager &sm) {
auto sl1 = expr->getLocStart();
auto sl2 = expr->getLocEnd();
auto sl1 = expr->getBeginLoc();
auto sl2 = expr->getEndLoc();
outfile << (string(spaces) + "start: ") << sl1.printToString(sm) << "\n";
outfile << (string(spaces) + "end: ") << sl2.printToString(sm) << "\n";
}
Expand Down Expand Up @@ -155,14 +152,14 @@ class CallPrinter : public MatchFinder::MatchCallback {
std::string fun_name = get_containing_function_name(Result, *call);
outfile << " containing_function: " << fun_name << "\n";

QualType rt = call->getCallReturnType();//(Result.Context);
QualType rt = call->getDirectCallee()->getReturnType();
spit_type( " ret_type: ", rt);
outfile << " args: \n";
for (auto it = call->arg_begin(); it != call->arg_end(); ++it) {
const Expr *arg = dyn_cast<Expr>(*it);
arg = arg->IgnoreImpCasts();
QualType at = arg->IgnoreImpCasts()->getType();
const Type *atp = at.getTypePtr();
const clang::Type *atp = at.getTypePtr();
string expstr, type, info;
outfile << " - arg: \n";
if (atp->isFunctionType()) {
Expand Down Expand Up @@ -201,7 +198,7 @@ class FnPtrAssignmentPrinter : public MatchFinder::MatchCallback {
virtual void run(const MatchFinder::MatchResult &Result) {
const BinaryOperator *bo = Result.Nodes.getNodeAs<BinaryOperator>("bo");
Expr *rhs = bo->getRHS()->IgnoreImpCasts();
const Type *rhst = rhs->getType().getTypePtr();
const clang::Type *rhst = rhs->getType().getTypePtr();
if (rhst->isFunctionType()) {
outfile << "- fnPtrAssign: \n";
spit_source_locs(" ", bo, *Result.SourceManager);
Expand All @@ -219,14 +216,14 @@ class VarDeclPrinter : public MatchFinder::MatchCallback {
public :
virtual void run(const MatchFinder::MatchResult &Result) {
const VarDecl *vd = Result.Nodes.getNodeAs<VarDecl>("vd");
const Type *et = vd->getType().getTypePtr();
const clang::Type *et = vd->getType().getTypePtr();
if (vd->hasInit() && et->isPointerType()) {
const Expr *init = vd->getInit()->IgnoreImpCasts();
const Type *it = init->getType().getTypePtr();
const clang::Type *it = init->getType().getTypePtr();
if (it->isFunctionType()) {
outfile << "- fnPtrAssign:\n";
auto sl1 = vd->getLocStart();
auto sl2 = vd->getLocEnd();
auto sl1 = vd->getBeginLoc();
auto sl2 = vd->getEndLoc();
outfile << " start: " << sl1.printToString(*Result.SourceManager) << "\n";
outfile << " end: " << sl2.printToString(*Result.SourceManager) << "\n";
const DeclRefExpr *dre = llvm::dyn_cast<DeclRefExpr>(init);
Expand All @@ -248,8 +245,8 @@ class FunctionPrinter : public MatchFinder::MatchCallback {
// if (func->isExternC()) return;
if (func) {
outfile << "- fun: \n";
auto sl1 = func->getLocStart();
auto sl2 = func->getLocEnd();
auto sl1 = func->getBeginLoc();
auto sl2 = func->getEndLoc();
outfile << " start: " << sl1.printToString(*Result.SourceManager) << "\n";
outfile << " end: " << sl2.printToString(*Result.SourceManager) << "\n";
outfile << " name: " << (func->getNameInfo().getAsString()) << "\n";
Expand Down

0 comments on commit ab95b05

Please sign in to comment.