Skip to content

Commit 994b8a4

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

File tree

6 files changed

+33
-2
lines changed

6 files changed

+33
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3251,6 +3251,7 @@ dependencies = [
32513251
"rustc_macros",
32523252
"rustc_serialize",
32533253
"rustc_span",
3254+
"serde",
32543255
"serde_json",
32553256
"tracing",
32563257
]

compiler/rustc_abi/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ rustc_index = { path = "../rustc_index", default-features = false }
1414
rustc_macros = { path = "../rustc_macros", optional = true }
1515
rustc_serialize = { path = "../rustc_serialize", optional = true }
1616
rustc_span = { path = "../rustc_span", optional = true }
17-
serde_json = "1"
17+
serde = { version = "1.0.200", features = ["derive"] }
18+
serde_json = "1.0.100"
1819
tracing = "0.1"
1920
# tidy-alphabetical-end
2021

compiler/rustc_abi/src/canon_abi.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ impl fmt::Display for CanonAbi {
9999
}
100100
}
101101

102+
impl serde::Serialize for CanonAbi {
103+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
104+
where
105+
S: serde::Serializer,
106+
{
107+
self.to_erased_extern_abi().as_str().serialize(serializer)
108+
}
109+
}
110+
102111
impl CanonAbi {
103112
/// convert to the ExternAbi that *shares a string* with this CanonAbi
104113
///
@@ -187,6 +196,14 @@ impl CanonAbi {
187196
}
188197
}
189198

199+
impl TryFrom<ExternAbi> for CanonAbi {
200+
type Error = AbiFromStrErr;
201+
202+
fn try_from(extern_abi: ExternAbi) -> Result<Self, Self::Error> {
203+
CanonAbi::try_from_extern_abi(extern_abi)
204+
}
205+
}
206+
190207
impl FromStr for CanonAbi {
191208
type Err = AbiFromStrErr;
192209

compiler/rustc_abi/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,3 +1913,13 @@ pub enum AbiFromJsonErr {
19131913
UnusedKey,
19141914
Parse { kind: AbiFromStrErr, value: String },
19151915
}
1916+
1917+
impl fmt::Display for AbiFromStrErr {
1918+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1919+
match self {
1920+
AbiFromStrErr::Unknown => "no such CanonAbi",
1921+
AbiFromStrErr::NoUnwind => "unwind is not a CanonAbi",
1922+
}
1923+
.fmt(f)
1924+
}
1925+
}

compiler/rustc_abi/src/map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use serde_json::Value as JsonValue;
44

55
use crate::{AbiFromJsonErr, ArmCall, CanonAbi, ExternAbi, InterruptKind};
66

7-
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
7+
#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize)]
88
pub struct AbiMap {
99
/// a target may support ABIs that are "proper names" for the C ABI, otherwise this is "C"
1010
pub c_proper: CanonAbi,

compiler/rustc_target/src/spec/json.rs

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

770+
d.insert("abi-map".to_owned(), serde_json::to_value(self.abi_map.clone()).unwrap());
771+
770772
target_val!(llvm_target);
771773
target_val!(metadata);
772774
d.insert("target-pointer-width".to_string(), self.pointer_width.to_string().to_json());

0 commit comments

Comments
 (0)