Path: blob/main/contrib/llvm-project/llvm/utils/TableGen/Common/AsmWriterInst.h
35290 views
//===- AsmWriterInst.h - Classes encapsulating a printable inst -*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// These classes implement a parser for assembly strings. The parser splits9// the string into operands, which can be literal strings (the constant bits of10// the string), actual operands (i.e., operands from the MachineInstr), and11// dynamically-generated text, specified by raw C++ code.12//13//===----------------------------------------------------------------------===//1415#ifndef LLVM_UTILS_TABLEGEN_ASMWRITERINST_H16#define LLVM_UTILS_TABLEGEN_ASMWRITERINST_H1718#include <string>19#include <vector>2021namespace llvm {22class CodeGenInstruction;2324struct AsmWriterOperand {25enum OpType {26// Output this text surrounded by quotes to the asm.27isLiteralTextOperand,28// This is the name of a routine to call to print the operand.29isMachineInstrOperand,30// Output this text verbatim to the asm writer. It is code that31// will output some text to the asm.32isLiteralStatementOperand33} OperandType;3435/// MiOpNo - For isMachineInstrOperand, this is the operand number of the36/// machine instruction.37unsigned MIOpNo = 0;3839/// Str - For isLiteralTextOperand, this IS the literal text. For40/// isMachineInstrOperand, this is the PrinterMethodName for the operand..41/// For isLiteralStatementOperand, this is the code to insert verbatim42/// into the asm writer.43std::string Str;4445/// MiModifier - For isMachineInstrOperand, this is the modifier string for46/// an operand, specified with syntax like ${opname:modifier}.47std::string MiModifier;4849bool PCRel = false;5051// To make VS STL happy52AsmWriterOperand(OpType op = isLiteralTextOperand) : OperandType(op) {}5354AsmWriterOperand(const std::string &LitStr, OpType op = isLiteralTextOperand)55: OperandType(op), Str(LitStr) {}5657AsmWriterOperand(const std::string &Printer, unsigned _MIOpNo,58const std::string &Modifier,59OpType op = isMachineInstrOperand, bool PCRel = false)60: OperandType(op), MIOpNo(_MIOpNo), Str(Printer), MiModifier(Modifier),61PCRel(PCRel) {}6263bool operator!=(const AsmWriterOperand &Other) const {64if (OperandType != Other.OperandType || Str != Other.Str)65return true;66if (OperandType == isMachineInstrOperand)67return MIOpNo != Other.MIOpNo || MiModifier != Other.MiModifier ||68PCRel != Other.PCRel;69return false;70}71bool operator==(const AsmWriterOperand &Other) const {72return !operator!=(Other);73}7475/// getCode - Return the code that prints this operand.76std::string getCode(bool PassSubtarget) const;77};7879class AsmWriterInst {80public:81std::vector<AsmWriterOperand> Operands;82const CodeGenInstruction *CGI;83unsigned CGIIndex;8485AsmWriterInst(const CodeGenInstruction &CGI, unsigned CGIIndex,86unsigned Variant);8788/// MatchesAllButOneOp - If this instruction is exactly identical to the89/// specified instruction except for one differing operand, return the90/// differing operand number. Otherwise return ~0.91unsigned MatchesAllButOneOp(const AsmWriterInst &Other) const;9293private:94void AddLiteralString(const std::string &Str) {95// If the last operand was already a literal text string, append this to96// it, otherwise add a new operand.97if (!Operands.empty() &&98Operands.back().OperandType == AsmWriterOperand::isLiteralTextOperand)99Operands.back().Str.append(Str);100else101Operands.push_back(AsmWriterOperand(Str));102}103};104} // namespace llvm105106#endif107108109