[llvm-commits] [hlvm] r38406 - in /hlvm/trunk: hlvm/AST/AST.cpp hlvm/AST/AST.h hlvm/AST/Bundle.cpp hlvm/AST/ContainerType.cpp hlvm/AST/ContainerType.h hlvm/AST/MemoryOps.cpp hlvm/AST/MemoryOps.h hlvm/Pass/Pass.cpp hlvm/Pass/Validate.cpp hlvm/Reader/XMLReader.cpp hlvm/Writer/XMLWriter.cpp tools/hlvm-gentestcase/Generate.cpp

Reid Spencer reid at x10sys.com
Sat Jul 7 17:03:05 PDT 2007


Author: reid
Date: Sat Jul  7 19:03:05 2007
New Revision: 38406

URL: http://llvm.org/viewvc/llvm-project?rev=38406&view=rev
Log:
Several changes:
1. Fix problems with generating the new rational type (gen integer instead)
2. Make GetFieldIndex identify the field directly, not via an operand.
3. Don't generate the incr/decr operators (for now), can't rely on the operand
   being an AutoVarOp or a reference.
4. Implement generation of array expressions
5. Change "depth" var to signed so we stop recursing if depth < 0
6. Rewrite handling for GetIndexOp and GetFeildOp operators.

Modified:
    hlvm/trunk/hlvm/AST/AST.cpp
    hlvm/trunk/hlvm/AST/AST.h
    hlvm/trunk/hlvm/AST/Bundle.cpp
    hlvm/trunk/hlvm/AST/ContainerType.cpp
    hlvm/trunk/hlvm/AST/ContainerType.h
    hlvm/trunk/hlvm/AST/MemoryOps.cpp
    hlvm/trunk/hlvm/AST/MemoryOps.h
    hlvm/trunk/hlvm/Pass/Pass.cpp
    hlvm/trunk/hlvm/Pass/Validate.cpp
    hlvm/trunk/hlvm/Reader/XMLReader.cpp
    hlvm/trunk/hlvm/Writer/XMLWriter.cpp
    hlvm/trunk/tools/hlvm-gentestcase/Generate.cpp

Modified: hlvm/trunk/hlvm/AST/AST.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/AST.cpp?rev=38406&r1=38405&r2=38406&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/AST.cpp (original)
+++ hlvm/trunk/hlvm/AST/AST.cpp Sat Jul  7 19:03:05 2007
@@ -698,7 +698,7 @@
   {
     const Type* Ty = (*I)->getType();
     assert(Ty && "Arguments can't be void type");
-    Argument* arg = new_Argument((*I)->getName(),0,loc);
+    Argument* arg = new_Argument((*I)->getName(),Ty,loc);
     result->addArgument(arg);
   }
   result->setParent(B);
@@ -764,6 +764,37 @@
     hlvmAssert(!"Invalid referent type");
   result->setLocator(loc);
   result->setReferent(V);
+  result->setType(V->getType());
+  return result;
+}
+
+GetFieldOp* 
+AST::new_GetFieldOp(
+  Operator* op,
+  const std::string& name,
+  const Locator* loc
+)
+{
+  GetFieldOp* result = new GetFieldOp();
+  result->setLocator(loc);
+  result->setOperand(0,op);
+  result->setFieldName(name);
+  result->setType(result->getFieldType());
+  return result;
+}
+
+GetIndexOp* 
+AST::new_GetIndexOp(
+  Operator* op1,
+  Operator* op2,
+  const Locator* loc
+)
+{
+  GetIndexOp* result = new GetIndexOp();
+  result->setLocator(loc);
+  result->setOperand(0,op1);
+  result->setOperand(1,op2);
+  result->setType(result->getIndexedType());
   return result;
 }
 
@@ -774,7 +805,7 @@
   hlvmAssert(Ty != 0 && "ConvertOp must have a type to convert the value");
   ConvertOp* result = new ConvertOp();
   result->setType(Ty);
-  result->setOperand(V);
+  result->setOperand(0,V);
   result->setLocator(loc);
   return result;
 }
@@ -1331,16 +1362,6 @@
 template LoadOp*   
 AST::new_UnaryOp<LoadOp>(Operator*op1,Bundle* B, const Locator*loc);
 
-template GetFieldOp*  
-AST::new_BinaryOp<GetFieldOp>(const Type*, Operator*op1,Operator*op2,const Locator*loc);
-template GetFieldOp*  
-AST::new_BinaryOp<GetFieldOp>(Operator*op1,Operator*op2,Bundle* B, const Locator*loc);
-
-template GetIndexOp*  
-AST::new_BinaryOp<GetIndexOp>(const Type*, Operator*op1,Operator*op2,const Locator*loc);
-template GetIndexOp*  
-AST::new_BinaryOp<GetIndexOp>(Operator*op1,Operator*op2,Bundle* B, const Locator*loc);
-
 // Input/Output Operators
 template OpenOp* 
 AST::new_UnaryOp<OpenOp>(const Type* Ty, Operator*op1,const Locator*loc);

Modified: hlvm/trunk/hlvm/AST/AST.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/AST.h?rev=38406&r1=38405&r2=38406&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/AST.h (original)
+++ hlvm/trunk/hlvm/AST/AST.h Sat Jul  7 19:03:05 2007
@@ -56,6 +56,8 @@
 class Operator;
 class AutoVarOp;
 class GetOp;
+class GetFieldOp;
+class GetIndexOp;
 class ConvertOp;
 class URI;
 
@@ -505,8 +507,20 @@
 
     /// Create a new GetOp.
     GetOp* new_GetOp(
-      const Value* V,       ///< The value being referenced
-      const Locator*loc = 0 ///< The source locator
+      const Value* V,          ///< The value being referenced
+      const Locator*loc = 0    ///< The source locator
+    );
+
+    GetFieldOp* new_GetFieldOp(
+      Operator* op,            ///< The thing to be indexed
+      const std::string& nm,   ///< The name of the field to index
+      const Locator* loc = 0   ///< The source locator
+    );
+
+    GetIndexOp* new_GetIndexOp(
+      Operator* op1,           ///< The thing to be indexed
+      Operator* op2,           ///< The index
+      const Locator* loc = 0   ///< The source locator
     );
 
     /// Create a new ConvertOp.

