forked from M-Labs/nac3
LenKind -> ArrayLen
This commit is contained in:
parent
4e714cb53b
commit
88b51acd0e
@ -11,7 +11,7 @@ use crate::codegen::{CodeGenContext, CodeGenerator};
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
/// Trait for Rust structs identifying length values for [`Array`].
|
/// Trait for Rust structs identifying length values for [`Array`].
|
||||||
pub trait LenKind: fmt::Debug + Clone + Copy {
|
pub trait ArrayLen: fmt::Debug + Clone + Copy {
|
||||||
fn get_length(&self) -> u32;
|
fn get_length(&self) -> u32;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,13 +23,13 @@ pub struct Len<const N: u32>;
|
|||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct AnyLen(pub u32);
|
pub struct AnyLen(pub u32);
|
||||||
|
|
||||||
impl<const N: u32> LenKind for Len<N> {
|
impl<const N: u32> ArrayLen for Len<N> {
|
||||||
fn get_length(&self) -> u32 {
|
fn get_length(&self) -> u32 {
|
||||||
N
|
N
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LenKind for AnyLen {
|
impl ArrayLen for AnyLen {
|
||||||
fn get_length(&self) -> u32 {
|
fn get_length(&self) -> u32 {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
@ -46,7 +46,7 @@ pub struct Array<Len, Item> {
|
|||||||
pub item: Item,
|
pub item: Item,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'ctx, Len: LenKind, Item: ModelBase<'ctx>> ModelBase<'ctx> for Array<Len, Item> {
|
impl<'ctx, Len: ArrayLen, Item: ModelBase<'ctx>> ModelBase<'ctx> for Array<Len, Item> {
|
||||||
fn get_type_impl(&self, size_t: IntType<'ctx>, ctx: &'ctx Context) -> BasicTypeEnum<'ctx> {
|
fn get_type_impl(&self, size_t: IntType<'ctx>, ctx: &'ctx Context) -> BasicTypeEnum<'ctx> {
|
||||||
let item = self.item.get_type_impl(size_t, ctx);
|
let item = self.item.get_type_impl(size_t, ctx);
|
||||||
item.array_type(self.len.get_length()).into()
|
item.array_type(self.len.get_length()).into()
|
||||||
@ -78,12 +78,12 @@ impl<'ctx, Len: LenKind, Item: ModelBase<'ctx>> ModelBase<'ctx> for Array<Len, I
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'ctx, Len: LenKind, Item: Model<'ctx>> Model<'ctx> for Array<Len, Item> {
|
impl<'ctx, Len: ArrayLen, Item: Model<'ctx>> Model<'ctx> for Array<Len, Item> {
|
||||||
type Type = ArrayType<'ctx>;
|
type Type = ArrayType<'ctx>;
|
||||||
type Value = ArrayValue<'ctx>;
|
type Value = ArrayValue<'ctx>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'ctx, Len: LenKind, Item: Model<'ctx>> Instance<'ctx, Ptr<Array<Len, Item>>> {
|
impl<'ctx, Len: ArrayLen, Item: Model<'ctx>> Instance<'ctx, Ptr<Array<Len, Item>>> {
|
||||||
/// Get the pointer to the `i`-th (0-based) array element.
|
/// Get the pointer to the `i`-th (0-based) array element.
|
||||||
pub fn gep(
|
pub fn gep(
|
||||||
&self,
|
&self,
|
||||||
|
Loading…
Reference in New Issue
Block a user