Commit aac37a40 authored by Malte Heithoff's avatar Malte Heithoff

CNNArchGenerator now implements the Generator interface

parent 16a10f1e
Pipeline #335891 canceled with stage
in 29 seconds
......@@ -4,21 +4,25 @@ package de.monticore.lang.monticar.cnnarch.generator;
import de.monticore.io.paths.ModelPath;
import de.monticore.lang.monticar.cnnarch._symboltable.ArchitectureSymbol;
import de.monticore.lang.monticar.cnnarch._symboltable.CNNArchLanguage;
import de.monticore.lang.monticar.generator.cmake.CMakeConfig;
import de.monticore.lang.monticar.generator.cmake.CMakeFindModule;
import de.monticore.lang.monticar.generator.Generator;
import de.monticore.lang.monticar.generator.FileContent;
import de.monticore.lang.monticar.generator.cpp.GeneratorCPP;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.monticore.symboltable.GlobalScope;
import de.monticore.symboltable.Scope;
import de.se_rwth.commons.logging.Log;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
public abstract class CNNArchGenerator {
public abstract class CNNArchGenerator implements Generator<ArchitectureSymbol> {
private boolean generateCMake = false;
protected ArchitectureSupportChecker architectureSupportChecker;
protected LayerSupportChecker layerSupportChecker;
......@@ -35,8 +39,14 @@ public abstract class CNNArchGenerator {
System.exit(1);
}
public boolean isCMakeRequired() {
return true;
@Override
public boolean isGenerateCMake() {
return generateCMake;
}
@Override
public void setGenerateCMake(boolean generateCMake) {
this.generateCMake = generateCMake;
}
public String getGenerationTargetPath(){
......@@ -58,7 +68,8 @@ public abstract class CNNArchGenerator {
this.modelsDirPath = modelsDirPath.toString();
final ModelPath mp = new ModelPath(modelsDirPath);
GlobalScope scope = new GlobalScope(mp, new CNNArchLanguage());
generate(scope, rootModelName);
TaggingResolver tagging = new TaggingResolver(scope, Arrays.asList(rootModelName));
generate(tagging, rootModelName);
}
// TODO: Rewrite so that CNNArchSymbolCompiler is used in EMADL2CPP instead of this method
......@@ -66,9 +77,9 @@ public abstract class CNNArchGenerator {
return architectureSupportChecker.check(architecture) && layerSupportChecker.check(architecture);
}
public void generate(Scope scope, String rootModelName){
public void generate(TaggingResolver taggingResolver, String rootModelName){
CNNArchSymbolCompiler symbolCompiler = new CNNArchSymbolCompiler(architectureSupportChecker, layerSupportChecker);
ArchitectureSymbol architectureSymbol = symbolCompiler.compileArchitectureSymbol(scope, rootModelName);
ArchitectureSymbol architectureSymbol = symbolCompiler.compileArchitectureSymbol(taggingResolver, rootModelName);
try{
String dataConfPath = getModelsDirPath() + "/data_paths.txt";
......@@ -86,37 +97,41 @@ public abstract class CNNArchGenerator {
}
architectureSymbol.setWeightsPath(weightsPath);
architectureSymbol.setComponentName(rootModelName);
generateFiles(architectureSymbol);
generateFiles(taggingResolver, architectureSymbol);
} catch (IOException e){
Log.error(e.toString());
}
}
//check cocos with CNNArchCocos.checkAll(architecture) before calling this method.
public abstract Map<String, String> generateStrings(ArchitectureSymbol architecture);
public abstract List<FileContent> generateStrings(TaggingResolver taggingResolver, ArchitectureSymbol architecture);
//check cocos with CNNArchCocos.checkAll(architecture) before calling this method.
public void generateFiles(ArchitectureSymbol architecture) throws IOException{
Map<String, String> fileContentMap = generateStrings(architecture);
generateFromFilecontentsMap(fileContentMap);
public List<File> generateFiles(TaggingResolver taggingResolver, ArchitectureSymbol architecture) throws IOException{
List<FileContent> fileContents = generateStrings(taggingResolver, architecture);
return generateFromFilecontentsMap(fileContents);
}
public void generateFromFilecontentsMap(Map<String, String> fileContentMap) throws IOException {
public List<File> generateFromFilecontentsMap(List<FileContent> fileContents) throws IOException {
List<File> res = new LinkedList<>();
GeneratorCPP genCPP = new GeneratorCPP();
genCPP.setGenerationTargetPath(getGenerationTargetPath());
for (String fileName : fileContentMap.keySet()){
genCPP.generateFile(new FileContent(fileContentMap.get(fileName), fileName));
for (FileContent fileContent : fileContents) {
res.add(genCPP.generateFile(fileContent));
}
return res;
}
public void generateCMake(String rootModelName){
Map<String, String> fileContentMap = generateCMakeContent(rootModelName);
List<FileContent> fileContents = generateCMakeContent(rootModelName);
try {
generateFromFilecontentsMap(fileContentMap);
generateFromFilecontentsMap(fileContents);
} catch (IOException e) {
Log.error("CMake file could not be generated" + e.getMessage());
}
}
public abstract Map<String, String> generateCMakeContent(String rootModelName);
public abstract List<FileContent> generateCMakeContent(String rootModelName);
}
Markdown is supported
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