@@ -221,24 +221,30 @@ func (p *T) genBlockValues(name string, blk *ssa.BasicBlock) {
221221// genValueLoc may need to work recursively on struct and
222222// array typed structured data.
223223func (p * T ) genValueLoc (v ssa.Value ) memory.Loc {
224- defer func () {
225- if e := recover (); e != nil {
226- fmt .Printf ("oops %s (%#v)\n " , v , v )
227- os .Stdout .Sync ()
228- panic (e )
229- }
230- }()
231- p .buildr .Pos (v .Pos ()).GoType (v .Type ()).Class (memory .Local ).Attrs (memory .NoAttrs )
224+ if traceGenValueLoc {
225+ fmt .Printf ("genValue for %s (%#v)\n " , v , v )
226+ }
227+ switch v := v .(type ) {
228+ case * ssa.Range , * ssa.Const :
229+ fmt .Printf ("no loc for range or const at %p: %s\n " , v , v )
230+ return memory .NoLoc
231+ default :
232+ p .buildr .Pos (v .Pos ()).GoType (v .Type ()).Class (memory .Local ).Attrs (memory .NoAttrs )
233+ }
232234 var res memory.Loc
233235 switch v := v .(type ) {
234236 case * ssa.Alloc :
235- res = p .buildr .Gen ()
237+ if v .Heap {
238+ p .buildr .Class (memory .Global )
239+ }
240+ p .buildr .GoType (v .Type ().Underlying ().(* types.Pointer ).Elem ())
241+ _ , res = p .buildr .WithPointer ()
236242 case * ssa.MakeSlice :
237- res = p .buildr .Slice (v .Type ().(* types.Slice ),
243+ res = p .buildr .Slice (v .Type ().Underlying (). (* types.Slice ),
238244 p .indexing .Var (),
239245 p .indexing .Var ()).Loc ()
240246 case * ssa.MakeMap :
241- res = p .buildr .Map (v .Type ().(* types.Map )).Loc ()
247+ res = p .buildr .Map (v .Type ().Underlying (). (* types.Map )).Loc ()
242248
243249 case * ssa.Field :
244250 xloc , ok := p .vmap [v .X ]
@@ -275,7 +281,11 @@ func (p *T) genValueLoc(v ssa.Value) memory.Loc {
275281 // 5. create res = load(qa)
276282 // TBD:
277283
278- ty := v .Type ().Underlying ().(* types.Array )
284+ ty , ok := v .X .Type ().Underlying ().(* types.Array )
285+ if ! ok {
286+ panic (fmt .Sprintf ("v type %s %#v\n " , v .Type (), v .Type ()))
287+ }
288+
279289 eltTy := ty .Elem ()
280290 ptrTy := types .NewPointer (ty .Elem ())
281291 pelt := p .buildr .GoType (ptrTy ).Gen ()
@@ -291,13 +301,37 @@ func (p *T) genValueLoc(v ssa.Value) memory.Loc {
291301 if tloc == memory .NoLoc {
292302 tloc = p .genValueLoc (v .Tuple )
293303 // reset bld cfg for genLoc below
294- p .buildr .Pos ( v . Pos ()). GoType (v .Type ()). Class ( memory . Local ). Attrs ( memory . NoAttrs )
304+ p .buildr .GoType (v .Type ())
295305 }
296- t := p .buildr .Object (tloc ).(* objects.Tuple )
297- res = t .Field (v .Index )
298-
299- case * ssa.Const :
300- return memory .NoLoc
306+ tuple := p .buildr .Object (tloc ).(* objects.Tuple )
307+ res = tuple .At (v .Index )
308+
309+ case * ssa.Next :
310+ if v .IsString {
311+ tupty := types .NewTuple (
312+ types .NewVar (v .Pos (), nil , "#2" , types .Typ [types .Bool ]),
313+ types .NewVar (v .Pos (), nil , "#0" , types .Typ [types .Int ]),
314+ types .NewVar (v .Pos (), nil , "#1" , types .Typ [types .Rune ]))
315+ res = p .buildr .Tuple (tupty ).Loc ()
316+ p .vmap [v ] = res
317+ return res
318+ }
319+ iter := v .Iter .(* ssa.Range )
320+ rxloc := p .vmap [iter .X ]
321+ if rxloc == memory .NoLoc {
322+ rxloc = p .genValueLoc (iter .X )
323+ p .buildr .Pos (v .Pos ()).Class (memory .Local ).Attrs (memory .NoAttrs )
324+ }
325+ mgoty := iter .X .Type ().Underlying ().(* types.Map )
326+ m := p .buildr .Object (rxloc ).(* objects.Map )
327+ tupty := types .NewTuple (
328+ types .NewVar (v .Pos (), nil , "#0" , types .Typ [types .Bool ]),
329+ types .NewVar (v .Pos (), nil , "#1" , mgoty .Key ()),
330+ types .NewVar (v .Pos (), nil , "#2" , mgoty .Elem ()))
331+ tuple := p .buildr .Tuple (tupty )
332+ res = tuple .Loc ()
333+ p .buildr .AddTransfer (tuple .At (1 ), m .Key ())
334+ p .buildr .AddTransfer (tuple .At (2 ), m .Elem ())
301335
302336 default :
303337 switch ty := v .Type ().Underlying ().(type ) {
@@ -313,7 +347,17 @@ func (p *T) genValueLoc(v ssa.Value) memory.Loc {
313347 res = p .buildr .Map (ty ).Loc ()
314348 case * types.Signature :
315349 res = p .buildr .Func (ty , "" , memory .NoAttrs ).Loc ()
350+ case * types.Pointer :
351+ res = p .buildr .Pointer (ty ).Loc ()
352+ case * types.Basic :
353+ res = p .buildr .Gen ()
354+ case * types.Chan :
355+ res = p .buildr .Gen ()
356+ case * types.Interface :
357+ res = p .buildr .Gen ()
358+
316359 default :
360+ fmt .Printf ("genValueLoc: default switch ty: %s\n " , ty )
317361 res = p .buildr .Gen ()
318362 }
319363
0 commit comments