GP-2451 addressing code review comments

GP-2451_James_program_specific_address_spaces_pcode_field
This commit is contained in:
James 2022-08-15 16:02:28 -04:00
parent fb05c4ecd2
commit c9b1b3c9ab
2 changed files with 20 additions and 8 deletions

View file

@ -86,9 +86,8 @@ public class PcodeFieldFactory extends FieldFactory {
ArrayList<TextFieldElement> elements = new ArrayList<>(); ArrayList<TextFieldElement> elements = new ArrayList<>();
List<AttributedString> pcodeListing = List<AttributedString> pcodeListing = formatter.formatOps(instr.getProgram().getLanguage(),
formatter.formatOps(instr.getProgram().getLanguage(), instr.getProgram().getAddressFactory(), Arrays.asList(instr.getPcode(true)));
Arrays.asList(instr.getPcode(true)));
int lineCnt = pcodeListing.size(); int lineCnt = pcodeListing.size();
for (int i = 0; i < lineCnt; i++) { for (int i = 0; i < lineCnt; i++) {
elements.add(new TextFieldElement(pcodeListing.get(i), i, 0)); elements.add(new TextFieldElement(pcodeListing.get(i), i, 0));
@ -129,8 +128,8 @@ public class PcodeFieldFactory extends FieldFactory {
Instruction instr = (Instruction) obj; Instruction instr = (Instruction) obj;
Program program = instr.getProgram(); Program program = instr.getProgram();
List<AttributedString> attributedStrings = List<AttributedString> attributedStrings = formatter.formatOps(program.getLanguage(),
formatter.formatOps(program.getLanguage(), Arrays.asList(instr.getPcode(true))); program.getAddressFactory(), Arrays.asList(instr.getPcode(true)));
List<String> strings = new ArrayList<>(attributedStrings.size()); List<String> strings = new ArrayList<>(attributedStrings.size());
for (AttributedString attributedString : attributedStrings) { for (AttributedString attributedString : attributedStrings) {
strings.add(attributedString.getText()); strings.add(attributedString.getText());

View file

@ -26,15 +26,28 @@ import ghidra.program.model.pcode.Varnode;
public interface PcodeFormatter<T> { public interface PcodeFormatter<T> {
/** /**
* Format the the p-code ops * Format the p-code ops
* *
* @param language the language generating the p-code * @param language the language generating the p-code
* @param pcodeOps the p-code ops * @param pcodeOps the p-code ops
* @return the formatted result * @return the formatted result
*/ */
default T formatOps(Language language, List<PcodeOp> pcodeOps) { default T formatOps(Language language, List<PcodeOp> pcodeOps) {
return formatTemplates(language, return formatOps(language, language.getAddressFactory(), pcodeOps);
getPcodeOpTemplates(language.getAddressFactory(), pcodeOps)); }
/**
* Format the pcode ops with a specified {@link AddressFactory}. For use when the
* pcode ops can reference program-specific address spaces.
*
* @param language the language generating the p-code
* @param addrFactory addressFactory to use when generating pcodeop templates
* @param pcodeOps p-code ops to format
* @return the formatted result
*
*/
default T formatOps(Language language, AddressFactory addrFactory, List<PcodeOp> pcodeOps) {
return formatTemplates(language, getPcodeOpTemplates(addrFactory, pcodeOps));
} }
/** /**