Skip to content

Commit

Permalink
Moved unops to use CILTrees
Browse files Browse the repository at this point in the history
  • Loading branch information
FractalFir committed Feb 20, 2024
1 parent 50118ef commit 5ded872
Show file tree
Hide file tree
Showing 15 changed files with 493 additions and 472 deletions.
96 changes: 46 additions & 50 deletions src/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ pub fn handle_aggregate<'tyctx>(
.map(|operand| {
(
operand.0 as u32,
crate::operand::handle_operand(operand.1, tyctx, method, method_instance, tycache).flatten(),
crate::operand::handle_operand(operand.1, tyctx, method, method_instance, tycache)
.flatten(),
)
})
.collect();
Expand Down Expand Up @@ -90,13 +91,10 @@ pub fn handle_aggregate<'tyctx>(
ops.extend(value.1);
ops.push(CILOp::Call(call_site.clone()));
}
ops.extend(super::place::place_get(
target_location,
tyctx,
method,
method_instance,
tycache,
).flatten());
ops.extend(
super::place::place_get(target_location, tyctx, method, method_instance, tycache)
.flatten(),
);
ops
}
AggregateKind::Tuple => {
Expand Down Expand Up @@ -130,13 +128,10 @@ pub fn handle_aggregate<'tyctx>(
name.into(),
)));
}
ops.extend(super::place::place_get(
target_location,
tyctx,
method,
method_instance,
tycache,
).flatten());
ops.extend(
super::place::place_get(target_location, tyctx, method, method_instance, tycache)
.flatten(),
);
ops
}
AggregateKind::Closure(_def_id, _args) => {
Expand All @@ -155,13 +150,9 @@ pub fn handle_aggregate<'tyctx>(
let field_ty =
crate::utilis::monomorphize(&method_instance, value.ty(method, tyctx), tyctx);
let field_ty = tycache.type_from_cache(field_ty, tyctx, Some(method_instance));
closure_constructor.extend(handle_operand(
value,
tyctx,
method,
method_instance,
tycache,
).flatten());
closure_constructor.extend(
handle_operand(value, tyctx, method, method_instance, tycache).flatten(),
);
closure_constructor.push(CILOp::STField(
FieldDescriptor::new(
closure_dotnet.clone(),
Expand All @@ -180,13 +171,9 @@ pub fn handle_aggregate<'tyctx>(
method_instance,
tycache,
);
ops.extend(place_get(
target_location,
tyctx,
method,
method_instance,
tycache,
).flatten());
ops.extend(
place_get(target_location, tyctx, method, method_instance, tycache).flatten(),
);
ops
}
_ => todo!("Unsuported aggregate kind {aggregate_kind:?}"),
Expand Down Expand Up @@ -247,13 +234,16 @@ fn aggregate_adt<'tyctx>(
);
ops.push(CILOp::STField(field_desc.into()));
}
ops.extend(crate::place::place_get(
target_location,
tyctx,
method,
method_instance,
type_cache,
).flatten());
ops.extend(
crate::place::place_get(
target_location,
tyctx,
method,
method_instance,
type_cache,
)
.flatten(),
);
ops
}
AdtKind::Enum => {
Expand Down Expand Up @@ -323,13 +313,16 @@ fn aggregate_adt<'tyctx>(
field_name,
))));
}
ops.extend(crate::place::place_get(
target_location,
tyctx,
method,
method_instance,
type_cache,
).flatten());
ops.extend(
crate::place::place_get(
target_location,
tyctx,
method,
method_instance,
type_cache,
)
.flatten(),
);
ops
}
AdtKind::Union => {
Expand Down Expand Up @@ -363,13 +356,16 @@ fn aggregate_adt<'tyctx>(

ops.push(CILOp::STField(field_desc));
}
ops.extend(crate::place::place_get(
target_location,
tyctx,
method,
method_instance,
type_cache,
).flatten());
ops.extend(
crate::place::place_get(
target_location,
tyctx,
method,
method_instance,
type_cache,
)
.flatten(),
);
ops
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/assembly_exporter/ilasm_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,9 @@ pub fn op_cli(op: &crate::cil::CILOp) -> Cow<'static, str> {
}
}
CILOp::ConvF32=> "conv.r4".into(),
CILOp::ConvF64 =>
CILOp::ConvF64 =>
"conv.r8".into(),
CILOp::ConvF64Un =>
CILOp::ConvF64Un =>
"conv.r.un".into(),
// Pointer stuff
CILOp::LDIndI8 => "ldind.i1".into(),
Expand Down
6 changes: 4 additions & 2 deletions src/binop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ pub(crate) fn binop_unchecked<'tyctx>(
method_instance: Instance<'tyctx>,
tycache: &mut TyCache,
) -> Vec<CILOp> {
let ops_a = crate::operand::handle_operand(operand_a, tyctx, method, method_instance, tycache).flatten();
let ops_b = crate::operand::handle_operand(operand_b, tyctx, method, method_instance, tycache).flatten();
let ops_a = crate::operand::handle_operand(operand_a, tyctx, method, method_instance, tycache)
.flatten();
let ops_b = crate::operand::handle_operand(operand_b, tyctx, method, method_instance, tycache)
.flatten();
let ty_a = operand_a.ty(&method.local_decls, tyctx);
let ty_b = operand_b.ty(&method.local_decls, tyctx);
match binop {
Expand Down
6 changes: 4 additions & 2 deletions src/checked_binop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ pub(crate) fn binop_checked<'tyctx>(
method_instance: Instance<'tyctx>,
cache: &mut TyCache,
) -> Vec<CILOp> {
let ops_a = crate::operand::handle_operand(operand_a, tyctx, method, method_instance, cache).flatten();
let ops_b = crate::operand::handle_operand(operand_b, tyctx, method, method_instance, cache).flatten();
let ops_a =
crate::operand::handle_operand(operand_a, tyctx, method, method_instance, cache).flatten();
let ops_b =
crate::operand::handle_operand(operand_b, tyctx, method, method_instance, cache).flatten();
let ty_a = operand_a.ty(&method.local_decls, tyctx);
let ty_a = crate::utilis::monomorphize(&method_instance, ty_a, tyctx);
let ty_b = operand_b.ty(&method.local_decls, tyctx);
Expand Down
29 changes: 22 additions & 7 deletions src/cil_tree/cil_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub enum CILNode {
LDLocA(u32),
LDArgA(u32),
BlackBox(Box<Self>),

ConvF32(Box<Self>),
ConvF64(Box<Self>),
SizeOf(Box<Type>),
Expand Down Expand Up @@ -69,7 +69,9 @@ pub enum CILNode {
LdcU32(u32),
LdcF64(f64),
LdcF32(f32),
LoadGlobalAllocPtr { alloc_id: u64 },
LoadGlobalAllocPtr {
alloc_id: u64,
},
ConvU8(Box<Self>),
ConvU16(Box<Self>),
ConvU32(Box<Self>),
Expand All @@ -81,6 +83,9 @@ pub enum CILNode {
ConvI64(Box<Self>),
ConvISize(Box<Self>),
Volatile(Box<Self>),
Neg(Box<Self>),
Not(Box<Self>),
Eq(Box<Self>, Box<Self>),
}
impl CILNode {
pub fn flatten(&self) -> Vec<CILOp> {
Expand All @@ -96,7 +101,7 @@ impl CILNode {
let mut res = vec![CILOp::Volatile];
res.extend(inner.flatten());
res
},
}

Self::ConvUSize(inner) => append_vec(inner.flatten(), CILOp::ConvUSize(false)),
Self::ConvU8(inner) => append_vec(inner.flatten(), CILOp::ConvU8(false)),
Expand All @@ -118,6 +123,10 @@ impl CILNode {
Self::LDIndI64 { ptr } => append_vec(ptr.flatten(), CILOp::LDIndI64),
Self::LDIndISize { ptr } => append_vec(ptr.flatten(), CILOp::LDIndISize),
Self::LdObj { ptr, obj } => append_vec(ptr.flatten(), CILOp::LdObj(obj.clone())),

Self::Neg(inner) => append_vec(inner.flatten(), CILOp::Neg),
Self::Not(inner) => append_vec(inner.flatten(), CILOp::Not),

Self::LDFieldAdress { addr, field } => {
append_vec(addr.flatten(), CILOp::LDFieldAdress(field.clone().into()))
}
Expand All @@ -132,6 +141,12 @@ impl CILNode {
res.push(CILOp::Add);
res
}
Self::Eq(a, b) => {
let mut res = a.flatten();
res.extend(b.flatten());
res.push(CILOp::Eq);
res
}
Self::Mul(a, b) => {
let mut res = a.flatten();
res.extend(b.flatten());
Expand All @@ -143,9 +158,7 @@ impl CILNode {
parrent.extend(ops.iter().cloned());
parrent
}
Self::RawOpsParrentless { ops } => {
ops.clone().into()
}
Self::RawOpsParrentless { ops } => ops.clone().into(),
Self::Call { args, site } => {
let mut res: Vec<CILOp> = args.iter().map(|arg| arg.flatten()).flatten().collect();
res.push(CILOp::Call(site.clone()));
Expand All @@ -157,7 +170,9 @@ impl CILNode {
Self::LdcU32(val) => vec![CILOp::LdcU32(*val)],
Self::LdcF64(val) => vec![CILOp::LdcF64(*val)],
Self::LdcF32(val) => vec![CILOp::LdcF32(*val)],
Self::LoadGlobalAllocPtr{alloc_id} => vec![CILOp::LoadGlobalAllocPtr { alloc_id: *alloc_id }]
Self::LoadGlobalAllocPtr { alloc_id } => vec![CILOp::LoadGlobalAllocPtr {
alloc_id: *alloc_id,
}],
}
}
}
Loading

0 comments on commit 5ded872

Please sign in to comment.