kecc::ir::dtype

Enum Dtype

Source
pub enum Dtype {
    Unit {
        is_const: bool,
    },
    Int {
        width: usize,
        is_signed: bool,
        is_const: bool,
    },
    Float {
        width: usize,
        is_const: bool,
    },
    Pointer {
        inner: Box<Dtype>,
        is_const: bool,
    },
    Array {
        inner: Box<Dtype>,
        size: usize,
    },
    Struct {
        name: Option<String>,
        fields: Option<Vec<Named<Dtype>>>,
        is_const: bool,
        size_align_offsets: Option<(usize, usize, Vec<usize>)>,
    },
    Function {
        ret: Box<Dtype>,
        params: Vec<Dtype>,
    },
    Typedef {
        name: String,
        is_const: bool,
    },
}
Expand description

TODO(document)

Variants§

§

Unit

TODO(document)

Fields

§is_const: bool

TODO(document)

§

Int

TODO(document)

Fields

§width: usize

TODO(document)

§is_signed: bool

TODO(document)

§is_const: bool

TODO(document)

§

Float

TODO(document)

Fields

§width: usize

TODO(document)

§is_const: bool

TODO(document)

§

Pointer

TODO(document)

Fields

§inner: Box<Dtype>

TODO(document)

§is_const: bool

TODO(document)

§

Array

TODO(document)

Fields

§inner: Box<Dtype>

TODO(document)

§size: usize

TODO(document)

§

Struct

TODO(document)

Fields

§name: Option<String>

TODO(document)

§fields: Option<Vec<Named<Dtype>>>

TODO(document)

§is_const: bool

TODO(document)

§size_align_offsets: Option<(usize, usize, Vec<usize>)>

TODO(document)

§

Function

TODO(document)

Fields

§ret: Box<Dtype>

TODO(document)

§params: Vec<Dtype>

TODO(document)

§

Typedef

TODO(document)

Fields

§name: String

TODO(document)

§is_const: bool

TODO(document)

Implementations§

Source§

impl Dtype

Source

pub const BITS_OF_BYTE: usize = 8usize

TODO(document)

Source

pub const SIZE_OF_BYTE: usize = 1usize

TODO(document)

Source

pub const SIZE_OF_POINTER: usize = 8usize

TODO(document)

Source

pub const SIZE_OF_CHAR: usize = 1usize

TODO(document)

Source

pub const SIZE_OF_SHORT: usize = 2usize

TODO(document)

Source

pub const SIZE_OF_INT: usize = 4usize

TODO(document)

Source

pub const SIZE_OF_LONG: usize = 8usize

TODO(document)

Source

pub const SIZE_OF_LONGLONG: usize = 8usize

TODO(document)

Source

pub const SIZE_OF_FLOAT: usize = 4usize

TODO(document)

Source

pub const SIZE_OF_DOUBLE: usize = 8usize

TODO(document)

Source

pub const BOOL: Self

TODO(document) A boolean value cannot be signed.

Source

pub const CHAR: Self

TODO(document)

Source

pub const SHORT: Self

TODO(document)

Source

pub const INT: Self

TODO(document)

Source

pub const LONG: Self

TODO(document)

Source

pub const LONGLONG: Self

TODO(document)

Source

pub const FLOAT: Self

TODO(document)

Source

pub const DOUBLE: Self

TODO(document)

Source

pub const fn unit() -> Self

TODO(document)

Source

pub const fn int(width: usize) -> Self

TODO(document)

Source

pub const fn float(width: usize) -> Self

TODO(document)

Source

pub fn pointer(inner: Dtype) -> Self

TODO(document)

Source

pub fn array(base_dtype: Dtype, size: usize) -> Self

TODO(document)

§Examples

Suppose the C declaration is int *a[2][3]. Then a’s ir::Dtype should be [2 x [3 x int*]]. But in the AST, it is parsed as Array(3, Array(2, Pointer(int))), reversing the order of 2 and 3. In the recursive translation of a declaration into Dtype, we need to insert 3 inside [2 * int*].

Source

pub fn structure(name: Option<String>, fields: Option<Vec<Named<Self>>>) -> Self

TODO(document)

Source

pub fn fill_size_align_offsets_of_struct( self, structs: &HashMap<String, Option<Dtype>>, ) -> Result<Self, DtypeError>

Source

pub fn function(ret: Dtype, params: Vec<Dtype>) -> Self

Source

pub fn typedef(name: String) -> Self

Source

pub fn get_int_width(&self) -> Option<usize>

Source

pub fn get_float_width(&self) -> Option<usize>

Source

pub fn get_pointer_inner(&self) -> Option<&Self>

Source

pub fn get_array_inner(&self) -> Option<&Self>

Source

pub fn get_struct_name(&self) -> Option<&Option<String>>

Source

pub fn get_struct_fields(&self) -> Option<&Option<Vec<Named<Self>>>>

Source

pub fn get_struct_size_align_offsets( &self, ) -> Option<&Option<(usize, usize, Vec<usize>)>>

