@@ -1416,6 +1416,28 @@ algorithm
14161416 then
14171417 (cache,ValuesUtil . makeArray({Values . STRING (executable),Values . STRING (initfilename)}),st);
14181418
1419+ case (cache,env,"buildLabel" ,vals,st,_)
1420+ equation
1421+ Flags . setConfigBool(Flags . GENERATE_LABELED_SIMCODE , true );
1422+ // Flags.set(Flags.WRITE_TO_BUFFER,true);
1423+ List . map_0(ClockIndexes . buildModelClocks,System . realtimeClear);
1424+ System . realtimeTick(ClockIndexes . RT_CLOCK_SIMULATE_TOTAL );
1425+ (cache,st,compileDir,executable,_,_,initfilename,_,_) = buildModel(cache,env, vals, st, msg);
1426+ then
1427+ (cache,ValuesUtil . makeArray({Values . STRING (executable),Values . STRING (initfilename)}),st);
1428+
1429+ case (cache,env,"reduceTerms" ,vals,st,_)
1430+ equation
1431+ Flags . setConfigBool(Flags . REDUCE_TERMS , true );
1432+ // Flags.setConfigBool(Flags.DISABLE_EXTRA_LABELING, true);
1433+ Flags . setConfigBool(Flags . GENERATE_LABELED_SIMCODE , false );
1434+ _= Flags . disableDebug(Flags . WRITE_TO_BUFFER );
1435+ List . map_0(ClockIndexes . buildModelClocks,System . realtimeClear);
1436+ System . realtimeTick(ClockIndexes . RT_CLOCK_SIMULATE_TOTAL );
1437+
1438+ (cache,st,compileDir,executable,_,_,initfilename,_,_) = buildLabeledModel(cache,env, vals, st, msg);
1439+ then
1440+ (cache,ValuesUtil . makeArray({Values . STRING (executable),Values . STRING (initfilename)}),st);
14191441 case (cache,env,"buildOpenTURNSInterface" ,vals,st,_)
14201442 equation
14211443 (cache,scriptFile,st) = buildOpenTURNSInterface(cache,env,vals,st,msg);
@@ -3139,6 +3161,72 @@ algorithm
31393161 end match;
31403162end translateModel;
31413163
3164+ protected function translateLabeledModel " author: Fatima
3165+ translates a labeled model into cpp code and writes also a makefile"
3166+ input FCore . Cache inCache;
3167+ input FCore . Graph inEnv;
3168+ input Absyn . Path className "path for the model" ;
3169+ input GlobalScript . SymbolTable inInteractiveSymbolTable;
3170+ input String inFileNamePrefix;
3171+ input Boolean addDummy "if true, add a dummy state" ;
3172+ input Option < SimCode . SimulationSettings > inSimSettingsOpt;
3173+ input list< Absyn . NamedArg > inLabelstoCancel;
3174+ output FCore . Cache outCache;
3175+ output GlobalScript . SymbolTable outInteractiveSymbolTable;
3176+ output BackendDAE . BackendDAE outBackendDAE;
3177+ output list< String > outStringLst;
3178+ output String outFileDir;
3179+ output list< tuple< String ,Values . Value >> resultValues;
3180+ algorithm
3181+ (outCache,outInteractiveSymbolTable,outBackendDAE,outStringLst,outFileDir,resultValues):=
3182+ match (inCache,inEnv,className,inInteractiveSymbolTable,inFileNamePrefix,addDummy,inSimSettingsOpt,inLabelstoCancel)
3183+ local
3184+ FCore . Cache cache;
3185+ FCore . Graph env;
3186+ BackendDAE . BackendDAE indexed_dlow;
3187+ GlobalScript . SymbolTable st;
3188+ list< String > libs;
3189+ String file_dir, fileNamePrefix;
3190+ Absyn . Program p;
3191+ Flags . Flags flags;
3192+ String commandLineOptions;
3193+ list< String > args;
3194+ Boolean haveAnnotation;
3195+ list< Absyn . NamedArg > labelstoCancel;
3196+
3197+ case (cache,env,_,st as GlobalScript . SYMBOLTABLE (),fileNamePrefix,_,_,labelstoCancel)
3198+ algorithm
3199+
3200+ if Config . ignoreCommandLineOptionsAnnotation() then
3201+ (cache, st, indexed_dlow, libs, file_dir, resultValues) :=
3202+ SimCodeMain . translateModel(cache,env,className,st,fileNamePrefix,addDummy,inSimSettingsOpt,Absyn . FUNCTIONARGS ({},argNames = labelstoCancel));
3203+ else
3204+ // read the __OpenModelica_commandLineOptions
3205+ Absyn . STRING (commandLineOptions) := Interactive . getNamedAnnotation(className, st. ast, Absyn . IDENT ("__OpenModelica_commandLineOptions" ), SOME (Absyn . STRING ("" )), Interactive . getAnnotationExp);
3206+ haveAnnotation := boolNot(stringEq(commandLineOptions, "" ));
3207+ // backup the flags.
3208+ flags := if haveAnnotation then Flags . backupFlags() else Flags . loadFlags();
3209+ try
3210+ // apply if there are any new flags
3211+ if haveAnnotation then
3212+ args := System . strtok(commandLineOptions, " " );
3213+ _ := Flags . readArgs(args);
3214+ end if ;
3215+
3216+ (cache, st, indexed_dlow, libs, file_dir, resultValues) :=
3217+ SimCodeMain . translateModel(cache,env,className,st,fileNamePrefix,addDummy,inSimSettingsOpt,Absyn . FUNCTIONARGS ({},argNames = labelstoCancel));
3218+ // reset to the original flags
3219+ Flags . saveFlags(flags);
3220+ else
3221+ Flags . saveFlags(flags);
3222+ fail();
3223+ end try ;
3224+ end if ;
3225+ then
3226+ (cache,st,indexed_dlow,libs,file_dir,resultValues);
3227+
3228+ end match;
3229+ end translateLabeledModel;
31423230/* protected function translateModelCPP " author: x02lucpo
31433231 translates a model into cpp code and writes also a makefile"
31443232 input FCore.Cache inCache;
@@ -4821,6 +4909,116 @@ algorithm
48214909 end matchcontinue;
48224910end buildModel;
48234911
4912+ protected function buildLabeledModel "translates and builds the labeled model by running compiler script on the generated makefile"
4913+ input FCore . Cache inCache;
4914+ input FCore . Graph inEnv;
4915+ input list< Values . Value > inValues;
4916+ input GlobalScript . SymbolTable inInteractiveSymbolTable;
4917+ input Absyn . Msg inMsg;
4918+ output FCore . Cache outCache;
4919+ output GlobalScript . SymbolTable outInteractiveSymbolTable3;
4920+ output String compileDir;
4921+ output String outString1 "className" ;
4922+ output String outString2 "method" ;
4923+ output String outputFormat_str;
4924+ output String outInitFileName "initFileName" ;
4925+ output String outSimFlags;
4926+ output list< tuple< String ,Values . Value >> resultValues;
4927+ protected
4928+ Values . Value labelstoCancel;
4929+ list< Absyn . NamedArg > named_args1= {},named_args2= {};
4930+ list< Values . Value > valuesList;
4931+ String labelstoCancelStr;
4932+ // Absyn.NamedArg named_arg;
4933+ algorithm
4934+ if listLength(inValues)== 13 then
4935+ labelstoCancel:= listGet(inValues,13 );
4936+ valuesList:= listDelete(inValues,13 );
4937+ end if ;
4938+ labelstoCancelStr:= System . stringReplace(ValuesUtil . valString(labelstoCancel), " \" " , "" );
4939+
4940+ named_args2:= Absyn . NAMEDARG ("labelstoCancel" , Absyn . STRING (labelstoCancelStr))::named_args1;
4941+
4942+ (outCache,outInteractiveSymbolTable3,compileDir,outString1,outString2,outputFormat_str,outInitFileName,outSimFlags,resultValues):=
4943+ matchcontinue (inCache,inEnv,valuesList,inInteractiveSymbolTable,inMsg)
4944+ local
4945+ GlobalScript . SymbolTable st,st_1,st2;
4946+ BackendDAE . BackendDAE indexed_dlow_1;
4947+ list< String > libs;
4948+ String file_dir,init_filename,method_str,filenameprefix,exeFile,s3,simflags,optionStr,filterStr,cflagsStr;
4949+ Absyn . Path classname;
4950+ Absyn . Program p;
4951+ Absyn . Class cdef;
4952+ Real edit,build,globalEdit,globalBuild,timeCompile;
4953+ FCore . Graph env;
4954+ SimCode . SimulationSettings simSettings;
4955+ Values . Value starttime,stoptime,interval,tolerance,method,options,outputFormat,variableFilter;
4956+ list< Values . Value > vals, values;
4957+ Absyn . Msg msg;
4958+ FCore . Cache cache;
4959+ Boolean existFile;
4960+
4961+ // compile the model
4962+ case (cache,env,vals,st,msg)
4963+ equation
4964+
4965+ // buildModel expects these arguments:
4966+ // className, startTime, stopTime, numberOfIntervals, tolerance, method, fileNamePrefix,
4967+ // options, outputFormat, variableFilter, cflags, simflags
4968+ values = vals;
4969+
4970+ (Values . CODE (Absyn . C_TYPENAME (classname)),vals) = getListFirstShowError(vals, "while retreaving the className (1 arg) from the buildModel arguments" );
4971+ (_,vals) = getListFirstShowError(vals, "while retreaving the startTime (2 arg) from the buildModel arguments" );
4972+ (_,vals) = getListFirstShowError(vals, "while retreaving the stopTime (3 arg) from the buildModel arguments" );
4973+ (_,vals) = getListFirstShowError(vals, "while retreaving the numberOfIntervals (4 arg) from the buildModel arguments" );
4974+ (_,vals) = getListFirstShowError(vals, "while retreaving the tolerance (5 arg) from the buildModel arguments" );
4975+ (_,vals) = getListFirstShowError(vals, "while retreaving the method (6 arg) from the buildModel arguments" );
4976+ (Values . STRING (filenameprefix),vals) = getListFirstShowError(vals, "while retreaving the fileNamePrefix (7 arg) from the buildModel arguments" );
4977+ (_,vals) = getListFirstShowError(vals, "while retreaving the options (8 arg) from the buildModel arguments" );
4978+ (_,vals) = getListFirstShowError(vals, "while retreaving the outputFormat (9 arg) from the buildModel arguments" );
4979+ (_,vals) = getListFirstShowError(vals, "while retreaving the variableFilter (10 arg) from the buildModel arguments" );
4980+ (_,vals) = getListFirstShowError(vals, "while retreaving the cflags (11 arg) from the buildModel arguments" );
4981+ (Values . STRING (simflags),vals) = getListFirstShowError(vals, "while retreaving the simflags (12 arg) from the buildModel arguments" );
4982+
4983+ Error . clearMessages() "Clear messages" ;
4984+ compileDir = System . pwd() + System . pathDelimiter();
4985+ (cache,simSettings) = calculateSimulationSettings(cache, env, values, st, msg);
4986+
4987+ SimCode . SIMULATION_SETTINGS (method = method_str,options= optionStr, outputFormat = outputFormat_str,variableFilter= filterStr,cflags= cflagsStr)
4988+ = simSettings;
4989+
4990+ (cache,st as GlobalScript . SYMBOLTABLE (),_,libs,file_dir,resultValues) = translateLabeledModel(cache,env, classname, st, filenameprefix,true , SOME (simSettings),named_args2);
4991+
4992+ // cname_str = Absyn.pathString(classname);
4993+ // SimCodeUtil.generateInitData(indexed_dlow_1, classname, filenameprefix, init_filename,
4994+ // starttime_r, stoptime_r, interval_r, tolerance_r, method_str,options_str,outputFormat_str);
4995+
4996+ System . realtimeTick(ClockIndexes . RT_CLOCK_BUILD_MODEL );
4997+ init_filename = filenameprefix + "_init.xml" ; // a hack ? should be at one place somewhere
4998+ // win1 = getWithinStatement(classname);
4999+
5000+ if Flags . isSet(Flags . DYN_LOAD ) then
5001+ Debug . traceln("buildModel: about to compile model " + filenameprefix + ", " + file_dir);
5002+ end if ;
5003+ CevalScript . compileModel(filenameprefix, libs);
5004+ print("after compilemodel in buildLabeledModel \n " );
5005+ if Flags . isSet(Flags . DYN_LOAD ) then
5006+ Debug . trace("buildModel: Compiling done. \n " );
5007+ end if ;
5008+ // p = setBuildTime(p,classname);
5009+ st2 = st;// Interactive.replaceSymbolTableProgram(st,p);
5010+ timeCompile = System . realtimeTock(ClockIndexes . RT_CLOCK_BUILD_MODEL );
5011+ resultValues = ("timeCompile" ,Values . REAL (timeCompile)) :: resultValues;
5012+ then
5013+ (cache,st2,compileDir,filenameprefix,method_str,outputFormat_str,init_filename,simflags,resultValues);
5014+
5015+ // failure
5016+ else
5017+ equation
5018+ Error . assertion(listLength(valuesList) == 12 , "buildModel failure, length = " + intString(listLength(valuesList)), Absyn . dummyInfo);
5019+ then fail();
5020+ end matchcontinue;
5021+ end buildLabeledModel;
48245022protected function createSimulationResultFromcallModelExecutable
48255023"This function calls the compiled simulation executable."
48265024 input Integer callRet;
0 commit comments