Skip to content

Commit 0079ca9

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

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

compiler/rustc_abi/src/canon_abi.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ impl fmt::Display for CanonAbi {
100100
}
101101

102102
impl CanonAbi {
103+
pub fn as_str(&self) -> &str {
104+
self.to_erased_extern_abi().as_str()
105+
}
103106
/// convert to the ExternAbi that *shares a string* with this CanonAbi
104107
///
105108
/// NOT correct to use if you want to map CanonAbi to an ABI it may have been lowered from,

compiler/rustc_abi/src/map.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,4 +335,60 @@ 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(), self.system.as_str().to_owned().into());
343+
json_obj
344+
.insert("system-varargs".to_owned(), self.system_varargs.as_str().to_owned().into());
345+
json_obj.insert("rust-cold".to_owned(), self.rust_cold.as_str().to_owned().into());
346+
if let Some(abi) = self.efiapi {
347+
json_obj.insert("efiapi".to_owned(), abi.as_str().to_owned().into());
348+
}
349+
if let Some(abi) = self.stdcall {
350+
json_obj.insert("stdcall".to_owned(), abi.as_str().to_owned().into());
351+
}
352+
if let Some(abi) = self.fastcall {
353+
json_obj.insert("fastcall".to_owned(), abi.as_str().to_owned().into());
354+
}
355+
if let Some(abi) = self.thiscall {
356+
json_obj.insert("thiscall".to_owned(), abi.as_str().to_owned().into());
357+
}
358+
if let Some(abi) = self.vectorcall {
359+
json_obj.insert("vectorcall".to_owned(), abi.as_str().to_owned().into());
360+
}
361+
if let Some(abi) = self.win64 {
362+
json_obj.insert("win64".to_owned(), abi.as_str().to_owned().into());
363+
}
364+
if let Some(abi) = self.sysv64 {
365+
json_obj.insert("sysv64".to_owned(), abi.as_str().to_owned().into());
366+
}
367+
if self.cmse_nonsecure_entry {
368+
json_obj.insert("cmse-nonsecure-entry".to_owned(), JsonValue::Bool(true));
369+
}
370+
if self.aapcs {
371+
json_obj.insert("aapcs".to_owned(), JsonValue::Bool(true));
372+
}
373+
if self.gpu_kernel {
374+
json_obj.insert("gpu-kernel".to_owned(), JsonValue::Bool(true));
375+
}
376+
if self.ptx_kernel {
377+
json_obj.insert("ptx-kernel".to_owned(), JsonValue::Bool(true));
378+
}
379+
if self.avr_interrupt {
380+
json_obj.insert("avr-interrupt".to_owned(), JsonValue::Bool(true));
381+
}
382+
if self.msp430_interrupt {
383+
json_obj.insert("msp430-interrupt".to_owned(), JsonValue::Bool(true));
384+
}
385+
if self.riscv_interrupt {
386+
json_obj.insert("riscv-interrupt".to_owned(), JsonValue::Bool(true));
387+
}
388+
if self.x86_interrupt {
389+
json_obj.insert("x86-interrupt".to_owned(), JsonValue::Bool(true));
390+
}
391+
392+
json_obj
393+
}
338394
}

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)