MCInstBuilder.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-- llvm/MC/MCInstBuilder.h - Simplify creation of MCInsts --*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file contains the MCInstBuilder class for convenient creation of
  15. // MCInsts.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_MC_MCINSTBUILDER_H
  19. #define LLVM_MC_MCINSTBUILDER_H
  20. #include "llvm/MC/MCInst.h"
  21. namespace llvm {
  22. class MCInstBuilder {
  23. MCInst Inst;
  24. public:
  25. /// Create a new MCInstBuilder for an MCInst with a specific opcode.
  26. MCInstBuilder(unsigned Opcode) {
  27. Inst.setOpcode(Opcode);
  28. }
  29. /// Add a new register operand.
  30. MCInstBuilder &addReg(unsigned Reg) {
  31. Inst.addOperand(MCOperand::createReg(Reg));
  32. return *this;
  33. }
  34. /// Add a new integer immediate operand.
  35. MCInstBuilder &addImm(int64_t Val) {
  36. Inst.addOperand(MCOperand::createImm(Val));
  37. return *this;
  38. }
  39. /// Add a new single floating point immediate operand.
  40. MCInstBuilder &addSFPImm(uint32_t Val) {
  41. Inst.addOperand(MCOperand::createSFPImm(Val));
  42. return *this;
  43. }
  44. /// Add a new floating point immediate operand.
  45. MCInstBuilder &addDFPImm(uint64_t Val) {
  46. Inst.addOperand(MCOperand::createDFPImm(Val));
  47. return *this;
  48. }
  49. /// Add a new MCExpr operand.
  50. MCInstBuilder &addExpr(const MCExpr *Val) {
  51. Inst.addOperand(MCOperand::createExpr(Val));
  52. return *this;
  53. }
  54. /// Add a new MCInst operand.
  55. MCInstBuilder &addInst(const MCInst *Val) {
  56. Inst.addOperand(MCOperand::createInst(Val));
  57. return *this;
  58. }
  59. /// Add an operand.
  60. MCInstBuilder &addOperand(const MCOperand &Op) {
  61. Inst.addOperand(Op);
  62. return *this;
  63. }
  64. operator MCInst&() {
  65. return Inst;
  66. }
  67. };
  68. } // end namespace llvm
  69. #endif
  70. #ifdef __GNUC__
  71. #pragma GCC diagnostic pop
  72. #endif