[llvm-commits] [hlvm] r38179 - in /hlvm/trunk: hlvm/AST/ hlvm/CodeGen/ hlvm/Pass/ hlvm/Reader/XML/ hlvm/Runtime/ hlvm/Writer/XML/ test/return0/ test/xml2xml/

Reid Spencer reid at x10sys.com
Sat Jul 7 17:00:48 PDT 2007


Author: reid
Date: Sat Jul  7 19:00:47 2007
New Revision: 38179

URL: http://llvm.org/viewvc/llvm-project?rev=38179&view=rev
Log:
Finish Pre-Release 0.1 Functionality by getting the "Hello, World" program
to execute.

Added:
    hlvm/trunk/hlvm/AST/RuntimeType.cpp
    hlvm/trunk/hlvm/AST/RuntimeType.h
    hlvm/trunk/hlvm/Runtime/Stream.cpp
      - copied, changed from r38176, hlvm/trunk/hlvm/Runtime/FileIO.cpp
    hlvm/trunk/hlvm/Runtime/Stream.h
      - copied, changed from r38176, hlvm/trunk/hlvm/Runtime/FileIO.h
    hlvm/trunk/hlvm/Runtime/Text.cpp
      - copied, changed from r38176, hlvm/trunk/hlvm/Runtime/String.cpp
    hlvm/trunk/hlvm/Runtime/Text.h
      - copied, changed from r38176, hlvm/trunk/hlvm/Runtime/String.h
    hlvm/trunk/test/xml2xml/helloworld.hlx
Removed:
    hlvm/trunk/hlvm/Runtime/FileIO.cpp
    hlvm/trunk/hlvm/Runtime/FileIO.h
    hlvm/trunk/hlvm/Runtime/String.cpp
    hlvm/trunk/hlvm/Runtime/String.h
    hlvm/trunk/hlvm/Runtime/Utilities.h
Modified:
    hlvm/trunk/hlvm/AST/AST.cpp
    hlvm/trunk/hlvm/AST/AST.h
    hlvm/trunk/hlvm/AST/Block.cpp
    hlvm/trunk/hlvm/AST/Block.h
    hlvm/trunk/hlvm/AST/Bundle.cpp
    hlvm/trunk/hlvm/AST/Bundle.h
    hlvm/trunk/hlvm/AST/Constants.h
    hlvm/trunk/hlvm/AST/ContainerType.cpp
    hlvm/trunk/hlvm/AST/ContainerType.h
    hlvm/trunk/hlvm/AST/Function.h
    hlvm/trunk/hlvm/AST/Import.h
    hlvm/trunk/hlvm/AST/InputOutput.cpp
    hlvm/trunk/hlvm/AST/InputOutput.h
    hlvm/trunk/hlvm/AST/MemoryOps.cpp
    hlvm/trunk/hlvm/AST/MemoryOps.h
    hlvm/trunk/hlvm/AST/Node.h
    hlvm/trunk/hlvm/AST/Operator.h
    hlvm/trunk/hlvm/AST/Program.h
    hlvm/trunk/hlvm/AST/SymbolTable.h
    hlvm/trunk/hlvm/AST/Type.cpp
    hlvm/trunk/hlvm/AST/Type.h
    hlvm/trunk/hlvm/AST/Variable.cpp
    hlvm/trunk/hlvm/AST/Variable.h
    hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp
    hlvm/trunk/hlvm/CodeGen/LLVMGenerator.h
    hlvm/trunk/hlvm/CodeGen/SConscript
    hlvm/trunk/hlvm/Pass/Pass.cpp
    hlvm/trunk/hlvm/Pass/Validate.cpp
    hlvm/trunk/hlvm/Reader/XML/HLVM.rng
    hlvm/trunk/hlvm/Reader/XML/XMLReader.cpp
    hlvm/trunk/hlvm/Runtime/Error.cpp
    hlvm/trunk/hlvm/Runtime/Error.h
    hlvm/trunk/hlvm/Runtime/Internal.cpp
    hlvm/trunk/hlvm/Runtime/Internal.h
    hlvm/trunk/hlvm/Runtime/Main.cpp
    hlvm/trunk/hlvm/Runtime/Memory.h
    hlvm/trunk/hlvm/Runtime/Program.cpp
    hlvm/trunk/hlvm/Runtime/Program.h
    hlvm/trunk/hlvm/Runtime/README.txt
    hlvm/trunk/hlvm/Writer/XML/XMLWriter.cpp
    hlvm/trunk/test/return0/helloworld.hlx
    hlvm/trunk/test/xml2xml/alias.hlx
    hlvm/trunk/test/xml2xml/array.hlx
    hlvm/trunk/test/xml2xml/doc.hlx
    hlvm/trunk/test/xml2xml/intrinsics.hlx
    hlvm/trunk/test/xml2xml/pointer.hlx
    hlvm/trunk/test/xml2xml/resolve.hlx
    hlvm/trunk/test/xml2xml/signature.hlx

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

==============================================================================
--- hlvm/trunk/hlvm/AST/AST.cpp (original)
+++ hlvm/trunk/hlvm/AST/AST.cpp Sat Jul  7 19:00:47 2007
@@ -56,13 +56,15 @@
   public:
     ASTImpl()
       : types(), vars(), funcs(), unresolvedTypes(), 
+        AnyTypeSingleton(0),
         VoidSingleton(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), ProgramTypeSingleton(0)
+        Float128Singleton(0), TextTypeSingleton(0), StreamTypeSingleton(0),
+        BufferTypeSingleton(0), ProgramTypeSingleton(0)
       {
         pool = Pool::create("ASTPool",0,false,1024,4,0);
       }
@@ -78,6 +80,7 @@
     SymbolTable    vars;
     SymbolTable    funcs;
     SymbolTable    unresolvedTypes;
+    AnyType*       AnyTypeSingleton;
     VoidType*      VoidSingleton;
     BooleanType*   BooleanSingleton;
     CharacterType* CharacterSingleton;
@@ -97,6 +100,9 @@
     RealType*      Float64Singleton;
     RealType*      Float80Singleton;
     RealType*      Float128Singleton;
+    TextType*      TextTypeSingleton;
+    StreamType*    StreamTypeSingleton;
+    BufferType*    BufferTypeSingleton;
     SignatureType* ProgramTypeSingleton;
 
   public:
@@ -353,7 +359,7 @@
   PointerType* result = new PointerType();
   result->setLocator(loc);
   result->setName(id);
-  result->setTargetType(target);
+  result->setElementType(target);
   static_cast<ASTImpl*>(this)->addType(result);
   return result;
 }
@@ -396,7 +402,7 @@
   AliasType* result = new AliasType();
   result->setLocator(loc);
   result->setName(id);
-  result->setType(referrant);
+  result->setElementType(referrant);
   static_cast<ASTImpl*>(this)->addType(result);
   return result;
 }
@@ -435,20 +441,22 @@
 }
 
 ConstantInteger*
-AST::new_ConstantInteger(uint64_t v, const Locator* loc)
+AST::new_ConstantInteger(uint64_t v, Type* Ty, const Locator* loc)
 {
   ConstantInteger* result = new ConstantInteger();
   result->setLocator(loc);
   result->setValue(v);
+  result->setType(Ty);
   return result;
 }
 
 ConstantReal*
-AST::new_ConstantReal(double v, const Locator* loc)
+AST::new_ConstantReal(double v, Type* Ty, const Locator* loc)
 {
   ConstantReal* result = new ConstantReal();
   result->setLocator(loc);
   result->setValue(v);
+  result->setType(Ty);
   return result;
 }
 
@@ -458,6 +466,7 @@
   ConstantText* result = new ConstantText();
   result->setLocator(loc);
   result->setValue(v);
+  result->setType( getPrimitiveType(TextTypeID) );
   return result;
 }
 
@@ -579,13 +588,15 @@
 AST::new_BinaryOp<StoreOp>(Value*op1,Value*op2,const Locator*loc);
 template LoadOp*   
 AST::new_UnaryOp<LoadOp>(Value*op1,const Locator*loc);
+template AutoVarOp*
+AST::new_UnaryOp<AutoVarOp>(Value*op1,const Locator* loc);
 template ReferenceOp* 
 AST::new_NilaryOp<ReferenceOp>(const Locator*loc);
 // Input/Output Operators
 template OpenOp* 
 AST::new_UnaryOp<OpenOp>(Value*op1,const Locator*loc);
 template WriteOp* 
-AST::new_TernaryOp<WriteOp>(Value*op1,Value*op2,Value*op3,const Locator*loc);
+AST::new_BinaryOp<WriteOp>(Value*op1,Value*op2,const Locator*loc);
 template CloseOp* 
 AST::new_UnaryOp<CloseOp>(Value*op1,const Locator*loc);
 
@@ -603,14 +614,33 @@
   Argument* result = new Argument();
   result->setLocator(loc);
   result->setName(id);
-  result->setType(ty);
+  result->setElementType(ty);
+  return result;
+}
+
+BufferType* 
+AST::new_BufferType( const std::string& id, const Locator* loc)
+{
+  BufferType* result = new BufferType();
+  result->setName(id);
+  result->setLocator(loc);
+  return result;
+}
+
+StreamType* 
+AST::new_StreamType( const std::string& id, const Locator* loc)
+{
+  StreamType* result = new StreamType();
+  result->setName(id);
+  result->setLocator(loc);
   return result;
 }
 
 TextType*
 AST::new_TextType(const std::string& id, const Locator* loc)
 {
-  TextType* result = new TextType(id);
+  TextType* result = new TextType();
+  result->setName(id);
   result->setLocator(loc);
   return result;
 }
@@ -621,6 +651,12 @@
   ASTImpl* ast = static_cast<ASTImpl*>(this);
   switch (pid) 
   {
+    case AnyTypeID:
+      if (!ast->AnyTypeSingleton) {
+        ast->AnyTypeSingleton = new AnyType();
+        ast->AnyTypeSingleton->setName("any");
+      }
+      return ast->AnyTypeSingleton;
     case VoidTypeID:
       if (!ast->VoidSingleton) {
         ast->VoidSingleton = new VoidType();
@@ -735,6 +771,21 @@
         ast->Float128Singleton->setName("f128");
       }
       return ast->Float128Singleton;
+    case TextTypeID:
+      if (!ast->TextTypeSingleton) {
+        ast->TextTypeSingleton = new TextType();
+      }
+      return ast->TextTypeSingleton;
+    case StreamTypeID:
+      if (!ast->StreamTypeSingleton) {
+        ast->StreamTypeSingleton = new StreamType();
+      }
+      return ast->StreamTypeSingleton;
+    case BufferTypeID:
+      if (!ast->BufferTypeSingleton) {
+        ast->BufferTypeSingleton = new BufferType();
+      }
+      return ast->BufferTypeSingleton;
     default:
       hlvmDeadCode("Invalid Primitive");
       break;

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

==============================================================================
--- hlvm/trunk/hlvm/AST/AST.h (original)
+++ hlvm/trunk/hlvm/AST/AST.h Sat Jul  7 19:00:47 2007
@@ -32,6 +32,8 @@
 
 #include <hlvm/AST/Node.h>
 #include <hlvm/AST/Type.h>
+#include <hlvm/AST/ContainerType.h>
+#include <hlvm/AST/RuntimeType.h>
 #include <string>
 #include <vector>
 
@@ -48,14 +50,11 @@
 class Program; 
 class Import;
 class Locator; 
-class SignatureType;
-class StructureType;
 class Variable; 
 class ConstantInteger;
 class ConstantReal;
 class ConstantText;
 class ConstantZero;
-class AliasType;
 class Pool;
 class ReturnOp;
 class StoreOp;
@@ -63,8 +62,6 @@
 class OpenOp;
 class CloseOp;
 class WriteOp;
-typedef AliasType Argument;
-typedef AliasType Field;
 
 /// This class is used to hold or contain an Abstract Syntax Tree. It provides
 /// those aspects of the tree that are not part of the tree itself.
@@ -235,18 +232,30 @@
       const std::string& id,  ///< The name of the type
       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(
+    /// 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
       const Locator* loc = 0  ///< The source locator
     );
-    /// Create a new TextType node. A TextType represents a string or block 
-    /// of text of arbitrary length in UTF-16 encoding.
+    /// 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
       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
+      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
+      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(
@@ -411,11 +420,13 @@
     /// Create a new ConstantInteger node.
     ConstantInteger* new_ConstantInteger(
       uint64_t value,         ///< The value of the ConstantInteger
+      Type* Ty,               ///< The type of the integer
       const Locator* loc = 0  ///< The source locator
     );
     /// Create a new ConstantInteger node.
     ConstantReal* new_ConstantReal(
       double value,           ///< The value of the ConstantReal
+      Type* Ty,               ///< The type of the real
       const Locator* loc = 0  ///< The source locator
     );
     /// Create a new ConstantText node.

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Block.cpp (original)
+++ hlvm/trunk/hlvm/AST/Block.cpp Sat Jul  7 19:00:47 2007
@@ -28,6 +28,9 @@
 //===----------------------------------------------------------------------===//
 
 #include <hlvm/AST/Block.h>
+#include <hlvm/AST/MemoryOps.h>
+#include <hlvm/Base/Assert.h>    
+#include <llvm/Support/Casting.h>
 
 namespace hlvm {
 
@@ -35,4 +38,35 @@
 {
 }
 
+void 
+Block::insertChild(Node* child)
+{
+  hlvmAssert(llvm::isa<Operator>(child));
+  if (llvm::isa<AutoVarOp>(child)) {
+    AutoVarOp* av = llvm::cast<AutoVarOp>(child);
+    autovars[av->getName()] = av;
+  }
+  MultiOperator::insertChild(child);
+}
+
+void 
+Block::removeChild(Node* child)
+{
+  hlvmAssert(llvm::isa<Operator>(child));
+  if (llvm::isa<AutoVarOp>(child)) {
+    AutoVarOp* av = llvm::cast<AutoVarOp>(child);
+    autovars.erase(av->getName());
+  }
+  MultiOperator::removeChild(child);
+}
+
+AutoVarOp*   
+Block::getAutoVar(const std::string& name) const
+{
+  AutoVarMap::const_iterator I = autovars.find(name);
+  if (I == autovars.end())
+    return 0;
+  return I->second;
+}
+
 }

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Block.h (original)
+++ hlvm/trunk/hlvm/AST/Block.h Sat Jul  7 19:00:47 2007
@@ -31,10 +31,13 @@
 #define HLVM_AST_BLOCK_H
 
 #include <hlvm/AST/Operator.h>
+#include <map>
 
 namespace hlvm 
 {
 
+class AutoVarOp;
+
 /// This class represents an Variable in the HLVM Abstract Syntax Tree.  
 /// A Variable is a storage location of a specific type. It can either be
 /// global or local, depending on its parent. Global variables are always
@@ -54,20 +57,25 @@
   /// @{
   public:
     const std::string& getLabel() const { return label; }
+    AutoVarOp*   getAutoVar(const std::string& name) const; 
     static inline bool classof(const Block*) { return true; }
-    static inline bool classof(const Operator* O) { return O->isBlock(); }
-    static inline bool classof(const Node* N) { return N->isBlock(); }
+    static inline bool classof(const Node* N) { return N->is(BlockID); }
 
   /// @}
   /// @name Mutators
   /// @{
   public:
     void setLabel(const std::string& l) { label = l; }
+  protected:
+    virtual void insertChild(Node* child);
+    virtual void removeChild(Node* child);
   /// @}
   /// @name Data
   /// @{
-  public:
+  private:
+    typedef std::map<std::string,AutoVarOp*> AutoVarMap;
     std::string label;
+    AutoVarMap  autovars;
   /// @}
   friend class AST;
 };

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Bundle.cpp (original)
+++ hlvm/trunk/hlvm/AST/Bundle.cpp Sat Jul  7 19:00:47 2007
@@ -54,11 +54,11 @@
 Bundle::insertChild(Node* kid)
 {
   if (kid->isType())
-    types.push_back(cast<Type>(kid));
-  else if (kid->isVariable())
-    vars.push_back(cast<Variable>(kid));
+    types.insert(cast<Type>(kid)->getName(), kid);
+  else if (kid->is(VariableID))
+    vars.insert(cast<Variable>(kid)->getName(), kid);
   else if (kid->isFunction())
-    funcs.push_back(cast<Function>(kid));
+    funcs.insert(cast<Function>(kid)->getName(), kid);
   else
     hlvmAssert("Don't know how to insert that in a Bundle");
 }
@@ -69,19 +69,31 @@
   hlvmAssert(isa<LinkageItem>(kid) && "Can't remove that here");
   // This is sucky slow, but we probably won't be removing nodes that much.
   if (kid->isType()) {
-    for (type_iterator I = type_begin(), E = type_end(); I != E; ++I ) {
-      if (*I == kid) { types.erase(I); return; }
-    }
-  } else if (kid->isVariable()) {
-    for (var_iterator I = var_begin(), E = var_end(); I != E; ++I ) {
-      if (*I == kid) { vars.erase(I); return; }
-    }
+    types.erase(cast<Type>(kid)->getName());
+  } else if (kid->is(VariableID)) {
+    vars.erase(cast<Variable>(kid)->getName());
   } else if (kid->isFunction()) {
-    for (func_iterator I = func_begin(), E = func_end(); I != E; ++I ) {
-      if (*I == kid) { funcs.erase(I); return; }
-    }
+    funcs.erase(cast<Function>(kid)->getName());
   }
   hlvmAssert(!"That node isn't my child");
 }
 
+Type*  
+Bundle::type_find(const std::string& name) const
+{
+  return llvm::cast<Type>(types.lookup(name));
+}
+
+Function*  
+Bundle::func_find(const std::string& name) const
+{
+  return llvm::cast<Function>(funcs.lookup(name));
+}
+
+Variable*  
+Bundle::var_find(const std::string& name) const
+{
+  return llvm::cast<Variable>(vars.lookup(name));
+}
+
 }

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Bundle.h (original)
+++ hlvm/trunk/hlvm/AST/Bundle.h Sat Jul  7 19:00:47 2007
@@ -31,6 +31,7 @@
 #define HLVM_AST_BUNDLE_H
 
 #include <hlvm/AST/Node.h>
