@@ -173,7 +173,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
173
173
case 3 :
174
174
// Conditional branch: [cond, thenBB, elseBB]
175
175
lastBB = currentBB
176
- switch operands [0 ].Uint () {
176
+ switch operands [0 ].Uint (r ) {
177
177
case 1 : // true -> thenBB
178
178
currentBB = int (operands [1 ].(literalValue ).value .(uint32 ))
179
179
case 0 : // false -> elseBB
@@ -191,12 +191,12 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
191
191
}
192
192
case llvm .Switch :
193
193
// Switch statement: [value, defaultLabel, case0, label0, case1, label1, ...]
194
- value := operands [0 ].Uint ()
195
- targetLabel := operands [1 ].Uint () // default label
194
+ value := operands [0 ].Uint (r )
195
+ targetLabel := operands [1 ].Uint (r ) // default label
196
196
// Do a lazy switch by iterating over all cases.
197
197
for i := 2 ; i < len (operands ); i += 2 {
198
- if value == operands [i ].Uint () {
199
- targetLabel = operands [i + 1 ].Uint ()
198
+ if value == operands [i ].Uint (r ) {
199
+ targetLabel = operands [i + 1 ].Uint (r )
200
200
break
201
201
}
202
202
}
@@ -211,7 +211,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
211
211
// Select is much like a ternary operator: it picks a result from
212
212
// the second and third operand based on the boolean first operand.
213
213
var result value
214
- switch operands [0 ].Uint () {
214
+ switch operands [0 ].Uint (r ) {
215
215
case 1 :
216
216
result = operands [1 ]
217
217
case 0 :
@@ -282,7 +282,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
282
282
// by creating a global variable.
283
283
284
284
// Get the requested memory size to be allocated.
285
- size := operands [1 ].Uint ()
285
+ size := operands [1 ].Uint (r )
286
286
287
287
// Get the object layout, if it is available.
288
288
llvmLayoutType := r .getLLVMTypeFromLayout (operands [2 ])
@@ -318,9 +318,9 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
318
318
// memmove(dst, src, n*elemSize)
319
319
// return int(n)
320
320
// }
321
- dstLen := operands [3 ].Uint ()
322
- srcLen := operands [4 ].Uint ()
323
- elemSize := operands [5 ].Uint ()
321
+ dstLen := operands [3 ].Uint (r )
322
+ srcLen := operands [4 ].Uint (r )
323
+ elemSize := operands [5 ].Uint (r )
324
324
n := srcLen
325
325
if n > dstLen {
326
326
n = dstLen
@@ -374,7 +374,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
374
374
if err != nil {
375
375
return nil , mem , r .errorAt (inst , err )
376
376
}
377
- nBytes := uint32 (operands [3 ].Uint ())
377
+ nBytes := uint32 (operands [3 ].Uint (r ))
378
378
dstObj := mem .getWritable (dst .index ())
379
379
dstBuf := dstObj .buffer .asRawValue (r )
380
380
if mem .get (src .index ()).buffer == nil {
@@ -661,8 +661,8 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
661
661
// pointer into the underlying object.
662
662
var offset int64
663
663
for i := 1 ; i < len (operands ); i += 2 {
664
- index := operands [i ].Int ()
665
- elementSize := operands [i + 1 ].Int ()
664
+ index := operands [i ].Int (r )
665
+ elementSize := operands [i + 1 ].Int (r )
666
666
if elementSize < 0 {
667
667
// This is a struct field.
668
668
offset += index
@@ -677,7 +677,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
677
677
return nil , mem , r .errorAt (inst , err )
678
678
}
679
679
// GEP on fixed pointer value (for example, memory-mapped I/O).
680
- ptrValue := operands [0 ].Uint () + uint64 (offset )
680
+ ptrValue := operands [0 ].Uint (r ) + uint64 (offset )
681
681
locals [inst .localIndex ] = makeLiteralInt (ptrValue , int (operands [0 ].len (r )* 8 ))
682
682
continue
683
683
}
@@ -739,11 +739,11 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
739
739
var lhs , rhs float64
740
740
switch operands [0 ].len (r ) {
741
741
case 8 :
742
- lhs = math .Float64frombits (operands [0 ].Uint ())
743
- rhs = math .Float64frombits (operands [1 ].Uint ())
742
+ lhs = math .Float64frombits (operands [0 ].Uint (r ))
743
+ rhs = math .Float64frombits (operands [1 ].Uint (r ))
744
744
case 4 :
745
- lhs = float64 (math .Float32frombits (uint32 (operands [0 ].Uint ())))
746
- rhs = float64 (math .Float32frombits (uint32 (operands [1 ].Uint ())))
745
+ lhs = float64 (math .Float32frombits (uint32 (operands [0 ].Uint (r ))))
746
+ rhs = float64 (math .Float32frombits (uint32 (operands [1 ].Uint (r ))))
747
747
default :
748
748
panic ("unknown float type" )
749
749
}
@@ -782,23 +782,23 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
782
782
if inst .opcode == llvm .Add {
783
783
// This likely means this is part of a
784
784
// unsafe.Pointer(uintptr(ptr) + offset) pattern.
785
- lhsPtr , err = lhsPtr .addOffset (int64 (rhs .Uint ()))
785
+ lhsPtr , err = lhsPtr .addOffset (int64 (rhs .Uint (r )))
786
786
if err != nil {
787
787
return nil , mem , r .errorAt (inst , err )
788
788
}
789
789
locals [inst .localIndex ] = lhsPtr
790
- } else if inst .opcode == llvm .Xor && rhs .Uint () == 0 {
790
+ } else if inst .opcode == llvm .Xor && rhs .Uint (r ) == 0 {
791
791
// Special workaround for strings.noescape, see
792
792
// src/strings/builder.go in the Go source tree. This is
793
793
// the identity operator, so we can return the input.
794
794
locals [inst .localIndex ] = lhs
795
- } else if inst .opcode == llvm .And && rhs .Uint () < 8 {
795
+ } else if inst .opcode == llvm .And && rhs .Uint (r ) < 8 {
796
796
// This is probably part of a pattern to get the lower bits
797
797
// of a pointer for pointer tagging, like this:
798
798
// uintptr(unsafe.Pointer(t)) & 0b11
799
799
// We can actually support this easily by ANDing with the
800
800
// pointer offset.
801
- result := uint64 (lhsPtr .offset ()) & rhs .Uint ()
801
+ result := uint64 (lhsPtr .offset ()) & rhs .Uint (r )
802
802
locals [inst .localIndex ] = makeLiteralInt (result , int (lhs .len (r )* 8 ))
803
803
} else {
804
804
// Catch-all for weird operations that should just be done
@@ -813,31 +813,31 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
813
813
var result uint64
814
814
switch inst .opcode {
815
815
case llvm .Add :
816
- result = lhs .Uint () + rhs .Uint ()
816
+ result = lhs .Uint (r ) + rhs .Uint (r )
817
817
case llvm .Sub :
818
- result = lhs .Uint () - rhs .Uint ()
818
+ result = lhs .Uint (r ) - rhs .Uint (r )
819
819
case llvm .Mul :
820
- result = lhs .Uint () * rhs .Uint ()
820
+ result = lhs .Uint (r ) * rhs .Uint (r )
821
821
case llvm .UDiv :
822
- result = lhs .Uint () / rhs .Uint ()
822
+ result = lhs .Uint (r ) / rhs .Uint (r )
823
823
case llvm .SDiv :
824
- result = uint64 (lhs .Int () / rhs .Int ())
824
+ result = uint64 (lhs .Int (r ) / rhs .Int (r ))
825
825
case llvm .URem :
826
- result = lhs .Uint () % rhs .Uint ()
826
+ result = lhs .Uint (r ) % rhs .Uint (r )
827
827
case llvm .SRem :
828
- result = uint64 (lhs .Int () % rhs .Int ())
828
+ result = uint64 (lhs .Int (r ) % rhs .Int (r ))
829
829
case llvm .Shl :
830
- result = lhs .Uint () << rhs .Uint ()
830
+ result = lhs .Uint (r ) << rhs .Uint (r )
831
831
case llvm .LShr :
832
- result = lhs .Uint () >> rhs .Uint ()
832
+ result = lhs .Uint (r ) >> rhs .Uint (r )
833
833
case llvm .AShr :
834
- result = uint64 (lhs .Int () >> rhs .Uint ())
834
+ result = uint64 (lhs .Int (r ) >> rhs .Uint (r ))
835
835
case llvm .And :
836
- result = lhs .Uint () & rhs .Uint ()
836
+ result = lhs .Uint (r ) & rhs .Uint (r )
837
837
case llvm .Or :
838
- result = lhs .Uint () | rhs .Uint ()
838
+ result = lhs .Uint (r ) | rhs .Uint (r )
839
839
case llvm .Xor :
840
- result = lhs .Uint () ^ rhs .Uint ()
840
+ result = lhs .Uint (r ) ^ rhs .Uint (r )
841
841
default :
842
842
panic ("unreachable" )
843
843
}
@@ -855,11 +855,11 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
855
855
// and then truncating it as necessary.
856
856
var value uint64
857
857
if inst .opcode == llvm .SExt {
858
- value = uint64 (operands [0 ].Int ())
858
+ value = uint64 (operands [0 ].Int (r ))
859
859
} else {
860
- value = operands [0 ].Uint ()
860
+ value = operands [0 ].Uint (r )
861
861
}
862
- bitwidth := operands [1 ].Uint ()
862
+ bitwidth := operands [1 ].Uint (r )
863
863
if r .debug {
864
864
fmt .Fprintln (os .Stderr , indent + instructionNameMap [inst .opcode ]+ ":" , value , bitwidth )
865
865
}
@@ -868,11 +868,11 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
868
868
var value float64
869
869
switch inst .opcode {
870
870
case llvm .SIToFP :
871
- value = float64 (operands [0 ].Int ())
871
+ value = float64 (operands [0 ].Int (r ))
872
872
case llvm .UIToFP :
873
- value = float64 (operands [0 ].Uint ())
873
+ value = float64 (operands [0 ].Uint (r ))
874
874
}
875
- bitwidth := operands [1 ].Uint ()
875
+ bitwidth := operands [1 ].Uint (r )
876
876
if r .debug {
877
877
fmt .Fprintln (os .Stderr , indent + instructionNameMap [inst .opcode ]+ ":" , value , bitwidth )
878
878
}
@@ -918,21 +918,21 @@ func (r *runner) interpretICmp(lhs, rhs value, predicate llvm.IntPredicate) bool
918
918
}
919
919
return result
920
920
case llvm .IntUGT :
921
- return lhs .Uint () > rhs .Uint ()
921
+ return lhs .Uint (r ) > rhs .Uint (r )
922
922
case llvm .IntUGE :
923
- return lhs .Uint () >= rhs .Uint ()
923
+ return lhs .Uint (r ) >= rhs .Uint (r )
924
924
case llvm .IntULT :
925
- return lhs .Uint () < rhs .Uint ()
925
+ return lhs .Uint (r ) < rhs .Uint (r )
926
926
case llvm .IntULE :
927
- return lhs .Uint () <= rhs .Uint ()
927
+ return lhs .Uint (r ) <= rhs .Uint (r )
928
928
case llvm .IntSGT :
929
- return lhs .Int () > rhs .Int ()
929
+ return lhs .Int (r ) > rhs .Int (r )
930
930
case llvm .IntSGE :
931
- return lhs .Int () >= rhs .Int ()
931
+ return lhs .Int (r ) >= rhs .Int (r )
932
932
case llvm .IntSLT :
933
- return lhs .Int () < rhs .Int ()
933
+ return lhs .Int (r ) < rhs .Int (r )
934
934
case llvm .IntSLE :
935
- return lhs .Int () <= rhs .Int ()
935
+ return lhs .Int (r ) <= rhs .Int (r )
936
936
default :
937
937
// _should_ be unreachable, until LLVM adds new icmp operands (unlikely)
938
938
panic ("interp: unsupported icmp" )
0 commit comments