bool SparcAsmParser::matchSparcAsmModifiers(const MCExpr *&EVal, SMLoc &EndLoc) { AsmToken Tok = Parser.getTok(); if (!Tok.is(AsmToken::Identifier)) return false; StringRef name = Tok.getString(); SparcMCExpr::VariantKind VK = SparcMCExpr::parseVariantKind(name); if (VK == SparcMCExpr::VK_Sparc_None) return false; Parser.Lex(); // Eat the identifier. if (Parser.getTok().getKind() != AsmToken::LParen) return false; Parser.Lex(); // Eat the LParen token. const MCExpr *subExpr; if (Parser.parseParenExpression(subExpr, EndLoc)) return false; EVal = SparcMCExpr::Create(VK, subExpr, getContext()); return true; }
size_t AsmLexer::peekTokens(MutableArrayRef<AsmToken> Buf, bool ShouldSkipSpace) { const char *SavedTokStart = TokStart; const char *SavedCurPtr = CurPtr; bool SavedAtStartOfLine = IsAtStartOfLine; bool SavedAtStartOfStatement = IsAtStartOfStatement; bool SavedSkipSpace = SkipSpace; std::string SavedErr = getErr(); SMLoc SavedErrLoc = getErrLoc(); SkipSpace = ShouldSkipSpace; size_t ReadCount; for (ReadCount = 0; ReadCount < Buf.size(); ++ReadCount) { AsmToken Token = LexToken(); Buf[ReadCount] = Token; if (Token.is(AsmToken::Eof)) break; } SetError(SavedErrLoc, SavedErr); SkipSpace = SavedSkipSpace; IsAtStartOfLine = SavedAtStartOfLine; IsAtStartOfStatement = SavedAtStartOfStatement; CurPtr = SavedCurPtr; TokStart = SavedTokStart; return ReadCount; }
bool PPCAsmParser:: MatchRegisterName(const AsmToken &Tok, unsigned &RegNo, int64_t &IntVal) { if (Tok.is(AsmToken::Identifier)) { StringRef Name = Tok.getString().lower(); if (Name == "lr") { RegNo = isPPC64()? PPC::LR8 : PPC::LR; IntVal = 8; return false; } else if (Name == "ctr") { RegNo = isPPC64()? PPC::CTR8 : PPC::CTR; IntVal = 9; return false; } else if (Name.startswith("r") && !Name.substr(1).getAsInteger(10, IntVal) && IntVal < 32) { RegNo = isPPC64()? XRegs[IntVal] : RRegs[IntVal]; return false; } else if (Name.startswith("f") && !Name.substr(1).getAsInteger(10, IntVal) && IntVal < 32) { RegNo = FRegs[IntVal]; return false; } else if (Name.startswith("v") && !Name.substr(1).getAsInteger(10, IntVal) && IntVal < 32) { RegNo = VRegs[IntVal]; return false; } else if (Name.startswith("cr") && !Name.substr(2).getAsInteger(10, IntVal) && IntVal < 8) { RegNo = CRRegs[IntVal]; return false; } } return true; }
bool SparcAsmParser::matchSparcAsmModifiers(const MCExpr *&EVal, SMLoc &EndLoc) { AsmToken Tok = Parser.getTok(); if (!Tok.is(AsmToken::Identifier)) return false; StringRef name = Tok.getString(); SparcMCExpr::VariantKind VK = SparcMCExpr::parseVariantKind(name); if (VK == SparcMCExpr::VK_Sparc_None) return false; Parser.Lex(); // Eat the identifier. if (Parser.getTok().getKind() != AsmToken::LParen) return false; Parser.Lex(); // Eat the LParen token. const MCExpr *subExpr; if (Parser.parseParenExpression(subExpr, EndLoc)) return false; bool isPIC = getContext().getObjectFileInfo()->getRelocM() == Reloc::PIC_; switch(VK) { default: break; case SparcMCExpr::VK_Sparc_LO: VK = (hasGOTReference(subExpr) ? SparcMCExpr::VK_Sparc_PC10 : (isPIC ? SparcMCExpr::VK_Sparc_GOT10 : VK)); break; case SparcMCExpr::VK_Sparc_HI: VK = (hasGOTReference(subExpr) ? SparcMCExpr::VK_Sparc_PC22 : (isPIC ? SparcMCExpr::VK_Sparc_GOT22 : VK)); break; } EVal = SparcMCExpr::Create(VK, subExpr, getContext()); return true; }
size_t AsmLexer::peekTokens(MutableArrayRef<AsmToken> Buf, bool ShouldSkipSpace) { SaveAndRestore<const char *> SavedTokenStart(TokStart); SaveAndRestore<const char *> SavedCurPtr(CurPtr); SaveAndRestore<bool> SavedAtStartOfLine(IsAtStartOfLine); SaveAndRestore<bool> SavedAtStartOfStatement(IsAtStartOfStatement); SaveAndRestore<bool> SavedSkipSpace(SkipSpace, ShouldSkipSpace); SaveAndRestore<bool> SavedIsPeeking(IsPeeking, true); std::string SavedErr = getErr(); SMLoc SavedErrLoc = getErrLoc(); size_t ReadCount; for (ReadCount = 0; ReadCount < Buf.size(); ++ReadCount) { AsmToken Token = LexToken(); Buf[ReadCount] = Token; if (Token.is(AsmToken::Eof)) break; } SetError(SavedErrLoc, SavedErr); return ReadCount; }
int EDDisassembler::parseInst(SmallVectorImpl<MCParsedAsmOperand*> &operands, SmallVectorImpl<AsmToken> &tokens, const std::string &str) { int ret = 0; switch (Key.Arch) { default: return -1; case Triple::x86: case Triple::x86_64: case Triple::arm: case Triple::thumb: break; } const char *cStr = str.c_str(); MemoryBuffer *buf = MemoryBuffer::getMemBuffer(cStr, cStr + strlen(cStr)); StringRef instName; SMLoc instLoc; SourceMgr sourceMgr; sourceMgr.AddNewSourceBuffer(buf, SMLoc()); // ownership of buf handed over MCContext context(*AsmInfo); OwningPtr<MCStreamer> streamer(createNullStreamer(context)); OwningPtr<AsmParser> genericParser(Tgt->createAsmParser(sys::getHostTriple(), sourceMgr, context, *streamer, *AsmInfo)); AsmToken OpcodeToken = genericParser->Lex(); AsmToken NextToken = genericParser->Lex(); // consume next token, because specificParser expects us to if (OpcodeToken.is(AsmToken::Identifier)) { instName = OpcodeToken.getString(); instLoc = OpcodeToken.getLoc(); if (NextToken.isNot(AsmToken::Eof) && genericParser->ParseInstruction(instName, instLoc, operands)) ret = -1; } else { ret = -1; } ParserMutex.acquire(); if (!ret) { GenericAsmLexer->setBuffer(buf); while (SpecificAsmLexer->Lex(), SpecificAsmLexer->isNot(AsmToken::Eof) && SpecificAsmLexer->isNot(AsmToken::EndOfStatement)) { if (SpecificAsmLexer->is(AsmToken::Error)) { ret = -1; break; } tokens.push_back(SpecificAsmLexer->getTok()); } } ParserMutex.release(); return ret; }
bool SparcAsmParser::matchRegisterName(const AsmToken &Tok, unsigned &RegNo, bool isDFP, bool isQFP) { int64_t intVal = 0; RegNo = 0; if (Tok.is(AsmToken::Identifier)) { StringRef name = Tok.getString(); // %fp if (name.equals("fp")) { RegNo = Sparc::I6; return true; } // %sp if (name.equals("sp")) { RegNo = Sparc::O6; return true; } if (name.equals("y")) { RegNo = Sparc::Y; return true; } if (name.equals("icc")) { RegNo = Sparc::ICC; return true; } if (name.equals("xcc")) { // FIXME:: check 64bit. RegNo = Sparc::ICC; return true; } // %fcc0 - %fcc3 if (name.substr(0, 3).equals_lower("fcc") && !name.substr(3).getAsInteger(10, intVal) && intVal < 4) { // FIXME: check 64bit and handle %fcc1 - %fcc3 RegNo = Sparc::FCC; return true; } // %g0 - %g7 if (name.substr(0, 1).equals_lower("g") && !name.substr(1).getAsInteger(10, intVal) && intVal < 8) { RegNo = IntRegs[intVal]; return true; } // %o0 - %o7 if (name.substr(0, 1).equals_lower("o") && !name.substr(1).getAsInteger(10, intVal) && intVal < 8) { RegNo = IntRegs[8 + intVal]; return true; } if (name.substr(0, 1).equals_lower("l") && !name.substr(1).getAsInteger(10, intVal) && intVal < 8) { RegNo = IntRegs[16 + intVal]; return true; } if (name.substr(0, 1).equals_lower("i") && !name.substr(1).getAsInteger(10, intVal) && intVal < 8) { RegNo = IntRegs[24 + intVal]; return true; } // %f0 - %f31 if (name.substr(0, 1).equals_lower("f") && !name.substr(1, 2).getAsInteger(10, intVal) && intVal < 32) { if (isDFP && (intVal%2 == 0)) { RegNo = DoubleRegs[intVal/2]; } else if (isQFP && (intVal%4 == 0)) { RegNo = QuadFPRegs[intVal/4]; } else { RegNo = FloatRegs[intVal]; } return true; } // %f32 - %f62 if (name.substr(0, 1).equals_lower("f") && !name.substr(1, 2).getAsInteger(10, intVal) && intVal >= 32 && intVal <= 62 && (intVal % 2 == 0)) { if (isDFP) { RegNo = DoubleRegs[16 + intVal/2]; } else if (isQFP && (intVal % 4 == 0)) { RegNo = QuadFPRegs[8 + intVal/4]; } else { return false; } return true; } // %r0 - %r31 if (name.substr(0, 1).equals_lower("r") && !name.substr(1, 2).getAsInteger(10, intVal) && intVal < 31) { RegNo = IntRegs[intVal]; return true; } } return false; }
bool SparcAsmParser::matchRegisterName(const AsmToken &Tok, unsigned &RegNo, unsigned &RegKind) { int64_t intVal = 0; RegNo = 0; RegKind = SparcOperand::rk_None; if (Tok.is(AsmToken::Identifier)) { StringRef name = Tok.getString(); // %fp if (name.equals("fp")) { RegNo = Sparc::I6; RegKind = SparcOperand::rk_IntReg; return true; } // %sp if (name.equals("sp")) { RegNo = Sparc::O6; RegKind = SparcOperand::rk_IntReg; return true; } if (name.equals("y")) { RegNo = Sparc::Y; RegKind = SparcOperand::rk_Special; return true; } if (name.substr(0, 3).equals_lower("asr") && !name.substr(3).getAsInteger(10, intVal) && intVal > 0 && intVal < 32) { RegNo = ASRRegs[intVal]; RegKind = SparcOperand::rk_Special; return true; } if (name.equals("icc")) { RegNo = Sparc::ICC; RegKind = SparcOperand::rk_Special; return true; } if (name.equals("psr")) { RegNo = Sparc::PSR; RegKind = SparcOperand::rk_Special; return true; } if (name.equals("wim")) { RegNo = Sparc::WIM; RegKind = SparcOperand::rk_Special; return true; } if (name.equals("tbr")) { RegNo = Sparc::TBR; RegKind = SparcOperand::rk_Special; return true; } if (name.equals("xcc")) { // FIXME:: check 64bit. RegNo = Sparc::ICC; RegKind = SparcOperand::rk_Special; return true; } // %fcc0 - %fcc3 if (name.substr(0, 3).equals_lower("fcc") && !name.substr(3).getAsInteger(10, intVal) && intVal < 4) { // FIXME: check 64bit and handle %fcc1 - %fcc3 RegNo = Sparc::FCC0 + intVal; RegKind = SparcOperand::rk_Special; return true; } // %g0 - %g7 if (name.substr(0, 1).equals_lower("g") && !name.substr(1).getAsInteger(10, intVal) && intVal < 8) { RegNo = IntRegs[intVal]; RegKind = SparcOperand::rk_IntReg; return true; } // %o0 - %o7 if (name.substr(0, 1).equals_lower("o") && !name.substr(1).getAsInteger(10, intVal) && intVal < 8) { RegNo = IntRegs[8 + intVal]; RegKind = SparcOperand::rk_IntReg; return true; } if (name.substr(0, 1).equals_lower("l") && !name.substr(1).getAsInteger(10, intVal) && intVal < 8) { RegNo = IntRegs[16 + intVal]; RegKind = SparcOperand::rk_IntReg; return true; } if (name.substr(0, 1).equals_lower("i") && !name.substr(1).getAsInteger(10, intVal) && intVal < 8) { RegNo = IntRegs[24 + intVal]; RegKind = SparcOperand::rk_IntReg; return true; } // %f0 - %f31 if (name.substr(0, 1).equals_lower("f") && !name.substr(1, 2).getAsInteger(10, intVal) && intVal < 32) { RegNo = FloatRegs[intVal]; RegKind = SparcOperand::rk_FloatReg; return true; } // %f32 - %f62 if (name.substr(0, 1).equals_lower("f") && !name.substr(1, 2).getAsInteger(10, intVal) && intVal >= 32 && intVal <= 62 && (intVal % 2 == 0)) { // FIXME: Check V9 RegNo = DoubleRegs[intVal/2]; RegKind = SparcOperand::rk_DoubleReg; return true; } // %r0 - %r31 if (name.substr(0, 1).equals_lower("r") && !name.substr(1, 2).getAsInteger(10, intVal) && intVal < 31) { RegNo = IntRegs[intVal]; RegKind = SparcOperand::rk_IntReg; return true; } } return false; }
bool SparcAsmParser::matchRegisterName(const AsmToken &Tok, unsigned &RegNo, unsigned &RegKind) { int64_t intVal = 0; RegNo = 0; RegKind = SparcOperand::rk_None; if (Tok.is(AsmToken::Identifier)) { StringRef name = Tok.getString(); // %fp if (name.equals("fp")) { RegNo = Sparc::I6; RegKind = SparcOperand::rk_IntReg; return true; } // %sp if (name.equals("sp")) { RegNo = Sparc::O6; RegKind = SparcOperand::rk_IntReg; return true; } if (name.equals("y")) { RegNo = Sparc::Y; RegKind = SparcOperand::rk_Special; return true; } if (name.substr(0, 3).equals_lower("asr") && !name.substr(3).getAsInteger(10, intVal) && intVal > 0 && intVal < 32) { RegNo = ASRRegs[intVal]; RegKind = SparcOperand::rk_Special; return true; } // %fprs is an alias of %asr6. if (name.equals("fprs")) { RegNo = ASRRegs[6]; RegKind = SparcOperand::rk_Special; return true; } if (name.equals("icc")) { RegNo = Sparc::ICC; RegKind = SparcOperand::rk_Special; return true; } if (name.equals("psr")) { RegNo = Sparc::PSR; RegKind = SparcOperand::rk_Special; return true; } if (name.equals("fsr")) { RegNo = Sparc::FSR; RegKind = SparcOperand::rk_Special; return true; } if (name.equals("fq")) { RegNo = Sparc::FQ; RegKind = SparcOperand::rk_Special; return true; } if (name.equals("csr")) { RegNo = Sparc::CPSR; RegKind = SparcOperand::rk_Special; return true; } if (name.equals("cq")) { RegNo = Sparc::CPQ; RegKind = SparcOperand::rk_Special; return true; } if (name.equals("wim")) { RegNo = Sparc::WIM; RegKind = SparcOperand::rk_Special; return true; } if (name.equals("tbr")) { RegNo = Sparc::TBR; RegKind = SparcOperand::rk_Special; return true; } if (name.equals("xcc")) { // FIXME:: check 64bit. RegNo = Sparc::ICC; RegKind = SparcOperand::rk_Special; return true; } // %fcc0 - %fcc3 if (name.substr(0, 3).equals_lower("fcc") && !name.substr(3).getAsInteger(10, intVal) && intVal < 4) { // FIXME: check 64bit and handle %fcc1 - %fcc3 RegNo = Sparc::FCC0 + intVal; RegKind = SparcOperand::rk_Special; return true; } // %g0 - %g7 if (name.substr(0, 1).equals_lower("g") && !name.substr(1).getAsInteger(10, intVal) && intVal < 8) { RegNo = IntRegs[intVal]; RegKind = SparcOperand::rk_IntReg; return true; } // %o0 - %o7 if (name.substr(0, 1).equals_lower("o") && !name.substr(1).getAsInteger(10, intVal) && intVal < 8) { RegNo = IntRegs[8 + intVal]; RegKind = SparcOperand::rk_IntReg; return true; } if (name.substr(0, 1).equals_lower("l") && !name.substr(1).getAsInteger(10, intVal) && intVal < 8) { RegNo = IntRegs[16 + intVal]; RegKind = SparcOperand::rk_IntReg; return true; } if (name.substr(0, 1).equals_lower("i") && !name.substr(1).getAsInteger(10, intVal) && intVal < 8) { RegNo = IntRegs[24 + intVal]; RegKind = SparcOperand::rk_IntReg; return true; } // %f0 - %f31 if (name.substr(0, 1).equals_lower("f") && !name.substr(1, 2).getAsInteger(10, intVal) && intVal < 32) { RegNo = FloatRegs[intVal]; RegKind = SparcOperand::rk_FloatReg; return true; } // %f32 - %f62 if (name.substr(0, 1).equals_lower("f") && !name.substr(1, 2).getAsInteger(10, intVal) && intVal >= 32 && intVal <= 62 && (intVal % 2 == 0)) { // FIXME: Check V9 RegNo = DoubleRegs[intVal/2]; RegKind = SparcOperand::rk_DoubleReg; return true; } // %r0 - %r31 if (name.substr(0, 1).equals_lower("r") && !name.substr(1, 2).getAsInteger(10, intVal) && intVal < 31) { RegNo = IntRegs[intVal]; RegKind = SparcOperand::rk_IntReg; return true; } // %c0 - %c31 if (name.substr(0, 1).equals_lower("c") && !name.substr(1).getAsInteger(10, intVal) && intVal < 32) { RegNo = CoprocRegs[intVal]; RegKind = SparcOperand::rk_CoprocReg; return true; } if (name.equals("tpc")) { RegNo = Sparc::TPC; RegKind = SparcOperand::rk_Special; return true; } if (name.equals("tnpc")) { RegNo = Sparc::TNPC; RegKind = SparcOperand::rk_Special; return true; } if (name.equals("tstate")) { RegNo = Sparc::TSTATE; RegKind = SparcOperand::rk_Special; return true; } if (name.equals("tt")) { RegNo = Sparc::TT; RegKind = SparcOperand::rk_Special; return true; } if (name.equals("tick")) { RegNo = Sparc::TICK; RegKind = SparcOperand::rk_Special; return true; } if (name.equals("tba")) { RegNo = Sparc::TBA; RegKind = SparcOperand::rk_Special; return true; } if (name.equals("pstate")) { RegNo = Sparc::PSTATE; RegKind = SparcOperand::rk_Special; return true; } if (name.equals("tl")) { RegNo = Sparc::TL; RegKind = SparcOperand::rk_Special; return true; } if (name.equals("pil")) { RegNo = Sparc::PIL; RegKind = SparcOperand::rk_Special; return true; } if (name.equals("cwp")) { RegNo = Sparc::CWP; RegKind = SparcOperand::rk_Special; return true; } if (name.equals("cansave")) { RegNo = Sparc::CANSAVE; RegKind = SparcOperand::rk_Special; return true; } if (name.equals("canrestore")) { RegNo = Sparc::CANRESTORE; RegKind = SparcOperand::rk_Special; return true; } if (name.equals("cleanwin")) { RegNo = Sparc::CLEANWIN; RegKind = SparcOperand::rk_Special; return true; } if (name.equals("otherwin")) { RegNo = Sparc::OTHERWIN; RegKind = SparcOperand::rk_Special; return true; } if (name.equals("wstate")) { RegNo = Sparc::WSTATE; RegKind = SparcOperand::rk_Special; return true; } } return false; }