+#include <hlvm/AST/SymbolTable.h>
 
 namespace hlvm 
 { 
@@ -50,15 +51,15 @@
   /// @name Types
   /// @{
   public:
-    typedef std::vector<Type*> TypeList;
+    typedef SymbolTable TypeList;
     typedef TypeList::iterator type_iterator;
     typedef TypeList::const_iterator type_const_iterator;
 
-    typedef std::vector<Function*> FuncList;
+    typedef SymbolTable FuncList;
     typedef FuncList::iterator func_iterator;
     typedef FuncList::const_iterator func_const_iterator;
 
-    typedef std::vector<Variable*> VarList;
+    typedef SymbolTable VarList;
     typedef VarList::iterator var_iterator;
     typedef VarList::const_iterator var_const_iterator;
 
@@ -78,7 +79,7 @@
   public:
     const std::string& getName() const { return name; }
     static inline bool classof(const Bundle*) { return true; }
-    static inline bool classof(const Node* N) { return N->isBundle(); }
+    static inline bool classof(const Node* N) { return N->is(BundleID); }
 
   /// @}
   /// @name Mutators
@@ -89,6 +90,14 @@
     virtual void removeChild(Node* kid);
 
   /// @}
+  /// @name Finders
+  /// @{
+  public:
+    Type*     type_find(const std::string& n) const;
+    Function* func_find(const std::string& n) const;
+    Variable*  var_find(const std::string& n) const;
+
+  /// @}
   /// @name Iterators
   /// @{
   public:
@@ -98,10 +107,6 @@
     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*                   type_front()       { return types.front(); }
-    const Type*             type_front() const { return types.front(); }
-    Type*                   type_back()        { return types.back(); }
-    const Type*             type_back()  const { return types.back(); }
 
     func_iterator           func_begin()       { return funcs.begin(); }
     func_const_iterator     func_begin() const { return funcs.begin(); }
@@ -109,10 +114,6 @@
     func_const_iterator     func_end  () const { return funcs.end(); }
     size_t                  func_size () const { return funcs.size(); }
     bool                    func_empty() const { return funcs.empty(); }
-    Function*               func_front()       { return funcs.front(); }
-    const Function*         func_front() const { return funcs.front(); }
-    Function*               func_back()        { return funcs.back(); }
-    const Function*         func_back()  const { return funcs.back(); }
 
     var_iterator            var_begin()       { return vars.begin(); }
     var_const_iterator      var_begin() const { return vars.begin(); }
@@ -120,10 +121,6 @@
     var_const_iterator      var_end  () const { return vars.end(); }
     size_t                  var_size () const { return vars.size(); }
     bool                    var_empty() const { return vars.empty(); }
-    Variable*               var_front()       { return vars.front(); }
-    const Variable*         var_front() const { return vars.front(); }
-    Variable*               var_back()        { return vars.back(); }
-    const Variable*         var_back()  const { return vars.back(); }
   /// @}
   /// @name Data
   /// @{

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Constants.h (original)
+++ hlvm/trunk/hlvm/AST/Constants.h Sat Jul  7 19:00:47 2007
@@ -80,7 +80,7 @@
   /// @name Constructors
   /// @{
   protected:
-    ConstantReal() : Constant(ConstantTextID)  {}
+    ConstantReal() : Constant(ConstantRealID)  {}
     virtual ~ConstantReal();
 
   /// @}
@@ -156,7 +156,7 @@
   public:
     static inline bool classof(const ConstantZero*) { return true; }
     static inline bool classof(const Node* N) 
-      { return N->is(ConstantTextID); }
+      { return N->is(ConstantZeroID); }
 
   /// @}
   friend class AST;

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

==============================================================================
--- hlvm/trunk/hlvm/AST/ContainerType.cpp (original)
+++ hlvm/trunk/hlvm/AST/ContainerType.cpp Sat Jul  7 19:00:47 2007
@@ -35,19 +35,77 @@
 
 namespace hlvm {
 
-ContainerType::~ContainerType()
+UniformContainerType::~UniformContainerType()
 {
 }
 
+const char* 
+UniformContainerType::getPrimitiveName() const
+{
+  hlvmDeadCode("getPrimitiveName called on a container type");
+  return 0;
+}
+
+void 
+UniformContainerType::insertChild(Node* n)
+{
+  hlvmAssert(isa<Type>(n) && "Can't insert those here");
+  if (type)
+    type->setParent(0);
+  type = cast<Type>(n);
+}
+
+void 
+UniformContainerType::removeChild(Node* n)
+{
+  hlvmAssert(isa<Type>(n) && "Can't remove those here");
+  hlvmAssert(n->getParent() == this && "Node isn't my kid!");
+  hlvmAssert(type == n && "Node isn't mine");
+  type = 0;
+}
+
+PointerType::~PointerType()
+{
+}
+
+ArrayType::~ArrayType()
+{
+}
+
+VectorType::~VectorType()
+{
+}
+
+AliasType::~AliasType()
+{
+}
+
+const char*
+AliasType::getPrimitiveName() const
+{
+  return type->getPrimitiveName();
+}
+
+DisparateContainerType::~DisparateContainerType()
+{
+}
+
+const char* 
+DisparateContainerType::getPrimitiveName() const
+{
+  hlvmDeadCode("getPrimitiveName called on a container type");
+  return 0;
+}
+
 void 
-ContainerType::insertChild(Node* n)
+DisparateContainerType::insertChild(Node* n)
 {
   hlvmAssert(isa<AliasType>(n) && "Can't insert those here");
   contents.push_back(cast<AliasType>(n));
 }
 
 void 
-ContainerType::removeChild(Node* n)
+DisparateContainerType::removeChild(Node* n)
 {
   hlvmAssert(isa<Type>(n) && "Can't remove those here");
   // This is sucky slow, but we probably won't be removing nodes that much.
@@ -57,12 +115,6 @@
   hlvmAssert(!"That node isn't my child");
 }
 
-const char* 
-ContainerType::getPrimitiveName() const
-{
-  return 0;
-}
-
 StructureType::~StructureType()
 {
 }

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

==============================================================================
--- hlvm/trunk/hlvm/AST/ContainerType.h (original)
+++ hlvm/trunk/hlvm/AST/ContainerType.h Sat Jul  7 19:00:47 2007
@@ -35,10 +35,172 @@
 namespace hlvm 
 {
 
+/// This class represents a Type that uses a single other element type in its
+/// construction.
+class UniformContainerType : public Type
+{
+  /// @name Constructors
+  /// @{
+  protected:
+    UniformContainerType(NodeIDs id) : Type(id), type(0) {}
+    virtual ~UniformContainerType();
+
+  /// @}
+  /// @name Accessors
+  /// @{
+  public:
+    Type* getElementType() const { return type; }
+    virtual const char* getPrimitiveName() const; // asserting override
+    // Methods to support type inquiry via isa, cast, dyn_cast
+    static inline bool classof(const UniformContainerType*) { return true; }
+    static inline bool classof(const Type* T) { 
+      return T->isUniformContainerType(); 
+    }
+
+  /// @}
+  /// @name Mutators
+  /// @{
+  public:
+    void setElementType(Type* t) { type = t; }
+
+  protected:
+    virtual void insertChild(Node* n);
+    virtual void removeChild(Node* n);
+
+  /// @}
+  /// @name Data
+  /// @{
+  protected:
+    Type* type; ///< The contained types
+  /// @}
+};
+
+/// This class represents a storage location that is a pointer to another
+/// type. 
+class PointerType : public UniformContainerType
+{
+  /// @name Constructors
+  /// @{
+  protected:
+    PointerType() : UniformContainerType(PointerTypeID) {}
+    virtual ~PointerType();
+
+  /// @}
+  /// @name Accessors
+  /// @{
+  public:
+    // Methods to support type inquiry via is, cast, dyn_cast
+    static inline bool classof(const PointerType*) { return true; }
+    static inline bool classof(const Node* T) { return T->is(PointerTypeID); }
+
+  /// @}
+  friend class AST;
+};
+
+/// This class represents a resizeable, aligned array of some other type. The
+/// Array references a Type that specifies the type of elements in the array.
+class ArrayType : public UniformContainerType
+{
+  /// @name Constructors
+  /// @{
+  protected:
+    ArrayType() : UniformContainerType(ArrayTypeID), maxSize(0) {}
+    virtual ~ArrayType();
+
+  /// @}
+  /// @name Accessors
+  /// @{
+  public:
+    /// Get the maximum size the array can grow to.
+    uint64_t getMaxSize()  const { return maxSize; }
+
+    // Methods to support type inquiry via is, cast, dyn_cast
+    static inline bool classof(const ArrayType*) { return true; }
+    static inline bool classof(const Node* T) { return T->is(ArrayTypeID); }
+    
+  /// @}
+  /// @name Mutators
+  /// @{
+  public:
+    /// Set the maximum size the array can grow to.
+    void setMaxSize(uint64_t max) { maxSize = max; }
+
+  /// @}
+  /// @name Data
+  /// @{
+  protected:
+    uint64_t maxSize; ///< The maximum number of elements in the array
+  /// @}
+  friend class AST;
+};
+
+/// This class represents a fixed size, packed vector of some other type.
+/// Where possible, HLVM will attempt to generate code that makes use of a
+/// machines vector instructions to process such types. If not possible, HLVM
+/// will treat the vector the same as an Array.
+class VectorType : public UniformContainerType
+{
+  /// @name Constructors
+  /// @{
+  protected:
+    VectorType() : UniformContainerType(VectorTypeID), size(0) {}
+    virtual ~VectorType();
+
+  /// @}
+  /// @name Accessors
+  /// @{
+  public:
+    /// Get the maximum size the array can grow to.
+    uint64_t getSize()  const { return size; }
+
+    // Methods to support type inquiry via is, cast, dyn_cast
+    static inline bool classof(const VectorType*) { return true; }
+    static inline bool classof(const Node* T) { return T->is(VectorTypeID); }
+
+  /// @}
+  /// @name Mutators
+  /// @{
+  public:
+    /// Set the size of the vector.
+    void setSize(uint64_t max) { size = max; }
+
+  /// @}
+  /// @name Data
+  /// @{
+  protected:
+    uint64_t size; ///< The (fixed) size of the vector
+  /// @}
+  friend class AST;
+};
+
+/// This class is type that combines a name with an arbitrary type. This
+/// construct is used any where a named and typed object is needed such as
+/// the parameter to a function or the field of a structure. 
+class AliasType : public UniformContainerType
+{
+  /// @name Constructors
+  /// @{
+  protected:
+    AliasType() : UniformContainerType(AliasTypeID) {}
+    virtual ~AliasType();
+
+  /// @}
+  /// @name Accessors
+  /// @{
+  public:
+    virtual const char* getPrimitiveName() const;
+    // Methods to support type inquiry via is, cast, dyn_cast
+    static inline bool classof(const AliasType*) { return true; }
+    static inline bool classof(const Node* T) { return T->is(AliasTypeID); }
+
+  /// @}
+  friend class AST;
+};
+
 /// This class represents a Type in the HLVM Abstract Syntax Tree.  
 /// A Type defines the format of storage. 
 /// @brief HLVM AST Type Node
-class ContainerType : public Type
+class DisparateContainerType : public Type
 {
   /// @name Types
   /// @{
@@ -51,8 +213,8 @@
   /// @name Constructors
   /// @{
   protected:
-    ContainerType(NodeIDs id) : Type(id), contents() {}
-    virtual ~ContainerType();
+    DisparateContainerType(NodeIDs id) : Type(id), contents() {}
+    virtual ~DisparateContainerType();
 
   /// @}
   /// @name Accessors
@@ -60,8 +222,9 @@
   public:
     virtual const char* getPrimitiveName() const;
     // Methods to support type inquiry via is, cast, dyn_cast
-    static inline bool classof(const ContainerType*) { return true; }
-    static inline bool classof(const Type* T) { return T->isContainerType(); }
+    static inline bool classof(const DisparateContainerType*) { return true; }
+    static inline bool classof(const Node* N) { 
+      return N->isDisparateContainerType(); }
 
   /// @}
   /// @name Mutators
@@ -93,16 +256,18 @@
   /// @}
 };
 
+
 typedef AliasType Field;
 
 /// This class represents an HLVM type that is a sequence of data fields 
 /// of varying type. 
-class StructureType : public ContainerType
+class StructureType : public DisparateContainerType
 {
   /// @name Constructors
   /// @{
-  public:
-    StructureType() : ContainerType(StructureTypeID) {}
+  protected:
+    StructureType(NodeIDs id = StructureTypeID ) : 
+      DisparateContainerType(id) {}
     virtual ~StructureType();
 
   /// @}
@@ -111,7 +276,6 @@
   public:
     // Methods to support type inquiry via is, cast, dyn_cast
     static inline bool classof(const StructureType*) { return true; }
-    static inline bool classof(const Type* T) { return T->isStructureType(); }
     static inline bool classof(const Node* T) 
       { return T->is(StructureTypeID); }
 
@@ -126,19 +290,42 @@
   /// @{
   protected:
   /// @}
+  friend class AST;
+};
+
+/// This class holds data for a continuation. TBD later.
+class ContinuationType : public StructureType
+{
+  /// @name Constructors
+  /// @{
+  protected:
+    ContinuationType() : StructureType(ContinuationTypeID) {}
+    virtual ~ContinuationType();
+
+  /// @}
+  /// @name Accessors
+  /// @{
+  public:
+    // Methods to support type inquiry via is, cast, dyn_cast
+    static inline bool classof(const ContinuationType*) { return true; }
+    static inline bool classof(const Node* T) 
+      { return T->is(ContinuationTypeID); }
+  /// @}
+
+  friend class AST;
 };
 
 typedef AliasType Argument;
 
 /// This class represents an HLVM type that is a sequence of data fields 
 /// of varying type. 
-class SignatureType : public ContainerType
+class SignatureType : public DisparateContainerType
 {
   /// @name Constructors
   /// @{
-  public:
+  protected:
     SignatureType() 
-      : ContainerType(SignatureTypeID), result(0), varargs(false) {}
+      : DisparateContainerType(SignatureTypeID), result(0), varargs(false) {}
     virtual ~SignatureType();
 
   /// @}
@@ -150,7 +337,6 @@
 
     // Methods to support type inquiry via is, cast, dyn_cast
     static inline bool classof(const SignatureType*) { return true; }
-    static inline bool classof(const Type* T) { return T->isSignatureType(); }
     static inline bool classof(const Node* T) 
       { return T->is(SignatureTypeID); }
 

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Function.h (original)
+++ hlvm/trunk/hlvm/AST/Function.h Sat Jul  7 19:00:47 2007
@@ -57,7 +57,7 @@
   /// @name Accessors
   /// @{
   public:
-    Block* getBlock() { return block; }
+    Block* getBlock() const { return block; }
     SignatureType* getSignature() { return signature; }
     static inline bool classof(const Function*) { return true; }
     static inline bool classof(const Node* N) { return N->isFunction(); }

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Import.h (original)
+++ hlvm/trunk/hlvm/AST/Import.h Sat Jul  7 19:00:47 2007
@@ -30,7 +30,7 @@
 #ifndef HLVM_AST_IMPORT_H
 #define HLVM_AST_IMPORT_H
 
-#include <hlvm/AST/LinkageItem.h>
+#include <hlvm/AST/Node.h>
 
 namespace hlvm
 {
@@ -41,12 +41,12 @@
 /// has a name, a set of formal arguments, a return type, and a block of
 /// code to execute.
 /// @brief HLVM AST Function Node
-class Import : public LinkageItem
+class Import : public Documentable
 {
   /// @name Constructors
   /// @{
   protected:
-    Import() : LinkageItem(ImportID) {}
+    Import() : Documentable(ImportID) {}
 
   public:
     virtual ~Import();

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

==============================================================================
--- hlvm/trunk/hlvm/AST/InputOutput.cpp (original)
+++ hlvm/trunk/hlvm/AST/InputOutput.cpp Sat Jul  7 19:00:47 2007
@@ -35,30 +35,16 @@
 {
 }
 
-OpenOp* 
-OpenOp::create()
-{
-  return new OpenOp;
-}
-
 CloseOp::~CloseOp()
 {
 }
 
-CloseOp* 
-CloseOp::create()
+ReadOp::~ReadOp()
 {
-  return new CloseOp;
 }
 
 WriteOp::~WriteOp()
 {
 }
 
-WriteOp* 
-WriteOp::create()
-{
-  return new WriteOp;
-}
-
 }

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

==============================================================================
--- hlvm/trunk/hlvm/AST/InputOutput.h (original)
+++ hlvm/trunk/hlvm/AST/InputOutput.h Sat Jul  7 19:00:47 2007
@@ -44,9 +44,6 @@
 {
   /// @name Constructors
   /// @{
-  public:
-    static OpenOp* create();
-
   protected:
     OpenOp() : UnaryOperator(OpenOpID)  {}
     virtual ~OpenOp();
@@ -70,9 +67,6 @@
 {
   /// @name Constructors
   /// @{
-  public:
-    static CloseOp* create();
-
   protected:
     CloseOp() : UnaryOperator(CloseOpID)  {}
     virtual ~CloseOp();
@@ -92,15 +86,35 @@
 /// operands: [1] the stream to write, [2] the data buffer to write, [3] the
 /// length of the data buffer.
 /// @brief HLVM AST Write Stream Operator
-class WriteOp : public TernaryOperator
+class ReadOp : public BinaryOperator
 {
   /// @name Constructors
   /// @{
+  protected:
+    ReadOp() : BinaryOperator(ReadOpID)  {}
+    virtual ~ReadOp();
+
+  /// @}
+  /// @name Accessors
+  /// @{
   public:
-    static WriteOp* create();
+    static inline bool classof(const ReadOp*) { return true; }
+    static inline bool classof(const Node* N) { return N->is(ReadOpID); }
+
+  /// @}
+  friend class AST;
+};
 
+/// This node type represents a stream write operation. There are three 
+/// operands: [1] the stream to write, [2] the data buffer to write, [3] the
+/// length of the data buffer.
+/// @brief HLVM AST Write Stream Operator
+class WriteOp : public BinaryOperator
+{
+  /// @name Constructors
+  /// @{
   protected:
-    WriteOp() : TernaryOperator(WriteOpID)  {}
+    WriteOp() : BinaryOperator(WriteOpID)  {}
     virtual ~WriteOp();
 
   /// @}

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

==============================================================================
--- hlvm/trunk/hlvm/AST/MemoryOps.cpp (original)
+++ hlvm/trunk/hlvm/AST/MemoryOps.cpp Sat Jul  7 19:00:47 2007
@@ -33,6 +33,8 @@
 
 LoadOp::~LoadOp() {}
 StoreOp::~StoreOp() {}
+AutoVarOp::~AutoVarOp() {}
 ReferenceOp::~ReferenceOp() {}
+IndexOp::~IndexOp() {}
 
 }

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

==============================================================================
--- hlvm/trunk/hlvm/AST/MemoryOps.h (original)
+++ hlvm/trunk/hlvm/AST/MemoryOps.h Sat Jul  7 19:00:47 2007
@@ -31,15 +31,15 @@
 #define HLVM_AST_MEMORYOPS_H
 
 #include <hlvm/AST/Operator.h>
+#include <hlvm/AST/Constant.h>
 
 namespace hlvm
 {
 
 class Variable;
 
-/// This operator represents the load operation for loading a variable into a
-/// register.
-/// @brief HLVM AST Memory Load Operator
+/// This operator loads the value of a memory location.
+/// @brief HLVM Memory Load Operator
 class LoadOp : public UnaryOperator
 {
   /// @name Constructors
@@ -70,14 +70,16 @@
   friend class AST;
 };
 
-/// This operator represents the 
-/// @brief HLVM AST String Insert Node
+/// This operator stores a value into a memory location. The first operand 
+/// resolves to the storage location into which the value is stored. The second
+/// operand provides the value to store.
+/// @brief HLVM Memory Store Operator
 class StoreOp : public BinaryOperator
 {
   /// @name Constructors
   /// @{
   protected:
-    StoreOp() : BinaryOperator(LoadOpID) {}
+    StoreOp() : BinaryOperator(StoreOpID) {}
 
   public:
     virtual ~StoreOp();
@@ -102,6 +104,44 @@
   friend class AST;
 };
 
+/// This operator represents a local (stack) variable whose lifespan is the
+/// lifespan of the enclosing block. Its value is the initialized value.
+/// @brief HLVM AST Automatic Variable Operator
+class AutoVarOp : public UnaryOperator
+{
+  /// @name Constructors
+  /// @{
+  protected:
+    AutoVarOp() : UnaryOperator(AutoVarOpID) {}
+
+  public:
+    virtual ~AutoVarOp();
+
+  /// @}
+  /// @name Accessors
+  /// @{
+  public:
+    const std::string& getName() { return name; }
+    Constant* getInitializer() { return static_cast<Constant*>(getOperand());}
+    static inline bool classof(const AutoVarOp*) { return true; }
+    static inline bool classof(const Node* N) { return N->is(AutoVarOpID); }
+
+  /// @}
+  /// @name Mutators
+  /// @{
+  public:
+    void setName(const std::string& n) { name = n; }
+    void setInitializer(Constant* c) { setOperand(c); }
+
+  /// @}
+  /// @name Data
+  /// @{
+  protected:
+    std::string name;
+  /// @}
+  friend class AST;
+};
+
 /// This operator yields the value of a named variable, either an automatic
 /// variable (function scoped) or global variable (bundle scoped). 
 /// @brief HLVM AST Variable Operator
@@ -119,7 +159,7 @@
   /// @name Accessors
   /// @{
   public:
-    const Variable* getReferent() const { return referent; }
+    Value* getReferent() const { return referent; }
     static inline bool classof(const ReferenceOp*) { return true; }
     static inline bool classof(const Node* N) { return N->is(ReferenceOpID); }
 
@@ -127,13 +167,13 @@
   /// @name Mutators
   /// @{
   public:
-    void setReferent(const Variable* var ) { referent = var; }
+    void setReferent(Value* ref) { referent = ref; }
 
   /// @}
   /// @name Data
   /// @{
   protected:
-    const Variable* referent;
+    Value* referent;
   /// @}
   friend class AST;
 };

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Node.h (original)
+++ hlvm/trunk/hlvm/AST/Node.h Sat Jul  7 19:00:47 2007
@@ -54,8 +54,21 @@
 enum NodeIDs 
 {
   NoTypeID = 0,            ///< Use this for an invalid type ID.
-  // Primitive Types (no child nodes)
-  VoidTypeID = 1,          ///< The Void Type (The Null Type)
+
+  // SUBCLASSES OF NODE
+  TreeTopID,               ///< The AST node which is always root of the tree
+FirstNodeID = TreeTopID,
+  DocumentationID,         ///< XHTML Documentation Node
+  DocumentableID,          ///< A node that can have a Documentation Node
+FirstDocumentableID = DocumentableID,
+  BundleID,                ///< The Bundle Node (a group of other declarations)
+  ImportID,                ///< A bundle's Import declaration
+
+  // SUBCLASSES OF TYPE
+  // Primitive Types (inherently supported by HLVM)
+  VoidTypeID,              ///< The Void Type (The Null Type)
+FirstTypeID          = VoidTypeID,
+FirstPrimitiveTypeID = VoidTypeID,
   BooleanTypeID,           ///< The Boolean Type (A simple on/off boolean value)
   CharacterTypeID,         ///< The Character Type (UTF-16 encoded character)
   OctetTypeID,             ///< The Octet Type (8 bits uninterpreted)
@@ -74,23 +87,43 @@
   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)
   AnyTypeID,               ///< The Any Type (Union of any type)
+FirstSimpleTypeID    = AnyTypeID,
   IntegerTypeID,           ///< The Integer Type (A # of bits of integer data)
   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)
-  TextTypeID,              ///< The Text Type (Array of UTF-16 chars + length)
+  OpaqueTypeID,            ///< A placeholder for unresolved types
+LastSimpleTypeID     = OpaqueTypeID,  
 
-  // Container Types
+  // Uniform Container Types
   AliasTypeID,             ///< A new name for an existing type
+FirstContainerTypeID = AliasTypeID,
+FirstUniformContainerTypeID = AliasTypeID,
   PointerTypeID,           ///< The Pointer Type (Pointer To object of Type)
   ArrayTypeID,             ///< The Array Type (Linear array of some type)
   VectorTypeID,            ///< The Vector Type (Packed Fixed Size Vector)
+LastUniformContainerTypeID = VectorTypeID,
+
+  // Disparate Container Types
   StructureTypeID,         ///< The Structure Type (Sequence of various types)
+FirstDisparateContainerTypeID = StructureTypeID,
   SignatureTypeID,         ///< The Function Signature Type
   ContinuationTypeID,      ///< A Continuation Type (data to continuations)
-  OpaqueTypeID,            ///< A placeholder for unresolved types
+LastDisparateContainerTypeID  = ContinuationTypeID,
+LastContainerTypeID = ContinuationTypeID,
+
+  // Runtime Types
+  BufferTypeID,            ///< A buffer of octets for I/O
+FirstRuntimeTypeID = BufferTypeID,
+  StreamTypeID,            ///< A stream handle
+  TextTypeID,              ///< A UTF-8 or UTF-16 encoded text string
+LastRuntimeTypeID = TextTypeID,
+LastTypeID = TextTypeID,
 
   // Class Constructs (TBD)
   InterfaceID,             ///< The Interface Type (set of Signatures)
@@ -98,31 +131,41 @@
   MethodID,                ///< The Method Node (define a method)
   ImplementsID,            ///< Specifies set of Interfaces implemented by class
 
+  // SUBCLASSES OF VALUE
+
   // Constants
   ConstantZeroID,          ///< A zero-filled constant of any type
+FirstValueID = ConstantZeroID,
+FirstConstantID = ConstantZeroID,
   ConstantIntegerID,       ///< A constant integer value
   ConstantRealID,          ///< A constant real value
   ConstantTextID,          ///< A constant text value
+  SizeOfID,                ///< Size of a type
 
   // Linkage Items
   VariableID,              ///< The Variable Node (a storage location)
+FirstLinkageItemID = VariableID,
   FunctionID,              ///< The Function Node (a callable function)
   ProgramID,               ///< The Program Node (a program starting point)
+LastLinkageItemID = ProgramID,
+LastConstantID = ProgramID,
 
-  // Container
-  BundleID,                ///< The Bundle Node (a group of other declarations)
-  BlockID,                 ///< A Block Of Code Nodes
-  ImportID,                ///< A bundle's Import declaration
+  // Operator
+  BlockID,                 ///< A Block Of Operators
+FirstOperatorID = BlockID,
 
   // Nilary Operators (those taking no operands)
   BreakOpID,               ///< Break out of the enclosing loop
+FirstNilaryOperatorID = BreakOpID,
   PInfOpID,                ///< Constant Positive Infinity Real Value
   NInfOpID,                ///< Constant Negative Infinity Real Value
   NaNOpID,                 ///< Constant Not-A-Number Real Value
-  AutoVarOpID,             ///< Declaration of an automatic (stack) variable
+  ReferenceOpID,           ///< Obtain pointer to local/global variable
+LastNilaryOperatorID = ReferenceOpID,
 
   // Control Flow Unary Operators
   ReturnOpID,              ///< The Return A Value Operator
+FirstUnaryOperatorID = ReturnOpID,
   ThrowOpID,               ///< The Throw an Exception Operator
   JumpToOpID,              ///< The Jump To Labelled Block Operator
 
@@ -153,19 +196,20 @@
   LoadOpID,                ///< The Load Operator (load a value from a location)
   AllocateOpID,            ///< The Allocate Memory Operator (get heap memory)
   FreeOpID,                ///< The Free Memory Operator (free heap memory)
-  StackAllocOpID,          ///< The Stack Allocation Operator (get stack mem)
+  AutoVarOpID,             ///< Declaration of an automatic (stack) variable
   IndexOpID,               ///< The Index Operator for indexing an array
-  ReferenceOpID,           ///< The Reference Memory Object Operator (for GC)
-  DereferenceOpID,         ///< The Dereference Memory Object Operator (for GC)
 
-  // Other Unary Operators
+  // Input/Output Unary Operators
   TellOpID,                ///< Tell the position of a stream
   CloseOpID,               ///< Close a stream previously opened.
-  LengthOpID,              ///< Extract Length of a String Operator
-  WithOpID,                ///< Scoping Operator (shorthand for a Bundle) 
+
+  // Other Unary Operators
+  LengthOpID,              ///< Extract Length of a Text/Array/Vector
+LastUnaryOperatorID = LengthOpID,
 
   // Arithmetic Binary Operators
   AddOpID,                 ///< Addition Binary Operator
+FirstBinaryOperatorID = AddOpID,
   SubtractOpID,            ///< Subtraction Binary Operator
   MultiplyOpID,            ///< Multiplcation Binary Operator
   DivideOpID,              ///< Division Binary Operator
@@ -201,54 +245,34 @@
   ReadOpID,                ///< Read from a stream
   WriteOpID,               ///< Write to a stream
   CreateContOpID,          ///< The Create Continutation Operator
+LastBinaryOperatorID = CreateContOpID,
 
   // Ternary Operators
   IfOpID,                  ///< The If-Then-Else Operator
+FirstTernaryOperatorID = IfOpID,
   StrInsertOpID,           ///< Insert(str,where,what)
   StrEraseOpID,            ///< Erase(str,at,len)
   StrReplaceOpID,          ///< Replace(str,at,len,what)
   PositionOpID,            ///< Position a stream (stream,where,relative-to)
+LastTernaryOperatorID = PositionOpID,
 
   // Multi Operators
   CallOpID,                ///< The Call Operator (n operands)
+FirstMultiOperatorID = CallOpID,
   InvokeOpID,              ///< The Invoke Operator (n operands)
   DispatchOpID,            ///< The Object Method Dispatch Operator (n operands)
   CallWithContOpID,        ///< The Call with Continuation Operator (n operands)
   SelectOpID,              ///< The Select An Alternate Operator (n operands)
   LoopOpID,                ///< The General Purpose Loop Operator (5 operands)
+LastMultiOperatorID = LoopOpID,
+LastOperatorID = LoopOpID,
+LastValueID = LoopOpID,
+LastDocumentableID = LoopOpID,
+LastNodeID = LoopOpID,
 
-  // Miscellaneous Nodes
-  DocumentationID,         ///< XHTML Documentation Node
-  TreeTopID,               ///< The AST node which is always root of the tree
-
-  // Enumeration Ranges and Limits
-  NumNodeIDs,              ///< The number of node identifiers in the enum
-  FirstPrimitiveTypeID = VoidTypeID, ///< First Primitive Type
-  LastPrimitiveTypeID  = Float128TypeID, ///< Last Primitive Type
-  FirstSimpleTypeID    = AnyTypeID,
-  LastSimpleTypeID     = TextTypeID,  
-  FirstContainerTypeID = PointerTypeID, ///< First Container Type
-  LastContainerTypeID  = ContinuationTypeID, ///< Last Container Type
-  FirstTypeID          = VoidTypeID,
-  LastTypeID           = OpaqueTypeID,
-  FirstConstantID      = ConstantIntegerID,
-  LastConstantID       = ProgramID,
-  FirstOperatorID      = BreakOpID, ///< First Operator
-  LastOperatorID       = LoopOpID,  ///< Last Operator
-  FirstNilaryOpID      = BreakOpID,
-  LastNilaryOpID       = NaNOpID,
-  FirstUnaryOpID       = ReturnOpID,
-  LastUnaryOpID        = WithOpID,
-  FirstBinaryOpID      = AddOpID,
-  LastBinaryOpID       = CreateContOpID,
-  FirstTernaryOpID     = IfOpID,
-  LastTernaryOpID      = PositionOpID,
-  FirstMultiOpID       = CallOpID,
-  LastMultiOpID        = LoopOpID
+  NumNodeIDs               ///< The number of node identifiers in the enum
 };
 
-class ParentNode;
-
 /// This class is the base class of HLVM Abstract Syntax Tree (AST). All 
 /// other AST nodes are subclasses of this class.
 /// @brief Abstract base class of all HLVM AST node classes
@@ -284,92 +308,81 @@
 
     /// Determine if the node is a Type
     inline bool isType() const {
-      return id >= FirstTypeID && id <= LastTypeID;
-    }
+      return id >= FirstTypeID && 
+             id <= LastTypeID; }
 
     inline bool isIntegralType()  const { 
       return (id >= UInt8TypeID && id <= UInt128TypeID) ||
              (id == IntegerTypeID) || (id == RangeTypeID) || 
-             (id == EnumerationTypeID);
-    }
+             (id == EnumerationTypeID); }
 
     /// Determine if the node is a primitive type
     inline bool isPrimitiveType() const {
-      return id >= FirstPrimitiveTypeID && id <= LastPrimitiveTypeID;
-    }
+      return id >= FirstPrimitiveTypeID && 
+             id <= LastPrimitiveTypeID; }
 
     /// Determine if the node is a simple type
     inline bool isSimpleType() const {
-      return id >= FirstSimpleTypeID && id <= LastSimpleTypeID;
+      return id >= FirstSimpleTypeID && 
+             id <= LastSimpleTypeID;
     }
 
+    /// Determine if the node is a uniform container type
+    inline bool isUniformContainerType() const {
+      return id >= FirstUniformContainerTypeID && 
+             id <= LastUniformContainerTypeID;
+    }
+    /// Determine if the node is a disparate container type
+    inline bool isDisparateContainerType() const {
+      return id >= FirstDisparateContainerTypeID && 
+             id <= LastDisparateContainerTypeID; }
+
+    /// Determine if the node is a runtime type
+    inline bool isRuntimeType() const {
+      return id >= FirstRuntimeTypeID &&
+             id <= LastRuntimeTypeID; }
+
     /// Determine if the node is a container type
     inline bool isContainerType() const {
       return id >= FirstContainerTypeID && id <= LastContainerTypeID;
     }
-
-    inline bool isAnyType() const { return id == AnyTypeID; }
-    inline bool isBooleanType() const { return id == BooleanTypeID; }
-    inline bool isCharacterType() const { return id == CharacterTypeID; }
-    inline bool isOctetType() const { return id == OctetTypeID; }
-    inline bool isIntegerType() const { return id == IntegerTypeID; }
-    inline bool isRangeType() const { return id == RangeTypeID; }
-    inline bool isRealType() const { return id == RealTypeID; }
-    inline bool isRationalType() const { return id == RationalTypeID; }
-    inline bool isPointerType() const { return id == PointerTypeID; }
-    inline bool isArrayType() const { return id == ArrayTypeID; }
-    inline bool isVectorType() const { return id == VectorTypeID; }
-    inline bool isStructureType() const { return id == StructureTypeID; }
-    inline bool isSignatureType() const { return id == SignatureTypeID; }
-    inline bool isVoidType() const { return id == VoidTypeID; }
-
     /// Determine if the node is one of the Constant values.
     inline bool isConstant() const {
-      return id >= FirstConstantID && id <= LastConstantID;
-    }
+      return id >= FirstConstantID && id <= LastConstantID; }
+
+    /// Determine if the node is a LinkageItem
+    inline bool isLinkageItem() const {
+      return id >= FirstLinkageItemID && id <= LastLinkageItemID; }
 
     /// Determine if the node is any of the Operators
     inline bool isOperator() const { 
-      return id >= FirstOperatorID && id <= LastOperatorID;
-    }
+      return id >= FirstOperatorID && id <= LastOperatorID; }
+
     inline bool isNilaryOperator() const {
-      return id >= FirstNilaryOpID && id <= LastNilaryOpID;
-    }
+      return id >= FirstNilaryOperatorID && id <= LastNilaryOperatorID; }
+
     inline bool isUnaryOperator() const {
-      return id >= FirstUnaryOpID && id <= LastUnaryOpID;
-    }
+      return id >= FirstUnaryOperatorID && id <= LastUnaryOperatorID; }
+
     inline bool isBinaryOperator() const {
-      return id >= FirstBinaryOpID && id <= LastBinaryOpID;
-    }
+      return id >= FirstBinaryOperatorID && id <= LastBinaryOperatorID; }
+
     inline bool isTernaryOperator() const {
-      return id >= FirstTernaryOpID && id <= LastTernaryOpID;
-    }
+      return id >= FirstTernaryOperatorID && id <= LastTernaryOperatorID; }
+
     inline bool isMultiOperator() const {
-      return id >= FirstMultiOpID && id <= LastMultiOpID;
-    }
+      return id >= FirstMultiOperatorID && id <= LastMultiOperatorID; }
 
     /// Determine if the node is a Documentable Node
