@@ -23,92 +23,13 @@ use option::is_some;
23
23
24
24
use ty_ctxt = middle:: ty:: ctxt;
25
25
26
- type nominal_id_ = { did : ast:: def_id , parent_id : Option < ast:: def_id > ,
27
- tps : ~[ ty:: t ] } ;
28
- type nominal_id = @nominal_id_ ;
29
-
30
- impl nominal_id_ : core:: cmp:: Eq {
31
- pure fn eq ( other : & nominal_id_ ) -> bool {
32
- if self . did != other. did ||
33
- self . parent_id != other. parent_id {
34
- false
35
- } else {
36
- do vec:: all2 ( self . tps , other. tps ) |m_tp, n_tp| {
37
- ty:: type_id ( m_tp) == ty:: type_id ( n_tp)
38
- }
39
- }
40
- }
41
- pure fn ne ( other : & nominal_id_ ) -> bool {
42
- ! ( self == * other)
43
- }
44
- }
45
-
46
- impl nominal_id_ : to_bytes:: IterBytes {
47
- pure fn iter_bytes ( lsb0 : bool , f : to_bytes:: Cb ) {
48
- to_bytes:: iter_bytes_2 ( & self . did , & self . parent_id , lsb0, f) ;
49
- for self . tps. each |t| {
50
- ty:: type_id ( * t) . iter_bytes ( lsb0, f) ;
51
- }
52
- }
53
- }
54
-
55
- fn mk_nominal_id ( tcx : ty:: ctxt , did : ast:: def_id ,
56
- parent_id : Option < ast:: def_id > ,
57
- tps : ~[ ty:: t ] ) -> nominal_id {
58
- let tps_norm = tps. map ( |t| ty:: normalize_ty ( tcx, * t) ) ;
59
- @{ did: did, parent_id: parent_id, tps: tps_norm}
60
- }
61
-
62
- fn new_nominal_id_hash < T : Copy > ( ) -> HashMap < nominal_id , T > {
63
- return HashMap ( ) ;
64
- }
65
-
66
- type enum_data = { did : ast:: def_id , substs : ty:: substs } ;
67
-
68
- type ctxt =
69
- { mut next_tag_id : u16 ,
70
- pad : u16 ,
71
- tag_id_to_index : HashMap < nominal_id , u16 > ,
72
- tag_order : DVec < enum_data > ,
73
- resources : interner:: interner < nominal_id > ,
74
- llshapetablesty : TypeRef ,
75
- llshapetables : ValueRef } ;
76
-
77
- const shape_u8: u8 = 0u8 ;
78
- const shape_u16: u8 = 1u8 ;
79
- const shape_u32: u8 = 2u8 ;
80
- const shape_u64: u8 = 3u8 ;
81
- const shape_i8: u8 = 4u8 ;
82
- const shape_i16: u8 = 5u8 ;
83
- const shape_i32: u8 = 6u8 ;
84
- const shape_i64: u8 = 7u8 ;
85
- const shape_f32: u8 = 8u8 ;
86
- const shape_f64: u8 = 9u8 ;
87
- const shape_box: u8 = 10u8 ;
88
- const shape_enum: u8 = 12u8 ;
89
- const shape_struct: u8 = 17u8 ;
90
- const shape_box_fn: u8 = 18u8 ;
91
- const shape_res: u8 = 20u8 ;
92
- const shape_uniq: u8 = 22u8 ;
93
- const shape_opaque_closure_ptr: u8 = 23u8 ; // the closure itself.
94
- const shape_uniq_fn: u8 = 25u8 ;
95
- const shape_stack_fn: u8 = 26u8 ;
96
- const shape_bare_fn: u8 = 27u8 ;
97
- const shape_tydesc: u8 = 28u8 ;
98
- const shape_send_tydesc: u8 = 29u8 ;
99
- const shape_rptr: u8 = 31u8 ;
100
- const shape_fixedvec: u8 = 32u8 ;
101
- const shape_slice: u8 = 33u8 ;
102
- const shape_unboxed_vec: u8 = 34u8 ;
26
+ type ctxt = { mut next_tag_id : u16 , pad : u16 , pad2 : u32 } ;
103
27
104
28
fn mk_global ( ccx : @crate_ctxt , name : ~str , llval : ValueRef , internal : bool ) ->
105
29
ValueRef {
106
- let llglobal =
107
- str:: as_c_str ( name,
108
- |buf| {
109
- lib:: llvm:: llvm:: LLVMAddGlobal ( ccx. llmod ,
110
- val_ty ( llval) , buf)
111
- } ) ;
30
+ let llglobal = do str:: as_c_str ( name) |buf| {
31
+ lib:: llvm:: llvm:: LLVMAddGlobal ( ccx. llmod , val_ty ( llval) , buf)
32
+ } ;
112
33
lib:: llvm:: llvm:: LLVMSetInitializer ( llglobal, llval) ;
113
34
lib:: llvm:: llvm:: LLVMSetGlobalConstant ( llglobal, True ) ;
114
35
@@ -119,91 +40,13 @@ fn mk_global(ccx: @crate_ctxt, name: ~str, llval: ValueRef, internal: bool) ->
119
40
return llglobal;
120
41
}
121
42
122
-
123
- // Computes a set of variants of a enum that are guaranteed to have size and
124
- // alignment at least as large as any other variant of the enum. This is an
125
- // important performance optimization.
126
-
127
- fn round_up ( size : u16 , align : u8 ) -> u16 {
128
- assert ( align >= 1u8 ) ;
129
- let alignment = align as u16 ;
130
- return size - 1u16 + alignment & !( alignment - 1u16 ) ;
131
- }
132
-
133
- type size_align = { size : u16 , align : u8 } ;
134
-
135
- enum enum_kind {
136
- tk_unit, // 1 variant, no data
137
- tk_enum, // N variants, no data
138
- tk_newtype, // 1 variant, data
139
- tk_complex // N variants, no data
140
- }
141
-
142
- fn enum_kind ( ccx : @crate_ctxt , did : ast:: def_id ) -> enum_kind {
143
- let variants = ty:: enum_variants ( ccx. tcx , did) ;
144
- if vec:: any ( * variants, |v| vec:: len ( v. args ) > 0 u) {
145
- if vec:: len ( * variants) == 1 u { tk_newtype }
146
- else { tk_complex }
147
- } else {
148
- if vec:: len ( * variants) <= 1 u { tk_unit }
149
- else { tk_enum }
150
- }
151
- }
152
-
153
- // Returns the code corresponding to the pointer size on this architecture.
154
- fn s_int ( tcx : ty_ctxt ) -> u8 {
155
- return match tcx. sess . targ_cfg . arch {
156
- session:: arch_x86 => shape_i32,
157
- session:: arch_x86_64 => shape_i64,
158
- session:: arch_arm => shape_i32
159
- } ;
160
- }
161
-
162
- fn s_uint ( tcx : ty_ctxt ) -> u8 {
163
- return match tcx. sess . targ_cfg . arch {
164
- session:: arch_x86 => shape_u32,
165
- session:: arch_x86_64 => shape_u64,
166
- session:: arch_arm => shape_u32
167
- } ;
168
- }
169
-
170
- fn s_float ( tcx : ty_ctxt ) -> u8 {
171
- return match tcx. sess . targ_cfg . arch {
172
- session:: arch_x86 => shape_f64,
173
- session:: arch_x86_64 => shape_f64,
174
- session:: arch_arm => shape_f64
175
- } ;
176
- }
177
-
178
- fn s_variant_enum_t ( tcx : ty_ctxt ) -> u8 {
179
- return s_int ( tcx) ;
180
- }
181
-
182
- fn s_tydesc ( _tcx : ty_ctxt ) -> u8 {
183
- return shape_tydesc;
184
- }
185
-
186
- fn s_send_tydesc ( _tcx : ty_ctxt ) -> u8 {
187
- return shape_send_tydesc;
188
- }
189
-
190
43
fn mk_ctxt ( llmod : ModuleRef ) -> ctxt {
191
44
let llshapetablesty = trans:: common:: T_named_struct ( ~"shapes") ;
192
- let llshapetables = str:: as_c_str ( ~"shapes", |buf| {
45
+ let _llshapetables = str:: as_c_str ( ~"shapes", |buf| {
193
46
lib:: llvm:: llvm:: LLVMAddGlobal ( llmod, llshapetablesty, buf)
194
47
} ) ;
195
48
196
- return { mut next_tag_id: 0u16 ,
197
- pad: 0u16 ,
198
- tag_id_to_index: new_nominal_id_hash ( ) ,
199
- tag_order: DVec ( ) ,
200
- resources: interner:: mk ( ) ,
201
- llshapetablesty: llshapetablesty,
202
- llshapetables: llshapetables} ;
203
- }
204
-
205
- fn add_bool ( & dest: ~[ u8 ] , val : bool ) {
206
- dest += ~[ if val { 1u8 } else { 0u8 } ] ;
49
+ return { mut next_tag_id: 0u16 , pad: 0u16 , pad2: 0u32 } ;
207
50
}
208
51
209
52
fn add_u16 ( & dest: ~[ u8 ] , val : u16 ) {
0 commit comments