Modified: hlvm/trunk/hlvm/AST/Bundle.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Bundle.cpp?rev=38406&r1=38405&r2=38406&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/Bundle.cpp (original)
+++ hlvm/trunk/hlvm/AST/Bundle.cpp Sat Jul  7 19:03:05 2007
@@ -184,6 +184,14 @@
     case intTy:             name = "int"; break;
     case longTy:            name = "long"; break;
     case octetTy:           name = "octet"; break;
+    case qs16Ty:            name = "qs16"; break;
+    case qs32Ty:            name = "qs32"; break;
+    case qs64Ty:            name = "qs64"; break;
+    case qs128Ty:           name = "qs128"; break;
+    case qu16Ty:            name = "qs16"; break;
+    case qu32Ty:            name = "qu32"; break;
+    case qu64Ty:            name = "qu64"; break;
+    case qu128Ty:           name = "qs128"; break;
     case r8Ty:              name = "r8"; break;
     case r16Ty:             name = "r16"; break;
     case r32Ty:             name = "r32"; break;

Modified: hlvm/trunk/hlvm/AST/ContainerType.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/ContainerType.cpp?rev=38406&r1=38405&r2=38406&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/ContainerType.cpp (original)
+++ hlvm/trunk/hlvm/AST/ContainerType.cpp Sat Jul  7 19:03:05 2007
@@ -35,9 +35,7 @@
 
 namespace hlvm {
 
-UniformContainerType::~UniformContainerType()
-{
-}
+UniformContainerType::~UniformContainerType() { }
 
 const char* 
 UniformContainerType::getPrimitiveName() const
@@ -76,30 +74,37 @@
   return 0;
 }
 
-unsigned 
-DisparateContainerType::getFieldIndex(const std::string& fldname) const
-{
-  for (const_iterator I = begin(), E = end(); I != E; ++I )
-    if ((*I)->getName() == fldname)
-      return I - begin() + 1;
-  return 0;
-}
-
-void 
+void
 DisparateContainerType::resolveTypeTo(const Type* from, const Type* to)
 {
   hlvmAssert(isa<OpaqueType>(from) && !isa<OpaqueType>(to));
   for (iterator I = begin(), E = end(); I != E; ++I)
-    if ((*I)->getType() == from) {
+    if ((*I)->getType() == from)
       (*I)->setType(to);
-    }
 }
 
+unsigned 
+DisparateContainerType::getFieldIndex(const std::string& fldname) const
+{
+for (const_iterator I = begin(), E = end(); I != E; ++I )
+  if ((*I)->getName() == fldname)
+    return I - begin() + 1;
+return 0;
+}
+
+const Type*
+DisparateContainerType::getFieldType(const std::string& fldname) const
+{
+for (const_iterator I = begin(), E = end(); I != E; ++I )
+  if ((*I)->getName() == fldname)
+    return (*I)->getType();
+return 0;
+}
 
-StructureType::~StructureType() { }
-ContinuationType::~ContinuationType() { }
+StructureType::~StructureType() {}
+ContinuationType::~ContinuationType() {}
+SignatureType::~SignatureType() {}
 
-SignatureType::~SignatureType() { }
 void SignatureType::resolveTypeTo(const Type* from, const Type* to)
 {
   DisparateContainerType::resolveTypeTo(from,to);

Modified: hlvm/trunk/hlvm/AST/ContainerType.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/ContainerType.h?rev=38406&r1=38405&r2=38406&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/ContainerType.h (original)
+++ hlvm/trunk/hlvm/AST/ContainerType.h Sat Jul  7 19:03:05 2007
@@ -272,6 +272,7 @@
     /// Return the index of a named field starting at 1. If the field is not
     /// found, returns 0.
     unsigned getFieldIndex(const std::string& fldname) const;
+    const Type* getFieldType(const std::string& fldname) const;
     /// Methods to support type inquiry via is, cast, dyn_cast
     static inline bool classof(const DisparateContainerType*) { return true; }
     static inline bool classof(const Node* N) { 

Modified: hlvm/trunk/hlvm/AST/MemoryOps.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/MemoryOps.cpp?rev=38406&r1=38405&r2=38406&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/MemoryOps.cpp (original)
+++ hlvm/trunk/hlvm/AST/MemoryOps.cpp Sat Jul  7 19:03:05 2007
@@ -28,6 +28,8 @@
 //===----------------------------------------------------------------------===//
 
 #include <hlvm/AST/MemoryOps.h>
+#include <hlvm/AST/ContainerType.h>
+#include <llvm/Support/Casting.h>
 
 namespace hlvm {
 
@@ -35,7 +37,24 @@
 StoreOp::~StoreOp() {}
 AutoVarOp::~AutoVarOp() {}
 GetOp::~GetOp() {}
-GetIndexOp::~GetIndexOp() {}
 GetFieldOp::~GetFieldOp() {}
+const Type* 
+GetFieldOp::getFieldType() const
+{
+  if (const DisparateContainerType* DCTy = 
+      llvm::dyn_cast<DisparateContainerType>(op1->getType()))
+    return DCTy->getFieldType(fieldName);
+  return 0;
+}
+
+GetIndexOp::~GetIndexOp() {}
+const Type* 
+GetIndexOp::getIndexedType() const
+{
+  if (const UniformContainerType* UCTy =
+      llvm::dyn_cast<UniformContainerType>(ops[0]->getType()))
+    return UCTy->getElementType();
+  return 0;
+}
 
 }

Modified: hlvm/trunk/hlvm/AST/MemoryOps.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/MemoryOps.h?rev=38406&r1=38405&r2=38406&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/MemoryOps.h (original)
+++ hlvm/trunk/hlvm/AST/MemoryOps.h Sat Jul  7 19:03:05 2007
@@ -261,18 +261,20 @@
 /// of the operator is the address of the memory location corresponding to the
 /// named field of the structure value.
 /// @brief AST GetFieldOp Operator
-class GetFieldOp : public MultiOperator
+class GetFieldOp : public UnaryOperator
 {
   /// @name Constructors
   /// @{
   protected:
-    GetFieldOp() : MultiOperator(GetFieldOpID) {}
+    GetFieldOp() : UnaryOperator(GetFieldOpID), fieldName() {}
     virtual ~GetFieldOp();
 
   /// @}
   /// @name Accessors
   /// @{
   public:
+    const std::string& getFieldName() const { return fieldName; }
+    const Type* getFieldType() const;
     static inline bool classof(const GetFieldOp*) { return true; }
     static inline bool classof(const Node* N) { return N->is(GetFieldOpID); }
 
@@ -280,11 +282,13 @@
   /// @name Mutators
   /// @{
   public:
+    void setFieldName(const std::string& nm) { fieldName = nm; }
 
   /// @}
   /// @name Data
   /// @{
   protected:
+    std::string fieldName;
   /// @}
   friend class AST;
 };
@@ -308,19 +312,11 @@
   /// @name Accessors
   /// @{
   public:
+    const Type* getIndexedType() const;
     static inline bool classof(const GetIndexOp*) { return true; }
     static inline bool classof(const Node* N) { return N->is(GetIndexOpID); }
 
   /// @}
-  /// @name Mutators
-  /// @{
-  public:
-
-  /// @}
-  /// @name Data
-  /// @{
-  protected:
-  /// @}
   friend class AST;
 };
 } // hlvm

