[llvm-branch-commits] [llvm-branch] r136019 - in /llvm/branches/exception-handling-rewrite/lib/AsmParser: LLLexer.cpp LLParser.cpp LLParser.h LLToken.h

Bill Wendling isanbard at gmail.com
Mon Jul 25 16:58:15 PDT 2011


Author: void
Date: Mon Jul 25 18:58:15 2011
New Revision: 136019

URL: http://llvm.org/viewvc/llvm-project?rev=136019&view=rev
Log:
Add parsing support for the landingpad instruction.

Modified:
    llvm/branches/exception-handling-rewrite/lib/AsmParser/LLLexer.cpp
    llvm/branches/exception-handling-rewrite/lib/AsmParser/LLParser.cpp
    llvm/branches/exception-handling-rewrite/lib/AsmParser/LLParser.h
    llvm/branches/exception-handling-rewrite/lib/AsmParser/LLToken.h

Modified: llvm/branches/exception-handling-rewrite/lib/AsmParser/LLLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/exception-handling-rewrite/lib/AsmParser/LLLexer.cpp?rev=136019&r1=136018&r2=136019&view=diff
==============================================================================
--- llvm/branches/exception-handling-rewrite/lib/AsmParser/LLLexer.cpp (original)
+++ llvm/branches/exception-handling-rewrite/lib/AsmParser/LLLexer.cpp Mon Jul 25 18:58:15 2011
@@ -572,6 +572,10 @@
 
   KEYWORD(x);
   KEYWORD(blockaddress);
+
+  KEYWORD(personality);
+  KEYWORD(catch);
+  KEYWORD(filter);
 #undef KEYWORD
 
   // Keywords for types.
@@ -637,6 +641,7 @@
   INSTKEYWORD(shufflevector,  ShuffleVector);
   INSTKEYWORD(extractvalue,   ExtractValue);
   INSTKEYWORD(insertvalue,    InsertValue);
+  INSTKEYWORD(landingpad,     LandingPad);
 #undef INSTKEYWORD
 
   // Check for [us]0x[0-9A-Fa-f]+ which are Hexadecimal constant generated by
@@ -664,7 +669,6 @@
   return lltok::Error;
 }
 
-
 /// Lex0x: Handle productions that start with 0x, knowing that it matches and
 /// that this is not a label:
 ///    HexFPConstant     0x[0-9A-Fa-f]+

Modified: llvm/branches/exception-handling-rewrite/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/exception-handling-rewrite/lib/AsmParser/LLParser.cpp?rev=136019&r1=136018&r2=136019&view=diff
==============================================================================
--- llvm/branches/exception-handling-rewrite/lib/AsmParser/LLParser.cpp (original)
+++ llvm/branches/exception-handling-rewrite/lib/AsmParser/LLParser.cpp Mon Jul 25 18:58:15 2011
@@ -2920,6 +2920,7 @@
   case lltok::kw_insertelement:  return ParseInsertElement(Inst, PFS);
   case lltok::kw_shufflevector:  return ParseShuffleVector(Inst, PFS);
   case lltok::kw_phi:            return ParsePHI(Inst, PFS);
+  case lltok::kw_landingpad:     return ParseLandingPad(Inst, PFS);
   case lltok::kw_call:           return ParseCall(Inst, PFS, false);
   case lltok::kw_tail:           return ParseCall(Inst, PFS, true);
   // Memory.
@@ -3470,6 +3471,53 @@
   return AteExtraComma ? InstExtraComma : InstNormal;
 }
 
