Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
monticore
EmbeddedMontiArc
generators
EMAM2Cpp
Commits
bcef2102
Commit
bcef2102
authored
Nov 16, 2020
by
Malte Heithoff
Browse files
ExecutionStepper and LoopInstanceSymbol generation
parent
9b2a2f55
Changes
2
Show whitespace changes
Inline
Side-by-side
src/main/java/de/monticore/lang/monticar/generator/cpp/ExecutionStepperHelper.java
View file @
bcef2102
...
@@ -33,8 +33,8 @@ public class ExecutionStepperHelper {
...
@@ -33,8 +33,8 @@ public class ExecutionStepperHelper {
return
"#ifndef EXECUTIONSTEPPER\n"
+
return
"#ifndef EXECUTIONSTEPPER\n"
+
"#define EXECUTIONSTEPPER\n"
+
"#define EXECUTIONSTEPPER\n"
+
"\n"
+
"\n"
+
"static double static_var_dt =
"
+
dt
+
";\n"
+
String
.
format
(
"static double static_var_dt =
%s;\n"
,
dt
)
+
"static double static_var_currentTime =
0
;\n"
+
String
.
format
(
"static double static_var_currentTime =
%s
;\n"
,
dt
)
+
"\n"
+
"\n"
+
"static double getCurrentTime() {\n"
+
"static double getCurrentTime() {\n"
+
" return static_var_currentTime;\n"
+
" return static_var_currentTime;\n"
+
...
...
src/main/java/de/monticore/lang/monticar/generator/cpp/GeneratorCPP.java
View file @
bcef2102
...
@@ -15,6 +15,9 @@ import de.monticore.lang.monticar.generator.cpp.Dynamics.DynamicHelper;
...
@@ -15,6 +15,9 @@ import de.monticore.lang.monticar.generator.cpp.Dynamics.DynamicHelper;
import
de.monticore.lang.monticar.generator.cpp.Dynamics.EventPortValueCheck
;
import
de.monticore.lang.monticar.generator.cpp.Dynamics.EventPortValueCheck
;
import
de.monticore.lang.monticar.generator.cpp.converter.*
;
import
de.monticore.lang.monticar.generator.cpp.converter.*
;
import
de.monticore.lang.monticar.generator.cpp.instruction.ConnectInstructionCPP
;
import
de.monticore.lang.monticar.generator.cpp.instruction.ConnectInstructionCPP
;
import
de.monticore.lang.monticar.generator.cpp.loopSolver.CPPEquationSystemHelper
;
import
de.monticore.lang.monticar.generator.cpp.loopSolver.daecpp.DAECPPEquationSystemGenerator
;
import
de.monticore.lang.monticar.generator.cpp.loopSolver.daecpp.DAECPPOptions
;
import
de.monticore.lang.monticar.generator.cpp.mathopt.MathOptSolverConfig
;
import
de.monticore.lang.monticar.generator.cpp.mathopt.MathOptSolverConfig
;
import
de.monticore.lang.monticar.generator.cpp.template.AllTemplates
;
import
de.monticore.lang.monticar.generator.cpp.template.AllTemplates
;
import
de.monticore.lang.monticar.generator.cpp.viewmodel.AutopilotAdapterDataModel
;
import
de.monticore.lang.monticar.generator.cpp.viewmodel.AutopilotAdapterDataModel
;
...
@@ -71,6 +74,7 @@ public class GeneratorCPP implements EMAMGenerator {
...
@@ -71,6 +74,7 @@ public class GeneratorCPP implements EMAMGenerator {
private
MathOptSolverConfig
mathOptSolverConfig
=
new
MathOptSolverConfig
();
private
MathOptSolverConfig
mathOptSolverConfig
=
new
MathOptSolverConfig
();
private
OptimizationSymbolHandler
mathOptExecuteMethodGenerator
=
new
OptimizationSymbolHandler
();
private
OptimizationSymbolHandler
mathOptExecuteMethodGenerator
=
new
OptimizationSymbolHandler
();
private
MathOptFunctionFixer
mathOptFunctionFixer
=
new
MathOptFunctionFixer
();
private
MathOptFunctionFixer
mathOptFunctionFixer
=
new
MathOptFunctionFixer
();
private
EMAComponentInstanceSymbol
rootModel
=
null
;
public
GeneratorCPP
()
{
public
GeneratorCPP
()
{
this
.
mathCommandRegister
=
new
MathCommandRegisterCPP
();
this
.
mathCommandRegister
=
new
MathCommandRegisterCPP
();
...
@@ -176,11 +180,33 @@ public class GeneratorCPP implements EMAMGenerator {
...
@@ -176,11 +180,33 @@ public class GeneratorCPP implements EMAMGenerator {
if
(
bluePrintCPP
!=
null
)
{
if
(
bluePrintCPP
!=
null
)
{
bluePrints
.
add
(
bluePrintCPP
);
bluePrints
.
add
(
bluePrintCPP
);
if
(
componentSymbol
.
equals
(
this
.
rootModel
)
&&
ExecutionStepperHelper
.
isUsed
())
{
Optional
<
Method
>
execute
=
bluePrintCPP
.
getMethod
(
"execute"
);
if
(!
execute
.
isPresent
())
Log
.
error
(
"TODO should not happen, bc ExecutionStepper is used"
);
else
{
execute
.
get
().
getInstructions
().
add
(
new
Instruction
()
{
@Override
public
String
getTargetLanguageInstruction
()
{
return
"advanceTime();\n"
;
}
@Override
public
boolean
isConnectInstruction
()
{
return
false
;
}
});
bluePrintCPP
.
addAdditionalIncludeString
(
ExecutionStepperHelper
.
fileName
);
}
}
// connect information to eqs
// connect information to eqs
if
(
componentSymbol
instanceof
LoopSymbolInstance
)
{
if
(
componentSymbol
instanceof
LoopSymbolInstance
)
{
ExecutionStepperHelper
.
setUsed
();
EMAEquationSystem
equationSystem
=
((
LoopSymbolInstance
)
componentSymbol
).
getEquationSystem
();
EMAEquationSystem
equationSystem
=
((
LoopSymbolInstance
)
componentSymbol
).
getEquationSystem
();
String
eqsName
=
equationSystem
.
getName
();
String
eqsName
=
equationSystem
.
getName
();
bluePrintCPP
.
addAdditionalIncludeString
(
eqsName
);
Variable
eqs
=
new
Variable
(
"eqs"
,
""
);
eqs
.
setVariableType
(
new
VariableType
(
""
,
eqsName
,
eqsName
));
bluePrintCPP
.
addVariable
(
eqs
);
Optional
<
Method
>
execute
=
bluePrintCPP
.
getMethod
(
"execute"
);
Optional
<
Method
>
execute
=
bluePrintCPP
.
getMethod
(
"execute"
);
if
(
execute
.
isPresent
())
{
if
(
execute
.
isPresent
())
{
for
(
EMAPortInstanceSymbol
inport
:
equationSystem
.
getInports
())
{
for
(
EMAPortInstanceSymbol
inport
:
equationSystem
.
getInports
())
{
...
@@ -190,8 +216,8 @@ public class GeneratorCPP implements EMAMGenerator {
...
@@ -190,8 +216,8 @@ public class GeneratorCPP implements EMAMGenerator {
.
findFirst
();
.
findFirst
();
if
(
currentPort
.
isPresent
())
{
if
(
currentPort
.
isPresent
())
{
String
sourceName
=
currentPort
.
get
().
getName
();
String
sourceName
=
currentPort
.
get
().
getName
();
String
targetName
=
String
.
join
(
"
::
"
,
eqs
Name
,
String
targetName
=
String
.
join
(
"
.
"
,
"
eqs
"
,
NameHelper
.
replaceWithUnderScore
(
NameHelper
.
calculateFullQualified
NameOf
(
inport
))
)
;
CPPEquationSystemHelper
.
get
NameOf
Port
(
inport
));
Variable
v1
=
PortConverter
.
convertPortSymbolToVariable
(
currentPort
.
get
(),
sourceName
,
bluePrintCPP
);
Variable
v1
=
PortConverter
.
convertPortSymbolToVariable
(
currentPort
.
get
(),
sourceName
,
bluePrintCPP
);
Variable
v2
=
PortConverter
.
convertPortSymbolToVariable
(
inport
,
targetName
,
bluePrintCPP
);
Variable
v2
=
PortConverter
.
convertPortSymbolToVariable
(
inport
,
targetName
,
bluePrintCPP
);
execute
.
get
().
addInstruction
(
new
ConnectInstructionCPP
(
v2
,
v1
));
execute
.
get
().
addInstruction
(
new
ConnectInstructionCPP
(
v2
,
v1
));
...
@@ -200,7 +226,7 @@ public class GeneratorCPP implements EMAMGenerator {
...
@@ -200,7 +226,7 @@ public class GeneratorCPP implements EMAMGenerator {
execute
.
get
().
addInstruction
(
new
Instruction
()
{
execute
.
get
().
addInstruction
(
new
Instruction
()
{
@Override
@Override
public
String
getTargetLanguageInstruction
()
{
public
String
getTargetLanguageInstruction
()
{
return
String
.
join
(
"::"
,
eqsName
,
"
execute();\n"
)
;
return
"eqs.
execute();\n"
;
}
}
@Override
@Override
public
boolean
isConnectInstruction
()
{
public
boolean
isConnectInstruction
()
{
...
@@ -212,8 +238,8 @@ public class GeneratorCPP implements EMAMGenerator {
...
@@ -212,8 +238,8 @@ public class GeneratorCPP implements EMAMGenerator {
.
filter
(
p
->
p
.
getFullName
().
equals
(
outport
.
getFullName
()))
.
filter
(
p
->
p
.
getFullName
().
equals
(
outport
.
getFullName
()))
.
findFirst
();
.
findFirst
();
if
(
eqsVar
.
isPresent
())
{
if
(
eqsVar
.
isPresent
())
{
String
sourceName
=
String
.
join
(
"
::
"
,
eqs
Name
,
String
sourceName
=
String
.
join
(
"
.
"
,
"
eqs
"
,
NameHelper
.
replaceWithUnderScore
(
NameHelper
.
calculateFullQualified
NameOf
(
eqsVar
.
get
()))
)
;
CPPEquationSystemHelper
.
get
NameOf
Port
(
eqsVar
.
get
()));
String
targetName
=
outport
.
getName
();
String
targetName
=
outport
.
getName
();
Variable
v1
=
PortConverter
.
convertPortSymbolToVariable
(
eqsVar
.
get
(),
sourceName
,
bluePrintCPP
);
Variable
v1
=
PortConverter
.
convertPortSymbolToVariable
(
eqsVar
.
get
(),
sourceName
,
bluePrintCPP
);
Variable
v2
=
PortConverter
.
convertPortSymbolToVariable
(
outport
,
targetName
,
bluePrintCPP
);
Variable
v2
=
PortConverter
.
convertPortSymbolToVariable
(
outport
,
targetName
,
bluePrintCPP
);
...
@@ -244,12 +270,17 @@ public class GeneratorCPP implements EMAMGenerator {
...
@@ -244,12 +270,17 @@ public class GeneratorCPP implements EMAMGenerator {
//setGenerateMainClass(true);
//setGenerateMainClass(true);
}
}
if
(
componentInstanceSymbol
instanceof
LoopSymbolInstance
)
{
((
LoopSymbolInstance
)
componentInstanceSymbol
).
getEquationSystem
()
.
setName
(
String
.
join
(
"_"
,
NameHelper
.
replaceWithUnderScore
(
NameHelper
.
calculateFullQualifiedNameOf
(
rootModel
)),
((
LoopSymbolInstance
)
componentInstanceSymbol
).
getEquationSystem
().
getName
()));
for
(
CMakeFindModule
dependency
:
DAECPPOptions
.
getDependencies
())
{
cMakeConfig
.
addModuleDependency
(
dependency
);
}
}
currentFileContentList
=
fileContents
;
currentFileContentList
=
fileContents
;
if
(!
streamTestGenerationMode
)
fileContents
.
add
(
new
FileContent
(
generateString
(
taggingResolver
,
componentInstanceSymbol
),
componentInstanceSymbol
));
else
fileContents
.
add
(
new
FileContent
(
generateString
(
taggingResolver
,
componentInstanceSymbol
),
componentInstanceSymbol
.
getPackageName
().
replaceAll
(
"\\."
,
"\\/"
)
+
"/"
+
StringUtils
.
capitalize
(
componentInstanceSymbol
.
getName
())
+
"Test"
+
testNamePostFix
+
".stream"
));
String
lastNameWithoutArrayPart
=
""
;
String
lastNameWithoutArrayPart
=
""
;
if
(!
streamTestGenerationMode
)
{
if
(!
streamTestGenerationMode
)
{
for
(
EMAComponentInstanceSymbol
instanceSymbol
:
componentInstanceSymbol
.
getSubComponents
())
{
for
(
EMAComponentInstanceSymbol
instanceSymbol
:
componentInstanceSymbol
.
getSubComponents
())
{
...
@@ -281,6 +312,12 @@ public class GeneratorCPP implements EMAMGenerator {
...
@@ -281,6 +312,12 @@ public class GeneratorCPP implements EMAMGenerator {
fileContents
.
addAll
(
SimulatorIntegrationHelper
.
getSimulatorIntegrationHelperFileContent
());
fileContents
.
addAll
(
SimulatorIntegrationHelper
.
getSimulatorIntegrationHelperFileContent
());
}
}
}
}
if
(!
streamTestGenerationMode
)
fileContents
.
add
(
new
FileContent
(
generateString
(
taggingResolver
,
componentInstanceSymbol
),
componentInstanceSymbol
));
else
fileContents
.
add
(
new
FileContent
(
generateString
(
taggingResolver
,
componentInstanceSymbol
),
componentInstanceSymbol
.
getPackageName
().
replaceAll
(
"\\."
,
"\\/"
)
+
"/"
+
StringUtils
.
capitalize
(
componentInstanceSymbol
.
getName
())
+
"Test"
+
testNamePostFix
+
".stream"
));
if
(
MathConverter
.
curBackend
.
getBackendName
().
equals
(
"OctaveBackend"
))
if
(
MathConverter
.
curBackend
.
getBackendName
().
equals
(
"OctaveBackend"
))
fileContents
.
add
(
OctaveHelper
.
getOctaveHelperFileContent
());
fileContents
.
add
(
OctaveHelper
.
getOctaveHelperFileContent
());
if
(
MathConverter
.
curBackend
.
getBackendName
().
equals
(
"ArmadilloBackend"
))
if
(
MathConverter
.
curBackend
.
getBackendName
().
equals
(
"ArmadilloBackend"
))
...
@@ -305,7 +342,8 @@ public class GeneratorCPP implements EMAMGenerator {
...
@@ -305,7 +342,8 @@ public class GeneratorCPP implements EMAMGenerator {
if
(
componentInstanceSymbol
instanceof
LoopSymbolInstance
)
{
if
(
componentInstanceSymbol
instanceof
LoopSymbolInstance
)
{
if
(!
equationSystemsAlreadyBuild
.
contains
(((
LoopSymbolInstance
)
componentInstanceSymbol
).
getEquationSystem
()))
{
if
(!
equationSystemsAlreadyBuild
.
contains
(((
LoopSymbolInstance
)
componentInstanceSymbol
).
getEquationSystem
()))
{
// Generate Equation System components and Helper maybe
fileContents
.
addAll
(
DAECPPEquationSystemGenerator
.
generateEquationSystem
(
((
LoopSymbolInstance
)
componentInstanceSymbol
).
getEquationSystem
()));
}
}
}
}
...
@@ -314,6 +352,7 @@ public class GeneratorCPP implements EMAMGenerator {
...
@@ -314,6 +352,7 @@ public class GeneratorCPP implements EMAMGenerator {
//TODO add incremental generation based on described concept
//TODO add incremental generation based on described concept
public
List
<
File
>
generateFiles
(
TaggingResolver
taggingResolver
,
EMAComponentInstanceSymbol
componentSymbol
)
throws
IOException
{
public
List
<
File
>
generateFiles
(
TaggingResolver
taggingResolver
,
EMAComponentInstanceSymbol
componentSymbol
)
throws
IOException
{
this
.
rootModel
=
componentSymbol
;
List
<
FileContent
>
fileContents
=
new
ArrayList
<>();
List
<
FileContent
>
fileContents
=
new
ArrayList
<>();
if
(
componentSymbol
==
null
)
{
if
(
componentSymbol
==
null
)
{
ComponentScanner
componentScanner
=
new
ComponentScanner
(
getModelsDirPath
(),
taggingResolver
,
"emam"
);
ComponentScanner
componentScanner
=
new
ComponentScanner
(
getModelsDirPath
(),
taggingResolver
,
"emam"
);
...
@@ -345,7 +384,6 @@ public class GeneratorCPP implements EMAMGenerator {
...
@@ -345,7 +384,6 @@ public class GeneratorCPP implements EMAMGenerator {
}
}
// Add advanceTime
// Add advanceTime
if
(
ExecutionStepperHelper
.
isUsed
())
{
if
(
ExecutionStepperHelper
.
isUsed
())
{
addAdvanceTimeToExecute
(
fileContents
,
componentSymbol
);
fileContents
.
add
(
ExecutionStepperHelper
.
getTimeHelperFileContent
(
dt
));
fileContents
.
add
(
ExecutionStepperHelper
.
getTimeHelperFileContent
(
dt
));
}
}
List
<
File
>
files
=
saveFilesToDisk
(
fileContents
);
List
<
File
>
files
=
saveFilesToDisk
(
fileContents
);
...
@@ -356,26 +394,6 @@ public class GeneratorCPP implements EMAMGenerator {
...
@@ -356,26 +394,6 @@ public class GeneratorCPP implements EMAMGenerator {
return
files
;
return
files
;
}
}
public
void
addAdvanceTimeToExecute
(
List
<
FileContent
>
fileContents
,
EMAComponentInstanceSymbol
componentSymbol
)
{
Optional
<
FileContent
>
main
=
fileContents
.
stream
().
filter
(
fileContent
->
fileContent
.
getFileName
().
equals
(
GeneralHelperMethods
.
getTargetLanguageComponentName
(
componentSymbol
.
getFullName
())
+
".h"
)).
findFirst
();
if
(!
main
.
get
().
getFileContent
().
contains
(
"advanceTime();"
))
{
String
newFileContent
=
main
.
get
().
getFileContent
()
.
replace
(
"void execute()\n"
+
"{\n"
,
"void execute()\n"
+
"{\n"
+
"advanceTime();\n"
);
if
(!
newFileContent
.
contains
(
"#include \"ExecutionStepperHelper.h\""
))
newFileContent
=
newFileContent
.
replace
(
"#endif\n"
,
"#endif\n#include \"ExecutionStepperHelper.h\"\n"
);
main
.
get
().
setFileContent
(
newFileContent
);
}
}
protected
List
<
File
>
generateCMakeFiles
(
EMAComponentInstanceSymbol
componentInstanceSymbol
)
{
protected
List
<
File
>
generateCMakeFiles
(
EMAComponentInstanceSymbol
componentInstanceSymbol
)
{
List
<
File
>
files
=
new
ArrayList
<>();
List
<
File
>
files
=
new
ArrayList
<>();
if
(
componentInstanceSymbol
!=
null
)
{
if
(
componentInstanceSymbol
!=
null
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment