Skip to content

Commit 1d52d41

Browse files
committed
cookie-cutter: add bin for asm analysis
1 parent 5b13a6d commit 1d52d41

File tree

3 files changed

+195
-3
lines changed

3 files changed

+195
-3
lines changed

Cargo.lock

Lines changed: 140 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cookie-cutter/Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,18 @@ edition = "2021"
66
[dependencies]
77
macros = { path = "../macros", version = "0.1.0" }
88
fill-array = "0.2.1"
9+
10+
# for binary
11+
panic-halt = { version = "1.0.0", optional = true }
12+
cortex-m = { version = "0.7.7", optional = true }
13+
cortex-m-rt = { version = "0.7.3", optional = true }
14+
15+
[features]
16+
binary = ["dep:panic-halt", "dep:cortex-m", "cortex-m-rt"]
17+
cortex-m-rt = ["dep:cortex-m-rt"]
18+
19+
[[bin]]
20+
name = "test"
21+
bench = false
22+
test = false
23+
required-features = ["binary"]

cookie-cutter/src/bin/test.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#![no_std]
2+
#![no_main]
3+
4+
use core::ptr::{null, null_mut, read_volatile, write_volatile};
5+
6+
use panic_halt as _;
7+
8+
use cookie_cutter::{encoding::vanilla, SerializeIter};
9+
use cortex_m_rt::entry;
10+
11+
#[derive(vanilla::SerializeIter)]
12+
struct Foo {
13+
a: u32,
14+
b: u16,
15+
}
16+
17+
#[inline(never)]
18+
fn deserialize<const N: usize>(buf: &[u8; N]) -> Foo {
19+
unsafe { Foo::deserialize_iter(buf).unwrap_unchecked() }
20+
}
21+
22+
#[inline(never)]
23+
fn serialize<const N: usize>(foo: Foo, buf: &mut [u8; N]) {
24+
unsafe { foo.serialize_iter(buf).unwrap_unchecked() }
25+
}
26+
27+
#[entry]
28+
fn main() -> ! {
29+
let buf = unsafe { read_volatile(null() as *const [u8; 20]) };
30+
31+
let foo = deserialize(&buf);
32+
33+
let mut buf = [0; 20];
34+
35+
serialize(foo, &mut buf);
36+
37+
unsafe { write_volatile(null_mut(), buf) };
38+
39+
loop {}
40+
}

0 commit comments

Comments
 (0)