-    bool isDocumentable() const { return isValue() || isType() || isBundle();}
-
-    /// Determine if the node is a LinkageItem
-    bool isLinkageItem() const {
-      return isFunction() || isVariable();
-    }
+    bool isDocumentable() const { 
+      return id >= FirstDocumentableID && id <= LastDocumentableID; }
 
     /// Determine if the node is a Value
-    bool isValue() const { return isOperator() || isConstant(); }
+    bool isValue() const { 
+      return id >= FirstValueID && id <= LastValueID; }
 
-    /// Determine if the node is a Block
-    inline bool isBlock() const { return id == BlockID; }
-    /// Determine if the node is a Bundle
-    inline bool isBundle() const { return id == BundleID; }
-    /// Determine if the node is a Function
     inline bool isFunction() const 
-      { return id == FunctionID || id == ProgramID;}
-    /// Determine if the node is a Program
-    inline bool isProgram() const { return id == ProgramID; }
-    /// Determine if the node is a Variable
-    inline bool isVariable() const { return id == VariableID; }
+      { return id == FunctionID || id == ProgramID; }
 
     /// Provide support for isa<X> and friends
     static inline bool classof(const Node*) { return true; }

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Operator.h (original)
+++ hlvm/trunk/hlvm/AST/Operator.h Sat Jul  7 19:00:47 2007
@@ -113,6 +113,7 @@
   /// @name Accessors
   /// @{
   public:
+    Value* getOperand() const { return op1; }
     virtual size_t  numOperands() const;
     virtual Value* getOperand(unsigned opnum) const;
     static inline bool classof(const UnaryOperator*) { return true; }

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Program.h (original)
+++ hlvm/trunk/hlvm/AST/Program.h Sat Jul  7 19:00:47 2007
@@ -59,8 +59,7 @@
   /// @{
   public:
     static inline bool classof(const Program*) { return true; }
-    static inline bool classof(const Function*F) { return F->isProgram(); }
-    static inline bool classof(const Node* N) { return N->isProgram(); }
+    static inline bool classof(const Node* N) { return N->is(ProgramID); }
 
   /// @}
   /// @name Data

Added: hlvm/trunk/hlvm/AST/RuntimeType.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/RuntimeType.cpp?rev=38179&view=auto

==============================================================================
--- hlvm/trunk/hlvm/AST/RuntimeType.cpp (added)
+++ hlvm/trunk/hlvm/AST/RuntimeType.cpp Sat Jul  7 19:00:47 2007
@@ -0,0 +1,59 @@
+//===-- AST Runtime Type Implementation -------------------------*- C++ -*-===//
+//
+//                      High Level Virtual Machine (HLVM)
+//
+// Copyright (C) 2006 Reid Spencer. All Rights Reserved.
+//
+// This software is free software; you can redistribute it and/or modify it 
+// under the terms of the GNU Lesser General Public License as published by 
+// the Free Software Foundation; either version 2.1 of the License, or (at 
+// your option) any later version.
+//
+// This software is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+// FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for 
+// more details.
+//
+// You should have received a copy of the GNU Lesser General Public License 
+// along with this library in the file named LICENSE.txt; if not, write to the 
+// Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+// MA 02110-1301 USA
+//
+//===----------------------------------------------------------------------===//
+/// @file hlvm/AST/RuntimeType.cpp
+/// @author Reid Spencer <rspencer at reidspencer.org> (original author)
+/// @date 2006/05/24
+/// @since 0.1.0
+/// @brief Implements the functions of the runtime types
+//===----------------------------------------------------------------------===//
+
+#include <hlvm/AST/RuntimeType.h>
+#include <hlvm/Base/Assert.h>
+
+namespace hlvm {
+
+
+const char* 
+RuntimeType::getPrimitiveName() const
+{
+  hlvmDeadCode("RuntimeTypes don't have primitive names");
+  return "";
+}
+
+RuntimeType::~RuntimeType()
+{
+}
+
+TextType::~TextType()
+{
+}
+
+StreamType::~StreamType()
+{
+}
+
+BufferType::~BufferType()
+{
+}
+
+}

Added: hlvm/trunk/hlvm/AST/RuntimeType.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/RuntimeType.h?rev=38179&view=auto

==============================================================================
--- hlvm/trunk/hlvm/AST/RuntimeType.h (added)
+++ hlvm/trunk/hlvm/AST/RuntimeType.h Sat Jul  7 19:00:47 2007
@@ -0,0 +1,121 @@
+//===-- AST Runtime Type Interfaces -----------------------------*- C++ -*-===//
+//
+//                      High Level Virtual Machine (HLVM)
+//
+// Copyright (C) 2006 Reid Spencer. All Rights Reserved.
+//
+// This software is free software; you can redistribute it and/or modify it 
+// under the terms of the GNU Lesser General Public License as published by 
+// the Free Software Foundation; either version 2.1 of the License, or (at 
+// your option) any later version.
+//
+// This software is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+// FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for 
+// more details.
+//
+// You should have received a copy of the GNU Lesser General Public License 
+// along with this library in the file named LICENSE.txt; if not, write to the 
+// Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+// MA 02110-1301 USA
+//
+//===----------------------------------------------------------------------===//
+/// @file hlvm/AST/RuntimeType.h   
+/// @author Reid Spencer <rspencer at reidspencer.com> (original author)
+/// @date 2006/05/04
+/// @since 0.1.0
+/// @brief Declares types for the objects that the runtime manipulates.
+//===----------------------------------------------------------------------===//
+
+#ifndef HLVM_AST_RUNTIMETYPE_H  
+#define HLVM_AST_RUNTIMETYPE_H  
+
+#include <hlvm/AST/Type.h>
+
+namespace hlvm 
+{
+
+/// This class represents an opaque type that the runtime will use. The generic
+/// definition (in LLVM lingo) is a "pointer to opaque". The Runtime then is
+/// able to define what the types are without breaking compatibility across
+/// releases. Runtime types are disginguished by their names.
+class RuntimeType : public Type
+{
+  /// @name Constructors
+  /// @{
+  protected:
+    RuntimeType(NodeIDs id, const std::string& n) : Type(id) { setName(n); }
+    virtual ~RuntimeType();
+
+  /// @}
+  /// @name Accessors
+  /// @{
+  public:
+    virtual const char* getPrimitiveName() const; // asserting override
+    // Methods to support type inquiry via isa, cast, dyn_cast
+    static inline bool classof(const RuntimeType*) { return true; }
+    static inline bool classof(const Type* T) { return T->isRuntimeType(); }
+  /// @}
+  friend class AST;
+};
+
+class TextType : public RuntimeType
+{
+  /// @name Constructors
+  /// @{
+  protected:
+    TextType() : RuntimeType(TextTypeID,"hlvm_text") {}
+    virtual ~TextType();
+
+  /// @}
+  /// @name Accessors
+  /// @{
+  public:
+    static inline bool classof(const TextType*) { return true; }
+    static inline bool classof(const Node* N) 
+      { return N->is(TextTypeID); }
+
+  /// @}
+  friend class AST;
+};
+
+class StreamType : public RuntimeType
+{
+  /// @name Constructors
+  /// @{
+  protected:
+    StreamType() : RuntimeType(StreamTypeID,"hlvm_stream") {}
+    virtual ~StreamType();
+  /// @}
+  /// @name Accessors
+  /// @{
+  public:
+    static inline bool classof(const StreamType*) { return true; }
+    static inline bool classof(const Node* N) 
+      { return N->is(StreamTypeID); }
+
+  /// @}
+  friend class AST;
+};
+
+class BufferType : public RuntimeType
+{
+  /// @name Constructors
+  /// @{
+  protected:
+    BufferType() : RuntimeType(BufferTypeID,"hlvm_buffer") {}
+    virtual ~BufferType();
+  /// @}
+  /// @name Accessors
+  /// @{
+  public:
+    static inline bool classof(const BufferType*) { return true; }
+    static inline bool classof(const Node* N) 
+      { return N->is(BufferTypeID); }
+
+  /// @}
+  friend class AST;
+};
+
+} // hlvm
+#endif

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

==============================================================================
--- hlvm/trunk/hlvm/AST/SymbolTable.h (original)
+++ hlvm/trunk/hlvm/AST/SymbolTable.h Sat Jul  7 19:00:47 2007
@@ -120,6 +120,9 @@
   /// @returns the Node that was erased from the symbol table.
   Node* erase(iterator TI);
 
+  /// Remove a node using a specific key
+  bool erase(const std::string& name) { return map_.erase(name) > 0; }
+
   /// Remove a specific Node from the symbol table. This isn't fast, linear
   /// search, O(n), algorithm.
   /// @returns true if the erase was successful (TI was found)

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Type.cpp (original)
+++ hlvm/trunk/hlvm/AST/Type.cpp Sat Jul  7 19:00:47 2007
@@ -39,7 +39,7 @@
 void
 Type::insertChild(Node* n)
 {
-  hlvmAssert(!"This type doesn't accept children!");
+  hlvmAssert(!"This Type doesn't accept children!");
 }
 
 const char*
@@ -223,32 +223,6 @@
   return "void";
 }
 
-PointerType::~PointerType()
-{
-}
-
-ArrayType::~ArrayType()
-{
-}
-
-VectorType::~VectorType()
-{
-}
-
-AliasType::~AliasType()
-{
-}
-
-const char*
-AliasType::getPrimitiveName() const
-{
-  return type->getPrimitiveName();
-}
-
-TextType::~TextType()
-{
-}
-
 OpaqueType::~OpaqueType()
 {
 }

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Type.h (original)
+++ hlvm/trunk/hlvm/AST/Type.h Sat Jul  7 19:00:47 2007
@@ -102,7 +102,6 @@
 
     // Methods to support type inquiry via is, cast, dyn_cast
     static inline bool classof(const AnyType*) { return true; }
-    static inline bool classof(const Type* T) { return T->isAnyType(); }
     static inline bool classof(const Node* T) { return T->is(AnyTypeID); }
   /// @}
   friend class AST;
@@ -123,7 +122,6 @@
     virtual const char* getPrimitiveName() const;
     // Methods to support type inquiry via is, cast, dyn_cast
     static inline bool classof(const BooleanType*) { return true; }
-    static inline bool classof(const Type* T) { return T->isBooleanType(); }
     static inline bool classof(const Node* T) { return T->is(BooleanTypeID); }
   /// @}
   friend class AST;
@@ -144,9 +142,7 @@
     virtual const char* getPrimitiveName() const;
     // Methods to support type inquiry via is, cast, dyn_cast
     static inline bool classof(const CharacterType*) { return true; }
-    static inline bool classof(const Type* T) { return T->isCharacterType(); }
-    static inline bool classof(const Node* T) 
-      { return T->is(CharacterTypeID); }
+    static inline bool classof(const Node* T) { return T->is(CharacterTypeID); }
   /// @}
   friend class AST;
 };
@@ -166,7 +162,6 @@
     virtual const char* getPrimitiveName() const;
     // Methods to support type inquiry via is, cast, dyn_cast
     static inline bool classof(const OctetType*) { return true; }
-    static inline bool classof(const Type* T) { return T->isOctetType(); }
     static inline bool classof(const Node* T) { return T->is(OctetTypeID); }
   /// @}
   friend class AST;
@@ -187,7 +182,6 @@
     virtual const char* getPrimitiveName() const;
     // Methods to support type inquiry via is, cast, dyn_cast
     static inline bool classof(const VoidType*) { return true; }
-    static inline bool classof(const Type* T) { return T->isVoidType(); }
     static inline bool classof(const Node* T) { return T->is(VoidTypeID); }
   /// @}
   friend class AST;
@@ -227,7 +221,6 @@
 
     // Methods to support type inquiry via is, cast, dyn_cast
     static inline bool classof(const IntegerType*) { return true; }
-    static inline bool classof(const Type* T) { return T->isIntegralType(); }
     static inline bool classof(const Node* T) { return T->isIntegralType(); }
 
   /// @}
@@ -276,7 +269,6 @@
 
     // Methods to support type inquiry via is, cast, dyn_cast
     static inline bool classof(const RangeType*) { return true; }
-    static inline bool classof(const Type* T) { return T->isRangeType(); }
     static inline bool classof(const Node* T) { return T->is(RangeTypeID); }
 
   /// @}
@@ -326,8 +318,6 @@
     virtual const char* getPrimitiveName() const;
     // Methods to support type inquiry via is, cast, dyn_cast
     static inline bool classof(const EnumerationType*) { return true; }
-    static inline bool classof(const Type* T) 
-      { return T->is(EnumerationTypeID); }
     static inline bool classof(const Node* T) 
       { return T->is(EnumerationTypeID); }
 
@@ -390,7 +380,6 @@
 
     // Methods to support type inquiry via is, cast, dyn_cast
     static inline bool classof(const RealType*) { return true; }
-    static inline bool classof(const Type* T) { return T->isRealType(); }
     static inline bool classof(const Node* T) { return T->is(RealTypeID); }
 
   /// @}
@@ -413,196 +402,6 @@
   friend class AST;
 };
 
-/// This class represents a storage location that is a pointer to another
-/// type. 
-class PointerType : public Type
-{
-  /// @name Constructors
-  /// @{
-  protected:
-    PointerType() : Type(PointerTypeID) {}
-    virtual ~PointerType();
-
-  /// @}
-  /// @name Accessors
-  /// @{
-  public:
-    // Get the target type
-    Type* getTargetType() const { return type; }
-
-    // Methods to support type inquiry via is, cast, dyn_cast
-    static inline bool classof(const PointerType*) { return true; }
-    static inline bool classof(const Type* T) { return T->isPointerType(); }
-    static inline bool classof(const Node* T) { return T->is(PointerTypeID); }
-
-  /// @}
-  /// @name Mutators
-  /// @{
-  public:
-    void setTargetType(Type* t) { type = t; }
-
-  /// @}
-  /// @name Data
-  /// @{
-  protected:
-    Type* type;
-  /// @}
-  friend class AST;
-};
-
-/// This class represents a resizeable, aligned array of some other type. The
-/// Array references a Type that specifies the type of elements in the array.
-class ArrayType : public Type
-{
-  /// @name Constructors
-  /// @{
-  public:
-    ArrayType() : Type(ArrayTypeID), type(0), maxSize(0) {}
-    virtual ~ArrayType();
-
-  /// @}
-  /// @name Accessors
-  /// @{
-  public:
-    /// Get the type of the array's elements.
-    Type* getElementType() const { return type; }
-
-    /// Get the maximum size the array can grow to.
-    uint64_t getMaxSize()  const { return maxSize; }
-
-    // Methods to support type inquiry via is, cast, dyn_cast
-    static inline bool classof(const ArrayType*) { return true; }
-    static inline bool classof(const Type* T) { return T->isArrayType(); }
-    static inline bool classof(const Node* T) { return T->is(ArrayTypeID); }
-    
-  /// @}
-  /// @name Mutators
-  /// @{
-  public:
-    /// Set the type of the array's elements.
-    void setElementType(Type* t) { type = t; }
-
-    /// Set the maximum size the array can grow to.
-    void setMaxSize(uint64_t max) { maxSize = max; }
-
-  /// @}
-  /// @name Data
-  /// @{
-  protected:
-    Type* type;       ///< The type of the elements of the array
-    uint64_t maxSize; ///< The maximum number of elements in the array
-  /// @}
-  friend class AST;
-};
-
-/// This class represents a fixed size, packed vector of some other type.
-/// Where possible, HLVM will attempt to generate code that makes use of a
-/// machines vector instructions to process such types. If not possible, HLVM
-/// will treat the vector the same as an Array.
-class VectorType : public Type
-{
-  /// @name Constructors
-  /// @{
-  protected:
-    VectorType() : Type(VectorTypeID), type(0), size(0) {}
-    virtual ~VectorType();
-
-  /// @}
-  /// @name Accessors
-  /// @{
-  public:
-    /// Get the type of the array's elements.
-    Type* getElementType() const { return type; }
-
-    /// Get the maximum size the array can grow to.
-    uint64_t getSize()  const { return size; }
-
-    // Methods to support type inquiry via is, cast, dyn_cast
-    static inline bool classof(const VectorType*) { return true; }
-    static inline bool classof(const Type* T) { return T->isVectorType(); }
-    static inline bool classof(const Node* T) { return T->is(VectorTypeID); }
-
-  /// @}
-  /// @name Mutators
-  /// @{
-  public:
-    /// Set the type of the vector's elements.
-    void setElementType(Type* t) { type = t; }
-
-    /// Set the size of the vector.
-    void setSize(uint64_t max) { size = max; }
-
-  /// @}
-  /// @name Data
-  /// @{
-  protected:
-    Type* type;    ///< The type of the vector's elements.
-    uint64_t size; ///< The (fixed) size of the vector
-  /// @}
-  friend class AST;
-};
-
-/// This class is type that combines a name with an arbitrary type. This
-/// construct is used any where a named and typed object is needed such as
-/// the parameter to a function or the field of a structure. 
-class AliasType : public Type
-{
-  /// @name Constructors
-  /// @{
-  public:
-    AliasType() : Type(AliasTypeID), type(0) {}
-    virtual ~AliasType();
-
-  /// @}
-  /// @name Accessors
-  /// @{
-  public:
-    virtual const char* getPrimitiveName() const;
-    
-    // Get the type for the name
-    Type *  getType() const { return type; }
-
-    // Methods to support type inquiry via is, cast, dyn_cast
-    static inline bool classof(const AliasType*) { return true; }
-    static inline bool classof(const Node* T) { return T->is(AliasTypeID); }
-
-  /// @}
-  /// @name Mutators
-  /// @{
-  public:
-    // Set the type for the name
-    void setType(Type * t) { type = t; }
-
-  /// @}
-  /// @name Data
-  /// @{
-  protected:
-    Type* type;
-  /// @}
-};
-
-class TextType : public Type
-{
-  /// @name Constructors
-  /// @{
-  public:
-    TextType(const std::string& nm) : 
-      Type(TextTypeID) { this->setName(nm); }
-  public:
-    virtual ~TextType();
-
-  /// @}
-  /// @name Accessors
-  /// @{
-  public:
-    static inline bool classof(const TextType*) { return true; }
-    static inline bool classof(const Node* N) 
-      { return N->is(TextTypeID); }
-
-  /// @}
-  friend class AST;
-};
-
 class OpaqueType : public Type
 {
   /// @name Constructors

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Variable.cpp (original)
+++ hlvm/trunk/hlvm/AST/Variable.cpp Sat Jul  7 19:00:47 2007
@@ -37,10 +37,4 @@
 {
 }
 
-bool
-Variable::isLocal() const
-{
-  return llvm::isa<Block>(this->getParent());
-}
-
 }

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Variable.h (original)
+++ hlvm/trunk/hlvm/AST/Variable.h Sat Jul  7 19:00:47 2007
@@ -58,10 +58,9 @@
   /// @{
   public:
     bool isConstant() const { return isConst; }
-    bool isLocal() const;
     Constant* getInitializer() { return init; }
     static inline bool classof(const Variable*) { return true; }
-    static inline bool classof(const Node* N) { return N->isVariable(); }
+    static inline bool classof(const Node* N) { return N->is(VariableID); }
 
   /// @}
   /// @name Mutators

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

==============================================================================
--- hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp (original)
+++ hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp Sat Jul  7 19:00:47 2007
@@ -49,12 +49,14 @@
 #include <llvm/Instructions.h>
 #include <llvm/DerivedTypes.h>
 #include <llvm/TypeSymbolTable.h>
+#include <llvm/ValueSymbolTable.h>
 #include <llvm/Constants.h>
 #include <llvm/CallingConv.h>
 #include <llvm/Linker.h>
 #include <llvm/Bytecode/Writer.h>
 #include <llvm/PassManager.h>
 #include <llvm/Assembly/PrintModulePass.h>
