/*******************************************************************************
* Copyright (c) 2011 protos software gmbh (http://www.protos.de).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* CONTRIBUTORS:
* Henrik Rentz-Reichert (initial contribution)
*
*******************************************************************************/
package org.eclipse.etrice.generator.c;
import java.util.List;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.etrice.core.etmap.util.ETMapUtil;
import org.eclipse.etrice.core.genmodel.etricegen.Root;
import org.eclipse.etrice.generator.base.AbstractGenerator;
import org.eclipse.etrice.generator.base.IDataConfiguration;
import org.eclipse.etrice.generator.base.args.Arguments;
import org.eclipse.etrice.generator.base.logging.Loglevel;
import org.eclipse.etrice.generator.c.gen.MainGen;
import org.eclipse.etrice.generator.c.gen.Validator;
import org.eclipse.etrice.generator.c.setup.GeneratorModule;
import org.eclipse.etrice.generator.c.setup.GeneratorOptions;
import com.google.inject.Inject;
/**
* This class is implementing the eTrice C generator.
*
*
* It is based on the {@link org.eclipse.etrice.generator.base.AbstractGenerator AbstractGenerator}
* and is a plain Java program with a main method and command line options.
*
*
* It can be called using the launcher (see plug-in org.eclipse.etrice.generator.launch.c, i.e. using a
* launch configuration (Run or Debug) which allows to configure command line options).
*
*
* Alternatively it can be called from the command line as Java application. In this case the following jars
* have to be on the class path:
*
* - org.eclipse.etrice.core.room
* - org.eclipse.etrice.core.genmodel
* - org.eclipse.etrice.generator
* - org.eclipse.emf.ecore
* - org.eclipse.emf.common
* - org.eclipse.emf.ecore.xmi
* - org.eclipse.xtext
* - org.eclipse.equinox.common
* - org.eclipse.xtext.util
* - org.eclipse.xtend.lib
* - org.eclipse.xtext.xbase.lib
* - org.apache.log4j
* - org.antlr.runtime
* - com.google.inject
* - com.google.guava
* - javax.inject
*
*
*
* @author Henrik Rentz-Reichert
*
*/
public class Main extends AbstractGenerator {
public static int run(String[] args) {
return createAndRunGenerator(new GeneratorModule(), args);
}
public static void main(String[] args) {
int ret = run(args);
System.exit(ret);
}
@Inject
private MainGen mainGenerator;
@Inject
protected org.eclipse.etrice.generator.doc.gen.MainGen mainDocGenerator;
@Inject
protected org.eclipse.etrice.generator.gnuplot.GnuplotScriptGenerator gnuPlotGenerator;
@Inject
private Validator validator;
@Inject
protected IDataConfiguration dataConfig;
private Root genModelResult = null;
/**
* The resulting genmodel of {@linkplain #Main.runGenerator} if available.
*/
public Root getGenModel() {
return genModelResult;
}
protected int runGenerator(List resources, Arguments arguments) {
if (!dataConfig.setResources(getResourceSet(), logger)) {
logger.logError("configuration errors");
return GENERATOR_ERROR;
}
Root genModel = createGeneratorModel(resources, arguments);
if (diagnostician.isFailed() || genModel==null) {
logger.logError("errors during build of generator model");
return GENERATOR_ERROR;
}
if (!validator.validate(genModel)) {
logger.logError("validation failed during build of generator model");
return GENERATOR_ERROR;
}
ETMapUtil.processModels(genModel, getResourceSet(), diagnostician);
if (Loglevel.DEBUG.compareTo(logger.getLoglevel()) >= 0) {
logger.logDebug("-- begin dump of mappings");
logger.logDebug(ETMapUtil.dumpMappings());
logger.logDebug("-- end dump of mappings");
}
if (diagnostician.isFailed() || genModel==null) {
logger.logError("errors in mapping");
return GENERATOR_ERROR;
}
logger.logInfo("-- starting code generation");
mainGenerator.doGenerate(genModel.eResource());
if (arguments.get(GeneratorOptions.DOCUMENTATION)) {
mainDocGenerator.doGenerate(genModel.eResource());
}
if(arguments.get(GeneratorOptions.DATA_INSTR)){
gnuPlotGenerator.doGenerate(genModel);
}
if (diagnostician.isFailed()) {
logger.logError("errors during code generation");
return GENERATOR_ERROR;
}
genModelResult = genModel;
return GENERATOR_OK;
}
}