+/// ParseLandingPad
+///   ::= 'landingpad' Type 'personality' TypeAndValue (ClauseID ClauseList)+
+/// ClauseID
+///   ::= 'catch'
+///   ::= 'filter'
+/// ClauseList
+///   ::= TypeAndValue (',' TypeAndValue)*
+bool LLParser::ParseLandingPad(Instruction *&Inst, PerFunctionState &PFS) {
+  Type *Ty = 0; LocTy TyLoc;
+  Value *PersFn; LocTy PersFnLoc;
+  LocTy LPLoc = Lex.getLoc();
+
+  if (ParseType(Ty, TyLoc) ||
+      ParseToken(lltok::kw_personality, "expected 'personality'") ||
+      ParseTypeAndValue(PersFn, PersFnLoc, PFS))
+    return true;
+
+  SmallVector<std::pair<LandingPadInst::ClauseType, Value*>, 16> Clauses;
+
+  while (Lex.getKind() == lltok::kw_catch || Lex.getKind() == lltok::kw_filter){
+    LandingPadInst::ClauseType CT;
+    if (Lex.getKind() == lltok::kw_catch) {
+      CT = LandingPadInst::Catch;
+      ParseToken(lltok::kw_catch, "expected 'catch'");
+    } else {
+      CT = LandingPadInst::Filter;
+      ParseToken(lltok::kw_filter, "expected 'filter'");
+    }
+
+    do {
+      Value *V; LocTy VLoc;
+      if (ParseTypeAndValue(V, VLoc, PFS))
+        return true;
+      Clauses.push_back(std::make_pair(CT, V));
+    } while (EatIfPresent(lltok::comma));
+  }
+
+  LandingPadInst *LP = LandingPadInst::Create(Ty, PersFn, Clauses.size());
+
+  for (SmallVectorImpl<std::pair<LandingPadInst::ClauseType, Value*> >::iterator
+         I = Clauses.begin(), E = Clauses.end(); I != E; ++I)
+    LP->addClause(I->first, I->second);
+
+  Inst = LP;
+  return false;
+}
+
 /// ParseCall
 ///   ::= 'tail'? 'call' OptionalCallingConv OptionalAttrs Type Value
 ///       ParameterList OptionalAttrs

Modified: llvm/branches/exception-handling-rewrite/lib/AsmParser/LLParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/exception-handling-rewrite/lib/AsmParser/LLParser.h?rev=136019&r1=136018&r2=136019&view=diff
==============================================================================
--- llvm/branches/exception-handling-rewrite/lib/AsmParser/LLParser.h (original)
+++ llvm/branches/exception-handling-rewrite/lib/AsmParser/LLParser.h Mon Jul 25 18:58:15 2011
@@ -356,6 +356,7 @@
     bool ParseInsertElement(Instruction *&I, PerFunctionState &PFS);
     bool ParseShuffleVector(Instruction *&I, PerFunctionState &PFS);
     int ParsePHI(Instruction *&I, PerFunctionState &PFS);
+    bool ParseLandingPad(Instruction *&I, PerFunctionState &PFS);
     bool ParseCall(Instruction *&I, PerFunctionState &PFS, bool isTail);
     int ParseAlloc(Instruction *&I, PerFunctionState &PFS);
     int ParseLoad(Instruction *&I, PerFunctionState &PFS, bool isVolatile);

Modified: llvm/branches/exception-handling-rewrite/lib/AsmParser/LLToken.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/exception-handling-rewrite/lib/AsmParser/LLToken.h?rev=136019&r1=136018&r2=136019&view=diff
==============================================================================
--- llvm/branches/exception-handling-rewrite/lib/AsmParser/LLToken.h (original)
+++ llvm/branches/exception-handling-rewrite/lib/AsmParser/LLToken.h Mon Jul 25 18:58:15 2011
@@ -118,6 +118,8 @@
     kw_fptoui, kw_fptosi, kw_inttoptr, kw_ptrtoint, kw_bitcast,
     kw_select, kw_va_arg,
 
+    kw_landingpad, kw_personality, kw_catch, kw_filter,
+
     kw_ret, kw_br, kw_switch, kw_indirectbr, kw_invoke, kw_unwind,
     kw_unreachable,
 
@@ -140,8 +142,8 @@
     // Type valued tokens (TyVal).
     Type,
 
-    APFloat,  // APFloatVal
-    APSInt // APSInt
+    APFloat,           // APFloatVal
+    APSInt             // APSInt
   };
 } // end namespace lltok
 } // end namespace llvm





More information about the llvm-branch-commits mailing list