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