diff --git a/lib/AsmParser/Lexer.l b/lib/AsmParser/Lexer.l index 47c067ba8ce..92d4f3424f8 100644 --- a/lib/AsmParser/Lexer.l +++ b/lib/AsmParser/Lexer.l @@ -19,6 +19,7 @@ %{ #include "ParserInternals.h" +#include "llvm/Module.h" #include #include "llvmAsmParser.h" #include @@ -176,6 +177,11 @@ null { return NULL_TOK; } to { return TO; } except { return EXCEPT; } not { return NOT; } /* Deprecated, turned into XOR */ +target { return TARGET; } +endian { return ENDIAN; } +pointersize { return POINTERSIZE; } +little { return LITTLE; } +big { return BIG; } void { llvmAsmlval.PrimType = Type::VoidTy ; return VOID; } bool { llvmAsmlval.PrimType = Type::BoolTy ; return BOOL; } diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y index 8309c91d5ed..19cda682a16 100644 --- a/lib/AsmParser/llvmAsmParser.y +++ b/lib/AsmParser/llvmAsmParser.y @@ -635,6 +635,7 @@ Module *RunVMAsmParser(const std::string &Filename, FILE *F) { Instruction::TermOps TermOpVal; Instruction::MemoryOps MemOpVal; Instruction::OtherOps OtherOpVal; + Module::Endianness Endianness; } %type Module FunctionList @@ -653,6 +654,7 @@ Module *RunVMAsmParser(const std::string &Filename, FILE *F) { %type JumpTable %type GlobalType // GLOBAL or CONSTANT? %type OptLinkage +%type BigOrLittle // ValueRef - Unresolved reference to a definition or BB %type ValueRef ConstValueRef SymbolicValueRef @@ -683,7 +685,7 @@ Module *RunVMAsmParser(const std::string &Filename, FILE *F) { %token IMPLEMENTATION TRUE FALSE BEGINTOK ENDTOK DECLARE GLOBAL CONSTANT %token TO EXCEPT DOTDOTDOT NULL_TOK CONST INTERNAL LINKONCE APPENDING -%token OPAQUE NOT EXTERNAL +%token OPAQUE NOT EXTERNAL TARGET ENDIAN POINTERSIZE LITTLE BIG // Basic Block Terminating Operators %token RET BR SWITCH @@ -1177,10 +1179,29 @@ ConstPool : ConstPool OptAssign CONST ConstVal { } delete $5; } + | ConstPool TARGET TargetDefinition { + } | /* empty: end of list */ { }; + +BigOrLittle : BIG { $$ = Module::BigEndian; }; +BigOrLittle : LITTLE { $$ = Module::LittleEndian; }; + +TargetDefinition : ENDIAN '=' BigOrLittle { + CurModule.CurrentModule->setEndianness($3); + } + | POINTERSIZE '=' EUINT64VAL { + if ($3 == 32) + CurModule.CurrentModule->setPointerSize(Module::Pointer32); + else if ($3 == 64) + CurModule.CurrentModule->setPointerSize(Module::Pointer64); + else + ThrowException("Invalid pointer size: '" + utostr($3) + "'!"); + }; + + //===----------------------------------------------------------------------===// // Rules to match Function Headers //===----------------------------------------------------------------------===//