2009-06-21 07:19:10 +00:00
|
|
|
//===- AsmLexer.h - Lexer for Assembly Files --------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This class declares the lexer for assembly files.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef ASMLEXER_H
|
|
|
|
#define ASMLEXER_H
|
|
|
|
|
|
|
|
#include "llvm/Support/DataTypes.h"
|
|
|
|
#include <string>
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
class MemoryBuffer;
|
|
|
|
class SourceMgr;
|
|
|
|
class SMLoc;
|
|
|
|
|
|
|
|
namespace asmtok {
|
|
|
|
enum TokKind {
|
|
|
|
// Markers
|
|
|
|
Eof, Error,
|
|
|
|
|
2009-06-21 19:56:35 +00:00
|
|
|
// String values.
|
2009-06-21 07:19:10 +00:00
|
|
|
Identifier,
|
2009-06-21 19:21:25 +00:00
|
|
|
Register,
|
2009-06-21 19:56:35 +00:00
|
|
|
String,
|
|
|
|
|
|
|
|
// Integer values.
|
2009-06-21 07:19:10 +00:00
|
|
|
IntVal,
|
|
|
|
|
2009-06-21 19:56:35 +00:00
|
|
|
// No-value.
|
2009-06-21 19:21:25 +00:00
|
|
|
EndOfStatement,
|
2009-06-21 07:19:10 +00:00
|
|
|
Colon,
|
2009-06-22 06:32:03 +00:00
|
|
|
Plus, Minus, Tilde,
|
2009-06-21 19:21:25 +00:00
|
|
|
Slash, // '/'
|
|
|
|
LParen, RParen,
|
2009-06-29 20:37:27 +00:00
|
|
|
Star, Comma, Dollar, Equal, EqualEqual,
|
2009-06-23 05:57:07 +00:00
|
|
|
|
2009-06-29 20:37:27 +00:00
|
|
|
Pipe, PipePipe, Caret,
|
|
|
|
Amp, AmpAmp, Exclaim, ExclaimEqual, Percent,
|
|
|
|
Less, LessEqual, LessLess, LessGreater,
|
|
|
|
Greater, GreaterEqual, GreaterGreater
|
2009-06-21 07:19:10 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/// AsmLexer - Lexer class for assembly files.
|
|
|
|
class AsmLexer {
|
|
|
|
SourceMgr &SrcMgr;
|
|
|
|
|
|
|
|
const char *CurPtr;
|
|
|
|
const MemoryBuffer *CurBuf;
|
2009-06-24 00:33:19 +00:00
|
|
|
// A llvm::StringSet<>, which provides uniqued and null-terminated strings.
|
|
|
|
void *TheStringSet;
|
2009-06-21 07:19:10 +00:00
|
|
|
|
|
|
|
// Information about the current token.
|
|
|
|
const char *TokStart;
|
|
|
|
asmtok::TokKind CurKind;
|
2009-06-24 00:33:19 +00:00
|
|
|
const char *CurStrVal; // This is valid for Identifier.
|
2009-06-21 07:19:10 +00:00
|
|
|
int64_t CurIntVal;
|
|
|
|
|
|
|
|
/// CurBuffer - This is the current buffer index we're lexing from as managed
|
|
|
|
/// by the SourceMgr object.
|
|
|
|
int CurBuffer;
|
|
|
|
|
2009-06-24 00:33:19 +00:00
|
|
|
void operator=(const AsmLexer&); // DO NOT IMPLEMENT
|
|
|
|
AsmLexer(const AsmLexer&); // DO NOT IMPLEMENT
|
2009-06-21 07:19:10 +00:00
|
|
|
public:
|
|
|
|
AsmLexer(SourceMgr &SrcMgr);
|
2009-06-24 00:33:19 +00:00
|
|
|
~AsmLexer();
|
2009-06-21 07:19:10 +00:00
|
|
|
|
|
|
|
asmtok::TokKind Lex() {
|
|
|
|
return CurKind = LexToken();
|
|
|
|
}
|
|
|
|
|
|
|
|
asmtok::TokKind getKind() const { return CurKind; }
|
2009-06-21 20:54:55 +00:00
|
|
|
bool is(asmtok::TokKind K) const { return CurKind == K; }
|
|
|
|
bool isNot(asmtok::TokKind K) const { return CurKind != K; }
|
2009-06-21 07:19:10 +00:00
|
|
|
|
2009-06-24 00:33:19 +00:00
|
|
|
const char *getCurStrVal() const {
|
2009-06-21 19:56:35 +00:00
|
|
|
assert((CurKind == asmtok::Identifier || CurKind == asmtok::Register ||
|
|
|
|
CurKind == asmtok::String) &&
|
2009-06-21 07:19:10 +00:00
|
|
|
"This token doesn't have a string value");
|
|
|
|
return CurStrVal;
|
|
|
|
}
|
|
|
|
int64_t getCurIntVal() const {
|
|
|
|
assert(CurKind == asmtok::IntVal && "This token isn't an integer");
|
|
|
|
return CurIntVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
SMLoc getLoc() const;
|
|
|
|
|
2009-06-30 00:49:23 +00:00
|
|
|
void PrintMessage(SMLoc Loc, const std::string &Msg, const char *Type) const;
|
2009-06-21 07:19:10 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
int getNextChar();
|
2009-06-21 19:21:25 +00:00
|
|
|
asmtok::TokKind ReturnError(const char *Loc, const std::string &Msg);
|
2009-06-21 07:19:10 +00:00
|
|
|
|
|
|
|
/// LexToken - Read the next token and return its code.
|
|
|
|
asmtok::TokKind LexToken();
|
2009-06-21 19:21:25 +00:00
|
|
|
asmtok::TokKind LexIdentifier();
|
|
|
|
asmtok::TokKind LexPercent();
|
|
|
|
asmtok::TokKind LexSlash();
|
2009-06-29 22:00:57 +00:00
|
|
|
asmtok::TokKind LexLineComment();
|
2009-06-21 19:21:25 +00:00
|
|
|
asmtok::TokKind LexDigit();
|
2009-06-21 19:56:35 +00:00
|
|
|
asmtok::TokKind LexQuote();
|
2009-06-21 07:19:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|