From ab84ad75629b0a4124221023ca91411d2cd62a32 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Tue, 25 Mar 2025 12:46:49 +1300 Subject: Restructure program This commit also includes changes to devices according to the latest devices specification, in particular the math and system devices. --- src/bin/br/formats/clang.rs | 10 ++++++++++ src/bin/br/formats/mod.rs | 24 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 src/bin/br/formats/clang.rs create mode 100644 src/bin/br/formats/mod.rs (limited to 'src/bin/br/formats') diff --git a/src/bin/br/formats/clang.rs b/src/bin/br/formats/clang.rs new file mode 100644 index 0000000..30d80de --- /dev/null +++ b/src/bin/br/formats/clang.rs @@ -0,0 +1,10 @@ +pub fn format_clang(bytecode: &[u8]) -> Vec { + let mut output = String::new(); + for chunk in bytecode.chunks(16) { + for byte in chunk { + output.push_str(&format!("0x{byte:02x}, ")); + } + output.push('\n'); + } + return output.into_bytes(); +} diff --git a/src/bin/br/formats/mod.rs b/src/bin/br/formats/mod.rs new file mode 100644 index 0000000..b159b16 --- /dev/null +++ b/src/bin/br/formats/mod.rs @@ -0,0 +1,24 @@ +mod clang; + +pub use clang::*; + +use log::fatal; + + +#[derive(Clone, Copy, PartialEq)] +pub enum Format { + Binary, + Source, + Clang, +} + +impl Format { + pub fn from_str(string: &str) -> Self { + match string { + "binary" => Self::Binary, + "source" => Self::Source, + "c" => Self::Clang, + _ => fatal!("Unknown format '{string}', expected 'binary', 'c', or 'source'"), + } + } +} -- cgit v1.2.3-70-g09d2