[llvm] [Offload][NFC] Use tablegen names rather than `name` parameter for API (PR #154736)
Ross Brunton via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 21 04:30:52 PDT 2025
https://github.com/RossBrunton created https://github.com/llvm/llvm-project/pull/154736
None
>From 089ac8836921423a1c7d2ec336102757f33de612 Mon Sep 17 00:00:00 2001
From: Ross Brunton <ross at codeplay.com>
Date: Thu, 21 Aug 2025 12:30:16 +0100
Subject: [PATCH] [Offload][NFC] Use tablegen names rather than `name`
parameter for API
---
offload/liboffload/API/APIDefs.td | 1 -
offload/liboffload/API/Common.td | 60 +++++++------------
offload/liboffload/API/Device.td | 24 +++-----
offload/liboffload/API/Event.td | 18 ++----
offload/liboffload/API/Kernel.td | 9 +--
offload/liboffload/API/Memory.td | 12 ++--
offload/liboffload/API/Platform.td | 12 ++--
offload/liboffload/API/Program.td | 6 +-
offload/liboffload/API/Queue.td | 27 +++------
offload/liboffload/API/Symbol.td | 15 ++---
offload/tools/offload-tblgen/MiscGen.cpp | 4 +-
offload/tools/offload-tblgen/RecordTypes.hpp | 63 ++++++++------------
12 files changed, 88 insertions(+), 163 deletions(-)
diff --git a/offload/liboffload/API/APIDefs.td b/offload/liboffload/API/APIDefs.td
index a30307fc90849..ea3896fc31035 100644
--- a/offload/liboffload/API/APIDefs.td
+++ b/offload/liboffload/API/APIDefs.td
@@ -145,7 +145,6 @@ defvar DefaultReturns = [Return<PREFIX#"_RESULT_SUCCESS">,
Return<PREFIX#"_ERRC_DEVICE_LOST">];
class APIObject {
- string name;
string desc;
}
diff --git a/offload/liboffload/API/Common.td b/offload/liboffload/API/Common.td
index 9a397812e417f..ac27d85b6c964 100644
--- a/offload/liboffload/API/Common.td
+++ b/offload/liboffload/API/Common.td
@@ -10,77 +10,64 @@
//
//===----------------------------------------------------------------------===//
-def : Macro {
- let name = "OL_VERSION_MAJOR";
+def OL_VERSION_MAJOR : Macro {
let desc = "Major version of the Offload API";
let value = "0";
}
-def : Macro {
- let name = "OL_VERSION_MINOR";
+def OL_VERSION_MINOR : Macro {
let desc = "Minor version of the Offload API";
let value = "0";
}
-def : Macro {
- let name = "OL_VERSION_PATCH";
+def OL_VERSION_PATCH : Macro {
let desc = "Patch version of the Offload API";
let value = "1";
}
-def : Macro {
- let name = "OL_APICALL";
+def OL_APICALL : Macro {
let desc = "Calling convention for all API functions";
let condition = "defined(_WIN32)";
let value = "__cdecl";
let alt_value = "";
}
-def : Macro {
- let name = "OL_APIEXPORT";
+def OL_APIEXPORT : Macro {
let desc = "Microsoft-specific dllexport storage-class attribute";
let condition = "defined(_WIN32)";
let value = "__declspec(dllexport)";
let alt_value = "";
}
-def : Handle {
- let name = "ol_platform_handle_t";
+def ol_platform_handle_t : Handle {
let desc = "Handle of a platform instance";
}
-def : Handle {
- let name = "ol_device_handle_t";
+def ol_device_handle_t : Handle {
let desc = "Handle of platform's device object";
}
-def : Handle {
- let name = "ol_context_handle_t";
+def ol_context_handle_t : Handle {
let desc = "Handle of context object";
}
-def : Handle {
- let name = "ol_queue_handle_t";
+def ol_queue_handle_t : Handle {
let desc = "Handle of queue object";
}
-def : Handle {
- let name = "ol_event_handle_t";
+def ol_event_handle_t : Handle {
let desc = "Handle of event object";
}
-def : Handle {
- let name = "ol_program_handle_t";
+def ol_program_handle_t : Handle {
let desc = "Handle of program object";
}
-def : Handle {
- let name = "ol_symbol_handle_t";
+def ol_symbol_handle_t : Handle {
let desc = "Handle of an object in a device's memory for a specific program";
}
-def ErrorCode : Enum {
- let name = "ol_errc_t";
+def ol_errc_t : Enum {
let desc = "Defines Return/Error codes";
let etors =[
Etor<"SUCCESS", "success">,
@@ -115,8 +102,7 @@ def ErrorCode : Enum {
];
}
-def : Struct {
- let name = "ol_error_struct_t";
+def ol_error_struct_t : Struct {
let desc = "Details of the error condition returned by an API call";
let members = [
StructMember<"ol_errc_t", "Code", "The error code">,
@@ -124,20 +110,17 @@ def : Struct {
];
}
-def : Typedef {
- let name = "ol_result_t";
+def ol_result_t : Typedef {
let desc = "Result type returned by all entry points.";
let value = "const struct ol_error_struct_t*";
}
-def : Macro {
- let name = "OL_SUCCESS";
+def OL_SUCCESS : Macro {
let desc = "Success condition";
let value = "NULL";
}
-def : Struct {
- let name = "ol_code_location_t";
+def ol_code_location_t : Struct {
let desc = "Code location information that can optionally be associated with an API call";
let members = [
StructMember<"const char*", "FunctionName", "Function name">,
@@ -147,8 +130,7 @@ def : Struct {
];
}
-def : Struct {
- let name = "ol_dimensions_t";
+def ol_dimensions_t : Struct {
let desc = "A three element vector";
let members = [
StructMember<"uint32_t", "x", "X">,
@@ -157,8 +139,7 @@ def : Struct {
];
}
-def : Function {
- let name = "olInit";
+def olInit : Function {
let desc = "Perform initialization of the Offload library and plugins";
let details = [
"This must be the first API call made by a user of the Offload library",
@@ -168,8 +149,7 @@ def : Function {
let returns = [];
}
-def : Function {
- let name = "olShutDown";
+def olShutDown : Function {
let desc = "Release the resources in use by Offload";
let details = [
"This decrements an internal reference count. When this reaches 0, all resources will be released",
diff --git a/offload/liboffload/API/Device.td b/offload/liboffload/API/Device.td
index f9ba184759c25..d1baa28687fb2 100644
--- a/offload/liboffload/API/Device.td
+++ b/offload/liboffload/API/Device.td
@@ -10,8 +10,7 @@
//
//===----------------------------------------------------------------------===//
-def : Enum {
- let name = "ol_device_type_t";
+def ol_device_type_t : Enum {
let desc = "Supported device types.";
let etors =[
Etor<"DEFAULT", "The default device type as preferred by the runtime">,
@@ -22,8 +21,7 @@ def : Enum {
];
}
-def DeviceInfo : Enum {
- let name = "ol_device_info_t";
+def ol_device_info_t : Enum {
let desc = "Supported device info.";
let is_typed = 1;
list<TaggedEtor> basic_etors =[
@@ -47,8 +45,7 @@ def DeviceInfo : Enum {
let etors = !listconcat(basic_etors, fp_configs, native_vec_widths);
}
-def : Enum {
- let name = "ol_device_fp_capability_flag_t";
+def ol_device_fp_capability_flag_t : Enum {
let desc = "Device floating-point capability flags";
let is_bit_field = 1;
let etors =[
@@ -63,14 +60,12 @@ def : Enum {
];
}
-def : Typedef {
- let name = "ol_device_fp_capability_flags_t";
+def ol_device_fp_capability_flags_t : Typedef {
let desc = "Device floating-point capability flags";
let value = "uint32_t";
}
-def : FptrTypedef {
- let name = "ol_device_iterate_cb_t";
+def ol_device_iterate_cb_t : FptrTypedef {
let desc = "User-provided function to be used with `olIterateDevices`";
let params = [
Param<"ol_device_handle_t", "Device", "the device handle of the current iteration", PARAM_IN>,
@@ -79,8 +74,7 @@ def : FptrTypedef {
let return = "bool";
}
-def : Function {
- let name = "olIterateDevices";
+def olIterateDevices : Function {
let desc = "Iterates over all available devices, calling the callback for each device.";
let details = [
"If the user-provided callback returns `false`, the iteration is stopped."
@@ -94,8 +88,7 @@ def : Function {
];
}
-def : Function {
- let name = "olGetDeviceInfo";
+def olGetDeviceInfo : Function {
let desc = "Queries the given property of the device.";
let details = [];
let params = [
@@ -118,8 +111,7 @@ def : Function {
];
}
-def : Function {
- let name = "olGetDeviceInfoSize";
+def olGetDeviceInfoSize : Function {
let desc = "Returns the storage size of the given device query.";
let details = [];
let params = [
diff --git a/offload/liboffload/API/Event.td b/offload/liboffload/API/Event.td
index 9d217ae230384..01d00692db3b4 100644
--- a/offload/liboffload/API/Event.td
+++ b/offload/liboffload/API/Event.td
@@ -10,8 +10,7 @@
//
//===----------------------------------------------------------------------===//
-def : Function {
- let name = "olCreateEvent";
+def olCreateEvent : Function {
let desc = "Enqueue an event to `Queue` and return it.";
let details = [
"This event can be used with `olSyncEvent` and `olWaitEvents` and will be complete once all enqueued work prior to the `olCreateEvent` call is complete.",
@@ -23,8 +22,7 @@ def : Function {
let returns = [];
}
-def : Function {
- let name = "olDestroyEvent";
+def olDestroyEvent : Function {
let desc = "Destroy the event and free all underlying resources.";
let details = [];
let params = [
@@ -33,8 +31,7 @@ def : Function {
let returns = [];
}
-def : Function {
- let name = "olSyncEvent";
+def olSyncEvent : Function {
let desc = "Block the calling thread until the event is complete.";
let details = [];
let params = [
@@ -43,8 +40,7 @@ def : Function {
let returns = [];
}
-def : Enum {
- let name = "ol_event_info_t";
+def ol_event_info_t : Enum {
let desc = "Supported event info.";
let is_typed = 1;
let etors = [
@@ -52,8 +48,7 @@ def : Enum {
];
}
-def : Function {
- let name = "olGetEventInfo";
+def olGetEventInfo : Function {
let desc = "Queries the given property of the event.";
let details = [
"`olGetEventInfoSize` can be used to query the storage size "
@@ -77,8 +72,7 @@ def : Function {
];
}
-def : Function {
- let name = "olGetEventInfoSize";
+def olGetEventInfoSize : Function {
let desc = "Returns the storage size of the given event query.";
let details = [];
let params = [
diff --git a/offload/liboffload/API/Kernel.td b/offload/liboffload/API/Kernel.td
index f9f5ef74b560d..2f5692a19d712 100644
--- a/offload/liboffload/API/Kernel.td
+++ b/offload/liboffload/API/Kernel.td
@@ -10,8 +10,7 @@
//
//===----------------------------------------------------------------------===//
-def : Struct {
- let name = "ol_kernel_launch_size_args_t";
+def ol_kernel_launch_size_args_t : Struct {
let desc = "Size-related arguments for a kernel launch.";
let members = [
StructMember<"size_t", "Dimensions", "Number of work dimensions">,
@@ -21,8 +20,7 @@ def : Struct {
];
}
-def : Function {
- let name = "olLaunchKernel";
+def olLaunchKernel : Function {
let desc = "Enqueue a kernel launch with the specified size and parameters.";
let details = [
"If a queue is not specified, kernel execution happens synchronously",
@@ -43,8 +41,7 @@ def : Function {
];
}
-def : Function {
- let name = "olCalculateOptimalOccupancy";
+def olCalculateOptimalOccupancy : Function {
let desc = "Given dynamic memory size, query the device for a workgroup size that will result in optimal occupancy.";
let details = [
"For most devices, this will be the largest workgroup size that will result in all work items fitting on the device at once.",
diff --git a/offload/liboffload/API/Memory.td b/offload/liboffload/API/Memory.td
index 5f7158588bc77..248d9621b651e 100644
--- a/offload/liboffload/API/Memory.td
+++ b/offload/liboffload/API/Memory.td
@@ -10,8 +10,7 @@
//
//===----------------------------------------------------------------------===//
-def : Enum {
- let name = "ol_alloc_type_t";
+def ol_alloc_type_t : Enum {
let desc = "Represents the type of allocation made with olMemAlloc.";
let etors = [
Etor<"HOST", "Host allocation">,
@@ -20,8 +19,7 @@ def : Enum {
];
}
-def : Function {
- let name = "olMemAlloc";
+def olMemAlloc : Function {
let desc = "Creates a memory allocation on the specified device.";
let params = [
Param<"ol_device_handle_t", "Device", "handle of the device to allocate on", PARAM_IN>,
@@ -36,8 +34,7 @@ def : Function {
];
}
-def : Function {
- let name = "olMemFree";
+def olMemFree : Function {
let desc = "Frees a memory allocation previously made by olMemAlloc.";
let params = [
Param<"void*", "Address", "address of the allocation to free", PARAM_IN>,
@@ -45,8 +42,7 @@ def : Function {
let returns = [];
}
-def : Function {
- let name = "olMemcpy";
+def olMemcpy : Function {
let desc = "Enqueue a memcpy operation.";
let details = [
"For host pointers, use the host device belonging to the OL_PLATFORM_BACKEND_HOST platform.",
diff --git a/offload/liboffload/API/Platform.td b/offload/liboffload/API/Platform.td
index 97c2cc2d05704..906f899076a80 100644
--- a/offload/liboffload/API/Platform.td
+++ b/offload/liboffload/API/Platform.td
@@ -10,8 +10,7 @@
//
//===----------------------------------------------------------------------===//
-def : Enum {
- let name = "ol_platform_info_t";
+def ol_platform_info_t : Enum {
let desc = "Supported platform info.";
let is_typed = 1;
let etors = [
@@ -22,8 +21,7 @@ def : Enum {
];
}
-def : Enum {
- let name = "ol_platform_backend_t";
+def ol_platform_backend_t : Enum {
let desc = "Identifies the native backend of the platform.";
let etors =[
Etor<"UNKNOWN", "The backend is not recognized">,
@@ -33,8 +31,7 @@ def : Enum {
];
}
-def : Function {
- let name = "olGetPlatformInfo";
+def olGetPlatformInfo : Function {
let desc = "Queries the given property of the platform.";
let details = [
"`olGetPlatformInfoSize` can be used to query the storage size "
@@ -61,8 +58,7 @@ def : Function {
];
}
-def : Function {
- let name = "olGetPlatformInfoSize";
+def olGetPlatformInfoSize : Function {
let desc = "Returns the storage size of the given platform query.";
let details = [];
let params = [
diff --git a/offload/liboffload/API/Program.td b/offload/liboffload/API/Program.td
index 0476fa1f7c27a..1f48f650cab70 100644
--- a/offload/liboffload/API/Program.td
+++ b/offload/liboffload/API/Program.td
@@ -10,8 +10,7 @@
//
//===----------------------------------------------------------------------===//
-def : Function {
- let name = "olCreateProgram";
+def olCreateProgram : Function {
let desc = "Create a program for the device from the binary image pointed to by `ProgData`.";
let details = [
"The provided `ProgData` will be copied and need not outlive the returned handle",
@@ -25,8 +24,7 @@ def : Function {
let returns = [];
}
-def : Function {
- let name = "olDestroyProgram";
+def olDestroyProgram : Function {
let desc = "Destroy the program and free all underlying resources.";
let details = [];
let params = [
diff --git a/offload/liboffload/API/Queue.td b/offload/liboffload/API/Queue.td
index 0e20e23999d5e..ededa9cc92fef 100644
--- a/offload/liboffload/API/Queue.td
+++ b/offload/liboffload/API/Queue.td
@@ -10,8 +10,7 @@
//
//===----------------------------------------------------------------------===//
-def : Function {
- let name = "olCreateQueue";
+def olCreateQueue : Function {
let desc = "Create a queue for the given device.";
let details = [];
let params = [
@@ -21,8 +20,7 @@ def : Function {
let returns = [];
}
-def : Function {
- let name = "olDestroyQueue";
+def olDestroyQueue : Function {
let desc = "Destroy the queue and free all underlying resources.";
let details = [
"Any work previously enqueued to the queue is still performed and any events generated for this queue remain valid."
@@ -33,8 +31,7 @@ def : Function {
let returns = [];
}
-def : Function {
- let name = "olSyncQueue";
+def olSyncQueue : Function {
let desc = "Block the calling thread until the enqueued work on a queue is complete.";
let details = [];
let params = [
@@ -43,8 +40,7 @@ def : Function {
let returns = [];
}
-def : Function {
- let name = "olWaitEvents";
+def olWaitEvents : Function {
let desc = "Make any future work submitted to this queue wait until the provided events are complete.";
let details = [
"All events in `Events` must complete before the queue is unblocked.",
@@ -60,8 +56,7 @@ def : Function {
];
}
-def : Enum {
- let name = "ol_queue_info_t";
+def ol_queue_info_t : Enum {
let desc = "Supported queue info.";
let is_typed = 1;
let etors = [
@@ -70,8 +65,7 @@ def : Enum {
];
}
-def : Function {
- let name = "olGetQueueInfo";
+def olGetQueueInfo : Function {
let desc = "Queries the given property of the queue.";
let details = [
"`olGetQueueInfoSize` can be used to query the storage size "
@@ -95,8 +89,7 @@ def : Function {
];
}
-def : Function {
- let name = "olGetQueueInfoSize";
+def olGetQueueInfoSize : Function {
let desc = "Returns the storage size of the given queue query.";
let details = [];
let params = [
@@ -109,8 +102,7 @@ def : Function {
];
}
-def : FptrTypedef {
- let name = "ol_host_function_cb_t";
+def ol_host_function_cb_t : FptrTypedef {
let desc = "Host function for use by `olLaunchHostFunction`.";
let params = [
Param<"void *", "UserData", "user specified data passed into `olLaunchHostFunction`.", PARAM_IN>,
@@ -118,8 +110,7 @@ def : FptrTypedef {
let return = "void";
}
-def : Function {
- let name = "olLaunchHostFunction";
+def olLaunchHostFunction : Function {
let desc = "Enqueue a callback function on the host.";
let details = [
"The provided function will be called from the same process as the one that called `olLaunchHostFunction`.",
diff --git a/offload/liboffload/API/Symbol.td b/offload/liboffload/API/Symbol.td
index 2e94d703809e7..c57a2e1b83632 100644
--- a/offload/liboffload/API/Symbol.td
+++ b/offload/liboffload/API/Symbol.td
@@ -10,8 +10,7 @@
//
//===----------------------------------------------------------------------===//
-def : Enum {
- let name = "ol_symbol_kind_t";
+def ol_symbol_kind_t : Enum {
let desc = "The kind of a symbol";
let etors =[
Etor<"KERNEL", "a kernel object">,
@@ -19,8 +18,7 @@ def : Enum {
];
}
-def : Function {
- let name = "olGetSymbol";
+def olGetSymbol : Function {
let desc = "Get a symbol (kernel or global variable) identified by `Name` in the given program.";
let details = [
"Symbol handles are owned by the program and do not need to be manually destroyed."
@@ -34,8 +32,7 @@ def : Function {
let returns = [];
}
-def : Enum {
- let name = "ol_symbol_info_t";
+def ol_symbol_info_t : Enum {
let desc = "Supported symbol info.";
let is_typed = 1;
let etors = [
@@ -45,8 +42,7 @@ def : Enum {
];
}
-def : Function {
- let name = "olGetSymbolInfo";
+def olGetSymbolInfo : Function {
let desc = "Queries the given property of the symbol.";
let details = [
"`olGetSymbolInfoSize` can be used to query the storage size "
@@ -73,8 +69,7 @@ def : Function {
];
}
-def : Function {
- let name = "olGetSymbolInfoSize";
+def olGetSymbolInfoSize : Function {
let desc = "Returns the storage size of the given symbol query.";
let details = [];
let params = [
diff --git a/offload/tools/offload-tblgen/MiscGen.cpp b/offload/tools/offload-tblgen/MiscGen.cpp
index 17378331242a4..8a8b9caf2348d 100644
--- a/offload/tools/offload-tblgen/MiscGen.cpp
+++ b/offload/tools/offload-tblgen/MiscGen.cpp
@@ -86,7 +86,7 @@ void EmitOffloadErrcodes(const RecordKeeper &Records, raw_ostream &OS) {
)";
- auto ErrorCodeEnum = EnumRec{Records.getDef("ErrorCode")};
+ auto ErrorCodeEnum = EnumRec{Records.getDef("ol_errc_t")};
uint32_t EtorVal = 0;
for (const auto &EnumVal : ErrorCodeEnum.getValues()) {
OS << formatv(TAB_1 "OFFLOAD_ERRC({0}, \"{1}\", {2})\n", EnumVal.getName(),
@@ -107,7 +107,7 @@ void EmitOffloadInfo(const RecordKeeper &Records, raw_ostream &OS) {
)";
- auto Enum = EnumRec{Records.getDef("DeviceInfo")};
+ auto Enum = EnumRec{Records.getDef("ol_device_info_t")};
// Bitfields start from 1, other enums from 0
uint32_t EtorVal = Enum.isBitField();
for (const auto &EnumVal : Enum.getValues()) {
diff --git a/offload/tools/offload-tblgen/RecordTypes.hpp b/offload/tools/offload-tblgen/RecordTypes.hpp
index 1cde8b84c3069..2abd9e10f0f96 100644
--- a/offload/tools/offload-tblgen/RecordTypes.hpp
+++ b/offload/tools/offload-tblgen/RecordTypes.hpp
@@ -16,25 +16,30 @@ namespace llvm {
namespace offload {
namespace tblgen {
-class HandleRec {
+class APIObject {
public:
- explicit HandleRec(const Record *rec) : rec(rec) {}
- StringRef getName() const { return rec->getValueAsString("name"); }
+ StringRef getName() const { return rec->getName(); }
StringRef getDesc() const { return rec->getValueAsString("desc"); }
-private:
+protected:
+ APIObject(const Record *rec) : rec(rec) {}
const Record *rec;
};
-class MacroRec {
+class HandleRec : public APIObject {
public:
- explicit MacroRec(const Record *rec) : rec(rec) {
- auto Name = rec->getValueAsString("name");
+ explicit HandleRec(const Record *rec) : APIObject(rec) {};
+};
+
+class MacroRec : public APIObject {
+public:
+ explicit MacroRec(const Record *rec) : APIObject(rec) {
+ auto Name = rec->getName();
auto OpenBrace = Name.find_first_of("(");
nameWithoutArgs = Name.substr(0, OpenBrace);
}
StringRef getName() const { return nameWithoutArgs; }
- StringRef getNameWithArgs() const { return rec->getValueAsString("name"); }
+ StringRef getNameWithArgs() const { return rec->getName(); }
StringRef getDesc() const { return rec->getValueAsString("desc"); }
std::optional<StringRef> getCondition() const {
@@ -46,19 +51,15 @@ class MacroRec {
}
private:
- const Record *rec;
std::string nameWithoutArgs;
};
-class TypedefRec {
+class TypedefRec : public APIObject {
public:
- explicit TypedefRec(const Record *rec) : rec(rec) {}
- StringRef getName() const { return rec->getValueAsString("name"); }
- StringRef getDesc() const { return rec->getValueAsString("desc"); }
- StringRef getValue() const { return rec->getValueAsString("value"); }
+ explicit TypedefRec(const Record *rec) : APIObject(rec) {};
-private:
- const Record *rec;
+public:
+ StringRef getValue() const { return rec->getValueAsString("value"); }
};
class EnumValueRec {
@@ -74,15 +75,13 @@ class EnumValueRec {
const Record *rec;
};
-class EnumRec {
+class EnumRec : public APIObject {
public:
- explicit EnumRec(const Record *rec) : rec(rec) {
+ explicit EnumRec(const Record *rec) : APIObject(rec) {
for (const auto *Val : rec->getValueAsListOfDefs("etors")) {
vals.emplace_back(EnumValueRec{Val});
}
}
- StringRef getName() const { return rec->getValueAsString("name"); }
- StringRef getDesc() const { return rec->getValueAsString("desc"); }
const std::vector<EnumValueRec> &getValues() const { return vals; }
std::string getEnumValNamePrefix() const {
@@ -95,7 +94,6 @@ class EnumRec {
bool isBitField() const { return rec->getValueAsBit("is_bit_field"); }
private:
- const Record *rec;
std::vector<EnumValueRec> vals;
};
@@ -112,22 +110,19 @@ class StructMemberRec {
const Record *rec;
};
-class StructRec {
+class StructRec : public APIObject {
public:
- explicit StructRec(const Record *rec) : rec(rec) {
+ explicit StructRec(const Record *rec) : APIObject(rec) {
for (auto *Member : rec->getValueAsListOfDefs("all_members")) {
members.emplace_back(StructMemberRec(Member));
}
}
- StringRef getName() const { return rec->getValueAsString("name"); }
- StringRef getDesc() const { return rec->getValueAsString("desc"); }
std::optional<StringRef> getBaseClass() const {
return rec->getValueAsOptionalString("base_class");
}
const std::vector<StructMemberRec> &getMembers() const { return members; }
private:
- const Record *rec;
std::vector<StructMemberRec> members;
};
@@ -207,9 +202,9 @@ class ReturnRec {
const Record *rec;
};
-class FunctionRec {
+class FunctionRec : public APIObject {
public:
- FunctionRec(const Record *rec) : rec(rec) {
+ FunctionRec(const Record *rec) : APIObject(rec) {
for (auto &Ret : rec->getValueAsListOfDefs("all_returns"))
rets.emplace_back(Ret);
for (auto &Param : rec->getValueAsListOfDefs("params"))
@@ -221,11 +216,9 @@ class FunctionRec {
llvm::convertToSnakeFromCamelCase(getName()));
}
- StringRef getName() const { return rec->getValueAsString("name"); }
StringRef getClass() const { return rec->getValueAsString("api_class"); }
const std::vector<ReturnRec> &getReturns() const { return rets; }
const std::vector<ParamRec> &getParams() const { return params; }
- StringRef getDesc() const { return rec->getValueAsString("desc"); }
std::vector<StringRef> getDetails() const {
return rec->getValueAsListOfStrings("details");
}
@@ -236,25 +229,19 @@ class FunctionRec {
private:
std::vector<ReturnRec> rets;
std::vector<ParamRec> params;
-
- const Record *rec;
};
-class FptrTypedefRec {
+class FptrTypedefRec : public APIObject {
public:
- explicit FptrTypedefRec(const Record *rec) : rec(rec) {
+ explicit FptrTypedefRec(const Record *rec) : APIObject(rec) {
for (auto &Param : rec->getValueAsListOfDefs("params"))
params.emplace_back(Param);
}
- StringRef getName() const { return rec->getValueAsString("name"); }
- StringRef getDesc() const { return rec->getValueAsString("desc"); }
StringRef getReturn() const { return rec->getValueAsString("return"); }
const std::vector<ParamRec> &getParams() const { return params; }
private:
std::vector<ParamRec> params;
-
- const Record *rec;
};
} // namespace tblgen
More information about the llvm-commits
mailing list