/**
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*/
package org.thingml.compilers.c.arduino;
import org.sintef.thingml.Configuration;
import org.sintef.thingml.Thing;
import org.sintef.thingml.constraints.ThingMLHelpers;
import org.sintef.thingml.helpers.ConfigurationHelper;
import org.thingml.compilers.ThingMLCompiler;
import org.thingml.compilers.c.CCfgMainGenerator;
import org.thingml.compilers.c.CCompilerContext;
import org.thingml.compilers.c.CThingImplCompiler;
import org.thingml.compilers.c.cepHelper.CCepHelper;
import org.thingml.compilers.configuration.CfgBuildCompiler;
import org.thingml.compilers.thing.ThingCepSourceDeclaration;
import org.thingml.compilers.thing.ThingCepViewCompiler;
import org.thingml.compilers.utils.OpaqueThingMLCompiler;
/**
* Created by ffl on 25.11.14.
*/
public class ArduinoCompiler extends OpaqueThingMLCompiler {
public ArduinoCompiler() {
super(new CThingActionCompilerArduino(), new CThingApiCompilerArduino(), new CCfgMainGenerator(),
new CfgBuildCompiler(), new CThingImplCompiler(),
new ArduinoThingCepCompiler(new ThingCepViewCompiler(), new ThingCepSourceDeclaration()));
this.checker = new ArduinoChecker(this.getID());
}
@Override
public ThingMLCompiler clone() {
return new ArduinoCompiler();
}
@Override
public String getID() {
return "arduino";
}
@Override
public String getName() {
return "C/C++ for Arduino (AVR Microcontrollers)";
}
public String getDescription() {
return "Generates C/C++ code for Arduino or other AVR microcontrollers (AVR-GCC compiler).";
}
@Override
public void do_call_compiler(Configuration cfg, String... options) {
CCompilerContext ctx = new CCompilerContextArduino(this);
processDebug(cfg);
ctx.setCurrentConfiguration(cfg);
//ctx.setOutputDirectory(new File(ctx.getOutputDirectory(), cfg.getName()));
//Checks
this.checker.do_check(cfg);
this.checker.printReport();
// GENERATE A MODULE FOR EACH THING
for (Thing thing : ConfigurationHelper.allThings(cfg)) {
ctx.setConcreteThing(thing);
((CCompilerContextArduino) ctx).renameParameterUniquely(thing);
// GENERATE HEADER
ctx.getCompiler().getThingApiCompiler().generatePublicAPI(thing, ctx);
// GENERATE IMPL
ctx.getCompiler().getThingImplCompiler().generateImplementation(thing, ctx);
ctx.clearConcreteThing();
}
CCepHelper.generateTimerPolling(cfg, ctx);
// GENERATE A MODULE FOR THE CONFIGURATION (+ its dependencies)
getMainCompiler().generateMainAndInit(cfg, ThingMLHelpers.findContainingModel(cfg), ctx);
// WRITE THE GENERATED CODE
ctx.writeGeneratedCodeToFiles();
}
}