Merge pull request #148 from rust-lang/feature/packed-struct

Feature/packed struct
This commit is contained in:
antoyo 2022-03-30 09:55:30 -04:00 committed by GitHub
commit f537564454
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -115,7 +115,7 @@ fn type_func(&self, params: &[Type<'gcc>], return_type: Type<'gcc>) -> Type<'gcc
self.context.new_function_pointer_type(None, return_type, params, false)
}
fn type_struct(&self, fields: &[Type<'gcc>], _packed: bool) -> Type<'gcc> {
fn type_struct(&self, fields: &[Type<'gcc>], packed: bool) -> Type<'gcc> {
let types = fields.to_vec();
if let Some(typ) = self.struct_types.borrow().get(fields) {
return typ.clone();
@ -123,8 +123,10 @@ fn type_struct(&self, fields: &[Type<'gcc>], _packed: bool) -> Type<'gcc> {
let fields: Vec<_> = fields.iter().enumerate()
.map(|(index, field)| self.context.new_field(None, *field, &format!("field{}_TODO", index)))
.collect();
// TODO(antoyo): use packed.
let typ = self.context.new_struct_type(None, "struct", &fields).as_type();
if packed {
typ.set_packed();
}
self.struct_types.borrow_mut().insert(types, typ);
typ
}
@ -209,12 +211,14 @@ pub fn type_padding_filler(&self, size: Size, align: Align) -> Type<'gcc> {
self.type_array(self.type_from_integer(unit), size / unit_size)
}
pub fn set_struct_body(&self, typ: Struct<'gcc>, fields: &[Type<'gcc>], _packed: bool) {
// TODO(antoyo): use packed.
pub fn set_struct_body(&self, typ: Struct<'gcc>, fields: &[Type<'gcc>], packed: bool) {
let fields: Vec<_> = fields.iter().enumerate()
.map(|(index, field)| self.context.new_field(None, *field, &format!("field_{}", index)))
.collect();
typ.set_fields(None, &fields);
if packed {
typ.as_type().set_packed();
}
}
pub fn type_named_struct(&self, name: &str) -> Struct<'gcc> {