Skip to content

Commit d1e0f69

Browse files
compiler: Serialize AbiMap to specs
1 parent 7d697fd commit d1e0f69

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

compiler/rustc_abi/src/canon_abi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl StableOrd for CanonAbi {
9595

9696
impl fmt::Display for CanonAbi {
9797
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
98-
self.to_erased_extern_abi().fmt(f)
98+
self.to_erased_extern_abi().as_str().fmt(f)
9999
}
100100
}
101101

compiler/rustc_abi/src/map.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,4 +335,62 @@ impl AbiMap {
335335
})
336336
}
337337
}
338+
339+
// serialization
340+
pub fn to_json_object(&self) -> JsonObject {
341+
let mut json_obj = JsonObject::new();
342+
json_obj.insert("system".to_owned(), format!("{}", self.system).to_owned().into());
343+
json_obj.insert(
344+
"system-varargs".to_owned(),
345+
format!("{}", self.system_varargs).to_owned().into(),
346+
);
347+
json_obj.insert("rust-cold".to_owned(), format!("{}", self.rust_cold).to_owned().into());
348+
if let Some(abi) = self.efiapi {
349+
json_obj.insert("efiapi".to_owned(), format!("{abi}").to_owned().into());
350+
}
351+
if let Some(abi) = self.stdcall {
352+
json_obj.insert("stdcall".to_owned(), format!("{abi}").to_owned().into());
353+
}
354+
if let Some(abi) = self.fastcall {
355+
json_obj.insert("fastcall".to_owned(), format!("{abi}").to_owned().into());
356+
}
357+
if let Some(abi) = self.thiscall {
358+
json_obj.insert("thiscall".to_owned(), format!("{abi}").to_owned().into());
359+
}
360+
if let Some(abi) = self.vectorcall {
361+
json_obj.insert("vectorcall".to_owned(), format!("{abi}").to_owned().into());
362+
}
363+
if let Some(abi) = self.win64 {
364+
json_obj.insert("win64".to_owned(), format!("{abi}").to_owned().into());
365+
}
366+
if let Some(abi) = self.sysv64 {
367+
json_obj.insert("sysv64".to_owned(), format!("{abi}").to_owned().into());
368+
}
369+
if self.cmse_nonsecure_entry {
370+
json_obj.insert("cmse-nonsecure-entry".to_owned(), JsonValue::Bool(true).into());
371+
}
372+
if self.aapcs {
373+
json_obj.insert("aapcs".to_owned(), JsonValue::Bool(true).into());
374+
}
375+
if self.gpu_kernel {
376+
json_obj.insert("gpu-kernel".to_owned(), JsonValue::Bool(true).into());
377+
}
378+
if self.ptx_kernel {
379+
json_obj.insert("ptx-kernel".to_owned(), JsonValue::Bool(true).into());
380+
}
381+
if self.avr_interrupt {
382+
json_obj.insert("avr-interrupt".to_owned(), JsonValue::Bool(true).into());
383+
}
384+
if self.msp430_interrupt {
385+
json_obj.insert("msp430-interrupt".to_owned(), JsonValue::Bool(true).into());
386+
}
387+
if self.riscv_interrupt {
388+
json_obj.insert("riscv-interrupt".to_owned(), JsonValue::Bool(true).into());
389+
}
390+
if self.x86_interrupt {
391+
json_obj.insert("x86-interrupt".to_owned(), JsonValue::Bool(true).into());
392+
}
393+
394+
json_obj
395+
}
338396
}

compiler/rustc_target/src/spec/json.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,9 @@ impl ToJson for Target {
767767
}};
768768
}
769769

770+
let abi_map = self.abi_map.to_json_object();
771+
d.insert("abi-map".to_owned(), Value::Object(abi_map));
772+
770773
target_val!(llvm_target);
771774
target_val!(metadata);
772775
d.insert("target-pointer-width".to_string(), self.pointer_width.to_string().to_json());

0 commit comments

Comments
 (0)