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.
|
||||
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
|
||||
readSpecification(slaFile);
|
||||
|
@ -144,19 +148,47 @@ public class SleighLanguage implements Language {
|
|||
initParallelHelper();
|
||||
}
|
||||
|
||||
private ResourceFile ensureSpecificationIsCompiled(SleighLanguageDescription langDescription)
|
||||
throws IOException {
|
||||
ResourceFile slaFile = langDescription.getSlaFile();
|
||||
if (!slaFile.exists()) {
|
||||
reloadLanguage(TaskMonitor.DUMMY, true);
|
||||
private boolean isSLAWrongVersion(ResourceFile slaFile) {
|
||||
|
||||
try {
|
||||
XmlPullParser parser = XmlPullParserFactory.create(slaFile, new ErrorHandler() {
|
||||
|
||||
@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();
|
||||
int index = slafilename.lastIndexOf('.');
|
||||
String slabase = slafilename.substring(0, index);
|
||||
String slaspecfilename = slabase + ".slaspec";
|
||||
ResourceFile slaspecFile = new ResourceFile(slaFile.getParentFile(), slaspecfilename);
|
||||
if (slaspecFile.canWrite()) {
|
||||
|
||||
File resourceAsFile = slaspecFile.getFile(true);
|
||||
SleighPreprocessor preprocessor =
|
||||
new SleighPreprocessor(new ModuleDefinitionsAdapter(), resourceAsFile);
|
||||
|
@ -169,13 +201,7 @@ public class SleighLanguage implements Language {
|
|||
// will propagate elsewhere
|
||||
}
|
||||
long compiledTimestamp = slaFile.lastModified();
|
||||
if (sourceTimestamp > compiledTimestamp) {
|
||||
reloadLanguage(TaskMonitor.DUMMY, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return slaFile;
|
||||
return (sourceTimestamp > compiledTimestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue