Skip to content

Commit b039a4b

Browse files
committed
[cc] improve assembly header comments
1 parent b895e50 commit b039a4b

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

cc/arch/aarch64/codegen.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,10 +1102,10 @@ impl Aarch64CodeGen {
11021102
}
11031103

11041104
fn emit_header(&mut self) {
1105-
// Header comment and initial text section
1106-
self.push_lir(Aarch64Inst::Directive(Directive::Comment(
1107-
"Generated by pcc (AArch64)".into(),
1108-
)));
1105+
// Header comments with compiler and target info (GCC-style)
1106+
for comment in crate::arch::codegen::generate_header_comments(&self.target) {
1107+
self.push_lir(Aarch64Inst::Directive(Directive::Comment(comment)));
1108+
}
11091109
self.push_lir(Aarch64Inst::Directive(Directive::Text));
11101110
}
11111111

cc/arch/codegen.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,40 @@
1212
use crate::ir::Module;
1313
use crate::target::Target;
1414

15+
/// pcc version string for assembly header
16+
pub const PCC_VERSION: &str = env!("CARGO_PKG_VERSION");
17+
18+
/// Generate header comment lines for assembly output (GCC-style)
19+
/// Returns a vector of comment strings to be emitted
20+
pub fn generate_header_comments(target: &Target) -> Vec<String> {
21+
let mut comments = Vec::new();
22+
23+
// Compiler identification
24+
comments.push(format!("Generated by pcc {}", PCC_VERSION));
25+
26+
// Target triple (normalized format)
27+
let os_triple = match target.os {
28+
crate::target::Os::Linux => "unknown-linux-gnu",
29+
crate::target::Os::MacOS => "apple-darwin",
30+
crate::target::Os::FreeBSD => "unknown-freebsd",
31+
};
32+
comments.push(format!("Target: {}-{}", target.arch, os_triple));
33+
34+
// ABI info
35+
comments.push(format!(
36+
"ABI: LP64, pointer={}bit, long={}bit, char={}",
37+
target.pointer_width,
38+
target.long_width,
39+
if target.char_signed {
40+
"signed"
41+
} else {
42+
"unsigned"
43+
}
44+
));
45+
46+
comments
47+
}
48+
1549
/// Trait for architecture-specific code generators
1650
pub trait CodeGenerator {
1751
/// Generate assembly code for the given IR module

cc/arch/x86_64/codegen.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -949,10 +949,10 @@ impl X86_64CodeGen {
949949
}
950950

951951
fn emit_header(&mut self) {
952-
// Header comment and initial text section
953-
self.push_lir(X86Inst::Directive(Directive::Comment(
954-
"Generated by pcc (x86-64)".into(),
955-
)));
952+
// Header comments with compiler and target info (GCC-style)
953+
for comment in crate::arch::codegen::generate_header_comments(&self.target) {
954+
self.push_lir(X86Inst::Directive(Directive::Comment(comment)));
955+
}
956956
self.push_lir(X86Inst::Directive(Directive::Text));
957957
}
958958

0 commit comments

Comments
 (0)