Skip to content

Commit e0797ac

Browse files
committed
Fixed typos + small bugfixes.
1 parent 970fea7 commit e0797ac

File tree

37 files changed

+201
-208
lines changed

37 files changed

+201
-208
lines changed

cargo_tests/build_std/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ fn should_fail() {
66
panic!();
77
}
88
pub fn main() {
9-
let vec = vec![0, 1, 2, 3, 4, 5, 6, 7, 8_u8];
9+
let mut vec = vec![];
10+
assert_eq!(vec.len(),0);
11+
vec = vec![0, 1, 2, 3, 4, 5, 6, 7, 8_u8];
1012
let mut s = String::new();
1113
s.push_str("Hi. Message");
1214
s.push_str("Hi. Message message messafe message mesasage!");

cargo_tests/string_tests/src/exchange_malloc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ pub unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
1515
if res == std::ptr::null_mut(){
1616
core::intrinsics::abort();
1717
}
18-
//unsafe{super::printf("Allocated buffer of size %p algined to %p at adress %p\n\r\n\r\0".as_ptr() as *const i8,size,align,res)};
19-
unsafe{super::printf("Allocating pointer at adress %p.\n\0".as_ptr() as *const i8,res)};
18+
//unsafe{super::printf("Allocated buffer of size %p algined to %p at address %p\n\r\n\r\0".as_ptr() as *const i8,size,align,res)};
19+
unsafe{super::printf("Allocating pointer at address %p.\n\0".as_ptr() as *const i8,res)};
2020
unsafe{super::printf("The align is %p.\n\0".as_ptr() as *const i8,align)};
2121
res
2222
}
@@ -45,7 +45,7 @@ pub fn exchange_malloc_test() {
4545
_11 = _8 & _10;
4646
_12 = _11 == 0_usize;
4747
_6 = _4 as *mut f64;
48-
unsafe{super::printf("Allocated ptr at adress %p\n\0".as_ptr() as *const i8,_6)};
48+
unsafe{super::printf("Allocated ptr at address %p\n\0".as_ptr() as *const i8,_6)};
4949
if _6 == std::ptr::null_mut(){
5050
core::intrinsics::abort();
5151
}

cilly/src/bin/linker/main.rs

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -327,45 +327,11 @@ fn main() {
327327
call_alias(&mut overrides, &mut final_assembly, "pthread_create", mref);
328328
}
329329
if !*PANIC_MANAGED_BT {
330-
overrides.insert(
331-
final_assembly.alloc_string("_Unwind_RaiseException"),
332-
Box::new(|_, asm| {
333-
let rust_exception = asm.alloc_string("RustException");
334-
let exception_class =
335-
asm.alloc_class_ref(ClassRef::new(rust_exception, None, false, [].into()));
336-
let exception_ctor = MethodRef::new(
337-
asm.alloc_class_ref(ClassRef::new(rust_exception, None, false, [].into())),
338-
asm.alloc_string(".ctor"),
339-
asm.sig(
340-
[Type::ClassRef(exception_class), Type::Int(Int::USize)],
341-
Type::Void,
342-
),
343-
MethodKind::Constructor,
344-
vec![].into(),
345-
);
346-
let arg0 = cilly::cil_node::V1Node::V2(asm.alloc_node(CILNode::LdArg(0)));
347-
MethodImpl::MethodBody {
348-
blocks: vec![cilly::BasicBlock::from_v1(
349-
&cilly::basic_block::BasicBlock::new(
350-
vec![
351-
cilly::cil_root::V1Root::Throw(cilly::cil_node::V1Node::NewObj(
352-
Box::new(cilly::cil_node::CallOpArgs {
353-
args: Box::new([conv_usize!(arg0)]),
354-
site: asm.alloc_methodref(exception_ctor),
355-
is_pure: IsPure::NOT,
356-
}),
357-
))
358-
.into(),
359-
],
360-
0,
361-
None,
362-
),
363-
asm,
364-
)],
365-
locals: vec![],
366-
}
367-
}),
368-
);
330+
if *C_MODE {
331+
cilly::v2::builtins::unwind::c_raise_exception(&mut final_assembly, &mut overrides);
332+
} else {
333+
cilly::v2::builtins::unwind::raise_exception(&mut final_assembly, &mut overrides);
334+
}
369335
}
370336
if !*C_MODE {
371337
overrides.insert(
@@ -378,7 +344,7 @@ fn main() {
378344
// 2. Create one local of the output type
379345
let loc_name = asm.alloc_string("uninit");
380346
let locals = vec![(Some(loc_name), asm.alloc_type(*output))];
381-
// 3. Create CIL returning an uninitalized value of this type. TODO: even tough this value is shortly discarded on the Rust side, this is UB. Consider zero-initializing it.
347+
// 3. Create CIL returning an uninitialized value of this type. TODO: even tough this value is shortly discarded on the Rust side, this is UB. Consider zero-initializing it.
382348
let loc = asm.alloc_node(CILNode::LdLoc(0));
383349
let ret = asm.alloc_root(CILRoot::Ret(loc));
384350
let blocks = vec![BasicBlock::new(vec![ret], 0, None)];

cilly/src/cil_node.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ impl V1Node {
214214
pub fn stack_addr(val: Self, _: Interned<Type>, asm: &mut Assembly) -> Self {
215215
let val = crate::v2::CILNode::from_v1(&val, asm);
216216
let sfld = asm.annon_const(val);
217-
V1Node::V2(asm.alloc_node(crate::v2::CILNode::LdStaticFieldAdress(sfld)))
217+
V1Node::V2(asm.alloc_node(crate::v2::CILNode::LdStaticFieldAddress(sfld)))
218218
}
219219
pub fn ovf_check_tuple(
220220
asm: &mut Assembly,
@@ -330,7 +330,7 @@ impl V1Node {
330330
}
331331
}
332332

333-
/// Creates an unintialized value of type *tpe*.
333+
/// Creates an uninitialized value of type *tpe*.
334334
pub fn uninit_val(tpe: Type, asm: &mut Assembly) -> Self {
335335
if tpe == Type::Void {
336336
let gv = asm.global_void();

cilly/src/cil_root.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,12 @@ pub enum V1Root {
156156
pub type SFI = Box<(std::ops::Range<u64>, std::ops::Range<u64>, IString)>;
157157
impl V1Root {
158158
pub fn try_typecheck(
159-
&self,
159+
&mut self,
160160
asm: &mut Assembly,
161161
fn_sig: Interned<FnSig>,
162162
locals: &[LocalDef],
163163
) -> Result<(), TypeCheckError> {
164-
let Self::V2(root) = self else { return Ok(()) };
164+
let Self::V2(root) = self else { panic!() };
165165
asm[*root].clone().typecheck(fn_sig, locals, asm)
166166
}
167167
#[must_use]

cilly/src/v2/asm.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl Assembly {
179179
) -> Interned<CILNode> {
180180
let addr = addr.into_idx(self);
181181
let field = field.into_idx(self);
182-
self.alloc_node(CILNode::LdFieldAdress { addr, field })
182+
self.alloc_node(CILNode::LdFieldAddress { addr, field })
183183
}
184184
pub fn typecheck(&mut self) {
185185
let method_def_idxs: Box<[_]> = self.method_defs.keys().copied().collect();
@@ -1255,7 +1255,7 @@ impl Assembly {
12551255
| CILNode::FloatCast { .. }
12561256
| CILNode::RefToPtr(_)
12571257
| CILNode::PtrCast(_, _)
1258-
| CILNode::LdFieldAdress { .. }
1258+
| CILNode::LdFieldAddress { .. }
12591259
| CILNode::LdField { .. }
12601260
| CILNode::LdInd { .. }
12611261
| CILNode::SizeOf(_)
@@ -1265,7 +1265,7 @@ impl Assembly {
12651265
| CILNode::CallI(_)
12661266
| CILNode::LocAlloc { .. }
12671267
| CILNode::LdStaticField(_)
1268-
| CILNode::LdStaticFieldAdress(_)
1268+
| CILNode::LdStaticFieldAddress(_)
12691269
| CILNode::LdTypeToken(_)
12701270
| CILNode::LdLen(_)
12711271
| CILNode::LocAllocAlgined { .. }
@@ -1462,7 +1462,7 @@ impl Assembly {
14621462
}
14631463

14641464
pub(crate) fn guaranted_align(&self) -> u8 {
1465-
*GUARANTED_ALIGN
1465+
*GUARANTEED_ALIGN
14661466
}
14671467

14681468
pub fn max_static_size(&self) -> usize {
@@ -1494,7 +1494,7 @@ impl Assembly {
14941494
stotic: impl IntoAsmIndex<Interned<StaticFieldDesc>>,
14951495
) -> Interned<CILNode> {
14961496
let stotic = stotic.into_idx(self);
1497-
self.alloc_node(CILNode::LdStaticFieldAdress(stotic))
1497+
self.alloc_node(CILNode::LdStaticFieldAddress(stotic))
14981498
}
14991499
/// Transmutes a value from one type to another.
15001500
pub fn transmute_on_stack(
@@ -1541,14 +1541,26 @@ impl Assembly {
15411541
const EMPTY: [Interned<CILNode>; 0] = [];
15421542
self.call(uninit_val, &EMPTY, IsPure::PURE)
15431543
}
1544+
1545+
pub(crate) fn ld_arg(&mut self, arg: u32) -> Interned<CILNode> {
1546+
self.alloc_node(CILNode::LdArg(arg))
1547+
}
1548+
1549+
pub(crate) fn throw(
1550+
&mut self,
1551+
exception: impl IntoAsmIndex<Interned<CILNode>>,
1552+
) -> Interned<CILRoot> {
1553+
let exception = exception.into_idx(self);
1554+
self.alloc_root(CILRoot::Throw(exception))
1555+
}
15441556
}
1545-
config!(GUARANTED_ALIGN, u8, 8);
1557+
config!(GUARANTEED_ALIGN, u8, 8);
15461558
config!(MAX_STATIC_SIZE, usize, 16);
15471559
/// An initializer, which runs before everything else. By convention, it is used to initialize static / const data. Should not execute any user code
15481560
pub const CCTOR: &str = ".cctor";
15491561
/// An thread-local initializer. Runs before each thread starts. By convention, it is used to initialize thread local data. Should not execute any user code.
15501562
pub const TCCTOR: &str = ".tcctor";
1551-
/// An intializer, which runs after the [`CCTOR`] and [`TCCTOR`], but before the [`ENTRYPOINT`]. Meant to execute user code, is roughly equivalnt to `.init_array` on GNU.
1563+
/// An initializer, which runs after the [`CCTOR`] and [`TCCTOR`], but before the [`ENTRYPOINT`]. Meant to execute user code, is roughly equivalnt to `.init_array` on GNU.
15521564
pub const USER_INIT: &str = "static_init";
15531565
/// The entrypoint of a program
15541566
pub const ENTRYPOINT: &str = "entrypoint";

cilly/src/v2/asm_link.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,12 @@ impl Assembly {
197197
};
198198
CILNode::PtrCast(input, Box::new(cast_res))
199199
}
200-
CILNode::LdFieldAdress { addr, field } => {
200+
CILNode::LdFieldAddress { addr, field } => {
201201
let field = self.translate_field(source, *source.get_field(*field));
202202
let field = self.alloc_field(field);
203203
let addr = self.translate_node(source, source.get_node(*addr).clone());
204204
let addr = self.alloc_node(addr);
205-
CILNode::LdFieldAdress { addr, field }
205+
CILNode::LdFieldAddress { addr, field }
206206
}
207207
CILNode::LdField { addr, field } => {
208208
let field = self.translate_field(source, *source.get_field(*field));
@@ -271,10 +271,10 @@ impl Assembly {
271271
let sfld = self.alloc_sfld(sfld);
272272
CILNode::LdStaticField(sfld)
273273
}
274-
CILNode::LdStaticFieldAdress(sfld) => {
274+
CILNode::LdStaticFieldAddress(sfld) => {
275275
let sfld = self.translate_static_field(source, *source.get_static_field(*sfld));
276276
let sfld = self.alloc_sfld(sfld);
277-
CILNode::LdStaticFieldAdress(sfld)
277+
CILNode::LdStaticFieldAddress(sfld)
278278
}
279279
CILNode::LdFtn(mref) => {
280280
let method_ref = self.translate_method_ref(source, &source[*mref]);

cilly/src/v2/builtins/math.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,10 @@ fn bitreverse_u32(asm: &mut Assembly, patcher: &mut MissingMethodPatcher) {
186186
let inv_mask = asm.alloc_node(Const::U32(!masks[i]));
187187
let masked = asm.alloc_node(CILNode::BinOp(curr, mask, BinOp::And));
188188
let inv_masked = asm.alloc_node(CILNode::BinOp(curr, inv_mask, BinOp::And));
189-
let shift_ammount = asm.alloc_node(Const::I32(shift));
190-
let masked_shifted =
191-
asm.alloc_node(CILNode::BinOp(masked, shift_ammount, BinOp::ShrUn));
189+
let shift_amount = asm.alloc_node(Const::I32(shift));
190+
let masked_shifted = asm.alloc_node(CILNode::BinOp(masked, shift_amount, BinOp::ShrUn));
192191
let inv_masked_shifted =
193-
asm.alloc_node(CILNode::BinOp(inv_masked, shift_ammount, BinOp::Shl));
192+
asm.alloc_node(CILNode::BinOp(inv_masked, shift_amount, BinOp::Shl));
194193
let curr_val = asm.alloc_node(CILNode::BinOp(
195194
masked_shifted,
196195
inv_masked_shifted,
@@ -229,11 +228,10 @@ fn bitreverse_u64(asm: &mut Assembly, patcher: &mut MissingMethodPatcher) {
229228
let inv_mask = asm.alloc_node(Const::U64(!masks[i]));
230229
let masked = asm.alloc_node(CILNode::BinOp(curr, mask, BinOp::And));
231230
let inv_masked = asm.alloc_node(CILNode::BinOp(curr, inv_mask, BinOp::And));
232-
let shift_ammount = asm.alloc_node(Const::I32(shift));
233-
let masked_shifted =
234-
asm.alloc_node(CILNode::BinOp(masked, shift_ammount, BinOp::ShrUn));
231+
let shift_amount = asm.alloc_node(Const::I32(shift));
232+
let masked_shifted = asm.alloc_node(CILNode::BinOp(masked, shift_amount, BinOp::ShrUn));
235233
let inv_masked_shifted =
236-
asm.alloc_node(CILNode::BinOp(inv_masked, shift_ammount, BinOp::Shl));
234+
asm.alloc_node(CILNode::BinOp(inv_masked, shift_amount, BinOp::Shl));
237235
let curr_val = asm.alloc_node(CILNode::BinOp(
238236
masked_shifted,
239237
inv_masked_shifted,
@@ -306,10 +304,10 @@ fn bitreverse_u128(asm: &mut Assembly, patcher: &mut MissingMethodPatcher) {
306304
let inv_mask = asm.alloc_node(Const::U128(curr_mask));
307305
let masked = asm.alloc_node(CILNode::call(and, [curr, mask]));
308306
let inv_masked = asm.alloc_node(CILNode::call(and, [curr, inv_mask]));
309-
let shift_ammount = asm.alloc_node(Const::I32(shift));
310-
let masked_shifted = asm.alloc_node(CILNode::call(rshift, [masked, shift_ammount]));
307+
let shift_amount = asm.alloc_node(Const::I32(shift));
308+
let masked_shifted = asm.alloc_node(CILNode::call(rshift, [masked, shift_amount]));
311309
let inv_masked_shifted =
312-
asm.alloc_node(CILNode::call(lshift, [inv_masked, shift_ammount]));
310+
asm.alloc_node(CILNode::call(lshift, [inv_masked, shift_amount]));
313311

314312
let curr_val = asm.alloc_node(CILNode::call(or, [masked_shifted, inv_masked_shifted]));
315313
trees.push(asm.alloc_root(CILRoot::StLoc(0, curr_val)));

cilly/src/v2/builtins/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub use int128::*;
2222
pub mod f16;
2323
pub use f16::*;
2424
pub mod simd;
25+
pub mod unwind;
2526

2627
pub fn insert_swap_at_generic(asm: &mut Assembly, patcher: &mut MissingMethodPatcher) {
2728
let name = asm.alloc_string("swap_at_generic");
@@ -588,7 +589,7 @@ fn insert_catch_unwind(asm: &mut Assembly, patcher: &mut MissingMethodPatcher) {
588589
target: 2,
589590
source: 0,
590591
});
591-
let exit_try_faliure = asm.alloc_root(CILRoot::ExitSpecialRegion {
592+
let exit_try_failure = asm.alloc_root(CILRoot::ExitSpecialRegion {
592593
target: 3,
593594
source: 0,
594595
});
@@ -641,7 +642,7 @@ fn insert_catch_unwind(asm: &mut Assembly, patcher: &mut MissingMethodPatcher) {
641642
set_exception,
642643
rethrow_if_wrong_exception,
643644
calli_catch,
644-
exit_try_faliure,
645+
exit_try_failure,
645646
],
646647
1,
647648
None,

cilly/src/v2/c_exporter/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ impl CExporter {
601601
PtrCastRes::ISize => format!("(intptr_t)({node})"),
602602
}
603603
}
604-
CILNode::LdFieldAdress { addr, field } => {
604+
CILNode::LdFieldAddress { addr, field } => {
605605
let addr = asm[addr].clone();
606606
let addr = Self::node_to_string(addr, asm, locals, inputs, sig)?;
607607
let field = asm[field];
@@ -726,7 +726,7 @@ impl CExporter {
726726
class_member_name(&asm[class.name()], &escape_nonfn_name(&asm[field.name()]));
727727
fname.to_string()
728728
}
729-
CILNode::LdStaticFieldAdress(static_field_idx) => {
729+
CILNode::LdStaticFieldAddress(static_field_idx) => {
730730
let field = asm[static_field_idx];
731731
let class = asm[field.owner()].clone();
732732
let fname =

0 commit comments

Comments
 (0)