Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammadfawaz committed Jul 7, 2022
1 parent 6a9f849 commit 85a8707
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 133 deletions.
6 changes: 3 additions & 3 deletions sway-core/src/asm_generation/from_ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ impl<'ir> AsmBuilder<'ir> {
self.stack_base_reg.as_ref().unwrap().clone(),
instr_reg.clone(),
)),
comment: "get offset reg for get_ptr".into(),
comment: "get large offset reg for get_ptr".into(),
owning_span: instr_val.get_span(self.context),
});
} else {
Expand Down Expand Up @@ -1404,7 +1404,7 @@ impl<'ir> AsmBuilder<'ir> {
if word_offs > compiler_constants::TWELVE_BITS {
let offs_reg = self.reg_seqr.next();
self.number_to_reg(
word_offs,
word_offs * 8, // Base reg for LW is in bytes
&offs_reg,
instr_val.get_span(self.context),
);
Expand Down Expand Up @@ -1789,7 +1789,7 @@ impl<'ir> AsmBuilder<'ir> {
if word_offs > compiler_constants::TWELVE_BITS {
let offs_reg = self.reg_seqr.next();
self.number_to_reg(
word_offs,
word_offs * 8, // Base reg for SW is in bytes
&offs_reg,
instr_val.get_span(self.context),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,142 +10,178 @@ struct Z {
}

fn main() -> u64 {
// Chosen name forces this variable to show up last in the list of locals in IR
// Chosen names force these variables to show up last in the list of locals in IR so they will
// be allocated last and require the highest offset to be computed
let zzz = Z {
a: 1,
b: 2,
c: 3,
d: 4,
};
let z1 = 5;
let z2 = 6;

// Add enough stack variables to reach > 4096 bytes
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
let b = ZERO_B256;
foo();
foo();
foo();
foo();
foo();
foo();
foo();
foo();
foo();
foo();
foo();
foo();
foo();
foo();
foo();
foo();
foo();
foo();
foo();
foo();
foo();
foo();
foo();
foo();
foo();
foo();
foo();
foo();
foo();
foo();
foo();
foo();
foo();
foo();

return zzz.a + zzz.b + zzz.c + zzz.d
return zzz.a + zzz.b + zzz.c + zzz.d + z1 + z2 // get 16
}

fn foo() {
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
let c = 0;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
category = "run"
expected_result = { action = "return", value = 10 }
expected_result = { action = "return", value = 21 }
validate_abi = true

0 comments on commit 85a8707

Please sign in to comment.