From 4b2723abb0e4bb9d10525c5f16bfd2582edcd9a9 Mon Sep 17 00:00:00 2001
From: Chris Fallin <chris@cfallin.org>
Date: Thu, 24 Jun 2021 11:03:47 -0700
Subject: [PATCH] cranelift-codegen: move old x86 and RISC-V backends to
 isa/legacy/.

These backends will be removed in the future (see
bytecodealliance/rfcs#12 and the pending #3009 in this repo).

In the meantime, to more clearly communicate that they are using
"legacy" APIs and will eventually be removed, this PR places them in an
`isa/legacy/` subdirectory. No functional changes otherwise.
---
 cranelift/codegen/src/isa/legacy/mod.rs       | 12 +++++++++++
 .../codegen/src/isa/{ => legacy}/riscv/abi.rs |  0
 .../src/isa/{ => legacy}/riscv/binemit.rs     |  0
 .../src/isa/{ => legacy}/riscv/enc_tables.rs  |  0
 .../codegen/src/isa/{ => legacy}/riscv/mod.rs |  0
 .../src/isa/{ => legacy}/riscv/registers.rs   |  0
 .../src/isa/{ => legacy}/riscv/settings.rs    |  0
 .../codegen/src/isa/{ => legacy}/x86/abi.rs   |  2 +-
 .../src/isa/{ => legacy}/x86/binemit.rs       |  0
 .../src/isa/{ => legacy}/x86/enc_tables.rs    |  0
 .../codegen/src/isa/{ => legacy}/x86/mod.rs   |  2 +-
 .../src/isa/{ => legacy}/x86/registers.rs     |  0
 .../src/isa/{ => legacy}/x86/settings.rs      |  0
 .../src/isa/{ => legacy}/x86/unwind.rs        |  0
 .../isa/{ => legacy}/x86/unwind/systemv.rs    |  0
 .../src/isa/{ => legacy}/x86/unwind/winx64.rs |  0
 cranelift/codegen/src/isa/mod.rs              | 20 +++++++++----------
 17 files changed, 23 insertions(+), 13 deletions(-)
 create mode 100644 cranelift/codegen/src/isa/legacy/mod.rs
 rename cranelift/codegen/src/isa/{ => legacy}/riscv/abi.rs (100%)
 rename cranelift/codegen/src/isa/{ => legacy}/riscv/binemit.rs (100%)
 rename cranelift/codegen/src/isa/{ => legacy}/riscv/enc_tables.rs (100%)
 rename cranelift/codegen/src/isa/{ => legacy}/riscv/mod.rs (100%)
 rename cranelift/codegen/src/isa/{ => legacy}/riscv/registers.rs (100%)
 rename cranelift/codegen/src/isa/{ => legacy}/riscv/settings.rs (100%)
 rename cranelift/codegen/src/isa/{ => legacy}/x86/abi.rs (99%)
 rename cranelift/codegen/src/isa/{ => legacy}/x86/binemit.rs (100%)
 rename cranelift/codegen/src/isa/{ => legacy}/x86/enc_tables.rs (100%)
 rename cranelift/codegen/src/isa/{ => legacy}/x86/mod.rs (98%)
 rename cranelift/codegen/src/isa/{ => legacy}/x86/registers.rs (100%)
 rename cranelift/codegen/src/isa/{ => legacy}/x86/settings.rs (100%)
 rename cranelift/codegen/src/isa/{ => legacy}/x86/unwind.rs (100%)
 rename cranelift/codegen/src/isa/{ => legacy}/x86/unwind/systemv.rs (100%)
 rename cranelift/codegen/src/isa/{ => legacy}/x86/unwind/winx64.rs (100%)

diff --git a/cranelift/codegen/src/isa/legacy/mod.rs b/cranelift/codegen/src/isa/legacy/mod.rs
new file mode 100644
index 000000000000..a89230f941c7
--- /dev/null
+++ b/cranelift/codegen/src/isa/legacy/mod.rs
@@ -0,0 +1,12 @@
+//! Legacy ("old-style") backends that will be removed in the future.
+
+// N.B.: the old x86-64 backend (`x86`) and the new one (`x64`) are both
+// included whenever building with x86 support. The new backend is the default,
+// but the old can be requested with `BackendVariant::Legacy`. However, if this
+// crate is built with the `old-x86-backend` feature, then the old backend is
+// default instead.
+#[cfg(feature = "x86")]
+pub(crate) mod x86;
+
+#[cfg(feature = "riscv")]
+pub(crate) mod riscv;
diff --git a/cranelift/codegen/src/isa/riscv/abi.rs b/cranelift/codegen/src/isa/legacy/riscv/abi.rs
similarity index 100%
rename from cranelift/codegen/src/isa/riscv/abi.rs
rename to cranelift/codegen/src/isa/legacy/riscv/abi.rs
diff --git a/cranelift/codegen/src/isa/riscv/binemit.rs b/cranelift/codegen/src/isa/legacy/riscv/binemit.rs
similarity index 100%
rename from cranelift/codegen/src/isa/riscv/binemit.rs
rename to cranelift/codegen/src/isa/legacy/riscv/binemit.rs
diff --git a/cranelift/codegen/src/isa/riscv/enc_tables.rs b/cranelift/codegen/src/isa/legacy/riscv/enc_tables.rs
similarity index 100%
rename from cranelift/codegen/src/isa/riscv/enc_tables.rs
rename to cranelift/codegen/src/isa/legacy/riscv/enc_tables.rs
diff --git a/cranelift/codegen/src/isa/riscv/mod.rs b/cranelift/codegen/src/isa/legacy/riscv/mod.rs
similarity index 100%
rename from cranelift/codegen/src/isa/riscv/mod.rs
rename to cranelift/codegen/src/isa/legacy/riscv/mod.rs
diff --git a/cranelift/codegen/src/isa/riscv/registers.rs b/cranelift/codegen/src/isa/legacy/riscv/registers.rs
similarity index 100%
rename from cranelift/codegen/src/isa/riscv/registers.rs
rename to cranelift/codegen/src/isa/legacy/riscv/registers.rs
diff --git a/cranelift/codegen/src/isa/riscv/settings.rs b/cranelift/codegen/src/isa/legacy/riscv/settings.rs
similarity index 100%
rename from cranelift/codegen/src/isa/riscv/settings.rs
rename to cranelift/codegen/src/isa/legacy/riscv/settings.rs
diff --git a/cranelift/codegen/src/isa/x86/abi.rs b/cranelift/codegen/src/isa/legacy/x86/abi.rs
similarity index 99%
rename from cranelift/codegen/src/isa/x86/abi.rs
rename to cranelift/codegen/src/isa/legacy/x86/abi.rs
index 69c1e1b7617d..934cfec4dd87 100644
--- a/cranelift/codegen/src/isa/x86/abi.rs
+++ b/cranelift/codegen/src/isa/legacy/x86/abi.rs
@@ -1,6 +1,6 @@
 //! x86 ABI implementation.
 
-use super::super::settings as shared_settings;
+use super::super::super::settings as shared_settings;
 use super::registers::{FPR, GPR, RU};
 use super::settings as isa_settings;
 use crate::abi::{legalize_args, ArgAction, ArgAssigner, ValueConversion};
diff --git a/cranelift/codegen/src/isa/x86/binemit.rs b/cranelift/codegen/src/isa/legacy/x86/binemit.rs
similarity index 100%
rename from cranelift/codegen/src/isa/x86/binemit.rs
rename to cranelift/codegen/src/isa/legacy/x86/binemit.rs
diff --git a/cranelift/codegen/src/isa/x86/enc_tables.rs b/cranelift/codegen/src/isa/legacy/x86/enc_tables.rs
similarity index 100%
rename from cranelift/codegen/src/isa/x86/enc_tables.rs
rename to cranelift/codegen/src/isa/legacy/x86/enc_tables.rs
diff --git a/cranelift/codegen/src/isa/x86/mod.rs b/cranelift/codegen/src/isa/legacy/x86/mod.rs
similarity index 98%
rename from cranelift/codegen/src/isa/x86/mod.rs
rename to cranelift/codegen/src/isa/legacy/x86/mod.rs
index 54efe7fcfdeb..e61fda1931cc 100644
--- a/cranelift/codegen/src/isa/x86/mod.rs
+++ b/cranelift/codegen/src/isa/legacy/x86/mod.rs
@@ -178,7 +178,7 @@ impl TargetIsa for Isa {
     fn create_unwind_info(
         &self,
         func: &ir::Function,
-    ) -> CodegenResult<Option<super::unwind::UnwindInfo>> {
+    ) -> CodegenResult<Option<super::super::unwind::UnwindInfo>> {
         abi::create_unwind_info(func, self)
     }
 
diff --git a/cranelift/codegen/src/isa/x86/registers.rs b/cranelift/codegen/src/isa/legacy/x86/registers.rs
similarity index 100%
rename from cranelift/codegen/src/isa/x86/registers.rs
rename to cranelift/codegen/src/isa/legacy/x86/registers.rs
diff --git a/cranelift/codegen/src/isa/x86/settings.rs b/cranelift/codegen/src/isa/legacy/x86/settings.rs
similarity index 100%
rename from cranelift/codegen/src/isa/x86/settings.rs
rename to cranelift/codegen/src/isa/legacy/x86/settings.rs
diff --git a/cranelift/codegen/src/isa/x86/unwind.rs b/cranelift/codegen/src/isa/legacy/x86/unwind.rs
similarity index 100%
rename from cranelift/codegen/src/isa/x86/unwind.rs
rename to cranelift/codegen/src/isa/legacy/x86/unwind.rs
diff --git a/cranelift/codegen/src/isa/x86/unwind/systemv.rs b/cranelift/codegen/src/isa/legacy/x86/unwind/systemv.rs
similarity index 100%
rename from cranelift/codegen/src/isa/x86/unwind/systemv.rs
rename to cranelift/codegen/src/isa/legacy/x86/unwind/systemv.rs
diff --git a/cranelift/codegen/src/isa/x86/unwind/winx64.rs b/cranelift/codegen/src/isa/legacy/x86/unwind/winx64.rs
similarity index 100%
rename from cranelift/codegen/src/isa/x86/unwind/winx64.rs
rename to cranelift/codegen/src/isa/legacy/x86/unwind/winx64.rs
diff --git a/cranelift/codegen/src/isa/mod.rs b/cranelift/codegen/src/isa/mod.rs
index 481c0c8de310..80a2599d3882 100644
--- a/cranelift/codegen/src/isa/mod.rs
+++ b/cranelift/codegen/src/isa/mod.rs
@@ -70,17 +70,6 @@ use core::fmt::{Debug, Formatter};
 use core::hash::Hasher;
 use target_lexicon::{triple, Architecture, OperatingSystem, PointerWidth, Triple};
 
-#[cfg(feature = "riscv")]
-mod riscv;
-
-// N.B.: the old x86-64 backend (`x86`) and the new one (`x64`) are both
-// included whenever building with x86 support. The new backend is the default,
-// but the old can be requested with `BackendVariant::Legacy`. However, if this
-// crate is built with the `old-x86-backend` feature, then the old backend is
-// default instead.
-#[cfg(feature = "x86")]
-mod x86;
-
 // This module is made public here for benchmarking purposes. No guarantees are
 // made regarding API stability.
 #[cfg(feature = "x86")]
@@ -95,6 +84,15 @@ pub(crate) mod aarch64;
 #[cfg(feature = "s390x")]
 mod s390x;
 
+#[cfg(any(feature = "x86", feature = "riscv"))]
+mod legacy;
+
+#[cfg(feature = "x86")]
+use legacy::x86;
+
+#[cfg(feature = "riscv")]
+use legacy::riscv;
+
 pub mod unwind;
 
 mod call_conv;