[llvm] [TextAPI] Introduce Records & RecordSlice Types (PR #74115)
Cyndy Ishida via llvm-commits
llvm-commits at lists.llvm.org
Sat Dec 2 09:45:59 PST 2023
================
@@ -0,0 +1,172 @@
+//===- llvm/TextAPI/Record.h - TAPI Record ----------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief Implements the TAPI Record Types.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TEXTAPI_RECORD_H
+#define LLVM_TEXTAPI_RECORD_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/TextAPI/Symbol.h"
+#include <string>
+
+namespace llvm {
+namespace MachO {
+
+LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
+
+class RecordsSlice;
+
+// Defines a list of linkage types.
+enum class RecordLinkage : uint8_t {
+ // Unknown linkage.
+ Unknown = 0,
+
+ // Local, hidden or private extern linkage.
+ Internal = 1,
+
+ // Undefined linkage, it represents usage of external interface.
+ Undefined = 2,
+
+ // Re-exported linkage, record is defined in external interface.
+ Rexported = 3,
+
+ // Exported linkage.
+ Exported = 4,
+};
+
+/// Define Record. They represent API's in binaries that could be linkable
+/// symbols.
+class Record {
+public:
+ Record() = default;
+ Record(StringRef Name, RecordLinkage Linkage, SymbolFlags Flags)
+ : Name(Name), Linkage(Linkage), Flags(Flags) {}
+
+ bool isWeakDefined() const {
+ return (Flags & SymbolFlags::WeakDefined) == SymbolFlags::WeakDefined;
+ }
+
+ bool isWeakReferenced() const {
+ return (Flags & SymbolFlags::WeakReferenced) == SymbolFlags::WeakReferenced;
+ }
+
+ bool isThreadLocalValue() const {
+ return (Flags & SymbolFlags::ThreadLocalValue) ==
+ SymbolFlags::ThreadLocalValue;
+ }
+
+ bool isData() const {
+ return (Flags & SymbolFlags::Data) == SymbolFlags::Data;
+ }
+
+ bool isText() const {
+ return (Flags & SymbolFlags::Text) == SymbolFlags::Text;
+ }
+
+ bool isInternal() const { return Linkage == RecordLinkage::Internal; }
+ bool isUndefined() const { return Linkage == RecordLinkage::Undefined; }
+ bool isExported() const { return Linkage >= RecordLinkage::Rexported; }
+ bool isRexported() const { return Linkage == RecordLinkage::Rexported; }
+
+ StringRef getName() const { return Name; }
+
+protected:
+ StringRef Name;
+ RecordLinkage Linkage;
+ SymbolFlags Flags;
+
+ friend class RecordsSlice;
+};
+
+// Defines broadly non-objc records, categorized as variables or functions.
+class GlobalRecord : public Record {
+public:
+ enum class Kind : uint8_t {
+ Unknown = 0,
+ Variable = 1,
+ Function = 2,
+ };
+
+ GlobalRecord(StringRef Name, RecordLinkage Linkage, SymbolFlags Flags,
+ Kind GV)
+ : Record({Name, Linkage, Flags}), GV(GV) {}
+
+ bool isFunction() const { return GV == Kind::Function; }
+ bool isVariable() const { return GV == Kind::Variable; }
+
+private:
+ Kind GV;
+};
+
+// Define Objective-C instance variable records.
+struct ObjCIVarRecord : public Record {
----------------
cyndyishida wrote:
Oh yes, thanks!
https://github.com/llvm/llvm-project/pull/74115
More information about the llvm-commits
mailing list