[ClavaLaraApi] Adds safeguard for codes without main in MemoiGen debug
@@ -288,9 +288,16 @@ MemoiGen.prototype._makeUpdateCode = function($function) {
MemoiGen.prototype._addMainDebug = function(totalName, missesName, wrapperName) {
- var chain = Query.search("file").search("function", {"name":"main"}).chain()[0];
- var $file = chain["file"];
- var $function = chain["function"];
+ var chain = Query.search("file").search("function", {"name":"main"}).chain();
+ var firstAndOnly = chain[0];
+
+ if(firstAndOnly === undefined) {
+ println("Could not find a main function. It may be impossible to print debug stats if this is a library code.");
+ return;
+ }
+
+ var $file = firstAndOnly["file"];
+ var $function = firstAndOnly["function"];
$file.addGlobal(totalName, ClavaJoinPoints.builtinType("unsigned int"), '0');
$file.addGlobal(missesName, ClavaJoinPoints.builtinType("unsigned int"), '0');