+#include <llvm/Analysis/Verifier.h>
 
 namespace {
 using namespace llvm;
@@ -71,36 +73,82 @@
 {
   typedef std::vector<llvm::Module*> ModuleList;
   typedef std::vector<llvm::Value*> OperandList;
+  typedef std::map<hlvm::Variable*,llvm::Value*> VariableDictionary;
+  typedef std::map<hlvm::AutoVarOp*,llvm::Value*> AutoVarDictionary;
+  typedef std::map<hlvm::Constant*,llvm::Constant*> ConstantDictionary;
   ModuleList modules;        ///< The list of modules we construct
   llvm::Module*     lmod;    ///< The current module we're generation 
   llvm::Function*   lfunc;   ///< The current LLVM function we're generating 
   llvm::BasicBlock* lblk;    ///< The current LLVM block we're generating
   llvm::BasicBlock::InstListType linst; 
   OperandList lops;          ///< The current list of instruction operands
+  VariableDictionary gvars;
+  AutoVarDictionary lvars;
   llvm::TypeSymbolTable ltypes; ///< The cached LLVM types we've generated
+  ConstantDictionary consts; ///< The cached LLVM constants we've generated
     ///< The current LLVM instructions we're generating
   const AST* ast;            ///< The current Tree we're traversing
   const Bundle* bundle;      ///< The current Bundle we're traversing
   const hlvm::Function* function;  ///< The current Function we're traversing
   const Block* block;        ///< The current Block we're traversing
   std::vector<llvm::Function*> progs; ///< The list of programs to emit
-  const llvm::FunctionType* entry_FT; ///< The llvm function type for programs
+
+  /// Interfaces to the HLVM Runtime Library
+  llvm::PointerType*  hlvm_text;          ///< Opaque type for text objects
+  llvm::Function*     hlvm_text_create;   ///< Create a new text object
+  llvm::Function*     hlvm_text_delete;   ///< Delete a text object
+  llvm::Function*     hlvm_text_to_buffer;///< Convert text to a buffer
+  llvm::PointerType*  hlvm_buffer;        ///< Pointer To octet
+  llvm::Function*     hlvm_buffer_create; ///< Create a new buffer object
+  llvm::Function*     hlvm_buffer_delete; ///< Delete a buffer
+  llvm::PointerType*  hlvm_stream;        ///< Pointer to stream type
+  llvm::Function*     hlvm_stream_open;   ///< Function for stream_open
+  llvm::Function*     hlvm_stream_read;   ///< Function for stream_read
+  llvm::Function*     hlvm_stream_write_buffer; ///< Write buffer to stream
+  llvm::Function*     hlvm_stream_write_text;   ///< Write text to stream
+  llvm::Function*     hlvm_stream_close;  ///< Function for stream_close
+  llvm::FunctionType* hlvm_program_signature; ///< The llvm type for programs
 
   public:
     LLVMGeneratorPass(const AST* tree)
       : Pass(0,Pass::PreAndPostOrderTraversal),
-      modules(), lmod(0), lfunc(0), lblk(0), linst(), lops(), ltypes(),
-      ast(tree),   bundle(0), function(0), block(0), entry_FT(0) { }
+      modules(), lmod(0), lfunc(0), lblk(0), linst(), lops(), 
+      gvars(), lvars(), ltypes(), consts(),
+      ast(tree),   bundle(0), function(0), block(0),
+      hlvm_text(0), hlvm_text_create(0), hlvm_text_delete(0),
+      hlvm_text_to_buffer(0),
+      hlvm_buffer(0), hlvm_buffer_create(0), hlvm_buffer_delete(0),
+      hlvm_stream(0),
+      hlvm_stream_open(0), hlvm_stream_read(0),
+      hlvm_stream_write_buffer(0), hlvm_stream_write_text(0), 
+      hlvm_stream_close(0), hlvm_program_signature(0)
+      { }
     ~LLVMGeneratorPass() { }
 
   /// Conversion functions
   const llvm::Type* getType(const hlvm::Type* ty);
   llvm::Constant* getConstant(const hlvm::Constant* C);
   llvm::Value* getVariable(const hlvm::Variable* V);
-  const llvm::FunctionType* getProgramFT();
   inline llvm::GlobalValue::LinkageTypes getLinkageTypes(LinkageKinds lk);
   inline std::string getLinkageName(LinkageItem* li);
 
+  /// Accessors for HLVM Runtime Library things
+  inline llvm::Type*         get_hlvm_size();
+  inline llvm::PointerType*  get_hlvm_text();
+  inline llvm::Function*     get_hlvm_text_create();
+  inline llvm::Function*     get_hlvm_text_delete();
+  inline llvm::Function*     get_hlvm_text_to_buffer();
+  inline llvm::PointerType*  get_hlvm_buffer();
+  inline llvm::Function*     get_hlvm_buffer_create();
+  inline llvm::Function*     get_hlvm_buffer_delete();
+  inline llvm::PointerType*  get_hlvm_stream();
+  inline llvm::Function*     get_hlvm_stream_open();
+  inline llvm::Function*     get_hlvm_stream_read();
+  inline llvm::Function*     get_hlvm_stream_write_buffer();
+  inline llvm::Function*     get_hlvm_stream_write_text();
+  inline llvm::Function*     get_hlvm_stream_close();
+  inline llvm::FunctionType* get_hlvm_program_signature();
+
   /// Generator
   template <class NodeClass>
   inline void gen(NodeClass *nc);
@@ -112,6 +160,228 @@
   inline llvm::Module* linkModules();
 };
 
+llvm::Type*
+LLVMGeneratorPass::get_hlvm_size()
+{
+  return llvm::Type::ULongTy;
+}
+
+llvm::PointerType*
+LLVMGeneratorPass::get_hlvm_text()
+{
+  if (! hlvm_text) {
+    llvm::OpaqueType* opq = llvm::OpaqueType::get();
+    lmod->addTypeName("hlvm_text_obj", opq);
+    hlvm_text = llvm::PointerType::get(opq);
+    lmod->addTypeName("hlvm_text", hlvm_text);
+  }
+  return hlvm_text;
+}
+
+llvm::Function*
+LLVMGeneratorPass::get_hlvm_text_create()
+{
+  if (! hlvm_text_create) {
+    llvm::Type* result = get_hlvm_text();
+    std::vector<const llvm::Type*> arg_types;
+    arg_types.push_back(llvm::PointerType::get(llvm::Type::SByteTy));
+    llvm::FunctionType* FT = llvm::FunctionType::get(result,arg_types,false);
+    lmod->addTypeName("hlvm_text_create",FT);
+    hlvm_text_create = 
+      new llvm::Function(FT, llvm::GlobalValue::ExternalLinkage, 
+      "hlvm_text_create", lmod);
+  }
+  return hlvm_text_create;
+}
+
+llvm::Function*
+LLVMGeneratorPass::get_hlvm_text_delete()
+{
+  if (! hlvm_text_delete) {
+    llvm::Type* result = get_hlvm_text();
+    std::vector<const llvm::Type*> arg_types;
+    arg_types.push_back(get_hlvm_text());
+    llvm::FunctionType* FT = llvm::FunctionType::get(result,arg_types,false);
+    lmod->addTypeName("hlvm_text_delete",FT);
+    hlvm_text_delete = 
+      new llvm::Function(FT, llvm::GlobalValue::ExternalLinkage, 
+      "hlvm_text_delete", lmod);
+  }
+  return hlvm_text_delete;
+}
+
+llvm::Function*
+LLVMGeneratorPass::get_hlvm_text_to_buffer()
+{
+  if (! hlvm_text_to_buffer) {
+    llvm::Type* result = get_hlvm_buffer();
+    std::vector<const llvm::Type*> arg_types;
+    arg_types.push_back(get_hlvm_text());
+    llvm::FunctionType* FT = llvm::FunctionType::get(result,arg_types,false);
+    lmod->addTypeName("hlvm_text_to_buffer_signature",FT);
+    hlvm_text_to_buffer = 
+      new llvm::Function(FT, llvm::GlobalValue::ExternalLinkage, 
+      "hlvm_text_to_buffer", lmod);
+  }
+  return hlvm_text_to_buffer;
+}
+
+llvm::PointerType*
+LLVMGeneratorPass::get_hlvm_buffer()
+{
+  if (! hlvm_buffer) {
+    llvm::OpaqueType* opq = llvm::OpaqueType::get();
+    lmod->addTypeName("hlvm_buffer_obj", opq);
+    hlvm_buffer = llvm::PointerType::get(opq);
+    lmod->addTypeName("hlvm_buffer", hlvm_buffer);
+  }
+  return hlvm_buffer;
+}
+
+llvm::Function*
+LLVMGeneratorPass::get_hlvm_buffer_create()
+{
+  if (! hlvm_buffer_create) {
+    llvm::Type* result = get_hlvm_buffer();
+    std::vector<const llvm::Type*> arg_types;
+    arg_types.push_back(get_hlvm_size());
+    llvm::FunctionType* FT = llvm::FunctionType::get(result,arg_types,false);
+    lmod->addTypeName("hlvm_buffer_create",FT);
+    hlvm_buffer_create = 
+      new llvm::Function(FT, llvm::GlobalValue::ExternalLinkage, 
+      "hlvm_buffer_create", lmod);
+  }
+  return hlvm_buffer_create;
+}
+
+llvm::Function*
+LLVMGeneratorPass::get_hlvm_buffer_delete()
+{
+  if (! hlvm_buffer_delete) {
+    llvm::Type* result = get_hlvm_buffer();
+    std::vector<const llvm::Type*> arg_types;
+    arg_types.push_back(get_hlvm_buffer());
+    llvm::FunctionType* FT = llvm::FunctionType::get(result,arg_types,false);
+    lmod->addTypeName("hlvm_buffer_delete",FT);
+    hlvm_buffer_delete = 
+      new llvm::Function(FT, llvm::GlobalValue::ExternalLinkage, 
+      "hlvm_buffer_delete", lmod);
+  }
+  return hlvm_buffer_delete;
+}
+
+llvm::PointerType* 
+LLVMGeneratorPass::get_hlvm_stream()
+{
+  if (! hlvm_stream) {
+    llvm::OpaqueType* opq = llvm::OpaqueType::get();
+    lmod->addTypeName("hlvm_stream_obj", opq);
+    hlvm_stream= llvm::PointerType::get(opq);
+    lmod->addTypeName("hlvm_stream", hlvm_stream);
+  }
+  return hlvm_stream;
+}
+
+llvm::Function*
+LLVMGeneratorPass::get_hlvm_stream_open()
+{
+  if (!hlvm_stream_open) {
+    llvm::Type* result = get_hlvm_stream();
+    std::vector<const llvm::Type*> arg_types;
+    arg_types.push_back(get_hlvm_text());
+    llvm::FunctionType* FT = llvm::FunctionType::get(result,arg_types,false);
+    lmod->addTypeName("hlvm_stream_open_signature",FT);
+    hlvm_stream_open = 
+      new llvm::Function(FT, llvm::GlobalValue::ExternalLinkage, 
+        "hlvm_stream_open", lmod);
+  }
+  return hlvm_stream_open;
+}
+
+llvm::Function*
+LLVMGeneratorPass::get_hlvm_stream_read()
+{
+  if (!hlvm_stream_read) {
+    llvm::Type* result = get_hlvm_size();
+    std::vector<const llvm::Type*> arg_types;
+    arg_types.push_back(get_hlvm_stream());
+    arg_types.push_back(get_hlvm_buffer());
+    arg_types.push_back(get_hlvm_size());
+    llvm::FunctionType* FT = llvm::FunctionType::get(result,arg_types,false);
+    lmod->addTypeName("hlvm_stream_read_signature",FT);
+    hlvm_stream_read = 
+      new llvm::Function(FT, llvm::GlobalValue::ExternalLinkage,
+      "hlvm_stream_read", lmod);
+  }
+  return hlvm_stream_read;
+}
+
+llvm::Function*
+LLVMGeneratorPass::get_hlvm_stream_write_buffer()
+{
+  if (!hlvm_stream_write_buffer) {
+    llvm::Type* result = get_hlvm_size();
+    std::vector<const llvm::Type*> arg_types;
+    arg_types.push_back(get_hlvm_stream());
+    arg_types.push_back(get_hlvm_buffer());
+    llvm::FunctionType* FT = llvm::FunctionType::get(result,arg_types,false);
+    lmod->addTypeName("hlvm_stream_write_buffer_signature",FT);
+    hlvm_stream_write_buffer = 
+      new llvm::Function(FT, llvm::GlobalValue::ExternalLinkage,
+      "hlvm_stream_write_buffer", lmod);
+  }
+  return hlvm_stream_write_buffer;
+}
+
+llvm::Function*
+LLVMGeneratorPass::get_hlvm_stream_write_text()
+{
+  if (!hlvm_stream_write_text) {
+    llvm::Type* result = get_hlvm_size();
+    std::vector<const llvm::Type*> arg_types;
+    arg_types.push_back(get_hlvm_stream());
+    arg_types.push_back(get_hlvm_text());
+    llvm::FunctionType* FT = llvm::FunctionType::get(result,arg_types,false);
+    lmod->addTypeName("hlvm_stream_write_text_signature",FT);
+    hlvm_stream_write_text = 
+      new llvm::Function(FT, llvm::GlobalValue::ExternalLinkage,
+      "hlvm_stream_write_text", lmod);
+  }
+  return hlvm_stream_write_text;
+}
+
+llvm::Function*
+LLVMGeneratorPass::get_hlvm_stream_close()
+{
+  if (!hlvm_stream_close) {
+    llvm::Type* result = llvm::Type::VoidTy;
+    std::vector<const llvm::Type*> arg_types;
+    arg_types.push_back(get_hlvm_stream());
+    llvm::FunctionType* FT = llvm::FunctionType::get(result,arg_types,false);
+    lmod->addTypeName("hlvm_stream_close_signature",FT);
+    hlvm_stream_close = 
+      new llvm::Function(FT, llvm::GlobalValue::ExternalLinkage,
+      "hlvm_stream_close", lmod);
+  }
+  return hlvm_stream_close;
+}
+
+llvm::FunctionType*
+LLVMGeneratorPass::get_hlvm_program_signature()
+{
+  if (!hlvm_program_signature) {
+    // Get the type of function that all entry points must have
+    std::vector<const llvm::Type*> arg_types;
+    arg_types.push_back(llvm::Type::IntTy);
+    arg_types.push_back(
+      llvm::PointerType::get(llvm::PointerType::get(llvm::Type::SByteTy)));
+    hlvm_program_signature = 
+      llvm::FunctionType::get(llvm::Type::IntTy,arg_types,false);
+    lmod->addTypeName("hlvm_program_signature",hlvm_program_signature);
+  }
+  return hlvm_program_signature;
+}
+
 const llvm::Type*
 LLVMGeneratorPass::getType(const hlvm::Type* ty)
 {
@@ -122,26 +392,26 @@
 
   // Okay, we haven't seen this type before so let's construct it
   switch (ty->getID()) {
-    case VoidTypeID: result = llvm::Type::VoidTy; break;
-    case BooleanTypeID: result = llvm::Type::BoolTy; break;
-    case CharacterTypeID: result = llvm::Type::UShortTy; break;
-    case OctetTypeID: result = llvm::Type::UByteTy; 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 VoidTypeID:               result = llvm::Type::VoidTy; break;
+    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 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::FloatTy; break;
+    case Float32TypeID:             result = llvm::Type::FloatTy; break;
+    case Float64TypeID:             result = llvm::Type::DoubleTy; break;
     case Float44TypeID: 
     case Float80TypeID: 
     case Float128TypeID: 
@@ -155,20 +425,29 @@
       break;
     case RealTypeID:
       hlvmNotImplemented("arbitrary precision real");
-    case TextTypeID: {
-      std::vector<const llvm::Type*> Fields;
-      Fields.push_back(llvm::Type::UIntTy);
-      Fields.push_back(llvm::PointerType::get(llvm::Type::UShortTy));
-      result = llvm::StructType::get(Fields);
+    case TextTypeID:
+      result = get_hlvm_text();
       break;
-    }
-    case AliasTypeID: {
-      result = getType(llvm::cast<AliasType>(ty)->getType());
+    case StreamTypeID: 
+      result = get_hlvm_stream();
       break;
-    }
-    case PointerTypeID: {
-      result = llvm::PointerType::get(
-        getType(llvm::cast<hlvm::PointerType>(ty)->getTargetType()));
+    case BufferTypeID: 
+      result = get_hlvm_buffer();
+      break;
+    case AliasTypeID:
+      result = getType(llvm::cast<AliasType>(ty)->getElementType());
+      break;
+    case PointerTypeID: 
+    {
+      hlvm::Type* hElemType = 
+        llvm::cast<hlvm::PointerType>(ty)->getElementType();
+      const llvm::Type* lElemType = getType(hElemType);
+      result = llvm::PointerType::get(lElemType);
+
+      // If the element type is opaque then we need to add a type name for this
+      // pointer type because all opaques are unique unless named similarly.
+      if (llvm::isa<llvm::OpaqueType>(lElemType))
+        lmod->addTypeName(ty->getName(), result);
       break;
     }
     case VectorTypeID: {
@@ -191,7 +470,7 @@
       std::vector<const llvm::Type*> Fields;
       for (StructureType::const_iterator I = ST->begin(), E = ST->end(); 
            I != E; ++I)
-        Fields.push_back(getType((*I)->getType()));
+        Fields.push_back(getType((*I)->getElementType()));
       result = llvm::StructType::get(Fields);
       break;
     }
@@ -224,68 +503,54 @@
 {
   if (C == 0)
     return 0;
+
+  // First, lets see if its cached already
+  ConstantDictionary::iterator I = consts.find(const_cast<hlvm::Constant*>(C));
+  if (I != consts.end())
+    return I->second;
+
   const hlvm::Type* hType = C->getType();
   const llvm::Type* lType = getType(hType);
+  llvm::Constant* result = 0;
   switch (C->getID()) 
   {
     case ConstantIntegerID:
     {
       const ConstantInteger* CI = llvm::cast<const ConstantInteger>(C);
       if (llvm::cast<IntegerType>(hType)->isSigned())
-        return llvm::ConstantSInt::get(lType,CI->getValue());
+        result = llvm::ConstantSInt::get(lType,CI->getValue());
       else
-         return llvm::ConstantUInt::get(lType,CI->getValue(0));
+        result = llvm::ConstantUInt::get(lType,CI->getValue(0));
+      break;
     }
     case ConstantRealID:
-      return llvm::ConstantFP::get(lType,
+    {
+      result = llvm::ConstantFP::get(lType,
         llvm::cast<ConstantReal>(C)->getValue());
+      break;
+    }
     case ConstantTextID:
-      return llvm::ConstantArray::get(
+    {
+      llvm::Constant* CA = llvm::ConstantArray::get(
         llvm::cast<ConstantText>(C)->getValue(),true);
+      llvm::GlobalVariable* GV = new llvm::GlobalVariable(
+        CA->getType(), true, llvm::GlobalValue::InternalLinkage, CA, "", lmod);
+      result = ConstantExpr::getPtrPtrFromArrayPtr(GV);
+      break;
+    }
     case ConstantZeroID:
     {
-      switch (lType->getTypeID()) {
-        case llvm::Type::VoidTyID:
-          hlvmDeadCode("Can't get constant for void type");
-          break;
-        case llvm::Type::BoolTyID:
-          return llvm::ConstantBool::get(false);
-          break;
-        case llvm::Type::UByteTyID:
-        case llvm::Type::SByteTyID:
-        case llvm::Type::UShortTyID:
-        case llvm::Type::ShortTyID:
-        case llvm::Type::UIntTyID:
-        case llvm::Type::IntTyID:
-        case llvm::Type::ULongTyID:
-        case llvm::Type::LongTyID:
-          return llvm::ConstantInt::get(lType,0);
-          break;
-        case llvm::Type::FloatTyID:
-        case llvm::Type::DoubleTyID:
-          return llvm::ConstantFP::get(lType,0.0);
-          break;
-        case llvm::Type::LabelTyID:
-          hlvmDeadCode("Can't get constant for label type");
-          break;
-        case llvm::Type::FunctionTyID:
-        case llvm::Type::StructTyID:
-        case llvm::Type::ArrayTyID:
-        case llvm::Type::PointerTyID:
-        case llvm::Type::OpaqueTyID:
-        case llvm::Type::PackedTyID:
-          return llvm::ConstantAggregateZero::get(lType);
-        default:
-          hlvmDeadCode("Invalid LLVM Type ID");
-          break;
-      }
+      result = llvm::Constant::getNullValue(lType);
       break;
     }
     default:
       break;
   }
-  hlvmDeadCode("Can't decipher constant");
-  return 0;
+  if (result)
+    consts[const_cast<hlvm::Constant*>(C)] = result;
+  else
+    hlvmDeadCode("Didn't find constant");
+  return result;
 }
 
 llvm::Value*
@@ -295,20 +560,6 @@
   return 0;
 }
 
-const llvm::FunctionType*
-LLVMGeneratorPass::getProgramFT()
-{
-  if (!entry_FT) {
-    // Get the type of function that all entry points must have
-    std::vector<const llvm::Type*> arg_types;
-    arg_types.push_back(llvm::Type::IntTy);
-    arg_types.push_back(
-      llvm::PointerType::get(llvm::PointerType::get(llvm::Type::SByteTy)));
-    entry_FT = llvm::FunctionType::get(llvm::Type::IntTy,arg_types,false);
-    lmod->addTypeName("hlvm_program_signature",entry_FT);
-  }
-  return entry_FT;
-}
 
 llvm::GlobalValue::LinkageTypes
 LLVMGeneratorPass::getLinkageTypes(LinkageKinds lk)
@@ -328,7 +579,7 @@
 template<> void 
 LLVMGeneratorPass::gen<AliasType>(AliasType* t)
 {
-  lmod->addTypeName(t->getName(), getType(t->getType()));
+  lmod->addTypeName(t->getName(), getType(t->getElementType()));
 }
 
 template<> void 
@@ -429,38 +680,89 @@
 }
 
 template<> void
+LLVMGeneratorPass::gen<ConstantReal>(ConstantReal* r)
+{
+  llvm::Constant* C = getConstant(r);
+  lops.push_back(C);
+}
+
+template<> void
+LLVMGeneratorPass::gen<ConstantZero>(ConstantZero* z)
+{
+  llvm::Constant* C = getConstant(z);
+  lops.push_back(C);
+}
+
+template<> void
 LLVMGeneratorPass::gen<ConstantText>(ConstantText* t)
 {
   llvm::Constant* C = getConstant(t);
-  lops.push_back(C);
+  std::vector<llvm::Value*> args;
+  args.push_back(C);
+  llvm::CallInst* CI = new CallInst(get_hlvm_text_create(),args,"",lblk);
+  lops.push_back(CI);
 }
 
 template<> void
-LLVMGeneratorPass::gen<Variable>(Variable* v)
+LLVMGeneratorPass::gen<AutoVarOp>(AutoVarOp* av)
 {
-  if (v->isLocal()) {
-    assert(lblk  != 0 && "Not in block context");
-    // emit a stack variable
-    const llvm::Type* elemType = getType(v->getType());
-    lops.push_back(
-      new llvm::AllocaInst(
-        /*Ty=*/ elemType,
-        /*ArraySize=*/ llvm::ConstantUInt::get(llvm::Type::UIntTy,1),
-        /*Name=*/ v->getName(),
-        /*InsertAtEnd=*/ lblk
-      )
-    );
-    // FIXME: Handle initializer
-  } else {
-    llvm::Constant* Initializer = getConstant(v->getInitializer());
-    new llvm::GlobalVariable(
-      /*Ty=*/ getType(v->getType()),
-      /*isConstant=*/ false,
-      /*Linkage=*/ llvm::GlobalValue::ExternalLinkage,
-      /*Initializer=*/ Initializer,
-      /*Name=*/ getLinkageName(v),
-      /*Parent=*/ lmod);
+  assert(lblk  != 0 && "Not in block context");
+  // emit a stack variable
+  const llvm::Type* elemType = getType(av->getType());
+  llvm::Value* init = lops.back(); lops.pop_back();
+  llvm::Value* alloca = new llvm::AllocaInst(
+      /*Ty=*/ elemType,
+      /*ArraySize=*/ llvm::ConstantUInt::get(llvm::Type::UIntTy,1),
+      /*Name=*/ av->getName(),
+      /*InsertAtEnd=*/ lblk
+  );
+  // FIXME: Handle initializer
+  llvm::Constant* C = getConstant(av->getInitializer());
+  if (C) {
+    const llvm::Type* CType = C->getType();
+    if (CType != elemType) {
+      if (llvm::isa<llvm::PointerType>(CType) && 
+          llvm::isa<llvm::PointerType>(elemType)) {
+        const llvm::Type* CElemType = 
+          llvm::cast<llvm::PointerType>(CType)->getElementType();
+        const llvm::Type* avElemType = 
+            llvm::cast<llvm::PointerType>(elemType)->getElementType();
+        if (CElemType != avElemType)
+        {
+          // We have pointers to different element types. This *can* be okay if
+          // we apply conversions.
+          if (CElemType == llvm::Type::SByteTy) {
+            // The initializer is an sbyte*, which we can conver to either a
+            // hlvm_text or an hlvm_buffer.
+            if (elemType = get_hlvm_buffer()) {
+              // Assign the constant string to the buffer
+            } else if (elemType == get_hlvm_text()) {
+            }
+          }
+        }
+      }
+      hlvmAssert(CType->isLosslesslyConvertibleTo(elemType));
+      C = ConstantExpr::getCast(C,elemType);
+    }
+    llvm::Value* store = new llvm::StoreInst(C,alloca,"",lblk);
   }
+  lops.push_back(alloca);
+  lvars[av] = alloca;
+}
+
+template<> void
+LLVMGeneratorPass::gen<Variable>(Variable* v)
+{
+  llvm::Constant* Initializer = getConstant(v->getInitializer());
+  llvm::Value* gv = new llvm::GlobalVariable(
+    /*Ty=*/ getType(v->getType()),
+    /*isConstant=*/ false,
+    /*Linkage=*/ llvm::GlobalValue::ExternalLinkage,
+    /*Initializer=*/ Initializer,
+    /*Name=*/ getLinkageName(v),
+    /*Parent=*/ lmod
+  );
+  gvars[v] = gv;
 }
 
 template<> void 
@@ -486,15 +788,15 @@
 LLVMGeneratorPass::gen<StoreOp>(StoreOp* s)
 {
   hlvmAssert(lops.size() >= 2 && "Too few operands for StoreOp");
-  llvm::Value* value = lops.back(); lops.pop_back();
+  llvm::Value* value =    lops.back(); lops.pop_back();
   llvm::Value* location = lops.back(); lops.pop_back();
-  lops.push_back(new StoreInst(location,value,lblk));
+  lops.push_back(new StoreInst(value,location,lblk));
 }
 
 template<> void
 LLVMGeneratorPass::gen<LoadOp>(LoadOp* s)
 {
-  hlvmAssert(lops.size() >= 1 && "Wrong number of ops for LoadOp");
+  hlvmAssert(lops.size() >= 1 && "Too few operands for LoadOp");
   llvm::Value* location = lops.back(); lops.pop_back();
   lops.push_back(new LoadInst(location,"",lblk));
 }
@@ -502,40 +804,75 @@
 template<> void
 LLVMGeneratorPass::gen<ReferenceOp>(ReferenceOp* r)
 {
-  hlvmAssert(lops.size() >= 0 && "Wrong number of ops for ReferenceOp");
-  llvm::Value* v = getVariable(r->getReferent());
+  hlvm::Value* referent = r->getReferent();
+  llvm::Value* v = 0;
+  if (isa<Variable>(referent)) {
+    VariableDictionary::iterator I = gvars.find(cast<Variable>(referent));
+    hlvmAssert(I != gvars.end());
+    v = I->second;
+  } 
+  else if (isa<AutoVarOp>(referent)) 
+  {
+    AutoVarDictionary::const_iterator I = lvars.find(cast<AutoVarOp>(referent));
+    hlvmAssert(I != lvars.end());
+    v = I->second;
+  }
+  else
+    hlvmDeadCode("Referent not a variable");
   lops.push_back(v);
 }
 
 template<> void
 LLVMGeneratorPass::gen<IndexOp>(IndexOp* r)
 {
-  hlvmAssert(lops.size() >= 1 && "Wrong number of ops for IndexOp");
+  hlvmAssert(lops.size() >= 2 && "Too few operands for IndexOp");
 }
 
 template<> void
 LLVMGeneratorPass::gen<OpenOp>(OpenOp* o)
 {
-  hlvmAssert(lops.size() >= 1 && "Wrong number of ops for StoreOp");
-  llvm::Value* uri = lops.back(); lops.pop_back();
+  hlvmAssert(lops.size() >= 1 && "Too few operands for OpenOp");
+  std::vector<llvm::Value*> args;
+  args.push_back(lops.back()); lops.pop_back();
+  llvm::CallInst* ci = new CallInst(get_hlvm_stream_open(), args, "", lblk);
+  lops.push_back(ci);
 }
 
 template<> void
 LLVMGeneratorPass::gen<WriteOp>(WriteOp* o)
 {
-  hlvmAssert(lops.size() >= 3 && "Wrong number of ops for StoreOp");
-  llvm::Value* length = lops.back(); lops.pop_back();
-  llvm::Value* buffer = lops.back(); lops.pop_back();
-  llvm::Value* stream = lops.back(); lops.pop_back();
+  hlvmAssert(lops.size() >= 2 && "Too few operands for WriteOp");
+  std::vector<llvm::Value*> args;
+  llvm::Value* arg2 = lops.back(); lops.pop_back();
+  llvm::Value* strm = lops.back(); lops.pop_back();
+  args.push_back(strm);
+  args.push_back(arg2);
+  if (arg2->getType() == get_hlvm_text())
+    lops.push_back(new CallInst(get_hlvm_stream_write_text(), args, "", lblk));
+  else
+    lops.push_back(new CallInst(get_hlvm_stream_write_buffer(), args, "",lblk));
 }
 
 template<> void
-LLVMGeneratorPass::gen<CloseOp>(CloseOp* o)
+LLVMGeneratorPass::gen<ReadOp>(ReadOp* o)
 {
-  hlvmAssert(lops.size() >= 1 && "Wrong number of ops for StoreOp");
-  llvm::Value* stream = lops.back(); lops.pop_back();
+  hlvmAssert(lops.size() >= 3 && "Too few operands for ReadOp");
+  std::vector<llvm::Value*> args;
+  args.insert(args.end(),lops.end()-3,lops.end());
+  lops.erase(lops.end()-3,lops.end());
+  llvm::CallInst* ci = new CallInst(get_hlvm_stream_read(), args, "", lblk);
+  lops.push_back(ci);
 }
 
+template<> void
+LLVMGeneratorPass::gen<CloseOp>(CloseOp* o)
+{
+  hlvmAssert(lops.size() >= 1 && "Too few operands for CloseOp");
+  std::vector<llvm::Value*> args;
+  args.push_back(lops.back()); lops.pop_back();
+  llvm::CallInst* ci = new CallInst(get_hlvm_stream_close(), args, "", lblk);
+  lops.push_back(ci);
+}
 
 template<> void
 LLVMGeneratorPass::gen<hlvm::Function>(hlvm::Function* f)
@@ -544,6 +881,7 @@
     llvm::cast<llvm::FunctionType>(getType(f->getSignature())),
     getLinkageTypes(f->getLinkageKind()), 
     getLinkageName(f), lmod);
+  lvars.clear();
 }
 
 template<> void
@@ -552,12 +890,10 @@
   // points after the entire parse is completed.
   std::string linkageName = getLinkageName(p);
 
-  // Get the FunctionType for entry points (programs)
-  const llvm::FunctionType* entry_signature = getProgramFT();
-
   // Create a new function for the program based on the signature
-  lfunc = new llvm::Function(entry_signature,
+  lfunc = new llvm::Function(get_hlvm_program_signature(),
     llvm::GlobalValue::InternalLinkage,linkageName,lmod);
+  lvars.clear();
 
   // Save the program so it can be generated into the list of program entry
   progs.push_back(lfunc);
@@ -568,11 +904,14 @@
 {
   lmod = new llvm::Module(b->getName());
   modules.push_back(lmod);
+  lvars.clear();
+  gvars.clear();
 }
 
 void
 LLVMGeneratorPass::handleInitialize()
 {
+  // Nothing to do
 }
 
 void
@@ -610,22 +949,30 @@
     case StructureTypeID:         gen(llvm::cast<StructureType>(n)); break;
     case SignatureTypeID:         gen(llvm::cast<SignatureType>(n)); break;
     case OpaqueTypeID:            gen(llvm::cast<hlvm::OpaqueType>(n)); break;
+    case ConstantZeroID:          gen(llvm::cast<ConstantZero>(n));break;
     case ConstantIntegerID:       gen(llvm::cast<ConstantInteger>(n));break;
+    case ConstantRealID:          gen(llvm::cast<ConstantReal>(n));break;
     case ConstantTextID:          gen(llvm::cast<ConstantText>(n));break;
     case VariableID:              gen(llvm::cast<Variable>(n)); break;
     case ReturnOpID:              gen(llvm::cast<ReturnOp>(n)); break;
     case LoadOpID:                gen(llvm::cast<LoadOp>(n)); break;
     case StoreOpID:               gen(llvm::cast<StoreOp>(n)); break;
     case ReferenceOpID:           gen(llvm::cast<ReferenceOp>(n)); break;
+    case AutoVarOpID:             gen(llvm::cast<AutoVarOp>(n)); break;
     case OpenOpID:                gen(llvm::cast<OpenOp>(n)); break;
     case CloseOpID:               gen(llvm::cast<CloseOp>(n)); break;
     case WriteOpID:               gen(llvm::cast<WriteOp>(n)); break;
+    case ReadOpID:                gen(llvm::cast<ReadOp>(n)); break;
 
     // ignore end of block, program, function and bundle
     case BundleID:
+      break;
     case ProgramID:
     case FunctionID:
+      lfunc = 0;
+      break;
     case BlockID:
+      lblk = 0;
       break;
 
     // everything else is an error
@@ -639,18 +986,20 @@
 void
 LLVMGeneratorPass::handleTerminate()
 {
-  // Get the type of function that all entry points must have
-  const llvm::FunctionType* entry_signature = getProgramFT();
+  // Short circuit if there's nothing to do
+  if (progs.empty())
+    return;
 
   // Define the type of the array elements (a structure with a pointer to
   // a string and a pointer to the function).
   std::vector<const llvm::Type*> Fields;
   Fields.push_back(llvm::PointerType::get(llvm::Type::SByteTy));
-  Fields.push_back(llvm::PointerType::get(entry_signature));
+  Fields.push_back(llvm::PointerType::get(get_hlvm_program_signature()));
   llvm::StructType* entry_elem_type = llvm::StructType::get(Fields);
 
   // Define the type of the array for the entry points
-  llvm::ArrayType* entry_points_type = llvm::ArrayType::get(entry_elem_type,1);
+  llvm::ArrayType* entry_points_type = 
+    llvm::ArrayType::get(entry_elem_type,progs.size());
 
   // Create a vector to hold the entry elements as they are created.
   std::vector<llvm::Constant*> entry_points_items;
@@ -660,11 +1009,11 @@
   {
     const std::string& funcName = (*I)->getName();
     // Get a constant for the name of the entry point (char array)
-    llvm::Constant* name_val = llvm::ConstantArray::get(funcName,false);
+    llvm::Constant* name_val = llvm::ConstantArray::get(funcName,true);
 
     // Create a constant global variable to hold the name of the program.
     llvm::GlobalVariable* name = new llvm::GlobalVariable(
-      /*Type=*/llvm::ArrayType::get(llvm::Type::SByteTy, funcName.length()),
+      /*Type=*/name_val->getType(),
       /*isConst=*/true,
       /*Linkage=*/llvm::GlobalValue::InternalLinkage, 
       /*Initializer=*/name_val, 
@@ -672,11 +1021,7 @@
       /*InsertInto=*/lmod
     );
 
-    // Get the GEP for indexing in to the name string
-    std::vector<llvm::Constant*> Indices;
-    Indices.push_back(llvm::Constant::getNullValue(llvm::Type::IntTy));
-    Indices.push_back(llvm::Constant::getNullValue(llvm::Type::IntTy));
-    llvm::Constant* index = llvm::ConstantExpr::getGetElementPtr(name,Indices);
+    llvm::Constant* index = llvm::ConstantExpr::getPtrPtrFromArrayPtr(name);
 
     // Get a constant structure for the entry containing the name and pointer
     // to the function.
@@ -685,7 +1030,7 @@
     items.push_back(*I);
     llvm::Constant* entry = llvm::ConstantStruct::get(entry_elem_type,items);
 
-    // Save the entry into the list of entry_point items
+    // Save the entry into the list of entry point items
     entry_points_items.push_back(entry);
   }
 
@@ -719,20 +1064,21 @@
 }
 
 void
-hlvm::generateBytecode(AST* tree,std::ostream& output)
+hlvm::generateBytecode(AST* tree, std::ostream& output, bool verify)
 {
   hlvm::PassManager* PM = hlvm::PassManager::create();
   LLVMGeneratorPass genPass(tree);
   PM->addPass(&genPass);
   PM->runOn(tree);
   llvm::Module* mod = genPass.linkModules();
+  llvm::verifyModule(*mod, llvm::PrintMessageAction);
   llvm::WriteBytecodeToFile(mod, output, /*compress= */ true);
   delete mod;
   delete PM;
 }
 
 void
-hlvm::generateAssembly(AST* tree, std::ostream& output)
+hlvm::generateAssembly(AST* tree, std::ostream& output, bool verify)
 {
   hlvm::PassManager* PM = hlvm::PassManager::create();
   LLVMGeneratorPass genPass(tree);

Modified: hlvm/trunk/hlvm/CodeGen/LLVMGenerator.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/CodeGen/LLVMGenerator.h?rev=38179&r1=38178&r2=38179&view=diff

==============================================================================
--- hlvm/trunk/hlvm/CodeGen/LLVMGenerator.h (original)
+++ hlvm/trunk/hlvm/CodeGen/LLVMGenerator.h Sat Jul  7 19:00:47 2007
@@ -38,11 +38,11 @@
 
   /// Convert an Abstract Syntax Tree into LLVM bytecode written on the output 
   /// stream.
-  void generateBytecode(AST* input, std::ostream& output);
+  void generateBytecode(AST* input, std::ostream& output, bool verify = true);
 
   /// Convert an Abstract Syntax Tree into LLVM assembly written on the output
   /// stream.
-  void generateAssembly(AST* input, std::ostream& output);
+  void generateAssembly(AST* input, std::ostream& output, bool verify = true);
 
 } // hlvm
 #endif

Modified: hlvm/trunk/hlvm/CodeGen/SConscript
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/CodeGen/SConscript?rev=38179&r1=38178&r2=38179&view=diff

==============================================================================
--- hlvm/trunk/hlvm/CodeGen/SConscript (original)
+++ hlvm/trunk/hlvm/CodeGen/SConscript Sat Jul  7 19:00:47 2007
@@ -29,5 +29,6 @@
   LLVM2CPPFLAGS='-gen-inline -for _hlvm_string_clear -funcname getStringClear')
 env.Cpp2LLVMCpp('program.inc','program.cxx',
   LLVM2CPPFLAGS='-gen-contents -funcname "getProgramDef"')
+env.Cpp2LLVMCpp('tryit.inc','tryit.cxx')
 lib = env.Library('HLVMCodeGen',hlvm.GetAllCXXFiles(env))
 hlvm.InstallLibrary(env,lib)

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

==============================================================================
--- hlvm/trunk/hlvm/Pass/Pass.cpp (original)
+++ hlvm/trunk/hlvm/Pass/Pass.cpp Sat Jul  7 19:00:47 2007
@@ -79,10 +79,10 @@
   if (interest == 0 ||
      ((interest & Pass::Type_Interest) && n->isType()) ||
      ((interest & Pass::Function_Interest) && n->isFunction()) ||
-     ((interest & Pass::Block_Interest) && n->isBlock()) ||
+     ((interest & Pass::Block_Interest) && n->is(BlockID)) ||
      ((interest & Pass::Operator_Interest) && n->isOperator()) ||
-     ((interest & Pass::Program_Interest) && n->isProgram()) ||
-     ((interest & Pass::Variable_Interest) && n->isVariable())
+     ((interest & Pass::Program_Interest) && n->is(ProgramID)) ||
+     ((interest & Pass::Variable_Interest) && n->is(VariableID))
      ) {
     p->handle(n,m);
   }
@@ -165,19 +165,19 @@
   runPreOrder(b);
   for (Bundle::type_iterator TI =b->type_begin(), TE = b->type_end(); 
        TI != TE; ++TI) {
-    runPreOrder(*TI);
-    runPostOrder(*TI);
+    runPreOrder(const_cast<Node*>(TI->second));
+    runPostOrder(const_cast<Node*>(TI->second));
   }
   for (Bundle::var_iterator VI = b->var_begin(), VE = b->var_end(); 
        VI != VE; ++VI) {
-    runPreOrder(*VI);
-    runPostOrder(*VI);
+    runPreOrder(const_cast<Node*>(VI->second));
+    runPostOrder(const_cast<Node*>(VI->second));
   }
   for (Bundle::func_iterator FI = b->func_begin(), FE = b->func_end(); 
        FI != FE; ++FI) {
-    runPreOrder(*FI);
-    runOn((*FI)->getBlock());
-    runPostOrder(*FI);
+    runPreOrder(const_cast<Node*>(FI->second));
+    runOn(llvm::cast<Function>(FI->second)->getBlock());
+    runPostOrder(const_cast<Node*>(FI->second));
   }
   runPostOrder(b);
 }

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

==============================================================================
--- hlvm/trunk/hlvm/Pass/Validate.cpp (original)
+++ hlvm/trunk/hlvm/Pass/Validate.cpp Sat Jul  7 19:00:47 2007
@@ -232,15 +232,12 @@
     case IfOpID:
     case LoopOpID:
     case SelectOpID:
-    case WithOpID:
     case LoadOpID:
     case StoreOpID:
     case AllocateOpID:
     case FreeOpID:
     case ReallocateOpID:
-    case StackAllocOpID:
     case ReferenceOpID:
-    case DereferenceOpID:
     case NegateOpID:
     case ComplementOpID:
     case PreIncrOpID:
@@ -269,6 +266,7 @@
     case IsPInfOpID:
     case IsNInfOpID:
     case IsNaNOpID:
+    case AutoVarOpID:
     case TruncOpID:
     case RoundOpID:
     case FloorOpID:
@@ -294,6 +292,7 @@
     case ConstantIntegerID:
     case ConstantRealID:
     case ConstantTextID:
+    case ConstantZeroID:
       break; // Not implemented yet
     case DocumentationID:
       /// Nothing to validate (any doc is a good thing :)

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

==============================================================================
--- hlvm/trunk/hlvm/Reader/XML/HLVM.rng (original)
+++ hlvm/trunk/hlvm/Reader/XML/HLVM.rng Sat Jul  7 19:00:47 2007
@@ -268,6 +268,7 @@
     <choice>
       <value>any</value>
       <value>bool</value>
+      <value>buffer</value>
       <value>char</value>
       <value>f32</value>
       <value>f44</value>
@@ -280,6 +281,7 @@
       <value>s32</value>
       <value>s64</value>
       <value>s128</value>
+      <value>stream</value>
       <value>text</value>
       <value>u8</value>
       <value>u16</value>
@@ -430,7 +432,6 @@
   <define name="Block.pat">
     <oneOrMore>
       <choice>
-        <ref name="variable.elem"/>
         <ref name="Operators.pat"/>
         <ref name="block.elem"/>
       </choice>
@@ -454,7 +455,7 @@
       <!-- 
       FIXME: This is hacked out right now because it causes infinite recursion
       in libxml2 function xmlRelaxNGGetElements. Debugging it didn't help me
-      find out whey.
+      find out why.
       <ref name="ConstantExpression.pat"/>
       -->
     </choice>
@@ -693,7 +694,7 @@
 
   <define name="Operators.pat">
     <choice>
-      <ref name="var.elem"/>
+      <ref name="autovar.elem"/>
       <ref name="ComparisonOperators.pat"/>
       <ref name="UnaryArithmeticOperators.pat"/>
       <ref name="BinaryArithmeticOperators.pat"/>
@@ -733,9 +734,15 @@
     <empty/>
   </define>
 
-  <define name="var.elem">
-    <element name="var">
+  <define name="autovar.elem">
+    <element name="autovar">
       <ref name="Named_Typed_Element.pat"/>
+      <choice>
+        <ref name="Constant.pat"/>
+        <element name="zero">
+          <empty/>
+        </element>
+      </choice>
     </element>
   </define>
 
@@ -811,6 +818,13 @@
       <ref name="Documentation.pat"/>
       <ref name="Value.pat"/>
       <ref name="Value.pat"/>
+    </element>
+  </define>
+
+  <define name="read.elem">
+    <element name="read">
+      <ref name="Documentation.pat"/>
+      <ref name="Value.pat"/>
       <ref name="Value.pat"/>
     </element>
   </define>

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

==============================================================================
--- hlvm/trunk/hlvm/Reader/XML/XMLReader.cpp (original)
+++ hlvm/trunk/hlvm/Reader/XML/XMLReader.cpp Sat Jul  7 19:00:47 2007
@@ -65,9 +65,12 @@
   xmlDocPtr doc;
   Locator* loc;
   URI* uri;
+  Block* block;
+  Function* func;
+  Bundle* bundle;
 public:
   XMLReaderImpl(const std::string& p)
-    : path(p), ast(0), loc(0)
+    : path(p), ast(0), loc(0), uri(0), block(0), func(0), bundle(0)
   {
     ast = AST::create();
     ast->setSystemID(p);
@@ -111,33 +114,24 @@
   inline ConstantReal*    parseFloat(xmlNodePtr& cur);
   inline ConstantReal*    parseDouble(xmlNodePtr& cur);
   inline ConstantText*    parseText(xmlNodePtr& cur);
+  inline ConstantZero*    parseZero(xmlNodePtr& cur,const Type* Ty);
+
+  inline xmlNodePtr   checkDoc(xmlNodePtr cur, Documentable* node);
+  inline Value*  getValue(xmlNodePtr&);
+
   void           parseTree          ();
-  AliasType*     parseAlias         (xmlNodePtr& cur);
-  Type*          parseArray         (xmlNodePtr& cur);
+
   Type*          parseAtom          (xmlNodePtr& cur);
-  Bundle*        parseBundle        (xmlNodePtr& cur);
-  Documentation* parseDocumentation (xmlNodePtr& cur);
-  Type*          parseEnumeration   (xmlNodePtr& cur);
-  Function*      parseFunction      (xmlNodePtr& cur);
-  Import*        parseImport        (xmlNodePtr& cur);
-  Type*          parsePointer       (xmlNodePtr& cur);
-  Type*          parseStructure     (xmlNodePtr& cur);
-  Type*          parseSignature     (xmlNodePtr& cur);
-  Type*          parseOpaque        (xmlNodePtr& cur);
-  Variable*      parseVariable      (xmlNodePtr& cur);
-  Type*          parseVector        (xmlNodePtr& cur);
-  Constant*      parseConstant      (xmlNodePtr& cur);
-  Constant*      parseConstant      (xmlNodePtr& cur, int token);
+  Constant*      parseConstant      (xmlNodePtr& cur, const Type* Ty);
+  Constant*      parseConstant      (xmlNodePtr& cur, const Type* Ty, int tkn);
   Operator*      parseOperator      (xmlNodePtr& cur);
   Operator*      parseOperator      (xmlNodePtr& cur, int token);
   Value*         parseValue         (xmlNodePtr& cur);
   Value*         parseValue         (xmlNodePtr& cur, int token);
-  ReturnOp*      parseReturn        (xmlNodePtr& cur);
-  Block*         parseBlock         (xmlNodePtr& cur);
-  ReferenceOp*   parseReference     (xmlNodePtr& cur);
-  Program*       parseProgram       (xmlNodePtr& cur);
-  inline xmlNodePtr   checkDoc(xmlNodePtr cur, Documentable* node);
-  inline Value*  getValue(xmlNodePtr&);
+
+  template<class OpClass>
+  OpClass*       parse(xmlNodePtr& cur);
+
   template<class OpClass>
   OpClass* parseNilaryOp(xmlNodePtr& cur);
   template<class OpClass>
@@ -265,6 +259,79 @@
   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_text:   result = ast->getPrimitiveType(TextTypeID); 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;
+    case TKN_void:   result = ast->getPrimitiveType(VoidTypeID); 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_text:    result = ast->new_TextType(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;
+    case TKN_void:    result = ast->new_VoidType(name,loc); break;
+    default: break;
+  }
+  return result;
+}
+
 inline const char* 
 getAttribute(xmlNodePtr cur,const char*name,bool required = true)
 {
@@ -300,8 +367,9 @@
   }
   if (child) skipBlanks(child);
   hlvmAssert(!child && "Illegal chlldren of <bin> element");
-  ConstantInteger* result = ast->new_ConstantInteger(value,getLocator(cur));
-  result->setType(ast->getPrimitiveType(UInt64TypeID));
+  ConstantInteger* result = ast->new_ConstantInteger(value,
+      ast->getPrimitiveType(UInt64TypeID),
+      getLocator(cur));
   return result;
 }
 
@@ -316,14 +384,15 @@
     while (*p != 0) {
       value <<= 3;
       hlvmAssert(*p >= '0' || *p == '7');
-      value |= *p++ - '0';
+      value += *p++ - '0';
     }
     child = child->next;
   }
   if (child) skipBlanks(child);
   hlvmAssert(!child && "Illegal chlldren of <oct> element");
