Commit 95f80e8f authored by Christoph Richter's avatar Christoph Richter
Browse files

PortConverter, TypeConverter: Added cube support also for ports (#37)

parent 896afb71
......@@ -4,6 +4,7 @@ import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.Connecto
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ConstantPortSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.PortSymbol;
import de.monticore.lang.math.math._ast.ASTAssignmentType;
import de.monticore.lang.monticar.common2._ast.ASTCommonMatrixType;
import de.monticore.lang.monticar.generator.Variable;
import de.monticore.lang.monticar.generator.cpp.BluePrintCPP;
import de.monticore.lang.monticar.ts.MCTypeSymbol;
......@@ -12,6 +13,8 @@ import de.monticore.lang.monticar.ts.references.MCTypeReference;
import de.monticore.lang.monticar.types2._ast.ASTType;
import de.se_rwth.commons.logging.Log;
import java.util.Optional;
/**
* @author Sascha Schneiders
*/
......@@ -61,7 +64,7 @@ public class PortConverter {
variable.setVariableType(TypeConverter.getVariableTypeForMontiCarTypeName(typeNameMontiCar, variable, portSymbol).get());
variable.addAdditionalInformation(Variable.ORIGINPORT);
bluePrint.getMathInformationRegister().addVariable(variable);
Log.debug("EMAVAR: " + variable.getName() + " targetType:" + variable.getVariableType().getTypeNameTargetLanguage()+" isArray:"+variable.isArray(), "PortConverter");
Log.debug("EMAVAR: " + variable.getName() + " targetType:" + variable.getVariableType().getTypeNameTargetLanguage() + " isArray:" + variable.isArray(), "PortConverter");
return variable;
}
......@@ -104,6 +107,28 @@ public class PortConverter {
}
}
private static Optional<ASTType> getAstTypeFromPortSymbol(PortSymbol portSymbol) {
Optional<ASTType> result = Optional.empty();
MCTypeReference<? extends MCTypeSymbol> typeRef = portSymbol.getTypeReference();
if (typeRef.existsReferencedSymbol() && typeRef.getReferencedSymbol() instanceof MCASTTypeSymbolReference) {
MCASTTypeSymbolReference typeSymbolReference = (MCASTTypeSymbolReference) portSymbol.getTypeReference().getReferencedSymbol();
ASTType astType = typeSymbolReference.getAstType();
result = Optional.of(astType);
}
return result;
}
public static Optional<ASTCommonMatrixType> getCommonMatrixTypeFromPortSymbol(PortSymbol portSymbol) {
Optional<ASTCommonMatrixType> result = Optional.empty();
Optional<ASTType> astType = getAstTypeFromPortSymbol(portSymbol);
if (astType.isPresent()) {
if (astType.get() instanceof ASTCommonMatrixType) {
result = Optional.of((ASTCommonMatrixType) astType.get());
}
}
return result;
}
public static String getPortNameWithoutArrayBracketPart(String name) {
String nameWithOutArrayBracketPart = name;
if (nameWithOutArrayBracketPart.endsWith("]")) {
......
......@@ -174,7 +174,7 @@ public class TypeConverter {
if (variableType.getTypeNameMontiCar().equals(typeNameMontiCar)) {
if (typeNameMontiCar.equals("CommonMatrixType")) {
if (MathConverter.curBackend.getBackendName().equals("ArmadilloBackend")) {
variableType = new VariableType("CommonMatrixType", MathConverter.curBackend.getMatrixTypeName(), MathConverter.curBackend.getIncludeHeaderName());
variableType = getRealVariableTypeFromPortSymbol(portSymbol);
}
handleCommonMatrixType(variable, portSymbol);
} else if (typeNameMontiCar.equals("AssignmentType")) {
......@@ -189,6 +189,17 @@ public class TypeConverter {
return Optional.empty();
}
private static VariableType getRealVariableTypeFromPortSymbol(PortSymbol portSymbol) {
VariableType variableType;
Optional<ASTCommonMatrixType> astCommonMatrixType = PortConverter.getCommonMatrixTypeFromPortSymbol(portSymbol);
if (astCommonMatrixType.isPresent()) {
variableType = getRealVariableType(astCommonMatrixType.get());
} else {
variableType = new VariableType("CommonMatrixType", MathConverter.curBackend.getMatrixTypeName(), MathConverter.curBackend.getIncludeHeaderName());
}
return variableType;
}
public static void handleCommonMatrixType(Variable variable, PortSymbol portSymbol) {
ASTCommonMatrixType astCommonMatrixType = (ASTCommonMatrixType) ((ASTPort) portSymbol.getAstNode().get()).getType();
handleCommonMatrixType(variable, astCommonMatrixType);
......
......@@ -105,6 +105,19 @@ public class BasicGenerationTest extends AbstractSymtabTest {
GeneratorCPP generatorCPP = new GeneratorCPP();
generatorCPP.useArmadilloBackend();
generatorCPP.setGenerationTargetPath("./target/generated-sources-cpp/armadillo/testing");
generatorCPP.generateFiles(componentSymbol,symtab);
generatorCPP.generateFiles(componentSymbol, symtab);
}
@Test
public void testPortTypeCube() throws IOException {
TaggingResolver symtab = createSymTabAndTaggingResolver("src/test/resources");
ExpandedComponentInstanceSymbol componentSymbol = symtab.<ExpandedComponentInstanceSymbol>resolve("testing.portTypeCubeTest", ExpandedComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentSymbol);
GeneratorCPP generatorCPP = new GeneratorCPP();
generatorCPP.useArmadilloBackend();
generatorCPP.setGenerationTargetPath("./target/generated-sources-cpp/armadillo/testing");
List<File> files = generatorCPP.generateFiles(componentSymbol, symtab);
String restPath = "armadillo/testing/";
testFilesAreEqual(files, restPath);
}
}
#ifndef TESTING_PORTTYPECUBETEST
#define TESTING_PORTTYPECUBETEST
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "armadillo.h"
using namespace arma;
class testing_portTypeCubeTest{
public:
cube cubeIn;
cube cubeOut;
void init()
{
cubeIn = cube(3, 224, 224);
cubeOut = cube(3, 224, 224);
}
void execute()
{
cubeOut = cubeIn;
}
};
#endif
package testing;
component PortTypeCubeTest {
ports in Q^{3, 224, 224} cubeIn,
out Q^{3, 224, 224} cubeOut;
implementation Math{
cubeOut = cubeIn;
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment