aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--bruiser/bruiser.cpp125
-rw-r--r--bruiser/bruiserffi.c119
-rw-r--r--bruiser/bruiserffi.h51
-rw-r--r--bruiser/compile_commands.json13
-rw-r--r--bruiser/lua-scripts/demo1.lua11
-rw-r--r--bruiser/makefile5
6 files changed, 283 insertions, 41 deletions
diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp
index 00076d1..ce0d6ec 100644
--- a/bruiser/bruiser.cpp
+++ b/bruiser/bruiser.cpp
@@ -1242,36 +1242,119 @@ class LuaWrapper
lua_rawgeti(__ls, 1, i);
xobj_code_.push_back(int(lua_tonumber(__ls, i + 2)));
}
- std::cout << RED << "function code: ";
- for (auto& iter : xobj_code_) {std::cout << RED << int(iter) << " ";}
+ std::cout << BLUE << "function code: ";
+ for (auto& iter : xobj_code_) {std::cout << NORMAL << int(iter) << " ";}
std::cout << NORMAL <<"\n";
xobj_name = lua_tostring(__ls, 2);
- //Executioner executioner;
std::pair<void*, size_t> xobj = executioner.loadObjsInXMem(xobj_code_);
std::cout << "xobj will be registered as " << YELLOW << xobj_name << NORMAL << ". " << "it is recommended to use a post- or pre-fix for the xobj names to avoid namespace pollution." "\n";
std::cout << GREEN << "pointer: " << BLUE << xobj.first << " " << GREEN << "size: " << BLUE << xobj.second << NORMAL << "\n";
- XObject ptr = (XObject)xobj.first;
executioner.pushvptr(xobj.first, xobj_name);
- ptr();
- xobj_2int ptr2;
- ptr2 = (xobj_2int)ptr;
- std::cout << MAGENTA << "result: " << NORMAL << ptr2(30,20) << "\n";
- //devi_luareg(__ls, ptr2, xobj_name, executioner);
return 0;
}
int BruiserLuaCallX(lua_State* __ls) {
int numargs = lua_gettop(__ls);
- if (numargs != 2) {PRINT_WITH_COLOR_LB(RED, "bad number of args. expected exactly two.");}
- int x_index = lua_tointeger(__ls, 1);
- int x_arg_num = lua_tointeger(__ls, 2);
- xobj_2int ptr;
- auto dummy = executioner.getvptrbyindex(x_index).first;
- if (dummy != nullptr) {
- ptr = (xobj_2int)dummy;
- int result = ptr(30, 20);
- std::cout << "call made to xobj named " << GREEN << executioner.getvptrbyindex(x_index).second << NORMAL << "\n";
- lua_pushnumber(__ls, result);
+ if (numargs != 5) {PRINT_WITH_COLOR_LB(RED, "xcall: bad number of args. expected exactly five.");}
+ int argc = lua_tointeger(__ls, 1);
+ // 2-table of strings
+ std::string ffi_ret_type_string = lua_tostring(__ls, 3);
+ int x_index = lua_tointeger(__ls, 4);
+ // 5-the actual args-table of values
+
+ // @DEVI-FIXME: currently we are not handling structs at all
+ ffi_type ret_type;
+ if (std::strcmp(ffi_ret_type_string.c_str(), "void") == 0) {ret_type = ffi_type_void;}
+ else if (std::strcmp(ffi_ret_type_string.c_str(), "uint8") == 0) {ret_type = ffi_type_uint8;}
+ else if (std::strcmp(ffi_ret_type_string.c_str(), "sint8") == 0) {ret_type = ffi_type_sint8;}
+ else if (std::strcmp(ffi_ret_type_string.c_str(), "uint16") == 0) {ret_type = ffi_type_uint16;}
+ else if (std::strcmp(ffi_ret_type_string.c_str(), "sint16") == 0) {ret_type = ffi_type_sint16;}
+ else if (std::strcmp(ffi_ret_type_string.c_str(), "uint32") == 0) {ret_type = ffi_type_uint32;}
+ else if (std::strcmp(ffi_ret_type_string.c_str(), "sint32") == 0) {ret_type = ffi_type_sint32;}
+ else if (std::strcmp(ffi_ret_type_string.c_str(), "uint64") == 0) {ret_type = ffi_type_uint64;}
+ else if (std::strcmp(ffi_ret_type_string.c_str(), "sint64") == 0) {ret_type = ffi_type_sint64;}
+ else if (std::strcmp(ffi_ret_type_string.c_str(), "float") == 0) {ret_type = ffi_type_float;}
+ else if (std::strcmp(ffi_ret_type_string.c_str(), "double") == 0) {ret_type = ffi_type_double;}
+ else if (std::strcmp(ffi_ret_type_string.c_str(), "pointer") == 0) {ret_type = ffi_type_pointer;}
+ else if (std::strcmp(ffi_ret_type_string.c_str(), "struct") == 0) {ret_type = ffi_type_pointer;}
+ else {PRINT_WITH_COLOR_LB(RED, "unknown return type string.");return 0;
+ }
+
+ const char* args[argc];
+ int table_length_2 = lua_rawlen(__ls, 2);
+ if (lua_type(__ls, 2) != LUA_TTABLE) {
+ PRINT_WITH_COLOR_LB(RED, "xcall: the stack value is not a table but is being accessed as such.");
+ return 0;
+ } else {
+ PRINT_WITH_COLOR_LB(GREEN, "xcall: stack index 2 is a table.");
+ }
+ std::cout << CYAN << "table_length: " << table_length_2 << NORMAL << "\n";
+ for (int i = 1; i <= table_length_2; ++i) {
+ lua_rawgeti(__ls, 2, i);
+ args[i-1] = lua_tostring(__ls, i + numargs);
+ //std::cout << YELLOW << args[i-1] << NORMAL << "\n";
+ }
+
+ std::list<uint64_t> uints;
+ std::list<int64_t> ints;
+ std::list<std::string> strings;
+ std::list<bool> bools;
+ std::list<uintptr_t> ptrs;
+ std::list<float> floats;
+ std::list<double> doubles;
+ void* values[argc];
+ int numbers[argc];
+ int table_length_5 = lua_rawlen(__ls, 5);
+
+ if (!lua_checkstack(__ls, 10)) {
+ PRINT_WITH_COLOR_LB(RED, "cant grow lua stack. current size is too small.");
+ return 0;
+ }
+ if (lua_type(__ls, 5) != LUA_TTABLE) {
+ PRINT_WITH_COLOR_LB(RED, "xcall: the stack value is not a table but is being accessed as such.");
+ return 0;
+ } else {
+ PRINT_WITH_COLOR_LB(GREEN, "xcall: stack index 5 is a table.");
+ }
+
+ std::cout << CYAN << "table_length: " << table_length_5 << NORMAL << "\n";
+ for (int i = 1; i <= table_length_5; ++i) {
+ lua_rawgeti(__ls, 5, i);
+ numbers[i-1] = lua_tointeger(__ls, i + numargs + argc);
+ if (lua_type(__ls, i) == LUA_TBOOLEAN) {}
+ else if (lua_type(__ls, i) == LUA_TLIGHTUSERDATA) {}
+ else if (lua_type(__ls, i+numargs+argc) == LUA_TNUMBER) {
+ uints.push_back(lua_tointeger(__ls, i + numargs + argc));
+ values[i-1]=&uints.back();
+ }
+ else if (lua_type(__ls, i) == LUA_TSTRING) {}
+ else if (lua_type(__ls, i) == LUA_TTABLE) {}
+ else if (lua_type(__ls, i) == LUA_TFUNCTION) {}
+ else if (lua_type(__ls, i) == LUA_TUSERDATA) {}
+ else if (lua_type(__ls, i) == LUA_TTHREAD) {}
+ }
+
+ auto x_ptr = executioner.getvptrbyindex(x_index).first;
+ void* result;
+ if (x_ptr != nullptr) {
+ std::cout << "calling xobj named " << GREEN << executioner.getvptrbyindex(x_index).second << NORMAL << "\n";
+ result = ffi_callX(argc, args, ret_type, x_ptr, values);
+ std::cout << reinterpret_cast<uint64_t>(result) << "\n";
+ lua_pushinteger(__ls, ffi_reinterpret_uint32_t(result));
+ if (std::strcmp(ffi_ret_type_string.c_str(), "void") == 0) {return 0;}
+ else if (std::strcmp(ffi_ret_type_string.c_str(), "uint8") == 0) {lua_pushinteger(__ls, ffi_reinterpret_uint8_t(result));}
+ else if (std::strcmp(ffi_ret_type_string.c_str(), "sint8") == 0) {lua_pushinteger(__ls, ffi_reinterpret_int8_t(result));}
+ else if (std::strcmp(ffi_ret_type_string.c_str(), "uint16") == 0) {lua_pushinteger(__ls, ffi_reinterpret_uint16_t(result));}
+ else if (std::strcmp(ffi_ret_type_string.c_str(), "sint16") == 0) {lua_pushinteger(__ls, ffi_reinterpret_int16_t(result));}
+ else if (std::strcmp(ffi_ret_type_string.c_str(), "uint32") == 0) {lua_pushinteger(__ls, ffi_reinterpret_uint32_t(result));}
+ else if (std::strcmp(ffi_ret_type_string.c_str(), "sint32") == 0) {lua_pushinteger(__ls, ffi_reinterpret_int32_t(result));}
+ else if (std::strcmp(ffi_ret_type_string.c_str(), "uint64") == 0) {lua_pushinteger(__ls, ffi_reinterpret_uint64_t(result));}
+ else if (std::strcmp(ffi_ret_type_string.c_str(), "sint64") == 0) {lua_pushinteger(__ls, ffi_reinterpret_int64_t(result));}
+ else if (std::strcmp(ffi_ret_type_string.c_str(), "float") == 0) {}
+ else if (std::strcmp(ffi_ret_type_string.c_str(), "double") == 0) {}
+ else if (std::strcmp(ffi_ret_type_string.c_str(), "pointer") == 0) {lua_pushinteger(__ls, ffi_reinterpret_uintptr_t(result));}
+ else if (std::strcmp(ffi_ret_type_string.c_str(), "struct") == 0) {}
+ else {PRINT_WITH_COLOR_LB(RED, "unknown return type string.");return 0;}
return 1;
} else {
PRINT_WITH_COLOR_LB(RED, "the index is too high into the xobj vector.");
@@ -1286,9 +1369,9 @@ class LuaWrapper
PRINT_WITH_COLOR_LB(RED, "cant grow lua stack. current size is too small.");
}
for (auto& iter : xlist) {
- std::cout << CYAN << iter.second << NORMAL <<"\n";
+ std::cout << CYAN << iter.second << NORMAL;
lua_pushstring(__ls, iter.second.c_str());
- std::cout << MAGENTA << (long int)iter.first << NORMAL <<"\n";
+ std::cout << " " << MAGENTA << (long int)iter.first << NORMAL <<"\n";
lua_pushinteger(__ls, (long int)iter.first);
lua_settable(__ls, -3);
}
diff --git a/bruiser/bruiserffi.c b/bruiser/bruiserffi.c
index d4d531d..6be7376 100644
--- a/bruiser/bruiserffi.c
+++ b/bruiser/bruiserffi.c
@@ -18,12 +18,99 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*/
/**********************************************************************************************************************/
+// @TODO-structs and unions not supported
+// @TODO-vararg xobjs are not supported
+/**********************************************************************************************************************/
#include <ffi.h>
+#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "bruiserffi.h"
/**********************************************************************************************************************/
+#define VOIDIFY(X) (void*)X
+/**********************************************************************************************************************/
+#define REINTERPRET_GENERATOR(X) \
+ X ffi_reinterpret_##X(void* result) {return (X)result;}
+
+#define X_LIST_GEN \
+ X(uint8_t, "uint8_t")\
+ X(uint16_t, "uint8_t")\
+ X(uint32_t, "uint8_t")\
+ X(uint64_t, "uint8_t")\
+ X(int8_t, "uint8_t")\
+ X(int16_t, "uint8_t")\
+ X(int32_t, "uint8_t")\
+ X(int64_t, "uint8_t")\
+ X(uintptr_t, "uint8_t")\
+ //X(float, "uint8_t")\
+ X(double, "uint8_t")
+
+#define X(X1,X2) REINTERPRET_GENERATOR(X1)
+X_LIST_GEN
+#undef X
+#undef X_LIST_GEN
+#undef REINTERPRET_GENERATOR
+
+void ffi_value_ctor(void** ret, int argc, ...) {
+ va_list value_list;
+ char* arg_string;
+ uint16_t counter = 0U;
+
+ va_start(value_list, argc);
+ for (int i = 0; i < argc; ++i) {
+ arg_string = va_arg(value_list, char*);
+ if (strcmp(arg_string, "uint8") == 0) {
+ uint8_t* dummy = va_arg(value_list, uint8_t*);
+ ret[counter] = VOIDIFY(dummy);
+ }
+ else if (strcmp(arg_string, "sint8") == 0) {
+ int8_t* dummy = va_arg(value_list, int8_t*);
+ ret[counter] = VOIDIFY(dummy);
+ }
+ else if (strcmp(arg_string, "uint16") == 0) {
+ uint16_t* dummy = va_arg(value_list, uint16_t*);
+ ret[counter] = VOIDIFY(dummy);
+ }
+ else if (strcmp(arg_string, "sint16") == 0) {
+ int16_t* dummy = va_arg(value_list, int16_t*);
+ ret[counter] = VOIDIFY(dummy);
+ }
+ else if (strcmp(arg_string, "uint32") == 0) {
+ uint32_t* dummy = va_arg(value_list, uint32_t*);
+ ret[counter] = VOIDIFY(dummy);
+ }
+ else if (strcmp(arg_string, "sint32") == 0) {
+ int32_t* dummy = va_arg(value_list, int32_t*);
+ ret[counter] = VOIDIFY(dummy);
+ }
+ else if (strcmp(arg_string, "uint64") == 0) {
+ uint64_t* dummy = va_arg(value_list, uint64_t*);
+ ret[counter] = VOIDIFY(dummy);
+ }
+ else if (strcmp(arg_string, "sint64") == 0) {
+ int64_t* dummy = va_arg(value_list, int64_t*);
+ ret[counter] = VOIDIFY(dummy);
+ }
+ else if (strcmp(arg_string, "float") == 0) {
+ float* dummy = va_arg(value_list, float*);
+ ret[counter] = dummy;
+ }
+ else if (strcmp(arg_string, "double") == 0) {
+ double* dummy = va_arg(value_list, double*);
+ ret[counter] = dummy;
+ }
+ else if (strcmp(arg_string, "pointer") == 0) {
+ ret[counter] = va_arg(value_list, void*);
+ }
+ else {
+ ret[counter] = NULL;
+ fprintf(stderr, "got garbage arg value string...\n");
+ }
+ counter++;
+ }
+}
+
ffi_type* ffi_type_ctor(const char* arg_string) {
if (strcmp(arg_string, "void") == 0) {return &ffi_type_void;}
else if (strcmp(arg_string, "uint8") == 0) {return &ffi_type_uint8;}
@@ -45,16 +132,17 @@ ffi_type* ffi_type_ctor(const char* arg_string) {
}
}
-void* ffi_callX(int argc, const char** arg_string, ffi_type rtype, void* x_ptr, const char* ret_type) {
+void* ffi_callX(int argc, const char** arg_string, ffi_type rtype, void* x_ptr, void** values) {
ffi_status status;
ffi_cif cif;
ffi_type* args_types[argc];
+ void* ret;
+
for (int i = 0; i < argc; ++i) {
if (ffi_type_ctor(arg_string[i])) args_types[i] = ffi_type_ctor(arg_string[i]);
}
- //status = ffi_prep_cif(&cif, FFI_DEFAULT_ABI, argc, &rtype, args);
- status = ffi_prep_cif(&cif, FFI_DEFAULT_ABI, argc, &ffi_type_uint32, args_types);
+ status = ffi_prep_cif(&cif, FFI_DEFAULT_ABI, argc, &rtype, args_types);
if (status == FFI_BAD_TYPEDEF) {
fprintf(stderr, "ffi_prep_cif returned FFI_BAD_TYPEDEF: %d\n", status);
return NULL;
@@ -68,32 +156,37 @@ void* ffi_callX(int argc, const char** arg_string, ffi_type rtype, void* x_ptr,
return NULL;
}
- uint32_t a = 30;
- uint32_t b = 20;
- void* ret;
- //void* values[argc]; //FIXME the actual arguments
- void* values[2] = {&a, &b};
ffi_call(&cif, FFI_FN(x_ptr), &ret, values);
return ret;
}
-void* ffi_callX_var(int argc, const char** arg_string, ffi_type rtype, void* x_ptr, const char* ret_type) {}
+void* ffi_callX_var(int argc, const char** arg_string, ffi_type rtype, void* x_ptr, void** values) {}
/**********************************************************************************************************************/
// @DEVI-the following lines are only meant for testing.
uint32_t add2(uint32_t a, uint32_t b) {return a+b;}
uint32_t sub2(uint32_t a, uint32_t b) {return a-b;}
+#pragma weak main
int main(int argc, char** argv) {
+ // @DEVI-we get these from lua
void* padd = &add2;
void* psub = &sub2;
+ // @DEVI-user input from lua
int argcount = 2;
+ // @DEVI-we get these from user in lua
ffi_type ret_type = ffi_type_uint32;
+ // @DEVI-we get these from user in lua
const char* args[] = {"uint32", "uint32"};
const char* ret_string = "uint32";
+ uint32_t a = 30;
+ uint32_t b = 20;
+ void* values[2];
+ // @DEVI-we get thsese from the user in lua
+ ffi_value_ctor(values, 2, "uint32", &a, "uint32", &b);
- void* result = ffi_callX(argcount, args, ret_type, psub, ret_string);
- fprintf(stdout, "first result %d\n", (uint32_t)result);
- result = ffi_callX(argcount, args, ret_type, padd, ret_string);
- fprintf(stdout, "first result %d\n", (uint32_t)result);
+ void* result = ffi_callX(argcount, args, ret_type, padd, values);
+ fprintf(stdout, "result of callling add is %d\n", (uint32_t)result);
+ result = ffi_callX(argcount, args, ret_type, psub, values);
+ fprintf(stdout, "result of calling sub is %d\n", (uint32_t)result);
return 0;
}
/**********************************************************************************************************************/
diff --git a/bruiser/bruiserffi.h b/bruiser/bruiserffi.h
index 0f98d2c..f9abdd5 100644
--- a/bruiser/bruiserffi.h
+++ b/bruiser/bruiserffi.h
@@ -19,6 +19,7 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*/
/**********************************************************************************************************************/
#include <ffi.h>
+#include <stdint.h>
/**********************************************************************************************************************/
#ifndef BRUISER_FFI_H
#define BRUISER_FFI_H
@@ -26,9 +27,55 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*
#ifdef __cplusplus
extern "C" {
#endif
+
+#define REINTERPRET_GENERATOR(X) \
+ X ffi_reinterpret_##X(void* result);
+
+#define X_LIST_GEN \
+ X(uint8_t, "uint8_t")\
+ X(uint16_t, "uint8_t")\
+ X(uint32_t, "uint8_t")\
+ X(uint64_t, "uint8_t")\
+ X(int8_t, "uint8_t")\
+ X(int16_t, "uint8_t")\
+ X(int32_t, "uint8_t")\
+ X(int64_t, "uint8_t")\
+ X(uintptr_t, "uint8_t")\
+ //X(float, "uint8_t")\
+ X(double, "uint8_t")
+
+#define X(X1,X2) REINTERPRET_GENERATOR(X1)
+X_LIST_GEN
+#undef X
+#undef X_LIST_GEN
+#undef REINTERPRET_GENERATOR
+
+ /**
+ * @brief constructs the arguments to be passed to ffi_call.
+ * @param ret the void** that will be passed to ffi_call.
+ * @param argc number of the arguments the function that's gonna be called has.
+ * @param ... pairs of the arg types in string format plus the references to the actual args themselves.
+ */
+void ffi_value_ctor(void** ret, int argc, ...);
+
+/**
+ * @brief returns the ffi_type of the given arg.
+ * @param arg_string the type of the arg in string format.
+ * @return the address of the corresponding ffi_type.
+ */
ffi_type* ffi_type_ctor(const char* arg_string);
-void* ffi_callX(int argc, const char** arg_string, ffi_type rtype, void* x_ptr, const char* ret_type);
-void* ffi_callX_var(int argc, const char** arg_string, ffi_type rtype, void* x_ptr, const char* ret_type);
+
+/**
+ * @brief call the xobj.
+ * @param argc number of args the xobj accepts.
+ * @param arg_string a char** of the arg types.
+ * @param rtype ffi_type of the return value.
+ * @param x_ptr the void* xobj pointer.
+ * @param values the actual args to be passed to ffi_call.
+ * @return return a void* to the return value of the xobj.
+ */
+void* ffi_callX(int argc, const char** arg_string, ffi_type rtype, void* x_ptr, void** values);
+void* ffi_callX_var(int argc, const char** arg_string, ffi_type rtype, void* x_ptr, void** values);
#ifdef __cplusplus
}
#endif
diff --git a/bruiser/compile_commands.json b/bruiser/compile_commands.json
index ef1b5c5..e72faee 100644
--- a/bruiser/compile_commands.json
+++ b/bruiser/compile_commands.json
@@ -1,6 +1,6 @@
[
{
- "command": "c++ -c -I/home/bloodstalker/extra/llvm-clang-4/llvm/include -I/home/bloodstalker/extra/llvm-clang-4/build/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment -ffunction-sections -fdata-sections -O2 -fno-exceptions -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/bloodstalker/extra/llvm-clang-4/llvm/tools/clang/include -I/home/bloodstalker/extra/llvm-clang-4/build/tools/clang/include -std=c++1z -stdlib=libstdc++ -UNDEBUG -fexceptions -I/usr/include -I/usr/include/python3.5m -o bruiser.o bruiser.cpp",
+ "command": "c++ -c -I/home/bloodstalker/extra/llvm-clang-4/llvm/include -I/home/bloodstalker/extra/llvm-clang-4/build/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment -ffunction-sections -fdata-sections -O2 -fno-exceptions -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/bloodstalker/extra/llvm-clang-4/llvm/tools/clang/include -I/home/bloodstalker/extra/llvm-clang-4/build/tools/clang/include -std=c++1z -stdlib=libstdc++ -UNDEBUG -fexceptions -I/usr/include -I/usr/include/python3.5m -I/usr/include/python3.5m -o bruiser.o bruiser.cpp",
"directory": "/home/bloodstalker/devi/hell2/bruiser",
"file": "/home/bloodstalker/devi/hell2/bruiser/bruiser.cpp"
},
@@ -10,21 +10,26 @@
"file": "/home/bloodstalker/devi/hell2/bruiser/linenoise/linenoise.c"
},
{
- "command": "c++ -c -I/home/bloodstalker/extra/llvm-clang-4/llvm/include -I/home/bloodstalker/extra/llvm-clang-4/build/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment -ffunction-sections -fdata-sections -O2 -fno-exceptions -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/bloodstalker/extra/llvm-clang-4/llvm/tools/clang/include -I/home/bloodstalker/extra/llvm-clang-4/build/tools/clang/include -std=c++1z -stdlib=libstdc++ -UNDEBUG -fexceptions -I/usr/include -I/usr/include/python3.5m -o CompletionHints.o CompletionHints.cpp",
+ "command": "c++ -c -I/home/bloodstalker/extra/llvm-clang-4/llvm/include -I/home/bloodstalker/extra/llvm-clang-4/build/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment -ffunction-sections -fdata-sections -O2 -fno-exceptions -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/bloodstalker/extra/llvm-clang-4/llvm/tools/clang/include -I/home/bloodstalker/extra/llvm-clang-4/build/tools/clang/include -std=c++1z -stdlib=libstdc++ -UNDEBUG -fexceptions -I/usr/include -I/usr/include/python3.5m -I/usr/include/python3.5m -o CompletionHints.o CompletionHints.cpp",
"directory": "/home/bloodstalker/devi/hell2/bruiser",
"file": "/home/bloodstalker/devi/hell2/bruiser/CompletionHints.cpp"
},
{
- "command": "c++ -c -I/home/bloodstalker/extra/llvm-clang-4/llvm/include -I/home/bloodstalker/extra/llvm-clang-4/build/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment -ffunction-sections -fdata-sections -O2 -fno-exceptions -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/bloodstalker/extra/llvm-clang-4/llvm/tools/clang/include -I/home/bloodstalker/extra/llvm-clang-4/build/tools/clang/include -std=c++1z -stdlib=libstdc++ -UNDEBUG -fexceptions -I/usr/include -I/usr/include/python3.5m -o mutagen.o mutagen.cpp",
+ "command": "c++ -c -I/home/bloodstalker/extra/llvm-clang-4/llvm/include -I/home/bloodstalker/extra/llvm-clang-4/build/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment -ffunction-sections -fdata-sections -O2 -fno-exceptions -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/bloodstalker/extra/llvm-clang-4/llvm/tools/clang/include -I/home/bloodstalker/extra/llvm-clang-4/build/tools/clang/include -std=c++1z -stdlib=libstdc++ -UNDEBUG -fexceptions -I/usr/include -I/usr/include/python3.5m -I/usr/include/python3.5m -o mutagen.o mutagen.cpp",
"directory": "/home/bloodstalker/devi/hell2/bruiser",
"file": "/home/bloodstalker/devi/hell2/bruiser/mutagen.cpp"
},
{
- "command": "c++ -c -I/home/bloodstalker/extra/llvm-clang-4/llvm/include -I/home/bloodstalker/extra/llvm-clang-4/build/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment -ffunction-sections -fdata-sections -O2 -fno-exceptions -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/bloodstalker/extra/llvm-clang-4/llvm/tools/clang/include -I/home/bloodstalker/extra/llvm-clang-4/build/tools/clang/include -std=c++1z -stdlib=libstdc++ -UNDEBUG -fexceptions -I/usr/include -I/usr/include/python3.5m -o ORCmutation.o ORCmutation.cpp",
+ "command": "c++ -c -I/home/bloodstalker/extra/llvm-clang-4/llvm/include -I/home/bloodstalker/extra/llvm-clang-4/build/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment -ffunction-sections -fdata-sections -O2 -fno-exceptions -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/bloodstalker/extra/llvm-clang-4/llvm/tools/clang/include -I/home/bloodstalker/extra/llvm-clang-4/build/tools/clang/include -std=c++1z -stdlib=libstdc++ -UNDEBUG -fexceptions -I/usr/include -I/usr/include/python3.5m -I/usr/include/python3.5m -o ORCmutation.o ORCmutation.cpp",
"directory": "/home/bloodstalker/devi/hell2/bruiser",
"file": "/home/bloodstalker/devi/hell2/bruiser/ORCmutation.cpp"
},
{
+ "command": "cc -c -o bruiserffi.o bruiserffi.c",
+ "directory": "/home/bloodstalker/devi/hell2/bruiser",
+ "file": "/home/bloodstalker/devi/hell2/bruiser/bruiserffi.c"
+ },
+ {
"command": "cc -c -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_USE_LINUX -o lapi.o lapi.c",
"directory": "/home/bloodstalker/devi/hell2/bruiser/lua-5.3.4/src",
"file": "/home/bloodstalker/devi/hell2/bruiser/lua-5.3.4/src/lapi.c"
diff --git a/bruiser/lua-scripts/demo1.lua b/bruiser/lua-scripts/demo1.lua
index 0bf26f6..c5c9d27 100644
--- a/bruiser/lua-scripts/demo1.lua
+++ b/bruiser/lua-scripts/demo1.lua
@@ -120,6 +120,13 @@ end
-- registration_name()
-- end of @placeholder
+-- start of @placeholder
+-- C--args = argc, arg_string, ffi_type, xptr, the_actual_args
+-- lua--args = number, table, string, xptr, args
+-- end of @placeholder
+function callX(n_argc, t_string, str, index, t_values)
+end
+
function main()
printObjNames()
printObjSizes()
@@ -148,6 +155,10 @@ function main()
pwd()
xobjregister(add2_code, "add2")
xobjregister(sub2_code, "sub2")
+ a=xcall(2,{"uint32","uint32"},"uint32",0, {30,20})
+ print("call add result", a)
+ a=xcall(2,{"uint32", "uint32"},"uint32",1, {30,20})
+ print("call sub result", a)
end
main()
diff --git a/bruiser/makefile b/bruiser/makefile
index 20d0956..c94359a 100644
--- a/bruiser/makefile
+++ b/bruiser/makefile
@@ -32,6 +32,9 @@ depend: .bruiser.d
.cpp.o: depend
$(CXX) $(CXX_FLAGS) -c $< -o $@
+.c.o:
+ $(CC) $(CC_FLAGS) -c $< -o $@
+
linenoise.o:
$(CC) $(CC_FLAGS) linenoise/linenoise.c -c -o linenoise.o
@@ -43,7 +46,7 @@ $(LIB_LUA_JIT):
$(MAKE) -C LuaJIT
@echo "building with jit"
-$(BRUISER): $(BRUISER).o ../mutator_aux.o ../tinyxml2/tinyxml2.o linenoise.o CompletionHints.o mutagen.o ORCmutation.o $(LIB_LUA)
+$(BRUISER): $(BRUISER).o ../mutator_aux.o ../tinyxml2/tinyxml2.o linenoise.o CompletionHints.o mutagen.o ORCmutation.o bruiserffi.o $(LIB_LUA)
$(CXX) $^ $(LD_FLAGS) -o $@
clean: