mirror of
https://github.com/RPCSX/llvm.git
synced 2024-11-25 04:39:44 +00:00
Replace the original flex lexer with a hand writen one. This
drops a dependency on flex and lets us make future progress more easily. Yay for 2 fewer .cvs files to make silly conflicts with. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44213 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
c1819188b6
commit
8e3a8e0452
826
lib/AsmParser/LLLexer.cpp
Normal file
826
lib/AsmParser/LLLexer.cpp
Normal file
@ -0,0 +1,826 @@
|
||||
//===- LLLexer.cpp - Lexer for .ll Files ----------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file was developed by Chris Lattner and is distributed under
|
||||
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Implement the Lexer for .ll files.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "LLLexer.h"
|
||||
#include "ParserInternals.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
|
||||
#include <list>
|
||||
#include "llvmAsmParser.h"
|
||||
using namespace llvm;
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Helper functions.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// atoull - Convert an ascii string of decimal digits into the unsigned long
|
||||
// long representation... this does not have to do input error checking,
|
||||
// because we know that the input will be matched by a suitable regex...
|
||||
//
|
||||
static uint64_t atoull(const char *Buffer, const char *End) {
|
||||
uint64_t Result = 0;
|
||||
for (; Buffer != End; Buffer++) {
|
||||
uint64_t OldRes = Result;
|
||||
Result *= 10;
|
||||
Result += *Buffer-'0';
|
||||
if (Result < OldRes) { // Uh, oh, overflow detected!!!
|
||||
GenerateError("constant bigger than 64 bits detected!");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
static uint64_t HexIntToVal(const char *Buffer, const char *End) {
|
||||
uint64_t Result = 0;
|
||||
for (; Buffer != End; ++Buffer) {
|
||||
uint64_t OldRes = Result;
|
||||
Result *= 16;
|
||||
char C = *Buffer;
|
||||
if (C >= '0' && C <= '9')
|
||||
Result += C-'0';
|
||||
else if (C >= 'A' && C <= 'F')
|
||||
Result += C-'A'+10;
|
||||
else if (C >= 'a' && C <= 'f')
|
||||
Result += C-'a'+10;
|
||||
|
||||
if (Result < OldRes) { // Uh, oh, overflow detected!!!
|
||||
GenerateError("constant bigger than 64 bits detected!");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
// HexToFP - Convert the ascii string in hexadecimal format to the floating
|
||||
// point representation of it.
|
||||
//
|
||||
static double HexToFP(const char *Buffer, const char *End) {
|
||||
return BitsToDouble(HexIntToVal(Buffer, End)); // Cast Hex constant to double
|
||||
}
|
||||
|
||||
static void HexToIntPair(const char *Buffer, const char *End, uint64_t Pair[2]){
|
||||
Pair[0] = 0;
|
||||
for (int i=0; i<16; i++, Buffer++) {
|
||||
assert(Buffer != End);
|
||||
Pair[0] *= 16;
|
||||
char C = *Buffer;
|
||||
if (C >= '0' && C <= '9')
|
||||
Pair[0] += C-'0';
|
||||
else if (C >= 'A' && C <= 'F')
|
||||
Pair[0] += C-'A'+10;
|
||||
else if (C >= 'a' && C <= 'f')
|
||||
Pair[0] += C-'a'+10;
|
||||
}
|
||||
Pair[1] = 0;
|
||||
for (int i=0; i<16 && Buffer != End; i++, Buffer++) {
|
||||
Pair[1] *= 16;
|
||||
char C = *Buffer;
|
||||
if (C >= '0' && C <= '9')
|
||||
Pair[1] += C-'0';
|
||||
else if (C >= 'A' && C <= 'F')
|
||||
Pair[1] += C-'A'+10;
|
||||
else if (C >= 'a' && C <= 'f')
|
||||
Pair[1] += C-'a'+10;
|
||||
}
|
||||
if (*Buffer)
|
||||
GenerateError("constant bigger than 128 bits detected!");
|
||||
}
|
||||
|
||||
// UnEscapeLexed - Run through the specified buffer and change \xx codes to the
|
||||
// appropriate character.
|
||||
static void UnEscapeLexed(std::string &Str) {
|
||||
if (Str.empty()) return;
|
||||
|
||||
char *Buffer = &Str[0], *EndBuffer = Buffer+Str.size();
|
||||
char *BOut = Buffer;
|
||||
for (char *BIn = Buffer; BIn != EndBuffer; ) {
|
||||
if (BIn[0] == '\\') {
|
||||
if (BIn < EndBuffer-1 && BIn[1] == '\\') {
|
||||
*BOut++ = '\\'; // Two \ becomes one
|
||||
BIn += 2;
|
||||
} else if (BIn < EndBuffer-2 && isxdigit(BIn[1]) && isxdigit(BIn[2])) {
|
||||
char Tmp = BIn[3]; BIn[3] = 0; // Terminate string
|
||||
*BOut = (char)strtol(BIn+1, 0, 16); // Convert to number
|
||||
BIn[3] = Tmp; // Restore character
|
||||
BIn += 3; // Skip over handled chars
|
||||
++BOut;
|
||||
} else {
|
||||
*BOut++ = *BIn++;
|
||||
}
|
||||
} else {
|
||||
*BOut++ = *BIn++;
|
||||
}
|
||||
}
|
||||
Str.resize(BOut-Buffer);
|
||||
}
|
||||
|
||||
/// isLabelChar - Return true for [-a-zA-Z$._0-9].
|
||||
static bool isLabelChar(char C) {
|
||||
return isalnum(C) || C == '-' || C == '$' || C == '.' || C == '_';
|
||||
}
|
||||
|
||||
|
||||
/// isLabelTail - Return true if this pointer points to a valid end of a label.
|
||||
static const char *isLabelTail(const char *CurPtr) {
|
||||
while (1) {
|
||||
if (CurPtr[0] == ':') return CurPtr+1;
|
||||
if (!isLabelChar(CurPtr[0])) return 0;
|
||||
++CurPtr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Lexer definition.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// FIXME: REMOVE THIS.
|
||||
#define YYEOF 0
|
||||
#define YYERROR -2
|
||||
|
||||
LLLexer::LLLexer(MemoryBuffer *StartBuf) : CurLineNo(1), CurBuf(StartBuf) {
|
||||
CurPtr = CurBuf->getBufferStart();
|
||||
}
|
||||
|
||||
std::string LLLexer::getFilename() const {
|
||||
return CurBuf->getBufferIdentifier();
|
||||
}
|
||||
|
||||
int LLLexer::getNextChar() {
|
||||
char CurChar = *CurPtr++;
|
||||
switch (CurChar) {
|
||||
default: return (unsigned char)CurChar;
|
||||
case 0:
|
||||
// A nul character in the stream is either the end of the current buffer or
|
||||
// a random nul in the file. Disambiguate that here.
|
||||
if (CurPtr-1 != CurBuf->getBufferEnd())
|
||||
return 0; // Just whitespace.
|
||||
|
||||
// Otherwise, return end of file.
|
||||
--CurPtr; // Another call to lex will return EOF again.
|
||||
return EOF;
|
||||
case '\n':
|
||||
case '\r':
|
||||
// Handle the newline character by ignoring it and incrementing the line
|
||||
// count. However, be careful about 'dos style' files with \n\r in them.
|
||||
// Only treat a \n\r or \r\n as a single line.
|
||||
if ((*CurPtr == '\n' || (*CurPtr == '\r')) &&
|
||||
*CurPtr != CurChar)
|
||||
++CurPtr; // Eat the two char newline sequence.
|
||||
|
||||
++CurLineNo;
|
||||
return '\n';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int LLLexer::LexToken() {
|
||||
TokStart = CurPtr;
|
||||
|
||||
int CurChar = getNextChar();
|
||||
|
||||
switch (CurChar) {
|
||||
default:
|
||||
// Handle letters: [a-zA-Z_]
|
||||
if (isalpha(CurChar) || CurChar == '_')
|
||||
return LexIdentifier();
|
||||
|
||||
return CurChar;
|
||||
case EOF: return YYEOF;
|
||||
case 0:
|
||||
case ' ':
|
||||
case '\t':
|
||||
case '\n':
|
||||
case '\r':
|
||||
// Ignore whitespace.
|
||||
return LexToken();
|
||||
case '+': return LexPositive();
|
||||
case '@': return LexAt();
|
||||
case '%': return LexPercent();
|
||||
case '"': return LexQuote();
|
||||
case '.':
|
||||
if (const char *Ptr = isLabelTail(CurPtr)) {
|
||||
CurPtr = Ptr;
|
||||
llvmAsmlval.StrVal = new std::string(TokStart, CurPtr-1);
|
||||
return LABELSTR;
|
||||
}
|
||||
if (CurPtr[0] == '.' && CurPtr[1] == '.') {
|
||||
CurPtr += 2;
|
||||
return DOTDOTDOT;
|
||||
}
|
||||
return '.';
|
||||
case '$':
|
||||
if (const char *Ptr = isLabelTail(CurPtr)) {
|
||||
CurPtr = Ptr;
|
||||
llvmAsmlval.StrVal = new std::string(TokStart, CurPtr-1);
|
||||
return LABELSTR;
|
||||
}
|
||||
return '$';
|
||||
case ';':
|
||||
SkipLineComment();
|
||||
return LexToken();
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
case '-':
|
||||
return LexDigitOrNegative();
|
||||
}
|
||||
}
|
||||
|
||||
void LLLexer::SkipLineComment() {
|
||||
while (1) {
|
||||
if (CurPtr[0] == '\n' || CurPtr[0] == '\r' || getNextChar() == EOF)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// LexAt - Lex all tokens that start with an @ character:
|
||||
/// AtStringConstant @\"[^\"]*\"
|
||||
/// GlobalVarName @[-a-zA-Z$._][-a-zA-Z$._0-9]*
|
||||
/// GlobalVarID @[0-9]+
|
||||
int LLLexer::LexAt() {
|
||||
// Handle AtStringConstant: @\"[^\"]*\"
|
||||
if (CurPtr[0] == '"') {
|
||||
++CurPtr;
|
||||
|
||||
while (1) {
|
||||
int CurChar = getNextChar();
|
||||
|
||||
if (CurChar == EOF) {
|
||||
GenerateError("End of file in global variable name");
|
||||
return YYERROR;
|
||||
}
|
||||
if (CurChar == '"') {
|
||||
llvmAsmlval.StrVal = new std::string(TokStart+2, CurPtr-1);
|
||||
UnEscapeLexed(*llvmAsmlval.StrVal);
|
||||
return ATSTRINGCONSTANT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle GlobalVarName: @[-a-zA-Z$._][-a-zA-Z$._0-9]*
|
||||
if (isalpha(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
|
||||
CurPtr[0] == '.' || CurPtr[0] == '_') {
|
||||
++CurPtr;
|
||||
while (isalnum(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
|
||||
CurPtr[0] == '.' || CurPtr[0] == '_')
|
||||
++CurPtr;
|
||||
|
||||
llvmAsmlval.StrVal = new std::string(TokStart+1, CurPtr); // Skip @
|
||||
return GLOBALVAR;
|
||||
}
|
||||
|
||||
// Handle GlobalVarID: @[0-9]+
|
||||
if (isdigit(CurPtr[0])) {
|
||||
for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr);
|
||||
|
||||
uint64_t Val = atoull(TokStart+1, CurPtr);
|
||||
if ((unsigned)Val != Val)
|
||||
GenerateError("Invalid value number (too large)!");
|
||||
llvmAsmlval.UIntVal = unsigned(Val);
|
||||
return GLOBALVAL_ID;
|
||||
}
|
||||
|
||||
return '@';
|
||||
}
|
||||
|
||||
|
||||
/// LexPercent - Lex all tokens that start with a % character:
|
||||
/// PctStringConstant %\"[^\"]*\"
|
||||
/// LocalVarName %[-a-zA-Z$._][-a-zA-Z$._0-9]*
|
||||
/// LocalVarID %[0-9]+
|
||||
int LLLexer::LexPercent() {
|
||||
// Handle PctStringConstant: %\"[^\"]*\"
|
||||
if (CurPtr[0] == '"') {
|
||||
++CurPtr;
|
||||
|
||||
while (1) {
|
||||
int CurChar = getNextChar();
|
||||
|
||||
if (CurChar == EOF) {
|
||||
GenerateError("End of file in local variable name");
|
||||
return YYERROR;
|
||||
}
|
||||
if (CurChar == '"') {
|
||||
llvmAsmlval.StrVal = new std::string(TokStart+2, CurPtr-1);
|
||||
UnEscapeLexed(*llvmAsmlval.StrVal);
|
||||
return PCTSTRINGCONSTANT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle LocalVarName: %[-a-zA-Z$._][-a-zA-Z$._0-9]*
|
||||
if (isalpha(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
|
||||
CurPtr[0] == '.' || CurPtr[0] == '_') {
|
||||
++CurPtr;
|
||||
while (isalnum(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
|
||||
CurPtr[0] == '.' || CurPtr[0] == '_')
|
||||
++CurPtr;
|
||||
|
||||
llvmAsmlval.StrVal = new std::string(TokStart+1, CurPtr); // Skip %
|
||||
return LOCALVAR;
|
||||
}
|
||||
|
||||
// Handle LocalVarID: %[0-9]+
|
||||
if (isdigit(CurPtr[0])) {
|
||||
for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr);
|
||||
|
||||
uint64_t Val = atoull(TokStart+1, CurPtr);
|
||||
if ((unsigned)Val != Val)
|
||||
GenerateError("Invalid value number (too large)!");
|
||||
llvmAsmlval.UIntVal = unsigned(Val);
|
||||
return LOCALVAL_ID;
|
||||
}
|
||||
|
||||
return '%';
|
||||
}
|
||||
|
||||
/// LexQuote - Lex all tokens that start with a " character:
|
||||
/// QuoteLabel "[^"]+":
|
||||
/// StringConstant "[^"]*"
|
||||
int LLLexer::LexQuote() {
|
||||
while (1) {
|
||||
int CurChar = getNextChar();
|
||||
|
||||
if (CurChar == EOF) {
|
||||
GenerateError("End of file in quoted string");
|
||||
return YYERROR;
|
||||
}
|
||||
|
||||
if (CurChar != '"') continue;
|
||||
|
||||
if (CurPtr[0] != ':') {
|
||||
llvmAsmlval.StrVal = new std::string(TokStart+1, CurPtr-1);
|
||||
UnEscapeLexed(*llvmAsmlval.StrVal);
|
||||
return STRINGCONSTANT;
|
||||
}
|
||||
|
||||
++CurPtr;
|
||||
llvmAsmlval.StrVal = new std::string(TokStart+1, CurPtr-2);
|
||||
UnEscapeLexed(*llvmAsmlval.StrVal);
|
||||
return LABELSTR;
|
||||
}
|
||||
}
|
||||
|
||||
static bool JustWhitespaceNewLine(const char *&Ptr) {
|
||||
const char *ThisPtr = Ptr;
|
||||
while (*ThisPtr == ' ' || *ThisPtr == '\t')
|
||||
++ThisPtr;
|
||||
if (*ThisPtr == '\n' || *ThisPtr == '\r') {
|
||||
Ptr = ThisPtr;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/// LexIdentifier: Handle several related productions:
|
||||
/// Label [-a-zA-Z$._0-9]+:
|
||||
/// IntegerType i[0-9]+
|
||||
/// Keyword sdiv, float, ...
|
||||
/// HexIntConstant [us]0x[0-9A-Fa-f]+
|
||||
int LLLexer::LexIdentifier() {
|
||||
const char *StartChar = CurPtr;
|
||||
const char *IntEnd = CurPtr[-1] == 'i' ? 0 : StartChar;
|
||||
const char *KeywordEnd = 0;
|
||||
|
||||
for (; isLabelChar(*CurPtr); ++CurPtr) {
|
||||
// If we decide this is an integer, remember the end of the sequence.
|
||||
if (!IntEnd && !isdigit(*CurPtr)) IntEnd = CurPtr;
|
||||
if (!KeywordEnd && !isalnum(*CurPtr) && *CurPtr != '_') KeywordEnd = CurPtr;
|
||||
}
|
||||
|
||||
// If we stopped due to a colon, this really is a label.
|
||||
if (*CurPtr == ':') {
|
||||
llvmAsmlval.StrVal = new std::string(StartChar-1, CurPtr++);
|
||||
return LABELSTR;
|
||||
}
|
||||
|
||||
// Otherwise, this wasn't a label. If this was valid as an integer type,
|
||||
// return it.
|
||||
if (IntEnd == 0) IntEnd = CurPtr;
|
||||
if (IntEnd != StartChar) {
|
||||
CurPtr = IntEnd;
|
||||
uint64_t NumBits = atoull(StartChar, CurPtr);
|
||||
if (NumBits < IntegerType::MIN_INT_BITS ||
|
||||
NumBits > IntegerType::MAX_INT_BITS) {
|
||||
GenerateError("Bitwidth for integer type out of range!");
|
||||
return YYERROR;
|
||||
}
|
||||
const Type* Ty = IntegerType::get(NumBits);
|
||||
llvmAsmlval.PrimType = Ty;
|
||||
return INTTYPE;
|
||||
}
|
||||
|
||||
// Otherwise, this was a letter sequence. See which keyword this is.
|
||||
if (KeywordEnd == 0) KeywordEnd = CurPtr;
|
||||
CurPtr = KeywordEnd;
|
||||
--StartChar;
|
||||
unsigned Len = CurPtr-StartChar;
|
||||
#define KEYWORD(STR, TOK) \
|
||||
if (Len == strlen(STR) && !memcmp(StartChar, STR, strlen(STR))) return TOK;
|
||||
|
||||
KEYWORD("begin", BEGINTOK);
|
||||
KEYWORD("end", ENDTOK);
|
||||
KEYWORD("true", TRUETOK);
|
||||
KEYWORD("false", FALSETOK);
|
||||
KEYWORD("declare", DECLARE);
|
||||
KEYWORD("define", DEFINE);
|
||||
KEYWORD("global", GLOBAL);
|
||||
KEYWORD("constant", CONSTANT);
|
||||
|
||||
KEYWORD("internal", INTERNAL);
|
||||
KEYWORD("linkonce", LINKONCE);
|
||||
KEYWORD("weak", WEAK);
|
||||
KEYWORD("appending", APPENDING);
|
||||
KEYWORD("dllimport", DLLIMPORT);
|
||||
KEYWORD("dllexport", DLLEXPORT);
|
||||
KEYWORD("hidden", HIDDEN);
|
||||
KEYWORD("protected", PROTECTED);
|
||||
KEYWORD("extern_weak", EXTERN_WEAK);
|
||||
KEYWORD("external", EXTERNAL);
|
||||
KEYWORD("thread_local", THREAD_LOCAL);
|
||||
KEYWORD("zeroinitializer", ZEROINITIALIZER);
|
||||
KEYWORD("undef", UNDEF);
|
||||
KEYWORD("null", NULL_TOK);
|
||||
KEYWORD("to", TO);
|
||||
KEYWORD("tail", TAIL);
|
||||
KEYWORD("target", TARGET);
|
||||
KEYWORD("triple", TRIPLE);
|
||||
KEYWORD("deplibs", DEPLIBS);
|
||||
KEYWORD("datalayout", DATALAYOUT);
|
||||
KEYWORD("volatile", VOLATILE);
|
||||
KEYWORD("align", ALIGN);
|
||||
KEYWORD("section", SECTION);
|
||||
KEYWORD("alias", ALIAS);
|
||||
KEYWORD("module", MODULE);
|
||||
KEYWORD("asm", ASM_TOK);
|
||||
KEYWORD("sideeffect", SIDEEFFECT);
|
||||
|
||||
KEYWORD("cc", CC_TOK);
|
||||
KEYWORD("ccc", CCC_TOK);
|
||||
KEYWORD("fastcc", FASTCC_TOK);
|
||||
KEYWORD("coldcc", COLDCC_TOK);
|
||||
KEYWORD("x86_stdcallcc", X86_STDCALLCC_TOK);
|
||||
KEYWORD("x86_fastcallcc", X86_FASTCALLCC_TOK);
|
||||
|
||||
KEYWORD("signext", SIGNEXT);
|
||||
KEYWORD("zeroext", ZEROEXT);
|
||||
KEYWORD("inreg", INREG);
|
||||
KEYWORD("sret", SRET);
|
||||
KEYWORD("nounwind", NOUNWIND);
|
||||
KEYWORD("noreturn", NORETURN);
|
||||
KEYWORD("noalias", NOALIAS);
|
||||
KEYWORD("byval", BYVAL);
|
||||
KEYWORD("nest", NEST);
|
||||
KEYWORD("pure", PURE);
|
||||
KEYWORD("const", CONST);
|
||||
|
||||
KEYWORD("type", TYPE);
|
||||
KEYWORD("opaque", OPAQUE);
|
||||
|
||||
KEYWORD("eq" , EQ);
|
||||
KEYWORD("ne" , NE);
|
||||
KEYWORD("slt", SLT);
|
||||
KEYWORD("sgt", SGT);
|
||||
KEYWORD("sle", SLE);
|
||||
KEYWORD("sge", SGE);
|
||||
KEYWORD("ult", ULT);
|
||||
KEYWORD("ugt", UGT);
|
||||
KEYWORD("ule", ULE);
|
||||
KEYWORD("uge", UGE);
|
||||
KEYWORD("oeq", OEQ);
|
||||
KEYWORD("one", ONE);
|
||||
KEYWORD("olt", OLT);
|
||||
KEYWORD("ogt", OGT);
|
||||
KEYWORD("ole", OLE);
|
||||
KEYWORD("oge", OGE);
|
||||
KEYWORD("ord", ORD);
|
||||
KEYWORD("uno", UNO);
|
||||
KEYWORD("ueq", UEQ);
|
||||
KEYWORD("une", UNE);
|
||||
#undef KEYWORD
|
||||
|
||||
// Keywords for types.
|
||||
#define TYPEKEYWORD(STR, LLVMTY, TOK) \
|
||||
if (Len == strlen(STR) && !memcmp(StartChar, STR, strlen(STR))) { \
|
||||
llvmAsmlval.PrimType = LLVMTY; return TOK; }
|
||||
TYPEKEYWORD("void", Type::VoidTy, VOID);
|
||||
TYPEKEYWORD("float", Type::FloatTy, FLOAT);
|
||||
TYPEKEYWORD("double", Type::DoubleTy, DOUBLE);
|
||||
TYPEKEYWORD("x86_fp80", Type::X86_FP80Ty, X86_FP80);
|
||||
TYPEKEYWORD("fp128", Type::FP128Ty, FP128);
|
||||
TYPEKEYWORD("ppc_fp128", Type::PPC_FP128Ty, PPC_FP128);
|
||||
TYPEKEYWORD("label", Type::LabelTy, LABEL);
|
||||
#undef TYPEKEYWORD
|
||||
|
||||
// Handle special forms for autoupgrading. Drop these in LLVM 3.0. This is
|
||||
// to avoid conflicting with the sext/zext instructions, below.
|
||||
if (Len == 4 && !memcmp(StartChar, "sext", 4)) {
|
||||
// Scan CurPtr ahead, seeing if there is just whitespace before the newline.
|
||||
if (JustWhitespaceNewLine(CurPtr))
|
||||
return SIGNEXT;
|
||||
} else if (Len == 4 && !memcmp(StartChar, "zext", 4)) {
|
||||
// Scan CurPtr ahead, seeing if there is just whitespace before the newline.
|
||||
if (JustWhitespaceNewLine(CurPtr))
|
||||
return ZEROEXT;
|
||||
}
|
||||
|
||||
// Keywords for instructions.
|
||||
#define INSTKEYWORD(STR, type, Enum, TOK) \
|
||||
if (Len == strlen(STR) && !memcmp(StartChar, STR, strlen(STR))) { \
|
||||
llvmAsmlval.type = Instruction::Enum; return TOK; }
|
||||
|
||||
INSTKEYWORD("add", BinaryOpVal, Add, ADD);
|
||||
INSTKEYWORD("sub", BinaryOpVal, Sub, SUB);
|
||||
INSTKEYWORD("mul", BinaryOpVal, Mul, MUL);
|
||||
INSTKEYWORD("udiv", BinaryOpVal, UDiv, UDIV);
|
||||
INSTKEYWORD("sdiv", BinaryOpVal, SDiv, SDIV);
|
||||
INSTKEYWORD("fdiv", BinaryOpVal, FDiv, FDIV);
|
||||
INSTKEYWORD("urem", BinaryOpVal, URem, UREM);
|
||||
INSTKEYWORD("srem", BinaryOpVal, SRem, SREM);
|
||||
INSTKEYWORD("frem", BinaryOpVal, FRem, FREM);
|
||||
INSTKEYWORD("shl", BinaryOpVal, Shl, SHL);
|
||||
INSTKEYWORD("lshr", BinaryOpVal, LShr, LSHR);
|
||||
INSTKEYWORD("ashr", BinaryOpVal, AShr, ASHR);
|
||||
INSTKEYWORD("and", BinaryOpVal, And, AND);
|
||||
INSTKEYWORD("or", BinaryOpVal, Or , OR );
|
||||
INSTKEYWORD("xor", BinaryOpVal, Xor, XOR);
|
||||
INSTKEYWORD("icmp", OtherOpVal, ICmp, ICMP);
|
||||
INSTKEYWORD("fcmp", OtherOpVal, FCmp, FCMP);
|
||||
|
||||
INSTKEYWORD("phi", OtherOpVal, PHI, PHI_TOK);
|
||||
INSTKEYWORD("call", OtherOpVal, Call, CALL);
|
||||
INSTKEYWORD("trunc", CastOpVal, Trunc, TRUNC);
|
||||
INSTKEYWORD("zext", CastOpVal, ZExt, ZEXT);
|
||||
INSTKEYWORD("sext", CastOpVal, SExt, SEXT);
|
||||
INSTKEYWORD("fptrunc", CastOpVal, FPTrunc, FPTRUNC);
|
||||
INSTKEYWORD("fpext", CastOpVal, FPExt, FPEXT);
|
||||
INSTKEYWORD("uitofp", CastOpVal, UIToFP, UITOFP);
|
||||
INSTKEYWORD("sitofp", CastOpVal, SIToFP, SITOFP);
|
||||
INSTKEYWORD("fptoui", CastOpVal, FPToUI, FPTOUI);
|
||||
INSTKEYWORD("fptosi", CastOpVal, FPToSI, FPTOSI);
|
||||
INSTKEYWORD("inttoptr", CastOpVal, IntToPtr, INTTOPTR);
|
||||
INSTKEYWORD("ptrtoint", CastOpVal, PtrToInt, PTRTOINT);
|
||||
INSTKEYWORD("bitcast", CastOpVal, BitCast, BITCAST);
|
||||
INSTKEYWORD("select", OtherOpVal, Select, SELECT);
|
||||
INSTKEYWORD("va_arg", OtherOpVal, VAArg , VAARG);
|
||||
INSTKEYWORD("ret", TermOpVal, Ret, RET);
|
||||
INSTKEYWORD("br", TermOpVal, Br, BR);
|
||||
INSTKEYWORD("switch", TermOpVal, Switch, SWITCH);
|
||||
INSTKEYWORD("invoke", TermOpVal, Invoke, INVOKE);
|
||||
INSTKEYWORD("unwind", TermOpVal, Unwind, UNWIND);
|
||||
INSTKEYWORD("unreachable", TermOpVal, Unreachable, UNREACHABLE);
|
||||
|
||||
INSTKEYWORD("malloc", MemOpVal, Malloc, MALLOC);
|
||||
INSTKEYWORD("alloca", MemOpVal, Alloca, ALLOCA);
|
||||
INSTKEYWORD("free", MemOpVal, Free, FREE);
|
||||
INSTKEYWORD("load", MemOpVal, Load, LOAD);
|
||||
INSTKEYWORD("store", MemOpVal, Store, STORE);
|
||||
INSTKEYWORD("getelementptr", MemOpVal, GetElementPtr, GETELEMENTPTR);
|
||||
|
||||
INSTKEYWORD("extractelement", OtherOpVal, ExtractElement, EXTRACTELEMENT);
|
||||
INSTKEYWORD("insertelement", OtherOpVal, InsertElement, INSERTELEMENT);
|
||||
INSTKEYWORD("shufflevector", OtherOpVal, ShuffleVector, SHUFFLEVECTOR);
|
||||
#undef INSTKEYWORD
|
||||
|
||||
// Check for [us]0x[0-9A-Fa-f]+ which are Hexadecimal constant generated by
|
||||
// the CFE to avoid forcing it to deal with 64-bit numbers.
|
||||
if ((TokStart[0] == 'u' || TokStart[0] == 's') &&
|
||||
TokStart[1] == '0' && TokStart[2] == 'x' && isxdigit(TokStart[3])) {
|
||||
int len = CurPtr-TokStart-3;
|
||||
uint32_t bits = len * 4;
|
||||
APInt Tmp(bits, TokStart+3, len, 16);
|
||||
uint32_t activeBits = Tmp.getActiveBits();
|
||||
if (activeBits > 0 && activeBits < bits)
|
||||
Tmp.trunc(activeBits);
|
||||
if (Tmp.getBitWidth() > 64) {
|
||||
llvmAsmlval.APIntVal = new APInt(Tmp);
|
||||
return TokStart[0] == 's' ? ESAPINTVAL : EUAPINTVAL;
|
||||
} else if (TokStart[0] == 's') {
|
||||
llvmAsmlval.SInt64Val = Tmp.getSExtValue();
|
||||
return ESINT64VAL;
|
||||
} else {
|
||||
llvmAsmlval.UInt64Val = Tmp.getZExtValue();
|
||||
return EUINT64VAL;
|
||||
}
|
||||
}
|
||||
|
||||
// Finally, if this is "cc1234", return this as just "cc".
|
||||
if (TokStart[0] == 'c' && TokStart[1] == 'c') {
|
||||
CurPtr = TokStart+2;
|
||||
return CC_TOK;
|
||||
}
|
||||
|
||||
// Finally, if this isn't known, return just a single character.
|
||||
CurPtr = TokStart+1;
|
||||
return TokStart[0];
|
||||
}
|
||||
|
||||
|
||||
/// Lex0x: Handle productions that start with 0x, knowing that it matches and
|
||||
/// that this is not a label:
|
||||
/// HexFPConstant 0x[0-9A-Fa-f]+
|
||||
/// HexFP80Constant 0xK[0-9A-Fa-f]+
|
||||
/// HexFP128Constant 0xL[0-9A-Fa-f]+
|
||||
/// HexPPC128Constant 0xM[0-9A-Fa-f]+
|
||||
int LLLexer::Lex0x() {
|
||||
CurPtr = TokStart + 2;
|
||||
|
||||
char Kind;
|
||||
if (CurPtr[0] >= 'K' && CurPtr[0] <= 'M') {
|
||||
Kind = *CurPtr++;
|
||||
} else {
|
||||
Kind = 'J';
|
||||
}
|
||||
|
||||
if (!isxdigit(CurPtr[0])) {
|
||||
// Bad token, return it as just zero.
|
||||
CurPtr = TokStart+1;
|
||||
return '0';
|
||||
}
|
||||
|
||||
while (isxdigit(CurPtr[0]))
|
||||
++CurPtr;
|
||||
|
||||
if (Kind == 'J') {
|
||||
// HexFPConstant - Floating point constant represented in IEEE format as a
|
||||
// hexadecimal number for when exponential notation is not precise enough.
|
||||
// Float and double only.
|
||||
llvmAsmlval.FPVal = new APFloat(HexToFP(TokStart+2, CurPtr));
|
||||
return FPVAL;
|
||||
}
|
||||
|
||||
uint64_t Pair[2];
|
||||
HexToIntPair(TokStart+3, CurPtr, Pair);
|
||||
switch (Kind) {
|
||||
default: assert(0 && "Unknown kind!");
|
||||
case 'K':
|
||||
// F80HexFPConstant - x87 long double in hexadecimal format (10 bytes)
|
||||
llvmAsmlval.FPVal = new APFloat(APInt(80, 2, Pair));
|
||||
return FPVAL;
|
||||
case 'L':
|
||||
// F128HexFPConstant - IEEE 128-bit in hexadecimal format (16 bytes)
|
||||
llvmAsmlval.FPVal = new APFloat(APInt(128, 2, Pair), true);
|
||||
return FPVAL;
|
||||
case 'M':
|
||||
// PPC128HexFPConstant - PowerPC 128-bit in hexadecimal format (16 bytes)
|
||||
llvmAsmlval.FPVal = new APFloat(APInt(128, 2, Pair));
|
||||
return FPVAL;
|
||||
}
|
||||
}
|
||||
|
||||
/// LexIdentifier: Handle several related productions:
|
||||
/// Label [-a-zA-Z$._0-9]+:
|
||||
/// NInteger -[0-9]+
|
||||
/// FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
|
||||
/// PInteger [0-9]+
|
||||
/// HexFPConstant 0x[0-9A-Fa-f]+
|
||||
/// HexFP80Constant 0xK[0-9A-Fa-f]+
|
||||
/// HexFP128Constant 0xL[0-9A-Fa-f]+
|
||||
/// HexPPC128Constant 0xM[0-9A-Fa-f]+
|
||||
int LLLexer::LexDigitOrNegative() {
|
||||
// If the letter after the negative is a number, this is probably a label.
|
||||
if (!isdigit(TokStart[0]) && !isdigit(CurPtr[0])) {
|
||||
// Okay, this is not a number after the -, it's probably a label.
|
||||
if (const char *End = isLabelTail(CurPtr)) {
|
||||
llvmAsmlval.StrVal = new std::string(TokStart, End-1);
|
||||
CurPtr = End;
|
||||
return LABELSTR;
|
||||
}
|
||||
|
||||
return CurPtr[-1];
|
||||
}
|
||||
|
||||
// At this point, it is either a label, int or fp constant.
|
||||
|
||||
// Skip digits, we have at least one.
|
||||
for (; isdigit(CurPtr[0]); ++CurPtr);
|
||||
|
||||
// Check to see if this really is a label afterall, e.g. "-1:".
|
||||
if (isLabelChar(CurPtr[0]) || CurPtr[0] == ':') {
|
||||
if (const char *End = isLabelTail(CurPtr)) {
|
||||
llvmAsmlval.StrVal = new std::string(TokStart, End-1);
|
||||
CurPtr = End;
|
||||
return LABELSTR;
|
||||
}
|
||||
}
|
||||
|
||||
// If the next character is a '.', then it is a fp value, otherwise its
|
||||
// integer.
|
||||
if (CurPtr[0] != '.') {
|
||||
if (TokStart[0] == '0' && TokStart[1] == 'x')
|
||||
return Lex0x();
|
||||
unsigned Len = CurPtr-TokStart;
|
||||
uint32_t numBits = ((Len * 64) / 19) + 2;
|
||||
APInt Tmp(numBits, TokStart, Len, 10);
|
||||
if (TokStart[0] == '-') {
|
||||
uint32_t minBits = Tmp.getMinSignedBits();
|
||||
if (minBits > 0 && minBits < numBits)
|
||||
Tmp.trunc(minBits);
|
||||
if (Tmp.getBitWidth() > 64) {
|
||||
llvmAsmlval.APIntVal = new APInt(Tmp);
|
||||
return ESAPINTVAL;
|
||||
} else {
|
||||
llvmAsmlval.SInt64Val = Tmp.getSExtValue();
|
||||
return ESINT64VAL;
|
||||
}
|
||||
} else {
|
||||
uint32_t activeBits = Tmp.getActiveBits();
|
||||
if (activeBits > 0 && activeBits < numBits)
|
||||
Tmp.trunc(activeBits);
|
||||
if (Tmp.getBitWidth() > 64) {
|
||||
llvmAsmlval.APIntVal = new APInt(Tmp);
|
||||
return EUAPINTVAL;
|
||||
} else {
|
||||
llvmAsmlval.UInt64Val = Tmp.getZExtValue();
|
||||
return EUINT64VAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
++CurPtr;
|
||||
|
||||
// Skip over [0-9]*([eE][-+]?[0-9]+)?
|
||||
while (isdigit(CurPtr[0])) ++CurPtr;
|
||||
|
||||
if (CurPtr[0] == 'e' || CurPtr[0] == 'E') {
|
||||
if (isdigit(CurPtr[1]) ||
|
||||
((CurPtr[1] == '-' || CurPtr[1] == '+') && isdigit(CurPtr[2]))) {
|
||||
CurPtr += 2;
|
||||
while (isdigit(CurPtr[0])) ++CurPtr;
|
||||
}
|
||||
}
|
||||
|
||||
llvmAsmlval.FPVal = new APFloat(atof(TokStart));
|
||||
return FPVAL;
|
||||
}
|
||||
|
||||
/// FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
|
||||
int LLLexer::LexPositive() {
|
||||
// If the letter after the negative is a number, this is probably not a
|
||||
// label.
|
||||
if (!isdigit(CurPtr[0]))
|
||||
return CurPtr[-1];
|
||||
|
||||
// Skip digits.
|
||||
for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr);
|
||||
|
||||
// At this point, we need a '.'.
|
||||
if (CurPtr[0] != '.') {
|
||||
CurPtr = TokStart+1;
|
||||
return TokStart[0];
|
||||
}
|
||||
|
||||
++CurPtr;
|
||||
|
||||
// Skip over [0-9]*([eE][-+]?[0-9]+)?
|
||||
while (isdigit(CurPtr[0])) ++CurPtr;
|
||||
|
||||
if (CurPtr[0] == 'e' || CurPtr[0] == 'E') {
|
||||
if (isdigit(CurPtr[1]) ||
|
||||
((CurPtr[1] == '-' || CurPtr[1] == '+') && isdigit(CurPtr[2]))) {
|
||||
CurPtr += 2;
|
||||
while (isdigit(CurPtr[0])) ++CurPtr;
|
||||
}
|
||||
}
|
||||
|
||||
llvmAsmlval.FPVal = new APFloat(atof(TokStart));
|
||||
return FPVAL;
|
||||
}
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Define the interface to this file.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
static LLLexer *TheLexer;
|
||||
|
||||
void InitLLLexer(llvm::MemoryBuffer *MB) {
|
||||
assert(TheLexer == 0 && "LL Lexer isn't reentrant yet");
|
||||
TheLexer = new LLLexer(MB);
|
||||
}
|
||||
|
||||
int llvmAsmlex() {
|
||||
return TheLexer->LexToken();
|
||||
}
|
||||
const char *LLLgetTokenStart() { return TheLexer->getTokStart(); }
|
||||
unsigned LLLgetTokenLength() { return TheLexer->getTokLength(); }
|
||||
std::string LLLgetFilename() { return TheLexer->getFilename(); }
|
||||
unsigned LLLgetLineNo() { return TheLexer->getLineNo(); }
|
||||
|
||||
void FreeLexer() {
|
||||
delete TheLexer;
|
||||
TheLexer = 0;
|
||||
}
|
57
lib/AsmParser/LLLexer.h
Normal file
57
lib/AsmParser/LLLexer.h
Normal file
@ -0,0 +1,57 @@
|
||||
//===- LLLexer.h - Lexer for LLVM Assembly Files ----------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file was developed by Chris Lattner and is distributed under
|
||||
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This class represents the Lexer for .ll files.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LIB_ASMPARSER_LLLEXER_H
|
||||
#define LIB_ASMPARSER_LLLEXER_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <iosfwd>
|
||||
|
||||
namespace llvm {
|
||||
class MemoryBuffer;
|
||||
|
||||
class LLLexer {
|
||||
const char *CurPtr;
|
||||
unsigned CurLineNo;
|
||||
MemoryBuffer *CurBuf;
|
||||
|
||||
const char *TokStart;
|
||||
|
||||
std::string TheError;
|
||||
public:
|
||||
LLLexer(MemoryBuffer *StartBuf);
|
||||
~LLLexer() {}
|
||||
|
||||
const char *getTokStart() const { return TokStart; }
|
||||
unsigned getTokLength() const { return CurPtr-TokStart; }
|
||||
unsigned getLineNo() const { return CurLineNo; }
|
||||
std::string getFilename() const;
|
||||
int LexToken();
|
||||
|
||||
const std::string getError() const { return TheError; }
|
||||
|
||||
private:
|
||||
int getNextChar();
|
||||
void SkipLineComment();
|
||||
int LexIdentifier();
|
||||
int LexDigitOrNegative();
|
||||
int LexPositive();
|
||||
int LexAt();
|
||||
int LexPercent();
|
||||
int LexQuote();
|
||||
int Lex0x();
|
||||
};
|
||||
} // end namespace llvm
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
@ -1,512 +0,0 @@
|
||||
/*===-- Lexer.l - Scanner for llvm assembly files --------------*- C++ -*--===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file was developed by the LLVM research group and is distributed under
|
||||
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file implements the flex scanner for LLVM assembly languages files.
|
||||
//
|
||||
//===----------------------------------------------------------------------===*/
|
||||
|
||||
%option prefix="llvmAsm"
|
||||
%option yylineno
|
||||
%option nostdinit
|
||||
%option never-interactive
|
||||
%option batch
|
||||
%option noyywrap
|
||||
%option nodefault
|
||||
%option 8bit
|
||||
%option outfile="Lexer.cpp"
|
||||
%option ecs
|
||||
%option noreject
|
||||
%option noyymore
|
||||
|
||||
%{
|
||||
#include "ParserInternals.h"
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/Support/MathExtras.h"
|
||||
#include <list>
|
||||
#include "llvmAsmParser.h"
|
||||
#include <cctype>
|
||||
#include <cstdlib>
|
||||
|
||||
void set_scan_file(FILE * F){
|
||||
yy_switch_to_buffer(yy_create_buffer( F, YY_BUF_SIZE ) );
|
||||
}
|
||||
void set_scan_string (const char * str) {
|
||||
yy_scan_string (str);
|
||||
}
|
||||
|
||||
// Construct a token value for a non-obsolete token
|
||||
#define RET_TOK(type, Enum, sym) \
|
||||
llvmAsmlval.type = Instruction::Enum; \
|
||||
return sym
|
||||
|
||||
// Construct a token value for an obsolete token
|
||||
#define RET_TY(CTYPE, SYM) \
|
||||
llvmAsmlval.PrimType = CTYPE;\
|
||||
return SYM
|
||||
|
||||
namespace llvm {
|
||||
|
||||
// TODO: All of the static identifiers are figured out by the lexer,
|
||||
// these should be hashed to reduce the lexer size
|
||||
|
||||
|
||||
// atoull - Convert an ascii string of decimal digits into the unsigned long
|
||||
// long representation... this does not have to do input error checking,
|
||||
// because we know that the input will be matched by a suitable regex...
|
||||
//
|
||||
static uint64_t atoull(const char *Buffer) {
|
||||
uint64_t Result = 0;
|
||||
for (; *Buffer; Buffer++) {
|
||||
uint64_t OldRes = Result;
|
||||
Result *= 10;
|
||||
Result += *Buffer-'0';
|
||||
if (Result < OldRes) // Uh, oh, overflow detected!!!
|
||||
GenerateError("constant bigger than 64 bits detected!");
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
static uint64_t HexIntToVal(const char *Buffer) {
|
||||
uint64_t Result = 0;
|
||||
for (; *Buffer; ++Buffer) {
|
||||
uint64_t OldRes = Result;
|
||||
Result *= 16;
|
||||
char C = *Buffer;
|
||||
if (C >= '0' && C <= '9')
|
||||
Result += C-'0';
|
||||
else if (C >= 'A' && C <= 'F')
|
||||
Result += C-'A'+10;
|
||||
else if (C >= 'a' && C <= 'f')
|
||||
Result += C-'a'+10;
|
||||
|
||||
if (Result < OldRes) // Uh, oh, overflow detected!!!
|
||||
GenerateError("constant bigger than 64 bits detected!");
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
// HexToFP - Convert the ascii string in hexadecimal format to the floating
|
||||
// point representation of it.
|
||||
//
|
||||
static double HexToFP(const char *Buffer) {
|
||||
return BitsToDouble(HexIntToVal(Buffer)); // Cast Hex constant to double
|
||||
}
|
||||
|
||||
static void HexToIntPair(const char *Buffer, uint64_t Pair[2]) {
|
||||
Pair[0] = 0;
|
||||
for (int i=0; i<16; i++, Buffer++) {
|
||||
assert(*Buffer);
|
||||
Pair[0] *= 16;
|
||||
char C = *Buffer;
|
||||
if (C >= '0' && C <= '9')
|
||||
Pair[0] += C-'0';
|
||||
else if (C >= 'A' && C <= 'F')
|
||||
Pair[0] += C-'A'+10;
|
||||
else if (C >= 'a' && C <= 'f')
|
||||
Pair[0] += C-'a'+10;
|
||||
}
|
||||
Pair[1] = 0;
|
||||
for (int i=0; i<16 && *Buffer; i++, Buffer++) {
|
||||
Pair[1] *= 16;
|
||||
char C = *Buffer;
|
||||
if (C >= '0' && C <= '9')
|
||||
Pair[1] += C-'0';
|
||||
else if (C >= 'A' && C <= 'F')
|
||||
Pair[1] += C-'A'+10;
|
||||
else if (C >= 'a' && C <= 'f')
|
||||
Pair[1] += C-'a'+10;
|
||||
}
|
||||
if (*Buffer)
|
||||
GenerateError("constant bigger than 128 bits detected!");
|
||||
}
|
||||
|
||||
// UnEscapeLexed - Run through the specified buffer and change \xx codes to the
|
||||
// appropriate character.
|
||||
char *UnEscapeLexed(char *Buffer, char* EndBuffer) {
|
||||
char *BOut = Buffer;
|
||||
for (char *BIn = Buffer; *BIn; ) {
|
||||
if (BIn[0] == '\\') {
|
||||
if (BIn < EndBuffer-1 && BIn[1] == '\\') {
|
||||
*BOut++ = '\\'; // Two \ becomes one
|
||||
BIn += 2;
|
||||
} else if (BIn < EndBuffer-2 && isxdigit(BIn[1]) && isxdigit(BIn[2])) {
|
||||
char Tmp = BIn[3]; BIn[3] = 0; // Terminate string
|
||||
*BOut = (char)strtol(BIn+1, 0, 16); // Convert to number
|
||||
BIn[3] = Tmp; // Restore character
|
||||
BIn += 3; // Skip over handled chars
|
||||
++BOut;
|
||||
} else {
|
||||
*BOut++ = *BIn++;
|
||||
}
|
||||
} else {
|
||||
*BOut++ = *BIn++;
|
||||
}
|
||||
}
|
||||
return BOut;
|
||||
}
|
||||
|
||||
} // End llvm namespace
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
#define YY_NEVER_INTERACTIVE 1
|
||||
%}
|
||||
|
||||
|
||||
|
||||
/* Comments start with a ; and go till end of line */
|
||||
Comment ;.*
|
||||
|
||||
/* Local Values and Type identifiers start with a % sign */
|
||||
LocalVarName %[-a-zA-Z$._][-a-zA-Z$._0-9]*
|
||||
|
||||
/* Global Value identifiers start with an @ sign */
|
||||
GlobalVarName @[-a-zA-Z$._][-a-zA-Z$._0-9]*
|
||||
|
||||
/* Label identifiers end with a colon */
|
||||
Label [-a-zA-Z$._0-9]+:
|
||||
QuoteLabel \"[^\"]+\":
|
||||
|
||||
/* Quoted names can contain any character except " and \ */
|
||||
StringConstant \"[^\"]*\"
|
||||
AtStringConstant @\"[^\"]*\"
|
||||
PctStringConstant %\"[^\"]*\"
|
||||
|
||||
/* LocalVarID/GlobalVarID: match an unnamed local variable slot ID. */
|
||||
LocalVarID %[0-9]+
|
||||
GlobalVarID @[0-9]+
|
||||
|
||||
/* Integer types are specified with i and a bitwidth */
|
||||
IntegerType i[0-9]+
|
||||
|
||||
/* E[PN]Integer: match positive and negative literal integer values. */
|
||||
PInteger [0-9]+
|
||||
NInteger -[0-9]+
|
||||
|
||||
/* FPConstant - A Floating point constant. Float and double only.
|
||||
*/
|
||||
FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
|
||||
|
||||
/* HexFPConstant - Floating point constant represented in IEEE format as a
|
||||
* hexadecimal number for when exponential notation is not precise enough.
|
||||
* Float and double only.
|
||||
*/
|
||||
HexFPConstant 0x[0-9A-Fa-f]+
|
||||
|
||||
/* F80HexFPConstant - x87 long double in hexadecimal format (10 bytes)
|
||||
*/
|
||||
HexFP80Constant 0xK[0-9A-Fa-f]+
|
||||
|
||||
/* F128HexFPConstant - IEEE 128-bit in hexadecimal format (16 bytes)
|
||||
*/
|
||||
HexFP128Constant 0xL[0-9A-Fa-f]+
|
||||
|
||||
/* PPC128HexFPConstant - PowerPC 128-bit in hexadecimal format (16 bytes)
|
||||
*/
|
||||
HexPPC128Constant 0xM[0-9A-Fa-f]+
|
||||
|
||||
/* HexIntConstant - Hexadecimal constant generated by the CFE to avoid forcing
|
||||
* it to deal with 64 bit numbers.
|
||||
*/
|
||||
HexIntConstant [us]0x[0-9A-Fa-f]+
|
||||
|
||||
/* WSNL - shorthand for whitespace followed by newline */
|
||||
WSNL [ \r\t]*$
|
||||
%%
|
||||
|
||||
{Comment} { /* Ignore comments for now */ }
|
||||
|
||||
begin { return BEGINTOK; }
|
||||
end { return ENDTOK; }
|
||||
true { return TRUETOK; }
|
||||
false { return FALSETOK; }
|
||||
declare { return DECLARE; }
|
||||
define { return DEFINE; }
|
||||
global { return GLOBAL; }
|
||||
constant { return CONSTANT; }
|
||||
internal { return INTERNAL; }
|
||||
linkonce { return LINKONCE; }
|
||||
weak { return WEAK; }
|
||||
appending { return APPENDING; }
|
||||
dllimport { return DLLIMPORT; }
|
||||
dllexport { return DLLEXPORT; }
|
||||
hidden { return HIDDEN; }
|
||||
protected { return PROTECTED; }
|
||||
extern_weak { return EXTERN_WEAK; }
|
||||
external { return EXTERNAL; }
|
||||
thread_local { return THREAD_LOCAL; }
|
||||
zeroinitializer { return ZEROINITIALIZER; }
|
||||
\.\.\. { return DOTDOTDOT; }
|
||||
undef { return UNDEF; }
|
||||
null { return NULL_TOK; }
|
||||
to { return TO; }
|
||||
tail { return TAIL; }
|
||||
target { return TARGET; }
|
||||
triple { return TRIPLE; }
|
||||
deplibs { return DEPLIBS; }
|
||||
datalayout { return DATALAYOUT; }
|
||||
volatile { return VOLATILE; }
|
||||
align { return ALIGN; }
|
||||
section { return SECTION; }
|
||||
alias { return ALIAS; }
|
||||
module { return MODULE; }
|
||||
asm { return ASM_TOK; }
|
||||
sideeffect { return SIDEEFFECT; }
|
||||
|
||||
cc { return CC_TOK; }
|
||||
ccc { return CCC_TOK; }
|
||||
fastcc { return FASTCC_TOK; }
|
||||
coldcc { return COLDCC_TOK; }
|
||||
x86_stdcallcc { return X86_STDCALLCC_TOK; }
|
||||
x86_fastcallcc { return X86_FASTCALLCC_TOK; }
|
||||
|
||||
signext { return SIGNEXT; }
|
||||
zeroext { return ZEROEXT; }
|
||||
inreg { return INREG; }
|
||||
sret { return SRET; }
|
||||
nounwind { return NOUNWIND; }
|
||||
noreturn { return NORETURN; }
|
||||
noalias { return NOALIAS; }
|
||||
byval { return BYVAL; }
|
||||
nest { return NEST; }
|
||||
pure { return PURE; }
|
||||
const { return CONST; }
|
||||
sext{WSNL} { // For auto-upgrade only, drop in LLVM 3.0
|
||||
return SIGNEXT; }
|
||||
zext{WSNL} { // For auto-upgrade only, drop in LLVM 3.0
|
||||
return ZEROEXT; }
|
||||
|
||||
void { RET_TY(Type::VoidTy, VOID); }
|
||||
float { RET_TY(Type::FloatTy, FLOAT); }
|
||||
double { RET_TY(Type::DoubleTy,DOUBLE);}
|
||||
x86_fp80 { RET_TY(Type::X86_FP80Ty, X86_FP80);}
|
||||
fp128 { RET_TY(Type::FP128Ty, FP128);}
|
||||
ppc_fp128 { RET_TY(Type::PPC_FP128Ty, PPC_FP128);}
|
||||
label { RET_TY(Type::LabelTy, LABEL); }
|
||||
type { return TYPE; }
|
||||
opaque { return OPAQUE; }
|
||||
{IntegerType} { uint64_t NumBits = atoull(yytext+1);
|
||||
if (NumBits < IntegerType::MIN_INT_BITS ||
|
||||
NumBits > IntegerType::MAX_INT_BITS)
|
||||
GenerateError("Bitwidth for integer type out of range!");
|
||||
const Type* Ty = IntegerType::get(NumBits);
|
||||
RET_TY(Ty, INTTYPE);
|
||||
}
|
||||
|
||||
add { RET_TOK(BinaryOpVal, Add, ADD); }
|
||||
sub { RET_TOK(BinaryOpVal, Sub, SUB); }
|
||||
mul { RET_TOK(BinaryOpVal, Mul, MUL); }
|
||||
udiv { RET_TOK(BinaryOpVal, UDiv, UDIV); }
|
||||
sdiv { RET_TOK(BinaryOpVal, SDiv, SDIV); }
|
||||
fdiv { RET_TOK(BinaryOpVal, FDiv, FDIV); }
|
||||
urem { RET_TOK(BinaryOpVal, URem, UREM); }
|
||||
srem { RET_TOK(BinaryOpVal, SRem, SREM); }
|
||||
frem { RET_TOK(BinaryOpVal, FRem, FREM); }
|
||||
shl { RET_TOK(BinaryOpVal, Shl, SHL); }
|
||||
lshr { RET_TOK(BinaryOpVal, LShr, LSHR); }
|
||||
ashr { RET_TOK(BinaryOpVal, AShr, ASHR); }
|
||||
and { RET_TOK(BinaryOpVal, And, AND); }
|
||||
or { RET_TOK(BinaryOpVal, Or , OR ); }
|
||||
xor { RET_TOK(BinaryOpVal, Xor, XOR); }
|
||||
icmp { RET_TOK(OtherOpVal, ICmp, ICMP); }
|
||||
fcmp { RET_TOK(OtherOpVal, FCmp, FCMP); }
|
||||
|
||||
eq { return EQ; }
|
||||
ne { return NE; }
|
||||
slt { return SLT; }
|
||||
sgt { return SGT; }
|
||||
sle { return SLE; }
|
||||
sge { return SGE; }
|
||||
ult { return ULT; }
|
||||
ugt { return UGT; }
|
||||
ule { return ULE; }
|
||||
uge { return UGE; }
|
||||
oeq { return OEQ; }
|
||||
one { return ONE; }
|
||||
olt { return OLT; }
|
||||
ogt { return OGT; }
|
||||
ole { return OLE; }
|
||||
oge { return OGE; }
|
||||
ord { return ORD; }
|
||||
uno { return UNO; }
|
||||
ueq { return UEQ; }
|
||||
une { return UNE; }
|
||||
|
||||
phi { RET_TOK(OtherOpVal, PHI, PHI_TOK); }
|
||||
call { RET_TOK(OtherOpVal, Call, CALL); }
|
||||
trunc { RET_TOK(CastOpVal, Trunc, TRUNC); }
|
||||
zext { RET_TOK(CastOpVal, ZExt, ZEXT); }
|
||||
sext { RET_TOK(CastOpVal, SExt, SEXT); }
|
||||
fptrunc { RET_TOK(CastOpVal, FPTrunc, FPTRUNC); }
|
||||
fpext { RET_TOK(CastOpVal, FPExt, FPEXT); }
|
||||
uitofp { RET_TOK(CastOpVal, UIToFP, UITOFP); }
|
||||
sitofp { RET_TOK(CastOpVal, SIToFP, SITOFP); }
|
||||
fptoui { RET_TOK(CastOpVal, FPToUI, FPTOUI); }
|
||||
fptosi { RET_TOK(CastOpVal, FPToSI, FPTOSI); }
|
||||
inttoptr { RET_TOK(CastOpVal, IntToPtr, INTTOPTR); }
|
||||
ptrtoint { RET_TOK(CastOpVal, PtrToInt, PTRTOINT); }
|
||||
bitcast { RET_TOK(CastOpVal, BitCast, BITCAST); }
|
||||
select { RET_TOK(OtherOpVal, Select, SELECT); }
|
||||
va_arg { RET_TOK(OtherOpVal, VAArg , VAARG); }
|
||||
ret { RET_TOK(TermOpVal, Ret, RET); }
|
||||
br { RET_TOK(TermOpVal, Br, BR); }
|
||||
switch { RET_TOK(TermOpVal, Switch, SWITCH); }
|
||||
invoke { RET_TOK(TermOpVal, Invoke, INVOKE); }
|
||||
unwind { RET_TOK(TermOpVal, Unwind, UNWIND); }
|
||||
unreachable { RET_TOK(TermOpVal, Unreachable, UNREACHABLE); }
|
||||
|
||||
malloc { RET_TOK(MemOpVal, Malloc, MALLOC); }
|
||||
alloca { RET_TOK(MemOpVal, Alloca, ALLOCA); }
|
||||
free { RET_TOK(MemOpVal, Free, FREE); }
|
||||
load { RET_TOK(MemOpVal, Load, LOAD); }
|
||||
store { RET_TOK(MemOpVal, Store, STORE); }
|
||||
getelementptr { RET_TOK(MemOpVal, GetElementPtr, GETELEMENTPTR); }
|
||||
|
||||
extractelement { RET_TOK(OtherOpVal, ExtractElement, EXTRACTELEMENT); }
|
||||
insertelement { RET_TOK(OtherOpVal, InsertElement, INSERTELEMENT); }
|
||||
shufflevector { RET_TOK(OtherOpVal, ShuffleVector, SHUFFLEVECTOR); }
|
||||
|
||||
|
||||
{LocalVarName} {
|
||||
llvmAsmlval.StrVal = new std::string(yytext+1); // Skip %
|
||||
return LOCALVAR;
|
||||
}
|
||||
{GlobalVarName} {
|
||||
llvmAsmlval.StrVal = new std::string(yytext+1); // Skip @
|
||||
return GLOBALVAR;
|
||||
}
|
||||
{Label} {
|
||||
yytext[yyleng-1] = 0; // nuke colon
|
||||
llvmAsmlval.StrVal = new std::string(yytext);
|
||||
return LABELSTR;
|
||||
}
|
||||
{QuoteLabel} {
|
||||
yytext[yyleng-2] = 0; // nuke colon, end quote
|
||||
const char* EndChar = UnEscapeLexed(yytext+1, yytext+yyleng);
|
||||
llvmAsmlval.StrVal =
|
||||
new std::string(yytext+1, EndChar - yytext - 1);
|
||||
return LABELSTR;
|
||||
}
|
||||
|
||||
{StringConstant} { yytext[yyleng-1] = 0; // nuke end quote
|
||||
const char* EndChar = UnEscapeLexed(yytext+1, yytext+yyleng);
|
||||
llvmAsmlval.StrVal =
|
||||
new std::string(yytext+1, EndChar - yytext - 1);
|
||||
return STRINGCONSTANT;
|
||||
}
|
||||
{AtStringConstant} {
|
||||
yytext[yyleng-1] = 0; // nuke end quote
|
||||
const char* EndChar =
|
||||
UnEscapeLexed(yytext+2, yytext+yyleng);
|
||||
llvmAsmlval.StrVal =
|
||||
new std::string(yytext+2, EndChar - yytext - 2);
|
||||
return ATSTRINGCONSTANT;
|
||||
}
|
||||
{PctStringConstant} {
|
||||
yytext[yyleng-1] = 0; // nuke end quote
|
||||
const char* EndChar =
|
||||
UnEscapeLexed(yytext+2, yytext+yyleng);
|
||||
llvmAsmlval.StrVal =
|
||||
new std::string(yytext+2, EndChar - yytext - 2);
|
||||
return PCTSTRINGCONSTANT;
|
||||
}
|
||||
{PInteger} {
|
||||
uint32_t numBits = ((yyleng * 64) / 19) + 1;
|
||||
APInt Tmp(numBits, yytext, yyleng, 10);
|
||||
uint32_t activeBits = Tmp.getActiveBits();
|
||||
if (activeBits > 0 && activeBits < numBits)
|
||||
Tmp.trunc(activeBits);
|
||||
if (Tmp.getBitWidth() > 64) {
|
||||
llvmAsmlval.APIntVal = new APInt(Tmp);
|
||||
return EUAPINTVAL;
|
||||
} else {
|
||||
llvmAsmlval.UInt64Val = Tmp.getZExtValue();
|
||||
return EUINT64VAL;
|
||||
}
|
||||
}
|
||||
{NInteger} {
|
||||
uint32_t numBits = (((yyleng-1) * 64) / 19) + 2;
|
||||
APInt Tmp(numBits, yytext, yyleng, 10);
|
||||
uint32_t minBits = Tmp.getMinSignedBits();
|
||||
if (minBits > 0 && minBits < numBits)
|
||||
Tmp.trunc(minBits);
|
||||
if (Tmp.getBitWidth() > 64) {
|
||||
llvmAsmlval.APIntVal = new APInt(Tmp);
|
||||
return ESAPINTVAL;
|
||||
} else {
|
||||
llvmAsmlval.SInt64Val = Tmp.getSExtValue();
|
||||
return ESINT64VAL;
|
||||
}
|
||||
}
|
||||
|
||||
{HexIntConstant} { int len = yyleng - 3;
|
||||
uint32_t bits = len * 4;
|
||||
APInt Tmp(bits, yytext+3, len, 16);
|
||||
uint32_t activeBits = Tmp.getActiveBits();
|
||||
if (activeBits > 0 && activeBits < bits)
|
||||
Tmp.trunc(activeBits);
|
||||
if (Tmp.getBitWidth() > 64) {
|
||||
llvmAsmlval.APIntVal = new APInt(Tmp);
|
||||
return yytext[0] == 's' ? ESAPINTVAL : EUAPINTVAL;
|
||||
} else if (yytext[0] == 's') {
|
||||
llvmAsmlval.SInt64Val = Tmp.getSExtValue();
|
||||
return ESINT64VAL;
|
||||
} else {
|
||||
llvmAsmlval.UInt64Val = Tmp.getZExtValue();
|
||||
return EUINT64VAL;
|
||||
}
|
||||
}
|
||||
|
||||
{LocalVarID} {
|
||||
uint64_t Val = atoull(yytext+1);
|
||||
if ((unsigned)Val != Val)
|
||||
GenerateError("Invalid value number (too large)!");
|
||||
llvmAsmlval.UIntVal = unsigned(Val);
|
||||
return LOCALVAL_ID;
|
||||
}
|
||||
{GlobalVarID} {
|
||||
uint64_t Val = atoull(yytext+1);
|
||||
if ((unsigned)Val != Val)
|
||||
GenerateError("Invalid value number (too large)!");
|
||||
llvmAsmlval.UIntVal = unsigned(Val);
|
||||
return GLOBALVAL_ID;
|
||||
}
|
||||
|
||||
{FPConstant} { llvmAsmlval.FPVal = new APFloat(atof(yytext)); return FPVAL; }
|
||||
{HexFPConstant} { llvmAsmlval.FPVal = new APFloat(HexToFP(yytext+2));
|
||||
return FPVAL;
|
||||
}
|
||||
{HexFP80Constant} { uint64_t Pair[2];
|
||||
HexToIntPair(yytext+3, Pair);
|
||||
llvmAsmlval.FPVal = new APFloat(APInt(80, 2, Pair));
|
||||
return FPVAL;
|
||||
}
|
||||
{HexFP128Constant} { uint64_t Pair[2];
|
||||
HexToIntPair(yytext+3, Pair);
|
||||
llvmAsmlval.FPVal = new APFloat(APInt(128, 2, Pair), true);
|
||||
return FPVAL;
|
||||
}
|
||||
{HexPPC128Constant} { uint64_t Pair[2];
|
||||
HexToIntPair(yytext+3, Pair);
|
||||
llvmAsmlval.FPVal = new APFloat(APInt(128, 2, Pair));
|
||||
return FPVAL;
|
||||
}
|
||||
|
||||
<<EOF>> {
|
||||
/* Make sure to free the internal buffers for flex when we are
|
||||
* done reading our input!
|
||||
*/
|
||||
yy_delete_buffer(YY_CURRENT_BUFFER);
|
||||
return EOF;
|
||||
}
|
||||
|
||||
[ \r\t\n] { /* Ignore whitespace */ }
|
||||
. { return yytext[0]; }
|
||||
|
||||
%%
|
@ -1,512 +0,0 @@
|
||||
/*===-- Lexer.l - Scanner for llvm assembly files --------------*- C++ -*--===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file was developed by the LLVM research group and is distributed under
|
||||
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file implements the flex scanner for LLVM assembly languages files.
|
||||
//
|
||||
//===----------------------------------------------------------------------===*/
|
||||
|
||||
%option prefix="llvmAsm"
|
||||
%option yylineno
|
||||
%option nostdinit
|
||||
%option never-interactive
|
||||
%option batch
|
||||
%option noyywrap
|
||||
%option nodefault
|
||||
%option 8bit
|
||||
%option outfile="Lexer.cpp"
|
||||
%option ecs
|
||||
%option noreject
|
||||
%option noyymore
|
||||
|
||||
%{
|
||||
#include "ParserInternals.h"
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/Support/MathExtras.h"
|
||||
#include <list>
|
||||
#include "llvmAsmParser.h"
|
||||
#include <cctype>
|
||||
#include <cstdlib>
|
||||
|
||||
void set_scan_file(FILE * F){
|
||||
yy_switch_to_buffer(yy_create_buffer( F, YY_BUF_SIZE ) );
|
||||
}
|
||||
void set_scan_string (const char * str) {
|
||||
yy_scan_string (str);
|
||||
}
|
||||
|
||||
// Construct a token value for a non-obsolete token
|
||||
#define RET_TOK(type, Enum, sym) \
|
||||
llvmAsmlval.type = Instruction::Enum; \
|
||||
return sym
|
||||
|
||||
// Construct a token value for an obsolete token
|
||||
#define RET_TY(CTYPE, SYM) \
|
||||
llvmAsmlval.PrimType = CTYPE;\
|
||||
return SYM
|
||||
|
||||
namespace llvm {
|
||||
|
||||
// TODO: All of the static identifiers are figured out by the lexer,
|
||||
// these should be hashed to reduce the lexer size
|
||||
|
||||
|
||||
// atoull - Convert an ascii string of decimal digits into the unsigned long
|
||||
// long representation... this does not have to do input error checking,
|
||||
// because we know that the input will be matched by a suitable regex...
|
||||
//
|
||||
static uint64_t atoull(const char *Buffer) {
|
||||
uint64_t Result = 0;
|
||||
for (; *Buffer; Buffer++) {
|
||||
uint64_t OldRes = Result;
|
||||
Result *= 10;
|
||||
Result += *Buffer-'0';
|
||||
if (Result < OldRes) // Uh, oh, overflow detected!!!
|
||||
GenerateError("constant bigger than 64 bits detected!");
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
static uint64_t HexIntToVal(const char *Buffer) {
|
||||
uint64_t Result = 0;
|
||||
for (; *Buffer; ++Buffer) {
|
||||
uint64_t OldRes = Result;
|
||||
Result *= 16;
|
||||
char C = *Buffer;
|
||||
if (C >= '0' && C <= '9')
|
||||
Result += C-'0';
|
||||
else if (C >= 'A' && C <= 'F')
|
||||
Result += C-'A'+10;
|
||||
else if (C >= 'a' && C <= 'f')
|
||||
Result += C-'a'+10;
|
||||
|
||||
if (Result < OldRes) // Uh, oh, overflow detected!!!
|
||||
GenerateError("constant bigger than 64 bits detected!");
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
// HexToFP - Convert the ascii string in hexadecimal format to the floating
|
||||
// point representation of it.
|
||||
//
|
||||
static double HexToFP(const char *Buffer) {
|
||||
return BitsToDouble(HexIntToVal(Buffer)); // Cast Hex constant to double
|
||||
}
|
||||
|
||||
static void HexToIntPair(const char *Buffer, uint64_t Pair[2]) {
|
||||
Pair[0] = 0;
|
||||
for (int i=0; i<16; i++, Buffer++) {
|
||||
assert(*Buffer);
|
||||
Pair[0] *= 16;
|
||||
char C = *Buffer;
|
||||
if (C >= '0' && C <= '9')
|
||||
Pair[0] += C-'0';
|
||||
else if (C >= 'A' && C <= 'F')
|
||||
Pair[0] += C-'A'+10;
|
||||
else if (C >= 'a' && C <= 'f')
|
||||
Pair[0] += C-'a'+10;
|
||||
}
|
||||
Pair[1] = 0;
|
||||
for (int i=0; i<16 && *Buffer; i++, Buffer++) {
|
||||
Pair[1] *= 16;
|
||||
char C = *Buffer;
|
||||
if (C >= '0' && C <= '9')
|
||||
Pair[1] += C-'0';
|
||||
else if (C >= 'A' && C <= 'F')
|
||||
Pair[1] += C-'A'+10;
|
||||
else if (C >= 'a' && C <= 'f')
|
||||
Pair[1] += C-'a'+10;
|
||||
}
|
||||
if (*Buffer)
|
||||
GenerateError("constant bigger than 128 bits detected!");
|
||||
}
|
||||
|
||||
// UnEscapeLexed - Run through the specified buffer and change \xx codes to the
|
||||
// appropriate character.
|
||||
char *UnEscapeLexed(char *Buffer, char* EndBuffer) {
|
||||
char *BOut = Buffer;
|
||||
for (char *BIn = Buffer; *BIn; ) {
|
||||
if (BIn[0] == '\\') {
|
||||
if (BIn < EndBuffer-1 && BIn[1] == '\\') {
|
||||
*BOut++ = '\\'; // Two \ becomes one
|
||||
BIn += 2;
|
||||
} else if (BIn < EndBuffer-2 && isxdigit(BIn[1]) && isxdigit(BIn[2])) {
|
||||
char Tmp = BIn[3]; BIn[3] = 0; // Terminate string
|
||||
*BOut = (char)strtol(BIn+1, 0, 16); // Convert to number
|
||||
BIn[3] = Tmp; // Restore character
|
||||
BIn += 3; // Skip over handled chars
|
||||
++BOut;
|
||||
} else {
|
||||
*BOut++ = *BIn++;
|
||||
}
|
||||
} else {
|
||||
*BOut++ = *BIn++;
|
||||
}
|
||||
}
|
||||
return BOut;
|
||||
}
|
||||
|
||||
} // End llvm namespace
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
#define YY_NEVER_INTERACTIVE 1
|
||||
%}
|
||||
|
||||
|
||||
|
||||
/* Comments start with a ; and go till end of line */
|
||||
Comment ;.*
|
||||
|
||||
/* Local Values and Type identifiers start with a % sign */
|
||||
LocalVarName %[-a-zA-Z$._][-a-zA-Z$._0-9]*
|
||||
|
||||
/* Global Value identifiers start with an @ sign */
|
||||
GlobalVarName @[-a-zA-Z$._][-a-zA-Z$._0-9]*
|
||||
|
||||
/* Label identifiers end with a colon */
|
||||
Label [-a-zA-Z$._0-9]+:
|
||||
QuoteLabel \"[^\"]+\":
|
||||
|
||||
/* Quoted names can contain any character except " and \ */
|
||||
StringConstant \"[^\"]*\"
|
||||
AtStringConstant @\"[^\"]*\"
|
||||
PctStringConstant %\"[^\"]*\"
|
||||
|
||||
/* LocalVarID/GlobalVarID: match an unnamed local variable slot ID. */
|
||||
LocalVarID %[0-9]+
|
||||
GlobalVarID @[0-9]+
|
||||
|
||||
/* Integer types are specified with i and a bitwidth */
|
||||
IntegerType i[0-9]+
|
||||
|
||||
/* E[PN]Integer: match positive and negative literal integer values. */
|
||||
PInteger [0-9]+
|
||||
NInteger -[0-9]+
|
||||
|
||||
/* FPConstant - A Floating point constant. Float and double only.
|
||||
*/
|
||||
FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
|
||||
|
||||
/* HexFPConstant - Floating point constant represented in IEEE format as a
|
||||
* hexadecimal number for when exponential notation is not precise enough.
|
||||
* Float and double only.
|
||||
*/
|
||||
HexFPConstant 0x[0-9A-Fa-f]+
|
||||
|
||||
/* F80HexFPConstant - x87 long double in hexadecimal format (10 bytes)
|
||||
*/
|
||||
HexFP80Constant 0xK[0-9A-Fa-f]+
|
||||
|
||||
/* F128HexFPConstant - IEEE 128-bit in hexadecimal format (16 bytes)
|
||||
*/
|
||||
HexFP128Constant 0xL[0-9A-Fa-f]+
|
||||
|
||||
/* PPC128HexFPConstant - PowerPC 128-bit in hexadecimal format (16 bytes)
|
||||
*/
|
||||
HexPPC128Constant 0xM[0-9A-Fa-f]+
|
||||
|
||||
/* HexIntConstant - Hexadecimal constant generated by the CFE to avoid forcing
|
||||
* it to deal with 64 bit numbers.
|
||||
*/
|
||||
HexIntConstant [us]0x[0-9A-Fa-f]+
|
||||
|
||||
/* WSNL - shorthand for whitespace followed by newline */
|
||||
WSNL [ \r\t]*$
|
||||
%%
|
||||
|
||||
{Comment} { /* Ignore comments for now */ }
|
||||
|
||||
begin { return BEGINTOK; }
|
||||
end { return ENDTOK; }
|
||||
true { return TRUETOK; }
|
||||
false { return FALSETOK; }
|
||||
declare { return DECLARE; }
|
||||
define { return DEFINE; }
|
||||
global { return GLOBAL; }
|
||||
constant { return CONSTANT; }
|
||||
internal { return INTERNAL; }
|
||||
linkonce { return LINKONCE; }
|
||||
weak { return WEAK; }
|
||||
appending { return APPENDING; }
|
||||
dllimport { return DLLIMPORT; }
|
||||
dllexport { return DLLEXPORT; }
|
||||
hidden { return HIDDEN; }
|
||||
protected { return PROTECTED; }
|
||||
extern_weak { return EXTERN_WEAK; }
|
||||
external { return EXTERNAL; }
|
||||
thread_local { return THREAD_LOCAL; }
|
||||
zeroinitializer { return ZEROINITIALIZER; }
|
||||
\.\.\. { return DOTDOTDOT; }
|
||||
undef { return UNDEF; }
|
||||
null { return NULL_TOK; }
|
||||
to { return TO; }
|
||||
tail { return TAIL; }
|
||||
target { return TARGET; }
|
||||
triple { return TRIPLE; }
|
||||
deplibs { return DEPLIBS; }
|
||||
datalayout { return DATALAYOUT; }
|
||||
volatile { return VOLATILE; }
|
||||
align { return ALIGN; }
|
||||
section { return SECTION; }
|
||||
alias { return ALIAS; }
|
||||
module { return MODULE; }
|
||||
asm { return ASM_TOK; }
|
||||
sideeffect { return SIDEEFFECT; }
|
||||
|
||||
cc { return CC_TOK; }
|
||||
ccc { return CCC_TOK; }
|
||||
fastcc { return FASTCC_TOK; }
|
||||
coldcc { return COLDCC_TOK; }
|
||||
x86_stdcallcc { return X86_STDCALLCC_TOK; }
|
||||
x86_fastcallcc { return X86_FASTCALLCC_TOK; }
|
||||
|
||||
signext { return SIGNEXT; }
|
||||
zeroext { return ZEROEXT; }
|
||||
inreg { return INREG; }
|
||||
sret { return SRET; }
|
||||
nounwind { return NOUNWIND; }
|
||||
noreturn { return NORETURN; }
|
||||
noalias { return NOALIAS; }
|
||||
byval { return BYVAL; }
|
||||
nest { return NEST; }
|
||||
pure { return PURE; }
|
||||
const { return CONST; }
|
||||
sext{WSNL} { // For auto-upgrade only, drop in LLVM 3.0
|
||||
return SIGNEXT; }
|
||||
zext{WSNL} { // For auto-upgrade only, drop in LLVM 3.0
|
||||
return ZEROEXT; }
|
||||
|
||||
void { RET_TY(Type::VoidTy, VOID); }
|
||||
float { RET_TY(Type::FloatTy, FLOAT); }
|
||||
double { RET_TY(Type::DoubleTy,DOUBLE);}
|
||||
x86_fp80 { RET_TY(Type::X86_FP80Ty, X86_FP80);}
|
||||
fp128 { RET_TY(Type::FP128Ty, FP128);}
|
||||
ppc_fp128 { RET_TY(Type::PPC_FP128Ty, PPC_FP128);}
|
||||
label { RET_TY(Type::LabelTy, LABEL); }
|
||||
type { return TYPE; }
|
||||
opaque { return OPAQUE; }
|
||||
{IntegerType} { uint64_t NumBits = atoull(yytext+1);
|
||||
if (NumBits < IntegerType::MIN_INT_BITS ||
|
||||
NumBits > IntegerType::MAX_INT_BITS)
|
||||
GenerateError("Bitwidth for integer type out of range!");
|
||||
const Type* Ty = IntegerType::get(NumBits);
|
||||
RET_TY(Ty, INTTYPE);
|
||||
}
|
||||
|
||||
add { RET_TOK(BinaryOpVal, Add, ADD); }
|
||||
sub { RET_TOK(BinaryOpVal, Sub, SUB); }
|
||||
mul { RET_TOK(BinaryOpVal, Mul, MUL); }
|
||||
udiv { RET_TOK(BinaryOpVal, UDiv, UDIV); }
|
||||
sdiv { RET_TOK(BinaryOpVal, SDiv, SDIV); }
|
||||
fdiv { RET_TOK(BinaryOpVal, FDiv, FDIV); }
|
||||
urem { RET_TOK(BinaryOpVal, URem, UREM); }
|
||||
srem { RET_TOK(BinaryOpVal, SRem, SREM); }
|
||||
frem { RET_TOK(BinaryOpVal, FRem, FREM); }
|
||||
shl { RET_TOK(BinaryOpVal, Shl, SHL); }
|
||||
lshr { RET_TOK(BinaryOpVal, LShr, LSHR); }
|
||||
ashr { RET_TOK(BinaryOpVal, AShr, ASHR); }
|
||||
and { RET_TOK(BinaryOpVal, And, AND); }
|
||||
or { RET_TOK(BinaryOpVal, Or , OR ); }
|
||||
xor { RET_TOK(BinaryOpVal, Xor, XOR); }
|
||||
icmp { RET_TOK(OtherOpVal, ICmp, ICMP); }
|
||||
fcmp { RET_TOK(OtherOpVal, FCmp, FCMP); }
|
||||
|
||||
eq { return EQ; }
|
||||
ne { return NE; }
|
||||
slt { return SLT; }
|
||||
sgt { return SGT; }
|
||||
sle { return SLE; }
|
||||
sge { return SGE; }
|
||||
ult { return ULT; }
|
||||
ugt { return UGT; }
|
||||
ule { return ULE; }
|
||||
uge { return UGE; }
|
||||
oeq { return OEQ; }
|
||||
one { return ONE; }
|
||||
olt { return OLT; }
|
||||
ogt { return OGT; }
|
||||
ole { return OLE; }
|
||||
oge { return OGE; }
|
||||
ord { return ORD; }
|
||||
uno { return UNO; }
|
||||
ueq { return UEQ; }
|
||||
une { return UNE; }
|
||||
|
||||
phi { RET_TOK(OtherOpVal, PHI, PHI_TOK); }
|
||||
call { RET_TOK(OtherOpVal, Call, CALL); }
|
||||
trunc { RET_TOK(CastOpVal, Trunc, TRUNC); }
|
||||
zext { RET_TOK(CastOpVal, ZExt, ZEXT); }
|
||||
sext { RET_TOK(CastOpVal, SExt, SEXT); }
|
||||
fptrunc { RET_TOK(CastOpVal, FPTrunc, FPTRUNC); }
|
||||
fpext { RET_TOK(CastOpVal, FPExt, FPEXT); }
|
||||
uitofp { RET_TOK(CastOpVal, UIToFP, UITOFP); }
|
||||
sitofp { RET_TOK(CastOpVal, SIToFP, SITOFP); }
|
||||
fptoui { RET_TOK(CastOpVal, FPToUI, FPTOUI); }
|
||||
fptosi { RET_TOK(CastOpVal, FPToSI, FPTOSI); }
|
||||
inttoptr { RET_TOK(CastOpVal, IntToPtr, INTTOPTR); }
|
||||
ptrtoint { RET_TOK(CastOpVal, PtrToInt, PTRTOINT); }
|
||||
bitcast { RET_TOK(CastOpVal, BitCast, BITCAST); }
|
||||
select { RET_TOK(OtherOpVal, Select, SELECT); }
|
||||
va_arg { RET_TOK(OtherOpVal, VAArg , VAARG); }
|
||||
ret { RET_TOK(TermOpVal, Ret, RET); }
|
||||
br { RET_TOK(TermOpVal, Br, BR); }
|
||||
switch { RET_TOK(TermOpVal, Switch, SWITCH); }
|
||||
invoke { RET_TOK(TermOpVal, Invoke, INVOKE); }
|
||||
unwind { RET_TOK(TermOpVal, Unwind, UNWIND); }
|
||||
unreachable { RET_TOK(TermOpVal, Unreachable, UNREACHABLE); }
|
||||
|
||||
malloc { RET_TOK(MemOpVal, Malloc, MALLOC); }
|
||||
alloca { RET_TOK(MemOpVal, Alloca, ALLOCA); }
|
||||
free { RET_TOK(MemOpVal, Free, FREE); }
|
||||
load { RET_TOK(MemOpVal, Load, LOAD); }
|
||||
store { RET_TOK(MemOpVal, Store, STORE); }
|
||||
getelementptr { RET_TOK(MemOpVal, GetElementPtr, GETELEMENTPTR); }
|
||||
|
||||
extractelement { RET_TOK(OtherOpVal, ExtractElement, EXTRACTELEMENT); }
|
||||
insertelement { RET_TOK(OtherOpVal, InsertElement, INSERTELEMENT); }
|
||||
shufflevector { RET_TOK(OtherOpVal, ShuffleVector, SHUFFLEVECTOR); }
|
||||
|
||||
|
||||
{LocalVarName} {
|
||||
llvmAsmlval.StrVal = new std::string(yytext+1); // Skip %
|
||||
return LOCALVAR;
|
||||
}
|
||||
{GlobalVarName} {
|
||||
llvmAsmlval.StrVal = new std::string(yytext+1); // Skip @
|
||||
return GLOBALVAR;
|
||||
}
|
||||
{Label} {
|
||||
yytext[yyleng-1] = 0; // nuke colon
|
||||
llvmAsmlval.StrVal = new std::string(yytext);
|
||||
return LABELSTR;
|
||||
}
|
||||
{QuoteLabel} {
|
||||
yytext[yyleng-2] = 0; // nuke colon, end quote
|
||||
const char* EndChar = UnEscapeLexed(yytext+1, yytext+yyleng);
|
||||
llvmAsmlval.StrVal =
|
||||
new std::string(yytext+1, EndChar - yytext - 1);
|
||||
return LABELSTR;
|
||||
}
|
||||
|
||||
{StringConstant} { yytext[yyleng-1] = 0; // nuke end quote
|
||||
const char* EndChar = UnEscapeLexed(yytext+1, yytext+yyleng);
|
||||
llvmAsmlval.StrVal =
|
||||
new std::string(yytext+1, EndChar - yytext - 1);
|
||||
return STRINGCONSTANT;
|
||||
}
|
||||
{AtStringConstant} {
|
||||
yytext[yyleng-1] = 0; // nuke end quote
|
||||
const char* EndChar =
|
||||
UnEscapeLexed(yytext+2, yytext+yyleng);
|
||||
llvmAsmlval.StrVal =
|
||||
new std::string(yytext+2, EndChar - yytext - 2);
|
||||
return ATSTRINGCONSTANT;
|
||||
}
|
||||
{PctStringConstant} {
|
||||
yytext[yyleng-1] = 0; // nuke end quote
|
||||
const char* EndChar =
|
||||
UnEscapeLexed(yytext+2, yytext+yyleng);
|
||||
llvmAsmlval.StrVal =
|
||||
new std::string(yytext+2, EndChar - yytext - 2);
|
||||
return PCTSTRINGCONSTANT;
|
||||
}
|
||||
{PInteger} {
|
||||
uint32_t numBits = ((yyleng * 64) / 19) + 1;
|
||||
APInt Tmp(numBits, yytext, yyleng, 10);
|
||||
uint32_t activeBits = Tmp.getActiveBits();
|
||||
if (activeBits > 0 && activeBits < numBits)
|
||||
Tmp.trunc(activeBits);
|
||||
if (Tmp.getBitWidth() > 64) {
|
||||
llvmAsmlval.APIntVal = new APInt(Tmp);
|
||||
return EUAPINTVAL;
|
||||
} else {
|
||||
llvmAsmlval.UInt64Val = Tmp.getZExtValue();
|
||||
return EUINT64VAL;
|
||||
}
|
||||
}
|
||||
{NInteger} {
|
||||
uint32_t numBits = (((yyleng-1) * 64) / 19) + 2;
|
||||
APInt Tmp(numBits, yytext, yyleng, 10);
|
||||
uint32_t minBits = Tmp.getMinSignedBits();
|
||||
if (minBits > 0 && minBits < numBits)
|
||||
Tmp.trunc(minBits);
|
||||
if (Tmp.getBitWidth() > 64) {
|
||||
llvmAsmlval.APIntVal = new APInt(Tmp);
|
||||
return ESAPINTVAL;
|
||||
} else {
|
||||
llvmAsmlval.SInt64Val = Tmp.getSExtValue();
|
||||
return ESINT64VAL;
|
||||
}
|
||||
}
|
||||
|
||||
{HexIntConstant} { int len = yyleng - 3;
|
||||
uint32_t bits = len * 4;
|
||||
APInt Tmp(bits, yytext+3, len, 16);
|
||||
uint32_t activeBits = Tmp.getActiveBits();
|
||||
if (activeBits > 0 && activeBits < bits)
|
||||
Tmp.trunc(activeBits);
|
||||
if (Tmp.getBitWidth() > 64) {
|
||||
llvmAsmlval.APIntVal = new APInt(Tmp);
|
||||
return yytext[0] == 's' ? ESAPINTVAL : EUAPINTVAL;
|
||||
} else if (yytext[0] == 's') {
|
||||
llvmAsmlval.SInt64Val = Tmp.getSExtValue();
|
||||
return ESINT64VAL;
|
||||
} else {
|
||||
llvmAsmlval.UInt64Val = Tmp.getZExtValue();
|
||||
return EUINT64VAL;
|
||||
}
|
||||
}
|
||||
|
||||
{LocalVarID} {
|
||||
uint64_t Val = atoull(yytext+1);
|
||||
if ((unsigned)Val != Val)
|
||||
GenerateError("Invalid value number (too large)!");
|
||||
llvmAsmlval.UIntVal = unsigned(Val);
|
||||
return LOCALVAL_ID;
|
||||
}
|
||||
{GlobalVarID} {
|
||||
uint64_t Val = atoull(yytext+1);
|
||||
if ((unsigned)Val != Val)
|
||||
GenerateError("Invalid value number (too large)!");
|
||||
llvmAsmlval.UIntVal = unsigned(Val);
|
||||
return GLOBALVAL_ID;
|
||||
}
|
||||
|
||||
{FPConstant} { llvmAsmlval.FPVal = new APFloat(atof(yytext)); return FPVAL; }
|
||||
{HexFPConstant} { llvmAsmlval.FPVal = new APFloat(HexToFP(yytext+2));
|
||||
return FPVAL;
|
||||
}
|
||||
{HexFP80Constant} { uint64_t Pair[2];
|
||||
HexToIntPair(yytext+3, Pair);
|
||||
llvmAsmlval.FPVal = new APFloat(APInt(80, 2, Pair));
|
||||
return FPVAL;
|
||||
}
|
||||
{HexFP128Constant} { uint64_t Pair[2];
|
||||
HexToIntPair(yytext+3, Pair);
|
||||
llvmAsmlval.FPVal = new APFloat(APInt(128, 2, Pair), true);
|
||||
return FPVAL;
|
||||
}
|
||||
{HexPPC128Constant} { uint64_t Pair[2];
|
||||
HexToIntPair(yytext+3, Pair);
|
||||
llvmAsmlval.FPVal = new APFloat(APInt(128, 2, Pair));
|
||||
return FPVAL;
|
||||
}
|
||||
|
||||
<<EOF>> {
|
||||
/* Make sure to free the internal buffers for flex when we are
|
||||
* done reading our input!
|
||||
*/
|
||||
yy_delete_buffer(YY_CURRENT_BUFFER);
|
||||
return EOF;
|
||||
}
|
||||
|
||||
[ \r\t\n] { /* Ignore whitespace */ }
|
||||
. { return yytext[0]; }
|
||||
|
||||
%%
|
@ -10,8 +10,7 @@
|
||||
LEVEL = ../..
|
||||
LIBRARYNAME := LLVMAsmParser
|
||||
BUILD_ARCHIVE = 1
|
||||
EXTRA_DIST := Lexer.cpp.cvs Lexer.l.cvs \
|
||||
llvmAsmParser.cpp.cvs llvmAsmParser.h.cvs llvmAsmParser.y.cvs
|
||||
EXTRA_DIST := llvmAsmParser.cpp.cvs llvmAsmParser.h.cvs llvmAsmParser.y.cvs
|
||||
|
||||
include $(LEVEL)/Makefile.common
|
||||
|
||||
@ -24,4 +23,4 @@ CompileCommonOpts := $(filter-out -Wno-long-long,$(CompileCommonOpts))
|
||||
# Make the object code file for the lexer depend upon the header file generated
|
||||
# by the Bison parser. This prevents the Lexer from being compiled before the
|
||||
# header file it needs is built.
|
||||
$(ObjDir)/Lexer.o: $(PROJ_SRC_DIR)/llvmAsmParser.h
|
||||
$(ObjDir)/LLLexer.o: $(PROJ_SRC_DIR)/llvmAsmParser.h
|
||||
|
@ -13,38 +13,37 @@
|
||||
|
||||
#include "ParserInternals.h"
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
using namespace llvm;
|
||||
|
||||
|
||||
ParseError* TheParseError = 0; /// FIXME: Not threading friendly
|
||||
|
||||
Module *llvm::ParseAssemblyFile(const std::string &Filename, ParseError* Err) {
|
||||
FILE *F = stdin;
|
||||
|
||||
if (Filename != "-") {
|
||||
F = fopen(Filename.c_str(), "r");
|
||||
|
||||
if (F == 0) {
|
||||
if (Err)
|
||||
Err->setError(Filename,"Could not open file '" + Filename + "'");
|
||||
return 0;
|
||||
}
|
||||
std::string ErrorStr;
|
||||
MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(&Filename[0], Filename.size(),
|
||||
&ErrorStr);
|
||||
if (F == 0) {
|
||||
if (Err)
|
||||
Err->setError(Filename, "Could not open input file '" + Filename + "'");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
TheParseError = Err;
|
||||
Module *Result = RunVMAsmParser(Filename, F);
|
||||
|
||||
if (F != stdin)
|
||||
fclose(F);
|
||||
|
||||
Module *Result = RunVMAsmParser(F);
|
||||
delete F;
|
||||
return Result;
|
||||
}
|
||||
|
||||
Module *llvm::ParseAssemblyString(
|
||||
const char * AsmString, Module * M, ParseError* Err)
|
||||
{
|
||||
Module *llvm::ParseAssemblyString(const char *AsmString, Module *M,
|
||||
ParseError *Err) {
|
||||
TheParseError = Err;
|
||||
return RunVMAsmParser(AsmString, M);
|
||||
MemoryBuffer *F = MemoryBuffer::getMemBuffer(AsmString,
|
||||
AsmString+strlen(AsmString),
|
||||
"<string>");
|
||||
Module *Result = RunVMAsmParser(F);
|
||||
delete F;
|
||||
return Result;
|
||||
}
|
||||
|
||||
|
||||
@ -54,9 +53,8 @@ Module *llvm::ParseAssemblyString(
|
||||
|
||||
|
||||
void ParseError::setError(const std::string &filename,
|
||||
const std::string &message,
|
||||
int lineNo, int colNo)
|
||||
{
|
||||
const std::string &message,
|
||||
int lineNo, int colNo) {
|
||||
Filename = filename;
|
||||
Message = message;
|
||||
LineNo = lineNo;
|
||||
|
@ -23,37 +23,25 @@
|
||||
#include "llvm/Assembly/Parser.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/ADT/APFloat.h"
|
||||
namespace llvm { class MemoryBuffer; }
|
||||
|
||||
// Global variables exported from the lexer...
|
||||
|
||||
extern int llvmAsmlineno; /// FIXME: Not threading friendly
|
||||
extern llvm::ParseError* TheParseError; /// FIXME: Not threading friendly
|
||||
|
||||
extern std::string &llvmAsmTextin;
|
||||
|
||||
// functions exported from the lexer
|
||||
void set_scan_file(FILE * F);
|
||||
void set_scan_string (const char * str);
|
||||
|
||||
// Globals exported by the parser...
|
||||
extern char* llvmAsmtext;
|
||||
extern int llvmAsmleng;
|
||||
void InitLLLexer(llvm::MemoryBuffer *MB);
|
||||
const char *LLLgetTokenStart();
|
||||
unsigned LLLgetTokenLength();
|
||||
std::string LLLgetFilename();
|
||||
unsigned LLLgetLineNo();
|
||||
void FreeLexer();
|
||||
|
||||
namespace llvm {
|
||||
class Module;
|
||||
|
||||
// Globals exported by the parser...
|
||||
extern std::string CurFilename; /// FIXME: Not threading friendly
|
||||
|
||||
// RunVMAsmParser - Parse a file and return Module
|
||||
Module *RunVMAsmParser(const std::string &Filename, FILE *F);
|
||||
|
||||
// Parse a string directly
|
||||
Module *RunVMAsmParser(const char * AsmString, Module * M);
|
||||
|
||||
// UnEscapeLexed - Run through the specified buffer and change \xx codes to the
|
||||
// appropriate character.
|
||||
char *UnEscapeLexed(char *Buffer);
|
||||
// RunVMAsmParser - Parse a buffer and return Module
|
||||
Module *RunVMAsmParser(llvm::MemoryBuffer *MB);
|
||||
|
||||
// GenerateError - Wrapper around the ParseException class that automatically
|
||||
// fills in file line number and column number and options info.
|
||||
|
@ -29,9 +29,6 @@
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <utility>
|
||||
#ifndef NDEBUG
|
||||
#define YYDEBUG 1
|
||||
#endif
|
||||
|
||||
// The following is a gross hack. In order to rid the libAsmParser library of
|
||||
// exceptions, we have to have a way of getting the yyparse function to go into
|
||||
@ -51,15 +48,6 @@ static bool TriggerError = false;
|
||||
int yyerror(const char *ErrorMsg); // Forward declarations to prevent "implicit
|
||||
int yylex(); // declaration" of xxx warnings.
|
||||
int yyparse();
|
||||
|
||||
namespace llvm {
|
||||
std::string CurFilename;
|
||||
#if YYDEBUG
|
||||
static cl::opt<bool>
|
||||
Debug("debug-yacc", cl::desc("Print yacc debug state changes"),
|
||||
cl::Hidden, cl::init(false));
|
||||
#endif
|
||||
}
|
||||
using namespace llvm;
|
||||
|
||||
static Module *ParserResult;
|
||||
@ -513,7 +501,7 @@ static Value *getVal(const Type *Ty, const ValID &ID) {
|
||||
// Remember where this forward reference came from. FIXME, shouldn't we try
|
||||
// to recycle these things??
|
||||
CurModule.PlaceHolderInfo.insert(std::make_pair(V, std::make_pair(ID,
|
||||
llvmAsmlineno)));
|
||||
LLLgetLineNo())));
|
||||
|
||||
if (inFunctionScope())
|
||||
InsertValue(V, CurFun.LateResolveValues);
|
||||
@ -945,22 +933,11 @@ static PATypeHolder HandleUpRefs(const Type *ty) {
|
||||
//
|
||||
static Module* RunParser(Module * M);
|
||||
|
||||
Module *llvm::RunVMAsmParser(const std::string &Filename, FILE *F) {
|
||||
set_scan_file(F);
|
||||
|
||||
CurFilename = Filename;
|
||||
return RunParser(new Module(CurFilename));
|
||||
}
|
||||
|
||||
Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
|
||||
set_scan_string(AsmString);
|
||||
|
||||
CurFilename = "from_memory";
|
||||
if (M == NULL) {
|
||||
return RunParser(new Module (CurFilename));
|
||||
} else {
|
||||
return RunParser(M);
|
||||
}
|
||||
Module *llvm::RunVMAsmParser(llvm::MemoryBuffer *MB) {
|
||||
InitLLLexer(MB);
|
||||
Module *M = RunParser(new Module(LLLgetFilename()));
|
||||
FreeLexer();
|
||||
return M;
|
||||
}
|
||||
|
||||
%}
|
||||
@ -3118,13 +3095,7 @@ MemoryInst : MALLOC Types OptCAlign {
|
||||
|
||||
// common code from the two 'RunVMAsmParser' functions
|
||||
static Module* RunParser(Module * M) {
|
||||
|
||||
llvmAsmlineno = 1; // Reset the current line number...
|
||||
CurModule.CurrentModule = M;
|
||||
#if YYDEBUG
|
||||
yydebug = Debug;
|
||||
#endif
|
||||
|
||||
// Check to make sure the parser succeeded
|
||||
if (yyparse()) {
|
||||
if (ParserResult)
|
||||
@ -3176,21 +3147,21 @@ static Module* RunParser(Module * M) {
|
||||
}
|
||||
|
||||
void llvm::GenerateError(const std::string &message, int LineNo) {
|
||||
if (LineNo == -1) LineNo = llvmAsmlineno;
|
||||
if (LineNo == -1) LineNo = LLLgetLineNo();
|
||||
// TODO: column number in exception
|
||||
if (TheParseError)
|
||||
TheParseError->setError(CurFilename, message, LineNo);
|
||||
TheParseError->setError(LLLgetFilename(), message, LineNo);
|
||||
TriggerError = 1;
|
||||
}
|
||||
|
||||
int yyerror(const char *ErrorMsg) {
|
||||
std::string where
|
||||
= std::string((CurFilename == "-") ? std::string("<stdin>") : CurFilename)
|
||||
+ ":" + utostr((unsigned) llvmAsmlineno) + ": ";
|
||||
std::string where = LLLgetFilename() + ":" + utostr(LLLgetLineNo()) + ": ";
|
||||
std::string errMsg = where + "error: " + std::string(ErrorMsg);
|
||||
if (yychar != YYEMPTY && yychar != 0)
|
||||
errMsg += " while reading token: '" + std::string(llvmAsmtext, llvmAsmleng)+
|
||||
"'";
|
||||
if (yychar != YYEMPTY && yychar != 0) {
|
||||
errMsg += " while reading token: '";
|
||||
errMsg += std::string(LLLgetTokenStart(),
|
||||
LLLgetTokenStart()+LLLgetTokenLength()) + "'";
|
||||
}
|
||||
GenerateError(errMsg);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user