From bf0b3bb5073100a1a031b14afd94a58197dc2b38 Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Mon, 29 May 2017 00:06:10 +0430 Subject: fixed the memory leak --- bruiser/bruiser.cpp | 62 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 22 deletions(-) (limited to 'bruiser/bruiser.cpp') diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp index 4bd4f87..4e2fae4 100644 --- a/bruiser/bruiser.cpp +++ b/bruiser/bruiser.cpp @@ -123,7 +123,6 @@ bruiser::BruiserReport::~BruiserReport() BruiserLog.close(); } -template /** * @brief Will print the argument in the log file. Expects to receive valid types usable for a stream. * @@ -131,6 +130,7 @@ template * * @return Returns true if the write was successful, false otherwise. */ +template bool bruiser::BruiserReport::PrintToLog(T __arg) { BruiserLog << __arg << "\n"; @@ -609,7 +609,10 @@ class BruiserFrontendAction : public ASTFrontendAction { public: BruiserFrontendAction() {} - virtual ~BruiserFrontendAction() {} + virtual ~BruiserFrontendAction() + { + delete BDCProto; + } void EndSourceFileAction() override { @@ -619,21 +622,21 @@ public: std::unique_ptr CreateASTConsumer(CompilerInstance &CI, StringRef file) override { DiagnosticsEngine &DE = CI.getPreprocessor().getDiagnostics(); - BlankDiagConsumer* BDCProto = new BlankDiagConsumer; - DE.setClient(BDCProto); + DE.setClient(BDCProto, false); TheRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts()); return llvm::make_unique(TheRewriter); } private: Rewriter TheRewriter; + BlankDiagConsumer* BDCProto = new BlankDiagConsumer; }; /**********************************************************************************************************************/ class LiveActionListVars : public ASTFrontendAction { public: - LiveActionListVars() {} - virtual ~LiveActionListVars() + LiveActionListVars() = default; + virtual ~LiveActionListVars() { delete BDCProto; } @@ -643,7 +646,7 @@ class LiveActionListVars : public ASTFrontendAction std::unique_ptr CreateASTConsumer(CompilerInstance &CI, StringRef file) override { DiagnosticsEngine &DE = CI.getPreprocessor().getDiagnostics(); - DE.setClient(BDCProto); + DE.setClient(BDCProto, false); TheRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts()); return llvm::make_unique(TheRewriter); } @@ -657,105 +660,120 @@ class LiveActionListFuncs : public ASTFrontendAction { public: LiveActionListFuncs() {} - ~LiveActionListFuncs() {} + ~LiveActionListFuncs() + { + delete BDCProto; + } void EndSourceFileAction() override {} std::unique_ptr CreateASTConsumer(CompilerInstance &CI, StringRef file) override { DiagnosticsEngine &DE = CI.getPreprocessor().getDiagnostics(); - BlankDiagConsumer* BDCProto = new BlankDiagConsumer; - DE.setClient(BDCProto); + DE.setClient(BDCProto, false); TheRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts()); return llvm::make_unique(TheRewriter); } private: Rewriter TheRewriter; + BlankDiagConsumer* BDCProto = new BlankDiagConsumer; }; /**********************************************************************************************************************/ class LiveActionListStructs : public ASTFrontendAction { public: LiveActionListStructs() {} - ~LiveActionListStructs() {} + ~LiveActionListStructs() + { + delete BDCProto; + } void EndSourceFileAction() override {} std::unique_ptr CreateASTConsumer(CompilerInstance &CI, StringRef file) override { DiagnosticsEngine &DE = CI.getPreprocessor().getDiagnostics(); - BlankDiagConsumer* BDCProto = new BlankDiagConsumer; - DE.setClient(BDCProto); + DE.setClient(BDCProto, false); TheRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts()); return llvm::make_unique(TheRewriter); } private: Rewriter TheRewriter; + BlankDiagConsumer* BDCProto = new BlankDiagConsumer; }; /**********************************************************************************************************************/ class LiveActionListClasses : public ASTFrontendAction { public: LiveActionListClasses() {} - ~LiveActionListClasses() {} + ~LiveActionListClasses() + { + delete BDCProto; + } void EndSourceFileAction() override {} std::unique_ptr CreateASTConsumer(CompilerInstance &CI, StringRef file) override { DiagnosticsEngine &DE = CI.getPreprocessor().getDiagnostics(); - BlankDiagConsumer* BDCProto = new BlankDiagConsumer; - DE.setClient(BDCProto); + DE.setClient(BDCProto, false); TheRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts()); return llvm::make_unique(TheRewriter); } private: Rewriter TheRewriter; + BlankDiagConsumer* BDCProto = new BlankDiagConsumer; }; /**********************************************************************************************************************/ class LiveActionListUnions : public ASTFrontendAction { public: LiveActionListUnions() {} - ~LiveActionListUnions() {} + ~LiveActionListUnions() + { + delete BDCProto; + } void EndSourceFileAction() override {} std::unique_ptr CreateASTConsumer(CompilerInstance &CI, StringRef file) override { DiagnosticsEngine &DE = CI.getPreprocessor().getDiagnostics(); - BlankDiagConsumer* BDCProto = new BlankDiagConsumer; - DE.setClient(BDCProto); + DE.setClient(BDCProto, false); TheRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts()); return llvm::make_unique(TheRewriter); } private: Rewriter TheRewriter; + BlankDiagConsumer* BDCProto = new BlankDiagConsumer; }; /**********************************************************************************************************************/ class LiveActionListArrays : public ASTFrontendAction { public: LiveActionListArrays() {} - ~LiveActionListArrays() {} + ~LiveActionListArrays() + { + delete BDCProto; + } void EndSourceFileAction() override {} std::unique_ptr CreateASTConsumer(CompilerInstance &CI, StringRef file) override { DiagnosticsEngine &DE = CI.getPreprocessor().getDiagnostics(); - BlankDiagConsumer* BDCProto = new BlankDiagConsumer; - DE.setClient(BDCProto); + DE.setClient(BDCProto, false); TheRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts()); return llvm::make_unique(TheRewriter); } private: Rewriter TheRewriter; + BlankDiagConsumer* BDCProto = new BlankDiagConsumer; }; /**********************************************************************************************************************/ /**********************************************************************************************************************/ -- cgit v1.2.3 From 36a79984514f3f1f769ab476d699c36e59d3bac8 Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Tue, 30 May 2017 19:13:34 +0430 Subject: nothing --- bruiser/bruiser.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'bruiser/bruiser.cpp') diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp index 4e2fae4..13d63b7 100644 --- a/bruiser/bruiser.cpp +++ b/bruiser/bruiser.cpp @@ -813,7 +813,6 @@ int main(int argc, const char **argv) linenoiseHistoryAdd(command); linenoiseHistorySave(SHELL_HISTORY_FILE); - //std::cin.getline(command, sizeof(command)); std::string dummy_string(command); shHistory.History.push_back(command); -- cgit v1.2.3 From 0f059a28c6fb85ad39f3ec35b606f5e5ddfb09fe Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Thu, 1 Jun 2017 03:17:06 +0430 Subject: now all commands are sent to the lua interpreter. what that simply means is that bruiser is an interactive lua interpreter that uses linenoise for shell-like functionality instead of what the normal lua interpreter does, plus it will feature its own functionality. Im updating the readme as well. I explain more there --- bruiser/bruiser.cpp | 105 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 92 insertions(+), 13 deletions(-) (limited to 'bruiser/bruiser.cpp') diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp index 13d63b7..7a2cd88 100644 --- a/bruiser/bruiser.cpp +++ b/bruiser/bruiser.cpp @@ -49,6 +49,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.* #include "lua-5.3.4/src/lua.hpp" #include "lua-5.3.4/src/lualib.h" #include "lua-5.3.4/src/lauxlib.h" + +#include "luadummy.h" /**********************************************************************************************************************/ /*used namespaces*/ using namespace llvm; @@ -79,23 +81,39 @@ class LuaEngine LS = luaL_newstate(); } - void LoadBaseLib(void) - { - luaopen_base(LS); - } + /*@DEVI-this will just create member functions that open a single lua libarary. + * For example to load the string library just call LuaEngine::LoadstringLib().*/ +#define OPEN_LUA_LIBS(__x1) \ + void Load##__x1##Lib(void){\ + luaL_requiref(LS, #__x1, luaopen_##__x1, 1);} + + OPEN_LUA_LIBS(base) + OPEN_LUA_LIBS(table) + OPEN_LUA_LIBS(io) + OPEN_LUA_LIBS(string) + OPEN_LUA_LIBS(math) +#undef OPEN_LUA_LIBS void LoadAuxLibs(void) { - luaopen_table(LS); - luaopen_io(LS); - luaopen_string(LS); + luaL_requiref(LS, "table", luaopen_table, 1); + luaL_requiref(LS, "io", luaopen_io, 1); + luaL_requiref(LS, "string", luaopen_string, 1); } void LoadEverylib(void) { - this->LoadBaseLib(); - this->LoadAuxLibs(); - luaopen_math(LS); + luaL_openlibs(LS); + } + + void RunString(char* __lua_string) + { + + } + + void RunChunk(char* __lua_chunk) + { + dostring(LS, __lua_chunk, "test"); } int RunScript(char* __lua_script) @@ -103,6 +121,33 @@ class LuaEngine return luaL_dofile(LS, __lua_script); } + void Test(void) + { + luaL_dofile(LS, "./lua-scripts/test.lua"); + luaL_dofile(LS, "./lua-scripts/test1.lua"); + luaL_dofile(LS, "./lua-scripts/test2.lua"); + } + + void Test2(void) + { + luaL_dofile(LS, "./lua-scripts/test1.lua"); + } + + void Test3(void) + { + luaL_dofile(LS, "./lua-scripts/test2.lua"); + } + + void Test4(void) + { + luaL_dofile(LS, "./lua-scripts/test3.lua"); + } + + lua_State* GetLuaState(void) + { + return this->LS; + } + void Cleanup(void) { lua_close(LS); @@ -805,9 +850,22 @@ int main(int argc, const char **argv) linenoiseHistoryLoad(SHELL_HISTORY_FILE); linenoiseSetMultiLine(1); - /*start runnnin the cli*/ + /*start running the cli*/ { char* command; + +#if 1 + LuaEngine LE; + LE.LoadEverylib(); + + while((command = linenoise("bruiser>>")) != NULL) + { + linenoiseHistoryAdd(command); + linenoiseHistorySave(SHELL_HISTORY_FILE); + LE.RunChunk(command); + } +#endif + while((command = linenoise("bruiser>>")) != NULL) { linenoiseHistoryAdd(command); @@ -967,10 +1025,31 @@ int main(int argc, const char **argv) { LuaEngine LE; LE.LoadEverylib(); - LE.RunScript((char*)"/home/bloodstalker/devi/abbatoir/hole6/proto.lua"); - LE.Cleanup(); + LE.Test(); + //LE.Cleanup(); + continue; } +#if 1 + if (std::strcmp(command, "runluachain1") == 0) + { + LuaEngine LE; + LE.LoadEverylib(); + LE.Test2(); + //LE.Cleanup(); + continue; + } + + if (std::strcmp(command, "runluachain2") == 0) + { + LuaEngine LE; + LE.LoadEverylib(); + LE.Test3(); + //LE.Cleanup(); + continue; + } +#endif + if (command[0] == '!') { /*FIXME*/ -- cgit v1.2.3 From 02d39f7a442d0b820f00376bb023b7ed11aa6a37 Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Fri, 2 Jun 2017 02:45:41 +0430 Subject: registering the functions in lua --- bruiser/bruiser.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'bruiser/bruiser.cpp') diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp index 7a2cd88..91bac9b 100644 --- a/bruiser/bruiser.cpp +++ b/bruiser/bruiser.cpp @@ -92,6 +92,7 @@ class LuaEngine OPEN_LUA_LIBS(io) OPEN_LUA_LIBS(string) OPEN_LUA_LIBS(math) + OPEN_LUA_LIBS(os) #undef OPEN_LUA_LIBS void LoadAuxLibs(void) @@ -822,6 +823,37 @@ class LiveActionListArrays : public ASTFrontendAction }; /**********************************************************************************************************************/ /**********************************************************************************************************************/ +/*lua wrappers*/ +class LuaWrapper +{ + public: + LuaWrapper(ClangTool &__CT) : CT(__CT) {} + +#define LIST_GENERATOR(__x1) \ + int List##__x1(lua_State* L)\ + {\ + return CT.run(newFrontendActionFactory().get());\ + } + +#define LIST_LIST_GENERATORS \ + X(Funcs, "lists all functions") \ + X(Vars, "lists all variables") \ + X(Arrays, "lists all arrays") \ + X(Classes, "lists all classes") \ + X(Structs, "lists all structs") \ + X(Unions, "lists all unions") \ + +#define X(__x1, __x2) LIST_GENERATOR(__x1) + + LIST_LIST_GENERATORS + +#undef X + + private: + ClangTool CT; +}; +/**********************************************************************************************************************/ +/**********************************************************************************************************************/ /*Main*/ int main(int argc, const char **argv) { @@ -841,6 +873,7 @@ int main(int argc, const char **argv) CommonOptionsParser op(argc, argv, BruiserCategory); ClangTool Tool(op.getCompilations(), op.getSourcePathList()); + LuaWrapper LW(Tool); /*linenoise init*/ linenoiseSetCompletionCallback(bruiser::ShellCompletion); @@ -858,6 +891,14 @@ int main(int argc, const char **argv) LuaEngine LE; LE.LoadEverylib(); +#define ARG_STRINGIFIER(__x1) LW.List##__x1 +#define X(__x1, __x2) lua_register(LE.GetLuaState(), #__x1, LW.List## __x1); + + //LIST_LIST_GENERATORS + //lua_register(LE.GetLuaState(), "garbage", LW.ListVars); + +#undef X + while((command = linenoise("bruiser>>")) != NULL) { linenoiseHistoryAdd(command); -- cgit v1.2.3 From 3e7e2e3bd5eaf5f0c05a66446cc660945e0d2575 Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Sat, 3 Jun 2017 23:53:55 +0430 Subject: you can now call the list functions from lua --- bruiser/bruiser.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 6 deletions(-) (limited to 'bruiser/bruiser.cpp') diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp index 91bac9b..e388ae6 100644 --- a/bruiser/bruiser.cpp +++ b/bruiser/bruiser.cpp @@ -93,6 +93,7 @@ class LuaEngine OPEN_LUA_LIBS(string) OPEN_LUA_LIBS(math) OPEN_LUA_LIBS(os) + #undef OPEN_LUA_LIBS void LoadAuxLibs(void) @@ -830,9 +831,12 @@ class LuaWrapper LuaWrapper(ClangTool &__CT) : CT(__CT) {} #define LIST_GENERATOR(__x1) \ - int List##__x1(lua_State* L)\ + int List##__x1(lua_State* __ls)\ {\ - return CT.run(newFrontendActionFactory().get());\ + unsigned int InArgCnt = 0;\ + InArgCnt = lua_gettop(__ls);\ + this->GetClangTool().run(newFrontendActionFactory().get());\ + return 1;\ } #define LIST_LIST_GENERATORS \ @@ -848,12 +852,42 @@ class LuaWrapper LIST_LIST_GENERATORS #undef X +#undef LIST_GENERATOR + + ClangTool GetClangTool(void) + { + return this->CT; + } private: ClangTool CT; }; /**********************************************************************************************************************/ /**********************************************************************************************************************/ +typedef int (LuaWrapper::*mem_func)(lua_State* L); + +/** + * @brief A template function to wrap LuaWrapper members into somehting that lua accepts. + * + * @param __ls + * + * @return + */ +template +int LuaDispatch(lua_State* __ls) +{ + LuaWrapper* LWPtr = *static_cast(lua_getextraspace(__ls)); + return ((*LWPtr).*func)(__ls); +} +/**********************************************************************************************************************/ +int bubu(lua_State* __ls) +{ + int n = lua_gettop(__ls); + std::cout << "hi im bubu\n"; + lua_pushfstring(__ls, "hi im bubu\n"); + return 1; +} +/**********************************************************************************************************************/ /*Main*/ int main(int argc, const char **argv) { @@ -890,20 +924,29 @@ int main(int argc, const char **argv) #if 1 LuaEngine LE; LE.LoadEverylib(); + *static_cast(lua_getextraspace(LE.GetLuaState())) = &LW; -#define ARG_STRINGIFIER(__x1) LW.List##__x1 -#define X(__x1, __x2) lua_register(LE.GetLuaState(), #__x1, LW.List## __x1); + /*@DEVI-this part is just registering our LuaWrapper member functions with lua so we can call them from lua.*/ +#define X(__x1, __x2) lua_register(LE.GetLuaState(), #__x1, &LuaDispatch<&LuaWrapper::List##__x1>); - //LIST_LIST_GENERATORS - //lua_register(LE.GetLuaState(), "garbage", LW.ListVars); + LIST_LIST_GENERATORS #undef X +#undef LIST_LIST_GENERATORS + + lua_register(LE.GetLuaState(), "bubu", bubu); while((command = linenoise("bruiser>>")) != NULL) { linenoiseHistoryAdd(command); linenoiseHistorySave(SHELL_HISTORY_FILE); LE.RunChunk(command); +#if 1 + //LE.Test(); + //LE.Test2(); + //LE.Test3(); + //luaL_dofile(LE.GetLuaState(), "./lua-scripts/test4.lua"); +#endif } #endif -- cgit v1.2.3 From aa71fe22d7d9072c4f5d0a9ab3f78105b431cc3f Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Mon, 5 Jun 2017 02:48:32 +0430 Subject: now the list commands output the results in as strings so they can be reused in lua in any way the user sees fit --- bruiser/bruiser.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'bruiser/bruiser.cpp') diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp index e388ae6..89e84f2 100644 --- a/bruiser/bruiser.cpp +++ b/bruiser/bruiser.cpp @@ -66,6 +66,7 @@ using namespace clang::tooling; /**********************************************************************************************************************/ /*global vars*/ static llvm::cl::OptionCategory BruiserCategory("Empty"); +std::vector PushToLua; bruiser::M0_ERR m0_err; bruiser::BruiserReport BruiseRep; @@ -413,6 +414,7 @@ class LiveListFuncs : public MatchFinder::MatchCallback //printf(CYAN"%s", R.getRewrittenText(clang::SourceRange(SLShebang, SLBody.getLocWithOffset(-1))).c_str()); //printf(NORMAL "\n"); 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)))); //PRINT_WITH_COLOR_LB(GREEN, "end"); } else @@ -420,6 +422,7 @@ class LiveListFuncs : public MatchFinder::MatchCallback SourceLocation SL = FD->getLocStart(); SourceLocation SLE = FD->getLocEnd(); PRINT_WITH_COLOR_LB(CYAN, R.getRewrittenText(clang::SourceRange(SL, SLE)).c_str()); + PushToLua.push_back(R.getRewrittenText(clang::SourceRange(SL, SLE))); } } } @@ -440,6 +443,7 @@ class LiveListVars : public MatchFinder::MatchCallback const clang::VarDecl* VD = MR.Nodes.getNodeAs("livelistvars"); PRINT_WITH_COLOR_LB(CYAN, R.getRewrittenText(SourceRange(VD->getLocStart(), VD->getLocEnd())).c_str()); + PushToLua.push_back(R.getRewrittenText(SourceRange(VD->getLocStart(), VD->getLocEnd()))); } } @@ -459,6 +463,7 @@ class LiveListRecords : public MatchFinder::MatchCallback const clang::RecordDecl* RD = MR.Nodes.getNodeAs("livelistvars"); PRINT_WITH_COLOR_LB(CYAN, R.getRewrittenText(SourceRange(RD->getLocStart(), RD->getLocEnd())).c_str()); + PushToLua.push_back(R.getRewrittenText(SourceRange(RD->getLocStart(), RD->getLocEnd()))); } } @@ -833,10 +838,14 @@ class LuaWrapper #define LIST_GENERATOR(__x1) \ int List##__x1(lua_State* __ls)\ {\ - unsigned int InArgCnt = 0;\ + unsigned int InArgCnt = 0U;\ InArgCnt = lua_gettop(__ls);\ + unsigned int returncount=0U;\ this->GetClangTool().run(newFrontendActionFactory().get());\ - return 1;\ + for(auto &iter : PushToLua)\ + {lua_pushstring(__ls, iter.c_str());returncount++;}\ + PushToLua.clear();\ + return returncount;\ } #define LIST_LIST_GENERATORS \ -- cgit v1.2.3 From d404e7217d41c1e7b20fdf021fd536a54e5c1c93 Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Mon, 5 Jun 2017 21:45:32 +0430 Subject: moved the other commands into lua now, so they are working again --- bruiser/bruiser.cpp | 113 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 96 insertions(+), 17 deletions(-) (limited to 'bruiser/bruiser.cpp') diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp index 89e84f2..12cbea0 100644 --- a/bruiser/bruiser.cpp +++ b/bruiser/bruiser.cpp @@ -835,6 +835,92 @@ class LuaWrapper public: LuaWrapper(ClangTool &__CT) : CT(__CT) {} + 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)) + { + printf(GREEN"%d - %s", tempint, tempstring.c_str()); + printf(NORMAL"\n"); + + tempint++; + } + + return tempint; + } + + int BruiserLuaHelp(lua_State* __ls) + { + unsigned int argcount = 0U; + + for (auto &iter : bruiser::CMDHelp) + { + printf(GREEN"%s:%s:%s",iter.name.c_str(),iter.proto.c_str(),iter.descr.c_str()); + printf(NORMAL"\n"); + argcount++; + } + + std::cout << NORMAL; + return argcount; + } + + int BruiserLuaHijackMain(lua_State* __ls) + { + int RunResult = this->GetClangTool().run(newFrontendActionFactory().get()); + //std::cout << CYAN <<"hijacking main returned " << RunResult << "\n" << NORMAL; + printf(CYAN"hijacking main returned %d", RunResult); + printf(NORMAL"\n"); + + return 1; + } + + 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 v2.0"); + PRINT_WITH_COLOR_LB(GREEN, "bloodstalker 2017"); + + return 1; + } + + int BruiserLuaClear(lua_State* _ls) + { + linenoiseClearScreen(); + return 0; + } + + int BruiserLuaM0(lua_State* __ls) + { + BruiseRep.PrintToLog("bruiser exited with:"); + + 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; + } + + XMLErr = M0Rep.ReadFirstElement(); + if (XMLErr != XML_SUCCESS) + { + std::cerr << RED << "could not read first element of m0 xml report.\n" << NORMAL; + return XMLErr; + } + + bruiser::SearchM0(M0Rep.getRootPointer()); + + return 1; + } + #define LIST_GENERATOR(__x1) \ int List##__x1(lua_State* __ls)\ {\ @@ -889,13 +975,6 @@ int LuaDispatch(lua_State* __ls) return ((*LWPtr).*func)(__ls); } /**********************************************************************************************************************/ -int bubu(lua_State* __ls) -{ - int n = lua_gettop(__ls); - std::cout << "hi im bubu\n"; - lua_pushfstring(__ls, "hi im bubu\n"); - return 1; -} /**********************************************************************************************************************/ /*Main*/ int main(int argc, const char **argv) @@ -914,8 +993,10 @@ int main(int argc, const char **argv) std::regex dumplist("^list\\sdump\\s"); std::smatch smresult; + /*gets the compilation database and options for the clang instances that we would later run*/ CommonOptionsParser op(argc, argv, BruiserCategory); ClangTool Tool(op.getCompilations(), op.getSourcePathList()); + /*initialize the LuaWrapper class so we can register and run them from lua.*/ LuaWrapper LW(Tool); /*linenoise init*/ @@ -930,12 +1011,17 @@ int main(int argc, const char **argv) { char* command; -#if 1 LuaEngine LE; LE.LoadEverylib(); *static_cast(lua_getextraspace(LE.GetLuaState())) = &LW; /*@DEVI-this part is just registering our LuaWrapper member functions with lua so we can call them from lua.*/ + lua_register(LE.GetLuaState(), "history", &LuaDispatch<&LuaWrapper::BruiserLuaHistory>); + lua_register(LE.GetLuaState(), "help", &LuaDispatch<&LuaWrapper::BruiserLuaHelp>); + lua_register(LE.GetLuaState(), "hijackmain", &LuaDispatch<&LuaWrapper::BruiserLuaHijackMain>); + lua_register(LE.GetLuaState(), "version", &LuaDispatch<&LuaWrapper::BruiserLuaVersion>); + lua_register(LE.GetLuaState(), "clear", &LuaDispatch<&LuaWrapper::BruiserLuaClear>); + /*its just regisering the List function from LuaWrapper with X-macros.*/ #define X(__x1, __x2) lua_register(LE.GetLuaState(), #__x1, &LuaDispatch<&LuaWrapper::List##__x1>); LIST_LIST_GENERATORS @@ -943,21 +1029,14 @@ int main(int argc, const char **argv) #undef X #undef LIST_LIST_GENERATORS - lua_register(LE.GetLuaState(), "bubu", bubu); - while((command = linenoise("bruiser>>")) != NULL) { linenoiseHistoryAdd(command); linenoiseHistorySave(SHELL_HISTORY_FILE); LE.RunChunk(command); -#if 1 - //LE.Test(); - //LE.Test2(); - //LE.Test3(); - //luaL_dofile(LE.GetLuaState(), "./lua-scripts/test4.lua"); -#endif } -#endif + + /*end of bruiser main*/ while((command = linenoise("bruiser>>")) != NULL) { -- cgit v1.2.3