summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/lib/Target/MBlaze/AsmParser/MBlazeAsmParser.cpp
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2014-03-21 17:53:59 +0000
committerdim <dim@FreeBSD.org>2014-03-21 17:53:59 +0000
commit9cedb8bb69b89b0f0c529937247a6a80cabdbaec (patch)
treec978f0e9ec1ab92dc8123783f30b08a7fd1e2a39 /contrib/llvm/lib/Target/MBlaze/AsmParser/MBlazeAsmParser.cpp
parent03fdc2934eb61c44c049a02b02aa974cfdd8a0eb (diff)
downloadFreeBSD-src-9cedb8bb69b89b0f0c529937247a6a80cabdbaec.zip
FreeBSD-src-9cedb8bb69b89b0f0c529937247a6a80cabdbaec.tar.gz
MFC 261991:
Upgrade our copy of llvm/clang to 3.4 release. This version supports all of the features in the current working draft of the upcoming C++ standard, provisionally named C++1y. The code generator's performance is greatly increased, and the loop auto-vectorizer is now enabled at -Os and -O2 in addition to -O3. The PowerPC backend has made several major improvements to code generation quality and compile time, and the X86, SPARC, ARM32, Aarch64 and SystemZ backends have all seen major feature work. Release notes for llvm and clang can be found here: <http://llvm.org/releases/3.4/docs/ReleaseNotes.html> <http://llvm.org/releases/3.4/tools/clang/docs/ReleaseNotes.html> MFC 262121 (by emaste): Update lldb for clang/llvm 3.4 import This commit largely restores the lldb source to the upstream r196259 snapshot with the addition of threaded inferior support and a few bug fixes. Specific upstream lldb revisions restored include: SVN git 181387 779e6ac 181703 7bef4e2 182099 b31044e 182650 f2dcf35 182683 0d91b80 183862 15c1774 183929 99447a6 184177 0b2934b 184948 4dc3761 184954 007e7bc 186990 eebd175 Sponsored by: DARPA, AFRL MFC 262186 (by emaste): Fix mismerge in r262121 A break statement was lost in the merge. The error had no functional impact, but restore it to reduce the diff against upstream. MFC 262303: Pull in r197521 from upstream clang trunk (by rdivacky): Use the integrated assembler by default on FreeBSD/ppc and ppc64. Requested by: jhibbits MFC 262611: Pull in r196874 from upstream llvm trunk: Fix a crash that occurs when PWD is invalid. MCJIT needs to be able to run in hostile environments, even when PWD is invalid. There's no need to crash MCJIT in this case. The obvious fix is to simply leave MCContext's CompilationDir empty when PWD can't be determined. This way, MCJIT clients, and other clients that link with LLVM don't need a valid working directory. If we do want to guarantee valid CompilationDir, that should be done only for clients of getCompilationDir(). This is as simple as checking for an empty string. The only current use of getCompilationDir is EmitGenDwarfInfo, which won't conceivably run with an invalid working dir. However, in the purely hypothetically and untestable case that this happens, the AT_comp_dir will be omitted from the compilation_unit DIE. This should help fix assertions occurring with ports-mgmt/tinderbox, when it is using jails, and sometimes invalidates clang's current working directory. Reported by: decke MFC 262809: Pull in r203007 from upstream clang trunk: Don't produce an alias between destructors with different calling conventions. Fixes pr19007. (Please note that is an LLVM PR identifier, not a FreeBSD one.) This should fix Firefox and/or libxul crashes (due to problems with regparm/stdcall calling conventions) on i386. Reported by: multiple users on freebsd-current PR: bin/187103 MFC 263048: Repair recognition of "CC" as an alias for the C++ compiler, since it was silently broken by upstream for a Windows-specific use-case. Apparently some versions of CMake still rely on this archaic feature... Reported by: rakuco MFC 263049: Garbage collect the old way of adding the libstdc++ include directories in clang's InitHeaderSearch.cpp. This has been superseded by David Chisnall's commit in r255321. Moreover, if libc++ is used, the libstdc++ include directories should not be in the search path at all. These directories are now only used if you pass -stdlib=libstdc++.
Diffstat (limited to 'contrib/llvm/lib/Target/MBlaze/AsmParser/MBlazeAsmParser.cpp')
-rw-r--r--contrib/llvm/lib/Target/MBlaze/AsmParser/MBlazeAsmParser.cpp572
1 files changed, 0 insertions, 572 deletions
diff --git a/contrib/llvm/lib/Target/MBlaze/AsmParser/MBlazeAsmParser.cpp b/contrib/llvm/lib/Target/MBlaze/AsmParser/MBlazeAsmParser.cpp
deleted file mode 100644
index dda6e24..0000000
--- a/contrib/llvm/lib/Target/MBlaze/AsmParser/MBlazeAsmParser.cpp
+++ /dev/null
@@ -1,572 +0,0 @@
-//===-- MBlazeAsmParser.cpp - Parse MBlaze asm to MCInst instructions -----===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "MCTargetDesc/MBlazeBaseInfo.h"
-#include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/Twine.h"
-#include "llvm/MC/MCExpr.h"
-#include "llvm/MC/MCInst.h"
-#include "llvm/MC/MCParser/MCAsmLexer.h"
-#include "llvm/MC/MCParser/MCAsmParser.h"
-#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
-#include "llvm/MC/MCStreamer.h"
-#include "llvm/MC/MCTargetAsmParser.h"
-#include "llvm/Support/SourceMgr.h"
-#include "llvm/Support/TargetRegistry.h"
-#include "llvm/Support/raw_ostream.h"
-using namespace llvm;
-
-namespace {
-struct MBlazeOperand;
-
-class MBlazeAsmParser : public MCTargetAsmParser {
- MCAsmParser &Parser;
-
- MCAsmParser &getParser() const { return Parser; }
- MCAsmLexer &getLexer() const { return Parser.getLexer(); }
-
- void Warning(SMLoc L, const Twine &Msg) { Parser.Warning(L, Msg); }
- bool Error(SMLoc L, const Twine &Msg) { return Parser.Error(L, Msg); }
-
- MBlazeOperand *ParseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands);
- MBlazeOperand *ParseRegister();
- MBlazeOperand *ParseRegister(SMLoc &StartLoc, SMLoc &EndLoc);
- MBlazeOperand *ParseImmediate();
- MBlazeOperand *ParseFsl();
- MBlazeOperand* ParseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands);
-
- virtual bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
-
- bool ParseDirectiveWord(unsigned Size, SMLoc L);
-
- bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
- SmallVectorImpl<MCParsedAsmOperand*> &Operands,
- MCStreamer &Out, unsigned &ErrorInfo,
- bool MatchingInlineAsm);
-
- /// @name Auto-generated Match Functions
- /// {
-
-#define GET_ASSEMBLER_HEADER
-#include "MBlazeGenAsmMatcher.inc"
-
- /// }
-
-public:
- MBlazeAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser)
- : MCTargetAsmParser(), Parser(_Parser) {}
-
- virtual bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
- SMLoc NameLoc,
- SmallVectorImpl<MCParsedAsmOperand*> &Operands);
-
- virtual bool ParseDirective(AsmToken DirectiveID);
-};
-
-/// MBlazeOperand - Instances of this class represent a parsed MBlaze machine
-/// instruction.
-struct MBlazeOperand : public MCParsedAsmOperand {
- enum KindTy {
- Token,
- Immediate,
- Register,
- Memory,
- Fsl
- } Kind;
-
- SMLoc StartLoc, EndLoc;
-
- struct TokOp {
- const char *Data;
- unsigned Length;
- };
-
- struct RegOp {
- unsigned RegNum;
- };
-
- struct ImmOp {
- const MCExpr *Val;
- };
-
- struct MemOp {
- unsigned Base;
- unsigned OffReg;
- const MCExpr *Off;
- };
-
- struct FslImmOp {
- const MCExpr *Val;
- };
-
- union {
- struct TokOp Tok;
- struct RegOp Reg;
- struct ImmOp Imm;
- struct MemOp Mem;
- struct FslImmOp FslImm;
- };
-
- MBlazeOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
-public:
- MBlazeOperand(const MBlazeOperand &o) : MCParsedAsmOperand() {
- Kind = o.Kind;
- StartLoc = o.StartLoc;
- EndLoc = o.EndLoc;
- switch (Kind) {
- case Register:
- Reg = o.Reg;
- break;
- case Immediate:
- Imm = o.Imm;
- break;
- case Token:
- Tok = o.Tok;
- break;
- case Memory:
- Mem = o.Mem;
- break;
- case Fsl:
- FslImm = o.FslImm;
- break;
- }
- }
-
- /// getStartLoc - Get the location of the first token of this operand.
- SMLoc getStartLoc() const { return StartLoc; }
-
- /// getEndLoc - Get the location of the last token of this operand.
- SMLoc getEndLoc() const { return EndLoc; }
-
- unsigned getReg() const {
- assert(Kind == Register && "Invalid access!");
- return Reg.RegNum;
- }
-
- const MCExpr *getImm() const {
- assert(Kind == Immediate && "Invalid access!");
- return Imm.Val;
- }
-
- const MCExpr *getFslImm() const {
- assert(Kind == Fsl && "Invalid access!");
- return FslImm.Val;
- }
-
- unsigned getMemBase() const {
- assert(Kind == Memory && "Invalid access!");
- return Mem.Base;
- }
-
- const MCExpr* getMemOff() const {
- assert(Kind == Memory && "Invalid access!");
- return Mem.Off;
- }
-
- unsigned getMemOffReg() const {
- assert(Kind == Memory && "Invalid access!");
- return Mem.OffReg;
- }
-
- bool isToken() const { return Kind == Token; }
- bool isImm() const { return Kind == Immediate; }
- bool isMem() const { return Kind == Memory; }
- bool isFsl() const { return Kind == Fsl; }
- bool isReg() const { return Kind == Register; }
-
- void addExpr(MCInst &Inst, const MCExpr *Expr) const {
- // Add as immediates when possible. Null MCExpr = 0.
- if (Expr == 0)
- Inst.addOperand(MCOperand::CreateImm(0));
- else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
- Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
- else
- Inst.addOperand(MCOperand::CreateExpr(Expr));
- }
-
- void addRegOperands(MCInst &Inst, unsigned N) const {
- assert(N == 1 && "Invalid number of operands!");
- Inst.addOperand(MCOperand::CreateReg(getReg()));
- }
-
- void addImmOperands(MCInst &Inst, unsigned N) const {
- assert(N == 1 && "Invalid number of operands!");
- addExpr(Inst, getImm());
- }
-
- void addFslOperands(MCInst &Inst, unsigned N) const {
- assert(N == 1 && "Invalid number of operands!");
- addExpr(Inst, getFslImm());
- }
-
- void addMemOperands(MCInst &Inst, unsigned N) const {
- assert(N == 2 && "Invalid number of operands!");
-
- Inst.addOperand(MCOperand::CreateReg(getMemBase()));
-
- unsigned RegOff = getMemOffReg();
- if (RegOff)
- Inst.addOperand(MCOperand::CreateReg(RegOff));
- else
- addExpr(Inst, getMemOff());
- }
-
- StringRef getToken() const {
- assert(Kind == Token && "Invalid access!");
- return StringRef(Tok.Data, Tok.Length);
- }
-
- virtual void print(raw_ostream &OS) const;
-
- static MBlazeOperand *CreateToken(StringRef Str, SMLoc S) {
- MBlazeOperand *Op = new MBlazeOperand(Token);
- Op->Tok.Data = Str.data();
- Op->Tok.Length = Str.size();
- Op->StartLoc = S;
- Op->EndLoc = S;
- return Op;
- }
-
- static MBlazeOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
- MBlazeOperand *Op = new MBlazeOperand(Register);
- Op->Reg.RegNum = RegNum;
- Op->StartLoc = S;
- Op->EndLoc = E;
- return Op;
- }
-
- static MBlazeOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
- MBlazeOperand *Op = new MBlazeOperand(Immediate);
- Op->Imm.Val = Val;
- Op->StartLoc = S;
- Op->EndLoc = E;
- return Op;
- }
-
- static MBlazeOperand *CreateFslImm(const MCExpr *Val, SMLoc S, SMLoc E) {
- MBlazeOperand *Op = new MBlazeOperand(Fsl);
- Op->Imm.Val = Val;
- Op->StartLoc = S;
- Op->EndLoc = E;
- return Op;
- }
-
- static MBlazeOperand *CreateMem(unsigned Base, const MCExpr *Off, SMLoc S,
- SMLoc E) {
- MBlazeOperand *Op = new MBlazeOperand(Memory);
- Op->Mem.Base = Base;
- Op->Mem.Off = Off;
- Op->Mem.OffReg = 0;
- Op->StartLoc = S;
- Op->EndLoc = E;
- return Op;
- }
-
- static MBlazeOperand *CreateMem(unsigned Base, unsigned Off, SMLoc S,
- SMLoc E) {
- MBlazeOperand *Op = new MBlazeOperand(Memory);
- Op->Mem.Base = Base;
- Op->Mem.OffReg = Off;
- Op->Mem.Off = 0;
- Op->StartLoc = S;
- Op->EndLoc = E;
- return Op;
- }
-};
-
-} // end anonymous namespace.
-
-void MBlazeOperand::print(raw_ostream &OS) const {
- switch (Kind) {
- case Immediate:
- getImm()->print(OS);
- break;
- case Register:
- OS << "<register R";
- OS << getMBlazeRegisterNumbering(getReg()) << ">";
- break;
- case Token:
- OS << "'" << getToken() << "'";
- break;
- case Memory: {
- OS << "<memory R";
- OS << getMBlazeRegisterNumbering(getMemBase());
- OS << ", ";
-
- unsigned RegOff = getMemOffReg();
- if (RegOff)
- OS << "R" << getMBlazeRegisterNumbering(RegOff);
- else
- OS << getMemOff();
- OS << ">";
- }
- break;
- case Fsl:
- getFslImm()->print(OS);
- break;
- }
-}
-
-/// @name Auto-generated Match Functions
-/// {
-
-static unsigned MatchRegisterName(StringRef Name);
-
-/// }
-//
-bool MBlazeAsmParser::
-MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
- SmallVectorImpl<MCParsedAsmOperand*> &Operands,
- MCStreamer &Out, unsigned &ErrorInfo,
- bool MatchingInlineAsm) {
- MCInst Inst;
- switch (MatchInstructionImpl(Operands, Inst, ErrorInfo,
- MatchingInlineAsm)) {
- default: break;
- case Match_Success:
- Out.EmitInstruction(Inst);
- return false;
- case Match_MissingFeature:
- return Error(IDLoc, "instruction use requires an option to be enabled");
- case Match_MnemonicFail:
- return Error(IDLoc, "unrecognized instruction mnemonic");
- case Match_InvalidOperand: {
- SMLoc ErrorLoc = IDLoc;
- if (ErrorInfo != ~0U) {
- if (ErrorInfo >= Operands.size())
- return Error(IDLoc, "too few operands for instruction");
-
- ErrorLoc = ((MBlazeOperand*)Operands[ErrorInfo])->getStartLoc();
- if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
- }
-
- return Error(ErrorLoc, "invalid operand for instruction");
- }
- }
-
- llvm_unreachable("Implement any new match types added!");
-}
-
-MBlazeOperand *MBlazeAsmParser::
-ParseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
- if (Operands.size() != 4)
- return 0;
-
- MBlazeOperand &Base = *(MBlazeOperand*)Operands[2];
- MBlazeOperand &Offset = *(MBlazeOperand*)Operands[3];
-
- SMLoc S = Base.getStartLoc();
- SMLoc O = Offset.getStartLoc();
- SMLoc E = Offset.getEndLoc();
-
- if (!Base.isReg()) {
- Error(S, "base address must be a register");
- return 0;
- }
-
- if (!Offset.isReg() && !Offset.isImm()) {
- Error(O, "offset must be a register or immediate");
- return 0;
- }
-
- MBlazeOperand *Op;
- if (Offset.isReg())
- Op = MBlazeOperand::CreateMem(Base.getReg(), Offset.getReg(), S, E);
- else
- Op = MBlazeOperand::CreateMem(Base.getReg(), Offset.getImm(), S, E);
-
- delete Operands.pop_back_val();
- delete Operands.pop_back_val();
- Operands.push_back(Op);
-
- return Op;
-}
-
-bool MBlazeAsmParser::ParseRegister(unsigned &RegNo,
- SMLoc &StartLoc, SMLoc &EndLoc) {
- MBlazeOperand *Reg = ParseRegister(StartLoc, EndLoc);
- if (!Reg)
- return true;
- RegNo = Reg->getReg();
- return false;
-}
-
-MBlazeOperand *MBlazeAsmParser::ParseRegister() {
- SMLoc S, E;
- return ParseRegister(S, E);
-}
-
-MBlazeOperand *MBlazeAsmParser::ParseRegister(SMLoc &StartLoc, SMLoc &EndLoc) {
- StartLoc = Parser.getTok().getLoc();
- EndLoc = Parser.getTok().getEndLoc();
-
- if (getLexer().getKind() != AsmToken::Identifier)
- return 0;
-
- unsigned RegNo = MatchRegisterName(getLexer().getTok().getIdentifier());
- if (RegNo == 0)
- return 0;
-
- getLexer().Lex();
- return MBlazeOperand::CreateReg(RegNo, StartLoc, EndLoc);
-}
-
-static unsigned MatchFslRegister(StringRef String) {
- if (!String.startswith("rfsl"))
- return -1;
-
- unsigned regNum;
- if (String.substr(4).getAsInteger(10,regNum))
- return -1;
-
- return regNum;
-}
-
-MBlazeOperand *MBlazeAsmParser::ParseFsl() {
- SMLoc S = Parser.getTok().getLoc();
- SMLoc E = Parser.getTok().getEndLoc();
-
- switch (getLexer().getKind()) {
- default: return 0;
- case AsmToken::Identifier:
- unsigned reg = MatchFslRegister(getLexer().getTok().getIdentifier());
- if (reg >= 16)
- return 0;
-
- getLexer().Lex();
- const MCExpr *EVal = MCConstantExpr::Create(reg,getContext());
- return MBlazeOperand::CreateFslImm(EVal,S,E);
- }
-}
-
-MBlazeOperand *MBlazeAsmParser::ParseImmediate() {
- SMLoc S = Parser.getTok().getLoc();
- SMLoc E = Parser.getTok().getEndLoc();
-
- const MCExpr *EVal;
- switch (getLexer().getKind()) {
- default: return 0;
- case AsmToken::LParen:
- case AsmToken::Plus:
- case AsmToken::Minus:
- case AsmToken::Integer:
- case AsmToken::Identifier:
- if (getParser().parseExpression(EVal))
- return 0;
-
- return MBlazeOperand::CreateImm(EVal, S, E);
- }
-}
-
-MBlazeOperand *MBlazeAsmParser::
-ParseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
- MBlazeOperand *Op;
-
- // Attempt to parse the next token as a register name
- Op = ParseRegister();
-
- // Attempt to parse the next token as an FSL immediate
- if (!Op)
- Op = ParseFsl();
-
- // Attempt to parse the next token as an immediate
- if (!Op)
- Op = ParseImmediate();
-
- // If the token could not be parsed then fail
- if (!Op) {
- Error(Parser.getTok().getLoc(), "unknown operand");
- return 0;
- }
-
- // Push the parsed operand into the list of operands
- Operands.push_back(Op);
- return Op;
-}
-
-/// Parse an mblaze instruction mnemonic followed by its operands.
-bool MBlazeAsmParser::
-ParseInstruction(ParseInstructionInfo &Info, StringRef Name, SMLoc NameLoc,
- SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
- // The first operands is the token for the instruction name
- size_t dotLoc = Name.find('.');
- Operands.push_back(MBlazeOperand::CreateToken(Name.substr(0,dotLoc),NameLoc));
- if (dotLoc < Name.size())
- Operands.push_back(MBlazeOperand::CreateToken(Name.substr(dotLoc),NameLoc));
-
- // If there are no more operands then finish
- if (getLexer().is(AsmToken::EndOfStatement))
- return false;
-
- // Parse the first operand
- if (!ParseOperand(Operands))
- return true;
-
- while (getLexer().isNot(AsmToken::EndOfStatement) &&
- getLexer().is(AsmToken::Comma)) {
- // Consume the comma token
- getLexer().Lex();
-
- // Parse the next operand
- if (!ParseOperand(Operands))
- return true;
- }
-
- // If the instruction requires a memory operand then we need to
- // replace the last two operands (base+offset) with a single
- // memory operand.
- if (Name.startswith("lw") || Name.startswith("sw") ||
- Name.startswith("lh") || Name.startswith("sh") ||
- Name.startswith("lb") || Name.startswith("sb"))
- return (ParseMemory(Operands) == NULL);
-
- return false;
-}
-
-/// ParseDirective parses the MBlaze specific directives
-bool MBlazeAsmParser::ParseDirective(AsmToken DirectiveID) {
- StringRef IDVal = DirectiveID.getIdentifier();
- if (IDVal == ".word")
- return ParseDirectiveWord(2, DirectiveID.getLoc());
- return true;
-}
-
-/// ParseDirectiveWord
-/// ::= .word [ expression (, expression)* ]
-bool MBlazeAsmParser::ParseDirectiveWord(unsigned Size, SMLoc L) {
- if (getLexer().isNot(AsmToken::EndOfStatement)) {
- for (;;) {
- const MCExpr *Value;
- if (getParser().parseExpression(Value))
- return true;
-
- getParser().getStreamer().EmitValue(Value, Size);
-
- if (getLexer().is(AsmToken::EndOfStatement))
- break;
-
- // FIXME: Improve diagnostic.
- if (getLexer().isNot(AsmToken::Comma))
- return Error(L, "unexpected token in directive");
- Parser.Lex();
- }
- }
-
- Parser.Lex();
- return false;
-}
-
-/// Force static initialization.
-extern "C" void LLVMInitializeMBlazeAsmParser() {
- RegisterMCAsmParser<MBlazeAsmParser> X(TheMBlazeTarget);
-}
-
-#define GET_REGISTER_MATCHER
-#define GET_MATCHER_IMPLEMENTATION
-#include "MBlazeGenAsmMatcher.inc"
OpenPOWER on IntegriCloud