Source

pub fn get_function_inner(&self) -> Option<(&Self, &Vec<Self>)>

Source

pub fn is_scalar(&self) -> bool

Source

pub fn is_int_signed(&self) -> bool

Source

pub fn is_const(&self) -> bool

Source

pub fn is_immutable(&self, structs: &HashMap<String, Option<Dtype>>) -> bool

Check if Dtype is constant. if it is constant, the variable of Dtype is not assignable.

Source

fn is_immutable_for_array_struct_field_inner( &self, structs: &HashMap<String, Option<Dtype>>, ) -> bool

Source

pub fn set_const(self, is_const: bool) -> Self

Source

pub fn size_align_of( &self, structs: &HashMap<String, Option<Dtype>>, ) -> Result<(usize, usize), DtypeError>

Source

pub fn get_offset_struct_field( &self, field_name: &str, structs: &HashMap<String, Option<Dtype>>, ) -> Option<(usize, Self)>

Source

pub fn set_signed(&self, is_signed: bool) -> Self

Source

pub fn try_from_ast_declaration_specifiers( specifiers: &[Node<DeclarationSpecifier>], ) -> Result<(Self, bool), DtypeError>

Derive a data type from declaration specifiers.

Source

pub fn try_from_ast_struct_declaration( declaration: &StructDeclaration, ) -> Result<Vec<Named<Self>>, DtypeError>

Derive a data type and its name from the struct declaration.

Source

pub fn with_ast_declarator( self, declarator: &Declarator, ) -> Result<Named<Self>, DtypeError>

Generate Dtype based on declarator and self which has a scalar type.

Let’s say declaration is const int * const * const a;. In general self start with const int which has a scalar type and declarator represents * const * const with ast::Declarator.

§Arguments
  • declarator - Parts requiring conversion to ‘Dtype’ on the declaration.
Source

pub fn with_ast_array_size( self, array_size: &ArraySize, ) -> Result<Self, DtypeError>

Generates Dtype based on declarator and self which has a scalar type.

Let’s say the AST declaration is int a[2][3]; self represents int [2]; and array_size is [3]. Then this function should return int [2][3].

§Arguments
  • array_size - the array size to add to self.
Source

pub fn resolve_typedefs( self, typedefs: &HashMap<String, Dtype>, ) -> Result<Self, DtypeError>

Source

pub fn resolve_structs( self, structs: &mut HashMap<String, Option<Dtype>>, tempid_counter: &mut usize, ) -> Result<Self, DtypeError>

If the struct type has a definition, it is saved to the struct table and transformed to a struct type with no definition.

Trait Implementations§

Source§

impl Clone for Dtype

Source§

fn clone(&self) -> Dtype

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Dtype

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Dtype

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Dtype

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for Dtype

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Dtype

Source§

fn eq(&self, other: &Dtype) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<&ParameterDeclaration> for Dtype

Source§

fn try_from(parameter_decl: &ParameterDeclaration) -> Result<Self, Self::Error>

Generate Dtype based on parameter declaration.

Source§

type Error = DtypeError

The type returned in the event of a conversion error.
Source§

impl TryFrom<&TypeName> for Dtype

Source§

fn try_from(type_name: &TypeName) -> Result<Self, Self::Error>

Derive a data type from type_name.

Source§

type Error = DtypeError

The type returned in the event of a conversion error.
Source§

impl TryFrom<BaseDtype> for Dtype

Source§

fn try_from(spec: BaseDtype) -> Result<Self, DtypeError>

Derive a data type containing scalar type from specifiers.

§Example

For declaration is const unsigned int * p, specifiers is const unsigned int, and the result is Dtype::Int { width: 4, is_signed: false, is_const: true }.

Source§

type Error = DtypeError

The type returned in the event of a conversion error.
Source§

impl TryFrom<Dtype> for DataSize

Source§

type Error = ()

The type returned in the event of a conversion error.
Source§

fn try_from(dtype: Dtype) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Dtype> for Declaration

Source§

fn try_from(dtype: Dtype) -> Result<Self, Self::Error>

Create an appropriate declaration according to dtype.

§Example

If int g = 0; is declared, dtype is ir::Dtype::Int{ width:32, is_signed:true, is_const:false }.

In this case, ir::Declaration::Variable{ dtype, initializer: Some(Constant::I32(1)) } is generated.

Conversely, if int foo(); is declared, dtype is ir::Dtype::Function{ret: Scalar(Int), params: []}. Thus, in this case, ir::Declaration::Function is generated.

Source§

type Error = DtypeError

The type returned in the event of a conversion error.
Source§

impl Eq for Dtype

Source§

impl StructuralPartialEq for Dtype

Auto Trait Implementations§

§

impl Freeze for Dtype

§

impl RefUnwindSafe for Dtype

§

impl Send for Dtype

§

impl Sync for Dtype

§

impl Unpin for Dtype

§

impl UnwindSafe for Dtype

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V