From c353d28be0607d03bf1539eff3b74f68e866c31f Mon Sep 17 00:00:00 2001 From: Jakub Doka Date: Sun, 10 Nov 2024 12:03:15 +0100 Subject: [PATCH] fixing another problem with const --- lang/src/son.rs | 17 ++++++++++------ lang/src/son/hbvm/their_regalloc.rs | 30 +++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/lang/src/son.rs b/lang/src/son.rs index 11f028b..ca08cbd 100644 --- a/lang/src/son.rs +++ b/lang/src/son.rs @@ -2433,7 +2433,9 @@ impl<'a> Codegen<'a> { self.ci.nodes.graphviz_in_browser(self.ty_display(ty::Id::VOID)); }); debug_assert!( - self.ci.nodes[region].kind != Kind::Load || self.ci.nodes[region].ty.is_pointer(), + self.ci.nodes[region].kind != Kind::Load + || self.ci.nodes[region].kind == Kind::Stck + || self.ci.nodes[region].ty.is_pointer(), "{:?} {} {}", self.ci.nodes.graphviz_in_browser(self.ty_display(ty::Id::VOID)), self.file().path, @@ -3817,11 +3819,14 @@ impl<'a> Codegen<'a> { let f = &self.files[c.file.index()]; let Expr::BinOp { left, right, .. } = c.ast.get(f) else { unreachable!() }; - left.find_pattern_path(c.name, right, |expr, is_ct| { - debug_assert!(is_ct); - self.expr_ctx(expr, ctx) - }) - .unwrap_or_else(|_| unreachable!()) + let mut value = left + .find_pattern_path(c.name, right, |expr, is_ct| { + debug_assert!(is_ct); + self.raw_expr_ctx(expr, ctx) + }) + .unwrap_or_else(|_| unreachable!())?; + self.strip_var(&mut value); + Some(value) } fn add_clobbers(&mut self, value: Value, clobbered_aliases: &mut BitSet) { diff --git a/lang/src/son/hbvm/their_regalloc.rs b/lang/src/son/hbvm/their_regalloc.rs index b98e893..e1a3756 100644 --- a/lang/src/son/hbvm/their_regalloc.rs +++ b/lang/src/son/hbvm/their_regalloc.rs @@ -50,7 +50,7 @@ impl HbvmBackend { ) -> (usize, bool) { let mut ralloc = mem::take(&mut self.ralloc); - let fuc = Function::new(nodes, tys, sig); + let fuc = Function::new(nodes, tys, files, sig); log::info!("{:?}", fuc); if !fuc.tail { mem::swap( @@ -447,6 +447,7 @@ pub struct Function<'a> { sig: Sig, nodes: &'a mut Nodes, tys: &'a Types, + files: &'a [parser::Ast], tail: bool, visited: BitSet, backrefs: Vec, @@ -471,10 +472,11 @@ impl core::fmt::Debug for Function<'_> { } impl<'a> Function<'a> { - fn new(nodes: &'a mut Nodes, tys: &'a Types, sig: Sig) -> Self { + fn new(nodes: &'a mut Nodes, tys: &'a Types, files: &'a [parser::Ast], sig: Sig) -> Self { let mut s = Self { tys, sig, + files, tail: true, visited: Default::default(), backrefs: vec![u16::MAX; nodes.values.len()], @@ -523,13 +525,27 @@ impl<'a> Function<'a> { regalloc2::Operand::reg_def(self.rg(nid)) } - fn rg(&self, nid: Nid) -> regalloc2::VReg { + fn rg(&mut self, nid: Nid) -> regalloc2::VReg { debug_assert!( !self.nodes.is_cfg(nid) || matches!(self.nodes[nid].kind, Kind::Call { .. }), "{:?}", self.nodes[nid] ); - debug_assert_eq!(self.nodes[nid].lock_rc, 0, "{nid} {:?}", self.nodes[nid]); + debug_assert_eq!( + { self.nodes[nid].lock_rc }, + 0, + "{nid} {:?} {:?} {:?}", + self.nodes[nid].clone(), + nid, + { + self.nodes[nid].lock_rc = u16::MAX - 1; + self.nodes.graphviz_in_browser(ty::Display::new( + self.tys, + self.files, + ty::Id::VOID, + )); + } + ); debug_assert!(self.nodes[nid].kind != Kind::Phi || self.nodes[nid].ty != ty::Id::VOID); regalloc2::VReg::new(nid as _, regalloc2::RegClass::Int) } @@ -665,8 +681,9 @@ impl<'a> Function<'a> { match parama.next(ty, self.tys) { None => {} Some(PLoc::Reg(r, _) | PLoc::WideReg(r, _) | PLoc::Ref(r, _)) => { + let a = self.rg(arg); self.add_instr(NEVER, vec![regalloc2::Operand::reg_fixed_def( - self.rg(arg), + a, regalloc2::PReg::new(r as _, regalloc2::RegClass::Int), )]); } @@ -674,8 +691,9 @@ impl<'a> Function<'a> { } if let Some(PLoc::Ref(r, ..)) = ret { + let m = self.rg(MEM); self.add_instr(NEVER, vec![regalloc2::Operand::reg_fixed_def( - self.rg(MEM), + m, regalloc2::PReg::new(r as _, regalloc2::RegClass::Int), )]); }