Commit f0ec78ea authored by Evgeny Kusmenko's avatar Evgeny Kusmenko

Merge branch 'adi-dev' into 'master'

Adi dev

See merge request !41
parents 7e9c51f0 19ba8eac
Pipeline #271488 passed with stage
in 21 minutes and 48 seconds
stages:
- linux
- windows
- linux
#- windows
masterJobLinux:
stage: linux
image: maven:3-jdk-8
script:
- apt-get update -q && apt-get install -y -q g++ libhdf5-serial-dev libhdf5-dev libopenblas-dev
- gcc --help
- mvn -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B clean deploy --settings settings.xml
- cat target/site/jacoco/index.html
- mvn package sonar:sonar -s settings.xml
only:
- master
masterJobWindows:
stage: windows
script:
- mvn -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B clean install --settings settings.xml -U
- apt-get update -q && apt-get install -y -q g++ libhdf5-serial-dev libhdf5-dev libopenblas-dev
- gcc --help
- mvn -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B clean deploy --settings settings.xml
- cat target/site/jacoco/index.html
- mvn package sonar:sonar -s settings.xml
only:
- master
tags:
- Windows10
#masterJobWindows:
# stage: windows
# script:
# - mvn -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B clean install --settings settings.xml -U
# only:
# - master
# tags:
# - Windows10
BranchJobLinux:
stage: linux
image: maven:3-jdk-8
script:
- apt-get update -q && apt-get install -y -q g++ libhdf5-serial-dev libhdf5-dev libopenblas-dev
- mvn -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B clean install --settings settings.xml
- cat target/site/jacoco/index.html
- apt-get update -q && apt-get install -y -q g++ libhdf5-serial-dev libhdf5-dev libopenblas-dev
- mvn -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true -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
- master
BranchJobWindows:
stage: windows
script:
- mvn -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B clean install --settings settings.xml -U
- cat target/site/jacoco/index.html
except:
- master
tags:
- Windows10
#BranchJobWindows:
# stage: windows
# script:
# - mvn -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B clean install --settings settings.xml -U
# - cat target/site/jacoco/index.html
# except:
# - master
# tags:
# - Windows10
......@@ -33,3 +33,15 @@ If no search directory is specified CMake will search on default locations. For
Here an example for Armadillo:
Create a environment variable called _Armadillo_Home_ with the path to the base directory of your Armadillo installation.
### Note to use CV-Commands:
* Available since version 0.1.16-SNAPSHOT.
* In case you use CV-Commands on input- or output ports in your Project, it is necessary to run the following command-call on the generated general file:
_sed -i 's/cube/Cube<unsigned char>/g' your_project_general_file.h_
* This adaptation should be integrated into _EMAM2CPP_ in the future.
* For conversion between _Armadillo_-matrix/cube and _OpenCV_-matrix/cube it exists a helper-header _ConvHelper.h_. This is generated automatically if at least one CV-command is used.
* For more information about how to use CV-Command, see the _BallTracking_-project in the application repository.
......@@ -10,7 +10,7 @@
<groupId>de.monticore.lang.monticar</groupId>
<artifactId>embedded-montiarc-math-generator</artifactId>
<version>0.1.15-SNAPSHOT</version>
<version>0.1.16-SNAPSHOT</version>
<!-- == PROJECT DEPENDENCIES ============================================= -->
......
......@@ -5,6 +5,7 @@ import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instance
import de.monticore.lang.monticar.generator.optimization.MathInformationRegister;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
......@@ -28,6 +29,10 @@ public class BluePrint {
this.variables = variables;
}
public List<Variable> getVariables() {
return variables;
}
public void setName(String name) {
this.name = name;
}
......@@ -44,10 +49,6 @@ public class BluePrint {
return packageName;
}
public List<Variable> getVariables() {
return variables;
}
public int howManyVariables() {
return variables.size();
}
......@@ -59,7 +60,6 @@ public class BluePrint {
return Optional.empty();
}
public void addVariable(Variable v) {
variables.add(v);
}
......@@ -68,7 +68,15 @@ public class BluePrint {
variables.remove(v);
}
public void replaceVariable(Variable varOld, Variable varNew){
Collections.replaceAll(variables,varOld, varNew);
}
public void addMethod(Method method) {
for(Method meth: methods){
if(meth.getName().equals(method.getName())){
return;
}
}
methods.add(method);
}
......
......@@ -22,6 +22,8 @@ public interface MathBackend {
String getRowAccessCommandName();
String getTubeAccessCommandName();
String getBackendName();
String getTransposeCommand();
......
......@@ -4,8 +4,11 @@ package de.monticore.lang.monticar.generator;
import de.monticore.lang.math._symboltable.expression.MathExpressionSymbol;
import de.monticore.lang.math._symboltable.matrix.MathMatrixNameExpressionSymbol;
import de.monticore.lang.monticar.generator.cpp.BluePrintCPP;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import static de.monticore.lang.monticar.generator.cpp.MathCommandRegisterCPP.removeBrackets;
......@@ -62,4 +65,58 @@ public abstract class MathCommand {
return false;
}
public String getTypeOfFirstInput(MathMatrixNameExpressionSymbol mathMatrixNameExpressionSymbol, BluePrintCPP bluePrintCPP){
String nameOfFirstParameter = mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols().get(0).getTextualRepresentation();
for(Variable var: bluePrintCPP.getVariables()){
String varName = var.getName();
if(varName.equals(nameOfFirstParameter)){
VariableType varType = var.getVariableType();
String typeName = varType.getTypeNameTargetLanguage();
return typeName;
}
}
return "";
}
public void redefineArmaMat(BluePrintCPP bluePrint){
List<Variable> vars= bluePrint.getVariables();
for(Variable var : vars){
VariableType varType = var.getVariableType();
String targetName = varType.getTypeNameTargetLanguage();
if(targetName.equals("mat")){
Variable newVar = var;
newVar.setTypeNameTargetLanguage("arma::Mat<unsigned char>");
bluePrint.replaceVariable(var, newVar);
}else if(targetName.equals("cube")){
Variable newVarCube = var;
newVarCube.setTypeNameTargetLanguage("Cube<unsigned char>");
bluePrint.replaceVariable(var, newVarCube);
}
}
}
public void redefineInit(BluePrintCPP bluePrint){
Optional<Method> methodOpt = bluePrint.getMethod("init");
Method initMethod = methodOpt.get();
List<Instruction> instructs = initMethod.getInstructions();
for(Instruction instruct : instructs){
String code = instruct.getTargetLanguageInstruction();
if(code.contains("mat(")){
code =code.replace("mat(", "Mat<unsigned char>(");
} else if(code.contains("cube(")){
code = code.replace("cube(", "Cube<unsigned char>(");
}
((TargetCodeInstruction)instruct).setInstruction(code);
}
}
public boolean isArgumentNoReturnMathCommand() {
return false;
}
public boolean isCVMathCommand(){
return false;
}
}
/* (c) https://github.com/MontiCore/monticore */
package de.monticore.lang.monticar.generator;
import de.monticore.lang.monticar.generator.cpp.commands.ArgumentNoReturnMathCommand;
import java.util.ArrayList;
import java.util.List;
......@@ -8,6 +10,7 @@ import java.util.List;
*/
public abstract class MathCommandRegister {
public List<MathCommand> mathCommands = new ArrayList<>();
public List<ArgumentNoReturnMathCommand> argumentNoReturnMathCommands = new ArrayList<>();
public MathCommandRegister() {
init();
......@@ -15,12 +18,15 @@ public abstract class MathCommandRegister {
public void registerMathCommand(MathCommand mathCommand) {
mathCommands.add(mathCommand);
if(mathCommand.isArgumentNoReturnMathCommand()){
argumentNoReturnMathCommands.add((ArgumentNoReturnMathCommand) mathCommand);
}
}
public MathCommand getMathCommand(String functionName) {
for (MathCommand mathCommand : mathCommands) {
if (mathCommand.getMathCommandName().equals(functionName))
return mathCommand;
if (mathCommand.getMathCommandName().equals(functionName))
return mathCommand;
}
return null;
}
......
......@@ -42,6 +42,13 @@ public class Method {
parameters.add(v);
}
public void addParameter(Variable var, String variableName, String typeNameMontiCar,
String typeNameTargetLangauge, String includeName){
var.setName(variableName);
var.setVariableType(new VariableType(typeNameMontiCar, typeNameTargetLangauge, includeName));
parameters.add(var);
}
public boolean addParameterUnique(Variable v) {
boolean added = !containsParameter(v);
if (added) {
......
......@@ -48,6 +48,11 @@ public class ArmadilloBackend implements MathBackend {
return "row";
}
@Override
public String getTubeAccessCommandName() {
return "tube";
}
@Override
public String getBackendName() {
return "ArmadilloBackend";
......
......@@ -18,6 +18,8 @@ import java.util.List;
*/
public class BluePrintCPP extends BluePrint {
public List<String> additionalIncludeStrings = new ArrayList<>();
public List<String> cvIncludeStrings = new ArrayList<>();
public static boolean usedCV = false;
public BluePrintCPP(String name) {
super(name);
......@@ -37,6 +39,21 @@ public class BluePrintCPP extends BluePrint {
return additionalIncludeStrings.contains(includeString);
}
public List<String> getCVIncludeStrings() {
return cvIncludeStrings;
}
public void addCVIncludeString(String includeString) {
if (!hasCVIncludeString(includeString)) {
cvIncludeStrings.add(includeString);
usedCV = true;
}
}
public boolean hasCVIncludeString(String includeString) {
return cvIncludeStrings.contains(includeString);
}
public List<String> getConsts() {
List<String> consts = new ArrayList<>();
......
/* (c) https://github.com/MontiCore/monticore */
package de.monticore.lang.monticar.generator.cpp;
import de.monticore.lang.monticar.generator.FileContent;
/**
* @author Ahmed Diab
*/
public class ConversionHelper {
public static String fileName = "ConvHelper";
public static FileContent getConversionHelperFileContent(boolean generateTests) {
FileContent fileContent = new FileContent();
fileContent.setFileName(fileName + ".h");
String fileContentString = ConversionHelperSource.conversionHelperSourceCode;
fileContent.setFileContent(fileContentString);
return fileContent;
}
public static FileContent getConversionHelperFileContent(){
return getConversionHelperFileContent(false);
}
}
/* (c) https://github.com/MontiCore/monticore */
package de.monticore.lang.monticar.generator.cpp;
/**
* @author Ahmed Diab
*/
public class ConversionHelperSource {
public static String conversionHelperSourceCode = "#ifndef CONVHELPER_H\n" +
"#define CONVHELPER_H\n" +
"#include <iostream>\n" +
"#include \"armadillo\"\n" +
"#include <stdarg.h>\n" +
"#include <initializer_list>\n" +
"#include <fstream>\n" +
"using namespace arma;\n" +
"\n" +
"\n" +
"// convert an OpenCV matrix to Armadillo matrix. NOTE: a copy is made\n" +
"template <typename T>\n" +
"arma::Mat<T> to_arma(const cv::Mat_<T>& src) {\n" +
" arma::Mat<T> dst(reinterpret_cast<T*>(src.data), src.cols, src.rows);\n" +
" //src.copyTo({ src.rows, src.cols, dst.memptr() });\n" +
" return dst;\n" +
"}\n" +
"\n" +
"// convert an Armadillo matrix to OpenCV matrix. NOTE: no copy is made\n" +
"template<typename T>\n" +
"cv::Mat_<T> to_cvmat(const arma::Mat<T>& src) {\n" +
" return cv::Mat_<T>{int(src.n_cols), int(src.n_rows), const_cast<T*>(src.memptr())};\n" +
"}\n" +
"\n" +
"// convert an OpenCV multi-channel matrix to Armadillo cube. A copy is made\n" +
"template <typename T, int NC>\n" +
"Cube<T> to_armaCube(const cv::Mat_<cv::Vec<T, NC>>& src)\n" +
"{\n" +
" std::vector<cv::Mat_<T>> channels;\n" +
" Cube<T> dst(src.cols, src.rows, NC);\n" +
" for (int c = 0; c < NC; ++c)\n" +
" channels.push_back({ src.rows, src.cols, dst.slice(c).memptr() });\n" +
" cv::split(src, channels);\n" +
" return dst;\n" +
"}\n" +
"\n" +
"// convert an Armadillo cube to OpenCV matrix. NOTE: a copy is made\n" +
"template <typename T>\n" +
"cv::Mat to_cvmat(const Cube<T>& src) {\n" +
" std::vector<cv::Mat_<T>> channels;\n" +
" for (size_t c = 0; c < src.n_slices; ++c) {\n" +
" auto* data = const_cast<T*>(src.slice(c).memptr());\n" +
" channels.push_back({ int(src.n_cols), int(src.n_rows), data });\n" +
" }\n" +
" cv::Mat dst;\n" +
" cv::merge(channels, dst);\n" +
" return dst;\n" +
"}\n" +
"\n" +
"\n" +
"#endif";
}
......@@ -16,6 +16,7 @@ import de.monticore.lang.monticar.generator.cpp.converter.ExecuteMethodGenerator
import de.monticore.lang.monticar.generator.cpp.converter.MathConverter;
import de.monticore.lang.monticar.generator.cpp.converter.OptimizationSymbolHandler;
import de.monticore.lang.monticar.generator.cpp.converter.TypeConverter;
import de.monticore.lang.monticar.generator.cpp.BluePrintCPP.*;
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.viewmodel.AutopilotAdapterDataModel;
......@@ -59,6 +60,8 @@ public class GeneratorCPP implements Generator {
private boolean generateCMake = false;
private CMakeConfig cMakeConfig;
//MathOpt
private MathOptSolverConfig mathOptSolverConfig = new MathOptSolverConfig();
private OptimizationSymbolHandler mathOptExecuteMethodGenerator = new OptimizationSymbolHandler();
......@@ -122,7 +125,6 @@ public class GeneratorCPP implements Generator {
public String generateString(TaggingResolver taggingResolver, EMAComponentInstanceSymbol componentInstanceSymbol, Scope symtab) {
MathStatementsSymbol mathSymbol = Helper.getMathStatementsSymbolFor(componentInstanceSymbol, symtab);
return generateString(taggingResolver, componentInstanceSymbol, mathSymbol);
}
......@@ -204,9 +206,13 @@ public class GeneratorCPP implements Generator {
}
if (MathConverter.curBackend.getBackendName().equals("OctaveBackend"))
fileContents.add(OctaveHelper.getOctaveHelperFileContent());
if (MathConverter.curBackend.getBackendName().equals("ArmadilloBackend"))
if (MathConverter.curBackend.getBackendName().equals("ArmadilloBackend")) {
fileContents.add(ArmadilloHelper.getArmadilloHelperFileContent(isGenerateTests));
if (BluePrintCPP.usedCV) {
fileContents.add(ConversionHelper.getConversionHelperFileContent(isGenerateTests));
BluePrintCPP.usedCV = false;
}
}
if (shouldGenerateMainClass()) {
//fileContents.add(getMainClassFileContent(componentInstanceSymbol, fileContents.get(0)));
} else if (shouldGenerateSimulatorInterface()) {
......
......@@ -3,9 +3,13 @@ package de.monticore.lang.monticar.generator.cpp;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.math._symboltable.MathStatementsSymbol;
import de.monticore.lang.math._symboltable.expression.MathAssignmentExpressionSymbol;
import de.monticore.lang.math._symboltable.expression.MathExpressionSymbol;
import de.monticore.lang.math._symboltable.matrix.MathMatrixNameExpressionSymbol;
import de.monticore.lang.monticar.generator.*;
import de.monticore.lang.monticar.generator.cpp.converter.ComponentConverter;
import de.monticore.lang.monticar.generator.cpp.converter.MathConverter;
import de.monticore.lang.monticar.generator.MathCommand;
import de.monticore.lang.monticar.generator.cpp.instruction.ConnectInstructionCPP;
import de.monticore.lang.monticar.generator.cpp.template.AllTemplates;
import de.monticore.lang.monticar.generator.cpp.viewmodel.LoggingViewModel;
......@@ -32,6 +36,15 @@ public class LanguageUnitCPP extends LanguageUnit {
this.generatorCPP = generatorCPP;
}
// add a function for seareching a string form list<String> in string
private boolean containsString(String str, List<String> listOfStrings){
boolean isContained = false;
for(String foo: listOfStrings){
if(str.toLowerCase().contains(foo.toLowerCase()))
isContained = true;
}
return isContained;
}
public void generateBluePrints() {
for (int i = 0; i < symbolsToConvert.size(); ++i) {
Symbol symbol = symbolsToConvert.get(i);
......@@ -73,16 +86,18 @@ public class LanguageUnitCPP extends LanguageUnit {
"#endif\n";
List<String> alreadyGeneratedIncludes = new ArrayList<>();
List<String> alreadyGeneratedCVIncludes = new ArrayList<>();
//includes
//add default include
String backendName = MathConverter.curBackend.getBackendName();
if (MathConverter.curBackend.getBackendName().equals("OctaveBackend")) {
if (backendName.equals("OctaveBackend")) {
resultString += "#include \"octave/oct.h\"\n";
alreadyGeneratedIncludes.add("octave/oct");
} else if (MathConverter.curBackend.getBackendName().equals("ArmadilloBackend")) {
} else if (backendName.equals("ArmadilloBackend")) {
resultString += "#include \"" + MathConverter.curBackend.getIncludeHeaderName() + "\"\n";
alreadyGeneratedIncludes.add(MathConverter.curBackend.getIncludeHeaderName());
}
for (Variable v : bluePrint.getVariables()) {
//TODO remove multiple same includes
if (v.hasInclude()) {
......@@ -108,6 +123,17 @@ public class LanguageUnitCPP extends LanguageUnit {
for (String string : bluePrint.getAdditionalIncludeStrings())
resultString += "#include \"" + string + ".h\"\n";
for(String includeName: bluePrint.getCVIncludeStrings())
if(!alreadyGeneratedCVIncludes.contains(includeName)) {
alreadyGeneratedCVIncludes.add(includeName);
if (includeName.contains("vector")) {
resultString += "#include <" + includeName + ">\n";
} else if (includeName.contains("ConvHelper")) {
resultString += "#include \"" + "ConvHelper" + ".h\"\n";
} else {
resultString += "#include <" + includeName + ".hpp>\n";
}
}
if (generatorCPP.isExecutionLoggingActive)
resultString += "#include <fstream>\n";
......@@ -124,8 +150,12 @@ public class LanguageUnitCPP extends LanguageUnit {
resultString += "using namespace arma;\n";
}
if(!bluePrint.cvIncludeStrings.isEmpty()){
resultString += "using namespace std;\n";
}
//class definition start
resultString += "class " + bluePrint.getName() ;
resultString += "class " + bluePrint.getName();
resultString += "{\n";
//const variables
......
......@@ -30,6 +30,11 @@ public class LinalgBackend implements MathBackend {
return null;
}
@Override
public String getTubeAccessCommandName(){
return null;
}
@Override
public String getColumnVectorTypeName() {
return null;
......
......@@ -53,6 +53,19 @@ public class MathCommandRegisterCPP extends MathCommandRegister {
registerMathCommand(new MathKMeansCommand());
registerMathCommand(new MathSqrtmCommand());
registerMathCommand(new MathSqrtmDiagCommand());
registerMathCommand(new MathCeilCommand());
//register CV commands
registerMathCommand(new ErodeCommand());
registerMathCommand(new DilateCommand());
registerMathCommand(new BoundingRectCommand());
registerMathCommand(new CvtColorCommand());
registerMathCommand(new FindContoursCommand());
registerMathCommand(new GaussianBlurCommand());
registerMathCommand(new InRangeCommand());
registerMathCommand(new LargestContourCommand());
registerMathCommand(new RectangleCommand());
//for fixing some errors
registerMathCommand(new MathRowCommand());
......
/* (c) https://github.com/MontiCore/monticore */
package de.monticore.lang.monticar.generator.cpp;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.ASTSubComponent;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.InstanceInformation;
import de.monticore.lang.monticar.generator.BluePrint;
import de.monticore.lang.monticar.generator.Instruction;
import de.monticore.lang.monticar.generator.Variable;
import de.monticore.lang.monticar.resolution._ast.ASTUnitNumberResolution;
import de.monticore.lang.monticar.si._symboltable.ResolutionDeclarationSymbol;
import de.se_rwth.commons.logging.Log;
import java.util.ArrayList;
import java.util.List;
/**
* @author Ahmed Diab
*/
public class MathExpressionProperties {
public Level pre = Level.ARMA;
public Level suc = Level.ARMA;
enum Level {
CV,
ARMA
}
public void setPreToCV(){
this.pre = Level.CV;
}
public void setSucToCV(){
this.suc = Level.CV;
}
public boolean isPreCV(){
return this.pre == Level.CV;
}
public boolean isSucCV(){
return this.suc == Level.CV;
}
}
......@@ -49,6 +49,10 @@ public class OctaveBackend implements MathBackend {
return "row";
}
@Override public String getTubeAccessCommandName(){
return "";
}
@Override
public String getBackendName() {
return NAME;
......