Skip to content

Commit

Permalink
Refactors to accessing assembly data
Browse files Browse the repository at this point in the history
  • Loading branch information
FractalFir committed Sep 26, 2024
1 parent d77172a commit eeb6b57
Show file tree
Hide file tree
Showing 24 changed files with 192 additions and 1,833 deletions.
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,4 @@ members = [ "cilly", "dotnet_aot",
exclude = ["rust/src/bootstrap"]
[profile.release]
debug = true
oom = "panic"
[profile.dev]
oom = "panic"

6 changes: 3 additions & 3 deletions cilly/src/bin/asmedit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fn main() {
}
};
for (id, def) in asm.methods_with(|_, _, def| *def.access() == access) {
println!("{name:?} {id:?}", name = asm.get_string(def.name()));
println!("{name:?} {id:?}", name = &asm[def.name()]);
}
}
"mbyname" => {
Expand Down Expand Up @@ -169,14 +169,14 @@ fn main() {
continue;
};
let def = asm.method_def(id);
let name = asm.get_string(def.name());
let name = &asm[def.name()];
let (blocks, locals) = match def.resolved_implementation(&asm) {
MethodImpl::MethodBody { blocks, locals } => (blocks, locals),
MethodImpl::Extern {
lib,
preserve_errno,
} => {
let lib = asm.get_string(*lib);
let lib = &asm[*lib];
eprintln!(
"Extern method {name} is in {lib} preserve_errno:{preserve_errno}"
);
Expand Down
12 changes: 6 additions & 6 deletions cilly/src/bin/linker/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fn file_stem(file: &str) -> String {
.unwrap()
.to_owned()
}
#[cfg(any(target_os = "linux", target_os = "darwin"))]
#[cfg(any(target_os = "linux", target_os = "macos"))]
fn get_out_path(args: &[String]) -> &str {
&args[1 + args
.iter()
Expand Down Expand Up @@ -235,7 +235,7 @@ fn main() {
let sig = final_assembly.sig([Type::Int(Int::ISize)], Type::Int(Int::ISize));
let allochglobal =
final_assembly.new_methodref(marshal, "AllocHGlobal", sig, MethodKind::Static, []);
let mref = final_assembly.get_mref(allochglobal).clone();
let mref = final_assembly[allochglobal].clone();
call_alias(&mut overrides, &mut final_assembly, "malloc", mref);
// Overrides calls to realloc
let sig = final_assembly.sig(
Expand All @@ -244,13 +244,13 @@ fn main() {
);
let realloc =
final_assembly.new_methodref(marshal, "ReAllocHGlobal", sig, MethodKind::Static, []);
let mref = final_assembly.get_mref(realloc).clone();
let mref = final_assembly[realloc].clone();
call_alias(&mut overrides, &mut final_assembly, "realloc", mref);
// Overrides calls to free
let sig = final_assembly.sig([Type::Int(Int::ISize)], Type::Void);
let allochglobal =
final_assembly.new_methodref(marshal, "FreeHGlobal", sig, MethodKind::Static, []);
let mref = final_assembly.get_mref(allochglobal).clone();
let mref = final_assembly[allochglobal].clone();
call_alias(&mut overrides, &mut final_assembly, "free", mref);
}
if !*PANIC_MANAGED_BT {
Expand Down Expand Up @@ -310,8 +310,8 @@ fn main() {
final_assembly.alloc_string("_Unwind_Backtrace"),
Box::new(|mref, asm| {
// 1 Get the output of the method.
let mref = asm.get_mref(mref);
let sig = asm.get_sig(mref.sig()).clone();
let mref = &asm[mref];
let sig = asm[mref.sig()].clone();
let output = sig.output();
// 2. Create one local of the output type
let loc_name = asm.alloc_string("uninit");
Expand Down
19 changes: 3 additions & 16 deletions cilly/src/bin/linker/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ pub fn call_alias(
asm.alloc_string(name),
Box::new(move |original, asm| {
let method_ref = asm.alloc_methodref(call.clone());
let inputs: Box<[_]> = asm.get_sig(call.sig()).inputs().into();
let inputs: Box<[_]> = asm[call.sig()].inputs().into();
let original_inputs: Box<[_]> =
asm.get_sig(asm.get_mref(original).sig()).inputs().into();
asm[asm[original].sig()].inputs().into();
let args = inputs
.iter()
.zip(original_inputs.iter())
Expand Down Expand Up @@ -59,7 +59,7 @@ pub fn call_alias(
}
})
.collect();
if *asm.get_sig(call.sig()).output() == Type::Void {
if *asm[call.sig()].output() == Type::Void {
let call = asm.alloc_root(CILRoot::Call(Box::new((method_ref, args))));
let ret = asm.alloc_root(CILRoot::VoidRet);
cilly::v2::MethodImpl::MethodBody {
Expand All @@ -77,16 +77,3 @@ pub fn call_alias(
}),
);
}
/*
pub fn builtin_call(
overrides: &mut MissingMethodPatcher,
asm: &mut Assembly,
name: impl Into<IString> + Clone,
sig: SigIdx,
) {
let main = asm.main_module();
let call = asm.new_methodref(*main, name.clone(), sig, MethodKind::Static, []);
let call = asm.get_mref(call).clone();
call_alias(overrides, asm, name, call)
}
*/
1 change: 0 additions & 1 deletion cilly/src/cil_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,6 @@ impl CILNode {
sig_ptr_args.2.iter_mut().for_each(|arg|arg.allocate_tmps(curr_loc, locals));
}
Self::LDStaticField(_sfield)=>(),
Self::AddressOfStaticField(_sfield)=>(),
Self::LDLen { arr } =>{
arr.allocate_tmps(curr_loc, locals);
}
Expand Down
65 changes: 1 addition & 64 deletions cilly/src/cil_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ impl CILTree {
pub fn root(&self) -> &CILRoot {
&self.tree
}
/// Optimizes this tree
pub fn opt(&mut self, opt_count: &mut usize) {}

/// Allocates the temporary variables this tree uses.
pub fn allocate_tmps(&mut self, locals: &mut Vec<(Option<IString>, Type)>) {
// self.tree.borrow_mut().allocate_tmps(None, locals);
Expand All @@ -57,65 +56,3 @@ impl CILTree {
&mut self.tree
}
}
/*
#[test]
fn test_sheed() {
use crate::cil_node::CILNode;
let node = CILNode::SubTrees(Box::new((
[CILRoot::STLoc {
local: 11,
tree: CILNode::TemporaryLocal(Box::new((
Type::ClassRef(Box::new(crate::ClassRef::new::<&str, _>(
None,
"core.ptr.metadata.PtrComponents.h4c1f0d773746020e",
))),
Box::new([CILRoot::SetTMPLocal {
value: CILNode::LDLoc(1),
}]),
CILNode::LdObj {
ptr: Box::new(CILNode::LoadAddresOfTMPLocal),
obj: Box::new(Type::ClassRef(Box::new(crate::ClassRef::new::<
&str,
_,
>(
None,
"core.ptr.metadata.PtrComponents.h4c1f0d773746020e",
)))),
},
))),
}]
.into(),
Box::new(CILNode::LdObj {
ptr: Box::new(CILNode::LDLocA(11)),
obj: Box::new(Type::ClassRef(Box::new(crate::ClassRef::new::<
&str,
_,
>(
None,
"core.ptr.metadata.PtrComponents.h4c1f0d773746020e",
)))),
}),
)));
let tree: CILTree = CILRoot::STLoc {
local: 7,
tree: node,
}
.into();
let _trees = tree.shed_trees();
}
#[test]
fn test_alloc() {
use crate::cil_node::CILNode;
let mut tree: CILNode = CILNode::TemporaryLocal(Box::new((
Type::Int(Int::U8),
[CILRoot::SetTMPLocal {
value: CILNode::TemporaryLocal(Box::new((Type::Int(Int::U8), [].into(), CILNode::LDLoc(0)))),
}]
.into(),
CILNode::LDLoc(0),
)));
let mut locs = vec![];
tree.allocate_tmps(None, &mut locs);
}
*/
Loading

0 comments on commit eeb6b57

Please sign in to comment.