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
2bb7be83
Commit
2bb7be83
authored
Jul 10, 2018
by
Evgeny Kusmenko
Browse files
Merge branch 'richter-dev' into 'master'
Richter dev Closes #5 See merge request
!9
parents
000b1bd5
491ff8bd
Pipeline
#61717
passed with stage
in 2 minutes and 43 seconds
Changes
9
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
.gitlab-ci.yml
View file @
2bb7be83
...
...
@@ -8,6 +8,7 @@ masterJobLinux:
script
:
-
gcc --help
-
mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B clean deploy --settings settings.xml
-
cat target/site/jacoco/index.html
only
:
-
master
...
...
@@ -23,5 +24,6 @@ BranchJobLinux:
image
:
maven:3-jdk-8
script
:
-
mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B clean install --settings settings.xml
-
cat target/site/jacoco/index.html
except
:
-
master
README.md
View file @
2bb7be83
[

](https://codeclimate.com/github/EmbeddedMontiArc/EMAM2Cpp/maintainability)
[

](https://travis-ci.org/EmbeddedMontiArc/EMAM2Cpp)
[

](https://circleci.com/gh/EmbeddedMontiArc/EMAM2Cpp/tree/master)
[

](https://coveralls.io/github/EmbeddedMontiArc/EMAM2Cpp?branch=master)


[

](https://github.com/EmbeddedMontiArc/Documentation/blob/master/reposlides/18.05.22.Docu.EMAM2CPP.pdf)
# EMAM2Cpp
pom.xml
View file @
2bb7be83
...
...
@@ -8,7 +8,7 @@
<groupId>
de.monticore.lang.monticar
</groupId>
<artifactId>
embedded-montiarc-math-generator
</artifactId>
<version>
0.0.1
7
-SNAPSHOT
</version>
<version>
0.0.1
8
-SNAPSHOT
</version>
<!-- == PROJECT DEPENDENCIES ============================================= -->
...
...
@@ -21,8 +21,8 @@
<Common-MontiCar.version>
0.0.14-SNAPSHOT
</Common-MontiCar.version>
<Embedded-MontiArc.version>
0.0.18-SNAPSHOT
</Embedded-MontiArc.version>
<Embedded-MontiArc-Behaviour.version>
0.0.14-SNAPSHOT
</Embedded-MontiArc-Behaviour.version>
<Math.version>
0.0.1
4
-SNAPSHOT
</Math.version>
<Embedded-MontiArc-Math.version>
0.0.1
5
-SNAPSHOT
</Embedded-MontiArc-Math.version>
<Math.version>
0.0.1
7
-SNAPSHOT
</Math.version>
<Embedded-MontiArc-Math.version>
0.0.1
8
-SNAPSHOT
</Embedded-MontiArc-Math.version>
<tagging.version>
0.0.3-SNAPSHOT
</tagging.version>
<!-- .. Libraries .................................................. -->
<guava.version>
18.0
</guava.version>
...
...
@@ -36,6 +36,7 @@
<compiler.plugin>
3.3
</compiler.plugin>
<source.plugin>
2.4
</source.plugin>
<shade.plugin>
2.4.3
</shade.plugin>
<jacoco.plugin>
0.8.1
</jacoco.plugin>
<!-- Classifiers -->
<grammars.classifier>
grammars
</grammars.classifier>
...
...
@@ -266,6 +267,28 @@
</executions>
</plugin>
<!-- Test coverage -->
<plugin>
<groupId>
org.jacoco
</groupId>
<artifactId>
jacoco-maven-plugin
</artifactId>
<version>
${jacoco.plugin}
</version>
<executions>
<execution>
<id>
pre-unit-test
</id>
<goals>
<goal>
prepare-agent
</goal>
</goals>
</execution>
<execution>
<id>
post-unit-test
</id>
<phase>
test
</phase>
<goals>
<goal>
report
</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Source Jar Configuration -->
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
...
...
src/main/java/de/monticore/lang/monticar/generator/cpp/converter/ExecuteMethodGeneratorHandler.java
View file @
2bb7be83
package
de.monticore.lang.monticar.generator.cpp.converter
;
import
de.monticore.lang.math._symboltable.MathAssignmentOperator
;
import
de.monticore.lang.math._symboltable.MathForLoopHeadSymbol
;
import
de.monticore.lang.math._symboltable.expression.*
;
import
de.monticore.lang.math._symboltable.matrix.MathMatrixNameExpressionSymbol
;
...
...
@@ -61,8 +62,8 @@ public class ExecuteMethodGeneratorHandler {
return
generateExecuteCode
((
MathNameExpressionSymbol
)
mathValueExpressionSymbol
,
includeStrings
);
}
else
if
(
mathValueExpressionSymbol
.
isNumberExpression
())
{
return
generateExecuteCode
((
MathNumberExpressionSymbol
)
mathValueExpressionSymbol
,
includeStrings
);
}
else
if
(
mathValueExpressionSymbol
.
isBooleanExpression
())
{
return
generateExecuteCode
((
MathBooleanExpressionSymbol
)
mathValueExpressionSymbol
,
includeStrings
);
}
else
if
(
mathValueExpressionSymbol
.
isBooleanExpression
())
{
return
generateExecuteCode
((
MathBooleanExpressionSymbol
)
mathValueExpressionSymbol
,
includeStrings
);
}
else
if
(
mathValueExpressionSymbol
.
isAssignmentDeclarationExpression
())
{
return
generateExecuteCodeDeclaration
((
MathValueSymbol
)
mathValueExpressionSymbol
,
includeStrings
);
}
else
{
...
...
@@ -83,12 +84,17 @@ public class ExecuteMethodGeneratorHandler {
ComponentConverter
.
currentBluePrint
.
addVariable
(
var
);
}
else
{
String
type
=
generateExecuteCode
(
mathValueSymbol
.
getType
(),
includeStrings
);
result
+=
type
+
" "
+
mathValueSymbol
.
getName
();
if
(
mathValueSymbol
.
getValue
()
!=
null
)
{
result
+=
" = "
+
ExecuteMethodGenerator
.
generateExecuteCode
(
mathValueSymbol
.
getValue
(),
includeStrings
);
}
else
if
(
mathValueSymbol
.
getValue
()
==
null
)
MathAssignmentExpressionSymbol
assignment
=
new
MathAssignmentExpressionSymbol
();
assignment
.
setNameOfMathValue
(
mathValueSymbol
.
getName
());
assignment
.
setExpressionSymbol
(
mathValueSymbol
.
getValue
());
assignment
.
setAssignmentOperator
(
new
MathAssignmentOperator
(
"="
));
result
+=
type
+
" "
+
ExecuteMethodGenerator
.
generateExecuteCode
(
assignment
,
includeStrings
);
}
else
if
(
mathValueSymbol
.
getValue
()
==
null
)
{
result
+=
type
+
" "
+
mathValueSymbol
.
getName
();
result
+=
addInitializationString
(
mathValueSymbol
,
type
,
includeStrings
);
result
+=
";\n"
;
result
+=
";\n"
;
}
}
ComponentConverter
.
currentBluePrint
.
getMathInformationRegister
().
addVariable
(
mathValueSymbol
);
//result += mathValueSymbol.getTextualRepresentation();
...
...
@@ -102,15 +108,15 @@ public class ExecuteMethodGeneratorHandler {
List
<
MathExpressionSymbol
>
dims
=
mathValueSymbol
.
getType
().
getDimensions
();
if
(
dims
.
size
()
==
1
)
{
if
(
typeString
.
equals
(
TypeConverter
.
getColvecAccessString
(
type
)))
{
result
=
"="
+
TypeConverter
.
getDimensionString
(
TypeConverter
.
getColvecAccessString
(
type
),
dims
,
includeStrings
);
result
=
"="
+
TypeConverter
.
getDimensionString
(
TypeConverter
.
getColvecAccessString
(
type
),
dims
,
includeStrings
);
}
}
else
if
(
dims
.
size
()
==
2
)
{
if
(
typeString
.
equals
(
TypeConverter
.
getMatAccessString
(
type
)))
{
result
=
"="
+
TypeConverter
.
getDimensionString
(
TypeConverter
.
getMatAccessString
(
type
),
dims
,
includeStrings
);
result
=
"="
+
TypeConverter
.
getDimensionString
(
TypeConverter
.
getMatAccessString
(
type
),
dims
,
includeStrings
);
}
}
else
if
(
dims
.
size
()
==
3
)
{
if
(
typeString
.
equals
(
TypeConverter
.
getCubeAccessString
(
type
)))
{
result
=
"="
+
TypeConverter
.
getDimensionString
(
TypeConverter
.
getCubeAccessString
(
type
),
dims
,
includeStrings
);
result
=
"="
+
TypeConverter
.
getDimensionString
(
TypeConverter
.
getCubeAccessString
(
type
),
dims
,
includeStrings
);
}
}
return
result
;
...
...
@@ -144,7 +150,6 @@ public class ExecuteMethodGeneratorHandler {
}
private
static
String
handleRationalType
(
MathValueType
mathValueType
)
{
if
(
mathValueType
.
getDimensions
().
size
()
==
0
)
{
return
"double"
;
...
...
@@ -216,7 +221,7 @@ public class ExecuteMethodGeneratorHandler {
Log
.
info
(
mathAssignmentExpressionSymbol
.
getTextualRepresentation
(),
"mathAssignmentExpressionSymbol:"
);
String
result
;
if
(
mathAssignmentExpressionSymbol
.
getMathMatrixAccessOperatorSymbol
()
!=
null
)
{
Log
.
info
(
mathAssignmentExpressionSymbol
.
getMathMatrixAccessOperatorSymbol
().
getTextualRepresentation
(),
"accessOperatorSymbol:"
);
Log
.
info
(
mathAssignmentExpressionSymbol
.
getMathMatrixAccessOperatorSymbol
().
getTextualRepresentation
(),
"accessOperatorSymbol:"
);
if
(
MathFunctionFixer
.
fixForLoopAccess
(
mathAssignmentExpressionSymbol
.
getNameOfMathValue
(),
ComponentConverter
.
currentBluePrint
))
{
result
=
mathAssignmentExpressionSymbol
.
getNameOfMathValue
();
...
...
@@ -255,26 +260,26 @@ public class ExecuteMethodGeneratorHandler {
String
name
=
mathAssignmentExpressionSymbol
.
getNameOfMathValue
();
String
op
=
mathAssignmentExpressionSymbol
.
getAssignmentOperator
().
getOperator
();
MathExpressionSymbol
assignmentSymbol
=
mathAssignmentExpressionSymbol
.
getExpressionSymbol
().
getRealMathExpressionSymbol
();
String
assignment
=
mathAssignmentExpressionSymbol
.
getExpressionSymbol
().
getTextualRepresentation
();
Log
.
info
(
assignment
,
"assignment0:"
);
String
assignment
=
mathAssignmentExpressionSymbol
.
getExpressionSymbol
().
getTextualRepresentation
();
Log
.
info
(
assignment
,
"assignment0:"
);
if
(
assignmentSymbol
instanceof
MathMatrixNameExpressionSymbol
)
{
MathMatrixNameExpressionSymbol
matrixAssignmentSymbol
=
(
MathMatrixNameExpressionSymbol
)
assignmentSymbol
;
if
(
useZeroBasedIndexing
(
matrixAssignmentSymbol
))
{
String
matrixName
=
matrixAssignmentSymbol
.
getNameToAccess
();
String
matrixAccess
=
ExecuteMethodGenerator
.
getCorrectAccessString
(
matrixAssignmentSymbol
.
getNameToAccess
(),
matrixAssignmentSymbol
.
getMathMatrixAccessOperatorSymbol
(),
includeStrings
);
assignment
=
String
.
format
(
"%s%s"
,
matrixName
,
matrixAccess
);
Log
.
info
(
assignment
,
"assignment1:"
);
Log
.
info
(
assignment
,
"assignment1:"
);
}
else
{
assignment
=
ExecuteMethodGenerator
.
generateExecuteCode
(
assignmentSymbol
,
includeStrings
);
Log
.
info
(
assignment
,
"assignment2:"
);
Log
.
info
(
assignment
,
"assignment2:"
);
}
}
else
{
assignment
=
ExecuteMethodGenerator
.
generateExecuteCode
(
assignmentSymbol
,
includeStrings
);
Log
.
info
(
assignment
,
"assignment3:"
);
Log
.
info
(
assignment
,
"assignment3:"
);
}
String
result
=
String
.
format
(
"%s %s %s;\n"
,
name
,
op
,
assignment
);
String
result
=
String
.
format
(
"%s %s %s;\n"
,
name
,
op
,
assignment
.
trim
()
);
Log
.
info
(
name
+
" "
+
op
+
" "
+
assignment
,
"additionalInfo:"
);
Log
.
info
(
"result3: "
+
result
,
"MathAssignmentExpressionSymbol"
);
return
result
;
...
...
@@ -282,9 +287,14 @@ public class ExecuteMethodGeneratorHandler {
private
static
boolean
useZeroBasedIndexing
(
MathMatrixNameExpressionSymbol
mathMatrixNameExpressionSymbol
)
{
boolean
isZeroBased
=
false
;
if
(
MathConverter
.
curBackend
.
usesZeroBasedIndexing
())
{
if
(!
isFunctionCall
(
mathMatrixNameExpressionSymbol
))
{
isZeroBased
=
true
;
// test if array
String
name
=
mathMatrixNameExpressionSymbol
.
getNameToAccess
();
Variable
variable
=
ComponentConverter
.
currentBluePrint
.
getVariable
(
name
).
orElse
(
null
);
if
(!(
variable
!=
null
&&
variable
.
isArray
()))
{
if
(
MathConverter
.
curBackend
.
usesZeroBasedIndexing
())
{
if
(!
isFunctionCall
(
mathMatrixNameExpressionSymbol
))
{
isZeroBased
=
true
;
}
}
}
return
isZeroBased
;
...
...
src/main/java/de/monticore/lang/monticar/generator/optimization/MathInformationRegister.java
View file @
2bb7be83
...
...
@@ -194,8 +194,13 @@ public class MathInformationRegister {
// is number
MathNumberExpressionSymbol
numberSymbol
=
(
MathNumberExpressionSymbol
)
symbol
;
result
=
Optional
.
of
(
numberSymbol
.
getValue
().
getRealNumber
().
doubleValue
());
}
else
{
// TODO resolve variable
}
else
if
(
symbol
instanceof
MathValueSymbol
)
{
result
=
tryGetDoubleValue
(((
MathValueSymbol
)
symbol
).
getValue
());
}
else
if
(
symbol
instanceof
MathNameExpressionSymbol
)
{
Optional
<
MathValueSymbol
>
resolvedSymbol
=
symbol
.
getEnclosingScope
().
resolve
(((
MathNameExpressionSymbol
)
symbol
).
getNameToResolveValue
(),
MathValueSymbol
.
KIND
);
if
(
resolvedSymbol
.
isPresent
())
{
result
=
tryGetDoubleValue
(
resolvedSymbol
.
get
());
}
}
}
return
result
;
...
...
@@ -260,7 +265,7 @@ public class MathInformationRegister {
}
return
result
;
}
private
MathExpressionSymbol
getSubstituteByName
(
String
name
,
MathExpressionSymbol
expr
,
String
atomarValueName
)
{
MathExpressionSymbol
result
;
MathValueSymbol
declaration
=
getMathValueSymbol
(
name
);
...
...
src/test/resources/results/armadillo/test/custom/l0/test_custom_pacmanSampleGame_main_pacmanWorldManager_pacmanWorldHandler_movementHandler_pacmanMovementCollisionChecker.h
View file @
2bb7be83
...
...
@@ -26,7 +26,7 @@ world=imat(tilesMaxX,tilesMaxY);
void
execute
()
{
int
value
=
1
;
value
=
world
(
pacmanPossibleNextPositionX
-
1
,
pacmanPossibleNextPositionY
-
1
)
;
value
=
world
(
pacmanPossibleNextPositionX
-
1
,
pacmanPossibleNextPositionY
-
1
);
if
(((
value
==
1
))){
canMove
=
0
;
pacmanChosenNextPositionX
=
pacmanPositionX
;
...
...
src/test/resources/results/armadillo/test/custom/l0/test_custom_sampleComponentInst_inst.h
View file @
2bb7be83
...
...
@@ -18,7 +18,7 @@ world=imat(tilesMaxX,tilesMaxY);
}
void
execute
()
{
int
value
=
world
(
posX
,
posY
);
int
value
=
world
(
posX
-
1
,
posY
-
1
);
}
};
...
...
src/test/resources/results/armadillo/testMath/l0/test_math_armadilloIndexTest.h
View file @
2bb7be83
...
...
@@ -8,6 +8,8 @@ using namespace arma;
class
test_math_armadilloIndexTest
{
public:
mat
in1
;
int
inRow
;
int
inCol
;
mat
out1
;
mat
CONSTANTCONSTANTVECTOR0
;
rowvec
CONSTANTCONSTANTVECTOR1
;
...
...
@@ -41,14 +43,15 @@ b(1-1) = A(1-1);
b
(
1
-
1
)
=
A
(
2
-
1
,
2
-
1
);
b
(
2
-
1
)
=
out1
(
4
-
1
,
4
-
1
);
double
x
=
0
;
x
=
A
(
1
-
1
,
2
-
1
)
;
x
=
b
(
2
-
1
)
;
x
=
in1
(
1
-
1
,
1
-
1
)
;
x
=
A
(
1
-
1
,
2
-
1
);
x
=
b
(
2
-
1
);
x
=
in1
(
1
-
1
,
1
-
1
);
out1
(
1
-
1
,
1
-
1
)
=
in1
(
1
-
1
,
1
-
1
);
mat
test
=
(
zeros
<
mat
>
(
4
,
4
));
out1
=
test
;
out1
(
1
-
1
)
=
test
(
1
-
1
);
out1
(
2
-
1
,
2
-
1
)
=
A
(
2
-
1
,
2
-
1
);
double
y
=
A
(
inRow
-
1
,
inCol
-
1
);
}
};
...
...
src/test/resources/test/math/ArmadilloIndexTest.emam
View file @
2bb7be83
...
...
@@ -3,6 +3,8 @@ package test.math;
component
ArmadilloIndexTest
{
ports
in
Q
^{
2
,
2
}
in1
,
in
Z
inRow
,
in
Z
inCol
,
out
Q
^{
4
,
4
}
out1
;
implementation
Math
{
...
...
@@ -44,5 +46,9 @@ component ArmadilloIndexTest{
out1
=
test
;
out1
(
1
)
=
test
(
1
);
out1
(
2
,
2
)
=
A
(
2
,
2
);
//
test
scalar
port
matrix
access
Q
y
=
A
(
inRow
,
inCol
);
}
}
\ No newline at end of file
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