[llvm-commits] [hlvm] r38365 - in /hlvm/trunk: build/ docs/ hlvm/AST/ hlvm/CodeGen/ hlvm/Pass/ hlvm/Reader/ hlvm/Writer/ test/invalid/ test/return0/ test/xml2xml/ tools/hlvm-config/ tools/hlvm-gentestcase/

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


Author: reid
Date: Sat Jul  7 19:02:42 2007
New Revision: 38365

URL: http://llvm.org/viewvc/llvm-project?rev=38365&view=rev
Log:
Major rewrite of type resolution: 
1. Move all type resolution code to Bundle from AST.
2. Remove non-class related NodeIDs and replace with Intrinsics in Bundle
3. Eliminate the Octet type, this is just an intrinsic for unsigned 8-bit int.
4. Fix type resolution in the XMLReader and Bundle for all types.
5. Make types print in declaration order as well as constants.
6. Fix the implementation of documentation on all nodes. Enhance the test.
7. Eliminate the "intrinsic" element from the XML scheme and just use an 
   element that names the type directly.
8. Implement constant values for strings as "str" not "string".
And probably many other small changes.

Added:
    hlvm/trunk/test/invalid/rename.hlx
Modified:
    hlvm/trunk/build/filterbuilders.py
    hlvm/trunk/docs/OpenProjects.html
    hlvm/trunk/hlvm/AST/AST.cpp
    hlvm/trunk/hlvm/AST/AST.h
    hlvm/trunk/hlvm/AST/Bundle.cpp
    hlvm/trunk/hlvm/AST/Bundle.h
    hlvm/trunk/hlvm/AST/Constants.cpp
    hlvm/trunk/hlvm/AST/Constants.h
    hlvm/trunk/hlvm/AST/ContainerType.cpp
    hlvm/trunk/hlvm/AST/ContainerType.h
    hlvm/trunk/hlvm/AST/Linkables.cpp
    hlvm/trunk/hlvm/AST/Linkables.h
    hlvm/trunk/hlvm/AST/Node.cpp
    hlvm/trunk/hlvm/AST/Node.h
    hlvm/trunk/hlvm/AST/Operator.cpp
    hlvm/trunk/hlvm/AST/Operator.h
    hlvm/trunk/hlvm/AST/SConscript
    hlvm/trunk/hlvm/AST/SymbolTable.cpp
    hlvm/trunk/hlvm/AST/SymbolTable.h
    hlvm/trunk/hlvm/AST/Type.cpp
    hlvm/trunk/hlvm/AST/Type.h
    hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp
    hlvm/trunk/hlvm/Pass/Pass.cpp
    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/return0/helloworld.hlx
    hlvm/trunk/test/xml2xml/array.hlx
    hlvm/trunk/test/xml2xml/bundle.hlx
    hlvm/trunk/test/xml2xml/doc.hlx
    hlvm/trunk/test/xml2xml/helloworld.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-config/hlvm-config.cpp
    hlvm/trunk/tools/hlvm-gentestcase/Generate.cpp

Modified: hlvm/trunk/build/filterbuilders.py
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/build/filterbuilders.py?rev=38365&r1=38364&r2=38365&view=diff

==============================================================================
--- hlvm/trunk/build/filterbuilders.py (original)
+++ hlvm/trunk/build/filterbuilders.py Sat Jul  7 19:02:42 2007
@@ -49,6 +49,7 @@
   elemPat = re.compile('<element[^>]*name[ ]*=[ ]*"([^"]*)"')
   attrPat = re.compile('<attribute[^>]*name[ ]*=[ ]*"([^"]*)"')
   valuPat = re.compile('<value>\s*([^<\s]*)')
+  subsPat = re.compile('[^A-Za-z0-9_]');
   tokens = []
   for line in fileinput.input(fname):
     tokens += elemPat.findall(line)
@@ -56,7 +57,8 @@
     tokens += valuPat.findall(line)
   dict = {}
   for tok in tokens:
-    dict[tok] = 1
+    clean_tok = subsPat.sub('_',tok);
+    dict[clean_tok] = 1
   result = list(dict.keys())
   result.sort()
   return result

Modified: hlvm/trunk/docs/OpenProjects.html
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/docs/OpenProjects.html?rev=38365&r1=38364&r2=38365&view=diff

==============================================================================
--- hlvm/trunk/docs/OpenProjects.html (original)
+++ hlvm/trunk/docs/OpenProjects.html Sat Jul  7 19:02:42 2007
@@ -51,6 +51,17 @@
   </ol>
 </div>
 
+<h2><a name="cleanup">Cleanup Projects</a></h2>
+<div class="text">
+  <p>Projects in the list below are things that are missing or need to be
+  fixed.</p>
+  <ol>
+    <li><em>Enumerator Documentation</em>. Right now enumerators are simple
+    string values in the EnumerationType. This prevents documentation from being
+    associated with the Enumerators. This needs to be fixed so that
+    documentation can be associated with the enumerators.</li>
+  </ol>
+</div>
 <h2><a name="doc">Documentation Projects</a></h2>
 <div class="text">
   <p>Projects in the list below are related to working on the projects

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

==============================================================================
--- hlvm/trunk/hlvm/AST/AST.cpp (original)
+++ hlvm/trunk/hlvm/AST/AST.cpp Sat Jul  7 19:02:42 2007
@@ -48,77 +48,21 @@
 
 using namespace hlvm;
 
-namespace 
+namespace hlvm 
 {
 
-class ASTImpl : public AST
+AST::AST() 
+  : Node(TreeTopID), sysid(), pubid(), bundles(), pool(0)
 {
-  public:
-    ASTImpl()
-      : types(), unresolvedTypes(), 
-        AnyTypeSingleton(0), StringTypeSingleton(0),
-        BooleanSingleton(), CharacterSingleton(0), 
-        OctetSingleton(0), UInt8Singleton(0), UInt16Singleton(0), 
-        UInt32Singleton(0), UInt64Singleton(0), UInt128Singleton(0),
-        SInt8Singleton(0), SInt16Singleton(0), SInt32Singleton(0),
-        SInt64Singleton(0), SInt128Singleton(0),  Float32Singleton(0),
-        Float44Singleton(0), Float64Singleton(0), Float80Singleton(0),
-        Float128Singleton(0), TextTypeSingleton(0), StreamTypeSingleton(0),
-        BufferTypeSingleton(0), ProgramTypeSingleton(0),
-        BooleanTrueSingleton(0), BooleanFalseSingleton(0)
-      {
-        pool = Pool::create("ASTPool",0,false,1024,4,0);
-      }
-    ~ASTImpl();
-
-  protected:
-    virtual void insertChild(Node* child);
-    virtual void removeChild(Node* child);
-
-  private:
-    // Pool pool;
-    SymbolTable<Type>    types;
-    SymbolTable<Type>    unresolvedTypes;
-    AnyType*       AnyTypeSingleton;
-    StringType*    StringTypeSingleton;
-    BooleanType*   BooleanSingleton;
-    CharacterType* CharacterSingleton;
-    OctetType*     OctetSingleton;
-    IntegerType*   UInt8Singleton;
-    IntegerType*   UInt16Singleton;
-    IntegerType*   UInt32Singleton;
-    IntegerType*   UInt64Singleton;
-    IntegerType*   UInt128Singleton;
-    IntegerType*   SInt8Singleton;
-    IntegerType*   SInt16Singleton;
-    IntegerType*   SInt32Singleton;
-    IntegerType*   SInt64Singleton;
-    IntegerType*   SInt128Singleton;  
-    RealType*      Float32Singleton;
-    RealType*      Float44Singleton;
-    RealType*      Float64Singleton;
-    RealType*      Float80Singleton;
-    RealType*      Float128Singleton;
-    TextType*      TextTypeSingleton;
-    StreamType*    StreamTypeSingleton;
-    BufferType*    BufferTypeSingleton;
-    SignatureType* ProgramTypeSingleton;
-    ConstantBoolean* BooleanTrueSingleton;
-    ConstantBoolean* BooleanFalseSingleton;
-
-  public:
-    Type* resolveType(const std::string& name);
-    void addType(Type*);
-    virtual void setParent(Node* parent);
-    friend class AST;
-};
+  pool = Pool::create("ASTPool",0,false,1024,4,0);
+}
 
-ASTImpl::~ASTImpl()
+AST::~AST()
 {
 }
 
 void 
-ASTImpl::insertChild(Node* child)
+AST::insertChild(Node* child)
 {
   hlvmAssert(llvm::isa<Bundle>(child) && "Can't insert that here");
 #ifdef HLVM_ASSERT
@@ -129,108 +73,28 @@
 }
 
 void 
-ASTImpl::removeChild(Node* child)
+AST::removeChild(Node* child)
 {
   hlvmAssert(llvm::isa<Bundle>(child) && "Can't remove that here");
   //FIXME: bundles.erase(llvm::cast<Bundle>(child));
 }
 
-Type*
-ASTImpl::resolveType(const std::string& name)
-{
-  Node* n = types.lookup(name);
-  if (n)
-    return llvm::cast<Type>(n);
-  n = unresolvedTypes.lookup(name);
-  if (n)
-    return llvm::cast<OpaqueType>(n);
-  OpaqueType* ot = this->new_OpaqueType(name);
-  unresolvedTypes.insert(ot);
-  return ot;
-}
-
 void
-ASTImpl::addType(Type* ty)
+AST::setParent(Node* n)
 {
-  Node* n = unresolvedTypes.lookup(ty->getName());
-  if (n) {
-    OpaqueType* ot = llvm::cast<OpaqueType>(n);
-    // FIXME: Replace all uses of "ot" with "ty"
-    unresolvedTypes.erase(ot);
-  }
-  types.insert(ty);
+  hlvmAssert(!"Can't set parent of root node (AST)!");
 }
 
-void
-ASTImpl::setParent(Node* n)
-{
-  hlvmAssert(!"Can't set parent of root node (AST)");
-}
-
-}
-
-namespace hlvm 
-{
-
 AST* 
 AST::create()
 {
-  return new ASTImpl();
+  return new AST();
 }
 
 void
 AST::destroy(AST* ast)
 {
-  delete static_cast<ASTImpl*>(ast);
-}
-
-AST::~AST()
-{
-}
-
-Type* 
-AST::resolveType(const std::string& name)
-{
-  return static_cast<const ASTImpl*>(this)->resolveType(name);
-}
-
-SignatureType* 
-AST::getProgramType()
-{
-  ASTImpl* ast = const_cast<ASTImpl*>(static_cast<const ASTImpl*>(this));
-  if (!ast->ProgramTypeSingleton) {
-    ast->ProgramTypeSingleton = new SignatureType();
-    ast->ProgramTypeSingleton->setLocator(loc);
-    ast->ProgramTypeSingleton->setName("ProgramType");
-    Type* intType = ast->getPrimitiveType(SInt32TypeID);
-    ast->ProgramTypeSingleton->setResultType(intType);
-    Parameter* argc = new_Parameter("argc",intType);
-    ast->ProgramTypeSingleton->addParameter(argc);
-    const PointerType* argv_type = getPointerTo(getPointerTo(
-      ast->getPrimitiveType(StringTypeID)));
-    Parameter* argv = new_Parameter("argv",argv_type);
-    ast->ProgramTypeSingleton->addParameter(argv);
-  }
-  return ast->ProgramTypeSingleton;
-}
-
-PointerType* 
-AST::getPointerTo(const Type* Ty)
-{
-  hlvmAssert(Ty != 0);
-  ASTImpl* ast = const_cast<ASTImpl*>(static_cast<const ASTImpl*>(this));
-  std::string ptr_name = Ty->getName() + "*";
-  Node* n = ast->types.lookup(ptr_name);
-  if (n && llvm::isa<PointerType>(n))
-    return llvm::cast<PointerType>(n);
-
-  // Okay, type doesn't exist already, create it a new
-  PointerType* PT = new PointerType();
-  PT->setElementType(Ty);
-  PT->setName(ptr_name);
-  PT->setParent(Ty->getContainingBundle());
-  ast->types.insert(PT);
-  return PT;
+  delete ast;
 }
 
 URI* 
@@ -289,44 +153,48 @@
 IntegerType* 
 AST::new_IntegerType(
   const std::string& id, 
+  Bundle* bundle,
   uint16_t bits, 
   bool isSigned,
   const Locator* loc)
 {
-  IntegerType* result = new IntegerType(IntegerTypeID,bits,isSigned);
+  IntegerType* result = new IntegerType(bits,isSigned);
   result->setLocator(loc);
   result->setName(id);
-  static_cast<ASTImpl*>(this)->addType(result);
+  result->setParent(bundle);
   return result;
 }
 
 RangeType* 
-AST::new_RangeType(const std::string& id, int64_t min, int64_t max, const Locator* loc)
+AST::new_RangeType(
+  const std::string& id, 
+  Bundle* bundle,
+  int64_t min, int64_t max, const Locator* loc)
 {
-  RangeType* result = new RangeType();
+  RangeType* result = new RangeType(min,max);
   result->setLocator(loc);
   result->setName(id);
-  result->setMin(min);
-  result->setMax(max);
-  static_cast<ASTImpl*>(this)->addType(result);
+  result->setParent(bundle);
   return result;
 }
 
 EnumerationType* 
 AST::new_EnumerationType(
   const std::string& id,
+  Bundle* bundle,
   const Locator* loc)
 {
   EnumerationType* result = new EnumerationType();
   result->setLocator(loc);
   result->setName(id);
-  static_cast<ASTImpl*>(this)->addType(result);
+  result->setParent(bundle);
   return result;
 }
 
 RealType* 
 AST::new_RealType(
   const std::string& id,  
+  Bundle* bundle,
   uint32_t mantissa, 
   uint32_t exponent,
   const Locator* loc)
@@ -336,107 +204,122 @@
   result->setExponent(exponent);
   result->setLocator(loc);
   result->setName(id);
-  static_cast<ASTImpl*>(this)->addType(result);
+  result->setParent(bundle);
   return result;
 }
 
 AnyType* 
-AST::new_AnyType(const std::string& id, const Locator* loc)
+AST::new_AnyType(
+  const std::string& id, 
+  Bundle* bundle,
+  const Locator* loc)
 {
   AnyType* result = new AnyType();
   result->setLocator(loc);
   result->setName(id);
-  static_cast<ASTImpl*>(this)->addType(result);
+  result->setParent(bundle);
   return result;
 }
 
 StringType* 
-AST::new_StringType(const std::string& id, const Locator* loc)
+AST::new_StringType(
+  const std::string& id, 
+  Bundle* bundle,
+  const std::string& encoding,
+  const Locator* loc)
 {
-  StringType* result = new StringType();
+  StringType* result = new StringType(encoding);
   result->setLocator(loc);
   result->setName(id);
-  static_cast<ASTImpl*>(this)->addType(result);
+  result->setParent(bundle);
   return result;
 }
 
 BooleanType* 
-AST::new_BooleanType(const std::string& id, const Locator* loc)
+AST::new_BooleanType(
+  const std::string& id, 
+  Bundle* bundle,
+  const Locator* loc)
 {
   BooleanType* result = new BooleanType();
   result->setLocator(loc);
   result->setName(id);
-  static_cast<ASTImpl*>(this)->addType(result);
+  result->setParent(bundle);
   return result;
 }
 
 BufferType* 
-AST::new_BufferType(const std::string& id, const Locator* loc)
+AST::new_BufferType(
+  const std::string& id, 
+  Bundle* bundle,
+  const Locator* loc)
 {
   BufferType* result = new BufferType();
   result->setLocator(loc);
   result->setName(id);
-  static_cast<ASTImpl*>(this)->addType(result);
+  result->setParent(bundle);
   return result;
 }
 
 TextType* 
-AST::new_TextType( const std::string& id, const Locator* loc)
+AST::new_TextType(
+  const std::string& id, 
+  Bundle* bundle,
+  const Locator* loc)
 {
   TextType* result = new TextType();
   result->setLocator(loc);
   result->setName(id);
-  static_cast<ASTImpl*>(this)->addType(result);
+  result->setParent(bundle);
   return result;
 }
 
 StreamType* 
-AST::new_StreamType(const std::string& id,  const Locator* loc)
+AST::new_StreamType(
+  const std::string& id,  
+  Bundle* bundle,
+  const Locator* loc)
 {
   StreamType* result = new StreamType();
   result->setLocator(loc);
   result->setName(id);
-  static_cast<ASTImpl*>(this)->addType(result);
+  result->setParent(bundle);
   return result;
 }
 
 CharacterType* 
-AST::new_CharacterType(const std::string& id, const Locator* loc)
-{
-  CharacterType* result = new CharacterType();
-  result->setLocator(loc);
-  result->setName(id);
-  static_cast<ASTImpl*>(this)->addType(result);
-  return result;
-}
-
-OctetType* 
-AST::new_OctetType(const std::string& id, const Locator* loc)
+AST::new_CharacterType(
+  const std::string& id, 
+  Bundle* bundle,
+  const std::string& encoding,
+  const Locator* loc)
 {
-  OctetType* result = new OctetType();
+  CharacterType* result = new CharacterType(encoding);
   result->setLocator(loc);
   result->setName(id);
-  static_cast<ASTImpl*>(this)->addType(result);
+  result->setParent(bundle);
   return result;
 }
 
 PointerType* 
 AST::new_PointerType(
   const std::string& id,
-  Type* target,
+  Bundle* bundle,
+  const Type* target,
   const Locator* loc)
 {
   PointerType* result = new PointerType();
   result->setLocator(loc);
   result->setName(id);
   result->setElementType(target);
-  static_cast<ASTImpl*>(this)->addType(result);
+  result->setParent(bundle);
   return result;
 }
 
 ArrayType* 
 AST::new_ArrayType(
   const std::string& id,
+  Bundle* bundle,
   Type* elemType,
   uint64_t maxSize,
   const Locator* loc)
@@ -446,13 +329,14 @@
   result->setName(id);
   result->setElementType(elemType);
   result->setMaxSize(maxSize);
-  static_cast<ASTImpl*>(this)->addType(result);
+  result->setParent(bundle);
   return result;
 }
 
 VectorType* 
 AST::new_VectorType(
   const std::string& id,
+  Bundle* bundle,
   Type* elemType,
   uint64_t size,
   const Locator* loc)
@@ -462,7 +346,7 @@
   result->setName(id);
   result->setElementType(elemType);
   result->setSize(size);
-  static_cast<ASTImpl*>(this)->addType(result);
+  result->setParent(bundle);
   return result;
 }
 
@@ -483,30 +367,33 @@
 StructureType*
 AST::new_StructureType(
   const std::string& id, 
+  Bundle* bundle,
   const Locator* loc)
 {
   StructureType* result = new StructureType();
   result->setLocator(loc);
   result->setName(id);
-  static_cast<ASTImpl*>(this)->addType(result);
+  result->setParent(bundle);
   return result;
 }
 
 ContinuationType*
 AST::new_ContinuationType(
   const std::string& id, 
+  Bundle* bundle,
   const Locator* loc)
 {
   ContinuationType* result = new ContinuationType();
   result->setLocator(loc);
   result->setName(id);
-  static_cast<ASTImpl*>(this)->addType(result);
+  result->setParent(bundle);
   return result;
 }
 
 SignatureType*
 AST::new_SignatureType(
   const std::string& id, 
+  Bundle* bundle,
   const Type* ty, 
   bool isVarArgs,
   const Locator* loc)
@@ -515,62 +402,82 @@
   result->setLocator(loc);
   result->setName(id);
   result->setResultType(ty);
-  static_cast<ASTImpl*>(this)->addType(result);
+  result->setParent(bundle);
   return result;
 }
 
 OpaqueType*
-AST::new_OpaqueType(const std::string& id, const Locator* loc)
+AST::new_OpaqueType(
+  const std::string& id, 
+  bool is_unresolved,
+  Bundle* bundle,
+  const Locator* loc)
 {
   OpaqueType* result = new OpaqueType(id);
   result->setLocator(loc);
+  if (is_unresolved)
+    result->setIsUnresolved(true);
+  else {
+    result->setIsUnresolved(false);
+    result->setParent(bundle);
+  }
   return result;
 }
 
 ConstantAny* 
 AST::new_ConstantAny(
   const std::string& name,
+  Bundle* bundle,
+  const Type* type,
   ConstantValue* val,
   const Locator* loc)
 {
   ConstantAny* result = new ConstantAny(val);
   result->setLocator(loc);
   result->setName(name);
-  result->setType(getPrimitiveType(AnyTypeID));
+  result->setType(type);
+  result->setParent(bundle);
   return result;
 }
 
 ConstantBoolean* 
 AST::new_ConstantBoolean(
   const std::string& name,
+  Bundle* bundle,
+  const Type* type,
   bool t_or_f, 
   const Locator* loc)
 {
   ConstantBoolean* result = new ConstantBoolean(t_or_f);
   result->setLocator(loc);
   result->setName(name);
-  result->setType(getPrimitiveType(BooleanTypeID));
+  result->setType(type);
+  result->setParent(bundle);
   return result;
 }
 
 ConstantCharacter* 
 AST::new_ConstantCharacter(
   const std::string& name,
+  Bundle* bundle,
+  const Type* type,
   const std::string& val,
   const Locator* loc)
 {
   ConstantCharacter* result = new ConstantCharacter(val);
   result->setLocator(loc);
   result->setName(name);
-  result->setType( getPrimitiveType(CharacterTypeID) );
+  result->setType( type );
+  result->setParent(bundle);
   return result;
 }
 
 ConstantEnumerator* 
 AST::new_ConstantEnumerator(
   const std::string& name,///< The name of the constant
-  const std::string& val, ///< The value for the constant
+  Bundle* bundle,
   const Type* Ty,         ///< The type of the enumerator
+  const std::string& val, ///< The value for the constant
   const Locator* loc      ///< The source locator
 )
 {
@@ -578,28 +485,17 @@
   result->setLocator(loc);
   result->setName(name);
   result->setType(Ty);
-  return result;
-}
-
-ConstantOctet* 
-AST::new_ConstantOctet(
-  const std::string& name,
-  unsigned char val,
-  const Locator* loc)
-{
-  ConstantOctet* result = new ConstantOctet(val);
-  result->setLocator(loc);
-  result->setName(name);
-  result->setType( getPrimitiveType(OctetTypeID) );
+  result->setParent(bundle);
   return result;
 }
 
 ConstantInteger*
 AST::new_ConstantInteger(
   const std::string& name,
+  Bundle* bundle,
+  const Type* type,
   const std::string&  v, 
   uint16_t base, 
-  const Type* Ty, 
   const Locator* loc)
 {
   ConstantInteger* result = new ConstantInteger(base);
@@ -607,28 +503,33 @@
   result->setName(name);
   result->setValue(v);
   result->setBase(base);
-  result->setType(Ty);
+  result->setType(type);
+  result->setParent(bundle);
   return result;
 }
 
 ConstantReal*
 AST::new_ConstantReal(
   const std::string& name,
+  Bundle* bundle,
+  const Type* type,
   const std::string& v, 
-  const Type* Ty, 
   const Locator* loc)
 {
   ConstantReal* result = new ConstantReal();
   result->setLocator(loc);
   result->setName(name);
   result->setValue(v);
-  result->setType(Ty);
+  result->setType(type);
+  result->setParent(bundle);
   return result;
 }
 
 ConstantString*
 AST::new_ConstantString(
   const std::string& name,
+  Bundle* bundle,
+  const Type* type,
   const std::string& v, 
   const Locator* loc)
 {
@@ -636,14 +537,16 @@
   result->setLocator(loc);
   result->setName(name);
   result->setValue(v);
-  result->setType( getPrimitiveType(StringTypeID) );
+  result->setType(type);
+  result->setParent(bundle);
   return result;
 }
 
 ConstantPointer* 
 AST::new_ConstantPointer(
   const std::string& name,
-  const Type* Ty,
+  Bundle* bundle,
+  const Type* type,
   Constant* referent,
   const Locator* loc
 )
@@ -651,15 +554,17 @@
   ConstantPointer* result = new ConstantPointer(referent);
   result->setLocator(loc);
   result->setName(name);
-  result->setType(Ty);
+  result->setType(type);
+  result->setParent(bundle);
   return result;
 }
 
 ConstantArray* 
 AST::new_ConstantArray(
   const std::string& name,
-  const std::vector<ConstantValue*>& vals,
+  Bundle* bundle,
   const ArrayType* AT,
+  const std::vector<ConstantValue*>& vals,
   const Locator* loc
 )
 {
@@ -672,14 +577,16 @@
     result->addConstant(*I);
   }
   result->setType(AT);
+  result->setParent(bundle);
   return result;
 }
 
 ConstantVector* 
 AST::new_ConstantVector(
   const std::string& name,
+  Bundle* bundle,
+  const VectorType* VT,
   const std::vector<ConstantValue*>& vals,
-  const VectorType* AT,
   const Locator* loc
 )
 {
@@ -691,15 +598,17 @@
   {
     result->addConstant(*I);
   }
-  result->setType(AT);
+  result->setType(VT);
+  result->setParent(bundle);
   return result;
 }
 
 ConstantStructure* 
 AST::new_ConstantStructure(
   const std::string& name,
-  const std::vector<ConstantValue*>& vals,
+  Bundle* bundle,
   const StructureType* ST,
+  const std::vector<ConstantValue*>& vals,
   const Locator* loc
 )
 {
@@ -716,14 +625,16 @@
     ++STI;
   }
   result->setType(ST);
+  result->setParent(bundle);
   return result;
 }
 
 ConstantContinuation* 
 AST::new_ConstantContinuation(
   const std::string& name,
-  const std::vector<ConstantValue*>& vals,
+  Bundle* bundle,
   const ContinuationType* ST,
+  const std::vector<ConstantValue*>& vals,
   const Locator* loc
 )
 {
@@ -740,16 +651,22 @@
     ++STI;
   }
   result->setType(ST);
+  result->setParent(bundle);
   return result;
 }
 
 Variable*
-AST::new_Variable(const std::string& id, const Type* Ty, const Locator* loc)
+AST::new_Variable(
+  const std::string& id, 
+  Bundle* B,
+  const Type* Ty, 
+  const Locator* loc)
 {
   Variable* result = new Variable();
   result->setName(id);
   result->setType(Ty);
   result->setLocator(loc);
+  result->setParent(B);
   return result;
 }
 
@@ -766,7 +683,10 @@
 
 Function*
 AST::new_Function(
-  const std::string& id, const SignatureType* ty, const Locator* loc)
+  const std::string& id, 
+  Bundle* B,
+  const SignatureType* ty, 
+  const Locator* loc)
 {
   Function* result = new Function();
   result->setLocator(loc);
@@ -780,15 +700,17 @@
     Argument* arg = new_Argument((*I)->getName(),0,loc);
     result->addArgument(arg);
   }
+  result->setParent(B);
   return result;
 }
 
 Program*
-AST::new_Program(const std::string& id, const Locator* loc)
+AST::new_Program(
+  const std::string& id, 
+  Bundle* B,
+  const Locator* loc)
 {
-  SignatureType* ty = getProgramType();
-  ASTImpl* ast = static_cast<ASTImpl*>(this);
-
+  SignatureType* ty = B->getProgramType();
   Program* result = new Program();
   result->setLocator(loc);
   result->setName(id);
@@ -802,6 +724,7 @@
     Argument* arg = new_Argument((*I)->getName(),Ty,loc);
     result->addArgument(arg);
   }
+  result->setParent(B);
   return result;
 }
 
