summaryrefslogtreecommitdiffstats
path: root/lib/AsmParser
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-08-29 17:12:13 +0000
committerChris Lattner <sabre@nondot.org>2008-08-29 17:12:13 +0000
commit6ac28095c27d887fe1f8191883baf67ab99432fe (patch)
tree06d6ce65db546b9d78ac80cf18f9c1b45009af82 /lib/AsmParser
parentba705f62b1f78f4854e2640c7a5626a05417c646 (diff)
downloadexternal_llvm-6ac28095c27d887fe1f8191883baf67ab99432fe.zip
external_llvm-6ac28095c27d887fe1f8191883baf67ab99432fe.tar.gz
external_llvm-6ac28095c27d887fe1f8191883baf67ab99432fe.tar.bz2
Add support for parsing .ll files that have numbers in front of
nameless values, such as: %3 = add i32 4, 2 This fixes the first half of PR2480 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55539 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AsmParser')
-rw-r--r--lib/AsmParser/llvmAsmParser.y44
1 files changed, 39 insertions, 5 deletions
diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y
index d9b8499..36b56ea 100644
--- a/lib/AsmParser/llvmAsmParser.y
+++ b/lib/AsmParser/llvmAsmParser.y
@@ -249,10 +249,12 @@ static bool inFunctionScope() { return CurFun.CurrentFunction != 0; }
// Code to handle definitions of all the types
//===----------------------------------------------------------------------===//
-static void InsertValue(Value *V, ValueList &ValueTab = CurFun.Values) {
+/// InsertValue - Insert a value into the value table. If it is named, this
+/// returns -1, otherwise it returns the slot number for the value.
+static int InsertValue(Value *V, ValueList &ValueTab = CurFun.Values) {
// Things that have names or are void typed don't get slot numbers
if (V->hasName() || (V->getType() == Type::VoidTy))
- return;
+ return -1;
// In the case of function values, we have to allow for the forward reference
// of basic blocks, which are included in the numbering. Consequently, we keep
@@ -262,10 +264,11 @@ static void InsertValue(Value *V, ValueList &ValueTab = CurFun.Values) {
if (ValueTab.size() <= CurFun.NextValNum)
ValueTab.resize(CurFun.NextValNum+1);
ValueTab[CurFun.NextValNum++] = V;
- return;
+ return CurFun.NextValNum-1;
}
// For all other lists, its okay to just tack it on the back of the vector.
ValueTab.push_back(V);
+ return ValueTab.size()-1;
}
static const Type *getTypeVal(const ValID &D, bool DoNotImprovise = false) {
@@ -1084,7 +1087,7 @@ Module *llvm::RunVMAsmParser(llvm::MemoryBuffer *MB) {
%token CC_TOK CCC_TOK FASTCC_TOK COLDCC_TOK X86_STDCALLCC_TOK X86_FASTCALLCC_TOK
%token X86_SSECALLCC_TOK
%token DATALAYOUT
-%type <UIntVal> OptCallingConv
+%type <UIntVal> OptCallingConv LocalNumber
%type <ParamAttrs> OptParamAttrs ParamAttr
%type <ParamAttrs> OptFuncAttrs FuncAttr
@@ -1177,6 +1180,12 @@ OptLocalAssign : LocalName '=' {
CHECK_FOR_ERROR
};
+LocalNumber : LOCALVAL_ID '=' {
+ $$ = $1;
+ CHECK_FOR_ERROR
+};
+
+
GlobalName : GLOBALVAR | ATSTRINGCONSTANT ;
OptGlobalAssign : GlobalAssign
@@ -2673,7 +2682,7 @@ BasicBlockList : BasicBlockList BasicBlock {
// Basic blocks are terminated by branching instructions:
// br, br/cc, switch, ret
//
-BasicBlock : InstructionList OptLocalAssign BBTerminatorInst {
+BasicBlock : InstructionList OptLocalAssign BBTerminatorInst {
setValueName($3, $2);
CHECK_FOR_ERROR
InsertValue($3);
@@ -2682,6 +2691,19 @@ BasicBlock : InstructionList OptLocalAssign BBTerminatorInst {
CHECK_FOR_ERROR
};
+BasicBlock : InstructionList LocalNumber BBTerminatorInst {
+ CHECK_FOR_ERROR
+ int ValNum = InsertValue($3);
+ if (ValNum != (int)$2)
+ GEN_ERROR("Result value number %" + utostr($2) +
+ " is incorrect, expected %" + utostr((unsigned)ValNum));
+
+ $1->getInstList().push_back($3);
+ $$ = $1;
+ CHECK_FOR_ERROR
+};
+
+
InstructionList : InstructionList Inst {
if (CastInst *CI1 = dyn_cast<CastInst>($2))
if (CastInst *CI2 = dyn_cast<CastInst>(CI1->getOperand(0)))
@@ -2901,6 +2923,18 @@ Inst : OptLocalAssign InstVal {
CHECK_FOR_ERROR
};
+Inst : LocalNumber InstVal {
+ CHECK_FOR_ERROR
+ int ValNum = InsertValue($2);
+
+ if (ValNum != (int)$1)
+ GEN_ERROR("Result value number %" + utostr($1) +
+ " is incorrect, expected %" + utostr((unsigned)ValNum));
+
+ $$ = $2;
+ CHECK_FOR_ERROR
+ };
+
PHIList : Types '[' ValueRef ',' ValueRef ']' { // Used for PHI nodes
if (!UpRefs.empty())