#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Assembly/Parser.h"
+#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace llvm;
case ';':
SkipLineComment();
return LexToken();
- case '!': return lltok::Metadata;
+ case '!': return LexExclaim();
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case '-':
return false;
}
+/// LexExclaim:
+/// !foo
+/// !
+lltok::Kind LLLexer::LexExclaim() {
+ // Lex a metadata name as a MetadataVar.
+ if (isalpha(CurPtr[0])) {
+ ++CurPtr;
+ while (isalnum(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
+ CurPtr[0] == '.' || CurPtr[0] == '_')
+ ++CurPtr;
+ StrVal.assign(TokStart+1, CurPtr); // Skip !
+ return lltok::MetadataVar;
+ }
+ return lltok::exclaim;
+}
+
/// LexIdentifier: Handle several related productions:
/// Label [-a-zA-Z$._0-9]+:
/// IntegerType i[0-9]+
Error("bitwidth for integer type out of range!");
return lltok::Error;
}
- TyVal = Context.getIntegerType(NumBits);
+ TyVal = IntegerType::get(Context, NumBits);
return lltok::Type;
}
KEYWORD(private);
KEYWORD(linker_private);
+ KEYWORD(linker_private_weak);
+ KEYWORD(linker_private_weak_def_auto);
KEYWORD(internal);
KEYWORD(available_externally);
KEYWORD(linkonce);
KEYWORD(deplibs);
KEYWORD(datalayout);
KEYWORD(volatile);
+ KEYWORD(nuw);
+ KEYWORD(nsw);
+ KEYWORD(exact);
+ KEYWORD(inbounds);
KEYWORD(align);
KEYWORD(addrspace);
KEYWORD(section);
KEYWORD(module);
KEYWORD(asm);
KEYWORD(sideeffect);
+ KEYWORD(alignstack);
KEYWORD(gc);
KEYWORD(ccc);
KEYWORD(coldcc);
KEYWORD(x86_stdcallcc);
KEYWORD(x86_fastcallcc);
+ KEYWORD(x86_thiscallcc);
KEYWORD(arm_apcscc);
KEYWORD(arm_aapcscc);
KEYWORD(arm_aapcs_vfpcc);
+ KEYWORD(msp430_intrcc);
KEYWORD(cc);
KEYWORD(c);
KEYWORD(readnone);
KEYWORD(readonly);
+ KEYWORD(inlinehint);
KEYWORD(noinline);
KEYWORD(alwaysinline);
KEYWORD(optsize);
KEYWORD(oge); KEYWORD(ord); KEYWORD(uno); KEYWORD(ueq); KEYWORD(une);
KEYWORD(x);
+ KEYWORD(blockaddress);
#undef KEYWORD
// Keywords for types.
#define TYPEKEYWORD(STR, LLVMTY) \
if (Len == strlen(STR) && !memcmp(StartChar, STR, strlen(STR))) { \
TyVal = LLVMTY; return lltok::Type; }
- TYPEKEYWORD("void", Type::VoidTy);
- TYPEKEYWORD("float", Type::FloatTy);
- TYPEKEYWORD("double", Type::DoubleTy);
- TYPEKEYWORD("x86_fp80", Type::X86_FP80Ty);
- TYPEKEYWORD("fp128", Type::FP128Ty);
- TYPEKEYWORD("ppc_fp128", Type::PPC_FP128Ty);
- TYPEKEYWORD("label", Type::LabelTy);
- TYPEKEYWORD("metadata", Type::MetadataTy);
+ TYPEKEYWORD("void", Type::getVoidTy(Context));
+ TYPEKEYWORD("float", Type::getFloatTy(Context));
+ TYPEKEYWORD("double", Type::getDoubleTy(Context));
+ TYPEKEYWORD("x86_fp80", Type::getX86_FP80Ty(Context));
+ TYPEKEYWORD("fp128", Type::getFP128Ty(Context));
+ TYPEKEYWORD("ppc_fp128", Type::getPPC_FP128Ty(Context));
+ TYPEKEYWORD("label", Type::getLabelTy(Context));
+ TYPEKEYWORD("metadata", Type::getMetadataTy(Context));
#undef TYPEKEYWORD
// Handle special forms for autoupgrading. Drop these in LLVM 3.0. This is
// Scan CurPtr ahead, seeing if there is just whitespace before the newline.
if (JustWhitespaceNewLine(CurPtr))
return lltok::kw_zeroext;
+ } else if (Len == 6 && !memcmp(StartChar, "malloc", 6)) {
+ // FIXME: Remove in LLVM 3.0.
+ // Autoupgrade malloc instruction.
+ return lltok::kw_malloc;
+ } else if (Len == 4 && !memcmp(StartChar, "free", 4)) {
+ // FIXME: Remove in LLVM 3.0.
+ // Autoupgrade malloc instruction.
+ return lltok::kw_free;
}
// Keywords for instructions.
INSTKEYWORD(ret, Ret);
INSTKEYWORD(br, Br);
INSTKEYWORD(switch, Switch);
+ INSTKEYWORD(indirectbr, IndirectBr);
INSTKEYWORD(invoke, Invoke);
INSTKEYWORD(unwind, Unwind);
INSTKEYWORD(unreachable, Unreachable);
- INSTKEYWORD(malloc, Malloc);
INSTKEYWORD(alloca, Alloca);
- INSTKEYWORD(free, Free);
INSTKEYWORD(load, Load);
INSTKEYWORD(store, Store);
INSTKEYWORD(getelementptr, GetElementPtr);
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);
+ APInt Tmp(bits, StringRef(TokStart+3, len), 16);
uint32_t activeBits = Tmp.getActiveBits();
if (activeBits > 0 && activeBits < bits)
Tmp.trunc(activeBits);
return Lex0x();
unsigned Len = CurPtr-TokStart;
uint32_t numBits = ((Len * 64) / 19) + 2;
- APInt Tmp(numBits, TokStart, Len, 10);
+ APInt Tmp(numBits, StringRef(TokStart, Len), 10);
if (TokStart[0] == '-') {
uint32_t minBits = Tmp.getMinSignedBits();
if (minBits > 0 && minBits < numBits)