@@ -860,17 +783,18 @@
 
 template<class OpClass> OpClass* 
 AST::new_NilaryOp(
+  Bundle* bundle,    ///< Bundle, for type resolution
   const Locator* loc ///< The source locator
 )
 {
-  return new_NilaryOp<OpClass>(0,loc);
+  return new_NilaryOp<OpClass>(static_cast<Type*>(0),loc);
 }
 
 /// Provide a template function for creating a unary operator
 template<class OpClass> OpClass* 
 AST::new_UnaryOp(
   const Type* Ty,    ///< Result type of the operator
-  Operator* oprnd1,     ///< The first operand
+  Operator* oprnd1,  ///< The first operand
   const Locator* loc ///< The source locator
 )
 {
@@ -885,6 +809,7 @@
 template<class OpClass> OpClass* 
 AST::new_UnaryOp(
   Operator* oprnd1,     ///< The first operand
+  Bundle* B,         ///< The bundle, for type lookup
   const Locator* loc ///< The source locator
 )
 {
@@ -895,8 +820,8 @@
 template<class OpClass> OpClass* 
 AST::new_BinaryOp(
   const Type* Ty,    ///< Result type of the operator
-  Operator* oprnd1,     ///< The first operand
-  Operator* oprnd2,     ///< The second operand
+  Operator* oprnd1,  ///< The first operand
+  Operator* oprnd2,  ///< The second operand
   const Locator* loc ///< The source locator
 )
 {
@@ -913,8 +838,9 @@
 /// Provide a template function for creating a binary operator
 template<class OpClass> OpClass* 
 AST::new_BinaryOp(
-  Operator* oprnd1,     ///< The first operand
-  Operator* oprnd2,     ///< The second operand
+  Operator* oprnd1,  ///< The first operand
+  Operator* oprnd2,  ///< The second operand
+  Bundle* B,         ///< The bundle, for type lookup
   const Locator* loc ///< The source locator
 )
 {
@@ -948,6 +874,7 @@
   Operator* oprnd1,     ///< The first operand
   Operator* oprnd2,     ///< The second operand
   Operator* oprnd3,     ///< The third operand
+  Bundle* B,
   const Locator* loc ///< The source locator
 )
 {
@@ -971,6 +898,7 @@
 template<class OpClass> OpClass* 
 AST::new_MultiOp(
   const std::vector<Operator*>& oprnds,
+  Bundle* B,
   const Locator* loc
 )
 {
@@ -983,228 +911,244 @@
 AST::new_UnaryOp<NegateOp>(
     const Type* Ty, Operator* op1, const Locator* loc);
 template NegateOp*
-AST::new_UnaryOp<NegateOp>(Operator* op1, const Locator* loc);
+AST::new_UnaryOp<NegateOp>(Operator* op1, Bundle* B, const Locator* loc);
 
 template ComplementOp*
 AST::new_UnaryOp<ComplementOp>(
     const Type* Ty, Operator* op1, const Locator* loc);
 template ComplementOp*
-AST::new_UnaryOp<ComplementOp>(Operator* op1, const Locator* loc);
+AST::new_UnaryOp<ComplementOp>(Operator* op1, Bundle* B, const Locator* loc);
 
 template PreIncrOp*
 AST::new_UnaryOp<PreIncrOp>(
     const Type* Ty, Operator* op1, const Locator* loc);
 template PreIncrOp*
-AST::new_UnaryOp<PreIncrOp>(Operator* op1, const Locator* loc);
+AST::new_UnaryOp<PreIncrOp>(Operator* op1, Bundle* B, const Locator* loc);
 
 template PreDecrOp*
 AST::new_UnaryOp<PreDecrOp>(
     const Type* Ty, Operator* op1, const Locator* loc);
 template PreDecrOp*
-AST::new_UnaryOp<PreDecrOp>(Operator* op1, const Locator* loc);
+AST::new_UnaryOp<PreDecrOp>(Operator* op1, Bundle* B, const Locator* loc);
 
 template PostIncrOp*
 AST::new_UnaryOp<PostIncrOp>(
     const Type* Ty, Operator* op1, const Locator* loc);
 template PostIncrOp*
-AST::new_UnaryOp<PostIncrOp>(Operator* op1, const Locator* loc);
+AST::new_UnaryOp<PostIncrOp>(Operator* op1, Bundle* B, const Locator* loc);
 
 template PostDecrOp*
 AST::new_UnaryOp<PostDecrOp>(
     const Type* Ty, Operator* op1, const Locator* loc);
 template PostDecrOp*
-AST::new_UnaryOp<PostDecrOp>(Operator* op1, const Locator* loc);
+AST::new_UnaryOp<PostDecrOp>(Operator* op1, Bundle* B, const Locator* loc);
 
 template AddOp*
 AST::new_BinaryOp<AddOp>(
     const Type* Ty, Operator* op1, Operator* op2, const Locator* loc);
 template AddOp*
-AST::new_BinaryOp<AddOp>(Operator* op1, Operator* op2, const Locator* loc);
+AST::new_BinaryOp<AddOp>(Operator* op1, Operator* op2, Bundle* B, const Locator* loc);
 
 template SubtractOp*
 AST::new_BinaryOp<SubtractOp>(
     const Type* Ty, Operator* op1, Operator* op2, const Locator* loc);
 template SubtractOp*
-AST::new_BinaryOp<SubtractOp>(Operator* op1, Operator* op2, const Locator* loc);
+AST::new_BinaryOp<SubtractOp>(Operator* op1, Operator* op2, Bundle* B, const Locator* loc);
 
 template MultiplyOp*
 AST::new_BinaryOp<MultiplyOp>(
     const Type* Ty, Operator* op1, Operator* op2, const Locator* loc);
 template MultiplyOp*
-AST::new_BinaryOp<MultiplyOp>(Operator* op1, Operator* op2, const Locator* loc);
+AST::new_BinaryOp<MultiplyOp>(Operator* op1, Operator* op2, Bundle* B, const Locator* loc);
 
 template DivideOp*
 AST::new_BinaryOp<DivideOp>(
     const Type* Ty, Operator* op1, Operator* op2, const Locator* loc);
 template DivideOp*
-AST::new_BinaryOp<DivideOp>(Operator* op1, Operator* op2, const Locator* loc);
+AST::new_BinaryOp<DivideOp>(Operator* op1, Operator* op2, Bundle* B, const Locator* loc);
 
 template ModuloOp*
 AST::new_BinaryOp<ModuloOp>(
     const Type* Ty, Operator* op1, Operator* op2, const Locator* loc);
 template ModuloOp*
-AST::new_BinaryOp<ModuloOp>(Operator* op1, Operator* op2, const Locator* loc);
+AST::new_BinaryOp<ModuloOp>(Operator* op1, Operator* op2, Bundle* B, const Locator* loc);
 
 template BAndOp*
 AST::new_BinaryOp<BAndOp>(
     const Type* Ty, Operator* op1, Operator* op2, const Locator* loc);
 template BAndOp*
-AST::new_BinaryOp<BAndOp>(Operator* op1, Operator* op2, const Locator* loc);
+AST::new_BinaryOp<BAndOp>(Operator* op1, Operator* op2, Bundle* B, const Locator* loc);
 
 template BOrOp*
 AST::new_BinaryOp<BOrOp>(
     const Type* Ty, Operator* op1, Operator* op2, const Locator* loc);
 template BOrOp*
-AST::new_BinaryOp<BOrOp>(Operator* op1, Operator* op2, const Locator* loc);
+AST::new_BinaryOp<BOrOp>(Operator* op1, Operator* op2, Bundle* B, const Locator* loc);
 
 template BXorOp*
 AST::new_BinaryOp<BXorOp>(
     const Type* Ty, Operator* op1, Operator* op2, const Locator* loc);
 template BXorOp*
-AST::new_BinaryOp<BXorOp>(Operator* op1, Operator* op2, const Locator* loc);
+AST::new_BinaryOp<BXorOp>(Operator* op1, Operator* op2, Bundle* B, const Locator* loc);
 
 template BNorOp*
 AST::new_BinaryOp<BNorOp>(
     const Type* Ty, Operator* op1, Operator* op2, const Locator* loc);
 template BNorOp*
-AST::new_BinaryOp<BNorOp>(Operator* op1, Operator* op2, const Locator* loc);
+AST::new_BinaryOp<BNorOp>(Operator* op1, Operator* op2, Bundle* B, const Locator* loc);
 
 // Boolean Operators
 template NotOp*
 AST::new_UnaryOp<NotOp>(const Type* Ty, Operator* op1, const Locator* loc);
 template<> NotOp*
-AST::new_UnaryOp<NotOp>(Operator* op1, const Locator* loc)
+AST::new_UnaryOp<NotOp>(Operator* op1, Bundle* B, const Locator* loc)
 {
-  return AST::new_UnaryOp<NotOp>(getPrimitiveType(BooleanTypeID),op1,loc);
+  Type* Ty = B->getIntrinsicType(boolTy);
+  return AST::new_UnaryOp<NotOp>(Ty,op1,loc);
 }
 
 template AndOp*
 AST::new_BinaryOp<AndOp>(
     const Type* Ty, Operator* op1, Operator* op2, const Locator* loc);
 template<> AndOp*
-AST::new_BinaryOp<AndOp>(Operator* op1, Operator* op2, const Locator* loc)
+AST::new_BinaryOp<AndOp>(Operator* op1, Operator* op2, Bundle* B, const Locator* loc)
 {
-  return AST::new_BinaryOp<AndOp>(getPrimitiveType(BooleanTypeID),op1,op2,loc);
+  Type* Ty = B->getIntrinsicType(boolTy);
+  return AST::new_BinaryOp<AndOp>(Ty,op1,op2,loc);
 }
 
 template OrOp*
 AST::new_BinaryOp<OrOp>(
     const Type* Ty, Operator* op1, Operator* op2, const Locator* loc);
 template<> OrOp*
-AST::new_BinaryOp<OrOp>(Operator* op1, Operator* op2, const Locator* loc)
+AST::new_BinaryOp<OrOp>(Operator* op1, Operator* op2, Bundle* B, const Locator* loc)
 {
-  return AST::new_BinaryOp<OrOp>(getPrimitiveType(BooleanTypeID),op1,op2,loc);
+  Type* Ty = B->getIntrinsicType(boolTy);
+  return AST::new_BinaryOp<OrOp>(Ty,op1,op2,loc);
 }
 
 template NorOp*
 AST::new_BinaryOp<NorOp>(
     const Type* Ty, Operator* op1, Operator* op2, const Locator* loc);
 template<> NorOp*
-AST::new_BinaryOp<NorOp>(Operator* op1, Operator* op2, const Locator* loc)
+AST::new_BinaryOp<NorOp>(Operator* op1, Operator* op2, Bundle* B, const Locator* loc)
 {
-  return AST::new_BinaryOp<NorOp>(getPrimitiveType(BooleanTypeID),op1,op2,loc);
+  Type* Ty = B->getIntrinsicType(boolTy);
+  return AST::new_BinaryOp<NorOp>(Ty,op1,op2,loc);
 }
 
 template XorOp*
 AST::new_BinaryOp<XorOp>(
     const Type* Ty, Operator* op1, Operator* op2, const Locator* loc);
 template<> XorOp*
-AST::new_BinaryOp<XorOp>(Operator* op1, Operator* op2, const Locator* loc)
+AST::new_BinaryOp<XorOp>(Operator* op1, Operator* op2, Bundle* B, const Locator* loc)
 {
-  return AST::new_BinaryOp<XorOp>(getPrimitiveType(BooleanTypeID),op1,op2,loc);
+  Type* Ty = B->getIntrinsicType(boolTy);
+  return AST::new_BinaryOp<XorOp>(Ty,op1,op2,loc);
 }
 
 template LessThanOp*
 AST::new_BinaryOp<LessThanOp>(
     const Type* Ty, Operator* op1, Operator* op2, const Locator* loc);
 template<> LessThanOp*
-AST::new_BinaryOp<LessThanOp>(Operator* op1, Operator* op2, const Locator* loc)
+AST::new_BinaryOp<LessThanOp>(Operator* op1, Operator* op2, Bundle* B, const Locator* loc)
 {
-  return AST::new_BinaryOp<LessThanOp>(getPrimitiveType(BooleanTypeID),op1,op2,loc);
+  Type* Ty = B->getIntrinsicType(boolTy);
+  return AST::new_BinaryOp<LessThanOp>(Ty,op1,op2,loc);
 }
 
 template GreaterThanOp* 
 AST::new_BinaryOp<GreaterThanOp>(
     const Type* Ty, Operator* op1, Operator* op2,const Locator* loc);
 template<> GreaterThanOp* 
-AST::new_BinaryOp<GreaterThanOp>(Operator* op1, Operator* op2,const Locator* loc)
+AST::new_BinaryOp<GreaterThanOp>(Operator* op1, Operator* op2,Bundle* B, const Locator* loc)
 {
-  return AST::new_BinaryOp<GreaterThanOp>(getPrimitiveType(BooleanTypeID),op1,op2,loc);
+  Type* Ty = B->getIntrinsicType(boolTy);
+  return AST::new_BinaryOp<GreaterThanOp>(Ty,op1,op2,loc);
 }
 
 template LessEqualOp* 
 AST::new_BinaryOp<LessEqualOp>(
     const Type* Ty, Operator* op1, Operator* op2, const Locator* loc);
 template<> LessEqualOp* 
-AST::new_BinaryOp<LessEqualOp>(Operator* op1, Operator* op2, const Locator* loc)
+AST::new_BinaryOp<LessEqualOp>(Operator* op1, Operator* op2, Bundle* B, const Locator* loc)
 {
-  return AST::new_BinaryOp<LessEqualOp>(getPrimitiveType(BooleanTypeID),op1,op2,loc);
+  Type* Ty = B->getIntrinsicType(boolTy);
+  return AST::new_BinaryOp<LessEqualOp>(Ty,op1,op2,loc);
 }
 
 template GreaterEqualOp* 
 AST::new_BinaryOp<GreaterEqualOp>(
     const Type* Ty, Operator* op1,Operator* op2, const Locator* loc);
 template<> GreaterEqualOp* 
-AST::new_BinaryOp<GreaterEqualOp>(Operator* op1,Operator* op2, const Locator* loc)
+AST::new_BinaryOp<GreaterEqualOp>(Operator* op1,Operator* op2, Bundle* B, const Locator* loc)
 {
-  return AST::new_BinaryOp<GreaterEqualOp>(getPrimitiveType(BooleanTypeID),op1,op2,loc);
+  Type* Ty = B->getIntrinsicType(boolTy);
+  return AST::new_BinaryOp<GreaterEqualOp>(Ty,op1,op2,loc);
 }
 
 template EqualityOp*
 AST::new_BinaryOp<EqualityOp>(
     const Type* Ty, Operator* op1, Operator* op2, const Locator* loc);
 template<> EqualityOp*
-AST::new_BinaryOp<EqualityOp>(Operator* op1, Operator* op2, const Locator* loc)
+AST::new_BinaryOp<EqualityOp>(Operator* op1, Operator* op2, Bundle* B, const Locator* loc)
 {
-  return AST::new_BinaryOp<EqualityOp>(getPrimitiveType(BooleanTypeID),op1,op2,loc);
+  Type* Ty = B->getIntrinsicType(boolTy);
+  return AST::new_BinaryOp<EqualityOp>(Ty,op1,op2,loc);
 }
 
 template InequalityOp*
 AST::new_BinaryOp<InequalityOp>(
     const Type* Ty, Operator* op1,Operator* op2,const Locator* loc);
 template<> InequalityOp*
-AST::new_BinaryOp<InequalityOp>(Operator* op1,Operator* op2,const Locator* loc)
+AST::new_BinaryOp<InequalityOp>(Operator* op1,Operator* op2,Bundle* B, const Locator* loc)
 {
-  return AST::new_BinaryOp<InequalityOp>(getPrimitiveType(BooleanTypeID),op1,op2,loc);
+  Type* Ty = B->getIntrinsicType(boolTy);
+  return AST::new_BinaryOp<InequalityOp>(Ty,op1,op2,loc);
 }
 
-
 // Control Flow Operators
 template Block* 
 AST::new_MultiOp<Block>(
     const Type* Ty, const std::vector<Operator*>& ops, const Locator*loc);
 template Block* 
-AST::new_MultiOp<Block>(const std::vector<Operator*>& ops, const Locator*loc);
+AST::new_MultiOp<Block>(const std::vector<Operator*>& ops, Bundle* B, const Locator*loc);
 
 template SelectOp*
 AST::new_TernaryOp<SelectOp>(
     const Type* Ty, Operator*op1,Operator*op2,Operator*op3,const Locator* loc);
 template<> SelectOp*
-AST::new_TernaryOp<SelectOp>(Operator*op1,Operator*op2,Operator*op3,const Locator* loc)
+AST::new_TernaryOp<SelectOp>(Operator*op1,Operator*op2,Operator*op3,Bundle* B,const Locator* loc)
 {
   return new_TernaryOp<SelectOp>(op2->getType(),op1,op2,op3,loc);
 }
 
 template WhileOp*
 AST::new_BinaryOp<WhileOp>(const Type* Ty, Operator* op1, Operator* op2, const Locator* loc);
-template WhileOp*
-AST::new_BinaryOp<WhileOp>(Operator* op1, Operator* op2,const Locator* loc);
+template<> WhileOp*
+AST::new_BinaryOp<WhileOp>(Operator* op1, Operator* op2,Bundle* B, const Locator* loc)
+{
+  return new_BinaryOp<WhileOp>(op2->getType(),op1,op2,loc);
+}
 
 template UnlessOp*
 AST::new_BinaryOp<UnlessOp>(const Type* Ty, Operator* op1, Operator* op2, const Locator* loc);
-template UnlessOp*
-AST::new_BinaryOp<UnlessOp>(Operator* op1, Operator* op2,const Locator* loc);
+template<> UnlessOp*
+AST::new_BinaryOp<UnlessOp>(Operator* op1, Operator* op2,Bundle* B, const Locator* loc)
+{
+  return new_BinaryOp<UnlessOp>(op2->getType(),op1,op2,loc);
+}
 
 template UntilOp*
 AST::new_BinaryOp<UntilOp>(const Type* Ty, Operator* op1, Operator* op2, const Locator* loc);
 template UntilOp*
-AST::new_BinaryOp<UntilOp>(Operator* op1, Operator* op2,const Locator* loc);
+AST::new_BinaryOp<UntilOp>(Operator* op1, Operator* op2,Bundle* B, const Locator* loc);
 
 template LoopOp*
 AST::new_TernaryOp<LoopOp>(const Type* Ty, Operator*op1,Operator*op2,Operator*op3,const Locator* loc);
 
 template<> LoopOp*
-AST::new_TernaryOp<LoopOp>(Operator*op1,Operator*op2,Operator*op3,const Locator* loc)
+AST::new_TernaryOp<LoopOp>(Operator*op1,Operator*op2,Operator*op3,Bundle* B,const Locator* loc)
 {
   const Type* Ty = op2->getType();
   if (Ty && llvm::isa<Block>(Ty))
@@ -1216,7 +1160,7 @@
 AST::new_MultiOp<SwitchOp>(
     const Type* Ty, const std::vector<Operator*>& ops, const Locator* loc);
 template<> SwitchOp*
-AST::new_MultiOp<SwitchOp>(const std::vector<Operator*>& ops, const Locator* loc)
+AST::new_MultiOp<SwitchOp>(const std::vector<Operator*>& ops, Bundle* B,const Locator* loc)
 {
   hlvmAssert(ops.size() >= 2 && "Too few operands for SwitchOp");
   const Type* Ty = ops[1]->getType();
@@ -1228,214 +1172,124 @@
 template BreakOp* 
 AST::new_NilaryOp<BreakOp>(const Type*Ty, const Locator*loc);
 template BreakOp* 
-AST::new_NilaryOp<BreakOp>(const Locator*loc);
+AST::new_NilaryOp<BreakOp>(Bundle* B, const Locator*loc);
 
 template ContinueOp* 
 AST::new_NilaryOp<ContinueOp>(const Type* Ty, const Locator*loc);
 template ContinueOp* 
-AST::new_NilaryOp<ContinueOp>(const Locator*loc);
+AST::new_NilaryOp<ContinueOp>(Bundle* B, const Locator*loc);
 
 template ReturnOp* 
 AST::new_NilaryOp<ReturnOp>(const Type*Ty, const Locator*loc);
 template ReturnOp* 
-AST::new_NilaryOp<ReturnOp>(const Locator*loc);
+AST::new_NilaryOp<ReturnOp>(Bundle* B, const Locator*loc);
 
 template ResultOp* 
 AST::new_UnaryOp<ResultOp>(const Type*Ty, Operator*op1,const Locator*loc);
 template ResultOp* 
-AST::new_UnaryOp<ResultOp>(Operator*op1,const Locator*loc);
+AST::new_UnaryOp<ResultOp>(Operator*op1,Bundle* B, const Locator*loc);
 
 template CallOp* 
 AST::new_MultiOp<CallOp>(const Type*Ty, const std::vector<Operator*>& ops, const Locator*loc);
 template CallOp* 
-AST::new_MultiOp<CallOp>(const std::vector<Operator*>& ops, const Locator* loc);
+AST::new_MultiOp<CallOp>(const std::vector<Operator*>& ops, Bundle* B,const Locator* loc);
 
 // Memory Operators
 template StoreOp*  
 AST::new_BinaryOp<StoreOp>(const Type*, Operator*op1,Operator*op2,const Locator*loc);
 template StoreOp*  
-AST::new_BinaryOp<StoreOp>(Operator*op1,Operator*op2,const Locator*loc);
+AST::new_BinaryOp<StoreOp>(Operator*op1,Operator*op2,Bundle* B, const Locator*loc);
 
 template LoadOp*   
 AST::new_UnaryOp<LoadOp>(const Type* Ty, Operator*op1,const Locator*loc);
 template LoadOp*   
-AST::new_UnaryOp<LoadOp>(Operator*op1,const Locator*loc);
+AST::new_UnaryOp<LoadOp>(Operator*op1,Bundle* B, const Locator*loc);
 
 // Input/Output Operators
 template OpenOp* 
 AST::new_UnaryOp<OpenOp>(const Type* Ty, Operator*op1,const Locator*loc);
 template<> OpenOp* 
-AST::new_UnaryOp<OpenOp>(Operator*op1,const Locator*loc)
+AST::new_UnaryOp<OpenOp>(Operator*op1,Bundle* B, const Locator*loc)
 {
-  return new_UnaryOp<OpenOp>(getPrimitiveType(StreamTypeID),op1,loc);
+  Type* Ty = B->getIntrinsicType(streamTy);
+  return new_UnaryOp<OpenOp>(Ty,op1,loc);
 }
 
 template WriteOp* 
 AST::new_BinaryOp<WriteOp>(
   const Type* Ty, Operator*op1,Operator*op2, const Locator*loc);
 template<> WriteOp* 
-AST::new_BinaryOp<WriteOp>(Operator*op1,Operator*op2,const Locator*loc)
+AST::new_BinaryOp<WriteOp>(Operator*op1,Operator*op2,Bundle* B, const Locator*loc)
 {
-  return new_BinaryOp<WriteOp>(getPrimitiveType(UInt64TypeID),op1,op2,loc);
+  Type* Ty = B->getIntrinsicType(u64Ty);
+  return new_BinaryOp<WriteOp>(Ty,op1,op2,loc);
 }
 
 template CloseOp* 
 AST::new_UnaryOp<CloseOp>(const Type* Ty, Operator*op1,const Locator*loc);
 template<> CloseOp* 
-AST::new_UnaryOp<CloseOp>(Operator*op1,const Locator*loc)
+AST::new_UnaryOp<CloseOp>(Operator*op1,Bundle* B, const Locator*loc)
 {
   return new_UnaryOp<CloseOp>(0,op1,loc);
 }
 
 Type* 
-AST::getPrimitiveType(NodeIDs pid)
+AST::new_IntrinsicType(
+ const std::string& id,  ///< The name for the new type
+ Bundle* bundle,         ///< The bundle to put the new type into
+ IntrinsicTypes it,      ///< The type of intrinsic to create
+ const Locator* loc      ///< The source locator
+) 
 {
-  ASTImpl* ast = static_cast<ASTImpl*>(this);
-  switch (pid) 
+  Type* result = 0;
+  switch (it) 
   {
-    case AnyTypeID:
-      if (!ast->AnyTypeSingleton) {
-        ast->AnyTypeSingleton = new AnyType();
-        ast->AnyTypeSingleton->setName("any");
-      }
-      return ast->AnyTypeSingleton;
-    case StringTypeID:
-      if (!ast->StringTypeSingleton) {
-        ast->StringTypeSingleton = new StringType();
-        ast->StringTypeSingleton->setName("string");
-      }
-      return ast->StringTypeSingleton;
-    case BooleanTypeID:
-      if (!ast->BooleanSingleton) {
-        ast->BooleanSingleton = new BooleanType();
-        ast->BooleanSingleton->setName("bool");
-      }
-      return ast->BooleanSingleton;
-    case CharacterTypeID:
-      if (!ast->CharacterSingleton) {
-        ast->CharacterSingleton = new CharacterType();
-        ast->CharacterSingleton->setName("char");
-      }
-      return ast->CharacterSingleton;
-    case OctetTypeID:
-      if (!ast->OctetSingleton) {
-        ast->OctetSingleton = new OctetType();
-        ast->OctetSingleton->setName("octet");
-      }
-      return ast->OctetSingleton;
-    case UInt8TypeID:
-      if (!ast->UInt8Singleton) {
-        ast->UInt8Singleton = new IntegerType(UInt8TypeID,8,false);
-        ast->UInt8Singleton->setName("u8");
-      }
-      return ast->UInt8Singleton;
-    case UInt16TypeID:
-      if (!ast->UInt16Singleton) {
-        ast->UInt16Singleton = new IntegerType(UInt16TypeID,16,false);
-        ast->UInt16Singleton->setName("u16");
-      }
-      return ast->UInt16Singleton;
-    case UInt32TypeID:
-      if (!ast->UInt32Singleton) {
-        ast->UInt32Singleton = new IntegerType(UInt32TypeID,32,false);
-        ast->UInt32Singleton->setName("u32");
-      }
-      return ast->UInt32Singleton;
-    case UInt64TypeID:
-      if (!ast->UInt64Singleton) {
-        ast->UInt64Singleton = new IntegerType(UInt64TypeID,64,false);
-        ast->UInt64Singleton->setName("u64");
-      }
-      return ast->UInt64Singleton;
-    case UInt128TypeID:
-      if (!ast->UInt128Singleton) {
-        ast->UInt128Singleton = new IntegerType(UInt128TypeID,128,false);
-        ast->UInt128Singleton->setName("u128");
-      }
-      return ast->UInt128Singleton;
-    case SInt8TypeID:
-      if (!ast->SInt8Singleton) {
-        ast->SInt8Singleton = new IntegerType(SInt8TypeID,8,true);
-        ast->SInt8Singleton->setName("s8");
-      }
-      return ast->SInt8Singleton;
-    case SInt16TypeID:
-      if (!ast->SInt16Singleton) {
-        ast->SInt16Singleton = new IntegerType(SInt16TypeID,16,true);
-        ast->SInt16Singleton->setName("s16");
-      }
-      return ast->SInt16Singleton;
-    case SInt32TypeID:
-      if (!ast->SInt32Singleton) {
-        ast->SInt32Singleton = new IntegerType(SInt32TypeID,32,true);
-        ast->SInt32Singleton->setName("s32");
-      }
-      return ast->SInt32Singleton;
-    case SInt64TypeID:
-      if (!ast->SInt64Singleton) {
-        ast->SInt64Singleton = new IntegerType(SInt64TypeID,64,true);
-        ast->SInt64Singleton->setName("s64");
-      }
-      return ast->SInt64Singleton;
-    case SInt128TypeID:
-      if (!ast->SInt128Singleton) {
-        ast->SInt128Singleton = new IntegerType(SInt128TypeID,128,true);
-        ast->SInt128Singleton->setName("s128");
-      }
-      return ast->SInt128Singleton;
-    case Float32TypeID:
-      if (!ast->Float32Singleton) {
-        ast->Float32Singleton = new RealType(Float32TypeID,23,8);
-        ast->Float32Singleton->setName("f32");
-      }
-      return ast->Float32Singleton;
-    case Float44TypeID:
-      if (!ast->Float44Singleton) {
-        ast->Float44Singleton = new RealType(Float44TypeID,32,11);
-        ast->Float44Singleton->setName("f44");
-      }
-      return ast->Float44Singleton;
-    case Float64TypeID:
-      if (!ast->Float64Singleton) {
-        ast->Float64Singleton = new RealType(Float64TypeID,52,11);
-        ast->Float64Singleton->setName("f64");
-      }
-      return ast->Float64Singleton;
-    case Float80TypeID:
-      if (!ast->Float80Singleton) {
-        ast->Float80Singleton = new RealType(Float80TypeID,64,15);
-        ast->Float80Singleton->setName("f80");
-      }
-      return ast->Float80Singleton;
-    case Float128TypeID:
-      if (!ast->Float128Singleton) {
-        ast->Float128Singleton = new RealType(Float128TypeID,112,15);
-        ast->Float128Singleton->setName("f128");
-      }
-      return ast->Float128Singleton;
-    case TextTypeID:
-      if (!ast->TextTypeSingleton) {
-        ast->TextTypeSingleton = new TextType();
-        ast->TextTypeSingleton->setName("text");
-      }
-      return ast->TextTypeSingleton;
-    case StreamTypeID:
-      if (!ast->StreamTypeSingleton) {
-        ast->StreamTypeSingleton = new StreamType();
-        ast->StreamTypeSingleton->setName("stream");
-      }
-      return ast->StreamTypeSingleton;
-    case BufferTypeID:
-      if (!ast->BufferTypeSingleton) {
-        ast->BufferTypeSingleton = new BufferType();
-        ast->BufferTypeSingleton->setName("buffer");
-      }
-      return ast->BufferTypeSingleton;
+    case boolTy:   result = new BooleanType(); break;
+    case bufferTy: result = new BufferType(); break;
+    case charTy:   result = new CharacterType("utf-8"); break;
+    case doubleTy: result = new RealType(52,11); break;
+    case f32Ty:    result = new RealType(23,8); break;
+    case f44Ty:    result = new RealType(32,11); break;
+    case f64Ty:    result = new RealType(52,11); break;
+    case f80Ty:    result = new RealType(64,15); break;
+    case f96Ty:    result = new RealType(112,15); break;
+    case f128Ty:   result = new RealType(112,15); break;
+    case floatTy:  result = new RealType(23,8); break;
+    case intTy:    result = new IntegerType(32,true); break;
+    case longTy:   result = new IntegerType(64,true); break;
+    case octetTy:  result = new IntegerType(8,false); break;
+    case r8Ty:     result = new RangeType(INT8_MIN,INT8_MAX); break;
+    case r16Ty:    result = new RangeType(INT16_MIN,INT16_MAX); break;
+    case r32Ty:    result = new RangeType(INT32_MIN,INT32_MAX); break;
+    case r64Ty:    result = new RangeType(INT64_MIN,INT64_MAX); break;
+    case s8Ty:     result = new IntegerType(8,true); break;
+    case s16Ty:    result = new IntegerType(16,true); break;
+    case s32Ty:    result = new IntegerType(32,true); break;
+    case s64Ty:    result = new IntegerType(64,true); break;
+    case s128Ty:   result = new IntegerType(128,true); break;
+    case textTy:   result = new TextType(); break;
+    case shortTy:  result = new IntegerType(16,true); break;
+    case streamTy: result = new StreamType(); break;
+    case stringTy: result = new StringType("utf-8"); break;
+    case u8Ty:     result = new IntegerType(8,false); break;
+    case u16Ty:    result = new IntegerType(16,false); break;
+    case u32Ty:    result = new IntegerType(32,false); break;
+    case u64Ty:    result = new IntegerType(64,false); break;
+    case u128Ty:   result = new IntegerType(128,false); break;
+    case voidTy:   result = new OpaqueType(id); break;
     default:
-      hlvmDeadCode("Invalid Primitive");
+      hlvmDeadCode("Invalid Intrinsic");
       break;
   }
-  return 0;
+  result->setName(id);
+  result->setParent(bundle);
+  return result;
+}
+
+void 
+AST::old(Node* to_be_deleted)
+{
+  delete to_be_deleted;
 }
 
 }

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

==============================================================================
--- hlvm/trunk/hlvm/AST/AST.h (original)
+++ hlvm/trunk/hlvm/AST/AST.h Sat Jul  7 19:02:42 2007
@@ -35,6 +35,7 @@
 #include <hlvm/AST/ContainerType.h>
 #include <hlvm/AST/RuntimeType.h>
 #include <hlvm/AST/Constants.h>
+#include <hlvm/AST/Bundle.h>
 #include <string>
 #include <vector>
 
@@ -44,13 +45,11 @@
 namespace hlvm
 {
 
-class Bundle;   
 class Documentation;
 class Block;
 class Argument;
 class Function; 
 class Program; 
-class Import;
 class Locator; 
 class Variable; 
 class Pool;
@@ -83,7 +82,7 @@
     static void destroy(AST* ast);
 
   protected:
-    AST() : Node(TreeTopID), sysid(), pubid(), bundles(), pool(0) {}
+    AST(); 
     ~AST();
 
   /// @}
@@ -93,7 +92,6 @@
     const std::string& getSystemID() const { return sysid; }
     const std::string& getPublicID() const { return pubid; }
     Pool* getPool() const { return pool; }
-    SignatureType* getProgramType();
 
   /// @}
   /// @name Mutators
@@ -102,19 +100,10 @@
     void setSystemID(const std::string& id) { sysid = id; }
     void setPublicID(const std::string& id) { pubid = id; }
     void addBundle(Bundle* b) { bundles.push_back(b); }
-
-  /// @}
-  /// @name Lookup
-  /// @{
-  public:
-    /// Get one of the primitive types directly by its identifier
-    Type* getPrimitiveType(NodeIDs kind);
-
-    /// Resolve a type name into a Type and allow for forward referencing.
-    Type* resolveType(const std::string& name);
-
-    /// Get a standard pointer type to the element type Ty.
-    PointerType* getPointerTo(const Type* Ty);
+    virtual void setParent(Node* parent);
+  protected:
+    virtual void insertChild(Node* child);
+    virtual void removeChild(Node* child);
 
   /// @}
   /// @name Iterators
@@ -182,6 +171,7 @@
     /// Create a new Function node. 
     Function* new_Function(
       const std::string& id, ///< The name of the function
+      Bundle* B,             ///< The bundle this function goes in
       const SignatureType* type,   ///< The type of the function
       const Locator* loc = 0 ///< The source locator
     );
@@ -191,20 +181,29 @@
     /// (entry points) in the same compilation unit.
     Program* new_Program(
       const std::string& id, ///< The name of the program
+      Bundle* B,             ///< The bundle this program goes in
       const Locator* loc = 0 ///< The source locator
     );
+    Type* new_IntrinsicType(
+      const std::string& id,  ///< The name for the new type
+      Bundle* bundle,         ///< The bundle to put the new type into
+      IntrinsicTypes it,      ///< The node ID for the primitive to create
+      const Locator* loc = 0  ///< The source locator
+    );
     /// Create a new IntegerType node. This is a general interface for creating
     /// integer types. By default it creates a signed 32-bit integer.
     IntegerType* new_IntegerType(
       const std::string& id,  ///< The name of the type
+      Bundle* bundle,         ///< The bundle to insert the type into
       uint16_t bits = 32,     ///< The number of bits
       bool isSigned = true,   ///< The signedness
-      const Locator* loc = 0  ///< The locator of the declaration
+      const Locator* loc = 0  ///< The source locator
     );
     /// Create a new RangeType node. RangeType nodes are integer nodes that
     /// perform range checking to ensure the assigned values are kept in range
     RangeType* new_RangeType(
       const std::string& id,  ///< The name of the type
+      Bundle* bundle,         ///< The bundle to insert the type into
       int64_t min,            ///< The minimum value accepted in range
       int64_t max,            ///< The maximum value accepted in range
       const Locator*loc = 0   ///< The locator of the declaration
@@ -214,6 +213,7 @@
     /// enumeration.
     EnumerationType* new_EnumerationType(
       const std::string& id,   ///< The name of the type
+      Bundle* bundle,         ///< The bundle to insert the type into
       const Locator*loc = 0    ///< The locator of the declaration
     );
     /// Create a new RealType node. This is the generalized interface for 
@@ -221,6 +221,7 @@
     /// precision floating point type.
     RealType* new_RealType(
       const std::string& id,  ///< The name of the type
+      Bundle* bundle,         ///< The bundle to insert the type into
       uint32_t mantissa = 52, ///< The bits in the mantissa (fraction)
       uint32_t exponent = 11, ///< The bits in the exponent
       const Locator* loc = 0   ///< The locator 
@@ -229,55 +230,59 @@
     /// value of any other HLVM type. 
     AnyType* new_AnyType(
       const std::string& id, ///< The name of the type
-      const Locator* loc = 0  ///< The source locator 
-    );
-    /// Create a new StringType node. A StringType node is a type that holds a
-    /// sequence of UTF-8 encoded characters.
-    StringType* new_StringType(
-      const std::string& id, ///< The name of the type
+      Bundle* bundle,         ///< The bundle to insert the type into
       const Locator* loc = 0  ///< The source locator 
     );
     /// Create a new BooleanType node. A BooleanType has a simple binary value,
     /// true or false.
     BooleanType* new_BooleanType(
       const std::string& id,  ///< The name of the type
+      Bundle* bundle,         ///< The bundle to insert the type into
       const Locator* loc = 0  ///< The source locator
     );
     /// Create a new BufferType node. A BufferType is a runtime type that is
     /// used to buffer input and output.
     BufferType* new_BufferType(
       const std::string& id,  ///< The name of the type
+      Bundle* bundle,         ///< The bundle to insert the type into
       const Locator* loc = 0  ///< The source locator
     );
     /// Create a new TextType node. A TextType is a runtime type that is
     /// used to represent unicode strings of text.
     TextType* new_TextType(
       const std::string& id,  ///< The name of the type
+      Bundle* bundle,         ///< The bundle to insert the type into
       const Locator* loc = 0  ///< The source locator
     );
     /// Create a new StreamType node. A StreamType is a runtime type that is
     /// used as a handle for input/output streams.
     StreamType* new_StreamType(
       const std::string& id,  ///< The name of the type
+      Bundle* bundle,         ///< The bundle to insert the type into
       const Locator* loc = 0  ///< The source locator
     );
     /// Create a new CharacterType node. A CharacterType represents a single 
     /// textual character in UTF-16 encoding.
     CharacterType* new_CharacterType(
       const std::string& id,  ///< The name of the type
+      Bundle* bundle,         ///< The bundle to insert the type into
+      const std::string& enc, ///< The name of the encoding for the character
       const Locator* loc = 0  ///< The source locator
     );
-    /// Create a new OctetType node. An OctetType represents an 8-bit 
-    /// non-numerical quantity. You can't do arithmetic with octets.
-    OctetType* new_OctetType(
+    /// Create a new StringType node. A StringType node is a type that holds a
+    /// sequence of UTF-8 encoded characters.
+    StringType* new_StringType(
       const std::string& id,  ///< The name of the type
-      const Locator*loc = 0   ///< The source locator
+      Bundle* bundle,         ///< The bundle to insert the type into
+      const std::string& enc, ///< The name of the encoding for the string
+      const Locator* loc = 0  ///< The source locator 
     );
     /// Create a new PointerType node. A PointerType just refers to a location
     /// of some other type.
     PointerType* new_PointerType(
       const std::string& id,  ///< The name of the pointer type
-      Type* target,           ///< The referent type
+      Bundle* bundle,         ///< The bundle to insert the type into
+      const Type* target,     ///< The referent type
       const Locator* loc = 0  ///< The source locator
     );
     /// Create a new ArrayType node. An ArrayType is a sequential arrangement of
@@ -285,6 +290,7 @@
     /// or shrunk, but not beyond the maxSize parameter. 
     ArrayType* new_ArrayType(
       const std::string& id,  ///< The name of the array type
+      Bundle* bundle,         ///< The bundle to insert the type into
       Type* elemType,         ///< The element type
       uint64_t maxSize,       ///< The maximum number of elements in the array
       const Locator* loc = 0  ///< The source locator
@@ -294,6 +300,7 @@
     /// a vector's size is always constant.
     VectorType* new_VectorType(
       const std::string& id,  ///< The name of the vector type
+      Bundle* bundle,         ///< The bundle to insert the type into
       Type* elemType,         ///< The element type
       uint64_t size,          ///< The number of elements in the vector
       const Locator* loc = 0  ///< The source locator
@@ -325,6 +332,7 @@
     /// definite types.
     StructureType* new_StructureType(
       const std::string& id,  ///< The name of the structure type
+      Bundle* bundle,         ///< The bundle to insert the type into
       const Locator* loc = 0  ///< The source locator
     );
     /// Create a new ContinuationType node. A ContinuationType is a type that 
@@ -332,6 +340,7 @@
     /// definite types combined with the data necessary to make a continuation.
     ContinuationType* new_ContinuationType(
       const std::string& id,  ///< The name of the structure type
+      Bundle* bundle,         ///< The bundle to insert the type into
       const Locator* loc = 0  ///< The source locator
     );
     /// Create a new SignatureType node. A SignatureType specifies the type of
@@ -339,6 +348,7 @@
     /// function and the type of its result value.
     SignatureType* new_SignatureType(
       const std::string& id,  ///< The name of the function signature type
+      Bundle* bundle,         ///< The bundle to insert the type into
       const Type *resultType, ///< The result type of the function
       bool isVarArgs = false, ///< Indicates variable number of arguments
       const Locator* loc = 0  ///< The source locator
@@ -348,148 +358,82 @@
     /// be exposed. You cannot create an object of OpaqueType but you can 
     /// obtain its location.
     OpaqueType* new_OpaqueType(
-      const std::string& id, ///< The name of the opaque type
-      const Locator* loc = 0 ///< The source locator
+      const std::string& id,  ///< The name of the opaque type
+      bool is_unresolved,     ///< Indicates whether this is an unresolved type
+      Bundle* bundle,         ///< The bundle to insert the type into
+      const Locator* loc = 0  ///< The source locator
     );
-    /// Create a new 128 bit primitive floating point type.
-    RealType* new_f128(
-      const std::string& id,  ///< The name of the 128-bit floating point type
-      const Locator* loc = 0  ///< The source locator
-    ) { return new_RealType(id,112,15,loc); }
-    /// Create a new 80 bit primitive floating point type.
-    RealType* new_f80(
-      const std::string& id,  ///< The name of the 80-bit floating point type
-      const Locator* loc = 0  ///< The source locator
-    ) { return new_RealType(id,64,15,loc); }
-    /// Create a new 64 bit primitive floating point type.
-    RealType* new_f64(
-      const std::string& id,  ///< The name of the 64-bit floating point type
-      const Locator* loc = 0  ///< The source locator
-    ) { return new_RealType(id,52,11,loc); }
-    /// Create a new 44 bit primitive floating point type.
-    RealType* new_f44(
-      const std::string& id,  ///< The name of the 44-bit floating point type
-      const Locator* loc = 0  ///< The source locator
-    ) { return new_RealType(id,32,11,loc); }
-    /// Create a new 32 bit primitive floating point type.
-    RealType* new_f32(
-      const std::string& id,  ///< The name of teh 32-bit floating point type
-      const Locator* loc = 0  ///< The source locator
-    ) { return new_RealType(id,23,8,loc); }
-    /// Create a new 128 bit primitive signed integer point type.
-    IntegerType* new_s128(
-      const std::string& id,  ///< The name of the 128-bit signed integer type
-      const Locator* loc = 0  ///< The source locator
-    ) { return new_IntegerType(id,128,true,loc); }
-    /// Create a new 64 bit primitive signed integer point type.
-    IntegerType* new_s64(
-      const std::string& id,  ///< The name of the 64-bit signed integer type
-      const Locator* loc = 0  ///< The source locator
-    ) { return new_IntegerType(id,64,true,loc); }
-    /// Create a new 32 bit primitive signed integer point type.
-    IntegerType* new_s32(
-      const std::string& id,  ///< The name of teh 32-bit signed integer type
-      const Locator* loc = 0  ///< The source locator
-    ) { return new_IntegerType(id,32,true,loc); }
-    /// Create a new 16 bit primitive signed integer point type.
-    IntegerType* new_s16(
-      const std::string& id,  ///< The name of the 16-bit signed integer type
-      const Locator* loc = 0  ///< THe source locator
-    ) { return new_IntegerType(id,16,true,loc); }
-    /// Create a new 8 bit primitive signed integer point type.
-    IntegerType* new_s8(
-      const std::string& id,  ///< The name of the 8-bit signed integer type
-      const Locator* l = 0    ///< The source locator
-    ) { return new_IntegerType(id,8,true,loc); }
-    /// Create a new 128 bit primitive unsigned integer point type.
-    IntegerType* new_u128(
-      const std::string& id,  ///< The name of the 128-bit unsigned integer type
-      const Locator* l = 0    ///< The source locator
-    ) { return new_IntegerType(id,128,false,loc); }
-    /// Create a new 64 bit primitive unsigned integer point type.
-    IntegerType* new_u64(
-      const std::string& id,  ///< The name of the 64-bit unsigned integer type
-      const Locator* l = 0    ///< The source locator
-    ) { return new_IntegerType(id,64,false,loc); }
-    /// Create a new 32 bit primitive unsigned integer point type.
-    IntegerType* new_u32(
-      const std::string& id,  ///< The name of the 32-bit unsigned integer type
-      const Locator* l = 0    ///< The source locator
-    ) { return new_IntegerType(id,32,false,loc); }
-    /// Create a new 16 bit primitive unsigned integer point type.
-    IntegerType* new_u16(
-      const std::string& id,  ///< The name of the 16-bit unsigned integer type
-      const Locator* l = 0    ///< The source locator
-    ) { return new_IntegerType(id,16,false,loc); }
-    /// Create a new 8 bit primitive unsigned integer point type.
-    IntegerType* new_u8(
-      const std::string& id,  ///< The name of the 8-bit unsigned integer type
-      const Locator* l = 0    ///< The source locator
-    ) { return new_IntegerType(id,8,false,loc); }
     /// Create a new Variable node. A Variable node represents a storage
     /// location. Variables can be declared in Bundles, Functions and Blocks.
     /// Their life span is the lifespan of the container in which they are
     /// declared.
     Variable* new_Variable(
       const std::string& id,  ///< The name of the variable
+      Bundle* bundle,         ///< The bundle to insert the type into
       const Type* ty,         ///< The type of the variable
       const Locator* loc = 0  ///< The source locator
     );
     /// Createa new ConstantAny node
     ConstantAny* new_ConstantAny(
       const std::string& name,///< The name of the constant
+      Bundle* bundle,         ///< The bundle to insert the type into
+      const Type* Ty,         ///< The type for this constant
       ConstantValue* val,     ///< The value for the constant
       const Locator* loc = 0  ///< The source locator
     );
     /// Createa new ConstantBoolean node
     ConstantBoolean* new_ConstantBoolean(
       const std::string& name,///< The name of the constant
+      Bundle* bundle,         ///< The bundle to insert the type into
+      const Type* Ty,         ///< The type for this constant
       bool t_or_f,            ///< The value for the constant
       const Locator* loc = 0  ///< The source locator
     );
     /// Createa new ConstantCharacter node
     ConstantCharacter* new_ConstantCharacter(
       const std::string& name,///< The name of the constant
+      Bundle* bundle,         ///< The bundle to insert the type into
+      const Type* Ty,         ///< The type for this constant
       const std::string& val, ///< The value for the constant
       const Locator* loc = 0  ///< The source locator
     );
     /// Createa new ConstantEnumerator node
     ConstantEnumerator* new_ConstantEnumerator(
       const std::string& name,///< The name of the constant
+      Bundle* bundle,         ///< The bundle to insert the type into
+      const Type* Ty,         ///< The type for this constant
       const std::string& val, ///< The value for the constant
-      const Type* Ty,         ///< The type of the enumerator
-      const Locator* loc = 0  ///< The source locator
-    );
-    /// Createa new ConstantOctet node
-    ConstantOctet* new_ConstantOctet(
-      const std::string& name,///< The name of the constant
-      unsigned char val,      ///< The value for the constant
       const Locator* loc = 0  ///< The source locator
     );
     /// Create a new ConstantInteger node.
     ConstantInteger* new_ConstantInteger(
       const std::string& name,///< The name of the constant
+      Bundle* bundle,         ///< The bundle to insert the type into
+      const Type* Ty,         ///< The type for this constant
       const std::string& val, ///< The value of the ConstantInteger
       uint16_t base,          ///< The numeric base the value is encoded in
-      const Type* Ty,         ///< The type of the integer
       const Locator* loc = 0  ///< The source locator
     );
     /// Create a new ConstantReal node.
     ConstantReal* new_ConstantReal(
       const std::string& name,///< The name of the constant
+      Bundle* bundle,         ///< The bundle to insert the type into
+      const Type* Ty,         ///< The type for this constant
       const std::string& val, ///< The value of the ConstantReal
-      const Type* Ty,         ///< The type of the real
       const Locator* loc = 0  ///< The source locator
     );
     /// Create a new ConstantString node.
     ConstantString* new_ConstantString(
       const std::string& name,///< The name of the constant
+      Bundle* bundle,         ///< The bundle to insert the type into
+      const Type* Ty,         ///< The type for this constant
       const std::string& value, ///< The value of the ConstantText
       const Locator* loc = 0    ///< The source locator
     );
     /// Create a new ConstantPointer node.
     ConstantPointer* new_ConstantPointer(
       const std::string& name,  ///< The name of the constant
+      Bundle* bundle,         ///< The bundle to insert the type into
       const Type* type,         ///< The type of the constant pointer
       Constant* referent,       ///< The value pointed to
       const Locator* loc = 0    ///< The source locator
@@ -497,29 +441,33 @@
     /// Create a new ConstantArray node.
     ConstantArray* new_ConstantArray(
       const std::string& name,  ///< The name of the constant
-      const std::vector<ConstantValue*>& elems, ///< The elements of the array
+      Bundle* bundle,         ///< The bundle to insert the type into
       const ArrayType* Ty,      ///< The type of the array
+      const std::vector<ConstantValue*>& elems, ///< The elements of the array
       const Locator* loc = 0    ///< The source locator
     );
     /// Create a new ConstantVector node.
     ConstantVector* new_ConstantVector(
       const std::string& name,  ///< The name of the constant
-      const std::vector<ConstantValue*>& elems, ///< The elements of the array
+      Bundle* bundle,         ///< The bundle to insert the type into
       const VectorType* Ty,     ///< The type of the array
+      const std::vector<ConstantValue*>& elems, ///< The elements of the array
       const Locator* loc = 0    ///< The source locator
     );
     /// Create a new ConstantStructure node.
     ConstantStructure* new_ConstantStructure(
       const std::string& name,  ///< The name of the constant
-      const std::vector<ConstantValue*>& elems, ///< The elements of the array
+      Bundle* bundle,         ///< The bundle to insert the type into
       const StructureType* Ty,  ///< The type of the array
+      const std::vector<ConstantValue*>& elems, ///< The elements of the array
       const Locator* loc = 0    ///< The source locator
     );
     /// Create a new ConstantContinuation node.
     ConstantContinuation* new_ConstantContinuation(
       const std::string& name,  ///< The name of the constant
-      const std::vector<ConstantValue*>& elems, ///< The elements of the array
+      Bundle* bundle,         ///< The bundle to insert the type into
       const ContinuationType* Ty,  ///< The type of the array
+      const std::vector<ConstantValue*>& elems, ///< The elements of the array
       const Locator* loc = 0    ///< The source locator
     );
     /// Create a unary ConstantExpression Node.
@@ -561,6 +509,7 @@
     /// Provide a template function for creating standard nilary operators
     template<class OpClass>
     OpClass* new_NilaryOp(
+      Bundle* bundle,        ///< The bundle, for type lookup
       const Locator* loc = 0 ///< The source locator
     );
 
@@ -568,6 +517,7 @@
     template<class OpClass>
     OpClass* new_UnaryOp(
       Operator* oprnd1,         ///< The first operand
+      Bundle* bundle,        ///< The bundle, for type lookup
       const Locator* loc = 0 ///< The source locator
     );
 
@@ -576,6 +526,7 @@
     OpClass* new_BinaryOp(
       Operator* oprnd1,         ///< The first operand
       Operator* oprnd2,         ///< The second operand
+      Bundle* bundle,        ///< The bundle, for type lookup
       const Locator* loc = 0 ///< The source locator
     );
 
@@ -585,6 +536,7 @@
       Operator* oprnd1,         ///< The first operand
       Operator* oprnd2,         ///< The second operand
       Operator* oprnd3,         ///< The third operand
+      Bundle* bundle,        ///< The bundle, for type lookup
       const Locator* loc = 0 ///< The source locator
     );
 
@@ -593,9 +545,14 @@
     template<class OpClass>
     OpClass* new_MultiOp(
       const std::vector<Operator*>& o, ///< The list of operands
-      const Locator* loc = 0
+      Bundle* bundle,        ///< The bundle, for type lookup
+      const Locator* loc = 0 ///< The source locator
     );
 
+    /// A function to remove an old node. The to_be_deleted node will no longer
+    /// be available after this call.
+    void old(Node* to_be_deleted);
+
   protected:
     template<class OpClass>
     OpClass* new_NilaryOp(

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Bundle.cpp (original)
+++ hlvm/trunk/hlvm/AST/Bundle.cpp Sat Jul  7 19:02:42 2007
@@ -27,9 +27,10 @@
 /// @brief Implements the functions of class hlvm::AST::Bundle.
 //===----------------------------------------------------------------------===//
 
+#include <hlvm/AST/AST.h>
 #include <hlvm/AST/Bundle.h>
-#include <hlvm/AST/Type.h>
 #include <hlvm/AST/Linkables.h>
+#include <hlvm/AST/IntrinsicTypesTokenizer.h>
 #include <hlvm/Base/Assert.h>
 #include <llvm/Support/Casting.h>
 
@@ -43,9 +44,23 @@
 Bundle::insertChild(Node* kid)
 {
   hlvmAssert(kid && "Null child!");
-  if (Type* Ty = dyn_cast<Type>(kid))
-    types.insert(Ty);
-  else if (Constant* C = dyn_cast<Constant>(kid)) {
+  if (Type* ty = dyn_cast<Type>(kid)) {
+    if (Type* n = unresolvedTypes.lookup(ty->getName())) {
+      OpaqueType* ot = llvm::cast<OpaqueType>(n);
+      // FIXME: we should really keep a use list in the type object so this is
+      // more efficient, but it will do for now.
+      for (tlist_iterator I = tlist_begin(), E = tlist_end(); I != E; ++I) {
+        (*I)->resolveTypeTo(ot,ty);
+      }
+      for (clist_iterator I = clist_begin(), E = clist_end(); I != E; ++I ) {
+        (*I)->resolveTypeTo(ot,ty);
+      }
+      unresolvedTypes.erase(ot);
+      // getRoot()->old(ot);
+    }
+    tlist.push_back(ty);
+    ttable.insert(ty);
+  } else if (Constant* C = dyn_cast<Constant>(kid)) {
     clist.push_back(C);
     ctable.insert(C);
   } else
@@ -56,9 +71,11 @@
 Bundle::removeChild(Node* kid)
 {
   hlvmAssert(kid && "Null child!");
-  if (const Type* Ty = dyn_cast<Type>(kid))
-    types.erase(Ty->getName());
-  else if (Constant* C = dyn_cast<Constant>(kid)) {
+  if (const Type* Ty = dyn_cast<Type>(kid)) {
+    for (tlist_iterator I = tlist_begin(), E = tlist_end(); I != E; ++I )
+      if (*I == Ty) { tlist.erase(I); break; }
+    ttable.erase(Ty->getName());
+  } else if (Constant* C = dyn_cast<Constant>(kid)) {
     // This is sucky slow, but we probably won't be removing nodes that much.
     for (clist_iterator I = clist_begin(), E = clist_end(); I != E; ++I )
       if (*I == C) { clist.erase(I); break; }
@@ -67,16 +84,176 @@
     hlvmAssert(!"That node isn't my child");
 }
 
-Type*  
-Bundle::find_type(const std::string& name) const
+SignatureType* 
+Bundle::getProgramType()
 {
-  if (Node* result = types.lookup(name))
-    return llvm::cast<Type>(result);
+  Type *type = getType("ProgramType");
+  if (!type) {
+    AST* ast = getRoot();
+    Type* intType = getIntrinsicType(s32Ty);
+    SignatureType* sig = 
+      ast->new_SignatureType("ProgramType",this,intType,false);
+    sig->setIsIntrinsic(true);
+    Parameter* argc = ast->new_Parameter("argc",intType);
+    PointerType* arg_type = getPointerTo(getIntrinsicType(stringTy));
+    arg_type->setIsIntrinsic(true);
+    PointerType* argv_type = getPointerTo(arg_type);
+    argv_type->setIsIntrinsic(true);
+    Parameter* argv = ast->new_Parameter("argv",argv_type);
+    sig->addParameter(argc);
+    sig->addParameter(argv);
+    return sig;
+  } else if (SignatureType* sig = llvm::dyn_cast<SignatureType>(type))
+    return sig;
+  else
+    hlvmAssert(!"Invalid use of ProgramType");
+}
+
+IntrinsicTypes 
+Bundle::getIntrinsicTypesValue(const std::string& name)
+{
+  int token = HLVM_AST::IntrinsicTypesTokenizer::recognize(name.c_str());
+  if (token == HLVM_AST::TKN_NONE)
+    return NoIntrinsicType;
+  switch (token) {
+    case HLVM_AST::TKN_bool:            return boolTy; break;
+    case HLVM_AST::TKN_buffer:          return bufferTy; break;
+    case HLVM_AST::TKN_char:            return charTy; break;
+    case HLVM_AST::TKN_double:          return doubleTy; break;
+    case HLVM_AST::TKN_f32:             return f32Ty; break;
+    case HLVM_AST::TKN_f44:             return f44Ty; break;
+    case HLVM_AST::TKN_f64:             return f64Ty; break;
+    case HLVM_AST::TKN_f80:             return f80Ty; break;
+    case HLVM_AST::TKN_f96:             return f96Ty; break;
+    case HLVM_AST::TKN_f128:            return f128Ty; break;
+    case HLVM_AST::TKN_float:           return floatTy; break;
+    case HLVM_AST::TKN_int:             return intTy; break;
+    case HLVM_AST::TKN_long:            return longTy; break;
+    case HLVM_AST::TKN_octet:           return octetTy; break;
+    case HLVM_AST::TKN_r8:              return r8Ty; break;
+    case HLVM_AST::TKN_r16:             return r16Ty; break;
+    case HLVM_AST::TKN_r32:             return r32Ty; break;
+    case HLVM_AST::TKN_r64:             return r64Ty; break;
+    case HLVM_AST::TKN_s8:              return s8Ty; break;
+    case HLVM_AST::TKN_s16:             return s16Ty; break;
+    case HLVM_AST::TKN_s32:             return s32Ty; break;
+    case HLVM_AST::TKN_s64:             return s64Ty; break;
+    case HLVM_AST::TKN_s128:            return s128Ty; break;
+    case HLVM_AST::TKN_short:           return shortTy; break;
+    case HLVM_AST::TKN_stream:          return streamTy; break;
+    case HLVM_AST::TKN_string:          return stringTy; break;
+    case HLVM_AST::TKN_text:            return textTy; break;
+    case HLVM_AST::TKN_u8:              return u8Ty; break;
+    case HLVM_AST::TKN_u16:             return u16Ty; break;
+    case HLVM_AST::TKN_u32:             return u32Ty; break;
+    case HLVM_AST::TKN_u64:             return u64Ty; break;
+    case HLVM_AST::TKN_u128:            return u128Ty; break;
+    case HLVM_AST::TKN_void:            return voidTy; break;
+    default:  return NoIntrinsicType;
+  }
+}
+
+void
+Bundle::getIntrinsicName(IntrinsicTypes id, std::string& name)
+{
+  switch (id) 
+  {
+    case boolTy:            name = "bool" ; break;
+    case bufferTy:          name = "buffer"; break;
+    case charTy:            name = "char"; break;
+    case doubleTy:          name = "double"; break;
+    case f32Ty:             name = "f32"; break;
+    case f44Ty:             name = "f44" ; break;
+    case f64Ty:             name = "f64" ; break;
+    case f80Ty:             name = "f80"; break;
+    case f96Ty:             name = "f96"; break;
+    case f128Ty:            name = "f128"; break;
+    case floatTy:           name = "float"; break;
+    case intTy:             name = "int"; break;
+    case longTy:            name = "long"; break;
+    case octetTy:           name = "octet"; break;
+    case r8Ty:              name = "r8"; break;
+    case r16Ty:             name = "r16"; break;
+    case r32Ty:             name = "r32"; break;
+    case r64Ty:             name = "r64"; break;
+    case s8Ty:              name = "s8"; break;
+    case s16Ty:             name = "s16"; break;
+    case s32Ty:             name = "s32"; break;
+    case s64Ty:             name = "s64"; break;
+    case s128Ty:            name = "s128"; break;
+    case shortTy:           name = "short"; break;
+    case streamTy:          name = "stream"; break;
+    case stringTy:          name = "string"; break;
+    case textTy:            name = "text"; break;
+    case u8Ty:              name = "u8"; break;
+    case u16Ty:             name = "u16"; break;
+    case u32Ty:             name = "u32"; break;
+    case u64Ty:             name = "u64"; break;
+    case u128Ty:            name = "u128"; break;
+    case voidTy:            name = "void"; break;
+    default:
+      hlvmDeadCode("Invalid Primitive");
+      name = "unknown";
+      break;
+  }
+}
+
+Type* 
+Bundle::getIntrinsicType(IntrinsicTypes id)
+{
+  std::string name;
+  getIntrinsicName(id, name);
+  Type* Ty = getType(name);
+  if (!Ty) {
+    Ty = getRoot()->new_IntrinsicType(name, this, id);
+    Ty->setIsIntrinsic(true);
+  }
+  return Ty;
+}
+
+Type*
+Bundle::getIntrinsicType(const std::string& name)
+{
+  IntrinsicTypes it = getIntrinsicTypesValue(name);
+  if (it == NoIntrinsicType)
+    return 0;
+  return getIntrinsicType(it);
+}
+
+PointerType* 
+Bundle::getPointerTo(const Type* Ty)
+{
+  hlvmAssert(Ty != 0);
+  std::string ptr_name = Ty->getName() + "*";
+  Type* t = getType(ptr_name);
+  if (!t || !llvm::isa<PointerType>(t))
+    t = getRoot()->new_PointerType(ptr_name,this,Ty);
+  return llvm::cast<PointerType>(t);
+}
+
+Type*
+Bundle::getType(const std::string& name)
+{
+  if (Type* t = ttable.lookup(name))
+    return t;
+  if (Type* t = unresolvedTypes.lookup(name))
+    return t;
   return 0;
 }
 
+Type*
+Bundle::getOrCreateType(const std::string& name)
+{
+  Type* t = getType(name);
+  if (!t) {
+    t = getRoot()->new_OpaqueType(name,true,this);
+    unresolvedTypes.insert(t);
+  }
+  return t;
+}
+
 Constant*  
-Bundle::find_const(const std::string& name) const
+Bundle::getConst(const std::string& name) const
 {
   if (Constant* result = ctable.lookup(name))
     return llvm::cast<Constant>(result);

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Bundle.h (original)
+++ hlvm/trunk/hlvm/AST/Bundle.h Sat Jul  7 19:02:42 2007
@@ -40,6 +40,49 @@
 class Type;
 class Linkable;
 
+/// This type enumerates the intrinsic types. Intrinsic types are those which
+/// are intrinsic to HLVM. They are well known, have immutable names, and are
+/// generally fundamental in character.
+/// @brief AST Intrinsic Types Enum
+enum IntrinsicTypes {
+  NoIntrinsicType, ///< This is used for errors, etc.
+  boolTy,     ///< The boolean type
+  FirstIntrinsicType = boolTy,
+  bufferTy,   ///< The memory buffer type
+  charTy,     ///< The UTF-8 character type
+  doubleTy,   ///< 64-bit IEEE 754 double precision
+  f32Ty,      ///< 32-bit IEEE 754 single precision 
+  f44Ty,      ///< 43-bit IEEE 754 extended single precision 
+  f64Ty,      ///< 64-bit IEEE 754 double precision
+  f80Ty,      ///< 80-bit IEEE 754 extended double precision
+  f96Ty,      ///< 96-bit IEEE 754 long extended double precision
+  f128Ty,     ///< 128-bit IEEE 754 quad precision
+  floatTy,    ///< 32-bit IEEE 754 single precision
+  intTy,      ///< Signed 32-bit integer quantity
+  longTy,     ///< Signed 64-bit integer quantity
+  octetTy,    ///< Unsigned 8-bit integer quantity, not computable
+  r8Ty,       ///< Range checked signed 8-bit integer quantity
+  r16Ty,      ///< Range checked signed 16-bit integer quantity
+  r32Ty,      ///< Range checked signed 32-bit integer quantity
+  r64Ty,      ///< Range checked signed 64-bit integer quantity
+  s8Ty,       ///< Signed 8-bit integer quantity
+  s16Ty,      ///< Signed 16-bit integer quantity
+  s32Ty,      ///< Signed 32-bit integer quantity
+  s64Ty,      ///< Signed 64-bit integer quantity
+  s128Ty,     ///< Signed 128-bit integer quantity
+  shortTy,    ///< Signed 16-bit integer quantity
+  streamTy,   ///< The I/O stream type
+  stringTy,   ///< The UTF-8 string type
+  textTy,     ///< The UTF-8 text type
+  u8Ty,       ///< Unsigned 8-bit integer quantity
+  u16Ty,      ///< Unsigned 16-bit integer quantity
+  u32Ty,      ///< Unsigned 32-bit integer quantity
+  u64Ty,      ///< Unsigned 64-bit integer quantity
+  u128Ty,     ///< Unsigned 128-bit integer quantity
+  voidTy,     ///< OpaqueType, 0-bits, non-readable, non-writable
+  LastIntrinsicType = u128Ty
+};
+
 /// This class is simply a collection of definitions. Things that can be 
 /// defined in a bundle include types, global variables, functions, classes,
 /// etc. A bundle is the unit of linking and loading. A given compilation unit 
@@ -54,9 +97,13 @@
   /// @name Types
   /// @{
   public:
+    typedef std::vector<Type*> TypeList;
+    typedef TypeList::iterator tlist_iterator;
+    typedef TypeList::const_iterator tlist_const_iterator;
+
     typedef SymbolTable<Type> TypeTable;
-    typedef TypeTable::iterator type_iterator;
-    typedef TypeTable::const_iterator type_const_iterator;
+    typedef TypeTable::iterator ttable_iterator;
+    typedef TypeTable::const_iterator ttable_const_iterator;
 
     typedef std::vector<Constant*> ConstantList;
     typedef ConstantList::iterator clist_iterator;
@@ -70,7 +117,8 @@
   /// @name Constructors
   /// @{
   protected:
-    Bundle() : Documentable(BundleID), name(), types(), clist(), ctable() {}
+    Bundle() 
+      : Documentable(BundleID), name(), tlist(), ttable(), clist(), ctable() {}
     virtual ~Bundle();
 
   /// @}
@@ -90,26 +138,57 @@
     virtual void removeChild(Node* kid);
 
   /// @}
-  /// @name Finders
+  /// @name Type Management
   /// @{
   public:
-    Type*      find_type(const std::string& n) const;
-    Constant*  find_const(const std::string& n) const;
+    /// Return the type of a program, named ProgramType
+    SignatureType* getProgramType();
+
+    /// Get the Intrinsic Id from the intrinsic's name
+    IntrinsicTypes getIntrinsicTypesValue(const std::string& name);
+
+    /// Get the standard name of one of the primitive types
+    void getIntrinsicName(IntrinsicTypes ty, std::string& name);
+
+    /// Get one of the intrinsic types directly by its identifier
+    Type* getIntrinsicType(IntrinsicTypes ty);
+
+    /// Get one of the intrinsic types by its name
+    Type* getIntrinsicType(const std::string& name);
+
+    /// Get a standard pointer type to the element type Ty.
+    PointerType* getPointerTo(const Type* Ty);
+
+    /// Resolve a type name into a Type and allow for forward referencing.
+    Type* getOrCreateType(const std::string& name);
+
+    /// Get an existing type by name or 0 if there is no such type
+    Type*      getType(const std::string& n);
+
+    /// Get an existing constant by name or 0 if there is no such constant
+    Constant*  getConst(const std::string& n) const;
 
   /// @}
   /// @name Iterators
   /// @{
   public:
-    /// Type iteration
-    type_iterator           type_begin()       { return types.begin(); }
-    type_const_iterator     type_begin() const { return types.begin(); }
-    type_iterator           type_end  ()       { return types.end(); }
-    type_const_iterator     type_end  () const { return types.end(); }
-    size_t                  type_size () const { return types.size(); }
-    bool                    type_empty() const { return types.empty(); }
+    // Type Insertion Order Iteration
+    tlist_iterator          tlist_begin()       { return tlist.begin(); }
+    tlist_const_iterator    tlist_begin() const { return tlist.begin(); }
+    tlist_iterator          tlist_end  ()       { return tlist.end(); }
+    tlist_const_iterator    tlist_end  () const { return tlist.end(); }
+    size_t                  tlist_size () const { return tlist.size(); }
+    bool                    tlist_empty() const { return tlist.empty(); }
+
+    /// Type Symbol Table Iteration
+    ttable_iterator         ttable_begin()       { return ttable.begin(); }
+    ttable_const_iterator   ttable_begin() const { return ttable.begin(); }
+    ttable_iterator         ttable_end  ()       { return ttable.end(); }
+    ttable_const_iterator   ttable_end  () const { return ttable.end(); }
+    size_t                  ttable_size () const { return ttable.size(); }
+    bool                    ttable_empty() const { return ttable.empty(); }
 
     /// Value Insertion Order Iteration
-    //
     clist_iterator          clist_begin()       { return clist.begin(); }
     clist_const_iterator    clist_begin() const { return clist.begin(); }
     clist_iterator          clist_end  ()       { return clist.end(); }
@@ -117,7 +196,7 @@
     size_t                  clist_size () const { return clist.size(); }
     bool                    clist_empty() const { return clist.empty(); }
 
-    /// ConstantValue Symbol Table iteration
+    /// Value Symbol Table Iteration
     ctable_iterator         ctable_begin()       { return ctable.begin(); }
     ctable_const_iterator   ctable_begin() const { return ctable.begin(); }
     ctable_iterator         ctable_end  ()       { return ctable.end(); }
@@ -130,7 +209,8 @@
   /// @{
   protected:
     std::string   name;      ///< The name for this bundle
-    TypeTable     types;     ///< The list of types
+    TypeList      tlist;     ///< The list of types
+    TypeTable     ttable;    ///< The list of types
     TypeTable     unresolvedTypes; ///< The list of forward referenced types
     ConstantList  clist;    ///< The list of values in insertion order
     ConstantTable ctable;

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Constants.cpp (original)
+++ hlvm/trunk/hlvm/AST/Constants.cpp Sat Jul  7 19:02:42 2007
@@ -40,12 +40,12 @@
 ConstantBoolean::~ConstantBoolean() { }
 ConstantCharacter::~ConstantCharacter() { }
 ConstantEnumerator::~ConstantEnumerator() { }
-ConstantOctet::~ConstantOctet() { }
 ConstantInteger::~ConstantInteger() { }
 ConstantReal::~ConstantReal() { }
 ConstantString::~ConstantString() { }
 ConstantPointer::~ConstantPointer() { }
 ConstantAggregate::~ConstantAggregate() { }
+
 void 
 ConstantAggregate::insertChild(Node* n)
 {

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Constants.h (original)
+++ hlvm/trunk/hlvm/AST/Constants.h Sat Jul  7 19:02:42 2007
@@ -192,36 +192,6 @@
 /// This class provides an Abstract Syntax Tree node that yields a 
 /// constant octet value. 
 /// @brief AST Constant Octet Node
-class ConstantOctet: public ConstantValue
-{
-  /// @name Constructors
-  /// @{
-  protected:
-    ConstantOctet(unsigned char val) : ConstantValue(ConstantOctetID) { 
-      value = val; }
-    virtual ~ConstantOctet();
-
-  /// @}
-  /// @name Accessors
-  /// @{
-  public:
-    unsigned char getValue() const { return value; }
-    static inline bool classof(const ConstantOctet*) { return true; }
-    static inline bool classof(const Node* N) 
-      { return N->is(ConstantOctetID); }
-
-  /// @}
-  /// @name Data
-  /// @{
-  public:
-    unsigned char value;
-  /// @}
-  friend class AST;
-};
-
-/// This class provides an Abstract Syntax Tree node that yields a 
-/// constant octet value. 
-/// @brief AST Constant Octet Node
 class ConstantEnumerator: public ConstantValue
 {
   /// @name Constructors

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

==============================================================================
--- hlvm/trunk/hlvm/AST/ContainerType.cpp (original)
+++ hlvm/trunk/hlvm/AST/ContainerType.cpp Sat Jul  7 19:02:42 2007
@@ -46,11 +46,27 @@
   return 0;
 }
 
+void 
+UniformContainerType::resolveTypeTo(const Type* from, const Type* to)
+{
+  hlvmAssert(isa<OpaqueType>(from) && !isa<OpaqueType>(to));
+  if (elemType == from)
+    elemType = to;
+}
+
 PointerType::~PointerType() { }
 ArrayType::~ArrayType() { }
 VectorType::~VectorType() { }
 NamedType::~NamedType() {}
 
+void 
+NamedType::resolveTypeTo(const Type* from, const Type* to)
+{
+  hlvmAssert(isa<OpaqueType>(from) && !isa<OpaqueType>(to));
+  if (type == from)
+    type = to;
+}
+
 DisparateContainerType::~DisparateContainerType() { }
 
 const char* 
@@ -60,9 +76,26 @@
   return 0;
 }
 
+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) {
+      (*I)->setType(to);
+    }
+}
+
+
 StructureType::~StructureType() { }
 ContinuationType::~ContinuationType() { }
 
 SignatureType::~SignatureType() { }
+void SignatureType::resolveTypeTo(const Type* from, const Type* to)
+{
+  DisparateContainerType::resolveTypeTo(from,to);
+  if (result == from)
+    result = to;
+}
 
 }

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

==============================================================================
--- hlvm/trunk/hlvm/AST/ContainerType.h (original)
+++ hlvm/trunk/hlvm/AST/ContainerType.h Sat Jul  7 19:02:42 2007
@@ -65,6 +65,7 @@
   /// @name Mutators
   /// @{
   public:
+    virtual void resolveTypeTo(const Type* from, const Type* to);
     void setElementType(const Type* t) { elemType = t; }
 
   /// @}
@@ -226,6 +227,7 @@
     /// Set the size of the vector.
     void setName(const std::string& N) { name = N; }
     void setType(const Type* Ty) { type = Ty; }
+    void resolveTypeTo(const Type* from, const Type* to);
 
   /// @}
   /// @name Data
@@ -272,7 +274,8 @@
   /// @}
   /// @name Mutators
   /// @{
-  protected:
+  public:
+    virtual void resolveTypeTo(const Type* from, const Type* to);
     void setTypes(const std::vector<NamedType*>& Types) { contents = Types; }
     void addType(NamedType* NT )
       { contents.push_back(NT); }
@@ -392,7 +395,7 @@
   /// @{
   public:
     const Type* getResultType() const { return result; }
-    bool  isVarArgs() const { return flags != 0; }
+    bool  isVarArgs() const { return flags & IsVarArgsTF; }
 
     /// Methods to support type inquiry via is, cast, dyn_cast
     static inline bool classof(const SignatureType*) { return true; }
@@ -404,9 +407,11 @@
   /// @{
   public:
     void setResultType(const Type* ty) { result = ty; }
-    void setIsVarArgs(bool is) { flags = is ? 1 : 0; }
+    void setIsVarArgs(bool is) { 
+      if (is) flags |= IsVarArgsTF; else  flags &= ~IsVarArgsTF; }
     void setParameters(const std::vector<Parameter*>& param) { setTypes(param);}
     void addParameter(Parameter* param) { addType(param); }
+    virtual void resolveTypeTo(const Type* from, const Type* to);
 
   /// @}
   /// @name Data

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Linkables.cpp (original)
+++ hlvm/trunk/hlvm/AST/Linkables.cpp Sat Jul  7 19:02:42 2007
@@ -72,6 +72,16 @@
   }
 }
 
+void 
+Function::resolveTypeTo(const Type* from, const Type* to)
+{
+  Linkable::resolveTypeTo(from,to);
+  for (iterator I = begin(), E = end(); I != E; ++I) {
+    (*I)->resolveTypeTo(from,to);
+  }
+  block->resolveTypeTo(from,to);
+}
+
 Program::~Program() { }
 
 }

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Linkables.h (original)
+++ hlvm/trunk/hlvm/AST/Linkables.h Sat Jul  7 19:02:42 2007
@@ -240,6 +240,7 @@
     virtual void removeChild(Node* kid);
     void setBlock(Block* blk) { blk->setParent(this); }
     void addArgument(Argument* arg) { args.push_back(arg); }
+    virtual void resolveTypeTo(const Type* from, const Type* to);
 
   /// @}
   /// @name Data

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Node.cpp (original)
+++ hlvm/trunk/hlvm/AST/Node.cpp Sat Jul  7 19:02:42 2007
@@ -99,4 +99,11 @@
 {
 }
 
+void 
+Value::resolveTypeTo(const Type* from, const Type* to)
+{
+  if (type == from)
+    type = to;
+}
+
 }

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Node.h (original)
+++ hlvm/trunk/hlvm/AST/Node.h Sat Jul  7 19:02:42 2007
@@ -50,7 +50,7 @@
 /// @brief Identifiers of th AST Node Types.
 enum NodeIDs 
 {
-  NoTypeID = 0,            ///< Use this for an invalid type ID.
+  NoNodeID = 0,            ///< Use this for an invalid node ID.
 
   // SUBCLASSES OF NODE
   TreeTopID,               ///< The AST node which is always root of the tree
@@ -62,40 +62,18 @@
   ImportID,                ///< A bundle's Import declaration
 
   // SUBCLASSES OF TYPE
-  // Primitive Types (inherently supported by HLVM)
-  BooleanTypeID,           ///< The Boolean Type (A simple on/off boolean value)
-FirstTypeID          = BooleanTypeID,
-FirstPrimitiveTypeID = BooleanTypeID,
-  CharacterTypeID,         ///< The Character Type (UTF-16 encoded character)
-  OctetTypeID,             ///< The Octet Type (8 bits uninterpreted)
-  UInt8TypeID,             ///< Unsigned 8-bit integer quantity
-  UInt16TypeID,            ///< Unsigned 16-bit integer quantity
-  UInt32TypeID,            ///< Unsigned 32-bit integer quantity
-  UInt64TypeID,            ///< Unsigned 64-bit integer quantity
-  UInt128TypeID,           ///< Unsigned 128-bit integer quantity
-  SInt8TypeID,             ///< Signed 8-bit integer quantity
-  SInt16TypeID,            ///< Signed 16-bit integer quantity
-  SInt32TypeID,            ///< Signed 32-bit integer quantity
-  SInt64TypeID,            ///< Signed 64-bit integer quantity
-  SInt128TypeID,           ///< Signed 128-bit integer quantity
-  Float32TypeID,           ///< 32-bit IEEE single precision 
-  Float44TypeID,           ///< 43-bit IEEE extended single precision 
-  Float64TypeID,           ///< 64-bit IEEE double precision
-  Float80TypeID,           ///< 80-bit IEEE extended double precision
-  Float128TypeID,          ///< 128-bit IEEE quad precision
-LastPrimitiveTypeID  = Float128TypeID, 
-
-  // Simple Types (no nested classes)
+  // Basic Types 
   AnyTypeID,               ///< The Any Type (Union of any type)
-FirstSimpleTypeID    = AnyTypeID,
-  StringTypeID,            ///< A string of characters type
+FirstTypeID          = AnyTypeID,
+  BooleanTypeID,           ///< The Boolean Type (A simple on/off boolean value)
+  CharacterTypeID,         ///< The Character Type (UTF-8 encoded character)
+  EnumerationTypeID,       ///< The Enumeration Type (set of enumerated ids)
   IntegerTypeID,           ///< The Integer Type (A # of bits of integer data)
+  OpaqueTypeID,            ///< A placeholder for unresolved types
   RangeTypeID,             ///< The Range Type (A Range of Integer Values)
-  EnumerationTypeID,       ///< The Enumeration Type (set of enumerated ids)
   RealTypeID,              ///< The Real Number Type (Any Real Number)
   RationalTypeID,          ///< The Rational Number Type (p/q type number)
-  OpaqueTypeID,            ///< A placeholder for unresolved types
-LastSimpleTypeID     = OpaqueTypeID,  
+  StringTypeID,            ///< A string of characters type
 
   // Uniform Container Types
   PointerTypeID,           ///< The Pointer Type (Pointer To object of Type)
@@ -137,7 +115,6 @@
 FirstConstantValueID = ConstantAnyID,
   ConstantBooleanID,       ///< A constant boolean value
   ConstantCharacterID,     ///< A constant UTF-8 character value
-  ConstantOctetID,         ///< A constant 8-bit value
   ConstantEnumeratorID,    ///< A constant enumeration value
   ConstantIntegerID,       ///< A constant integer value
   ConstantRealID,          ///< A constant real value
@@ -312,115 +289,97 @@
   /// @{
   public:
     /// Get the AST root node that this Node is part of.
-    inline AST* getRoot(); 
+    AST* getRoot(); 
 
     /// Return the bundle that contains this Node.
     Bundle* getContainingBundle() const;
 
     /// Get the type of node
-    inline NodeIDs getID() const { return NodeIDs(id); }
+    NodeIDs getID() const { return NodeIDs(id); }
 
     /// Get the parent node
-    inline Node* getParent() const { return parent; }
+    Node* getParent() const { return parent; }
 
     /// Get the flags
-    inline unsigned getFlags() const { return flags; }
+    unsigned getFlags() const { return flags; }
 
     /// Get the Locator
-    inline const Locator* getLocator() const { return loc; }
+    const Locator* getLocator() const { return loc; }
 
     /// Determine if the node is a specific kind
-    inline bool is(NodeIDs kind) const { return id == unsigned(kind); }
+    bool is(NodeIDs kind) const { return id == unsigned(kind); }
 
     /// Determine if the node is a Type
-    inline bool isType() const {
+    bool isType() const {
       return id >= FirstTypeID && 
              id <= LastTypeID; }
 
-    inline bool isIntegerType() const {
-      return (id >= UInt8TypeID && id <= SInt128TypeID) || id == IntegerTypeID;}
-
-    inline bool isIntegralType()  const { 
-      return isIntegerType() || (id == RangeTypeID) || 
+    bool isIntegralType()  const { 
+      return (id == IntegerTypeID) || (id == RangeTypeID) || 
         (id == EnumerationTypeID) || (id == BooleanTypeID);  }
 
-    inline bool isRealType() const {
-      return (id >= Float32TypeID && id <= Float128TypeID) ||
-             (id == RealTypeID); }
-
-    inline bool isNumericType() const {
-      return isIntegralType() || isRealType() || id == RangeTypeID; }
-
-    /// Determine if the node is a primitive type
-    inline bool isPrimitiveType() const {
-      return id >= FirstPrimitiveTypeID && 
-             id <= LastPrimitiveTypeID; }
-
-    /// Determine if the node is a simple type
-    inline bool isSimpleType() const {
-      return id >= FirstSimpleTypeID && 
-             id <= LastSimpleTypeID;
-    }
+    bool isNumericType() const {
+      return isIntegralType() || id == RealTypeID; }
 
     /// Determine if the node is a uniform container type
-    inline bool isUniformContainerType() const {
+    bool isUniformContainerType() const {
       return id >= FirstUniformContainerTypeID && 
              id <= LastUniformContainerTypeID;
     }
+
     /// Determine if the node is a disparate container type
-    inline bool isDisparateContainerType() const {
+    bool isDisparateContainerType() const {
       return id >= FirstDisparateContainerTypeID && 
              id <= LastDisparateContainerTypeID; }
 
     /// Determine if the node is a runtime type
-    inline bool isRuntimeType() const {
+    bool isRuntimeType() const {
       return id >= FirstRuntimeTypeID &&
              id <= LastRuntimeTypeID; }
 
     /// Determine if the node is a container type
-    inline bool isContainerType() const {
+    bool isContainerType() const {
       return id >= FirstContainerTypeID && id <= LastContainerTypeID;
     }
     /// Determine if the node is one of the Constant values.
-    inline bool isConstant() const {
+    bool isConstant() const {
       return id >= FirstConstantID && id <= LastConstantID; }
 
     /// Determine if the node is one of the Constant values.
-    inline bool isConstantValue() const {
+    bool isConstantValue() const {
       return id >= FirstConstantValueID && id <= LastConstantValueID; }
 
     /// Determine if the node is one of the ConstantAggregate values.
-    inline bool isConstantAggregate() const {
+    bool isConstantAggregate() const {
       return id >= FirstConstantAggregateID && id <= LastConstantAggregateID; }
 
     /// Determine if the node is a Linkable
-    inline bool isLinkable() const {
+    bool isLinkable() const {
       return id >= FirstLinkableID && id <= LastLinkableID; }
 
     /// Determine if the node is any of the Operators
-    inline bool isOperator() const { 
+    bool isOperator() const { 
       return id >= FirstOperatorID && id <= LastOperatorID; }
 
-    inline bool isTerminator() const {
+    bool isTerminator() const {
       return (id >= BreakOpID && id <= ReturnOpID) || (id == ThrowOpID); }
 
-    inline bool isLoop() const {
-      return id == LoopOpID || (id >= WhileOpID && id <= UntilOpID);
-    }
+    bool isLoop() const {
+      return id == LoopOpID || (id >= WhileOpID && id <= UntilOpID); }
 
-    inline bool isNilaryOperator() const {
+    bool isNilaryOperator() const {
       return id >= FirstNilaryOperatorID && id <= LastNilaryOperatorID; }
 
-    inline bool isUnaryOperator() const {
+    bool isUnaryOperator() const {
       return id >= FirstUnaryOperatorID && id <= LastUnaryOperatorID; }
 
-    inline bool isBinaryOperator() const {
+    bool isBinaryOperator() const {
       return id >= FirstBinaryOperatorID && id <= LastBinaryOperatorID; }
 
-    inline bool isTernaryOperator() const {
+    bool isTernaryOperator() const {
       return id >= FirstTernaryOperatorID && id <= LastTernaryOperatorID; }
 
-    inline bool isMultiOperator() const {
+    bool isMultiOperator() const {
       return id >= FirstMultiOperatorID && id <= LastMultiOperatorID; }
 
     /// Determine if the node is a Documentable Node
@@ -431,7 +390,7 @@
     bool isValue() const { 
       return id >= FirstValueID && id <= LastValueID; }
 
-    inline bool isFunction() const 
+    bool isFunction() const 
       { return id == FunctionID || id == ProgramID; }
 
     /// Provide support for isa<X> and friends
@@ -585,6 +544,7 @@
   /// @{
   public:
     void setType(const Type* t) { type = t; }
+    virtual void resolveTypeTo(const Type* from, const Type* to);
 
   /// @}
   /// @name Data

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Operator.cpp (original)
+++ hlvm/trunk/hlvm/AST/Operator.cpp Sat Jul  7 19:02:42 2007
@@ -152,6 +152,14 @@
     hlvmAssert(!"Can't remove child from UnaryOperator");
 }
 
+void 
+UnaryOperator::resolveTypeTo(const Type* from, const Type* to)
+{
+  Operator::resolveTypeTo(from,to);
+  if(op1)
+    op1->resolveTypeTo(from,to);
+}
+
 BinaryOperator::~BinaryOperator()
 {
 }
@@ -201,6 +209,17 @@
     hlvmAssert(!"Can't remove child from BinaryOperator");
 }
 
+void 
+BinaryOperator::resolveTypeTo(const Type* from, const Type* to)
+{
+  Operator::resolveTypeTo(from,to);
+  if(ops[0])
+    ops[0]->resolveTypeTo(from,to);
+  if(ops[1])
+    ops[1]->resolveTypeTo(from,to);
+
+}
+
 TernaryOperator::~TernaryOperator()
 {
 }
@@ -255,6 +274,19 @@
     hlvmAssert(!"Can't remove child from TernaryOperator!");
 }
 
+void 
+TernaryOperator::resolveTypeTo(const Type* from, const Type* to)
+{
+  Operator::resolveTypeTo(from,to);
+  if(ops[0])
+    ops[0]->resolveTypeTo(from,to);
+  if(ops[1])
+    ops[1]->resolveTypeTo(from,to);
+  if(ops[2])
+    ops[2]->resolveTypeTo(from,to);
+
+}
+
 MultiOperator::~MultiOperator()
 {
 }
@@ -310,4 +342,12 @@
   }
 }
 
+void 
+MultiOperator::resolveTypeTo(const Type* from, const Type* to)
+{
+  Operator::resolveTypeTo(from,to);
+  for (iterator I = begin(), E = end(); I != E; ++I )
+    (*I)->resolveTypeTo(from,to);
+}
+
 }

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Operator.h (original)
+++ hlvm/trunk/hlvm/AST/Operator.h Sat Jul  7 19:02:42 2007
@@ -154,6 +154,7 @@
   /// @{
   public:
     virtual void setOperand(unsigned opnum, Operator* oprnd);
+    virtual void resolveTypeTo(const Type* from, const Type* to);
   protected:
     virtual void insertChild(Node* child);
     virtual void removeChild(Node* child);
@@ -193,6 +194,7 @@
   /// @{
   public:
     virtual void setOperand(unsigned opnum, Operator* oprnd);
+    virtual void resolveTypeTo(const Type* from, const Type* to);
   protected:
     virtual void insertChild(Node* child);
     virtual void removeChild(Node* child);
@@ -232,6 +234,7 @@
   /// @{
   public:
     virtual void setOperand(unsigned opnum, Operator* oprnd);
+    virtual void resolveTypeTo(const Type* from, const Type* to);
   protected:
     virtual void insertChild(Node* child);
     virtual void removeChild(Node* child);
@@ -297,6 +300,7 @@
   /// @{
   public:
     virtual void setOperand(unsigned opnum, Operator* oprnd);
+    virtual void resolveTypeTo(const Type* from, const Type* to);
     void addOperand(Operator* v) { v->setParent(this); }
     void addOperands(const OprndList& new_ops); 
   protected:

Modified: hlvm/trunk/hlvm/AST/SConscript
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/SConscript?rev=38365&r1=38364&r2=38365&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/SConscript (original)
+++ hlvm/trunk/hlvm/AST/SConscript Sat Jul  7 19:02:42 2007
@@ -22,6 +22,10 @@
 #===----------------------------------------------------------------------===#
 from build import hlvm
 Import('env')
-lib = env.StaticLibrary('HLVMAST',hlvm.GetAllCXXFiles(env))
+hlvm.GetRNGTokenizer(env)
+env.RNGTokenizer('IntrinsicTypesTokenizer.cpp','IntrinsicTypes.rng')
+env.Depends('Bundle.o','IntrinsicTypesTokenizer.cpp')
+lib = env.StaticLibrary('HLVMAST',
+  hlvm.GetAllCXXFiles(env)+['IntrinsicTypesTokenizer.cpp'])
 hlvm.InstallLibrary(env,lib)
 hlvm.InstallHeader(env,hlvm.GetFiles(env,'*.h'))

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

==============================================================================
--- hlvm/trunk/hlvm/AST/SymbolTable.cpp (original)
+++ hlvm/trunk/hlvm/AST/SymbolTable.cpp Sat Jul  7 19:02:42 2007
@@ -37,20 +37,6 @@
 
 namespace hlvm {
 
-template<class ElemType>
-std::string 
-SymbolTable<ElemType>::getUniqueName(const std::string &base_name) const {
-  std::string try_name = base_name;
-  const_iterator end = map_.end();
-
-  // See if the name exists. Loop until we find a free name in the symbol table
-  // by incrementing the last_unique_ counter.
-  while (map_.find(&try_name) != end)
-    try_name = base_name + 
-      llvm::utostr(++last_unique_);
-  return try_name;
-}
-
 // lookup a node by name - returns null on failure
 template<class ElemType>
 ElemType* SymbolTable<ElemType>::lookup(const std::string& name) const {
@@ -86,9 +72,8 @@
 void SymbolTable<ElemType>::insert(ElemType* N) {
   hlvmAssert(N && "Can't insert null node into symbol table!");
 
-  // Check to see if there is a naming conflict.  If so, rename this type!
-  if (lookup(N->getName()))
-    N->setName(getUniqueName(N->getName()));
+  // It is an error to reuse a name
+  hlvmAssert(0 == lookup(N->getName()));
 
   // Insert the map entry
   map_.insert(make_pair(&N->getName(), N));

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

==============================================================================
--- hlvm/trunk/hlvm/AST/SymbolTable.h (original)
+++ hlvm/trunk/hlvm/AST/SymbolTable.h Sat Jul  7 19:02:42 2007
@@ -71,12 +71,6 @@
 /// @name Accessors
 /// @{
 public:
-  /// Generates a unique name for a node based on the \p BaseName by
-  /// incrementing an integer and appending it to the name, if necessary
-  /// @returns the unique name
-  /// @brief Get a unique name for a node
-  std::string getUniqueName(const std::string &BaseName) const;
-
   /// This method finds the node with the given \p name in the node map
   /// and returns it.
   /// @returns null if the name is not found, otherwise the ElemType
@@ -140,8 +134,6 @@
 /// @{
 private:
   NodeMap map_; ///< This is the mapping of names to types.
-  mutable uint64_t order_;  
-  mutable uint64_t last_unique_; ///< Counter for tracking unique names
 /// @}
 };
 

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Type.cpp (original)
+++ hlvm/trunk/hlvm/AST/Type.cpp Sat Jul  7 19:02:42 2007
@@ -48,6 +48,12 @@
   return 0;
 }
 
+void 
+Type::resolveTypeTo(const Type* from, const Type* to)
+{
+  // Do nothing, no nested types
+}
+
 AnyType::~AnyType()
 {
 }
@@ -125,16 +131,6 @@
   hlvmDeadCode("Primitive Name");
 }
 
-OctetType::~OctetType()
-{
-}
-
-const char* 
-OctetType::getPrimitiveName() const
-{
-  return "octet";
-}
-
 RangeType::~RangeType()
 {
 }

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Type.h (original)
+++ hlvm/trunk/hlvm/AST/Type.h Sat Jul  7 19:02:42 2007
@@ -35,6 +35,13 @@
 namespace hlvm 
 {
 
+enum TypeFlags {
+  IntrinsicTF    = 0x0001, ///< Set if the type is intrinsic
+  SignedTF       = 0x0002, ///< Set if IntegerType is signed
+  IsVarArgsTF    = 0x0004, ///< Set if Signature is variable argument length
+  UnresolvedTF   = 0x0008  ///< Set if the type is unresolved (OpaqueType)
+};
+
 /// This class provides the Abstract Syntax Tree base class for all Types. A
 /// Type describes the memory layout of a Value. There are many subclasses of
 /// of Type, each with a particular way of describing memory layout. In HLVM,
@@ -53,11 +60,20 @@
   /// @name Accessors
   /// @{
   public:
+    bool isIntrinsic() const { return flags & IntrinsicTF; }
     const std::string& getName() const { return name; }
     virtual const char* getPrimitiveName() const;
     bool isPrimitive() const { return getPrimitiveName() != 0; }
 
   /// @}
+  /// @name Mutators
+  /// @{
+  protected:
+    void setIsIntrinsic(bool is) { 
+      if (is) flags |= IntrinsicTF; else flags &= ~IntrinsicTF; }
+    virtual void resolveTypeTo(const Type* from, const Type* to);
+
+  /// @}
   /// @name Type Identification
   /// @{
   public:
@@ -85,9 +101,9 @@
     std::string name;
   /// @}
   friend class AST;
+  friend class Bundle;
 };
 
-
 /// This class provides an Abstract Syntax Tree node for describing a type that
 /// can accept any type of Value. The AnyType can be used to represent
 /// dynamically typed variables and it, essentially, bypasses the HLVM type 
@@ -118,31 +134,6 @@
   friend class AST;
 };
 
-/// This class provides an Abstract Syntax Tree node for describing a character
-/// string type. The StringType value is a sequence of UTF-8 encoded characters
-/// with a null terminator.
-/// @brief AST String Type
-class StringType : public Type
-{
-  /// @name Constructors
-  /// @{
-  protected:
-    StringType() : Type(StringTypeID) {}
-    virtual ~StringType();
-
-  /// @}
-  /// @name Accessors
-  /// @{
-  public:
-    virtual const char* getPrimitiveName() const;
-
-    // Methods to support type inquiry via is, cast, dyn_cast
-    static inline bool classof(const StringType*) { return true; }
-    static inline bool classof(const Node* T) { return T->is(StringTypeID); }
-  /// @}
-  friend class AST;
-};
-
 /// This class provides an Abstract Syntax Tree node to represent the boolean
 /// type. Booleans have a simple true-or-false value and could be represented by
 /// a single bit.
@@ -176,7 +167,7 @@
   /// @name Constructors
   /// @{
   protected:
-    CharacterType() : Type(CharacterTypeID) {}
+    CharacterType(const std::string& E) : Type(CharacterTypeID), encoding(E) {}
     virtual ~CharacterType();
 
   /// @}
@@ -184,35 +175,55 @@
   /// @{
   public:
     virtual const char* getPrimitiveName() const;
+    const std::string& getEncoding() const { return encoding; }
+
     // Methods to support type inquiry via is, cast, dyn_cast
     static inline bool classof(const CharacterType*) { return true; }
     static inline bool classof(const Node* T) { return T->is(CharacterTypeID); }
+
+  /// @}
+  /// @name Data
+  /// @{
+  public:
+    std::string encoding;
   /// @}
   friend class AST;
 };
 
-/// This class provides an Abstract Syntax Tree node that represents an octet
-/// type. Octets are simply 8 bits of data without interpretation. Octets are
-/// used as the element type of a buffer. Octets cannot be used in arithmetic
-/// computation. They simply hold 8 bits of data.  Octets are commonly used in
-/// stream I/O to represent the raw data flowing on the stream. 
-/// @brief AST Octet Type
-class OctetType : public Type
+/// This class provides an Abstract Syntax Tree node for describing a character
+/// string type. The StringType value is a sequence of unicode characters. Each
+/// String type specifies the encoding to use for the characters. Strings treat
+/// their content as a single unit. It is not possible to manipulate the 
+/// individual characters of which the string is composed. String-typed
+/// locations can be assigned new string-typed values but the strings are
+/// treated as atomic units. To edit sequential characters, use a Text type.
+/// @see Text
+/// @see Character
+/// @brief AST String Type
+class StringType : public Type
 {
   /// @name Constructors
   /// @{
   protected:
-    OctetType() : Type(OctetTypeID) {}
-    virtual ~OctetType();
+    StringType(const std::string& E) : Type(StringTypeID), encoding(E) {}
+    virtual ~StringType();
 
   /// @}
   /// @name Accessors
   /// @{
   public:
     virtual const char* getPrimitiveName() const;
+    const std::string& getEncoding() const { return encoding; }
+
     // Methods to support type inquiry via is, cast, dyn_cast
-    static inline bool classof(const OctetType*) { return true; }
-    static inline bool classof(const Node* T) { return T->is(OctetTypeID); }
+    static inline bool classof(const StringType*) { return true; }
+    static inline bool classof(const Node* T) { return T->is(StringTypeID); }
+
+  /// @}
+  /// @name Data
+  /// @{
+  public:
+    std::string encoding;
   /// @}
   friend class AST;
 };
@@ -236,29 +247,15 @@
   /// @{
   protected:
     IntegerType(
-      NodeIDs id,  ///< The node type identifier, passed on to Node base class
-      int16_t bits = 32, ///< The number of bits in this integer type
+      uint16_t bits = 32, ///< The number of bits in this integer type
       bool sign = true ///< Indicates if this is a signed integer type, or not.
-    ) : Type(id) {
+    ) : Type(IntegerTypeID) {
       setBits(bits);
       setSigned(sign); 
     }
     virtual ~IntegerType();
 
   /// @}
-  /// @name Constants
-  /// @{
-  public:
-    /// The enum defines various masks and shifts to interpret the bits in
-    /// the Node's flag field.
-    enum FlagsMasks {
-      BitsMask = 0x7FFF, ///< Mask the # of bits, 10 bits
-      SignMask = 0x8000, ///< Mask the sign bit, 1 bit
-      BitsShift = 0,     ///< Bits to shift flags to get # of bits 
-      SignShift = 15     ///< Bits to shift flags to get sign bit
-    };
-
-  /// @}
   /// @name Accessors
   /// @{
   public:
@@ -267,28 +264,32 @@
     virtual const char* getPrimitiveName() const;
 
     /// @brief Return the number of bits in this integer type
-    uint16_t getBits()  const { return uint16_t((flags & BitsMask)>>BitsShift);}
+    uint16_t getBits()  const { return bits; }
 
     /// @brief Return the signedness of this type
-    bool isSigned() const { return flags & SignMask; }
+    bool isSigned() const { return flags & SignedTF; }
 
     /// @brief Methods to support type inquiry via isa, cast, dyn_cast
     static inline bool classof(const IntegerType*) { return true; }
-    static inline bool classof(const Node* T) { return T->isIntegerType(); }
+    static inline bool classof(const Node* T) { return T->is(IntegerTypeID); }
 
   /// @}
   /// @name Mutators
   /// @{
   public:
     /// @brief Set the number of bits for this integer type
-    void setBits(uint16_t bits) { 
-      flags &= ~BitsMask; flags |= (bits << BitsShift) & BitsMask; }
+    void setBits(uint16_t numBits) { bits = numBits; }
 
     /// @brief Set the signedness of the type
     void setSigned(bool isSigned) { 
-      if (isSigned) flags |= SignMask; else flags &= ~SignMask; }
+      if (isSigned) flags |= SignedTF; else flags &= ~SignedTF; }
 
   /// @}
+  /// @name Data
+  /// @{
+  public:
+    uint16_t bits;
+  /// @}
   friend class AST;
 };
 
@@ -305,7 +306,7 @@
   /// @name Constructors
   /// @{
   protected:
-    RangeType() : Type(RangeTypeID), min(0), max(256) {}
+    RangeType(uint64_t n, uint64_t x) : Type(RangeTypeID), min(n), max(x) {}
     virtual ~RangeType();
 
   /// @}
@@ -324,16 +325,6 @@
     static inline bool classof(const Node* T) { return T->is(RangeTypeID); }
 
   /// @}
-  /// @name Mutators
-  /// @{
-  public:
-    /// Set min value of range
-    void setMin(int64_t val) { min = val; }
-
-    /// Set max value of range
-    void setMax(int64_t val) { max = val; }
-
-  /// @}
   /// @name Data
   /// @{
   protected:
@@ -424,8 +415,8 @@
   /// @name Constructors
   /// @{
   protected:
-    RealType(NodeIDs id, uint32_t m=52, uint32_t x=11) 
-      : Type(id), mantissa(m), exponent(x) {}
+    RealType(uint32_t m=52, uint32_t x=11) 
+      : Type(RealTypeID), mantissa(m), exponent(x) {}
     virtual ~RealType();
 
   /// @}
@@ -439,6 +430,11 @@
     /// Get the exponent bits
     uint32_t getExponent() const { return exponent; }
 
+    /// Get the total number of bits
+    uint32_t getBits() const { 
+      return 1 + getMantissa() + getExponent();
+    }
+
     // Methods to support type inquiry via is, cast, dyn_cast
     static inline bool classof(const RealType*) { return true; }
     static inline bool classof(const Node* T) { return T->is(RealTypeID); }
@@ -486,11 +482,18 @@
   /// @name Accessors
   /// @{
   public:
+    bool isUnresolved() { return flags & UnresolvedTF; }
     static inline bool classof(const OpaqueType*) { return true; }
     static inline bool classof(const Node* N) 
       { return N->is(OpaqueTypeID); }
 
   /// @}
+  /// @name Mutators
+  /// @{
+  public:
+    void setIsUnresolved(bool B) {
+      if (B) flags |= UnresolvedTF; else flags &= ~UnresolvedTF; }
+  /// @}
   friend class AST;
 };
 

Modified: hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp?rev=38365&r1=38364&r2=38365&view=diff

==============================================================================
--- hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp (original)
+++ hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp Sat Jul  7 19:02:42 2007
@@ -469,28 +469,6 @@
   switch (ty->getID()) {
     case BooleanTypeID:            result = llvm::Type::BoolTy; break;
     case CharacterTypeID:          result = llvm::Type::UShortTy; break;
-    case OctetTypeID:              result = llvm::Type::SByteTy; break;
-    case UInt8TypeID:              result = llvm::Type::UByteTy; break;
-    case UInt16TypeID:             result = llvm::Type::UShortTy; break;
-    case UInt32TypeID:             result = llvm::Type::UIntTy; break;
-    case UInt64TypeID:             result = llvm::Type::ULongTy; break;
-    case UInt128TypeID: 
-      hlvmNotImplemented("128 bit primitive integer");
-      break;
-    case SInt8TypeID:              result = llvm::Type::SByteTy; break;
-    case SInt16TypeID:             result = llvm::Type::ShortTy; break;
-    case SInt32TypeID:             result = llvm::Type::IntTy; break;
-    case SInt64TypeID:             result = llvm::Type::LongTy; break;
-    case SInt128TypeID: 
-      hlvmNotImplemented("128 bit primitive integer");
-      break;
-    case Float32TypeID:             result = llvm::Type::FloatTy; break;
-    case Float64TypeID:             result = llvm::Type::DoubleTy; break;
-    case Float44TypeID: 
-    case Float80TypeID: 
-    case Float128TypeID: 
-      hlvmNotImplemented("extended and quad floating point");
-      break;
     case AnyTypeID:
       hlvmNotImplemented("Any Type");
       break;
@@ -498,10 +476,35 @@
       result = llvm::PointerType::get(llvm::Type::SByteTy);
       break;
     case IntegerTypeID:
-      hlvmNotImplemented("arbitrary precision integer");
+    {
+      const IntegerType* IT = llvm::cast<hlvm::IntegerType>(ty);
+      uint16_t bits = IT->getBits();
+      if (bits <= 8)
+        result = (IT->isSigned() ? llvm::Type::SByteTy : llvm::Type::UByteTy);
+      else if (bits <= 16)
+        result = (IT->isSigned() ? llvm::Type::ShortTy : llvm::Type::UShortTy);
+      else if (bits <= 32)
+        result = (IT->isSigned() ? llvm::Type::IntTy : llvm::Type::UIntTy);
+      else if (bits <= 64)
+        result = (IT->isSigned() ? llvm::Type::LongTy : llvm::Type::ULongTy);
+      else if (bits <= 128)
+        hlvmNotImplemented("128-bit integer");
+      else
+        hlvmNotImplemented("arbitrary precision integer");
       break;
+    }
     case RealTypeID:
-      hlvmNotImplemented("arbitrary precision real");
+    {
+      const RealType *RT = llvm::cast<hlvm::RealType>(ty);
+      uint16_t bits = RT->getBits();
+      if (bits <= 32)
+        result = llvm::Type::FloatTy;
+      else if (bits <= 64)
+        result = llvm::Type::DoubleTy;
+      else
+        hlvmNotImplemented("arbitrary precision real");
+      break;
+    }
     case TextTypeID:
       result = get_hlvm_text();
       break;
@@ -1916,6 +1919,14 @@
       case ConstantStringID:        
         getConstant(llvm::cast<ConstantString>(n));
         break;
+      case ConstantAnyID:
+      case ConstantStructureID:
+      case ConstantArrayID:
+      case ConstantVectorID:
+      case ConstantContinuationID:
+      case ConstantPointerID:
+        hlvmAssert(!"Not implemented yet");
+        break;
       case VariableID:              
         getVariable(llvm::cast<Variable>(n)); 
         break;
@@ -1971,20 +1982,22 @@
     switch (n->getID()) 
     {
       case AnyTypeID:
-      case StringTypeID:
+      case ArrayTypeID:
       case BooleanTypeID:
+      case BufferTypeID:
       case CharacterTypeID:
+      case EnumerationTypeID:
       case IntegerTypeID:
+      case OpaqueTypeID:
+      case PointerTypeID:
       case RangeTypeID:
-      case EnumerationTypeID:
+      case RationalTypeID:
       case RealTypeID:
-      case OctetTypeID:
-      case PointerTypeID:
-      case ArrayTypeID:
-      case VectorTypeID:
+      case StreamTypeID:
+      case StringTypeID:
       case StructureTypeID:
       case SignatureTypeID:
-      case OpaqueTypeID:
+      case VectorTypeID:
       {
         Type* t = llvm::cast<Type>(n);
         lmod->addTypeName(t->getName(), getType(t));

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

==============================================================================
--- hlvm/trunk/hlvm/Pass/Pass.cpp (original)
+++ hlvm/trunk/hlvm/Pass/Pass.cpp Sat Jul  7 19:02:42 2007
@@ -153,10 +153,10 @@
 {
   hlvmAssert(b && "Null bundle?");
   runPreOrder(b);
-  for (Bundle::type_iterator TI = b->type_begin(), TE = b->type_end(); 
+  for (Bundle::tlist_iterator TI = b->tlist_begin(), TE = b->tlist_end(); 
        TI != TE; ++TI) {
-    runPreOrder(const_cast<Type*>(TI->second));
-    runPostOrder(const_cast<Type*>(TI->second));
+    runPreOrder(const_cast<Type*>(*TI));
+    runPostOrder(const_cast<Type*>(*TI));
   }
   for (Bundle::clist_iterator CI = b->clist_begin(), CE = b->clist_end(); 
        CI != CE; ++CI) {

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

==============================================================================
--- hlvm/trunk/hlvm/Pass/Validate.cpp (original)
+++ hlvm/trunk/hlvm/Pass/Validate.cpp Sat Jul  7 19:02:42 2007
@@ -350,19 +350,13 @@
 }
 
 template<> inline void
-ValidateImpl::validate(OctetType* n)
-{
-  checkType(n,OctetTypeID);
-}
-
-template<> inline void
 ValidateImpl::validate(IntegerType* n)
 {
   if (checkNode(n))
-    if (!n->isIntegerType())
+    if (!n->is(IntegerTypeID))
       error(n,"Bad ID for IntegerType");
     else if (n->getBits() == 0)
-      error(n,"Invalid number of bits");
+      error(n,"Integer type cannot have zero bits");
 }
 
 template<> inline void
@@ -392,7 +386,7 @@
 ValidateImpl::validate(RealType* n)
 {
   if (checkNode(n))
-    if (!n->isRealType())
+    if (!n->is(RealTypeID))
       error(n,"Bad ID for RealType");
     else {
       uint64_t bits = n->getMantissa() + n->getExponent();
@@ -498,12 +492,6 @@
 }
 
 template<> inline void
-ValidateImpl::validate(ConstantOctet* n)
-{
-  checkConstant(n,ConstantOctetID);
-}
-
-template<> inline void
 ValidateImpl::validate(ConstantInteger* CI)
 {
   if (checkConstant(CI,ConstantIntegerID)) {
@@ -549,23 +537,8 @@
       error(CR,"Invalid real constant. Conversion failed.");
     else {
       // It converted to a double okay, check that it is in range
-      unsigned numBits = 0;
-      switch (CR->getType()->getID()) {
-        case Float32TypeID: numBits = 32; break;
-        case Float44TypeID: numBits = 44; break;
-        case Float64TypeID: numBits = 64; break;
-        case Float80TypeID: numBits = 80; break;
-        case Float128TypeID: numBits = 128; break;
-        case RealTypeID: 
-        {
-          const RealType* Ty = llvm::cast<RealType>(CR->getType());
-          numBits = Ty->getMantissa() + Ty->getExponent() + 1; 
-          break;
-        }
-        default:
-          error(CR,"Invalid floating point type");
-          return;
-      }
+      const RealType* Ty = llvm::cast<RealType>(CR->getType());
+      unsigned numBits = Ty->getMantissa() + Ty->getExponent() + 1; 
       if (numBits <= sizeof(float)*8) {
         float x = val;
         long double x2 = x;
@@ -739,7 +712,7 @@
       error(P,"Program without signature");
     else if (P->getSignature()->getID() != SignatureTypeID)
       error(P,"Program does not have SignatureType signature");
-    else if (P->getSignature() != ast->getProgramType())
+    else if (P->getSignature() != P->getContainingBundle()->getProgramType())
       error(P,"Program has wrong signature");
     if (P->getLinkageKind() != ExternalLinkage && P->getBlock() == 0)
       error(P,"Non-external Program without defining block");
@@ -1036,7 +1009,7 @@
       Bundle* B = op->getContainingBundle();
       if (!B)
         error(op,"ReferenceOp not in a bundle?");
-      else if (B->find_const(cval->getName()) != cval)
+      else if (B->getConst(cval->getName()) != cval)
         error(cval,"Referent does not value found in Bundle");
     } else {
       error(op,"Referent of unknown kind");
@@ -1189,7 +1162,7 @@
   if (checkOperator(n,BAndOpID,2)) {
     const Type* Ty1 = n->getOperand(0)->getType();
     const Type* Ty2 = n->getOperand(1)->getType();
-    if (!Ty1->isIntegerType() || !Ty2->isIntegerType())
+    if (!Ty1->is(IntegerTypeID) || !Ty2->is(IntegerTypeID))
       error(n,"You can only bitwise and objects of integer type");
   }
 }
@@ -1200,7 +1173,7 @@
   if (checkOperator(n,BOrOpID,2)) {
     const Type* Ty1 = n->getOperand(0)->getType();
     const Type* Ty2 = n->getOperand(1)->getType();
-    if (!Ty1->isIntegerType() || !Ty2->isIntegerType())
+    if (!Ty1->is(IntegerTypeID) || !Ty2->is(IntegerTypeID))
       error(n,"You can only bitwise or objects of integer type");
   }
 }
@@ -1211,7 +1184,7 @@
   if (checkOperator(n,BXorOpID,2)) {
     const Type* Ty1 = n->getOperand(0)->getType();
     const Type* Ty2 = n->getOperand(1)->getType();
-    if (!Ty1->isIntegerType() || !Ty2->isIntegerType())
+    if (!Ty1->is(IntegerTypeID) || !Ty2->is(IntegerTypeID))
       error(n,"You can only bitwise xor objects of integer type");
   }
 }
@@ -1222,7 +1195,7 @@
   if (checkOperator(n,BNorOpID,2)) {
     const Type* Ty1 = n->getOperand(0)->getType();
     const Type* Ty2 = n->getOperand(1)->getType();
-    if (!Ty1->isIntegerType() || !Ty2->isIntegerType())
+    if (!Ty1->is(IntegerTypeID) || !Ty2->is(IntegerTypeID))
       error(n,"You can only bitwise nor objects of integer type");
   }
 }
@@ -1328,7 +1301,7 @@
 {
   if (checkOperator(n,IsPInfOpID,1)) {
     const Type* Ty1 = n->getOperand(0)->getType();
-    if (!Ty1->isRealType())
+    if (!Ty1->is(RealTypeID))
       error(n,"IsPInfoOp requires real number operand");
   }
 }
@@ -1338,7 +1311,7 @@
 {
   if (checkOperator(n,IsNInfOpID,1)) {
     const Type* Ty1 = n->getOperand(0)->getType();
-    if (!Ty1->isRealType())
+    if (!Ty1->is(RealTypeID))
       error(n,"IsPInfoOp requires real number operand");
   }
 }
@@ -1348,7 +1321,7 @@
 {
   if (checkOperator(n,IsNanOpID,1)) {
     const Type* Ty1 = n->getOperand(0)->getType();
-    if (!Ty1->isRealType())
+    if (!Ty1->is(RealTypeID))
       error(n,"IsNanOp requires real number operand");
   }
 }
@@ -1358,7 +1331,7 @@
 {
   if (checkOperator(n,TruncOpID,1)) {
     const Type* Ty1 = n->getOperand(0)->getType();
-    if (!Ty1->isRealType())
+    if (!Ty1->is(RealTypeID))
       error(n,"TruncOp requires real number operand");
   }
 }
@@ -1368,7 +1341,7 @@
 {
   if (checkOperator(n,RoundOpID,1)) {
     const Type* Ty1 = n->getOperand(0)->getType();
-    if (!Ty1->isRealType())
+    if (!Ty1->is(RealTypeID))
       error(n,"RoundOp requires real number operand");
   }
 }
@@ -1378,7 +1351,7 @@
 {
   if (checkOperator(n,FloorOpID,1)) {
     const Type* Ty1 = n->getOperand(0)->getType();
-    if (!Ty1->isRealType())
+    if (!Ty1->is(RealTypeID))
       error(n,"FloorOp requires real number operand");
   }
 }
@@ -1388,7 +1361,7 @@
 {
   if (checkOperator(n,CeilingOpID,1)) {
     const Type* Ty1 = n->getOperand(0)->getType();
-    if (!Ty1->isRealType())
+    if (!Ty1->is(RealTypeID))
       error(n,"CeilingOp requires real number operand");
   }
 }
@@ -1398,7 +1371,7 @@
 {
   if (checkOperator(n,LogEOpID,1)) {
     const Type* Ty1 = n->getOperand(0)->getType();
-    if (!Ty1->isRealType())
+    if (!Ty1->is(RealTypeID))
       error(n,"LogEOpID requires real number operand");
   }
 }
@@ -1408,7 +1381,7 @@
 {
   if (checkOperator(n,Log2OpID,1)) {
     const Type* Ty1 = n->getOperand(0)->getType();
-    if (!Ty1->isRealType())
+    if (!Ty1->is(RealTypeID))
       error(n,"Log2OpID requires real number operand");
   }
 }
@@ -1418,7 +1391,7 @@
 {
   if (checkOperator(n,Log10OpID,1)) {
     const Type* Ty1 = n->getOperand(0)->getType();
-    if (!Ty1->isRealType())
+    if (!Ty1->is(RealTypeID))
       error(n,"Log10OpID requires real number operand");
   }
 }
@@ -1428,7 +1401,7 @@
 {
   if (checkOperator(n,SquareRootOpID,1)) {
     const Type* Ty1 = n->getOperand(0)->getType();
-    if (!Ty1->isRealType())
+    if (!Ty1->is(RealTypeID))
       error(n,"SquareRootOp requires real number operand");
   }
 }
@@ -1438,7 +1411,7 @@
 {
   if (checkOperator(n,CubeRootOpID,1)) {
     const Type* Ty1 = n->getOperand(0)->getType();
-    if (!Ty1->isRealType())
+    if (!Ty1->is(RealTypeID))
       error(n,"CubeRootOpID requires real number operand");
   }
 }
@@ -1448,7 +1421,7 @@
 {
   if (checkOperator(n,FactorialOpID,1)) {
     const Type* Ty1 = n->getOperand(0)->getType();
-    if (!Ty1->isRealType())
+    if (!Ty1->is(RealTypeID))
       error(n,"FactorialOp requires real number operand");
   }
 }
@@ -1459,7 +1432,7 @@
   if (checkOperator(n,PowerOpID,2)) {
     const Type* Ty1 = n->getOperand(0)->getType();
     const Type* Ty2 = n->getOperand(1)->getType();
-    if (!Ty1->isRealType() || !Ty2->isRealType())
+    if (!Ty1->is(RealTypeID) || !Ty2->is(RealTypeID))
       error(n,"LogEOpID requires two real number operands");
   }
 }
@@ -1470,7 +1443,7 @@
   if (checkOperator(n,RootOpID,2)) {
     const Type* Ty1 = n->getOperand(0)->getType();
     const Type* Ty2 = n->getOperand(1)->getType();
-    if (!Ty1->isRealType() || !Ty2->isRealType())
+    if (!Ty1->is(RealTypeID) || !Ty2->is(RealTypeID))
       error(n,"RootOp requires two real number operands");
   }
 }
@@ -1481,7 +1454,7 @@
   if (checkOperator(n,GCDOpID,2)) {
     const Type* Ty1 = n->getOperand(0)->getType();
     const Type* Ty2 = n->getOperand(1)->getType();
-    if (!Ty1->isRealType() || !Ty2->isRealType())
+    if (!Ty1->is(RealTypeID) || !Ty2->is(RealTypeID))
       error(n,"GCDOp requires two real number operands");
   }
 }
@@ -1492,7 +1465,7 @@
   if (checkOperator(n,LCMOpID,2)) {
     const Type* Ty1 = n->getOperand(0)->getType();
     const Type* Ty2 = n->getOperand(1)->getType();
-    if (!Ty1->isRealType() || !Ty2->isRealType())
+    if (!Ty1->is(RealTypeID) || !Ty2->is(RealTypeID))
       error(n,"LCMOp requires two real number operands");
   }
 }
@@ -1567,19 +1540,19 @@
 {
   switch (n->getID())
   {
-    case NoTypeID:
+    case NoNodeID:
       hlvmDeadCode("Invalid Node Kind");
       break;
     case AnyTypeID:              validate(cast<AnyType>(n)); break;
     case BooleanTypeID:          validate(cast<BooleanType>(n)); break;
     case CharacterTypeID:        validate(cast<CharacterType>(n)); break;
-    case OctetTypeID:            validate(cast<OctetType>(n)); break;
     case IntegerTypeID:          validate(cast<IntegerType>(n)); break;
     case RangeTypeID:            validate(cast<RangeType>(n)); break;
     case EnumerationTypeID:      validate(cast<EnumerationType>(n)); break;
     case RealTypeID:             validate(cast<RealType>(n)); break;
     case RationalTypeID:         /*validate(cast<RationalType>(n));*/ break;
     case TextTypeID:             validate(cast<TextType>(n)); break;
+    case StringTypeID:           validate(cast<StringType>(n)); break;
     case StreamTypeID:           validate(cast<StreamType>(n)); break;
     case BufferTypeID:           validate(cast<BufferType>(n)); break;
     case PointerTypeID:          validate(cast<PointerType>(n)); break;
@@ -1678,7 +1651,6 @@
     case ConstantBooleanID:      validate(cast<ConstantBoolean>(n)); break;
     case ConstantCharacterID:    validate(cast<ConstantCharacter>(n)); break;
     case ConstantEnumeratorID:   validate(cast<ConstantEnumerator>(n)); break;
-    case ConstantOctetID:        validate(cast<ConstantOctet>(n)); break;
     case ConstantIntegerID:      validate(cast<ConstantInteger>(n)); break;
     case ConstantRealID:         validate(cast<ConstantReal>(n)); break;
     case ConstantStringID:       validate(cast<ConstantString>(n)); break;

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

==============================================================================
--- hlvm/trunk/hlvm/Reader/HLVM.rng (original)
+++ hlvm/trunk/hlvm/Reader/HLVM.rng Sat Jul  7 19:02:42 2007
@@ -143,6 +143,14 @@
     </data>
   </define>
 
+  <define name="Encoding.type">
+    <choice>
+      <value>utf-8</value>
+      <value>utf-16</value>
+      <value>ucs</value>
+    </choice>
+  </define>
+
   <define name="Character.type">
     <choice>
       <data type="string">
@@ -195,14 +203,12 @@
     <attribute name="id">
       <ref name="Identifier.type"/>
     </attribute>
-    <ref name="Documentation.pat"/>
   </define>
 
   <define name="Typed_Element.pat">
     <attribute name="type">
       <ref name="Identifier.type"/>
     </attribute>
-    <ref name="Documentation.pat"/>
   </define>
 
   <define name="Named_Typed_Element.pat">
@@ -212,7 +218,6 @@
     <attribute name="type">
       <ref name="Identifier.type"/>
     </attribute>
-    <ref name="Documentation.pat"/>
   </define>
 
   <!-- HLVM PATTERN -->
@@ -231,16 +236,21 @@
   <define name="bundle.elem">
     <element name="bundle">
       <ref name="Named_Element.pat"/>
+      <ref name="Documentation.pat"/>
       <zeroOrMore>
         <ref name="import.elem"/>
       </zeroOrMore>
       <oneOrMore>
         <choice>
+          <ref name="alias.elem"/>
+          <ref name="any.elem"/>
           <ref name="array.elem"/>
+          <ref name="boolean.elem"/>
+          <ref name="buffer.elem"/>
+          <ref name="character.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="program.elem"/>
@@ -248,7 +258,10 @@
           <ref name="real.elem"/>
           <ref name="signature.elem"/>
           <ref name="signed.elem"/>
+          <ref name="stream.elem"/>
+          <ref name="string.elem"/>
           <ref name="structure.elem"/>
+          <ref name="text.elem"/>
           <ref name="unsigned.elem"/>
           <ref name="variable.elem"/>
           <ref name="vector.elem"/>
@@ -271,132 +284,148 @@
 
   <!--PATTERNS FOR DEFINING TYPES -->
 
-  <define name="signed.elem">
-    <element name="signed">
-      <attribute name="bits">
-        <ref name="Integer.type"/>
-      </attribute>
+  <define name="alias.elem">
+    <element name="alias">
       <ref name="Named_Element.pat"/>
+      <attribute name="is">
+        <ref name="Identifier.type"/>
+      </attribute>
+      <ref name="Documentation.pat"/>
     </element>
   </define>
 
-  <define name="unsigned.elem">
-    <element name="unsigned">
-      <attribute name="bits">
-        <ref name="Integer.type"/>
-      </attribute>
+  <define name="any.elem">
+    <element name="any">
       <ref name="Named_Element.pat"/>
+      <ref name="Documentation.pat"/>
     </element>
   </define>
 
-  <define name="range.elem">
-    <element name="range">
-      <attribute name="min">
-        <ref name="Integer.type"/>
-      </attribute>
-      <attribute name="max">
-        <ref name="Integer.type"/>
-      </attribute>
+  <define name="array.elem">
+    <element name="array">
       <ref name="Named_Element.pat"/>
+      <attribute name="length"><data type="nonNegativeInteger"/></attribute>
+      <attribute name="of"><ref name="Identifier.type"/></attribute>
+      <ref name="Documentation.pat"/>
     </element>
   </define>
 
-  <define name="real.elem">
-    <element name="real">
-      <attribute name="mantissa">
-        <ref name="Integer.type"/>
-      </attribute>
-      <attribute name="exponent">
-        <ref name="Integer.type"/>
-      </attribute>
+  <define name="boolean.elem">
+    <element name="boolean">
       <ref name="Named_Element.pat"/>
+      <ref name="Documentation.pat"/>
     </element>
   </define>
 
-  <define name="intrinsic.elem">
-    <element name="intrinsic">
-      <attribute name="is">
-        <ref name="Intrinsic_Atoms.type"/>
-      </attribute>
+  <define name="buffer.elem">
+    <element name="buffer">
       <ref name="Named_Element.pat"/>
+      <ref name="Documentation.pat"/>
     </element>
   </define>
 
-  <define name="Intrinsic_Atoms.type">
-    <choice>
-      <value>any</value>
-      <value>bool</value>
-      <value>buffer</value>
-      <value>char</value>
-      <value>f32</value>
-      <value>f44</value>
-      <value>f64</value>
-      <value>f80</value>
-      <value>f128</value>
-      <value>octet</value>
-      <value>s8</value>
-      <value>s16</value>
-      <value>s32</value>
-      <value>s64</value>
-      <value>s128</value>
-      <value>stream</value>
-      <value>string</value>
-      <value>u8</value>
-      <value>u16</value>
-      <value>u32</value>
-      <value>u64</value>
-      <value>u128</value>
-      <value>void</value>
-    </choice>
+  <define name="character.elem">
+    <element name="character">
+      <ref name="Named_Element.pat"/>
+      <attribute name="encoding">
+        <ref name="Encoding.type"/>
+      </attribute>
+      <ref name="Documentation.pat"/>
+    </element>
   </define>
 
   <define name="enumeration.elem">
     <element name="enumeration">
       <ref name="Named_Element.pat"/>
+      <ref name="Documentation.pat"/>
       <oneOrMore>
         <element name="enumerator">
           <attribute name="id">
             <ref name="Unprefixed_Identifier.type"/>
           </attribute>
-          <ref name="Documentation.pat"/>
         </element>
       </oneOrMore>
     </element>
   </define>
 
+  <define name="opaque.elem">
+    <element name="opaque">
+      <ref name="Named_Element.pat"/>
+      <ref name="Documentation.pat"/>
+    </element>
+  </define>
+
   <define name="pointer.elem">
     <element name="pointer">
+      <ref name="Named_Element.pat"/>
       <attribute name="to"><ref name="Identifier.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="vector.elem">
-    <element name="vector">
-      <attribute name="of">
-        <ref name="Intrinsic_Atoms.type"/>
+  <define name="real.elem">
+    <element name="real">
+      <ref name="Named_Element.pat"/>
+      <attribute name="mantissa">
+        <ref name="Integer.type"/>
       </attribute>
-      <attribute name="length">
-        <data type="nonNegativeInteger"/>
+      <attribute name="exponent">
+        <ref name="Integer.type"/>
       </attribute>
+      <ref name="Documentation.pat"/>
+    </element>
+  </define>
+
+  <define name="signed.elem">
+    <element name="signed">
+      <ref name="Named_Element.pat"/>
+      <optional>
+        <attribute name="bits">
+          <ref name="Integer.type"/>
+        </attribute>
+      </optional>
+      <ref name="Documentation.pat"/>
+    </element>
+  </define>
+
+  <define name="stream.elem">
+    <element name="stream">
       <ref name="Named_Element.pat"/>
+      <ref name="Documentation.pat"/>
     </element>
   </define>
 
-  <define name="array.elem">
-    <element name="array">
-      <attribute name="length"><data type="nonNegativeInteger"/></attribute>
-      <attribute name="of"><ref name="Identifier.type"/></attribute>
+  <define name="string.elem">
+    <element name="string">
       <ref name="Named_Element.pat"/>
+      <attribute name="encoding">
+        <ref name="Encoding.type"/>
+      </attribute>
+      <ref name="Documentation.pat"/>
     </element>
   </define>
 
   <define name="structure.elem">
     <element name="structure">
       <ref name="Named_Element.pat"/>
+      <ref name="Documentation.pat"/>
       <zeroOrMore>
         <element name="field">
           <ref name="Named_Typed_Element.pat"/>
+          <ref name="Documentation.pat"/>
         </element>
       </zeroOrMore>
     </element>
@@ -404,23 +433,46 @@
 
   <define name="signature.elem">
     <element name="signature">
+      <ref name="Named_Element.pat"/>
       <attribute name="result"><ref name="Identifier.type"/></attribute>
       <optional>
         <attribute name="varargs"><ref name="Boolean.type"/></attribute>
       </optional>
-      <ref name="Named_Element.pat"/>
+      <ref name="Documentation.pat"/>
       <zeroOrMore>
         <element name="arg">
           <ref name="Named_Typed_Element.pat"/>
+          <ref name="Documentation.pat"/>
         </element>
       </zeroOrMore>
     </element>
   </define>
 
-  <define name="opaque.elem">
-    <element name="opaque">
+  <define name="text.elem">
+    <element name="text">
       <ref name="Named_Element.pat"/>
-      <empty/>
+      <ref name="Documentation.pat"/>
+    </element>
+  </define>
+
+  <define name="unsigned.elem">
+    <element name="unsigned">
+      <ref name="Named_Element.pat"/>
+      <optional>
+        <attribute name="bits">
+          <ref name="Integer.type"/>
+        </attribute>
+      </optional>
+      <ref name="Documentation.pat"/>
+    </element>
+  </define>
+
+  <define name="vector.elem">
+    <element name="vector">
+      <ref name="Named_Element.pat"/>
+      <attribute name="of"><ref name="Identifier.type"/></attribute>
+      <attribute name="length"><data type="nonNegativeInteger"/></attribute>
+      <ref name="Documentation.pat"/>
     </element>
   </define>
 
@@ -429,6 +481,7 @@
   <define name="constant.elem">
     <element name="constant">
       <ref name="Named_Typed_Element.pat"/>
+      <ref name="Documentation.pat"/>
       <ref name="Literal.pat"/>
     </element>
   </define>
@@ -451,7 +504,7 @@
       <ref name="char.elem"/>
       <ref name="octet.elem"/>
       <ref name="enum.elem"/>
-      <ref name="string.elem"/>
+      <ref name="str.elem"/>
       <ref name="null.elem"/>
       <ref name="ptr.elem"/>
       <ref name="arr.elem"/>
@@ -534,8 +587,8 @@
     </element>
   </define>
 
-  <define name="string.elem">
-    <element name="string">
+  <define name="str.elem">
+    <element name="str">
       <ref name="Typed_Literal.pat"/>
       <text/>
     </element>
@@ -613,6 +666,7 @@
           <ref name="Identifier.type"/>
         </attribute>
       </optional>
+      <ref name="Documentation.pat"/>
     </element>
   </define>
 
@@ -634,6 +688,7 @@
       <optional>
         <attribute name="linkage"><ref name="Linkage.type"/></attribute>
       </optional>
+      <ref name="Documentation.pat"/>
       <optional>
         <choice>
           <element name="as"><ref name="C_Identifier.type"/></element>
@@ -645,13 +700,12 @@
 
   <define name="program.elem">
     <element name="program">
+      <ref name="Named_Element.pat"/>
       <optional>
         <attribute name="linkage"><ref name="Linkage.type"/></attribute>
       </optional>
-      <ref name="Named_Element.pat"/>
-      <zeroOrMore>
-        <ref name="block.elem"/>
-      </zeroOrMore>
+      <ref name="Documentation.pat"/>
+      <ref name="block.elem"/>
     </element>
   </define>
 
@@ -718,6 +772,7 @@
       <optional>
         <attribute name="label"><ref name="Identifier.type"/></attribute>
       </optional>
+      <ref name="Documentation.pat"/>
       <oneOrMore>
         <choice>
           <ref name="Operators.pat"/>
@@ -774,6 +829,7 @@
   <define name="ref.elem">
     <element name="ref">
       <ref name="Named_Element.pat"/>
+      <ref name="Documentation.pat"/>
     </element>
   </define>
 
@@ -817,6 +873,7 @@
           <ref name="Identifier.type"/>
         </attribute>
       </optional>
+      <ref name="Documentation.pat"/>
     </element>
   </define>
 

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

==============================================================================
--- hlvm/trunk/hlvm/Reader/XMLReader.cpp (original)
+++ hlvm/trunk/hlvm/Reader/XMLReader.cpp Sat Jul  7 19:02:42 2007
@@ -105,6 +105,7 @@
   }
 
   inline Type* getType(const std::string& name );
+  bool checkNewType(const std::string& name, Locator* loc);
 
 
   inline void handleParseError(xmlErrorPtr error);
@@ -119,7 +120,7 @@
   Constant*      parseConstant      (xmlNodePtr& cur);
   Operator*      parseOperator      (xmlNodePtr& cur);
   void           parseTree          ();
-  Type*          parseIntrinsic     (xmlNodePtr& cur);
+  Type*          parseAlias         (xmlNodePtr& cur);
   Type*          parseInteger       (xmlNodePtr& cur, bool isSigned);
 
   template<class OpClass>
@@ -140,6 +141,8 @@
   getAttribute(xmlNodePtr cur,const char*name,bool required = true);
   inline void getTextContent(xmlNodePtr cur, std::string& buffer);
   inline void getNameType(xmlNodePtr& cur, std::string& name,std::string& type);
+  inline Type* createIntrinsicType(
+    const std::string& tname, const std::string& name, Locator* loc);
 
 private:
 };
@@ -264,77 +267,6 @@
   return 0;
 }
 
-inline Type*
-recognize_builtin_type( hlvm::AST* ast, const std::string& tname)
-{
-  Type* result = 0;
-  int token = HLVMTokenizer::recognize(tname.c_str());
-  switch (token) {
-    case TKN_any:    result = ast->getPrimitiveType(AnyTypeID); break;
-    case TKN_bool:   result = ast->getPrimitiveType(BooleanTypeID); break;
-    case TKN_buffer: result = ast->getPrimitiveType(BufferTypeID); break;
-    case TKN_char:   result = ast->getPrimitiveType(CharacterTypeID); break;
-    case TKN_f128:   result = ast->getPrimitiveType(Float128TypeID); break;
-    case TKN_f32:    result = ast->getPrimitiveType(Float32TypeID); break;
-    case TKN_f44:    result = ast->getPrimitiveType(Float44TypeID); break;
-    case TKN_f64:    result = ast->getPrimitiveType(Float64TypeID); break;
-    case TKN_f80:    result = ast->getPrimitiveType(Float80TypeID); break;
-    case TKN_octet:  result = ast->getPrimitiveType(OctetTypeID); break;
-    case TKN_s128:   result = ast->getPrimitiveType(SInt128TypeID); break;
-    case TKN_s16:    result = ast->getPrimitiveType(SInt16TypeID); break;
-    case TKN_s32:    result = ast->getPrimitiveType(SInt32TypeID); break;
-    case TKN_s64:    result = ast->getPrimitiveType(SInt64TypeID); break;
-    case TKN_s8:     result = ast->getPrimitiveType(SInt8TypeID); break;
-    case TKN_stream: result = ast->getPrimitiveType(StreamTypeID); break;
-    case TKN_string: result = ast->getPrimitiveType(StringTypeID); break;
-    case TKN_u128:   result = ast->getPrimitiveType(UInt128TypeID); break;
-    case TKN_u16:    result = ast->getPrimitiveType(UInt16TypeID); break;
-    case TKN_u32:    result = ast->getPrimitiveType(UInt32TypeID); break;
-    case TKN_u64:    result = ast->getPrimitiveType(UInt64TypeID); break;
-    case TKN_u8:     result = ast->getPrimitiveType(UInt8TypeID); break;
-    default:
-      break;
-  }
-  return result;
-}
-
-inline Type*
-create_builtin_type(
-  hlvm::AST* ast, 
-  const std::string& tname,
-  const std::string& name,
-  Locator* loc
-) {
-  Type* result = 0;
-  int token = HLVMTokenizer::recognize(tname.c_str());
-  switch (token) {
-    case TKN_any:     result = ast->new_AnyType(name,loc); break;
-    case TKN_bool:    result = ast->new_BooleanType(name,loc); break;
-    case TKN_buffer:  result = ast->new_BufferType(name,loc); break;
-    case TKN_char:    result = ast->new_CharacterType(name,loc); break;
-    case TKN_f128:    result = ast->new_f128(name,loc); break;
-    case TKN_f32:     result = ast->new_f32(name,loc); break;
-    case TKN_f44:     result = ast->new_f44(name,loc); break;
-    case TKN_f64:     result = ast->new_f64(name,loc); break;
-    case TKN_f80:     result = ast->new_f80(name,loc); break;
-    case TKN_octet:   result = ast->new_OctetType(name,loc); break;
-    case TKN_s128:    result = ast->new_s128(name,loc); break;
-    case TKN_s16:     result = ast->new_s16(name,loc); break;
-    case TKN_s32:     result = ast->new_s32(name,loc); break;
-    case TKN_s64:     result = ast->new_s64(name,loc); break;
-    case TKN_s8:      result = ast->new_s8(name,loc); break;
-    case TKN_stream:  result = ast->new_StreamType(name,loc); break;
-    case TKN_string:  result = ast->new_StringType(name,loc); break;
-    case TKN_u128:    result = ast->new_u128(name,loc); break;
-    case TKN_u16:     result = ast->new_u16(name,loc); break;
-    case TKN_u32:     result = ast->new_u32(name,loc); break;
-    case TKN_u64:     result = ast->new_u64(name,loc); break;
-    case TKN_u8:      result = ast->new_u8(name,loc); break;
-    default: break;
-  }
-  return result;
-}
-
 inline const char* 
 XMLReaderImpl::getAttribute(xmlNodePtr cur,const char*name,bool required )
 {
@@ -379,23 +311,73 @@
 }
 
 Type*
-XMLReaderImpl::getType(const std::string& name )
+XMLReaderImpl::getType(const std::string& name)
 {
-  Type* Ty = recognize_builtin_type(ast,name);
-  if (!Ty) {
-    Ty = ast->resolveType(name);
-  }
+  IntrinsicTypes IT = bundle->getIntrinsicTypesValue(name);
+  if (NoIntrinsicType != IT)
+    return bundle->getIntrinsicType(IT);
+  Type* Ty = bundle->getOrCreateType(name);
   hlvmAssert(Ty != 0 && "Couldn't get Type!");
   return Ty;
 }
 
+bool
+XMLReaderImpl::checkNewType(const std::string& name, Locator* loc)
+{
+  bool result = true;
+  if (NoIntrinsicType != bundle->getIntrinsicTypesValue(name)) {
+    error(loc,"Attempt to redefine intrinsic type '" + name + "'");
+    result = false;
+  }
+  if (Type* Ty = bundle->getType(name))
+    if (OpaqueType* OTy = llvm::dyn_cast<OpaqueType>(Ty))
+      if (!OTy->isUnresolved()) {
+        error(loc, "Attempt to redefine type '" + name + "'");
+        result = false;
+      }
+  return result;
+}
+
+template<> Documentation*
+XMLReaderImpl::parse<Documentation>(xmlNodePtr& cur)
+{
+  // Documentation is always optional so don't error out if the
+  // node is not a TKN_doc
+  if (cur && skipBlanks(cur) && getToken(cur->name) == TKN_doc) {
+    xmlBufferPtr buffer = xmlBufferCreate();
+    xmlNodeDump(buffer,doc,cur,0,0);
+    int length = xmlBufferLength(buffer);
+    std::string 
+      str(reinterpret_cast<const char*>(xmlBufferContent(buffer)),length);
+    str.erase(0,5); // Zap the <doc> at the start
+    str.erase(str.length()-6); // Zap the </doc> at the end
+    Documentation* doc = ast->new_Documentation(getLocator(cur));
+    doc->setDoc(str);
+    xmlBufferFree(buffer);
+    cur = cur->next;
+    return doc;
+  }
+  // Just signal that there's no documentation in this node
+  return 0;
+}
+
+inline xmlNodePtr
+XMLReaderImpl::checkDoc(xmlNodePtr cur, Documentable* node)
+{
+  xmlNodePtr child = cur->children;
+  Documentation* theDoc = parse<Documentation>(child);
+  if (theDoc)
+    node->setDoc(theDoc);
+  return child;
+}
+
 ConstantValue*
 XMLReaderImpl::parseLiteralConstant(
     xmlNodePtr& cur, 
     const std::string& name,
     const Type* Ty)
 {
-  if (!name.empty() && bundle->find_const(name) != 0) {
+  if (!name.empty() && bundle->getConst(name) != 0) {
     error(getLocator(cur),std::string("Constant '") + name 
           + "' already exists.");
     return 0;
@@ -412,13 +394,13 @@
     case TKN_false:   
     {
       std::string name = actualName.empty() ? "bool_false" : actualName;
-      C = ast->new_ConstantBoolean(name, false, getLocator(cur)); 
+      C = ast->new_ConstantBoolean(name, bundle,Ty,false, getLocator(cur)); 
       break;
     }
     case TKN_true:
     {
       std::string name = actualName.empty() ? "bool_true" : actualName;
-      C = ast->new_ConstantBoolean(name,true, getLocator(cur));
+      C = ast->new_ConstantBoolean(name,bundle,Ty,true, getLocator(cur));
       break;
     }
     case TKN_bool:
@@ -430,7 +412,7 @@
       bool value = recognize_boolean( buffer.c_str() );
       std::string name = actualName.empty() ? std::string("bool_") + 
         (value?"true_":"false") : actualName;
-      C = ast->new_ConstantBoolean(name, value, getLocator(cur));
+      C = ast->new_ConstantBoolean(name, bundle,Ty,value, getLocator(cur));
       break;
     }
     case TKN_char:
@@ -441,7 +423,7 @@
       getTextContent(child,buffer);
       std::string name= actualName.empty() ? 
         std::string("char_") + buffer : actualName;
-      C = ast->new_ConstantCharacter(name, buffer, getLocator(cur));
+      C = ast->new_ConstantCharacter(name, bundle,Ty,buffer, getLocator(cur));
       break;
     }
     case TKN_bin:
@@ -449,7 +431,7 @@
     case TKN_dec:
     case TKN_hex:
     {
-      hlvmAssert(Ty->isIntegerType());
+      hlvmAssert(Ty->is(IntegerTypeID));
       std::string value;
       xmlNodePtr child = cur->children;
       getTextContent(child,value);
@@ -457,23 +439,23 @@
                       (token == TKN_oct ? 8 : (token == TKN_bin ? 2 : 10))));
       std::string name = actualName.empty() ? 
         std::string("int_") + value : actualName;
-      C = ast->new_ConstantInteger(name, value, base, Ty, getLocator(cur));
+      C = ast->new_ConstantInteger(name,bundle,Ty,value,base,getLocator(cur));
       break;
     }
     case TKN_flt:
     case TKN_dbl:
     case TKN_real:
     {
-      hlvmAssert(Ty->isRealType());
+      hlvmAssert(Ty->is(RealTypeID));
       std::string value;
       xmlNodePtr child = cur->children;
       getTextContent(child,value);
       std::string name = actualName.empty() ? std::string("real_") + value :
           actualName;
-      C = ast->new_ConstantReal(name,value, Ty, getLocator(cur));
+      C = ast->new_ConstantReal(name,bundle,Ty,value,getLocator(cur));
       break;
     }
-    case TKN_string:
+    case TKN_str:
     {
       hlvmAssert(Ty->is(StringTypeID));
       std::string value;
@@ -481,7 +463,7 @@
       getTextContent(child,value);
       std::string name = actualName.empty() ? std::string("str_") + value :
           actualName;
-      C =  ast->new_ConstantString(name,value,getLocator(cur));
+      C =  ast->new_ConstantString(name,bundle,Ty,value,getLocator(cur));
       break;
     }
     case TKN_ptr:
@@ -489,10 +471,10 @@
       std::string id = getAttribute(cur,"id");
       std::string name = actualName.empty() ? std::string("ptr_") + id :
           actualName;
-      Constant* referent = bundle->find_const(id);
+      Constant* referent = bundle->getConst(id);
       if (!referent)
         error(loc,"Unkown referent for constant pointer");
-      C = ast->new_ConstantPointer(name,Ty,referent,loc);
+      C = ast->new_ConstantPointer(name,bundle,Ty,referent,loc);
       break;
     }
     case TKN_arr:
@@ -507,7 +489,7 @@
         child = child->next;
       }
       std::string name = actualName.empty() ? std::string("arr") : actualName;
-      C = ast->new_ConstantArray(name,elems,AT,getLocator(cur));
+      C = ast->new_ConstantArray(name,bundle,AT,elems,getLocator(cur));
       break;
     }
     case TKN_vect:
@@ -522,7 +504,7 @@
         child = child->next;
       }
       std::string name = actualName.empty() ? std::string("vec") : actualName;
-      C = ast->new_ConstantVector(name,elems,VT,getLocator(cur));
+      C = ast->new_ConstantVector(name,bundle,VT,elems,getLocator(cur));
       break;
     }
     case TKN_struct:
@@ -538,7 +520,7 @@
         ++I;
       }
       std::string name = actualName.empty() ? std::string("struct") :actualName;
-      C = ast->new_ConstantStructure(name,fields,ST,getLocator(cur));
+      C = ast->new_ConstantStructure(name,bundle,ST,fields,getLocator(cur));
       break;
     }
     case TKN_cont:
@@ -554,7 +536,7 @@
         ++I;
       }
       std::string name = actualName.empty() ? std::string("struct") :actualName;
-      C = ast->new_ConstantContinuation(name,fields,CT,getLocator(cur));
+      C = ast->new_ConstantContinuation(name,bundle,CT,fields,getLocator(cur));
       break;
     }
     default:
@@ -576,60 +558,103 @@
   getNameType(cur,name,type);
   Type* Ty = getType(type);
   xmlNodePtr child = cur->children;
+  Documentation* theDoc = parse<Documentation>(child);
   Constant* C = parseLiteralConstant(child,name,Ty);
+  if (theDoc)
+    C->setDoc(theDoc);
   return C;
 }
-
-template<> Documentation*
-XMLReaderImpl::parse<Documentation>(xmlNodePtr& cur)
+Type*     
+XMLReaderImpl::parseAlias(xmlNodePtr& cur)
 {
-  // Documentation is always optional so don't error out if the
-  // node is not a TKN_doc
-  if (cur && skipBlanks(cur) && getToken(cur->name) == TKN_doc) {
-    xmlBufferPtr buffer = xmlBufferCreate();
-    xmlNodeDump(buffer,doc,cur,0,0);
-    int length = xmlBufferLength(buffer);
-    std::string 
-      str(reinterpret_cast<const char*>(xmlBufferContent(buffer)),length);
-    str.erase(0,5); // Zap the <doc> at the start
-    str.erase(str.length()-6); // Zap the </doc> at the end
-    Documentation* progDoc = ast->new_Documentation(getLocator(cur));
-    progDoc->setDoc(str);
-    xmlBufferFree(buffer);
-    return progDoc;
+  Locator* loc = getLocator(cur);
+  std::string name = getAttribute(cur,"id");
+  if (NoIntrinsicType != bundle->getIntrinsicTypesValue(name))
+    error(loc,"Attempt to redefine intrinsic type '" + name + "'");
+  if (bundle->getType(name))
+    error(loc,"Type '" + name + "' was already defined");
+  const char* is = getAttribute(cur,"is",true);
+  xmlNodePtr child = cur->children;
+  Documentation* theDoc = parse<Documentation>(child);
+  Type* result = 0;
+  if (is) {
+    IntrinsicTypes it = bundle->getIntrinsicTypesValue(is);
+    if (it != NoIntrinsicType) {
+      result = ast->new_IntrinsicType(name,bundle,it,loc);
+    } else if (Type* Ty = bundle->getType(is)) {
+      error(loc,"Not implemented yet: type cloning");
+    } else 
+      error(loc,std::string("Type '") + is + "' does not exist.");
+    if (theDoc)
+      result->setDoc(theDoc);
   }
-  // Just signal that there's no documentation in this node
-  return 0;
+  return result;
 }
 
-inline xmlNodePtr
-XMLReaderImpl::checkDoc(xmlNodePtr cur, Documentable* node)
+template<> AnyType*
+XMLReaderImpl::parse<AnyType>(xmlNodePtr& cur)
 {
+  Locator* loc = getLocator(cur);
+  std::string name = getAttribute(cur,"id");
+  if (!checkNewType(name,loc))
+    return 0;
   xmlNodePtr child = cur->children;
   Documentation* theDoc = parse<Documentation>(child);
-  if (theDoc) {
-    node->setDoc(theDoc);
-    return child->next;
-  }
-  return child;
+  AnyType* result = ast->new_AnyType(name,bundle,loc);
+  if (theDoc)
+    result->setDoc(theDoc);
+  return result;
 }
 
-Type*     
-XMLReaderImpl::parseIntrinsic(xmlNodePtr& cur)
+template<> BooleanType*
+XMLReaderImpl::parse<BooleanType>(xmlNodePtr& cur)
 {
   Locator* loc = getLocator(cur);
   std::string name = getAttribute(cur,"id");
-  if (bundle->find_type(name))
-    error(loc,"Type '" + name + "' was already defined");
-  const char* is = getAttribute(cur,"is");
+  if (!checkNewType(name,loc))
+    return 0;
   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");
+  BooleanType* result = ast->new_BooleanType(name,bundle,loc);
+  if (theDoc)
+    result->setDoc(theDoc);
+  return result;
+}
+
+template<> BufferType*
+XMLReaderImpl::parse<BufferType>(xmlNodePtr& cur)
+{
+  Locator* loc = getLocator(cur);
+  std::string name = getAttribute(cur,"id");
+  if (!checkNewType(name,loc))
+    return 0;
+  xmlNodePtr child = cur->children;
+  Documentation* theDoc = parse<Documentation>(child);
+  Type* result = ast->new_IntrinsicType(name,bundle,bufferTy,loc);
+  if (theDoc)
+    result->setDoc(theDoc);
+  return llvm::cast<BufferType>(result);
+}
+
+template<> CharacterType*
+XMLReaderImpl::parse<CharacterType>(xmlNodePtr& cur)
+{
+  Locator* loc = getLocator(cur);
+  std::string name = getAttribute(cur,"id");
+  if (!checkNewType(name,loc))
+    return 0;
+  const char* encoding = getAttribute(cur,"encoding");
+  xmlNodePtr child = cur->children;
+  Documentation* theDoc = parse<Documentation>(child);
+  std::string enc;
+  if (encoding)
+    enc = encoding;
+  else
+    enc = "utf-8";
+  CharacterType* result = 
+    ast->new_CharacterType(name,bundle,encoding,loc);
+  if (theDoc)
+    result->setDoc(theDoc);
   return result;
 }
 
@@ -638,20 +663,21 @@
 {
   Locator* loc = getLocator(cur);
   std::string name = getAttribute(cur,"id");
-  if (bundle->find_type(name))
-    error(loc,"Type '" + name + "' was already defined");
+  if (!checkNewType(name,loc))
+    return 0;
   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;
+  uint64_t numBits = 0;
+  if (bits)
+    numBits = recognize_nonNegativeInteger(bits);
+  else
+    numBits = 32;
+  IntegerType* result = 
+    ast->new_IntegerType(name,bundle,numBits,isSigned,loc);
+  if (theDoc)
+    result->setDoc(theDoc);
+  return result;
 }
 
 template<> RangeType*
@@ -659,8 +685,8 @@
 {
   Locator* loc = getLocator(cur);
   std::string name = getAttribute(cur,"id");
-  if (bundle->find_type(name))
-    error(loc,"Type '" + name + "' was already defined");
+  if (!checkNewType(name,loc))
+    return 0;
   const char* min = getAttribute(cur, "min");
   const char* max = getAttribute(cur, "max");
   xmlNodePtr child = cur->children;
@@ -668,7 +694,7 @@
   if (min && max) {
     int64_t minVal = recognize_Integer(min);
     int64_t maxVal = recognize_Integer(max);
-    RangeType* result = ast->new_RangeType(name,minVal,maxVal,loc);
+    RangeType* result = ast->new_RangeType(name,bundle,minVal,maxVal,loc);
     if (theDoc)
       result->setDoc(theDoc);
     return result;
@@ -682,8 +708,8 @@
 {
   Locator* loc = getLocator(cur);
   std::string name = getAttribute(cur,"id");
-  if (bundle->find_type(name))
-    error(loc,"Type '" + name + "' was already defined");
+  if (!checkNewType(name,loc))
+    return 0;
   const char* mantissa = getAttribute(cur, "mantissa");
   const char* exponent = getAttribute(cur, "exponent");
   xmlNodePtr child = cur->children;
@@ -691,7 +717,7 @@
   if (mantissa && exponent) {
     int32_t mantVal = recognize_nonNegativeInteger(mantissa);
     int32_t expoVal = recognize_nonNegativeInteger(exponent);
-    RealType* result = ast->new_RealType(name,mantVal,expoVal,loc);
+    RealType* result = ast->new_RealType(name,bundle,mantVal,expoVal,loc);
     if (theDoc)
       result->setDoc(theDoc);
     return result;
@@ -706,9 +732,9 @@
   hlvmAssert(getToken(cur->name)==TKN_enumeration);
   Locator* loc = getLocator(cur);
   std::string name = getAttribute(cur,"id");
-  if (bundle->find_type(name))
-    error(loc,"Type '" + name + "' was already defined");
-  EnumerationType* en = ast->new_EnumerationType(name,loc);
+  if (!checkNewType(name,loc))
+    return 0;
+  EnumerationType* en = ast->new_EnumerationType(name,bundle,loc);
   xmlNodePtr child = checkDoc(cur,en);
   while (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE) {
     hlvmAssert(getToken(child->name) == TKN_enumerator);
@@ -725,11 +751,11 @@
   hlvmAssert(getToken(cur->name)==TKN_pointer);
   Locator* loc = getLocator(cur);
   std::string name = getAttribute(cur,"id");
-  if (bundle->find_type(name))
-    error(loc,"Type '" + name + "' was already defined");
+  if (!checkNewType(name,loc))
+    return 0;
   std::string type = getAttribute(cur,"to");
   PointerType* result = 
-    ast->new_PointerType(name,getType(type),loc);
+    ast->new_PointerType(name,bundle,getType(type),loc);
   checkDoc(cur,result);
   return result;
 }
@@ -740,12 +766,12 @@
   hlvmAssert(getToken(cur->name)==TKN_array);
   Locator* loc = getLocator(cur);
   std::string name = getAttribute(cur,"id");
-  if (bundle->find_type(name))
-    error(loc,"Type '" + name + "' was already defined");
+  if (!checkNewType(name,loc))
+    return 0;
   std::string type = getAttribute(cur,"of");
   const char* len = getAttribute(cur,"length");
   ArrayType* result = ast->new_ArrayType(
-    name, getType(type), recognize_nonNegativeInteger(len),loc);
+    name, bundle, getType(type), recognize_nonNegativeInteger(len),loc);
   checkDoc(cur,result);
   return result;
 }
@@ -756,26 +782,62 @@
   hlvmAssert(getToken(cur->name)==TKN_vector);
   Locator* loc = getLocator(cur);
   std::string name = getAttribute(cur,"id");
-  if (bundle->find_type(name))
-    error(loc,"Type '" + name + "' was already defined");
+  if (!checkNewType(name,loc))
+    return 0;
   std::string type = getAttribute(cur,"of");
   const char* len  = getAttribute(cur,"length");
-  VectorType* result =
-    ast->new_VectorType(
-      name,getType(type), recognize_nonNegativeInteger(len),loc);
+  VectorType* result = ast->new_VectorType(
+      name, bundle, getType(type), recognize_nonNegativeInteger(len),loc);
   checkDoc(cur,result);
   return result;
 }
 
+template<> StreamType*
+XMLReaderImpl::parse<StreamType>(xmlNodePtr& cur)
+{
+  Locator* loc = getLocator(cur);
+  std::string name = getAttribute(cur,"id");
+  if (!checkNewType(name,loc))
+    return 0;
+  xmlNodePtr child = cur->children;
+  Documentation* theDoc = parse<Documentation>(child);
+  Type* result = ast->new_IntrinsicType(name,bundle,streamTy,loc);
+  if (theDoc)
+    result->setDoc(theDoc);
+  return llvm::cast<StreamType>(result);
+}
+
+template<> StringType*
+XMLReaderImpl::parse<StringType>(xmlNodePtr& cur)
+{
+  Locator* loc = getLocator(cur);
+  std::string name = getAttribute(cur,"id");
+  if (!checkNewType(name,loc))
+    return 0;
+  const char* encoding = getAttribute(cur,"encoding");
+  xmlNodePtr child = cur->children;
+  Documentation* theDoc = parse<Documentation>(child);
+  std::string enc;
+  if (encoding)
+    enc = encoding;
+  else
+    enc = "utf-8";
+  StringType* result = 
+    ast->new_StringType(name,bundle,encoding,loc);
+  if (theDoc)
+    result->setDoc(theDoc);
+  return result;
+}
+
 template<> StructureType*
 XMLReaderImpl::parse<StructureType>(xmlNodePtr& cur)
 {
   hlvmAssert(getToken(cur->name)==TKN_structure);
   Locator* loc = getLocator(cur);
   std::string name = getAttribute(cur,"id");
-  if (bundle->find_type(name))
-    error(loc,"Type '" + name + "' was already defined");
-  StructureType* struc = ast->new_StructureType(name,loc);
+  if (!checkNewType(name,loc))
+    return 0;
+  StructureType* struc = ast->new_StructureType(name, bundle, loc);
   xmlNodePtr child = checkDoc(cur,struc); 
   while (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE) {
     hlvmAssert(getToken(child->name) == TKN_field && 
@@ -783,7 +845,7 @@
     std::string name = getAttribute(child,"id");
     std::string type = getAttribute(child,"type");
     Locator* fldLoc = getLocator(child);
-    Field* fld = ast->new_Field(name,getType(type),fldLoc);
+    Field* fld = ast->new_Field(name, getType(type),fldLoc);
     struc->addField(fld);
     checkDoc(child,fld);
     child = child->next;
@@ -797,9 +859,9 @@
   hlvmAssert(getToken(cur->name)==TKN_structure);
   Locator* loc = getLocator(cur);
   std::string name = getAttribute(cur,"id");
-  if (bundle->find_type(name))
-    error(loc,"Type '" + name + "' was already defined");
-  ContinuationType* cont = ast->new_ContinuationType(name,loc);
+  if (!checkNewType(name,loc))
+    return 0;
+  ContinuationType* cont = ast->new_ContinuationType(name, bundle, loc);
   xmlNodePtr child = checkDoc(cur,cont); 
   while (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE) {
     hlvmAssert(getToken(child->name) == TKN_field && 
@@ -821,12 +883,12 @@
   hlvmAssert(getToken(cur->name)==TKN_signature);
   Locator* loc = getLocator(cur);
   std::string name = getAttribute(cur,"id");
-  if (bundle->find_type(name))
-    error(loc,"Type '" + name + "' was already defined");
+  if (!checkNewType(name,loc))
+    return 0;
   std::string result = getAttribute(cur,"result");
   const char* varargs = getAttribute(cur,"varargs",false);
   SignatureType* sig = 
-    ast->new_SignatureType(name,getType(result),loc);
+    ast->new_SignatureType(name, bundle, getType(result),loc);
   if (varargs)
     sig->setIsVarArgs(recognize_boolean(varargs));
   xmlNodePtr child = checkDoc(cur,sig); 
@@ -843,15 +905,30 @@
   return sig;
 }
 
+template<> TextType*
+XMLReaderImpl::parse<TextType>(xmlNodePtr& cur)
+{
+  Locator* loc = getLocator(cur);
+  std::string name = getAttribute(cur,"id");
+  if (!checkNewType(name,loc))
+    return 0;
+  xmlNodePtr child = cur->children;
+  Documentation* theDoc = parse<Documentation>(child);
+  Type* result = ast->new_IntrinsicType(name,bundle,textTy,loc);
+  if (theDoc)
+    result->setDoc(theDoc);
+  return llvm::cast<TextType>(result);
+}
+
 template<> OpaqueType*
 XMLReaderImpl::parse<OpaqueType>(xmlNodePtr& cur)
 {
   hlvmAssert(getToken(cur->name)==TKN_opaque);
   std::string name = getAttribute(cur,"id");
-  if (bundle->find_type(name))
-    error(loc,"Type '" + name + "' was already defined");
+  if (!checkNewType(name,loc))
+    return 0;
   Locator* loc = getLocator(cur);
-  OpaqueType* result = ast->new_OpaqueType(name,loc);
+  OpaqueType* result = ast->new_OpaqueType(name, false, bundle, loc);
   checkDoc(cur,result);
   return result;
 }
@@ -863,19 +940,19 @@
   Locator* loc = getLocator(cur);
   std::string name, type;
   getNameType(cur, name, type);
-  if (Constant* lkbl = bundle->find_const(name)) 
+  if (Constant* lkbl = bundle->getConst(name)) 
     error(loc, "Name '" + name + "' is already in use");
   const char* cnst = getAttribute(cur, "const", false);
   const char* lnkg = getAttribute(cur, "linkage", false);
   const char* init = getAttribute(cur, "init", false);
   const Type* Ty = getType(type);
-  Variable* var = ast->new_Variable(name,Ty,loc);
+  Variable* var = ast->new_Variable(name, bundle, Ty,loc);
   if (cnst)
     var->setIsConstant(recognize_boolean(cnst));
   if (lnkg)
     var->setLinkageKind(recognize_LinkageKinds(lnkg));
   if (init) {
-    Constant* initializer = bundle->find_const(init);
+    Constant* initializer = bundle->getConst(init);
     if (initializer)
       var->setInitializer(initializer);
     else 
@@ -896,7 +973,7 @@
   const char* init = getAttribute(cur,"init",false);
   Constant*initializer = 0;
   if (init) {
-    initializer = bundle->find_const(init);
+    initializer = bundle->getConst(init);
     if (!initializer)
       error(loc,std::string("Initializer '") + init + "' not found .");
   }
@@ -930,22 +1007,28 @@
 
   // Didn't find an autovar? Try a constant value.
   if (!referent)
-    referent= bundle->find_const(id);
+    referent= bundle->getConst(id);
     
   // Didn't find a linkable? Try an error message for size
   if (!referent)
       error(loc,std::string("Referent '") + id + "' not found");
 
-  return ast->AST::new_ReferenceOp(referent, loc);
+  ReferenceOp* refop = ast->AST::new_ReferenceOp(referent, loc);
+  checkDoc(cur,refop);
+  return refop;
 }
 
 template<class OpClass>
 OpClass*
 XMLReaderImpl::parseNilaryOp(xmlNodePtr& cur)
 {
-  xmlNodePtr child = cur->children;
   Locator* loc = getLocator(cur);
-  return ast->AST::new_NilaryOp<OpClass>(loc);
+  xmlNodePtr child = cur->children;
+  Documentation* doc = parse<Documentation>(child); 
+  OpClass* result = ast->AST::new_NilaryOp<OpClass>(bundle,loc);
+  if (doc)
+    result->setDoc(doc);
+  return result;
 }
 
 template<class OpClass>
@@ -954,9 +1037,13 @@
 {
   Locator* loc = getLocator(cur);
   xmlNodePtr child = cur->children;
+  Documentation* doc = parse<Documentation>(child); 
   if (child && skipBlanks(child)) {
     Operator* oprnd1 = parseOperator(child);
-    return ast->AST::new_UnaryOp<OpClass>(oprnd1,loc);
+    OpClass* result = ast->AST::new_UnaryOp<OpClass>(oprnd1,bundle,loc);
+    if (doc)
+      result->setDoc(doc);
+    return result;
   } else
     error(loc,std::string("Operator '") + 
       reinterpret_cast<const char*>(cur->name) + "' requires one operand.");
@@ -969,12 +1056,17 @@
 {
   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);
-      return ast->AST::new_BinaryOp<OpClass>(oprnd1,oprnd2,loc);
+      OpClass* result =  
+        ast->AST::new_BinaryOp<OpClass>(oprnd1,oprnd2,bundle,loc);
+      if (doc)
+        result->setDoc(doc);
+      return result;
     } else {
       error(loc,std::string("Operator '") + 
             reinterpret_cast<const char*>(cur->name) + 
@@ -993,6 +1085,7 @@
 {
   Locator* loc = getLocator(cur);
   xmlNodePtr child = cur->children;
+  Documentation* doc = parse<Documentation>(child); 
   if (child && skipBlanks(child)) {
     Operator* oprnd1 = parseOperator(child);
     child = child->next;
@@ -1001,7 +1094,11 @@
       child = child->next;
       if (child && skipBlanks(child)) {
         Operator* oprnd3 = parseOperator(child);
-        return ast->AST::new_TernaryOp<OpClass>(oprnd1,oprnd2,oprnd3,loc);
+        OpClass* result =  
+          ast->AST::new_TernaryOp<OpClass>(oprnd1,oprnd2,oprnd3,bundle,loc);
+        if (doc)
+          result->setDoc(doc);
+        return result;
       } else
         error(loc,std::string("Operator '") + 
               reinterpret_cast<const char*>(cur->name) +
@@ -1022,6 +1119,7 @@
 {
   Locator* loc = getLocator(cur);
   xmlNodePtr child = cur->children;
+  Documentation* doc = parse<Documentation>(child); 
   MultiOperator::OprndList ol;
   while (child != 0 && skipBlanks(child)) {
     Operator* operand = parseOperator(child);
@@ -1031,7 +1129,10 @@
       break;
     child = child->next;
   }
-  return ast->AST::new_MultiOp<OpClass>(ol,loc);
+  OpClass* result = ast->AST::new_MultiOp<OpClass>(ol,bundle,loc);
+  if (doc)
+    result->setDoc(doc);
+  return result;
 }
 
 template<> Block*
@@ -1041,9 +1142,9 @@
   hlvmAssert(func != 0);
   Locator* loc = getLocator(cur);
   const char* label = getAttribute(cur, "label",false);
-  xmlNodePtr child = cur->children;
-  MultiOperator::OprndList ops;
   Block* result = ast->new_Block(loc);
+  xmlNodePtr child = checkDoc(cur,result);
+  MultiOperator::OprndList ops;
   block = result;
   if (label)
     block->setLabel(label);
@@ -1069,7 +1170,7 @@
   Locator* loc = getLocator(cur);
   std::string name, type;
   getNameType(cur, name, type);
-  Constant* lkbl = bundle->find_const(name);
+  Constant* lkbl = bundle->getConst(name);
   if (lkbl) {
     if (llvm::isa<Function>(lkbl)) {
       func = llvm::cast<Function>(lkbl);
@@ -1084,7 +1185,7 @@
   } else {
     const Type* Ty = getType(type);
     if (llvm::isa<SignatureType>(Ty)) {
-      func = ast->new_Function(name,llvm::cast<SignatureType>(Ty),loc);
+      func = ast->new_Function(name,bundle,llvm::cast<SignatureType>(Ty),loc);
       const char* lnkg = getAttribute(cur, "linkage", false);
       if (lnkg)
         func->setLinkageKind(recognize_LinkageKinds(lnkg));
@@ -1092,8 +1193,7 @@
       error(loc,"Invalid type for a function, must be signature");
     }
   }
-  checkDoc(cur,func);
-  xmlNodePtr child = cur->children;
+  xmlNodePtr child = checkDoc(cur,func);
   if (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE) {
     Block* b = parse<Block>(child);
     b->setParent(func);
@@ -1107,10 +1207,9 @@
   hlvmAssert(getToken(cur->name) == TKN_program && "Expecting program element");
   Locator* loc = getLocator(cur);
   std::string name(getAttribute(cur, "id"));
-  Program* program = ast->new_Program(name,loc);
+  Program* program = ast->new_Program(name,bundle,loc);
   func = program;
-  checkDoc(cur,func);
-  xmlNodePtr child = cur->children;
+  xmlNodePtr child = checkDoc(cur,func);
   if (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE) {
     Block* b = parse<Block>(child);
     b->setParent(func);
@@ -1137,24 +1236,22 @@
   std::string pubid(getAttribute(cur, "id"));
   Locator* loc = getLocator(cur);
   bundle = ast->new_Bundle(pubid,loc);
-  xmlNodePtr child = cur->children;
+  xmlNodePtr child = checkDoc(cur,bundle);
   while (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE) 
   {
     int tkn = getToken(child->name);
     Node* n = 0;
     switch (tkn) {
-      case TKN_doc      : {
-        Documentation* theDoc = parse<Documentation>(child);
-        if (theDoc)
-          bundle->setDoc(theDoc);
-        break;
-      }
-      case TKN_import      : { n = parse<Import>(child); break; }
+      case TKN_alias       : { n = parseAlias(child); break; }
       case TKN_array       : { n = parse<ArrayType>(child); break; }
+      case TKN_any         : { n = parse<AnyType>(child); break; }
+      case TKN_boolean     : { n = parse<BooleanType>(child); break; }
+      case TKN_buffer      : { n = parse<BufferType>(child); break; }
+      case TKN_character   : { n = parse<CharacterType>(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_import      : { n = parse<Import>(child); break; }
       case TKN_opaque      : { n = parse<OpaqueType>(child); break; }
       case TKN_pointer     : { n = parse<PointerType>(child); break; }
       case TKN_program     : { n = parse<Program>(child); break; }
@@ -1162,7 +1259,10 @@
       case TKN_real        : { n = parse<RealType>(child); break; }
       case TKN_signature   : { n = parse<SignatureType>(child); break; }
       case TKN_signed      : { n = parseInteger(child,true); break; }
+      case TKN_stream      : { n = parse<StreamType>(child); break; }
+      case TKN_string      : { n = parse<StringType>(child); break; }
       case TKN_structure   : { n = parse<StructureType>(child); break; }
+      case TKN_text        : { n = parse<TextType>(child); break; }
       case TKN_unsigned    : { n = parseInteger(child,false); break; }
       case TKN_variable    : { n = parse<Variable>(child); break; }
       case TKN_vector      : { n = parse<VectorType>(child); break; }

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

==============================================================================
--- hlvm/trunk/hlvm/Writer/XMLWriter.cpp (original)
+++ hlvm/trunk/hlvm/Writer/XMLWriter.cpp Sat Jul  7 19:02:42 2007
@@ -182,50 +182,67 @@
 }
 
 template<> void 
+XMLWriterImpl::WriterPass::put(const NamedType* t)
+{
+  startElement("alias");
+  writeAttribute("id",t->getName());
+  writeAttribute("is",t->getType()->getName());
+  putDoc(t);
+  endElement();
+}
+
+template<> void 
 XMLWriterImpl::WriterPass::put(const AnyType* t)
 {
-  startElement("intrinsic");
+  if (t->isIntrinsic())
+    return;
+  startElement("any");
   writeAttribute("id",t->getName());
-  writeAttribute("is","any");
   putDoc(t);
+  endElement();
 }
 
 template<> void 
 XMLWriterImpl::WriterPass::put(const StringType* t)
 {
-  startElement("intrinsic");
+  if (t->isIntrinsic())
+    return;
+  startElement("string");
   writeAttribute("id",t->getName());
-  writeAttribute("is","string");
+  writeAttribute("encoding",t->getEncoding());
   putDoc(t);
+  endElement();
 }
 
 template<>void
 XMLWriterImpl::WriterPass::put(const BooleanType* t)
 {
-  startElement("intrinsic");
+  if (t->isIntrinsic())
+    return;
+  startElement("boolean");
   writeAttribute("id",t->getName());
-  writeAttribute("is","bool");
   putDoc(t);
+  endElement();
 }
 
 template<> void
 XMLWriterImpl::WriterPass::put(const CharacterType* t)
 {
-  startElement("intrinsic");
+  if (t->isIntrinsic())
+    return;
+  startElement("character");
   writeAttribute("id",t->getName());
-  writeAttribute("is","char");
+  writeAttribute("encoding",t->getEncoding());
   putDoc(t);
+  endElement();
 }
 
 template<> void
 XMLWriterImpl::WriterPass::put(const IntegerType* t)
 {
-  const char* primName = t->getPrimitiveName();
-  if (primName) {
-    startElement("intrinsic");
-    writeAttribute("id",t->getName());
-    writeAttribute("is",primName);
-  } else if (t->isSigned()) {
+  if (t->isIntrinsic())
+    return;
+  if (t->isSigned()) {
     startElement("signed");
     writeAttribute("id",t->getName());
     writeAttribute("bits", llvm::utostr(t->getBits()));
@@ -235,20 +252,27 @@
     writeAttribute("bits", llvm::utostr(t->getBits()));
   }
   putDoc(t);
+  endElement();
 }
 
 template<> void
 XMLWriterImpl::WriterPass::put(const RangeType* t)
 {
+  if (t->isIntrinsic())
+    return;
   startElement("range");
   writeAttribute("id",t->getName());
   writeAttribute("min",t->getMin());
   writeAttribute("max",t->getMax());
+  putDoc(t);
+  endElement();
 }
 
 template<> void 
 XMLWriterImpl::WriterPass::put(const EnumerationType* t)
 {
+  if (t->isIntrinsic())
+    return;
   startElement("enumeration");
   writeAttribute("id",t->getName());
   putDoc(t);
@@ -259,74 +283,76 @@
     writeAttribute("id",*I);
     endElement();
   }
+  endElement();
 }
 
 template<> void
 XMLWriterImpl::WriterPass::put(const RealType* t)
 {
-  const char* primName = t->getPrimitiveName();
-  if (primName) {
-    startElement("intrinsic");
-    writeAttribute("id",t->getName());
-    writeAttribute("is",primName);
-  } else {
-    startElement("real");
-    writeAttribute("id",t->getName());
-    writeAttribute("mantissa", llvm::utostr(t->getMantissa()));
-    writeAttribute("exponent", llvm::utostr(t->getExponent()));
-  }
-  putDoc(t);
-}
-
-template<> void
-XMLWriterImpl::WriterPass::put(const OctetType* t)
-{
-  startElement("intrinsic");
+  if (t->isIntrinsic())
+    return;
+  startElement("real");
   writeAttribute("id",t->getName());
-  writeAttribute("is","octet");
+  writeAttribute("mantissa", llvm::utostr(t->getMantissa()));
+  writeAttribute("exponent", llvm::utostr(t->getExponent()));
   putDoc(t);
+  endElement();
 }
 
 template<> void
 XMLWriterImpl::WriterPass::put(const OpaqueType* op)
 {
+  if (op->isIntrinsic())
+    return;
   startElement("opaque");
   writeAttribute("id",op->getName());
   putDoc(op);
+  endElement();
 }
 
 template<> void 
 XMLWriterImpl::WriterPass::put(const PointerType* t)
 {
+  if (t->isIntrinsic())
+    return;
   startElement("pointer");
   writeAttribute("id", t->getName());
   writeAttribute("to", t->getElementType());
   putDoc(t);
+  endElement();
 }
 
 template<> void 
 XMLWriterImpl::WriterPass::put(const ArrayType* t)
 {
+  if (t->isIntrinsic())
+    return;
   startElement("array");
   writeAttribute("id", t->getName());
   writeAttribute("of", t->getElementType());
   writeAttribute("length", t->getMaxSize());
   putDoc(t);
+  endElement();
 }
 
 template<> void 
 XMLWriterImpl::WriterPass::put(const VectorType* t)
 {
+  if (t->isIntrinsic())
+    return;
   startElement("vector");
   writeAttribute("id", t->getName());
   writeAttribute("of", t->getElementType());
   writeAttribute("length", t->getSize());
   putDoc(t);
+  endElement();
 }
 
 template<> void 
 XMLWriterImpl::WriterPass::put(const StructureType* t)
 {
+  if (t->isIntrinsic())
+    return;
   startElement("structure");
   writeAttribute("id",t->getName());
   putDoc(t);
@@ -339,11 +365,34 @@
     putDoc(field);
     endElement();
   }
+  endElement();
+}
+
+template<> void 
+XMLWriterImpl::WriterPass::put(const ContinuationType* t)
+{
+  if (t->isIntrinsic())
+    return;
+  startElement("continuation");
+  writeAttribute("id",t->getName());
+  putDoc(t);
+  for (ContinuationType::const_iterator I = t->begin(), E = t->end(); 
+       I != E; ++I) {
+    startElement("field");
+    Field* field = cast<Field>(*I);
+    writeAttribute("id",field->getName());
+    writeAttribute("type",field->getType());
+    putDoc(field);
+    endElement();
+  }
+  endElement();
 }
 
 template<> void 
 XMLWriterImpl::WriterPass::put(const SignatureType* t)
 {
+  if (t->isIntrinsic())
+    return;
   startElement("signature");
   writeAttribute("id",t->getName());
   writeAttribute("result",t->getResultType());
@@ -359,14 +408,52 @@
     putDoc(param);
     endElement();
   }
+  endElement();
+}
+
+template<> void 
+XMLWriterImpl::WriterPass::put(const StreamType* t)
+{
+  if (t->isIntrinsic())
+    return;
+  startElement("stream");
+  writeAttribute("id",t->getName());
+  putDoc(t);
+  endElement();
+}
+
+template<> void 
+XMLWriterImpl::WriterPass::put(const TextType* t)
+{
+  if (t->isIntrinsic())
+    return;
+  startElement("text");
+  writeAttribute("id",t->getName());
+  putDoc(t);
+  endElement();
+}
+
+template<> void 
+XMLWriterImpl::WriterPass::put(const BufferType* t)
+{
+  if (t->isIntrinsic())
+    return;
+  startElement("buffer");
+  writeAttribute("id",t->getName());
+  putDoc(t);
+  endElement();
 }
 
 template<> void
 XMLWriterImpl::WriterPass::put<ConstantAny>(const ConstantAny* 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());
+    putDoc(i);
+  }
+  putConstantValue(i->getValue(),true);
 }
 
 template<> void 
@@ -376,6 +463,7 @@
     startElement("constant");
     writeAttribute("id",i->getName());
     writeAttribute("type",i->getType()->getName());
+    putDoc(i);
   }
   if (i->getValue())
     startElement("true");
@@ -391,6 +479,7 @@
     startElement("constant");
     writeAttribute("id",i->getName());
     writeAttribute("type",i->getType()->getName());
+    putDoc(i);
   }
   startElement("char");
   writeString(i->getValue());
@@ -404,26 +493,13 @@
     startElement("constant");
     writeAttribute("id",i->getName());
     writeAttribute("type",i->getType()->getName());
+    putDoc(i);
   }
   startElement("enum");
   writeString(i->getValue());
   endElement();
 }
 
-template<> void
-XMLWriterImpl::WriterPass::put(const ConstantOctet* i, bool nested)
-{
-  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(const ConstantInteger* i, bool nested)
 {
@@ -431,6 +507,7 @@
     startElement("constant");
     writeAttribute("id",i->getName());
     writeAttribute("type",i->getType()->getName());
+    putDoc(i);
   }
   switch (i->getBase()) {
     case 2: startElement("bin"); break;
@@ -449,6 +526,7 @@
     startElement("constant");
     writeAttribute("id",r->getName());
     writeAttribute("type",r->getType()->getName());
+    putDoc(r);
   }
   startElement("dbl");
   writeString(r->getValue());
@@ -462,8 +540,9 @@
     startElement("constant");
     writeAttribute("id",t->getName());
     writeAttribute("type",t->getType()->getName());
+    putDoc(t);
   }
-  startElement("string");
+  startElement("str");
   writeString(t->getValue());
   endElement();
 }
@@ -475,6 +554,7 @@
     startElement("constant");
     writeAttribute("id",i->getName());
     writeAttribute("type",i->getType()->getName());
+    putDoc(i);
   }
   startElement("ptr");
   writeAttribute("to",i->getValue()->getName());
@@ -488,6 +568,7 @@
     startElement("constant");
     writeAttribute("id",i->getName());
     writeAttribute("type",i->getType()->getName());
+    putDoc(i);
   }
   startElement("arr");
   for (ConstantArray::const_iterator I = i->begin(), E = i->end(); I != E; ++I)
@@ -502,6 +583,7 @@
     startElement("constant");
     writeAttribute("id",i->getName());
     writeAttribute("type",i->getType()->getName());
+    putDoc(i);
   }
   startElement("vect");
   for (ConstantArray::const_iterator I = i->begin(), E = i->end(); I != E; ++I)
@@ -516,6 +598,7 @@
     startElement("constant");
     writeAttribute("id",i->getName());
     writeAttribute("type",i->getType()->getName());
+    putDoc(i);
   }
   startElement("struct");
   for (ConstantStructure::const_iterator I = i->begin(), E = i->end(); 
@@ -531,6 +614,7 @@
     startElement("constant");
     writeAttribute("id",i->getName());
     writeAttribute("type",i->getType()->getName());
+    putDoc(i);
   }
   startElement("cont");
   for (ConstantContinuation::const_iterator I = i->begin(), E = i->end(); 
@@ -547,7 +631,6 @@
     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;
@@ -940,27 +1023,32 @@
   if (mode & Pass::PreOrderTraversal) {
     switch (n->getID()) 
     {
+      case BundleID:               put(cast<Bundle>(n)); break;
+      /* TYPES */
       case AnyTypeID:              put(cast<AnyType>(n)); break;
-      case StringTypeID:           put(cast<StringType>(n)); break;
+      case ArrayTypeID:            put(cast<ArrayType>(n)); break;
       case BooleanTypeID:          put(cast<BooleanType>(n)); break;
-      case BundleID:               put(cast<Bundle>(n)); break;
+      case BufferTypeID:           put(cast<BufferType>(n)); break;
       case CharacterTypeID:        put(cast<CharacterType>(n)); break;
-      case IntegerTypeID:          put(cast<IntegerType>(n)); break;
-      case RangeTypeID:            put(cast<RangeType>(n)); break;
+      case ContinuationTypeID:     put(cast<ContinuationType>(n)); break;
       case EnumerationTypeID:      put(cast<EnumerationType>(n)); break;
-      case RealTypeID:             put(cast<RealType>(n)); break;
-      case OctetTypeID:            put(cast<OctetType>(n)); break;
+      case IntegerTypeID:          put(cast<IntegerType>(n)); break;
+      case NamedTypeID:            put(cast<NamedType>(n)); break;
       case OpaqueTypeID:           put(cast<OpaqueType>(n)); break;
       case PointerTypeID:          put(cast<PointerType>(n)); break;
-      case ArrayTypeID:            put(cast<ArrayType>(n)); break;
-      case VectorTypeID:           put(cast<VectorType>(n)); break;
-      case StructureTypeID:        put(cast<StructureType>(n)); break;
+      case RangeTypeID:            put(cast<RangeType>(n)); break;
+      case RealTypeID:             put(cast<RealType>(n)); break;
       case SignatureTypeID:        put(cast<SignatureType>(n)); break;
+      case StreamTypeID:           put(cast<StreamType>(n)); break;
+      case StringTypeID:           put(cast<StringType>(n)); break;
+      case StructureTypeID:        put(cast<StructureType>(n)); break;
+      case TextTypeID:             put(cast<TextType>(n)); break;
+      case VectorTypeID:           put(cast<VectorType>(n)); break;
+      /* CONSTANTS */
       case ConstantAnyID:          
       case ConstantBooleanID:      
       case ConstantCharacterID:    
       case ConstantEnumeratorID:   
-      case ConstantOctetID:        
       case ConstantIntegerID:      
       case ConstantRealID:         
       case ConstantStringID:       
@@ -970,10 +1058,12 @@
       case ConstantStructureID:    
       case ConstantContinuationID: 
         putConstantValue(cast<ConstantValue>(n),false); break;
+      /* LINKABLES */
       case VariableID:             put(cast<Variable>(n)); break;
       case FunctionID:             put(cast<Function>(n)); break;
       case ProgramID:              put(cast<Program>(n)); break;
       case BlockID:                put(cast<Block>(n)); break;
+      /* OPERATORS */
       case AutoVarOpID:            put(cast<AutoVarOp>(n)); break;
       case NegateOpID:             put(cast<NegateOp>(n)); break;
       case ComplementOpID:         put(cast<ComplementOp>(n)); break;
@@ -1024,7 +1114,33 @@
     }
   }
   if (mode & Pass::PostOrderTraversal) {
-    endElement();
+    // The types print their own end element because intrinsic types
+    // don't print at all so we can't assume a startElement.
+    switch (n->getID()) 
+    {
+      case AnyTypeID: 
+      case ArrayTypeID:  
+      case BooleanTypeID:
+      case BufferTypeID:
+      case CharacterTypeID:
+      case EnumerationTypeID:
+      case IntegerTypeID: 
+      case NamedTypeID:
+      case OpaqueTypeID:   
+      case PointerTypeID: 
+      case RangeTypeID:  
+      case RealTypeID:      
+      case StringTypeID:
+      case StreamTypeID:
+      case StructureTypeID:
+      case SignatureTypeID:
+      case TextTypeID:
+      case VectorTypeID: 
+        break;
+      default:
+        // For everything else, there was a startElement, so just end it now
+        endElement();
+    }
   }
 }
 

Added: hlvm/trunk/test/invalid/rename.hlx
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/invalid/rename.hlx?rev=38365&view=auto

==============================================================================
--- hlvm/trunk/test/invalid/rename.hlx (added)
+++ hlvm/trunk/test/invalid/rename.hlx Sat Jul  7 19:02:42 2007
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<hlvm xmlns="http://hlvm.org/src/hlvm/Reader/XML/HLVM.rng" pubid="http://hlvm.org/src/hlvm/test/invalid/rename.hlx">
+  <bundle id="rename">
+    <intrinsic id="one" is="u32"/>
+    <intrinsic id="one" is="s32"/>
+    <constant id="two" type="one"><dec>2</dec></constant>
+    <constant id="two" type="one"><dec>3</dec></constant>
+    <variable id="three" type="one" init="two"/>
+    <variable id="three" type="one" init="two"/>
+    <signature id="callee_type" result="s32"/>
+    <function id="four" type="callee_type">
+      <block>
+        <result>
+          <ref id="two"/>
+        </result>
+        <ret/>
+      </block>
+    </function>
+    <function id="four" type="callee_type">
+      <block>
+        <result>
+          <ref id="two"/>
+        </result>
+        <ret/>
+      </block>
+    </function>
+    <program id="rename">
+      <block>
+        <result>
+          <call>
+            <ref id="four"/>
+          </call>
+        </result>
+        <ret/>
+      </block>
+    </program>
+  </bundle>
+</hlvm>

Modified: hlvm/trunk/test/return0/helloworld.hlx
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/return0/helloworld.hlx?rev=38365&r1=38364&r2=38365&view=diff

==============================================================================
--- hlvm/trunk/test/return0/helloworld.hlx (original)
+++ hlvm/trunk/test/return0/helloworld.hlx Sat Jul  7 19:02:42 2007
@@ -3,10 +3,10 @@
       pubid="http://hlvm.org/src/hlvm/test/return0/helloworld.hlx">
   <bundle id="helloworld">
     <constant id="hw" type="string">
-      <string>Hello, World
</string>
+      <str>Hello, World
</str>
     </constant>
     <constant id="stdout" type="string">
-      <string>hlvm:std:out</string>
+      <str>hlvm:std:out</str>
     </constant>
     <constant id="zero" type="s32">
       <dec>0</dec>

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

==============================================================================
--- hlvm/trunk/test/xml2xml/array.hlx (original)
+++ hlvm/trunk/test/xml2xml/array.hlx Sat Jul  7 19:02:42 2007
@@ -2,6 +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"/>
-    <intrinsic id="someType" is="any"/>
+    <any id="someType"/>
   </bundle>
 </hlvm>

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

==============================================================================
--- hlvm/trunk/test/xml2xml/bundle.hlx (original)
+++ hlvm/trunk/test/xml2xml/bundle.hlx Sat Jul  7 19:02:42 2007
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <hlvm xmlns="http://hlvm.org/src/hlvm/Reader/XML/HLVM.rng" pubid="name">
   <bundle id="name">
-    <intrinsic id="nada" is="u32"/>
+    <unsigned id="nada" bits="32"/>
   </bundle>
 </hlvm>

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

==============================================================================
--- hlvm/trunk/test/xml2xml/doc.hlx (original)
+++ hlvm/trunk/test/xml2xml/doc.hlx Sat Jul  7 19:02:42 2007
@@ -2,72 +2,18 @@
 <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>
-    <intrinsic id="1" is="any">
+    <any id="someType">
       <doc>Any can hold anything. It provides the dynamic typing</doc>
-    </intrinsic>
-    <intrinsic id="10" is="s64">
-      <doc>Signed 64 bit integer</doc>
-    </intrinsic>
-    <intrinsic id="11" is="s32">
-      <doc>Signed 32 bit integer</doc>
-    </intrinsic>
-    <intrinsic id="12" is="s16">
-      <doc>Signed 16 bit integer</doc>
-    </intrinsic>
-    <intrinsic id="13" is="s8">
-      <doc>Signed 8 bit integer</doc>
-    </intrinsic>
-    <intrinsic id="14" is="octet">
-      <doc>An 8-bit non-numerical quantity</doc>
-    </intrinsic>
-    <intrinsic id="15" is="u128">
-      <doc>Unsigned 128 bit integer</doc>
-    </intrinsic>
-    <intrinsic id="16" is="u64">
-      <doc>Unsigned 64 bit integer</doc>
-    </intrinsic>
-    <intrinsic id="17" is="u32">
-      <doc>Unsigned 32 bit integer</doc>
-    </intrinsic>
-    <intrinsic id="18" is="u16">
-      <doc>Unsigned 16 bit integer</doc>
-    </intrinsic>
-    <intrinsic id="19" is="u8">
-      <doc>Unsigned 8 bit integer</doc>
-    </intrinsic>
-    <intrinsic id="2" is="bool">
-      <doc>Obviously this is a boolean</doc>
-    </intrinsic>
-    <intrinsic id="3" is="char">
-      <doc>UTF-16 character</doc>
-    </intrinsic>
-    <intrinsic id="4" is="f128">
-      <doc>IEEE Quad Floating Point (128 bits)</doc>
-    </intrinsic>
-    <intrinsic id="5" is="f80">
-      <doc>IEEE Extended Double Floating Point (80 bits)</doc>
-    </intrinsic>
-    <intrinsic id="6" is="f64">
-      <doc>IEEE Double Floating Point (64 bits)</doc>
-    </intrinsic>
-    <intrinsic id="7" is="f44">
-      <doc>IEEE Extended Single Floating Point (43 bits)</doc>
-    </intrinsic>
-    <intrinsic id="8" is="f32">
-      <doc>IEEE Single Floating Point (32 bits)</doc>
-    </intrinsic>
-    <intrinsic id="9" is="s128">
-      <doc>Signed 128 bit integer</doc>
-    </intrinsic>
-    <pointer id="aPointerType" to="someType">
-      <doc>A Pointer Type</doc>
-    </pointer>
-    <vector id="aVector" of="f32" length="128">
-      <doc>Vector doc</doc>
-    </vector>
+    </any>
     <array id="anArray" of="someType" length="128">
       <doc><p>Array Doc</p></doc>
     </array>
+    <boolean id="myBoolean">
+      <doc>Boolean type</doc>
+    </boolean>
+    <character id="myChar" encoding="utf-16">
+      <doc>Character type</doc>
+    </character>
     <enumeration id="anEnumeration">
       <doc>This is anEnumeration</doc>
       <enumerator id="one"/>
@@ -75,18 +21,33 @@
       <enumerator id="three"/>
       <enumerator id="four"/>
     </enumeration>
-    <signature id="sig1" result="someType" varargs="true">
+    <signed id="signed32Bit" bits="32">
+      <doc>Signed 32 bit integer</doc>
+    </signed>
+    <signature id="sig1" result="signed32Bit" varargs="true">
       <doc>This is signature doc</doc>
       <arg id="arg1" type="someType">
         <doc>Doc for "arg1"</doc>
       </arg>
-      <arg id="arg2" type="someType">
+      <arg id="arg2" type="anEnumeration">
         <doc><i>Doc for "arg2"</i></doc>
       </arg>
     </signature>
-    <intrinsic id="someType" is="any">
-      <doc><p>Atom Doc</p></doc>
-    </intrinsic>
+    <opaque id="nada">
+      <doc>Opaque types can't used. Useful for encapsulation</doc>
+    </opaque>
+    <pointer id="myPointer" to="sig1">
+      <doc>This is a pointer to a function</doc>
+    </pointer>
+    <range id="myRange" min="-2" max="2">
+      <doc>Pretty small range, huh?</doc>
+    </range>
+    <real id="myReal" mantissa="23" exponent="8">
+      <doc>Should be equal to IEEE 754 single precision</doc>
+    </real>
+    <string id="myString" encoding="ucs">
+      <doc>I wonder what encoding's HLVM will support?</doc>
+    </string>
     <structure id="struct2">
       <doc>This is structure doc</doc>
       <field id="field1" type="someType">
@@ -96,6 +57,53 @@
         <doc>Documentation for field 2</doc>
       </field>
     </structure>
+    <vector id="aVector" of="f32" length="128">
+      <doc>Vector doc</doc>
+    </vector>
+    <unsigned id="unsigned32Bit" bits="32">
+      <doc>Unsigned 32 bit integer</doc>
+    </unsigned>
+    <constant id="s32val" type="signed32Bit">
+      <doc>32-bit signed integer</doc>
+      <dec>1234</dec>
+    </constant>
+    <constant id="unchanging" type="myBoolean">
+      <true/>
+    </constant>
+    <constant id="intval" type="s32">
+      <doc>32-bit signed integer</doc>
+      <dec>4321</dec>
+    </constant>
+    <function id="myFunc" type="sig1" linkage="internal">
+      <doc><i>This function doesn't do much</i></doc>
+      <block>
+        <doc><i>This block just returns a constant result</i></doc>
+        <result>
+          <ref id="s32val">
+            <doc>
+              <b>This just references the intval constant as the result</b>
+            </doc>
+          </ref>
+        </result>
+        <ret/>
+      </block>
+    </function>
+    <program id="doc">
+      <doc>
+        <i>This program is a placeholder for testing doc elements</i>
+      </doc>
+      <block>
+        <doc>Again, doesn't do much but return a result</doc>
+        <result>
+          <ref id="intval">
+            <doc>
+              <b>This just references the intval constant as the result</b>
+            </doc>
+          </ref>
+        </result>
+        <ret/>
+      </block>
+    </program>
     <variable id="var" type="int">
       <doc><p>This is documentation for a <i>var</i>iable</p></doc>
     </variable>

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

==============================================================================
--- hlvm/trunk/test/xml2xml/helloworld.hlx (original)
+++ hlvm/trunk/test/xml2xml/helloworld.hlx Sat Jul  7 19:02:42 2007
@@ -5,10 +5,10 @@
       <dec>0</dec>
     </constant>
     <constant id="hw" type="string">
-      <string>Hello, World</string>
+      <str>Hello, World</str>
     </constant>
     <constant id="stdout" type="string">
-      <string>hlvm:std:out</string>
+      <str>hlvm:std:out</str>
     </constant>
     <program id="helloworld">
       <block>

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

==============================================================================
--- hlvm/trunk/test/xml2xml/intrinsics.hlx (original)
+++ hlvm/trunk/test/xml2xml/intrinsics.hlx Sat Jul  7 19:02:42 2007
@@ -1,24 +1,37 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <hlvm xmlns="http://hlvm.org/src/hlvm/Reader/XML/HLVM.rng" pubid="name">
   <bundle id="bundle">
-    <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"/>
+    <alias id="2" is="bool"/>
+    <alias id="3" is="buffer"/>
+    <alias id="4" is="char"/>
+    <alias id="5" is="double"/>
+    <alias id="6" is="f32"/>
+    <alias id="7" is="f44"/>
+    <alias id="8" is="f64"/>
+    <alias id="9" is="f80"/>
+    <alias id="10" is="f128"/>
+    <alias id="11" is="float"/>
+    <alias id="12" is="int"/>
+    <alias id="13" is="long"/>
+    <alias id="14" is="octet"/>
+    <alias id="15" is="r8"/>
+    <alias id="16" is="r16"/>
+    <alias id="17" is="r32"/>
+    <alias id="18" is="r64"/>
+    <alias id="20" is="s8"/>
+    <alias id="21" is="s16"/>
+    <alias id="22" is="s32"/>
+    <alias id="23" is="s64"/>
+    <alias id="24" is="s128"/>
+    <alias id="25" is="short"/>
+    <alias id="26" is="stream"/>
+    <alias id="27" is="string"/>
+    <alias id="28" is="text"/>
+    <alias id="29" is="u8"/>
+    <alias id="30" is="u16"/>
+    <alias id="31" is="u32"/>
+    <alias id="32" is="u64"/>
+    <alias id="33" is="u128"/>
+    <alias id="34" is="void"/>
   </bundle>
 </hlvm>

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

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

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

==============================================================================
--- hlvm/trunk/test/xml2xml/resolve.hlx (original)
+++ hlvm/trunk/test/xml2xml/resolve.hlx Sat Jul  7 19:02:42 2007
@@ -2,7 +2,7 @@
 <hlvm xmlns="http://hlvm.org/src/hlvm/Reader/XML/HLVM.rng" pubid="name">
   <bundle id="bundle">
     <pointer id="PtrToSomeType" to="SomeType"/>
-    <intrinsic id="SomeType" is="any"/>
+    <any id="SomeType"/>
     <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=38365&r1=38364&r2=38365&view=diff

==============================================================================
--- hlvm/trunk/test/xml2xml/signature.hlx (original)
+++ hlvm/trunk/test/xml2xml/signature.hlx Sat Jul  7 19:02:42 2007
@@ -8,6 +8,6 @@
       <arg id="arg1" type="someType"/>
       <arg id="arg1" type="someType"/>
     </signature>
-    <intrinsic id="someType" is="any"/>
+    <any id="someType"/>
   </bundle>
 </hlvm>

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

==============================================================================
--- hlvm/trunk/test/xml2xml/structure.hlx (original)
+++ hlvm/trunk/test/xml2xml/structure.hlx Sat Jul  7 19:02:42 2007
@@ -1,7 +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">
-    <intrinsic id="someType" is="any"/>
+    <any id="someType"/>
     <structure id="struct1">
       <field id="field1" type="someType"/>
     </structure>

Modified: hlvm/trunk/tools/hlvm-config/hlvm-config.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/tools/hlvm-config/hlvm-config.cpp?rev=38365&r1=38364&r2=38365&view=diff

==============================================================================
--- hlvm/trunk/tools/hlvm-config/hlvm-config.cpp (original)
+++ hlvm/trunk/tools/hlvm-config/hlvm-config.cpp Sat Jul  7 19:02:42 2007
@@ -46,32 +46,16 @@
   "NamedType",
   "Bundle",
   "Import",
+  "AnyType",
   "BooleanType",
   "CharacterType",
-  "OctetType",
-  "UInt8Type",
-  "UInt16Type",
-  "UInt32Type",
-  "UInt64Type",
-  "UInt128Type",
-  "SInt8Type",
-  "SInt16Type",
-  "SInt32Type",
-  "SInt64Type",
-  "SInt128Type",
-  "Float32Type",
-  "Float44Type",
-  "Float64Type",
-  "Float80Type",
-  "Float128Type",
-  "AnyType",
-  "StringType",
+  "EnumerationType",
   "IntegerType",
+  "OpaqueType",
   "RangeType",
-  "EnumerationType",
   "RealType",
   "RationalType",
-  "OpaqueType",
+  "StringType",
   "PointerType",
   "ArrayType",
   "VectorType",
@@ -89,7 +73,6 @@
   "ConstantAny",
   "ConstantBoolean",
   "ConstantCharacter",
-  "ConstantOctet",
   "ConstantEnumerator",
   "ConstantInteger",
   "ConstantReal",
@@ -217,12 +200,6 @@
   std::cout << "Types:" 
             << FirstTypeID << " -> " 
             << LastTypeID << "\n";
-  std::cout << "PrimitiveTypes: " 
-            << FirstPrimitiveTypeID << " -> " 
-            << LastPrimitiveTypeID << "\n";
-  std::cout << "SimpleTypeID: " 
-            << FirstSimpleTypeID << " -> " 
-            << LastSimpleTypeID << "\n";
   std::cout << "ContainerTypes: " 
             << FirstContainerTypeID << " -> "
             << LastContainerTypeID << "\n";

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

==============================================================================
--- hlvm/trunk/tools/hlvm-gentestcase/Generate.cpp (original)
+++ hlvm/trunk/tools/hlvm-gentestcase/Generate.cpp Sat Jul  7 19:02:42 2007
@@ -114,36 +114,33 @@
 genType(unsigned limit)
 {
   Type* result = 0;
-  NodeIDs id = NodeIDs(randRange(FirstTypeID,LastTypeID));
+  bool intrinsic_type = randRange(0,TypeComplexity) < TypeComplexity/3;
   if (--limit == 0)
-    id = NodeIDs(randRange(FirstPrimitiveTypeID,LastPrimitiveTypeID));
+    intrinsic_type = true;
+
+  if (intrinsic_type) {
+    IntrinsicTypes theType = IntrinsicTypes(
+        randRange(FirstIntrinsicType,LastIntrinsicType));
+    // FIXME: Don't allow things we can't code gen right now
+    if (theType == u128Ty)
+      theType = u64Ty;
+    else if (theType == s128Ty)
+      theType = s64Ty;
+    else if (theType == f128Ty || theType == f96Ty)
+      theType = f64Ty;
+    else if (theType == bufferTy || theType == streamTy || theType == textTy)
+      theType = s32Ty;
+    return bundle->getIntrinsicType(theType);
+  }
 
+  NodeIDs id = NodeIDs(randRange(FirstTypeID,LastTypeID));
   switch (id) {
-    case BooleanTypeID:
-    case CharacterTypeID:
-    case OctetTypeID:
-    case UInt8TypeID:
-    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:
-    case Float80TypeID:
+    case BooleanTypeID: 
+      result = bundle->getIntrinsicType(boolTy);
+      break;
     case StringTypeID:
-      return ast->getPrimitiveType(id);
-    case Float128TypeID:
-      return ast->getPrimitiveType(Float64TypeID);
+      result = bundle->getIntrinsicType(stringTy);
+      break;
     case AnyTypeID:
     case BufferTypeID:
     case StreamTypeID:
@@ -158,7 +155,8 @@
       Locator* loc = getLocator();
       std::string name = "int_" + utostr(line);
       bool isSigned = randRange(0,TypeComplexity+2,true) < (TypeComplexity+2)/2;
-      result = ast->new_IntegerType(name,randRange(4,64,true),isSigned,loc);
+      result = 
+        ast->new_IntegerType(name,bundle,randRange(4,64,true),isSigned,loc);
       break;
     }
     case RangeTypeID:
@@ -166,14 +164,14 @@
       Locator* loc = getLocator();
       std::string name = "range_" + utostr(line);
       int64_t limit = randRange(0,8000000);
-      result = ast->new_RangeType(name,-limit,limit,loc);
+      result = ast->new_RangeType(name,bundle,-limit,limit,loc);
       break;
     }
     case EnumerationTypeID:
     {
       Locator* loc = getLocator();
       std::string name = "enum_" + utostr(line);
-      EnumerationType* E = ast->new_EnumerationType(name,loc);
+      EnumerationType* E = ast->new_EnumerationType(name,bundle,loc);
       unsigned numEnums = randRange(1,TypeComplexity,true);
       for (unsigned i = 0; i < numEnums; i++)
         E->addEnumerator(name + "_" + utostr(i));
@@ -184,21 +182,22 @@
     {
       Locator* loc = getLocator();
       std::string name = "real_" + utostr(line);
-      result = ast->new_RealType(name,randRange(1,52),randRange(1,11),loc);
+      result = 
+        ast->new_RealType(name,bundle,randRange(1,52),randRange(1,11),loc);
       break;
     }
     case PointerTypeID:
     {
       Locator* loc = getLocator();
       std::string name = "ptr_" + utostr(line);
-      result = ast->new_PointerType(name,genType(limit),loc);
+      result = ast->new_PointerType(name,bundle,genType(limit),loc);
       break;
     }
     case ArrayTypeID:
     {
       Locator* loc = getLocator();
       std::string name = "array_" + utostr(line);
-      result = ast->new_ArrayType(name,
+      result = ast->new_ArrayType(name,bundle,
           genType(limit),randRange(1,Size),loc);
       break;
     }
@@ -206,8 +205,8 @@
     {
       Locator* loc = getLocator();
       std::string name = "vector_" + utostr(line);
-      result = ast->new_VectorType(
-          name,genType(limit),randRange(1,Size),loc);
+      result = ast->new_VectorType(name,bundle,
+          genType(limit),randRange(1,Size),loc);
       break;
     }
     case OpaqueTypeID:
@@ -217,7 +216,7 @@
     {
       Locator* loc = getLocator();
       std::string name = "struct_" + utostr(line);
-      StructureType* S = ast->new_StructureType(name,loc);
+      StructureType* S = ast->new_StructureType(name,bundle,loc);
       unsigned numFields = randRange(1,Size,true);
       for (unsigned i = 0; i < numFields; ++i) {
         Field* fld = ast->new_Field(name+"_"+utostr(i),
@@ -231,7 +230,6 @@
       hlvmAssert(!"Invalid Type?");
   }
   hlvmAssert(result && "No type defined?");
-  result->setParent(bundle);
   return result;
 }
 
@@ -271,7 +269,7 @@
     {
       bool val = randRange(0,Complexity+2) < (Complexity+2)/2;
       C = ast->new_ConstantBoolean(
-          std::string("cbool_") + utostr(line), val, loc);
+          std::string("cbool_") + utostr(line), bundle,Ty, val, loc);
       break;
     }
     case CharacterTypeID:
@@ -279,94 +277,7 @@
       std::string val;
       val += char(randRange(35,126));
       C = ast->new_ConstantCharacter(
-        std::string("cchar_") + utostr(line), val, loc);
-      break;
-    }
-    case OctetTypeID:
-    {
-      C = ast->new_ConstantOctet(
-        std::string("coctet_") + utostr(line), 
-          static_cast<unsigned char>(randRange(0,255)), loc);
-      break;
-    }
-    case UInt8TypeID:
-    {
-      uint8_t val = uint8_t(randRange(0,255));
-      std::string val_str(utostr(val));
-      C = ast->new_ConstantInteger(
-        std::string("cu8_")+utostr(line),val_str,10,Ty,loc);
-      break;
-    }
-    case UInt16TypeID:
-    {
-      uint16_t val = uint16_t(randRange(0,65535));
-      std::string val_str(utostr(val));
-      C = ast->new_ConstantInteger(
-        std::string("cu16_")+utostr(line),val_str,10,Ty,loc);
-      break;
-    }
-    case UInt32TypeID:
-    {
-      uint32_t val = randRange(0,4000000000U);
-      std::string val_str(utostr(val));
-      C = ast->new_ConstantInteger(
-        std::string("cu32_")+utostr(line),val_str,10,Ty,loc);
-      break;
-    }
-    case UInt128TypeID:
-      /* FALL THROUGH (not implemented) */
-    case UInt64TypeID:
-    {
-      uint64_t val = randRange(0,4000000000U);
-      std::string val_str(utostr(val));
-      C = ast->new_ConstantInteger(
-        std::string("cu64_")+utostr(line),val_str,10,Ty,loc);
-      break;
-    }
-    case SInt8TypeID:
-    {
-      int8_t val = int8_t(randRange(-127,127));
-      std::string val_str(itostr(val));
-      C = ast->new_ConstantInteger(
-        std::string("cs8_")+utostr(line),val_str,10,Ty,loc);
-      break;
-    }
-    case SInt16TypeID:
-    {
-      int16_t val = int16_t(randRange(-32767,32767));
-      std::string val_str(itostr(val));
-      C = ast->new_ConstantInteger(
-        std::string("cs16_")+utostr(line),val_str,10,Ty,loc);
-      break;
-    }
-    case SInt32TypeID:
-    {
-      int32_t val = int32_t(randRange(-2000000000,2000000000));
-      std::string val_str(itostr(val));
-      C = ast->new_ConstantInteger(
-        std::string("cs32_")+utostr(line),val_str,10,Ty,loc);
-      break;
-    }
-    case SInt128TypeID:
-      /* FALL THROUGH (not implemented) */
-    case SInt64TypeID:
-    {
-      int64_t val = int64_t(randRange(-2000000000,2000000000));
-      std::string val_str(itostr(val));
-      C = ast->new_ConstantInteger(
-        std::string("cs64_")+utostr(line),val_str,10,Ty,loc);
-      break;
-    }
-    case Float32TypeID:
-    case Float44TypeID:
-    case Float64TypeID:
-    case Float80TypeID:
-    case Float128TypeID:
-    {
-      double val = double(randRange(-10000000,10000000));
-      std::string val_str(ftostr(val));
-      C = ast->new_ConstantReal(
-        std::string("cf32_")+utostr(line),val_str,Ty,loc);
+        std::string("cchar_") + utostr(line), bundle,Ty, val, loc);
       break;
     }
     case StringTypeID:
@@ -376,13 +287,13 @@
       for (unsigned i = 0 ; i < numChars; i++)
         val += char(randRange(35,126));
       C = ast->new_ConstantString(
-        std::string("cstr_")+utostr(line),val,loc);
+        std::string("cstr_")+utostr(line),bundle,Ty,val,loc);
       break;
     }
-    case AnyTypeID:
     case BufferTypeID:
     case StreamTypeID:
     case TextTypeID:
+    case AnyTypeID:
       // hlvmAssert("Can't get constant for these types");
       /* FALL THROUGH (unimplemented) */
     case SignatureTypeID:
@@ -403,7 +314,7 @@
         uint64_t val = randRange(uint64_t(0),uint64_t(max),true);
         val_str = utostr(val);
       }
-      C = ast->new_ConstantInteger(name,val_str,10,Ty,loc);
+      C = ast->new_ConstantInteger(name,bundle,Ty,val_str,10,loc);
       break;
     }
     case RangeTypeID:
@@ -412,7 +323,7 @@
       const RangeType* RngTy = llvm::cast<RangeType>(Ty);
       int64_t val = randRange(RngTy->getMin(),RngTy->getMax());
       std::string val_str( itostr(val) );
-      C = ast->new_ConstantInteger(name,val_str,10,RngTy,loc);
+      C = ast->new_ConstantInteger(name,bundle,RngTy,val_str,10,loc);
       break;
     }
     case EnumerationTypeID:
@@ -421,7 +332,7 @@
       const EnumerationType* ETy = llvm::cast<EnumerationType>(Ty);
       unsigned val = randRange(0,ETy->size()-1);
       EnumerationType::const_iterator I = ETy->begin() + val;
-      C = ast->new_ConstantEnumerator(name,*I,ETy,loc);
+      C = ast->new_ConstantEnumerator(name,bundle,ETy,*I,loc);
       break;
     }
     case RealTypeID:
@@ -429,7 +340,7 @@
       double val = double(randRange(-10000000,10000000));
       std::string val_str(ftostr(val));
       C = ast->new_ConstantReal(
-        std::string("cf32_")+utostr(line),val_str,Ty,loc);
+        std::string("cf32_")+utostr(line),bundle,Ty,val_str,loc);
       break;
     }
     case PointerTypeID:
@@ -438,7 +349,8 @@
       const Type* refType = PT->getElementType();
       std::string name = std::string("cptr_") + utostr(line);
       Value* refValue = genValue(refType,true);
-      C = ast->new_ConstantPointer(name, PT, cast<ConstantValue>(refValue),loc);
+      C = ast->new_ConstantPointer(name, bundle,PT, 
+        cast<ConstantValue>(refValue),loc);
       break;
     }
     case ArrayTypeID:
@@ -450,7 +362,7 @@
       std::string name = "cptr_" + utostr(line);
       for (unsigned i = 0; i < nElems; i++)
         elems.push_back(cast<ConstantValue>(genValue(elemTy,true)));
-      C = ast->new_ConstantArray(name, elems, AT, loc);
+      C = ast->new_ConstantArray(name, bundle,AT,elems, loc);
       break;
     }
     case VectorTypeID:
@@ -462,7 +374,7 @@
       std::vector<ConstantValue*> elems;
       for (unsigned i = 0; i < nElems; i++)
         elems.push_back(cast<ConstantValue>(genValue(elemTy,true)));
-      C = ast->new_ConstantVector(name, elems, VT, loc);
+      C = ast->new_ConstantVector(name, bundle, VT, elems, loc);
       break;
     }
     case OpaqueTypeID:
@@ -480,7 +392,7 @@
         Value* V = genValue(Ty,true);
         elems.push_back(cast<ConstantValue>(V));
       }
-      C = ast->new_ConstantStructure(name, elems, ST, loc);
+      C = ast->new_ConstantStructure(name, bundle, ST, elems, loc);
       break;
     }
     default:
