[llvm-commits] [hlvm] r38345 - in /hlvm/trunk: hlvm/AST/AST.cpp hlvm/AST/AST.h hlvm/AST/Bundle.h hlvm/AST/Constants.h hlvm/AST/Node.h hlvm/Pass/Validate.cpp hlvm/Reader/HLVM.rng hlvm/Reader/XMLReader.cpp hlvm/Writer/XMLWriter.cpp test/xml2xml/array.hlx test/xml2xml/doc.hlx test/xml2xml/intrinsics.hlx test/xml2xml/pointer.hlx test/xml2xml/resolve.hlx test/xml2xml/signature.hlx test/xml2xml/structure.hlx tools/hlvm-gentestcase/Generate.cpp tools/hlvm-gentestcase/hlvm-gentestcase.cpp

Reid Spencer reid at x10sys.com
Sat Jul 7 17:02:32 PDT 2007


Author: reid
Date: Sat Jul  7 19:02:32 2007
New Revision: 38345

URL: http://llvm.org/viewvc/llvm-project?rev=38345&view=rev
Log:
Some work on literal constants:
1. Forget about "atom", just use "intrinsic" directly (schema change)
2. Implement the remaining constant literals for structs, arrays, etc.
3. Fix some bugs in the test case generator that make it almost always
   produce code that passes validation (not quite perfect yet, but close).

Modified:
    hlvm/trunk/hlvm/AST/AST.cpp
    hlvm/trunk/hlvm/AST/AST.h
    hlvm/trunk/hlvm/AST/Bundle.h
    hlvm/trunk/hlvm/AST/Constants.h
    hlvm/trunk/hlvm/AST/Node.h
    hlvm/trunk/hlvm/Pass/Validate.cpp
    hlvm/trunk/hlvm/Reader/HLVM.rng
    hlvm/trunk/hlvm/Reader/XMLReader.cpp
    hlvm/trunk/hlvm/Writer/XMLWriter.cpp
    hlvm/trunk/test/xml2xml/array.hlx
    hlvm/trunk/test/xml2xml/doc.hlx
    hlvm/trunk/test/xml2xml/intrinsics.hlx
    hlvm/trunk/test/xml2xml/pointer.hlx
    hlvm/trunk/test/xml2xml/resolve.hlx
    hlvm/trunk/test/xml2xml/signature.hlx
    hlvm/trunk/test/xml2xml/structure.hlx
    hlvm/trunk/tools/hlvm-gentestcase/Generate.cpp
    hlvm/trunk/tools/hlvm-gentestcase/hlvm-gentestcase.cpp

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

==============================================================================
--- hlvm/trunk/hlvm/AST/AST.cpp (original)
+++ hlvm/trunk/hlvm/AST/AST.cpp Sat Jul  7 19:02:32 2007
@@ -630,7 +630,7 @@
 ConstantPointer* 
 AST::new_ConstantPointer(
   const std::string& name,
-  ConstantValue* referent,
+  Constant* referent,
   const Locator* loc
 )
 {
@@ -645,7 +645,7 @@
 AST::new_ConstantArray(
   const std::string& name,
   const std::vector<ConstantValue*>& vals,
-  const ArrayType* VT,
+  const ArrayType* AT,
   const Locator* loc
 )
 {
@@ -655,10 +655,9 @@
   for (std::vector<ConstantValue*>::const_iterator I = vals.begin(),
        E = vals.end(); I != E; ++I ) 
   {
-    hlvmAssert((*I)->getType() == VT->getElementType());
     result->addConstant(*I);
   }
-  result->setType(VT);
+  result->setType(AT);
   return result;
 }
 
@@ -676,7 +675,6 @@
   for (std::vector<ConstantValue*>::const_iterator I = vals.begin(),
        E = vals.end(); I != E; ++I ) 
   {
-    hlvmAssert((*I)->getType() == AT->getElementType());
     result->addConstant(*I);
   }
   result->setType(AT);
@@ -707,6 +705,30 @@
   return result;
 }
 
+ConstantContinuation* 
+AST::new_ConstantContinuation(
+  const std::string& name,
+  const std::vector<ConstantValue*>& vals,
+  const ContinuationType* ST,
+  const Locator* loc
+)
+{
+  ConstantContinuation* result = new ConstantContinuation();
+  result->setLocator(loc);
+  result->setName(name);
+  hlvmAssert(ST->size() == vals.size());
+  ContinuationType::const_iterator STI = ST->begin();
+  for (std::vector<ConstantValue*>::const_iterator I = vals.begin(),
+       E = vals.end(); I != E; ++I ) 
+  {
+    hlvmAssert(STI != ST->end());
+    result->addConstant(*I);
+    ++STI;
+  }
+  result->setType(ST);
+  return result;
+}
+
 Variable*
 AST::new_Variable(const std::string& id, const Type* Ty, const Locator* loc)
 {

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

==============================================================================
--- hlvm/trunk/hlvm/AST/AST.h (original)
+++ hlvm/trunk/hlvm/AST/AST.h Sat Jul  7 19:02:32 2007
@@ -483,7 +483,7 @@
     /// Create a new ConstantPointer node.
     ConstantPointer* new_ConstantPointer(
       const std::string& name,  ///< The name of the constant
-      ConstantValue* referent,          ///< The value pointed to
+      Constant* referent,       ///< The value pointed to
       const Locator* loc = 0    ///< The source locator
     );
     /// Create a new ConstantArray node.

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Bundle.h (original)
+++ hlvm/trunk/hlvm/AST/Bundle.h Sat Jul  7 19:02:32 2007
@@ -144,6 +144,7 @@
   protected:
     std::string  name;      ///< The name for this bundle
     TypeList     types;     ///< The list of types
+    TypeList     unresolvedTypes; ///< The list of forward referenced types
     ValueList    values;    ///< The list of values in insertion order
     CValList     cvals;     ///< The list of constant values
     LinkableList linkables; ///< The list of linkables

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Constants.h (original)
+++ hlvm/trunk/hlvm/AST/Constants.h Sat Jul  7 19:02:32 2007
@@ -370,7 +370,7 @@
   /// @name Constructors
   /// @{
   protected:
-    ConstantPointer(const ConstantValue* cv) 
+    ConstantPointer(const Constant* cv) 
       : ConstantValue(ConstantPointerID)  { value = cv; }
     virtual ~ConstantPointer();
 
@@ -378,7 +378,7 @@
   /// @name Accessors
   /// @{
   public:
-    const ConstantValue* getValue() const { return value; }
+    const Constant* getValue() const { return value; }
     static inline bool classof(const ConstantPointer*) { return true; }
     static inline bool classof(const Node* N) 
       { return N->is(ConstantPointerID); }
@@ -387,7 +387,7 @@
   /// @name Data
   /// @{
   public:
-    const ConstantValue* value;
+    const Constant* value;
   /// @}
   friend class AST;
 };

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Node.h (original)
+++ hlvm/trunk/hlvm/AST/Node.h Sat Jul  7 19:02:32 2007
@@ -527,7 +527,8 @@
   /// @{
   public:
     /// Get the name of the node
-    inline Documentation* getDoc() { return doc; }
+    inline Documentation* getDoc() const { 
+      return const_cast<Documentation*>(doc); }
 
     static inline bool classof(const Documentable*) { return true; }
     static inline bool classof(const Node* N) { return N->isDocumentable(); }

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

==============================================================================
--- hlvm/trunk/hlvm/Pass/Validate.cpp (original)
+++ hlvm/trunk/hlvm/Pass/Validate.cpp Sat Jul  7 19:02:32 2007
@@ -492,8 +492,6 @@
     // Check that it can be converted to binary
     if (!endp || startp == endp || *endp != '\0')
       error(CI,"Invalid integer constant. Conversion failed.");
