Skip to content

Commit f537564

Browse files
authored
Merge pull request #148 from rust-lang/feature/packed-struct
Feature/packed struct
2 parents 76cf7c2 + 927eea3 commit f537564

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/type_.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,18 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
115115
self.context.new_function_pointer_type(None, return_type, params, false)
116116
}
117117

118-
fn type_struct(&self, fields: &[Type<'gcc>], _packed: bool) -> Type<'gcc> {
118+
fn type_struct(&self, fields: &[Type<'gcc>], packed: bool) -> Type<'gcc> {
119119
let types = fields.to_vec();
120120
if let Some(typ) = self.struct_types.borrow().get(fields) {
121121
return typ.clone();
122122
}
123123
let fields: Vec<_> = fields.iter().enumerate()
124124
.map(|(index, field)| self.context.new_field(None, *field, &format!("field{}_TODO", index)))
125125
.collect();
126-
// TODO(antoyo): use packed.
127126
let typ = self.context.new_struct_type(None, "struct", &fields).as_type();
127+
if packed {
128+
typ.set_packed();
129+
}
128130
self.struct_types.borrow_mut().insert(types, typ);
129131
typ
130132
}
@@ -209,12 +211,14 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
209211
self.type_array(self.type_from_integer(unit), size / unit_size)
210212
}
211213

212-
pub fn set_struct_body(&self, typ: Struct<'gcc>, fields: &[Type<'gcc>], _packed: bool) {
213-
// TODO(antoyo): use packed.
214+
pub fn set_struct_body(&self, typ: Struct<'gcc>, fields: &[Type<'gcc>], packed: bool) {
214215
let fields: Vec<_> = fields.iter().enumerate()
215216
.map(|(index, field)| self.context.new_field(None, *field, &format!("field_{}", index)))
216217
.collect();
217218
typ.set_fields(None, &fields);
219+
if packed {
220+
typ.as_type().set_packed();
221+
}
218222
}
219223

220224
pub fn type_named_struct(&self, name: &str) -> Struct<'gcc> {

0 commit comments

Comments
 (0)