Deleted Added
full compact
X86AsmParser.cpp (207618) X86AsmParser.cpp (207631)
1//===-- X86AsmParser.cpp - Parse X86 assembly to MCInst instructions ------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//

--- 37 unchanged lines hidden (view full) ---

46 X86Operand *ParseOperand();
47 X86Operand *ParseMemOperand(unsigned SegReg, SMLoc StartLoc);
48
49 bool ParseDirectiveWord(unsigned Size, SMLoc L);
50
51 void InstructionCleanup(MCInst &Inst);
52
53 /// @name Auto-generated Match Functions
1//===-- X86AsmParser.cpp - Parse X86 assembly to MCInst instructions ------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//

--- 37 unchanged lines hidden (view full) ---

46 X86Operand *ParseOperand();
47 X86Operand *ParseMemOperand(unsigned SegReg, SMLoc StartLoc);
48
49 bool ParseDirectiveWord(unsigned Size, SMLoc L);
50
51 void InstructionCleanup(MCInst &Inst);
52
53 /// @name Auto-generated Match Functions
54 /// {
54 /// {
55
56 bool MatchInstruction(const SmallVectorImpl<MCParsedAsmOperand*> &Operands,
57 MCInst &Inst);
58
55
56 bool MatchInstruction(const SmallVectorImpl<MCParsedAsmOperand*> &Operands,
57 MCInst &Inst);
58
59 bool MatchInstructionImpl(
60 const SmallVectorImpl<MCParsedAsmOperand*> &Operands, MCInst &Inst);
61
59 /// }
60
61public:
62 X86ATTAsmParser(const Target &T, MCAsmParser &_Parser)
63 : TargetAsmParser(T), Parser(_Parser) {}
64
65 virtual bool ParseInstruction(const StringRef &Name, SMLoc NameLoc,
66 SmallVectorImpl<MCParsedAsmOperand*> &Operands);

--- 60 unchanged lines hidden (view full) ---

127 unsigned BaseReg;
128 unsigned IndexReg;
129 unsigned Scale;
130 } Mem;
131 };
132
133 X86Operand(KindTy K, SMLoc Start, SMLoc End)
134 : Kind(K), StartLoc(Start), EndLoc(End) {}
62 /// }
63
64public:
65 X86ATTAsmParser(const Target &T, MCAsmParser &_Parser)
66 : TargetAsmParser(T), Parser(_Parser) {}
67
68 virtual bool ParseInstruction(const StringRef &Name, SMLoc NameLoc,
69 SmallVectorImpl<MCParsedAsmOperand*> &Operands);

--- 60 unchanged lines hidden (view full) ---

