mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 10:19:23 +02:00
Merge remote-tracking branch 'origin/GT-3328_ghidra1_SleighArgs' into patch
This commit is contained in:
commit
b7a3dff215
15 changed files with 205 additions and 92 deletions
|
@ -422,7 +422,7 @@ public class SleighLanguage implements Language {
|
|||
String languageName = specName + ".slaspec";
|
||||
ResourceFile languageFile = new ResourceFile(slaFile.getParentFile(), languageName);
|
||||
|
||||
// see gradleScripts/processorUtils.gradle for sleighArgs.txt generation
|
||||
// see gradle/processorUtils.gradle for sleighArgs.txt generation
|
||||
ResourceFile sleighArgsFile = null;
|
||||
ResourceFile languageModule = Application.getModuleContainingResourceFile(languageFile);
|
||||
if (languageModule != null) {
|
||||
|
@ -430,21 +430,23 @@ public class SleighLanguage implements Language {
|
|||
sleighArgsFile = new ResourceFile(languageModule, "data/sleighArgs.txt");
|
||||
}
|
||||
else {
|
||||
sleighArgsFile = new ResourceFile(languageModule, "build/data/sleighArgs.txt");
|
||||
sleighArgsFile = new ResourceFile(languageModule, "build/tmp/sleighArgs.txt");
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, String> defineMap;
|
||||
String[] args;
|
||||
if (sleighArgsFile != null && sleighArgsFile.isFile()) {
|
||||
args = new String[] { "-i", sleighArgsFile.getAbsolutePath(),
|
||||
String baseDir = Application.getInstallationDirectory().getAbsolutePath().replace(
|
||||
File.separatorChar, '/');
|
||||
if (!baseDir.endsWith("/")) {
|
||||
baseDir += "/";
|
||||
}
|
||||
args = new String[] { "-DBaseDir=" + baseDir, "-i", sleighArgsFile.getAbsolutePath(),
|
||||
languageFile.getAbsolutePath(), description.getSlaFile().getAbsolutePath() };
|
||||
defineMap = new HashMap<>();
|
||||
}
|
||||
else {
|
||||
args = new String[] { languageFile.getAbsolutePath(),
|
||||
description.getSlaFile().getAbsolutePath() };
|
||||
defineMap = ModuleDefinitionsMap.getModuleMap();
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -454,7 +456,7 @@ public class SleighLanguage implements Language {
|
|||
buf.append(" ");
|
||||
}
|
||||
Msg.debug(this, "Sleigh compile: " + buf);
|
||||
int returnCode = SleighCompileLauncher.runMain(args, defineMap);
|
||||
int returnCode = SleighCompileLauncher.runMain(args);
|
||||
if (returnCode != 0) {
|
||||
throw new SleighException("Errors compiling " + languageFile.getAbsolutePath() +
|
||||
" -- please check log messages for details");
|
||||
|
|
|
@ -1688,6 +1688,6 @@ public class SleighCompile extends SleighBase {
|
|||
* @throws RecognitionException
|
||||
*/
|
||||
public static void main(String[] args) throws JDOMException, IOException, RecognitionException {
|
||||
System.exit(SleighCompileLauncher.runMain(args, new HashMap<String, String>()));
|
||||
System.exit(SleighCompileLauncher.runMain(args));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,24 +71,24 @@ public class SleighCompileLauncher implements GhidraLaunchable {
|
|||
ApplicationConfiguration configuration = new ApplicationConfiguration();
|
||||
Application.initializeApplication(layout, configuration);
|
||||
|
||||
System.exit(runMain(args, new HashMap<String, String>()));
|
||||
System.exit(runMain(args));
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the Sleigh compiler process
|
||||
*
|
||||
* @param args sleigh compiler command line arguments
|
||||
* @param preprocs additional preprocessor macro
|
||||
* @return exit code (TODO: exit codes are not well defined)
|
||||
* @throws JDOMException
|
||||
* @throws IOException
|
||||
* @throws RecognitionException
|
||||
*/
|
||||
public static int runMain(String[] args, Map<String, String> preprocs)
|
||||
public static int runMain(String[] args)
|
||||
throws JDOMException, IOException, RecognitionException {
|
||||
int retval;
|
||||
String filein = null;
|
||||
String fileout = null;
|
||||
Map<String, String> preprocs = new HashMap<>();
|
||||
|
||||
SleighCompile.yydebug = false;
|
||||
boolean allMode = false;
|
||||
|
@ -218,8 +218,8 @@ public class SleighCompileLauncher implements GhidraLaunchable {
|
|||
System.out.println("Compiling " + input + ":");
|
||||
SleighCompile compiler = new SleighCompile();
|
||||
initCompiler(compiler, preprocs, unnecessaryPcodeWarning, lenientConflict,
|
||||
allCollisionWarning,
|
||||
allNopWarning, deadTempWarning, unusedFieldWarning, enforceLocalKeyWord);
|
||||
allCollisionWarning, allNopWarning, deadTempWarning, unusedFieldWarning,
|
||||
enforceLocalKeyWord);
|
||||
|
||||
String outname = input.getName().replace(".slaspec", ".sla");
|
||||
File output = new File(input.getParent(), outname);
|
||||
|
@ -247,8 +247,8 @@ public class SleighCompileLauncher implements GhidraLaunchable {
|
|||
// single file compile
|
||||
SleighCompile compiler = new SleighCompile();
|
||||
initCompiler(compiler, preprocs, unnecessaryPcodeWarning, lenientConflict,
|
||||
allCollisionWarning, allNopWarning,
|
||||
deadTempWarning, unusedFieldWarning, enforceLocalKeyWord);
|
||||
allCollisionWarning, allNopWarning, deadTempWarning, unusedFieldWarning,
|
||||
enforceLocalKeyWord);
|
||||
if (i == args.length) {
|
||||
Msg.error(SleighCompile.class, "Missing input file name");
|
||||
return 1;
|
||||
|
@ -418,6 +418,7 @@ public class SleighCompileLauncher implements GhidraLaunchable {
|
|||
return 4;
|
||||
}
|
||||
catch (PreprocessorException e) {
|
||||
Msg.error(SleighCompile.class, e.getMessage());
|
||||
Msg.error(SleighCompile.class, "Errors during preprocessing, halting compilation");
|
||||
return 5;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*/
|
||||
package ghidra.pcodeCPort.slgh_compile.regression;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
@ -167,11 +167,9 @@ public class SleighCompileRegressionTest extends AbstractGenericTest {
|
|||
|
||||
private int runActualCompiler(File inputFile, File actualFile)
|
||||
throws JDOMException, IOException, RecognitionException {
|
||||
return SleighCompileLauncher.runMain(
|
||||
new String[] { "-DMIPS=../../../../../../ghidra/Ghidra/Processors/MIPS",
|
||||
"-D8051=../../../../../../ghidra/Ghidra/Processors/8051",
|
||||
inputFile.getAbsolutePath(), actualFile.getAbsolutePath() },
|
||||
new HashMap<String, String>());
|
||||
return SleighCompileLauncher.runMain(new String[] { "-DBaseDir=../../../../../../",
|
||||
"-DMIPS=ghidra/Ghidra/Processors/MIPS", "-D8051=ghidra/Ghidra/Processors/8051",
|
||||
inputFile.getAbsolutePath(), actualFile.getAbsolutePath() });
|
||||
}
|
||||
|
||||
private static final Pattern SPACEMATCH = Pattern.compile("^\\s*<print piece=\" \"/>\\s*$");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue