[llvm-commits] CVS: llvm/lib/VMCore/AsmWriter.cpp Type.cpp

Reid Spencer reid at x10sys.com
Fri Jan 5 09:06:38 PST 2007



Changes in directory llvm/lib/VMCore:

AsmWriter.cpp updated: 1.233 -> 1.234
Type.cpp updated: 1.154 -> 1.155
---
Log message:

Change the syntax for parameter attributes:
1. The @ sign is no longer necessary.
2. We now support "function attributes" as parameter attribute 0. 
3. Instead of locating the return type attributes after the type of a
   function result, they are now located after the function header's
   closing paranthesis and before any alignment or section options.
4. The way has been prepared for a new "noreturn" function attribute but 
   there is no support for recognizing it in the lexer nor doing anything
   with it if it does get set.
5. The FunctionType::getParamAttrsText method now has support for 
   returning multiple attributes. This required a change in its interface.

I'm unhappy that this change leads to 6 new shift/reduce conflicts, but 
in each case bison's decision to choose the shift is correct so there 
shouldn't be any damage from these conflicts.


---
Diffs of the changes:  (+27 -27)

 AsmWriter.cpp |   28 ++++++++++++++--------------
 Type.cpp      |   26 +++++++++++++-------------
 2 files changed, 27 insertions(+), 27 deletions(-)


Index: llvm/lib/VMCore/AsmWriter.cpp
diff -u llvm/lib/VMCore/AsmWriter.cpp:1.233 llvm/lib/VMCore/AsmWriter.cpp:1.234
--- llvm/lib/VMCore/AsmWriter.cpp:1.233	Sun Dec 31 16:17:01 2006
+++ llvm/lib/VMCore/AsmWriter.cpp	Fri Jan  5 11:06:19 2007
@@ -271,10 +271,6 @@
   case Type::FunctionTyID: {
     const FunctionType *FTy = cast<FunctionType>(Ty);
     calcTypeName(FTy->getReturnType(), TypeStack, TypeNames, Result);
-    if (FTy->getParamAttrs(0)) {
-      Result += " ";
-      Result += FunctionType::getParamAttrsText(FTy->getParamAttrs(0));
-    }
     Result += " (";
     unsigned Idx = 1;
     for (FunctionType::param_iterator I = FTy->param_begin(),
@@ -293,6 +289,10 @@
       Result += "...";
     }
     Result += ")";
+    if (FTy->getParamAttrs(0)) {
+      Result += " ";
+      Result += FunctionType::getParamAttrsText(FTy->getParamAttrs(0));
+    }
     break;
   }
   case Type::StructTyID: {
@@ -698,8 +698,6 @@
 std::ostream &AssemblyWriter::printTypeAtLeastOneLevel(const Type *Ty) {
   if (const FunctionType *FTy = dyn_cast<FunctionType>(Ty)) {
     printType(FTy->getReturnType());
-    if (FTy->getParamAttrs(0))
-      Out << ' ' << FunctionType::getParamAttrsText(FTy->getParamAttrs(0));
     Out << " (";
     unsigned Idx = 1;
     for (FunctionType::param_iterator I = FTy->param_begin(),
@@ -717,6 +715,8 @@
       Out << "...";
     }
     Out << ')';
+    if (FTy->getParamAttrs(0))
+      Out << ' ' << FunctionType::getParamAttrsText(FTy->getParamAttrs(0));
   } else if (const StructType *STy = dyn_cast<StructType>(Ty)) {
     if (STy->isPacked())
       Out << '<';
@@ -969,8 +969,6 @@
 
   const FunctionType *FT = F->getFunctionType();
   printType(F->getReturnType()) << ' ';
-  if (FT->getParamAttrs(0))
-    Out << FunctionType::getParamAttrsText(FT->getParamAttrs(0)) << ' ';
   if (!F->getName().empty())
     Out << getLLVMName(F->getName());
   else
@@ -995,7 +993,8 @@
     Out << "...";  // Output varargs portion of signature!
   }
   Out << ')';
-
+  if (FT->getParamAttrs(0))
+    Out << ' ' << FunctionType::getParamAttrsText(FT->getParamAttrs(0));
   if (F->hasSection())
     Out << " section \"" << F->getSection() << '"';
   if (F->getAlignment())
@@ -1186,8 +1185,6 @@
         (!isa<PointerType>(RetTy) ||
          !isa<FunctionType>(cast<PointerType>(RetTy)->getElementType()))) {
       Out << ' '; printType(RetTy);
-      if (FTy->getParamAttrs(0) != FunctionType::NoAttributeSet)
-        Out << " " << FTy->getParamAttrsText(FTy->getParamAttrs(0));
       writeOperand(Operand, false);
     } else {
       writeOperand(Operand, true);
@@ -1201,6 +1198,8 @@
         Out << " " << FTy->getParamAttrsText(FTy->getParamAttrs(op));
     }
     Out << " )";
+    if (FTy->getParamAttrs(0) != FunctionType::NoAttributeSet)
+      Out << ' ' << FTy->getParamAttrsText(FTy->getParamAttrs(0));
   } else if (const InvokeInst *II = dyn_cast<InvokeInst>(&I)) {
     const PointerType  *PTy = cast<PointerType>(Operand->getType());
     const FunctionType *FTy = cast<FunctionType>(PTy->getElementType());
@@ -1225,8 +1224,6 @@
         (!isa<PointerType>(RetTy) ||
          !isa<FunctionType>(cast<PointerType>(RetTy)->getElementType()))) {
       Out << ' '; printType(RetTy);
-      if (FTy->getParamAttrs(0) != FunctionType::NoAttributeSet)
-        Out << " " << FTy->getParamAttrsText(FTy->getParamAttrs(0));
       writeOperand(Operand, false);
     } else {
       writeOperand(Operand, true);
@@ -1241,7 +1238,10 @@
         Out << " " << FTy->getParamAttrsText(FTy->getParamAttrs(op-2));
     }
 