-    else if (llvm::itostr(val) != CI->getValue())
-      error(CI,"Invalid integer constant, not losslessly convertible");
     else if (const IntegerType* Ty = dyn_cast<IntegerType>(CI->getType())) {
       if (val < 0 && !Ty->isSigned()) {
         error(CI,"Invalid integer constant. " 

Modified: hlvm/trunk/hlvm/Reader/HLVM.rng
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Reader/HLVM.rng?rev=38345&r1=38344&r2=38345&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Reader/HLVM.rng (original)
+++ hlvm/trunk/hlvm/Reader/HLVM.rng Sat Jul  7 19:02:32 2007
@@ -233,19 +233,22 @@
       </zeroOrMore>
       <zeroOrMore>
         <choice>
-          <ref name="alias.elem"/>
           <ref name="array.elem"/>
-          <ref name="atom.elem"/>
+          <ref name="constant.elem"/>
           <ref name="enumeration.elem"/>
+          <ref name="function.elem"/>
+          <ref name="intrinsic.elem"/>
+          <ref name="opaque.elem"/>
           <ref name="pointer.elem"/>
-          <ref name="structure.elem"/>
+          <ref name="program.elem"/>
+          <ref name="range.elem"/>
+          <ref name="real.elem"/>
           <ref name="signature.elem"/>
-          <ref name="vector.elem"/>
-          <ref name="opaque.elem"/>
-          <ref name="constant.elem"/>
+          <ref name="signed.elem"/>
+          <ref name="structure.elem"/>
+          <ref name="unsigned.elem"/>
           <ref name="variable.elem"/>
-          <ref name="function.elem"/>
-          <ref name="program.elem"/>
+          <ref name="vector.elem"/>
         </choice>
       </zeroOrMore>
     </element>
@@ -265,66 +268,59 @@
 
   <!--PATTERNS FOR DEFINING TYPES -->
 
-  <define name="alias.elem">
-    <element name="alias">
-      <ref name="Named_Element.pat"/>
-      <attribute name="renames"><ref name="Identifier.type"/></attribute>
-    </element>
-  </define>
-
-  <define name="intrinsic.elem">
-    <element name="intrinsic">
-      <attribute name="is">
-        <ref name="Intrinsic_Atoms.type"/>
-      </attribute>
-    </element>
-  </define>
-
   <define name="signed.elem">
     <element name="signed">
+      <ref name="Named_Element.pat"/>
       <attribute name="bits">
         <ref name="Integer.type"/>
       </attribute>
+      <ref name="Documentation.pat"/>
     </element>
   </define>
 
   <define name="unsigned.elem">
     <element name="unsigned">
+      <ref name="Named_Element.pat"/>
       <attribute name="bits">
         <ref name="Integer.type"/>
       </attribute>
+      <ref name="Documentation.pat"/>
     </element>
   </define>
 
   <define name="range.elem">
     <element name="range">
+      <ref name="Named_Element.pat"/>
       <attribute name="min">
         <ref name="Integer.type"/>
       </attribute>
       <attribute name="max">
         <ref name="Integer.type"/>
       </attribute>
+      <ref name="Documentation.pat"/>
     </element>
   </define>
 
   <define name="real.elem">
     <element name="real">
-      <attribute name="precision">
+      <ref name="Named_Element.pat"/>
+      <attribute name="mantissa">
+        <ref name="Integer.type"/>
+      </attribute>
+      <attribute name="exponent">
         <ref name="Integer.type"/>
       </attribute>
+      <ref name="Documentation.pat"/>
     </element>
   </define>
 
-  <define name="atom.elem">
-    <element name="atom">
+  <define name="intrinsic.elem">
+    <element name="intrinsic">
       <ref name="Named_Element.pat"/>
-      <choice>
-        <ref name="intrinsic.elem"/>
-        <ref name="signed.elem"/>
-        <ref name="unsigned.elem"/>
-        <ref name="range.elem"/>
-        <ref name="real.elem"/>
-      </choice>
+      <attribute name="is">
+        <ref name="Intrinsic_Atoms.type"/>
+      </attribute>
+      <ref name="Documentation.pat"/>
     </element>
   </define>
 
@@ -450,6 +446,7 @@
   <define name="Literal.pat">
     <choice>
       <ref name="Boolean_Literal.pat"/>
+      <ref name="char.elem"/>
       <ref name="Integer_Literal.pat"/>
       <ref name="Real_Literal.pat"/>
       <ref name="char.elem"/>
@@ -478,6 +475,11 @@
     </choice>
   </define>
 
+  <define name="Character_Literal.pat">
+    <element name="char">
+      <ref name="Character.type"/>
+    </element>
+  </define>
 
   <define name="Integer_Literal.pat">
     <choice>
@@ -539,7 +541,9 @@
   <define name="ptr.elem">
     <element name="ptr">
       <ref name="Typed_Literal.pat"/>
-      <ref name="Literal.pat"/>
+      <attribute name="to">
+        <ref name="Identifier.type"/>
+      </attribute>
     </element>
   </define>
 

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

==============================================================================
--- hlvm/trunk/hlvm/Reader/XMLReader.cpp (original)
+++ hlvm/trunk/hlvm/Reader/XMLReader.cpp Sat Jul  7 19:02:32 2007
@@ -114,12 +114,13 @@
 
   inline xmlNodePtr   checkDoc(xmlNodePtr cur, Documentable* node);
 
-  Constant*      parseLiteralConstant(xmlNodePtr& cur, const std::string& name,
+  ConstantValue* parseLiteralConstant(xmlNodePtr& cur, const std::string& name,
     const Type* Ty);
   Constant*      parseConstant      (xmlNodePtr& cur);
   Operator*      parseOperator      (xmlNodePtr& cur);
   void           parseTree          ();
-  Type*          parseAtom          (xmlNodePtr& cur);
+  Type*          parseIntrinsic     (xmlNodePtr& cur);
+  Type*          parseInteger       (xmlNodePtr& cur, bool isSigned);
 
   template<class OpClass>
   OpClass*       parse(xmlNodePtr& cur);
@@ -388,7 +389,7 @@
   return Ty;
 }
 
-Constant*
+ConstantValue*
 XMLReaderImpl::parseLiteralConstant(
     xmlNodePtr& cur, 
     const std::string& name,
@@ -403,7 +404,7 @@
   // skip over blank text to find next element
   skipBlanks(cur);
 
-  Constant* C = 0;
+  ConstantValue* C = 0;
   const char* prefix = 0;
   std::string actualName(name);
   int token = getToken(cur->name);
@@ -432,6 +433,17 @@
       C = ast->new_ConstantBoolean(name, value, getLocator(cur));
       break;
     }
+    case TKN_char:
+    {
+      hlvmAssert(Ty->is(CharacterTypeID));
+      std::string buffer;
+      xmlNodePtr child = cur->children;
+      getTextContent(child,buffer);
+      std::string name= actualName.empty() ? 
+        std::string("char_") + buffer : actualName;
+      C = ast->new_ConstantCharacter(name, buffer, getLocator(cur));
+      break;
+    }
     case TKN_bin:
     case TKN_oct:
     case TKN_dec:
@@ -472,6 +484,80 @@
       C =  ast->new_ConstantString(name,value,getLocator(cur));
       break;
     }
+    case TKN_ptr:
+    {
+      std::string id = getAttribute(cur,"id");
+      std::string name = actualName.empty() ? std::string("ptr_") + id :
+          actualName;
+      Constant* referent =  bundle->find_cval(id);
+      // Didn't find a constant? Try a linkable
+      if (!referent)
+        referent = bundle->find_linkable(id);
+      C = ast->new_ConstantPointer(name,referent,loc);
+      break;
+    }
+    case TKN_arr:
+    {
+      const ArrayType* AT = llvm::cast<ArrayType>(Ty);
+      const Type* ElemType = AT->getElementType();
+      xmlNodePtr child = cur->children;
+      std::vector<ConstantValue*> elems;
+      while (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE) {
+        ConstantValue* elem = parseLiteralConstant(child,"",ElemType);
+        elems.push_back(elem);
+        child = child->next;
+      }
+      std::string name = actualName.empty() ? std::string("arr") : actualName;
+      C = ast->new_ConstantArray(name,elems,AT,getLocator(cur));
+      break;
+    }
+    case TKN_vect:
+    {
+      const VectorType* VT = llvm::cast<VectorType>(Ty);
+      const Type* ElemType = VT->getElementType();
+      xmlNodePtr child = cur->children;
+      std::vector<ConstantValue*> elems;
+      while (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE) {
+        ConstantValue* elem = parseLiteralConstant(child,"",ElemType);
+        elems.push_back(elem);
+        child = child->next;
+      }
+      std::string name = actualName.empty() ? std::string("vec") : actualName;
+      C = ast->new_ConstantVector(name,elems,VT,getLocator(cur));
+      break;
+    }
+    case TKN_struct:
+    {
+      const StructureType* ST = llvm::cast<StructureType>(Ty);
+      xmlNodePtr child = cur->children;
+      std::vector<ConstantValue*> fields;
+      StructureType::const_iterator I = ST->begin();
+      while (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE) {
+        ConstantValue* field = parseLiteralConstant(child,"",(*I)->getType());
+        fields.push_back(field);
+        child = child->next;
+        ++I;
+      }
+      std::string name = actualName.empty() ? std::string("struct") :actualName;
+      C = ast->new_ConstantStructure(name,fields,ST,getLocator(cur));
+      break;
+    }
+    case TKN_cont:
+    {
+      const ContinuationType* CT = llvm::cast<ContinuationType>(Ty);
+      xmlNodePtr child = cur->children;
+      std::vector<ConstantValue*> fields;
+      ContinuationType::const_iterator I = CT->begin();
+      while (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE) {
+        ConstantValue* field = parseLiteralConstant(child,"",(*I)->getType());
+        fields.push_back(field);
+        child = child->next;
+        ++I;
+      }
+      std::string name = actualName.empty() ? std::string("struct") :actualName;
+      C = ast->new_ConstantContinuation(name,fields,CT,getLocator(cur));
+      break;
+    }
     default:
       hlvmAssert(!"Invalid kind of constant");
       break;
@@ -529,6 +615,84 @@
   return child;
 }
 
+Type*     
+XMLReaderImpl::parseIntrinsic(xmlNodePtr& cur)
+{
+  Locator* loc = getLocator(cur);
+  std::string name = getAttribute(cur,"id");
+  const char* is = getAttribute(cur,"is");
+  xmlNodePtr child = cur->children;
+  Documentation* theDoc = parse<Documentation>(child);
+  Type* result = create_builtin_type(ast,is,name,loc);
+  if (result) {
+    if (theDoc)
+      result->setDoc(theDoc);
+  } else
+    error(loc,"Invalid intrinsic kind");
+  return result;
+}
+
+Type*
+XMLReaderImpl::parseInteger(xmlNodePtr& cur, bool isSigned)
+{
+  Locator* loc = getLocator(cur);
+  std::string name = getAttribute(cur,"id");
+  const char* bits = getAttribute(cur,"bits");
+  xmlNodePtr child = cur->children;
+  Documentation* theDoc = parse<Documentation>(child);
+  if (bits) {
+    uint64_t numBits = recognize_nonNegativeInteger(bits);
+    IntegerType* result = ast->new_IntegerType(name,numBits,isSigned,loc);
+    if (theDoc)
+      result->setDoc(theDoc);
+    return result;
+  }
+  error(loc,"Invalid integer specificaiton");
+  return 0;
+}
+
+template<> RangeType*
+XMLReaderImpl::parse<RangeType>(xmlNodePtr& cur)
+{
+  Locator* loc = getLocator(cur);
+  std::string name = getAttribute(cur,"id");
+  const char* min = getAttribute(cur, "min");
+  const char* max = getAttribute(cur, "max");
+  xmlNodePtr child = cur->children;
+  Documentation* theDoc = parse<Documentation>(child);
+  if (min && max) {
+    int64_t minVal = recognize_Integer(min);
+    int64_t maxVal = recognize_Integer(max);
+    RangeType* result = ast->new_RangeType(name,minVal,maxVal,loc);
+    if (theDoc)
+      result->setDoc(theDoc);
+    return result;
+  }
+  error(loc,"Invalid min/max specification");
+  return 0;
+}
+
+template<> RealType*
+XMLReaderImpl::parse<RealType>(xmlNodePtr& cur)
+{
+  Locator* loc = getLocator(cur);
+  std::string name = getAttribute(cur,"id");
+  const char* mantissa = getAttribute(cur, "mantissa");
+  const char* exponent = getAttribute(cur, "exponent");
+  xmlNodePtr child = cur->children;
+  Documentation* theDoc = parse<Documentation>(child);
+  if (mantissa && exponent) {
+    int32_t mantVal = recognize_nonNegativeInteger(mantissa);
+    int32_t expoVal = recognize_nonNegativeInteger(exponent);
+    RealType* result = ast->new_RealType(name,mantVal,expoVal,loc);
+    if (theDoc)
+      result->setDoc(theDoc);
+    return result;
+  }
+  error(loc,"Invalid mantissa/exponent specification");
+  return 0;
+}
+
 template<> EnumerationType*
 XMLReaderImpl::parse<EnumerationType>(xmlNodePtr& cur)
 {
@@ -944,19 +1108,22 @@
         break;
       }
       case TKN_import      : { n = parse<Import>(child); break; }
-      case TKN_bundle      : { n = parse<Bundle>(child); break; }
-      case TKN_atom        : { n = parseAtom(child); break; }
+      case TKN_array       : { n = parse<ArrayType>(child); break; }
+      case TKN_constant    : { n = parseConstant(child); break; }
       case TKN_enumeration : { n = parse<EnumerationType>(child); break; }
+      case TKN_function    : { n = parse<Function>(child); break; }
+      case TKN_intrinsic   : { n = parseIntrinsic(child); break; }
+      case TKN_opaque      : { n = parse<OpaqueType>(child); break; }
       case TKN_pointer     : { n = parse<PointerType>(child); break; }
-      case TKN_array       : { n = parse<ArrayType>(child); break; }
-      case TKN_vector      : { n = parse<VectorType>(child); break; }
-      case TKN_structure   : { n = parse<StructureType>(child); break; }
+      case TKN_program     : { n = parse<Program>(child); break; }
+      case TKN_range       : { n = parse<RangeType>(child); break; }
+      case TKN_real        : { n = parse<RealType>(child); break; }
       case TKN_signature   : { n = parse<SignatureType>(child); break; }
-      case TKN_opaque      : { n = parse<OpaqueType>(child); break; }
-      case TKN_constant    : { n = parseConstant(child); break; }
+      case TKN_signed      : { n = parseInteger(child,true); break; }
+      case TKN_structure   : { n = parse<StructureType>(child); break; }
+      case TKN_unsigned    : { n = parseInteger(child,false); break; }
       case TKN_variable    : { n = parse<Variable>(child); break; }
-      case TKN_program     : { n = parse<Program>(child); break; }
-      case TKN_function    : { n = parse<Function>(child); break; }
+      case TKN_vector      : { n = parse<VectorType>(child); break; }
       default:
       {
         hlvmDeadCode("Invalid content for bundle");
@@ -970,76 +1137,6 @@
   return bundle;
 }
 
-Type*     
-XMLReaderImpl::parseAtom(xmlNodePtr& cur)
-{
-  hlvmAssert(getToken(cur->name)==TKN_atom);
-  Locator* loc = getLocator(cur);
-  std::string name = getAttribute(cur,"id");
-  xmlNodePtr child = cur->children;
-  Documentation* theDoc = parse<Documentation>(child);
-  child = (theDoc==0 ? child : child->next );
-  Type* result = 0;
-  if (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE) {
-    int tkn = getToken(child->name);
-    switch (tkn) {
-      case TKN_intrinsic: {
-        const char* is = getAttribute(child,"is");
-        result = create_builtin_type(ast,is,name,loc);
-        if (!result)
-          error(loc,"Invalid intrinsic kind");
-        break;
-      }
-      case TKN_signed: {
-        const char* bits = getAttribute(child,"bits");
-        if (bits) {
-          uint64_t numBits = recognize_nonNegativeInteger(bits);
-          result = ast->new_IntegerType(name,numBits,/*signed=*/true,loc);
-        }
-        break;
-      }
-      case TKN_unsigned: {
-        const char* bits = getAttribute(child,"bits");
-        if (bits) {
-          uint64_t numBits = recognize_nonNegativeInteger(bits);
-          result = ast->new_IntegerType(name,numBits,/*signed=*/false,loc);
-        }
-        break;
-      }      
-      case TKN_range: {
-        const char* min = getAttribute(child, "min");
-        const char* max = getAttribute(child, "max");
-        if (min && max) {
-          int64_t minVal = recognize_Integer(min);
-          int64_t maxVal = recognize_Integer(max);
-          result = ast->new_RangeType(name,minVal,maxVal,loc);
-        }
-        break;
-      }
-      case TKN_real: {
-        const char* mantissa = getAttribute(child, "mantissa");
-        const char* exponent = getAttribute(child, "exponent");
-        if (mantissa && exponent) {
-          int32_t mantVal = recognize_nonNegativeInteger(mantissa);
-          int32_t expoVal = recognize_nonNegativeInteger(exponent);
-          result = ast->new_RealType(name,mantVal,expoVal,loc);
-        }
-        break;
-      }
-      default:
-        error(loc, "Invalid content for atom");
-        break;
-    }
-    if (result) {
-      if (theDoc)
-        result->setDoc(theDoc);
-      return result;
-    }
-  }
-  error(loc,"Atom definition element expected");
-  return 0;
-}
-
 Operator*
 XMLReaderImpl::parseOperator(xmlNodePtr& cur)
 {

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

==============================================================================
--- hlvm/trunk/hlvm/Writer/XMLWriter.cpp (original)
+++ hlvm/trunk/hlvm/Writer/XMLWriter.cpp Sat Jul  7 19:02:32 2007
@@ -98,10 +98,15 @@
 
     inline void putHeader();
     inline void putFooter();
-    inline void putDoc(Documentable* node);
+    inline void putDoc(const Documentable* node);
+
+    void putConstantValue(const ConstantValue* CV,bool nested);
+
+    template<class NodeClass>
+    inline void put(const NodeClass* nc);
 
     template<class NodeClass>
-    inline void put(NodeClass* nc);
+    inline void put(const NodeClass* nc, bool nested);
 
     virtual void handle(Node* n,Pass::TraversalKinds mode);
 
@@ -156,7 +161,7 @@
 }
 
 template<> void 
-XMLWriterImpl::WriterPass::put(Documentation* b)
+XMLWriterImpl::WriterPass::put(const Documentation* b)
 {
   startElement("doc");
   const std::string& data = b->getDoc();
@@ -166,7 +171,7 @@
 }
 
 inline void
-XMLWriterImpl::WriterPass::putDoc(Documentable* node)
+XMLWriterImpl::WriterPass::putDoc(const Documentable* node)
 {
   Documentation* theDoc = node->getDoc();
   if (theDoc) {
@@ -175,81 +180,72 @@
 }
 
 template<> void 
-XMLWriterImpl::WriterPass::put(AnyType* t)
+XMLWriterImpl::WriterPass::put(const AnyType* t)
 {
-  startElement("atom");
-  writeAttribute("id",t->getName());
-  putDoc(t);
   startElement("intrinsic");
+  writeAttribute("id",t->getName());
   writeAttribute("is","any");
-  endElement();
+  putDoc(t);
 }
 
 template<> void 
-XMLWriterImpl::WriterPass::put(StringType* t)
+XMLWriterImpl::WriterPass::put(const StringType* t)
 {
-  startElement("atom");
-  writeAttribute("id",t->getName());
-  putDoc(t);
   startElement("intrinsic");
+  writeAttribute("id",t->getName());
   writeAttribute("is","string");
-  endElement();
+  putDoc(t);
 }
 
 template<>void
-XMLWriterImpl::WriterPass::put(BooleanType* t)
+XMLWriterImpl::WriterPass::put(const BooleanType* t)
 {
-  startElement("atom");
-  writeAttribute("id",t->getName());
-  putDoc(t);
   startElement("intrinsic");
+  writeAttribute("id",t->getName());
   writeAttribute("is","bool");
-  endElement();
+  putDoc(t);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(CharacterType* t)
+XMLWriterImpl::WriterPass::put(const CharacterType* t)
 {
-  startElement("atom");
-  writeAttribute("id",t->getName());
-  putDoc(t);
   startElement("intrinsic");
+  writeAttribute("id",t->getName());
   writeAttribute("is","char");
-  endElement();
+  putDoc(t);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(IntegerType* t)
+XMLWriterImpl::WriterPass::put(const IntegerType* t)
 {
-  startElement("atom");
-  writeAttribute("id",t->getName());
-  putDoc(t);
   const char* primName = t->getPrimitiveName();
   if (primName) {
     startElement("intrinsic");
+    writeAttribute("id",t->getName());
     writeAttribute("is",primName);
   } else if (t->isSigned()) {
     startElement("signed");
+    writeAttribute("id",t->getName());
     writeAttribute("bits", llvm::utostr(t->getBits()));
   } else {
     startElement("unsigned");
+    writeAttribute("id",t->getName());
     writeAttribute("bits", llvm::utostr(t->getBits()));
   }
-  endElement();
+  putDoc(t);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(RangeType* t)
+XMLWriterImpl::WriterPass::put(const RangeType* t)
 {
   startElement("range");
   writeAttribute("id",t->getName());
   writeAttribute("min",t->getMin());
   writeAttribute("max",t->getMax());
-  putDoc(t);
 }
 
 template<> void 
-XMLWriterImpl::WriterPass::put(EnumerationType* t)
+XMLWriterImpl::WriterPass::put(const EnumerationType* t)
 {
   startElement("enumeration");
   writeAttribute("id",t->getName());
@@ -264,37 +260,33 @@
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(RealType* t)
+XMLWriterImpl::WriterPass::put(const RealType* t)
 {
-  startElement("atom");
-  writeAttribute("id",t->getName());
-  putDoc(t);
   const char* primName = t->getPrimitiveName();
   if (primName) {
     startElement("intrinsic");
+    writeAttribute("id",t->getName());
     writeAttribute("is",primName);
-    endElement();
   } else {
     startElement("real");
+    writeAttribute("id",t->getName());
     writeAttribute("mantissa", llvm::utostr(t->getMantissa()));
     writeAttribute("exponent", llvm::utostr(t->getExponent()));
-    endElement();
   }
+  putDoc(t);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(OctetType* t)
+XMLWriterImpl::WriterPass::put(const OctetType* t)
 {
-  startElement("atom");
-  writeAttribute("id",t->getName());
-  putDoc(t);
   startElement("intrinsic");
+  writeAttribute("id",t->getName());
   writeAttribute("is","octet");
-  endElement();
+  putDoc(t);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(OpaqueType* op)
+XMLWriterImpl::WriterPass::put(const OpaqueType* op)
 {
   startElement("opaque");
   writeAttribute("id",op->getName());
@@ -302,7 +294,7 @@
 }
 
 template<> void 
-XMLWriterImpl::WriterPass::put(PointerType* t)
+XMLWriterImpl::WriterPass::put(const PointerType* t)
 {
   startElement("pointer");
   writeAttribute("id", t->getName());
@@ -311,7 +303,7 @@
 }
 
 template<> void 
-XMLWriterImpl::WriterPass::put(ArrayType* t)
+XMLWriterImpl::WriterPass::put(const ArrayType* t)
 {
   startElement("array");
   writeAttribute("id", t->getName());
@@ -321,7 +313,7 @@
 }
 
 template<> void 
-XMLWriterImpl::WriterPass::put(VectorType* t)
+XMLWriterImpl::WriterPass::put(const VectorType* t)
 {
   startElement("vector");
   writeAttribute("id", t->getName());
@@ -331,12 +323,13 @@
 }
 
 template<> void 
-XMLWriterImpl::WriterPass::put(StructureType* t)
+XMLWriterImpl::WriterPass::put(const StructureType* t)
 {
   startElement("structure");
   writeAttribute("id",t->getName());
   putDoc(t);
-  for (StructureType::iterator I = t->begin(), E = t->end(); I != E; ++I) {
+  for (StructureType::const_iterator I = t->begin(), E = t->end(); 
+       I != E; ++I) {
     startElement("field");
     Field* field = cast<Field>(*I);
     writeAttribute("id",field->getName());
@@ -347,7 +340,7 @@
 }
 
 template<> void 
-XMLWriterImpl::WriterPass::put(SignatureType* t)
+XMLWriterImpl::WriterPass::put(const SignatureType* t)
 {
   startElement("signature");
   writeAttribute("id",t->getName());
@@ -355,7 +348,8 @@
   if (t->isVarArgs())
     writeAttribute("varargs","true");
   putDoc(t);
-  for (SignatureType::iterator I = t->begin(), E = t->end(); I != E; ++I) {
+  for (SignatureType::const_iterator I = t->begin(), E = t->end(); I != E; ++I)
+  {
     startElement("arg");
     Parameter* param = cast<Parameter>(*I);
     writeAttribute("id",param->getName());
@@ -365,9 +359,8 @@
   }
 }
 
-
 template<> void
-XMLWriterImpl::WriterPass::put(ConstantAny* i)
+XMLWriterImpl::WriterPass::put<ConstantAny>(const ConstantAny* i, bool nested)
 {
   startElement("constant");
   writeAttribute("id",i->getName());
@@ -375,11 +368,13 @@
 }
 
 template<> void 
-XMLWriterImpl::WriterPass::put(ConstantBoolean* i)
+XMLWriterImpl::WriterPass::put(const ConstantBoolean* i, bool nested)
 {
-  startElement("constant");
-  writeAttribute("id",i->getName());
-  writeAttribute("type",i->getType()->getName());
+  if (!nested) {
+    startElement("constant");
+    writeAttribute("id",i->getName());
+    writeAttribute("type",i->getType()->getName());
+  }
   if (i->getValue())
     startElement("true");
   else
@@ -388,35 +383,53 @@
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(ConstantCharacter* i)
+XMLWriterImpl::WriterPass::put(const ConstantCharacter* i, bool nested)
 {
-  startElement("constant");
-  writeAttribute("id",i->getName());
-  writeAttribute("type",i->getType()->getName());
+  if (!nested) {
+    startElement("constant");
+    writeAttribute("id",i->getName());
+    writeAttribute("type",i->getType()->getName());
+  }
+  startElement("char");
+  writeString(i->getValue());
+  endElement();
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(ConstantEnumerator* i)
+XMLWriterImpl::WriterPass::put(const ConstantEnumerator* i, bool nested)
 {
-  startElement("constant");
-  writeAttribute("id",i->getName());
-  writeAttribute("type",i->getType()->getName());
+  if (!nested) {
+    startElement("constant");
+    writeAttribute("id",i->getName());
+    writeAttribute("type",i->getType()->getName());
+  }
+  startElement("enum");
+  writeString(i->getValue());
+  endElement();
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(ConstantOctet* i)
+XMLWriterImpl::WriterPass::put(const ConstantOctet* i, bool nested)
 {
-  startElement("constant");
-  writeAttribute("id",i->getName());
-  writeAttribute("type",i->getType()->getName());
+  if (!nested) {
+    startElement("constant");
+    writeAttribute("id",i->getName());
+    writeAttribute("type",i->getType()->getName());
+  }
+  startElement("octet");
+  unsigned char val = i->getValue();
+  writeString(llvm::utostr(val));
+  endElement();
 }
 
 template<> void 
-XMLWriterImpl::WriterPass::put(ConstantInteger* i)
+XMLWriterImpl::WriterPass::put(const ConstantInteger* i, bool nested)
 {
-  startElement("constant");
-  writeAttribute("id",i->getName());
-  writeAttribute("type",i->getType()->getName());
+  if (!nested) {
+    startElement("constant");
+    writeAttribute("id",i->getName());
+    writeAttribute("type",i->getType()->getName());
+  }
   switch (i->getBase()) {
     case 2: startElement("bin"); break;
     case 8: startElement("oct"); break;
@@ -428,69 +441,126 @@
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(ConstantReal* r)
+XMLWriterImpl::WriterPass::put(const ConstantReal* r, bool nested)
 {
-  startElement("constant");
-  writeAttribute("id",r->getName());
-  writeAttribute("type",r->getType()->getName());
+  if (!nested) {
+    startElement("constant");
+    writeAttribute("id",r->getName());
+    writeAttribute("type",r->getType()->getName());
+  }
   startElement("dbl");
   writeString(r->getValue());
   endElement();
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(ConstantString* t)
+XMLWriterImpl::WriterPass::put(const ConstantString* t, bool nested)
 {
-  startElement("constant");
-  writeAttribute("id",t->getName());
-  writeAttribute("type",t->getType()->getName());
+  if (!nested) {
+    startElement("constant");
+    writeAttribute("id",t->getName());
+    writeAttribute("type",t->getType()->getName());
+  }
   startElement("string");
   writeString(t->getValue());
   endElement();
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(ConstantPointer* i)
+XMLWriterImpl::WriterPass::put(const ConstantPointer* i, bool nested)
 {
-  startElement("constant");
-  writeAttribute("id",i->getName());
-  writeAttribute("type",i->getType()->getName());
+  if (!nested) {
+    startElement("constant");
+    writeAttribute("id",i->getName());
+    writeAttribute("type",i->getType()->getName());
+  }
+  startElement("ptr");
+  writeAttribute("to",i->getValue()->getName());
+  endElement();
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(ConstantArray* i)
+XMLWriterImpl::WriterPass::put(const ConstantArray* i, bool nested)
 {
-  startElement("constant");
-  writeAttribute("id",i->getName());
-  writeAttribute("type",i->getType()->getName());
+  if (!nested) {
+    startElement("constant");
+    writeAttribute("id",i->getName());
+    writeAttribute("type",i->getType()->getName());
+  }
+  startElement("arr");
+  for (ConstantArray::const_iterator I = i->begin(), E = i->end(); I != E; ++I)
+    putConstantValue(*I,true);
+  endElement();
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(ConstantVector* i)
+XMLWriterImpl::WriterPass::put(const ConstantVector* i, bool nested)
 {
-  startElement("constant");
-  writeAttribute("id",i->getName());
-  writeAttribute("type",i->getType()->getName());
+  if (!nested) {
+    startElement("constant");
+    writeAttribute("id",i->getName());
+    writeAttribute("type",i->getType()->getName());
+  }
+  startElement("vect");
+  for (ConstantArray::const_iterator I = i->begin(), E = i->end(); I != E; ++I)
+    putConstantValue(*I,true);
+  endElement();
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(ConstantStructure* i)
+XMLWriterImpl::WriterPass::put(const ConstantStructure* i, bool nested)
 {
-  startElement("constant");
-  writeAttribute("id",i->getName());
-  writeAttribute("type",i->getType()->getName());
+  if (!nested) {
+    startElement("constant");
+    writeAttribute("id",i->getName());
+    writeAttribute("type",i->getType()->getName());
+  }
+  startElement("struct");
+  for (ConstantStructure::const_iterator I = i->begin(), E = i->end(); 
+       I != E; ++I)
+    putConstantValue(*I,true);
+  endElement();
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(ConstantContinuation* i)
+XMLWriterImpl::WriterPass::put(const ConstantContinuation* i, bool nested)
 {
-  startElement("constant");
-  writeAttribute("id",i->getName());
-  writeAttribute("type",i->getType()->getName());
+  if (!nested) {
+    startElement("constant");
+    writeAttribute("id",i->getName());
+    writeAttribute("type",i->getType()->getName());
+  }
+  startElement("cont");
+  for (ConstantContinuation::const_iterator I = i->begin(), E = i->end(); 
+       I != E; ++I)
+    putConstantValue(*I,true);
+  endElement();
+}
+
+inline void
+XMLWriterImpl::WriterPass::putConstantValue(const ConstantValue* V, bool nstd)
+{
+  switch (V->getID()) {
+    case ConstantAnyID:          put(cast<ConstantAny>(V),nstd); break;
+    case ConstantBooleanID:      put(cast<ConstantBoolean>(V),nstd); break;
+    case ConstantCharacterID:    put(cast<ConstantCharacter>(V),nstd); break;
+    case ConstantEnumeratorID:   put(cast<ConstantEnumerator>(V),nstd); break;
+    case ConstantOctetID:        put(cast<ConstantOctet>(V),nstd); break;
+    case ConstantIntegerID:      put(cast<ConstantInteger>(V),nstd); break;
+    case ConstantRealID:         put(cast<ConstantReal>(V),nstd); break;
+    case ConstantStringID:       put(cast<ConstantString>(V),nstd); break;
+    case ConstantPointerID:      put(cast<ConstantPointer>(V),nstd); break;
+    case ConstantArrayID:        put(cast<ConstantArray>(V),nstd); break;
+    case ConstantVectorID:       put(cast<ConstantVector>(V),nstd); break;
+    case ConstantStructureID:    put(cast<ConstantStructure>(V),nstd); break;
+    case ConstantContinuationID: put(cast<ConstantContinuation>(V),nstd); break;
+    default:
+      hlvmAssert(!"Invalid ConstantValue kind");
+  }
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(Variable* v)
+XMLWriterImpl::WriterPass::put(const Variable* v)
 {
   startElement("variable");
   writeAttribute("id",v->getName());
@@ -503,7 +573,7 @@
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(Function* f)
+XMLWriterImpl::WriterPass::put(const Function* f)
 {
   startElement("function");
   writeAttribute("id",f->getName());
@@ -513,7 +583,7 @@
 }
 
 template<> void 
-XMLWriterImpl::WriterPass::put(Program* p)
+XMLWriterImpl::WriterPass::put(const Program* p)
 {
   startElement("program");
   writeAttribute("id",p->getName());
@@ -521,7 +591,7 @@
 }
 
 template<> void 
-XMLWriterImpl::WriterPass::put(Block* b)
+XMLWriterImpl::WriterPass::put(const Block* b)
 {
   startElement("block");
   if (!b->getLabel().empty())
@@ -530,7 +600,7 @@
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(AutoVarOp* av)
+XMLWriterImpl::WriterPass::put(const AutoVarOp* av)
 {
   startElement("autovar");
   writeAttribute("id",av->getName());
@@ -543,280 +613,280 @@
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(NegateOp* op)
+XMLWriterImpl::WriterPass::put(const NegateOp* op)
 {
   startElement("neg");
   putDoc(op);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(ComplementOp* op)
+XMLWriterImpl::WriterPass::put(const ComplementOp* op)
 {
   startElement("cmpl");
   putDoc(op);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(PreIncrOp* op)
+XMLWriterImpl::WriterPass::put(const PreIncrOp* op)
 {
   startElement("preinc");
   putDoc(op);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(PreDecrOp* op)
+XMLWriterImpl::WriterPass::put(const PreDecrOp* op)
 {
   startElement("predec");
   putDoc(op);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(PostIncrOp* op)
+XMLWriterImpl::WriterPass::put(const PostIncrOp* op)
 {
   startElement("postinc");
   putDoc(op);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(PostDecrOp* op)
+XMLWriterImpl::WriterPass::put(const PostDecrOp* op)
 {
   startElement("postdec");
   putDoc(op);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(AddOp* op)
+XMLWriterImpl::WriterPass::put(const AddOp* op)
 {
   startElement("add");
   putDoc(op);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(SubtractOp* op)
+XMLWriterImpl::WriterPass::put(const SubtractOp* op)
 {
   startElement("sub");
   putDoc(op);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(MultiplyOp* op)
+XMLWriterImpl::WriterPass::put(const MultiplyOp* op)
 {
   startElement("mul");
   putDoc(op);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(DivideOp* op)
+XMLWriterImpl::WriterPass::put(const DivideOp* op)
 {
   startElement("div");
   putDoc(op);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(ModuloOp* op)
+XMLWriterImpl::WriterPass::put(const ModuloOp* op)
 {
   startElement("mod");
   putDoc(op);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(BAndOp* op)
+XMLWriterImpl::WriterPass::put(const BAndOp* op)
 {
   startElement("band");
   putDoc(op);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(BOrOp* op)
+XMLWriterImpl::WriterPass::put(const BOrOp* op)
 {
   startElement("bor");
   putDoc(op);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(BXorOp* op)
+XMLWriterImpl::WriterPass::put(const BXorOp* op)
 {
   startElement("bxor");
   putDoc(op);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(BNorOp* op)
+XMLWriterImpl::WriterPass::put(const BNorOp* op)
 {
   startElement("bnor");
   putDoc(op);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(NotOp* op)
+XMLWriterImpl::WriterPass::put(const NotOp* op)
 {
   startElement("not");
   putDoc(op);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(AndOp* op)
+XMLWriterImpl::WriterPass::put(const AndOp* op)
 {
   startElement("and");
   putDoc(op);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(OrOp* op)
+XMLWriterImpl::WriterPass::put(const OrOp* op)
 {
   startElement("or");
   putDoc(op);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(XorOp* op)
+XMLWriterImpl::WriterPass::put(const XorOp* op)
 {
   startElement("xor");
   putDoc(op);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(NorOp* op)
+XMLWriterImpl::WriterPass::put(const NorOp* op)
 {
   startElement("nor");
   putDoc(op);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(EqualityOp* op)
+XMLWriterImpl::WriterPass::put(const EqualityOp* op)
 {
   startElement("eq");
   putDoc(op);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(InequalityOp* op)
+XMLWriterImpl::WriterPass::put(const InequalityOp* op)
 {
   startElement("ne");
   putDoc(op);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(LessThanOp* op)
+XMLWriterImpl::WriterPass::put(const LessThanOp* op)
 {
   startElement("lt");
   putDoc(op);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(GreaterThanOp* op)
+XMLWriterImpl::WriterPass::put(const GreaterThanOp* op)
 {
   startElement("gt");
   putDoc(op);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(LessEqualOp* op)
+XMLWriterImpl::WriterPass::put(const LessEqualOp* op)
 {
   startElement("le");
   putDoc(op);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(GreaterEqualOp* op)
+XMLWriterImpl::WriterPass::put(const GreaterEqualOp* op)
 {
   startElement("ge");
   putDoc(op);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(SelectOp* op)
+XMLWriterImpl::WriterPass::put(const SelectOp* op)
 {
   startElement("select");
   putDoc(op);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(SwitchOp* op) 
+XMLWriterImpl::WriterPass::put(const SwitchOp* op) 
 {
   startElement("switch");
   putDoc(op);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(WhileOp* op) 
+XMLWriterImpl::WriterPass::put(const WhileOp* op) 
 {
   startElement("while");
   putDoc(op);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(UnlessOp* op) 
+XMLWriterImpl::WriterPass::put(const UnlessOp* op) 
 {
   startElement("unless");
   putDoc(op);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(UntilOp* op) 
+XMLWriterImpl::WriterPass::put(const UntilOp* op) 
 {
   startElement("until");
   putDoc(op);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(LoopOp* op) 
+XMLWriterImpl::WriterPass::put(const LoopOp* op) 
 {
   startElement("loop");
   putDoc(op);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(BreakOp* op)
+XMLWriterImpl::WriterPass::put(const BreakOp* op)
 {
   startElement("break");
   putDoc(op);
 }
 
 template<> void
-XMLWriterImpl::WriterPass::put(ContinueOp* op)
+XMLWriterImpl::WriterPass::put(const ContinueOp* op)
 {
   startElement("continue");
   putDoc(op);
 }
 
 template<> void 
-XMLWriterImpl::WriterPass::put(ReturnOp* r)
+XMLWriterImpl::WriterPass::put(const ReturnOp* r)
 {
   startElement("ret");
   putDoc(r);
 }
 
 template<> void 
-XMLWriterImpl::WriterPass::put(ResultOp* r)
+XMLWriterImpl::WriterPass::put(const ResultOp* r)
 {
   startElement("result");
   putDoc(r);
 }
 
 template<> void 
-XMLWriterImpl::WriterPass::put(CallOp* r)
+XMLWriterImpl::WriterPass::put(const CallOp* r)
 {
   startElement("call");
   putDoc(r);
 }
 
 template<> void 
-XMLWriterImpl::WriterPass::put(StoreOp* r)
+XMLWriterImpl::WriterPass::put(const StoreOp* r)
 {
   startElement("store");
   putDoc(r);
 }
 
 template<> void 
-XMLWriterImpl::WriterPass::put(LoadOp* r)
+XMLWriterImpl::WriterPass::put(const LoadOp* r)
 {
   startElement("load");
   putDoc(r);
 }
 
 template<> void 
-XMLWriterImpl::WriterPass::put(ReferenceOp* r)
+XMLWriterImpl::WriterPass::put(const ReferenceOp* r)
 {
   startElement("ref");
   const Value* ref = r->getReferent();
@@ -834,28 +904,28 @@
 }
 
 template<> void 
-XMLWriterImpl::WriterPass::put(OpenOp* r)
+XMLWriterImpl::WriterPass::put(const OpenOp* r)
 {
   startElement("open");
   putDoc(r);
 }
 
 template<> void 
-XMLWriterImpl::WriterPass::put(WriteOp* r)
+XMLWriterImpl::WriterPass::put(const WriteOp* r)
 {
   startElement("write");
   putDoc(r);
 }
 
 template<> void 
-XMLWriterImpl::WriterPass::put(CloseOp* r)
+XMLWriterImpl::WriterPass::put(const CloseOp* r)
 {
   startElement("close");
   putDoc(r);
 }
 
 template<> void 
-XMLWriterImpl::WriterPass::put(Bundle* b)
+XMLWriterImpl::WriterPass::put(const Bundle* b)
 {
   startElement("bundle");
   writeAttribute("id",b->getName());
@@ -884,19 +954,20 @@
       case VectorTypeID:           put(cast<VectorType>(n)); break;
       case StructureTypeID:        put(cast<StructureType>(n)); break;
       case SignatureTypeID:        put(cast<SignatureType>(n)); break;
-      case ConstantAnyID:          put(cast<ConstantAny>(n)); break;
-      case ConstantBooleanID:      put(cast<ConstantBoolean>(n)); break;
-      case ConstantCharacterID:    put(cast<ConstantCharacter>(n)); break;
-      case ConstantEnumeratorID:   put(cast<ConstantEnumerator>(n)); break;
-      case ConstantOctetID:        put(cast<ConstantOctet>(n)); break;
-      case ConstantIntegerID:      put(cast<ConstantInteger>(n)); break;
-      case ConstantRealID:         put(cast<ConstantReal>(n)); break;
-      case ConstantStringID:       put(cast<ConstantString>(n)); break;
-      case ConstantPointerID:      put(cast<ConstantPointer>(n)); break;
-      case ConstantArrayID:        put(cast<ConstantArray>(n)); break;
-      case ConstantVectorID:       put(cast<ConstantVector>(n)); break;
-      case ConstantStructureID:    put(cast<ConstantStructure>(n)); break;
-      case ConstantContinuationID: put(cast<ConstantContinuation>(n)); break;
+      case ConstantAnyID:          
+      case ConstantBooleanID:      
+      case ConstantCharacterID:    
+      case ConstantEnumeratorID:   
+      case ConstantOctetID:        
+      case ConstantIntegerID:      
+      case ConstantRealID:         
+      case ConstantStringID:       
+      case ConstantPointerID:      
+      case ConstantArrayID:        
+      case ConstantVectorID:       
+      case ConstantStructureID:    
+      case ConstantContinuationID: 
+        putConstantValue(cast<ConstantValue>(n),false); break;
       case VariableID:             put(cast<Variable>(n)); break;
       case FunctionID:             put(cast<Function>(n)); break;
       case ProgramID:              put(cast<Program>(n)); break;

Modified: hlvm/trunk/test/xml2xml/array.hlx
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/xml2xml/array.hlx?rev=38345&r1=38344&r2=38345&view=diff

==============================================================================
--- hlvm/trunk/test/xml2xml/array.hlx (original)
+++ hlvm/trunk/test/xml2xml/array.hlx Sat Jul  7 19:02:32 2007
@@ -2,8 +2,6 @@
 <hlvm xmlns="http://hlvm.org/src/hlvm/Reader/XML/HLVM.rng" pubid="name">
   <bundle id="bundle">
     <array id="anArray" of="someType" length="128"/>
-    <atom id="someType">
-      <intrinsic is="any"/>
-    </atom>
+    <intrinsic id="someType" is="any"/>
   </bundle>
 </hlvm>

Modified: hlvm/trunk/test/xml2xml/doc.hlx
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/xml2xml/doc.hlx?rev=38345&r1=38344&r2=38345&view=diff

==============================================================================
--- hlvm/trunk/test/xml2xml/doc.hlx (original)
+++ hlvm/trunk/test/xml2xml/doc.hlx Sat Jul  7 19:02:32 2007
@@ -2,82 +2,63 @@
 <hlvm xmlns="http://hlvm.org/src/hlvm/Reader/XML/HLVM.rng" pubid="name">
   <bundle id="bundle">
     <doc><p>This is a documentation node for a bundle element</p></doc>
-    <atom id="1">
+    <intrinsic id="1" is="any">
       <doc>Any can hold anything. It provides the dynamic typing</doc>
-      <intrinsic is="any"/>
-    </atom>
-    <atom id="10">
+    </intrinsic>
+    <intrinsic id="10" is="s64">
       <doc>Signed 64 bit integer</doc>
-      <intrinsic is="s64"/>
-    </atom>
-    <atom id="11">
+    </intrinsic>
+    <intrinsic id="11" is="s32">
       <doc>Signed 32 bit integer</doc>
-      <intrinsic is="s32"/>
-    </atom>
-    <atom id="12">
+    </intrinsic>
+    <intrinsic id="12" is="s16">
       <doc>Signed 16 bit integer</doc>
-      <intrinsic is="s16"/>
-    </atom>
-    <atom id="13">
+    </intrinsic>
+    <intrinsic id="13" is="s8">
       <doc>Signed 8 bit integer</doc>
-      <intrinsic is="s8"/>
-    </atom>
-    <atom id="14">
+    </intrinsic>
+    <intrinsic id="14" is="octet">
       <doc>An 8-bit non-numerical quantity</doc>
-      <intrinsic is="octet"/>
-    </atom>
-    <atom id="15">
+    </intrinsic>
+    <intrinsic id="15" is="u128">
       <doc>Unsigned 128 bit integer</doc>
-      <intrinsic is="u128"/>
-    </atom>
-    <atom id="16">
+    </intrinsic>
+    <intrinsic id="16" is="u64">
       <doc>Unsigned 64 bit integer</doc>
-      <intrinsic is="u64"/>
-    </atom>
-    <atom id="17">
+    </intrinsic>
+    <intrinsic id="17" is="u32">
       <doc>Unsigned 32 bit integer</doc>
-      <intrinsic is="u32"/>
-    </atom>
-    <atom id="18">
+    </intrinsic>
+    <intrinsic id="18" is="u16">
       <doc>Unsigned 16 bit integer</doc>
-      <intrinsic is="u16"/>
-    </atom>
-    <atom id="19">
+    </intrinsic>
+    <intrinsic id="19" is="u8">
       <doc>Unsigned 8 bit integer</doc>
-      <intrinsic is="u8"/>
-    </atom>
-    <atom id="2">
+    </intrinsic>
+    <intrinsic id="2" is="bool">
       <doc>Obviously this is a boolean</doc>
-      <intrinsic is="bool"/>
-    </atom>
-    <atom id="3">
+    </intrinsic>
+    <intrinsic id="3" is="char">
       <doc>UTF-16 character</doc>
-      <intrinsic is="char"/>
-    </atom>
-    <atom id="4">
+    </intrinsic>
+    <intrinsic id="4" is="f128">
       <doc>IEEE Quad Floating Point (128 bits)</doc>
-      <intrinsic is="f128"/>
-    </atom>
-    <atom id="5">
+    </intrinsic>
+    <intrinsic id="5" is="f80">
       <doc>IEEE Extended Double Floating Point (80 bits)</doc>
-      <intrinsic is="f80"/>
-    </atom>
-    <atom id="6">
+    </intrinsic>
+    <intrinsic id="6" is="f64">
       <doc>IEEE Double Floating Point (64 bits)</doc>
-      <intrinsic is="f64"/>
-    </atom>
-    <atom id="7">
+    </intrinsic>
+    <intrinsic id="7" is="f44">
       <doc>IEEE Extended Single Floating Point (43 bits)</doc>
-      <intrinsic is="f44"/>
-    </atom>
-    <atom id="8">
+    </intrinsic>
+    <intrinsic id="8" is="f32">
       <doc>IEEE Single Floating Point (32 bits)</doc>
-      <intrinsic is="f32"/>
-    </atom>
-    <atom id="9">
+    </intrinsic>
+    <intrinsic id="9" is="s128">
       <doc>Signed 128 bit integer</doc>
-      <intrinsic is="s128"/>
-    </atom>
+    </intrinsic>
     <pointer id="aPointerType" to="someType">
       <doc>A Pointer Type</doc>
     </pointer>
@@ -103,10 +84,9 @@
         <doc><i>Doc for "arg2"</i></doc>
       </arg>
     </signature>
-    <atom id="someType">
+    <intrinsic id="someType" is="any">
       <doc><p>Atom Doc</p></doc>
-      <intrinsic is="any"/>
-    </atom>
+    </intrinsic>
     <structure id="struct2">
       <doc>This is structure doc</doc>
       <field id="field1" type="someType">

Modified: hlvm/trunk/test/xml2xml/intrinsics.hlx
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/xml2xml/intrinsics.hlx?rev=38345&r1=38344&r2=38345&view=diff

==============================================================================
--- hlvm/trunk/test/xml2xml/intrinsics.hlx (original)
+++ hlvm/trunk/test/xml2xml/intrinsics.hlx Sat Jul  7 19:02:32 2007
@@ -1,62 +1,24 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <hlvm xmlns="http://hlvm.org/src/hlvm/Reader/XML/HLVM.rng" pubid="name">
   <bundle id="bundle">
-    <atom id="1">
-      <intrinsic is="any"/>
-    </atom>
-    <atom id="10">
-      <intrinsic is="s64"/>
-    </atom>
-    <atom id="11">
-      <intrinsic is="s32"/>
-    </atom>
-    <atom id="12">
-      <intrinsic is="s16"/>
-    </atom>
-    <atom id="13">
-      <intrinsic is="s8"/>
-    </atom>
-    <atom id="14">
-      <intrinsic is="octet"/>
-    </atom>
-    <atom id="15">
-      <intrinsic is="u128"/>
-    </atom>
-    <atom id="16">
-      <intrinsic is="u64"/>
-    </atom>
-    <atom id="17">
-      <intrinsic is="u32"/>
-    </atom>
-    <atom id="18">
-      <intrinsic is="u16"/>
-    </atom>
-    <atom id="19">
-      <intrinsic is="u8"/>
-    </atom>
-    <atom id="2">
-      <intrinsic is="bool"/>
-    </atom>
-    <atom id="3">
-      <intrinsic is="char"/>
-    </atom>
-    <atom id="4">
-      <intrinsic is="f128"/>
-    </atom>
-    <atom id="5">
-      <intrinsic is="f80"/>
-    </atom>
-    <atom id="6">
-      <intrinsic is="f64"/>
-    </atom>
-    <atom id="7">
-      <intrinsic is="f44"/>
-    </atom>
-    <atom id="8">
-      <intrinsic is="f32"/>
-    </atom>
-    <atom id="9">
-      <intrinsic is="s128"/>
-    </atom>
+    <intrinsic id="1" is="any"/>
+    <intrinsic id="10" is="s64"/>
+    <intrinsic id="11" is="s32"/>
+    <intrinsic id="12" is="s16"/>
+    <intrinsic id="13" is="s8"/>
+    <intrinsic id="14" is="octet"/>
+    <intrinsic id="15" is="u128"/>
+    <intrinsic id="16" is="u64"/>
+    <intrinsic id="17" is="u32"/>
+    <intrinsic id="18" is="u16"/>
+    <intrinsic id="19" is="u8"/>
+    <intrinsic id="2" is="bool"/>
+    <intrinsic id="3" is="char"/>
+    <intrinsic id="4" is="f128"/>
+    <intrinsic id="5" is="f80"/>
+    <intrinsic id="6" is="f64"/>
+    <intrinsic id="7" is="f44"/>
+    <intrinsic id="8" is="f32"/>
+    <intrinsic id="9" is="s128"/>
   </bundle>
 </hlvm>

Modified: hlvm/trunk/test/xml2xml/pointer.hlx
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/xml2xml/pointer.hlx?rev=38345&r1=38344&r2=38345&view=diff

==============================================================================
--- hlvm/trunk/test/xml2xml/pointer.hlx (original)
+++ hlvm/trunk/test/xml2xml/pointer.hlx Sat Jul  7 19:02:32 2007
@@ -2,8 +2,6 @@
 <hlvm xmlns="http://hlvm.org/src/hlvm/Reader/XML/HLVM.rng" pubid="name">
   <bundle id="bundle">
     <pointer id="aPointerType" to="someType"/>
-    <atom id="someType">
-      <intrinsic is="any"/>
-    </atom>
+    <intrinsic id="someType" is="any"/>
   </bundle>
 </hlvm>

Modified: hlvm/trunk/test/xml2xml/resolve.hlx
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/xml2xml/resolve.hlx?rev=38345&r1=38344&r2=38345&view=diff

==============================================================================
--- hlvm/trunk/test/xml2xml/resolve.hlx (original)
+++ hlvm/trunk/test/xml2xml/resolve.hlx Sat Jul  7 19:02:32 2007
@@ -2,9 +2,7 @@
 <hlvm xmlns="http://hlvm.org/src/hlvm/Reader/XML/HLVM.rng" pubid="name">
   <bundle id="bundle">
     <pointer id="PtrToSomeType" to="SomeType"/>
-    <atom id="SomeType">
-      <intrinsic is="any"/>
-    </atom>
+    <intrinsic id="SomeType" is="any"/>
     <structure id="struct1">
       <field id="field1" type="SomeType"/>
     </structure>

Modified: hlvm/trunk/test/xml2xml/signature.hlx
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/xml2xml/signature.hlx?rev=38345&r1=38344&r2=38345&view=diff

==============================================================================
--- hlvm/trunk/test/xml2xml/signature.hlx (original)
+++ hlvm/trunk/test/xml2xml/signature.hlx Sat Jul  7 19:02:32 2007
@@ -4,12 +4,10 @@
     <signature id="sig1" result="someType">
       <arg id="arg1" type="someType"/>
     </signature>
-    <atom id="someType">
-      <intrinsic is="any"/>
-    </atom>
-    <signature id="struct2" result="someType" varargs="true">
+    <signature id="sig2" result="someType" varargs="true">
       <arg id="arg1" type="someType"/>
       <arg id="arg1" type="someType"/>
     </signature>
+    <intrinsic id="someType" is="any"/>
   </bundle>
 </hlvm>

Modified: hlvm/trunk/test/xml2xml/structure.hlx
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/xml2xml/structure.hlx?rev=38345&r1=38344&r2=38345&view=diff

==============================================================================
--- hlvm/trunk/test/xml2xml/structure.hlx (original)
+++ hlvm/trunk/test/xml2xml/structure.hlx Sat Jul  7 19:02:32 2007
@@ -1,9 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <hlvm xmlns="http://hlvm.org/src/hlvm/Reader/XML/HLVM.rng" pubid="name">
   <bundle id="bundle">
-    <atom id="someType">
-      <intrinsic is="any"/>
-    </atom>
+    <intrinsic id="someType" is="any"/>
     <structure id="struct1">
       <field id="field1" type="someType"/>
     </structure>

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

==============================================================================
--- hlvm/trunk/tools/hlvm-gentestcase/Generate.cpp (original)
+++ hlvm/trunk/tools/hlvm-gentestcase/Generate.cpp Sat Jul  7 19:02:32 2007
@@ -53,6 +53,10 @@
       cl::value_desc("num"));
 
 cl::opt<unsigned>
+  TypeComplexity("type-complexity", cl::desc("Specify complexity of types"),
+      cl::value_desc("0-20"), cl::init(10));
+
+cl::opt<unsigned>
   Seed("seed", cl::desc("Specify random number generator seed"),
       cl::value_desc("num"));
 
@@ -68,6 +72,8 @@
 typedef std::vector<hlvm::Value*> ValueList;
 typedef std::map<const hlvm::Type*,ValueList> TypeValueMap;
 TypeValueMap values;
+typedef std::vector<hlvm::Type*> TypeList;
+TypeList types;
 
 inline hlvm::Locator* 
 getLocator()
@@ -83,7 +89,7 @@
   else if (low > high)
     return int64_t(random()) % (low-high) + high;
   else
-    return 1;
+    return low;
 }
 
 inline
@@ -94,7 +100,7 @@
   else if (low > high)
     return uint64_t(random()) % (low-high) + high;
   else
-    return 1;
+    return low;
 }
 
 hlvm::Type*
@@ -112,12 +118,16 @@
     case UInt16TypeID:
     case UInt32TypeID:
     case UInt64TypeID:
+      return ast->getPrimitiveType(id);
     case UInt128TypeID:
+      return ast->getPrimitiveType(UInt64TypeID);
     case SInt8TypeID:
     case SInt16TypeID:
     case SInt32TypeID:
     case SInt64TypeID:
+      return ast->getPrimitiveType(id);
     case SInt128TypeID:
+      return ast->getPrimitiveType(UInt64TypeID);
     case Float32TypeID:
     case Float44TypeID:
     case Float64TypeID:
@@ -148,8 +158,8 @@
     {
       Locator* loc = getLocator();
       std::string name = "range_" + utostr(line);
-      uint64_t limit = randRange(0,5000000000LL);
-      result = ast->new_RangeType(name,-int64_t(limit),int64_t(limit),loc);
+      int64_t limit = randRange(0LL,5000000000LL);
+      result = ast->new_RangeType(name,-limit,limit,loc);
       break;
     }
     case EnumerationTypeID:
@@ -179,7 +189,7 @@
       Locator* loc = getLocator();
       std::string name = "array_" + utostr(line);
       result = ast->new_ArrayType(name,
-          genTypeLimited(limit),randRange(1,Complexity),loc);
+          genTypeLimited(limit),randRange(1,Size),loc);
       break;
     }
     case VectorTypeID:
@@ -187,7 +197,7 @@
       Locator* loc = getLocator();
       std::string name = "vector_" + utostr(line);
       result = ast->new_VectorType(
-          name,genTypeLimited(limit),randRange(1,Complexity),loc);
+          name,genTypeLimited(limit),randRange(1,Size),loc);
       break;
     }
     case OpaqueTypeID:
@@ -198,7 +208,8 @@
       Locator* loc = getLocator();
       std::string name = "struct_" + utostr(line);
       StructureType* S = ast->new_StructureType(name,loc);
-      for (unsigned i = 0; i < Complexity; ++i) {
+      unsigned numFields = randRange(1,Size,true);
+      for (unsigned i = 0; i < numFields; ++i) {
         Field* fld = ast->new_Field(name+"_"+utostr(i),
             genTypeLimited(limit),getLocator());
         S->addField(fld);
@@ -214,13 +225,19 @@
   return result;
 }
 
-hlvm::Type*
+Type*
 genType()
 {
-  return genTypeLimited(Complexity);
+  bool shouldGenNewType = randRange(0,20) < TypeComplexity;
+  if (types.empty() || shouldGenNewType) {
+    Type* Ty = genTypeLimited(Complexity);
+    types.push_back(Ty);
+    return Ty;
+  }
+  return types[ randRange(0,types.size()-1) ];
 }
 
-hlvm::Value*
+Value*
 genValue(const hlvm::Type* Ty, bool is_constant = false)
 {
   if (!is_constant && randRange(0,Complexity) < Complexity/2) {
@@ -228,7 +245,10 @@
     TypeValueMap::iterator VI = values.find(Ty);
     if (VI != values.end()) {
       ValueList& VL = VI->second;
-      return VL[ randRange(0,VL.size()-1) ];
+      unsigned index = randRange(0,VL.size()-1,true);
+      Value* result = VL[index];
+      hlvmAssert(result->getType() == Ty);
+      return result;
     }
   }
 
@@ -245,8 +265,10 @@
     }
     case CharacterTypeID:
     {
+      std::string val;
+      val += char(randRange(35,126));
       C = ast->new_ConstantCharacter(
-        std::string("cchar_") + utostr(line), "a", loc);
+        std::string("cchar_") + utostr(line), val, loc);
       break;
     }
     case OctetTypeID:
@@ -459,6 +481,7 @@
   if (is_constant || (randRange(0,Complexity*Size) < (Complexity*Size)/2))
     result = C;
   else {
+    C->setParent(bundle);
     Variable* var = ast->new_Variable(C->getName()+"_var",C->getType(),loc);
     var->setIsConstant(false);
     var->setInitializer(C);
@@ -541,7 +564,7 @@
   ret->setParent(B);
   
   // Install the function in the value map
-  values[resultType].push_back(F);
+  values[sig].push_back(F);
 
   return F;
 }

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

==============================================================================
--- hlvm/trunk/tools/hlvm-gentestcase/hlvm-gentestcase.cpp (original)
+++ hlvm/trunk/tools/hlvm-gentestcase/hlvm-gentestcase.cpp Sat Jul  7 19:02:32 2007
@@ -49,6 +49,10 @@
 BundleName("bundle", cl::desc("Specify bundle name"),
     cl::value_desc("name"));
 
+static cl::opt<bool>
+NoValidate("no-validate",cl::desc("Disable validation of generated code"),
+    cl::init(false));
+
 extern AST* GenerateTestCase(const std::string& id, const std::string& bname);
 
 int main(int argc, char**argv) 
@@ -82,9 +86,10 @@
     }
 
     AST* tree = GenerateTestCase(URL,BundleName);
-    if (!validate(tree)) {
-      std::cerr << argv[0] << ": Generated test case did not validate.\n";
-      return 1;
+    if (!NoValidate) {
+      if (!validate(tree)) {
+        std::cerr << argv[0] << ": Generated test case did not validate.\n";
+      }
     }
     XMLWriter* wrtr = XMLWriter::create(OutputFilename.c_str());
     wrtr->write(tree);





More information about the llvm-commits mailing list