File indexing completed on 2026-05-10 08:42:56
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLDB_UTILITY_ARCHSPEC_H
0010 #define LLDB_UTILITY_ARCHSPEC_H
0011
0012 #include "lldb/Utility/CompletionRequest.h"
0013 #include "lldb/lldb-enumerations.h"
0014 #include "lldb/lldb-forward.h"
0015 #include "lldb/lldb-private-enumerations.h"
0016 #include "llvm/ADT/StringRef.h"
0017 #include "llvm/TargetParser/Triple.h"
0018 #include <cstddef>
0019 #include <cstdint>
0020 #include <string>
0021
0022 namespace lldb_private {
0023
0024
0025
0026
0027
0028
0029
0030
0031 class ArchSpec {
0032 public:
0033 enum MIPSSubType {
0034 eMIPSSubType_unknown,
0035 eMIPSSubType_mips32,
0036 eMIPSSubType_mips32r2,
0037 eMIPSSubType_mips32r6,
0038 eMIPSSubType_mips32el,
0039 eMIPSSubType_mips32r2el,
0040 eMIPSSubType_mips32r6el,
0041 eMIPSSubType_mips64,
0042 eMIPSSubType_mips64r2,
0043 eMIPSSubType_mips64r6,
0044 eMIPSSubType_mips64el,
0045 eMIPSSubType_mips64r2el,
0046 eMIPSSubType_mips64r6el,
0047 };
0048
0049
0050 enum MIPSASE {
0051 eMIPSAse_dsp = 0x00000001,
0052 eMIPSAse_dspr2 = 0x00000002,
0053 eMIPSAse_eva = 0x00000004,
0054 eMIPSAse_mcu = 0x00000008,
0055 eMIPSAse_mdmx = 0x00000010,
0056 eMIPSAse_mips3d = 0x00000020,
0057 eMIPSAse_mt = 0x00000040,
0058 eMIPSAse_smartmips = 0x00000080,
0059 eMIPSAse_virt = 0x00000100,
0060 eMIPSAse_msa = 0x00000200,
0061 eMIPSAse_mips16 = 0x00000400,
0062 eMIPSAse_micromips = 0x00000800,
0063 eMIPSAse_xpa = 0x00001000,
0064 eMIPSAse_mask = 0x00001fff,
0065 eMIPSABI_O32 = 0x00002000,
0066 eMIPSABI_N32 = 0x00004000,
0067 eMIPSABI_N64 = 0x00008000,
0068 eMIPSABI_O64 = 0x00020000,
0069 eMIPSABI_EABI32 = 0x00040000,
0070 eMIPSABI_EABI64 = 0x00080000,
0071 eMIPSABI_mask = 0x000ff000
0072 };
0073
0074
0075 enum MIPS_ABI_FP {
0076 eMIPS_ABI_FP_ANY = 0x00000000,
0077 eMIPS_ABI_FP_DOUBLE = 0x00100000,
0078 eMIPS_ABI_FP_SINGLE = 0x00200000,
0079 eMIPS_ABI_FP_SOFT = 0x00300000,
0080 eMIPS_ABI_FP_OLD_64 = 0x00400000,
0081 eMIPS_ABI_FP_XX = 0x00500000,
0082 eMIPS_ABI_FP_64 = 0x00600000,
0083 eMIPS_ABI_FP_64A = 0x00700000,
0084 eMIPS_ABI_FP_mask = 0x00700000
0085 };
0086
0087
0088 enum ARMeflags {
0089 eARM_abi_soft_float = 0x00000200,
0090 eARM_abi_hard_float = 0x00000400
0091 };
0092
0093 enum RISCVeflags {
0094 eRISCV_rvc = 0x00000001,
0095 eRISCV_float_abi_soft = 0x00000000,
0096 eRISCV_float_abi_single = 0x00000002,
0097 eRISCV_float_abi_double = 0x00000004,
0098 eRISCV_float_abi_quad = 0x00000006,
0099 eRISCV_float_abi_mask = 0x00000006,
0100 eRISCV_rve = 0x00000008,
0101 eRISCV_tso = 0x00000010,
0102 };
0103
0104 enum RISCVSubType {
0105 eRISCVSubType_unknown,
0106 eRISCVSubType_riscv32,
0107 eRISCVSubType_riscv64,
0108 };
0109
0110 enum LoongArcheflags {
0111 eLoongArch_abi_soft_float = 0x00000000,
0112 eLoongArch_abi_single_float =
0113 0x00000001,
0114 eLoongArch_abi_double_float =
0115 0x00000002,
0116 eLoongArch_abi_mask = 0x00000003,
0117 };
0118
0119 enum LoongArchSubType {
0120 eLoongArchSubType_unknown,
0121 eLoongArchSubType_loongarch32,
0122 eLoongArchSubType_loongarch64,
0123 };
0124
0125 enum Core {
0126 eCore_arm_generic,
0127 eCore_arm_armv4,
0128 eCore_arm_armv4t,
0129 eCore_arm_armv5,
0130 eCore_arm_armv5e,
0131 eCore_arm_armv5t,
0132 eCore_arm_armv6,
0133 eCore_arm_armv6m,
0134 eCore_arm_armv7,
0135 eCore_arm_armv7a,
0136 eCore_arm_armv7l,
0137 eCore_arm_armv7f,
0138 eCore_arm_armv7s,
0139 eCore_arm_armv7k,
0140 eCore_arm_armv7m,
0141 eCore_arm_armv7em,
0142 eCore_arm_xscale,
0143
0144 eCore_thumb,
0145 eCore_thumbv4t,
0146 eCore_thumbv5,
0147 eCore_thumbv5e,
0148 eCore_thumbv6,
0149 eCore_thumbv6m,
0150 eCore_thumbv7,
0151 eCore_thumbv7s,
0152 eCore_thumbv7k,
0153 eCore_thumbv7f,
0154 eCore_thumbv7m,
0155 eCore_thumbv7em,
0156 eCore_arm_arm64,
0157 eCore_arm_armv8,
0158 eCore_arm_armv8a,
0159 eCore_arm_armv8l,
0160 eCore_arm_arm64e,
0161 eCore_arm_arm64_32,
0162 eCore_arm_aarch64,
0163
0164 eCore_mips32,
0165 eCore_mips32r2,
0166 eCore_mips32r3,
0167 eCore_mips32r5,
0168 eCore_mips32r6,
0169 eCore_mips32el,
0170 eCore_mips32r2el,
0171 eCore_mips32r3el,
0172 eCore_mips32r5el,
0173 eCore_mips32r6el,
0174 eCore_mips64,
0175 eCore_mips64r2,
0176 eCore_mips64r3,
0177 eCore_mips64r5,
0178 eCore_mips64r6,
0179 eCore_mips64el,
0180 eCore_mips64r2el,
0181 eCore_mips64r3el,
0182 eCore_mips64r5el,
0183 eCore_mips64r6el,
0184
0185 eCore_msp430,
0186
0187 eCore_ppc_generic,
0188 eCore_ppc_ppc601,
0189 eCore_ppc_ppc602,
0190 eCore_ppc_ppc603,
0191 eCore_ppc_ppc603e,
0192 eCore_ppc_ppc603ev,
0193 eCore_ppc_ppc604,
0194 eCore_ppc_ppc604e,
0195 eCore_ppc_ppc620,
0196 eCore_ppc_ppc750,
0197 eCore_ppc_ppc7400,
0198 eCore_ppc_ppc7450,
0199 eCore_ppc_ppc970,
0200
0201 eCore_ppc64le_generic,
0202 eCore_ppc64_generic,
0203 eCore_ppc64_ppc970_64,
0204
0205 eCore_s390x_generic,
0206
0207 eCore_sparc_generic,
0208
0209 eCore_sparc9_generic,
0210
0211 eCore_x86_32_i386,
0212 eCore_x86_32_i486,
0213 eCore_x86_32_i486sx,
0214 eCore_x86_32_i686,
0215
0216 eCore_x86_64_x86_64,
0217 eCore_x86_64_x86_64h,
0218 eCore_x86_64_amd64,
0219
0220 eCore_hexagon_generic,
0221 eCore_hexagon_hexagonv4,
0222 eCore_hexagon_hexagonv5,
0223
0224 eCore_riscv32,
0225 eCore_riscv64,
0226
0227 eCore_loongarch32,
0228 eCore_loongarch64,
0229
0230 eCore_uknownMach32,
0231 eCore_uknownMach64,
0232
0233 eCore_arc,
0234
0235 eCore_avr,
0236
0237 eCore_wasm32,
0238
0239 kNumCores,
0240
0241 kCore_invalid,
0242
0243 kCore_any,
0244 kCore_arm_any,
0245 kCore_ppc_any,
0246 kCore_ppc64_any,
0247 kCore_x86_32_any,
0248 kCore_x86_64_any,
0249 kCore_hexagon_any,
0250
0251 kCore_arm_first = eCore_arm_generic,
0252 kCore_arm_last = eCore_arm_xscale,
0253
0254 kCore_thumb_first = eCore_thumb,
0255 kCore_thumb_last = eCore_thumbv7em,
0256
0257 kCore_ppc_first = eCore_ppc_generic,
0258 kCore_ppc_last = eCore_ppc_ppc970,
0259
0260 kCore_ppc64_first = eCore_ppc64_generic,
0261 kCore_ppc64_last = eCore_ppc64_ppc970_64,
0262
0263 kCore_x86_32_first = eCore_x86_32_i386,
0264 kCore_x86_32_last = eCore_x86_32_i686,
0265
0266 kCore_x86_64_first = eCore_x86_64_x86_64,
0267 kCore_x86_64_last = eCore_x86_64_x86_64h,
0268
0269 kCore_hexagon_first = eCore_hexagon_generic,
0270 kCore_hexagon_last = eCore_hexagon_hexagonv5,
0271
0272 kCore_mips32_first = eCore_mips32,
0273 kCore_mips32_last = eCore_mips32r6,
0274
0275 kCore_mips32el_first = eCore_mips32el,
0276 kCore_mips32el_last = eCore_mips32r6el,
0277
0278 kCore_mips64_first = eCore_mips64,
0279 kCore_mips64_last = eCore_mips64r6,
0280
0281 kCore_mips64el_first = eCore_mips64el,
0282 kCore_mips64el_last = eCore_mips64r6el,
0283
0284 kCore_mips_first = eCore_mips32,
0285 kCore_mips_last = eCore_mips64r6el
0286
0287 };
0288
0289
0290
0291
0292
0293 ArchSpec();
0294
0295
0296
0297
0298 explicit ArchSpec(const llvm::Triple &triple);
0299 explicit ArchSpec(const char *triple_cstr);
0300 explicit ArchSpec(llvm::StringRef triple_str);
0301
0302
0303
0304
0305 explicit ArchSpec(ArchitectureType arch_type, uint32_t cpu_type,
0306 uint32_t cpu_subtype);
0307
0308
0309 ~ArchSpec();
0310
0311
0312
0313
0314 static bool ContainsOnlyArch(const llvm::Triple &normalized_triple);
0315
0316 static void ListSupportedArchNames(StringList &list);
0317 static void AutoComplete(CompletionRequest &request);
0318
0319
0320
0321
0322
0323 const char *GetArchitectureName() const;
0324
0325
0326
0327
0328 bool IsMIPS() const;
0329
0330
0331
0332
0333
0334
0335 std::string GetClangTargetCPU() const;
0336
0337
0338
0339
0340 std::string GetTargetABI() const;
0341
0342
0343
0344
0345 void Clear();
0346
0347
0348
0349
0350 uint32_t GetAddressByteSize() const;
0351
0352
0353
0354
0355 llvm::Triple::ArchType GetMachine() const;
0356
0357
0358
0359
0360
0361 bool IsValid() const {
0362 return m_core >= eCore_arm_generic && m_core < kNumCores;
0363 }
0364 explicit operator bool() const { return IsValid(); }
0365
0366 bool TripleVendorWasSpecified() const {
0367 return !m_triple.getVendorName().empty();
0368 }
0369
0370 bool TripleOSWasSpecified() const { return !m_triple.getOSName().empty(); }
0371
0372 bool TripleEnvironmentWasSpecified() const {
0373 return m_triple.hasEnvironment();
0374 }
0375
0376
0377
0378
0379
0380
0381
0382
0383
0384
0385 void MergeFrom(const ArchSpec &other);
0386
0387
0388
0389
0390
0391
0392
0393
0394
0395
0396
0397
0398
0399
0400
0401
0402
0403
0404
0405
0406
0407
0408
0409
0410
0411
0412
0413
0414
0415
0416
0417
0418
0419
0420
0421 bool SetArchitecture(ArchitectureType arch_type, uint32_t cpu, uint32_t sub,
0422 uint32_t os = 0);
0423
0424
0425
0426
0427
0428 lldb::ByteOrder GetByteOrder() const;
0429
0430
0431
0432
0433
0434
0435
0436 void SetByteOrder(lldb::ByteOrder byte_order) { m_byte_order = byte_order; }
0437
0438 uint32_t GetMinimumOpcodeByteSize() const;
0439
0440 uint32_t GetMaximumOpcodeByteSize() const;
0441
0442 Core GetCore() const { return m_core; }
0443
0444 uint32_t GetMachOCPUType() const;
0445
0446 uint32_t GetMachOCPUSubType() const;
0447
0448
0449
0450
0451
0452 uint32_t GetDataByteSize() const;
0453
0454
0455
0456
0457
0458 uint32_t GetCodeByteSize() const;
0459
0460
0461
0462
0463 llvm::Triple &GetTriple() { return m_triple; }
0464
0465
0466
0467
0468 const llvm::Triple &GetTriple() const { return m_triple; }
0469
0470 void DumpTriple(llvm::raw_ostream &s) const;
0471
0472
0473
0474
0475
0476
0477
0478
0479
0480
0481
0482 bool SetTriple(const llvm::Triple &triple);
0483
0484 bool SetTriple(llvm::StringRef triple_str);
0485
0486
0487
0488
0489
0490 lldb::ByteOrder GetDefaultEndian() const;
0491
0492
0493
0494
0495
0496
0497 bool CharIsSignedByDefault() const;
0498
0499 enum MatchType : bool { CompatibleMatch, ExactMatch };
0500
0501
0502
0503
0504
0505
0506
0507 bool IsMatch(const ArchSpec &rhs, MatchType match) const;
0508
0509
0510 bool IsExactMatch(const ArchSpec &rhs) const {
0511 return IsMatch(rhs, ExactMatch);
0512 }
0513
0514
0515 bool IsCompatibleMatch(const ArchSpec &rhs) const {
0516 return IsMatch(rhs, CompatibleMatch);
0517 }
0518
0519 bool IsFullySpecifiedTriple() const;
0520
0521
0522
0523
0524
0525
0526
0527
0528
0529
0530
0531
0532 bool IsAlwaysThumbInstructions() const;
0533
0534 uint32_t GetFlags() const { return m_flags; }
0535
0536 void SetFlags(uint32_t flags) { m_flags = flags; }
0537
0538 void SetFlags(const std::string &elf_abi);
0539
0540 protected:
0541 void UpdateCore();
0542
0543 llvm::Triple m_triple;
0544 Core m_core = kCore_invalid;
0545 lldb::ByteOrder m_byte_order = lldb::eByteOrderInvalid;
0546
0547
0548
0549 uint32_t m_flags = 0;
0550
0551
0552
0553 void CoreUpdated(bool update_triple);
0554 };
0555
0556
0557
0558
0559
0560
0561
0562
0563
0564
0565 bool operator<(const ArchSpec &lhs, const ArchSpec &rhs);
0566 bool operator==(const ArchSpec &lhs, const ArchSpec &rhs);
0567
0568 bool ParseMachCPUDashSubtypeTriple(llvm::StringRef triple_str, ArchSpec &arch);
0569
0570 }
0571
0572 #endif