mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 10:19:23 +02:00
Merge remote-tracking branch 'origin/GT-3591_ghidra1_SleighCompile'
This commit is contained in:
commit
dc5f354675
1 changed files with 58 additions and 32 deletions
|
@ -127,7 +127,11 @@ public class SleighLanguage implements Language {
|
||||||
// for now we'll assume yes.
|
// for now we'll assume yes.
|
||||||
contextcache = new ContextCache();
|
contextcache = new ContextCache();
|
||||||
|
|
||||||
ResourceFile slaFile = ensureSpecificationIsCompiled(langDescription);
|
ResourceFile slaFile = langDescription.getSlaFile();
|
||||||
|
if (!slaFile.exists() ||
|
||||||
|
(slaFile.canWrite() && (isSLAWrongVersion(slaFile) || isSLAStale(slaFile)))) {
|
||||||
|
reloadLanguage(TaskMonitor.DUMMY, true);
|
||||||
|
}
|
||||||
|
|
||||||
// Read in the sleigh specification
|
// Read in the sleigh specification
|
||||||
readSpecification(slaFile);
|
readSpecification(slaFile);
|
||||||
|
@ -144,19 +148,47 @@ public class SleighLanguage implements Language {
|
||||||
initParallelHelper();
|
initParallelHelper();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResourceFile ensureSpecificationIsCompiled(SleighLanguageDescription langDescription)
|
private boolean isSLAWrongVersion(ResourceFile slaFile) {
|
||||||
throws IOException {
|
|
||||||
ResourceFile slaFile = langDescription.getSlaFile();
|
try {
|
||||||
if (!slaFile.exists()) {
|
XmlPullParser parser = XmlPullParserFactory.create(slaFile, new ErrorHandler() {
|
||||||
reloadLanguage(TaskMonitor.DUMMY, true);
|
|
||||||
|
@Override
|
||||||
|
public void warning(SAXParseException exception) throws SAXException {
|
||||||
|
// ignore
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
|
@Override
|
||||||
|
public void fatalError(SAXParseException exception) throws SAXException {
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void error(SAXParseException exception) throws SAXException {
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
XmlElement e = parser.peek();
|
||||||
|
if (!"sleigh".equals(e.getName())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int version = SpecXmlUtils.decodeInt(e.getAttribute("version"));
|
||||||
|
return (version != SLA_FORMAT_VERSION);
|
||||||
|
}
|
||||||
|
catch (SAXException | IOException e) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isSLAStale(ResourceFile slaFile) {
|
||||||
String slafilename = slaFile.getName();
|
String slafilename = slaFile.getName();
|
||||||
int index = slafilename.lastIndexOf('.');
|
int index = slafilename.lastIndexOf('.');
|
||||||
String slabase = slafilename.substring(0, index);
|
String slabase = slafilename.substring(0, index);
|
||||||
String slaspecfilename = slabase + ".slaspec";
|
String slaspecfilename = slabase + ".slaspec";
|
||||||
ResourceFile slaspecFile = new ResourceFile(slaFile.getParentFile(), slaspecfilename);
|
ResourceFile slaspecFile = new ResourceFile(slaFile.getParentFile(), slaspecfilename);
|
||||||
if (slaspecFile.canWrite()) {
|
|
||||||
File resourceAsFile = slaspecFile.getFile(true);
|
File resourceAsFile = slaspecFile.getFile(true);
|
||||||
SleighPreprocessor preprocessor =
|
SleighPreprocessor preprocessor =
|
||||||
new SleighPreprocessor(new ModuleDefinitionsAdapter(), resourceAsFile);
|
new SleighPreprocessor(new ModuleDefinitionsAdapter(), resourceAsFile);
|
||||||
|
@ -169,13 +201,7 @@ public class SleighLanguage implements Language {
|
||||||
// will propagate elsewhere
|
// will propagate elsewhere
|
||||||
}
|
}
|
||||||
long compiledTimestamp = slaFile.lastModified();
|
long compiledTimestamp = slaFile.lastModified();
|
||||||
if (sourceTimestamp > compiledTimestamp) {
|
return (sourceTimestamp > compiledTimestamp);
|
||||||
reloadLanguage(TaskMonitor.DUMMY, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return slaFile;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue