1 //===-- SystemZAsmParser.cpp - Parse SystemZ assembly instructions --------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "MCTargetDesc/SystemZMCTargetDesc.h"
11 #include "llvm/MC/MCContext.h"
12 #include "llvm/MC/MCExpr.h"
13 #include "llvm/MC/MCInst.h"
14 #include "llvm/MC/MCParser/MCParsedAsmOperand.h"
15 #include "llvm/MC/MCStreamer.h"
16 #include "llvm/MC/MCSubtargetInfo.h"
17 #include "llvm/MC/MCTargetAsmParser.h"
18 #include "llvm/Support/TargetRegistry.h"
22 // Return true if Expr is in the range [MinValue, MaxValue].
23 static bool inRange(const MCExpr *Expr, int64_t MinValue, int64_t MaxValue) {
24 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr)) {
25 int64_t Value = CE->getValue();
26 return Value >= MinValue && Value <= MaxValue;
32 class SystemZOperand : public MCParsedAsmOperand {
56 SMLoc StartLoc, EndLoc;
58 // A string of length Length, starting at Data.
64 // LLVM register Num, which has kind Kind. In some ways it might be
65 // easier for this class to have a register bank (general, floating-point
66 // or access) and a raw register number (0-15). This would postpone the
67 // interpretation of the operand to the add*() methods and avoid the need
68 // for context-dependent parsing. However, we do things the current way
69 // because of the virtual getReg() method, which needs to distinguish
70 // between (say) %r0 used as a single register and %r0 used as a pair.
71 // Context-dependent parsing can also give us slightly better error
72 // messages when invalid pairs like %r1 are used.
78 // Base + Disp + Index, where Base and Index are LLVM registers or 0.
79 // RegKind says what type the registers have (ADDR32Reg or ADDR64Reg).
96 SystemZOperand(OperandKind kind, SMLoc startLoc, SMLoc endLoc)
97 : Kind(kind), StartLoc(startLoc), EndLoc(endLoc)
100 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
101 // Add as immediates when possible. Null MCExpr = 0.
103 Inst.addOperand(MCOperand::CreateImm(0));
104 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
105 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
107 Inst.addOperand(MCOperand::CreateExpr(Expr));
111 // Create particular kinds of operand.
112 static SystemZOperand *createInvalid(SMLoc StartLoc, SMLoc EndLoc) {
113 return new SystemZOperand(KindInvalid, StartLoc, EndLoc);
115 static SystemZOperand *createToken(StringRef Str, SMLoc Loc) {
116 SystemZOperand *Op = new SystemZOperand(KindToken, Loc, Loc);
117 Op->Token.Data = Str.data();
118 Op->Token.Length = Str.size();
121 static SystemZOperand *createReg(RegisterKind Kind, unsigned Num,
122 SMLoc StartLoc, SMLoc EndLoc) {
123 SystemZOperand *Op = new SystemZOperand(KindReg, StartLoc, EndLoc);
128 static SystemZOperand *createAccessReg(unsigned Num, SMLoc StartLoc,
130 SystemZOperand *Op = new SystemZOperand(KindAccessReg, StartLoc, EndLoc);
134 static SystemZOperand *createImm(const MCExpr *Expr, SMLoc StartLoc,
136 SystemZOperand *Op = new SystemZOperand(KindImm, StartLoc, EndLoc);
140 static SystemZOperand *createMem(RegisterKind RegKind, unsigned Base,
141 const MCExpr *Disp, unsigned Index,
142 SMLoc StartLoc, SMLoc EndLoc) {
143 SystemZOperand *Op = new SystemZOperand(KindMem, StartLoc, EndLoc);
144 Op->Mem.RegKind = RegKind;
146 Op->Mem.Index = Index;
152 virtual bool isToken() const LLVM_OVERRIDE {
153 return Kind == KindToken;
155 StringRef getToken() const {
156 assert(Kind == KindToken && "Not a token");
157 return StringRef(Token.Data, Token.Length);
160 // Register operands.
161 virtual bool isReg() const LLVM_OVERRIDE {
162 return Kind == KindReg;
164 bool isReg(RegisterKind RegKind) const {
165 return Kind == KindReg && Reg.Kind == RegKind;
167 virtual unsigned getReg() const LLVM_OVERRIDE {
168 assert(Kind == KindReg && "Not a register");
172 // Access register operands. Access registers aren't exposed to LLVM
174 bool isAccessReg() const {
175 return Kind == KindAccessReg;
178 // Immediate operands.
179 virtual bool isImm() const LLVM_OVERRIDE {
180 return Kind == KindImm;
182 bool isImm(int64_t MinValue, int64_t MaxValue) const {
183 return Kind == KindImm && inRange(Imm, MinValue, MaxValue);
185 const MCExpr *getImm() const {
186 assert(Kind == KindImm && "Not an immediate");
191 virtual bool isMem() const LLVM_OVERRIDE {
192 return Kind == KindMem;
194 bool isMem(RegisterKind RegKind, bool HasIndex) const {
195 return (Kind == KindMem &&
196 Mem.RegKind == RegKind &&
197 (HasIndex || !Mem.Index));
199 bool isMemDisp12(RegisterKind RegKind, bool HasIndex) const {
200 return isMem(RegKind, HasIndex) && inRange(Mem.Disp, 0, 0xfff);
202 bool isMemDisp20(RegisterKind RegKind, bool HasIndex) const {
203 return isMem(RegKind, HasIndex) && inRange(Mem.Disp, -524288, 524287);
206 // Override MCParsedAsmOperand.
207 virtual SMLoc getStartLoc() const LLVM_OVERRIDE { return StartLoc; }
208 virtual SMLoc getEndLoc() const LLVM_OVERRIDE { return EndLoc; }
209 virtual void print(raw_ostream &OS) const LLVM_OVERRIDE;
211 // Used by the TableGen code to add particular types of operand
212 // to an instruction.
213 void addRegOperands(MCInst &Inst, unsigned N) const {
214 assert(N == 1 && "Invalid number of operands");
215 Inst.addOperand(MCOperand::CreateReg(getReg()));
217 void addAccessRegOperands(MCInst &Inst, unsigned N) const {
218 assert(N == 1 && "Invalid number of operands");
219 assert(Kind == KindAccessReg && "Invalid operand type");
220 Inst.addOperand(MCOperand::CreateImm(AccessReg));
222 void addImmOperands(MCInst &Inst, unsigned N) const {
223 assert(N == 1 && "Invalid number of operands");
224 addExpr(Inst, getImm());
226 void addBDAddrOperands(MCInst &Inst, unsigned N) const {
227 assert(N == 2 && "Invalid number of operands");
228 assert(Kind == KindMem && Mem.Index == 0 && "Invalid operand type");
229 Inst.addOperand(MCOperand::CreateReg(Mem.Base));
230 addExpr(Inst, Mem.Disp);
232 void addBDXAddrOperands(MCInst &Inst, unsigned N) const {
233 assert(N == 3 && "Invalid number of operands");
234 assert(Kind == KindMem && "Invalid operand type");
235 Inst.addOperand(MCOperand::CreateReg(Mem.Base));
236 addExpr(Inst, Mem.Disp);
237 Inst.addOperand(MCOperand::CreateReg(Mem.Index));
240 // Used by the TableGen code to check for particular operand types.
241 bool isGR32() const { return isReg(GR32Reg); }
242 bool isGR64() const { return isReg(GR64Reg); }
243 bool isGR128() const { return isReg(GR128Reg); }
244 bool isADDR32() const { return isReg(ADDR32Reg); }
245 bool isADDR64() const { return isReg(ADDR64Reg); }
246 bool isADDR128() const { return false; }
247 bool isFP32() const { return isReg(FP32Reg); }
248 bool isFP64() const { return isReg(FP64Reg); }
249 bool isFP128() const { return isReg(FP128Reg); }
250 bool isBDAddr32Disp12() const { return isMemDisp12(ADDR32Reg, false); }
251 bool isBDAddr32Disp20() const { return isMemDisp20(ADDR32Reg, false); }
252 bool isBDAddr64Disp12() const { return isMemDisp12(ADDR64Reg, false); }
253 bool isBDAddr64Disp20() const { return isMemDisp20(ADDR64Reg, false); }
254 bool isBDXAddr64Disp12() const { return isMemDisp12(ADDR64Reg, true); }
255 bool isBDXAddr64Disp20() const { return isMemDisp20(ADDR64Reg, true); }
256 bool isU4Imm() const { return isImm(0, 15); }
257 bool isU6Imm() const { return isImm(0, 63); }
258 bool isU8Imm() const { return isImm(0, 255); }
259 bool isS8Imm() const { return isImm(-128, 127); }
260 bool isU16Imm() const { return isImm(0, 65535); }
261 bool isS16Imm() const { return isImm(-32768, 32767); }
262 bool isU32Imm() const { return isImm(0, (1LL << 32) - 1); }
263 bool isS32Imm() const { return isImm(-(1LL << 31), (1LL << 31) - 1); }
266 class SystemZAsmParser : public MCTargetAsmParser {
267 #define GET_ASSEMBLER_HEADER
268 #include "SystemZGenAsmMatcher.inc"
271 MCSubtargetInfo &STI;
281 SMLoc StartLoc, EndLoc;
284 bool parseRegister(Register &Reg);
286 bool parseRegister(Register &Reg, RegisterGroup Group, const unsigned *Regs,
287 bool IsAddress = false);
290 parseRegister(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
291 RegisterGroup Group, const unsigned *Regs,
292 SystemZOperand::RegisterKind Kind,
293 bool IsAddress = false);
295 bool parseAddress(unsigned &Base, const MCExpr *&Disp,
296 unsigned &Index, const unsigned *Regs,
297 SystemZOperand::RegisterKind RegKind,
301 parseAddress(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
302 const unsigned *Regs, SystemZOperand::RegisterKind RegKind,
305 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
309 SystemZAsmParser(MCSubtargetInfo &sti, MCAsmParser &parser)
310 : MCTargetAsmParser(), STI(sti), Parser(parser) {
311 MCAsmParserExtension::Initialize(Parser);
313 // Initialize the set of available features.
314 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
317 // Override MCTargetAsmParser.
318 virtual bool ParseDirective(AsmToken DirectiveID) LLVM_OVERRIDE;
319 virtual bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc,
320 SMLoc &EndLoc) LLVM_OVERRIDE;
321 virtual bool ParseInstruction(ParseInstructionInfo &Info,
322 StringRef Name, SMLoc NameLoc,
323 SmallVectorImpl<MCParsedAsmOperand*> &Operands)
326 MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
327 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
328 MCStreamer &Out, unsigned &ErrorInfo,
329 bool MatchingInlineAsm) LLVM_OVERRIDE;
331 // Used by the TableGen code to parse particular operand types.
333 parseGR32(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
334 return parseRegister(Operands, RegGR, SystemZMC::GR32Regs,
335 SystemZOperand::GR32Reg);
338 parseGR64(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
339 return parseRegister(Operands, RegGR, SystemZMC::GR64Regs,
340 SystemZOperand::GR64Reg);
343 parseGR128(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
344 return parseRegister(Operands, RegGR, SystemZMC::GR128Regs,
345 SystemZOperand::GR128Reg);
348 parseADDR32(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
349 return parseRegister(Operands, RegGR, SystemZMC::GR32Regs,
350 SystemZOperand::ADDR32Reg, true);
353 parseADDR64(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
354 return parseRegister(Operands, RegGR, SystemZMC::GR64Regs,
355 SystemZOperand::ADDR64Reg, true);
358 parseADDR128(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
359 llvm_unreachable("Shouldn't be used as an operand");
362 parseFP32(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
363 return parseRegister(Operands, RegFP, SystemZMC::FP32Regs,
364 SystemZOperand::FP32Reg);
367 parseFP64(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
368 return parseRegister(Operands, RegFP, SystemZMC::FP64Regs,
369 SystemZOperand::FP64Reg);
372 parseFP128(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
373 return parseRegister(Operands, RegFP, SystemZMC::FP128Regs,
374 SystemZOperand::FP128Reg);
377 parseBDAddr32(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
378 return parseAddress(Operands, SystemZMC::GR32Regs,
379 SystemZOperand::ADDR32Reg, false);
382 parseBDAddr64(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
383 return parseAddress(Operands, SystemZMC::GR64Regs,
384 SystemZOperand::ADDR64Reg, false);
387 parseBDXAddr64(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
388 return parseAddress(Operands, SystemZMC::GR64Regs,
389 SystemZOperand::ADDR64Reg, true);
392 parseAccessReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands);
394 parsePCRel(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
395 int64_t MinVal, int64_t MaxVal);
397 parsePCRel16(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
398 return parsePCRel(Operands, -(1LL << 16), (1LL << 16) - 1);
401 parsePCRel32(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
402 return parsePCRel(Operands, -(1LL << 32), (1LL << 32) - 1);
407 #define GET_REGISTER_MATCHER
408 #define GET_SUBTARGET_FEATURE_NAME
409 #define GET_MATCHER_IMPLEMENTATION
410 #include "SystemZGenAsmMatcher.inc"
412 void SystemZOperand::print(raw_ostream &OS) const {
413 llvm_unreachable("Not implemented");
416 // Parse one register of the form %<prefix><number>.
417 bool SystemZAsmParser::parseRegister(Register &Reg) {
418 Reg.StartLoc = Parser.getTok().getLoc();
421 if (Parser.getTok().isNot(AsmToken::Percent))
422 return Error(Parser.getTok().getLoc(), "register expected");
425 // Expect a register name.
426 if (Parser.getTok().isNot(AsmToken::Identifier))
427 return Error(Reg.StartLoc, "invalid register");
429 // Check that there's a prefix.
430 StringRef Name = Parser.getTok().getString();
432 return Error(Reg.StartLoc, "invalid register");
433 char Prefix = Name[0];
435 // Treat the rest of the register name as a register number.
436 if (Name.substr(1).getAsInteger(10, Reg.Num))
437 return Error(Reg.StartLoc, "invalid register");
439 // Look for valid combinations of prefix and number.
440 if (Prefix == 'r' && Reg.Num < 16)
442 else if (Prefix == 'f' && Reg.Num < 16)
444 else if (Prefix == 'a' && Reg.Num < 16)
445 Reg.Group = RegAccess;
447 return Error(Reg.StartLoc, "invalid register");
449 Reg.EndLoc = Parser.getTok().getLoc();
454 // Parse a register of group Group. If Regs is nonnull, use it to map
455 // the raw register number to LLVM numbering, with zero entries indicating
456 // an invalid register. IsAddress says whether the register appears in an
458 bool SystemZAsmParser::parseRegister(Register &Reg, RegisterGroup Group,
459 const unsigned *Regs, bool IsAddress) {
460 if (parseRegister(Reg))
462 if (Reg.Group != Group)
463 return Error(Reg.StartLoc, "invalid operand for instruction");
464 if (Regs && Regs[Reg.Num] == 0)
465 return Error(Reg.StartLoc, "invalid register pair");
466 if (Reg.Num == 0 && IsAddress)
467 return Error(Reg.StartLoc, "%r0 used in an address");
469 Reg.Num = Regs[Reg.Num];
473 // Parse a register and add it to Operands. The other arguments are as above.
474 SystemZAsmParser::OperandMatchResultTy
475 SystemZAsmParser::parseRegister(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
476 RegisterGroup Group, const unsigned *Regs,
477 SystemZOperand::RegisterKind Kind,
479 if (Parser.getTok().isNot(AsmToken::Percent))
480 return MatchOperand_NoMatch;
483 if (parseRegister(Reg, Group, Regs, IsAddress))
484 return MatchOperand_ParseFail;
486 Operands.push_back(SystemZOperand::createReg(Kind, Reg.Num,
487 Reg.StartLoc, Reg.EndLoc));
488 return MatchOperand_Success;
491 // Parse a memory operand into Base, Disp and Index. Regs maps asm
492 // register numbers to LLVM register numbers and RegKind says what kind
493 // of address register we're using (ADDR32Reg or ADDR64Reg). HasIndex
494 // says whether the address allows index registers.
495 bool SystemZAsmParser::parseAddress(unsigned &Base, const MCExpr *&Disp,
496 unsigned &Index, const unsigned *Regs,
497 SystemZOperand::RegisterKind RegKind,
499 // Parse the displacement, which must always be present.
500 if (getParser().parseExpression(Disp))
503 // Parse the optional base and index.
506 if (getLexer().is(AsmToken::LParen)) {
509 // Parse the first register.
511 if (parseRegister(Reg, RegGR, Regs, RegKind))
514 // Check whether there's a second register. If so, the one that we
515 // just parsed was the index.
516 if (getLexer().is(AsmToken::Comma)) {
520 return Error(Reg.StartLoc, "invalid use of indexed addressing");
523 if (parseRegister(Reg, RegGR, Regs, RegKind))
528 // Consume the closing bracket.
529 if (getLexer().isNot(AsmToken::RParen))
530 return Error(Parser.getTok().getLoc(), "unexpected token in address");
536 // Parse a memory operand and add it to Operands. The other arguments
538 SystemZAsmParser::OperandMatchResultTy
539 SystemZAsmParser::parseAddress(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
540 const unsigned *Regs,
541 SystemZOperand::RegisterKind RegKind,
543 SMLoc StartLoc = Parser.getTok().getLoc();
544 unsigned Base, Index;
546 if (parseAddress(Base, Disp, Index, Regs, RegKind, HasIndex))
547 return MatchOperand_ParseFail;
550 SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
551 Operands.push_back(SystemZOperand::createMem(RegKind, Base, Disp, Index,
553 return MatchOperand_Success;
556 bool SystemZAsmParser::ParseDirective(AsmToken DirectiveID) {
560 bool SystemZAsmParser::ParseRegister(unsigned &RegNo, SMLoc &StartLoc,
563 if (parseRegister(Reg))
565 if (Reg.Group == RegGR)
566 RegNo = SystemZMC::GR64Regs[Reg.Num];
567 else if (Reg.Group == RegFP)
568 RegNo = SystemZMC::FP64Regs[Reg.Num];
570 // FIXME: Access registers aren't modelled as LLVM registers yet.
571 return Error(Reg.StartLoc, "invalid operand for instruction");
572 StartLoc = Reg.StartLoc;
577 bool SystemZAsmParser::
578 ParseInstruction(ParseInstructionInfo &Info, StringRef Name, SMLoc NameLoc,
579 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
580 Operands.push_back(SystemZOperand::createToken(Name, NameLoc));
582 // Read the remaining operands.
583 if (getLexer().isNot(AsmToken::EndOfStatement)) {
584 // Read the first operand.
585 if (parseOperand(Operands, Name)) {
586 Parser.eatToEndOfStatement();
590 // Read any subsequent operands.
591 while (getLexer().is(AsmToken::Comma)) {
593 if (parseOperand(Operands, Name)) {
594 Parser.eatToEndOfStatement();
598 if (getLexer().isNot(AsmToken::EndOfStatement)) {
599 SMLoc Loc = getLexer().getLoc();
600 Parser.eatToEndOfStatement();
601 return Error(Loc, "unexpected token in argument list");
605 // Consume the EndOfStatement.
610 bool SystemZAsmParser::
611 parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
612 StringRef Mnemonic) {
613 // Check if the current operand has a custom associated parser, if so, try to
614 // custom parse the operand, or fallback to the general approach.
615 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
616 if (ResTy == MatchOperand_Success)
619 // If there wasn't a custom match, try the generic matcher below. Otherwise,
620 // there was a match, but an error occurred, in which case, just return that
621 // the operand parsing failed.
622 if (ResTy == MatchOperand_ParseFail)
625 // Check for a register. All real register operands should have used
626 // a context-dependent parse routine, which gives the required register
627 // class. The code is here to mop up other cases, like those where
628 // the instruction isn't recognized.
629 if (Parser.getTok().is(AsmToken::Percent)) {
631 if (parseRegister(Reg))
633 Operands.push_back(SystemZOperand::createInvalid(Reg.StartLoc, Reg.EndLoc));
637 // The only other type of operand is an immediate or address. As above,
638 // real address operands should have used a context-dependent parse routine,
639 // so we treat any plain expression as an immediate.
640 SMLoc StartLoc = Parser.getTok().getLoc();
641 unsigned Base, Index;
643 if (parseAddress(Base, Expr, Index, SystemZMC::GR64Regs,
644 SystemZOperand::ADDR64Reg, true))
648 SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
650 Operands.push_back(SystemZOperand::createInvalid(StartLoc, EndLoc));
652 Operands.push_back(SystemZOperand::createImm(Expr, StartLoc, EndLoc));
656 bool SystemZAsmParser::
657 MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
658 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
659 MCStreamer &Out, unsigned &ErrorInfo,
660 bool MatchingInlineAsm) {
662 unsigned MatchResult;
664 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
666 switch (MatchResult) {
670 Out.EmitInstruction(Inst);
673 case Match_MissingFeature: {
674 assert(ErrorInfo && "Unknown missing feature!");
675 // Special case the error message for the very common case where only
676 // a single subtarget feature is missing
677 std::string Msg = "instruction requires:";
679 for (unsigned I = 0; I < sizeof(ErrorInfo) * 8 - 1; ++I) {
680 if (ErrorInfo & Mask) {
682 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
686 return Error(IDLoc, Msg);
689 case Match_InvalidOperand: {
690 SMLoc ErrorLoc = IDLoc;
691 if (ErrorInfo != ~0U) {
692 if (ErrorInfo >= Operands.size())
693 return Error(IDLoc, "too few operands for instruction");
695 ErrorLoc = ((SystemZOperand*)Operands[ErrorInfo])->getStartLoc();
696 if (ErrorLoc == SMLoc())
699 return Error(ErrorLoc, "invalid operand for instruction");
702 case Match_MnemonicFail:
703 return Error(IDLoc, "invalid instruction");
706 llvm_unreachable("Unexpected match type");
709 SystemZAsmParser::OperandMatchResultTy SystemZAsmParser::
710 parseAccessReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
711 if (Parser.getTok().isNot(AsmToken::Percent))
712 return MatchOperand_NoMatch;
715 if (parseRegister(Reg, RegAccess, 0))
716 return MatchOperand_ParseFail;
718 Operands.push_back(SystemZOperand::createAccessReg(Reg.Num,
721 return MatchOperand_Success;
724 SystemZAsmParser::OperandMatchResultTy SystemZAsmParser::
725 parsePCRel(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
726 int64_t MinVal, int64_t MaxVal) {
727 MCContext &Ctx = getContext();
728 MCStreamer &Out = getStreamer();
730 SMLoc StartLoc = Parser.getTok().getLoc();
731 if (getParser().parseExpression(Expr))
732 return MatchOperand_NoMatch;
734 // For consistency with the GNU assembler, treat immediates as offsets
736 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr)) {
737 int64_t Value = CE->getValue();
738 if ((Value & 1) || Value < MinVal || Value > MaxVal) {
739 Error(StartLoc, "offset out of range");
740 return MatchOperand_ParseFail;
742 MCSymbol *Sym = Ctx.CreateTempSymbol();
744 const MCExpr *Base = MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_None,
746 Expr = Value == 0 ? Base : MCBinaryExpr::CreateAdd(Base, Expr, Ctx);
750 SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
751 Operands.push_back(SystemZOperand::createImm(Expr, StartLoc, EndLoc));
752 return MatchOperand_Success;
755 // Force static initialization.
756 extern "C" void LLVMInitializeSystemZAsmParser() {
757 RegisterMCAsmParser<SystemZAsmParser> X(TheSystemZTarget);