Skip to content

Commit 5128ff6

Browse files
committed
bin2c: Honor symbol alignment
1 parent dd60128 commit 5128ff6

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "decomp-toolkit"
33
description = "Yet another GameCube/Wii decompilation toolkit."
44
authors = ["Luke Street <[email protected]>"]
55
license = "MIT OR Apache-2.0"
6-
version = "0.6.2"
6+
version = "0.6.3"
77
edition = "2021"
88
publish = false
99
repository = "https://github.com/encounter/decomp-toolkit"

src/util/bin2c.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
use crate::obj::{ObjSection, ObjSectionKind, ObjSymbol};
22

3+
const PROLOGUE: &str = r#"
4+
#ifndef ATTRIBUTE_ALIGN
5+
#if defined(__MWERKS__) || defined(__GNUC__)
6+
#define ATTRIBUTE_ALIGN(num) __attribute__((aligned(num)))
7+
#elif defined(_MSC_VER) || defined(__INTELLISENSE__)
8+
#define ATTRIBUTE_ALIGN(num)
9+
#else
10+
#error unknown compiler
11+
#endif
12+
#endif
13+
14+
"#;
15+
316
/// Converts a binary blob into a C array.
417
pub fn bin2c(symbol: &ObjSymbol, section: &ObjSection, data: &[u8]) -> String {
518
let mut output = String::new();
19+
output.push_str(PROLOGUE);
620
output.push_str(&format!(
721
"// {} (size: {:#X}, address: {:#X}, section: {})\n",
822
symbol.name, symbol.size, symbol.address, section.name
@@ -15,7 +29,7 @@ pub fn bin2c(symbol: &ObjSymbol, section: &ObjSection, data: &[u8]) -> String {
1529
}
1630
output.push_str("unsigned char ");
1731
output.push_str(symbol.demangled_name.as_deref().unwrap_or(symbol.name.as_str()));
18-
output.push_str("[] = {");
32+
output.push_str(&format!("[] ATTRIBUTE_ALIGN({}) = {{", symbol.align.unwrap_or(4)));
1933
for (i, byte) in data.iter().enumerate() {
2034
if i % 16 == 0 {
2135
output.push_str("\n ");

0 commit comments

Comments
 (0)