use of com.dat3m.dartagnan.exception.ParsingException in project Dat3M by hernanponcedeleon.
the class VisitorBoogie method visitAssign_cmd.
@Override
public Object visitAssign_cmd(Assign_cmdContext ctx) {
ExprsContext exprs = ctx.def_body().exprs();
if (ctx.Ident().size() != 1 && exprs.expr().size() != ctx.Ident().size()) {
throw new ParsingException("There should be one expression per variable\nor only one expression for all in " + ctx.getText());
}
for (int i = 0; i < ctx.Ident().size(); i++) {
ExprInterface value = (ExprInterface) exprs.expr(i).accept(this);
if (value == null) {
continue;
}
String name = ctx.Ident(i).getText();
if (smackDummyVariables.contains(name)) {
continue;
}
if (constantsTypeMap.containsKey(name)) {
throw new ParsingException("Constants cannot be assigned: " + ctx.getText());
}
if (initMode) {
programBuilder.initLocEqConst(name, ((IExpr) value).reduce());
continue;
}
Register register = programBuilder.getRegister(threadCount, currentScope.getID() + ":" + name);
if (register != null) {
if (ctx.getText().contains("$load.") || value instanceof MemoryObject) {
try {
// This names are global so we don't use currentScope.getID(), but per thread.
Register reg = programBuilder.getOrCreateRegister(threadCount, ctx.Ident(0).getText(), ARCH_PRECISION);
String tmp = ctx.def_body().exprs().expr(0).getText();
tmp = tmp.substring(tmp.indexOf(",") + 1, tmp.indexOf(")"));
// This names are global so we don't use currentScope.getID(), but per thread.
Register ptr = programBuilder.getOrCreateRegister(threadCount, tmp, ARCH_PRECISION);
pool.addRegPtr(reg, ptr);
} catch (Exception e) {
// Nothing to be done
}
if (!allocationRegs.contains(value)) {
programBuilder.addChild(threadCount, EventFactory.newLoad(register, (IExpr) value, null)).setCLine(currentLine).setSourceCodeFile(sourceCodeFile);
} else {
programBuilder.addChild(threadCount, EventFactory.newLoad(register, (IExpr) value, null));
}
continue;
}
value = value.visit(exprSimplifier);
programBuilder.addChild(threadCount, EventFactory.newLocal(register, value)).setCLine(currentLine).setSourceCodeFile(sourceCodeFile);
continue;
}
MemoryObject object = programBuilder.getObject(name);
if (object != null) {
programBuilder.addChild(threadCount, EventFactory.newStore(object, value, null)).setCLine(currentLine).setSourceCodeFile(sourceCodeFile);
continue;
}
if (currentReturnName.equals(name)) {
if (!returnRegister.isEmpty()) {
Register ret = returnRegister.remove(returnRegister.size() - 1);
programBuilder.addChild(threadCount, EventFactory.newLocal(ret, value)).setCLine(currentLine).setSourceCodeFile(sourceCodeFile);
}
continue;
}
throw new ParsingException("Variable " + name + " is not defined");
}
return null;
}
use of com.dat3m.dartagnan.exception.ParsingException in project Dat3M by hernanponcedeleon.
the class SVCOMPSanitizer method run.
public File run(int bound) throws ParsingException {
File tmp = new File(System.getenv("DAT3M_HOME") + "/output/" + file.getName().substring(0, file.getName().lastIndexOf('.')) + "_tmp.c");
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file.getAbsolutePath())));
PrintWriter writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(tmp)));
StringBuilder contents = new StringBuilder();
while (reader.ready()) {
contents.append(reader.readLine());
}
reader.close();
String stringContents = contents.toString();
if (stringContents.matches(".*main\\(.*\\).*for.*\\{.*pthread_create(.*).*\\}")) {
reader.close();
writer.close();
tmp.delete();
throw new ParsingException("pthread_create cannot be inside a for loop");
}
reader = new BufferedReader(new InputStreamReader(new FileInputStream(file.getAbsolutePath())));
for (String line; (line = reader.readLine()) != null; ) {
// SMACK does not create procedures for inline functions
if (!line.contains("__inline")) {
line = line.replace("inline ", "");
}
line = line.replace("void reach_error(){}", "__attribute__((optnone))void reach_error(){}");
if (line.contains("while(1) { pthread_create(&t, 0, thr1, 0); }") || line.contains("while(1) pthread_create(&t, 0, thr1, 0);") || line.contains("while(__VERIFIER_nondet_int()) pthread_create(&t, 0, thr1, 0);")) {
// While with empty body to force the creation of boundEvents
line = line.replace("while(1) { pthread_create(&t, 0, thr1, 0); }", "for (int i = 1; i < " + bound + 1 + "; ++i) {}");
line = line.replace("while(1) pthread_create(&t, 0, thr1, 0);", "for (int i = 1; i < " + bound + 1 + "; ++i) {}");
line = line.replace("while(__VERIFIER_nondet_int()) pthread_create(&t, 0, thr1, 0);", "for (int i = 1; i < " + bound + 1 + "; ++i) {}");
int i = 0;
while (i < bound) {
writer.print("pthread_t t" + i + ";");
writer.print("pthread_create(&t" + i + ", 0, thr1, 0); ");
i++;
}
}
if (line.contains("while(1) { pthread_create(&t, 0, thr2, 0); }")) {
// While with empty body to force the creation of boundEvents
line = line.replace("while(1) { pthread_create(&t, 0, thr2, 0); }", "while(1) {}");
int i = 0;
while (i < bound) {
writer.print("pthread_create(&t, 0, thr2, 0); ");
i++;
}
}
if (line.contains("while") && line.contains("pthread_create")) {
reader.close();
writer.close();
tmp.delete();
throw new ParsingException(line + " cannot be parsed");
}
writer.println(line);
}
reader.close();
writer.close();
} catch (IOException e) {
System.out.println(e.getMessage());
System.exit(0);
}
return tmp;
}
Aggregations