@@ -84,15 +84,18 @@ func (fr *frame) evalBasicBlock(bb, incoming llvm.BasicBlock, indent string) (re
84
84
85
85
// Memory operators
86
86
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 ,
90
93
Eval : fr .Eval ,
91
94
}
92
95
case ! inst .IsALoadInst ().IsNil ():
93
- operand := fr .getLocal (inst .Operand (0 ))
96
+ operand := fr .getLocal (inst .Operand (0 )).( * LocalValue )
94
97
var value llvm.Value
95
- if ! operand .IsConstant () || inst .IsVolatile () {
98
+ if ! operand .IsConstant () || inst .IsVolatile () || operand . Underlying . Opcode () == llvm . BitCast {
96
99
value = fr .builder .CreateLoad (operand .Value (), inst .Name ())
97
100
} else {
98
101
value = operand .Load ()
@@ -173,11 +176,8 @@ func (fr *frame) evalBasicBlock(bb, incoming llvm.BasicBlock, indent string) (re
173
176
continue // special case: bitcast of alloc
174
177
}
175
178
}
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 (), "" )}
181
181
182
182
// Other operators
183
183
case ! inst .IsAICmpInst ().IsNil ():
@@ -222,7 +222,7 @@ func (fr *frame) evalBasicBlock(bb, incoming llvm.BasicBlock, indent string) (re
222
222
alloc := llvm .AddGlobal (fr .Mod , allocType , fr .pkgName + "$alloc" )
223
223
alloc .SetInitializer (getZeroValue (allocType ))
224
224
alloc .SetLinkage (llvm .InternalLinkage )
225
- result := & GlobalValue {
225
+ result := & LocalValue {
226
226
Underlying : alloc ,
227
227
Eval : fr .Eval ,
228
228
}
@@ -246,15 +246,15 @@ func (fr *frame) evalBasicBlock(bb, incoming llvm.BasicBlock, indent string) (re
246
246
m := fr .getLocal (inst .Operand (0 )).(* MapValue )
247
247
// "key" is a Go string value, which in the TinyGo calling convention is split up
248
248
// 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 )
252
252
m .PutString (keyBuf , keyLen , valPtr )
253
253
case callee .Name () == "runtime.hashmapBinarySet" :
254
254
// set a binary (int etc.) key in the map
255
255
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 )
258
258
m .PutBinary (keyBuf , valPtr )
259
259
case callee .Name () == "runtime.stringConcat" :
260
260
// adding two strings together
0 commit comments