noOptimization = disableOptimization;
this.variablesToLog.clear();
// this.variablesToLog.addAll(variablesToLog);
if (!linkFile.exists() || linkFile.isDirectory())
{
throw new RemoteSimulationException("The VDM link file does not exist: "
+ linkFile);
}
VdmLinkParserWrapper linksParser = new VdmLinkParserWrapper();
links = linksParser.parse(linkFile);// Links.load(linkFile);
if (links == null || linksParser.hasErrors())
{
throw new RemoteSimulationException("Faild to parse vdm links");
}
if (disableRtLog)
{
RTLogger.enable(false);
controller.setLogFile(null);
} else
{
File logFile = new File(outputDir, "ExecutionTrace.logrt");
controller.setLogFile(logFile);
RTLogger.enable(true);
RTLogger.setLogfile(new PrintWriter(logFile));
}
if (Settings.timingInvChecks)
{
PrintWriter p = new PrintWriter(new FileOutputStream(new File(outputDir, "Timing.logtv"), false));
RuntimeValidator.setLogFile(p);
}
if (!disableCoverage)
{
coverageDirectory = new File(outputDir, "coverage");
}
if (this.variablesToLog.isEmpty())
{
SimulationLogger.enable(false);
} else
{
this.simulationLogFile = new File(outputDir, "desimulation.log");
}
controller.setScript(script);
Settings.baseDir = baseDirFile;
VDMCO.outputDir = outputDir;
ExitStatus status = controller.parse(specfiles);
if (status == ExitStatus.EXIT_OK)
{
status = controller.typeCheck();
if (status == ExitStatus.EXIT_OK)
{
this.status = CoSimStatusEnum.LOADED;
} else
{
final Writer result = new StringWriter();
final PrintWriter printWriter = new PrintWriter(result);
TypeChecker.printWarnings(printWriter);
TypeChecker.printErrors(printWriter);
throw new RemoteSimulationException("Type check error: "
+ result.toString());
}
} else
{
throw new RemoteSimulationException("Cannot not parse specification", null);
}
boolean hasScriptCall = false;
int cpus = 0;
this.interpreter = controller.getInterpreter();
for (ClassDefinition def : interpreter.getClasses())
{
if (def instanceof SystemDefinition)
{
for (Definition d : def.definitions)
{
Type t = d.getType();
if (t instanceof ClassType)
{
ClassType ct = (ClassType) t;
if (ct.classdef instanceof CPUClassDefinition)
{
cpus++;
}
}
}
} else if (def instanceof ClassDefinition)
{
if (def.getName().equals(scriptClass))
{
for (Definition d : def.definitions)
{
if (d.getName() != null
&& d.getName().equals(scriptOperation)
&& (d instanceof ExplicitOperationDefinition || d instanceof ExplicitFunctionDefinition))
{
hasScriptCall = true;
}
}
}
}
}
if (!hasScriptCall)
{
throw new RemoteSimulationException("The specification do not contain the entrypoint: "
+ script, null);
}
if (cpus == 0)
{
throw new RemoteSimulationException("Cannot load system to few CPUS", null);
}
return true;
} catch (RemoteSimulationException e)
{
throw e;
} catch (Exception e)
{
debugErr(e);
throw new RemoteSimulationException("Internal Error while loading the model.", e);
}
}