@@ -495,7 +407,8 @@
   if (is_constant || (randRange(0,Complexity+2) < (Complexity+2)/2))
     result = C;
   else {
-    Variable* var = ast->new_Variable(C->getName()+"_var",C->getType(),loc);
+    Variable* var = 
+      ast->new_Variable(C->getName()+"_var",bundle,C->getType(),loc);
     var->setIsConstant(false);
     var->setInitializer(C);
     var->setParent(bundle);
@@ -513,7 +426,7 @@
   Value* V = genValue(Ty,is_constant);
   Operator* O = ast->new_ReferenceOp(V,getLocator());
   if (isa<Linkable>(V))
-    O = ast->new_UnaryOp<LoadOp>(O,getLocator());
+    O = ast->new_UnaryOp<LoadOp>(O,bundle,getLocator());
   return O;
 }
 
@@ -533,7 +446,7 @@
     hlvmAssert(argTy == O->getType());
     args.push_back(O);
   }
-  return ast->new_MultiOp<CallOp>(args,getLocator());
+  return ast->new_MultiOp<CallOp>(args,bundle,getLocator());
 }
 
 Block*
@@ -552,7 +465,7 @@
 
   // Get the signature
   std::string sigName = name + "_type";
-  SignatureType* sig = ast->new_SignatureType(sigName,resultType,loc);
+  SignatureType* sig = ast->new_SignatureType(sigName,bundle,resultType,loc);
   if (randRange(0,Complexity) > int(Complexity/3))
     sig->setIsVarArgs(true);
   for (unsigned i = 0; i < numArgs; ++i )
