Commit 99b87d1f authored by Sebastian Nickels's avatar Sebastian Nickels
Browse files

Merge branch 'rnn' of git.rwth-aachen.de:monticore/EmbeddedMontiArc/languages/CNNArchLang into rnn

parents 0f57917d 7712a02f
Pipeline #175533 passed with stages
in 18 minutes and 43 seconds
target
nppBackup
.project
.settings
.classpath
.idea
.git
*.iml
#
#
# ******************************************************************************
# MontiCAR Modeling Family, www.se-rwth.de
# Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
# All rights reserved.
#
# This project is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this project. If not, see <http://www.gnu.org/licenses/>.
# *******************************************************************************
#
stages:
- windows
- linux
masterJobLinux:
stage: linux
image: maven:3-jdk-8
script:
- mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B clean deploy --settings settings.xml
- mvn package sonar:sonar -s settings.xml
only:
- master
masterJobWindows:
stage: windows
script:
- mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B clean install --settings settings.xml
tags:
- Windows10
BranchJobLinux:
stage: linux
image: maven:3-jdk-8
script:
- mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B clean install --settings settings.xml
except:
- master
#
#
# ******************************************************************************
# MontiCAR Modeling Family, www.se-rwth.de
# Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
# All rights reserved.
#
# This project is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this project. If not, see <http://www.gnu.org/licenses/>.
# *******************************************************************************
#
script:
- git checkout ${TRAVIS_BRANCH}
- mvn clean install cobertura:cobertura org.eluder.coveralls:coveralls-maven-plugin:report --settings "settings.xml"
after_success:
- if [ "${TRAVIS_BRANCH}" == "master" ]; then mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B deploy --debug --settings "./settings.xml"; fi
......@@ -62,7 +62,7 @@ grammar CNNArch extends de.monticore.CommonExpressions, de.monticore.lang.Math,
Stream = elements:(ArchitectureElement || "->")+;
Unroll = "timed" "<" timeParameter:ArchitectureParameter ">"
Unroll = "timed" "<" timeParameter:LayerParameter ">"
Name "(" arguments:(ArchArgument || ",")* ")"
"{" body:Stream "}";
......
......@@ -36,6 +36,9 @@ public class CNNArchSymbolCoCo {
else if (sym instanceof UnrollDeclarationSymbol){
check((UnrollDeclarationSymbol) sym);
}
else if (sym instanceof UnrollSymbol){
check((UnrollSymbol) sym);
}
else if (sym instanceof ArchitectureElementSymbol){
check((ArchitectureElementSymbol) sym);
}
......@@ -110,4 +113,8 @@ public class CNNArchSymbolCoCo {
public void check(MathExpressionSymbol sym){
//Override if needed
}
public void check(UnrollSymbol sym){
//Override if needed
}
}
......@@ -30,9 +30,7 @@ public class CheckArchitectureFinished extends CNNArchSymbolCoCo {
@Override
public void check(ArchitectureSymbol architecture) {
System.err.println("Architecture in checkArchFinished: " + architecture.toString());
for (CompositeElementSymbol stream : architecture.getStreams()) {
System.err.println("Stream in checkArchFinished");
if (!stream.getOutputTypes().isEmpty()){
Log.error("0" + ErrorCodes.UNFINISHED_ARCHITECTURE + " The architecture is not finished. " +
"There are still open streams at the end of the architecture. "
......@@ -40,8 +38,7 @@ public class CheckArchitectureFinished extends CNNArchSymbolCoCo {
}
}
for (UnrollSymbol unroll : architecture.getUnrolls()) {
System.err.println("UnrollSymbol in checkArchFinished");
if (!unroll.getOutputTypes().isEmpty()){
if (!unroll.getBody().getOutputTypes().isEmpty()){
Log.error("0" + ErrorCodes.UNFINISHED_ARCHITECTURE + " The architecture is not finished. " +
"There are still open streams at the end of the architecture. "
, architecture.getSourcePosition());
......
......@@ -33,9 +33,7 @@ public class CheckElementInputs extends CNNArchSymbolCoCo {
}
for (UnrollSymbol unroll : architecture.getUnrolls()) {
System.err.println("BEFORE check");
unroll.checkInput();
System.err.println("AFTER check");
unroll.getBody().checkInput();
}
}
}
......@@ -52,63 +52,29 @@ public class CheckLayer implements CNNArchASTLayerCoCo{
nameSet.add(name);
}
}
if(node.getSymbolOpt().get() instanceof LayerSymbol) {
LayerDeclarationSymbol layerDeclaration = ((LayerSymbol) node.getSymbolOpt().get()).getDeclaration();
if (layerDeclaration == null){
ArchitectureSymbol architecture = node.getSymbolOpt().get().getEnclosingScope().<ArchitectureSymbol>resolve("", ArchitectureSymbol.KIND).get();
Log.error("0" + ErrorCodes.UNKNOWN_LAYER + " Unknown layer. " +
"Layer with name '" + node.getName() + "' does not exist. " +
"Existing layers: " + Joiners.COMMA.join(architecture.getLayerDeclarations()) + "."
, node.get_SourcePositionStart());
}
else {
Set<String> requiredArguments = new HashSet<>();
for (ParameterSymbol param : layerDeclaration.getParameters()){
if (!param.getDefaultExpression().isPresent()){
requiredArguments.add(param.getName());
}
}
for (ASTArchArgument argument : node.getArgumentsList()){
requiredArguments.remove(argument.getName());
}
for (String missingArgumentName : requiredArguments){
Log.error("0"+ErrorCodes.MISSING_ARGUMENT + " Missing argument. " +
"The argument '" + missingArgumentName + "' is required."
, node.get_SourcePositionStart());
LayerDeclarationSymbol layerDeclaration = ((LayerSymbol) node.getSymbolOpt().get()).getDeclaration();
if (layerDeclaration == null){
ArchitectureSymbol architecture = node.getSymbolOpt().get().getEnclosingScope().<ArchitectureSymbol>resolve("", ArchitectureSymbol.KIND).get();
Log.error("0" + ErrorCodes.UNKNOWN_LAYER + " Unknown layer. " +
"Layer with name '" + node.getName() + "' does not exist. " +
"Existing layers: " + Joiners.COMMA.join(architecture.getLayerDeclarations()) + "."
, node.get_SourcePositionStart());
}
else {
Set<String> requiredArguments = new HashSet<>();
for (ParameterSymbol param : layerDeclaration.getParameters()){
if (!param.getDefaultExpression().isPresent()){
requiredArguments.add(param.getName());
}
}
}else{
UnrollDeclarationSymbol unrollDeclaration = ((UnrollSymbol) node.getSymbolOpt().get()).getDeclaration();
if (unrollDeclaration == null){
ArchitectureSymbol architecture = node.getSymbolOpt().get().getEnclosingScope().<ArchitectureSymbol>resolve("", ArchitectureSymbol.KIND).get();
Log.error("0" + ErrorCodes.UNKNOWN_LAYER + " Unknown layer. " +
"Layer with name '" + node.getName() + "' does not exist. " +
"Existing layers: " + Joiners.COMMA.join(architecture.getLayerDeclarations()) + "."
, node.get_SourcePositionStart());
for (ASTArchArgument argument : node.getArgumentsList()){
requiredArguments.remove(argument.getName());
}
else {
Set<String> requiredArguments = new HashSet<>();
for (ParameterSymbol param : unrollDeclaration.getParameters()){
if (!param.getDefaultExpression().isPresent()){
requiredArguments.add(param.getName());
}
}
for (ASTArchArgument argument : node.getArgumentsList()){
requiredArguments.remove(argument.getName());
}
for (String missingArgumentName : requiredArguments){
Log.error("0"+ErrorCodes.MISSING_ARGUMENT + " Missing argument. " +
"The argument '" + missingArgumentName + "' is required."
, node.get_SourcePositionStart());
}
for(LayerSymbol sublayer: unrollDeclaration.getLayers()){
check((ASTLayer) sublayer.getAstNode().get());
}
for (String missingArgumentName : requiredArguments){
Log.error("0"+ErrorCodes.MISSING_ARGUMENT + " Missing argument. " +
"The argument '" + missingArgumentName + "' is required."
, node.get_SourcePositionStart());
}
}
}
......
......@@ -117,7 +117,6 @@ public class ArchTypeSymbol extends CommonSymbol {
public void setDimensionSymbols(List<ArchSimpleExpressionSymbol> dimensions) {
this.dimensions = dimensions;
System.err.println("Setting dimensions: " + dimensions.toString());
}
public List<ArchSimpleExpressionSymbol> getDimensionSymbols() {
......
......@@ -103,7 +103,10 @@ public abstract class ArchitectureElementSymbol extends CommonScopeSpanningSymbo
if (sym instanceof ArchitectureSymbol){
return (ArchitectureSymbol) sym;
}
else {
else if (sym instanceof UnrollSymbol) {
sym = sym.getEnclosingScope().getSpanningSymbol().get();
return (ArchitectureSymbol)sym;
}else {
return ((ArchitectureElementSymbol) sym).getArchitecture();
}
}
......
......@@ -91,7 +91,6 @@ public class ArchitectureSymbol extends CommonScopeSpanningSymbol {
public List<VariableSymbol> getInputs() {
System.err.println("THE inputs: " + inputs);
return inputs;
}
......@@ -124,14 +123,14 @@ public class ArchitectureSymbol extends CommonScopeSpanningSymbol {
}
for (UnrollSymbol unroll : unrolls) {
unroll.checkIfResolvable();
try {
unroll.resolveOrError();
unroll.getBody().resolveOrError();
}
catch (ArchResolveException e) {
// Do nothing; error is already logged
if(unroll.isResolvable());
{
try {
unroll.resolve();
}
catch (ArchResolveException e) {
// Do nothing; error is already logged
}
}
}
}
......@@ -143,9 +142,6 @@ public class ArchitectureSymbol extends CommonScopeSpanningSymbol {
resolved &= stream.isResolved();
}
for (UnrollSymbol unroll: unrolls) {
resolved &= unroll.isResolved();
}
return resolved;
}
......
......@@ -104,6 +104,7 @@ public class ArgumentSymbol extends CommonSymbol {
public void set(){
if (getRhs().isResolved() && getRhs().isSimpleValue()){
getParameter().setExpression((ArchSimpleExpressionSymbol) getRhs());
getUnrollParameter().setExpression((ArchSimpleExpressionSymbol) getRhs());
}
else {
throw new IllegalStateException("The value of the parameter is set to a sequence or the expression is not resolved. This should never happen.");
......
......@@ -31,6 +31,7 @@ import de.monticore.lang.monticar.cnnarch.predefined.AllPredefinedVariables;
import de.monticore.symboltable.*;
import de.se_rwth.commons.logging.Log;
import java.lang.reflect.Array;
import java.util.*;
public class CNNArchSymbolTableCreator extends de.monticore.symboltable.CommonSymbolTableCreator
......@@ -345,35 +346,16 @@ public class CNNArchSymbolTableCreator extends de.monticore.symboltable.CommonSy
@Override
public void endVisit(ASTUnroll ast) {
UnrollSymbol layer = (UnrollSymbol) ast.getSymbolOpt().get();
SerialCompositeElementSymbol sces = new SerialCompositeElementSymbol();
List<ArchitectureElementSymbol> elements = new ArrayList<>();
for (ASTArchitectureElement astElement : ast.getBody().getElementsList()){
elements.add((ArchitectureElementSymbol) astElement.getSymbolOpt().get());
}
sces.setElements(elements);
layer.setBody(sces);
//layer.getDeclaration().setBody(sces);
//layer.setElements(elements);
layer.setBody((SerialCompositeElementSymbol) ast.getBody().getSymbolOpt().get());
List<ArgumentSymbol> arguments = new ArrayList<>(6);
//ast.getArgumentsList().add(ast.getTimeParameter());
for (ASTArchArgument astArgument : ast.getArgumentsList()){
Optional<ArgumentSymbol> optArgument = astArgument.getSymbolOpt().map(e -> (ArgumentSymbol)e);
optArgument.ifPresent(arguments::add);
}
layer.setArguments(arguments);
/*List<ArchitectureElementSymbol> elements = new ArrayList<>();
for (ASTStream astStream : ast.getGroupsList()){
elements.add((SerialCompositeElementSymbol) astStream.getSymbolOpt().get());
}
compositeElement.setElements(elements);
*/
removeCurrentScope();
}
......
......@@ -64,9 +64,6 @@ public abstract class CompositeElementSymbol extends ArchitectureElementSymbol {
}
}
}
else if (element instanceof UnrollSymbol) {
isTrainable |= ((UnrollSymbol) element).isTrainable();
}
}
return isTrainable;
......
......@@ -112,25 +112,10 @@ public class UnrollDeclarationSymbol extends CommonScopeSpanningSymbol {
}
public ArchitectureElementSymbol call(UnrollSymbol layer) throws ArchResolveException{
public UnrollSymbol call(UnrollSymbol layer) throws ArchResolveException{
checkForSequence(layer.getArguments());
return layer;
if (isPredefined()){
return layer;
}
else {
reset();
set(layer.getArguments());
SerialCompositeElementSymbol copy = getBody().preResolveDeepCopy();
copy.putInScope(getSpannedScope());
copy.resolveOrError();
getSpannedScope().remove(copy);
getSpannedScope().removeSubScope(copy.getSpannedScope());
reset();
return copy;
}
}
private void reset(){
......
/**
*
* ******************************************************************************
* MontiCAR Modeling Family, www.se-rwth.de
* Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
* All rights reserved.
*
* This project is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
* *******************************************************************************
*/
package de.monticore.lang.monticar.cnnarch._symboltable;
import de.monticore.symboltable.SymbolKind;
public class UnrollKind implements SymbolKind {
private static final String NAME = "de.monticore.lang.monticar.cnnarch._symboltable.UnrollKind";
@Override
public String getName() {
return NAME;
}
@Override
public boolean isKindOf(SymbolKind kind) {
return NAME.equals(kind.getName()) || SymbolKind.super.isKindOf(kind);
}
}
......@@ -21,47 +21,27 @@
package de.monticore.lang.monticar.cnnarch._symboltable;
import de.monticore.lang.monticar.cnnarch._ast.ASTArchitectureParameter;
import de.monticore.lang.monticar.cnnarch.helper.ErrorCodes;
import de.monticore.lang.monticar.cnnarch.predefined.AllPredefinedLayers;
import de.monticore.lang.monticar.cnnarch.predefined.AllPredefinedVariables;
import de.monticore.symboltable.CommonScopeSpanningSymbol;
import de.monticore.symboltable.Scope;
import de.monticore.symboltable.Symbol;
import de.monticore.symboltable.SymbolKind;
import de.se_rwth.commons.logging.Log;
import java.util.*;
import java.util.function.Function;
public class UnrollSymbol extends ArchitectureElementSymbol {
protected List<ArchitectureElementSymbol> elements = new ArrayList<>();
protected void setElements(List<ArchitectureElementSymbol> elements) {
ArchitectureElementSymbol previous = null;
for (ArchitectureElementSymbol current : elements){
if (previous != null){
current.setInputElement(previous);
previous.setOutputElement(current);
}
else {
if (getInputElement().isPresent()){
current.setInputElement(getInputElement().get());
}
if (getOutputElement().isPresent()){
current.setOutputElement(getOutputElement().get());
}
}
previous = current;
}
this.elements = elements;
}
public List<ArchitectureElementSymbol> getElements() {
return elements;
}
public class UnrollSymbol extends CommonScopeSpanningSymbol {
public static final UnrollKind KIND = new UnrollKind();
private UnrollDeclarationSymbol declaration = null;
private List<ArgumentSymbol> arguments;
private ParameterSymbol timeParameter;
private UnrollSymbol resolvedThis = null;
private SerialCompositeElementSymbol body;
public SerialCompositeElementSymbol getBody() {
......@@ -77,7 +57,7 @@ public class UnrollSymbol extends ArchitectureElementSymbol {
}
protected UnrollSymbol(String name) {
super(name);
super(name, KIND);
}
public UnrollDeclarationSymbol getDeclaration() {
......@@ -90,9 +70,9 @@ public class UnrollSymbol extends ArchitectureElementSymbol {
return declaration;
}
@Override
public boolean isResolvable() {
return super.isResolvable() && getDeclaration() != null;
return getBody().isResolvable() && getDeclaration() != null;
}
private void setDeclaration(UnrollDeclarationSymbol declaration) {
......@@ -107,6 +87,14 @@ public class UnrollSymbol extends ArchitectureElementSymbol {
this.arguments = arguments;
}
public ParameterSymbol getTimeParameter(){
return timeParameter;
}
protected void setTimeParameter(ParameterSymbol timeParameter){
this.timeParameter = timeParameter;
}
public ArchExpressionSymbol getIfExpression(){
Optional<ArgumentSymbol> argument = getArgument(AllPredefinedVariables.CONDITIONAL_ARG_NAME);
if (argument.isPresent()){
......@@ -117,23 +105,6 @@ public class UnrollSymbol extends ArchitectureElementSymbol {
}
}
@Override
public void setInputElement(ArchitectureElementSymbol inputElement) {
super.setInputElement(inputElement);
if (getResolvedThis().isPresent() && getResolvedThis().get() != this){
getResolvedThis().get().setInputElement(inputElement);
}
}
@Override
public void setOutputElement(ArchitectureElementSymbol outputElement) {
super.setOutputElement(outputElement);
if (getResolvedThis().isPresent() && getResolvedThis().get() != this){
getResolvedThis().get().setOutputElement(outputElement);
}
}
@Override
protected void putInScope(Scope scope){
Collection<Symbol> symbolsInScope = scope.getLocalSymbols().get(getName());
if (symbolsInScope == null || !symbolsInScope.contains(this)){
......@@ -142,56 +113,34 @@ public class UnrollSymbol extends ArchitectureElementSymbol {
getResolvedThis().get().putInScope(getSpannedScope());
}*/
for (ArgumentSymbol argument : getArguments()){
argument.putInScope(getSpannedScope());
argument.putInScope(getSpannedScope().getAsMutableScope());
}
}
}
@Override
public boolean isAtomic(){
return getResolvedThis().isPresent() && getResolvedThis().get() == this;
protected void setResolvedThis(UnrollSymbol resolvedThis) {
if (resolvedThis != null){
//resolvedThis.putInScope(getSpannedScope());
}
this.resolvedThis = resolvedThis;
}
@Override
public List<ArchitectureElementSymbol> getFirstAtomicElements() {
return this.getBody().getElements().get(0).getFirstAtomicElements();
}
@Override