scilab: remove outputlibrary option + renaming module to gateway
This commit is contained in:
parent
06614ebb79
commit
30faff1fce
2 changed files with 37 additions and 79 deletions
|
|
@ -290,12 +290,6 @@ The following table lists the Scilab specific command line options in addition t
|
||||||
<td>Generate the gateway XML with the given <gateway_id></td>
|
<td>Generate the gateway XML with the given <gateway_id></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td>-outputlibrary <name></td>
|
|
||||||
<td>Set name of the output library</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,7 @@ Scilab options (available with -scilab)\n\
|
||||||
-buildflags <file> - Use the Scilab script <file> to set build flags\n\
|
-buildflags <file> - Use the Scilab script <file> to set build flags\n\
|
||||||
-buildverbositylevel <level> - Set the build verbosity <level> (default 0)\n\
|
-buildverbositylevel <level> - Set the build verbosity <level> (default 0)\n\
|
||||||
-gatewayxml <gateway_id> - Generate gateway xml with the given <gateway_id>\n\
|
-gatewayxml <gateway_id> - Generate gateway xml with the given <gateway_id>\n\
|
||||||
-nobuilder - Do not generate builder script\n\
|
-nobuilder - Do not generate builder script\n\n";
|
||||||
-outputlibrary <name> - Set name of the output library to <name>\n\n";
|
|
||||||
|
|
||||||
class SCILAB:public Language {
|
class SCILAB:public Language {
|
||||||
protected:
|
protected:
|
||||||
|
|
@ -67,8 +66,6 @@ protected:
|
||||||
bool createLoader;
|
bool createLoader;
|
||||||
File *loaderFile;
|
File *loaderFile;
|
||||||
String* loaderScript;
|
String* loaderScript;
|
||||||
|
|
||||||
String *libraryName;
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------
|
||||||
|
|
@ -98,8 +95,6 @@ public:
|
||||||
loaderFile = NULL;
|
loaderFile = NULL;
|
||||||
loaderScript = NULL;
|
loaderScript = NULL;
|
||||||
|
|
||||||
libraryName = NULL;
|
|
||||||
|
|
||||||
/* Manage command line arguments */
|
/* Manage command line arguments */
|
||||||
for (int argIndex = 1; argIndex < argc; argIndex++) {
|
for (int argIndex = 1; argIndex < argc; argIndex++) {
|
||||||
if (argv[argIndex] != NULL) {
|
if (argv[argIndex] != NULL) {
|
||||||
|
|
@ -145,10 +140,6 @@ public:
|
||||||
createGatewayXML = true;
|
createGatewayXML = true;
|
||||||
gatewayID = NewString(argv[argIndex + 1]);
|
gatewayID = NewString(argv[argIndex + 1]);
|
||||||
Swig_mark_arg(argIndex + 1);
|
Swig_mark_arg(argIndex + 1);
|
||||||
} else if (strcmp(argv[argIndex], "-outputlibrary") == 0) {
|
|
||||||
Swig_mark_arg(argIndex);
|
|
||||||
libraryName = NewString(argv[argIndex + 1]);
|
|
||||||
Swig_mark_arg(argIndex + 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -179,12 +170,11 @@ public:
|
||||||
virtual int top(Node *node) {
|
virtual int top(Node *node) {
|
||||||
|
|
||||||
/* Get the module name */
|
/* Get the module name */
|
||||||
String *moduleName = Getattr(node, "name");
|
String *gatewayName = Getattr(node, "name");
|
||||||
|
|
||||||
/* Set the library name if not specified */
|
// Set gateway source and library name
|
||||||
if (libraryName == NULL) {
|
String* gatewaySourceName = NewStringf("gw_%s", gatewayName);
|
||||||
libraryName = moduleName;
|
String* gatewayLibraryName = NewStringf("lib%s", gatewayName);
|
||||||
}
|
|
||||||
|
|
||||||
/* Get the output file name */
|
/* Get the output file name */
|
||||||
String *outputFilename = Getattr(node, "outfile");
|
String *outputFilename = Getattr(node, "outfile");
|
||||||
|
|
@ -212,31 +202,29 @@ public:
|
||||||
|
|
||||||
// Create builder file if required
|
// Create builder file if required
|
||||||
if (generateBuilder) {
|
if (generateBuilder) {
|
||||||
createBuilderFile();
|
createBuilderFile(outputFilename);
|
||||||
startBuilderCode(outputFilename);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create gateway source if required
|
// Create gateway source if required
|
||||||
if (createGatewaySource) {
|
if (createGatewaySource) {
|
||||||
createGatewaySourceFile(moduleName);
|
createGatewaySourceFile(gatewaySourceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create gateway XML if required
|
// Create gateway XML if required
|
||||||
if (createGatewayXML) {
|
if (createGatewayXML) {
|
||||||
createGatewayXMLFile(moduleName);
|
createGatewayXMLFile(gatewayName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create loader script if required
|
// Create loader script if required
|
||||||
if (createLoader) {
|
if (createLoader) {
|
||||||
createLoaderFile(moduleName);
|
createLoaderFile(gatewayLibraryName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Module initialization function
|
// Module initialization function
|
||||||
String *moduleInitFunctionName = NewString("");
|
String *gatewayInitFunctionName = NewStringf("%s_Init", gatewayName);
|
||||||
Printf(moduleInitFunctionName, "%s_Init", moduleName);
|
|
||||||
|
|
||||||
/* Add initialization function to builder table */
|
/* Add initialization function to builder table */
|
||||||
addFunctionToScilab(moduleInitFunctionName, moduleInitFunctionName);
|
addFunctionToScilab(gatewayInitFunctionName, gatewayInitFunctionName);
|
||||||
|
|
||||||
// Add helper functions to builder table
|
// Add helper functions to builder table
|
||||||
addHelperFunctions();
|
addHelperFunctions();
|
||||||
|
|
@ -260,13 +248,12 @@ public:
|
||||||
|
|
||||||
// Add Builder footer code and save
|
// Add Builder footer code and save
|
||||||
if (generateBuilder) {
|
if (generateBuilder) {
|
||||||
terminateBuilderCode();
|
saveBuilderFile(gatewayLibraryName);
|
||||||
saveBuilderFile();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Close the init function and rename with module name */
|
/* Close the init function and rename with module name */
|
||||||
Printf(initSection, "return 0;\n}\n");
|
Printf(initSection, "return 0;\n}\n");
|
||||||
Replaceall(initSection, "<module>", moduleName);
|
Replaceall(initSection, "<module>", gatewayName);
|
||||||
|
|
||||||
/* 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)
|
||||||
|
|
@ -278,7 +265,7 @@ public:
|
||||||
Wrapper_pretty_print(initSection, beginSection);
|
Wrapper_pretty_print(initSection, beginSection);
|
||||||
|
|
||||||
if (createGatewaySource) {
|
if (createGatewaySource) {
|
||||||
saveGatewaySourceFile(moduleName);
|
saveGatewaySourceFile(gatewaySourceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (createGatewayXML) {
|
if (createGatewayXML) {
|
||||||
|
|
@ -286,7 +273,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (createLoader) {
|
if (createLoader) {
|
||||||
saveLoaderFile(moduleName);
|
saveLoaderFile(gatewaySourceName, gatewayLibraryName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Cleanup files */
|
/* Cleanup files */
|
||||||
|
|
@ -876,7 +863,7 @@ public:
|
||||||
* createBuilderCode()
|
* createBuilderCode()
|
||||||
* ----------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------- */
|
||||||
|
|
||||||
void createBuilderFile() {
|
void createBuilderFile(String *outputFilename) {
|
||||||
String *builderFilename = NewStringf("builder.sce");
|
String *builderFilename = NewStringf("builder.sce");
|
||||||
builderFile = NewFile(builderFilename, "w", SWIG_output_files());
|
builderFile = NewFile(builderFilename, "w", SWIG_output_files());
|
||||||
if (!builderFile) {
|
if (!builderFile) {
|
||||||
|
|
@ -884,13 +871,7 @@ public:
|
||||||
SWIG_exit(EXIT_FAILURE);
|
SWIG_exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
emitBanner(builderFile);
|
emitBanner(builderFile);
|
||||||
}
|
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------
|
|
||||||
* startBuilderCode()
|
|
||||||
* ----------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
void startBuilderCode(String *outputFilename) {
|
|
||||||
builderFunctionCount = 0;
|
builderFunctionCount = 0;
|
||||||
builderCode = NewString("");
|
builderCode = NewString("");
|
||||||
Printf(builderCode, "mode(-1);\n");
|
Printf(builderCode, "mode(-1);\n");
|
||||||
|
|
@ -903,8 +884,6 @@ public:
|
||||||
|
|
||||||
Printf(builderCode, "ilib_verbose(%s);\n", verboseBuildLevel);
|
Printf(builderCode, "ilib_verbose(%s);\n", verboseBuildLevel);
|
||||||
|
|
||||||
Printf(builderCode, "lib_name = \"%s\";\n", libraryName);
|
|
||||||
|
|
||||||
Printf(builderCode, "libs = [];\n");
|
Printf(builderCode, "libs = [];\n");
|
||||||
|
|
||||||
// Flags from command line arguments
|
// Flags from command line arguments
|
||||||
|
|
@ -960,15 +939,15 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------
|
/* -----------------------------------------------------------------------
|
||||||
* terminateBuilderCode()
|
* saveBuilderFile()
|
||||||
* ----------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------- */
|
||||||
|
|
||||||
void terminateBuilderCode() {
|
void saveBuilderFile(String *gatewayLibraryName) {
|
||||||
Printf(builderCode, "];\n");
|
Printf(builderCode, "];\n");
|
||||||
Printf(builderCode, "ierr = 0;\n");
|
Printf(builderCode, "ierr = 0;\n");
|
||||||
Printf(builderCode, "if ~isempty(table) then\n");
|
Printf(builderCode, "if ~isempty(table) then\n");
|
||||||
Printf(builderCode, " libfilename = 'lib%s' + getdynlibext();\n", libraryName);
|
Printf(builderCode, " libfilename = '%s' + getdynlibext();\n", gatewayLibraryName);
|
||||||
Printf(builderCode, " ierr = execstr(\"ilib_build(''%s'', table, files, libs, [], ldflags, cflags);\", 'errcatch');\n", libraryName);
|
Printf(builderCode, " ierr = execstr(\"ilib_build(''%s'', table, files, libs, [], ldflags, cflags);\", 'errcatch');\n", gatewayLibraryName);
|
||||||
Printf(builderCode, " if ierr <> 0 then\n");
|
Printf(builderCode, " if ierr <> 0 then\n");
|
||||||
Printf(builderCode, " err_msg = lasterror();\n");
|
Printf(builderCode, " err_msg = lasterror();\n");
|
||||||
Printf(builderCode, " elseif ~isfile(libfilename) then\n");
|
Printf(builderCode, " elseif ~isfile(libfilename) then\n");
|
||||||
|
|
@ -983,13 +962,6 @@ public:
|
||||||
Printf(builderCode, "if ierr <> 0 then\n");
|
Printf(builderCode, "if ierr <> 0 then\n");
|
||||||
Printf(builderCode, " error(ierr, err_msg);\n");
|
Printf(builderCode, " error(ierr, err_msg);\n");
|
||||||
Printf(builderCode, "end\n");
|
Printf(builderCode, "end\n");
|
||||||
}
|
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------
|
|
||||||
* saveBuilderCode()
|
|
||||||
* ----------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
void saveBuilderFile() {
|
|
||||||
Printv(builderFile, builderCode, NIL);
|
Printv(builderFile, builderCode, NIL);
|
||||||
Delete(builderFile);
|
Delete(builderFile);
|
||||||
}
|
}
|
||||||
|
|
@ -999,8 +971,8 @@ public:
|
||||||
* This XML file is used by Scilab in the context of internal modules
|
* This XML file is used by Scilab in the context of internal modules
|
||||||
* ----------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------- */
|
||||||
|
|
||||||
void createGatewayXMLFile(String *moduleName) {
|
void createGatewayXMLFile(String *gatewayName) {
|
||||||
String *gatewayXMLFilename = NewStringf("%s_gateway.xml", moduleName);
|
String *gatewayXMLFilename = NewStringf("%s_gateway.xml", gatewayName);
|
||||||
gatewayXMLFile = NewFile(gatewayXMLFilename, "w", SWIG_output_files());
|
gatewayXMLFile = NewFile(gatewayXMLFilename, "w", SWIG_output_files());
|
||||||
if (!gatewayXMLFile) {
|
if (!gatewayXMLFile) {
|
||||||
FileErrorDisplay(gatewayXMLFilename);
|
FileErrorDisplay(gatewayXMLFilename);
|
||||||
|
|
@ -1009,7 +981,7 @@ public:
|
||||||
|
|
||||||
gatewayXML = NewString("");
|
gatewayXML = NewString("");
|
||||||
Printf(gatewayXML, "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n");
|
Printf(gatewayXML, "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n");
|
||||||
Printf(gatewayXML, "<GATEWAY name=\"%s\">\n", moduleName);
|
Printf(gatewayXML, "<GATEWAY name=\"%s\">\n", gatewayName);
|
||||||
Printf(gatewayXML, "<!--\n");
|
Printf(gatewayXML, "<!--\n");
|
||||||
Printf(gatewayXML, "Scilab Interface description. In this file, we define the list of the function which\n");
|
Printf(gatewayXML, "Scilab Interface description. In this file, we define the list of the function which\n");
|
||||||
Printf(gatewayXML, "will be available into Scilab and the link to the \"native\" function.\n\n");
|
Printf(gatewayXML, "will be available into Scilab and the link to the \"native\" function.\n\n");
|
||||||
|
|
@ -1029,7 +1001,7 @@ public:
|
||||||
* ----------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------- */
|
||||||
|
|
||||||
void saveGatewayXMLFile() {
|
void saveGatewayXMLFile() {
|
||||||
Printv(gatewayXML, "</GATEWAY>\n", NIL);
|
Printf(gatewayXML, "</GATEWAY>\n");
|
||||||
Printv(gatewayXMLFile, gatewayXML, NIL);
|
Printv(gatewayXMLFile, gatewayXML, NIL);
|
||||||
Delete(gatewayXMLFile);
|
Delete(gatewayXMLFile);
|
||||||
}
|
}
|
||||||
|
|
@ -1039,9 +1011,8 @@ public:
|
||||||
* Creates the gateway entry point source file (entry point gw_<module>.c)
|
* Creates the gateway entry point source file (entry point gw_<module>.c)
|
||||||
* ----------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------- */
|
||||||
|
|
||||||
void createGatewaySourceFile(String *moduleName) {
|
void createGatewaySourceFile(String *gatewaySourceName) {
|
||||||
String *gatewaySourceFilename = NewString("");
|
String *gatewaySourceFilename = NewStringf("%s.c", gatewaySourceName);
|
||||||
Printf(gatewaySourceFilename, "gw_%s.c", moduleName);
|
|
||||||
gatewaySourceFile = NewFile(gatewaySourceFilename, "w", SWIG_output_files());
|
gatewaySourceFile = NewFile(gatewaySourceFilename, "w", SWIG_output_files());
|
||||||
if (!gatewaySourceFile) {
|
if (!gatewaySourceFile) {
|
||||||
FileErrorDisplay(gatewaySourceFilename);
|
FileErrorDisplay(gatewaySourceFilename);
|
||||||
|
|
@ -1084,7 +1055,7 @@ public:
|
||||||
* Saves the gateway entry point source file
|
* Saves the gateway entry point source file
|
||||||
* ----------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------- */
|
||||||
|
|
||||||
void saveGatewaySourceFile(String *moduleName) {
|
void saveGatewaySourceFile(String *gatewaySourceName) {
|
||||||
Printv(gatewaySourceFile, gatewaySourceWrapperDeclaration, NIL);
|
Printv(gatewaySourceFile, gatewaySourceWrapperDeclaration, NIL);
|
||||||
Printf(gatewaySourceFunctionTable, "};\n");
|
Printf(gatewaySourceFunctionTable, "};\n");
|
||||||
|
|
||||||
|
|
@ -1092,7 +1063,7 @@ public:
|
||||||
Printv(gatewaySourceFile, "\n", NIL);
|
Printv(gatewaySourceFile, "\n", NIL);
|
||||||
|
|
||||||
String* gatewaySourceEntryPoint = NewString("");
|
String* gatewaySourceEntryPoint = NewString("");
|
||||||
Printf(gatewaySourceEntryPoint, "int C2F(gw_%s)()\n", moduleName);
|
Printf(gatewaySourceEntryPoint, "int C2F(%s)()\n", gatewaySourceName);
|
||||||
Printf(gatewaySourceEntryPoint, "{\n");
|
Printf(gatewaySourceEntryPoint, "{\n");
|
||||||
Printf(gatewaySourceEntryPoint, " Rhs = Max(0, Rhs);\n");
|
Printf(gatewaySourceEntryPoint, " Rhs = Max(0, Rhs);\n");
|
||||||
Printf(gatewaySourceEntryPoint, " if (*(Tab[Fin-1].f) != NULL)\n");
|
Printf(gatewaySourceEntryPoint, " if (*(Tab[Fin-1].f) != NULL)\n");
|
||||||
|
|
@ -1121,24 +1092,19 @@ public:
|
||||||
* Creates the loader script file (loader.sce)
|
* Creates the loader script file (loader.sce)
|
||||||
* ----------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------- */
|
||||||
|
|
||||||
void createLoaderFile(String *moduleName) {
|
void createLoaderFile(String *gatewayLibraryName) {
|
||||||
String *loaderFilename = NewString("");
|
String *loaderFilename = NewString("loader.sce");
|
||||||
Printf(loaderFilename, "loader.sce");
|
|
||||||
|
|
||||||
loaderFile = NewFile(loaderFilename, "w", SWIG_output_files());
|
loaderFile = NewFile(loaderFilename, "w", SWIG_output_files());
|
||||||
if (!loaderFile) {
|
if (!loaderFile) {
|
||||||
FileErrorDisplay(loaderFilename);
|
FileErrorDisplay(loaderFilename);
|
||||||
SWIG_exit(EXIT_FAILURE);
|
SWIG_exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
String *libName = NewString("");
|
|
||||||
Printf(libName, "lib%s", moduleName);
|
|
||||||
|
|
||||||
emitBanner(loaderFile);
|
emitBanner(loaderFile);
|
||||||
|
|
||||||
loaderScript = NewString("");
|
loaderScript = NewString("");
|
||||||
Printf(loaderScript, "%s_path = get_absolute_file_path('loader.sce');\n", libName);
|
Printf(loaderScript, "%s_path = get_absolute_file_path('loader.sce');\n", gatewayLibraryName);
|
||||||
Printf(loaderScript, "[bOK, ilib] = c_link('%s');\n", libName);
|
Printf(loaderScript, "[bOK, ilib] = c_link('%s');\n", gatewayLibraryName);
|
||||||
Printf(loaderScript, "if bOK then\n");
|
Printf(loaderScript, "if bOK then\n");
|
||||||
Printf(loaderScript, " ulink(ilib);\n");
|
Printf(loaderScript, " ulink(ilib);\n");
|
||||||
Printf(loaderScript, "end\n");
|
Printf(loaderScript, "end\n");
|
||||||
|
|
@ -1159,14 +1125,12 @@ public:
|
||||||
* Terminates and saves the loader script
|
* Terminates and saves the loader script
|
||||||
* ----------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------- */
|
||||||
|
|
||||||
void saveLoaderFile(String *moduleName) {
|
void saveLoaderFile(String *gatewaySourceName, String *gatewayLibraryName) {
|
||||||
Printf(loaderScript, "];\n");
|
Printf(loaderScript, "];\n");
|
||||||
|
|
||||||
String *libName = NewString("");
|
Printf(loaderScript, "addinter(fullfile(%s_path, '%s' + getdynlibext()), '%s', list_functions);\n",
|
||||||
Printf(libName, "lib%s", moduleName);
|
gatewayLibraryName, gatewayLibraryName, gatewaySourceName);
|
||||||
|
Printf(loaderScript, "clear %s_path;\n", gatewayLibraryName);
|
||||||
Printf(loaderScript, "addinter(fullfile(%s_path, '%s' + getdynlibext()), 'gw_%s', list_functions);\n", libName, libName, moduleName);
|
|
||||||
Printf(loaderScript, "clear %s_path;\n", libName);
|
|
||||||
Printf(loaderScript, "clear bOK;\n");
|
Printf(loaderScript, "clear bOK;\n");
|
||||||
Printf(loaderScript, "clear ilib;\n");
|
Printf(loaderScript, "clear ilib;\n");
|
||||||
Printf(loaderScript, "clear list_functions;\n");
|
Printf(loaderScript, "clear list_functions;\n");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue