Merge pull request #148 from rust-lang/feature/packed-struct
Feature/packed struct
This commit is contained in:
commit
f537564454
12
src/type_.rs
12
src/type_.rs
@ -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> {
|
||||
|
Loading…
Reference in New Issue
Block a user