Commit 5f1ad44a authored by Yuyuan Liu's avatar Yuyuan Liu
Browse files

new parameter

parent b50aa9ef
Pipeline #98496 passed with stages
in 6 minutes and 2 seconds
{
"configurations": [
{
"type": "java",
"name": "CodeLens (Launch) - EMADLGeneratorCli",
"request": "launch",
"mainClass": "de.monticore.lang.monticar.emadl.generator.EMADLGeneratorCli",
"projectName": "embedded-montiarc-emadl-generator"
}
]
}
\ No newline at end of file
......@@ -103,7 +103,7 @@ public class EMADLGenerator {
return emamGen;
}
public void generate(String modelPath, String qualifiedName) throws IOException, TemplateException {
public void generate(String modelPath, String qualifiedName, String forced) throws IOException, TemplateException {
setModelsPath( modelPath );
TaggingResolver symtab = EMADLAbstractSymtab.createSymTabAndTaggingResolver(getModelsPath());
ComponentSymbol component = symtab.<ComponentSymbol>resolve(qualifiedName, ComponentSymbol.KIND).orElse(null);
......@@ -118,12 +118,14 @@ public class EMADLGenerator {
}
ExpandedComponentInstanceSymbol instance = component.getEnclosingScope().<ExpandedComponentInstanceSymbol>resolve(instanceName, ExpandedComponentInstanceSymbol.KIND).get();
generateFiles(symtab, instance, symtab);
generateFiles(symtab, instance, symtab, forced);
}
public void generateFiles(TaggingResolver taggingResolver, ExpandedComponentInstanceSymbol componentSymbol, Scope symtab) throws IOException {
List<FileContent> fileContents = generateStrings(taggingResolver, componentSymbol, symtab);
public void generateFiles(TaggingResolver taggingResolver, ExpandedComponentInstanceSymbol componentSymbol, Scope symtab, String forced) throws IOException {
List<FileContent> fileContents = generateStrings(taggingResolver, componentSymbol, symtab, forced);
for (FileContent fileContent : fileContents) {
emamGen.generateFile(fileContent);
......@@ -181,7 +183,7 @@ public class EMADLGenerator {
}
}
public List<FileContent> generateStrings(TaggingResolver taggingResolver, ExpandedComponentInstanceSymbol componentInstanceSymbol, Scope symtab){
public List<FileContent> generateStrings(TaggingResolver taggingResolver, ExpandedComponentInstanceSymbol componentInstanceSymbol, Scope symtab, String forced){
List<FileContent> fileContents = new ArrayList<>();
Set<ExpandedComponentInstanceSymbol> allInstances = new HashSet<>();
......@@ -231,7 +233,7 @@ public class EMADLGenerator {
System.out.println(trainingHash);
boolean alreadyTrained = isAlreadyTrained(trainingHash, componentInstance);
if(alreadyTrained) {
if(alreadyTrained || forced == "n") {
System.out.println("Already trained");
}
else {
......
......@@ -20,7 +20,6 @@
*/
package de.monticore.lang.monticar.emadl.generator;
import de.se_rwth.commons.logging.Log;
import freemarker.template.TemplateException;
import org.apache.commons.cli.*;
......@@ -56,6 +55,16 @@ public class EMADLGeneratorCli {
.hasArg(true)
.required(false)
.build();
/**/
public static final Option OPTION_RESTRAINED_TRAINING = Option.builder("f")
.longOpt("forced")
.desc("no training or a forced training. Options: y (a forced training), n (no training)")
.hasArg(true)
.required(false)
.build();
private EMADLGeneratorCli() {
}
......@@ -75,6 +84,7 @@ public class EMADLGeneratorCli {
options.addOption(OPTION_ROOT_MODEL);
options.addOption(OPTION_OUTPUT_PATH);
options.addOption(OPTION_BACKEND);
options.addOption(OPTION_RESTRAINED_TRAINING);
return options;
}
......@@ -94,7 +104,9 @@ public class EMADLGeneratorCli {
String rootModelName = cliArgs.getOptionValue(OPTION_ROOT_MODEL.getOpt());
String outputPath = cliArgs.getOptionValue(OPTION_OUTPUT_PATH.getOpt());
String backendString = cliArgs.getOptionValue(OPTION_BACKEND.getOpt());
String forced = cliArgs.getOptionValue(OPTION_RESTRAINED_TRAINING.getOpt());
final String DEFAULT_BACKEND = "MXNET";
final String DEFAULT_FORCED = "UNSET";
if (backendString == null) {
Log.warn("backend not specified. backend set to default value " + DEFAULT_BACKEND);
......@@ -106,13 +118,27 @@ public class EMADLGeneratorCli {
Log.warn("specified backend " + backendString + " not supported. backend set to default value " + DEFAULT_BACKEND);
backend = Backend.getBackendFromString(DEFAULT_BACKEND);
}
if (forced == null) {
Log.warn("forced not specified. forced set to default value" + DEFAULT_FORCED);
forced = DEFAULT_FORCED;
}else if (forced == "y") {
Log.warn("training with enforcement");
/**/
}else if (forced == "n") {
Log.warn("no training with enforcement");
}else{
Log.error("no such parameter" + forced);
System.exit(1);
}
EMADLGenerator generator = new EMADLGenerator(backend.get());
if (outputPath != null){
generator.setGenerationTargetPath(outputPath);
}
try{
generator.generate(cliArgs.getOptionValue(OPTION_MODELS_PATH.getOpt()), rootModelName);
generator.generate(cliArgs.getOptionValue(OPTION_MODELS_PATH.getOpt()), rootModelName, forced);
}
catch (IOException e){
Log.error("io error during generation", e);
......@@ -122,5 +148,6 @@ public class EMADLGeneratorCli {
Log.error("template error during generation", e);
System.exit(1);
}
}
}
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