@@ -567,7 +480,7 @@
   LinkageKinds LK = LinkageKinds(randRange(ExternalLinkage,InternalLinkage));
   if (LK == AppendingLinkage)
     LK = InternalLinkage;
-  Function* F = ast->new_Function(name,sig,loc);
+  Function* F = ast->new_Function(name,bundle,sig,loc);
   F->setLinkageKind(LK);
 
   // Create a block and set its parent
@@ -576,10 +489,10 @@
 
   // Get the function result and return instruction
   Operator* O = genValueOperator(F->getResultType());
-  ResultOp* rslt = ast->new_UnaryOp<ResultOp>(O,getLocator());
+  ResultOp* rslt = ast->new_UnaryOp<ResultOp>(O,bundle,getLocator());
   rslt->setParent(B);
 
-  ReturnOp* ret = ast->new_NilaryOp<ReturnOp>(getLocator());
+  ReturnOp* ret = ast->new_NilaryOp<ReturnOp>(bundle,getLocator());
   ret->setParent(B);
   
   // Install the function in the value map
@@ -599,7 +512,7 @@
   ast->setSystemID(bundleName);
   uri = ast->new_URI(pubid);
   bundle = ast->new_Bundle(bundleName,getLocator());
-  program = ast->new_Program(bundleName,getLocator());
+  program = ast->new_Program(bundleName,bundle,getLocator());
   Block* blk = ast->new_Block(getLocator());
   blk->setParent(program);
   for (unsigned i = 0; i < Size; i++) {
@@ -614,10 +527,10 @@
 
   // Get the function result and return instruction
   Operator* O = genValueOperator(program->getResultType());
-  ResultOp* rslt = ast->new_UnaryOp<ResultOp>(O,getLocator());
+  ResultOp* rslt = ast->new_UnaryOp<ResultOp>(O,bundle,getLocator());
   rslt->setParent(blk);
 
-  ReturnOp* ret = ast->new_NilaryOp<ReturnOp>(getLocator());
+  ReturnOp* ret = ast->new_NilaryOp<ReturnOp>(bundle,getLocator());
   ret->setParent(blk);
   program->setParent(bundle);
   return ast;





More information about the llvm-commits mailing list