[Offload][NFC] Use tablegen names rather than name parameter for API (#154736)

This commit is contained in:
Ross Brunton 2025-08-22 11:13:57 +01:00 committed by GitHub
parent 8439777131
commit 17dbb92612
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 88 additions and 163 deletions

View File

@ -145,7 +145,6 @@ defvar DefaultReturns = [Return<PREFIX#"_RESULT_SUCCESS">,
Return<PREFIX#"_ERRC_DEVICE_LOST">]; Return<PREFIX#"_ERRC_DEVICE_LOST">];
class APIObject { class APIObject {
string name;
string desc; string desc;
} }

View File

@ -10,77 +10,64 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
def : Macro { def OL_VERSION_MAJOR : Macro {
let name = "OL_VERSION_MAJOR";
let desc = "Major version of the Offload API"; let desc = "Major version of the Offload API";
let value = "0"; let value = "0";
} }
def : Macro { def OL_VERSION_MINOR : Macro {
let name = "OL_VERSION_MINOR";
let desc = "Minor version of the Offload API"; let desc = "Minor version of the Offload API";
let value = "0"; let value = "0";
} }
def : Macro { def OL_VERSION_PATCH : Macro {
let name = "OL_VERSION_PATCH";
let desc = "Patch version of the Offload API"; let desc = "Patch version of the Offload API";
let value = "1"; let value = "1";
} }
def : Macro { def OL_APICALL : Macro {
let name = "OL_APICALL";
let desc = "Calling convention for all API functions"; let desc = "Calling convention for all API functions";
let condition = "defined(_WIN32)"; let condition = "defined(_WIN32)";
let value = "__cdecl"; let value = "__cdecl";
let alt_value = ""; let alt_value = "";
} }
def : Macro { def OL_APIEXPORT : Macro {
let name = "OL_APIEXPORT";
let desc = "Microsoft-specific dllexport storage-class attribute"; let desc = "Microsoft-specific dllexport storage-class attribute";
let condition = "defined(_WIN32)"; let condition = "defined(_WIN32)";
let value = "__declspec(dllexport)"; let value = "__declspec(dllexport)";
let alt_value = ""; let alt_value = "";
} }
def : Handle { def ol_platform_handle_t : Handle {
let name = "ol_platform_handle_t";
let desc = "Handle of a platform instance"; let desc = "Handle of a platform instance";
} }
def : Handle { def ol_device_handle_t : Handle {
let name = "ol_device_handle_t";
let desc = "Handle of platform's device object"; let desc = "Handle of platform's device object";
} }
def : Handle { def ol_context_handle_t : Handle {
let name = "ol_context_handle_t";
let desc = "Handle of context object"; let desc = "Handle of context object";
} }
def : Handle { def ol_queue_handle_t : Handle {
let name = "ol_queue_handle_t";
let desc = "Handle of queue object"; let desc = "Handle of queue object";
} }
def : Handle { def ol_event_handle_t : Handle {
let name = "ol_event_handle_t";
let desc = "Handle of event object"; let desc = "Handle of event object";
} }
def : Handle { def ol_program_handle_t : Handle {
let name = "ol_program_handle_t";
let desc = "Handle of program object"; let desc = "Handle of program object";
} }
def : Handle { def ol_symbol_handle_t : Handle {
let name = "ol_symbol_handle_t";
let desc = "Handle of an object in a device's memory for a specific program"; let desc = "Handle of an object in a device's memory for a specific program";
} }
def ErrorCode : Enum { def ol_errc_t : Enum {
let name = "ol_errc_t";
let desc = "Defines Return/Error codes"; let desc = "Defines Return/Error codes";
let etors =[ let etors =[
Etor<"SUCCESS", "success">, Etor<"SUCCESS", "success">,
@ -115,8 +102,7 @@ def ErrorCode : Enum {
]; ];
} }
def : Struct { def ol_error_struct_t : Struct {
let name = "ol_error_struct_t";
let desc = "Details of the error condition returned by an API call"; let desc = "Details of the error condition returned by an API call";
let members = [ let members = [
StructMember<"ol_errc_t", "Code", "The error code">, StructMember<"ol_errc_t", "Code", "The error code">,
@ -124,20 +110,17 @@ def : Struct {
]; ];
} }
def : Typedef { def ol_result_t : Typedef {
let name = "ol_result_t";
let desc = "Result type returned by all entry points."; let desc = "Result type returned by all entry points.";
let value = "const struct ol_error_struct_t*"; let value = "const struct ol_error_struct_t*";
} }
def : Macro { def OL_SUCCESS : Macro {
let name = "OL_SUCCESS";
let desc = "Success condition"; let desc = "Success condition";
let value = "NULL"; let value = "NULL";
} }
def : Struct { def ol_code_location_t : Struct {
let name = "ol_code_location_t";
let desc = "Code location information that can optionally be associated with an API call"; let desc = "Code location information that can optionally be associated with an API call";
let members = [ let members = [
StructMember<"const char*", "FunctionName", "Function name">, StructMember<"const char*", "FunctionName", "Function name">,
@ -147,8 +130,7 @@ def : Struct {
]; ];
} }
def : Struct { def ol_dimensions_t : Struct {
let name = "ol_dimensions_t";
let desc = "A three element vector"; let desc = "A three element vector";
let members = [ let members = [
StructMember<"uint32_t", "x", "X">, StructMember<"uint32_t", "x", "X">,
@ -157,8 +139,7 @@ def : Struct {
]; ];
} }
def : Function { def olInit : Function {
let name = "olInit";
let desc = "Perform initialization of the Offload library and plugins"; let desc = "Perform initialization of the Offload library and plugins";
let details = [ let details = [
"This must be the first API call made by a user of the Offload library", "This must be the first API call made by a user of the Offload library",
@ -168,8 +149,7 @@ def : Function {
let returns = []; let returns = [];
} }
def : Function { def olShutDown : Function {
let name = "olShutDown";
let desc = "Release the resources in use by Offload"; let desc = "Release the resources in use by Offload";
let details = [ let details = [
"This decrements an internal reference count. When this reaches 0, all resources will be released", "This decrements an internal reference count. When this reaches 0, all resources will be released",

View File

@ -10,8 +10,7 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
def : Enum { def ol_device_type_t : Enum {
let name = "ol_device_type_t";
let desc = "Supported device types."; let desc = "Supported device types.";
let etors =[ let etors =[
Etor<"DEFAULT", "The default device type as preferred by the runtime">, Etor<"DEFAULT", "The default device type as preferred by the runtime">,
@ -22,8 +21,7 @@ def : Enum {
]; ];
} }
def DeviceInfo : Enum { def ol_device_info_t : Enum {
let name = "ol_device_info_t";
let desc = "Supported device info."; let desc = "Supported device info.";
let is_typed = 1; let is_typed = 1;
list<TaggedEtor> basic_etors =[ list<TaggedEtor> basic_etors =[
@ -47,8 +45,7 @@ def DeviceInfo : Enum {
let etors = !listconcat(basic_etors, fp_configs, native_vec_widths); let etors = !listconcat(basic_etors, fp_configs, native_vec_widths);
} }
def : Enum { def ol_device_fp_capability_flag_t : Enum {
let name = "ol_device_fp_capability_flag_t";
let desc = "Device floating-point capability flags"; let desc = "Device floating-point capability flags";
let is_bit_field = 1; let is_bit_field = 1;
let etors =[ let etors =[
@ -63,14 +60,12 @@ def : Enum {
]; ];
} }
def : Typedef { def ol_device_fp_capability_flags_t : Typedef {
let name = "ol_device_fp_capability_flags_t";
let desc = "Device floating-point capability flags"; let desc = "Device floating-point capability flags";
let value = "uint32_t"; let value = "uint32_t";
} }
def : FptrTypedef { def ol_device_iterate_cb_t : FptrTypedef {
let name = "ol_device_iterate_cb_t";
let desc = "User-provided function to be used with `olIterateDevices`"; let desc = "User-provided function to be used with `olIterateDevices`";
let params = [ let params = [
Param<"ol_device_handle_t", "Device", "the device handle of the current iteration", PARAM_IN>, Param<"ol_device_handle_t", "Device", "the device handle of the current iteration", PARAM_IN>,
@ -79,8 +74,7 @@ def : FptrTypedef {
let return = "bool"; let return = "bool";
} }
def : Function { def olIterateDevices : Function {
let name = "olIterateDevices";
let desc = "Iterates over all available devices, calling the callback for each device."; let desc = "Iterates over all available devices, calling the callback for each device.";
let details = [ let details = [
"If the user-provided callback returns `false`, the iteration is stopped." "If the user-provided callback returns `false`, the iteration is stopped."
@ -94,8 +88,7 @@ def : Function {
]; ];
} }
def : Function { def olGetDeviceInfo : Function {
let name = "olGetDeviceInfo";
let desc = "Queries the given property of the device."; let desc = "Queries the given property of the device.";
let details = []; let details = [];
let params = [ let params = [
@ -118,8 +111,7 @@ def : Function {
]; ];
} }
def : Function { def olGetDeviceInfoSize : Function {
let name = "olGetDeviceInfoSize";
let desc = "Returns the storage size of the given device query."; let desc = "Returns the storage size of the given device query.";
let details = []; let details = [];
let params = [ let params = [

View File

@ -10,8 +10,7 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
def : Function { def olCreateEvent : Function {
let name = "olCreateEvent";
let desc = "Enqueue an event to `Queue` and return it."; let desc = "Enqueue an event to `Queue` and return it.";
let details = [ 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.", "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 = []; let returns = [];
} }
def : Function { def olDestroyEvent : Function {
let name = "olDestroyEvent";
let desc = "Destroy the event and free all underlying resources."; let desc = "Destroy the event and free all underlying resources.";
let details = []; let details = [];
let params = [ let params = [
@ -33,8 +31,7 @@ def : Function {
let returns = []; let returns = [];
} }
def : Function { def olSyncEvent : Function {
let name = "olSyncEvent";
let desc = "Block the calling thread until the event is complete."; let desc = "Block the calling thread until the event is complete.";
let details = []; let details = [];
let params = [ let params = [
@ -43,8 +40,7 @@ def : Function {
let returns = []; let returns = [];
} }
def : Enum { def ol_event_info_t : Enum {
let name = "ol_event_info_t";
let desc = "Supported event info."; let desc = "Supported event info.";
let is_typed = 1; let is_typed = 1;
let etors = [ let etors = [
@ -52,8 +48,7 @@ def : Enum {
]; ];
} }
def : Function { def olGetEventInfo : Function {
let name = "olGetEventInfo";
let desc = "Queries the given property of the event."; let desc = "Queries the given property of the event.";
let details = [ let details = [
"`olGetEventInfoSize` can be used to query the storage size " "`olGetEventInfoSize` can be used to query the storage size "
@ -77,8 +72,7 @@ def : Function {
]; ];
} }
def : Function { def olGetEventInfoSize : Function {
let name = "olGetEventInfoSize";
let desc = "Returns the storage size of the given event query."; let desc = "Returns the storage size of the given event query.";
let details = []; let details = [];
let params = [ let params = [

View File

@ -10,8 +10,7 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
def : Struct { def ol_kernel_launch_size_args_t : Struct {
let name = "ol_kernel_launch_size_args_t";
let desc = "Size-related arguments for a kernel launch."; let desc = "Size-related arguments for a kernel launch.";
let members = [ let members = [
StructMember<"size_t", "Dimensions", "Number of work dimensions">, StructMember<"size_t", "Dimensions", "Number of work dimensions">,
@ -21,8 +20,7 @@ def : Struct {
]; ];
} }
def : Function { def olLaunchKernel : Function {
let name = "olLaunchKernel";
let desc = "Enqueue a kernel launch with the specified size and parameters."; let desc = "Enqueue a kernel launch with the specified size and parameters.";
let details = [ let details = [
"If a queue is not specified, kernel execution happens synchronously", "If a queue is not specified, kernel execution happens synchronously",
@ -43,8 +41,7 @@ def : Function {
]; ];
} }
def : Function { def olCalculateOptimalOccupancy : Function {
let name = "olCalculateOptimalOccupancy";
let desc = "Given dynamic memory size, query the device for a workgroup size that will result in optimal occupancy."; let desc = "Given dynamic memory size, query the device for a workgroup size that will result in optimal occupancy.";
let details = [ 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.", "For most devices, this will be the largest workgroup size that will result in all work items fitting on the device at once.",

View File

@ -10,8 +10,7 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
def : Enum { def ol_alloc_type_t : Enum {
let name = "ol_alloc_type_t";
let desc = "Represents the type of allocation made with olMemAlloc."; let desc = "Represents the type of allocation made with olMemAlloc.";
let etors = [ let etors = [
Etor<"HOST", "Host allocation">, Etor<"HOST", "Host allocation">,
@ -20,8 +19,7 @@ def : Enum {
]; ];
} }
def : Function { def olMemAlloc : Function {
let name = "olMemAlloc";
let desc = "Creates a memory allocation on the specified device."; let desc = "Creates a memory allocation on the specified device.";
let params = [ let params = [
Param<"ol_device_handle_t", "Device", "handle of the device to allocate on", PARAM_IN>, Param<"ol_device_handle_t", "Device", "handle of the device to allocate on", PARAM_IN>,
@ -36,8 +34,7 @@ def : Function {
]; ];
} }
def : Function { def olMemFree : Function {
let name = "olMemFree";
let desc = "Frees a memory allocation previously made by olMemAlloc."; let desc = "Frees a memory allocation previously made by olMemAlloc.";
let params = [ let params = [
Param<"void*", "Address", "address of the allocation to free", PARAM_IN>, Param<"void*", "Address", "address of the allocation to free", PARAM_IN>,
@ -45,8 +42,7 @@ def : Function {
let returns = []; let returns = [];
} }
def : Function { def olMemcpy : Function {
let name = "olMemcpy";
let desc = "Enqueue a memcpy operation."; let desc = "Enqueue a memcpy operation.";
let details = [ let details = [
"For host pointers, use the host device belonging to the OL_PLATFORM_BACKEND_HOST platform.", "For host pointers, use the host device belonging to the OL_PLATFORM_BACKEND_HOST platform.",

View File

@ -10,8 +10,7 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
def : Enum { def ol_platform_info_t : Enum {
let name = "ol_platform_info_t";
let desc = "Supported platform info."; let desc = "Supported platform info.";
let is_typed = 1; let is_typed = 1;
let etors = [ let etors = [
@ -22,8 +21,7 @@ def : Enum {
]; ];
} }
def : Enum { def ol_platform_backend_t : Enum {
let name = "ol_platform_backend_t";
let desc = "Identifies the native backend of the platform."; let desc = "Identifies the native backend of the platform.";
let etors =[ let etors =[
Etor<"UNKNOWN", "The backend is not recognized">, Etor<"UNKNOWN", "The backend is not recognized">,
@ -33,8 +31,7 @@ def : Enum {
]; ];
} }
def : Function { def olGetPlatformInfo : Function {
let name = "olGetPlatformInfo";
let desc = "Queries the given property of the platform."; let desc = "Queries the given property of the platform.";
let details = [ let details = [
"`olGetPlatformInfoSize` can be used to query the storage size " "`olGetPlatformInfoSize` can be used to query the storage size "
@ -61,8 +58,7 @@ def : Function {
]; ];
} }
def : Function { def olGetPlatformInfoSize : Function {
let name = "olGetPlatformInfoSize";
let desc = "Returns the storage size of the given platform query."; let desc = "Returns the storage size of the given platform query.";
let details = []; let details = [];
let params = [ let params = [

View File

@ -10,8 +10,7 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
def : Function { def olCreateProgram : Function {
let name = "olCreateProgram";
let desc = "Create a program for the device from the binary image pointed to by `ProgData`."; let desc = "Create a program for the device from the binary image pointed to by `ProgData`.";
let details = [ let details = [
"The provided `ProgData` will be copied and need not outlive the returned handle", "The provided `ProgData` will be copied and need not outlive the returned handle",
@ -25,8 +24,7 @@ def : Function {
let returns = []; let returns = [];
} }
def : Function { def olDestroyProgram : Function {
let name = "olDestroyProgram";
let desc = "Destroy the program and free all underlying resources."; let desc = "Destroy the program and free all underlying resources.";
let details = []; let details = [];
let params = [ let params = [

View File

@ -10,8 +10,7 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
def : Function { def olCreateQueue : Function {
let name = "olCreateQueue";
let desc = "Create a queue for the given device."; let desc = "Create a queue for the given device.";
let details = []; let details = [];
let params = [ let params = [
@ -21,8 +20,7 @@ def : Function {
let returns = []; let returns = [];
} }
def : Function { def olDestroyQueue : Function {
let name = "olDestroyQueue";
let desc = "Destroy the queue and free all underlying resources."; let desc = "Destroy the queue and free all underlying resources.";
let details = [ let details = [
"Any work previously enqueued to the queue is still performed and any events generated for this queue remain valid." "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 = []; let returns = [];
} }
def : Function { def olSyncQueue : Function {
let name = "olSyncQueue";
let desc = "Block the calling thread until the enqueued work on a queue is complete."; let desc = "Block the calling thread until the enqueued work on a queue is complete.";
let details = []; let details = [];
let params = [ let params = [
@ -43,8 +40,7 @@ def : Function {
let returns = []; let returns = [];
} }
def : Function { def olWaitEvents : Function {
let name = "olWaitEvents";
let desc = "Make any future work submitted to this queue wait until the provided events are complete."; let desc = "Make any future work submitted to this queue wait until the provided events are complete.";
let details = [ let details = [
"All events in `Events` must complete before the queue is unblocked.", "All events in `Events` must complete before the queue is unblocked.",
@ -60,8 +56,7 @@ def : Function {
]; ];
} }
def : Enum { def ol_queue_info_t : Enum {
let name = "ol_queue_info_t";
let desc = "Supported queue info."; let desc = "Supported queue info.";
let is_typed = 1; let is_typed = 1;
let etors = [ let etors = [
@ -70,8 +65,7 @@ def : Enum {
]; ];
} }
def : Function { def olGetQueueInfo : Function {
let name = "olGetQueueInfo";
let desc = "Queries the given property of the queue."; let desc = "Queries the given property of the queue.";
let details = [ let details = [
"`olGetQueueInfoSize` can be used to query the storage size " "`olGetQueueInfoSize` can be used to query the storage size "
@ -95,8 +89,7 @@ def : Function {
]; ];
} }
def : Function { def olGetQueueInfoSize : Function {
let name = "olGetQueueInfoSize";
let desc = "Returns the storage size of the given queue query."; let desc = "Returns the storage size of the given queue query.";
let details = []; let details = [];
let params = [ let params = [
@ -109,8 +102,7 @@ def : Function {
]; ];
} }
def : FptrTypedef { def ol_host_function_cb_t : FptrTypedef {
let name = "ol_host_function_cb_t";
let desc = "Host function for use by `olLaunchHostFunction`."; let desc = "Host function for use by `olLaunchHostFunction`.";
let params = [ let params = [
Param<"void *", "UserData", "user specified data passed into `olLaunchHostFunction`.", PARAM_IN>, Param<"void *", "UserData", "user specified data passed into `olLaunchHostFunction`.", PARAM_IN>,
@ -118,8 +110,7 @@ def : FptrTypedef {
let return = "void"; let return = "void";
} }
def : Function { def olLaunchHostFunction : Function {
let name = "olLaunchHostFunction";
let desc = "Enqueue a callback function on the host."; let desc = "Enqueue a callback function on the host.";
let details = [ let details = [
"The provided function will be called from the same process as the one that called `olLaunchHostFunction`.", "The provided function will be called from the same process as the one that called `olLaunchHostFunction`.",

View File

@ -10,8 +10,7 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
def : Enum { def ol_symbol_kind_t : Enum {
let name = "ol_symbol_kind_t";
let desc = "The kind of a symbol"; let desc = "The kind of a symbol";
let etors =[ let etors =[
Etor<"KERNEL", "a kernel object">, Etor<"KERNEL", "a kernel object">,
@ -19,8 +18,7 @@ def : Enum {
]; ];
} }
def : Function { def olGetSymbol : Function {
let name = "olGetSymbol";
let desc = "Get a symbol (kernel or global variable) identified by `Name` in the given program."; let desc = "Get a symbol (kernel or global variable) identified by `Name` in the given program.";
let details = [ let details = [
"Symbol handles are owned by the program and do not need to be manually destroyed." "Symbol handles are owned by the program and do not need to be manually destroyed."
@ -34,8 +32,7 @@ def : Function {
let returns = []; let returns = [];
} }
def : Enum { def ol_symbol_info_t : Enum {
let name = "ol_symbol_info_t";
let desc = "Supported symbol info."; let desc = "Supported symbol info.";
let is_typed = 1; let is_typed = 1;
let etors = [ let etors = [
@ -45,8 +42,7 @@ def : Enum {
]; ];
} }
def : Function { def olGetSymbolInfo : Function {
let name = "olGetSymbolInfo";
let desc = "Queries the given property of the symbol."; let desc = "Queries the given property of the symbol.";
let details = [ let details = [
"`olGetSymbolInfoSize` can be used to query the storage size " "`olGetSymbolInfoSize` can be used to query the storage size "
@ -73,8 +69,7 @@ def : Function {
]; ];
} }
def : Function { def olGetSymbolInfoSize : Function {
let name = "olGetSymbolInfoSize";
let desc = "Returns the storage size of the given symbol query."; let desc = "Returns the storage size of the given symbol query.";
let details = []; let details = [];
let params = [ let params = [

View File

@ -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; uint32_t EtorVal = 0;
for (const auto &EnumVal : ErrorCodeEnum.getValues()) { for (const auto &EnumVal : ErrorCodeEnum.getValues()) {
OS << formatv(TAB_1 "OFFLOAD_ERRC({0}, \"{1}\", {2})\n", EnumVal.getName(), 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 // Bitfields start from 1, other enums from 0
uint32_t EtorVal = Enum.isBitField(); uint32_t EtorVal = Enum.isBitField();
for (const auto &EnumVal : Enum.getValues()) { for (const auto &EnumVal : Enum.getValues()) {

View File

@ -16,25 +16,30 @@ namespace llvm {
namespace offload { namespace offload {
namespace tblgen { namespace tblgen {
class HandleRec { class APIObject {
public: public:
explicit HandleRec(const Record *rec) : rec(rec) {} StringRef getName() const { return rec->getName(); }
StringRef getName() const { return rec->getValueAsString("name"); }
StringRef getDesc() const { return rec->getValueAsString("desc"); } StringRef getDesc() const { return rec->getValueAsString("desc"); }
private: protected:
APIObject(const Record *rec) : rec(rec) {}
const Record *rec; const Record *rec;
}; };
class MacroRec { class HandleRec : public APIObject {
public: public:
explicit MacroRec(const Record *rec) : rec(rec) { explicit HandleRec(const Record *rec) : APIObject(rec) {};
auto Name = rec->getValueAsString("name"); };
class MacroRec : public APIObject {
public:
explicit MacroRec(const Record *rec) : APIObject(rec) {
auto Name = rec->getName();
auto OpenBrace = Name.find_first_of("("); auto OpenBrace = Name.find_first_of("(");
nameWithoutArgs = Name.substr(0, OpenBrace); nameWithoutArgs = Name.substr(0, OpenBrace);
} }
StringRef getName() const { return nameWithoutArgs; } 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"); } StringRef getDesc() const { return rec->getValueAsString("desc"); }
std::optional<StringRef> getCondition() const { std::optional<StringRef> getCondition() const {
@ -46,19 +51,15 @@ public:
} }
private: private:
const Record *rec;
std::string nameWithoutArgs; std::string nameWithoutArgs;
}; };
class TypedefRec { class TypedefRec : public APIObject {
public: public:
explicit TypedefRec(const Record *rec) : rec(rec) {} explicit TypedefRec(const Record *rec) : APIObject(rec) {};
StringRef getName() const { return rec->getValueAsString("name"); }
StringRef getDesc() const { return rec->getValueAsString("desc"); }
StringRef getValue() const { return rec->getValueAsString("value"); }
private: public:
const Record *rec; StringRef getValue() const { return rec->getValueAsString("value"); }
}; };
class EnumValueRec { class EnumValueRec {
@ -74,15 +75,13 @@ private:
const Record *rec; const Record *rec;
}; };
class EnumRec { class EnumRec : public APIObject {
public: public:
explicit EnumRec(const Record *rec) : rec(rec) { explicit EnumRec(const Record *rec) : APIObject(rec) {
for (const auto *Val : rec->getValueAsListOfDefs("etors")) { for (const auto *Val : rec->getValueAsListOfDefs("etors")) {
vals.emplace_back(EnumValueRec{Val}); 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; } const std::vector<EnumValueRec> &getValues() const { return vals; }
std::string getEnumValNamePrefix() const { std::string getEnumValNamePrefix() const {
@ -95,7 +94,6 @@ public:
bool isBitField() const { return rec->getValueAsBit("is_bit_field"); } bool isBitField() const { return rec->getValueAsBit("is_bit_field"); }
private: private:
const Record *rec;
std::vector<EnumValueRec> vals; std::vector<EnumValueRec> vals;
}; };
@ -112,22 +110,19 @@ private:
const Record *rec; const Record *rec;
}; };
class StructRec { class StructRec : public APIObject {
public: public:
explicit StructRec(const Record *rec) : rec(rec) { explicit StructRec(const Record *rec) : APIObject(rec) {
for (auto *Member : rec->getValueAsListOfDefs("all_members")) { for (auto *Member : rec->getValueAsListOfDefs("all_members")) {
members.emplace_back(StructMemberRec(Member)); members.emplace_back(StructMemberRec(Member));
} }
} }
StringRef getName() const { return rec->getValueAsString("name"); }
StringRef getDesc() const { return rec->getValueAsString("desc"); }
std::optional<StringRef> getBaseClass() const { std::optional<StringRef> getBaseClass() const {
return rec->getValueAsOptionalString("base_class"); return rec->getValueAsOptionalString("base_class");
} }
const std::vector<StructMemberRec> &getMembers() const { return members; } const std::vector<StructMemberRec> &getMembers() const { return members; }
private: private:
const Record *rec;
std::vector<StructMemberRec> members; std::vector<StructMemberRec> members;
}; };
@ -207,9 +202,9 @@ private:
const Record *rec; const Record *rec;
}; };
class FunctionRec { class FunctionRec : public APIObject {
public: public:
FunctionRec(const Record *rec) : rec(rec) { FunctionRec(const Record *rec) : APIObject(rec) {
for (auto &Ret : rec->getValueAsListOfDefs("all_returns")) for (auto &Ret : rec->getValueAsListOfDefs("all_returns"))
rets.emplace_back(Ret); rets.emplace_back(Ret);
for (auto &Param : rec->getValueAsListOfDefs("params")) for (auto &Param : rec->getValueAsListOfDefs("params"))
@ -221,11 +216,9 @@ public:
llvm::convertToSnakeFromCamelCase(getName())); llvm::convertToSnakeFromCamelCase(getName()));
} }
StringRef getName() const { return rec->getValueAsString("name"); }
StringRef getClass() const { return rec->getValueAsString("api_class"); } StringRef getClass() const { return rec->getValueAsString("api_class"); }
const std::vector<ReturnRec> &getReturns() const { return rets; } const std::vector<ReturnRec> &getReturns() const { return rets; }
const std::vector<ParamRec> &getParams() const { return params; } const std::vector<ParamRec> &getParams() const { return params; }
StringRef getDesc() const { return rec->getValueAsString("desc"); }
std::vector<StringRef> getDetails() const { std::vector<StringRef> getDetails() const {
return rec->getValueAsListOfStrings("details"); return rec->getValueAsListOfStrings("details");
} }
@ -236,25 +229,19 @@ public:
private: private:
std::vector<ReturnRec> rets; std::vector<ReturnRec> rets;
std::vector<ParamRec> params; std::vector<ParamRec> params;
const Record *rec;
}; };
class FptrTypedefRec { class FptrTypedefRec : public APIObject {
public: public:
explicit FptrTypedefRec(const Record *rec) : rec(rec) { explicit FptrTypedefRec(const Record *rec) : APIObject(rec) {
for (auto &Param : rec->getValueAsListOfDefs("params")) for (auto &Param : rec->getValueAsListOfDefs("params"))
params.emplace_back(Param); 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"); } StringRef getReturn() const { return rec->getValueAsString("return"); }
const std::vector<ParamRec> &getParams() const { return params; } const std::vector<ParamRec> &getParams() const { return params; }
private: private:
std::vector<ParamRec> params; std::vector<ParamRec> params;
const Record *rec;
}; };
} // namespace tblgen } // namespace tblgen