LLLexer.cpp revision 970bfcc7d8b9991430caa7ab33975617f3f4c40d
18e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner//===- LLLexer.cpp - Lexer for .ll Files ----------------------------------===//
28e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner//
38e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner//                     The LLVM Compiler Infrastructure
48e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner//
54ee451de366474b9c228b4e5fa573795a715216dChris Lattner// This file is distributed under the University of Illinois Open Source
64ee451de366474b9c228b4e5fa573795a715216dChris Lattner// License. See LICENSE.TXT for details.
78e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner//
88e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner//===----------------------------------------------------------------------===//
98e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner//
108e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner// Implement the Lexer for .ll files.
118e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner//
128e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner//===----------------------------------------------------------------------===//
138e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
148e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner#include "LLLexer.h"
15df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner#include "llvm/DerivedTypes.h"
16df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner#include "llvm/Instruction.h"
17ff6c91efcf62d1cb99343fdcb2de6271520a1981Owen Anderson#include "llvm/LLVMContext.h"
18d1e1703c39742f3c9fc3d27a442ff59bbdbfb5aaBenjamin Kramer#include "llvm/ADT/Twine.h"
19d1e1703c39742f3c9fc3d27a442ff59bbdbfb5aaBenjamin Kramer#include "llvm/Assembly/Parser.h"
20c25e7581b9b8088910da31702d4ca21c4734c6d7Torok Edwin#include "llvm/Support/ErrorHandling.h"
218e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner#include "llvm/Support/MemoryBuffer.h"
22d185f64f828ce1f8b476807a4a1345c0c53d8213Chris Lattner#include "llvm/Support/MathExtras.h"
2392bcb426c3e4503c99324afd4ed0a73521711a56Chris Lattner#include "llvm/Support/SourceMgr.h"
24df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner#include "llvm/Support/raw_ostream.h"
25bcef7df6ec9aba7c5009a4d33944f80227563665Duncan Sands#include <cstdio>
26a896176973d59d8e22514b363d31e8d1becf185eChris Lattner#include <cstdlib>
275679d18c54ef46170e46f51bf471bb334f2b6525Misha Brukman#include <cstring>
288e3a8e0452695643d04c21e15c94b802aef81baeChris Lattnerusing namespace llvm;
298e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
30d1e1703c39742f3c9fc3d27a442ff59bbdbfb5aaBenjamin Kramerbool LLLexer::Error(LocTy ErrorLoc, const Twine &Msg) const {
31eeb4a84ac8d91fb1d5a7c484a1c7047409faee30Chris Lattner  ErrorInfo = SM.GetMessage(ErrorLoc, Msg, "error");
32df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  return true;
33df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner}
34df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner
358e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner//===----------------------------------------------------------------------===//
368e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner// Helper functions.
378e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner//===----------------------------------------------------------------------===//
388e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
398e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner// atoull - Convert an ascii string of decimal digits into the unsigned long
408e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner// long representation... this does not have to do input error checking,
418e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner// because we know that the input will be matched by a suitable regex...
428e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner//
43df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattneruint64_t LLLexer::atoull(const char *Buffer, const char *End) {
448e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  uint64_t Result = 0;
458e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  for (; Buffer != End; Buffer++) {
468e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    uint64_t OldRes = Result;
478e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    Result *= 10;
488e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    Result += *Buffer-'0';
498e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (Result < OldRes) {  // Uh, oh, overflow detected!!!
50df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      Error("constant bigger than 64 bits detected!");
518e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      return 0;
528e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    }
538e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
548e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  return Result;
558e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
568e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
57df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattneruint64_t LLLexer::HexIntToVal(const char *Buffer, const char *End) {
588e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  uint64_t Result = 0;
598e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  for (; Buffer != End; ++Buffer) {
608e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    uint64_t OldRes = Result;
618e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    Result *= 16;
628e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    char C = *Buffer;
638e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (C >= '0' && C <= '9')
648e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      Result += C-'0';
658e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    else if (C >= 'A' && C <= 'F')
668e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      Result += C-'A'+10;
678e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    else if (C >= 'a' && C <= 'f')
688e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      Result += C-'a'+10;
692c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
708e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (Result < OldRes) {   // Uh, oh, overflow detected!!!
71df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      Error("constant bigger than 64 bits detected!");
728e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      return 0;
738e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    }
748e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
758e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  return Result;
768e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
778e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
78df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattnervoid LLLexer::HexToIntPair(const char *Buffer, const char *End,
79df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner                           uint64_t Pair[2]) {
808e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  Pair[0] = 0;
818e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  for (int i=0; i<16; i++, Buffer++) {
828e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    assert(Buffer != End);
838e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    Pair[0] *= 16;
848e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    char C = *Buffer;
858e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (C >= '0' && C <= '9')
868e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      Pair[0] += C-'0';
878e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    else if (C >= 'A' && C <= 'F')
888e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      Pair[0] += C-'A'+10;
898e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    else if (C >= 'a' && C <= 'f')
908e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      Pair[0] += C-'a'+10;
918e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
928e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  Pair[1] = 0;
938e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  for (int i=0; i<16 && Buffer != End; i++, Buffer++) {
948e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    Pair[1] *= 16;
958e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    char C = *Buffer;
968e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (C >= '0' && C <= '9')
978e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      Pair[1] += C-'0';
988e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    else if (C >= 'A' && C <= 'F')
998e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      Pair[1] += C-'A'+10;
1008e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    else if (C >= 'a' && C <= 'f')
1018e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      Pair[1] += C-'a'+10;
1028e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
103d343c6b70ec03b357d42e47ce7c00b3c3cb78efdChris Lattner  if (Buffer != End)
104df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    Error("constant bigger than 128 bits detected!");
1058e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
1068e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
1071b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen/// FP80HexToIntPair - translate an 80 bit FP80 number (20 hexits) into
1081b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen/// { low64, high16 } as usual for an APInt.
1091b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesenvoid LLLexer::FP80HexToIntPair(const char *Buffer, const char *End,
1101b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen                           uint64_t Pair[2]) {
1111b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen  Pair[1] = 0;
1121b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen  for (int i=0; i<4 && Buffer != End; i++, Buffer++) {
1131b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen    assert(Buffer != End);
1141b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen    Pair[1] *= 16;
1151b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen    char C = *Buffer;
1161b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen    if (C >= '0' && C <= '9')
1171b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen      Pair[1] += C-'0';
1181b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen    else if (C >= 'A' && C <= 'F')
1191b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen      Pair[1] += C-'A'+10;
1201b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen    else if (C >= 'a' && C <= 'f')
1211b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen      Pair[1] += C-'a'+10;
1221b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen  }
1231b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen  Pair[0] = 0;
1241b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen  for (int i=0; i<16; i++, Buffer++) {
1251b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen    Pair[0] *= 16;
1261b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen    char C = *Buffer;
1271b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen    if (C >= '0' && C <= '9')
1281b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen      Pair[0] += C-'0';
1291b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen    else if (C >= 'A' && C <= 'F')
1301b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen      Pair[0] += C-'A'+10;
1311b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen    else if (C >= 'a' && C <= 'f')
1321b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen      Pair[0] += C-'a'+10;
1331b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen  }
1341b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen  if (Buffer != End)
1351b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen    Error("constant bigger than 128 bits detected!");
1361b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen}
1371b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen
1388e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner// UnEscapeLexed - Run through the specified buffer and change \xx codes to the
1398e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner// appropriate character.
1408e3a8e0452695643d04c21e15c94b802aef81baeChris Lattnerstatic void UnEscapeLexed(std::string &Str) {
1418e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (Str.empty()) return;
1422c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
1438e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  char *Buffer = &Str[0], *EndBuffer = Buffer+Str.size();
1448e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  char *BOut = Buffer;
1458e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  for (char *BIn = Buffer; BIn != EndBuffer; ) {
1468e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (BIn[0] == '\\') {
1478e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      if (BIn < EndBuffer-1 && BIn[1] == '\\') {
1488e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner        *BOut++ = '\\'; // Two \ becomes one
1498e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner        BIn += 2;
1508e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      } else if (BIn < EndBuffer-2 && isxdigit(BIn[1]) && isxdigit(BIn[2])) {
1518e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner        char Tmp = BIn[3]; BIn[3] = 0;      // Terminate string
1528e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner        *BOut = (char)strtol(BIn+1, 0, 16); // Convert to number
1538e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner        BIn[3] = Tmp;                       // Restore character
1548e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner        BIn += 3;                           // Skip over handled chars
1558e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner        ++BOut;
1568e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      } else {
1578e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner        *BOut++ = *BIn++;
1588e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      }
1598e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    } else {
1608e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      *BOut++ = *BIn++;
1618e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    }
1628e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
1638e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  Str.resize(BOut-Buffer);
1648e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
1658e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
1668e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner/// isLabelChar - Return true for [-a-zA-Z$._0-9].
1678e3a8e0452695643d04c21e15c94b802aef81baeChris Lattnerstatic bool isLabelChar(char C) {
1688e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  return isalnum(C) || C == '-' || C == '$' || C == '.' || C == '_';
1698e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
1708e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
1718e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
1728e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner/// isLabelTail - Return true if this pointer points to a valid end of a label.
1738e3a8e0452695643d04c21e15c94b802aef81baeChris Lattnerstatic const char *isLabelTail(const char *CurPtr) {
1748e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  while (1) {
1758e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (CurPtr[0] == ':') return CurPtr+1;
1768e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (!isLabelChar(CurPtr[0])) return 0;
1778e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    ++CurPtr;
1788e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
1798e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
1808e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
1818e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
1828e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
1838e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner//===----------------------------------------------------------------------===//
1848e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner// Lexer definition.
1858e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner//===----------------------------------------------------------------------===//
1868e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
187ff6c91efcf62d1cb99343fdcb2de6271520a1981Owen AndersonLLLexer::LLLexer(MemoryBuffer *StartBuf, SourceMgr &sm, SMDiagnostic &Err,
188ff6c91efcf62d1cb99343fdcb2de6271520a1981Owen Anderson                 LLVMContext &C)
189ff6c91efcf62d1cb99343fdcb2de6271520a1981Owen Anderson  : CurBuf(StartBuf), ErrorInfo(Err), SM(sm), Context(C), APFloatVal(0.0) {
1908e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  CurPtr = CurBuf->getBufferStart();
1918e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
1928e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
1938e3a8e0452695643d04c21e15c94b802aef81baeChris Lattnerstd::string LLLexer::getFilename() const {
1948e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  return CurBuf->getBufferIdentifier();
1958e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
1968e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
1978e3a8e0452695643d04c21e15c94b802aef81baeChris Lattnerint LLLexer::getNextChar() {
1988e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  char CurChar = *CurPtr++;
1998e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  switch (CurChar) {
2008e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  default: return (unsigned char)CurChar;
2018e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case 0:
2028e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    // A nul character in the stream is either the end of the current buffer or
2038e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    // a random nul in the file.  Disambiguate that here.
2048e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (CurPtr-1 != CurBuf->getBufferEnd())
2058e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      return 0;  // Just whitespace.
2062c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
2078e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    // Otherwise, return end of file.
2082c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling    --CurPtr;  // Another call to lex will return EOF again.
2098e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    return EOF;
2102c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling  }
2118e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
2128e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
2138e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
214df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattnerlltok::Kind LLLexer::LexToken() {
2158e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  TokStart = CurPtr;
2162c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
2178e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  int CurChar = getNextChar();
2188e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  switch (CurChar) {
2198e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  default:
2208e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    // Handle letters: [a-zA-Z_]
2218e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (isalpha(CurChar) || CurChar == '_')
2228e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      return LexIdentifier();
2232c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
224df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::Error;
225df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  case EOF: return lltok::Eof;
2268e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case 0:
2278e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case ' ':
2288e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case '\t':
2298e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case '\n':
2308e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case '\r':
2318e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    // Ignore whitespace.
2328e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    return LexToken();
2338e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case '+': return LexPositive();
2348e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case '@': return LexAt();
2358e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case '%': return LexPercent();
2368e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case '"': return LexQuote();
2378e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case '.':
2388e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (const char *Ptr = isLabelTail(CurPtr)) {
2398e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      CurPtr = Ptr;
240df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      StrVal.assign(TokStart, CurPtr-1);
241df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      return lltok::LabelStr;
2428e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    }
2438e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (CurPtr[0] == '.' && CurPtr[1] == '.') {
2448e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      CurPtr += 2;
245df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      return lltok::dotdotdot;
2468e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    }
247df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::Error;
2488e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case '$':
2498e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (const char *Ptr = isLabelTail(CurPtr)) {
2508e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      CurPtr = Ptr;
251df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      StrVal.assign(TokStart, CurPtr-1);
252df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      return lltok::LabelStr;
2538e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    }
254df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::Error;
2558e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case ';':
2568e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    SkipLineComment();
2578e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    return LexToken();
258e434d277ca5183eeb6f881000732dcf4c8edd52eChris Lattner  case '!': return LexExclaim();
2598e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case '0': case '1': case '2': case '3': case '4':
2608e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case '5': case '6': case '7': case '8': case '9':
2612c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling  case '-':
2628e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    return LexDigitOrNegative();
263df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  case '=': return lltok::equal;
264df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  case '[': return lltok::lsquare;
265df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  case ']': return lltok::rsquare;
266df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  case '{': return lltok::lbrace;
267df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  case '}': return lltok::rbrace;
268df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  case '<': return lltok::less;
269df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  case '>': return lltok::greater;
270df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  case '(': return lltok::lparen;
271df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  case ')': return lltok::rparen;
272df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  case ',': return lltok::comma;
273df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  case '*': return lltok::star;
274df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  case '\\': return lltok::backslash;
2758e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
2768e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
2778e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
2788e3a8e0452695643d04c21e15c94b802aef81baeChris Lattnervoid LLLexer::SkipLineComment() {
2798e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  while (1) {
2808e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (CurPtr[0] == '\n' || CurPtr[0] == '\r' || getNextChar() == EOF)
2818e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      return;
2828e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
2838e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
2848e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
2858e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner/// LexAt - Lex all tokens that start with an @ character:
286df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner///   GlobalVar   @\"[^\"]*\"
287df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner///   GlobalVar   @[-a-zA-Z$._][-a-zA-Z$._0-9]*
288df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner///   GlobalVarID @[0-9]+
289df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattnerlltok::Kind LLLexer::LexAt() {
2908e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // Handle AtStringConstant: @\"[^\"]*\"
2918e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (CurPtr[0] == '"') {
2928e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    ++CurPtr;
2932c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
2948e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    while (1) {
2958e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      int CurChar = getNextChar();
2962c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
2972c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling      if (CurChar == EOF) {
298df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner        Error("end of file in global variable name");
299df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner        return lltok::Error;
3008e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      }
3018e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      if (CurChar == '"') {
302df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner        StrVal.assign(TokStart+2, CurPtr-1);
303df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner        UnEscapeLexed(StrVal);
304df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner        return lltok::GlobalVar;
3058e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      }
3068e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    }
3078e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
3082c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
3098e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // Handle GlobalVarName: @[-a-zA-Z$._][-a-zA-Z$._0-9]*
3102c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling  if (isalpha(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
3118e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      CurPtr[0] == '.' || CurPtr[0] == '_') {
3128e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    ++CurPtr;
3132c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling    while (isalnum(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
3148e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner           CurPtr[0] == '.' || CurPtr[0] == '_')
3158e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      ++CurPtr;
3168e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
317df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    StrVal.assign(TokStart+1, CurPtr);   // Skip @
318df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::GlobalVar;
3198e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
3202c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
3218e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // Handle GlobalVarID: @[0-9]+
3228e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (isdigit(CurPtr[0])) {
3232c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling    for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
3242c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling      /*empty*/;
3252c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
3268e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    uint64_t Val = atoull(TokStart+1, CurPtr);
3278e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if ((unsigned)Val != Val)
328df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      Error("invalid value number (too large)!");
329df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    UIntVal = unsigned(Val);
330df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::GlobalID;
3318e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
3322c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
333df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  return lltok::Error;
3348e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
3358e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
3368e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
3378e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner/// LexPercent - Lex all tokens that start with a % character:
338df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner///   LocalVar   ::= %\"[^\"]*\"
339df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner///   LocalVar   ::= %[-a-zA-Z$._][-a-zA-Z$._0-9]*
340df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner///   LocalVarID ::= %[0-9]+
341df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattnerlltok::Kind LLLexer::LexPercent() {
342df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  // Handle LocalVarName: %\"[^\"]*\"
3438e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (CurPtr[0] == '"') {
3448e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    ++CurPtr;
3452c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
3468e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    while (1) {
3478e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      int CurChar = getNextChar();
3482c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
3492c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling      if (CurChar == EOF) {
350df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner        Error("end of file in string constant");
351df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner        return lltok::Error;
3528e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      }
3538e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      if (CurChar == '"') {
354df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner        StrVal.assign(TokStart+2, CurPtr-1);
355df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner        UnEscapeLexed(StrVal);
356df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner        return lltok::LocalVar;
3578e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      }
3588e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    }
3598e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
3602c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
3618e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // Handle LocalVarName: %[-a-zA-Z$._][-a-zA-Z$._0-9]*
3622c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling  if (isalpha(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
3638e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      CurPtr[0] == '.' || CurPtr[0] == '_') {
3648e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    ++CurPtr;
3652c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling    while (isalnum(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
3668e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner           CurPtr[0] == '.' || CurPtr[0] == '_')
3678e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      ++CurPtr;
3682c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
369df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    StrVal.assign(TokStart+1, CurPtr);   // Skip %
370df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::LocalVar;
3718e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
3722c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
3738e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // Handle LocalVarID: %[0-9]+
3748e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (isdigit(CurPtr[0])) {
3752c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling    for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
3762c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling      /*empty*/;
3772c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
3788e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    uint64_t Val = atoull(TokStart+1, CurPtr);
3798e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if ((unsigned)Val != Val)
380df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      Error("invalid value number (too large)!");
381df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    UIntVal = unsigned(Val);
382df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::LocalVarID;
3838e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
3842c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
385df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  return lltok::Error;
3868e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
3878e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
3888e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner/// LexQuote - Lex all tokens that start with a " character:
3898e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///   QuoteLabel        "[^"]+":
3908e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///   StringConstant    "[^"]*"
391df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattnerlltok::Kind LLLexer::LexQuote() {
3928e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  while (1) {
3938e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    int CurChar = getNextChar();
3942c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
3952c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling    if (CurChar == EOF) {
396df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      Error("end of file in quoted string");
397df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      return lltok::Error;
3988e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    }
3992c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
4008e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (CurChar != '"') continue;
4018e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
4028e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (CurPtr[0] != ':') {
403df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      StrVal.assign(TokStart+1, CurPtr-1);
404df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      UnEscapeLexed(StrVal);
405df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      return lltok::StringConstant;
4068e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    }
4072c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
4088e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    ++CurPtr;
409df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    StrVal.assign(TokStart+1, CurPtr-2);
410df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    UnEscapeLexed(StrVal);
411df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::LabelStr;
4128e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
4138e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
4148e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
4158e3a8e0452695643d04c21e15c94b802aef81baeChris Lattnerstatic bool JustWhitespaceNewLine(const char *&Ptr) {
4168e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  const char *ThisPtr = Ptr;
4178e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  while (*ThisPtr == ' ' || *ThisPtr == '\t')
4188e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    ++ThisPtr;
4198e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (*ThisPtr == '\n' || *ThisPtr == '\r') {
4208e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    Ptr = ThisPtr;
4218e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    return true;
4228e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
4238e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  return false;
4248e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
4258e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
426e434d277ca5183eeb6f881000732dcf4c8edd52eChris Lattner/// LexExclaim:
427eff2ab61b5d411fe64ba601d402b7c549644b590Devang Patel///    !foo
4281d92831759620a2e5ce4f5a3088c0a1a77a48c8fChris Lattner///    !
429e434d277ca5183eeb6f881000732dcf4c8edd52eChris Lattnerlltok::Kind LLLexer::LexExclaim() {
4301d92831759620a2e5ce4f5a3088c0a1a77a48c8fChris Lattner  // Lex a metadata name as a MetadataVar.
431eff2ab61b5d411fe64ba601d402b7c549644b590Devang Patel  if (isalpha(CurPtr[0])) {
432eff2ab61b5d411fe64ba601d402b7c549644b590Devang Patel    ++CurPtr;
433eff2ab61b5d411fe64ba601d402b7c549644b590Devang Patel    while (isalnum(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
434eff2ab61b5d411fe64ba601d402b7c549644b590Devang Patel           CurPtr[0] == '.' || CurPtr[0] == '_')
435eff2ab61b5d411fe64ba601d402b7c549644b590Devang Patel      ++CurPtr;
4368e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
437eff2ab61b5d411fe64ba601d402b7c549644b590Devang Patel    StrVal.assign(TokStart+1, CurPtr);   // Skip !
4381d92831759620a2e5ce4f5a3088c0a1a77a48c8fChris Lattner    return lltok::MetadataVar;
439eff2ab61b5d411fe64ba601d402b7c549644b590Devang Patel  }
440e434d277ca5183eeb6f881000732dcf4c8edd52eChris Lattner  return lltok::exclaim;
441eff2ab61b5d411fe64ba601d402b7c549644b590Devang Patel}
442eff2ab61b5d411fe64ba601d402b7c549644b590Devang Patel
4438e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner/// LexIdentifier: Handle several related productions:
4448e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    Label           [-a-zA-Z$._0-9]+:
4458e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    IntegerType     i[0-9]+
4468e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    Keyword         sdiv, float, ...
4478e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    HexIntConstant  [us]0x[0-9A-Fa-f]+
448df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattnerlltok::Kind LLLexer::LexIdentifier() {
4498e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  const char *StartChar = CurPtr;
4508e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  const char *IntEnd = CurPtr[-1] == 'i' ? 0 : StartChar;
4518e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  const char *KeywordEnd = 0;
4522c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
4538e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  for (; isLabelChar(*CurPtr); ++CurPtr) {
4548e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    // If we decide this is an integer, remember the end of the sequence.
4558e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (!IntEnd && !isdigit(*CurPtr)) IntEnd = CurPtr;
4568e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (!KeywordEnd && !isalnum(*CurPtr) && *CurPtr != '_') KeywordEnd = CurPtr;
4578e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
4582c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
4598e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // If we stopped due to a colon, this really is a label.
4608e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (*CurPtr == ':') {
461df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    StrVal.assign(StartChar-1, CurPtr++);
462df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::LabelStr;
4638e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
4642c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
4658e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // Otherwise, this wasn't a label.  If this was valid as an integer type,
4668e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // return it.
4678e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (IntEnd == 0) IntEnd = CurPtr;
4688e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (IntEnd != StartChar) {
4698e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    CurPtr = IntEnd;
4708e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    uint64_t NumBits = atoull(StartChar, CurPtr);
4712c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling    if (NumBits < IntegerType::MIN_INT_BITS ||
4728e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner        NumBits > IntegerType::MAX_INT_BITS) {
473df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      Error("bitwidth for integer type out of range!");
474df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      return lltok::Error;
4758e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    }
4761d0be15f89cb5056e20e2d24faa8d6afb1573bcaOwen Anderson    TyVal = IntegerType::get(Context, NumBits);
477df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::Type;
4788e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
4792c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
4808e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // Otherwise, this was a letter sequence.  See which keyword this is.
4818e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (KeywordEnd == 0) KeywordEnd = CurPtr;
4828e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  CurPtr = KeywordEnd;
4838e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  --StartChar;
4848e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  unsigned Len = CurPtr-StartChar;
485df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner#define KEYWORD(STR) \
486df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  if (Len == strlen(#STR) && !memcmp(StartChar, #STR, strlen(#STR))) \
487df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::kw_##STR;
488df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner
489df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(begin);   KEYWORD(end);
490df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(true);    KEYWORD(false);
491df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(declare); KEYWORD(define);
492df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(global);  KEYWORD(constant);
493df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner
494bb46f52027416598a662dc1c58f48d9d56b1a65bRafael Espindola  KEYWORD(private);
4953d10a5a75794356a0a568ce283713adc3a963200Bill Wendling  KEYWORD(linker_private);
4965e721d768254a920b78b9129d79a84c0163cb3f4Bill Wendling  KEYWORD(linker_private_weak);
49755ae515f9db484125a23429d4906c5edaf9f10d2Bill Wendling  KEYWORD(linker_private_weak_def_auto);
498df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(internal);
499266c7bbbbcc4b326dea82e577de1a415d6acc23eChris Lattner  KEYWORD(available_externally);
500df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(linkonce);
501667d4b8de6dea70195ff12ef39a4deebffa2f5c7Duncan Sands  KEYWORD(linkonce_odr);
502df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(weak);
503667d4b8de6dea70195ff12ef39a4deebffa2f5c7Duncan Sands  KEYWORD(weak_odr);
504df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(appending);
505df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(dllimport);
506df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(dllexport);
507df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(common);
508df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(default);
509df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(hidden);
510df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(protected);
511df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(extern_weak);
512df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(external);
513df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(thread_local);
514df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(zeroinitializer);
515df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(undef);
516df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(null);
517df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(to);
518df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(tail);
519df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(target);
520df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(triple);
521df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(deplibs);
522df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(datalayout);
523df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(volatile);
52408d012eba490c4906ec773c39db9f2a18a78c997Dan Gohman  KEYWORD(nuw);
52508d012eba490c4906ec773c39db9f2a18a78c997Dan Gohman  KEYWORD(nsw);
5261224c386981f7948f298ed9ad444c40609570f2eDan Gohman  KEYWORD(exact);
527dd8004dc73d091ccb3927dbbc3b41639a3738ae3Dan Gohman  KEYWORD(inbounds);
528df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(align);
529df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(addrspace);
530df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(section);
531df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(alias);
532df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(module);
533df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(asm);
534df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(sideeffect);
5358ba2d5befc05ca73d3bac8708819bbbe759e2cf9Dale Johannesen  KEYWORD(alignstack);
536df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(gc);
537df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner
538df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(ccc);
539df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(fastcc);
540df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(coldcc);
541df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(x86_stdcallcc);
542df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(x86_fastcallcc);
543ded05e34b65dc42998e9db6ca1abd513e7a9d120Anton Korobeynikov  KEYWORD(x86_thiscallcc);
544385f5a99ecc7fee48a7539bc63d3e1d3b5089c0dAnton Korobeynikov  KEYWORD(arm_apcscc);
545385f5a99ecc7fee48a7539bc63d3e1d3b5089c0dAnton Korobeynikov  KEYWORD(arm_aapcscc);
546385f5a99ecc7fee48a7539bc63d3e1d3b5089c0dAnton Korobeynikov  KEYWORD(arm_aapcs_vfpcc);
547211a14e476abc9b864ab6a5d5e0bbb86d288b650Anton Korobeynikov  KEYWORD(msp430_intrcc);
548f9930da2ef72350c6c805af09e754e4e6e13d47bChe-Liang Chiou  KEYWORD(ptx_kernel);
549f9930da2ef72350c6c805af09e754e4e6e13d47bChe-Liang Chiou  KEYWORD(ptx_device);
550385f5a99ecc7fee48a7539bc63d3e1d3b5089c0dAnton Korobeynikov
551df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(cc);
552df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(c);
553df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner
554df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(signext);
555df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(zeroext);
556df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(inreg);
557df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(sret);
558df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(nounwind);
559df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(noreturn);
560df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(noalias);
561df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(nocapture);
562df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(byval);
563df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(nest);
564df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(readnone);
565df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(readonly);
566df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner
567570a4a5d9ca31f276a67502d1e0533d59d331feaJakob Stoklund Olesen  KEYWORD(inlinehint);
568df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(noinline);
569df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(alwaysinline);
570df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(optsize);
571df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(ssp);
572df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(sspreq);
573d18e31ae17390d9c6f6cf93d18badf962452031dDevang Patel  KEYWORD(noredzone);
574578efa920abd218ba75a0fb3c9b8398f4c0a774bDevang Patel  KEYWORD(noimplicitfloat);
575c5ec8a78ea898087ad361e5b755f74a76150e5fdAnton Korobeynikov  KEYWORD(naked);
576970bfcc7d8b9991430caa7ab33975617f3f4c40dCharles Davis  KEYWORD(hotpatch);
577df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner
578df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(type);
579df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(opaque);
580df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner
581df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(eq); KEYWORD(ne); KEYWORD(slt); KEYWORD(sgt); KEYWORD(sle);
582df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(sge); KEYWORD(ult); KEYWORD(ugt); KEYWORD(ule); KEYWORD(uge);
583df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(oeq); KEYWORD(one); KEYWORD(olt); KEYWORD(ogt); KEYWORD(ole);
584df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(oge); KEYWORD(ord); KEYWORD(uno); KEYWORD(ueq); KEYWORD(une);
5859ea4034e007a83c778cd306ea66481be1317a51bMisha Brukman
586df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(x);
58709d9ef4122414a1a2ec95f52d660d6500f2819d0Chris Lattner  KEYWORD(blockaddress);
5888e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner#undef KEYWORD
5898e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
5908e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // Keywords for types.
591df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner#define TYPEKEYWORD(STR, LLVMTY) \
5928e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (Len == strlen(STR) && !memcmp(StartChar, STR, strlen(STR))) { \
593df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    TyVal = LLVMTY; return lltok::Type; }
5941d0be15f89cb5056e20e2d24faa8d6afb1573bcaOwen Anderson  TYPEKEYWORD("void",      Type::getVoidTy(Context));
5951d0be15f89cb5056e20e2d24faa8d6afb1573bcaOwen Anderson  TYPEKEYWORD("float",     Type::getFloatTy(Context));
5961d0be15f89cb5056e20e2d24faa8d6afb1573bcaOwen Anderson  TYPEKEYWORD("double",    Type::getDoubleTy(Context));
5971d0be15f89cb5056e20e2d24faa8d6afb1573bcaOwen Anderson  TYPEKEYWORD("x86_fp80",  Type::getX86_FP80Ty(Context));
5981d0be15f89cb5056e20e2d24faa8d6afb1573bcaOwen Anderson  TYPEKEYWORD("fp128",     Type::getFP128Ty(Context));
5991d0be15f89cb5056e20e2d24faa8d6afb1573bcaOwen Anderson  TYPEKEYWORD("ppc_fp128", Type::getPPC_FP128Ty(Context));
6001d0be15f89cb5056e20e2d24faa8d6afb1573bcaOwen Anderson  TYPEKEYWORD("label",     Type::getLabelTy(Context));
6011d0be15f89cb5056e20e2d24faa8d6afb1573bcaOwen Anderson  TYPEKEYWORD("metadata",  Type::getMetadataTy(Context));
602bb811a244567aa8a1522203f15588f4d001b7353Dale Johannesen  TYPEKEYWORD("x86_mmx",   Type::getX86_MMXTy(Context));
6038e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner#undef TYPEKEYWORD
6048e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
6058e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // Handle special forms for autoupgrading.  Drop these in LLVM 3.0.  This is
6068e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // to avoid conflicting with the sext/zext instructions, below.
6078e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (Len == 4 && !memcmp(StartChar, "sext", 4)) {
6088e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    // Scan CurPtr ahead, seeing if there is just whitespace before the newline.
6098e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (JustWhitespaceNewLine(CurPtr))
610df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      return lltok::kw_signext;
6118e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  } else if (Len == 4 && !memcmp(StartChar, "zext", 4)) {
6128e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    // Scan CurPtr ahead, seeing if there is just whitespace before the newline.
6138e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (JustWhitespaceNewLine(CurPtr))
614df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      return lltok::kw_zeroext;
61513ad5aaaff8a446758b402fd5e9aea22f5bc5682Victor Hernandez  } else if (Len == 6 && !memcmp(StartChar, "malloc", 6)) {
616cf4d2f11a1acc12a0f6b50991907e4a998ee9cddChris Lattner    // FIXME: Remove in LLVM 3.0.
617cf4d2f11a1acc12a0f6b50991907e4a998ee9cddChris Lattner    // Autoupgrade malloc instruction.
61813ad5aaaff8a446758b402fd5e9aea22f5bc5682Victor Hernandez    return lltok::kw_malloc;
619046e78ce55a7c3d82b7b6758d2d77f2d99f970bfVictor Hernandez  } else if (Len == 4 && !memcmp(StartChar, "free", 4)) {
620046e78ce55a7c3d82b7b6758d2d77f2d99f970bfVictor Hernandez    // FIXME: Remove in LLVM 3.0.
621046e78ce55a7c3d82b7b6758d2d77f2d99f970bfVictor Hernandez    // Autoupgrade malloc instruction.
622046e78ce55a7c3d82b7b6758d2d77f2d99f970bfVictor Hernandez    return lltok::kw_free;
6238e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
6242c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
6258e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // Keywords for instructions.
626df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner#define INSTKEYWORD(STR, Enum) \
627df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  if (Len == strlen(#STR) && !memcmp(StartChar, #STR, strlen(#STR))) { \
628df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    UIntVal = Instruction::Enum; return lltok::kw_##STR; }
629df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner
630ae3a0be92e33bc716722aa600983fc1535acb122Dan Gohman  INSTKEYWORD(add,   Add);  INSTKEYWORD(fadd,   FAdd);
631ae3a0be92e33bc716722aa600983fc1535acb122Dan Gohman  INSTKEYWORD(sub,   Sub);  INSTKEYWORD(fsub,   FSub);
632ae3a0be92e33bc716722aa600983fc1535acb122Dan Gohman  INSTKEYWORD(mul,   Mul);  INSTKEYWORD(fmul,   FMul);
633df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(udiv,  UDiv); INSTKEYWORD(sdiv,  SDiv); INSTKEYWORD(fdiv,  FDiv);
634df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(urem,  URem); INSTKEYWORD(srem,  SRem); INSTKEYWORD(frem,  FRem);
635df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(shl,   Shl);  INSTKEYWORD(lshr,  LShr); INSTKEYWORD(ashr,  AShr);
636df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(and,   And);  INSTKEYWORD(or,    Or);   INSTKEYWORD(xor,   Xor);
637df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(icmp,  ICmp); INSTKEYWORD(fcmp,  FCmp);
638df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner
639df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(phi,         PHI);
640df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(call,        Call);
641df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(trunc,       Trunc);
642df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(zext,        ZExt);
643df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(sext,        SExt);
644df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(fptrunc,     FPTrunc);
645df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(fpext,       FPExt);
646df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(uitofp,      UIToFP);
647df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(sitofp,      SIToFP);
648df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(fptoui,      FPToUI);
649df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(fptosi,      FPToSI);
650df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(inttoptr,    IntToPtr);
651df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(ptrtoint,    PtrToInt);
652df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(bitcast,     BitCast);
653df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(select,      Select);
654df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(va_arg,      VAArg);
655df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(ret,         Ret);
656df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(br,          Br);
657df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(switch,      Switch);
658ab21db79ef1d2530880ad11f21f0b87ffca02dd4Chris Lattner  INSTKEYWORD(indirectbr,  IndirectBr);
659df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(invoke,      Invoke);
660df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(unwind,      Unwind);
661df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(unreachable, Unreachable);
662df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner
663df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(alloca,      Alloca);
664df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(load,        Load);
665df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(store,       Store);
666df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(getelementptr, GetElementPtr);
667df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner
668df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(extractelement, ExtractElement);
669df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(insertelement,  InsertElement);
670df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(shufflevector,  ShuffleVector);
671df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(getresult,      ExtractValue);
672df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(extractvalue,   ExtractValue);
673df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(insertvalue,    InsertValue);
6742c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling#undef INSTKEYWORD
6752c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
6768e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // Check for [us]0x[0-9A-Fa-f]+ which are Hexadecimal constant generated by
6778e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // the CFE to avoid forcing it to deal with 64-bit numbers.
6788e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if ((TokStart[0] == 'u' || TokStart[0] == 's') &&
6798e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      TokStart[1] == '0' && TokStart[2] == 'x' && isxdigit(TokStart[3])) {
6808e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    int len = CurPtr-TokStart-3;
6818e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    uint32_t bits = len * 4;
682689ad6ef3fd2e89394f1e8860dfebfe56b73c3daDaniel Dunbar    APInt Tmp(bits, StringRef(TokStart+3, len), 16);
6838e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    uint32_t activeBits = Tmp.getActiveBits();
6848e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (activeBits > 0 && activeBits < bits)
6858e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      Tmp.trunc(activeBits);
686df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    APSIntVal = APSInt(Tmp, TokStart[0] == 'u');
687df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::APSInt;
6888e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
6892c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
6904ce0df610879e82d9853c6a38a75b1883feaee06Chris Lattner  // If this is "cc1234", return this as just "cc".
6918e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (TokStart[0] == 'c' && TokStart[1] == 'c') {
6928e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    CurPtr = TokStart+2;
693df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::kw_cc;
6948e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
6952c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
6964ce0df610879e82d9853c6a38a75b1883feaee06Chris Lattner  // If this starts with "call", return it as CALL.  This is to support old
6974ce0df610879e82d9853c6a38a75b1883feaee06Chris Lattner  // broken .ll files.  FIXME: remove this with LLVM 3.0.
6984ce0df610879e82d9853c6a38a75b1883feaee06Chris Lattner  if (CurPtr-TokStart > 4 && !memcmp(TokStart, "call", 4)) {
6994ce0df610879e82d9853c6a38a75b1883feaee06Chris Lattner    CurPtr = TokStart+4;
700df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    UIntVal = Instruction::Call;
701df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::kw_call;
7024ce0df610879e82d9853c6a38a75b1883feaee06Chris Lattner  }
7032c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
704df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  // Finally, if this isn't known, return an error.
7058e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  CurPtr = TokStart+1;
706df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  return lltok::Error;
7078e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
7088e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
7098e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
7108e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner/// Lex0x: Handle productions that start with 0x, knowing that it matches and
7118e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner/// that this is not a label:
7128e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    HexFPConstant     0x[0-9A-Fa-f]+
7138e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    HexFP80Constant   0xK[0-9A-Fa-f]+
7148e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    HexFP128Constant  0xL[0-9A-Fa-f]+
7158e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    HexPPC128Constant 0xM[0-9A-Fa-f]+
716df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattnerlltok::Kind LLLexer::Lex0x() {
7178e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  CurPtr = TokStart + 2;
7182c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
7198e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  char Kind;
7208e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (CurPtr[0] >= 'K' && CurPtr[0] <= 'M') {
7218e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    Kind = *CurPtr++;
7228e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  } else {
7238e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    Kind = 'J';
7248e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
7258e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
7268e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (!isxdigit(CurPtr[0])) {
727df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    // Bad token, return it as an error.
7288e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    CurPtr = TokStart+1;
729df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::Error;
7308e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
7312c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
7328e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  while (isxdigit(CurPtr[0]))
7338e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    ++CurPtr;
7342c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
7358e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (Kind == 'J') {
7368e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    // HexFPConstant - Floating point constant represented in IEEE format as a
7378e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    // hexadecimal number for when exponential notation is not precise enough.
7388e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    // Float and double only.
739df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    APFloatVal = APFloat(BitsToDouble(HexIntToVal(TokStart+2, CurPtr)));
740df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::APFloat;
7418e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
7422c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
7438e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  uint64_t Pair[2];
7448e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  switch (Kind) {
745c23197a26f34f559ea9797de51e187087c039c42Torok Edwin  default: llvm_unreachable("Unknown kind!");
7468e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case 'K':
7478e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    // F80HexFPConstant - x87 long double in hexadecimal format (10 bytes)
7481b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen    FP80HexToIntPair(TokStart+3, CurPtr, Pair);
749df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    APFloatVal = APFloat(APInt(80, 2, Pair));
750df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::APFloat;
7518e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case 'L':
7528e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    // F128HexFPConstant - IEEE 128-bit in hexadecimal format (16 bytes)
7531b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen    HexToIntPair(TokStart+3, CurPtr, Pair);
754df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    APFloatVal = APFloat(APInt(128, 2, Pair), true);
755df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::APFloat;
7568e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case 'M':
7578e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    // PPC128HexFPConstant - PowerPC 128-bit in hexadecimal format (16 bytes)
7581b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen    HexToIntPair(TokStart+3, CurPtr, Pair);
759df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    APFloatVal = APFloat(APInt(128, 2, Pair));
760df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::APFloat;
7618e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
7628e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
7638e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
7648e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner/// LexIdentifier: Handle several related productions:
7658e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    Label             [-a-zA-Z$._0-9]+:
7668e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    NInteger          -[0-9]+
7678e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    FPConstant        [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
7688e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    PInteger          [0-9]+
7698e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    HexFPConstant     0x[0-9A-Fa-f]+
7708e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    HexFP80Constant   0xK[0-9A-Fa-f]+
7718e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    HexFP128Constant  0xL[0-9A-Fa-f]+
7728e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    HexPPC128Constant 0xM[0-9A-Fa-f]+
773df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattnerlltok::Kind LLLexer::LexDigitOrNegative() {
7748e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // If the letter after the negative is a number, this is probably a label.
7758e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (!isdigit(TokStart[0]) && !isdigit(CurPtr[0])) {
7768e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    // Okay, this is not a number after the -, it's probably a label.
7778e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (const char *End = isLabelTail(CurPtr)) {
778df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      StrVal.assign(TokStart, End-1);
7798e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      CurPtr = End;
780df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      return lltok::LabelStr;
7818e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    }
7822c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
783df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::Error;
7848e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
7852c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
7868e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // At this point, it is either a label, int or fp constant.
7872c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
7888e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // Skip digits, we have at least one.
7892c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling  for (; isdigit(CurPtr[0]); ++CurPtr)
7902c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling    /*empty*/;
7912c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
7928e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // Check to see if this really is a label afterall, e.g. "-1:".
7938e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (isLabelChar(CurPtr[0]) || CurPtr[0] == ':') {
7948e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (const char *End = isLabelTail(CurPtr)) {
795df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      StrVal.assign(TokStart, End-1);
7968e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      CurPtr = End;
797df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      return lltok::LabelStr;
7988e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    }
7998e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
8002c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
8018e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // If the next character is a '.', then it is a fp value, otherwise its
8028e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // integer.
8038e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (CurPtr[0] != '.') {
8048e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (TokStart[0] == '0' && TokStart[1] == 'x')
8058e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      return Lex0x();
8068e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    unsigned Len = CurPtr-TokStart;
8078e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    uint32_t numBits = ((Len * 64) / 19) + 2;
808689ad6ef3fd2e89394f1e8860dfebfe56b73c3daDaniel Dunbar    APInt Tmp(numBits, StringRef(TokStart, Len), 10);
8098e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (TokStart[0] == '-') {
8108e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      uint32_t minBits = Tmp.getMinSignedBits();
8118e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      if (minBits > 0 && minBits < numBits)
8128e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner        Tmp.trunc(minBits);
813df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      APSIntVal = APSInt(Tmp, false);
8148e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    } else {
8158e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      uint32_t activeBits = Tmp.getActiveBits();
8168e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      if (activeBits > 0 && activeBits < numBits)
8178e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner        Tmp.trunc(activeBits);
818df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      APSIntVal = APSInt(Tmp, true);
8198e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    }
820df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::APSInt;
8218e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
8228e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
8238e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  ++CurPtr;
8242c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
8258e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // Skip over [0-9]*([eE][-+]?[0-9]+)?
8268e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  while (isdigit(CurPtr[0])) ++CurPtr;
8272c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
8288e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (CurPtr[0] == 'e' || CurPtr[0] == 'E') {
8292c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling    if (isdigit(CurPtr[1]) ||
8308e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner        ((CurPtr[1] == '-' || CurPtr[1] == '+') && isdigit(CurPtr[2]))) {
8318e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      CurPtr += 2;
8328e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      while (isdigit(CurPtr[0])) ++CurPtr;
8338e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    }
8348e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
8352c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
836df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  APFloatVal = APFloat(atof(TokStart));
837df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  return lltok::APFloat;
8388e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
8398e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
8408e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    FPConstant  [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
841df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattnerlltok::Kind LLLexer::LexPositive() {
8428e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // If the letter after the negative is a number, this is probably not a
8438e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // label.
8448e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (!isdigit(CurPtr[0]))
845df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::Error;
8462c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
8478e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // Skip digits.
8482c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling  for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
8492c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling    /*empty*/;
8508e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
8518e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // At this point, we need a '.'.
8528e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (CurPtr[0] != '.') {
8538e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    CurPtr = TokStart+1;
854df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::Error;
8558e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
8562c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
8578e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  ++CurPtr;
8582c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
8598e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // Skip over [0-9]*([eE][-+]?[0-9]+)?
8608e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  while (isdigit(CurPtr[0])) ++CurPtr;
8612c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
8628e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (CurPtr[0] == 'e' || CurPtr[0] == 'E') {
8632c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling    if (isdigit(CurPtr[1]) ||
8648e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner        ((CurPtr[1] == '-' || CurPtr[1] == '+') && isdigit(CurPtr[2]))) {
8658e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      CurPtr += 2;
8668e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      while (isdigit(CurPtr[0])) ++CurPtr;
8678e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    }
8688e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
8692c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
870df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  APFloatVal = APFloat(atof(TokStart));
871df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  return lltok::APFloat;
8728e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
873