Skip to content

Commit c4a884a

Browse files
committed
Removed a few more nodes
1 parent 7a131b8 commit c4a884a

File tree

11 files changed

+76
-255
lines changed

11 files changed

+76
-255
lines changed

cilly/src/cil_node.rs

Lines changed: 6 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ pub enum CILNode {
2929

3030
/// A black box that prevents the bulit-in optimization engine from doing any optimizations.
3131
BlackBox(Box<Self>),
32-
/// Loads the value of a static variable described by the descripstor.
33-
LDStaticField(Box<StaticFieldDesc>),
3432
/// Converts the signed inner value to a 32 bit floating-point number.
3533
ConvF32(Box<Self>),
3634
/// Converts the signed inner value to a 64 bit floating-point number.
@@ -128,8 +126,6 @@ pub enum CILNode {
128126
ShrUn(Box<Self>, Box<Self>),
129127
Call(Box<CallOpArgs>),
130128
CallVirt(Box<CallOpArgs>),
131-
LdcF64(HashableF64),
132-
LdcF32(HashableF32),
133129

134130
ConvU8(Box<Self>),
135131
ConvU16(Box<Self>),
@@ -208,10 +204,12 @@ pub enum CILNode {
208204
/// Marks the inner pointer operation as volatile.
209205
Volatile(Box<Self>),
210206
UnboxAny(Box<Self>, Box<Type>),
211-
AddressOfStaticField(Box<StaticFieldDesc>),
212-
LdNull(Interned<ClassRef>),
213207
}
214-
208+
impl From<Interned<crate::v2::CILNode>> for CILNode {
209+
fn from(value: Interned<crate::v2::CILNode>) -> Self {
210+
Self::V2(value)
211+
}
212+
}
215213
impl CILNode {
216214
pub fn stack_addr(val: Self, _: Interned<Type>, asm: &mut Assembly) -> Self {
217215
let val = crate::v2::CILNode::from_v1(&val, asm);
@@ -336,7 +334,7 @@ impl CILNode {
336334
pub fn uninit_val(tpe: Type, asm: &mut Assembly) -> Self {
337335
if tpe == Type::Void {
338336
let gv = asm.global_void();
339-
return CILNode::LDStaticField(Box::new(asm[gv]));
337+
return CILNode::V2(asm.load_static(gv));
340338
}
341339
let main = asm.main_module();
342340
let sig = asm.sig([], tpe);
@@ -410,100 +408,6 @@ impl CILNode {
410408
new_ptr: Box::new(new_ptr),
411409
}
412410
}
413-
pub(crate) fn allocate_tmps(&mut self, curr_loc: Option<u32>, locals: &mut Vec<LocalDef>) {
414-
match self {
415-
Self::V2(_)=>(),
416-
Self::AddressOfStaticField(_)=>(),
417-
Self::LdNull(_tpe)=>(),
418-
Self::UnboxAny(val,_tpe )=>val.allocate_tmps(curr_loc, locals),
419-
Self::Volatile(inner)=>inner.allocate_tmps(curr_loc, locals),
420-
Self::CheckedCast(inner)=>inner.0.allocate_tmps(curr_loc, locals),
421-
Self::IsInst(inner)=>inner.0.allocate_tmps(curr_loc, locals),
422-
Self::GetException=>(),
423-
Self::LocAlloc{..}=>(),
424-
Self::LocAllocAligned {..}=>(),
425-
Self::CastPtr { val, new_ptr: _ }=>val.allocate_tmps(curr_loc, locals),
426-
Self::LDLoc(_) => (),
427-
Self::BlackBox(inner) => inner.allocate_tmps(curr_loc, locals),
428-
Self::LDIndI8 { ptr }|
429-
Self::LDIndBool { ptr }|
430-
Self::LDIndI16 { ptr }|
431-
Self::LDIndI32 { ptr }|
432-
Self::LDIndI64 { ptr }|
433-
Self::LDIndU8 { ptr }|
434-
Self::LDIndU16 { ptr }|
435-
Self::LDIndU32 { ptr }|
436-
Self::LDIndU64 { ptr }|
437-
Self::LDIndISize { ptr }|
438-
Self::LDIndPtr { ptr, .. }|
439-
Self::LDIndUSize { ptr }|
440-
Self::LdObj { ptr, .. }|
441-
Self::LDIndF32 { ptr } |
442-
Self::LDIndF64 { ptr } => ptr.allocate_tmps(curr_loc, locals),
443-
Self::LDFieldAdress { addr, field: _ } |
444-
Self::LDField { addr, field: _ }=> addr.allocate_tmps(curr_loc, locals),
445-
Self::Add(a, b)
446-
| Self::And(a, b)
447-
| Self::Sub(a, b)
448-
| Self::Mul(a, b)
449-
| Self::Div(a, b)
450-
| Self::DivUn(a, b)
451-
| Self::Rem(a, b)
452-
| Self::RemUn(a, b)
453-
| Self::Or(a, b)
454-
| Self::XOr(a, b)
455-
| Self::Shr(a, b)
456-
| Self::Shl(a, b)
457-
| Self::ShrUn(a, b)
458-
| Self::Eq(a, b)
459-
| Self::Lt(a, b)
460-
| Self::LtUn(a, b)
461-
| Self::Gt(a, b)
462-
| Self::GtUn(a, b) => {
463-
a.allocate_tmps(curr_loc, locals);
464-
b.allocate_tmps(curr_loc, locals);
465-
}
466-
Self::Call (call_op_args) | Self::CallVirt (call_op_args) | Self::NewObj (call_op_args) =>call_op_args.args.iter_mut().for_each(|arg|arg.allocate_tmps(curr_loc, locals)),
467-
Self::LdcF64(_) |
468-
Self::LdcF32(_) =>(),
469-
Self::ConvF64Un(val) |
470-
Self::ConvF32(val)|
471-
Self::ConvF64(val) |
472-
Self::ConvU8(val)|
473-
Self::ConvU16(val)|
474-
Self::ConvU32(val)|
475-
Self::ZeroExtendToU64(val)|
476-
Self::MRefToRawPtr(val) |
477-
Self::ZeroExtendToUSize(val)|
478-
Self::ZeroExtendToISize(val)|
479-
Self::ConvI8(val) |
480-
Self::ConvI16(val)|
481-
Self::ConvI32(val)|
482-
Self::SignExtendToI64(val) |
483-
Self::SignExtendToU64(val) |
484-
Self::SignExtendToISize(val)|
485-
Self::SignExtendToUSize(val)|
486-
//Self::Volatile(_) => todo!(),
487-
Self::Neg(val) |
488-
Self::Not(val) =>val.allocate_tmps(curr_loc, locals),
489-
Self::LDFtn(_) => (),
490-
Self::LDTypeToken(_) =>(),
491-
492-
Self::LdStr(_) => (),
493-
Self::CallI (sig_ptr_args) => {
494-
sig_ptr_args.1.allocate_tmps(curr_loc, locals);
495-
sig_ptr_args.2.iter_mut().for_each(|arg|arg.allocate_tmps(curr_loc, locals));
496-
}
497-
Self::LDStaticField(_sfield)=>(),
498-
Self::LDLen { arr } =>{
499-
arr.allocate_tmps(curr_loc, locals);
500-
}
501-
Self::LDElelemRef { arr, idx }=>{
502-
arr.allocate_tmps(curr_loc, locals);
503-
idx.allocate_tmps(curr_loc, locals);
504-
}
505-
};
506-
}
507411
}
508412

509413
#[macro_export]

cilly/src/cil_root.rs

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -254,95 +254,6 @@ impl CILRoot {
254254
}
255255
}
256256

257-
pub fn allocate_tmps(&mut self, curr_loc: Option<u32>, locals: &mut Vec<LocalDef>) {
258-
match self {
259-
Self::V2(_) => (),
260-
Self::Volatile(inner) => inner.allocate_tmps(curr_loc, locals),
261-
Self::InitObj(inner, _) => inner.allocate_tmps(curr_loc, locals),
262-
Self::SourceFileInfo(_) => (),
263-
Self::OptimizedSourceFileInfo(_, _, _) => (),
264-
Self::STLoc { tree, .. } => {
265-
tree.allocate_tmps(curr_loc, locals);
266-
}
267-
Self::BTrue { cond: ops, .. } => ops.allocate_tmps(curr_loc, locals),
268-
Self::BFalse { cond: ops, .. } => ops.allocate_tmps(curr_loc, locals),
269-
Self::BEq { a, b, .. }
270-
| Self::BNe { a, b, .. }
271-
| Self::BLt { a, b, .. }
272-
| Self::BLtUn { a, b, .. }
273-
| Self::BGt { a, b, .. }
274-
| Self::BGtUn { a, b, .. }
275-
| Self::BLe { a, b, .. }
276-
| Self::BGe { a, b, .. } => {
277-
a.allocate_tmps(curr_loc, locals);
278-
b.allocate_tmps(curr_loc, locals);
279-
}
280-
Self::GoTo { .. } => (),
281-
Self::CallVirt { site: _, args } | Self::Call { site: _, args } => args
282-
.iter_mut()
283-
.for_each(|arg| arg.allocate_tmps(curr_loc, locals)),
284-
Self::SetField {
285-
addr,
286-
value,
287-
desc: _,
288-
} => {
289-
addr.allocate_tmps(curr_loc, locals);
290-
value.allocate_tmps(curr_loc, locals);
291-
}
292-
Self::CpBlk { src, dst, len } => {
293-
src.allocate_tmps(curr_loc, locals);
294-
dst.allocate_tmps(curr_loc, locals);
295-
len.allocate_tmps(curr_loc, locals);
296-
}
297-
Self::STIndI8(addr_calc, value_calc)
298-
| Self::STIndI16(addr_calc, value_calc)
299-
| Self::STIndI32(addr_calc, value_calc)
300-
| Self::STIndI64(addr_calc, value_calc)
301-
| Self::STIndISize(addr_calc, value_calc)
302-
| Self::STIndPtr(addr_calc, value_calc, _)
303-
| Self::STIndF64(addr_calc, value_calc)
304-
| Self::STIndF32(addr_calc, value_calc) => {
305-
addr_calc.allocate_tmps(curr_loc, locals);
306-
value_calc.allocate_tmps(curr_loc, locals);
307-
}
308-
Self::STObj {
309-
addr_calc,
310-
value_calc,
311-
..
312-
} => {
313-
addr_calc.allocate_tmps(curr_loc, locals);
314-
value_calc.allocate_tmps(curr_loc, locals);
315-
}
316-
Self::STArg { arg: _, tree } => tree.allocate_tmps(curr_loc, locals),
317-
Self::Break => (),
318-
Self::Nop => (),
319-
Self::InitBlk { dst, val, count } => {
320-
dst.allocate_tmps(curr_loc, locals);
321-
val.allocate_tmps(curr_loc, locals);
322-
count.allocate_tmps(curr_loc, locals);
323-
}
324-
325-
Self::Ret { tree } | Self::Pop { tree } | Self::Throw(tree) => {
326-
tree.allocate_tmps(curr_loc, locals);
327-
}
328-
Self::VoidRet => (),
329-
330-
Self::ReThrow => (),
331-
Self::CallI {
332-
sig: _,
333-
fn_ptr,
334-
args,
335-
} => {
336-
fn_ptr.allocate_tmps(curr_loc, locals);
337-
args.iter_mut()
338-
.for_each(|arg| arg.allocate_tmps(curr_loc, locals));
339-
}
340-
341-
Self::SetStaticField { descr: _, value } => value.allocate_tmps(curr_loc, locals),
342-
Self::JumpingPad { .. } => (),
343-
};
344-
}
345-
346257
#[must_use]
347258
pub fn source_info(
348259
file: &str,

cilly/src/cil_tree.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ impl CILTree {
3737
}
3838

3939
/// Allocates the temporary variables this tree uses.
40-
pub fn allocate_tmps(&mut self, locals: &mut Vec<LocalDef>) {
41-
// self.tree.borrow_mut().allocate_tmps(None, locals);
42-
self.tree.allocate_tmps(None, locals);
43-
}
40+
pub fn allocate_tmps(&mut self, locals: &mut Vec<LocalDef>) {}
4441

4542
// TODO: remember to make this recompute tree metadtata when it is added
4643
pub fn root_mut(&mut self) -> &mut CILRoot {

cilly/src/utilis.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ pub fn get_environ(asm: &mut Assembly) -> Interned<MethodRef> {
4545
if asm.method_def_from_ref(init_cs).is_some() {
4646
return init_cs;
4747
}
48-
4948
let mut get_environ = Method::new(
5049
crate::Access::Extern,
5150
crate::method::MethodType::Static,
@@ -56,6 +55,14 @@ pub fn get_environ(asm: &mut Assembly) -> Interned<MethodRef> {
5655
vec![],
5756
asm,
5857
);
58+
// Environ static
59+
let environ = StaticFieldDesc::new(
60+
*asm.main_module(),
61+
asm.alloc_string("environ"),
62+
uint8_ptr_ptr,
63+
);
64+
let environ = asm.alloc_sfld(environ);
65+
let environ = asm.alloc_node(crate::v2::CILNode::LdStaticField(environ));
5966
let dictionary_local = get_environ.add_local(
6067
Type::ClassRef(ClassRef::i_dictionary(asm)),
6168
Some("dict"),
@@ -87,11 +94,7 @@ pub fn get_environ(asm: &mut Assembly) -> Interned<MethodRef> {
8794
CILRoot::BNe {
8895
target: ret_bb,
8996
sub_target: 0,
90-
a: Box::new(CILNode::LDStaticField(Box::new(StaticFieldDesc::new(
91-
*asm.main_module(),
92-
asm.alloc_string("environ"),
93-
uint8_ptr_ptr,
94-
)))),
97+
a: Box::new(CILNode::V2(environ)),
9598
b: Box::new(conv_usize!(CILNode::V2(asm.alloc_node(0_i32))).cast_ptr(uint8_ptr_ptr)),
9699
}
97100
.into(),
@@ -184,16 +187,9 @@ pub fn get_environ(asm: &mut Assembly) -> Interned<MethodRef> {
184187
.into(),
185188
);
186189
let ret = &mut blocks[ret_bb as usize];
187-
ret.trees_mut().push(
188-
CILRoot::Ret {
189-
tree: CILNode::LDStaticField(Box::new(StaticFieldDesc::new(
190-
*asm.main_module(),
191-
asm.alloc_string("environ"),
192-
uint8_ptr_ptr,
193-
))),
194-
}
195-
.into(),
196-
);
190+
191+
ret.trees_mut()
192+
.push(CILRoot::V2(asm.alloc_root(crate::v2::CILRoot::Ret(environ))).into());
197193
let loop_body = &mut blocks[loop_body_bb as usize];
198194
let move_next = MethodRef::new(
199195
ClassRef::i_enumerator(asm),

cilly/src/v2/asm.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,6 +1476,21 @@ impl Assembly {
14761476
pub(crate) fn char_is_u8(&self) -> bool {
14771477
true
14781478
}
1479+
1480+
pub fn load_static(
1481+
&mut self,
1482+
stotic: impl IntoAsmIndex<Interned<StaticFieldDesc>>,
1483+
) -> Interned<CILNode> {
1484+
let stotic = stotic.into_idx(self);
1485+
self.alloc_node(CILNode::LdStaticField(stotic))
1486+
}
1487+
pub fn static_addr(
1488+
&mut self,
1489+
stotic: impl IntoAsmIndex<Interned<StaticFieldDesc>>,
1490+
) -> Interned<CILNode> {
1491+
let stotic = stotic.into_idx(self);
1492+
self.alloc_node(CILNode::LdStaticFieldAdress(stotic))
1493+
}
14791494
}
14801495
config!(GUARANTED_ALIGN, u8, 8);
14811496
config!(MAX_STATIC_SIZE, usize, 16);

cilly/src/v2/builtins/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,11 +791,12 @@ pub fn argc_argv_init(asm: &mut Assembly, patcher: &mut MissingMethodPatcher) {
791791
asm.alloc_string("argv_argc_init_status"),
792792
Type::Bool,
793793
);
794+
let status = asm.alloc_sfld(status);
794795
start_block.trees_mut().push(
795796
CILRoot::BTrue {
796797
target: start_bb + 3,
797798
sub_target: 0,
798-
cond: CILNode::LDStaticField(Box::new(status)),
799+
cond: CILNode::V2(asm.load_static(status)),
799800
}
800801
.into(),
801802
);
@@ -913,7 +914,7 @@ pub fn argc_argv_init(asm: &mut Assembly, patcher: &mut MissingMethodPatcher) {
913914
);
914915
loop_end_block.trees_mut().push(
915916
CILRoot::SetStaticField {
916-
descr: Box::new(status),
917+
descr: Box::new(asm[status]),
917918
value: CILNode::V2(asm.alloc_node(true)),
918919
}
919920
.into(),

cilly/src/v2/cilnode.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -781,8 +781,6 @@ impl CILNode {
781781

782782
V1Node::LDTypeToken(tpe) => Self::LdTypeToken(asm.alloc_type(*tpe.as_ref())),
783783

784-
V1Node::LdcF64(val) => Const::F64(*val).into(),
785-
V1Node::LdcF32(val) => Const::F32(*val).into(),
786784
// Special
787785
V1Node::IsInst(combined) => {
788786
let (val, tpe) = combined.as_ref();
@@ -822,8 +820,6 @@ impl CILNode {
822820
let tpe = asm.alloc_type(*tpe.as_ref());
823821
CILNode::LocAllocAlgined { tpe, align: *align }
824822
}
825-
V1Node::AddressOfStaticField(sfld) => Self::LdStaticFieldAdress(asm.alloc_sfld(**sfld)),
826-
V1Node::LDStaticField(sfld) => Self::LdStaticField(asm.alloc_sfld(**sfld)),
827823
V1Node::LDFtn(method_ref) => Self::LdFtn(*method_ref),
828824
V1Node::Volatile(inner) => {
829825
let mut tmp = Self::from_v1(inner, asm);
@@ -855,7 +851,6 @@ impl CILNode {
855851
let tpe = asm.alloc_type(*tpe.as_ref());
856852
Self::UnboxAny { object, tpe }
857853
}
858-
V1Node::LdNull(tpe) => Self::Const(Box::new(Const::Null(*tpe))),
859854
V1Node::V2(v2) => asm[*v2].clone(),
860855
_ => todo!("v1:{v1:?}"),
861856
}

cilly/src/v2/field.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ pub struct StaticFieldDesc {
6262
name: Interned<IString>,
6363
tpe: Type,
6464
}
65-
65+
impl IntoAsmIndex<Interned<StaticFieldDesc>> for StaticFieldDesc {
66+
fn into_idx(self, asm: &mut super::Assembly) -> Interned<StaticFieldDesc> {
67+
asm.alloc_sfld(self)
68+
}
69+
}
6670
impl StaticFieldDesc {
6771
#[must_use]
6872
pub fn new(owner: Interned<ClassRef>, name: Interned<IString>, tpe: Type) -> Self {

0 commit comments

Comments
 (0)