use of org.abs_models.backend.common.InternalBackendException in project abstools by abstools.
the class JavaBackend method compile.
private int compile() throws Exception {
final Model model = parse(arguments.files);
if (model.hasParserErrors() || model.hasErrors() || model.hasTypeErrors()) {
printErrorMessage();
return 1;
}
if (!arguments.destDir.mkdirs() && !arguments.destDir.isDirectory()) {
throw new IOException("Could not create directory " + arguments.destDir.toString());
}
if (!arguments.destDir.canWrite()) {
throw new InternalBackendException("Destination directory " + arguments.destDir.getAbsolutePath() + " cannot be written to!");
}
compile(model, arguments.destDir);
return 0;
}
use of org.abs_models.backend.common.InternalBackendException in project abstools by abstools.
the class ABSTest method assertParseFilesOk.
protected Model assertParseFilesOk(Set<String> fileNames, Config... config) throws IOException, InternalBackendException, DeltaModellingException, WrongProgramArgumentException {
Main main = new Main();
java.util.List<File> files = fileNames.stream().map(f -> new File(resolveFileName(f))).collect(Collectors.toList());
Model m = main.parse(files);
return assertParseModelOk(m, config);
}
use of org.abs_models.backend.common.InternalBackendException in project abstools by abstools.
the class Main method mainMethod.
public int mainMethod(Absc arguments) {
int result = 0;
boolean done = false;
this.arguments = arguments;
try {
if (arguments.backend != null) {
if (arguments.backend.maude) {
result = Math.max(result, MaudeCompiler.doMain(arguments));
done = true;
}
if (arguments.backend.java) {
result = Math.max(result, JavaBackend.doMain(arguments));
done = true;
}
if (arguments.backend.erlang) {
result = Math.max(result, ErlangBackend.doMain(arguments));
done = true;
}
if (arguments.backend.prolog) {
result = Math.max(result, PrologBackend.doMain(arguments));
done = true;
}
if (arguments.backend.coreabs) {
result = Math.max(result, CoreAbsBackend.doMain(arguments));
done = true;
}
if (arguments.backend.json) {
result = Math.max(result, Tester.doMain(arguments));
done = true;
}
if (arguments.backend.prettyprint) {
result = Math.max(result, PrettyPrinterBackEnd.doMain(arguments));
done = true;
}
if (arguments.backend.outline) {
result = Math.max(result, OutlinePrinterBackEnd.doMain(arguments));
done = true;
}
if (arguments.backend.dumpProducts) {
Model m = parse(arguments.files);
if (m.hasParserErrors()) {
// parse should have already printed errors
result = Math.max(result, 1);
} else {
Iterator<ProductDecl> pi = m.getProductDecls().iterator();
while (pi.hasNext()) {
System.out.print(pi.next().getName());
if (pi.hasNext())
System.out.print(' ');
}
}
done = true;
}
}
if (!done) {
// no backend selected, just do type-checking
Model m = parse(arguments.files);
if (m.hasParserErrors() || m.hasErrors() || m.hasTypeErrors()) {
printErrorMessage();
result = 1;
}
}
} catch (InternalBackendException e) {
// don't print stack trace here
printError(e.getMessage());
result = 1;
} catch (Exception e) {
if (e.getMessage() == null) {
e.printStackTrace();
}
assert e.getMessage() != null : e.toString();
printError(e.getMessage());
result = 1;
}
return result;
}
use of org.abs_models.backend.common.InternalBackendException in project abstools by abstools.
the class MaudeCompiler method compile.
/**
* @throws Exception
*/
public int compile() throws Exception {
if (arguments.verbose)
System.out.println("Generating Maude code...");
module = arguments.maude_timed ? SIMULATOR.EQ_TIMED : SIMULATOR.RL;
final Model model = parse(arguments.files);
// Maude has build-in AwaitAsyncCall support
model.doAACrewrite = false;
if (model.hasParserErrors() || model.hasErrors() || model.hasTypeErrors()) {
printErrorMessage();
return 1;
}
PrintStream stream = System.out;
if (arguments.outputfile != null) {
stream = new PrintStream(arguments.outputfile);
}
// Are we running in the source directory?
InputStream is = ClassLoader.getSystemResourceAsStream(RUNTIME_INTERPRETER_PATH);
if (is == null) {
// Are we running within absfrontend.jar?
is = ClassLoader.getSystemResourceAsStream("maude/abs-interpreter.maude");
}
if (is == null) {
throw new InternalBackendException("Could not locate abs-interpreter.maude");
}
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
stream.println("*** Generated " + dateFormat.format(new Date()));
ByteStreams.copy(is, stream);
model.generateMaude(stream, module, arguments.maude_mainBlock, arguments.maude_clocklimit, arguments.maude_defaultResources);
if (arguments.verbose && arguments.outputfile != null) {
System.out.println("Finished. Start `maude " + arguments.outputfile.toString() + "' to run the model.");
}
return 0;
}
use of org.abs_models.backend.common.InternalBackendException in project abstools by abstools.
the class ErlangBackend method compile.
public void compile(Model m, File destDir, EnumSet<CompileOptions> options) throws IOException, InterruptedException, InternalBackendException {
int version = getErlangVersion();
if (version < minErlangVersion) {
String message = "ABS requires at least erlang version " + Integer.toString(minErlangVersion) + ", installed version is " + Integer.toString(version);
throw new InternalBackendException(message);
}
String ebin_dir = "/absmodel/_build/default/lib/absmodel/ebin/";
ErlApp erlApp = new ErlApp(destDir, arguments.http_index_file, arguments.http_static_dir);
m.generateErlangCode(erlApp, options);
erlApp.close();
List<String> compile_command = new ArrayList<String>();
// We used to call "rebar compile" here but calling erlc directly
// removes 1.5s from the compile time
compile_command.add("erlc");
if (options.contains(CompileOptions.DEBUG)) {
compile_command.add("+debug_info");
}
compile_command.add("-I");
compile_command.add(destDir + "/absmodel/include");
compile_command.add("-o");
compile_command.add(destDir + ebin_dir);
// Set<String> compiled_basenames =
// Arrays.stream(new File(destDir, ebin_dir).listFiles())
// .map((File f) -> FilenameUtils.removeExtension(f.getName()))
// .collect(Collectors.toSet());
Arrays.stream(new File(destDir, "absmodel/src/").listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".erl");
}
})).forEach((File f) -> compile_command.add(f.toString()));
if (options.contains(CompileOptions.VERBOSE)) {
System.out.println("Compiling erlang files with command: " + String.join(" ", compile_command));
}
Process p = Runtime.getRuntime().exec(compile_command.toArray(new String[0]));
if (options.contains(CompileOptions.VERBOSE))
IOUtils.copy(p.getInputStream(), System.out);
else
IOUtils.copy(p.getInputStream(), new NullOutputStream());
p.waitFor();
if (p.exitValue() != 0) {
String message = "Compilation of generated erlang code failed with exit value " + p.exitValue();
if (!options.contains(CompileOptions.VERBOSE))
message = message + "\n (use -v for detailed compiler output)";
throw new InternalBackendException(message);
// TODO: consider removing the generated code here. For now,
// let's leave it in place for diagnosis.
} else {
if (options.contains(CompileOptions.VERBOSE)) {
System.out.println();
System.out.println("Finished. \"gen/erl/run\" to start the model.");
System.out.println(" (\"gen/erl/run --help\" for more options)");
}
}
}
Aggregations