Skip to content

Commit

Permalink
remove .cl
Browse files Browse the repository at this point in the history
  • Loading branch information
tonghaining committed Oct 2, 2024
1 parent 533d214 commit a02dbd2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import static com.dat3m.dartagnan.parsers.program.utils.Compilation.applyLlvmPasses;
import static com.dat3m.dartagnan.parsers.program.utils.Compilation.compileWithClang;
import static com.dat3m.dartagnan.parsers.program.utils.Compilation.applyDemangling;;

public class ProgramParser {

Expand All @@ -25,7 +24,6 @@ public Program parse(File file) throws Exception {
if (needsClang(file)) {
file = compileWithClang(file, "");
file = applyLlvmPasses(file);
file = applyDemangling(file);
return new ProgramParser().parse(file);
}

Expand All @@ -40,15 +38,15 @@ public Program parse(File file) throws Exception {
}

private boolean needsClang(File f) {
return f.getPath().endsWith(".c") || f.getPath().endsWith(".i") || f.getPath().endsWith(".cl");
return f.getPath().endsWith(".c") || f.getPath().endsWith(".i");
}

public Program parse(String raw, String path, String format, String cflags) throws Exception {
switch (format) {
case "c", "i", "cl" -> {
case "c", "i" -> {
File file = path.isEmpty() ?
// This is for the case where the user fully typed the program instead of loading it
File.createTempFile("dat3m", format) :
File.createTempFile("dat3m", ".c") :
// This is for the case where the user loaded the program
new File(path, "dat3m.c");
try (FileWriter writer = new FileWriter(file)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,47 +54,25 @@ public static File applyLlvmPasses(File file) throws IOException {
return new File(outputFileName);
}

public static File applyDemangling(File file) throws IOException {
final File outputFile = new File(getOutputName(file, "-dmg.ll"));
ArrayList<String> cmd = new ArrayList<>();
cmd.add("llvm-cxxfilt");
try {
runCmd(cmd, file, outputFile);
} catch (Exception e) {
logger.warn("Failed to run llvm-cxxfilt (llvm symbol name demangler). Continuing without demangling.");
return file;
}
return outputFile;
}

private static String getOutputName(File file, String postfix) throws IOException {
return getOrCreateOutputDirectory() + "/" +
file.getName().substring(0, file.getName().lastIndexOf('.')) + postfix;
}

private static void runCmd(ArrayList<String> cmd) throws Exception {
runCmd(cmd, null, null);
}

private static void runCmd(ArrayList<String> cmd, File inputFile, File outputFile) throws Exception {
logger.debug(String.join(" ", cmd));
ProcessBuilder processBuilder = new ProcessBuilder(cmd);
if(inputFile != null) {
processBuilder.redirectInput(inputFile);
}
// "Unless the standard input and output streams are promptly written and read respectively
// of the sub process, it may block or deadlock the sub process."
// https://www.developer.com/design/understanding-java-process-and-java-processbuilder/
// The lines below take care of this.
if(outputFile == null) {
outputFile = File.createTempFile("log", null);
}
File log = File.createTempFile("log", null);
processBuilder.redirectErrorStream(true);
processBuilder.redirectOutput(outputFile);
processBuilder.redirectOutput(log);
Process proc = processBuilder.start();
proc.waitFor();
if(proc.exitValue() != 0) {
String errorString = Files.asCharSource(outputFile, Charsets.UTF_8).read();
String errorString = Files.asCharSource(log, Charsets.UTF_8).read();
throw new IOException("'" + String.join("' '", cmd) + "': " + errorString);
}
}
Expand Down

0 comments on commit a02dbd2

Please sign in to comment.