gateway source is moved into wrapper source
This commit is contained in:
parent
698248d2bf
commit
78705a5175
3 changed files with 58 additions and 110 deletions
|
|
@ -1706,18 +1706,13 @@ SCILAB_INC= @SCILABINCLUDE@
|
||||||
SCILAB_OPT = @SCILABOPT@
|
SCILAB_OPT = @SCILABOPT@
|
||||||
SCILAB_LIBPREFIX = lib
|
SCILAB_LIBPREFIX = lib
|
||||||
|
|
||||||
# Gateway entry point source file
|
|
||||||
SCILAB_GW = $(addprefix gw_, $(INTERFACE))
|
|
||||||
SCILAB_GWSRCS = $(SCILAB_GW:.i=.c)
|
|
||||||
SCILAB_GWOBJS = $(SCILAB_GW:.i=.o)
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
# Build a C dynamically loadable module
|
# Build a C dynamically loadable module
|
||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
|
|
||||||
scilab:
|
scilab:
|
||||||
$(SWIG) -scilab -nobuilder $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH);
|
$(SWIG) -scilab -nobuilder $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH);
|
||||||
$(CC) -g -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(SCILAB_INC) $(INCLUDES) $(ISRCS) $(SCILAB_GWSRCS) $(SRCDIR_SRCS) $(SRCDIR_CSRCS)
|
$(CC) -g -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(SCILAB_INC) $(INCLUDES) $(ISRCS) $(SRCDIR_SRCS) $(SRCDIR_CSRCS)
|
||||||
$(LDSHARED) $(CFLAGS) $(LDFLAGS) $(IOBJS) $(SCILAB_GWOBJS) $(OBJS) $(LIBS) -o $(SCILAB_LIBPREFIX)$(TARGET)$(SO)
|
$(LDSHARED) $(CFLAGS) $(LDFLAGS) $(IOBJS) $(SCILAB_GWOBJS) $(OBJS) $(LIBS) -o $(SCILAB_LIBPREFIX)$(TARGET)$(SO)
|
||||||
|
|
||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
|
|
@ -1726,9 +1721,8 @@ scilab:
|
||||||
|
|
||||||
scilab_cpp:
|
scilab_cpp:
|
||||||
$(SWIG) -scilab -c++ -nobuilder $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH);
|
$(SWIG) -scilab -c++ -nobuilder $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH);
|
||||||
$(CC) -g -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(SCILAB_INC) $(INCLUDES) $(SCILAB_GWSRCS)
|
|
||||||
$(CXX) -g -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(SCILAB_INC) $(INCLUDES) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS)
|
$(CXX) -g -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(SCILAB_INC) $(INCLUDES) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS)
|
||||||
$(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(IOBJS) $(SCILAB_GWOBJS) $(OBJS) $(LIBS) $(CPP_DLLIBS) -o $(SCILAB_LIBPREFIX)$(TARGET)$(SO)
|
$(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(IOBJS) $(OBJS) $(LIBS) $(CPP_DLLIBS) -o $(SCILAB_LIBPREFIX)$(TARGET)$(SO)
|
||||||
|
|
||||||
# -----------------------------------------------------------------
|
# -----------------------------------------------------------------
|
||||||
# Running a Scilab example
|
# Running a Scilab example
|
||||||
|
|
@ -1752,7 +1746,7 @@ scilab_clean:
|
||||||
rm -f *_wrap* *~ .~*
|
rm -f *_wrap* *~ .~*
|
||||||
rm -f core @EXTRA_CLEAN@
|
rm -f core @EXTRA_CLEAN@
|
||||||
rm -f *.@OBJEXT@ *@SO@
|
rm -f *.@OBJEXT@ *@SO@
|
||||||
rm -f *.sce gw_*.c
|
rm -f *.sce
|
||||||
|
|
||||||
##################################################################
|
##################################################################
|
||||||
##### Go ######
|
##### Go ######
|
||||||
|
|
|
||||||
|
|
@ -21,13 +21,12 @@ extern "C" {
|
||||||
#include "Scierror.h"
|
#include "Scierror.h"
|
||||||
#include "localization.h"
|
#include "localization.h"
|
||||||
#include "freeArrayOfString.h"
|
#include "freeArrayOfString.h"
|
||||||
|
#include <sci_gateway.h>
|
||||||
|
#include <mex.h>
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#undef Max
|
|
||||||
#undef Min
|
|
||||||
|
|
||||||
/* Gateway signature */
|
/* Gateway signature */
|
||||||
|
|
||||||
#if SWIG_SCILAB_VERSION >= 600
|
#if SWIG_SCILAB_VERSION >= 600
|
||||||
|
|
|
||||||
|
|
@ -51,10 +51,7 @@ protected:
|
||||||
String *verboseBuildLevel;
|
String *verboseBuildLevel;
|
||||||
String *buildFlagsScript;
|
String *buildFlagsScript;
|
||||||
|
|
||||||
bool createGatewaySource;
|
String *gatewayHeader;
|
||||||
File *gatewaySourceFile;
|
|
||||||
String *gatewaySourceWrapperDeclaration;
|
|
||||||
String *gatewaySourceFunctionTable;
|
|
||||||
|
|
||||||
bool createGatewayXML;
|
bool createGatewayXML;
|
||||||
File *gatewayXMLFile;
|
File *gatewayXMLFile;
|
||||||
|
|
@ -80,10 +77,7 @@ public:
|
||||||
verboseBuildLevel = NULL;
|
verboseBuildLevel = NULL;
|
||||||
buildFlagsScript = NULL;
|
buildFlagsScript = NULL;
|
||||||
|
|
||||||
createGatewaySource = false;
|
gatewayHeader = NULL;
|
||||||
gatewaySourceWrapperDeclaration = NULL;
|
|
||||||
gatewaySourceFunctionTable = NULL;
|
|
||||||
gatewaySourceFile = NULL;
|
|
||||||
|
|
||||||
createGatewayXML = false;
|
createGatewayXML = false;
|
||||||
gatewayXML = NULL;
|
gatewayXML = NULL;
|
||||||
|
|
@ -102,7 +96,6 @@ public:
|
||||||
} else if (strcmp(argv[argIndex], "-builder") == 0) {
|
} else if (strcmp(argv[argIndex], "-builder") == 0) {
|
||||||
Swig_mark_arg(argIndex);
|
Swig_mark_arg(argIndex);
|
||||||
generateBuilder = true;
|
generateBuilder = true;
|
||||||
createGatewaySource = false;
|
|
||||||
createLoader = false;
|
createLoader = false;
|
||||||
} else if (strcmp(argv[argIndex], "-buildersources") == 0) {
|
} else if (strcmp(argv[argIndex], "-buildersources") == 0) {
|
||||||
if (argv[argIndex + 1] != NULL) {
|
if (argv[argIndex + 1] != NULL) {
|
||||||
|
|
@ -137,7 +130,6 @@ public:
|
||||||
} else if (strcmp(argv[argIndex], "-nobuilder") == 0) {
|
} else if (strcmp(argv[argIndex], "-nobuilder") == 0) {
|
||||||
Swig_mark_arg(argIndex);
|
Swig_mark_arg(argIndex);
|
||||||
generateBuilder = false;
|
generateBuilder = false;
|
||||||
createGatewaySource = true;
|
|
||||||
createLoader = true;
|
createLoader = true;
|
||||||
} else if (strcmp(argv[argIndex], "-gatewayxml") == 0) {
|
} else if (strcmp(argv[argIndex], "-gatewayxml") == 0) {
|
||||||
Swig_mark_arg(argIndex);
|
Swig_mark_arg(argIndex);
|
||||||
|
|
@ -176,8 +168,7 @@ public:
|
||||||
/* Get the module name */
|
/* Get the module name */
|
||||||
String *gatewayName = Getattr(node, "name");
|
String *gatewayName = Getattr(node, "name");
|
||||||
|
|
||||||
// Set gateway source and library name
|
// Set library name
|
||||||
String *gatewaySourceName = NewStringf("gw_%s", gatewayName);
|
|
||||||
String *gatewayLibraryName = NewStringf("lib%s", gatewayName);
|
String *gatewayLibraryName = NewStringf("lib%s", gatewayName);
|
||||||
|
|
||||||
/* Get the output file name */
|
/* Get the output file name */
|
||||||
|
|
@ -208,18 +199,17 @@ public:
|
||||||
if (generateBuilder) {
|
if (generateBuilder) {
|
||||||
createBuilderFile(outputFilename);
|
createBuilderFile(outputFilename);
|
||||||
}
|
}
|
||||||
// Create gateway source if required
|
|
||||||
if (createGatewaySource) {
|
|
||||||
createGatewaySourceFile(gatewaySourceName);
|
|
||||||
}
|
|
||||||
// Create gateway XML if required
|
// Create gateway XML if required
|
||||||
if (createGatewayXML) {
|
if (createGatewayXML) {
|
||||||
createGatewayXMLFile(gatewayName);
|
createGatewayXMLFile(gatewayName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create loader script if required
|
// Create loader script if required
|
||||||
if (createLoader) {
|
if (createLoader) {
|
||||||
createLoaderFile(gatewayLibraryName);
|
createLoaderFile(gatewayLibraryName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Module initialization function
|
// Module initialization function
|
||||||
String *gatewayInitFunctionName = NewStringf("%s_Init", gatewayName);
|
String *gatewayInitFunctionName = NewStringf("%s_Init", gatewayName);
|
||||||
|
|
||||||
|
|
@ -258,22 +248,22 @@ public:
|
||||||
/* Write all to the wrapper file */
|
/* Write all to the wrapper file */
|
||||||
SwigType_emit_type_table(runtimeSection, wrappersSection); // Declare pointer types, ... (Ex: SWIGTYPE_p_p_double)
|
SwigType_emit_type_table(runtimeSection, wrappersSection); // Declare pointer types, ... (Ex: SWIGTYPE_p_p_double)
|
||||||
|
|
||||||
|
// Add gateway functions declaration to init section
|
||||||
|
terminateGatewayHeader(gatewayName);
|
||||||
|
Printv(initSection, gatewayHeader, NIL);
|
||||||
|
|
||||||
Dump(runtimeSection, beginSection);
|
Dump(runtimeSection, beginSection);
|
||||||
Dump(headerSection, beginSection);
|
Dump(headerSection, beginSection);
|
||||||
Dump(wrappersSection, beginSection);
|
Dump(wrappersSection, beginSection);
|
||||||
Dump(variablesCode, beginSection);
|
Dump(variablesCode, beginSection);
|
||||||
Wrapper_pretty_print(initSection, beginSection);
|
Wrapper_pretty_print(initSection, beginSection);
|
||||||
|
|
||||||
if (createGatewaySource) {
|
|
||||||
saveGatewaySourceFile(gatewaySourceName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (createGatewayXML) {
|
if (createGatewayXML) {
|
||||||
saveGatewayXMLFile();
|
saveGatewayXMLFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (createLoader) {
|
if (createLoader) {
|
||||||
saveLoaderFile(gatewaySourceName, gatewayLibraryName);
|
saveLoaderFile(gatewayName, gatewayLibraryName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Cleanup files */
|
/* Cleanup files */
|
||||||
|
|
@ -837,14 +827,12 @@ public:
|
||||||
* ----------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------- */
|
||||||
|
|
||||||
void addFunctionToScilab(const_String_or_char_ptr scilabFunctionName, const_String_or_char_ptr wrapperFunctionName) {
|
void addFunctionToScilab(const_String_or_char_ptr scilabFunctionName, const_String_or_char_ptr wrapperFunctionName) {
|
||||||
|
addFunctionInGatewayHeader(scilabFunctionName, wrapperFunctionName);
|
||||||
|
|
||||||
if (generateBuilder) {
|
if (generateBuilder) {
|
||||||
addFunctionInScriptTable(scilabFunctionName, wrapperFunctionName, builderCode);
|
addFunctionInScriptTable(scilabFunctionName, wrapperFunctionName, builderCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gatewaySourceFile) {
|
|
||||||
addFunctionInGatewaySource(scilabFunctionName, wrapperFunctionName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (createLoader) {
|
if (createLoader) {
|
||||||
addFunctionInLoader(scilabFunctionName);
|
addFunctionInLoader(scilabFunctionName);
|
||||||
}
|
}
|
||||||
|
|
@ -992,83 +980,51 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------
|
/* -----------------------------------------------------------------------
|
||||||
* createGatewaySourceFile()
|
* addFunctionInGatewayHeader()
|
||||||
* Creates the gateway entry point source file (entry point gw_<module>.c)
|
* Add a function in the gateway header
|
||||||
* ----------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------- */
|
||||||
|
|
||||||
void createGatewaySourceFile(String *gatewaySourceName) {
|
void addFunctionInGatewayHeader(const_String_or_char_ptr scilabFunctionName, const_String_or_char_ptr wrapperFunctionName) {
|
||||||
String *gatewaySourceFilename = NewStringf("%s.c", gatewaySourceName);
|
if (gatewayHeader == NULL) {
|
||||||
gatewaySourceFile = NewFile(gatewaySourceFilename, "w", SWIG_output_files());
|
gatewayHeader = NewString("");
|
||||||
if (!gatewaySourceFile) {
|
Printf(gatewayHeader, "\n");
|
||||||
FileErrorDisplay(gatewaySourceFilename);
|
Printf(gatewayHeader, "#ifdef __cplusplus\n");
|
||||||
SWIG_exit(EXIT_FAILURE);
|
Printf(gatewayHeader, "extern \"C\" {\n");
|
||||||
}
|
Printf(gatewayHeader, "#endif\n");
|
||||||
|
Printf(gatewayHeader, "static int direct_gateway(char *fname, void F(void)) { F();\n");
|
||||||
emitBanner(gatewaySourceFile);
|
Printf(gatewayHeader, "return 0; };\n");
|
||||||
String *gatewaySource = NewString("");
|
Printf(gatewayHeader, "static GenericTable Tab[] = {\n");
|
||||||
Printf(gatewaySource, "#ifdef __cplusplus\n");
|
Printf(gatewayHeader, " {(Myinterfun)sci_gateway, (GT)%s, (char *)\"%s\"}\n", wrapperFunctionName, scilabFunctionName);
|
||||||
Printf(gatewaySource, "extern \"C\" {\n");
|
|
||||||
Printf(gatewaySource, "#endif\n");
|
|
||||||
Printf(gatewaySource, "\n");
|
|
||||||
Printf(gatewaySource, "#include <api_scilab.h>\n");
|
|
||||||
Printf(gatewaySource, "#include <mex.h>\n");
|
|
||||||
Printf(gatewaySource, "#include <sci_gateway.h>\n");
|
|
||||||
Printf(gatewaySource, "#include <MALLOC.h>\n");
|
|
||||||
Printf(gatewaySource, "\n");
|
|
||||||
Printf(gatewaySource, "static int direct_gateway(char *fname, void F(void)) { F(); return 0; };\n");
|
|
||||||
Printv(gatewaySourceFile, gatewaySource, NIL);
|
|
||||||
|
|
||||||
gatewaySourceWrapperDeclaration = NewString("");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------
|
|
||||||
* addFunctionInGatewaySource()
|
|
||||||
* Add a function in the gateway entry point source
|
|
||||||
* ----------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
void addFunctionInGatewaySource(const_String_or_char_ptr scilabFunctionName, const_String_or_char_ptr wrapperFunctionName) {
|
|
||||||
Printf(gatewaySourceWrapperDeclaration, "extern Gatefunc %s;\n", wrapperFunctionName);
|
|
||||||
if (gatewaySourceFunctionTable == NULL) {
|
|
||||||
gatewaySourceFunctionTable = NewString("static GenericTable Tab[] = {\n");
|
|
||||||
Printf(gatewaySourceFunctionTable, " {(Myinterfun)sci_gateway, %s, \"%s\"}\n", wrapperFunctionName, scilabFunctionName);
|
|
||||||
} else
|
} else
|
||||||
Printf(gatewaySourceFunctionTable, " ,{(Myinterfun)sci_gateway, %s, \"%s\"}\n", wrapperFunctionName, scilabFunctionName);
|
Printf(gatewayHeader, " ,{(Myinterfun)sci_gateway, (GT)%s, (char *)\"%s\"}\n", wrapperFunctionName, scilabFunctionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------
|
/* -----------------------------------------------------------------------
|
||||||
* saveGatewaySourceFile()
|
* terminateGatewayHeader()
|
||||||
* Saves the gateway entry point source file
|
* Terminates the gateway header
|
||||||
* ----------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------- */
|
||||||
|
|
||||||
void saveGatewaySourceFile(String *gatewaySourceName) {
|
void terminateGatewayHeader(String *moduleName) {
|
||||||
Printv(gatewaySourceFile, gatewaySourceWrapperDeclaration, NIL);
|
Printf(gatewayHeader, "};\n");
|
||||||
Printf(gatewaySourceFunctionTable, "};\n");
|
Printf(gatewayHeader, "\n");
|
||||||
|
Printf(gatewayHeader, "int C2F(gw_%s)()\n", moduleName);
|
||||||
Printv(gatewaySourceFile, gatewaySourceFunctionTable, NIL);
|
Printf(gatewayHeader, "{\n");
|
||||||
Printv(gatewaySourceFile, "\n", NIL);
|
Printf(gatewayHeader, " Rhs = Max(0, Rhs);\n");
|
||||||
|
Printf(gatewayHeader, " if (*(Tab[Fin-1].f) != NULL)\n");
|
||||||
String *gatewaySourceEntryPoint = NewString("");
|
Printf(gatewayHeader, " {\n");
|
||||||
Printf(gatewaySourceEntryPoint, "int C2F(%s)()\n", gatewaySourceName);
|
Printf(gatewayHeader, " if(pvApiCtx == NULL)\n");
|
||||||
Printf(gatewaySourceEntryPoint, "{\n");
|
Printf(gatewayHeader, " {\n");
|
||||||
Printf(gatewaySourceEntryPoint, " Rhs = Max(0, Rhs);\n");
|
Printf(gatewayHeader, " pvApiCtx = (StrCtx*)MALLOC(sizeof(StrCtx));\n");
|
||||||
Printf(gatewaySourceEntryPoint, " if (*(Tab[Fin-1].f) != NULL)\n");
|
Printf(gatewayHeader, " }\n");
|
||||||
Printf(gatewaySourceEntryPoint, " {\n");
|
Printf(gatewayHeader, " pvApiCtx->pstName = (char*)Tab[Fin-1].name;\n");
|
||||||
Printf(gatewaySourceEntryPoint, " if(pvApiCtx == NULL)\n");
|
Printf(gatewayHeader, " (*(Tab[Fin-1].f))(Tab[Fin-1].name,(GatefuncH)Tab[Fin-1].F);\n");
|
||||||
Printf(gatewaySourceEntryPoint, " {\n");
|
Printf(gatewayHeader, " }\n");
|
||||||
Printf(gatewaySourceEntryPoint, " pvApiCtx = (StrCtx*)MALLOC(sizeof(StrCtx));\n");
|
Printf(gatewayHeader, " return 0;\n");
|
||||||
Printf(gatewaySourceEntryPoint, " }\n");
|
Printf(gatewayHeader, "}\n");
|
||||||
Printf(gatewaySourceEntryPoint, " pvApiCtx->pstName = (char*)Tab[Fin-1].name;\n");
|
Printf(gatewayHeader, "\n");
|
||||||
Printf(gatewaySourceEntryPoint, " (*(Tab[Fin-1].f))(Tab[Fin-1].name,Tab[Fin-1].F);\n");
|
Printf(gatewayHeader, "#ifdef __cplusplus\n");
|
||||||
Printf(gatewaySourceEntryPoint, " }\n");
|
Printf(gatewayHeader, "}\n");
|
||||||
Printf(gatewaySourceEntryPoint, " return 0;\n");
|
Printf(gatewayHeader, "#endif\n");
|
||||||
Printf(gatewaySourceEntryPoint, "}\n");
|
|
||||||
Printf(gatewaySourceEntryPoint, "\n");
|
|
||||||
Printf(gatewaySourceEntryPoint, "#ifdef __cplusplus\n");
|
|
||||||
Printf(gatewaySourceEntryPoint, "}\n");
|
|
||||||
Printf(gatewaySourceEntryPoint, "#endif\n");
|
|
||||||
Printv(gatewaySourceFile, gatewaySourceEntryPoint, NIL);
|
|
||||||
|
|
||||||
Delete(gatewaySourceFile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1110,11 +1066,10 @@ public:
|
||||||
* Terminates and saves the loader script
|
* Terminates and saves the loader script
|
||||||
* ----------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------- */
|
||||||
|
|
||||||
void saveLoaderFile(String *gatewaySourceName, String *gatewayLibraryName) {
|
void saveLoaderFile(String *gatewayName, String *gatewayLibraryName) {
|
||||||
Printf(loaderScript, "];\n");
|
Printf(loaderScript, "];\n");
|
||||||
|
Printf(loaderScript, "addinter(fullfile(%s_path, '%s' + getdynlibext()), 'gw_%s', list_functions);\n",
|
||||||
Printf(loaderScript, "addinter(fullfile(%s_path, '%s' + getdynlibext()), '%s', list_functions);\n",
|
gatewayLibraryName, gatewayLibraryName, gatewayName);
|
||||||
gatewayLibraryName, gatewayLibraryName, gatewaySourceName);
|
|
||||||
Printf(loaderScript, "clear %s_path;\n", gatewayLibraryName);
|
Printf(loaderScript, "clear %s_path;\n", gatewayLibraryName);
|
||||||
Printf(loaderScript, "clear bOK;\n");
|
Printf(loaderScript, "clear bOK;\n");
|
||||||
Printf(loaderScript, "clear ilib;\n");
|
Printf(loaderScript, "clear ilib;\n");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue