Skip to content

Commit

Permalink
Misc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
FractalFir committed Aug 8, 2024
1 parent f899e39 commit a66f0e5
Show file tree
Hide file tree
Showing 15 changed files with 185 additions and 338 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ rustc-demangle = "0.1.23"
cilly = {path = "./cilly"}
serde = { version = "1.0.183", features = ["derive"] }
strsim = "0.11.1"
regex = "1.10.5"

fxhash = "0.2.1"
ordered-float = { version = "4.2.1", features = ["serde"] }

[profile.dev.package.fxhash]
opt-level = 3
[lib]
Expand Down
6 changes: 0 additions & 6 deletions cilly/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ lazy_static = "1.4.0"
postcard = { version = "1.0.6", features = ["use-std"] }
ar = "0.9.0"
fxhash = "0.2.1"
name-variant = "0.1.0"
internment = { version = "0.8.4", features = ["arc", "serde"] }
ordered-float = { version = "4.2.1", features = ["serde"] }
string-interner = { version = "*", features = ["serde"] }
interner = "0.2.1"
streaming-iterator = "0.1.9"
[[bin]]
name = "linker"
test = false
Expand Down
12 changes: 3 additions & 9 deletions cilly/src/cil_iter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{call_site::CallSite, cil_node::CILNode, cil_root::CILRoot};
use crate::{call_site::CallSite, cil_node::CILNode, cil_root::CILRoot, v2::hashable::HashableF32};

#[derive(Debug, Clone, Copy)]
pub enum CILIterElem<'a> {
Expand Down Expand Up @@ -576,11 +576,7 @@ fn iter() {
FnSig::new(&[Type::I32, Type::F32], Type::Void),
true,
)),
args: [
CILNode::LdcI32(-77),
CILNode::LdcF32(ordered_float::OrderedFloat(3.119765)),
]
.into(),
args: [CILNode::LdcI32(-77), CILNode::LdcF32(HashableF32(3.119765))].into(),
};
let mut iter = root.into_iter();
assert!(matches!(
Expand All @@ -593,9 +589,7 @@ fn iter() {
));
assert!(matches!(
iter.next(),
Some(CILIterElem::Node(CILNode::LdcF32(
ordered_float::OrderedFloat(3.119765)
)))
Some(CILIterElem::Node(CILNode::LdcF32(HashableF32(3.119765))))
));
assert!(iter.next().is_none());
}
14 changes: 3 additions & 11 deletions cilly/src/cil_iter_mut.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::marker::PhantomData;

use ordered_float::OrderedFloat;

use crate::{cil_node::CILNode, cil_root::CILRoot};
use crate::{cil_node::CILNode, cil_root::CILRoot, v2::hashable::HashableF32};

#[derive(Debug)]
enum CILIterElemUnsafe<'a> {
Expand Down Expand Up @@ -615,11 +613,7 @@ fn iter() {
FnSig::new(&[Type::I32, Type::F32], Type::Void),
true,
)),
args: [
CILNode::LdcI32(-77),
CILNode::LdcF32(OrderedFloat(3.119765)),
]
.into(),
args: [CILNode::LdcI32(-77), CILNode::LdcF32(HashableF32(3.119765))].into(),
};
let mut iter = (&mut root).into_iter();
assert!(matches!(
Expand All @@ -632,9 +626,7 @@ fn iter() {
));
assert!(matches!(
iter.next(),
Some(CILIterElemMut::Node(CILNode::LdcF32(OrderedFloat(
3.119765
))))
Some(CILIterElemMut::Node(CILNode::LdcF32(HashableF32(3.119765))))
));
assert!(iter.next().is_none());
}
17 changes: 12 additions & 5 deletions cilly/src/cil_node.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
use crate::{
call, call_site::CallSite, cil_iter::CILIterTrait, cil_root::CILRoot,
field_desc::FieldDescriptor, fn_sig::FnSig, ptr, static_field_desc::StaticFieldDescriptor,
call,
call_site::CallSite,
cil_iter::CILIterTrait,
cil_root::CILRoot,
field_desc::FieldDescriptor,
fn_sig::FnSig,
ptr,
static_field_desc::StaticFieldDescriptor,
v2::hashable::{HashableF32, HashableF64},
DotnetTypeRef, IString, Type,
};
use ordered_float::OrderedFloat;

use serde::{Deserialize, Serialize};
/// A container for the arguments of a call, callvirt, or newobj instruction.
#[derive(Clone, Eq, PartialEq, Serialize, Deserialize, Hash, Debug)]
Expand Down Expand Up @@ -134,8 +141,8 @@ pub enum CILNode {
LdcU32(u32),
LdcI8(i8),
LdcI16(i16),
LdcF64(OrderedFloat<f64>),
LdcF32(OrderedFloat<f32>),
LdcF64(HashableF64),
LdcF32(HashableF32),
LoadGlobalAllocPtr {
alloc_id: u64,
},
Expand Down
3 changes: 0 additions & 3 deletions cilly/src/v2/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,6 @@ impl ClassDef {
// Merge the static fields, removing duplicates
self.static_fields_mut().extend(translated.static_fields());
make_unique(&mut self.static_fields);
// Merge the static fields, removing duplicates
self.static_fields_mut().extend(translated.static_fields());
make_unique(self.static_fields_mut());
// Merge the methods, removing duplicates
self.methods_mut().extend(translated.methods());
make_unique(self.methods_mut());
Expand Down
10 changes: 6 additions & 4 deletions cilly/src/v2/cst.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use ordered_float::OrderedFloat;
use serde::{Deserialize, Serialize};

use super::{CILNode, Float, Int, StringIdx, Type};
use super::{
hashable::{HashableF32, HashableF64},
CILNode, Float, Int, StringIdx, Type,
};

#[derive(PartialEq, Eq, Clone, Debug, Hash, Serialize, Deserialize)]
pub enum Const {
Expand All @@ -17,8 +19,8 @@ pub enum Const {
USize(u64),
PlatformString(StringIdx),
Bool(bool),
F32(OrderedFloat<f32>),
F64(OrderedFloat<f64>),
F32(HashableF32),
F64(HashableF64),
}
impl Const {
pub(crate) fn get_type(&self) -> Type {
Expand Down
2 changes: 2 additions & 0 deletions cilly/src/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub mod cst;
pub mod field;
pub mod float;
pub mod fnsig;
/// Defines hashable and equable floating point types. All NaNs are compared by bits, and -0.0 != 0.0.
pub mod hashable;
pub mod il_exporter;
pub mod int;
pub mod iter;
Expand Down
8 changes: 4 additions & 4 deletions src/assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use rustc_middle::{
mono::MonoItem,
Local, LocalDecl, Statement, Terminator,
},
ty::{Instance, ParamEnv, Ty, TyCtxt, TyKind},
ty::{Instance, ParamEnv, TyCtxt, TyKind},
};
type LocalDefList = Vec<(Option<IString>, Type)>;
type ArgsDebugInfo = Vec<Option<IString>>;
Expand Down Expand Up @@ -639,14 +639,14 @@ pub fn add_allocation(
}
GlobalAlloc::VTable(..) => {
//TODO: handle VTables
let alloc_fld: IString = format!("alloc_{alloc_id:x}").into();
let alloc_fld: IString = format!("al_{alloc_id:x}").into();
let field_desc = StaticFieldDescriptor::new(None, ptr!(Type::U8), alloc_fld.clone());
asm.add_static(ptr!(Type::U8), &alloc_fld, false);
return CILNode::LDStaticField(Box::new(field_desc));
}
GlobalAlloc::Function { .. } => {
//TODO: handle constant functions
let alloc_fld: IString = format!("alloc_{alloc_id:x}").into();
let alloc_fld: IString = format!("al_{alloc_id:x}").into();
let field_desc = StaticFieldDescriptor::new(None, ptr!(Type::U8), alloc_fld.clone());
asm.add_static(ptr!(Type::U8), &alloc_fld, false);

Expand All @@ -662,7 +662,7 @@ pub fn add_allocation(
// Alloc ids are *not* unique across all crates. Adding the hash here ensures we don't overwrite allocations during linking
// TODO:consider using something better here / making the hashes stable.
let byte_hash = calculate_hash(&bytes);
let alloc_fld: IString = format!("a_{}{}", encode(alloc_id), encode(byte_hash)).into();
let alloc_fld: IString = format!("al_{}_{}", encode(alloc_id), encode(byte_hash)).into();
let field_desc = StaticFieldDescriptor::new(None, ptr!(Type::U8), alloc_fld.clone());
if !asm.static_fields().contains_key(&alloc_fld) {
let init_method =
Expand Down
Loading

0 comments on commit a66f0e5

Please sign in to comment.