for !data.Type.IsPtr() {
switch {
case data.Type.IsArray():
- data = s.newValue1I(ssa.OpArrayIndex, data.Type.Elem(), 0, data)
+ data = s.newValue1I(ssa.OpArrayIndex, data.Type.ElemType(), 0, data)
case data.Type.IsStruct():
for i := data.Type.NumFields() - 1; i >= 0; i-- {
f := data.Type.FieldType(i)
return t.Etype == TINTER
}
-func (t *Type) Elem() ssa.Type {
- return t.Type
+func (t *Type) ElemType() ssa.Type {
+ switch t.Etype {
+ case TARRAY, TPTR32, TPTR64:
+ return t.Type
+ }
+ panic(fmt.Sprintf("ElemType on invalid type %v", t))
}
func (t *Type) PtrTo() ssa.Type {
return Ptrto(t)
v.SetArgs1(v.Args[2])
} else {
// zero addr mem
- sz := v.Args[0].Type.Elem().Size()
+ sz := v.Args[0].Type.ElemType().Size()
if v.AuxInt != sz {
f.Fatalf("mismatched zero/store sizes: %d and %d [%s]",
v.AuxInt, sz, v.LongString())
// indexing operations
// Note: bounds check has already been done
(ArrayIndex <t> [0] (Load ptr mem)) -> @v.Args[0].Block (Load <t> ptr mem)
-(PtrIndex <t> ptr idx) && config.PtrSize == 4 -> (AddPtr ptr (Mul32 <config.fe.TypeInt()> idx (Const32 <config.fe.TypeInt()> [t.Elem().Size()])))
-(PtrIndex <t> ptr idx) && config.PtrSize == 8 -> (AddPtr ptr (Mul64 <config.fe.TypeInt()> idx (Const64 <config.fe.TypeInt()> [t.Elem().Size()])))
+(PtrIndex <t> ptr idx) && config.PtrSize == 4 -> (AddPtr ptr (Mul32 <config.fe.TypeInt()> idx (Const32 <config.fe.TypeInt()> [t.ElemType().Size()])))
+(PtrIndex <t> ptr idx) && config.PtrSize == 8 -> (AddPtr ptr (Mul64 <config.fe.TypeInt()> idx (Const64 <config.fe.TypeInt()> [t.ElemType().Size()])))
// struct operations
(StructSelect (StructMake1 x)) -> x
_ = b
// match: (PtrIndex <t> ptr idx)
// cond: config.PtrSize == 4
- // result: (AddPtr ptr (Mul32 <config.fe.TypeInt()> idx (Const32 <config.fe.TypeInt()> [t.Elem().Size()])))
+ // result: (AddPtr ptr (Mul32 <config.fe.TypeInt()> idx (Const32 <config.fe.TypeInt()> [t.ElemType().Size()])))
for {
t := v.Type
ptr := v.Args[0]
v0 := b.NewValue0(v.Line, OpMul32, config.fe.TypeInt())
v0.AddArg(idx)
v1 := b.NewValue0(v.Line, OpConst32, config.fe.TypeInt())
- v1.AuxInt = t.Elem().Size()
+ v1.AuxInt = t.ElemType().Size()
v0.AddArg(v1)
v.AddArg(v0)
return true
}
// match: (PtrIndex <t> ptr idx)
// cond: config.PtrSize == 8
- // result: (AddPtr ptr (Mul64 <config.fe.TypeInt()> idx (Const64 <config.fe.TypeInt()> [t.Elem().Size()])))
+ // result: (AddPtr ptr (Mul64 <config.fe.TypeInt()> idx (Const64 <config.fe.TypeInt()> [t.ElemType().Size()])))
for {
t := v.Type
ptr := v.Args[0]
v0 := b.NewValue0(v.Line, OpMul64, config.fe.TypeInt())
v0.AddArg(idx)
v1 := b.NewValue0(v.Line, OpConst64, config.fe.TypeInt())
- v1.AuxInt = t.Elem().Size()
+ v1.AuxInt = t.ElemType().Size()
v0.AddArg(v1)
v.AddArg(v0)
return true
IsFlags() bool
IsVoid() bool
- Elem() Type // given []T or *T or [n]T, return T
- PtrTo() Type // given T, return *T
+ ElemType() Type // given []T or *T or [n]T, return T
+ PtrTo() Type // given T, return *T
NumFields() int64 // # of fields of a struct
FieldType(i int64) Type // type of ith field of the struct
func (t *CompilerType) IsVoid() bool { return t.Void }
func (t *CompilerType) String() string { return t.Name }
func (t *CompilerType) SimpleString() string { return t.Name }
-func (t *CompilerType) Elem() Type { panic("not implemented") }
+func (t *CompilerType) ElemType() Type { panic("not implemented") }
func (t *CompilerType) PtrTo() Type { panic("not implemented") }
func (t *CompilerType) NumFields() int64 { panic("not implemented") }
func (t *CompilerType) FieldType(i int64) Type { panic("not implemented") }
func (t *TypeImpl) IsVoid() bool { return false }
func (t *TypeImpl) String() string { return t.Name }
func (t *TypeImpl) SimpleString() string { return t.Name }
-func (t *TypeImpl) Elem() Type { return t.Elem_ }
+func (t *TypeImpl) ElemType() Type { return t.Elem_ }
func (t *TypeImpl) PtrTo() Type { panic("not implemented") }
func (t *TypeImpl) NumFields() int64 { panic("not implemented") }
func (t *TypeImpl) FieldType(i int64) Type { panic("not implemented") }