@@ -50,26 +50,26 @@ func Init() {
50
50
// Note: this has to be called explicitly instead of being
51
51
// an init function so it runs after the types package has
52
52
// been properly initialized.
53
- Type = fromReflect (reflect .TypeOf (abi.Type {}))
54
- ArrayType = fromReflect (reflect .TypeOf (abi.ArrayType {}))
55
- ChanType = fromReflect (reflect .TypeOf (abi.ChanType {}))
56
- FuncType = fromReflect (reflect .TypeOf (abi.FuncType {}))
57
- InterfaceType = fromReflect (reflect .TypeOf (abi.InterfaceType {}))
58
- OldMapType = fromReflect (reflect .TypeOf (abi.OldMapType {}))
59
- SwissMapType = fromReflect (reflect .TypeOf (abi.SwissMapType {}))
60
- PtrType = fromReflect (reflect .TypeOf (abi.PtrType {}))
61
- SliceType = fromReflect (reflect .TypeOf (abi.SliceType {}))
62
- StructType = fromReflect (reflect .TypeOf (abi.StructType {}))
53
+ Type = FromReflect (reflect .TypeOf (abi.Type {}))
54
+ ArrayType = FromReflect (reflect .TypeOf (abi.ArrayType {}))
55
+ ChanType = FromReflect (reflect .TypeOf (abi.ChanType {}))
56
+ FuncType = FromReflect (reflect .TypeOf (abi.FuncType {}))
57
+ InterfaceType = FromReflect (reflect .TypeOf (abi.InterfaceType {}))
58
+ OldMapType = FromReflect (reflect .TypeOf (abi.OldMapType {}))
59
+ SwissMapType = FromReflect (reflect .TypeOf (abi.SwissMapType {}))
60
+ PtrType = FromReflect (reflect .TypeOf (abi.PtrType {}))
61
+ SliceType = FromReflect (reflect .TypeOf (abi.SliceType {}))
62
+ StructType = FromReflect (reflect .TypeOf (abi.StructType {}))
63
63
64
- IMethod = fromReflect (reflect .TypeOf (abi.Imethod {}))
65
- Method = fromReflect (reflect .TypeOf (abi.Method {}))
66
- StructField = fromReflect (reflect .TypeOf (abi.StructField {}))
67
- UncommonType = fromReflect (reflect .TypeOf (abi.UncommonType {}))
64
+ IMethod = FromReflect (reflect .TypeOf (abi.Imethod {}))
65
+ Method = FromReflect (reflect .TypeOf (abi.Method {}))
66
+ StructField = FromReflect (reflect .TypeOf (abi.StructField {}))
67
+ UncommonType = FromReflect (reflect .TypeOf (abi.UncommonType {}))
68
68
69
- InterfaceSwitch = fromReflect (reflect .TypeOf (abi.InterfaceSwitch {}))
70
- TypeAssert = fromReflect (reflect .TypeOf (abi.TypeAssert {}))
69
+ InterfaceSwitch = FromReflect (reflect .TypeOf (abi.InterfaceSwitch {}))
70
+ TypeAssert = FromReflect (reflect .TypeOf (abi.TypeAssert {}))
71
71
72
- ITab = fromReflect (reflect .TypeOf (abi.ITab {}))
72
+ ITab = FromReflect (reflect .TypeOf (abi.ITab {}))
73
73
74
74
// Make sure abi functions are correct. These functions are used
75
75
// by the linker which doesn't have the ability to do type layout,
@@ -92,8 +92,8 @@ func Init() {
92
92
}
93
93
}
94
94
95
- // fromReflect translates from a host type to the equivalent target type.
96
- func fromReflect (rt reflect.Type ) * types.Type {
95
+ // FromReflect translates from a host type to the equivalent target type.
96
+ func FromReflect (rt reflect.Type ) * types.Type {
97
97
t := reflectToType (rt )
98
98
types .CalcSize (t )
99
99
return t
@@ -108,6 +108,10 @@ func reflectToType(rt reflect.Type) *types.Type {
108
108
return types .Types [types .TBOOL ]
109
109
case reflect .Int :
110
110
return types .Types [types .TINT ]
111
+ case reflect .Int8 :
112
+ return types .Types [types .TINT8 ]
113
+ case reflect .Int16 :
114
+ return types .Types [types .TINT16 ]
111
115
case reflect .Int32 :
112
116
return types .Types [types .TINT32 ]
113
117
case reflect .Uint8 :
@@ -116,9 +120,15 @@ func reflectToType(rt reflect.Type) *types.Type {
116
120
return types .Types [types .TUINT16 ]
117
121
case reflect .Uint32 :
118
122
return types .Types [types .TUINT32 ]
123
+ case reflect .Float32 :
124
+ return types .Types [types .TFLOAT32 ]
125
+ case reflect .Float64 :
126
+ return types .Types [types .TFLOAT64 ]
119
127
case reflect .Uintptr :
120
128
return types .Types [types .TUINTPTR ]
121
- case reflect .Ptr , reflect .Func , reflect .UnsafePointer :
129
+ case reflect .Ptr :
130
+ return types .NewPtr (reflectToType (rt .Elem ()))
131
+ case reflect .Func , reflect .UnsafePointer :
122
132
// TODO: there's no mechanism to distinguish different pointer types,
123
133
// so we treat them all as unsafe.Pointer.
124
134
return types .Types [types .TUNSAFEPTR ]
@@ -134,6 +144,12 @@ func reflectToType(rt reflect.Type) *types.Type {
134
144
fields [i ] = & types.Field {Sym : & types.Sym {Name : f .Name }, Type : ft }
135
145
}
136
146
return types .NewStruct (fields )
147
+ case reflect .Chan :
148
+ return types .NewChan (reflectToType (rt .Elem ()), types .ChanDir (rt .ChanDir ()))
149
+ case reflect .String :
150
+ return types .Types [types .TSTRING ]
151
+ case reflect .Complex128 :
152
+ return types .Types [types .TCOMPLEX128 ]
137
153
default :
138
154
base .Fatalf ("unhandled kind %s" , rt .Kind ())
139
155
return nil
@@ -155,7 +171,7 @@ func NewCursor(lsym *obj.LSym, off int64, t *types.Type) Cursor {
155
171
156
172
// WritePtr writes a pointer "target" to the component at the location specified by c.
157
173
func (c Cursor ) WritePtr (target * obj.LSym ) {
158
- if c .typ .Kind () != types .TUNSAFEPTR {
174
+ if c .typ .Kind () != types .TUNSAFEPTR && c . typ . Kind () != types . TPTR {
159
175
base .Fatalf ("can't write ptr, it has kind %s" , c .typ .Kind ())
160
176
}
161
177
if target == nil {
0 commit comments