Commit e4cf7189 authored by Malte Heithoff's avatar Malte Heithoff
Browse files

Add EMAM2CPP Options

parent b162fa14
/* (c) https://github.com/MontiCore/monticore */
package de.monticore.lang.monticar.emadl.generator;
import de.monticore.lang.monticar.generator.cpp.GeneratorCppCli;
import de.se_rwth.commons.logging.Log;
import freemarker.template.TemplateException;
import org.apache.commons.cli.*;
import org.apache.commons.lang3.SystemUtils;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;
import static de.monticore.lang.monticar.generator.cpp.GeneratorCppCli.*;
public class EMADLGeneratorCli {
public static final Option OPTION_MODELS_PATH = Option.builder("m")
......@@ -41,7 +47,7 @@ public class EMADLGeneratorCli {
public static final Option OPTION_TRAINING_PYTHON_PATH = Option.builder("p")
.longOpt("python")
.desc("path to python. Default is /usr/bin/python")
.desc("path to python. Default is /usr/bin/python, or python (PATH) for windows")
.hasArg(true)
.required(false)
.build();
......@@ -73,16 +79,21 @@ public class EMADLGeneratorCli {
}
}
private static Options getOptions() {
Options options = new Options();
options.addOption(OPTION_MODELS_PATH);
options.addOption(OPTION_ROOT_MODEL);
options.addOption(OPTION_OUTPUT_PATH);
public static Options getOptions() {
Options options = GeneratorCppCli.getOptions();
addEMADL2CPPOptions(options);
return options;
}
// Add EMADL Options
public static void addEMADL2CPPOptions(Options options) {
// options.addOption(OPTION_MODELS_PATH);
// options.addOption(OPTION_ROOT_MODEL);
// options.addOption(OPTION_OUTPUT_PATH);
options.addOption(OPTION_BACKEND);
options.addOption(OPTION_RESTRAINED_TRAINING);
options.addOption(OPTION_TRAINING_PYTHON_PATH);
options.addOption(OPTION_COMPILE);
return options;
}
private static CommandLine parseArgs(Options options, CommandLineParser parser, String[] args) {
......@@ -120,14 +131,14 @@ public class EMADLGeneratorCli {
}
if (pythonPath == null) {
pythonPath = "/usr/bin/python";
pythonPath = SystemUtils.IS_OS_WINDOWS ? "python" : "/usr/bin/python";
}
if (forced == null) {
forced = DEFAULT_FORCED;
}
else if (!forced.equals("y") && !forced.equals("n")) {
Log.error("specified setting ("+forced+") for forcing/preventing training not supported. set to default value " + DEFAULT_FORCED);
Log.warn("specified setting ("+forced+") for forcing/preventing training not supported. set to default value " + DEFAULT_FORCED);
forced = DEFAULT_FORCED;
}
......@@ -144,6 +155,31 @@ public class EMADLGeneratorCli {
if (outputPath != null){
generator.setGenerationTargetPath(outputPath);
}
generator.setGenerateCMake(cliArgs.hasOption(OPTION_FLAG_CMAKE.getLongOpt()));
// EMAM2CPP options
Path modelsDirPath = Paths.get(cliArgs.getOptionValue(OPTION_MODELS_PATH.getOpt()));
generator.getEmamGen().setUseAlgebraicOptimizations(false);
generator.getEmamGen().setUseThreadingOptimization(false);
generator.getEmamGen().setModelsDirPath(modelsDirPath);
// generator.getEmamGen().setGenerationTargetPath(outputPath); // done by EMADLGenerator
generator.getEmamGen().setGenerateTests(cliArgs.hasOption(OPTION_FLAG_TESTS.getOpt()));
if (cliArgs.hasOption(OPTION_FLAG_ARMADILLO.getOpt())) {
generator.getEmamGen().useArmadilloBackend();
}
generator.getEmamGen().setCheckModelDir(cliArgs.hasOption(OPTION_FLAG_CHECK_MODEL_DIR.getLongOpt()));
generator.getEmamGen().setGenerateServerWrapper(cliArgs.hasOption(OPTION_FLAG_SERVER_WRAPPER.getLongOpt()));
generator.getEmamGen().setGenerateAutopilotAdapter(cliArgs.hasOption(OPTION_FLAG_AUTOPILOT_ADAPTER.getLongOpt()));
generator.getEmamGen().setUseAlgebraicOptimizations(cliArgs.hasOption(OPTION_FLAG_ALGEBRAIC.getLongOpt()));
generator.getEmamGen().setUseThreadingOptimization(cliArgs.hasOption(OPTION_FLAG_THREADING.getLongOpt()));
generator.getEmamGen().setExecutionLoggingActive(cliArgs.hasOption(OPTION_FLAG_EXEC_LOGGING.getLongOpt()));
generator.getEmamGen().setGenerateCMake(cliArgs.hasOption(OPTION_FLAG_CMAKE.getLongOpt()));
// end EMAM2CPP options
try{
generator.generate(cliArgs.getOptionValue(OPTION_MODELS_PATH.getOpt()), rootModelName, pythonPath, forced, compile.equals("y"));
}
......
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