GP-4712 refactoring, adding back in cache with no locking

This commit is contained in:
emteere 2024-06-24 16:20:10 -04:00
parent 7e5ffc2cf3
commit 19cf2fba3c
3 changed files with 21 additions and 11 deletions

View File

@ -15,16 +15,19 @@
*/
package ghidra.app.plugin.processors.sleigh;
import ghidra.program.model.address.Address;
import ghidra.program.model.lang.*;
import java.math.BigInteger;
import java.util.Arrays;
import generic.stl.Pair;
import ghidra.program.model.address.Address;
import ghidra.program.model.lang.*;
public class ContextCache {
private int context_size = 0;
private Register contextBaseRegister = null;
Pair <BigInteger, int []> lastValue = null;
public ContextCache() {
}
@ -55,7 +58,13 @@ public class ContextCache {
private int[] getWords(BigInteger value) {
Pair <BigInteger, int []> lastValueTmp = lastValue;
if (lastValueTmp != null && value.equals(lastValueTmp.first)) {
return lastValueTmp.second;
}
int[] words = new int[context_size];
byte[] bytes = value.toByteArray();
int byteIndexDiff = context_size * 4 - bytes.length;
for (int i = 0; i < context_size; i++) {
@ -66,6 +75,10 @@ public class ContextCache {
}
words[i] = word;
}
lastValueTmp = new Pair<BigInteger, int[]>(value, words);
lastValue = lastValueTmp;
return words;
}

View File

@ -378,13 +378,12 @@ public class SleighLanguage implements Language {
if (!instructProtoMap.containsKey(hashcode)) {
newProto.cacheInfo(buf, context, true);
}
res = instructProtoMap.get(hashcode);
if (res == null) { // We have a prototype we have never seen
// before, build it fully
instructProtoMap.put(hashcode, newProto);
res = instructProtoMap.putIfAbsent(hashcode, newProto);
// if there was no previous value, assume newProto inserted
if (res == null) {
res = newProto;
}
if (inDelaySlot && res.hasDelaySlots()) {
throw new NestedDelaySlotException();
}

View File

@ -51,7 +51,6 @@ public class HighFunction extends PcodeSyntaxTree {
private List<JumpTable> jumpTables;
private List<DataTypeSymbol> protoOverrides;
private Address entryPoint;
private AddressSpace entryAddrSpace;
/**
* @param function function associated with the higher level function abstraction.
@ -67,7 +66,6 @@ public class HighFunction extends PcodeSyntaxTree {
this.compilerSpec = compilerSpec;
AddressSpace stackSpace = function.getProgram().getAddressFactory().getStackSpace();
entryPoint = function.getEntryPoint();
entryAddrSpace = entryPoint.getAddressSpace();
localSymbols = new LocalSymbolMap(this, stackSpace);
globalSymbols = new GlobalSymbolMap(this);
proto = new FunctionPrototype(localSymbols, function);
@ -304,7 +302,7 @@ public class HighFunction extends PcodeSyntaxTree {
private void decodeJumpTableList(Decoder decoder) throws DecoderException {
int el = decoder.openElement(ELEM_JUMPTABLELIST);
while (decoder.peekElement() != 0) {
JumpTable table = new JumpTable(entryAddrSpace);
JumpTable table = new JumpTable(entryPoint.getAddressSpace());
table.decode(decoder);
if (!table.isEmpty()) {
if (jumpTables == null) {