-    Out << " )\n\t\t\tto";
+    Out << " )";
+    if (FTy->getParamAttrs(0) != FunctionType::NoAttributeSet)
+      Out << " " << FTy->getParamAttrsText(FTy->getParamAttrs(0));
+    Out << "\n\t\t\tto";
     writeOperand(II->getNormalDest(), true);
     Out << " unwind";
     writeOperand(II->getUnwindDest(), true);


Index: llvm/lib/VMCore/Type.cpp
diff -u llvm/lib/VMCore/Type.cpp:1.154 llvm/lib/VMCore/Type.cpp:1.155
--- llvm/lib/VMCore/Type.cpp:1.154	Sun Dec 31 11:50:33 2006
+++ llvm/lib/VMCore/Type.cpp	Fri Jan  5 11:06:19 2007
@@ -245,7 +245,6 @@
   switch (Ty->getTypeID()) {
   case Type::FunctionTyID: {
     const FunctionType *FTy = cast<FunctionType>(Ty);
-    Result = FunctionType::getParamAttrsText(FTy->getParamAttrs(0));
     if (!Result.empty())
       Result += " ";
     Result += getTypeDescription(FTy->getReturnType(), TypeStack) + " (";
@@ -254,11 +253,7 @@
            E = FTy->param_end(); I != E; ++I) {
       if (I != FTy->param_begin())
         Result += ", ";
-      const char *PA = FunctionType::getParamAttrsText(FTy->getParamAttrs(Idx));
-      if (PA[0] != 0) {
-        Result += PA;
-        Result += " ";
-      }
+      Result +=  FunctionType::getParamAttrsText(FTy->getParamAttrs(Idx));
       Idx++;
       Result += getTypeDescription(*I, TypeStack);
     }
@@ -267,6 +262,9 @@
       Result += "...";
     }
     Result += ")";
+    if (FTy->getParamAttrs(0)) {
+      Result += " " + FunctionType::getParamAttrsText(FTy->getParamAttrs(0));
+    }
     break;
   }
   case Type::StructTyID: {
@@ -1021,13 +1019,15 @@
   return (*ParamAttrs)[Idx];
 }
 
-const char *FunctionType::getParamAttrsText(ParameterAttributes Attr) {
-  switch (Attr) {
-    default: assert(0 && "Invalid ParameterAttribute value");
-    case 0: return "";
-    case ZExtAttribute: return "@zext";
-    case SExtAttribute: return "@sext";
-  }
+std::string FunctionType::getParamAttrsText(ParameterAttributes Attr) {
+  std::string Result;
+  if (Attr & ZExtAttribute)
+    Result += "zext ";
+  if (Attr & SExtAttribute)
+    Result += "sext ";
+  if (Attr & NoReturnAttribute)
+    Result += "noreturn ";
+  return Result;
 }
 
 //===----------------------------------------------------------------------===//






More information about the llvm-commits mailing list