Skip to content

Commit

Permalink
cookie-cutter: add bin for asm analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
AdinAck committed Nov 1, 2024
1 parent 5b13a6d commit 1d52d41
Show file tree
Hide file tree
Showing 3 changed files with 195 additions and 3 deletions.
143 changes: 140 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions cookie-cutter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,18 @@ edition = "2021"
[dependencies]
macros = { path = "../macros", version = "0.1.0" }
fill-array = "0.2.1"

# for binary
panic-halt = { version = "1.0.0", optional = true }
cortex-m = { version = "0.7.7", optional = true }
cortex-m-rt = { version = "0.7.3", optional = true }

[features]
binary = ["dep:panic-halt", "dep:cortex-m", "cortex-m-rt"]
cortex-m-rt = ["dep:cortex-m-rt"]

[[bin]]
name = "test"
bench = false
test = false
required-features = ["binary"]
40 changes: 40 additions & 0 deletions cookie-cutter/src/bin/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#![no_std]
#![no_main]

use core::ptr::{null, null_mut, read_volatile, write_volatile};

use panic_halt as _;

use cookie_cutter::{encoding::vanilla, SerializeIter};
use cortex_m_rt::entry;

#[derive(vanilla::SerializeIter)]
struct Foo {
a: u32,
b: u16,
}

#[inline(never)]
fn deserialize<const N: usize>(buf: &[u8; N]) -> Foo {
unsafe { Foo::deserialize_iter(buf).unwrap_unchecked() }
}

#[inline(never)]
fn serialize<const N: usize>(foo: Foo, buf: &mut [u8; N]) {
unsafe { foo.serialize_iter(buf).unwrap_unchecked() }
}

#[entry]
fn main() -> ! {
let buf = unsafe { read_volatile(null() as *const [u8; 20]) };

let foo = deserialize(&buf);

let mut buf = [0; 20];

serialize(foo, &mut buf);

unsafe { write_volatile(null_mut(), buf) };

loop {}
}

0 comments on commit 1d52d41

Please sign in to comment.