Modified: hlvm/trunk/hlvm/Pass/Pass.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Pass/Pass.cpp?rev=38406&r1=38405&r2=38406&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Pass/Pass.cpp (original)
+++ hlvm/trunk/hlvm/Pass/Pass.cpp Sat Jul  7 19:03:05 2007
@@ -148,16 +148,22 @@
   runPostOrder(l);
 }
 
+template<> inline void
+PassManagerImpl::runOn(Type* Ty)
+{
+  runPreOrder(Ty);
+  runPostOrder(Ty);
+}
+
 template<> inline void 
 PassManagerImpl::runOn(Bundle* b)
 {
   hlvmAssert(b && "Null bundle?");
   runPreOrder(b);
   for (Bundle::tlist_iterator TI = b->tlist_begin(), TE = b->tlist_end(); 
-       TI != TE; ++TI) {
-    runPreOrder(const_cast<Type*>(*TI));
-    runPostOrder(const_cast<Type*>(*TI));
-  }
+       TI != TE; ++TI)
+    runOn(const_cast<Type*>(*TI));
+
   for (Bundle::clist_iterator CI = b->clist_begin(), CE = b->clist_end(); 
        CI != CE; ++CI) {
     runPreOrder(const_cast<Constant*>(*CI));
@@ -207,6 +213,8 @@
     runOn(cast<ConstantValue>(startAt));
   else if (isa<Operator>(startAt))
     runOn(cast<Operator>(startAt));
+  else if (isa<Type>(startAt))
+    runOn(cast<Type>(startAt));
   else
     hlvmAssert(!"startAt type not supported");
 }

