2010-02-10 05:50:41 +08:00
|
|
|
//===- AsmWriterInst.h - Classes encapsulating a printable inst -*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// 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
|
2010-02-10 05:50:41 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// These classes implement a parser for assembly strings. The parser splits
|
|
|
|
// the string into operands, which can be literal strings (the constant bits of
|
|
|
|
// the string), actual operands (i.e., operands from the MachineInstr), and
|
|
|
|
// dynamically-generated text, specified by raw C++ code.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#ifndef LLVM_UTILS_TABLEGEN_ASMWRITERINST_H
|
|
|
|
#define LLVM_UTILS_TABLEGEN_ASMWRITERINST_H
|
2010-02-10 05:50:41 +08:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
class CodeGenInstruction;
|
|
|
|
class Record;
|
2010-10-12 03:38:01 +08:00
|
|
|
|
2010-02-10 05:50:41 +08:00
|
|
|
struct AsmWriterOperand {
|
|
|
|
enum OpType {
|
|
|
|
// Output this text surrounded by quotes to the asm.
|
2010-10-12 03:38:01 +08:00
|
|
|
isLiteralTextOperand,
|
2010-02-10 05:50:41 +08:00
|
|
|
// This is the name of a routine to call to print the operand.
|
|
|
|
isMachineInstrOperand,
|
|
|
|
// Output this text verbatim to the asm writer. It is code that
|
|
|
|
// will output some text to the asm.
|
|
|
|
isLiteralStatementOperand
|
|
|
|
} OperandType;
|
2010-10-12 03:38:01 +08:00
|
|
|
|
2016-01-22 13:59:40 +08:00
|
|
|
/// MiOpNo - For isMachineInstrOperand, this is the operand number of the
|
|
|
|
/// machine instruction.
|
|
|
|
unsigned MIOpNo;
|
|
|
|
|
2010-02-10 05:50:41 +08:00
|
|
|
/// Str - For isLiteralTextOperand, this IS the literal text. For
|
|
|
|
/// isMachineInstrOperand, this is the PrinterMethodName for the operand..
|
2010-10-12 03:38:01 +08:00
|
|
|
/// For isLiteralStatementOperand, this is the code to insert verbatim
|
2010-02-10 05:50:41 +08:00
|
|
|
/// into the asm writer.
|
|
|
|
std::string Str;
|
2010-10-12 03:38:01 +08:00
|
|
|
|
2010-02-10 05:50:41 +08:00
|
|
|
/// MiModifier - For isMachineInstrOperand, this is the modifier string for
|
|
|
|
/// an operand, specified with syntax like ${opname:modifier}.
|
|
|
|
std::string MiModifier;
|
2010-10-12 03:38:01 +08:00
|
|
|
|
2010-02-10 05:50:41 +08:00
|
|
|
// To make VS STL happy
|
|
|
|
AsmWriterOperand(OpType op = isLiteralTextOperand):OperandType(op) {}
|
2010-10-12 03:38:01 +08:00
|
|
|
|
2010-02-10 05:50:41 +08:00
|
|
|
AsmWriterOperand(const std::string &LitStr,
|
|
|
|
OpType op = isLiteralTextOperand)
|
|
|
|
: OperandType(op), Str(LitStr) {}
|
2010-10-12 03:38:01 +08:00
|
|
|
|
2010-02-10 10:27:43 +08:00
|
|
|
AsmWriterOperand(const std::string &Printer,
|
|
|
|
unsigned _MIOpNo,
|
2010-02-10 05:50:41 +08:00
|
|
|
const std::string &Modifier,
|
2010-10-12 03:38:01 +08:00
|
|
|
OpType op = isMachineInstrOperand)
|
2016-01-22 13:59:40 +08:00
|
|
|
: OperandType(op), MIOpNo(_MIOpNo), Str(Printer), MiModifier(Modifier) {}
|
2010-10-12 03:38:01 +08:00
|
|
|
|
2010-02-10 05:50:41 +08:00
|
|
|
bool operator!=(const AsmWriterOperand &Other) const {
|
|
|
|
if (OperandType != Other.OperandType || Str != Other.Str) return true;
|
|
|
|
if (OperandType == isMachineInstrOperand)
|
|
|
|
return MIOpNo != Other.MIOpNo || MiModifier != Other.MiModifier;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool operator==(const AsmWriterOperand &Other) const {
|
|
|
|
return !operator!=(Other);
|
|
|
|
}
|
2010-10-12 03:38:01 +08:00
|
|
|
|
2010-02-10 05:50:41 +08:00
|
|
|
/// getCode - Return the code that prints this operand.
|
2016-01-14 14:15:07 +08:00
|
|
|
std::string getCode(bool PassSubtarget) const;
|
2010-02-10 05:50:41 +08:00
|
|
|
};
|
2010-10-12 03:38:01 +08:00
|
|
|
|
2010-02-10 05:50:41 +08:00
|
|
|
class AsmWriterInst {
|
|
|
|
public:
|
|
|
|
std::vector<AsmWriterOperand> Operands;
|
|
|
|
const CodeGenInstruction *CGI;
|
2016-01-17 16:05:33 +08:00
|
|
|
unsigned CGIIndex;
|
2010-10-12 03:38:01 +08:00
|
|
|
|
2016-01-17 16:05:33 +08:00
|
|
|
AsmWriterInst(const CodeGenInstruction &CGI, unsigned CGIIndex,
|
|
|
|
unsigned Variant);
|
2010-10-12 03:38:01 +08:00
|
|
|
|
2010-02-10 05:50:41 +08:00
|
|
|
/// MatchesAllButOneOp - If this instruction is exactly identical to the
|
|
|
|
/// specified instruction except for one differing operand, return the
|
|
|
|
/// differing operand number. Otherwise return ~0.
|
|
|
|
unsigned MatchesAllButOneOp(const AsmWriterInst &Other) const;
|
2010-10-12 03:38:01 +08:00
|
|
|
|
2010-02-10 05:50:41 +08:00
|
|
|
private:
|
|
|
|
void AddLiteralString(const std::string &Str) {
|
|
|
|
// If the last operand was already a literal text string, append this to
|
|
|
|
// it, otherwise add a new operand.
|
|
|
|
if (!Operands.empty() &&
|
|
|
|
Operands.back().OperandType == AsmWriterOperand::isLiteralTextOperand)
|
|
|
|
Operands.back().Str.append(Str);
|
|
|
|
else
|
|
|
|
Operands.push_back(AsmWriterOperand(Str));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|