Skip to content

Commit 5d9b2d7

Browse files
committed
move gotype memory loc generation to objects/builder
1 parent e5c6a3f commit 5d9b2d7

File tree

4 files changed

+36
-27
lines changed

4 files changed

+36
-27
lines changed

memory/model.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ func NewModel(index indexing.T) *Model {
5252
z.class = Zero
5353
z.parent = zz
5454
z.root = zz
55+
z.obj = z
56+
res.AddPointsTo(z, z)
5557
return res
5658
}
5759

objects/builder.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package objects
1616

1717
import (
18+
"fmt"
1819
"go/token"
1920
"go/types"
2021

@@ -228,6 +229,38 @@ func (b *Builder) Func(sig *types.Signature, declName string, opaque memory.Attr
228229
return fn
229230
}
230231

232+
func (b *Builder) FromGoType(gt types.Type) memory.Loc {
233+
var res memory.Loc
234+
switch ty := gt.Underlying().(type) {
235+
case *types.Tuple:
236+
res = b.Tuple(ty).Loc()
237+
case *types.Struct:
238+
res = b.Struct(ty).Loc()
239+
case *types.Array:
240+
res = b.Array(ty).Loc()
241+
case *types.Slice:
242+
res = b.Slice(ty, nil, nil).Loc()
243+
case *types.Map:
244+
res = b.Map(ty).Loc()
245+
case *types.Signature:
246+
res = b.Func(ty, "", memory.NoAttrs).Loc()
247+
case *types.Pointer:
248+
res = b.Pointer(ty).Loc()
249+
case *types.Chan:
250+
res = b.Chan(ty).Loc()
251+
case *types.Basic:
252+
res = b.Gen()
253+
case *types.Interface:
254+
res = b.Gen()
255+
256+
default:
257+
fmt.Printf("genValueLoc: default switch ty: %s\n", ty)
258+
res = b.Gen()
259+
}
260+
return res
261+
262+
}
263+
231264
// second pass to associate objects with all object like memory locations...
232265
// the input is likely to just create roots at variables, but we need objects
233266
// everywhere...

objects/func_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,4 @@ func TestFuncPlain(t *testing.T) {
4747
if err != nil {
4848
t.Error(err)
4949
}
50-
5150
}

ssa2pal/t.go

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -348,32 +348,7 @@ func (p *T) genValueLoc(v ssa.Value) memory.Loc {
348348
p.buildr.AddTransfer(tuple.At(2), m.Elem())
349349

350350
default:
351-
switch ty := v.Type().Underlying().(type) {
352-
case *types.Tuple:
353-
res = p.buildr.Tuple(ty).Loc()
354-
case *types.Struct:
355-
res = p.buildr.Struct(ty).Loc()
356-
case *types.Array:
357-
res = p.buildr.Array(ty).Loc()
358-
case *types.Slice:
359-
res = p.buildr.Slice(ty, nil, nil).Loc()
360-
case *types.Map:
361-
res = p.buildr.Map(ty).Loc()
362-
case *types.Signature:
363-
res = p.buildr.Func(ty, "", memory.NoAttrs).Loc()
364-
case *types.Pointer:
365-
res = p.buildr.Pointer(ty).Loc()
366-
case *types.Chan:
367-
res = p.buildr.Chan(ty).Loc()
368-
case *types.Basic:
369-
res = p.buildr.Gen()
370-
case *types.Interface:
371-
res = p.buildr.Gen()
372-
373-
default:
374-
fmt.Printf("genValueLoc: default switch ty: %s\n", ty)
375-
res = p.buildr.Gen()
376-
}
351+
res = p.buildr.FromGoType(v.Type())
377352

378353
}
379354
p.vmap[v] = res

0 commit comments

Comments
 (0)