Skip to content

Commit

Permalink
blah
Browse files Browse the repository at this point in the history
  • Loading branch information
ragusaa committed Dec 15, 2023
1 parent c98cb2f commit b677c77
Showing 1 changed file with 1 addition and 64 deletions.
65 changes: 1 addition & 64 deletions libclambcc/ClamBCRebuild/ClamBCRebuild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include <llvm/ADT/DenseSet.h>
#include <llvm/Analysis/ValueTracking.h>
#include <llvm/Analysis/ScalarEvolution.h>
//#include <llvm/Analysis/ScalarEvolutionExpander.h>
#include <llvm/IR/BasicBlock.h>
#include <llvm/IR/Constants.h>
#include <llvm/IR/DerivedTypes.h>
Expand All @@ -49,13 +48,11 @@

using namespace llvm;

//class ClamBCRebuild : public ModulePass, public InstVisitor<ClamBCRebuild>
class ClamBCRebuild : public PassInfoMixin<ClamBCRebuild>, public InstVisitor<ClamBCRebuild>
{
public:
static char ID;
explicit ClamBCRebuild()
/* : ModulePass(ID) */ {}
explicit ClamBCRebuild() {}
virtual llvm::StringRef getPassName() const
{
return "ClamAV Bytecode Backend Rebuilder";
Expand Down Expand Up @@ -89,9 +86,6 @@ class ClamBCRebuild : public PassInfoMixin<ClamBCRebuild>, public InstVisitor<Cl
Builder = new IRBuilder<TargetFolder>(*Context, TF);

SE = nullptr;
#if 0
Expander = nullptr;
#endif

visitFunction(F, &NF);
for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) {
Expand Down Expand Up @@ -129,11 +123,6 @@ class ClamBCRebuild : public PassInfoMixin<ClamBCRebuild>, public InstVisitor<Cl
fixupCalls(F, copy);
F->setLinkage(GlobalValue::InternalLinkage);

#if 0
if (Expander) {
delete Expander;
}
#endif
delete Builder;
return true;
}
Expand Down Expand Up @@ -163,18 +152,6 @@ class ClamBCRebuild : public PassInfoMixin<ClamBCRebuild>, public InstVisitor<Cl
void fixupCallInst(CallInst *pCallInst, Function *pFunc)
{
assert(pCallInst->arg_size() == pFunc->arg_size() && "Incorrect number of arguments");
#if 1
DEBUGERR << "THIS SHOULD WORK FIGURE OUT WHY" << "<END>\n";
//assert(pCallInst->getCalledValue() == pFunc && "This CallInst doesn't call this function");
#else
DEBUG_VALUE(pCallInst);
DEBUG_NONPOINTER(pFunc->getName());
DEBUG_NONPOINTER((pCallInst->getCalledFunction() == pFunc));
DEBUG_NONPOINTER(pCallInst->getCalledFunction());
DEBUG_NONPOINTER(pFunc);
DEBUG_VALUE(pCallInst->getCalledFunction());
assert(pCallInst->getCalledFunction() == pFunc && "This CallInst doesn't call this function");
#endif

auto argIter = pFunc->arg_begin(), argEnd = pFunc->arg_end();
auto callIter = pCallInst->arg_begin(), callEnd = pCallInst->arg_end();
Expand Down Expand Up @@ -202,14 +179,12 @@ class ClamBCRebuild : public PassInfoMixin<ClamBCRebuild>, public InstVisitor<Cl
}
}

//bool runOnModule(Module &M)
PreservedAnalyses run(Module & M, ModuleAnalysisManager & MAM)
{
pMod = &M;

/* Taken from doInitialization. */
FMap.clear();
//FMapRev.clear();

Context = &(pMod->getContext());
i8Ty = Type::getInt8Ty(*Context);
Expand All @@ -229,7 +204,6 @@ class ClamBCRebuild : public PassInfoMixin<ClamBCRebuild>, public InstVisitor<Cl
runOnFunction(*pFunc);
}

// return true;
return PreservedAnalyses::none();
}

Expand All @@ -251,35 +225,16 @@ class ClamBCRebuild : public PassInfoMixin<ClamBCRebuild>, public InstVisitor<Cl
ScalarEvolution *SE = nullptr;
Type *i8Ty = nullptr;
Type *i8pTy = nullptr;
//FunctionPassManager *FPM = nullptr;
LLVMContext *Context = nullptr;
DenseSet<const BasicBlock *> visitedBB;
IRBuilder<TargetFolder> *Builder = nullptr;
#if 0
SCEVExpander *Expander = nullptr;
#endif

void stop(const std::string &Msg, const llvm::Instruction *I)
{
ClamBCStop(Msg, I);
}
friend class InstVisitor<ClamBCRebuild>;

#if 0
const Type *getInnerElementType(const CompositeType *CTy)
{
const Type *ETy = nullptr;
// get pointer to first element
do {
assert(CTy->indexValid(0u));
ETy = CTy->getTypeAtIndex(0u);
CTy = dyn_cast<CompositeType>(ETy);
} while (CTy);
assert(ETy->isIntegerTy());
return ETy;
}
#endif

Type *rebuildType(Type *Ty, bool i8only = false)
{
assert(Ty);
Expand Down Expand Up @@ -384,13 +339,8 @@ class ClamBCRebuild : public PassInfoMixin<ClamBCRebuild>, public InstVisitor<Cl
{
Value *PV = mapValue(P);
if (PV->getType() == Ty && !isa<AllocaInst>(PV)) {
#if 0
assert(!isa<AllocaInst>(PV) ||
cast<PointerType>(Ty)->getElementType()->isIntegerTy());
#else
assert(!isa<AllocaInst>(PV) ||
Ty->getPointerElementType()->isIntegerTy());
#endif

return PV;
}
Expand Down Expand Up @@ -649,18 +599,6 @@ class ClamBCRebuild : public PassInfoMixin<ClamBCRebuild>, public InstVisitor<Cl
return ret;
}
};
#if 0
char ClamBCRebuild::ID = 0;

static RegisterPass<ClamBCRebuild> X("clambc-rebuild", "ClamBCRebuild Pass",
false /* Only looks at CFG */,
false /* Analysis Pass */);

llvm::ModulePass *createClamBCRebuild(void)
{
return new ClamBCRebuild();
}
#else



Expand All @@ -686,7 +624,6 @@ llvmGetPassPluginInfo() {



#endif



Expand Down

0 comments on commit b677c77

Please sign in to comment.