Skip to content

Commit 67b0102

Browse files
committed
Merge remote-tracking branch 'origin/GP-2368_James_pcodecompile_npe'
2 parents 8f811ef + 07f87bb commit 67b0102

File tree

1 file changed

+33
-45
lines changed
  • Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcodeCPort/slgh_compile

1 file changed

+33
-45
lines changed

Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/pcodeCPort/slgh_compile/PcodeCompile.java

+33-45
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
*/
1616
package ghidra.pcodeCPort.slgh_compile;
1717

18-
import java.util.Arrays;
19-
import java.util.List;
18+
import java.util.*;
2019
import java.util.stream.Collectors;
2120

2221
import org.apache.logging.log4j.LogManager;
@@ -171,10 +170,9 @@ private void force_size(VarnodeTpl vt, ConstTpl size, VectorSTL<OpTpl> ops)
171170
// Build temporary variable (with zerosize)
172171
public VarnodeTpl buildTemporary(Location location) {
173172
entry("buildTemporary", location);
174-
VarnodeTpl res =
175-
new VarnodeTpl(location, new ConstTpl(getUniqueSpace()), new ConstTpl(
176-
ConstTpl.const_type.real, allocateTemp()),
177-
new ConstTpl(ConstTpl.const_type.real, 0));
173+
VarnodeTpl res = new VarnodeTpl(location, new ConstTpl(getUniqueSpace()),
174+
new ConstTpl(ConstTpl.const_type.real, allocateTemp()),
175+
new ConstTpl(ConstTpl.const_type.real, 0));
178176
res.setUnnamed(true);
179177
return res;
180178
}
@@ -197,8 +195,7 @@ public VectorSTL<OpTpl> placeLabel(Location location, LabelSymbol labsym) {
197195
labsym.setPlaced();
198196
VectorSTL<OpTpl> res = new VectorSTL<OpTpl>();
199197
OpTpl op = new OpTpl(location, OpCode.CPUI_PTRADD);
200-
VarnodeTpl idvn = new VarnodeTpl(location,
201-
new ConstTpl(getConstantSpace()),
198+
VarnodeTpl idvn = new VarnodeTpl(location, new ConstTpl(getConstantSpace()),
202199
new ConstTpl(ConstTpl.const_type.real, labsym.getIndex()),
203200
new ConstTpl(ConstTpl.const_type.real, 4));
204201
op.addInput(idvn);
@@ -239,9 +236,8 @@ public void newLocalDefinition(Location location, String varname, int size) {
239236
if (size != 0) {
240237
tmpvn.setSize(new ConstTpl(ConstTpl.const_type.real, size)); // Size was explicitly specified
241238
}
242-
sym =
243-
new VarnodeSymbol(location, varname, tmpvn.getSpace().getSpace(),
244-
tmpvn.getOffset().getReal(), (int) tmpvn.getSize().getReal());
239+
sym = new VarnodeSymbol(location, varname, tmpvn.getSpace().getSpace(),
240+
tmpvn.getOffset().getReal(), (int) tmpvn.getSize().getReal());
245241
addSymbol(sym);
246242
}
247243

@@ -268,9 +264,8 @@ else if ((rhs.getSize().getType() == ConstTpl.const_type.real) &&
268264
// cannot build the VarnodeSymbol with a placeholder constant
269265
rhs.setOutput(location, tmpvn);
270266
// Create new symbol regardless
271-
sym =
272-
new VarnodeSymbol(location, varname, tmpvn.getSpace().getSpace(),
273-
tmpvn.getOffset().getReal(), (int) tmpvn.getSize().getReal());
267+
sym = new VarnodeSymbol(location, varname, tmpvn.getSpace().getSpace(),
268+
tmpvn.getOffset().getReal(), (int) tmpvn.getSize().getReal());
274269
addSymbol(sym);
275270
if ((!usesLocalKey) && enforceLocalKey) {
276271
reportError(location, "Must use 'local' keyword to define symbol '" + varname + "'");
@@ -369,9 +364,8 @@ public VectorSTL<OpTpl> createOpNoOut(Location location, OpCode opc, ExprTree vn
369364

370365
public VectorSTL<OpTpl> createOpConst(Location location, OpCode opc, long val) {
371366
entry("createOpConst", location, opc, val);
372-
VarnodeTpl vn =
373-
new VarnodeTpl(location, new ConstTpl(getConstantSpace()), new ConstTpl(
374-
ConstTpl.const_type.real, val), new ConstTpl(ConstTpl.const_type.real, 4));
367+
VarnodeTpl vn = new VarnodeTpl(location, new ConstTpl(getConstantSpace()),
368+
new ConstTpl(ConstTpl.const_type.real, val), new ConstTpl(ConstTpl.const_type.real, 4));
375369
VectorSTL<OpTpl> res = new VectorSTL<OpTpl>();
376370
OpTpl op = new OpTpl(location, opc);
377371
op.addInput(vn);
@@ -384,9 +378,8 @@ public ExprTree createLoad(Location location, StarQuality qual, ExprTree ptr) {
384378
entry("createLoad", location, qual, ptr);
385379
VarnodeTpl outvn = buildTemporary(location);
386380
OpTpl op = new OpTpl(location, OpCode.CPUI_LOAD);
387-
VarnodeTpl spcvn =
388-
new VarnodeTpl(location, new ConstTpl(getConstantSpace()), qual.getId(), new ConstTpl(
389-
ConstTpl.const_type.real, 8));
381+
VarnodeTpl spcvn = new VarnodeTpl(location, new ConstTpl(getConstantSpace()), qual.getId(),
382+
new ConstTpl(ConstTpl.const_type.real, 8));
390383
op.addInput(spcvn);
391384
op.addInput(ptr.outvn);
392385
op.setOutput(outvn);
@@ -406,9 +399,8 @@ public VectorSTL<OpTpl> createStore(Location location, StarQuality qual, ExprTre
406399
res.appendAll(val.ops);
407400
val.ops.clear();
408401
OpTpl op = new OpTpl(location, OpCode.CPUI_STORE);
409-
VarnodeTpl spcvn =
410-
new VarnodeTpl(location, new ConstTpl(getConstantSpace()), qual.getId(), new ConstTpl(
411-
ConstTpl.const_type.real, 8));
402+
VarnodeTpl spcvn = new VarnodeTpl(location, new ConstTpl(getConstantSpace()), qual.getId(),
403+
new ConstTpl(ConstTpl.const_type.real, 8));
412404
op.addInput(spcvn);
413405
op.addInput(ptr.outvn);
414406
op.addInput(val.outvn);
@@ -434,10 +426,9 @@ public VectorSTL<OpTpl> createUserOpNoOut(Location location, UserOpSymbol sym,
434426
VectorSTL<ExprTree> param) {
435427
entry("createUserOpNoOut", sym, param);
436428
OpTpl op = new OpTpl(location, OpCode.CPUI_CALLOTHER);
437-
VarnodeTpl vn =
438-
new VarnodeTpl(sym.location, new ConstTpl(getConstantSpace()), new ConstTpl(
439-
ConstTpl.const_type.real, sym.getIndex()),
440-
new ConstTpl(ConstTpl.const_type.real, 4));
429+
VarnodeTpl vn = new VarnodeTpl(sym.location, new ConstTpl(getConstantSpace()),
430+
new ConstTpl(ConstTpl.const_type.real, sym.getIndex()),
431+
new ConstTpl(ConstTpl.const_type.real, 4));
441432
op.addInput(vn);
442433
return ExprTree.appendParams(op, param);
443434
}
@@ -493,9 +484,8 @@ public VarnodeTpl buildTruncatedVarnode(Location loc, VarnodeTpl basevn, int bit
493484
// We put in the correct adjustment to offset assuming things are little endian
494485
// We defer the correct big endian calculation until after the consistency check
495486
// because we need to know the subtable export sizes
496-
specialoff =
497-
new ConstTpl(const_type.handle, basevn.getOffset().getHandleIndex(),
498-
v_field.v_offset_plus, byteoffset);
487+
specialoff = new ConstTpl(const_type.handle, basevn.getOffset().getHandleIndex(),
488+
v_field.v_offset_plus, byteoffset);
499489
}
500490
else {
501491
if (basevn.getSize().getType() != const_type.real) {
@@ -510,9 +500,8 @@ public VarnodeTpl buildTruncatedVarnode(Location loc, VarnodeTpl basevn, int bit
510500
}
511501
specialoff = new ConstTpl(const_type.real, basevn.getOffset().getReal() + plus);
512502
}
513-
VarnodeTpl res =
514-
new VarnodeTpl(loc, basevn.getSpace(), specialoff, new ConstTpl(const_type.real,
515-
numbytes));
503+
VarnodeTpl res = new VarnodeTpl(loc, basevn.getSpace(), specialoff,
504+
new ConstTpl(const_type.real, numbytes));
516505
return res;
517506
}
518507

@@ -521,10 +510,9 @@ public VarnodeTpl buildTruncatedVarnode(Location loc, VarnodeTpl basevn, int bit
521510
public void appendOp(Location location, OpCode opc, ExprTree res, long constval, int constsz) {
522511
entry("appendOp", location, opc, res, constval, constsz);
523512
OpTpl op = new OpTpl(location, opc);
524-
VarnodeTpl constvn =
525-
new VarnodeTpl(location, new ConstTpl(getConstantSpace()), new ConstTpl(
526-
ConstTpl.const_type.real, constval),
527-
new ConstTpl(ConstTpl.const_type.real, constsz));
513+
VarnodeTpl constvn = new VarnodeTpl(location, new ConstTpl(getConstantSpace()),
514+
new ConstTpl(ConstTpl.const_type.real, constval),
515+
new ConstTpl(ConstTpl.const_type.real, constsz));
528516
VarnodeTpl outvn = buildTemporary(location);
529517
op.addInput(res.outvn);
530518
op.addInput(constvn);
@@ -708,15 +696,13 @@ public VarnodeTpl addressOf(VarnodeTpl var, int size) {
708696
if ((var.getOffset().getType() == ConstTpl.const_type.real) &&
709697
(var.getSpace().getType() == ConstTpl.const_type.spaceid)) {
710698
AddrSpace spc = var.getSpace().getSpace();
711-
res =
712-
new VarnodeTpl(var.location, new ConstTpl(getConstantSpace()), new ConstTpl(
713-
ConstTpl.const_type.real, var.getOffset().getReal() >> spc.getScale()),
714-
new ConstTpl(ConstTpl.const_type.real, size));
699+
res = new VarnodeTpl(var.location, new ConstTpl(getConstantSpace()),
700+
new ConstTpl(ConstTpl.const_type.real, var.getOffset().getReal() >> spc.getScale()),
701+
new ConstTpl(ConstTpl.const_type.real, size));
715702
}
716703
else {
717-
res =
718-
new VarnodeTpl(var.location, new ConstTpl(getConstantSpace()), var.getOffset(),
719-
new ConstTpl(ConstTpl.const_type.real, size));
704+
res = new VarnodeTpl(var.location, new ConstTpl(getConstantSpace()), var.getOffset(),
705+
new ConstTpl(ConstTpl.const_type.real, size));
720706
}
721707
return res;
722708
}
@@ -898,7 +884,9 @@ public boolean propagateSize(ConstructTpl ct) {
898884
public static void entry(String name, Object... args) {
899885
StringBuilder sb = new StringBuilder();
900886
sb.append(name).append("(");
901-
sb.append(Arrays.stream(args).map(Object::toString).collect(Collectors.joining(", ")));
887+
sb.append(Arrays.stream(args)
888+
.map(x -> Objects.toString(x, "null"))
889+
.collect(Collectors.joining(", ")));
902890
sb.append(")");
903891

904892
log.trace(sb.toString());

0 commit comments

Comments
 (0)