scilab: for internal modules, create a script to generate gateway entry point
This commit is contained in:
parent
7bfffbb0dc
commit
034aa554ba
1 changed files with 76 additions and 28 deletions
|
|
@ -23,7 +23,7 @@ Scilab options (available with -scilab)\n\
|
||||||
-vbl <level> - Sets the build verbose <level> (default 0)\n\
|
-vbl <level> - Sets the build verbose <level> (default 0)\n\
|
||||||
-buildflags <file> - Uses a Scilab script in <file> to set build flags\n\
|
-buildflags <file> - Uses a Scilab script in <file> to set build flags\n\
|
||||||
-nobuilder - Do not generate builder script\n\
|
-nobuilder - Do not generate builder script\n\
|
||||||
-gwid <id> - Gateway ID \n\
|
-intmod <gateway id> - Generate internal module files with the given <gateway id>\n\
|
||||||
-ol <library name> - Set name of the output library\n\n"
|
-ol <library name> - Set name of the output library\n\n"
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
@ -53,12 +53,17 @@ protected:
|
||||||
|
|
||||||
File *gatewayXMLFile;
|
File *gatewayXMLFile;
|
||||||
String *gatewayXML;
|
String *gatewayXML;
|
||||||
|
|
||||||
|
File *gatewayGeneratorFile;
|
||||||
|
String *gatewayGeneratorCode;
|
||||||
|
|
||||||
String *gatewayID;
|
String *gatewayID;
|
||||||
int primitiveID;
|
int primitiveID;
|
||||||
|
|
||||||
String *libraryName;
|
String *libraryName;
|
||||||
|
|
||||||
bool generateBuilder;
|
bool generateBuilder;
|
||||||
|
bool internalModule;
|
||||||
bool extraWarning;
|
bool extraWarning;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
@ -72,9 +77,14 @@ public:
|
||||||
ldflags = NewList();
|
ldflags = NewList();
|
||||||
verboseBuildLevel = NULL;
|
verboseBuildLevel = NULL;
|
||||||
buildFlagsScript = NULL;
|
buildFlagsScript = NULL;
|
||||||
generateBuilder = true;
|
|
||||||
gatewayID = NULL;
|
gatewayID = NULL;
|
||||||
|
gatewayXML = NULL;
|
||||||
|
gatewayXMLFile = NULL;
|
||||||
|
gatewayGeneratorCode = NULL;
|
||||||
|
gatewayGeneratorFile = NULL;
|
||||||
libraryName = NULL;
|
libraryName = NULL;
|
||||||
|
generateBuilder = true;
|
||||||
|
internalModule = false;
|
||||||
extraWarning = false;
|
extraWarning = false;
|
||||||
|
|
||||||
/* Manage command line arguments */
|
/* Manage command line arguments */
|
||||||
|
|
@ -116,8 +126,10 @@ public:
|
||||||
Swig_mark_arg(argIndex);
|
Swig_mark_arg(argIndex);
|
||||||
generateBuilder = false;
|
generateBuilder = false;
|
||||||
}
|
}
|
||||||
else if (strcmp(argv[argIndex], "-gwid") == 0) {
|
else if (strcmp(argv[argIndex], "-intmod") == 0) {
|
||||||
Swig_mark_arg(argIndex);
|
Swig_mark_arg(argIndex);
|
||||||
|
generateBuilder = false;
|
||||||
|
internalModule = true;
|
||||||
gatewayID = NewString(argv[argIndex + 1]);
|
gatewayID = NewString(argv[argIndex + 1]);
|
||||||
Swig_mark_arg(argIndex + 1);
|
Swig_mark_arg(argIndex + 1);
|
||||||
}
|
}
|
||||||
|
|
@ -149,9 +161,6 @@ public:
|
||||||
SWIG_typemap_lang("scilab");
|
SWIG_typemap_lang("scilab");
|
||||||
|
|
||||||
allow_overloading();
|
allow_overloading();
|
||||||
|
|
||||||
gatewayXML = NULL;
|
|
||||||
gatewayXMLFile = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------
|
||||||
|
|
@ -194,13 +203,13 @@ public:
|
||||||
// Add builder header code
|
// Add builder header code
|
||||||
if (generateBuilder) {
|
if (generateBuilder) {
|
||||||
createBuilderFile();
|
createBuilderFile();
|
||||||
startBuilderCode(moduleName, outputFilename);
|
startBuilderCode(outputFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create gateway XML file if specified
|
// In the case of internal module, create gateway gateway XML and generation script
|
||||||
if (gatewayID) {
|
if (internalModule) {
|
||||||
createGatewayXMLFile(moduleName);
|
createGatewayXMLFile(moduleName);
|
||||||
primitiveID = 1;
|
createGatewayGeneratorFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Module initialization function
|
// Module initialization function
|
||||||
|
|
@ -250,9 +259,10 @@ public:
|
||||||
Dump(variablesCode, beginSection);
|
Dump(variablesCode, beginSection);
|
||||||
Wrapper_pretty_print(initSection, beginSection);
|
Wrapper_pretty_print(initSection, beginSection);
|
||||||
|
|
||||||
// Save gateway XML file
|
// In the case of internal module, terminate and save gateway XML and generation script
|
||||||
if (gatewayXMLFile) {
|
if (internalModule) {
|
||||||
saveGatewayXMLFile();
|
saveGatewayXMLFile();
|
||||||
|
saveGatewayGeneratorFile(moduleName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Cleanup files */
|
/* Cleanup files */
|
||||||
|
|
@ -589,7 +599,7 @@ public:
|
||||||
Wrapper_print(setFunctionWrapper, wrappersSection);
|
Wrapper_print(setFunctionWrapper, wrappersSection);
|
||||||
|
|
||||||
/* Add function to builder table */
|
/* Add function to builder table */
|
||||||
Printf(builderCode, "\"%s\",\"%s\";", setFunctionName, setFunctionName);
|
addFunctionToScilab(getFunctionName, getFunctionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
return SWIG_OK;
|
return SWIG_OK;
|
||||||
|
|
@ -667,8 +677,8 @@ public:
|
||||||
Append(getFunctionWrapper->code, "}\n");
|
Append(getFunctionWrapper->code, "}\n");
|
||||||
Wrapper_print(getFunctionWrapper, wrappersSection);
|
Wrapper_print(getFunctionWrapper, wrappersSection);
|
||||||
|
|
||||||
/* Add the function to the builder table */
|
/* Add the function to Scilab */
|
||||||
Printf(builderCode, "\"%s\",\"%s\";", getFunctionName, getFunctionName);
|
addFunctionToScilab(getFunctionName, getFunctionName);
|
||||||
|
|
||||||
DelWrapper(getFunctionWrapper);
|
DelWrapper(getFunctionWrapper);
|
||||||
|
|
||||||
|
|
@ -756,7 +766,7 @@ public:
|
||||||
/* -----------------------------------------------------------------------
|
/* -----------------------------------------------------------------------
|
||||||
* startBuilderCode()
|
* startBuilderCode()
|
||||||
* ----------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------- */
|
||||||
void startBuilderCode(String *moduleName, String *outputFilename) {
|
void startBuilderCode(String *outputFilename) {
|
||||||
builderFunctionCount = 0;
|
builderFunctionCount = 0;
|
||||||
builderCode = NewString("");
|
builderCode = NewString("");
|
||||||
Printf(builderCode, "mode(-1);\n");
|
Printf(builderCode, "mode(-1);\n");
|
||||||
|
|
@ -847,7 +857,7 @@ public:
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------
|
/* -----------------------------------------------------------------------
|
||||||
* createGatewayXMLFile()
|
* createGatewayXMLFile()
|
||||||
* This 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 *moduleName) {
|
||||||
String *gatewayXMLFilename = NewStringf("%s_gateway.xml", moduleName);
|
String *gatewayXMLFilename = NewStringf("%s_gateway.xml", moduleName);
|
||||||
|
|
@ -870,6 +880,8 @@ public:
|
||||||
Printf(gatewayXML, "primitiveName is the name of the Scilab function\n\n");
|
Printf(gatewayXML, "primitiveName is the name of the Scilab function\n\n");
|
||||||
Printf(gatewayXML, "Don't touch if you do not know what you are doing\n");
|
Printf(gatewayXML, "Don't touch if you do not know what you are doing\n");
|
||||||
Printf(gatewayXML, "-->\n");
|
Printf(gatewayXML, "-->\n");
|
||||||
|
|
||||||
|
primitiveID = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------
|
/* -----------------------------------------------------------------------
|
||||||
|
|
@ -882,25 +894,61 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------
|
/* -----------------------------------------------------------------------
|
||||||
* addFunctionToScilab(): add a function in Scilab (builder, XML, ...)
|
* createGatewayGenerator()
|
||||||
|
* Creates a Scilab macro to generate the gateway source (entry point gw_<module>.c)
|
||||||
|
* Used in the context of internal module generation (-intmod)
|
||||||
|
* ----------------------------------------------------------------------- */
|
||||||
|
void createGatewayGeneratorFile() {
|
||||||
|
String *gatewayGeneratorFilename = NewString("generate_gateway.sce");
|
||||||
|
gatewayGeneratorFile = NewFile(gatewayGeneratorFilename, "w", SWIG_output_files());
|
||||||
|
if (!gatewayGeneratorFile) {
|
||||||
|
FileErrorDisplay(gatewayGeneratorFilename);
|
||||||
|
SWIG_exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
gatewayGeneratorCode = NewString("table = [");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------
|
||||||
|
* saveGatewayGenerator()
|
||||||
|
* ----------------------------------------------------------------------- */
|
||||||
|
void saveGatewayGeneratorFile(String *moduleName) {
|
||||||
|
Printf(gatewayGeneratorCode, "];\n");
|
||||||
|
Printv(gatewayGeneratorFile, gatewayGeneratorCode, NIL);
|
||||||
|
String *gatewayGenerateCommand = NewStringf("ilib_gen_gateway('gw_%s.c', table);\n", moduleName);
|
||||||
|
Printv(gatewayGeneratorFile, gatewayGenerateCommand, NIL);
|
||||||
|
Delete(gatewayGeneratorFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------
|
||||||
|
* addFunctionToScilab()
|
||||||
|
* Add a function wrapper in Scilab file (builder, XML, ...)
|
||||||
* ----------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------- */
|
||||||
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) {
|
||||||
addFunctionInBuilder(scilabFunctionName, wrapperFunctionName);
|
if (generateBuilder) {
|
||||||
if (gatewayID) {
|
addFunctionInScriptTable(scilabFunctionName, wrapperFunctionName, builderCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (internalModule) {
|
||||||
|
if (gatewayGeneratorFile) {
|
||||||
|
addFunctionInScriptTable(scilabFunctionName, wrapperFunctionName, gatewayGeneratorCode);
|
||||||
|
}
|
||||||
|
if (gatewayXMLFile) {
|
||||||
Printf(gatewayXML, "<PRIMITIVE gatewayId=\"%s\" primitiveId=\"%d\" primitiveName=\"%s\"/>\n", gatewayID, primitiveID++, scilabFunctionName);
|
Printf(gatewayXML, "<PRIMITIVE gatewayId=\"%s\" primitiveId=\"%d\" primitiveName=\"%s\"/>\n", gatewayID, primitiveID++, scilabFunctionName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------
|
/* -----------------------------------------------------------------------
|
||||||
* addFunctionInBuilder(): add a new function wrapper in builder.sce file
|
* addFunctionInScriptTable()
|
||||||
|
* Add a function wrapper in a table in a generated script
|
||||||
|
* This table will be either given in parameter to ilib_build or ilib_gen_gateway,
|
||||||
|
* called later in the script
|
||||||
* ----------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------- */
|
||||||
void addFunctionInBuilder(const_String_or_char_ptr scilabFunctionName, const_String_or_char_ptr wrapperFunctionName) {
|
void addFunctionInScriptTable(const_String_or_char_ptr scilabFunctionName, const_String_or_char_ptr wrapperFunctionName, String* scriptCode) {
|
||||||
if (generateBuilder) {
|
|
||||||
if (++builderFunctionCount % 10 == 0) {
|
if (++builderFunctionCount % 10 == 0) {
|
||||||
Printf(builderCode, "];\n\ntable = [table;");
|
Printf(scriptCode, "];\ntable = [table;");
|
||||||
}
|
|
||||||
Printf(builderCode, "\"%s\",\"%s\";", scilabFunctionName, wrapperFunctionName);
|
|
||||||
}
|
}
|
||||||
|
Printf(scriptCode, "\"%s\",\"%s\";", scilabFunctionName, wrapperFunctionName);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue