本文整理汇总了C++中AsmToken类的典型用法代码示例。如果您正苦于以下问题:C++ AsmToken类的具体用法?C++ AsmToken怎么用?C++ AsmToken使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AsmToken类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getErr
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;
}
示例2: ParseDirective
bool MachOAsmParser::ParseDirective(AsmToken DirectiveID) {
StringRef IDVal = DirectiveID.getIdentifier();
SMLoc IDLoc = DirectiveID.getLoc();
// FIXME: This should be driven based on a hash lookup and callback.
if (IDVal == ".section")
return ParseDirectiveDarwinSection();
if (IDVal == ".zerofill")
return ParseDirectiveDarwinZerofill();
if (IDVal == ".desc")
return ParseDirectiveDarwinSymbolDesc();
if (IDVal == ".lsym")
return ParseDirectiveDarwinLsym();
if (IDVal == ".tbss")
return ParseDirectiveDarwinTBSS();
if (IDVal == ".comm")
return ParseDirectiveComm(/*IsLocal=*/false);
if (IDVal == ".lcomm")
return ParseDirectiveComm(/*IsLocal=*/true);
if (IDVal == ".subsections_via_symbols")
return ParseDirectiveDarwinSubsectionsViaSymbols();
if (IDVal == ".dump")
return ParseDirectiveDarwinDumpOrLoad(IDLoc, /*IsDump=*/true);
if (IDVal == ".load")
return ParseDirectiveDarwinDumpOrLoad(IDLoc, /*IsLoad=*/false);
if (!ParseDirectiveSectionSwitch(IDVal))
return false;
// Don't understand directive.
return true;
}
示例3: matchSparcAsmModifiers
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;
}
示例4: MatchRegisterName
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;
}
示例5: ParseDirective
/// ParseDirective parses the PPC specific directives
bool PPCAsmParser::ParseDirective(AsmToken DirectiveID) {
StringRef IDVal = DirectiveID.getIdentifier();
if (IDVal == ".word")
return ParseDirectiveWord(4, DirectiveID.getLoc());
if (IDVal == ".tc")
return ParseDirectiveTC(isPPC64()? 8 : 4, DirectiveID.getLoc());
return true;
}
示例6: ParseDirective
bool SystemZAsmParser::ParseDirective(AsmToken DirectiveID) {
StringRef IDVal = DirectiveID.getIdentifier();
if (IDVal == ".insn")
return ParseDirectiveInsn(DirectiveID.getLoc());
return true;
}
示例7: ParseDirectiveRefSym
bool MSP430AsmParser::ParseDirective(AsmToken DirectiveID) {
StringRef IDVal = DirectiveID.getIdentifier();
if (IDVal.lower() == ".long") {
ParseLiteralValues(4, DirectiveID.getLoc());
} else if (IDVal.lower() == ".word" || IDVal.lower() == ".short") {
ParseLiteralValues(2, DirectiveID.getLoc());
} else if (IDVal.lower() == ".byte") {
ParseLiteralValues(1, DirectiveID.getLoc());
} else if (IDVal.lower() == ".refsym") {
return ParseDirectiveRefSym(DirectiveID);
}
return true;
}
示例8: matchSparcAsmModifiers
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;
}
示例9: ParseDirective
bool ELFAsmParser::ParseDirective(AsmToken DirectiveID) {
StringRef IDVal = DirectiveID.getIdentifier();
SMLoc IDLoc = DirectiveID.getLoc();
if (IDVal == ".local")
return ParseDirectiveLocal();
if (IDVal == ".lcomm")
return ParseDirectiveComm(/*IsLocal=*/true);
if (IDVal == ".comm")
return ParseDirectiveComm(/*IsLocal=*/false);
if (IDVal == ".size")
return ParseDirectiveSize();
if (!ParseDirectiveSectionSwitch(IDVal))
return false;
// Don't understand directive.
return true;
}
示例10: ParseDirective
bool SparcAsmParser::
ParseDirective(AsmToken DirectiveID)
{
StringRef IDVal = DirectiveID.getString();
if (IDVal == ".byte")
return parseDirectiveWord(1, DirectiveID.getLoc());
if (IDVal == ".half")
return parseDirectiveWord(2, DirectiveID.getLoc());
if (IDVal == ".word")
return parseDirectiveWord(4, DirectiveID.getLoc());
if (IDVal == ".nword")
return parseDirectiveWord(is64Bit() ? 8 : 4, DirectiveID.getLoc());
if (is64Bit() && IDVal == ".xword")
return parseDirectiveWord(8, DirectiveID.getLoc());
if (IDVal == ".register") {
// For now, ignore .register directive.
Parser.eatToEndOfStatement();
return false;
}
// Let the MC layer to handle other directives.
return true;
}
示例11: ParseDirective
bool SparcAsmParser::
ParseDirective(AsmToken DirectiveID)
{
StringRef IDVal = DirectiveID.getString();
if (IDVal == ".byte")
return parseDirectiveWord(1, DirectiveID.getLoc());
if (IDVal == ".half")
return parseDirectiveWord(2, DirectiveID.getLoc());
if (IDVal == ".word")
return parseDirectiveWord(4, DirectiveID.getLoc());
if (IDVal == ".nword")
return parseDirectiveWord(is64Bit() ? 8 : 4, DirectiveID.getLoc());
if (is64Bit() && IDVal == ".xword")
return parseDirectiveWord(8, DirectiveID.getLoc());
if (IDVal == ".register") {
// For now, ignore .register directive.
Parser.eatToEndOfStatement();
return false;
}
if (IDVal == ".proc") {
// For compatibility, ignore this directive.
// (It's supposed to be an "optimization" in the Sun assembler)
Parser.eatToEndOfStatement();
return false;
}
// Let the MC layer to handle other directives.
return true;
}
示例12: SavedTokenStart
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;
}
示例13: matchRegisterName
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")
//.........这里部分代码省略.........
示例14: switch
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;
}
示例15: AsLexInput
static int AsLexInput(SourceMgr &SrcMgr, MCAsmInfo &MAI,
tool_output_file *Out) {
AsmLexer Lexer(MAI);
Lexer.setBuffer(SrcMgr.getMemoryBuffer(SrcMgr.getMainFileID())->getBuffer());
bool Error = false;
while (Lexer.Lex().isNot(AsmToken::Eof)) {
AsmToken Tok = Lexer.getTok();
switch (Tok.getKind()) {
default:
SrcMgr.PrintMessage(Lexer.getLoc(), SourceMgr::DK_Warning,
"unknown token");
Error = true;
break;
case AsmToken::Error:
Error = true; // error already printed.
break;
case AsmToken::Identifier:
Out->os() << "identifier: " << Lexer.getTok().getString();
break;
case AsmToken::Integer:
Out->os() << "int: " << Lexer.getTok().getString();
break;
case AsmToken::Real:
Out->os() << "real: " << Lexer.getTok().getString();
break;
case AsmToken::String:
Out->os() << "string: " << Lexer.getTok().getString();
break;
case AsmToken::Amp: Out->os() << "Amp"; break;
case AsmToken::AmpAmp: Out->os() << "AmpAmp"; break;
case AsmToken::At: Out->os() << "At"; break;
case AsmToken::Caret: Out->os() << "Caret"; break;
case AsmToken::Colon: Out->os() << "Colon"; break;
case AsmToken::Comma: Out->os() << "Comma"; break;
case AsmToken::Dollar: Out->os() << "Dollar"; break;
case AsmToken::Dot: Out->os() << "Dot"; break;
case AsmToken::EndOfStatement: Out->os() << "EndOfStatement"; break;
case AsmToken::Eof: Out->os() << "Eof"; break;
case AsmToken::Equal: Out->os() << "Equal"; break;
case AsmToken::EqualEqual: Out->os() << "EqualEqual"; break;
case AsmToken::Exclaim: Out->os() << "Exclaim"; break;
case AsmToken::ExclaimEqual: Out->os() << "ExclaimEqual"; break;
case AsmToken::Greater: Out->os() << "Greater"; break;
case AsmToken::GreaterEqual: Out->os() << "GreaterEqual"; break;
case AsmToken::GreaterGreater: Out->os() << "GreaterGreater"; break;
case AsmToken::Hash: Out->os() << "Hash"; break;
case AsmToken::LBrac: Out->os() << "LBrac"; break;
case AsmToken::LCurly: Out->os() << "LCurly"; break;
case AsmToken::LParen: Out->os() << "LParen"; break;
case AsmToken::Less: Out->os() << "Less"; break;
case AsmToken::LessEqual: Out->os() << "LessEqual"; break;
case AsmToken::LessGreater: Out->os() << "LessGreater"; break;
case AsmToken::LessLess: Out->os() << "LessLess"; break;
case AsmToken::Minus: Out->os() << "Minus"; break;
case AsmToken::Percent: Out->os() << "Percent"; break;
case AsmToken::Pipe: Out->os() << "Pipe"; break;
case AsmToken::PipePipe: Out->os() << "PipePipe"; break;
case AsmToken::Plus: Out->os() << "Plus"; break;
case AsmToken::RBrac: Out->os() << "RBrac"; break;
case AsmToken::RCurly: Out->os() << "RCurly"; break;
case AsmToken::RParen: Out->os() << "RParen"; break;
case AsmToken::Slash: Out->os() << "Slash"; break;
case AsmToken::Star: Out->os() << "Star"; break;
case AsmToken::Tilde: Out->os() << "Tilde"; break;
}
// Print the token string.
Out->os() << " (\"";
Out->os().write_escaped(Tok.getString());
Out->os() << "\")\n";
}
return Error;
}