-  ConstantInteger* result = ast->new_ConstantInteger(value,getLocator(cur));
-  result->setType(ast->getPrimitiveType(UInt64TypeID));
+  ConstantInteger* result = ast->new_ConstantInteger(value,
+      ast->getPrimitiveType(UInt64TypeID),
+      getLocator(cur));
   return result;
 }
 
@@ -338,14 +407,15 @@
     while (*p != 0) {
       value *= 10;
       hlvmAssert(*p >= '0' || *p <= '9');
-      value |= *p++ - '0';
+      value += *p++ - '0';
     }
     child = child->next;
   }
   if (child) skipBlanks(child);
   hlvmAssert(!child && "Illegal chlldren of <dec> element");
-  ConstantInteger* result = ast->new_ConstantInteger(value,getLocator(cur));
-  result->setType(ast->getPrimitiveType(UInt64TypeID));
+  ConstantInteger* result = ast->new_ConstantInteger(value,
+      ast->getPrimitiveType(UInt64TypeID),
+      getLocator(cur));
   return result;
 }
 
@@ -361,21 +431,21 @@
       value <<= 4;
       switch (*p) {
         case '0': break;
-        case '1': value |= 1; break;
-        case '2': value |= 2; break;
-        case '3': value |= 3; break;
-        case '4': value |= 4; break;
-        case '5': value |= 5; break;
-        case '6': value |= 6; break;
-        case '7': value |= 7; break;
-        case '8': value |= 8; break;
-        case '9': value |= 9; break;
-        case 'a': case 'A': value |= 10; break;
-        case 'b': case 'B': value |= 11; break;
-        case 'c': case 'C': value |= 12; break;
-        case 'd': case 'D': value |= 13; break;
-        case 'e': case 'E': value |= 14; break;
-        case 'f': case 'F': value |= 15; break;
+        case '1': value += 1; break;
+        case '2': value += 2; break;
+        case '3': value += 3; break;
+        case '4': value += 4; break;
+        case '5': value += 5; break;
+        case '6': value += 6; break;
+        case '7': value += 7; break;
+        case '8': value += 8; break;
+        case '9': value += 9; break;
+        case 'a': case 'A': value += 10; break;
+        case 'b': case 'B': value += 11; break;
+        case 'c': case 'C': value += 12; break;
+        case 'd': case 'D': value += 13; break;
+        case 'e': case 'E': value += 14; break;
+        case 'f': case 'F': value += 15; break;
         default:
           hlvmAssert("Invalid hex digit");
           break;
@@ -386,8 +456,9 @@
   }
   if (child) skipBlanks(child);
   hlvmAssert(!child && "Illegal chlldren of <hex> element");
-  ConstantInteger* result = ast->new_ConstantInteger(value,getLocator(cur));
-  result->setType(ast->getPrimitiveType(UInt64TypeID));
+  ConstantInteger* result = ast->new_ConstantInteger(value,
+      ast->getPrimitiveType(UInt64TypeID),
+      getLocator(cur));
   return result;
 }
 
@@ -405,8 +476,8 @@
   if (child) skipBlanks(child);
   hlvmAssert(!child && "Illegal chlldren of <flt> element");
   value = atof(buffer.c_str());
-  ConstantReal* result = ast->new_ConstantReal(value,getLocator(cur));
-  result->setType(ast->getPrimitiveType(UInt64TypeID));
+  ConstantReal* result = ast->new_ConstantReal(value,
+    ast->getPrimitiveType(UInt64TypeID),getLocator(cur));
   return result;
 }
 
@@ -424,8 +495,8 @@
   if (child) skipBlanks(child);
   hlvmAssert(!child && "Illegal chlldren of <dbl> element");
   value = atof(buffer.c_str());
-  ConstantReal* result = ast->new_ConstantReal(value,getLocator(cur));
-  result->setType(ast->getPrimitiveType(UInt64TypeID));
+  ConstantReal* result = ast->new_ConstantReal(value,
+    ast->getPrimitiveType(UInt64TypeID), getLocator(cur));
   return result;
 }
 
@@ -436,7 +507,7 @@
   xmlNodePtr child = cur->children;
   if (child) skipBlanks(child,false);
   while (child && child->type == XML_TEXT_NODE) {
-    buffer += reinterpret_cast<const char*>(cur->content);
+    buffer += reinterpret_cast<const char*>(child->content);
     child = child->next;
   }
   if (child) skipBlanks(child);
@@ -444,8 +515,17 @@
   return ast->new_ConstantText(buffer,getLocator(cur));
 }
 
