aboutsummaryrefslogtreecommitdiff
path: root/backend/utils/TableGen/CallingConvEmitter.cpp
diff options
context:
space:
mode:
authorRichard-Qin-X <richard.qin.001@gmail.com>2026-08-13 13:10:47 +0800
committerRichard-Qin-X <richard.qin.001@gmail.com>2026-08-13 13:10:47 +0800
commit444db30751380e8fe459bfeae4c5bb2a93c596eb (patch)
tree5c60a23678f836113e75fb2526d3ec7b28b42f55 /backend/utils/TableGen/CallingConvEmitter.cpp
parentfde3e045d4dcc5c404cb4216389e18b0e720b8e0 (diff)
downloadrcc-project-444db30751380e8fe459bfeae4c5bb2a93c596eb.tar.gz
rcc-project-444db30751380e8fe459bfeae4c5bb2a93c596eb.tar.xz
[TableGen] Split the target description generator
Diffstat (limited to 'backend/utils/TableGen/CallingConvEmitter.cpp')
-rw-r--r--backend/utils/TableGen/CallingConvEmitter.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/backend/utils/TableGen/CallingConvEmitter.cpp b/backend/utils/TableGen/CallingConvEmitter.cpp
new file mode 100644
index 0000000..d71241e
--- /dev/null
+++ b/backend/utils/TableGen/CallingConvEmitter.cpp
@@ -0,0 +1,58 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#include "TableGenBackends.h"
+
+#include <cstdint>
+#include <ostream>
+#include <span>
+#include <sstream>
+#include <string>
+#include <string_view>
+
+namespace rcc::targetgen {
+namespace {
+
+void emitPhysicalRegisterArray(std::ostream &Output, const NormalizedTargetModel &Model,
+ std::string_view Name, std::span<const std::uint32_t> IDs) {
+ Output << "const std::array<PhysicalRegister, " << IDs.size() << "> " << Name << " = {{\n";
+ for (const std::uint32_t ID : IDs)
+ Output << " physical(PhysicalRegisterID::" << findRegister(Model, ID).Symbol << "),\n";
+ Output << "}};\n";
+}
+
+} // namespace
+
+std::string emitCallingConventions(const NormalizedTargetModel &Model) {
+ std::ostringstream Output;
+ for (const NormalizedCallingConvention &Convention : Model.CallingConventions) {
+ const std::string Prefix = "CC" + std::to_string(Convention.ID);
+ emitPhysicalRegisterArray(Output, Model, Prefix + "IntegerArguments",
+ Convention.IntegerArgumentRegisters);
+ emitPhysicalRegisterArray(Output, Model, Prefix + "FloatingArguments",
+ Convention.FloatingArgumentRegisters);
+ emitPhysicalRegisterArray(Output, Model, Prefix + "IntegerReturns",
+ Convention.IntegerReturnRegisters);
+ emitPhysicalRegisterArray(Output, Model, Prefix + "FloatingReturns",
+ Convention.FloatingReturnRegisters);
+ }
+ Output << "const std::array<CallingConventionInfo, " << Model.CallingConventions.size()
+ << "> GeneratedCallingConventions = {{\n";
+ for (const NormalizedCallingConvention &Convention : Model.CallingConventions) {
+ const std::string Prefix = "CC" + std::to_string(Convention.ID);
+ Output << " {CallingConvention::" << Convention.Symbol << ", ";
+ appendQuoted(Output, Convention.Name);
+ Output << ", RegisterClassID::fromValue(" << Convention.IntegerRegisterClass
+ << "), RegisterClassID::fromValue(" << Convention.FloatingRegisterClass << "), "
+ << Prefix << "IntegerArguments, " << Prefix << "FloatingArguments, " << Prefix
+ << "IntegerReturns, " << Prefix << "FloatingReturns, ";
+ appendQuoted(Output, Convention.PreservedMaskName);
+ Output << ", " << Convention.StackAlignmentBytes << ", "
+ << Convention.StackArgumentAlignmentBytes << ", " << Convention.ShadowSpaceBytes << ", "
+ << (Convention.SupportsVarArgs ? "true" : "false") << ", "
+ << (Convention.SupportsTailCalls ? "true" : "false") << "},\n";
+ }
+ Output << "}};\n";
+ return Output.str();
+}
+
+} // namespace rcc::targetgen