2011-07-26 00:24:13 +00:00
|
|
|
//===-- llvm/MC/MCTargetAsmParser.h - Target Assembly Parser ----*- C++ -*-===//
|
2009-07-17 20:42:00 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-13 16:26:38 +00:00
|
|
|
#ifndef LLVM_MC_MCTARGETASMPARSER_H
|
|
|
|
#define LLVM_MC_MCTARGETASMPARSER_H
|
2009-07-17 20:42:00 +00:00
|
|
|
|
2013-08-27 20:23:19 +00:00
|
|
|
#include "llvm/MC/MCExpr.h"
|
2014-01-07 11:48:04 +00:00
|
|
|
#include "llvm/MC/MCParser/MCAsmParserExtension.h"
|
2014-04-23 11:16:03 +00:00
|
|
|
#include "llvm/MC/MCTargetOptions.h"
|
2010-07-12 17:27:45 +00:00
|
|
|
|
2014-06-08 16:18:35 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2009-07-17 20:42:00 +00:00
|
|
|
namespace llvm {
|
2010-01-14 21:32:45 +00:00
|
|
|
class AsmToken;
|
2011-08-15 23:03:29 +00:00
|
|
|
class MCInst;
|
2014-04-23 11:16:03 +00:00
|
|
|
class MCParsedAsmOperand;
|
|
|
|
class MCStreamer;
|
|
|
|
class SMLoc;
|
|
|
|
class StringRef;
|
2010-01-14 22:21:20 +00:00
|
|
|
template <typename T> class SmallVectorImpl;
|
2009-07-17 20:42:00 +00:00
|
|
|
|
2014-06-08 16:18:35 +00:00
|
|
|
typedef SmallVectorImpl<std::unique_ptr<MCParsedAsmOperand>> OperandVector;
|
|
|
|
|
2012-10-25 20:41:34 +00:00
|
|
|
enum AsmRewriteKind {
|
2013-04-11 22:00:03 +00:00
|
|
|
AOK_Delete = 0, // Rewrite should be ignored.
|
|
|
|
AOK_Align, // Rewrite align as .align.
|
2012-10-26 18:04:20 +00:00
|
|
|
AOK_DotOperator, // Rewrite a dot operator expression as an immediate.
|
|
|
|
// E.g., [eax].foo.bar -> [eax].8
|
|
|
|
AOK_Emit, // Rewrite _emit as .byte.
|
|
|
|
AOK_Imm, // Rewrite as $$N.
|
|
|
|
AOK_ImmPrefix, // Add $$ before a parsed Imm.
|
|
|
|
AOK_Input, // Rewrite in terms of $N.
|
|
|
|
AOK_Output, // Rewrite in terms of $N.
|
|
|
|
AOK_SizeDirective, // Add a sizing directive (e.g., dword ptr).
|
2014-09-22 02:21:35 +00:00
|
|
|
AOK_Label, // Rewrite local labels.
|
2012-10-26 18:04:20 +00:00
|
|
|
AOK_Skip // Skip emission (e.g., offset/type operators).
|
2012-10-25 20:41:34 +00:00
|
|
|
};
|
|
|
|
|
2013-04-08 17:43:47 +00:00
|
|
|
const char AsmRewritePrecedence [] = {
|
2013-04-11 22:00:03 +00:00
|
|
|
0, // AOK_Delete
|
2014-09-22 20:40:36 +00:00
|
|
|
2, // AOK_Align
|
|
|
|
2, // AOK_DotOperator
|
|
|
|
2, // AOK_Emit
|
|
|
|
4, // AOK_Imm
|
|
|
|
4, // AOK_ImmPrefix
|
|
|
|
3, // AOK_Input
|
|
|
|
3, // AOK_Output
|
|
|
|
5, // AOK_SizeDirective
|
2014-09-22 02:21:35 +00:00
|
|
|
1, // AOK_Label
|
2014-09-22 20:40:36 +00:00
|
|
|
2 // AOK_Skip
|
2013-04-08 17:43:47 +00:00
|
|
|
};
|
|
|
|
|
2012-10-25 20:41:34 +00:00
|
|
|
struct AsmRewrite {
|
|
|
|
AsmRewriteKind Kind;
|
|
|
|
SMLoc Loc;
|
|
|
|
unsigned Len;
|
|
|
|
unsigned Val;
|
2014-09-22 02:21:35 +00:00
|
|
|
StringRef Label;
|
2012-10-25 20:41:34 +00:00
|
|
|
public:
|
2012-10-26 18:04:20 +00:00
|
|
|
AsmRewrite(AsmRewriteKind kind, SMLoc loc, unsigned len = 0, unsigned val = 0)
|
2012-10-25 20:41:34 +00:00
|
|
|
: Kind(kind), Loc(loc), Len(len), Val(val) {}
|
2014-09-22 02:21:35 +00:00
|
|
|
AsmRewrite(AsmRewriteKind kind, SMLoc loc, unsigned len, StringRef label)
|
|
|
|
: Kind(kind), Loc(loc), Len(len), Val(0), Label(label) {}
|
2012-10-25 20:41:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ParseInstructionInfo {
|
|
|
|
|
|
|
|
SmallVectorImpl<AsmRewrite> *AsmRewrites;
|
|
|
|
|
2014-04-15 06:32:26 +00:00
|
|
|
ParseInstructionInfo() : AsmRewrites(nullptr) {}
|
2012-10-25 20:41:34 +00:00
|
|
|
ParseInstructionInfo(SmallVectorImpl<AsmRewrite> *rewrites)
|
|
|
|
: AsmRewrites(rewrites) {}
|
|
|
|
|
|
|
|
~ParseInstructionInfo() {}
|
|
|
|
};
|
|
|
|
|
2011-07-26 00:24:13 +00:00
|
|
|
/// MCTargetAsmParser - Generic interface to target specific assembly parsers.
|
|
|
|
class MCTargetAsmParser : public MCAsmParserExtension {
|
2011-08-15 20:53:08 +00:00
|
|
|
public:
|
|
|
|
enum MatchResultTy {
|
|
|
|
Match_InvalidOperand,
|
|
|
|
Match_MissingFeature,
|
|
|
|
Match_MnemonicFail,
|
2011-08-15 23:03:29 +00:00
|
|
|
Match_Success,
|
|
|
|
FIRST_TARGET_MATCH_RESULT_TY
|
2011-08-15 20:53:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2012-08-29 06:28:46 +00:00
|
|
|
MCTargetAsmParser(const MCTargetAsmParser &) LLVM_DELETED_FUNCTION;
|
|
|
|
void operator=(const MCTargetAsmParser &) LLVM_DELETED_FUNCTION;
|
2009-07-17 20:42:00 +00:00
|
|
|
protected: // Can only create subclasses.
|
2011-07-26 00:24:13 +00:00
|
|
|
MCTargetAsmParser();
|
2011-08-15 17:30:25 +00:00
|
|
|
|
2011-07-08 19:33:14 +00:00
|
|
|
/// AvailableFeatures - The current set of available features.
|
2014-08-18 11:49:42 +00:00
|
|
|
uint64_t AvailableFeatures;
|
2010-07-19 05:44:09 +00:00
|
|
|
|
2012-10-19 17:57:49 +00:00
|
|
|
/// ParsingInlineAsm - Are we parsing ms-style inline assembly?
|
|
|
|
bool ParsingInlineAsm;
|
|
|
|
|
2012-10-19 20:35:42 +00:00
|
|
|
/// SemaCallback - The Sema callback implementation. Must be set when parsing
|
|
|
|
/// ms-style inline assembly.
|
|
|
|
MCAsmParserSemaCallback *SemaCallback;
|
|
|
|
|
2014-04-23 11:16:03 +00:00
|
|
|
/// Set of options which affects instrumentation of inline assembly.
|
|
|
|
MCTargetOptions MCOptions;
|
|
|
|
|
2009-07-17 20:42:00 +00:00
|
|
|
public:
|
2011-07-26 00:24:13 +00:00
|
|
|
virtual ~MCTargetAsmParser();
|
2009-07-17 20:42:00 +00:00
|
|
|
|
2014-08-18 11:49:42 +00:00
|
|
|
uint64_t getAvailableFeatures() const { return AvailableFeatures; }
|
|
|
|
void setAvailableFeatures(uint64_t Value) { AvailableFeatures = Value; }
|
2010-07-19 05:44:09 +00:00
|
|
|
|
2012-10-19 17:57:49 +00:00
|
|
|
bool isParsingInlineAsm () { return ParsingInlineAsm; }
|
|
|
|
void setParsingInlineAsm (bool Value) { ParsingInlineAsm = Value; }
|
|
|
|
|
2014-08-26 18:39:50 +00:00
|
|
|
MCTargetOptions getTargetOptions() const { return MCOptions; }
|
|
|
|
|
2012-10-19 20:35:42 +00:00
|
|
|
void setSemaCallback(MCAsmParserSemaCallback *Callback) {
|
|
|
|
SemaCallback = Callback;
|
|
|
|
}
|
|
|
|
|
2011-07-08 19:33:14 +00:00
|
|
|
virtual bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc,
|
|
|
|
SMLoc &EndLoc) = 0;
|
2011-01-27 17:14:22 +00:00
|
|
|
|
2014-09-10 09:45:49 +00:00
|
|
|
/// Sets frame register corresponding to the current MachineFunction.
|
|
|
|
virtual void SetFrameRegister(unsigned RegNo) {}
|
|
|
|
|
2009-07-20 18:55:04 +00:00
|
|
|
/// ParseInstruction - Parse one assembly instruction.
|
|
|
|
///
|
|
|
|
/// The parser is positioned following the instruction name. The target
|
|
|
|
/// specific instruction parser should parse the entire instruction and
|
|
|
|
/// construct the appropriate MCInst, or emit an error. On success, the entire
|
|
|
|
/// line should be parsed up to and including the end-of-statement token. On
|
|
|
|
/// failure, the parser is not required to read to the end of the line.
|
|
|
|
//
|
|
|
|
/// \param Name - The instruction name.
|
2010-02-22 04:10:52 +00:00
|
|
|
/// \param NameLoc - The source location of the name.
|
2010-01-14 22:21:20 +00:00
|
|
|
/// \param Operands [out] - The list of parsed operands, this returns
|
|
|
|
/// ownership of them to the caller.
|
2009-07-20 18:55:04 +00:00
|
|
|
/// \return True on failure.
|
2012-10-25 20:41:34 +00:00
|
|
|
virtual bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
|
2014-06-08 16:18:35 +00:00
|
|
|
SMLoc NameLoc, OperandVector &Operands) = 0;
|
2009-09-10 20:51:44 +00:00
|
|
|
|
|
|
|
/// ParseDirective - Parse a target specific assembler directive
|
|
|
|
///
|
|
|
|
/// The parser is positioned following the directive name. The target
|
|
|
|
/// specific directive parser should parse the entire directive doing or
|
|
|
|
/// recording any target specific work, or return true and do nothing if the
|
|
|
|
/// directive is not target specific. If the directive is specific for
|
|
|
|
/// the target, the entire line is parsed up to and including the
|
|
|
|
/// end-of-statement token and false is returned.
|
|
|
|
///
|
2010-02-22 04:10:52 +00:00
|
|
|
/// \param DirectiveID - the identifier token of the directive.
|
2009-09-10 20:51:44 +00:00
|
|
|
virtual bool ParseDirective(AsmToken DirectiveID) = 0;
|
2011-08-15 17:30:25 +00:00
|
|
|
|
2012-09-21 22:21:26 +00:00
|
|
|
/// mnemonicIsValid - This returns true if this is a valid mnemonic and false
|
|
|
|
/// otherwise.
|
2013-07-24 07:33:14 +00:00
|
|
|
virtual bool mnemonicIsValid(StringRef Mnemonic, unsigned VariantID) = 0;
|
2012-09-21 22:21:26 +00:00
|
|
|
|
2010-09-29 01:42:58 +00:00
|
|
|
/// MatchAndEmitInstruction - Recognize a series of operands of a parsed
|
|
|
|
/// instruction as an actual MCInst and emit it to the specified MCStreamer.
|
|
|
|
/// This returns false on success and returns true on failure to match.
|
2010-08-12 00:55:38 +00:00
|
|
|
///
|
|
|
|
/// On failure, the target parser is responsible for emitting a diagnostic
|
|
|
|
/// explaining the match failure.
|
2014-06-08 16:18:35 +00:00
|
|
|
virtual bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
|
|
|
|
OperandVector &Operands, MCStreamer &Out,
|
2014-08-18 11:49:42 +00:00
|
|
|
uint64_t &ErrorInfo,
|
2014-06-08 16:18:35 +00:00
|
|
|
bool MatchingInlineAsm) = 0;
|
2011-08-15 17:30:25 +00:00
|
|
|
|
2014-07-17 20:24:55 +00:00
|
|
|
/// Allows targets to let registers opt out of clobber lists.
|
|
|
|
virtual bool OmitRegisterFromClobberLists(unsigned RegNo) { return false; }
|
|
|
|
|
2013-02-06 06:00:06 +00:00
|
|
|
/// Allow a target to add special case operand matching for things that
|
|
|
|
/// tblgen doesn't/can't handle effectively. For example, literal
|
|
|
|
/// immediates on ARM. TableGen expects a token operand, but the parser
|
|
|
|
/// will recognize them as immediates.
|
2014-06-08 16:18:35 +00:00
|
|
|
virtual unsigned validateTargetOperandClass(MCParsedAsmOperand &Op,
|
2013-02-06 06:00:06 +00:00
|
|
|
unsigned Kind) {
|
|
|
|
return Match_InvalidOperand;
|
|
|
|
}
|
|
|
|
|
2011-08-15 23:03:29 +00:00
|
|
|
/// checkTargetMatchPredicate - Validate the instruction match against
|
|
|
|
/// any complex target predicates not expressible via match classes.
|
|
|
|
virtual unsigned checkTargetMatchPredicate(MCInst &Inst) {
|
|
|
|
return Match_Success;
|
|
|
|
}
|
|
|
|
|
2012-10-01 23:45:51 +00:00
|
|
|
virtual void convertToMapAndConstraints(unsigned Kind,
|
2014-06-08 16:18:35 +00:00
|
|
|
const OperandVector &Operands) = 0;
|
2013-08-27 20:23:19 +00:00
|
|
|
|
|
|
|
virtual const MCExpr *applyModifierToExpr(const MCExpr *E,
|
|
|
|
MCSymbolRefExpr::VariantKind,
|
|
|
|
MCContext &Ctx) {
|
2014-04-15 06:32:26 +00:00
|
|
|
return nullptr;
|
2013-08-27 20:23:19 +00:00
|
|
|
}
|
2013-10-25 12:49:50 +00:00
|
|
|
|
|
|
|
virtual void onLabelParsed(MCSymbol *Symbol) { };
|
2009-07-17 20:42:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|