-Documentation*
-XMLReaderImpl::parseDocumentation(xmlNodePtr& cur)
+inline ConstantZero*
+XMLReaderImpl::parseZero(xmlNodePtr& cur, const Type* Ty)
+{
+  hlvmAssert(cur->children == 0);
+  if (Ty == 0)
+    Ty = ast->new_s32("zero",getLocator(cur));
+  return ast->new_ConstantZero(Ty,getLocator(cur));
+}
+
+template<> Documentation*
+XMLReaderImpl::parse<Documentation>(xmlNodePtr& cur)
 {
   // Documentation is always optional so don't error out if the
   // node is not a TKN_doc
@@ -470,7 +550,7 @@
 XMLReaderImpl::checkDoc(xmlNodePtr cur, Documentable* node)
 {
   xmlNodePtr child = cur->children;
-  Documentation* theDoc = parseDocumentation(child);
+  Documentation* theDoc = parse<Documentation>(child);
   if (theDoc) {
     node->setDoc(theDoc);
     return child->next;
@@ -481,25 +561,18 @@
 inline Value*
 XMLReaderImpl::getValue(xmlNodePtr& cur)
 {
-  if (cur && skipBlanks(cur) && cur->type == XML_ELEMENT_NODE)
-    return parseValue(cur);
+  if (cur && skipBlanks(cur) && cur->type == XML_ELEMENT_NODE) {
+    Value* result = parseValue(cur);
+    cur = cur->next;
+    return result;
+  }
   else
     hlvmDeadCode("Expecting a value");
   return 0;
 }
 
-Import*
-XMLReaderImpl::parseImport(xmlNodePtr& cur)
-{
-  hlvmAssert(getToken(cur->name)==TKN_import);
-  std::string pfx = getAttribute(cur,"prefix");
-  Import* imp = ast->new_Import(pfx,getLocator(cur));
-  checkDoc(cur,imp);
-  return imp;
-}
-
-AliasType*
-XMLReaderImpl::parseAlias(xmlNodePtr& cur)
+template<> AliasType*
+XMLReaderImpl::parse<AliasType>(xmlNodePtr& cur)
 {
   hlvmAssert(getToken(cur->name)==TKN_alias);
   std::string name = getAttribute(cur,"id");
@@ -510,108 +583,8 @@
   return alias;
 }
 
-Type*     
-XMLReaderImpl::parseAtom(xmlNodePtr& cur)
-{
-  hlvmAssert(getToken(cur->name)==TKN_atom);
-  Locator* loc = getLocator(cur);
-  std::string name = getAttribute(cur,"id");
-  xmlNodePtr child = cur->children;
-  Documentation* theDoc = parseDocumentation(child);
-  child = (theDoc==0 ? child : child->next );
-  Type* result = 0;
-  if (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE) {
-    int tkn = getToken(child->name);
-    switch (tkn) {
-      case TKN_intrinsic: {
-        const char* is = getAttribute(child,"is");
-        if (!is)
-          hlvmAssert(!"intrinsic element requires 'is' attribute");
-        int typeTkn = getToken(reinterpret_cast<const xmlChar*>(is));
-        switch (typeTkn) {
-          case TKN_any:  result=ast->new_AnyType(name,loc); break;
-          case TKN_bool: result=ast->new_BooleanType(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_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;
-          case TKN_void: result=ast->new_VoidType(name,loc); break;
-          default:
-            hlvmDeadCode("Invalid intrinsic kind");
-        }
-        break;
-      }
-      case TKN_signed: {
-        const char* bits = getAttribute(child,"bits");
-        if (bits) {
-          uint64_t numBits = recognize_nonNegativeInteger(bits);
-          result = ast->new_IntegerType(name,numBits,/*signed=*/true,loc);
-          break;
-        }
-        hlvmAssert(!"Missing 'bits' attribute");
-        break;
-      }
-      case TKN_unsigned: {
-        const char* bits = getAttribute(child,"bits");
-        if (bits) {
-          uint64_t numBits = recognize_nonNegativeInteger(bits);
-          result = ast->new_IntegerType(name,numBits,/*signed=*/false,loc);
-          break;
-        }
-        hlvmAssert(!"Missing 'bits' attribute");
-        break;
-      }      
-      case TKN_range: {
-        const char* min = getAttribute(child, "min");
-        const char* max = getAttribute(child, "max");
-        if (min && max) {
-          int64_t minVal = recognize_Integer(min);
-          int64_t maxVal = recognize_Integer(max);
-          result = ast->new_RangeType(name,minVal,maxVal,loc);
-          break;
-        }
-        hlvmAssert(!"Missing 'min' or 'max' attribute");
-        break;
-      }
-      case TKN_real: {
-        const char* mantissa = getAttribute(child, "mantissa");
-        const char* exponent = getAttribute(child, "exponent");
-        if (mantissa && exponent) {
-          int32_t mantVal = recognize_nonNegativeInteger(mantissa);
-          int32_t expoVal = recognize_nonNegativeInteger(exponent);
-          result = ast->new_RealType(name,mantVal,expoVal,loc);
-        }
-        break;
-      }
-      default:
-        hlvmAssert(!"Invalid content for atom");
-        break;
-    }
-    if (result) {
-      if (theDoc)
-        result->setDoc(theDoc);
-      return result;
-    }
-  }
-  hlvmAssert(!"Atom definition element expected");
-  return 0;
-}
-
-Type*
-XMLReaderImpl::parseEnumeration(xmlNodePtr& cur)
+template<> EnumerationType*
+XMLReaderImpl::parse<EnumerationType>(xmlNodePtr& cur)
 {
   hlvmAssert(getToken(cur->name)==TKN_enumeration);
   Locator* loc = getLocator(cur);
@@ -627,8 +600,8 @@
   return en;
 }
 
-Type*     
-XMLReaderImpl::parsePointer(xmlNodePtr& cur)
+template<> PointerType*     
+XMLReaderImpl::parse<PointerType>(xmlNodePtr& cur)
 {
   hlvmAssert(getToken(cur->name)==TKN_pointer);
   Locator* loc = getLocator(cur);
@@ -640,8 +613,8 @@
   return result;
 }
 
-Type*     
-XMLReaderImpl::parseArray(xmlNodePtr& cur)
+template<> ArrayType*     
+XMLReaderImpl::parse<ArrayType>(xmlNodePtr& cur)
 {
   hlvmAssert(getToken(cur->name)==TKN_array);
   Locator* loc = getLocator(cur);
@@ -654,8 +627,8 @@
   return result;
 }
 
-Type*     
-XMLReaderImpl::parseVector(xmlNodePtr& cur)
+template<> VectorType*     
+XMLReaderImpl::parse<VectorType>(xmlNodePtr& cur)
 {
   hlvmAssert(getToken(cur->name)==TKN_vector);
   Locator* loc = getLocator(cur);
@@ -669,8 +642,8 @@
   return result;
 }
 
-Type*
-XMLReaderImpl::parseStructure(xmlNodePtr& cur)
+template<> StructureType*
+XMLReaderImpl::parse<StructureType>(xmlNodePtr& cur)
 {
   hlvmAssert(getToken(cur->name)==TKN_structure);
   Locator* loc = getLocator(cur);
@@ -690,8 +663,8 @@
   return struc;
 }
 
-Type*     
-XMLReaderImpl::parseSignature(xmlNodePtr& cur)
+template<> SignatureType*
+XMLReaderImpl::parse<SignatureType>(xmlNodePtr& cur)
 {
   hlvmAssert(getToken(cur->name)==TKN_signature);
   Locator* loc = getLocator(cur);
@@ -715,8 +688,8 @@
   return sig;
 }
 
-Type*
-XMLReaderImpl::parseOpaque(xmlNodePtr& cur)
+template<> OpaqueType*
+XMLReaderImpl::parse<OpaqueType>(xmlNodePtr& cur)
 {
   hlvmAssert(getToken(cur->name)==TKN_opaque);
   Locator* loc = getLocator(cur);
@@ -726,8 +699,8 @@
   return result;
 }
 
-Variable*
-XMLReaderImpl::parseVariable(xmlNodePtr& cur)
+template<> Variable*
+XMLReaderImpl::parse<Variable>(xmlNodePtr& cur)
 {
   hlvmAssert(getToken(cur->name)==TKN_variable);
   Locator* loc = getLocator(cur);
@@ -735,7 +708,9 @@
   getNameType(cur, name, type);
   const char* cnst = getAttribute(cur, "const", false);
   const char* lnkg = getAttribute(cur, "linkage", false);
-  const Type* Ty = ast->resolveType(type);
+  const Type* Ty = recognize_builtin_type(ast,type);
+  if (!Ty)
+    Ty = ast->resolveType(type);
   Variable* var = ast->new_Variable(name,Ty,loc);
   if (cnst)
     var->setIsConstant(recognize_boolean(cnst));
@@ -743,19 +718,59 @@
     var->setLinkageKind(recognize_LinkageKinds(lnkg));
   xmlNodePtr child = checkDoc(cur,var);
   if (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE) {
-    Constant* C = parseConstant(child);
+    Constant* C = parseConstant(child,Ty);
     var->setInitializer(C);
   }
   return var;
 }
 
-ReferenceOp*
-XMLReaderImpl::parseReference(xmlNodePtr& cur)
+template<> AutoVarOp*
+XMLReaderImpl::parse<AutoVarOp>(xmlNodePtr& cur)
+{
+  std::string name, type;
+  getNameType(cur, name, type);
+  Locator* loc = getLocator(cur);
+  const Type* Ty = recognize_builtin_type(ast,type);
+  if (Ty == 0)
+    Ty = ast->resolveType(type);
+  xmlNodePtr child = cur->children;
+  Constant* C = 0;
+  if (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE) {
+    C = parseConstant(child,Ty);
+  } else {
+    C = ast->new_ConstantZero(Ty,loc);
+  }
+  AutoVarOp* result = ast->AST::new_UnaryOp<AutoVarOp>(C,loc);
+  result->setName(name);
+  result->setType(Ty);
+  return result;
+}
+
+template<> ReferenceOp*
+XMLReaderImpl::parse<ReferenceOp>(xmlNodePtr& cur)
 {
   std::string id = getAttribute(cur,"id");
   Locator* loc = getLocator(cur);
+
   ReferenceOp* result = ast->AST::new_NilaryOp<ReferenceOp>(loc);
-  // result->setReferent(id);
+
+  // Find the referrent variable in a block
+  Block* blk = block;
+  while (blk != 0) {
+    if (AutoVarOp* av = blk->getAutoVar(id)) {
+      result->setReferent(av);
+      return result;
+    }
+    if (llvm::isa<Block>(blk->getParent()))
+      blk = llvm::cast<Block>(blk->getParent());
+    else
+      blk = 0;
+  }
+
+  // Didn't find an autovar, try a global variable
+  Variable* var = bundle->var_find(id);
+  hlvmAssert(var && "Variable not found");
+  result->setReferent(var);
   return result;
 }
 
@@ -801,14 +816,202 @@
   return ast->AST::new_TernaryOp<OpClass>(oprnd1,oprnd2,oprnd3,loc);
 }
 
+template<> Block*
+XMLReaderImpl::parse<Block>(xmlNodePtr& cur)
+{
+  hlvmAssert(getToken(cur->name) == TKN_block && "Expecting block element");
+  Locator* loc = getLocator(cur);
+  const char* label = getAttribute(cur, "label",false);
+  if (label)
+    block = ast->new_Block(label,loc);
+  else
+    block = ast->new_Block("",loc);
+  hlvmAssert(func != 0);
+  block->setParent(func);
+  xmlNodePtr child = cur->children;
+  while (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE) 
+  {
+    Value* op = parseOperator(child);
+    block->addOperand(op);
+    child = child->next;
+  }
+  return block;
+}
+
+template<> Function*
+XMLReaderImpl::parse<Function>(xmlNodePtr& cur)
+{
+  hlvmAssert(getToken(cur->name)==TKN_function);
+  Locator* loc = getLocator(cur);
+  std::string name, type;
+  getNameType(cur, name, type);
+  func = ast->new_Function(name,loc);
+  const char* lnkg = getAttribute(cur, "linkage", false);
+  if (lnkg)
+    func->setLinkageKind(recognize_LinkageKinds(lnkg));
+  checkDoc(cur,func);
+  return func;
+}
+
+template<> Program*
+XMLReaderImpl::parse<Program>(xmlNodePtr& cur)
+{
+  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);
+  func = program;
+  xmlNodePtr child = cur->children;
+  if (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE) {
+    Block* b = parse<Block>(child);
+    program->setBlock(b);
+  } else {
+    hlvmDeadCode("Program Without Block!");
+  }
+  return program;
+}
+
+template<> Import*
+XMLReaderImpl::parse<Import>(xmlNodePtr& cur)
+{
+  hlvmAssert(getToken(cur->name)==TKN_import);
+  std::string pfx = getAttribute(cur,"prefix");
+  Import* imp = ast->new_Import(pfx,getLocator(cur));
+  checkDoc(cur,imp);
+  return imp;
+}
+
+template<> Bundle*
+XMLReaderImpl::parse<Bundle>(xmlNodePtr& cur) 
+{
+  hlvmAssert(getToken(cur->name) == TKN_bundle && "Expecting bundle element");
+  std::string pubid(getAttribute(cur, "id"));
+  Locator* loc = getLocator(cur);
+  bundle = ast->new_Bundle(pubid,loc);
+  xmlNodePtr child = cur->children;
+  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_bundle      : { n = parse<Bundle>(child); break; }
+      case TKN_alias       : { n = parse<AliasType>(child); break; }
+      case TKN_atom        : { n = parseAtom(child); break; }
+      case TKN_enumeration : { n = parse<EnumerationType>(child); break; }
+      case TKN_pointer     : { n = parse<PointerType>(child); break; }
+      case TKN_array       : { n = parse<ArrayType>(child); break; }
+      case TKN_vector      : { n = parse<VectorType>(child); break; }
+      case TKN_structure   : { n = parse<StructureType>(child); break; }
+      case TKN_signature   : { n = parse<SignatureType>(child); break; }
+      case TKN_opaque      : { n = parse<OpaqueType>(child); break; }
+      case TKN_variable    : { n = parse<Variable>(child); break; }
+      case TKN_program     : { n = parse<Program>(child); break; }
+      case TKN_function    : { n = parse<Function>(child); break; }
+      default:
+      {
+        hlvmDeadCode("Invalid content for bundle");
+        break;
+      }
+    }
+    if (n)
+      n->setParent(bundle); 
+    child = child->next;
+  }
+  return bundle;
+}
+
+Type*     
+XMLReaderImpl::parseAtom(xmlNodePtr& cur)
+{
+  hlvmAssert(getToken(cur->name)==TKN_atom);
+  Locator* loc = getLocator(cur);
+  std::string name = getAttribute(cur,"id");
+  xmlNodePtr child = cur->children;
+  Documentation* theDoc = parse<Documentation>(child);
+  child = (theDoc==0 ? child : child->next );
+  Type* result = 0;
+  if (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE) {
+    int tkn = getToken(child->name);
+    switch (tkn) {
+      case TKN_intrinsic: {
+        const char* is = getAttribute(child,"is");
+        if (!is)
+          hlvmAssert(!"intrinsic element requires 'is' attribute");
+        result = create_builtin_type(ast,is,name,loc);
+        hlvmAssert(result && "Invalid intrinsic kind");
+        break;
+      }
+      case TKN_signed: {
+        const char* bits = getAttribute(child,"bits");
+        if (bits) {
+          uint64_t numBits = recognize_nonNegativeInteger(bits);
+          result = ast->new_IntegerType(name,numBits,/*signed=*/true,loc);
+          break;
+        }
+        hlvmAssert(!"Missing 'bits' attribute");
+        break;
+      }
+      case TKN_unsigned: {
+        const char* bits = getAttribute(child,"bits");
+        if (bits) {
+          uint64_t numBits = recognize_nonNegativeInteger(bits);
+          result = ast->new_IntegerType(name,numBits,/*signed=*/false,loc);
+          break;
+        }
+        hlvmAssert(!"Missing 'bits' attribute");
+        break;
+      }      
+      case TKN_range: {
+        const char* min = getAttribute(child, "min");
+        const char* max = getAttribute(child, "max");
+        if (min && max) {
+          int64_t minVal = recognize_Integer(min);
+          int64_t maxVal = recognize_Integer(max);
+          result = ast->new_RangeType(name,minVal,maxVal,loc);
+          break;
+        }
+        hlvmAssert(!"Missing 'min' or 'max' attribute");
+        break;
+      }
+      case TKN_real: {
+        const char* mantissa = getAttribute(child, "mantissa");
+        const char* exponent = getAttribute(child, "exponent");
+        if (mantissa && exponent) {
+          int32_t mantVal = recognize_nonNegativeInteger(mantissa);
+          int32_t expoVal = recognize_nonNegativeInteger(exponent);
+          result = ast->new_RealType(name,mantVal,expoVal,loc);
+        }
+        break;
+      }
+      default:
+        hlvmAssert(!"Invalid content for atom");
+        break;
+    }
+    if (result) {
+      if (theDoc)
+        result->setDoc(theDoc);
+      return result;
+    }
+  }
+  hlvmAssert(!"Atom definition element expected");
+  return 0;
+}
+
 inline Constant*
-XMLReaderImpl::parseConstant(xmlNodePtr& cur)
+XMLReaderImpl::parseConstant(xmlNodePtr& cur,const Type* Ty)
 {
-  return parseConstant(cur, getToken(cur->name));
+  return parseConstant(cur, Ty, getToken(cur->name));
 }
 
 Constant*
