Skip to content
Snippets Groups Projects
Commit bf1b9c90 authored by rarbore2's avatar rarbore2
Browse files

Merge branch 'juno-fix' into 'main'

Reimplement create_constant_zero in builder for Juno codegen

See merge request !32
parents 52f5d493 a347103d
No related branches found
No related tags found
1 merge request!32Reimplement create_constant_zero in builder for Juno codegen
......@@ -354,14 +354,41 @@ impl<'a> Builder<'a> {
pub fn create_constant_array(
&mut self,
elem_ty: TypeID,
extents: Box<[u32]>,
) -> BuilderResult<ConstantID> {
let extents = extents
.iter()
.map(|extent| self.create_dynamic_constant_constant(*extent as usize))
.collect();
extents: Box<[DynamicConstantID]>,
) -> ConstantID {
let ty = self.create_type_array(elem_ty, extents);
Ok(self.intern_constant(Constant::Array(ty), ty))
self.intern_constant(Constant::Array(ty), ty)
}
pub fn create_constant_zero(&mut self, typ : TypeID) -> ConstantID {
match &self.module.types[typ.idx()] {
Type::Control(_) => panic!("Cannot create constant for control types"),
Type::Boolean => self.create_constant_bool(false),
Type::Integer8 => self.create_constant_i8(0),
Type::Integer16 => self.create_constant_i16(0),
Type::Integer32 => self.create_constant_i32(0),
Type::Integer64 => self.create_constant_i64(0),
Type::UnsignedInteger8 => self.create_constant_u8(0),
Type::UnsignedInteger16 => self.create_constant_u16(0),
Type::UnsignedInteger32 => self.create_constant_u32(0),
Type::UnsignedInteger64 => self.create_constant_u64(0),
Type::Float32 => self.create_constant_f32(0.0),
Type::Float64 => self.create_constant_f64(0.0),
Type::Product(fs) => {
let mut cs = vec![];
for t in fs.clone() {
cs.push(self.create_constant_zero(t));
}
self.create_constant_prod(cs.into())
},
Type::Summation(cs) => {
assert!(cs.len() >= 1, "Cannot create zero for empty summation");
let c = self.create_constant_zero(cs[0]);
self.create_constant_sum(typ, 0, c)
.expect("Exists and well typed by construction")
},
Type::Array(t, dims) => self.create_constant_array(*t, dims.clone()),
}
}
pub fn create_dynamic_constant_constant(&mut self, val: usize) -> DynamicConstantID {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment