@@ -56,6 +56,7 @@ import SimCode;
5656protected
5757import AvlSetString ;
5858import BackendDAECreate ;
59+ import BackendDump ;
5960import Builtin ;
6061import ClockIndexes ;
6162import CevalScriptBackend ;
@@ -77,6 +78,7 @@ import DAEUtil;
7778import Debug ;
7879import Error ;
7980import ErrorExt ;
81+ import ExecStat ;
8082import Flags ;
8183import FMI ;
8284import GC ;
@@ -87,11 +89,10 @@ import TaskSystemDump;
8789import SerializeInitXML ;
8890import Serializer ;
8991import SimCodeUtil ;
92+ import StackOverflow ;
9093import StringUtil ;
9194import System ;
9295import Util ;
93- import BackendDump ;
94- import ExecStat ;
9596
9697public function createSimulationSettings
9798 input Real startTime;
@@ -420,7 +421,11 @@ protected
420421 Absyn . ComponentRef a_cref;
421422 tuple< Integer , HashTableExpToIndex . HashTable , list< DAE . Exp >> literals;
422423 list< tuple< String , String >> program;
424+ Integer numCheckpoints;
423425algorithm
426+ numCheckpoints:= ErrorExt . getNumCheckpoints();
427+ try
428+ StackOverflow . clearStacktraceMessages();
424429 if Flags . isSet(Flags . GRAPHML ) then
425430 HpcOmTaskGraph . dumpTaskGraph(inBackendDAE, filenamePrefix);
426431 end if ;
@@ -442,6 +447,15 @@ algorithm
442447 callTargetTemplates(simCode, Config . simCodeTarget());
443448 timeTemplates := System . realtimeTock(ClockIndexes . RT_CLOCK_TEMPLATES );
444449 ExecStat . execStat("Templates" );
450+ return ;
451+ else
452+ setGlobalRoot(Global . stackoverFlowIndex, NONE ());
453+ ErrorExt . rollbackNumCheckpoints(ErrorExt . getNumCheckpoints()- numCheckpoints);
454+ Error . addInternalError("Stack overflow in " + getInstanceName()+ "... \n " + stringDelimitList(StackOverflow . readableStacktraceMessages(), " \n " ), sourceInfo());
455+ /* Do not fail or we can loop too much */
456+ StackOverflow . clearStacktraceMessages();
457+ end try annotation(__OpenModelica_stackOverflowCheckpoint= true );
458+ fail();
445459end generateModelCode;
446460
447461protected function createSimCode "
@@ -900,11 +914,11 @@ algorithm
900914 list< BackendDAE . Var > allPrimaryParameters "already sorted" ;
901915 Real fsize;
902916
903- case (cache, graph, _, (st as GlobalScript . SYMBOLTABLE (ast= p)), filenameprefix, _, _, _) equation
917+ case (cache, graph, _, (st as GlobalScript . SYMBOLTABLE (ast= p)), filenameprefix, _, _, _) algorithm
904918 // calculate stuff that we need to create SimCode data structure
905919 System . realtimeTick(ClockIndexes . RT_CLOCK_FRONTEND );
906920 ExecStat . execStatReset();
907- (cache, graph, dae, st) = CevalScriptBackend . runFrontEnd(cache, graph, className, st, false );
921+ (cache, graph, dae, st) : = CevalScriptBackend . runFrontEnd(cache, graph, className, st, false );
908922 ExecStat . execStat("FrontEnd" );
909923
910924 if Flags . isSet(Flags . SERIALIZED_SIZE ) then
@@ -915,26 +929,26 @@ algorithm
915929 ExecStat . execStat("Serialize FrontEnd" );
916930 end if ;
917931
918- timeFrontend = System . realtimeTock(ClockIndexes . RT_CLOCK_FRONTEND );
932+ timeFrontend : = System . realtimeTock(ClockIndexes . RT_CLOCK_FRONTEND );
919933
920934 System . realtimeTick(ClockIndexes . RT_CLOCK_BACKEND );
921- dae = DAEUtil . transformationsBeforeBackend(cache, graph, dae);
935+ dae : = DAEUtil . transformationsBeforeBackend(cache, graph, dae);
922936 ExecStat . execStat("Transformations before backend" );
923937
924938 if Flags . isSet(Flags . SERIALIZED_SIZE ) then
925939 serializeNotify(dae, filenameprefix, "dae2" );
926940 ExecStat . execStat("Serialize DAE (2)" );
927941 end if ;
928942
929- generateFunctions = Flags . set(Flags . GEN , false );
943+ generateFunctions : = Flags . set(Flags . GEN , false );
930944 // We should not need to lookup constants and classes in the backend,
931945 // so let's free up the old graph and just make it the initial environment.
932946 if not Flags . isSet(Flags . BACKEND_KEEP_ENV_GRAPH ) then
933- (cache,graph) = Builtin . initialGraph(cache);
947+ (cache,graph) : = Builtin . initialGraph(cache);
934948 end if ;
935949
936- description = DAEUtil . daeDescription(dae);
937- dlow = BackendDAECreate . lower(dae, cache, graph, BackendDAE . EXTRA_INFO (description,filenameprefix));
950+ description : = DAEUtil . daeDescription(dae);
951+ dlow : = BackendDAECreate . lower(dae, cache, graph, BackendDAE . EXTRA_INFO (description,filenameprefix));
938952
939953 GC . free(dae);
940954
@@ -944,8 +958,8 @@ algorithm
944958 end if ;
945959
946960 // BackendDump.printBackendDAE(dlow);
947- (dlow, initDAE, inlineData, useHomotopy, initDAE_lambda0, removedInitialEquationLst, primaryParameters, allPrimaryParameters) = BackendDAEUtil . getSolvedSystem(dlow,inFileNamePrefix);
948- timeBackend = System . realtimeTock(ClockIndexes . RT_CLOCK_BACKEND );
961+ (dlow, initDAE, inlineData, useHomotopy, initDAE_lambda0, removedInitialEquationLst, primaryParameters, allPrimaryParameters) : = BackendDAEUtil . getSolvedSystem(dlow,inFileNamePrefix);
962+ timeBackend : = System . realtimeTock(ClockIndexes . RT_CLOCK_BACKEND );
949963
950964 if Flags . isSet(Flags . SERIALIZED_SIZE ) then
951965 serializeNotify(dlow, filenameprefix, "simDAE" );
@@ -957,10 +971,9 @@ algorithm
957971 ExecStat . execStat("Serialize solved system" );
958972 end if ;
959973
960- (libs, file_dir, timeSimCode, timeTemplates) =
961- generateModelCode(dlow, initDAE, inlineData, useHomotopy, initDAE_lambda0, removedInitialEquationLst, primaryParameters, allPrimaryParameters, p, className, filenameprefix, inSimSettingsOpt, args);
974+ (libs, file_dir, timeSimCode, timeTemplates) := generateModelCode(dlow, initDAE, inlineData, useHomotopy, initDAE_lambda0, removedInitialEquationLst, primaryParameters, allPrimaryParameters, p, className, filenameprefix, inSimSettingsOpt, args);
962975
963- resultValues = {("timeTemplates" , Values . REAL (timeTemplates)),
976+ resultValues : = {("timeTemplates" , Values . REAL (timeTemplates)),
964977 ("timeSimCode" , Values . REAL (timeSimCode)),
965978 ("timeBackend" , Values . REAL (timeBackend)),
966979 ("timeFrontend" , Values . REAL (timeFrontend))};
0 commit comments