Modified: hlvm/trunk/hlvm/Pass/Validate.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Pass/Validate.cpp?rev=38406&r1=38405&r2=38406&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Pass/Validate.cpp (original)
+++ hlvm/trunk/hlvm/Pass/Validate.cpp Sat Jul  7 19:03:05 2007
@@ -1014,7 +1014,7 @@
       if (cast<AutoVarOp>(op1)->isConstant()) 
         error(n,"Can't store to constant automatic variable");
     } else if (const GetOp* ref = dyn_cast<GetOp>(n->getOperand(0))) {
-      const Documentable* R = ref->getReferent();
+      const Value* R = ref->getReferent();
       if (isa<Variable>(R) && cast<Variable>(R)->isConstant())
         error(n,"Can't store to constant variable");
       else if (isa<AutoVarOp>(R) && cast<AutoVarOp>(R)->isConstant())
@@ -1060,7 +1060,7 @@
 ValidateImpl::validate(GetOp* op)
 {
   if (checkOperator(op,GetOpID,0,true)) {
-    const Documentable* referent = op->getReferent();
+    const Value* referent = op->getReferent();
     Block* blk = op->getContainingBlock();
     if (!blk)
       error(op,"GetOp not in a block?");
@@ -1122,7 +1122,7 @@
 {
   if (checkOperator(n,PreIncrOpID,1)) {
     if (GetOp* oprnd = llvm::dyn_cast<GetOp>(n->getOperand(0))) {
-      const Documentable* V = oprnd->getReferent();
+      const Value* V = oprnd->getReferent();
       if (V && (isa<AutoVarOp>(V) || isa<Variable>(V))) {
         if (!llvm::cast<Value>(V)->getType()->isNumericType())
           error(n,"Target of PostIncrOp is not numeric type");
@@ -1138,7 +1138,7 @@
 {
   if (checkOperator(n,PostIncrOpID,1)) {
     if (GetOp* oprnd = llvm::dyn_cast<GetOp>(n->getOperand(0))) {
-      const Documentable* V = oprnd->getReferent();
+      const Value* V = oprnd->getReferent();
       if (V && (isa<AutoVarOp>(V) || isa<Variable>(V))) {
         if (!llvm::cast<Value>(V)->getType()->isNumericType())
           error(n,"Target of PostIncrOp is not numeric type");
@@ -1154,7 +1154,7 @@
 {
   if (checkOperator(n,PreDecrOpID,1)){
     if (GetOp* oprnd = llvm::dyn_cast<GetOp>(n->getOperand(0))) {
-      const Documentable* V = oprnd->getReferent();
+      const Value* V = oprnd->getReferent();
       if (V && (isa<AutoVarOp>(V) || isa<Variable>(V))) {
         if (!llvm::cast<Value>(V)->getType()->isNumericType())
           error(n,"Target of PreDecrOp is not numeric type");
@@ -1170,7 +1170,7 @@
 {
   if (checkOperator(n,PostDecrOpID,1)) {
     if (GetOp* oprnd = llvm::dyn_cast<GetOp>(n->getOperand(0))) {
-      const Documentable* V = oprnd->getReferent();
+      const Value* V = oprnd->getReferent();
       if (V && (isa<AutoVarOp>(V) || isa<Variable>(V))) {
         if (!llvm::cast<Value>(V)->getType()->isNumericType())
           error(n,"Target of PostDecrOp is not numeric type");
@@ -1198,7 +1198,7 @@
 template<> inline void
 ValidateImpl::validate(ConvertOp* n)
 {
-  if (checkOperator(n,ConvertOpID,2)) {
+  if (checkOperator(n,ConvertOpID,1)) {
     const Operator* Oprnd1 = n->getOperand(0);
     /// FIXME: assure type of Oprnd1 is convertible to n->getType();
   }

Modified: hlvm/trunk/hlvm/Reader/XMLReader.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Reader/XMLReader.cpp?rev=38406&r1=38405&r2=38406&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Reader/XMLReader.cpp (original)
+++ hlvm/trunk/hlvm/Reader/XMLReader.cpp Sat Jul  7 19:03:05 2007
@@ -987,6 +987,53 @@
   return refop;
 }
 
+template<> GetFieldOp*
+XMLReaderImpl::parse<GetFieldOp>(xmlNodePtr& cur)
+{
+  std::string fieldName = getAttribute(cur,"field");
+  Locator* loc = getLocator(cur);
+  xmlNodePtr child = cur->children;
+  Documentation* doc = parse<Documentation>(child); 
+  if (child && skipBlanks(child)) {
+    Operator* oprnd1 = parseOperator(child);
+    GetFieldOp* gfo = ast->AST::new_GetFieldOp(oprnd1,fieldName,loc);
+    if (doc)
+      gfo->setDoc(doc);
+    return gfo;
+  } else {
+    error(loc,std::string("Operator '") + 
+          reinterpret_cast<const char*>(cur->name) + "' requires an operand.");
+  }
+  return 0;
+}
+
+template<> GetIndexOp*
+XMLReaderImpl::parse<GetIndexOp>(xmlNodePtr& cur)
+{
+  Locator* loc = getLocator(cur);
+  xmlNodePtr child = cur->children;
+  Documentation* doc = parse<Documentation>(child); 
+  if (child && skipBlanks(child)) {
+    Operator* oprnd1 = parseOperator(child);
+    child = child->next;
+    if (child && skipBlanks(child)) {
+      Operator* oprnd2 = parseOperator(child);
+      GetIndexOp* gio = ast->AST::new_GetIndexOp(oprnd1,oprnd2,loc);
+      if (doc)
+        gio->setDoc(doc);
+      return gio;
+    } else {
+      error(loc,std::string("Operator '") + 
+            reinterpret_cast<const char*>(cur->name) + 
+            "' needs a second operand.");
+    }
+  } else {
+    error(loc,std::string("Operator '") + 
+          reinterpret_cast<const char*>(cur->name) + "' requires 2 operands.");
+  }
+  return 0;
+}
+
 template<> ConvertOp*
 XMLReaderImpl::parse<ConvertOp>(xmlNodePtr& cur)
 {
@@ -1001,8 +1048,10 @@
     if (doc)
       cnvrt->setDoc(doc);
     return cnvrt;
+  } else {
+    error(loc,std::string("Operator '") + 
+          reinterpret_cast<const char*>(cur->name) + "' requires an operand.");
   }
-  hlvmDeadCode("Invalid ConvertOp");
   return 0;
 }
 
@@ -1034,7 +1083,7 @@
     return result;
   } else
     error(loc,std::string("Operator '") + 
-      reinterpret_cast<const char*>(cur->name) + "' requires one operand.");
+      reinterpret_cast<const char*>(cur->name) + "' requires an operand.");
   return 0;
 }
 
@@ -1332,12 +1381,12 @@
       case TKN_call:         op = parseMultiOp<CallOp>(cur); break;
       case TKN_store:        op = parseBinaryOp<StoreOp>(cur); break;
       case TKN_load:         op = parseUnaryOp<LoadOp>(cur); break;
-      case TKN_getidx:       op = parseBinaryOp<GetIndexOp>(cur); break;
-      case TKN_getfld:       op = parseBinaryOp<GetFieldOp>(cur); break;
       case TKN_open:         op = parseUnaryOp<OpenOp>(cur); break;
       case TKN_write:        op = parseBinaryOp<WriteOp>(cur); break;
       case TKN_close:        op = parseUnaryOp<CloseOp>(cur); break;
       case TKN_get:          op = parse<GetOp>(cur); break;
+      case TKN_getidx:       op = parse<GetIndexOp>(cur); break;
+      case TKN_getfld:       op = parse<GetFieldOp>(cur); break;
       case TKN_convert:      op = parse<ConvertOp>(cur); break;
       case TKN_autovar:      op = parse<AutoVarOp>(cur); break;
       case TKN_block:        op = parse<Block>(cur); break;

Modified: hlvm/trunk/hlvm/Writer/XMLWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Writer/XMLWriter.cpp?rev=38406&r1=38405&r2=38406&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Writer/XMLWriter.cpp (original)
+++ hlvm/trunk/hlvm/Writer/XMLWriter.cpp Sat Jul  7 19:03:05 2007
@@ -312,6 +312,19 @@
 }
 
 template<> void
+XMLWriterImpl::WriterPass::put(const RationalType* t)
+{
+  if (t->isIntrinsic())
+    return;
+  startElement("rational");
+  writeAttribute("id",t->getName());
+  writeAttribute("numerator", llvm::utostr(t->getNumeratorBits()));
+  writeAttribute("denominator", llvm::utostr(t->getDenominatorBits()));
+  putDoc(t);
+  endElement();
+}
+
+template<> void
 XMLWriterImpl::WriterPass::put(const OpaqueType* op)
 {
   if (op->isIntrinsic())
@@ -1222,6 +1235,7 @@
       case PointerTypeID:          put(cast<PointerType>(n)); break;
       case RangeTypeID:            put(cast<RangeType>(n)); break;
       case RealTypeID:             put(cast<RealType>(n)); break;
+      case RationalTypeID:         put(cast<RationalType>(n)); break;
       case SignatureTypeID:        put(cast<SignatureType>(n)); break;
       case StreamTypeID:           put(cast<StreamType>(n)); break;
       case StringTypeID:           put(cast<StringType>(n)); break;

Modified: hlvm/trunk/tools/hlvm-gentestcase/Generate.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/tools/hlvm-gentestcase/Generate.cpp?rev=38406&r1=38405&r2=38406&view=diff

==============================================================================
--- hlvm/trunk/tools/hlvm-gentestcase/Generate.cpp (original)
+++ hlvm/trunk/tools/hlvm-gentestcase/Generate.cpp Sat Jul  7 19:03:05 2007
@@ -129,6 +129,8 @@
       theType = f64Ty;
     else if (theType == bufferTy || theType == streamTy || theType == textTy)
       theType = s32Ty;
+    else if (theType >= qs16Ty && theType <= qu128Ty)
+      theType = u32Ty;
     return bundle->getIntrinsicType(theType);
   }
 
@@ -507,35 +509,33 @@
   if (V->typeis<StructureType>()) {
     const StructureType* Ty = cast<StructureType>(V->getType());
     const NamedType* fldname = Ty->getField(randRange(0,Ty->size()-1));
-    Constant* cfield = getConstantString(fldname->getName());
-    GetOp* field  = getReference(cfield);
-    return ast->new_BinaryOp<GetFieldOp>(V,field,bundle,getLocator());
+    return ast->new_GetFieldOp(V,fldname->getName(),getLocator());
   } else if (V->typeis<ArrayType>()) {
     const ArrayType* Ty = cast<ArrayType>(V->getType());
     Constant* cindex = getConstantInteger(0); //FIXME: gen rand at runtime
     GetOp* index = getReference(cindex);
-    return ast->new_BinaryOp<GetIndexOp>(V,index,bundle,getLocator());
+    return ast->new_GetIndexOp(V,index,getLocator());
   } else if (V->typeis<VectorType>()) {
     const VectorType* Ty = cast<VectorType>(V->getType());
     int64_t idx = randRange(0,Ty->getSize()-1);
     Constant* cindex = getConstantInteger(idx);
     GetOp* index = getReference(cindex);
-    return ast->new_BinaryOp<GetIndexOp>(V,index,bundle,getLocator());
+    return ast->new_GetIndexOp(V,index,getLocator());
   } else if (V->typeis<StringType>()) {
     const StringType* Ty = cast<StringType>(V->getType());
     Constant* cindex = getConstantInteger(0); //FIXME: gen rand at runtime
     GetOp* index = getReference(cindex);
-    return ast->new_BinaryOp<GetIndexOp>(V,index,bundle,getLocator());
+    return ast->new_GetIndexOp(V,index,getLocator());
   } else if (V->typeis<PointerType>()) {
     Constant* cindex = getConstantInteger(0);
     GetOp* index = getReference(cindex);
-    return ast->new_BinaryOp<GetIndexOp>(V,index,bundle,getLocator());
+    return ast->new_GetIndexOp(V,index,getLocator());
   } else
     hlvmAssert(!"Can't index this type!");
   return 0;
 }
 
-static Operator* genExpression(Operator* Val, unsigned depth);
+static Operator* genExpression(Operator* Val, int depth);
 static Operator* genUnaryExpression(Operator* Val);
 static Operator* genBinaryExpression(Operator* V1, Operator*V2);
 
@@ -608,28 +608,20 @@
 static Operator*
 genIntegerUnary(Operator* V1)
 {
-  hlvmAssert(V1->getType()->getID() == IntegerTypeID);
+  hlvmAssert(V1->getType()->isIntegralType());
   Operator* result = 0;
   NodeIDs id = NodeIDs(randRange(NegateOpID, PostDecrOpID));
   switch (id) {
-    case NegateOpID:
-      result = ast->new_UnaryOp<NegateOp>(V1,bundle,getLocator());
-      break;
-    case ComplementOpID:
-      result = ast->new_UnaryOp<ComplementOp>(V1,bundle,getLocator());
-      break;
     case PreIncrOpID:
-      result = ast->new_UnaryOp<PreIncrOp>(V1,bundle,getLocator());
-      break;
     case PostIncrOpID:
-      result = ast->new_UnaryOp<PostIncrOp>(V1,bundle,getLocator());
-      break;
     case PreDecrOpID:
-      result = ast->new_UnaryOp<PreDecrOp>(V1,bundle,getLocator());
-      break;
     case PostDecrOpID:
+    case NegateOpID:
       result = ast->new_UnaryOp<NegateOp>(V1,bundle,getLocator());
       break;
+    case ComplementOpID:
+      result = ast->new_UnaryOp<ComplementOp>(V1,bundle,getLocator());
+      break;
     default:
       hlvmAssert(!"Invalid unary op id for integer");
       result = ast->new_UnaryOp<ComplementOp>(V1,bundle,getLocator());
@@ -773,7 +765,72 @@
 {
   hlvmAssert(isa<ArrayType>(V1));
   const ArrayType* Ty = cast<ArrayType>(V1->getType());
-  return 0;
+  Block* blk = ast->new_Block(getLocator());
+  AutoVarOp* val1 = ast->new_AutoVarOp("val1",Ty,getLocator());
+  V1->setParent(val1);
+  AutoVarOp* result = ast->new_AutoVarOp("result",Ty,getLocator());
+  blk->addOperand(result);
+  Type* ptr_type = bundle->getPointerTo(Ty->getElementType());
+  ConstantInteger* null = getConstantInteger(0);
+  GetOp* getNull1 = ast->new_GetOp(null,getLocator());
+  AutoVarOp* ptr1 = ast->new_AutoVarOp("ptr1",ptr_type,getLocator());
+  blk->addOperand(ptr1);
+  GetIndexOp* idx1 = 
+    ast->new_GetIndexOp(val1,getNull1,getLocator());
+  idx1->setParent(ptr1);
+  GetOp* getNull2 = ast->new_GetOp(null,getLocator());
+  AutoVarOp* ptr2 = ast->new_AutoVarOp("ptr2",ptr_type,getLocator());
+  blk->addOperand(ptr2);
+  Value* val2 = genValue(Ty);
+  GetOp* getVal2 = ast->new_GetOp(val2,getLocator());
+  GetIndexOp* idx2 = 
+    ast->new_GetIndexOp(getVal2,getNull2,getLocator());
+  idx2->setParent(ptr2);
+  GetOp* getNull3 = ast->new_GetOp(null,getLocator());
+  AutoVarOp* ptr3 = ast->new_AutoVarOp("ptr3",ptr_type,getLocator());
+  blk->addOperand(ptr3);
+  GetIndexOp* idx3 = 
+    ast->new_GetIndexOp(result,getNull3,getLocator());
+  idx3->setParent(ptr3);
+  AutoVarOp* end = ast->new_AutoVarOp("end",ptr_type,getLocator());
+  blk->addOperand(end);
+  GetOp* get1 = ast->new_GetOp(val1,getLocator());
+  LengthOp* len1 = ast->new_UnaryOp<LengthOp>(get1,bundle,getLocator());
+  GetOp* get2 = ast->new_GetOp(val2,getLocator());
+  LengthOp* len2 = ast->new_UnaryOp<LengthOp>(get2,bundle,getLocator());
+  LessThanOp* le = ast->new_BinaryOp<LessThanOp>(len1,len2,bundle,getLocator());
+  GetOp* get3 = ast->new_GetOp(val1,getLocator());
+  LengthOp* len3 = ast->new_UnaryOp<LengthOp>(get3,bundle,getLocator());
+  GetOp* get4 = ast->new_GetOp(val2,getLocator());
+  LengthOp* len4 = ast->new_UnaryOp<LengthOp>(get4,bundle,getLocator());
+  SelectOp* sel = 
+    ast->new_TernaryOp<SelectOp>(le,len3,len4,bundle,getLocator());
+  GetIndexOp* endIndex = 
+    ast->new_GetIndexOp(val1,endIndex,getLocator());
+  endIndex->setParent(end);
+
+  LessThanOp* cond = 
+    ast->new_BinaryOp<LessThanOp>(ptr1,end,bundle,getLocator());
+  Block* whileBlock = ast->new_Block(getLocator());
+  GetOp* get5 = ast->new_GetOp(ptr1,getLocator());
+  PostIncrOp* incr1 = ast->new_UnaryOp<PostIncrOp>(get5,bundle,getLocator());
+  LoadOp* load1 = ast->new_UnaryOp<LoadOp>(incr1,bundle,getLocator());
+  GetOp* get6 = ast->new_GetOp(ptr2,getLocator());
+  PostIncrOp* incr2 = ast->new_UnaryOp<PostIncrOp>(get6,bundle,getLocator());
+  LoadOp* load2 = ast->new_UnaryOp<LoadOp>(incr2,bundle,getLocator());
+  Operator* expr = genBinaryExpression(load1,load2);
+  GetOp* get7 = ast->new_GetOp(ptr3,getLocator());
+  PostIncrOp* incr3 = ast->new_UnaryOp<PostIncrOp>(get7,bundle,getLocator());
+  StoreOp* store = ast->new_BinaryOp<StoreOp>(incr3,expr,bundle,getLocator());
+  whileBlock->addOperand(store);
+
+  WhileOp* whilst = 
+    ast->new_BinaryOp<WhileOp>(cond,whileBlock,bundle,getLocator());
+  blk->addOperand(whilst);
+  GetOp* get = ast->new_GetOp(result,getLocator());
+  ResultOp* rslt = ast->new_UnaryOp<ResultOp>(get,bundle,getLocator());
+  blk->addOperand(rslt);
+  return blk;
 }
 
 static Operator*
@@ -783,7 +840,72 @@
   hlvmAssert(isa<ArrayType>(V2));
   hlvmAssert(V1->getType() == V2->getType());
   const ArrayType* Ty = cast<ArrayType>(V1->getType());
-  return 0;
+  Block* blk = ast->new_Block(getLocator());
+  AutoVarOp* val1 = ast->new_AutoVarOp("val1",Ty,getLocator());
+  V1->setParent(val1);
+  AutoVarOp* val2 = ast->new_AutoVarOp("val2",Ty,getLocator());
+  V2->setParent(val2);
+  AutoVarOp* result = ast->new_AutoVarOp("result",Ty,getLocator());
+  blk->addOperand(result);
+  Type* ptr_type = bundle->getPointerTo(Ty->getElementType());
+  ConstantInteger* null = getConstantInteger(0);
+  GetOp* getNull1 = ast->new_GetOp(null,getLocator());
+  AutoVarOp* ptr1 = ast->new_AutoVarOp("ptr1",ptr_type,getLocator());
+  blk->addOperand(ptr1);
+  GetIndexOp* idx1 = 
+    ast->new_GetIndexOp(val1,getNull1,getLocator());
+  idx1->setParent(ptr1);
+  GetOp* getNull2 = ast->new_GetOp(null,getLocator());
+  AutoVarOp* ptr2 = ast->new_AutoVarOp("ptr2",ptr_type,getLocator());
+  blk->addOperand(ptr2);
+  GetIndexOp* idx2 = 
+    ast->new_GetIndexOp(val2,getNull2,getLocator());
+  idx2->setParent(ptr2);
+  GetOp* getNull3 = ast->new_GetOp(null,getLocator());
+  AutoVarOp* ptr3 = ast->new_AutoVarOp("ptr3",ptr_type,getLocator());
+  blk->addOperand(ptr3);
+  GetIndexOp* idx3 = 
+    ast->new_GetIndexOp(result,getNull3,getLocator());
+  idx3->setParent(ptr3);
+  AutoVarOp* end = ast->new_AutoVarOp("end",ptr_type,getLocator());
+  blk->addOperand(end);
+  GetOp* get1 = ast->new_GetOp(val1,getLocator());
+  LengthOp* len1 = ast->new_UnaryOp<LengthOp>(get1,bundle,getLocator());
+  GetOp* get2 = ast->new_GetOp(val2,getLocator());
+  LengthOp* len2 = ast->new_UnaryOp<LengthOp>(val2,bundle,getLocator());
+  LessThanOp* le = ast->new_BinaryOp<LessThanOp>(len1,len2,bundle,getLocator());
+  GetOp* get3 = ast->new_GetOp(val1,getLocator());
+  LengthOp* len3 = ast->new_UnaryOp<LengthOp>(get3,bundle,getLocator());
+  GetOp* get4 = ast->new_GetOp(val2,getLocator());
+  LengthOp* len4 = ast->new_UnaryOp<LengthOp>(get4,bundle,getLocator());
+  SelectOp* sel = 
+    ast->new_TernaryOp<SelectOp>(le,len3,len4,bundle,getLocator());
+  GetIndexOp* endIndex = 
+    ast->new_GetIndexOp(val1,endIndex,getLocator());
+  endIndex->setParent(end);
+
+  LessThanOp* cond = 
+    ast->new_BinaryOp<LessThanOp>(ptr1,end,bundle,getLocator());
+  Block* whileBlock = ast->new_Block(getLocator());
+  GetOp* get5 = ast->new_GetOp(ptr1,getLocator());
+  PostIncrOp* incr1 = ast->new_UnaryOp<PostIncrOp>(get5,bundle,getLocator());
+  LoadOp* load1 = ast->new_UnaryOp<LoadOp>(incr1,bundle,getLocator());
+  GetOp* get6 = ast->new_GetOp(ptr2,getLocator());
+  PostIncrOp* incr2 = ast->new_UnaryOp<PostIncrOp>(get6,bundle,getLocator());
+  LoadOp* load2 = ast->new_UnaryOp<LoadOp>(incr2,bundle,getLocator());
+  Operator* expr = genBinaryExpression(load1,load2);
+  GetOp* get7 = ast->new_GetOp(ptr3,getLocator());
+  PostIncrOp* incr3 = ast->new_UnaryOp<PostIncrOp>(get7,bundle,getLocator());
+  StoreOp* store = ast->new_BinaryOp<StoreOp>(incr3,expr,bundle,getLocator());
+  whileBlock->addOperand(store);
+
+  WhileOp* whilst = 
+    ast->new_BinaryOp<WhileOp>(cond,whileBlock,bundle,getLocator());
+  blk->addOperand(whilst);
+  GetOp* get = ast->new_GetOp(result,getLocator());
+  ResultOp* rslt = ast->new_UnaryOp<ResultOp>(get,bundle,getLocator());
+  blk->addOperand(rslt);
+  return blk;
 }
 
 static Operator*
@@ -793,16 +915,19 @@
   const VectorType* Ty = cast<VectorType>(V1->getType());
   Block* blk = ast->new_Block(getLocator());
   AutoVarOp* autovar = ast->new_AutoVarOp("result",Ty,getLocator());
+  autovar->setParent(blk);
+  AutoVarOp* val1 = ast->new_AutoVarOp("val1",Ty,getLocator());
+  V1->setParent(val1);
   for (unsigned i = 0; i < Ty->getSize(); ++i) {
     ConstantInteger* cst = getConstantInteger(i);
     GetOp* index = ast->new_GetOp(cst,getLocator());
     GetIndexOp* elem = 
-      ast->new_BinaryOp<GetIndexOp>(V1,index,bundle,getLocator());
+      ast->new_GetIndexOp(val1,index,getLocator());
     LoadOp* load1 = ast->new_UnaryOp<LoadOp>(elem,bundle,getLocator());
     Operator* expr = genUnaryExpression(load1);
     GetOp* get = ast->new_GetOp(autovar,getLocator());
     GetIndexOp* elem2 =
-      ast->new_BinaryOp<GetIndexOp>(get,index,bundle,getLocator());
+      ast->new_GetIndexOp(get,index,getLocator());
     StoreOp* store = 
       ast->new_BinaryOp<StoreOp>(elem2,expr,bundle,getLocator());
     blk->addOperand(store);
@@ -822,20 +947,25 @@
   const VectorType* Ty = llvm::cast<VectorType>(V1->getType());
   Block* blk = ast->new_Block(getLocator());
   AutoVarOp* autovar = ast->new_AutoVarOp("result",Ty,getLocator());
+  autovar->setParent(blk);
+  AutoVarOp* val1 = ast->new_AutoVarOp("val1",Ty,getLocator());
+  V1->setParent(val1);
+  AutoVarOp* val2 = ast->new_AutoVarOp("val2",Ty,getLocator());
+  V2->setParent(val2);
   for (unsigned i = 0; i < Ty->getSize(); ++i)
   {
     ConstantInteger* cst = getConstantInteger(i);
     GetOp* index = ast->new_GetOp(cst,getLocator());
-    GetFieldOp* elem1 = 
-      ast->new_BinaryOp<GetFieldOp>(V1,index,bundle,getLocator());
+    GetIndexOp* elem1 = 
+      ast->new_GetIndexOp(val1,index,getLocator());
     LoadOp* load1 = ast->new_UnaryOp<LoadOp>(elem1,bundle,getLocator());
-    GetFieldOp* elem2 = 
-      ast->new_BinaryOp<GetFieldOp>(V2,index,bundle,getLocator());
+    GetIndexOp* elem2 = 
+      ast->new_GetIndexOp(val2,index,getLocator());
     LoadOp* load2 = ast->new_UnaryOp<LoadOp>(elem1,bundle,getLocator());
     Operator* expr = genBinaryExpression(load1,load2);
     GetOp* get = ast->new_GetOp(autovar,getLocator());
-    GetFieldOp* elem3 = 
-      ast->new_BinaryOp<GetFieldOp>(get,index,bundle,getLocator());
+    GetIndexOp* elem3 = 
+      ast->new_GetIndexOp(get,index,getLocator());
     StoreOp* store = 
       ast->new_BinaryOp<StoreOp>(elem3,expr,bundle,getLocator());
     blk->addOperand(store);
@@ -850,21 +980,23 @@
 genStructureUnary(Operator* V1)
 {
   hlvmAssert(V1->getType()->getID() == StructureTypeID);
-  Block* blk = ast->new_Block(getLocator());
-  AutoVarOp* autovar = ast->new_AutoVarOp("result",V1->getType(),getLocator());
   const StructureType* Ty = llvm::cast<StructureType>(V1->getType());
+  Block* blk = ast->new_Block(getLocator());
+  AutoVarOp* autovar = ast->new_AutoVarOp("result",Ty,getLocator());
+  autovar->setParent(blk);
+  AutoVarOp* val1 = ast->new_AutoVarOp("val1",Ty,getLocator());
+  V1->setParent(val1);
   for (StructureType::const_iterator I = Ty->begin(), E = Ty->end(); 
        I != E; ++I)
   {
-    ConstantString* cst = getConstantString((*I)->getName());
-    GetOp* fldName = ast->new_GetOp(cst,getLocator());
+    const std::string& fldName = (*I)->getName();
     GetFieldOp* getField1 = 
-      ast->new_BinaryOp<GetFieldOp>(V1,fldName,bundle,getLocator());
+      ast->new_GetFieldOp(val1,fldName,getLocator());
     LoadOp* load1 = ast->new_UnaryOp<LoadOp>(getField1,bundle,getLocator());
     Operator* expr = genUnaryExpression(load1);
     GetOp* get = ast->new_GetOp(autovar,getLocator());
     GetFieldOp* getField3 =
-      ast->new_BinaryOp<GetFieldOp>(get,fldName,bundle,getLocator());
+      ast->new_GetFieldOp(get,fldName,getLocator());
     StoreOp* store = 
       ast->new_BinaryOp<StoreOp>(getField3,expr,bundle,getLocator());
     blk->addOperand(store);
@@ -881,24 +1013,27 @@
   hlvmAssert(V1->getType()->getID() == StructureTypeID);
   hlvmAssert(V2->getType()->getID() == StructureTypeID);
   hlvmAssert(V1->getType() == V2->getType());
-  Block* blk = ast->new_Block(getLocator());
-  AutoVarOp* autovar = ast->new_AutoVarOp("result",V1->getType(),getLocator());
   const StructureType* Ty = llvm::cast<StructureType>(V1->getType());
+  Block* blk = ast->new_Block(getLocator());
+  AutoVarOp* autovar = ast->new_AutoVarOp("result",Ty,getLocator());
+  autovar->setParent(blk);
+  AutoVarOp* val1 = ast->new_AutoVarOp("val1",Ty,getLocator());
+  V1->setParent(val1);
+  AutoVarOp* val2 = ast->new_AutoVarOp("val2",Ty,getLocator());
+  V2->setParent(val2);
   for (StructureType::const_iterator I = Ty->begin(), E = Ty->end(); 
        I != E; ++I)
   {
-    ConstantString* cst = getConstantString((*I)->getName());
-    GetOp* fldName = ast->new_GetOp(cst,getLocator());
     GetFieldOp* getField1 = 
-      ast->new_BinaryOp<GetFieldOp>(V1,fldName,bundle,getLocator());
+      ast->new_GetFieldOp(val1,(*I)->getName(),getLocator());
     LoadOp* load1 = ast->new_UnaryOp<LoadOp>(getField1,bundle,getLocator());
     GetFieldOp* getField2 = 
-      ast->new_BinaryOp<GetFieldOp>(V2,fldName,bundle,getLocator());
+      ast->new_GetFieldOp(val2,(*I)->getName(),getLocator());
     LoadOp* load2 = ast->new_UnaryOp<LoadOp>(getField2,bundle,getLocator());
     Operator* expr = genBinaryExpression(load1,load2);
     GetOp* get = ast->new_GetOp(autovar,getLocator());
     GetFieldOp* getField3 = 
-      ast->new_BinaryOp<GetFieldOp>(get,fldName,bundle,getLocator());
+      ast->new_GetFieldOp(get,(*I)->getName(),getLocator());
     StoreOp* store = 
       ast->new_BinaryOp<StoreOp>(getField3,expr,bundle,getLocator());
     blk->addOperand(store);
@@ -989,10 +1124,10 @@
 }
 
 // Forward declare
-static Function* genFunction(const Type* resultType, unsigned depth);
+static Function* genFunction(const Type* resultType, int depth);
 
 static Operator*
-genExpression(Operator* Val, unsigned depth)
+genExpression(Operator* Val, int depth)
 {
   if (depth > 0) {
     // Generate a function
@@ -1018,7 +1153,6 @@
   // Get the type of the thing to be merged
   const Type* Ty = op2->getType();
 
-
   // If its just a numeric type, simply add the merged value into the autovar
   if (Ty->isNumericType()) {
     Operator* get1 = ast->new_GetOp(op1,getLocator());
@@ -1053,7 +1187,7 @@
 }
 
 static Block*
-genFunctionBody(Function* F, unsigned depth)
+genFunctionBody(Function* F, int depth)
 {
   // Create the function body block and initialize it
   Block* B = ast->new_Block(getLocator());
@@ -1080,7 +1214,7 @@
     }
 
     // Generate the expression
-    Operator* expr = genExpression(theValue,depth-1);
+    Operator* expr = genExpression(theValue,depth);
 
     // Merge the current value of the autovar result with the generated
     // expression.
@@ -1097,7 +1231,7 @@
 }
 
 static Function*
-genFunction(const Type* resultType, unsigned depth)
+genFunction(const Type* resultType, int depth)
 {
   // Get the function name
   Locator* loc = getLocator();
@@ -1129,7 +1263,7 @@
   F->setLinkageKind(LK);
 
   // Create the body of the function
-  Block* blk = genFunctionBody(F,depth);
+  Block* blk = genFunctionBody(F,depth-1);
 
   // Insert the return operator
   ReturnOp* ret = ast->new_NilaryOp<ReturnOp>(bundle,getLocator());





More information about the llvm-commits mailing list