@@ -346,16 +346,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
346
346
dstObj .buffer = dstBuf
347
347
mem .put (dst .index (), dstObj )
348
348
}
349
- switch inst .llvmInst .Type ().IntTypeWidth () {
350
- case 16 :
351
- locals [inst .localIndex ] = literalValue {uint16 (n )}
352
- case 32 :
353
- locals [inst .localIndex ] = literalValue {uint32 (n )}
354
- case 64 :
355
- locals [inst .localIndex ] = literalValue {uint64 (n )}
356
- default :
357
- panic ("unknown integer type width" )
358
- }
349
+ locals [inst .localIndex ] = makeLiteralInt (n , inst .llvmInst .Type ().IntTypeWidth ())
359
350
case strings .HasPrefix (callFn .name , "llvm.memcpy.p0" ) || strings .HasPrefix (callFn .name , "llvm.memmove.p0" ):
360
351
// Copy a block of memory from one pointer to another.
361
352
dst , err := operands [1 ].asPointer (r )
@@ -647,16 +638,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
647
638
}
648
639
// GEP on fixed pointer value (for example, memory-mapped I/O).
649
640
ptrValue := operands [0 ].Uint () + offset
650
- switch operands [0 ].len (r ) {
651
- case 8 :
652
- locals [inst .localIndex ] = literalValue {uint64 (ptrValue )}
653
- case 4 :
654
- locals [inst .localIndex ] = literalValue {uint32 (ptrValue )}
655
- case 2 :
656
- locals [inst .localIndex ] = literalValue {uint16 (ptrValue )}
657
- default :
658
- panic ("pointer operand is not of a known pointer size" )
659
- }
641
+ locals [inst .localIndex ] = makeLiteralInt (ptrValue , int (operands [0 ].len (r )* 8 ))
660
642
continue
661
643
}
662
644
ptr = ptr .addOffset (int64 (offset ))
@@ -810,18 +792,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
810
792
default :
811
793
panic ("unreachable" )
812
794
}
813
- switch lhs .len (r ) {
814
- case 8 :
815
- locals [inst .localIndex ] = literalValue {result }
816
- case 4 :
817
- locals [inst .localIndex ] = literalValue {uint32 (result )}
818
- case 2 :
819
- locals [inst .localIndex ] = literalValue {uint16 (result )}
820
- case 1 :
821
- locals [inst .localIndex ] = literalValue {uint8 (result )}
822
- default :
823
- panic ("unknown integer size" )
824
- }
795
+ locals [inst .localIndex ] = makeLiteralInt (result , int (lhs .len (r )* 8 ))
825
796
if r .debug {
826
797
fmt .Fprintln (os .Stderr , indent + instructionNameMap [inst .opcode ]+ ":" , lhs , rhs , "->" , result )
827
798
}
@@ -843,18 +814,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
843
814
if r .debug {
844
815
fmt .Fprintln (os .Stderr , indent + instructionNameMap [inst .opcode ]+ ":" , value , bitwidth )
845
816
}
846
- switch bitwidth {
847
- case 64 :
848
- locals [inst .localIndex ] = literalValue {value }
849
- case 32 :
850
- locals [inst .localIndex ] = literalValue {uint32 (value )}
851
- case 16 :
852
- locals [inst .localIndex ] = literalValue {uint16 (value )}
853
- case 8 :
854
- locals [inst .localIndex ] = literalValue {uint8 (value )}
855
- default :
856
- panic ("unknown integer size in sext/zext/trunc" )
857
- }
817
+ locals [inst .localIndex ] = makeLiteralInt (value , int (bitwidth ))
858
818
case llvm .SIToFP , llvm .UIToFP :
859
819
var value float64
860
820
switch inst .opcode {
0 commit comments