-XMLReaderImpl::parseConstant(xmlNodePtr& cur, int tkn)
+XMLReaderImpl::parseConstant(xmlNodePtr& cur, const Type* Ty, int tkn)
 {
   Constant* C = 0;
   switch (tkn) {
@@ -819,6 +1022,7 @@
     case TKN_flt:          C = parseFloat(cur); break;
     case TKN_dbl:          C = parseDouble(cur); break;
     case TKN_text:         C = parseText(cur); break;
+    case TKN_zero:         C = parseZero(cur,Ty); break;
     default:
       hlvmAssert(!"Invalid kind of constant");
       break;
@@ -839,13 +1043,14 @@
   Operator* op = 0;
   switch (tkn) {
     case TKN_ret:          op = parseUnaryOp<ReturnOp>(cur); break;
-    case TKN_block:        op = parseBlock(cur); break;
+    case TKN_block:        op = parse<Block>(cur); break;
     case TKN_store:        op = parseBinaryOp<StoreOp>(cur); break;
     case TKN_load:         op = parseUnaryOp<LoadOp>(cur); break;
     case TKN_open:         op = parseUnaryOp<OpenOp>(cur); break;
-    case TKN_write:        op = parseTernaryOp<WriteOp>(cur); break;
+    case TKN_write:        op = parseBinaryOp<WriteOp>(cur); break;
     case TKN_close:        op = parseUnaryOp<CloseOp>(cur); break;
-    case TKN_ref:          op = parseReference(cur); break;
+    case TKN_ref:          op = parse<ReferenceOp>(cur); break;
+    case TKN_autovar:      op = parse<AutoVarOp>(cur); break;
     default:
       hlvmDeadCode("Unrecognized operator");
       break;
@@ -872,7 +1077,7 @@
     case TKN_dbl:
     case TKN_text:
     case TKN_zero:
-      v = parseConstant(cur,tkn);
+      v = parseConstant(cur,0,tkn);
       break;
     case TKN_ret:
     case TKN_open:
@@ -881,19 +1086,20 @@
     case TKN_store:
     case TKN_load:
     case TKN_ref:
+    case TKN_autovar:
       v = parseOperator(cur,tkn);
       break;
     case TKN_block: 
-      v = parseBlock(cur);
+      v = parse<Block>(cur);
       break;
     case TKN_program:
-      v = parseProgram(cur);
+      v = parse<Program>(cur);
       break;
     case TKN_function:
-      v = parseFunction(cur);
+      v = parse<Function>(cur);
       break;
     case TKN_variable:
-      v = parseVariable(cur);
+      v = parse<Variable>(cur);
       break;
     default:
       hlvmDeadCode("Unrecognized operator");
@@ -902,105 +1108,6 @@
   return v;
 }
 
-Block*
-XMLReaderImpl::parseBlock(xmlNodePtr& cur)
-{
-  hlvmAssert(getToken(cur->name) == TKN_block && "Expecting block element");
-  Locator* loc = getLocator(cur);
-  const char* label = getAttribute(cur, "label",false);
-  Block* block = 0;
-  if (label)
-    block = ast->new_Block(label,loc);
-  else
-    block = ast->new_Block("",loc);
-  xmlNodePtr child = cur->children;
-  while (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE) 
-  {
-    Value* op = parseValue(child);
-    block->addOperand(op);
-    child = child->next;
-  }
-  return block;
-}
-
-Function*
-XMLReaderImpl::parseFunction(xmlNodePtr& cur)
-{
-  hlvmAssert(getToken(cur->name)==TKN_function);
-  Locator* loc = getLocator(cur);
-  std::string name, type;
-  getNameType(cur, name, type);
-  Function* func = ast->new_Function(name,loc);
-  const char* lnkg = getAttribute(cur, "linkage", false);
-  if (lnkg)
-    func->setLinkageKind(recognize_LinkageKinds(lnkg));
-  checkDoc(cur,func);
-  return func;
-}
-
-Program*
-XMLReaderImpl::parseProgram(xmlNodePtr& cur)
-{
-  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);
-  xmlNodePtr child = cur->children;
-  if (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE) {
-    Block* b = parseBlock(child);
-    program->setBlock(b);
-  } else {
-    hlvmDeadCode("Program Without Block!");
-  }
-  return program;
-}
-
-Bundle*
-XMLReaderImpl::parseBundle(xmlNodePtr& cur) 
-{
-  hlvmAssert(getToken(cur->name) == TKN_bundle && "Expecting bundle element");
-  std::string pubid(getAttribute(cur, "id"));
-  Locator* loc = getLocator(cur);
-  Bundle* bundle = ast->new_Bundle(pubid,loc);
-  xmlNodePtr child = cur->children;
-  while (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE) 
-  {
-    int tkn = getToken(child->name);
-    Node* n = 0;
-    switch (tkn) {
-      case TKN_doc      : {
-        Documentation* theDoc = parseDocumentation(child);
-        if (theDoc)
-          bundle->setDoc(theDoc);
-        break;
-      }
-      case TKN_import      : { n = parseImport(child); break; }
-      case TKN_bundle      : { n = parseBundle(child); break; }
-      case TKN_alias       : { n = parseAlias(child); break; }
-      case TKN_atom        : { n = parseAtom(child); break; }
-      case TKN_enumeration : { n = parseEnumeration(child); break; }
-      case TKN_pointer     : { n = parsePointer(child); break; }
-      case TKN_array       : { n = parseArray(child); break; }
-      case TKN_vector      : { n = parseVector(child); break; }
-      case TKN_structure   : { n = parseStructure(child); break; }
-      case TKN_signature   : { n = parseSignature(child); break; }
-      case TKN_opaque      : { n = parseOpaque(child); break; }
-      case TKN_variable    : { n = parseVariable(child); break; }
-      case TKN_program     : { n = parseProgram(child); break; }
-      case TKN_function    : { n = parseFunction(child); break; }
-      default:
-      {
-        hlvmDeadCode("Invalid content for bundle");
-        break;
-      }
-    }
-    if (n)
-      n->setParent(bundle); 
-    child = child->next;
-  }
-  return bundle;
-}
-
 void
 XMLReaderImpl::parseTree() 
 {
@@ -1014,8 +1121,8 @@
   ast->setPublicID(pubid);
   cur = cur->children;
   if (skipBlanks(cur)) {
-    Bundle* bundle = parseBundle(cur);
-    ast->addBundle(bundle);
+    Bundle* b = parse<Bundle>(cur);
+    ast->addBundle(b);
   }
 }
 

Modified: hlvm/trunk/hlvm/Runtime/Error.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Runtime/Error.cpp?rev=38179&r1=38178&r2=38179&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Runtime/Error.cpp (original)
+++ hlvm/trunk/hlvm/Runtime/Error.cpp Sat Jul  7 19:00:47 2007
@@ -27,29 +27,47 @@
 /// @brief Implements the runtime error handling facilities.
 //===----------------------------------------------------------------------===//
 
+#include <hlvm/Runtime/Internal.h>
+
 extern "C" {
 
-#include <apr-1/apr_file_io.h>
 #include <hlvm/Runtime/Error.h>
-#include <hlvm/Runtime/Internal.h>
 #include <stdlib.h>
 
-void 
-hlvm_error(ErrorCodes ec, const char* arg)
+void
+hlvm_verror(ErrorCodes ec, va_list ap)
 {
-  const char* msg = "Unknown";
+  const char* format = "Unknown Error";
   switch (ec) {
-    case E_UNHANDLED_EXCEPTION: msg = "Unhandled Exception"; break;
-    case E_BAD_OPTION         : msg = "Unrecognized option"; break;
-    case E_MISSING_ARGUMENT   : msg = "Missing option argument"; break;
-    case E_NO_PROGRAM_NAME    : msg = "Program name not specified"; break;
-    case E_PROGRAM_NOT_FOUND  : msg = "Program not found"; break;
+    case E_UNHANDLED_EXCEPTION: format = "Unhandled Exception"; break;
+    case E_BAD_OPTION         : format = "Unrecognized option: %s"; break;
+    case E_MISSING_ARGUMENT   : format = "Missing option argument for %s";break;
+    case E_NO_PROGRAM_NAME    : format = "Program name not specified"; break;
+    case E_PROGRAM_NOT_FOUND  : format = "Program '%s' not found"; break;
+    case E_APR_ERROR          : format = "%s while %s"; break;
+    case E_ASSERT_FAIL        : format = "Assertion Failure: (%s) at %s:%d"; break;
+    case E_OPTION_ERROR       : format = "In Options: %s"; break;
     default: break;
   }
-  if (arg)
-    apr_file_printf(_hlvm_stderr, "Error: %s: %s\n", msg, arg);
-  else
-    apr_file_printf(_hlvm_stderr, "Error: %s\n", msg);
+  char* msg = apr_pvsprintf(_hlvm_pool, format, ap);
+  apr_file_printf(_hlvm_stderr, "Error: %s\n", msg);
+}
+
+void 
+hlvm_error(ErrorCodes ec, ...)
+{
+  va_list ap;
+  va_start(ap,ec);
+  hlvm_verror(ec,ap);
+}
+
+void 
+hlvm_fatal(ErrorCodes ec, ...)
+{
+  va_list ap;
+  va_start(ap,ec);
+  hlvm_verror(ec,ap);
+  exit(ec);
 }
 
 void hlvm_panic(const char* msg) {

Modified: hlvm/trunk/hlvm/Runtime/Error.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Runtime/Error.h?rev=38179&r1=38178&r2=38179&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Runtime/Error.h (original)
+++ hlvm/trunk/hlvm/Runtime/Error.h Sat Jul  7 19:00:47 2007
@@ -35,10 +35,15 @@
   E_BAD_OPTION,
   E_MISSING_ARGUMENT,
   E_NO_PROGRAM_NAME,
-  E_PROGRAM_NOT_FOUND
+  E_PROGRAM_NOT_FOUND,
+  E_APR_ERROR,
+  E_ASSERT_FAIL,
+  E_OPTION_ERROR
 };
 
-void hlvm_error(ErrorCodes ec, const char* msg);
+void hlvm_error(ErrorCodes ec, ...);
+void hlvm_verror(ErrorCodes ec, va_list ap);
+void hlvm_fatal(ErrorCodes ec, ...);
 void hlvm_panic(const char *msg);
 
 #endif

Removed: hlvm/trunk/hlvm/Runtime/FileIO.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Runtime/FileIO.cpp?rev=38178&view=auto

==============================================================================
--- hlvm/trunk/hlvm/Runtime/FileIO.cpp (original)
+++ hlvm/trunk/hlvm/Runtime/FileIO.cpp (removed)
@@ -1,58 +0,0 @@
-//===-- Runtime File I/O Implementation -------------------------*- C++ -*-===//
-//
-//                      High Level Virtual Machine (HLVM)
-//
-// Copyright (C) 2006 Reid Spencer. All Rights Reserved.
-//
-// This software is free software; you can redistribute it and/or modify it 
-// under the terms of the GNU Lesser General Public License as published by 
-// the Free Software Foundation; either version 2.1 of the License, or (at 
-// your option) any later version.
-//
-// This software is distributed in the hope that it will be useful, but WITHOUT
-// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-// FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for 
-// more details.
-//
-// You should have received a copy of the GNU Lesser General Public License 
-// along with this library in the file named LICENSE.txt; if not, write to the 
-// Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
-// MA 02110-1301 USA
-//
-//===----------------------------------------------------------------------===//
-/// @file hlvm/Runtime/FileIO.cpp
-/// @author Reid Spencer <rspencer at reidspencer.org> (original author)
-/// @date 2006/05/24
-/// @since 0.1.0
-/// @brief Implements the functions for runtime file input/output.
-//===----------------------------------------------------------------------===//
-
-#include <hlvm/Runtime/FileIO.h>
-#include <apr-1/apr_file_io.h>
-#include <hlvm/Runtime/Utilities.h>
-
-namespace 
-{
-}
-
-extern "C" 
-{
-
-void* 
-hlvm_op_file_open(hlvm_string* uri)
-{
-  return 0;
-}
-
-void 
-hlvm_op_file_close(void* fnum)
-{
-}
-
-uint32_t 
-hovm_op_file_write(void* fnum, void* data, size_t len)
-{
-  return 0;
-}
-
-}

Removed: hlvm/trunk/hlvm/Runtime/FileIO.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Runtime/FileIO.h?rev=38178&view=auto

==============================================================================
--- hlvm/trunk/hlvm/Runtime/FileIO.h (original)
+++ hlvm/trunk/hlvm/Runtime/FileIO.h (removed)
@@ -1,45 +0,0 @@
-//===-- Runtime File I/O Interface ------------------------------*- C++ -*-===//
-//
-//                      High Level Virtual Machine (HLVM)
-//
-// Copyright (C) 2006 Reid Spencer. All Rights Reserved.
-//
-// This software is free software; you can redistribute it and/or modify it 
-// under the terms of the GNU Lesser General Public License as published by 
-// the Free Software Foundation; either version 2.1 of the License, or (at 
-// your option) any later version.
-//
-// This software is distributed in the hope that it will be useful, but WITHOUT
-// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-// FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for 
-// more details.
-//
-// You should have received a copy of the GNU Lesser General Public License 
-// along with this library in the file named LICENSE.txt; if not, write to the 
-// Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
-// MA 02110-1301 USA
-//
-//===----------------------------------------------------------------------===//
-/// @file hlvm/Runtime/FileIO.h
-/// @author Reid Spencer <rspencer at reidspencer.com> (original author)
-/// @date 2006/05/24
-/// @since 0.1.0
-/// @brief Declares the interface to the runtime File Input/Output operations
-//===----------------------------------------------------------------------===//
-
-#ifndef HLVM_RUNTIME_FILEIO_H
-#define HLVM_RUNTIME_FILEIO_H
-
-#include <hlvm/Runtime/String.h>
-
-extern "C" 
-{
-
-void* hlvm_op_file_open(hlvm_string* uri);
-
-uint32_t hlvm_op_file_write(void* file, void* data, size_t len);
-
-void hlvm_op_file_close(void* file);
-}
-
-#endif

Modified: hlvm/trunk/hlvm/Runtime/Internal.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Runtime/Internal.cpp?rev=38179&r1=38178&r2=38179&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Runtime/Internal.cpp (original)
+++ hlvm/trunk/hlvm/Runtime/Internal.cpp Sat Jul  7 19:00:47 2007
@@ -27,11 +27,10 @@
 /// @brief Declares the implementation to the internal runtime facilities
 //===----------------------------------------------------------------------===//
 
-#include <apr-1/apr_file_io.h>
+#include <hlvm/Runtime/Internal.h>
 
 extern "C" {
 
-#include <hlvm/Runtime/Internal.h>
 #include <hlvm/Runtime/Error.h>
 
 apr_pool_t* _hlvm_pool = 0;
@@ -47,4 +46,21 @@
     hlvm_panic("Can't open stderr");
 }
 
+bool hlvm_apr_error(apr_status_t stat, const char* whilst)
+{
+  if (APR_SUCCESS != stat) {
+    char buffer[1024];
+    apr_strerror(stat,buffer,1024);
+    hlvm_error(E_APR_ERROR, buffer, whilst);
+    return false;
+  }
+  return true;
+}
+
+bool hlvm_assert_fail(const char* expr, const char* file, int line)
+{
+  hlvm_error(E_ASSERT_FAIL,expr,file,line);
+  return false;
+}
+
 }

Modified: hlvm/trunk/hlvm/Runtime/Internal.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Runtime/Internal.h?rev=38179&r1=38178&r2=38179&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Runtime/Internal.h (original)
+++ hlvm/trunk/hlvm/Runtime/Internal.h Sat Jul  7 19:00:47 2007
@@ -30,11 +30,55 @@
 #ifndef HLVM_RUNTIME_INTERNAL_H 
 #define HLVM_RUNTIME_INTERNAL_H 
 
-#include <apr-1/apr_pools.h>
+#include <apr-1/apr_file_io.h>
+#include <apr-1/apr_strings.h>
+
+extern "C" {
+
+#include <hlvm/Runtime/Error.h>
+
+typedef apr_uint64_t hlvm_size;
+
+struct hlvm_text_obj {
+  hlvm_size len;
+  char* str;
+  unsigned is_const : 1;
+};
+
+struct hlvm_stream_obj {
+  apr_file_t* fp;
+};
+
+struct hlvm_buffer_obj {
+  hlvm_size len;
+  char* data;
+};
 
 extern apr_pool_t* _hlvm_pool;
 extern apr_file_t* _hlvm_stderr;
 
 extern void _hlvm_initialize();
 
+/// This is the HLVM runtime assert macro. It is very much similar to
+/// the <cassert> version but without some of the overhead. It also lets
+/// us take control of what to do when an assertion happens. The standard
+/// implementation just prints and aborts.
+#define hlvm_stringize(expr) #expr
+#define hlvm_assert(expr) \
+  ((expr) ? 1 : hlvm_assert_fail(#expr,__FILE__,__LINE__))
+
+
+/// This function gets called by the hlvm_assert macro, and in other situations
+/// where a "panic" happens. It provides the proper escape mechanism given the
+/// configuration of the runtime.
+bool hlvm_assert_fail(const char* expression, const char* file, int line_num);
+
+/// This macro checks the return value of an APR call and reports the error
+/// if there is one. It can be used as a
+#define HLVM_APR(apr_call,whilst) (hlvm_apr_error(apr_call,whilst))
+
+extern bool hlvm_apr_error(apr_status_t stat, const char* whilst);
+
+}
+
 #endif

Modified: hlvm/trunk/hlvm/Runtime/Main.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Runtime/Main.cpp?rev=38179&r1=38178&r2=38179&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Runtime/Main.cpp (original)
+++ hlvm/trunk/hlvm/Runtime/Main.cpp Sat Jul  7 19:00:47 2007
@@ -29,19 +29,54 @@
 
 #include <apr-1/apr_getopt.h>
 #include <apr-1/apr_file_io.h>
+#include <stdlib.h>
+#include <hlvm/Runtime/Internal.h>
+#include <hlvm/Base/Config.h>
+
+namespace {
+
+apr_getopt_option_t hlvm_options[] = {
+  { "help", 'h', 0, "Print help on using HLVM" },
+  { "version", 'v', 0, "Print version information" },
+  { 0, 0, 0, 0 }
+};
+
+void print_version( bool should_exit = true )
+{
+  apr_file_printf(_hlvm_stderr, 
+    "HLVM Runtime Version %s; %s\n", HLVM_Version, HLVM_ConfigTime);
+  apr_file_printf(_hlvm_stderr, "%s\n", HLVM_Copyright);
+  apr_file_printf(_hlvm_stderr, "Contact %s For Details\n", HLVM_Maintainer);
+  if (should_exit)
+    exit(0);
+}
+
+void print_help()
+{
+  print_version(false);
+  apr_file_printf(_hlvm_stderr,"\nOptions:\n");
+  for (unsigned i = 0; i < sizeof(hlvm_options)/sizeof(hlvm_options[0])-1; ++i) {
+    apr_file_printf(_hlvm_stderr, "  --%-15s  %-74s\n", 
+      hlvm_options[i].name, hlvm_options[i].description);
+  }
+  exit(0);
+}
+
+void print_error(void*, const char* fmt, ...)
+{
+  va_list ap;
+  va_start(ap,fmt);
+  char* msg = apr_pvsprintf(_hlvm_pool, fmt, ap);
+  hlvm_fatal(E_OPTION_ERROR,msg);
+}
+
+}
 
 extern "C" {
 
 #include <hlvm/Runtime/Main.h>
 #include <hlvm/Runtime/Program.h>
 #include <hlvm/Runtime/Memory.h>
-#include <hlvm/Runtime/Error.h>
-#include <hlvm/Runtime/Internal.h>
-
-apr_getopt_option_t hlvm_options[] = {
-  { "help", 'h', 0, "Provides help on using HLVM" },
-  { 0, 0, 0, 0 }
-};
 
 
 /// This is the function called from the real main() in hlvm/tools/hlvm.  We 
@@ -60,28 +95,35 @@
     if (APR_SUCCESS != apr_getopt_init(&options, _hlvm_pool, argc, argv))
       hlvm_panic("Can't initialize apr_getopt");
     options->interleave = 0;
+    options->errfn = print_error;
+    options->errarg = _hlvm_stderr;
     int ch;
     const char* arg;
+    hlvm_program_type entry_func = 0;
     apr_status_t stat = apr_getopt_long(options, hlvm_options, &ch, &arg); 
     while (stat != APR_EOF) {
       switch (stat) {
         case APR_SUCCESS:
         {
           switch (ch) {
-            case 'h':
-              break;
+            case 'h': print_help(); break;
+            case 'v': print_version(); break;
             default:
               break;
           }
+          break;
         }
         case APR_BADCH:
         {
-          hlvm_error(E_BAD_OPTION,0);
+          char option[3];
+          option[0] = ch;
+          option[1] = 0;
+          hlvm_error(E_BAD_OPTION,option);
           return E_BAD_OPTION;
         }
         case APR_BADARG:
         {
-          hlvm_error(E_MISSING_ARGUMENT,0);
+          hlvm_error(E_MISSING_ARGUMENT);
           return E_MISSING_ARGUMENT;
         }
         case APR_EOF:
@@ -94,27 +136,26 @@
       stat = apr_getopt_long(options, hlvm_options, &ch, &arg); 
     }
 
-    // Find the function that represents the start point.
-    if (options->ind == 0) {
-      hlvm_error(E_NO_PROGRAM_NAME,0);
-      return E_NO_PROGRAM_NAME;
-    } else {
-      const char* prog_name = argv[options->ind];
-      hlvm_program_type func = hlvm_find_program(prog_name);
-
-      // If we got a start function ..
-      if (func) {
-        // Invoke it.
-        return (*func)(options->argc, options->argv);
-      } else {
+    const char* prog_name = argv[options->ind];
+    if (prog_name) {
+      entry_func = hlvm_find_program(prog_name);
+      // If we didn't get a start function ..
+      if (!entry_func) {
         // Give an error
-        hlvm_error(E_PROGRAM_NOT_FOUND,argv[1]);
+        hlvm_error(E_PROGRAM_NOT_FOUND,prog_name);
         return E_PROGRAM_NOT_FOUND;
       }
+      result = (*entry_func)(options->argc, options->argv);
+    } else {
+      hlvm_error(E_NO_PROGRAM_NAME,0);
+      return E_NO_PROGRAM_NAME;
     }
-  } catch (...) {
-    hlvm_error(E_UNHANDLED_EXCEPTION,0);
+  } 
+  catch (...) 
+  {
+    hlvm_error(E_UNHANDLED_EXCEPTION);
   }
   return result;
 }
-}
+
+} // end extern "C"

Modified: hlvm/trunk/hlvm/Runtime/Memory.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Runtime/Memory.h?rev=38179&r1=38178&r2=38179&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Runtime/Memory.h (original)
+++ hlvm/trunk/hlvm/Runtime/Memory.h Sat Jul  7 19:00:47 2007
@@ -30,14 +30,8 @@
 #ifndef HLVM_RUNTIME_MEMORY_H
 #define HLVM_RUNTIME_MEMORY_H
 
-#include <llvm/Support/DataTypes.h>
+#include <apr-1/apr.h>
 
-extern "C" {
-
-void* hlvm_allocate_array(uint64_t count, uint64_t elemSize);
-
-void hlvm_deallocate_array(void* ptr);
-
-}
+typedef apr_uint64_t hlvm_size;
 
 #endif

Modified: hlvm/trunk/hlvm/Runtime/Program.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Runtime/Program.cpp?rev=38179&r1=38178&r2=38179&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Runtime/Program.cpp (original)
+++ hlvm/trunk/hlvm/Runtime/Program.cpp Sat Jul  7 19:00:47 2007
@@ -27,16 +27,12 @@
 /// @brief Implements the runtime program facilities.
 //===----------------------------------------------------------------------===//
 
-#include <hlvm/Runtime/Program.h>
-#include <string.h>
-
-namespace {
-
-
-}
+#include <hlvm/Runtime/Internal.h>
 
 extern "C" {
 
+#include <hlvm/Runtime/Program.h>
+
 /// Declare the external function that gets use the first element in
 /// the hlvm_programs appending array. This function is implemented in the
 /// hlvm_get_programs.ll file.
@@ -51,7 +47,7 @@
 {
   hlvm_programs_element* p = hlvm_get_programs();
   while (p && p->program_entry) {
-    if (strcmp(p->program_name,uri) == 0)
+    if (0 == apr_strnatcmp(p->program_name,uri))
       return p->program_entry;
     ++p;
   }

Modified: hlvm/trunk/hlvm/Runtime/Program.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Runtime/Program.h?rev=38179&r1=38178&r2=38179&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Runtime/Program.h (original)
+++ hlvm/trunk/hlvm/Runtime/Program.h Sat Jul  7 19:00:47 2007
@@ -30,10 +30,6 @@
 #ifndef HLVM_RUNTIME_PROGRAM_H
 #define HLVM_RUNTIME_PROGRAM_H
 
-#include <hlvm/Runtime/String.h>
-
-extern "C" {
-
 /// This is the type of a program entry point function.
 typedef int (*hlvm_program_type)(int, const char **);
 
@@ -47,6 +43,4 @@
 /// uri and returns a pointer to the corresponding program.
 extern hlvm_program_type hlvm_find_program(const char* uri);
 
-}
-
 #endif

Modified: hlvm/trunk/hlvm/Runtime/README.txt
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Runtime/README.txt?rev=38179&r1=38178&r2=38179&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Runtime/README.txt (original)
+++ hlvm/trunk/hlvm/Runtime/README.txt Sat Jul  7 19:00:47 2007
@@ -40,3 +40,18 @@
 The Runtime library must not #include any system headers. Instead it should use
 the facilities of the APR or APRUTIL libraries.
 
+7. Three Layers
+------------------------
+There are three layers of abstraction in the runtime. The first layer is what
+user programs can see. At this level, most everything is a void*. This is so
+that the implementation choices are not restricted and so that runtime
+implementation can change without affecting its users. 
+
+The second layer is that which is common to the runtime. That is, between
+compilation units of the runtime itself. At this level, most of the types are
+defined as simple structs which allow access to data members between modules.
+
+The third layer is that which is internal to the defining module.  Each module
+might decide to embellish the inter-module definition of a given type,
+including by making it a C++ class. None of this can be exposed outside the
+module.

Copied: hlvm/trunk/hlvm/Runtime/Stream.cpp (from r38176, hlvm/trunk/hlvm/Runtime/FileIO.cpp)
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Runtime/Stream.cpp?p2=hlvm/trunk/hlvm/Runtime/Stream.cpp&p1=hlvm/trunk/hlvm/Runtime/FileIO.cpp&r1=38176&r2=38179&rev=38179&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Runtime/FileIO.cpp (original)
+++ hlvm/trunk/hlvm/Runtime/Stream.cpp Sat Jul  7 19:00:47 2007
@@ -1,4 +1,4 @@
-//===-- Runtime File I/O Implementation -------------------------*- C++ -*-===//
+//===-- Runtime Stream I/O Implementation -----------------------*- C++ -*-===//
 //
 //                      High Level Virtual Machine (HLVM)
 //
@@ -20,39 +20,85 @@
 // MA 02110-1301 USA
 //
 //===----------------------------------------------------------------------===//
-/// @file hlvm/Runtime/FileIO.cpp
+/// @file hlvm/Runtime/Stream.cpp
 /// @author Reid Spencer <rspencer at reidspencer.org> (original author)
 /// @date 2006/05/24
 /// @since 0.1.0
-/// @brief Implements the functions for runtime file input/output.
+/// @brief Implements the functions for runtime stream input/output.
 //===----------------------------------------------------------------------===//
 
-#include <hlvm/Runtime/FileIO.h>
-#include <apr-1/apr_file_io.h>
-#include <hlvm/Runtime/Utilities.h>
+#include <hlvm/Runtime/Internal.h>
+
+extern "C" {
+#include <hlvm/Runtime/Stream.h>
+}
 
 namespace 
 {
+  class Stream : public hlvm_stream_obj 
+  {
+  public:
+    Stream* open(const char* uri)
+    {
+      if (uri[0] == 'h' && uri[1] == 'l' && uri[2] == 'v' && uri[3] == 'm') {
+        if (0 == apr_strnatcmp(uri,"hlvm:std:out")) {
+          if (HLVM_APR(apr_file_open_stdout(&this->fp,_hlvm_pool),"opening std:out"))
+            return this;
+        } else if (0 == apr_strnatcmp(uri,"hlvm::std::in")) {
+          if (HLVM_APR(apr_file_open_stdin(&this->fp,_hlvm_pool),"opening std:in"))
+            return this;
+        } else if (0 == apr_strnatcmp(uri,"hlvm::std::err")) {
+          if (HLVM_APR(apr_file_open_stderr(&this->fp,_hlvm_pool),"opening std:err"))
+            return this;
+        }
+      }
+      return 0;
+    }
+    void close() {
+      HLVM_APR(apr_file_close(this->fp),"closing a stream");
+    }
+    hlvm_size write(void* data, hlvm_size len) {
+      apr_size_t nbytes = len;
+      HLVM_APR(apr_file_write(this->fp, data, &nbytes),"writing a stream");
+      return nbytes;
+    }
+  };
 }
 
-extern "C" 
-{
+extern "C" {
 
-void* 
-hlvm_op_file_open(hlvm_string* uri)
+hlvm_stream
+hlvm_stream_open(hlvm_text uri)
 {
-  return 0;
+  hlvm_assert(uri && uri->str);
+  Stream* result = new Stream();
+  return result->open(uri->str);
 }
 
 void 
-hlvm_op_file_close(void* fnum)
+hlvm_stream_close(hlvm_stream stream)
+{
+  hlvm_assert(stream);
+  Stream* strm = static_cast<Stream*>(stream);
+  strm->close();
+}
+
+hlvm_size
+hlvm_stream_write_buffer(hlvm_stream stream, hlvm_buffer data, hlvm_size len)
 {
+  hlvm_assert(stream);
+  hlvm_assert(data && data->data);
+  Stream* strm = static_cast<Stream*>(stream);
+  return strm->write(data->data,data->len);
 }
 
-uint32_t 
-hovm_op_file_write(void* fnum, void* data, size_t len)
+hlvm_size
+hlvm_stream_write_text(hlvm_stream stream, hlvm_text txt)
 {
-  return 0;
+  hlvm_assert(stream);
+  hlvm_assert(txt && txt->str);
+  Stream* strm = static_cast<Stream*>(stream);
+  return strm->write(txt->str,txt->len);
 }
 
 }

Copied: hlvm/trunk/hlvm/Runtime/Stream.h (from r38176, hlvm/trunk/hlvm/Runtime/FileIO.h)
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Runtime/Stream.h?p2=hlvm/trunk/hlvm/Runtime/Stream.h&p1=hlvm/trunk/hlvm/Runtime/FileIO.h&r1=38176&r2=38179&rev=38179&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Runtime/FileIO.h (original)
+++ hlvm/trunk/hlvm/Runtime/Stream.h Sat Jul  7 19:00:47 2007
@@ -1,4 +1,4 @@
-//===-- Runtime File I/O Interface ------------------------------*- C++ -*-===//
+//===-- Runtime Stream I/O Interface ----------------------------*- C++ -*-===//
 //
 //                      High Level Virtual Machine (HLVM)
 //
@@ -20,26 +20,28 @@
 // MA 02110-1301 USA
 //
 //===----------------------------------------------------------------------===//
-/// @file hlvm/Runtime/FileIO.h
+/// @file hlvm/Runtime/Stream.h
 /// @author Reid Spencer <rspencer at reidspencer.com> (original author)
 /// @date 2006/05/24
 /// @since 0.1.0
-/// @brief Declares the interface to the runtime File Input/Output operations
+/// @brief Declares the interface to the runtime Stream Input/Output operations
 //===----------------------------------------------------------------------===//
 
-#ifndef HLVM_RUNTIME_FILEIO_H
-#define HLVM_RUNTIME_FILEIO_H
+#ifndef HLVM_RUNTIME_STREAM_H
+#define HLVM_RUNTIME_STREAM_H
 
-#include <hlvm/Runtime/String.h>
+#include <hlvm/Runtime/Text.h>
 
-extern "C" 
-{
+typedef struct hlvm_stream_obj* hlvm_stream;
+typedef struct hlvm_buffer_obj* hlvm_buffer;
 
-void* hlvm_op_file_open(hlvm_string* uri);
+extern hlvm_stream 
+hlvm_stream_open(hlvm_text uri);
 
-uint32_t hlvm_op_file_write(void* file, void* data, size_t len);
+extern hlvm_size 
+hlvm_stream_write(hlvm_stream str, hlvm_buffer data, hlvm_size len);
 
-void hlvm_op_file_close(void* file);
-}
+extern void 
+hlvm_op_file_close(hlvm_stream file);
 
 #endif

Removed: hlvm/trunk/hlvm/Runtime/String.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Runtime/String.cpp?rev=38178&view=auto

==============================================================================
--- hlvm/trunk/hlvm/Runtime/String.cpp (original)
+++ hlvm/trunk/hlvm/Runtime/String.cpp (removed)
@@ -1,35 +0,0 @@
-//===-- Runtime String Implementation ---------------------------*- C++ -*-===//
-//
-//                      High Level Virtual Machine (HLVM)
-//
-// Copyright (C) 2006 Reid Spencer. All Rights Reserved.
-//
-// This software is free software; you can redistribute it and/or modify it 
-// under the terms of the GNU Lesser General Public License as published by 
-// the Free Software Foundation; either version 2.1 of the License, or (at 
-// your option) any later version.
-//
-// This software is distributed in the hope that it will be useful, but WITHOUT
-// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-// FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for 
-// more details.
-//
-// You should have received a copy of the GNU Lesser General Public License 
-// along with this library in the file named LICENSE.txt; if not, write to the 
-// Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
-// MA 02110-1301 USA
-//
-//===----------------------------------------------------------------------===//
-/// @file hlvm/Runtime/String.cpp
-/// @author Reid Spencer <rspencer at reidspencer.org> (original author)
-/// @date 2006/05/25
-/// @since 0.1.0
-/// @brief Implements the functions for runtime string support
-//===----------------------------------------------------------------------===//
-
-#include <hlvm/Runtime/String.h>
-#include <apr-1/apr_strings.h>
-
-extern "C" {
-
-}

Removed: hlvm/trunk/hlvm/Runtime/String.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Runtime/String.h?rev=38178&view=auto

==============================================================================
--- hlvm/trunk/hlvm/Runtime/String.h (original)
+++ hlvm/trunk/hlvm/Runtime/String.h (removed)
@@ -1,44 +0,0 @@
-//===-- Runtime String Interface --------------------------------*- C++ -*-===//
-//
-//                      High Level Virtual Machine (HLVM)
-//
-// Copyright (C) 2006 Reid Spencer. All Rights Reserved.
-//
-// This software is free software; you can redistribute it and/or modify it 
-// under the terms of the GNU Lesser General Public License as published by 
-// the Free Software Foundation; either version 2.1 of the License, or (at 
-// your option) any later version.
-//
-// This software is distributed in the hope that it will be useful, but WITHOUT
-// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-// FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for 
-// more details.
-//
-// You should have received a copy of the GNU Lesser General Public License 
-// along with this library in the file named LICENSE.txt; if not, write to the 
-// Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
-// MA 02110-1301 USA
-//
-//===----------------------------------------------------------------------===//
-/// @file hlvm/Runtime/String.h
-/// @author Reid Spencer <rspencer at reidspencer.com> (original author)
-/// @date 2006/05/24
-/// @since 0.1.0
-/// @brief Declares the interface to the runtime string facilities
-//===----------------------------------------------------------------------===//
-
-#ifndef HLVM_RUNTIME_STRING_H
-#define HLVM_RUNTIME_STRING_H
-
-#include <llvm/Support/DataTypes.h>
-
-extern "C" {
-
-struct hlvm_string {
-  uint64_t    len;
-  const char* str;
-};
-
-}
-
-#endif

Copied: hlvm/trunk/hlvm/Runtime/Text.cpp (from r38176, hlvm/trunk/hlvm/Runtime/String.cpp)
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Runtime/Text.cpp?p2=hlvm/trunk/hlvm/Runtime/Text.cpp&p1=hlvm/trunk/hlvm/Runtime/String.cpp&r1=38176&r2=38179&rev=38179&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Runtime/String.cpp (original)
+++ hlvm/trunk/hlvm/Runtime/Text.cpp Sat Jul  7 19:00:47 2007
@@ -27,9 +27,46 @@
 /// @brief Implements the functions for runtime string support
 //===----------------------------------------------------------------------===//
 
-#include <hlvm/Runtime/String.h>
 #include <apr-1/apr_strings.h>
 
+#include <hlvm/Runtime/Internal.h>
+
+extern "C" {
+#include <hlvm/Runtime/Text.h>
+}
+
+namespace {
+
+class Text : public hlvm_text_obj {
+};
+
+}
+
 extern "C" {
 
+hlvm_text 
+hlvm_text_create(const char* initializer)
+{
+  Text* result = new Text();
+  if (initializer) {
+    result->len = strlen(initializer);
+    result->str = const_cast<char*>(initializer);
+    result->is_const = true;
+  } else {
+    result->len = 0;
+    result->str = 0;
+    result->is_const = false;
+  }
+  return hlvm_text(result);
+}
+
+void
+hlvm_text_delete(hlvm_text T)
+{
+  Text* t = reinterpret_cast<Text*>(T);
+  if (!t->is_const && t->str)
+    delete [] t->str;
+  delete t;
+}
+
 }

Copied: hlvm/trunk/hlvm/Runtime/Text.h (from r38176, hlvm/trunk/hlvm/Runtime/String.h)
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Runtime/Text.h?p2=hlvm/trunk/hlvm/Runtime/Text.h&p1=hlvm/trunk/hlvm/Runtime/String.h&r1=38176&r2=38179&rev=38179&view=diff

==============================================================================
--- hlvm/trunk/hlvm/Runtime/String.h (original)
+++ hlvm/trunk/hlvm/Runtime/Text.h Sat Jul  7 19:00:47 2007
@@ -30,15 +30,11 @@
 #ifndef HLVM_RUNTIME_STRING_H
 #define HLVM_RUNTIME_STRING_H
 
-#include <llvm/Support/DataTypes.h>
+#include <hlvm/Runtime/Memory.h>
 
-extern "C" {
+typedef struct hlvm_text_obj* hlvm_text;
 
-struct hlvm_string {
-  uint64_t    len;
-  const char* str;
-};
-
-}
+extern hlvm_text hlvm_text_create(const char* initializer);
+extern void hlvm_text_delete(hlvm_text T);
 
 #endif

Removed: hlvm/trunk/hlvm/Runtime/Utilities.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Runtime/Utilities.h?rev=38178&view=auto

==============================================================================
--- hlvm/trunk/hlvm/Runtime/Utilities.h (original)
+++ hlvm/trunk/hlvm/Runtime/Utilities.h (removed)
@@ -1,48 +0,0 @@
-//===-- Runtime Utilities Interface -----------------------------*- C++ -*-===//
-//
-//                      High Level Virtual Machine (HLVM)
-//
-// Copyright (C) 2006 Reid Spencer. All Rights Reserved.
-//
-// This software is free software; you can redistribute it and/or modify it 
-// under the terms of the GNU Lesser General Public License as published by 
-// the Free Software Foundation; either version 2.1 of the License, or (at 
-// your option) any later version.
-//
-// This software is distributed in the hope that it will be useful, but WITHOUT
-// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-// FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for 
-// more details.
-//
-// You should have received a copy of the GNU Lesser General Public License 
-// along with this library in the file named LICENSE.txt; if not, write to the 
-// Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
-// MA 02110-1301 USA
-//
-//===----------------------------------------------------------------------===//
-/// @file hlvm/Runtime/Utilities.h
-/// @author Reid Spencer <rspencer at reidspencer.com> (original author)
-/// @date 2006/06/05
-/// @since 0.1.0
-/// @brief Declares the interface to the runtime utilities
-//===----------------------------------------------------------------------===//
-
-#ifndef HLVM_RUNTIME_UTILITIES_H
-#define HLVM_RUNTIME_UTILITIES_H
-
-/// This is the HLVM runtime assert macro. It is very much similar to
-/// the <cassert> version but without some of the overhead. It also lets
-/// us take control of what to do when an assertion happens. The standard
-/// implementation just prints and aborts.
-#define hlvm_assert(expr) \
-  (static_cast<void>((expr) ? 0 : \
-    (hlvm_assert_fail(" #expr ", __FILE__, __LINE__))))
-
-
-/// This function gets called by the hlvm_assert macro, and in other situations
-/// where a "panic" happens. It provides the proper escape mechanism given the
-/// configuration of the runtime.
-void hlvm_assert_fail(const char* expression, const char* file, int line_num);
-
-
-#endif

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

==============================================================================
--- hlvm/trunk/hlvm/Writer/XML/XMLWriter.cpp (original)
+++ hlvm/trunk/hlvm/Writer/XML/XMLWriter.cpp Sat Jul  7 19:00:47 2007
@@ -34,14 +34,17 @@
 #include <hlvm/AST/Documentation.h>
 #include <hlvm/AST/ContainerType.h>
 #include <hlvm/AST/Variable.h>
+#include <hlvm/AST/Constants.h>
 #include <hlvm/AST/Program.h>
 #include <hlvm/AST/Block.h>
 #include <hlvm/AST/ControlFlow.h>
-#include <hlvm/AST/Constants.h>
+#include <hlvm/AST/MemoryOps.h>
+#include <hlvm/AST/InputOutput.h>
 #include <hlvm/Base/Assert.h>
 #include <hlvm/Pass/Pass.h>
 #include <llvm/ADT/StringExtras.h>
 #include <libxml/xmlwriter.h>
+//#include <libxml/entities.h>
 #include <iostream>
 
 using namespace hlvm;
@@ -91,39 +94,14 @@
       { xmlTextWriterWriteElement(writer,
           reinterpret_cast<const xmlChar*>(elem),
           reinterpret_cast<const xmlChar*>(body)); }
-    inline void writeString(const std::string& text)
-      { xmlTextWriterWriteString(writer,
-          reinterpret_cast<const xmlChar*>(text.c_str())); }
+    inline void writeString(const std::string& text) ;
 
     inline void putHeader();
     inline void putFooter();
     inline void putDoc(Documentable* node);
-    inline void put(Bundle* b);
-    inline void put(Documentation* b);
-    inline void put(AliasType* t);
-    inline void put(AnyType* t);
-    inline void put(BooleanType* t);
-    inline void put(CharacterType* t);
-    inline void put(IntegerType* t);
-    inline void put(RangeType* t);
-    inline void put(EnumerationType* t);
-    inline void put(RealType* t);
-    inline void put(OctetType* t);
-    inline void put(VoidType* t);
-    inline void put(PointerType* t);
-    inline void put(ArrayType* t);
-    inline void put(VectorType* t);
-    inline void put(StructureType* t);
-    inline void put(SignatureType* t);
-    inline void put(ConstantInteger* t);
-    inline void put(ConstantReal* t);
-    inline void put(ConstantText* t);
-    inline void put(ConstantZero* t);
-    inline void put(Variable* v);
-    inline void put(Function* f);
-    inline void put(Program* p);
-    inline void put(Block* f);
-    inline void put(ReturnOp* f);
+
+    template<class NodeClass>
+    inline void put(NodeClass* nc);
 
     virtual void handle(Node* n,Pass::TraversalKinds mode);
 
@@ -152,13 +130,13 @@
   return "error";
 }
 
-inline void
-XMLWriterImpl::WriterPass::putDoc(Documentable* node)
-{
-  Documentation* theDoc = node->getDoc();
-  if (theDoc) {
-    this->put(theDoc);
-  }
+void 
+XMLWriterImpl::WriterPass::writeString(const std::string& text)
+{ 
+  const xmlChar* str_to_write = // xmlEncodeSpecialChars(
+      reinterpret_cast<const xmlChar*>(text.c_str()); // ); 
+  xmlTextWriterWriteString(writer, str_to_write);
+  // xmlMemFree(str_to_write);
 }
 
 void
@@ -176,7 +154,8 @@
   endElement();
   xmlTextWriterEndDocument(writer);
 }
-void 
+
+template<> void 
 XMLWriterImpl::WriterPass::put(Documentation* b)
 {
   startElement("doc");
@@ -186,15 +165,25 @@
   endElement();
 }
 
-void 
+inline void
+XMLWriterImpl::WriterPass::putDoc(Documentable* node)
+{
+  Documentation* theDoc = node->getDoc();
+  if (theDoc) {
+    this->put<Documentation>(theDoc);
+  }
+}
+
+template<> void 
 XMLWriterImpl::WriterPass::put(AliasType* t)
 {
   startElement("alias");
   writeAttribute("id",t->getName());
-  writeAttribute("renames",t->getType());
+  writeAttribute("renames",t->getElementType());
   putDoc(t);
 }
-void 
+
+template<> void 
 XMLWriterImpl::WriterPass::put(AnyType* t)
 {
   startElement("atom");
@@ -205,7 +194,7 @@
   endElement();
 }
 
-void
+template<>void
 XMLWriterImpl::WriterPass::put(BooleanType* t)
 {
   startElement("atom");
@@ -216,7 +205,7 @@
   endElement();
 }
 
-void
+template<> void
 XMLWriterImpl::WriterPass::put(CharacterType* t)
 {
   startElement("atom");
@@ -227,7 +216,7 @@
   endElement();
 }
 
-void
+template<> void
 XMLWriterImpl::WriterPass::put(IntegerType* t)
 {
   startElement("atom");
@@ -247,7 +236,7 @@
   endElement();
 }
 
-void
+template<> void
 XMLWriterImpl::WriterPass::put(RangeType* t)
 {
   startElement("range");
@@ -257,7 +246,7 @@
   putDoc(t);
 }
 
-void 
+template<> void 
 XMLWriterImpl::WriterPass::put(EnumerationType* t)
 {
   startElement("enumeration");
@@ -272,8 +261,8 @@
   }
 }
 
-void
-XMLWriterImpl::WriterPass::put(RealType* t)
+template<> void
+XMLWriterImpl::WriterPass::put<RealType>(RealType* t)
 {
   startElement("atom");
   writeAttribute("id",t->getName());
@@ -291,8 +280,8 @@
   }
 }
 
-void
-XMLWriterImpl::WriterPass::put(OctetType* t)
+template<> void
+XMLWriterImpl::WriterPass::put<OctetType>(OctetType* t)
 {
   startElement("atom");
   writeAttribute("id",t->getName());
@@ -302,8 +291,8 @@
   endElement();
 }
 
-void
-XMLWriterImpl::WriterPass::put(VoidType* t)
+template<> void
+XMLWriterImpl::WriterPass::put<VoidType>(VoidType* t)
 {
   startElement("atom");
   writeAttribute("id",t->getName());
@@ -313,17 +302,25 @@
   endElement();
 }
 
-void 
-XMLWriterImpl::WriterPass::put(PointerType* t)
+template<> void
+XMLWriterImpl::WriterPass::put<OpaqueType>(OpaqueType* op)
+{
+  startElement("opaque");
+  writeAttribute("id",op->getName());
+  putDoc(op);
+}
+
+template<> void 
+XMLWriterImpl::WriterPass::put<PointerType>(PointerType* t)
 {
   startElement("pointer");
   writeAttribute("id", t->getName());
-  writeAttribute("to", t->getTargetType());
+  writeAttribute("to", t->getElementType());
   putDoc(t);
 }
 
-void 
-XMLWriterImpl::WriterPass::put(ArrayType* t)
+template<> void 
+XMLWriterImpl::WriterPass::put<ArrayType>(ArrayType* t)
 {
   startElement("array");
   writeAttribute("id", t->getName());
@@ -332,8 +329,8 @@
   putDoc(t);
 }
 
-void 
-XMLWriterImpl::WriterPass::put(VectorType* t)
+template<> void 
+XMLWriterImpl::WriterPass::put<VectorType>(VectorType* t)
 {
   startElement("vector");
   writeAttribute("id", t->getName());
@@ -342,8 +339,8 @@
   putDoc(t);
 }
 
-void 
-XMLWriterImpl::WriterPass::put(StructureType* t)
+template<> void 
+XMLWriterImpl::WriterPass::put<StructureType>(StructureType* t)
 {
   startElement("structure");
   writeAttribute("id",t->getName());
@@ -352,14 +349,14 @@
     startElement("field");
     AliasType* alias = cast<AliasType>(*I);
     writeAttribute("id",alias->getName());
-    writeAttribute("type",alias->getType());
+    writeAttribute("type",alias->getElementType());
     putDoc(alias);
     endElement();
   }
 }
 
-void 
-XMLWriterImpl::WriterPass::put(SignatureType* t)
+template<> void 
+XMLWriterImpl::WriterPass::put<SignatureType>(SignatureType* t)
 {
   startElement("signature");
   writeAttribute("id",t->getName());
@@ -370,14 +367,14 @@
     startElement("arg");
     AliasType* alias = cast<AliasType>(*I);
     writeAttribute("id",alias->getName());
-    writeAttribute("type",alias->getType());
+    writeAttribute("type",alias->getElementType());
     putDoc(alias);
     endElement();
   }
 }
 
-void 
-XMLWriterImpl::WriterPass::put(ConstantInteger* i)
+template<> void 
+XMLWriterImpl::WriterPass::put<ConstantInteger>(ConstantInteger* i)
 {
   startElement("dec");
   if (cast<IntegerType>(i->getType())->isSigned())
@@ -386,28 +383,28 @@
     writeString(llvm::utostr(i->getValue(0)));
 }
 
-void
-XMLWriterImpl::WriterPass::put(ConstantReal* r)
+template<> void
+XMLWriterImpl::WriterPass::put<ConstantReal>(ConstantReal* r)
 {
   startElement("dbl");
   writeString(llvm::ftostr(r->getValue()));
 }
 
-void
-XMLWriterImpl::WriterPass::put(ConstantText* t)
+template<> void
+XMLWriterImpl::WriterPass::put<ConstantText>(ConstantText* t)
 {
   startElement("text");
   writeString(t->getValue());
 }
 
-void
-XMLWriterImpl::WriterPass::put(ConstantZero* t)
+template<> void
+XMLWriterImpl::WriterPass::put<ConstantZero>(ConstantZero* t)
 {
   startElement("zero");
 }
 
-void
-XMLWriterImpl::WriterPass::put(Variable* v)
+template<> void
+XMLWriterImpl::WriterPass::put<Variable>(Variable* v)
 {
   startElement("variable");
   writeAttribute("id",v->getName());
@@ -415,8 +412,8 @@
   putDoc(v);
 }
 
-void
-XMLWriterImpl::WriterPass::put(Function* f)
+template<> void
+XMLWriterImpl::WriterPass::put<Function>(Function* f)
 {
   startElement("function");
   writeAttribute("id",f->getName());
@@ -425,16 +422,16 @@
   putDoc(f);
 }
 
-void 
-XMLWriterImpl::WriterPass::put(Program* p)
+template<> void 
+XMLWriterImpl::WriterPass::put<Program>(Program* p)
 {
   startElement("program");
   writeAttribute("id",p->getName());
   putDoc(p);
 }
 
-void 
-XMLWriterImpl::WriterPass::put(Block* b)
+template<> void 
+XMLWriterImpl::WriterPass::put<Block>(Block* b)
 {
   startElement("block");
   if (!b->getLabel().empty())
@@ -442,15 +439,71 @@
   putDoc(b);
 }
 
-void 
-XMLWriterImpl::WriterPass::put(ReturnOp* r)
+template<> void
+XMLWriterImpl::WriterPass::put<AutoVarOp>(AutoVarOp* av)
+{
+  startElement("autovar");
+  writeAttribute("id",av->getName());
+  writeAttribute("type",av->getType()->getName());
+  putDoc(av);
+}
+
+template<> void 
+XMLWriterImpl::WriterPass::put<ReturnOp>(ReturnOp* r)
 {
   startElement("ret");
   putDoc(r);
 }
 
-void 
-XMLWriterImpl::WriterPass::put(Bundle* b)
+template<> void 
+XMLWriterImpl::WriterPass::put(StoreOp* r)
+{
+  startElement("store");
+  putDoc(r);
+}
+
+template<> void 
+XMLWriterImpl::WriterPass::put(LoadOp* r)
+{
+  startElement("load");
+  putDoc(r);
+}
+
+template<> void 
+XMLWriterImpl::WriterPass::put(ReferenceOp* r)
+{
+  startElement("ref");
+  Value* ref = r->getReferent();
+  const std::string& name = 
+     (isa<Variable>(ref) ? cast<Variable>(ref)->getName() :
+      (isa<AutoVarOp>(ref) ? cast<AutoVarOp>(ref)->getName() : "oops" ));
+  writeAttribute("id",name);
+  putDoc(r);
+}
+
+template<> void 
+XMLWriterImpl::WriterPass::put(OpenOp* r)
+{
+  startElement("open");
+  putDoc(r);
+}
+
+template<> void 
+XMLWriterImpl::WriterPass::put(WriteOp* r)
+{
+  startElement("write");
+  putDoc(r);
+}
+
+template<> void 
+XMLWriterImpl::WriterPass::put(CloseOp* r)
+{
+  startElement("close");
+  putDoc(r);
+}
+
+template<> void 
+XMLWriterImpl::WriterPass::put<Bundle>(Bundle* b)
 {
   startElement("bundle");
   writeAttribute("id",b->getName());
@@ -463,31 +516,39 @@
   if (mode & Pass::PreOrderTraversal) {
     switch (n->getID()) 
     {
-      case AliasTypeID:               put(cast<AliasType>(n)); break;
-      case AnyTypeID:                 put(cast<AnyType>(n)); break;
-      case BooleanTypeID:             put(cast<BooleanType>(n)); break;
-      case BundleID:                  put(cast<Bundle>(n)); break;
-      case CharacterTypeID:           put(cast<CharacterType>(n)); break;
-      case IntegerTypeID:             put(cast<IntegerType>(n)); break;
-      case RangeTypeID:               put(cast<RangeType>(n)); break;
-      case EnumerationTypeID:         put(cast<EnumerationType>(n)); break;
-      case RealTypeID:                put(cast<RealType>(n)); break;
-      case OctetTypeID:               put(cast<OctetType>(n)); break;
-      case VoidTypeID:                put(cast<VoidType>(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 SignatureTypeID:           put(cast<SignatureType>(n)); break;
-      case ConstantIntegerID:         put(cast<ConstantInteger>(n)); break;
-      case ConstantRealID:            put(cast<ConstantReal>(n)); break;
-      case ConstantTextID:            put(cast<ConstantText>(n)); break;
-      case ConstantZeroID:            put(cast<ConstantZero>(n)); break;
-      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;
-      case ReturnOpID:                put(cast<ReturnOp>(n)); break;
+      case AliasTypeID:          put(cast<AliasType>(n)); break;
+      case AnyTypeID:            put(cast<AnyType>(n)); break;
+      case BooleanTypeID:        put(cast<BooleanType>(n)); break;
+      case BundleID:             put(cast<Bundle>(n)); break;
+      case CharacterTypeID:      put(cast<CharacterType>(n)); break;
+      case IntegerTypeID:        put(cast<IntegerType>(n)); break;
+      case RangeTypeID:          put(cast<RangeType>(n)); break;
+      case EnumerationTypeID:    put(cast<EnumerationType>(n)); break;
+      case RealTypeID:           put(cast<RealType>(n)); break;
+      case OctetTypeID:          put(cast<OctetType>(n)); break;
+      case VoidTypeID:           put(cast<VoidType>(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 SignatureTypeID:      put(cast<SignatureType>(n)); break;
+      case ConstantIntegerID:    put(cast<ConstantInteger>(n)); break;
+      case ConstantRealID:       put(cast<ConstantReal>(n)); break;
+      case ConstantTextID:       put(cast<ConstantText>(n)); break;
+      case ConstantZeroID:       put(cast<ConstantZero>(n)); break;
+      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;
+      case AutoVarOpID:          put(cast<AutoVarOp>(n)); break;
+      case ReturnOpID:           put(cast<ReturnOp>(n)); break;
+      case StoreOpID:            put(cast<StoreOp>(n)); break;
+      case LoadOpID:             put(cast<LoadOp>(n)); break;
+      case ReferenceOpID:        put(cast<ReferenceOp>(n)); break;
+      case OpenOpID:             put(cast<OpenOp>(n)); break;
+      case CloseOpID:            put(cast<CloseOp>(n)); break;
+      case WriteOpID:            put(cast<WriteOp>(n)); break;
       default:
         hlvmDeadCode("Unknown Type");
         break;

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

==============================================================================
--- hlvm/trunk/test/return0/helloworld.hlx (original)
+++ hlvm/trunk/test/return0/helloworld.hlx Sat Jul  7 19:00:47 2007
@@ -2,11 +2,9 @@
 <hlvm xmlns="http://hlvm.org/src/hlvm/Reader/XML/HLVM.rng"
       pubid="http://hlvm.org/src/hlvm/test/xml2xml/helloworld.hlx">
   <bundle id="helloworld">
-    <opaque id="stream"/>
-    <pointer id="streamp" to="stream"/>
     <program id="helloworld">
       <block>
-        <variable id="stdout" type="streamp"/>
+        <autovar id="stdout" type="stream"><zero/></autovar>
         <store>
           <ref id="stdout"/>
           <open><text>hlvm:std:out</text></open>
@@ -14,7 +12,6 @@
         <write>
           <load><ref id="stdout"/></load>
           <text>Hello, World
</text>
-          <dec>13</dec>
         </write>
         <close>
           <load><ref id="stdout"/></load>

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

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

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

==============================================================================
--- hlvm/trunk/test/xml2xml/array.hlx (original)
+++ hlvm/trunk/test/xml2xml/array.hlx Sat Jul  7 19:00:47 2007
@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <hlvm xmlns="http://hlvm.org/src/hlvm/Reader/XML/HLVM.rng" pubid="name">
   <bundle id="bundle">
+    <array id="anArray" of="someType" length="128"/>
     <atom id="someType">
       <intrinsic is="any"/>
     </atom>
-    <array id="anArray" of="someType" length="128"/>
   </bundle>
 </hlvm>

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

==============================================================================
--- hlvm/trunk/test/xml2xml/doc.hlx (original)
+++ hlvm/trunk/test/xml2xml/doc.hlx Sat Jul  7 19:00:47 2007
@@ -2,59 +2,10 @@
 <hlvm xmlns="http://hlvm.org/src/hlvm/Reader/XML/HLVM.rng" pubid="name">
   <bundle id="bundle">
     <doc><p>This is a documentation node for a bundle element</p></doc>
-    <atom id="someType">
-      <doc><p>Atom Doc</p></doc>
-      <intrinsic is="any"/>
-    </atom>
-    <alias id="anAlias" renames="someType">
-      <doc><p>Alias Doc</p></doc>
-    </alias>
-    <array id="anArray" of="someType" length="128">
-      <doc><p>Array Doc</p></doc>
-    </array>
-    <enumeration id="anEnumeration">
-      <doc>This is anEnumeration</doc>
-      <enumerator id="one"/>
-      <enumerator id="two"/>
-      <enumerator id="three"/>
-      <enumerator id="four"/>
-    </enumeration>
     <atom id="1">
       <doc>Any can hold anything. It provides the dynamic typing</doc>
       <intrinsic is="any"/>
     </atom>
-    <atom id="2">
-      <doc>Obviously this is a boolean</doc>
-      <intrinsic is="bool"/>
-    </atom>
-    <atom id="3">
-      <doc>UTF-16 character</doc>
-      <intrinsic is="char"/>
-    </atom>
-    <atom id="4">
-      <doc>IEEE Quad Floating Point (128 bits)</doc>
-      <intrinsic is="f128"/>
-    </atom>
-    <atom id="5">
-      <doc>IEEE Extended Double Floating Point (80 bits)</doc>
-      <intrinsic is="f80"/>
-    </atom>
-    <atom id="6">
-      <doc>IEEE Double Floating Point (64 bits)</doc>
-      <intrinsic is="f64"/>
-    </atom>
-    <atom id="7">
-      <doc>IEEE Extended Single Floating Point (43 bits)</doc>
-      <intrinsic is="f44"/>
-    </atom>
-    <atom id="8">
-      <doc>IEEE Single Floating Point (32 bits)</doc>
-      <intrinsic is="f32"/>
-    </atom>
-    <atom id="9">
-      <doc>Signed 128 bit integer</doc>
-      <intrinsic is="s128"/>
-    </atom>
     <atom id="10">
       <doc>Signed 64 bit integer</doc>
       <intrinsic is="s64"/>
@@ -95,14 +46,62 @@
       <doc>Unsigned 8 bit integer</doc>
       <intrinsic is="u8"/>
     </atom>
+    <atom id="2">
+      <doc>Obviously this is a boolean</doc>
+      <intrinsic is="bool"/>
+    </atom>
     <atom id="20">
       <doc>The void type, zero size</doc>
       <intrinsic is="void"/>
     </atom>
+    <atom id="3">
+      <doc>UTF-16 character</doc>
+      <intrinsic is="char"/>
+    </atom>
+    <atom id="4">
+      <doc>IEEE Quad Floating Point (128 bits)</doc>
+      <intrinsic is="f128"/>
+    </atom>
+    <atom id="5">
+      <doc>IEEE Extended Double Floating Point (80 bits)</doc>
+      <intrinsic is="f80"/>
+    </atom>
+    <atom id="6">
+      <doc>IEEE Double Floating Point (64 bits)</doc>
+      <intrinsic is="f64"/>
+    </atom>
+    <atom id="7">
+      <doc>IEEE Extended Single Floating Point (43 bits)</doc>
+      <intrinsic is="f44"/>
+    </atom>
+    <atom id="8">
+      <doc>IEEE Single Floating Point (32 bits)</doc>
+      <intrinsic is="f32"/>
+    </atom>
+    <atom id="9">
+      <doc>Signed 128 bit integer</doc>
+      <intrinsic is="s128"/>
+    </atom>
     <pointer id="aPointerType" to="someType">
       <doc>A Pointer Type</doc>
     </pointer>
-    <signature id="struct2" result="someType" varargs="true">
+    <vector id="aVector" of="f32" length="128">
+      <doc>Vector doc</doc>
+    </vector>
+    <alias id="anAlias" renames="someType">
+      <doc><p>Alias Doc</p></doc>
+    </alias>
+    <array id="anArray" of="someType" length="128">
+      <doc><p>Array Doc</p></doc>
+    </array>
+    <enumeration id="anEnumeration">
+      <doc>This is anEnumeration</doc>
+      <enumerator id="one"/>
+      <enumerator id="two"/>
+      <enumerator id="three"/>
+      <enumerator id="four"/>
+    </enumeration>
+    <signature id="sig1" result="someType" varargs="true">
       <doc>This is signature doc</doc>
       <arg id="arg1" type="someType">
         <doc>Doc for "arg1"</doc>
@@ -111,6 +110,10 @@
         <doc><i>Doc for "arg2"</i></doc>
       </arg>
     </signature>
+    <atom id="someType">
+      <doc><p>Atom Doc</p></doc>
+      <intrinsic is="any"/>
+    </atom>
     <structure id="struct2">
       <doc>This is structure doc</doc>
       <field id="field1" type="someType">
@@ -120,9 +123,6 @@
         <doc>Documentation for field 2</doc>
       </field>
     </structure>
-    <vector id="aVector" of="f32" length="128">
-      <doc>Vector doc</doc>
-    </vector>
     <variable id="var" type="int">
       <doc><p>This is documentation for a <i>var</i>iable</p></doc>
     </variable>

Added: hlvm/trunk/test/xml2xml/helloworld.hlx
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/xml2xml/helloworld.hlx?rev=38179&view=auto

==============================================================================
--- hlvm/trunk/test/xml2xml/helloworld.hlx (added)
+++ hlvm/trunk/test/xml2xml/helloworld.hlx Sat Jul  7 19:00:47 2007
@@ -0,0 +1,32 @@
+<?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/xml2xml/helloworld.hlx">
+  <bundle id="helloworld">
+    <program id="helloworld">
+      <block>
+        <autovar id="stdout" type="hlvm_stream">
+          <zero/>
+        </autovar>
+        <store>
+          <ref id="stdout"/>
+          <open>
+            <text>hlvm:std:out</text>
+          </open>
+        </store>
+        <write>
+          <load>
+            <ref id="stdout"/>
+          </load>
+          <text>Hello, World</text>
+        </write>
+        <close>
+          <load>
+            <ref id="stdout"/>
+          </load>
+        </close>
+        <ret>
+          <dec>0</dec>
+        </ret>
+      </block>
+    </program>
+  </bundle>
+</hlvm>

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

==============================================================================
--- hlvm/trunk/test/xml2xml/intrinsics.hlx (original)
+++ hlvm/trunk/test/xml2xml/intrinsics.hlx Sat Jul  7 19:00:47 2007
@@ -4,30 +4,6 @@
     <atom id="1">
       <intrinsic is="any"/>
     </atom>
-    <atom id="2">
-      <intrinsic is="bool"/>
-    </atom>
-    <atom id="3">
-      <intrinsic is="char"/>
-    </atom>
-    <atom id="4">
-      <intrinsic is="f128"/>
-    </atom>
-    <atom id="5">
-      <intrinsic is="f80"/>
-    </atom>
-    <atom id="6">
-      <intrinsic is="f64"/>
-    </atom>
-    <atom id="7">
-      <intrinsic is="f44"/>
-    </atom>
-    <atom id="8">
-      <intrinsic is="f32"/>
-    </atom>
-    <atom id="9">
-      <intrinsic is="s128"/>
-    </atom>
     <atom id="10">
       <intrinsic is="s64"/>
     </atom>
@@ -58,8 +34,32 @@
     <atom id="19">
       <intrinsic is="u8"/>
     </atom>
+    <atom id="2">
+      <intrinsic is="bool"/>
+    </atom>
     <atom id="20">
       <intrinsic is="void"/>
     </atom>
+    <atom id="3">
+      <intrinsic is="char"/>
+    </atom>
+    <atom id="4">
+      <intrinsic is="f128"/>
+    </atom>
+    <atom id="5">
+      <intrinsic is="f80"/>
+    </atom>
+    <atom id="6">
+      <intrinsic is="f64"/>
+    </atom>
+    <atom id="7">
+      <intrinsic is="f44"/>
+    </atom>
+    <atom id="8">
+      <intrinsic is="f32"/>
+    </atom>
+    <atom id="9">
+      <intrinsic is="s128"/>
+    </atom>
   </bundle>
 </hlvm>

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

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

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

==============================================================================
--- hlvm/trunk/test/xml2xml/resolve.hlx (original)
+++ hlvm/trunk/test/xml2xml/resolve.hlx Sat Jul  7 19:00:47 2007
@@ -1,6 +1,10 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <hlvm xmlns="http://hlvm.org/src/hlvm/Reader/XML/HLVM.rng" pubid="name">
   <bundle id="bundle">
+    <pointer id="PtrToSomeType" to="SomeType"/>
+    <atom id="SomeType">
+      <intrinsic is="any"/>
+    </atom>
     <structure id="struct1">
       <field id="field1" type="SomeType"/>
     </structure>
@@ -8,9 +12,5 @@
       <field id="field1" type="SomeType"/>
       <field id="field2" type="PtrToSomeType"/>
     </structure>
-    <pointer id="PtrToSomeType" to="SomeType"/>
-    <atom id="SomeType">
-      <intrinsic is="any"/>
-    </atom>
   </bundle>
 </hlvm>

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

==============================================================================
--- hlvm/trunk/test/xml2xml/signature.hlx (original)
+++ hlvm/trunk/test/xml2xml/signature.hlx Sat Jul  7 19:00:47 2007
@@ -1,12 +1,12 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <hlvm xmlns="http://hlvm.org/src/hlvm/Reader/XML/HLVM.rng" pubid="name">
   <bundle id="bundle">
-    <atom id="someType">
-      <intrinsic is="any"/>
-    </atom>
     <signature id="sig1" result="someType" varargs="false">
       <arg id="arg1" type="someType"/>
     </signature>
+    <atom id="someType">
+      <intrinsic is="any"/>
+    </atom>
     <signature id="struct2" result="someType" varargs="true">
       <arg id="arg1" type="someType"/>
       <arg id="arg1" type="someType"/>





More information about the llvm-commits mailing list