|
|
Re: Can XDC script get a list of names of functions in a module? [message #502473 is a reply to message #499077] |
Tue, 08 December 2009 12:58 |
Brian Cruickshank Messages: 19 Registered: September 2009 |
Junior Member |
|
|
Thanks Dave, that works very well. The script function below can be called from a package.xs file's close() function to generate a GEL file that defines short name aliases for functions in a RTSC program. It helps make debugging a package's functions in CCS a bit easier.
Is there a way to determine the type names that have been defined so that the GEL script can be extended to define short name aliases for types as well? Should I add any __V or whatever suffixes to the long names for the types??
e.g. #define Types_Timestamp64 xdc_runtime_Types_Timestamp64
#define LoggerBuf_Object xdc_runtime_LoggerBuf_Object
etc.
Regards,
Brian
/*
* ======== genShortNameAliasGELfile ========
* generates configPkg\shortNames.gel, which contains a GEL hotmenu
* function that defines short name aliases for the fully qualified
* Module method names
*/
function genShortNameAliasGELfile(){
var strFuncName = "";
var strShortModName = "";
var strLongModName = "";
var strShortDeclName = "";
var strLongDeclName = "";
var decl;
var lastDotIndex = 0;
var uuFindex = 0;
var strToWrite = "";
var modName = "";
var enablePrintMsgs = false;
gelFile = new java.io.FileWriter("shortNames.gel");
print("package.xs: generating shortNames.gel");
gelFile.write("menuitem \"Short Names\"\;\n\n");
gelFile.write("hotmenu AddShortFunctionNames(){\n");
for each (var mod in Program.targetModules()) {
modName = mod.$name;
lastDotIndex = mod.$name.lastIndexOf('.')+1;
strShortModName = mod.$name.substring(lastDotIndex,mod.$name.length);
strLongModName = mod.$name;
while (strLongModName.indexOf('.') > 0){
strLongModName = strLongModName.replace(".","_");
}
if (enablePrintMsgs) {
print("======== "+strLongModName+" ========");
}
var fxns = mod.$spec.getFxns().toArray();
for (var i = 0; i < fxns.length; i++) {
var f = fxns[i];
strFuncName = f.getName();
if (strFuncName.indexOf("__") < 0){
strShortDeclName = strShortModName + "_"+strFuncName;
if (strShortDeclName.indexOf("_Module_") < 0){
strLongDeclName = strLongModName + "_"+strFuncName+"__F";
strToWrite = "#define "+strShortDeclName+ " " + strLongDeclName+"\n";
gelFile.write(strToWrite);
if (enablePrintMsgs) {
print("GEL: "+strToWrite);
}
}
}
}
}
gelFile.write("}\n");
gelFile.flush();
gelFile.close();
}
[Updated on: Tue, 08 December 2009 13:03] Report message to a moderator
|
|
|
Re: Can XDC script get a list of names of functions in a module? [message #505240 is a reply to message #502473] |
Mon, 28 December 2009 21:03 |
Dave Russo Messages: 172 Registered: July 2009 |
Senior Member |
|
|
comments below
Brian Cruickshank wrote:
> Thanks Dave, that works very well. The attached script function can be
> called from a package.xs file's close() function to generate a GEL file
> that defines short name aliases for functions in a RTSC program. It
> helps make debugging a package's functions in CCS a bit easier.
Cool.
BTW: in your script, the following loop:
while (strLongModName.indexOf('.') > 0) {
strLongModName = strLongModName.replace(".", "_");
}
can be replaced by a single line:
strLongModName = strLongModName.replace(/\./g, "_");
The JavaScript replace() function can take a regular expression and this
regular expression can be applied "globally".
Also, the variable modName is unused.
> Is there a way to determine the type names that have been defined so
> that the GEL script can be extended to define short name aliases for
> types as well?
I don't know what type names would be useful to GEL, but the types
defined for any module are described by the "Module Binary Contract";
see
http://rtsc.eclipse.org/docs-tip/C_Language_Binding#Module_B inary_Contract
Of course, just like getting a module's functions, you can get all of
the types declared by a module via its $spec object. For example:
var Mod = xdc.module("my.fav.Mod");
var decls = Mod.$spec.getDecls().toArray();
for (var i = 0; i < decls.length; i++) {
var decl = decls[i];
if (decl.isMeta()) {
continue; /* skip meta-only decls */
}
var name = decl.getName();
if ("getTypeSig" in decl) {
print(name + ": " + decl.getTypeSig());
}
else if (decl instanceof Packages.xdc.services.spec.Decl.Struct) {
: /* handle structure decl */
}
}
}
>Should I add any __V or whatever suffixes to the long
> names for the types??
>
> e.g. #define Types_Timestamp64 xdc_runtime_Types_Timestamp64 #define
> LoggerBuf_Object xdc_runtime_LoggerBuf_Object
> etc.
>
> Regards,
> Brian
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.04205 seconds