For PR411:
[oota-llvm.git] / lib / AsmParser / llvmAsmParser.y
index 53862bc3e75825ebe29009471450479217239399..24b0abfdd344912a0de86f1ca889bc436e3d9367 100644 (file)
 #include "llvm/InlineAsm.h"
 #include "llvm/Instructions.h"
 #include "llvm/Module.h"
-#include "llvm/SymbolTable.h"
+#include "llvm/ValueSymbolTable.h"
 #include "llvm/Support/GetElementPtrTypeIterator.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/Streams.h"
@@ -149,6 +150,58 @@ static struct PerModuleInfo {
     }
     return Ret;
   }
+
+  bool TypeIsUnresolved(PATypeHolder* PATy) {
+    // If it isn't abstract, its resolved
+    const Type* Ty = PATy->get();
+    if (!Ty->isAbstract())
+      return false;
+    // Traverse the type looking for abstract types. If it isn't abstract then
+    // we don't need to traverse that leg of the type. 
+    std::vector<const Type*> WorkList, SeenList;
+    WorkList.push_back(Ty);
+    while (!WorkList.empty()) {
+      const Type* Ty = WorkList.back();
+      SeenList.push_back(Ty);
+      WorkList.pop_back();
+      if (const OpaqueType* OpTy = dyn_cast<OpaqueType>(Ty)) {
+        // Check to see if this is an unresolved type
+        std::map<ValID, PATypeHolder>::iterator I = LateResolveTypes.begin();
+        std::map<ValID, PATypeHolder>::iterator E = LateResolveTypes.end();
+        for ( ; I != E; ++I) {
+          if (I->second.get() == OpTy)
+            return true;
+        }
+      } else if (const SequentialType* SeqTy = dyn_cast<SequentialType>(Ty)) {
+        const Type* TheTy = SeqTy->getElementType();
+        if (TheTy->isAbstract() && TheTy != Ty) {
+          std::vector<const Type*>::iterator I = SeenList.begin(), 
+                                             E = SeenList.end();
+          for ( ; I != E; ++I)
+            if (*I == TheTy)
+              break;
+          if (I == E)
+            WorkList.push_back(TheTy);
+        }
+      } else if (const StructType* StrTy = dyn_cast<StructType>(Ty)) {
+        for (unsigned i = 0; i < StrTy->getNumElements(); ++i) {
+          const Type* TheTy = StrTy->getElementType(i);
+          if (TheTy->isAbstract() && TheTy != Ty) {
+            std::vector<const Type*>::iterator I = SeenList.begin(), 
+                                               E = SeenList.end();
+            for ( ; I != E; ++I)
+              if (*I == TheTy)
+                break;
+            if (I == E)
+              WorkList.push_back(TheTy);
+          }
+        }
+      }
+    }
+    return false;
+  }
+
+
 } CurModule;
 
 static struct PerFunctionInfo {
@@ -156,8 +209,9 @@ static struct PerFunctionInfo {
 
   std::map<const Type*, ValueList> Values; // Keep track of #'d definitions
   std::map<const Type*, ValueList> LateResolveValues;
-  bool isDeclare;                    // Is this function a forward declararation?
+  bool isDeclare;                   // Is this function a forward declararation?
   GlobalValue::LinkageTypes Linkage; // Linkage for forward declaration.
+  GlobalValue::VisibilityTypes Visibility;
 
   /// BBForwardRefs - When we see forward references to basic blocks, keep
   /// track of them here.
@@ -168,7 +222,8 @@ static struct PerFunctionInfo {
   inline PerFunctionInfo() {
     CurrentFunction = 0;
     isDeclare = false;
-    Linkage = GlobalValue::ExternalLinkage;    
+    Linkage = GlobalValue::ExternalLinkage;
+    Visibility = GlobalValue::DefaultVisibility;
   }
 
   inline void FunctionStart(Function *M) {
@@ -193,6 +248,7 @@ static struct PerFunctionInfo {
     CurrentFunction = 0;
     isDeclare = false;
     Linkage = GlobalValue::ExternalLinkage;
+    Visibility = GlobalValue::DefaultVisibility;
   }
 } CurFun;  // Info for the current function...
 
@@ -215,19 +271,19 @@ static int InsertValue(Value *V,
 
 static const Type *getTypeVal(const ValID &D, bool DoNotImprovise = false) {
   switch (D.Type) {
-  case ValID::NumberVal:               // Is it a numbered definition?
+  case ValID::LocalID:               // Is it a numbered definition?
     // Module constants occupy the lowest numbered slots...
-    if ((unsigned)D.Num < CurModule.Types.size())
-      return CurModule.Types[(unsigned)D.Num];
+    if (D.Num < CurModule.Types.size())
+      return CurModule.Types[D.Num];
     break;
-  case ValID::NameVal:                 // Is it a named definition?
+  case ValID::LocalName:                 // Is it a named definition?
     if (const Type *N = CurModule.CurrentModule->getTypeByName(D.Name)) {
       D.destroy();  // Free old strdup'd memory...
       return N;
     }
     break;
   default:
-    GenerateError("Internal parser error: Invalid symbol type reference!");
+    GenerateError("Internal parser error: Invalid symbol type reference");
     return 0;
   }
 
@@ -239,11 +295,11 @@ static const Type *getTypeVal(const ValID &D, bool DoNotImprovise = false) {
 
 
   if (inFunctionScope()) {
-    if (D.Type == ValID::NameVal) {
+    if (D.Type == ValID::LocalName) {
       GenerateError("Reference to an undefined type: '" + D.getName() + "'");
       return 0;
     } else {
-      GenerateError("Reference to an undefined type: #" + itostr(D.Num));
+      GenerateError("Reference to an undefined type: #" + utostr(D.Num));
       return 0;
     }
   }
@@ -257,13 +313,6 @@ static const Type *getTypeVal(const ValID &D, bool DoNotImprovise = false) {
   return Typ;
  }
 
-static Value *lookupInSymbolTable(const Type *Ty, const std::string &Name) {
-  SymbolTable &SymTab =
-    inFunctionScope() ? CurFun.CurrentFunction->getSymbolTable() :
-                        CurModule.CurrentModule->getSymbolTable();
-  return SymTab.lookup(Ty, Name);
-}
-
 // getValNonImprovising - Look up the value specified by the provided type and
 // the provided ValID.  If the value exists and has already been defined, return
 // it.  Otherwise return null.
@@ -276,30 +325,49 @@ static Value *getValNonImprovising(const Type *Ty, const ValID &D) {
   }
 
   switch (D.Type) {
-  case ValID::NumberVal: {                 // Is it a numbered definition?
-    unsigned Num = (unsigned)D.Num;
-
-    // Module constants occupy the lowest numbered slots...
-    std::map<const Type*,ValueList>::iterator VI = CurModule.Values.find(Ty);
-    if (VI != CurModule.Values.end()) {
-      if (Num < VI->second.size())
-        return VI->second[Num];
-      Num -= VI->second.size();
-    }
-
-    // Make sure that our type is within bounds
-    VI = CurFun.Values.find(Ty);
+  case ValID::LocalID: {                 // Is it a numbered definition?
+    // Module constants occupy the lowest numbered slots.
+    std::map<const Type*,ValueList>::iterator VI = CurFun.Values.find(Ty);
+    // Make sure that our type is within bounds.
     if (VI == CurFun.Values.end()) return 0;
 
-    // Check that the number is within bounds...
-    if (VI->second.size() <= Num) return 0;
+    // Check that the number is within bounds.
+    if (D.Num >= VI->second.size()) return 0;
 
+    return VI->second[D.Num];
+  }
+  case ValID::GlobalID: {                 // Is it a numbered definition?
+    unsigned Num = D.Num;
+    
+    // Module constants occupy the lowest numbered slots...
+    std::map<const Type*,ValueList>::iterator VI = CurModule.Values.find(Ty);
+    if (VI == CurModule.Values.end()) 
+      return 0;
+    if (D.Num >= VI->second.size()) 
+      return 0;
     return VI->second[Num];
   }
-
-  case ValID::NameVal: {                // Is it a named definition?
-    Value *N = lookupInSymbolTable(Ty, std::string(D.Name));
-    if (N == 0) return 0;
+    
+  case ValID::LocalName: {                // Is it a named definition?
+    if (!inFunctionScope()) 
+      return 0;
+    ValueSymbolTable &SymTab = CurFun.CurrentFunction->getValueSymbolTable();
+    Value *N = SymTab.lookup(D.Name);
+    if (N == 0) 
+      return 0;
+    if (N->getType() != Ty)
+      return 0;
+    
+    D.destroy();  // Free old strdup'd memory...
+    return N;
+  }
+  case ValID::GlobalName: {                // Is it a named definition?
+    ValueSymbolTable &SymTab = CurModule.CurrentModule->getValueSymbolTable();
+    Value *N = SymTab.lookup(D.Name);
+    if (N == 0) 
+      return 0;
+    if (N->getType() != Ty)
+      return 0;
 
     D.destroy();  // Free old strdup'd memory...
     return N;
@@ -311,7 +379,7 @@ static Value *getValNonImprovising(const Type *Ty, const ValID &D) {
     if (!ConstantInt::isValueValidForType(Ty, D.ConstPool64)) {
       GenerateError("Signed integral constant '" +
                      itostr(D.ConstPool64) + "' is invalid for type '" +
-                     Ty->getDescription() + "'!");
+                     Ty->getDescription() + "'");
       return 0;
     }
     return ConstantInt::get(Ty, D.ConstPool64);
@@ -320,7 +388,7 @@ static Value *getValNonImprovising(const Type *Ty, const ValID &D) {
     if (!ConstantInt::isValueValidForType(Ty, D.UConstPool64)) {
       if (!ConstantInt::isValueValidForType(Ty, D.ConstPool64)) {
         GenerateError("Integral constant '" + utostr(D.UConstPool64) +
-                       "' is invalid or out of range!");
+                       "' is invalid or out of range");
         return 0;
       } else {     // This is really a signed reference.  Transmogrify.
         return ConstantInt::get(Ty, D.ConstPool64);
@@ -331,14 +399,14 @@ static Value *getValNonImprovising(const Type *Ty, const ValID &D) {
 
   case ValID::ConstFPVal:        // Is it a floating point const pool reference?
     if (!ConstantFP::isValueValidForType(Ty, D.ConstPoolFP)) {
-      GenerateError("FP constant invalid for type!!");
+      GenerateError("FP constant invalid for type");
       return 0;
     }
     return ConstantFP::get(Ty, D.ConstPoolFP);
 
   case ValID::ConstNullVal:      // Is it a null value?
     if (!isa<PointerType>(Ty)) {
-      GenerateError("Cannot create a a non pointer null!");
+      GenerateError("Cannot create a a non pointer null");
       return 0;
     }
     return ConstantPointerNull::get(cast<PointerType>(Ty));
@@ -351,7 +419,7 @@ static Value *getValNonImprovising(const Type *Ty, const ValID &D) {
     
   case ValID::ConstantVal:       // Fully resolved constant?
     if (D.ConstantValue->getType() != Ty) {
-      GenerateError("Constant expression type different from required type!");
+      GenerateError("Constant expression type different from required type");
       return 0;
     }
     return D.ConstantValue;
@@ -361,7 +429,7 @@ static Value *getValNonImprovising(const Type *Ty, const ValID &D) {
     const FunctionType *FTy =
       PTy ? dyn_cast<FunctionType>(PTy->getElementType()) : 0;
     if (!FTy || !InlineAsm::Verify(FTy, D.IAD->Constraints)) {
-      GenerateError("Invalid type for asm constraint string!");
+      GenerateError("Invalid type for asm constraint string");
       return 0;
     }
     InlineAsm *IA = InlineAsm::get(FTy, D.IAD->AsmString, D.IAD->Constraints,
@@ -396,7 +464,7 @@ static Value *getVal(const Type *Ty, const ValID &ID) {
   if (TriggerError) return 0;
 
   if (!Ty->isFirstClassType() && !isa<OpaqueType>(Ty)) {
-    GenerateError("Invalid use of a composite type!");
+    GenerateError("Invalid use of a composite type");
     return 0;
   }
 
@@ -433,15 +501,15 @@ static BasicBlock *getBBVal(const ValID &ID, bool isDefinition = false) {
   default: 
     GenerateError("Illegal label reference " + ID.getName());
     return 0;
-  case ValID::NumberVal:                // Is it a numbered definition?
-    if (unsigned(ID.Num) >= CurFun.NumberedBlocks.size())
+  case ValID::LocalID:                // Is it a numbered definition?
+    if (ID.Num >= CurFun.NumberedBlocks.size())
       CurFun.NumberedBlocks.resize(ID.Num+1);
     BB = CurFun.NumberedBlocks[ID.Num];
     break;
-  case ValID::NameVal:                  // Is it a named definition?
+  case ValID::LocalName:                  // Is it a named definition?
     Name = ID.Name;
-    if (Value *N = CurFun.CurrentFunction->
-                   getSymbolTable().lookup(Type::LabelTy, Name))
+    Value *N = CurFun.CurrentFunction->getValueSymbolTable().lookup(Name);
+    if (N && N->getType()->getTypeID() == Type::LabelTyID)
       BB = cast<BasicBlock>(N);
     break;
   }
@@ -463,7 +531,7 @@ static BasicBlock *getBBVal(const ValID &ID, bool isDefinition = false) {
 
   // Otherwise this block has not been seen before.
   BB = new BasicBlock("", CurFun.CurrentFunction);
-  if (ID.Type == ValID::NameVal) {
+  if (ID.Type == ValID::LocalName) {
     BB->setName(ID.Name);
   } else {
     CurFun.NumberedBlocks[ID.Num] = BB;
@@ -530,7 +598,7 @@ ResolveDefinitions(std::map<const Type*,ValueList> &LateResolvers,
         // resolver table
         InsertValue(V, *FutureLateResolvers);
       } else {
-        if (DID.Type == ValID::NameVal) {
+        if (DID.Type == ValID::LocalName || DID.Type == ValID::GlobalName) {
           GenerateError("Reference to an invalid definition: '" +DID.getName()+
                          "' of type '" + V->getType()->getDescription() + "'",
                          PHI->second.second);
@@ -555,8 +623,8 @@ ResolveDefinitions(std::map<const Type*,ValueList> &LateResolvers,
 //
 static void ResolveTypeTo(char *Name, const Type *ToTy) {
   ValID D;
-  if (Name) D = ValID::create(Name);
-  else      D = ValID::create((int)CurModule.Types.size());
+  if (Name) D = ValID::createLocalName(Name);
+  else      D = ValID::createLocalID(CurModule.Types.size());
 
   std::map<ValID, PATypeHolder>::iterator I =
     CurModule.LateResolveTypes.find(D);
@@ -571,36 +639,37 @@ static void ResolveTypeTo(char *Name, const Type *ToTy) {
 // assumed to be a malloc'd string buffer, and is free'd by this function.
 //
 static void setValueName(Value *V, char *NameStr) {
-  if (NameStr) {
-    std::string Name(NameStr);      // Copy string
-    free(NameStr);                  // Free old string
-
-    if (V->getType() == Type::VoidTy) {
-      GenerateError("Can't assign name '" + Name+"' to value with void type!");
-      return;
-    }
+  if (!NameStr) return;
+  std::string Name(NameStr);      // Copy string
+  free(NameStr);                  // Free old string
 
-    assert(inFunctionScope() && "Must be in function scope!");
-    SymbolTable &ST = CurFun.CurrentFunction->getSymbolTable();
-    if (ST.lookup(V->getType(), Name)) {
-      GenerateError("Redefinition of value named '" + Name + "' in the '" +
-                     V->getType()->getDescription() + "' type plane!");
-      return;
-    }
+  if (V->getType() == Type::VoidTy) {
+    GenerateError("Can't assign name '" + Name+"' to value with void type");
+    return;
+  }
 
-    // Set the name.
-    V->setName(Name);
+  assert(inFunctionScope() && "Must be in function scope!");
+  ValueSymbolTable &ST = CurFun.CurrentFunction->getValueSymbolTable();
+  if (ST.lookup(Name)) {
+    GenerateError("Redefinition of value '" + Name + "' of type '" +
+                   V->getType()->getDescription() + "'");
+    return;
   }
+
+  // Set the name.
+  V->setName(Name);
 }
 
 /// ParseGlobalVariable - Handle parsing of a global.  If Initializer is null,
 /// this is a declaration, otherwise it is a definition.
 static GlobalVariable *
-ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage,
+ParseGlobalVariable(char *NameStr,
+                    GlobalValue::LinkageTypes Linkage,
+                    GlobalValue::VisibilityTypes Visibility,
                     bool isConstantGlobal, const Type *Ty,
                     Constant *Initializer) {
   if (isa<FunctionType>(Ty)) {
-    GenerateError("Cannot declare global vars of function type!");
+    GenerateError("Cannot declare global vars of function type");
     return 0;
   }
 
@@ -616,9 +685,9 @@ ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage,
   // object.
   ValID ID;
   if (!Name.empty()) {
-    ID = ValID::create((char*)Name.c_str());
+    ID = ValID::createGlobalName((char*)Name.c_str());
   } else {
-    ID = ValID::create((int)CurModule.Values[PTy].size());
+    ID = ValID::createGlobalID(CurModule.Values[PTy].size());
   }
 
   if (GlobalValue *FWGV = CurModule.GetForwardRefForGlobal(PTy, ID)) {
@@ -629,46 +698,34 @@ ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage,
     CurModule.CurrentModule->getGlobalList().push_back(GV);
     GV->setInitializer(Initializer);
     GV->setLinkage(Linkage);
+    GV->setVisibility(Visibility);
     GV->setConstant(isConstantGlobal);
     InsertValue(GV, CurModule.Values);
     return GV;
   }
 
-  // If this global has a name, check to see if there is already a definition
-  // of this global in the module.  If so, merge as appropriate.  Note that
-  // this is really just a hack around problems in the CFE.  :(
+  // If this global has a name
   if (!Name.empty()) {
-    // We are a simple redefinition of a value, check to see if it is defined
-    // the same as the old one.
-    if (GlobalVariable *EGV =
-                CurModule.CurrentModule->getGlobalVariable(Name, Ty)) {
-      // We are allowed to redefine a global variable in two circumstances:
-      // 1. If at least one of the globals is uninitialized or
-      // 2. If both initializers have the same value.
-      //
-      if (!EGV->hasInitializer() || !Initializer ||
-          EGV->getInitializer() == Initializer) {
-
-        // Make sure the existing global version gets the initializer!  Make
-        // sure that it also gets marked const if the new version is.
-        if (Initializer && !EGV->hasInitializer())
-          EGV->setInitializer(Initializer);
-        if (isConstantGlobal)
-          EGV->setConstant(true);
-        EGV->setLinkage(Linkage);
-        return EGV;
+    // if the global we're parsing has an initializer (is a definition) and
+    // has external linkage.
+    if (Initializer && Linkage != GlobalValue::InternalLinkage)
+      // If there is already a global with external linkage with this name
+      if (CurModule.CurrentModule->getGlobalVariable(Name, false)) {
+        // If we allow this GVar to get created, it will be renamed in the
+        // symbol table because it conflicts with an existing GVar. We can't
+        // allow redefinition of GVars whose linking indicates that their name
+        // must stay the same. Issue the error.
+        GenerateError("Redefinition of global variable named '" + Name +
+                       "' of type '" + Ty->getDescription() + "'");
+        return 0;
       }
-
-      GenerateError("Redefinition of global variable named '" + Name +
-                     "' in the '" + Ty->getDescription() + "' type plane!");
-      return 0;
-    }
   }
 
   // Otherwise there is no existing GV to use, create one now.
   GlobalVariable *GV =
     new GlobalVariable(Ty, isConstantGlobal, Linkage, Initializer, Name,
                        CurModule.CurrentModule);
+  GV->setVisibility(Visibility);
   InsertValue(GV, CurModule.Values);
   return GV;
 }
@@ -689,7 +746,7 @@ static bool setTypeName(const Type *T, char *NameStr) {
 
   // We don't allow assigning names to void type
   if (T == Type::VoidTy) {
-    GenerateError("Can't assign name '" + Name + "' to the void type!");
+    GenerateError("Can't assign name '" + Name + "' to the void type");
     return false;
   }
 
@@ -698,7 +755,7 @@ static bool setTypeName(const Type *T, char *NameStr) {
 
   if (AlreadyExists) {   // Inserting a name that is already defined???
     const Type *Existing = CurModule.CurrentModule->getTypeByName(Name);
-    assert(Existing && "Conflict but no matching type?");
+    assert(Existing && "Conflict but no matching type?!");
 
     // There is only one case where this is allowed: when we are refining an
     // opaque type.  In this case, Existing will be an opaque type.
@@ -715,8 +772,8 @@ static bool setTypeName(const Type *T, char *NameStr) {
     if (Existing == T) return true;  // Yes, it's equal.
 
     // Any other kind of (non-equivalent) redefinition is an error.
-    GenerateError("Redefinition of type named '" + Name + "' in the '" +
-                   T->getDescription() + "' type plane!");
+    GenerateError("Redefinition of type named '" + Name + "' of type '" +
+                   T->getDescription() + "'");
   }
 
   return false;
@@ -865,6 +922,7 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
   std::vector<llvm::Constant*>           *ConstVector;
 
   llvm::GlobalValue::LinkageTypes         Linkage;
+  llvm::GlobalValue::VisibilityTypes      Visibility;
   llvm::FunctionType::ParameterAttributes ParamAttrs;
   int64_t                           SInt64Val;
   uint64_t                          UInt64Val;
@@ -881,7 +939,6 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
   llvm::Instruction::MemoryOps      MemOpVal;
   llvm::Instruction::CastOps        CastOpVal;
   llvm::Instruction::OtherOps       OtherOpVal;
-  llvm::Module::Endianness          Endianness;
   llvm::ICmpInst::Predicate         IPredicate;
   llvm::FCmpInst::Predicate         FPredicate;
 }
@@ -899,7 +956,7 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
 %type <ValueList>     IndexList         // For GEP indices
 %type <TypeList>      TypeListI 
 %type <TypeWithAttrsList> ArgTypeList ArgTypeListI
-%type <TypeWithAttrs> ArgType ResultType
+%type <TypeWithAttrs> ArgType
 %type <JumpTable>     JumpTable
 %type <BoolVal>       GlobalType                  // GLOBAL or CONSTANT?
 %type <BoolVal>       OptVolatile                 // 'volatile' or not
@@ -907,7 +964,7 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
 %type <BoolVal>       OptSideEffect               // 'sideeffect' or not.
 %type <Linkage>       GVInternalLinkage GVExternalLinkage
 %type <Linkage>       FunctionDefineLinkage FunctionDeclareLinkage
-%type <Endianness>    BigOrLittle
+%type <Visibility>    GVVisibilityStyle
 
 // ValueRef - Unresolved reference to a definition or BB
 %type <ValIDVal>      ValueRef ConstValueRef SymbolicValueRef
@@ -920,34 +977,33 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
 // EUINT64VAL - A positive number within uns. long long range
 %token <UInt64Val> EUINT64VAL
 
-%token  <SIntVal>   SINTVAL   // Signed 32 bit ints...
-%token  <UIntVal>   UINTVAL   // Unsigned 32 bit ints...
-%type   <SIntVal>   INTVAL
+%token  <UIntVal>   LOCALVAL_ID GLOBALVAL_ID  // %123 @123
 %token  <FPVal>     FPVAL     // Float or Double constant
 
 // Built in types...
-%type  <TypeVal> Types
+%type  <TypeVal> Types ResultTypes
 %type  <PrimType> IntType FPType PrimType           // Classifications
-%token <PrimType> VOID BOOL INT8 INT16 INT32 INT64
+%token <PrimType> VOID INTTYPE 
 %token <PrimType> FLOAT DOUBLE LABEL
 %token TYPE
 
-%token <StrVal> VAR_ID LABELSTR STRINGCONSTANT
-%type  <StrVal> Name OptName OptAssign
-%type  <UIntVal> OptAlign OptCAlign
+%token<StrVal> LOCALVAR GLOBALVAR LABELSTR STRINGCONSTANT ATSTRINGCONSTANT
+%type <StrVal> LocalName OptLocalName OptLocalAssign
+%type <StrVal> GlobalName OptGlobalAssign
+%type <UIntVal> OptAlign OptCAlign
 %type <StrVal> OptSection SectionString
 
 %token IMPLEMENTATION ZEROINITIALIZER TRUETOK FALSETOK BEGINTOK ENDTOK
 %token DECLARE DEFINE GLOBAL CONSTANT SECTION VOLATILE
 %token TO DOTDOTDOT NULL_TOK UNDEF INTERNAL LINKONCE WEAK APPENDING
 %token DLLIMPORT DLLEXPORT EXTERN_WEAK
-%token OPAQUE NOT EXTERNAL TARGET TRIPLE ENDIAN POINTERSIZE LITTLE BIG ALIGN
+%token OPAQUE EXTERNAL TARGET TRIPLE ALIGN
 %token DEPLIBS CALL TAIL ASM_TOK MODULE SIDEEFFECT
-%token CC_TOK CCC_TOK CSRETCC_TOK FASTCC_TOK COLDCC_TOK
-%token X86_STDCALLCC_TOK X86_FASTCALLCC_TOK
+%token CC_TOK CCC_TOK FASTCC_TOK COLDCC_TOK X86_STDCALLCC_TOK X86_FASTCALLCC_TOK
 %token DATALAYOUT
 %type <UIntVal> OptCallingConv
-%type <ParamAttrs> OptParamAttrs ParamAttrList ParamAttr
+%type <ParamAttrs> OptParamAttrs ParamAttr 
+%type <ParamAttrs> OptFuncAttrs  FuncAttr
 
 // Basic Block Terminating Operators
 %token <TermOpVal> RET BR SWITCH INVOKE UNWIND UNREACHABLE
@@ -955,6 +1011,8 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
 // Binary Operators
 %type  <BinaryOpVal> ArithmeticOps LogicalOps // Binops Subcatagories
 %token <BinaryOpVal> ADD SUB MUL UDIV SDIV FDIV UREM SREM FREM AND OR XOR
+%token <BinaryOpVal> SHL LSHR ASHR
+
 %token <OtherOpVal> ICMP FCMP
 %type  <IPredicate> IPredicates
 %type  <FPredicate> FPredicates
@@ -970,32 +1028,27 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
 %token <CastOpVal> UITOFP SITOFP FPTOUI FPTOSI INTTOPTR PTRTOINT
 
 // Other Operators
-%type  <OtherOpVal> ShiftOps
-%token <OtherOpVal> PHI_TOK SELECT SHL LSHR ASHR VAARG
+%token <OtherOpVal> PHI_TOK SELECT VAARG
 %token <OtherOpVal> EXTRACTELEMENT INSERTELEMENT SHUFFLEVECTOR
 
+// Function Attributes
+%token NORETURN INREG SRET
+
+// Visibility Styles
+%token DEFAULT HIDDEN
 
 %start Module
 %%
 
-// Handle constant integer size restriction and conversion...
-//
-INTVAL : SINTVAL;
-INTVAL : UINTVAL {
-  if ($1 > (uint32_t)INT32_MAX)     // Outside of my range!
-    GEN_ERROR("Value too large for type!");
-  $$ = (int32_t)$1;
-  CHECK_FOR_ERROR
-};
 
 // Operations that are notably excluded from this list include:
 // RET, BR, & SWITCH because they end basic blocks and are treated specially.
 //
 ArithmeticOps: ADD | SUB | MUL | UDIV | SDIV | FDIV | UREM | SREM | FREM;
-LogicalOps   : AND | OR | XOR;
+LogicalOps   : SHL | LSHR | ASHR | AND | OR | XOR;
 CastOps      : TRUNC | ZEXT | SEXT | FPTRUNC | FPEXT | BITCAST | 
                UITOFP | SITOFP | FPTOUI | FPTOSI | INTTOPTR | PTRTOINT;
-ShiftOps     : SHL | LSHR | ASHR;
+
 IPredicates  
   : EQ   { $$ = ICmpInst::ICMP_EQ; }  | NE   { $$ = ICmpInst::ICMP_NE; }
   | SLT  { $$ = ICmpInst::ICMP_SLT; } | SGT  { $$ = ICmpInst::ICMP_SGT; }
@@ -1018,11 +1071,26 @@ FPredicates
 
 // These are some types that allow classification if we only want a particular 
 // thing... for example, only a signed, unsigned, or integral type.
-IntType :  INT64 | INT32 | INT16 | INT8;
+IntType :  INTTYPE;
 FPType   : FLOAT | DOUBLE;
 
-// OptAssign - Value producing statements have an optional assignment component
-OptAssign : Name '=' {
+LocalName : LOCALVAR | STRINGCONSTANT;
+OptLocalName : LocalName | /*empty*/ { $$ = 0; };
+
+/// OptLocalAssign - Value producing statements have an optional assignment
+/// component.
+OptLocalAssign : LocalName '=' {
+    $$ = $1;
+    CHECK_FOR_ERROR
+  }
+  | /*empty*/ {
+    $$ = 0;
+    CHECK_FOR_ERROR
+  };
+
+GlobalName : GLOBALVAR | ATSTRINGCONSTANT;
+
+OptGlobalAssign : GlobalName '=' {
     $$ = $1;
     CHECK_FOR_ERROR
   }
@@ -1045,6 +1113,11 @@ GVExternalLinkage
   | EXTERNAL    { $$ = GlobalValue::ExternalLinkage; }
   ;
 
+GVVisibilityStyle
+  : /*empty*/ { $$ = GlobalValue::DefaultVisibility; }
+  | HIDDEN    { $$ = GlobalValue::HiddenVisibility;  }
+  ;
+
 FunctionDeclareLinkage
   : /*empty*/   { $$ = GlobalValue::ExternalLinkage; }
   | DLLIMPORT   { $$ = GlobalValue::DLLImportLinkage; } 
@@ -1061,31 +1134,37 @@ FunctionDefineLinkage
 
 OptCallingConv : /*empty*/          { $$ = CallingConv::C; } |
                  CCC_TOK            { $$ = CallingConv::C; } |
-                 CSRETCC_TOK        { $$ = CallingConv::CSRet; } |
                  FASTCC_TOK         { $$ = CallingConv::Fast; } |
                  COLDCC_TOK         { $$ = CallingConv::Cold; } |
                  X86_STDCALLCC_TOK  { $$ = CallingConv::X86_StdCall; } |
                  X86_FASTCALLCC_TOK { $$ = CallingConv::X86_FastCall; } |
                  CC_TOK EUINT64VAL  {
                    if ((unsigned)$2 != $2)
-                     GEN_ERROR("Calling conv too large!");
+                     GEN_ERROR("Calling conv too large");
                    $$ = $2;
                   CHECK_FOR_ERROR
                  };
 
-ParamAttr     : ZEXT { $$ = FunctionType::ZExtAttribute; }
-              | SEXT { $$ = FunctionType::SExtAttribute; }
+ParamAttr     : ZEXT  { $$ = FunctionType::ZExtAttribute;      }
+              | SEXT  { $$ = FunctionType::SExtAttribute;      }
+              | INREG { $$ = FunctionType::InRegAttribute;     }
+              | SRET  { $$ = FunctionType::StructRetAttribute; }
               ;
 
-ParamAttrList : ParamAttr    { $$ = $1; }
-              | ParamAttrList ',' ParamAttr {
-                $$ = FunctionType::ParameterAttributes($1 | $3);
+OptParamAttrs : /* empty */  { $$ = FunctionType::NoAttributeSet; }
+              | OptParamAttrs ParamAttr {
+                $$ = FunctionType::ParameterAttributes($1 | $2);
               }
               ;
 
-OptParamAttrs : /* empty */  { $$ = FunctionType::NoAttributeSet; }
-              | '@' ParamAttr { $$ = $2; }
-              | '@' '(' ParamAttrList ')' { $$ = $3; }
+FuncAttr      : NORETURN { $$ = FunctionType::NoReturnAttribute; }
+              | ParamAttr
+              ;
+
+OptFuncAttrs  : /* empty */ { $$ = FunctionType::NoAttributeSet; }
+              | OptFuncAttrs FuncAttr {
+                $$ = FunctionType::ParameterAttributes($1 | $2);
+              }
               ;
 
 // OptAlign/OptCAlign - An optional alignment, and an optional alignment with
@@ -1094,14 +1173,14 @@ OptAlign : /*empty*/        { $$ = 0; } |
            ALIGN EUINT64VAL {
   $$ = $2;
   if ($$ != 0 && !isPowerOf2_32($$))
-    GEN_ERROR("Alignment must be a power of two!");
+    GEN_ERROR("Alignment must be a power of two");
   CHECK_FOR_ERROR
 };
 OptCAlign : /*empty*/            { $$ = 0; } |
             ',' ALIGN EUINT64VAL {
   $$ = $3;
   if ($$ != 0 && !isPowerOf2_32($$))
-    GEN_ERROR("Alignment must be a power of two!");
+    GEN_ERROR("Alignment must be a power of two");
   CHECK_FOR_ERROR
 };
 
@@ -1109,7 +1188,7 @@ OptCAlign : /*empty*/            { $$ = 0; } |
 SectionString : SECTION STRINGCONSTANT {
   for (unsigned i = 0, e = strlen($2); i != e; ++i)
     if ($2[i] == '"' || $2[i] == '\\')
-      GEN_ERROR("Invalid character in section name!");
+      GEN_ERROR("Invalid character in section name");
   $$ = $2;
   CHECK_FOR_ERROR
 };
@@ -1129,7 +1208,7 @@ GlobalVarAttribute : SectionString {
   } 
   | ALIGN EUINT64VAL {
     if ($2 != 0 && !isPowerOf2_32($2))
-      GEN_ERROR("Alignment must be a power of two!");
+      GEN_ERROR("Alignment must be a power of two");
     CurGV->setAlignment($2);
     CHECK_FOR_ERROR
   };
@@ -1140,7 +1219,7 @@ GlobalVarAttribute : SectionString {
 
 // Derived types are added later...
 //
-PrimType : BOOL | INT8 | INT16  | INT32 | INT64 | FLOAT | DOUBLE | LABEL ;
+PrimType : INTTYPE | FLOAT | DOUBLE | LABEL ;
 
 Types 
   : OPAQUE {
@@ -1164,18 +1243,18 @@ Types
     $$ = new PATypeHolder(tmp);
   }
   | '\\' EUINT64VAL {                   // Type UpReference
-    if ($2 > (uint64_t)~0U) GEN_ERROR("Value out of range!");
+    if ($2 > (uint64_t)~0U) GEN_ERROR("Value out of range");
     OpaqueType *OT = OpaqueType::get();        // Use temporary placeholder
     UpRefs.push_back(UpRefRecord((unsigned)$2, OT));  // Add to vector...
     $$ = new PATypeHolder(OT);
     UR_OUT("New Upreference!\n");
     CHECK_FOR_ERROR
   }
-  | Types OptParamAttrs '(' ArgTypeListI ')' {
+  | Types '(' ArgTypeListI ')' OptFuncAttrs {
     std::vector<const Type*> Params;
     std::vector<FunctionType::ParameterAttributes> Attrs;
-    Attrs.push_back($2);
-    for (TypeWithAttrsList::iterator I=$4->begin(), E=$4->end(); I != E; ++I) {
+    Attrs.push_back($5);
+    for (TypeWithAttrsList::iterator I=$3->begin(), E=$3->end(); I != E; ++I) {
       Params.push_back(I->Ty->get());
       if (I->Ty->get() != Type::VoidTy)
         Attrs.push_back(I->Attrs);
@@ -1184,16 +1263,16 @@ Types
     if (isVarArg) Params.pop_back();
 
     FunctionType *FT = FunctionType::get(*$1, Params, isVarArg, Attrs);
-    delete $4;      // Delete the argument list
+    delete $3;   // Delete the argument list
     delete $1;   // Delete the return type handle
     $$ = new PATypeHolder(HandleUpRefs(FT)); 
     CHECK_FOR_ERROR
   }
-  | VOID OptParamAttrs '(' ArgTypeListI ')' {
+  | VOID '(' ArgTypeListI ')' OptFuncAttrs {
     std::vector<const Type*> Params;
     std::vector<FunctionType::ParameterAttributes> Attrs;
-    Attrs.push_back($2);
-    for (TypeWithAttrsList::iterator I=$4->begin(), E=$4->end(); I != E; ++I) {
+    Attrs.push_back($5);
+    for (TypeWithAttrsList::iterator I=$3->begin(), E=$3->end(); I != E; ++I) {
       Params.push_back(I->Ty->get());
       if (I->Ty->get() != Type::VoidTy)
         Attrs.push_back(I->Attrs);
@@ -1202,7 +1281,7 @@ Types
     if (isVarArg) Params.pop_back();
 
     FunctionType *FT = FunctionType::get($1, Params, isVarArg, Attrs);
-    delete $4;      // Delete the argument list
+    delete $3;      // Delete the argument list
     $$ = new PATypeHolder(HandleUpRefs(FT)); 
     CHECK_FOR_ERROR
   }
@@ -1216,10 +1295,10 @@ Types
      const llvm::Type* ElemTy = $4->get();
      if ((unsigned)$2 != $2)
         GEN_ERROR("Unsigned result not equal to signed result");
-     if (!ElemTy->isPrimitiveType())
-        GEN_ERROR("Elemental type of a PackedType must be primitive");
+     if (!ElemTy->isFloatingPoint() && !ElemTy->isInteger())
+        GEN_ERROR("Element type of a PackedType must be primitive");
      if (!isPowerOf2_32($2))
-       GEN_ERROR("Vector length should be a power of 2!");
+       GEN_ERROR("Vector length should be a power of 2");
      $$ = new PATypeHolder(HandleUpRefs(PackedType::get(*$4, (unsigned)$2)));
      delete $4;
      CHECK_FOR_ERROR
@@ -1261,18 +1340,16 @@ ArgType
   }
   ;
 
-ResultType 
-  : Types OptParamAttrs { 
+ResultTypes
+  : Types {
     if (!UpRefs.empty())
       GEN_ERROR("Invalid upreference in type: " + (*$1)->getDescription());
     if (!(*$1)->isFirstClassType())
-      GEN_ERROR("LLVM functions cannot return aggregate types!");
-    $$.Ty = $1;
-    $$.Attrs = $2;
+      GEN_ERROR("LLVM functions cannot return aggregate types");
+    $$ = $1;
   }
-  | VOID OptParamAttrs {
-    $$.Ty = new PATypeHolder(Type::VoidTy);
-    $$.Attrs = $2;
+  | VOID {
+    $$ = new PATypeHolder(Type::VoidTy);
   }
   ;
 
@@ -1333,7 +1410,7 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
     const ArrayType *ATy = dyn_cast<ArrayType>($1->get());
     if (ATy == 0)
       GEN_ERROR("Cannot make array constant with type: '" + 
-                     (*$1)->getDescription() + "'!");
+                     (*$1)->getDescription() + "'");
     const Type *ETy = ATy->getElementType();
     int NumElements = ATy->getNumElements();
 
@@ -1341,7 +1418,7 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
     if (NumElements != -1 && NumElements != (int)$3->size())
       GEN_ERROR("Type mismatch: constant sized array initialized with " +
                      utostr($3->size()) +  " arguments, but has size of " + 
-                     itostr(NumElements) + "!");
+                     itostr(NumElements) + "");
 
     // Verify all elements are correct type!
     for (unsigned i = 0; i < $3->size(); i++) {
@@ -1361,12 +1438,12 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
     const ArrayType *ATy = dyn_cast<ArrayType>($1->get());
     if (ATy == 0)
       GEN_ERROR("Cannot make array constant with type: '" + 
-                     (*$1)->getDescription() + "'!");
+                     (*$1)->getDescription() + "'");
 
     int NumElements = ATy->getNumElements();
     if (NumElements != -1 && NumElements != 0) 
       GEN_ERROR("Type mismatch: constant sized array initialized with 0"
-                     " arguments, but has size of " + itostr(NumElements) +"!");
+                     " arguments, but has size of " + itostr(NumElements) +"");
     $$ = ConstantArray::get(ATy, std::vector<Constant*>());
     delete $1;
     CHECK_FOR_ERROR
@@ -1377,7 +1454,7 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
     const ArrayType *ATy = dyn_cast<ArrayType>($1->get());
     if (ATy == 0)
       GEN_ERROR("Cannot make array constant with type: '" + 
-                     (*$1)->getDescription() + "'!");
+                     (*$1)->getDescription() + "'");
 
     int NumElements = ATy->getNumElements();
     const Type *ETy = ATy->getElementType();
@@ -1385,7 +1462,7 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
     if (NumElements != -1 && NumElements != (EndStr-$3))
       GEN_ERROR("Can't build string constant of size " + 
                      itostr((int)(EndStr-$3)) +
-                     " when array has size " + itostr(NumElements) + "!");
+                     " when array has size " + itostr(NumElements) + "");
     std::vector<Constant*> Vals;
     if (ETy == Type::Int8Ty) {
       for (unsigned char *C = (unsigned char *)$3; 
@@ -1393,7 +1470,7 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
       Vals.push_back(ConstantInt::get(ETy, *C));
     } else {
       free($3);
-      GEN_ERROR("Cannot build string arrays of non byte sized elements!");
+      GEN_ERROR("Cannot build string arrays of non byte sized elements");
     }
     free($3);
     $$ = ConstantArray::get(ATy, Vals);
@@ -1406,7 +1483,7 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
     const PackedType *PTy = dyn_cast<PackedType>($1->get());
     if (PTy == 0)
       GEN_ERROR("Cannot make packed constant with type: '" + 
-                     (*$1)->getDescription() + "'!");
+                     (*$1)->getDescription() + "'");
     const Type *ETy = PTy->getElementType();
     int NumElements = PTy->getNumElements();
 
@@ -1414,7 +1491,7 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
     if (NumElements != -1 && NumElements != (int)$3->size())
       GEN_ERROR("Type mismatch: constant sized packed initialized with " +
                      utostr($3->size()) +  " arguments, but has size of " + 
-                     itostr(NumElements) + "!");
+                     itostr(NumElements) + "");
 
     // Verify all elements are correct type!
     for (unsigned i = 0; i < $3->size(); i++) {
@@ -1432,10 +1509,10 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
     const StructType *STy = dyn_cast<StructType>($1->get());
     if (STy == 0)
       GEN_ERROR("Cannot make struct constant with type: '" + 
-                     (*$1)->getDescription() + "'!");
+                     (*$1)->getDescription() + "'");
 
     if ($3->size() != STy->getNumContainedTypes())
-      GEN_ERROR("Illegal number of initializers for structure type!");
+      GEN_ERROR("Illegal number of initializers for structure type");
 
     // Check to ensure that constants are compatible with the type initializer!
     for (unsigned i = 0, e = $3->size(); i != e; ++i)
@@ -1443,7 +1520,11 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
         GEN_ERROR("Expected type '" +
                        STy->getElementType(i)->getDescription() +
                        "' for element #" + utostr(i) +
-                       " of structure initializer!");
+                       " of structure initializer");
+
+    // Check to ensure that Type is not packed
+    if (STy->isPacked())
+      GEN_ERROR("Unpacked Initializer to packed type '" + STy->getDescription() + "'");
 
     $$ = ConstantStruct::get(STy, *$3);
     delete $1; delete $3;
@@ -1455,10 +1536,58 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
     const StructType *STy = dyn_cast<StructType>($1->get());
     if (STy == 0)
       GEN_ERROR("Cannot make struct constant with type: '" + 
-                     (*$1)->getDescription() + "'!");
+                     (*$1)->getDescription() + "'");
 
     if (STy->getNumContainedTypes() != 0)
-      GEN_ERROR("Illegal number of initializers for structure type!");
+      GEN_ERROR("Illegal number of initializers for structure type");
+
+    // Check to ensure that Type is not packed
+    if (STy->isPacked())
+      GEN_ERROR("Unpacked Initializer to packed type '" + STy->getDescription() + "'");
+
+    $$ = ConstantStruct::get(STy, std::vector<Constant*>());
+    delete $1;
+    CHECK_FOR_ERROR
+  }
+  | Types '<' '{' ConstVector '}' '>' {
+    const StructType *STy = dyn_cast<StructType>($1->get());
+    if (STy == 0)
+      GEN_ERROR("Cannot make struct constant with type: '" + 
+                     (*$1)->getDescription() + "'");
+
+    if ($4->size() != STy->getNumContainedTypes())
+      GEN_ERROR("Illegal number of initializers for structure type");
+
+    // Check to ensure that constants are compatible with the type initializer!
+    for (unsigned i = 0, e = $4->size(); i != e; ++i)
+      if ((*$4)[i]->getType() != STy->getElementType(i))
+        GEN_ERROR("Expected type '" +
+                       STy->getElementType(i)->getDescription() +
+                       "' for element #" + utostr(i) +
+                       " of structure initializer");
+
+    // Check to ensure that Type is packed
+    if (!STy->isPacked())
+      GEN_ERROR("Packed Initializer to unpacked type '" + STy->getDescription() + "'");
+
+    $$ = ConstantStruct::get(STy, *$4);
+    delete $1; delete $4;
+    CHECK_FOR_ERROR
+  }
+  | Types '<' '{' '}' '>' {
+    if (!UpRefs.empty())
+      GEN_ERROR("Invalid upreference in type: " + (*$1)->getDescription());
+    const StructType *STy = dyn_cast<StructType>($1->get());
+    if (STy == 0)
+      GEN_ERROR("Cannot make struct constant with type: '" + 
+                     (*$1)->getDescription() + "'");
+
+    if (STy->getNumContainedTypes() != 0)
+      GEN_ERROR("Illegal number of initializers for structure type");
+
+    // Check to ensure that Type is packed
+    if (!STy->isPacked())
+      GEN_ERROR("Packed Initializer to unpacked type '" + STy->getDescription() + "'");
 
     $$ = ConstantStruct::get(STy, std::vector<Constant*>());
     delete $1;
@@ -1470,7 +1599,7 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
     const PointerType *PTy = dyn_cast<PointerType>($1->get());
     if (PTy == 0)
       GEN_ERROR("Cannot make null pointer constant with type: '" + 
-                     (*$1)->getDescription() + "'!");
+                     (*$1)->getDescription() + "'");
 
     $$ = ConstantPointerNull::get(PTy);
     delete $1;
@@ -1488,7 +1617,7 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
       GEN_ERROR("Invalid upreference in type: " + (*$1)->getDescription());
     const PointerType *Ty = dyn_cast<PointerType>($1->get());
     if (Ty == 0)
-      GEN_ERROR("Global const reference must be a pointer type!");
+      GEN_ERROR("Global const reference must be a pointer type");
 
     // ConstExprs can exist in the body of a function, thus creating
     // GlobalValues whenever they refer to a variable.  Because we are in
@@ -1522,7 +1651,10 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
         $2.destroy();
       } else {
         std::string Name;
-        if ($2.Type == ValID::NameVal) Name = $2.Name;
+        if ($2.Type == ValID::GlobalName)
+          Name = $2.Name;
+        else if ($2.Type != ValID::GlobalID)
+          GEN_ERROR("Invalid reference to global");
 
         // Create the forward referenced global.
         GlobalValue *GV;
@@ -1550,7 +1682,8 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
     if (!UpRefs.empty())
       GEN_ERROR("Invalid upreference in type: " + (*$1)->getDescription());
     if ($1->get() != $2->getType())
-      GEN_ERROR("Mismatched types for constant expression!");
+      GEN_ERROR("Mismatched types for constant expression: " + 
+        (*$1)->getDescription() + " and " + $2->getType()->getDescription());
     $$ = $2;
     delete $1;
     CHECK_FOR_ERROR
@@ -1560,34 +1693,36 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
       GEN_ERROR("Invalid upreference in type: " + (*$1)->getDescription());
     const Type *Ty = $1->get();
     if (isa<FunctionType>(Ty) || Ty == Type::LabelTy || isa<OpaqueType>(Ty))
-      GEN_ERROR("Cannot create a null initialized value of this type!");
+      GEN_ERROR("Cannot create a null initialized value of this type");
     $$ = Constant::getNullValue(Ty);
     delete $1;
     CHECK_FOR_ERROR
   }
   | IntType ESINT64VAL {      // integral constants
     if (!ConstantInt::isValueValidForType($1, $2))
-      GEN_ERROR("Constant value doesn't fit in type!");
+      GEN_ERROR("Constant value doesn't fit in type");
     $$ = ConstantInt::get($1, $2);
     CHECK_FOR_ERROR
   }
   | IntType EUINT64VAL {      // integral constants
     if (!ConstantInt::isValueValidForType($1, $2))
-      GEN_ERROR("Constant value doesn't fit in type!");
+      GEN_ERROR("Constant value doesn't fit in type");
     $$ = ConstantInt::get($1, $2);
     CHECK_FOR_ERROR
   }
-  | BOOL TRUETOK {                      // Boolean constants
-    $$ = ConstantBool::getTrue();
+  | INTTYPE TRUETOK {                      // Boolean constants
+    assert(cast<IntegerType>($1)->getBitWidth() == 1 && "Not Bool?");
+    $$ = ConstantInt::getTrue();
     CHECK_FOR_ERROR
   }
-  | BOOL FALSETOK {                     // Boolean constants
-    $$ = ConstantBool::getFalse();
+  | INTTYPE FALSETOK {                     // Boolean constants
+    assert(cast<IntegerType>($1)->getBitWidth() == 1 && "Not Bool?");
+    $$ = ConstantInt::getFalse();
     CHECK_FOR_ERROR
   }
   | FPType FPVAL {                   // Float & Double constants
     if (!ConstantFP::isValueValidForType($1, $2))
-      GEN_ERROR("Floating point constant invalid for type!!");
+      GEN_ERROR("Floating point constant invalid for type");
     $$ = ConstantFP::get($1, $2);
     CHECK_FOR_ERROR
   };
@@ -1597,96 +1732,85 @@ ConstExpr: CastOps '(' ConstVal TO Types ')' {
     if (!UpRefs.empty())
       GEN_ERROR("Invalid upreference in type: " + (*$5)->getDescription());
     Constant *Val = $3;
-    const Type *Ty = $5->get();
-    if (!Val->getType()->isFirstClassType())
-      GEN_ERROR("cast constant expression from a non-primitive type: '" +
-                     Val->getType()->getDescription() + "'!");
-    if (!Ty->isFirstClassType())
-      GEN_ERROR("cast constant expression to a non-primitive type: '" +
-                Ty->getDescription() + "'!");
-    $$ = ConstantExpr::getCast($1, $3, $5->get());
+    const Type *DestTy = $5->get();
+    if (!CastInst::castIsValid($1, $3, DestTy))
+      GEN_ERROR("invalid cast opcode for cast from '" +
+                Val->getType()->getDescription() + "' to '" +
+                DestTy->getDescription() + "'"); 
+    $$ = ConstantExpr::getCast($1, $3, DestTy);
     delete $5;
   }
   | GETELEMENTPTR '(' ConstVal IndexList ')' {
     if (!isa<PointerType>($3->getType()))
-      GEN_ERROR("GetElementPtr requires a pointer operand!");
+      GEN_ERROR("GetElementPtr requires a pointer operand");
 
     const Type *IdxTy =
       GetElementPtrInst::getIndexedType($3->getType(), *$4, true);
     if (!IdxTy)
-      GEN_ERROR("Index list invalid for constant getelementptr!");
+      GEN_ERROR("Index list invalid for constant getelementptr");
 
-    std::vector<Constant*> IdxVec;
+    SmallVector<Constant*, 8> IdxVec;
     for (unsigned i = 0, e = $4->size(); i != e; ++i)
       if (Constant *C = dyn_cast<Constant>((*$4)[i]))
         IdxVec.push_back(C);
       else
-        GEN_ERROR("Indices to constant getelementptr must be constants!");
+        GEN_ERROR("Indices to constant getelementptr must be constants");
 
     delete $4;
 
-    $$ = ConstantExpr::getGetElementPtr($3, IdxVec);
+    $$ = ConstantExpr::getGetElementPtr($3, &IdxVec[0], IdxVec.size());
     CHECK_FOR_ERROR
   }
   | SELECT '(' ConstVal ',' ConstVal ',' ConstVal ')' {
-    if ($3->getType() != Type::BoolTy)
-      GEN_ERROR("Select condition must be of boolean type!");
+    if ($3->getType() != Type::Int1Ty)
+      GEN_ERROR("Select condition must be of boolean type");
     if ($5->getType() != $7->getType())
-      GEN_ERROR("Select operand types must match!");
+      GEN_ERROR("Select operand types must match");
     $$ = ConstantExpr::getSelect($3, $5, $7);
     CHECK_FOR_ERROR
   }
   | ArithmeticOps '(' ConstVal ',' ConstVal ')' {
     if ($3->getType() != $5->getType())
-      GEN_ERROR("Binary operator types must match!");
+      GEN_ERROR("Binary operator types must match");
     CHECK_FOR_ERROR;
     $$ = ConstantExpr::get($1, $3, $5);
   }
   | LogicalOps '(' ConstVal ',' ConstVal ')' {
     if ($3->getType() != $5->getType())
-      GEN_ERROR("Logical operator types must match!");
-    if (!$3->getType()->isIntegral()) {
-      if (!isa<PackedType>($3->getType()) || 
-          !cast<PackedType>($3->getType())->getElementType()->isIntegral())
-        GEN_ERROR("Logical operator requires integral operands!");
+      GEN_ERROR("Logical operator types must match");
+    if (!$3->getType()->isInteger()) {
+      if (Instruction::isShift($1) || !isa<PackedType>($3->getType()) || 
+          !cast<PackedType>($3->getType())->getElementType()->isInteger())
+        GEN_ERROR("Logical operator requires integral operands");
     }
     $$ = ConstantExpr::get($1, $3, $5);
     CHECK_FOR_ERROR
   }
   | ICMP IPredicates '(' ConstVal ',' ConstVal ')' {
     if ($4->getType() != $6->getType())
-      GEN_ERROR("icmp operand types must match!");
+      GEN_ERROR("icmp operand types must match");
     $$ = ConstantExpr::getICmp($2, $4, $6);
   }
   | FCMP FPredicates '(' ConstVal ',' ConstVal ')' {
     if ($4->getType() != $6->getType())
-      GEN_ERROR("fcmp operand types must match!");
+      GEN_ERROR("fcmp operand types must match");
     $$ = ConstantExpr::getFCmp($2, $4, $6);
   }
-  | ShiftOps '(' ConstVal ',' ConstVal ')' {
-    if ($5->getType() != Type::Int8Ty)
-      GEN_ERROR("Shift count for shift constant must be i8 type!");
-    if (!$3->getType()->isInteger())
-      GEN_ERROR("Shift constant expression requires integer operand!");
-    CHECK_FOR_ERROR;
-    $$ = ConstantExpr::get($1, $3, $5);
-    CHECK_FOR_ERROR
-  }
   | EXTRACTELEMENT '(' ConstVal ',' ConstVal ')' {
     if (!ExtractElementInst::isValidOperands($3, $5))
-      GEN_ERROR("Invalid extractelement operands!");
+      GEN_ERROR("Invalid extractelement operands");
     $$ = ConstantExpr::getExtractElement($3, $5);
     CHECK_FOR_ERROR
   }
   | INSERTELEMENT '(' ConstVal ',' ConstVal ',' ConstVal ')' {
     if (!InsertElementInst::isValidOperands($3, $5, $7))
-      GEN_ERROR("Invalid insertelement operands!");
+      GEN_ERROR("Invalid insertelement operands");
     $$ = ConstantExpr::getInsertElement($3, $5, $7);
     CHECK_FOR_ERROR
   }
   | SHUFFLEVECTOR '(' ConstVal ',' ConstVal ',' ConstVal ')' {
     if (!ShuffleVectorInst::isValidOperands($3, $5, $7))
-      GEN_ERROR("Invalid shufflevector operands!");
+      GEN_ERROR("Invalid shufflevector operands");
     $$ = ConstantExpr::getShuffleVector($3, $5, $7);
     CHECK_FOR_ERROR
   };
@@ -1734,7 +1858,7 @@ DefinitionList
   ;
 
 Definition 
-  : DEFINE { CurFun.isDeclare = false } Function {
+  : DEFINE { CurFun.isDeclare = false; } Function {
     CurFun.FunctionDone();
     CHECK_FOR_ERROR
   }
@@ -1748,7 +1872,7 @@ Definition
     // Emit an error if there are any unresolved types left.
     if (!CurModule.LateResolveTypes.empty()) {
       const ValID &DID = CurModule.LateResolveTypes.begin()->first;
-      if (DID.Type == ValID::NameVal) {
+      if (DID.Type == ValID::LocalName) {
         GEN_ERROR("Reference to an undefined type: '"+DID.getName() + "'");
       } else {
         GEN_ERROR("Reference to an undefined type: #" + itostr(DID.Num));
@@ -1756,7 +1880,7 @@ Definition
     }
     CHECK_FOR_ERROR
   }
-  | OptAssign TYPE Types {
+  | OptLocalAssign TYPE Types {
     if (!UpRefs.empty())
       GEN_ERROR("Invalid upreference in type: " + (*$3)->getDescription());
     // Eagerly resolve types.  This is not an optimization, this is a
@@ -1780,7 +1904,7 @@ Definition
     delete $3;
     CHECK_FOR_ERROR
   }
-  | OptAssign TYPE VOID {
+  | OptLocalAssign TYPE VOID {
     ResolveTypeTo($1, $3);
 
     if (!setTypeName($3, $1) && !$1) {
@@ -1791,29 +1915,30 @@ Definition
     }
     CHECK_FOR_ERROR
   }
-  | OptAssign GlobalType ConstVal { /* "Externally Visible" Linkage */
-    if ($3 == 0) 
-      GEN_ERROR("Global value initializer is not a constant!");
-    CurGV = ParseGlobalVariable($1, GlobalValue::ExternalLinkage, $2, 
-                                $3->getType(), $3);
+  | OptGlobalAssign GVVisibilityStyle GlobalType ConstVal { 
+    /* "Externally Visible" Linkage */
+    if ($4 == 0) 
+      GEN_ERROR("Global value initializer is not a constant");
+    CurGV = ParseGlobalVariable($1, GlobalValue::ExternalLinkage,
+                                $2, $3, $4->getType(), $4);
     CHECK_FOR_ERROR
   } GlobalVarAttributes {
     CurGV = 0;
   }
-  | OptAssign GVInternalLinkage GlobalType ConstVal {
-    if ($4 == 0) 
-      GEN_ERROR("Global value initializer is not a constant!");
-    CurGV = ParseGlobalVariable($1, $2, $3, $4->getType(), $4);
+  | OptGlobalAssign GVInternalLinkage GVVisibilityStyle GlobalType ConstVal {
+    if ($5 == 0) 
+      GEN_ERROR("Global value initializer is not a constant");
+    CurGV = ParseGlobalVariable($1, $2, $3, $4, $5->getType(), $5);
     CHECK_FOR_ERROR
   } GlobalVarAttributes {
     CurGV = 0;
   }
-  | OptAssign GVExternalLinkage GlobalType Types {
+  | OptGlobalAssign GVExternalLinkage GVVisibilityStyle GlobalType Types {
     if (!UpRefs.empty())
-      GEN_ERROR("Invalid upreference in type: " + (*$4)->getDescription());
-    CurGV = ParseGlobalVariable($1, $2, $3, *$4, 0);
+      GEN_ERROR("Invalid upreference in type: " + (*$5)->getDescription());
+    CurGV = ParseGlobalVariable($1, $2, $3, $4, *$5, 0);
     CHECK_FOR_ERROR
-    delete $4;
+    delete $5;
   } GlobalVarAttributes {
     CurGV = 0;
     CHECK_FOR_ERROR
@@ -1840,23 +1965,7 @@ AsmBlock : STRINGCONSTANT {
   CHECK_FOR_ERROR
 };
 
-BigOrLittle : BIG    { $$ = Module::BigEndian; };
-BigOrLittle : LITTLE { $$ = Module::LittleEndian; };
-
-TargetDefinition : ENDIAN '=' BigOrLittle {
-    CurModule.CurrentModule->setEndianness($3);
-    CHECK_FOR_ERROR
-  }
-  | POINTERSIZE '=' EUINT64VAL {
-    if ($3 == 32)
-      CurModule.CurrentModule->setPointerSize(Module::Pointer32);
-    else if ($3 == 64)
-      CurModule.CurrentModule->setPointerSize(Module::Pointer64);
-    else
-      GEN_ERROR("Invalid pointer size: '" + utostr($3) + "'!");
-    CHECK_FOR_ERROR
-  }
-  | TRIPLE '=' STRINGCONSTANT {
+TargetDefinition : TRIPLE '=' STRINGCONSTANT {
     CurModule.CurrentModule->setTargetTriple($3);
     free($3);
   }
@@ -1886,24 +1995,21 @@ LibList : LibList ',' STRINGCONSTANT {
 //                       Rules to match Function Headers
 //===----------------------------------------------------------------------===//
 
-Name : VAR_ID | STRINGCONSTANT;
-OptName : Name | /*empty*/ { $$ = 0; };
-
-ArgListH : ArgListH ',' Types OptParamAttrs OptName {
+ArgListH : ArgListH ',' Types OptParamAttrs OptLocalName {
     if (!UpRefs.empty())
       GEN_ERROR("Invalid upreference in type: " + (*$3)->getDescription());
     if (*$3 == Type::VoidTy)
-      GEN_ERROR("void typed arguments are invalid!");
+      GEN_ERROR("void typed arguments are invalid");
     ArgListEntry E; E.Attrs = $4; E.Ty = $3; E.Name = $5;
     $$ = $1;
     $1->push_back(E);
     CHECK_FOR_ERROR
   }
-  | Types OptParamAttrs OptName {
+  | Types OptParamAttrs OptLocalName {
     if (!UpRefs.empty())
       GEN_ERROR("Invalid upreference in type: " + (*$1)->getDescription());
     if (*$1 == Type::VoidTy)
-      GEN_ERROR("void typed arguments are invalid!");
+      GEN_ERROR("void typed arguments are invalid");
     ArgListEntry E; E.Attrs = $2; E.Ty = $1; E.Name = $3;
     $$ = new ArgListType;
     $$->push_back(E);
@@ -1937,18 +2043,25 @@ ArgList : ArgListH {
     CHECK_FOR_ERROR
   };
 
-FunctionHeaderH : OptCallingConv ResultType Name '(' ArgList ')' 
-                  OptSection OptAlign {
+FunctionHeaderH : OptCallingConv ResultTypes GlobalName '(' ArgList ')' 
+                  OptFuncAttrs OptSection OptAlign {
   UnEscapeLexed($3);
   std::string FunctionName($3);
   free($3);  // Free strdup'd memory!
   
+  // Check the function result for abstractness if this is a define. We should
+  // have no abstract types at this point
+  if (!CurFun.isDeclare && CurModule.TypeIsUnresolved($2))
+    GEN_ERROR("Reference to abstract result: "+ $2->get()->getDescription());
+
   std::vector<const Type*> ParamTypeList;
   std::vector<FunctionType::ParameterAttributes> ParamAttrs;
-  ParamAttrs.push_back($2.Attrs);
+  ParamAttrs.push_back($7);
   if ($5) {   // If there are arguments...
     for (ArgListType::iterator I = $5->begin(); I != $5->end(); ++I) {
       const Type* Ty = I->Ty->get();
+      if (!CurFun.isDeclare && CurModule.TypeIsUnresolved(I->Ty))
+        GEN_ERROR("Reference to abstract argument: " + Ty->getDescription());
       ParamTypeList.push_back(Ty);
       if (Ty != Type::VoidTy)
         ParamAttrs.push_back(I->Attrs);
@@ -1958,16 +2071,16 @@ FunctionHeaderH : OptCallingConv ResultType Name '(' ArgList ')'
   bool isVarArg = ParamTypeList.size() && ParamTypeList.back() == Type::VoidTy;
   if (isVarArg) ParamTypeList.pop_back();
 
-  FunctionType *FT = FunctionType::get(*$2.Ty, ParamTypeList, isVarArg,
+  FunctionType *FT = FunctionType::get(*$2, ParamTypeList, isVarArg,
                                        ParamAttrs);
   const PointerType *PFT = PointerType::get(FT);
-  delete $2.Ty;
+  delete $2;
 
   ValID ID;
   if (!FunctionName.empty()) {
-    ID = ValID::create((char*)FunctionName.c_str());
+    ID = ValID::createGlobalName((char*)FunctionName.c_str());
   } else {
-    ID = ValID::create((int)CurModule.Values[PFT].size());
+    ID = ValID::createGlobalID(CurModule.Values[PFT].size());
   }
 
   Function *Fn = 0;
@@ -1979,17 +2092,21 @@ FunctionHeaderH : OptCallingConv ResultType Name '(' ArgList ')'
     CurModule.CurrentModule->getFunctionList().remove(Fn);
     CurModule.CurrentModule->getFunctionList().push_back(Fn);
   } else if (!FunctionName.empty() &&     // Merge with an earlier prototype?
-             (Fn = CurModule.CurrentModule->getFunction(FunctionName, FT))) {
-    // If this is the case, either we need to be a forward decl, or it needs 
-    // to be.
-    if (!CurFun.isDeclare && !Fn->isExternal())
-      GEN_ERROR("Redefinition of function '" + FunctionName + "'!");
-    
-    // Make sure to strip off any argument names so we can't get conflicts.
-    if (Fn->isExternal())
+             (Fn = CurModule.CurrentModule->getFunction(FunctionName))) {
+    if (Fn->getFunctionType() != FT ) {
+      // The existing function doesn't have the same type. This is an overload
+      // error.
+      GEN_ERROR("Overload of function '" + FunctionName + "' not permitted.");
+    } else if (!CurFun.isDeclare && !Fn->isDeclaration()) {
+      // Neither the existing or the current function is a declaration and they
+      // have the same name and same type. Clearly this is a redefinition.
+      GEN_ERROR("Redefinition of function '" + FunctionName + "'");
+    } if (Fn->isDeclaration()) {
+      // Make sure to strip off any argument names so we can't get conflicts.
       for (Function::arg_iterator AI = Fn->arg_begin(), AE = Fn->arg_end();
            AI != AE; ++AI)
         AI->setName("");
+    }
   } else  {  // Not already defined?
     Fn = new Function(FT, GlobalValue::ExternalLinkage, FunctionName,
                       CurModule.CurrentModule);
@@ -2004,27 +2121,30 @@ FunctionHeaderH : OptCallingConv ResultType Name '(' ArgList ')'
     // correctly handle cases, when pointer to function is passed as argument to
     // another function.
     Fn->setLinkage(CurFun.Linkage);
+    Fn->setVisibility(CurFun.Visibility);
   }
   Fn->setCallingConv($1);
-  Fn->setAlignment($8);
-  if ($7) {
-    Fn->setSection($7);
-    free($7);
+  Fn->setAlignment($9);
+  if ($8) {
+    Fn->setSection($8);
+    free($8);
   }
 
   // Add all of the arguments we parsed to the function...
   if ($5) {                     // Is null if empty...
     if (isVarArg) {  // Nuke the last entry
-      assert($5->back().Ty->get() == Type::VoidTy && $5->back().Name == 0&&
+      assert($5->back().Ty->get() == Type::VoidTy && $5->back().Name == 0 &&
              "Not a varargs marker!");
       delete $5->back().Ty;
       $5->pop_back();  // Delete the last entry
     }
     Function::arg_iterator ArgIt = Fn->arg_begin();
+    Function::arg_iterator ArgEnd = Fn->arg_end();
     unsigned Idx = 1;
-    for (ArgListType::iterator I = $5->begin(); I != $5->end(); ++I, ++ArgIt) {
+    for (ArgListType::iterator I = $5->begin(); 
+         I != $5->end() && ArgIt != ArgEnd; ++I, ++ArgIt) {
       delete I->Ty;                          // Delete the typeholder...
-      setValueName(ArgIt, I->Name);           // Insert arg into symtab...
+      setValueName(ArgIt, I->Name);          // Insert arg into symtab...
       CHECK_FOR_ERROR
       InsertValue(ArgIt);
       Idx++;
@@ -2037,12 +2157,13 @@ FunctionHeaderH : OptCallingConv ResultType Name '(' ArgList ')'
 
 BEGIN : BEGINTOK | '{';                // Allow BEGIN or '{' to start a function
 
-FunctionHeader : FunctionDefineLinkage FunctionHeaderH BEGIN {
+FunctionHeader : FunctionDefineLinkage GVVisibilityStyle FunctionHeaderH BEGIN {
   $$ = CurFun.CurrentFunction;
 
   // Make sure that we keep track of the linkage type even if there was a
   // previous "declare".
   $$->setLinkage($1);
+  $$->setVisibility($2);
 };
 
 END : ENDTOK | '}';                    // Allow end of '}' to end a function
@@ -2052,8 +2173,9 @@ Function : BasicBlockList END {
   CHECK_FOR_ERROR
 };
 
-FunctionProto : FunctionDeclareLinkage FunctionHeaderH {
+FunctionProto : FunctionDeclareLinkage GVVisibilityStyle FunctionHeaderH {
     CurFun.CurrentFunction->setLinkage($1);
+    CurFun.CurrentFunction->setVisibility($2);
     $$ = CurFun.CurrentFunction;
     CurFun.FunctionDone();
     CHECK_FOR_ERROR
@@ -2085,11 +2207,11 @@ ConstValueRef : ESINT64VAL {    // A reference to a direct constant
     CHECK_FOR_ERROR
   }
   | TRUETOK {
-    $$ = ValID::create(ConstantBool::getTrue());
+    $$ = ValID::create(ConstantInt::getTrue());
     CHECK_FOR_ERROR
   } 
   | FALSETOK {
-    $$ = ValID::create(ConstantBool::getFalse());
+    $$ = ValID::create(ConstantInt::getFalse());
     CHECK_FOR_ERROR
   }
   | NULL_TOK {
@@ -2147,12 +2269,20 @@ ConstValueRef : ESINT64VAL {    // A reference to a direct constant
 // SymbolicValueRef - Reference to one of two ways of symbolically refering to
 // another value.
 //
-SymbolicValueRef : INTVAL {  // Is it an integer reference...?
-    $$ = ValID::create($1);
+SymbolicValueRef : LOCALVAL_ID {  // Is it an integer reference...?
+    $$ = ValID::createLocalID($1);
     CHECK_FOR_ERROR
   }
-  | Name {                   // Is it a named reference...?
-    $$ = ValID::create($1);
+  | GLOBALVAL_ID {
+    $$ = ValID::createGlobalID($1);
+    CHECK_FOR_ERROR
+  }
+  | LocalName {                   // Is it a named reference...?
+    $$ = ValID::createLocalName($1);
+    CHECK_FOR_ERROR
+  }
+  | GlobalName {                   // Is it a named reference...?
+    $$ = ValID::createGlobalName($1);
     CHECK_FOR_ERROR
   };
 
@@ -2185,11 +2315,10 @@ BasicBlockList : BasicBlockList BasicBlock {
 // Basic blocks are terminated by branching instructions: 
 // br, br/cc, switch, ret
 //
-BasicBlock : InstructionList OptAssign BBTerminatorInst  {
+BasicBlock : InstructionList OptLocalAssign BBTerminatorInst  {
     setValueName($3, $2);
     CHECK_FOR_ERROR
     InsertValue($3);
-
     $1->getInstList().push_back($3);
     InsertValue($1);
     $$ = $1;
@@ -2206,7 +2335,7 @@ InstructionList : InstructionList Inst {
     CHECK_FOR_ERROR
   }
   | /* empty */ {
-    $$ = getBBVal(ValID::create((int)CurFun.NextBBNum++), true);
+    $$ = getBBVal(ValID::createLocalID(CurFun.NextBBNum++), true);
     CHECK_FOR_ERROR
 
     // Make sure to move the basic block to the correct location in the
@@ -2218,7 +2347,7 @@ InstructionList : InstructionList Inst {
     CHECK_FOR_ERROR
   }
   | LABELSTR {
-    $$ = getBBVal(ValID::create($1), true);
+    $$ = getBBVal(ValID::createLocalName($1), true);
     CHECK_FOR_ERROR
 
     // Make sure to move the basic block to the correct location in the
@@ -2243,12 +2372,13 @@ BBTerminatorInst : RET ResolvedVal {              // Return with a result...
     CHECK_FOR_ERROR
     $$ = new BranchInst(tmpBB);
   }                                                  // Conditional Branch...
-  | BR BOOL ValueRef ',' LABEL ValueRef ',' LABEL ValueRef {  
+  | BR INTTYPE ValueRef ',' LABEL ValueRef ',' LABEL ValueRef {  
+    assert(cast<IntegerType>($2)->getBitWidth() == 1 && "Not Bool?");
     BasicBlock* tmpBBA = getBBVal($6);
     CHECK_FOR_ERROR
     BasicBlock* tmpBBB = getBBVal($9);
     CHECK_FOR_ERROR
-    Value* tmpVal = getVal(Type::BoolTy, $3);
+    Value* tmpVal = getVal(Type::Int1Ty, $3);
     CHECK_FOR_ERROR
     $$ = new BranchInst(tmpBBA, tmpBBB, tmpVal);
   }
@@ -2266,7 +2396,7 @@ BBTerminatorInst : RET ResolvedVal {              // Return with a result...
       if (ConstantInt *CI = dyn_cast<ConstantInt>(I->first))
           S->addCase(CI, I->second);
       else
-        GEN_ERROR("Switch case is constant, but not a simple integer!");
+        GEN_ERROR("Switch case is constant, but not a simple integer");
     }
     delete $8;
     CHECK_FOR_ERROR
@@ -2280,18 +2410,18 @@ BBTerminatorInst : RET ResolvedVal {              // Return with a result...
     $$ = S;
     CHECK_FOR_ERROR
   }
-  | INVOKE OptCallingConv ResultType ValueRef '(' ValueRefList ')' 
+  | INVOKE OptCallingConv ResultTypes ValueRef '(' ValueRefList ')' OptFuncAttrs
     TO LABEL ValueRef UNWIND LABEL ValueRef {
 
     // Handle the short syntax
     const PointerType *PFTy = 0;
     const FunctionType *Ty = 0;
-    if (!(PFTy = dyn_cast<PointerType>($3.Ty->get())) ||
+    if (!(PFTy = dyn_cast<PointerType>($3->get())) ||
         !(Ty = dyn_cast<FunctionType>(PFTy->getElementType()))) {
       // Pull out the types of all of the arguments...
       std::vector<const Type*> ParamTypes;
       FunctionType::ParamAttrsList ParamAttrs;
-      ParamAttrs.push_back($3.Attrs);
+      ParamAttrs.push_back($8);
       for (ValueRefList::iterator I = $6->begin(), E = $6->end(); I != E; ++I) {
         const Type *Ty = I->Val->getType();
         if (Ty == Type::VoidTy)
@@ -2300,15 +2430,15 @@ BBTerminatorInst : RET ResolvedVal {              // Return with a result...
         ParamAttrs.push_back(I->Attrs);
       }
 
-      Ty = FunctionType::get($3.Ty->get(), ParamTypes, false, ParamAttrs);
+      Ty = FunctionType::get($3->get(), ParamTypes, false, ParamAttrs);
       PFTy = PointerType::get(Ty);
     }
 
     Value *V = getVal(PFTy, $4);   // Get the function we're calling...
     CHECK_FOR_ERROR
-    BasicBlock *Normal = getBBVal($10);
+    BasicBlock *Normal = getBBVal($11);
     CHECK_FOR_ERROR
-    BasicBlock *Except = getBBVal($13);
+    BasicBlock *Except = getBBVal($14);
     CHECK_FOR_ERROR
 
     // Check the arguments
@@ -2317,7 +2447,7 @@ BBTerminatorInst : RET ResolvedVal {              // Return with a result...
       // Make sure no arguments is a good thing!
       if (Ty->getNumParams() != 0)
         GEN_ERROR("No arguments passed to a function that "
-                       "expects arguments!");
+                       "expects arguments");
     } else {                                     // Has arguments?
       // Loop through FunctionType's arguments and ensure they are specified
       // correctly!
@@ -2328,7 +2458,7 @@ BBTerminatorInst : RET ResolvedVal {              // Return with a result...
       for (; ArgI != ArgE && I != E; ++ArgI, ++I) {
         if (ArgI->Val->getType() != *I)
           GEN_ERROR("Parameter " + ArgI->Val->getName()+ " is not of type '" +
-                         (*I)->getDescription() + "'!");
+                         (*I)->getDescription() + "'");
         Args.push_back(ArgI->Val);
       }
 
@@ -2337,7 +2467,7 @@ BBTerminatorInst : RET ResolvedVal {              // Return with a result...
           for (; ArgI != ArgE; ++ArgI)
             Args.push_back(ArgI->Val); // push the remaining varargs
       } else if (I != E || ArgI != ArgE)
-        GEN_ERROR("Invalid number of parameters detected!");
+        GEN_ERROR("Invalid number of parameters detected");
     }
 
     // Create the InvokeInst
@@ -2363,7 +2493,7 @@ JumpTable : JumpTable IntType ConstValueRef ',' LABEL ValueRef {
     Constant *V = cast<Constant>(getValNonImprovising($2, $3));
     CHECK_FOR_ERROR
     if (V == 0)
-      GEN_ERROR("May only switch on a constant pool value!");
+      GEN_ERROR("May only switch on a constant pool value");
 
     BasicBlock* tmpBB = getBBVal($6);
     CHECK_FOR_ERROR
@@ -2375,21 +2505,22 @@ JumpTable : JumpTable IntType ConstValueRef ',' LABEL ValueRef {
     CHECK_FOR_ERROR
 
     if (V == 0)
-      GEN_ERROR("May only switch on a constant pool value!");
+      GEN_ERROR("May only switch on a constant pool value");
 
     BasicBlock* tmpBB = getBBVal($5);
     CHECK_FOR_ERROR
     $$->push_back(std::make_pair(V, tmpBB)); 
   };
 
-Inst : OptAssign InstVal {
-  // Is this definition named?? if so, assign the name...
-  setValueName($2, $1);
-  CHECK_FOR_ERROR
-  InsertValue($2);
-  $$ = $2;
-  CHECK_FOR_ERROR
-};
+Inst : OptLocalAssign InstVal {
+    // Is this definition named?? if so, assign the name...
+    setValueName($2, $1);
+    CHECK_FOR_ERROR
+    InsertValue($2);
+    $$ = $2;
+    CHECK_FOR_ERROR
+  };
+
 
 PHIList : Types '[' ValueRef ',' ValueRef ']' {    // Used for PHI nodes
     if (!UpRefs.empty())
@@ -2431,7 +2562,7 @@ ValueRefList : Types ValueRef OptParamAttrs {
   | /*empty*/ { $$ = new ValueRefList(); };
 
 IndexList       // Used for gep instructions and constant expressions
-  : /*empty*/ { $$ = new std::vector<Value*>(); };
+  : /*empty*/ { $$ = new std::vector<Value*>(); }
   | IndexList ',' ResolvedVal {
     $$ = $1;
     $$->push_back($3);
@@ -2454,28 +2585,28 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
     if (!(*$2)->isInteger() && !(*$2)->isFloatingPoint() && 
         !isa<PackedType>((*$2).get()))
       GEN_ERROR(
-        "Arithmetic operator requires integer, FP, or packed operands!");
+        "Arithmetic operator requires integer, FP, or packed operands");
     if (isa<PackedType>((*$2).get()) && 
         ($1 == Instruction::URem || 
          $1 == Instruction::SRem ||
          $1 == Instruction::FRem))
-      GEN_ERROR("U/S/FRem not supported on packed types!");
+      GEN_ERROR("Remainder not supported on packed types");
     Value* val1 = getVal(*$2, $3); 
     CHECK_FOR_ERROR
     Value* val2 = getVal(*$2, $5);
     CHECK_FOR_ERROR
     $$ = BinaryOperator::create($1, val1, val2);
     if ($$ == 0)
-      GEN_ERROR("binary operator returned null!");
+      GEN_ERROR("binary operator returned null");
     delete $2;
   }
   | LogicalOps Types ValueRef ',' ValueRef {
     if (!UpRefs.empty())
       GEN_ERROR("Invalid upreference in type: " + (*$2)->getDescription());
-    if (!(*$2)->isIntegral()) {
-      if (!isa<PackedType>($2->get()) ||
-          !cast<PackedType>($2->get())->getElementType()->isIntegral())
-        GEN_ERROR("Logical operator requires integral operands!");
+    if (!(*$2)->isInteger()) {
+      if (Instruction::isShift($1) || !isa<PackedType>($2->get()) ||
+          !cast<PackedType>($2->get())->getElementType()->isInteger())
+        GEN_ERROR("Logical operator requires integral operands");
     }
     Value* tmpVal1 = getVal(*$2, $3);
     CHECK_FOR_ERROR
@@ -2483,7 +2614,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
     CHECK_FOR_ERROR
     $$ = BinaryOperator::create($1, tmpVal1, tmpVal2);
     if ($$ == 0)
-      GEN_ERROR("binary operator returned null!");
+      GEN_ERROR("binary operator returned null");
     delete $2;
   }
   | ICMP IPredicates Types ValueRef ',' ValueRef  {
@@ -2497,7 +2628,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
     CHECK_FOR_ERROR
     $$ = CmpInst::create($1, $2, tmpVal1, tmpVal2);
     if ($$ == 0)
-      GEN_ERROR("icmp operator returned null!");
+      GEN_ERROR("icmp operator returned null");
   }
   | FCMP FPredicates Types ValueRef ',' ValueRef  {
     if (!UpRefs.empty())
@@ -2510,48 +2641,25 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
     CHECK_FOR_ERROR
     $$ = CmpInst::create($1, $2, tmpVal1, tmpVal2);
     if ($$ == 0)
-      GEN_ERROR("fcmp operator returned null!");
-  }
-  | NOT ResolvedVal {
-    cerr << "WARNING: Use of eliminated 'not' instruction:"
-         << " Replacing with 'xor'.\n";
-
-    Value *Ones = ConstantIntegral::getAllOnesValue($2->getType());
-    if (Ones == 0)
-      GEN_ERROR("Expected integral type for not instruction!");
-
-    $$ = BinaryOperator::create(Instruction::Xor, $2, Ones);
-    if ($$ == 0)
-      GEN_ERROR("Could not create a xor instruction!");
-    CHECK_FOR_ERROR
-  }
-  | ShiftOps ResolvedVal ',' ResolvedVal {
-    if ($4->getType() != Type::Int8Ty)
-      GEN_ERROR("Shift amount must be i8 type!");
-    if (!$2->getType()->isInteger())
-      GEN_ERROR("Shift constant expression requires integer operand!");
-    CHECK_FOR_ERROR;
-    $$ = new ShiftInst($1, $2, $4);
-    CHECK_FOR_ERROR
+      GEN_ERROR("fcmp operator returned null");
   }
   | CastOps ResolvedVal TO Types {
     if (!UpRefs.empty())
       GEN_ERROR("Invalid upreference in type: " + (*$4)->getDescription());
     Value* Val = $2;
-    const Type* Ty = $4->get();
-    if (!Val->getType()->isFirstClassType())
-      GEN_ERROR("cast from a non-primitive type: '" +
-                Val->getType()->getDescription() + "'!");
-    if (!Ty->isFirstClassType())
-      GEN_ERROR("cast to a non-primitive type: '" + Ty->getDescription() +"'!");
-    $$ = CastInst::create($1, Val, $4->get());
+    const Type* DestTy = $4->get();
+    if (!CastInst::castIsValid($1, Val, DestTy))
+      GEN_ERROR("invalid cast opcode for cast from '" +
+                Val->getType()->getDescription() + "' to '" +
+                DestTy->getDescription() + "'"); 
+    $$ = CastInst::create($1, Val, DestTy);
     delete $4;
   }
   | SELECT ResolvedVal ',' ResolvedVal ',' ResolvedVal {
-    if ($2->getType() != Type::BoolTy)
-      GEN_ERROR("select condition must be boolean!");
+    if ($2->getType() != Type::Int1Ty)
+      GEN_ERROR("select condition must be boolean");
     if ($4->getType() != $6->getType())
-      GEN_ERROR("select value types should match!");
+      GEN_ERROR("select value types should match");
     $$ = new SelectInst($2, $4, $6);
     CHECK_FOR_ERROR
   }
@@ -2564,48 +2672,49 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
   }
   | EXTRACTELEMENT ResolvedVal ',' ResolvedVal {
     if (!ExtractElementInst::isValidOperands($2, $4))
-      GEN_ERROR("Invalid extractelement operands!");
+      GEN_ERROR("Invalid extractelement operands");
     $$ = new ExtractElementInst($2, $4);
     CHECK_FOR_ERROR
   }
   | INSERTELEMENT ResolvedVal ',' ResolvedVal ',' ResolvedVal {
     if (!InsertElementInst::isValidOperands($2, $4, $6))
-      GEN_ERROR("Invalid insertelement operands!");
+      GEN_ERROR("Invalid insertelement operands");
     $$ = new InsertElementInst($2, $4, $6);
     CHECK_FOR_ERROR
   }
   | SHUFFLEVECTOR ResolvedVal ',' ResolvedVal ',' ResolvedVal {
     if (!ShuffleVectorInst::isValidOperands($2, $4, $6))
-      GEN_ERROR("Invalid shufflevector operands!");
+      GEN_ERROR("Invalid shufflevector operands");
     $$ = new ShuffleVectorInst($2, $4, $6);
     CHECK_FOR_ERROR
   }
   | PHI_TOK PHIList {
     const Type *Ty = $2->front().first->getType();
     if (!Ty->isFirstClassType())
-      GEN_ERROR("PHI node operands must be of first class type!");
+      GEN_ERROR("PHI node operands must be of first class type");
     $$ = new PHINode(Ty);
     ((PHINode*)$$)->reserveOperandSpace($2->size());
     while ($2->begin() != $2->end()) {
       if ($2->front().first->getType() != Ty) 
-        GEN_ERROR("All elements of a PHI node must be of the same type!");
+        GEN_ERROR("All elements of a PHI node must be of the same type");
       cast<PHINode>($$)->addIncoming($2->front().first, $2->front().second);
       $2->pop_front();
     }
     delete $2;  // Free the list...
     CHECK_FOR_ERROR
   }
-  | OptTailCall OptCallingConv ResultType ValueRef '(' ValueRefList ')' {
+  | OptTailCall OptCallingConv ResultTypes ValueRef '(' ValueRefList ')' 
+    OptFuncAttrs {
 
     // Handle the short syntax
     const PointerType *PFTy = 0;
     const FunctionType *Ty = 0;
-    if (!(PFTy = dyn_cast<PointerType>($3.Ty->get())) ||
+    if (!(PFTy = dyn_cast<PointerType>($3->get())) ||
         !(Ty = dyn_cast<FunctionType>(PFTy->getElementType()))) {
       // Pull out the types of all of the arguments...
       std::vector<const Type*> ParamTypes;
       FunctionType::ParamAttrsList ParamAttrs;
-      ParamAttrs.push_back($3.Attrs);
+      ParamAttrs.push_back($8);
       for (ValueRefList::iterator I = $6->begin(), E = $6->end(); I != E; ++I) {
         const Type *Ty = I->Val->getType();
         if (Ty == Type::VoidTy)
@@ -2614,7 +2723,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
         ParamAttrs.push_back(I->Attrs);
       }
 
-      Ty = FunctionType::get($3.Ty->get(), ParamTypes, false, ParamAttrs);
+      Ty = FunctionType::get($3->get(), ParamTypes, false, ParamAttrs);
       PFTy = PointerType::get(Ty);
     }
 
@@ -2627,7 +2736,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
       // Make sure no arguments is a good thing!
       if (Ty->getNumParams() != 0)
         GEN_ERROR("No arguments passed to a function that "
-                       "expects arguments!");
+                       "expects arguments");
     } else {                                     // Has arguments?
       // Loop through FunctionType's arguments and ensure they are specified
       // correctly!
@@ -2639,7 +2748,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
       for (; ArgI != ArgE && I != E; ++ArgI, ++I) {
         if (ArgI->Val->getType() != *I)
           GEN_ERROR("Parameter " + ArgI->Val->getName()+ " is not of type '" +
-                         (*I)->getDescription() + "'!");
+                         (*I)->getDescription() + "'");
         Args.push_back(ArgI->Val);
       }
       if (Ty->isVarArg()) {
@@ -2647,7 +2756,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
           for (; ArgI != ArgE; ++ArgI)
             Args.push_back(ArgI->Val); // push the remaining varargs
       } else if (I != E || ArgI != ArgE)
-        GEN_ERROR("Invalid number of parameters detected!");
+        GEN_ERROR("Invalid number of parameters detected");
     }
     // Create the call node
     CallInst *CI = new CallInst(V, Args);
@@ -2655,6 +2764,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
     CI->setCallingConv($2);
     $$ = CI;
     delete $6;
+    delete $3;
     CHECK_FOR_ERROR
   }
   | MemoryInst {
@@ -2680,7 +2790,7 @@ MemoryInst : MALLOC Types OptCAlign {
     delete $2;
     CHECK_FOR_ERROR
   }
-  | MALLOC Types ',' INT32 ValueRef OptCAlign {
+  | MALLOC Types ',' INTTYPE ValueRef OptCAlign {
     if (!UpRefs.empty())
       GEN_ERROR("Invalid upreference in type: " + (*$2)->getDescription());
     Value* tmpVal = getVal($4, $5);
@@ -2695,7 +2805,7 @@ MemoryInst : MALLOC Types OptCAlign {
     delete $2;
     CHECK_FOR_ERROR
   }
-  | ALLOCA Types ',' INT32 ValueRef OptCAlign {
+  | ALLOCA Types ',' INTTYPE ValueRef OptCAlign {
     if (!UpRefs.empty())
       GEN_ERROR("Invalid upreference in type: " + (*$2)->getDescription());
     Value* tmpVal = getVal($4, $5);
@@ -2706,7 +2816,7 @@ MemoryInst : MALLOC Types OptCAlign {
   | FREE ResolvedVal {
     if (!isa<PointerType>($2->getType()))
       GEN_ERROR("Trying to free nonpointer type " + 
-                     $2->getType()->getDescription() + "!");
+                     $2->getType()->getDescription() + "");
     $$ = new FreeInst($2);
     CHECK_FOR_ERROR
   }
@@ -2735,7 +2845,7 @@ MemoryInst : MALLOC Types OptCAlign {
     const Type *ElTy = PT->getElementType();
     if (ElTy != $3->getType())
       GEN_ERROR("Can't store '" + $3->getType()->getDescription() +
-                     "' into space of type '" + ElTy->getDescription() + "'!");
+                     "' into space of type '" + ElTy->getDescription() + "'");
 
     Value* tmpVal = getVal(*$5, $6);
     CHECK_FOR_ERROR
@@ -2746,11 +2856,11 @@ MemoryInst : MALLOC Types OptCAlign {
     if (!UpRefs.empty())
       GEN_ERROR("Invalid upreference in type: " + (*$2)->getDescription());
     if (!isa<PointerType>($2->get()))
-      GEN_ERROR("getelementptr insn requires pointer operand!");
+      GEN_ERROR("getelementptr insn requires pointer operand");
 
     if (!GetElementPtrInst::getIndexedType(*$2, *$4, true))
       GEN_ERROR("Invalid getelementptr indices for type '" +
-                     (*$2)->getDescription()+ "'!");
+                     (*$2)->getDescription()+ "'");
     Value* tmpVal = getVal(*$2, $3);
     CHECK_FOR_ERROR
     $$ = new GetElementPtrInst(tmpVal, *$4);
@@ -2800,11 +2910,10 @@ int yyerror(const char *ErrorMsg) {
   std::string where 
     = std::string((CurFilename == "-") ? std::string("<stdin>") : CurFilename)
                   + ":" + utostr((unsigned) llvmAsmlineno) + ": ";
-  std::string errMsg = std::string(ErrorMsg) + "\n" + where + " while reading ";
-  if (yychar == YYEMPTY || yychar == 0)
-    errMsg += "end-of-file.";
-  else
-    errMsg += "token: '" + std::string(llvmAsmtext, llvmAsmleng) + "'";
+  std::string errMsg = where + "error: " + std::string(ErrorMsg);
+  if (yychar != YYEMPTY && yychar != 0)
+    errMsg += " while reading token: '" + std::string(llvmAsmtext, llvmAsmleng)+
+              "'";
   GenerateError(errMsg);
   return 0;
 }