15
15
*/
16
16
package ghidra .pcodeCPort .slgh_compile ;
17
17
18
- import java .util .Arrays ;
19
- import java .util .List ;
18
+ import java .util .*;
20
19
import java .util .stream .Collectors ;
21
20
22
21
import org .apache .logging .log4j .LogManager ;
@@ -171,10 +170,9 @@ private void force_size(VarnodeTpl vt, ConstTpl size, VectorSTL<OpTpl> ops)
171
170
// Build temporary variable (with zerosize)
172
171
public VarnodeTpl buildTemporary (Location location ) {
173
172
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 ));
178
176
res .setUnnamed (true );
179
177
return res ;
180
178
}
@@ -197,8 +195,7 @@ public VectorSTL<OpTpl> placeLabel(Location location, LabelSymbol labsym) {
197
195
labsym .setPlaced ();
198
196
VectorSTL <OpTpl > res = new VectorSTL <OpTpl >();
199
197
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 ()),
202
199
new ConstTpl (ConstTpl .const_type .real , labsym .getIndex ()),
203
200
new ConstTpl (ConstTpl .const_type .real , 4 ));
204
201
op .addInput (idvn );
@@ -239,9 +236,8 @@ public void newLocalDefinition(Location location, String varname, int size) {
239
236
if (size != 0 ) {
240
237
tmpvn .setSize (new ConstTpl (ConstTpl .const_type .real , size )); // Size was explicitly specified
241
238
}
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 ());
245
241
addSymbol (sym );
246
242
}
247
243
@@ -268,9 +264,8 @@ else if ((rhs.getSize().getType() == ConstTpl.const_type.real) &&
268
264
// cannot build the VarnodeSymbol with a placeholder constant
269
265
rhs .setOutput (location , tmpvn );
270
266
// 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 ());
274
269
addSymbol (sym );
275
270
if ((!usesLocalKey ) && enforceLocalKey ) {
276
271
reportError (location , "Must use 'local' keyword to define symbol '" + varname + "'" );
@@ -369,9 +364,8 @@ public VectorSTL<OpTpl> createOpNoOut(Location location, OpCode opc, ExprTree vn
369
364
370
365
public VectorSTL <OpTpl > createOpConst (Location location , OpCode opc , long val ) {
371
366
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 ));
375
369
VectorSTL <OpTpl > res = new VectorSTL <OpTpl >();
376
370
OpTpl op = new OpTpl (location , opc );
377
371
op .addInput (vn );
@@ -384,9 +378,8 @@ public ExprTree createLoad(Location location, StarQuality qual, ExprTree ptr) {
384
378
entry ("createLoad" , location , qual , ptr );
385
379
VarnodeTpl outvn = buildTemporary (location );
386
380
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 ));
390
383
op .addInput (spcvn );
391
384
op .addInput (ptr .outvn );
392
385
op .setOutput (outvn );
@@ -406,9 +399,8 @@ public VectorSTL<OpTpl> createStore(Location location, StarQuality qual, ExprTre
406
399
res .appendAll (val .ops );
407
400
val .ops .clear ();
408
401
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 ));
412
404
op .addInput (spcvn );
413
405
op .addInput (ptr .outvn );
414
406
op .addInput (val .outvn );
@@ -434,10 +426,9 @@ public VectorSTL<OpTpl> createUserOpNoOut(Location location, UserOpSymbol sym,
434
426
VectorSTL <ExprTree > param ) {
435
427
entry ("createUserOpNoOut" , sym , param );
436
428
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 ));
441
432
op .addInput (vn );
442
433
return ExprTree .appendParams (op , param );
443
434
}
@@ -493,9 +484,8 @@ public VarnodeTpl buildTruncatedVarnode(Location loc, VarnodeTpl basevn, int bit
493
484
// We put in the correct adjustment to offset assuming things are little endian
494
485
// We defer the correct big endian calculation until after the consistency check
495
486
// 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 );
499
489
}
500
490
else {
501
491
if (basevn .getSize ().getType () != const_type .real ) {
@@ -510,9 +500,8 @@ public VarnodeTpl buildTruncatedVarnode(Location loc, VarnodeTpl basevn, int bit
510
500
}
511
501
specialoff = new ConstTpl (const_type .real , basevn .getOffset ().getReal () + plus );
512
502
}
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 ));
516
505
return res ;
517
506
}
518
507
@@ -521,10 +510,9 @@ public VarnodeTpl buildTruncatedVarnode(Location loc, VarnodeTpl basevn, int bit
521
510
public void appendOp (Location location , OpCode opc , ExprTree res , long constval , int constsz ) {
522
511
entry ("appendOp" , location , opc , res , constval , constsz );
523
512
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 ));
528
516
VarnodeTpl outvn = buildTemporary (location );
529
517
op .addInput (res .outvn );
530
518
op .addInput (constvn );
@@ -708,15 +696,13 @@ public VarnodeTpl addressOf(VarnodeTpl var, int size) {
708
696
if ((var .getOffset ().getType () == ConstTpl .const_type .real ) &&
709
697
(var .getSpace ().getType () == ConstTpl .const_type .spaceid )) {
710
698
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 ));
715
702
}
716
703
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 ));
720
706
}
721
707
return res ;
722
708
}
@@ -898,7 +884,9 @@ public boolean propagateSize(ConstructTpl ct) {
898
884
public static void entry (String name , Object ... args ) {
899
885
StringBuilder sb = new StringBuilder ();
900
886
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 (", " )));
902
890
sb .append (")" );
903
891
904
892
log .trace (sb .toString ());
0 commit comments