Skip to content

Commit

Permalink
Small bugifixes + changes to actions
Browse files Browse the repository at this point in the history
  • Loading branch information
FractalFir committed Feb 15, 2024
1 parent c9739ec commit 2d43bab
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 37 deletions.
18 changes: 0 additions & 18 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,5 @@ jobs:
run: ilasm --version
- name: Run cargo tests
run: cargo test --verbose ::stable
windows_test:

runs-on: windows-latest

steps:
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose
- name: Setup dotnet
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0.x'
#- name: Install ILASM
#run: dotnet add package Microsoft.NETCore.ILAsm --version 8.0.0
- name: Check ILASM
run: ilasm --version
- name: Run cargo tests
run: cargo test --verbose ::stable


17 changes: 17 additions & 0 deletions src/casts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ pub fn int_to_int(src: Type, target: Type) -> Vec<CILOp> {
return vec![];
}
match (&src, &target) {
/*
(Type::DotnetType(tpe), Type::I128) | (Type::I128,Type::DotnetType(tpe))=>{
if Some("System.Runtime".into()) == tpe.asm() && tpe.name_path().contains("System.Int128"){
return vec![];
}
panic!();
}*/
(Type::ISize, Type::I128) => vec![
CILOp::ConvI64(false),
CILOp::Call(
Expand Down Expand Up @@ -57,6 +64,15 @@ pub fn int_to_int(src: Type, target: Type) -> Vec<CILOp> {
.into(),
),
],
(Type::U128,Type::I128) => vec![CILOp::Call(
CallSite::new(
Some(DotnetTypeRef::uint_128()),
"op_Explicit".into(),
FnSig::new(&[src], &target),
true,
)
.into(),
)],
(_, Type::I128) => {
vec![CILOp::Call(
CallSite::new(
Expand All @@ -77,6 +93,7 @@ pub fn int_to_int(src: Type, target: Type) -> Vec<CILOp> {
)
.into(),
)],

(Type::I8 | Type::I16 | Type::I32 | Type::I64, Type::U128) => vec![CILOp::Call(
CallSite::new(
Some(DotnetTypeRef::uint_128()),
Expand Down
27 changes: 20 additions & 7 deletions src/compile_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ fn test_dotnet_executable(file_path: &str, test_dir: &str) -> String {
file.write_all(RUNTIME_CONFIG.as_bytes())
.expect("Could not write runtime config");
//RUNTIME_CONFIG
let mut cmd = std::process::Command::new("dotnet");
let mut cmd = std::process::Command::new("timeout");
cmd.arg("-v");
cmd.arg("5");
cmd.arg("dotnet");
cmd.current_dir(test_dir).args([exec_path]);
#[cfg(target_family = "unix")]
with_stack_size(&mut cmd, 1024 * 20);
with_stack_size(&mut cmd, 1024 * 80);
let out = cmd.output().expect("failed to run test assebmly!");

let stderr = String::from_utf8(out.stderr).expect("Stdout is not UTF8 String!");
Expand Down Expand Up @@ -152,7 +155,6 @@ macro_rules! compare_tests {
//"--target",
//"clr64-unknown-clr"
]);
eprintln!("Command: {cmd:?}");
let out = cmd.output().expect("failed to execute process");
// If stderr is not empty, then something went wrong, so print the stdout and stderr for debuging.
if !out.stderr.is_empty() {
Expand Down Expand Up @@ -181,7 +183,6 @@ macro_rules! compare_tests {
"--edition",
"2021",
]);
eprintln!("Buildin");
let out = cmd.output().expect("failed to execute process");
// If stderr is not empty, then something went wrong, so print the stdout and stderr for debuging.
if !out.stderr.is_empty() {
Expand All @@ -202,7 +203,10 @@ macro_rules! compare_tests {
.expect("failed to execute process");
let rust_out = String::from_utf8(rust_out.stdout)
.expect("rust error contained non-UTF8 characters.");
assert_eq!(rust_out, dotnet_out);
if rust_out != dotnet_out{
panic!("rust_out:\n{rust_out}\n\ndotnet_out:\n{dotnet_out}");
}

if should_panic {
panic!("{rust_out}{dotnet_out}");
}
Expand Down Expand Up @@ -598,15 +602,14 @@ fn with_stack_size(cmd: &mut Command, limit_kb: u64) {

unsafe {
cmd.pre_exec(move || {
unsafe {

setrlimit(
RLIMIT_STACK,
&rlimit {
rlim_cur: limit_kb * 1024,
rlim_max: limit_kb * 1024,
},
);
}
Ok(())
})
};
Expand Down Expand Up @@ -712,6 +715,16 @@ compare_tests! {fuzz,fuzz6,unstable}
compare_tests! {fuzz,fuzz7,unstable}
compare_tests! {fuzz,fuzz8,unstable}
compare_tests! {fuzz,fuzz9,stable}
compare_tests! {fuzz,fuzz10,unstable}
compare_tests! {fuzz,fuzz11,unstable}
compare_tests! {fuzz,fuzz12,unstable}
compare_tests! {fuzz,fuzz13,unstable}
compare_tests! {fuzz,fuzz14,stable}
compare_tests! {fuzz,fuzz15,unstable}
compare_tests! {fuzz,fuzz16,unstable}
compare_tests! {fuzz,fuzz17,unstable}
compare_tests! {fuzz,fuzz18,unstable}
compare_tests! {fuzz,fuzz19,unstable}

run_test! {fuzz,fail0,stable}

Expand Down
10 changes: 8 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,24 @@ macro_rules! config_flag{
}
}
config_flag! {ABORT_ON_ERROR,false,"Should the codegen stop working when ecountering an error, or try to press on, replacing unusuported code with exceptions throws?"}
config_flag! {TEST_WITH_MONO,false}


config_flag! {TRACE_CALLS,false,"Preapends each function call with a debug message"}
config_flag! {ALWAYS_INIT_LOCALS,false,"Changes `.locals` into `.locals init`. Causes the runtime to always initialize local variables.\nTry turining on in cause of issues. If it fixes them, then their root cause is use of uninitailized memory."}
config_flag! {TRACE_STATEMENTS,false,"Preapends each statement with a debug message"}

config_flag! {ALWAYS_INIT_LOCALS,false,"Changes `.locals` into `.locals init`. Causes the runtime to always initialize local variables.\nTry turining on in cause of issues. If it fixes them, then their root cause is use of uninitailized memory."}

config_flag! {INLINE_SIMPLE_FUNCTIONS,false,"Allows the optimizer to inline very simple functions. It is buggy."}
config_flag! {REMOVE_UNSUED_LOCALS,false,"Turns on the local removal optimization."}
config_flag! {CHECK_ALLOCATIONS,false,"Turns on allocation checks/debug info."}
config_flag! {VERIFY_METHODS,false,"Typechecks all methods"}

config_flag! {SPLIT_LOCAL_STRUCTS,false,"Turns on the struct spliting optimzation."}
config_flag! {ALLOW_MISCOMPILATIONS,true,"Should the codegen continue working after it encoutnered a miscompilation?"}
config_flag! {INSERT_MIR_DEBUG_COMMENTS,false,"Tells the codegen to insert comments containing the MIR statemtens after each one of them."}
config_flag! {PRINT_LOCAL_TYPES,false,"Prints local types of all compiled MIR functions."}
config_flag! {OPTIMIZE_CIL,true,"Tells the codegen to optmize the emiited CIL."}
config_flag! {USE_CECIL_EXPORTER,false,"Tells the codegen to use the CECIL based assembly exporter"}
config_flag! {ESCAPE_NAMES,false,"Tells the codegen to escape class and method names."}

config_flag! {TEST_WITH_MONO,false}
3 changes: 3 additions & 0 deletions src/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ impl Method {
pub fn ops_mut(&mut self) -> &mut Vec<CILOp> {
&mut self.ops
}
pub fn ops_n_locals_mut(&mut self) -> (&mut Vec<CILOp>,&mut [(Option<IString>,Type)]) {
(&mut self.ops,&mut self.locals)
}
/// Returns the access modifier of this function.
pub fn access(&self) -> AccessModifer {
self.access
Expand Down
3 changes: 2 additions & 1 deletion src/opt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ pub fn opt_method(method: &mut Method, asm: &Assembly) {
repalce_const_sizes(method.ops_mut());
let mut cache = LocalAccessRangeCache::new();
for pass in 0..MAX_PASS {
op2_combos::optimize_combos(method.ops_mut());
let (ops,locals) = method.ops_n_locals_mut();
op2_combos::optimize_combos(ops,locals);
op3_combos::optimize_combos(method.ops_mut());
op4_combos(method.ops_mut());
let local_count = method.locals().len();
Expand Down
21 changes: 13 additions & 8 deletions src/opt/op2_combos.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::cil::CILOp;
use crate::{cil::CILOp, r#type::Type, IString};

pub fn optimize_combos(ops: &mut Vec<CILOp>) {
pub fn optimize_combos(ops: &mut Vec<CILOp>,locals:&[(Option<IString>,Type)]) {
if ops.is_empty() {
return;
}
Expand All @@ -20,13 +20,18 @@ pub fn optimize_combos(ops: &mut Vec<CILOp>) {
ops[idx] = CILOp::Nop;
ops[idx + 1] = CILOp::Nop;
}
} /*
}
(CILOp::STLoc(a), CILOp::LDLoc(b)) => {
if a == b {
ops[idx + 1] = CILOp::STLoc(*a);
ops[idx] = CILOp::Dup;
}
} */
if a == b {
match locals[*a as usize].1{
// Assigment acts as a hidden cast
Type::I8 | Type::U8 | Type::I16 | Type::U16 => continue,
_=>(),
}
ops[idx + 1] = CILOp::STLoc(*a);
ops[idx] = CILOp::Dup;
}
}
(CILOp::Dup | CILOp::LDLoc(_) | CILOp::LDLocA(_), CILOp::Pop) => {
ops[idx] = CILOp::Nop;
ops[idx + 1] = CILOp::Nop;
Expand Down
3 changes: 2 additions & 1 deletion src/verify/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ fn verify_op(
CILOp::GoTo(_) => Ok(()),
CILOp::LDTypeToken(_) => Ok(stack.push(DotnetTypeRef::type_handle_type().into())),
CILOp::LdcI32(_) | CILOp::SizeOf(_) => Ok(stack.push(Type::I32)),
CILOp::LdcU32(_)=> Ok(stack.push(Type::U32)),
CILOp::LdcF32(_) => Ok(stack.push(Type::F32)),
CILOp::LdcI64(_) => Ok(stack.push(Type::I64)),
CILOp::LdcF64(_) => Ok(stack.push(Type::F64)),
Expand Down Expand Up @@ -539,7 +540,7 @@ fn verify_op(
) {
return Err(VerificationFailure::StackUnexpected(ptr));
}
if stack_input == **tpe {
if equivalent(&stack_input , tpe) {
Ok(())
} else {
Err(VerificationFailure::StackUnexpected(stack_input))
Expand Down

0 comments on commit 2d43bab

Please sign in to comment.