130 unsigned BaseReg;
131 unsigned IndexReg;
132 unsigned Scale;
133 } Mem;
134 };
135
136 X86Operand(KindTy K, SMLoc Start, SMLoc End)
137 : Kind(K), StartLoc(Start), EndLoc(End) {}
135
138
136 /// getStartLoc - Get the location of the first token of this operand.
137 SMLoc getStartLoc() const { return StartLoc; }
138 /// getEndLoc - Get the location of the last token of this operand.
139 SMLoc getEndLoc() const { return EndLoc; }
140
141 StringRef getToken() const {
142 assert(Kind == Token && "Invalid access!");
143 return StringRef(Tok.Data, Tok.Length);
144 }
139 /// getStartLoc - Get the location of the first token of this operand.
140 SMLoc getStartLoc() const { return StartLoc; }
141 /// getEndLoc - Get the location of the last token of this operand.
142 SMLoc getEndLoc() const { return EndLoc; }
143
144 StringRef getToken() const {
145 assert(Kind == Token && "Invalid access!");
146 return StringRef(Tok.Data, Tok.Length);
147 }
148 void setTokenValue(StringRef Value) {
149 assert(Kind == Token && "Invalid access!");
150 Tok.Data = Value.data();
151 Tok.Length = Value.size();
152 }
145
146 unsigned getReg() const {
147 assert(Kind == Register && "Invalid access!");
148 return Reg.RegNo;
149 }
150
151 const MCExpr *getImm() const {
152 assert(Kind == Immediate && "Invalid access!");

--- 474 unchanged lines hidden (view full) ---

627 case X86::DEC32m: Inst.setOpcode(X86::DEC64_32m); break;
628 case X86::INC16r: Inst.setOpcode(X86::INC64_16r); break;
629 case X86::INC16m: Inst.setOpcode(X86::INC64_16m); break;
630 case X86::INC32r: Inst.setOpcode(X86::INC64_32r); break;
631 case X86::INC32m: Inst.setOpcode(X86::INC64_32m); break;
632 }
633}
634
153
154 unsigned getReg() const {
155 assert(Kind == Register && "Invalid access!");
156 return Reg.RegNo;
157 }
158
159 const MCExpr *getImm() const {
160 assert(Kind == Immediate && "Invalid access!");

--- 474 unchanged lines hidden (view full) ---

635 case X86::DEC32m: Inst.setOpcode(X86::DEC64_32m); break;
636 case X86::INC16r: Inst.setOpcode(X86::INC64_16r); break;
637 case X86::INC16m: Inst.setOpcode(X86::INC64_16m); break;
638 case X86::INC32r: Inst.setOpcode(X86::INC64_32r); break;
639 case X86::INC32m: Inst.setOpcode(X86::INC64_32m); break;
640 }
641}
642
643bool
644X86ATTAsmParser::MatchInstruction(const SmallVectorImpl<MCParsedAsmOperand*>
645 &Operands,
646 MCInst &Inst) {
647 // First, try a direct match.
648 if (!MatchInstructionImpl(Operands, Inst))
649 return false;
650
651 // Ignore anything which is obviously not a suffix match.
652 if (Operands.size() == 0)
653 return true;
654 X86Operand *Op = static_cast<X86Operand*>(Operands[0]);
655 if (!Op->isToken() || Op->getToken().size() > 15)
656 return true;
657
658 // FIXME: Ideally, we would only attempt suffix matches for things which are
659 // valid prefixes, and we could just infer the right unambiguous
660 // type. However, that requires substantially more matcher support than the
661 // following hack.
662
663 // Change the operand to point to a temporary token.
664 char Tmp[16];
665 StringRef Base = Op->getToken();
666 memcpy(Tmp, Base.data(), Base.size());
667 Op->setTokenValue(StringRef(Tmp, Base.size() + 1));
668
669 // Check for the various suffix matches.
670 Tmp[Base.size()] = 'b';
671 bool MatchB = MatchInstructionImpl(Operands, Inst);
672 Tmp[Base.size()] = 'w';
673 bool MatchW = MatchInstructionImpl(Operands, Inst);
674 Tmp[Base.size()] = 'l';
675 bool MatchL = MatchInstructionImpl(Operands, Inst);
676
677 // Restore the old token.
678 Op->setTokenValue(Base);
679
680 // If exactly one matched, then we treat that as a successful match (and the
681 // instruction will already have been filled in correctly, since the failing
682 // matches won't have modified it).
683 if (MatchB + MatchW + MatchL == 2)
684 return false;
685
686 // Otherwise, the match failed.
687 return true;
688}
689
690
635extern "C" void LLVMInitializeX86AsmLexer();
636
637// Force static initialization.
638extern "C" void LLVMInitializeX86AsmParser() {
639 RegisterAsmParser<X86_32ATTAsmParser> X(TheX86_32Target);
640 RegisterAsmParser<X86_64ATTAsmParser> Y(TheX86_64Target);
641 LLVMInitializeX86AsmLexer();
642}
643
644#include "X86GenAsmMatcher.inc"
691extern "C" void LLVMInitializeX86AsmLexer();
692
693// Force static initialization.
694extern "C" void LLVMInitializeX86AsmParser() {
695 RegisterAsmParser<X86_32ATTAsmParser> X(TheX86_32Target);
696 RegisterAsmParser<X86_64ATTAsmParser> Y(TheX86_64Target);
697 LLVMInitializeX86AsmLexer();
698}
699
700#include "X86GenAsmMatcher.inc"