aboutsummaryrefslogtreecommitdiffstats
path: root/bruiser
diff options
context:
space:
mode:
Diffstat (limited to 'bruiser')
-rw-r--r--bruiser/bruiser.cpp494
-rw-r--r--bruiser/bruiser.h53
-rw-r--r--bruiser/lua-scripts/wasmtest.lua1
3 files changed, 101 insertions, 447 deletions
diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp
index 54b632e..ae6db23 100644
--- a/bruiser/bruiser.cpp
+++ b/bruiser/bruiser.cpp
@@ -618,13 +618,11 @@ class CompilationDatabaseProcessor {
};
/**********************************************************************************************************************/
/*the implementation of the bruiser logger.*/
-bruiser::BruiserReport::BruiserReport ()
-{
+bruiser::BruiserReport::BruiserReport () {
BruiserLog.open("bruiser.log");
}
-bruiser::BruiserReport::~BruiserReport()
-{
+bruiser::BruiserReport::~BruiserReport() {
BruiserLog.close();
}
@@ -636,8 +634,7 @@ bruiser::BruiserReport::~BruiserReport()
* @return Returns true if the write was successful, false otherwise.
*/
template <typename T>
-bool bruiser::BruiserReport::PrintToLog(T __arg)
-{
+bool bruiser::BruiserReport::PrintToLog(T __arg) {
BruiserLog << __arg << "\n";
return !BruiserLog.bad();
}
@@ -646,184 +643,42 @@ bruiser::TypeInfo::TypeInfo(const clang::ast_type_traits::DynTypedNode* __dtn) :
bruiser::TypeInfo::~TypeInfo() {};
-const clang::Type* bruiser::TypeInfo::getTypeInfo(clang::ASTContext* __astc)
-{
+const clang::Type* bruiser::TypeInfo::getTypeInfo(clang::ASTContext* __astc) {
const clang::Expr* EXP = DTN->get<clang::Expr>();
-
const clang::Type* TP = EXP->getType().getTypePtr();
-
return __astc->getCanonicalType(TP);
}
/**********************************************************************************************************************/
-class AbstractMatcherHandler : public virtual MatchFinder::MatchCallback
-{
- public:
- AbstractMatcherHandler (Rewriter &Rewrite) : R(Rewrite) {}
-
- public:
- virtual void run(const MatchFinder::MatchResult &MR)
- {
-
- }
-
- private:
- Rewriter &R [[maybe_unused]];
-};
-/**********************************************************************************************************************/
-class MatcherHandlerLVL0 : public AbstractMatcherHandler
-{
- public:
- explicit MatcherHandlerLVL0 (Rewriter &Rewrite) : AbstractMatcherHandler(Rewrite) {}
-
- virtual ~MatcherHandlerLVL0() {}
-
- virtual void run(const MatchFinder::MatchResult &MR) override
- {
-
- }
-
- private:
-};
-/**********************************************************************************************************************/
-class NameFinder
-{
- public:
- NameFinder () {}
-
- class runDeclRefExprMatcher
- {
- public:
- runDeclRefExprMatcher (Rewriter &__rwrt) : LVL0Proto(__rwrt), __rwrt(__rwrt) {}
-
- virtual void runMatcher(const StringRef __sr, ASTContext &__ctx)
- {
- Matcher.addMatcher(declRefExpr(to(namedDecl(hasName(__sr.str())))).bind("declrefexpbyname"), &LVL0Proto);
- Matcher.matchAST(__ctx);
- }
-
- private:
- MatchFinder Matcher;
- MatcherHandlerLVL0 LVL0Proto;
- Rewriter __rwrt;
- StringRef __sr;
- };
-
- class runNamedDeclMatcher
- {
- public:
- runNamedDeclMatcher (Rewriter &__rwrt) : LVL0Proto(__rwrt), __rwrt(__rwrt) {}
-
- virtual void runMatcher(const StringRef __sr, ASTContext &__ctx)
- {
- Matcher.addMatcher(declRefExpr(to(namedDecl(hasName(__sr.str())))).bind("nameddeclbyname"), &LVL0Proto);
- Matcher.matchAST(__ctx);
- }
-
- private:
- MatchFinder Matcher;
- MatcherHandlerLVL0 LVL0Proto;
- Rewriter __rwrt;
- StringRef __sr;
- };
-
- private:
-};
-/**********************************************************************************************************************/
-/**********************************************************************************************************************/
-/**********************************************************************************************************************/
-class IfBreaker : public MatchFinder::MatchCallback
-{
- public:
- IfBreaker (Rewriter &Rewrite) : Rewrite(Rewrite) {}
-
- virtual void run(const MatchFinder::MatchResult &MR)
- {
- if (MR.Nodes.getNodeAs<clang::UnaryOperator>("uno") != nullptr)
- {
- const clang::UnaryOperator* UO = MR.Nodes.getNodeAs<clang::UnaryOperator>("uno");
-
- SourceLocation SL = UO->getLocStart();
- CheckSLValidity(SL);
- SL = Devi::SourceLocationHasMacro(SL, Rewrite);
-
- const Expr* EXP = UO->getSubExpr();
- const ast_type_traits::DynTypedNode DynNode = ast_type_traits::DynTypedNode::create<clang::Expr>(*EXP);
- bruiser::TypeInfo TIProto(&DynNode);
-
- const clang::Type* CTP [[maybe_unused]] = TIProto.getTypeInfo(MR.Context);
-
- NameFinder::runDeclRefExprMatcher DRENameMatcher(Rewrite);
-
- DRENameMatcher.runMatcher(StringRef(), *MR.Context);
- }
-
- if (MR.Nodes.getNodeAs<clang::BinaryOperator>("dous") != nullptr)
- {
- const clang::BinaryOperator* BO = MR.Nodes.getNodeAs<clang::BinaryOperator>("dous");
-
- SourceLocation SL = BO->getLocStart();
- CheckSLValidity(SL);
- SL = Devi::SourceLocationHasMacro(SL, Rewrite);
-
- const Expr* LHS = BO->getLHS();
- const Expr* RHS = BO->getRHS();
-
- QualType LQT = LHS->getType();
- QualType RQT = RHS->getType();
-
- const clang::Type* LTP = LQT.getTypePtr();
- const clang::Type* RTP = RQT.getTypePtr();
-
- const clang::Type* CLTP [[maybe_unused]] = MR.Context->getCanonicalType(LTP);
- const clang::Type* CRTP [[maybe_unused]] = MR.Context->getCanonicalType(RTP);
- }
- }
-
- private:
- Rewriter &Rewrite;
- MatchFinder Matcher;
-};
/**********************************************************************************************************************/
/**
* @brief Hijacks the main main and replaces it with bruiser's main.
*/
-class MainWrapper : public MatchFinder::MatchCallback
-{
+class MainWrapper : public MatchFinder::MatchCallback {
public:
MainWrapper (Rewriter &Rewrite) : Rewrite(Rewrite) {}
- virtual void run(const MatchFinder::MatchResult &MR)
- {
- if (MR.Nodes.getNodeAs<clang::FunctionDecl>("mainwrapper") != nullptr)
- {
+ virtual void run(const MatchFinder::MatchResult &MR) {
+ if (MR.Nodes.getNodeAs<clang::FunctionDecl>("mainwrapper") != nullptr) {
const FunctionDecl* FD = MR.Nodes.getNodeAs<clang::FunctionDecl>("mainwrapper");
SourceLocation SL = FD->getLocStart();
CheckSLValidity(SL);
SL = Devi::SourceLocationHasMacro(SL, Rewrite);
-
SourceLocation SLE = FD->getLocEnd();
CheckSLValidity(SLE);
SLE = Devi::SourceLocationHasMacro(SLE, Rewrite);
- if (!Devi::IsTheMatchInMainFile(MainFileOnly, MR, SL) || Devi::IsTheMatchInSysHeader(CheckSystemHeader, MR, SL))
- {
+ if (!Devi::IsTheMatchInMainFile(MainFileOnly, MR, SL) || Devi::IsTheMatchInSysHeader(CheckSystemHeader, MR, SL)) {
return void();
}
SourceRange SR(SL, SLE);
-
std::string MainSig = Rewrite.getRewrittenText(SR);
-
size_t mainbegin = MainSig.find("main");
-
StringRef __sr("sub_main");
-
Rewrite.ReplaceText(SL.getLocWithOffset(mainbegin), 4U, __sr);
-
/*@DEVI-obviously the best way to do this is to use the main signature already used, instead of going with a general predefined one. the current form is a temp.*/
Rewrite.InsertTextAfter(SLE.getLocWithOffset(1U), StringRef("\n\nint main(int argc, const char **argv)\n{\n\treturn sub_main(argc, argv);\n}\n"));
-
//BruiseRep.PrintToLog("hijacked main main.");
}
}
@@ -832,36 +687,29 @@ public:
Rewriter &Rewrite;
};
/**********************************************************************************************************************/
-class LiveListFuncs : public MatchFinder::MatchCallback
-{
+class LiveListFuncs : public MatchFinder::MatchCallback {
public:
LiveListFuncs (Rewriter &R) : R(R) {}
- virtual void run(const MatchFinder::MatchResult &MR)
- {
- if (MR.Nodes.getNodeAs<clang::FunctionDecl>("livelistfuncs") != nullptr)
- {
+ virtual void run(const MatchFinder::MatchResult &MR) {
+ if (MR.Nodes.getNodeAs<clang::FunctionDecl>("livelistfuncs") != nullptr) {
const clang::FunctionDecl* FD = MR.Nodes.getNodeAs<clang::FunctionDecl>("livelistfuncs");
SourceLocation SL = FD->getLocStart();
CheckSLValidity(SL);
SL = Devi::SourceLocationHasMacro(SL, R);
- if (!Devi::IsTheMatchInMainFile(MainFileOnly, MR, SL) || Devi::IsTheMatchInSysHeader(CheckSystemHeader, MR, SL))
- {
+ if (!Devi::IsTheMatchInMainFile(MainFileOnly, MR, SL) || Devi::IsTheMatchInSysHeader(CheckSystemHeader, MR, SL)) {
return void();
}
- if (FD->hasBody())
- {
+ if (FD->hasBody()) {
Stmt* Body = FD->getBody();
SourceLocation SLBody = Body->getLocStart();
SourceLocation SLShebang = FD->getLocStart();
PRINT_WITH_COLOR_LB(CYAN, R.getRewrittenText(clang::SourceRange(SLShebang, SLBody.getLocWithOffset(-1))).c_str());
PushToLua.push_back(R.getRewrittenText(clang::SourceRange(SLShebang, SLBody.getLocWithOffset(-1))));
- }
- else
- {
+ } else {
SourceLocation SL = FD->getLocStart();
SourceLocation SLE = FD->getLocEnd();
PRINT_WITH_COLOR_LB(CYAN, R.getRewrittenText(clang::SourceRange(SL, SLE)).c_str());
@@ -874,23 +722,19 @@ class LiveListFuncs : public MatchFinder::MatchCallback
Rewriter R;
};
/**********************************************************************************************************************/
-class LiveListVars : public MatchFinder::MatchCallback
-{
+class LiveListVars : public MatchFinder::MatchCallback {
public:
LiveListVars (Rewriter &R) : R(R) {}
- virtual void run(const MatchFinder::MatchResult &MR)
- {
- if (MR.Nodes.getNodeAs<clang::VarDecl>("livelistvars") != nullptr)
- {
+ virtual void run(const MatchFinder::MatchResult &MR) {
+ if (MR.Nodes.getNodeAs<clang::VarDecl>("livelistvars") != nullptr) {
const clang::VarDecl* VD = MR.Nodes.getNodeAs<clang::VarDecl>("livelistvars");
SourceLocation SL = VD->getLocStart();
CheckSLValidity(SL);
SL = Devi::SourceLocationHasMacro(SL, R);
- if (!Devi::IsTheMatchInMainFile(MainFileOnly, MR, SL) || Devi::IsTheMatchInSysHeader(CheckSystemHeader, MR, SL))
- {
+ if (!Devi::IsTheMatchInMainFile(MainFileOnly, MR, SL) || Devi::IsTheMatchInSysHeader(CheckSystemHeader, MR, SL)) {
return void();
}
@@ -903,15 +747,12 @@ class LiveListVars : public MatchFinder::MatchCallback
Rewriter R;
};
/**********************************************************************************************************************/
-class LiveListRecords : public MatchFinder::MatchCallback
-{
+class LiveListRecords : public MatchFinder::MatchCallback {
public:
LiveListRecords (Rewriter &R) : R(R) {}
- virtual void run(const MatchFinder::MatchResult &MR)
- {
- if (MR.Nodes.getNodeAs<clang::RecordDecl>("livelistvars") != nullptr)
- {
+ virtual void run(const MatchFinder::MatchResult &MR) {
+ if (MR.Nodes.getNodeAs<clang::RecordDecl>("livelistvars") != nullptr) {
const clang::RecordDecl* RD = MR.Nodes.getNodeAs<clang::RecordDecl>("livelistvars");
PRINT_WITH_COLOR_LB(CYAN, R.getRewrittenText(SourceRange(RD->getLocStart(), RD->getLocEnd())).c_str());
@@ -924,76 +765,27 @@ class LiveListRecords : public MatchFinder::MatchCallback
};
/**********************************************************************************************************************/
/**********************************************************************************************************************/
-/**********************************************************************************************************************/
-/**********************************************************************************************************************/
-/**********************************************************************************************************************/
-/**********************************************************************************************************************/
-/**********************************************************************************************************************/
class BruiserASTConsumer : public ASTConsumer {
-
public:
- BruiserASTConsumer(Rewriter &R) : HIfBreaker(R), HMainWrapper(R)
- {}
-
- void HandleTranslationUnit(ASTContext &Context) override
- {
- Matcher.addMatcher(ifStmt(hasDescendant(expr(anyOf(unaryOperator().bind("uno"), binaryOperator().bind("dous"))))), &HIfBreaker);
+ BruiserASTConsumer(Rewriter &R) : HMainWrapper(R) {}
+ void HandleTranslationUnit(ASTContext &Context) override {
Matcher.addMatcher(functionDecl(hasName("main")).bind("mainwrapper"), &HMainWrapper);
-
-
Matcher.matchAST(Context);
}
private:
- IfBreaker HIfBreaker;
MainWrapper HMainWrapper;
MatchFinder Matcher;
Rewriter R;
};
/**********************************************************************************************************************/
-class LiveConsumerFactory
-{
+class LiveListVarsConsumer : public ASTConsumer {
public:
- LiveConsumerFactory() {}
+ LiveListVarsConsumer(Rewriter &R) : HLLVars(R) {}
- template<typename T>
- void operator()(T __consumer)
- {
-
- }
-
-};
-/**********************************************************************************************************************/
-class LiveConsumer : public ASTConsumer
-{
- public:
- LiveConsumer(Rewriter &R) : HLLVars(R), HLLFuncs(R), HLLRecords(R)
- {}
-
- void HandleTranslationUnit(ASTContext &ctx) override
- {
- Matcher.matchAST(ctx);
- }
-
- private:
- MatchFinder Matcher;
- LiveListVars HLLVars;
- LiveListFuncs HLLFuncs;
- LiveListRecords HLLRecords;
- Rewriter R;
-};
-/**********************************************************************************************************************/
-class LiveListVarsConsumer : public ASTConsumer
-{
- public:
- LiveListVarsConsumer(Rewriter &R) : HLLVars(R)
- {}
-
- void HandleTranslationUnit(ASTContext &ctx) override
- {
+ void HandleTranslationUnit(ASTContext &ctx) override {
Matcher.addMatcher(varDecl().bind("livelistvars"), &HLLVars);
-
Matcher.matchAST(ctx);
}
@@ -1003,16 +795,12 @@ class LiveListVarsConsumer : public ASTConsumer
MatchFinder Matcher;
};
/**********************************************************************************************************************/
-class LiveListFuncsConsumer : public ASTConsumer
-{
+class LiveListFuncsConsumer : public ASTConsumer {
public:
- LiveListFuncsConsumer(Rewriter &R) : HLLFuncs(R)
- {}
+ LiveListFuncsConsumer(Rewriter &R) : HLLFuncs(R) {}
- void HandleTranslationUnit(ASTContext &ctx) override
- {
+ void HandleTranslationUnit(ASTContext &ctx) override {
Matcher.addMatcher(functionDecl().bind("livelistfuncs"), &HLLFuncs);
-
Matcher.matchAST(ctx);
}
@@ -1022,16 +810,12 @@ class LiveListFuncsConsumer : public ASTConsumer
Rewriter R;
};
/**********************************************************************************************************************/
-class LiveListClassConsumer : public ASTConsumer
-{
+class LiveListClassConsumer : public ASTConsumer {
public:
- LiveListClassConsumer(Rewriter &R) : HLLRecords(R)
- {}
+ LiveListClassConsumer(Rewriter &R) : HLLRecords(R) {}
- void HandleTranslationUnit(ASTContext &ctx) override
- {
+ void HandleTranslationUnit(ASTContext &ctx) override {
Matcher.addMatcher(recordDecl(isClass()).bind("livelistclass"), &HLLRecords);
-
Matcher.matchAST(ctx);
}
@@ -1041,16 +825,12 @@ class LiveListClassConsumer : public ASTConsumer
Rewriter R;
};
/**********************************************************************************************************************/
-class LiveListStructConsumer : public ASTConsumer
-{
+class LiveListStructConsumer : public ASTConsumer {
public:
- LiveListStructConsumer(Rewriter &R) : HLLRecords(R)
- {}
+ LiveListStructConsumer(Rewriter &R) : HLLRecords(R) {}
- void HandleTranslationUnit(ASTContext &ctx) override
- {
+ void HandleTranslationUnit(ASTContext &ctx) override {
Matcher.addMatcher(recordDecl(isStruct()).bind("liveliststruct"), &HLLRecords);
-
Matcher.matchAST(ctx);
}
@@ -1060,16 +840,12 @@ class LiveListStructConsumer : public ASTConsumer
Rewriter R;
};
/**********************************************************************************************************************/
-class LiveListUnionConsumer : public ASTConsumer
-{
+class LiveListUnionConsumer : public ASTConsumer {
public:
- LiveListUnionConsumer(Rewriter &R) : HLLRecords(R)
- {}
+ LiveListUnionConsumer(Rewriter &R) : HLLRecords(R) {}
- void HandleTranslationUnit(ASTContext &ctx) override
- {
+ void HandleTranslationUnit(ASTContext &ctx) override {
Matcher.addMatcher(recordDecl(isUnion()).bind("livelistclass"), &HLLRecords);
-
Matcher.matchAST(ctx);
}
@@ -1079,16 +855,12 @@ class LiveListUnionConsumer : public ASTConsumer
Rewriter R;
};
/**********************************************************************************************************************/
-class LiveListArrayConsumer : public ASTConsumer
-{
+class LiveListArrayConsumer : public ASTConsumer {
public:
- LiveListArrayConsumer(Rewriter &R) : HLLVars(R)
- {}
+ LiveListArrayConsumer(Rewriter &R) : HLLVars(R) {}
- void HandleTranslationUnit(ASTContext &ctx) override
- {
+ void HandleTranslationUnit(ASTContext &ctx) override {
Matcher.addMatcher(varDecl(hasType(arrayType())).bind("livelistvars"), &HLLVars);
-
Matcher.matchAST(ctx);
}
@@ -1099,28 +871,22 @@ class LiveListArrayConsumer : public ASTConsumer
};
/**********************************************************************************************************************/
/**********************************************************************************************************************/
-/**********************************************************************************************************************/
-/**********************************************************************************************************************/
-class BlankDiagConsumer : public clang::DiagnosticConsumer
-{
+class BlankDiagConsumer : public clang::DiagnosticConsumer {
public:
BlankDiagConsumer() = default;
virtual ~BlankDiagConsumer() {}
virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) override {}
};
/**********************************************************************************************************************/
-class BruiserFrontendAction : public ASTFrontendAction
-{
+class BruiserFrontendAction : public ASTFrontendAction {
public:
BruiserFrontendAction() {}
- virtual ~BruiserFrontendAction()
- {
+ virtual ~BruiserFrontendAction() {
delete BDCProto;
delete tee;
}
- void EndSourceFileAction() override
- {
+ void EndSourceFileAction() override {
std::error_code EC;
std::string OutputFilename = "./libtooling-tee";
TheRewriter.getEditBuffer(TheRewriter.getSourceMgr().getMainFileID()).write(llvm::outs());
@@ -1128,8 +894,7 @@ public:
TheRewriter.getEditBuffer(TheRewriter.getSourceMgr().getMainFileID()).write(*tee);
}
- std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override
- {
+ std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override {
DiagnosticsEngine &DE = CI.getPreprocessor().getDiagnostics();
DE.setClient(BDCProto, false);
TheRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts());
@@ -1142,19 +907,16 @@ private:
raw_ostream *tee = &llvm::outs();
};
/**********************************************************************************************************************/
-class LiveActionListVars : public ASTFrontendAction
-{
+class LiveActionListVars : public ASTFrontendAction {
public:
LiveActionListVars() = default;
- virtual ~LiveActionListVars()
- {
+ virtual ~LiveActionListVars() {
delete BDCProto;
}
void EndSourceFileAction() override {}
- std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override
- {
+ std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override {
DiagnosticsEngine &DE = CI.getPreprocessor().getDiagnostics();
DE.setClient(BDCProto, false);
TheRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts());
@@ -1166,19 +928,16 @@ class LiveActionListVars : public ASTFrontendAction
BlankDiagConsumer* BDCProto = new BlankDiagConsumer();
};
/**********************************************************************************************************************/
-class LiveActionListFuncs : public ASTFrontendAction
-{
+class LiveActionListFuncs : public ASTFrontendAction {
public:
LiveActionListFuncs() {}
- ~LiveActionListFuncs()
- {
+ ~LiveActionListFuncs() {
delete BDCProto;
}
void EndSourceFileAction() override {}
- std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override
- {
+ std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override {
DiagnosticsEngine &DE = CI.getPreprocessor().getDiagnostics();
DE.setClient(BDCProto, false);
TheRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts());
@@ -1190,19 +949,16 @@ class LiveActionListFuncs : public ASTFrontendAction
BlankDiagConsumer* BDCProto = new BlankDiagConsumer;
};
/**********************************************************************************************************************/
-class LiveActionListStructs : public ASTFrontendAction
-{
+class LiveActionListStructs : public ASTFrontendAction {
public:
LiveActionListStructs() {}
- ~LiveActionListStructs()
- {
+ ~LiveActionListStructs() {
delete BDCProto;
}
void EndSourceFileAction() override {}
- std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override
- {
+ std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override {
DiagnosticsEngine &DE = CI.getPreprocessor().getDiagnostics();
DE.setClient(BDCProto, false);
TheRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts());
@@ -1214,19 +970,16 @@ class LiveActionListStructs : public ASTFrontendAction
BlankDiagConsumer* BDCProto = new BlankDiagConsumer;
};
/**********************************************************************************************************************/
-class LiveActionListClasses : public ASTFrontendAction
-{
+class LiveActionListClasses : public ASTFrontendAction {
public:
LiveActionListClasses() {}
- ~LiveActionListClasses()
- {
+ ~LiveActionListClasses() {
delete BDCProto;
}
void EndSourceFileAction() override {}
- std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override
- {
+ std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override {
DiagnosticsEngine &DE = CI.getPreprocessor().getDiagnostics();
DE.setClient(BDCProto, false);
TheRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts());
@@ -1238,19 +991,16 @@ class LiveActionListClasses : public ASTFrontendAction
BlankDiagConsumer* BDCProto = new BlankDiagConsumer;
};
/**********************************************************************************************************************/
-class LiveActionListUnions : public ASTFrontendAction
-{
+class LiveActionListUnions : public ASTFrontendAction {
public:
LiveActionListUnions() {}
- ~LiveActionListUnions()
- {
+ ~LiveActionListUnions() {
delete BDCProto;
}
void EndSourceFileAction() override {}
- std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override
- {
+ std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override {
DiagnosticsEngine &DE = CI.getPreprocessor().getDiagnostics();
DE.setClient(BDCProto, false);
TheRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts());
@@ -1262,19 +1012,16 @@ class LiveActionListUnions : public ASTFrontendAction
BlankDiagConsumer* BDCProto = new BlankDiagConsumer;
};
/**********************************************************************************************************************/
-class LiveActionListArrays : public ASTFrontendAction
-{
+class LiveActionListArrays : public ASTFrontendAction {
public:
LiveActionListArrays() {}
- ~LiveActionListArrays()
- {
+ ~LiveActionListArrays() {
delete BDCProto;
}
void EndSourceFileAction() override {}
- std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override
- {
+ std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) override {
DiagnosticsEngine &DE = CI.getPreprocessor().getDiagnostics();
DE.setClient(BDCProto, false);
TheRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts());
@@ -1288,39 +1035,31 @@ class LiveActionListArrays : public ASTFrontendAction
/**********************************************************************************************************************/
/**********************************************************************************************************************/
/*lua wrappers*/
-class LuaWrapper
-{
+class LuaWrapper {
public:
//LuaWrapper(std::unique_ptr<Executioner> _e, std::unique_ptr<XGlobals> _x) : executioner(std::move(_e)), xglobals(std::move(_x)) {}
LuaWrapper() {}
/*print out the history*/
- int BruiserLuaHistory(lua_State* __ls)
- {
+ int BruiserLuaHistory(lua_State* __ls) {
std::ifstream historyfile;
historyfile.open(SHELL_HISTORY_FILE);
std::string tempstring;
unsigned int tempint = 0;
- while(std::getline(historyfile, tempstring))
- {
+ while(std::getline(historyfile, tempstring)) {
printf(BLUE"%d ", tempint);
printf(CYAN"%s", tempstring.c_str());
printf(NORMAL"\n");
-
tempint++;
}
-
return tempint;
}
/*print the help menu*/
- int BruiserLuaHelp(lua_State* __ls)
- {
+ int BruiserLuaHelp(lua_State* __ls) {
unsigned int argcount = 0U;
-
- for (auto &iter : bruiser::CMDHelp)
- {
+ for (auto &iter : bruiser::CMDHelp) {
printf(GREEN"name: ");
printf(CYAN"%s ", iter.name.c_str());
printf(GREEN"proto: ");
@@ -1341,19 +1080,16 @@ class LuaWrapper
/*print out bruiser version*/
- int BruiserLuaVersion(lua_State* __ls)
- {
+ int BruiserLuaVersion(lua_State* __ls) {
PRINT_WITH_COLOR_LB(GREEN, "bruiser experimental version something.");
PRINT_WITH_COLOR_LB(GREEN, "project mutator");
PRINT_WITH_COLOR_LB(GREEN, "GPL v3.0");
PRINT_WITH_COLOR_LB(GREEN, "bloodstalker 2017");
-
return 1;
}
/*clear the screen*/
- int BruiserLuaClear(lua_State* __ls)
- {
+ int BruiserLuaClear(lua_State* __ls) {
linenoiseClearScreen();
return 0;
}
@@ -1985,42 +1721,34 @@ class LuaWrapper
}
/*read the m0 report*/
- int BruiserLuaM0(lua_State* __ls)
- {
- bruiser::ReadM0 M0Rep;
- tinyxml2::XMLError XMLErr;
-
- XMLErr = M0Rep.LoadXMLDoc();
- if (XMLErr != XML_SUCCESS)
- {
- std::cout << RED << "could not load m0 xml report.\n" << NORMAL;
- std::cout << RED << "tinyxml2 returned " << XMLErr << NORMAL;
- return XMLErr;
- }
+ int BruiserLuaM0(lua_State* __ls) {
+ bruiser::ReadM0 M0Rep;
+ tinyxml2::XMLError XMLErr;
- XMLErr = M0Rep.ReadFirstElement();
- if (XMLErr != XML_SUCCESS)
- {
- std::cerr << RED << "could not read first element of m0 xml report.\n" << NORMAL;
- return XMLErr;
- }
+ XMLErr = M0Rep.LoadXMLDoc();
+ if (XMLErr != XML_SUCCESS) {
+ std::cout << RED << "could not load m0 xml report.\n" << NORMAL;
+ std::cout << RED << "tinyxml2 returned " << XMLErr << NORMAL;
+ return XMLErr;
+ }
- bruiser::SearchM0(M0Rep.getRootPointer());
+ XMLErr = M0Rep.ReadFirstElement();
+ if (XMLErr != XML_SUCCESS) {
+ std::cerr << RED << "could not read first element of m0 xml report.\n" << NORMAL;
+ return XMLErr;
+ }
- return 1;
+ bruiser::SearchM0(M0Rep.getRootPointer());
+ return 1;
}
- int BruiserLuaReadXMLReport(lua_State* __ls)
- {
+ int BruiserLuaReadXMLReport(lua_State* __ls) {
int numargs = lua_gettop(__ls);
std::string xml_address;
- if (numargs == 1)
- {
+ if (numargs == 1) {
xml_address = lua_tostring(__ls, 1);
- }
- else
- {
+ } else {
xml_address = bruiser::M0REP;
}
@@ -2028,8 +1756,7 @@ class LuaWrapper
tinyxml2::XMLError error;
error = MutagenRep.LoadXMLDoc();
- if (error != XML_SUCCESS)
- {
+ if (error != XML_SUCCESS) {
PRINT_WITH_COLOR_LB(RED, "could not load report.");
PRINT_WITH_COLOR(RED, "tinyxml2 returned ");
std::cout << RED << error << NORMAL;
@@ -2038,59 +1765,49 @@ class LuaWrapper
}
error = MutagenRep.ReadFirstElement();
- if (error != XML_SUCCESS)
- {
+ if (error != XML_SUCCESS) {
PRINT_WITH_COLOR_LB(RED, "could not read first element of xml report.");
lua_pushnumber(__ls, (double)error);
return 1;
}
bruiser::SearchM0(MutagenRep.getRootPointer());
-
return 1;
}
/*quit*/
- int BruiserLuaQuit(lua_State* __ls)
- {
+ int BruiserLuaQuit(lua_State* __ls) {
dostring(__ls, "os.exit()", "test");
return 0;
}
/*quit*/
- int BruiserLuaExit(lua_State* __ls)
- {
+ int BruiserLuaExit(lua_State* __ls) {
dostring(__ls, "os.exit()", "test");
return 0;
}
- int BruiserLuaRunMake(lua_State* __ls)
- {
+ int BruiserLuaRunMake(lua_State* __ls) {
unsigned int args = 0U;
- if ((args = lua_gettop(__ls)) != 1U)
- {
+ if ((args = lua_gettop(__ls)) != 1U) {
PRINT_WITH_COLOR_LB(RED, "function was not called by one argument. Run help().");
lua_pushnumber(__ls, 1);
return 1;
}
std::string makearg = lua_tostring(__ls , 1);
-
- if (ShellGlobalInstance.MAKEPATH == "")
- {
+ if (ShellGlobalInstance.MAKEPATH == "") {
PRINT_WITH_COLOR_LB(RED, "MAKEPATH is not set. set it using setmakepath or type help.");
lua_pushnumber(__ls, 1);
return 1;
}
pid_t pid = fork();
-
if (pid < 0) {
PRINT_WITH_COLOR_LB(RED, "could not fork...");
lua_pushnumber(__ls, EXIT_FAILURE);
}
-
if (pid == 0) {
std::cout << BLUE << "MAKEPATH: " << ShellGlobalInstance.MAKEPATH << NORMAL << "\n";
std::cout << BLUE << "Running: " << "make -C " << ShellGlobalInstance.MAKEPATH << " " << makearg << NORMAL << "\n";
@@ -2098,7 +1815,6 @@ class LuaWrapper
lua_pushnumber(__ls, retval);
exit(EXIT_SUCCESS);
}
-
if (pid > 0) {
int status;
pid_t returned;
@@ -2111,14 +1827,12 @@ class LuaWrapper
int BruiserLuaChangeHistorySize(lua_State* __ls) {
unsigned int args = 0U;
-
if ((args = lua_gettop(__ls)) != 1U) {
PRINT_WITH_COLOR_LB(RED, "function was not called by one argument. Run help().");
return 0;
}
unsigned int historysize = lua_tonumber(__ls, 1);
-
linenoiseHistorySetMaxLen(historysize);
ShellGlobalInstance.HISTORY_SIZE = historysize;
@@ -2143,9 +1857,7 @@ class LuaWrapper
if (iter.rfind(filename) == iter.size() - filename.size()) {
ShellCacheInstance.LastFileUsed = iter;
ShellCacheInstance.LastFileUsedShort = filename;
-
targetfile.open(iter);
-
if(targetfile.rdstate() != std::ios_base::goodbit) {
PRINT_WITH_COLOR_LB(RED, "could not open the file.");
}
@@ -2176,7 +1888,6 @@ class LuaWrapper
}
pid_t pid = fork();
-
if (pid < 0) {
/*bruiser could not spawn a child*/
PRINT_WITH_COLOR_LB(RED, "could not fork a child process(m0).");
@@ -2291,7 +2002,6 @@ class LuaWrapper
}
ShellGlobalInstance.BINPATH = lua_tostring(__ls, 1);
-
return 0;
}
@@ -2388,8 +2098,7 @@ class LuaWrapper
return 0;
}
- int BruiserLuaPWD(lua_State* __ls)
- {
+ int BruiserLuaPWD(lua_State* __ls) {
pid_t pid = fork();
if (pid < 0) {
@@ -2426,13 +2135,11 @@ class BruiserCFE {
std::ifstream libtooling_tee("../test/bruisertest/libtooling-tee");
std::string luaoutstr;
std::string dummy;
-
while(std::getline(libtooling_tee, dummy)) {
luaoutstr = luaoutstr + dummy + "\n";
}
lua_pushstring(__ls, luaoutstr.c_str());
-
return 1;
}
@@ -2473,8 +2180,7 @@ class BruiserCFE {
std::unique_ptr<ClangTool> CT;
};
/**********************************************************************************************************************/
-class RunLoop
-{
+class RunLoop {
public:
RunLoop(lua_State* __ls, LuaEngine __le) : ls(__ls), le(__le) {}
@@ -2558,7 +2264,7 @@ std::pair<ClangTool*, CompilationDatabaseProcessor*> clang_cli_args(int argc, co
}
/**********************************************************************************************************************/
/*Main*/
-int main(int argc, const char **argv) {
+int main(int argc, const char** argv) {
int argc_n = 0;
std::vector<std::string> argv_n;
std::vector<const char*> vc;
diff --git a/bruiser/bruiser.h b/bruiser/bruiser.h
index ff47919..1e54d34 100644
--- a/bruiser/bruiser.h
+++ b/bruiser/bruiser.h
@@ -301,59 +301,6 @@ class Daemonize
};
/**********************************************************************************************************************/
/*structs to hold load.py's return values*/
-/*@DEVI-at some point in the future i might revert to using libbfd or libelf.*/
-
-/*elf*/
-#define ELF_EI_MAGIC = 0x000000000000ffff;
-#define ELF_EI_CLASS = 0x00000000000f0000;
-#define ELF_EI_DATA = 0x0000000000f00000;
-#define ELF_EI_VERSION = 0x000000000f000000;
-#define ELF_EI_OSABI = 0x00000000f0000000;
-#define ELF_EI_ABIVERSION = 0x0000000f00000000;
-#define ELF_EI_PAD = 0xfffffff000000000;
-
-// @DEVI-FIXME-using uint128 here
-// fails to build on stock ubuntu 16.04
-# if 0
-struct ELFHDR_64 {
- public:
- ELFHDR_64() = default;
- ELFHDR_64(__uint128_t _ident, uint16_t _type, uint16_t _machine,
- uint32_t _version, uint64_t _entry, uint64_t _phoff, uint64_t _shoff,
- uint32_t _flags, uint16_t _ehsize, uint16_t _phentsize,
- uint16_t _phnum, uint16_t _shentsize, uint16_t _shnum, uint16_t _shstrndx) {
- e_ident = _ident; e_type = _type; e_machine = _machine; e_version = _version;
- e_entry = _entry; e_phoff = _phoff; e_shoff = _shoff; e_flags = _flags;
- e_ehsize = _ehsize; e_phentsize = _phentsize; e_phnum = _phnum;
- e_shentsize = _shentsize; e_shnum = _shnum; e_shstrndx = _shstrndx;
- }
- __uint128_t e_ident; uint16_t e_type; uint16_t e_machine; uint32_t e_version;
- uint64_t e_entry; uint64_t e_phoff; uint64_t e_shoff; uint32_t e_flags;
- uint16_t e_ehsize; uint16_t e_phentsize; uint16_t e_phnum; uint16_t e_shentsize;
- uint16_t e_shnum; uint16_t e_shstrndx;
-};
-
-// @DEVI-FIXME-using uint128 here
-struct ELFHDR_32 {
- public:
- ELFHDR_32() = default;
- ELFHDR_32(__uint128_t _ident, uint16_t _type, uint16_t _machine, uint32_t _version,
- uint32_t _entry, uint32_t _phoff, uint32_t _shoff, uint32_t _flags,
- uint16_t _ehsize, uint16_t _phentsize, uint16_t _phnum, uint16_t _shentsize,
- uint16_t _shnum, uint16_t _shstrndx) {
- e_ident = _ident; e_type = _type; e_machine = _machine; e_version = _version;
- e_entry = _entry; e_phoff = _phoff; e_shoff = _shoff; e_flags = _flags;
- e_ehsize = _ehsize; e_phentsize = _phentsize; e_phnum = _phnum;
- e_shentsize = _shentsize; e_shnum = _shnum; e_shstrndx = _shstrndx;
- }
-
- __uint128_t e_ident; uint16_t e_type; uint16_t e_machine; uint32_t e_version;
- uint32_t e_entry; uint32_t e_phoff; uint32_t e_shoff; uint32_t e_flags;
- uint16_t e_ehsize; uint16_t e_phentsize; uint16_t e_phnum; uint16_t e_shentsize;
- uint16_t e_shnum; uint16_t e_shstrndx;
-};
-#endif
-/*program header*/
struct PHDR_64 {
public:
PHDR_64() = default;
diff --git a/bruiser/lua-scripts/wasmtest.lua b/bruiser/lua-scripts/wasmtest.lua
index 8942ad2..15aa395 100644
--- a/bruiser/lua-scripts/wasmtest.lua
+++ b/bruiser/lua-scripts/wasmtest.lua
@@ -198,6 +198,7 @@ function demo4()
io.write(v:index().."\t")
io.write(tostring(v:offset()).."\t")
io.write(v:size().."\n")
+ --FIXME
--io.write(v:data().."\n")
end
end