@@ -84,15 +84,18 @@ func (fr *frame) evalBasicBlock(bb, incoming llvm.BasicBlock, indent string) (re
8484
8585 // Memory operators
8686 case ! inst .IsAAllocaInst ().IsNil ():
87- fr .locals [inst ] = & AllocaValue {
88- Underlying : getZeroValue (inst .Type ().ElementType ()),
89- Dirty : false ,
87+ allocType := inst .Type ().ElementType ()
88+ alloca := llvm .AddGlobal (fr .Mod , allocType , fr .pkgName + "$alloca" )
89+ alloca .SetInitializer (getZeroValue (allocType ))
90+ alloca .SetLinkage (llvm .InternalLinkage )
91+ fr .locals [inst ] = & LocalValue {
92+ Underlying : alloca ,
9093 Eval : fr .Eval ,
9194 }
9295 case ! inst .IsALoadInst ().IsNil ():
93- operand := fr .getLocal (inst .Operand (0 ))
96+ operand := fr .getLocal (inst .Operand (0 )).( * LocalValue )
9497 var value llvm.Value
95- if ! operand .IsConstant () || inst .IsVolatile () {
98+ if ! operand .IsConstant () || inst .IsVolatile () || operand . Underlying . Opcode () == llvm . BitCast {
9699 value = fr .builder .CreateLoad (operand .Value (), inst .Name ())
97100 } else {
98101 value = operand .Load ()
@@ -173,11 +176,8 @@ func (fr *frame) evalBasicBlock(bb, incoming llvm.BasicBlock, indent string) (re
173176 continue // special case: bitcast of alloc
174177 }
175178 }
176- value := fr .getLocal (operand )
177- if bc , ok := value .(* PointerCastValue ); ok {
178- value = bc .Underlying // avoid double bitcasts
179- }
180- fr .locals [inst ] = & PointerCastValue {Eval : fr .Eval , Underlying : value , CastType : inst .Type ()}
179+ value := fr .getLocal (operand ).(* LocalValue )
180+ fr .locals [inst ] = & LocalValue {fr .Eval , fr .builder .CreateBitCast (value .Value (), inst .Type (), "" )}
181181
182182 // Other operators
183183 case ! inst .IsAICmpInst ().IsNil ():
@@ -222,7 +222,7 @@ func (fr *frame) evalBasicBlock(bb, incoming llvm.BasicBlock, indent string) (re
222222 alloc := llvm .AddGlobal (fr .Mod , allocType , fr .pkgName + "$alloc" )
223223 alloc .SetInitializer (getZeroValue (allocType ))
224224 alloc .SetLinkage (llvm .InternalLinkage )
225- result := & GlobalValue {
225+ result := & LocalValue {
226226 Underlying : alloc ,
227227 Eval : fr .Eval ,
228228 }
@@ -246,15 +246,15 @@ func (fr *frame) evalBasicBlock(bb, incoming llvm.BasicBlock, indent string) (re
246246 m := fr .getLocal (inst .Operand (0 )).(* MapValue )
247247 // "key" is a Go string value, which in the TinyGo calling convention is split up
248248 // into separate pointer and length parameters.
249- keyBuf := fr .getLocal (inst .Operand (1 ))
250- keyLen := fr .getLocal (inst .Operand (2 ))
251- valPtr := fr .getLocal (inst .Operand (3 ))
249+ keyBuf := fr .getLocal (inst .Operand (1 )).( * LocalValue )
250+ keyLen := fr .getLocal (inst .Operand (2 )).( * LocalValue )
251+ valPtr := fr .getLocal (inst .Operand (3 )).( * LocalValue )
252252 m .PutString (keyBuf , keyLen , valPtr )
253253 case callee .Name () == "runtime.hashmapBinarySet" :
254254 // set a binary (int etc.) key in the map
255255 m := fr .getLocal (inst .Operand (0 )).(* MapValue )
256- keyBuf := fr .getLocal (inst .Operand (1 ))
257- valPtr := fr .getLocal (inst .Operand (2 ))
256+ keyBuf := fr .getLocal (inst .Operand (1 )).( * LocalValue )
257+ valPtr := fr .getLocal (inst .Operand (2 )).( * LocalValue )
258258 m .PutBinary (keyBuf , valPtr )
259259 case callee .Name () == "runtime.stringConcat" :
260260 // adding two strings together
0 commit comments