[llvm-commits] [hlvm] r38115 - in /hlvm/trunk: build/ hlvm/ hlvm/AST/ hlvm/CodeGen/ hlvm/CodeGen/LLVM/ hlvm/Reader/XML/ hlvm/Writer/XML/ test/ test/lib/ test/return0/ test/xml2xml/ tools/ tools/hlvm-compiler/

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


Author: reid
Date: Sat Jul  7 18:59:59 2007
New Revision: 38115

URL: http://llvm.org/viewvc/llvm-project?rev=38115&view=rev
Log:
FIRST CODE EMITTED:
This patch provides the hlvm-compiler tool to compile an AST to an LLVM 
representation of the program. Not much other than "return 0" is supported at
this point, but it does produce the correct code. The AST type system was
overhauld to make things easier to use. A new class of tests was added, return 0
which compile and run programs and expect them to return value 0.

Added:
    hlvm/trunk/hlvm/CodeGen/
    hlvm/trunk/hlvm/CodeGen/LLVM/
    hlvm/trunk/hlvm/CodeGen/LLVM/LLVMGenerator.cpp
    hlvm/trunk/hlvm/CodeGen/LLVM/LLVMGenerator.h
    hlvm/trunk/hlvm/CodeGen/LLVM/SConscript
    hlvm/trunk/hlvm/CodeGen/SConscript
    hlvm/trunk/test/lib/return0.exp
    hlvm/trunk/test/return0/
    hlvm/trunk/test/return0/dg.exp
    hlvm/trunk/test/return0/helloworld.hlx
    hlvm/trunk/test/return0/return0.hlx
    hlvm/trunk/tools/hlvm-compiler/
    hlvm/trunk/tools/hlvm-compiler/SConscript
    hlvm/trunk/tools/hlvm-compiler/hlvm-compiler.cpp
Modified:
    hlvm/trunk/build/check.py
    hlvm/trunk/build/configure.py
    hlvm/trunk/build/hlvm.py
    hlvm/trunk/hlvm/AST/AST.cpp
    hlvm/trunk/hlvm/AST/AST.h
    hlvm/trunk/hlvm/AST/Constants.cpp
    hlvm/trunk/hlvm/AST/Constants.h
    hlvm/trunk/hlvm/AST/ContainerType.cpp
    hlvm/trunk/hlvm/AST/ContainerType.h
    hlvm/trunk/hlvm/AST/Function.h
    hlvm/trunk/hlvm/AST/LinkageItem.h
    hlvm/trunk/hlvm/AST/Node.cpp
    hlvm/trunk/hlvm/AST/Node.h
    hlvm/trunk/hlvm/AST/Program.cpp
    hlvm/trunk/hlvm/AST/Program.h
    hlvm/trunk/hlvm/AST/Type.cpp
    hlvm/trunk/hlvm/AST/Type.h
    hlvm/trunk/hlvm/Reader/XML/XMLReader.cpp
    hlvm/trunk/hlvm/SConscript
    hlvm/trunk/hlvm/Writer/XML/XMLWriter.cpp
    hlvm/trunk/test/SConscript
    hlvm/trunk/test/xml2xml/return.hlx
    hlvm/trunk/tools/SConscript

Modified: hlvm/trunk/build/check.py
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/build/check.py?rev=38115&r1=38114&r2=38115&view=diff

==============================================================================
--- hlvm/trunk/build/check.py (original)
+++ hlvm/trunk/build/check.py Sat Jul  7 18:59:59 2007
@@ -28,6 +28,7 @@
   outf.write('set tmpdir "$objdir/tmp"\n')
   outf.write('set srcrootdir "' + env['AbsSrcRoot'] + '"\n')
   outf.write('set objrootdir "' + env['AbsObjRoot'] + '"\n')
+  outf.write('set llcpath "' + env['LLC'] + '"\n')
   outf.write('## All vars above are generated by scons. Do Not Edit!\n')
   outf.close()
   return 0
@@ -51,15 +52,16 @@
 def CheckMessage(target,source,env):
   return "Running DejaGNU Test Suite"
 
-def Check(env):
+def Check(env,dirs):
   checkAction = env.Action(CheckAction,CheckMessage)
   checkBuilder = env.Builder(action=checkAction,suffix='results')
   sitexpAction = env.Action(SiteExpAction,SiteExpMessage)
   sitexpBuilder = env.Builder(action=sitexpAction,suffix='exp')
   env.Append(BUILDERS = {'Check':checkBuilder,'SiteExp':sitexpBuilder})
   env.SiteExp('#test/site.exp',[])
-  env.Check(['#test/xml2xml.sum','#test/xml2xml.log'],
-            getTestCases('xml2xml',env)+['#test/site.exp'])
-  env.Alias('check','#test/xml2xml.log')
+  for dir in dirs:
+    env.Check(['#test/' + dir + '.sum','#test/' + dir + '.log'],
+              getTestCases(dir,env)+['#test/site.exp'])
+    env.Alias('check','#test/' + dir + '.log')
   return 1
 

Modified: hlvm/trunk/build/configure.py
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/build/configure.py?rev=38115&r1=38114&r2=38115&view=diff

==============================================================================
--- hlvm/trunk/build/configure.py (original)
+++ hlvm/trunk/build/configure.py Sat Jul  7 18:59:59 2007
@@ -132,7 +132,8 @@
 
 def CheckProgram(context,progname,varname,moredirs=[]):
   context.Message("Checking for " + progname + "...")
-  fname = context.env.WhereIs(progname,environ['PATH'])
+  paths = environ['PATH'] 
+  fname = context.env.WhereIs(progname,paths)
   ret = fname != None
   if ret:
     context.env[varname] = fname
@@ -181,6 +182,8 @@
 def CheckForPrograms(conf,env):
   if not conf.CheckProgram('gperf','GPERF'):
     env.Exit(1)
+  if not conf.CheckProgram('llc','LLC'):
+    env.Exit(1)
   if not conf.CheckProgram('runtest','RUNTEST'):
     env['RUNTEST'] = None
     print "*** TESTING DISABLED ***"

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

==============================================================================
--- hlvm/trunk/build/hlvm.py (original)
+++ hlvm/trunk/build/hlvm.py Sat Jul  7 18:59:59 2007
@@ -118,6 +118,7 @@
     env.Append(CCFLAGS=' -ggdb')
     env.Append(CXXFLAGS=' -ggdb')
     env.Append(CPPDEFINES={'HLVM_DEBUG':None})
+    env.Append(LINKFLAGS='-ggdb')
   else :
     VariantName+='d'
 
@@ -131,6 +132,7 @@
     VariantName+='O'
     env.Append(CCFLAGS=' -O3')
     env.Append(CXXFLAGS=' -O3')
+    env.Append(LINKFLAGS='-O3')
   else :
     VariantName+='o'
 

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

==============================================================================
--- hlvm/trunk/hlvm/AST/AST.cpp (original)
+++ hlvm/trunk/hlvm/AST/AST.cpp Sat Jul  7 18:59:59 2007
@@ -39,32 +39,84 @@
 #include <hlvm/AST/Block.h>
 #include <hlvm/AST/ControlFlow.h>
 #include <hlvm/AST/SymbolTable.h>
+#include <hlvm/Base/Assert.h>
+#include <llvm/Support/Casting.h>
 
 using namespace hlvm;
 
-namespace {
+namespace 
+{
+
 class ASTImpl : public AST
 {
   public:
-    ASTImpl() {}
+    ASTImpl()
+      : types(), vars(), funcs(), unresolvedTypes(), 
+        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)
+      {}
     ~ASTImpl();
 
+  protected:
+    virtual void insertChild(Node* child);
+    virtual void removeChild(Node* child);
+
   private:
     // Pool pool;
-    SymbolTable types;
-    SymbolTable vars;
-    SymbolTable funcs;
-    SymbolTable unresolvedTypes;
+    SymbolTable    types;
+    SymbolTable    vars;
+    SymbolTable    funcs;
+    SymbolTable    unresolvedTypes;
+    VoidType*      VoidSingleton;
+    BooleanType*   BooleanSingleton;
+    CharacterType* CharacterSingleton;
+    OctetType*     OctetSingleton;
+    IntegerType*   UInt8Singleton;
+    IntegerType*   UInt16Singleton;;
+    IntegerType*   UInt32Singleton;
+    IntegerType*   UInt64Singleton;
+    IntegerType*   UInt128Singleton;
+    IntegerType*   SInt8Singleton;
+    IntegerType*   SInt16Singleton;
+    IntegerType*   SInt32Singleton;
+    IntegerType*   SInt64Singleton;
+    IntegerType*   SInt128Singleton;  
+    RealType*      Float32Singleton;
+    RealType*      Float44Singleton;
+    RealType*      Float64Singleton;
+    RealType*      Float80Singleton;
+    RealType*      Float128Singleton;
+    SignatureType* ProgramTypeSingleton;
 
   public:
     Type* resolveType(const std::string& name);
     void addType(Type*);
+    virtual void setParent(Node* parent);
+    friend class AST;
 };
 
 ASTImpl::~ASTImpl()
 {
 }
 
+void 
+ASTImpl::insertChild(Node* child)
+{
+  hlvmAssert(llvm::isa<Bundle>(child) && "Can't insert that here");
+  bundles.push_back(llvm::cast<Bundle>(child));
+}
+
+void 
+ASTImpl::removeChild(Node* child)
+{
+  hlvmAssert(llvm::isa<Bundle>(child) && "Can't remove that here");
+}
+
 Type*
 ASTImpl::resolveType(const std::string& name)
 {
@@ -91,9 +143,16 @@
   types.insert(ty->getName(),ty);
 }
 
+void
+ASTImpl::setParent(Node* n)
+{
+  hlvmAssert(!"Can't set parent of root node (AST)");
+}
+
 }
 
-namespace hlvm {
+namespace hlvm 
+{
 
 AST* 
 AST::create()
@@ -142,7 +201,7 @@
   uint64_t bits, 
   bool isSigned )
 {
-  IntegerType* result = new IntegerType();
+  IntegerType* result = new IntegerType(IntegerTypeID);
   result->setBits(bits);
   result->setSigned(isSigned);
   result->setLocator(loc);
@@ -182,7 +241,7 @@
   uint32_t mantissa, 
   uint32_t exponent)
 {
-  RealType* result = new RealType();
+  RealType* result = new RealType(RealTypeID);
   result->setMantissa(mantissa);
   result->setExponent(exponent);
   result->setLocator(loc);
@@ -357,9 +416,25 @@
 Program*
 AST::new_Program(const Locator& loc, const std::string& id)
 {
+  ASTImpl* ast = static_cast<ASTImpl*>(this);
+  if (!ast->ProgramTypeSingleton) {
+    ast->ProgramTypeSingleton = new SignatureType();
+    ast->ProgramTypeSingleton->setLocator(loc);
+    ast->ProgramTypeSingleton->setName(id);
+    Type* intType = getPrimitiveType(SInt32TypeID);
+    ast->ProgramTypeSingleton->setResultType(intType);
+    ArrayType* arg_array = new_ArrayType(loc,"arg_array",
+      new_StringType(loc,"string"),0);
+    PointerType* args = new_PointerType(loc,"arg_array_ptr",arg_array);
+    Argument* param = new_Argument(loc,"args",args);
+    ast->ProgramTypeSingleton->addArgument(param);
+  }
+
   Program* result = new Program();
   result->setLocator(loc);
   result->setName(id);
+  result->setSignature(ast->ProgramTypeSingleton); 
+  result->setLinkageKind(ExternalLinkage);
   return result;
 }
 
@@ -387,4 +462,148 @@
   return result;
 }
 
+Argument* 
+AST::new_Argument(const Locator& loc, const std::string& id, Type* ty )
+{
+  Argument* result = new Argument();
+  result->setLocator(loc);
+  result->setName(id);
+  result->setType(ty);
+  return result;
+}
+
+StringType*
+AST::new_StringType(const Locator& loc, const std::string& id)
+{
+  StringType* result = new StringType(id);
+  result->setLocator(loc);
+  return result;
+}
+
+Type* 
+AST::getPrimitiveType(NodeIDs pid)
+{
+  ASTImpl* ast = static_cast<ASTImpl*>(this);
+  switch (pid) 
+  {
+    case VoidTypeID:
+      if (!ast->VoidSingleton) {
+        ast->VoidSingleton = new VoidType();
+        ast->VoidSingleton->setName("void");
+      }
+      return ast->VoidSingleton;
+    case BooleanTypeID:
+      if (!ast->BooleanSingleton) {
+        ast->BooleanSingleton = new BooleanType();
+        ast->BooleanSingleton->setName("bool");
+      }
+      return ast->BooleanSingleton;
+    case CharacterTypeID:
+      if (!ast->CharacterSingleton) {
+        ast->CharacterSingleton = new CharacterType();
+        ast->CharacterSingleton->setName("char");
+      }
+      return ast->CharacterSingleton;
+    case OctetTypeID:
+      if (!ast->OctetSingleton) {
+        ast->OctetSingleton = new OctetType();
+        ast->OctetSingleton->setName("octet");
+      }
+      return ast->OctetSingleton;
+    case UInt8TypeID:
+      if (!ast->UInt8Singleton) {
+        ast->UInt8Singleton = new IntegerType(UInt8TypeID,8,false);
+        ast->UInt8Singleton->setName("uint8_t");
+      }
+      return ast->UInt8Singleton;
+    case UInt16TypeID:
+      if (!ast->UInt16Singleton) {
+        ast->UInt16Singleton = new IntegerType(UInt16TypeID,16,false);
+        ast->UInt16Singleton->setName("uint16_t");
+      }
+      return ast->UInt16Singleton;
+    case UInt32TypeID:
+      if (!ast->UInt32Singleton) {
+        ast->UInt32Singleton = new IntegerType(UInt32TypeID,32,false);
+        ast->UInt32Singleton->setName("uint32_t");
+      }
+      return ast->UInt32Singleton;
+    case UInt64TypeID:
+      if (!ast->UInt64Singleton) {
+        ast->UInt64Singleton = new IntegerType(UInt64TypeID,64,false);
+        ast->UInt64Singleton->setName("uint64_t");
+      }
+      return ast->UInt64Singleton;
+    case UInt128TypeID:
+      if (!ast->UInt128Singleton) {
+        ast->UInt128Singleton = new IntegerType(UInt128TypeID,128,false);
+        ast->UInt128Singleton->setName("uint128_t");
+      }
+      return ast->UInt128Singleton;
+    case SInt8TypeID:
+      if (!ast->SInt8Singleton) {
+        ast->SInt8Singleton = new IntegerType(SInt8TypeID,8,false);
+        ast->SInt8Singleton->setName("int8_t");
+      }
+      return ast->SInt8Singleton;
+    case SInt16TypeID:
+      if (!ast->SInt16Singleton) {
+        ast->SInt16Singleton = new IntegerType(SInt16TypeID,16,false);
+        ast->SInt16Singleton->setName("int16_t");
+      }
+      return ast->SInt16Singleton;
+    case SInt32TypeID:
+      if (!ast->SInt32Singleton) {
+        ast->SInt32Singleton = new IntegerType(SInt32TypeID,32,false);
+        ast->SInt32Singleton->setName("int32_t");
+      }
+      return ast->SInt32Singleton;
+    case SInt64TypeID:
+      if (!ast->SInt64Singleton) {
+        ast->SInt64Singleton = new IntegerType(SInt64TypeID,64,false);
+        ast->SInt64Singleton->setName("int64_t");
+      }
+      return ast->SInt64Singleton;
+    case SInt128TypeID:
+      if (!ast->SInt128Singleton) {
+        ast->SInt128Singleton = new IntegerType(SInt128TypeID,128,false);
+        ast->SInt128Singleton->setName("int128_t");
+      }
+      return ast->SInt128Singleton;
+    case Float32TypeID:
+      if (!ast->Float32Singleton) {
+        ast->Float32Singleton = new RealType(Float32TypeID,23,8);
+        ast->Float32Singleton->setName("f32");
+      }
+      return ast->Float32Singleton;
+    case Float44TypeID:
+      if (!ast->Float44Singleton) {
+        ast->Float44Singleton = new RealType(Float44TypeID,32,11);
+        ast->Float44Singleton->setName("f44");
+      }
+      return ast->Float44Singleton;
+    case Float64TypeID:
+      if (!ast->Float64Singleton) {
+        ast->Float64Singleton = new RealType(Float64TypeID,52,11);
+        ast->Float64Singleton->setName("f64");
+      }
+      return ast->Float64Singleton;
+    case Float80TypeID:
+      if (!ast->Float80Singleton) {
+        ast->Float80Singleton = new RealType(Float80TypeID,64,15);
+        ast->Float80Singleton->setName("f80");
+      }
+      return ast->Float80Singleton;
+    case Float128TypeID:
+      if (!ast->Float128Singleton) {
+        ast->Float128Singleton = new RealType(Float128TypeID,112,15);
+        ast->Float128Singleton->setName("f128");
+      }
+      return ast->Float128Singleton;
+    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=38115&r1=38114&r2=38115&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/AST.h (original)
+++ hlvm/trunk/hlvm/AST/AST.h Sat Jul  7 18:59:59 2007
@@ -30,6 +30,8 @@
 #ifndef HLVM_AST_AST_H
 #define HLVM_AST_AST_H
 
+#include <hlvm/AST/Node.h>
+#include <hlvm/AST/Type.h>
 #include <string>
 #include <vector>
 
@@ -47,38 +49,25 @@
 class Import;
 class Locator; 
 class SignatureType;
-class Type;
-class Variable; 
-class AnyType;
-class BooleanType;
-class CharacterType;
-class OctetType;
-class VoidType;
-class IntegerType;
-class RangeType;
-class RealType;
-class PointerType;
-class VectorType;
-class ArrayType;
-class AliasType;
 class StructureType;
-class SignatureType;
-class OpaqueType;
-class EnumerationType;
+class Variable; 
 class ConstLiteralInteger;
 class ReturnOp;
+class AliasType;
+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.
 /// @brief AST Container Class
-class AST
+class AST : public Node
 {
   /// @name Types
   /// @{
   public:
-    typedef std::vector<Bundle*> NodeList;
-    typedef NodeList::iterator   iterator;
-    typedef NodeList::const_iterator const_iterator;
+    typedef std::vector<Bundle*> BundleList;
+    typedef BundleList::iterator   iterator;
+    typedef BundleList::const_iterator const_iterator;
 
   /// @}
   /// @name Constructors
@@ -88,15 +77,15 @@
     static void destroy(AST* ast);
 
   protected:
-    AST() : sysid(), pubid(), nodes(0) {}
+    AST() : Node(TreeTopID), sysid(), pubid(), bundles() {}
     ~AST();
 
   /// @}
   /// @name Accessors
   /// @{
   public:
-    const std::string& getSystemID() { return sysid; }
-    const std::string& getPublicID() { return pubid; }
+    const std::string& getSystemID() const { return sysid; }
+    const std::string& getPublicID() const { return pubid; }
 
   /// @}
   /// @name Mutators
@@ -104,7 +93,7 @@
   public:
     void setSystemID(const std::string& id) { sysid = id; }
     void setPublicID(const std::string& id) { pubid = id; }
-    void addBundle(Bundle* b) { nodes.push_back(b); }
+    void addBundle(Bundle* b) { bundles.push_back(b); }
 
   /// @}
   /// @name Lookup
@@ -116,16 +105,16 @@
   /// @name Iterators
   /// @{
   public:
-    iterator           begin()       { return nodes.begin(); }
-    const_iterator     begin() const { return nodes.begin(); }
-    iterator           end  ()       { return nodes.end(); }
-    const_iterator     end  () const { return nodes.end(); }
-    size_t             size () const { return nodes.size(); }
-    bool               empty() const { return nodes.empty(); }
-    Bundle*            front()       { return nodes.front(); }
-    const Bundle*      front() const { return nodes.front(); }
-    Bundle*            back()        { return nodes.back(); }
-    const Bundle*      back()  const { return nodes.back(); }
+    iterator           begin()       { return bundles.begin(); }
+    const_iterator     begin() const { return bundles.begin(); }
+    iterator           end  ()       { return bundles.end(); }
+    const_iterator     end  () const { return bundles.end(); }
+    size_t             size () const { return bundles.size(); }
+    bool               empty() const { return bundles.empty(); }
+    Bundle*            front()       { return bundles.front(); }
+    const Bundle*      front() const { return bundles.front(); }
+    Bundle*            back()        { return bundles.back(); }
+    const Bundle*      back()  const { return bundles.back(); }
 
   /// @}
   /// @name Factories
@@ -229,8 +218,14 @@
     IntegerType* new_u8(const Locator& l, const std::string& id)
       { return new_IntegerType(l,id,8,false); }
 
+    Argument* 
+      new_Argument(const Locator& loc, const std::string& id, Type* ty );
+
+    StringType* new_StringType(const Locator& loc, const std::string& id);
+
     ConstLiteralInteger* new_ConstLiteralInteger(const Locator& loc);
     Documentation* new_Documentation(const Locator& loc);
+    Type* getPrimitiveType(NodeIDs kind);
 
   /// @}
   /// @name Data
@@ -238,7 +233,7 @@
   protected:
     std::string sysid;
     std::string pubid;
-    NodeList nodes;
+    BundleList bundles;;
   /// @}
 };
 

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Constants.cpp (original)
+++ hlvm/trunk/hlvm/AST/Constants.cpp Sat Jul  7 18:59:59 2007
@@ -28,6 +28,7 @@
 //===----------------------------------------------------------------------===//
 
 #include <hlvm/AST/Constants.h>
+#include <hlvm/AST/Type.h>
 
 namespace hlvm {
 

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Constants.h (original)
+++ hlvm/trunk/hlvm/AST/Constants.h Sat Jul  7 18:59:59 2007
@@ -46,14 +46,15 @@
     static ConstLiteralInteger* create();
 
   protected:
-    ConstLiteralInteger() : NilaryOperator(ConstLiteralIntegerOpID)  {}
+    ConstLiteralInteger() : NilaryOperator(ConstLiteralIntegerOpID) {}
     virtual ~ConstLiteralInteger();
 
   /// @}
   /// @name Accessors
   /// @{
   public:
-    uint64_t getValue() { return value; }
+    uint64_t getValue(int) const { return value.u; }
+    int64_t  getValue()    const { return value.s; }
     static inline bool classof(const ConstLiteralInteger*) { return true; }
     static inline bool classof(const Node* N) 
       { return N->is(ConstLiteralIntegerOpID); }
@@ -62,13 +63,17 @@
   /// @name Accessors
   /// @{
   public:
-    void setValue(uint64_t v) { value = v; }
+    void setValue(uint64_t v) { value.u = v; }
+    void setValue(int64_t v)  { value.s = v; }
 
   /// @}
   /// @name Data
   /// @{
   public:
-    uint64_t value;
+    union {
+      uint64_t u;
+      int64_t  s;
+    } value;
   /// @}
   friend class AST;
 };

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

==============================================================================
--- hlvm/trunk/hlvm/AST/ContainerType.cpp (original)
+++ hlvm/trunk/hlvm/AST/ContainerType.cpp Sat Jul  7 18:59:59 2007
@@ -29,6 +29,7 @@
 
 #include <hlvm/AST/ContainerType.h>
 #include <hlvm/Base/Assert.h>
+#include <llvm/ADT/StringExtras.h>
 
 using namespace llvm;
 
@@ -41,8 +42,8 @@
 void 
 ContainerType::insertChild(Node* n)
 {
-  hlvmAssert(isa<Type>(n) && "Can't insert those here");
-  types.push_back(cast<Type>(n));
+  hlvmAssert(isa<AliasType>(n) && "Can't insert those here");
+  contents.push_back(cast<AliasType>(n));
 }
 
 void 
@@ -51,7 +52,7 @@
   hlvmAssert(isa<Type>(n) && "Can't remove those here");
   // This is sucky slow, but we probably won't be removing nodes that much.
   for (iterator I = begin(), E = end(); I != E; ++I ) {
-    if (*I == n) { types.erase(I); break; }
+    if (*I == n) { contents.erase(I); break; }
   }
   hlvmAssert(!"That node isn't my child");
 }
@@ -66,22 +67,8 @@
 {
 }
 
-void
-StructureType::insertChild(Node* n)
-{
-  hlvmAssert(isa<AliasType>(n) && "Can't insert those here");
-  types.push_back(cast<AliasType>(n));
-}
-
 SignatureType::~SignatureType()
 {
 }
 
-void 
-SignatureType::insertChild(Node* n)
-{
-  hlvmAssert(isa<AliasType>(n) && "Can't insert those here");
-  types.push_back(cast<AliasType>(n));
-}
-
 }

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

==============================================================================
--- hlvm/trunk/hlvm/AST/ContainerType.h (original)
+++ hlvm/trunk/hlvm/AST/ContainerType.h Sat Jul  7 18:59:59 2007
@@ -43,17 +43,15 @@
   /// @name Types
   /// @{
   public:
-    typedef std::vector<Type*> TypeList;
-    typedef TypeList::iterator iterator;
-    typedef TypeList::const_iterator const_iterator;
+    typedef std::vector<AliasType*> ContentsList;
+    typedef ContentsList::iterator iterator;
+    typedef ContentsList::const_iterator const_iterator;
 
   /// @}
   /// @name Constructors
   /// @{
-  public:
-    ContainerType(
-      NodeIDs id ///< The node id of the subclass
-    ) : Type(id), types() {}
+  protected:
+    ContainerType(NodeIDs id) : Type(id), contents() {}
     virtual ~ContainerType();
 
   /// @}
@@ -66,9 +64,9 @@
     static inline bool classof(const Type* T) { return T->isContainerType(); }
 
   /// @}
-  /// @name Accessors
+  /// @name Mutators
   /// @{
-  public:
+  protected:
     virtual void insertChild(Node* n);
     virtual void removeChild(Node* n);
 
@@ -76,25 +74,27 @@
   /// @name Iterators
   /// @{
   public:
-    iterator       begin()       { return types.begin(); }
-    const_iterator begin() const { return types.begin(); }
-    iterator       end  ()       { return types.end(); }
-    const_iterator end  () const { return types.end(); }
-    size_t         size () const { return types.size(); }
-    bool           empty() const { return types.empty(); }
-    Type*          front()       { return types.front(); }
-    const Type*    front() const { return types.front(); }
-    Type*          back()        { return types.back(); }
-    const Type*    back()  const { return types.back(); }
+    iterator         begin()       { return contents.begin(); }
+    const_iterator   begin() const { return contents.begin(); }
+    iterator         end  ()       { return contents.end(); }
+    const_iterator   end  () const { return contents.end(); }
+    size_t           size () const { return contents.size(); }
+    bool             empty() const { return contents.empty(); }
+    AliasType*       front()       { return contents.front(); }
+    const AliasType* front() const { return contents.front(); }
+    AliasType*       back()        { return contents.back(); }
+    const AliasType* back()  const { return contents.back(); }
 
   /// @}
   /// @name Data
   /// @{
   protected:
-    std::vector<Type*> types; ///< The contained types
+    ContentsList contents; ///< The contained types
   /// @}
 };
 
+typedef AliasType Field;
+
 /// This class represents an HLVM type that is a sequence of data fields 
 /// of varying type. 
 class StructureType : public ContainerType
@@ -116,10 +116,10 @@
       { return T->is(StructureTypeID); }
 
   /// @}
-  /// @name Accessors
+  /// @name Mutators
   /// @{
-  public:
-    virtual void insertChild(Node* n);
+  protected:
+    void addField(Field* field) { contents.push_back(field); }
 
   /// @}
   /// @name Data
@@ -128,6 +128,8 @@
   /// @}
 };
 
+typedef AliasType Argument;
+
 /// This class represents an HLVM type that is a sequence of data fields 
 /// of varying type. 
 class SignatureType : public ContainerType
@@ -153,12 +155,12 @@
       { return T->is(SignatureTypeID); }
 
   /// @}
-  /// @name Accessors
+  /// @name Mutators
   /// @{
   public:
     void setResultType(Type* ty) { result = ty; }
     void setIsVarArgs(bool is) { varargs = is; }
-    virtual void insertChild(Node* n);
+    void addArgument(Argument* arg) { contents.push_back(arg); }
 
   /// @}
   /// @name Data

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Function.h (original)
+++ hlvm/trunk/hlvm/AST/Function.h Sat Jul  7 18:59:59 2007
@@ -68,7 +68,7 @@
   public:
     virtual void insertChild(Node* kid);
     virtual void removeChild(Node* kid);
-    void setSignature(SignatureType* sig) { sig->setParent(this); }
+    void setSignature(SignatureType* sig) { signature = sig; }
     void setBlock(Block* blk) { blk->setParent(this); }
 
   /// @}

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

==============================================================================
--- hlvm/trunk/hlvm/AST/LinkageItem.h (original)
+++ hlvm/trunk/hlvm/AST/LinkageItem.h Sat Jul  7 18:59:59 2007
@@ -39,10 +39,10 @@
 /// permitted for a LinkageItem.
 enum LinkageKinds {
   ExternalLinkage,    ///< Externally visible item
-  InternalLinkage,    ///< Rename collisions when linking (static funcs)
   LinkOnceLinkage,    ///< Keep one copy of item when linking (inline)
   WeakLinkage,        ///< Keep one copy of item when linking (weak)
-  AppendingLinkage    ///< Append item to an array of similar items
+  AppendingLinkage,   ///< Append item to an array of similar items
+  InternalLinkage     ///< Rename collisions when linking (static funcs)
 };
 
 /// This class represents an LinkageItem in the HLVM Abstract Syntax Tree. 

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Node.cpp (original)
+++ hlvm/trunk/hlvm/AST/Node.cpp Sat Jul  7 18:59:59 2007
@@ -28,7 +28,9 @@
 //===----------------------------------------------------------------------===//
 
 #include <hlvm/AST/Node.h>
+#include <hlvm/AST/AST.h>
 #include <hlvm/Base/Assert.h>
+#include <llvm/Support/Casting.h>
 
 namespace hlvm {
 
@@ -36,6 +38,16 @@
 {
 }
 
+AST*
+Node::getRoot()
+{
+  Node* p = parent, *last = this; 
+  while (p!=0) { 
+    last = p; 
+    p = p->parent; 
+  }
+  return llvm::cast<AST>(last);
+}
 
 void 
 Node::insertChild(Node* child)

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Node.h (original)
+++ hlvm/trunk/hlvm/AST/Node.h Sat Jul  7 18:59:59 2007
@@ -39,8 +39,15 @@
 
 class Type;
 class Documentation;
+class AST;
 
-/// This enumeration is used to identify a specific type. Its organization is
+/// This enumeration is used to identify the primitive types. Each of these 
+/// types is a node with a NodeID but they are treated specially because of
+/// their frequency of use. 
+enum PrimitiveTypes {
+};
+
+/// This enumeration is used to identify a specific node. Its organization is
 /// very specific and dependent on the class hierarchy. In order to use these
 /// values as ranges for class identification (classof methods), we need to 
 /// group things by inheritance rather than by function. 
@@ -49,10 +56,25 @@
   NoTypeID = 0,            ///< Use this for an invalid type ID.
   // Primitive Types (no child nodes)
   VoidTypeID = 1,          ///< The Void Type (The Null Type)
-  AnyTypeID,               ///< The Any Type (Union of any type)
   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)
+  UInt8TypeID,             ///< Unsigned 8-bit integer quantity
+  UInt16TypeID,            ///< Unsigned 16-bit integer quantity
+  UInt32TypeID,            ///< Unsigned 32-bit integer quantity
+  UInt64TypeID,            ///< Unsigned 64-bit integer quantity
+  UInt128TypeID,           ///< Unsigned 128-bit integer quantity
+  SInt8TypeID,             ///< Signed 8-bit integer quantity
+  SInt16TypeID,            ///< Signed 16-bit integer quantity
+  SInt32TypeID,            ///< Signed 32-bit integer quantity
+  SInt64TypeID,            ///< Signed 64-bit integer quantity
+  SInt128TypeID,           ///< Signed 128-bit integer quantity
+  Float32TypeID,           ///< 32-bit IEEE single precision 
+  Float44TypeID,           ///< 43-bit IEEE extended single precision 
+  Float64TypeID,           ///< 64-bit IEEE double precision
+  Float80TypeID,           ///< 80-bit IEEE extended double precision
+  Float128TypeID,          ///< 128-bit IEEE quad precision
+  AnyTypeID,               ///< The Any Type (Union of any type)
   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)
@@ -125,17 +147,17 @@
 
   // Memory Unary Operators
   LoadOpID,                ///< The Load Operator (load a value from a location)
-  AllocateOpID,            ///< The Allocate Memory Operator (get some heap memory)
-  FreeOpID,                ///< The Free Memory Operator (free some heap memory)
-  StackAllocOpID,          ///< The Stack Allocation Operator (get some stack mem)
-  ReferenceOpID,           ///< The Reference A Memory Object Operator (for GC)
-  DereferenceOpID,         ///< The Dereference A Memory Object Operator (for GC)
+  AllocateOpID,            ///< The Allocate Memory Operator (get heap memory)
+  FreeOpID,                ///< The Free Memory Operator (free heap memory)
+  StackAllocOpID,          ///< The Stack Allocation Operator (get stack mem)
+  ReferenceOpID,           ///< The Reference Memory Object Operator (for GC)
+  DereferenceOpID,         ///< The Dereference Memory Object Operator (for GC)
 
   // Other 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, e.g.using) 
+  WithOpID,                ///< Scoping Operator (shorthand for a Bundle) 
 
   // Arithmetic Binary Operators
   AddOpID,                 ///< Addition Binary Operator
@@ -192,11 +214,14 @@
 
   // 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  = StringTypeID, ///< Last Primitive Type
+  LastPrimitiveTypeID  = Float128TypeID, ///< Last Primitive Type
+  FirstSimpleTypeID    = AnyTypeID,
+  LastSimpleTypeID     = StringTypeID,
   FirstContainerTypeID = PointerTypeID, ///< First Container Type
   LastContainerTypeID  = ContinuationTypeID, ///< Last Container Type
   FirstTypeID          = VoidTypeID,
@@ -233,6 +258,8 @@
   /// @name Accessors
   /// @{
   public:
+    inline AST* getRoot(); 
+
     /// Get the type of node
     inline NodeIDs getID() const { return NodeIDs(id); }
 
@@ -252,6 +279,43 @@
     inline bool isType() const {
       return id >= FirstTypeID && id <= LastTypeID;
     }
+
+    inline bool isIntegralType()  const { 
+      return (id >= UInt8TypeID && id <= UInt128TypeID) ||
+             (id == IntegerTypeID) || (id == RangeTypeID) || 
+             (id == EnumerationTypeID);
+    }
+
+    /// Determine if the node is a primitive type
+    inline bool isPrimitiveType() const {
+      return id >= FirstPrimitiveTypeID && id <= LastPrimitiveTypeID;
+    }
+
+    /// Determine if the node is a simple type
+    inline bool isSimpleType() const {
+      return id >= FirstSimpleTypeID && id <= LastSimpleTypeID;
+    }
+
+    /// 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 any of the Operators
     inline bool isOperator() const { 
       return id >= FirstOperatorID && id <= LastOperatorID;

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Program.cpp (original)
+++ hlvm/trunk/hlvm/AST/Program.cpp Sat Jul  7 18:59:59 2007
@@ -32,18 +32,6 @@
 
 using namespace hlvm;
 
-namespace {
-SignatureType* initSignature() {
-  SignatureType* result = new SignatureType();
-  result->setName("_hlvm_ProgramSignature");
-  return result;
-}
-}
-
-
-SignatureType* 
-Program::SignatureTy = initSignature();
-
 Program::~Program()
 {
 }

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Program.h (original)
+++ hlvm/trunk/hlvm/AST/Program.h Sat Jul  7 18:59:59 2007
@@ -49,9 +49,9 @@
 {
   /// @name Constructors
   /// @{
-  public:
-    Program() : Function(ProgramID) 
-    { setSignature(SignatureTy); setLinkageKind(ExternalLinkage); }
+  protected:
+    Program() : Function(ProgramID) {}
+      
     virtual ~Program();
 
   /// @}
@@ -66,7 +66,6 @@
   /// @name Data
   /// @{
   private:
-    static SignatureType* SignatureTy; ///< The signature for programs
     LinkageItem::setLinkageKind;
   /// @}
   friend class AST;

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Type.cpp (original)
+++ hlvm/trunk/hlvm/AST/Type.cpp Sat Jul  7 18:59:59 2007
@@ -82,6 +82,14 @@
 {
 }
 
+IntegerType* 
+IntegerType::clone(const std::string& newname)
+{
+  IntegerType* result = new IntegerType(*this);
+  result->setName(newname);
+  return result;
+}
+
 const char* 
 IntegerType::getPrimitiveName() const
 {
@@ -237,6 +245,10 @@
   return type->getPrimitiveName();
 }
 
+StringType::~StringType()
+{
+}
+
 OpaqueType::~OpaqueType()
 {
 }

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Type.h (original)
+++ hlvm/trunk/hlvm/AST/Type.h Sat Jul  7 18:59:59 2007
@@ -60,27 +60,6 @@
   /// @name Type Identification
   /// @{
   public:
-    inline bool isPrimitiveType() const { return id <= LastPrimitiveTypeID; }
-    inline bool isIntegralType()  const { 
-      return id == IntegerTypeID || id == RangeTypeID; 
-    }
-    inline bool isContainerType() const { 
-      return id >= FirstContainerTypeID; 
-    }
-    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; }
 
     // Methods to support type inquiry via is, cast, dyn_cast
     static inline bool classof(const Type*) { return true; }
@@ -221,12 +200,18 @@
 /// it implies infinite precision integer arithmetic.
 class IntegerType : public Type
 {
+  /// @name Types
+  /// @{
+  public:
   /// @name Constructors
   /// @{
   protected:
-    IntegerType() : Type(IntegerTypeID), numBits(32), signedness(true) {}
+    IntegerType(NodeIDs id, int bits = 32, bool sign = true) 
+      : Type(id), numBits(bits), signedness(sign) {}
   public:
     virtual ~IntegerType();
+    IntegerType* clone(const std::string& newname);
+
 
   /// @}
   /// @name Accessors
@@ -242,8 +227,8 @@
 
     // 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->isIntegerType(); }
-    static inline bool classof(const Node* T) { return T->is(IntegerTypeID); }
+    static inline bool classof(const Type* T) { return T->isIntegralType(); }
+    static inline bool classof(const Node* T) { return T->isIntegralType(); }
 
   /// @}
   /// @name Mutators
@@ -387,7 +372,8 @@
   /// @name Constructors
   /// @{
   protected:
-    RealType() : Type(RealTypeID), mantissa(52), exponent(11) {}
+    RealType(NodeIDs id, uint32_t m=52, uint32_t x=11) 
+      : Type(id), mantissa(m), exponent(x) {}
   public:
     virtual ~RealType();
 
@@ -442,7 +428,7 @@
   /// @{
   public:
     // Get the target type
-    Type* getTargetType() { return type; }
+    Type* getTargetType() const { return type; }
 
     // Methods to support type inquiry via is, cast, dyn_cast
     static inline bool classof(const PointerType*) { return true; }
@@ -470,9 +456,8 @@
 {
   /// @name Constructors
   /// @{
-  protected:
-    ArrayType() : Type(ArrayTypeID), type(0), maxSize(0) {}
   public:
+    ArrayType() : Type(ArrayTypeID), type(0), maxSize(0) {}
     virtual ~ArrayType();
 
   /// @}
@@ -596,6 +581,28 @@
   /// @}
 };
 
+class StringType : public Type
+{
+  /// @name Constructors
+  /// @{
+  public:
+    StringType(const std::string& nm) : 
+      Type(StringTypeID) { this->setName(nm); }
+  public:
+    virtual ~StringType();
+
+  /// @}
+  /// @name Accessors
+  /// @{
+  public:
+    static inline bool classof(const StringType*) { return true; }
+    static inline bool classof(const Node* N) 
+      { return N->is(StringTypeID); }
+
+  /// @}
+  friend class AST;
+};
+
 class OpaqueType : public Type
 {
   /// @name Constructors

Added: hlvm/trunk/hlvm/CodeGen/LLVM/LLVMGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/CodeGen/LLVM/LLVMGenerator.cpp?rev=38115&view=auto

==============================================================================
--- hlvm/trunk/hlvm/CodeGen/LLVM/LLVMGenerator.cpp (added)
+++ hlvm/trunk/hlvm/CodeGen/LLVM/LLVMGenerator.cpp Sat Jul  7 18:59:59 2007
@@ -0,0 +1,434 @@
+//===-- HLVM to LLVM Code Generator -----------------------------*- 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/CodeGen/LLVM/LLVMGenerator.cpp
+/// @author Reid Spencer <rspencer at x10sys.com>
+/// @date 2006/05/12
+/// @since 0.1.0
+/// @brief Provides the implementation of the HLVM -> LLVM Code Generator
+//===----------------------------------------------------------------------===//
+
+#include <hlvm/CodeGen/LLVM/LLVMGenerator.h>
+#include <hlvm/AST/AST.h>
+#include <hlvm/AST/Bundle.h>
+#include <hlvm/AST/Import.h>
+#include <hlvm/AST/Documentation.h>
+#include <hlvm/AST/ContainerType.h>
+#include <hlvm/AST/Variable.h>
+#include <hlvm/AST/Program.h>
+#include <hlvm/AST/Block.h>
+#include <hlvm/AST/ControlFlow.h>
+#include <hlvm/AST/Constants.h>
+#include <hlvm/Base/Assert.h>
+#include <hlvm/Pass/Pass.h>
+#include <llvm/Module.h>
+#include <llvm/BasicBlock.h>
+#include <llvm/Function.h>
+#include <llvm/Instructions.h>
+#include <llvm/DerivedTypes.h>
+#include <llvm/TypeSymbolTable.h>
+#include <llvm/Constants.h>
+#include <llvm/Linker.h>
+#include <llvm/Bytecode/Writer.h>
+#include <llvm/PassManager.h>
+#include <llvm/Assembly/PrintModulePass.h>
+
+using namespace hlvm;
+
+namespace 
+{
+
+class LLVMGeneratorPass : public Pass
+{
+  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) { }
+    ~LLVMGeneratorPass() { }
+
+  /// Conversion functions
+  inline const llvm::Type* getType(const Type* ty);
+  inline llvm::GlobalValue::LinkageTypes getLinkageTypes(LinkageKinds lk);
+  inline std::string getLinkageName(LinkageItem* li);
+
+  /// Generators
+  inline void gen(Bundle* b);
+  inline void gen(AliasType* t);
+  inline void gen(AnyType* t);
+  inline void gen(BooleanType* t);
+  inline void gen(CharacterType* t);
+  inline void gen(IntegerType* t);
+  inline void gen(RangeType* t);
+  inline void gen(EnumerationType* t);
+  inline void gen(RealType* t);
+  inline void gen(OctetType* t);
+  inline void gen(VoidType* t);
+  inline void gen(PointerType* t);
+  inline void gen(ArrayType* t);
+  inline void gen(VectorType* t);
+  inline void gen(StructureType* t);
+  inline void gen(SignatureType* t);
+  inline void gen(ConstLiteralInteger* t);
+  inline void gen(Variable* v);
+  inline void gen(Function* f);
+  inline void gen(Program* p);
+  inline void gen(Block* f);
+  inline void gen(ReturnOp* f);
+
+  virtual void handle(Node* n,Pass::TraversalKinds mode);
+
+  inline llvm::Module* linkModules();
+
+private:
+  typedef std::vector<llvm::Module*> ModuleList;
+  typedef std::vector<llvm::Value*> OperandList;
+  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
+  llvm::TypeSymbolTable ltypes; ///< The cached LLVM types 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 Function* function;  ///< The current Function we're traversing
+  const Block* block;        ///< The current Block we're traversing
+};
+
+
+const llvm::Type*
+LLVMGeneratorPass::getType(const Type* ty)
+{
+  // First, lets see if its cached already
+  const llvm::Type* result = ltypes.lookup(ty->getName());
+  if (result)
+    return result;
+
+  // Okay, we haven't seen this type before so let's construct it
+  switch (ty->getID()) {
+    case SignatureTypeID:
+    {
+      std::vector<const llvm::Type*> params;
+      const SignatureType* st = llvm::cast<SignatureType>(ty);
+      for (SignatureType::const_iterator I = st->begin(), E = st->end(); 
+           I != E; ++I)
+        params.push_back(getType(*I));
+      result = llvm::FunctionType::get(
+        getType(st->getResultType()),params,st->isVarArgs());
+      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::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 UInt128TypeID: 
+      hlvmNotImplemented("128 bit primitive integer");
+      break;
+    case SInt8TypeID: result = llvm::Type::SByteTy; break;
+    case SInt16TypeID: result = llvm::Type::ShortTy; break;
+    case SInt32TypeID: result = llvm::Type::IntTy; break;
+    case SInt64TypeID: result = llvm::Type::LongTy; break;
+    case SInt128TypeID: 
+      hlvmNotImplemented("128 bit primitive integer");
+      break;
+    case Float32TypeID: result = llvm::Type::FloatTy; break;
+    case Float64TypeID: result = llvm::Type::FloatTy; break;
+    case Float44TypeID: 
+    case Float80TypeID: 
+    case Float128TypeID: 
+      hlvmNotImplemented("extended and quad floating point");
+      break;
+    case IntegerTypeID:
+      hlvmNotImplemented("arbitrary precision integer");
+      break;
+    case RealTypeID:
+      hlvmNotImplemented("arbitrary precision real");
+    case StringTypeID: {
+      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);
+      break;
+    }
+    case AliasTypeID: {
+      result = getType(llvm::cast<AliasType>(ty)->getType());
+      break;
+    }
+    case PointerTypeID: {
+      result = llvm::PointerType::get(
+        getType(llvm::cast<PointerType>(ty)->getTargetType()));
+      break;
+    }
+    case ArrayTypeID: {
+      const llvm::Type* elemType = 
+        getType(llvm::cast<ArrayType>(ty)->getElementType());
+      std::vector<const llvm::Type*> Fields;
+      Fields.push_back(llvm::Type::UIntTy);
+      Fields.push_back(llvm::PointerType::get(elemType));
+      result = llvm::StructType::get(Fields);
+      break;
+    }
+    default:
+      hlvmDeadCode("Invalid type code");
+      break;
+  }
+  if (result)
+    ltypes.insert(ty->getName(),result);
+  return result;
+}
+
+void 
+LLVMGeneratorPass::gen(AliasType* t)
+{
+}
+void 
+LLVMGeneratorPass::gen(AnyType* t)
+{
+}
+
+void
+LLVMGeneratorPass::gen(BooleanType* t)
+{
+}
+
+void
+LLVMGeneratorPass::gen(CharacterType* t)
+{
+}
+
+void
+LLVMGeneratorPass::gen(IntegerType* t)
+{
+}
+
+void
+LLVMGeneratorPass::gen(RangeType* t)
+{
+}
+
+void 
+LLVMGeneratorPass::gen(EnumerationType* t)
+{
+}
+
+void
+LLVMGeneratorPass::gen(RealType* t)
+{
+}
+
+void
+LLVMGeneratorPass::gen(OctetType* t)
+{
+}
+
+void
+LLVMGeneratorPass::gen(VoidType* t)
+{
+}
+
+void 
+LLVMGeneratorPass::gen(PointerType* t)
+{
+}
+
+void 
+LLVMGeneratorPass::gen(ArrayType* t)
+{
+}
+
+void 
+LLVMGeneratorPass::gen(VectorType* t)
+{
+}
+
+void 
+LLVMGeneratorPass::gen(StructureType* t)
+{
+}
+
+void 
+LLVMGeneratorPass::gen(SignatureType* t)
+{
+}
+
+void 
+LLVMGeneratorPass::gen(ConstLiteralInteger* i)
+{
+  const Type* hType = i->getType();
+  const llvm::Type* lType = getType(hType);
+  if (llvm::cast<IntegerType>(hType)->isSigned())
+    lops.push_back(llvm::ConstantSInt::get(lType,i->getValue()));
+  else
+    lops.push_back(llvm::ConstantUInt::get(lType,i->getValue(0)));
+}
+
+void
+LLVMGeneratorPass::gen(Variable* v)
+{
+}
+
+void 
+LLVMGeneratorPass::gen(Block* b)
+{
+  lblk = new llvm::BasicBlock(b->getLabel(),lfunc,0);
+}
+
+void
+LLVMGeneratorPass::gen(ReturnOp* r)
+{
+  llvm::ReturnInst* ret = 0;
+  if (lops.empty())
+    ret =  new llvm::ReturnInst(lblk);
+  else {
+    hlvmAssert(lops.size() == 1 && "Too many operands for ReturnInst");
+    llvm::Value* retVal = lops[0];;
+    const llvm::Type* retTy = retVal->getType();
+    if (retTy != lfunc->getReturnType()) {
+      retVal = new llvm::CastInst(retVal,lfunc->getReturnType(),"",lblk);
+    }
+    ret = new llvm::ReturnInst(retVal,lblk);
+    lops.clear();
+  }
+  // RetInst is never the operand of another instruction (Terminator)
+}
+
+llvm::GlobalValue::LinkageTypes
+LLVMGeneratorPass::getLinkageTypes(LinkageKinds lk)
+{
+  return llvm::GlobalValue::LinkageTypes(lk);
+}
+
+std::string
+LLVMGeneratorPass::getLinkageName(LinkageItem* lk)
+{
+  if (lk->isProgram())
+    return std::string("_hlvm_entry_") + lk->getName();
+  // FIXME: This needs to incorporate the bundle name
+  return lk->getName();
+}
+
+void
+LLVMGeneratorPass::gen(Function* f)
+{
+  lfunc = new llvm::Function(
+    llvm::cast<llvm::FunctionType>(getType(f->getSignature())),
+    getLinkageTypes(f->getLinkageKind()), 
+    getLinkageName(f), lmod);
+}
+
+void
+LLVMGeneratorPass::gen(Bundle* b)
+{
+  lmod = new llvm::Module(b->getName());
+  modules.push_back(lmod);
+}
+
+void
+LLVMGeneratorPass::handle(Node* n,Pass::TraversalKinds mode)
+{
+  if (mode == Pass::PreOrderTraversal) {
+    // We process container nodes here (preorder) to ensure that we create the
+    // container that is being asked for.
+    switch (n->getID()) {
+    case BundleID:                gen(llvm::cast<Bundle>(n)); break;
+    case FunctionID:              gen(llvm::cast<Function>(n)); break;
+    case ProgramID:               gen(llvm::cast<Function>(n)); break;
+    case BlockID:                 gen(llvm::cast<Block>(n)); break;
+    default:
+      break;
+    }
+  } else {
+    // We process non-container nodes and operators. Operators are done
+    // post-order because we want their operands to be constructed first.
+    switch (n->getID()) 
+    {
+    case AliasTypeID:             gen(llvm::cast<AliasType>(n)); break;
+    case AnyTypeID:               gen(llvm::cast<AnyType>(n)); break;
+    case BooleanTypeID:           gen(llvm::cast<BooleanType>(n)); break;
+    case CharacterTypeID:         gen(llvm::cast<CharacterType>(n)); break;
+    case IntegerTypeID:           gen(llvm::cast<IntegerType>(n)); break;
+    case RangeTypeID:             gen(llvm::cast<RangeType>(n)); break;
+    case EnumerationTypeID:       gen(llvm::cast<EnumerationType>(n)); break;
+    case RealTypeID:              gen(llvm::cast<RealType>(n)); break;
+    case OctetTypeID:             gen(llvm::cast<OctetType>(n)); break;
+    case VoidTypeID:              gen(llvm::cast<VoidType>(n)); break;
+    case PointerTypeID:           gen(llvm::cast<PointerType>(n)); break;
+    case ArrayTypeID:             gen(llvm::cast<ArrayType>(n)); break;
+    case VectorTypeID:            gen(llvm::cast<VectorType>(n)); break;
+    case StructureTypeID:         gen(llvm::cast<StructureType>(n)); break;
+    case SignatureTypeID:         gen(llvm::cast<SignatureType>(n)); break;
+    case ConstLiteralIntegerOpID: gen(llvm::cast<ConstLiteralInteger>(n));break;
+    case VariableID:              gen(llvm::cast<Variable>(n)); break;
+    case ReturnOpID:              gen(llvm::cast<ReturnOp>(n)); break;
+    default:
+      break;
+    }
+  }
+}
+
+
+llvm::Module*
+LLVMGeneratorPass::linkModules()
+{
+  llvm::Linker linker("HLVM",ast->getPublicID(),0);
+  for (ModuleList::iterator I = modules.begin(), E = modules.end(); I!=E; ++I) {
+    linker.LinkInModule(*I);
+  }
+  modules.empty(); // LinkInModules destroyed/merged them all
+  return linker.releaseModule();
+}
+
+}
+
+void
+hlvm::generateBytecode(AST* tree,std::ostream& output)
+{
+  hlvm::PassManager* PM = hlvm::PassManager::create();
+  LLVMGeneratorPass genPass(tree);
+  PM->addPass(&genPass);
+  PM->runOn(tree);
+  llvm::Module* mod = genPass.linkModules();
+  llvm::WriteBytecodeToFile(mod, output, /*compress= */ true);
+  delete mod;
+  delete PM;
+}
+
+void
+hlvm::generateAssembly(AST* tree, std::ostream& output)
+{
+  hlvm::PassManager* PM = hlvm::PassManager::create();
+  LLVMGeneratorPass genPass(tree);
+  PM->addPass(&genPass);
+  PM->runOn(tree);
+  llvm::Module* mod = genPass.linkModules();
+  llvm::PassManager Passes;
+  Passes.add(new llvm::PrintModulePass(&output));
+  Passes.run(*mod);
+  delete mod;
+  delete PM;
+}

Added: hlvm/trunk/hlvm/CodeGen/LLVM/LLVMGenerator.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/CodeGen/LLVM/LLVMGenerator.h?rev=38115&view=auto

==============================================================================
--- hlvm/trunk/hlvm/CodeGen/LLVM/LLVMGenerator.h (added)
+++ hlvm/trunk/hlvm/CodeGen/LLVM/LLVMGenerator.h Sat Jul  7 18:59:59 2007
@@ -0,0 +1,48 @@
+//===-- LLVM Code Generation 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/CodeGen/LLVM/LLVMGenerator.h
+/// @author Reid Spencer <rspencer at reidspencer.com> (original author)
+/// @date 2006/05/26
+/// @since 0.1.0
+/// @brief Declares the interface for generating code with LLVM
+//===----------------------------------------------------------------------===//
+
+#ifndef HLVM_CODEGEN_LLVM_LLVMGENERATOR_H
+#define HLVM_CODEGEN_LLVM_LLVMGENERATOR_H
+
+#include <ostream>
+
+namespace hlvm 
+{
+  class AST;
+
+  /// Convert an Abstract Syntax Tree into LLVM bytecode written on the output 
+  /// stream.
+  void generateBytecode(AST* input, std::ostream& output);
+
+  /// Convert an Abstract Syntax Tree into LLVM assembly written on the output
+  /// stream.
+  void generateAssembly(AST* input, std::ostream& output);
+
+} // hlvm
+#endif

Added: hlvm/trunk/hlvm/CodeGen/LLVM/SConscript
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/CodeGen/LLVM/SConscript?rev=38115&view=auto

==============================================================================
--- hlvm/trunk/hlvm/CodeGen/LLVM/SConscript (added)
+++ hlvm/trunk/hlvm/CodeGen/LLVM/SConscript Sat Jul  7 18:59:59 2007
@@ -0,0 +1,26 @@
+#===-- Build Script For hlvm/Base -----------------------------*- Python -*-===#
+#
+#                      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
+#
+#===----------------------------------------------------------------------===#
+from build import hlvm
+Import('env')
+lib = env.Library('HLVMLLVMCG',hlvm.GetAllCXXFiles(env))
+hlvm.InstallLibrary(env,lib)

Added: hlvm/trunk/hlvm/CodeGen/SConscript
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/CodeGen/SConscript?rev=38115&view=auto

==============================================================================
--- hlvm/trunk/hlvm/CodeGen/SConscript (added)
+++ hlvm/trunk/hlvm/CodeGen/SConscript Sat Jul  7 18:59:59 2007
@@ -0,0 +1,25 @@
+#===-- Build Script For hlvm ----------------------------------*- Python -*-===#
+#
+#                      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
+#
+#===----------------------------------------------------------------------===#
+from build import hlvm
+Import('env')
+hlvm.Dirs(env,['LLVM'])

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

==============================================================================
--- hlvm/trunk/hlvm/Reader/XML/XMLReader.cpp (original)
+++ hlvm/trunk/hlvm/Reader/XML/XMLReader.cpp Sat Jul  7 18:59:59 2007
@@ -263,6 +263,7 @@
   hlvmAssert(!child && "Illegal chlldren of <bin> element");
   Locator loc(cur->line,0,&ast->getSystemID());
   ConstLiteralInteger* result = ast->new_ConstLiteralInteger(loc);
+  result->setType(ast->getPrimitiveType(UInt64TypeID));
   result->setValue(value);
   return result;
 }
@@ -286,6 +287,7 @@
   hlvmAssert(!child && "Illegal chlldren of <oct> element");
   Locator loc(cur->line,0,&ast->getSystemID());
   ConstLiteralInteger* result = ast->new_ConstLiteralInteger(loc);
+  result->setType(ast->getPrimitiveType(UInt64TypeID));
   result->setValue(value);
   return result;
 }
@@ -309,6 +311,7 @@
   hlvmAssert(!child && "Illegal chlldren of <dec> element");
   Locator loc(cur->line,0,&ast->getSystemID());
   ConstLiteralInteger* result = ast->new_ConstLiteralInteger(loc);
+  result->setType(ast->getPrimitiveType(UInt64TypeID));
   result->setValue(value);
   return result;
 }
@@ -352,6 +355,7 @@
   hlvmAssert(!child && "Illegal chlldren of <hex> element");
   Locator loc(cur->line,0,&ast->getSystemID());
   ConstLiteralInteger* result = ast->new_ConstLiteralInteger(loc);
+  result->setType(ast->getPrimitiveType(UInt64TypeID));
   result->setValue(value);
   return result;
 }

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

==============================================================================
--- hlvm/trunk/hlvm/SConscript (original)
+++ hlvm/trunk/hlvm/SConscript Sat Jul  7 18:59:59 2007
@@ -22,4 +22,4 @@
 #===----------------------------------------------------------------------===#
 from build import hlvm
 Import('env')
-hlvm.Dirs(env,['Base','AST','Pass','Reader','Writer','Runtime'])
+hlvm.Dirs(env,['Base','AST','Pass','Reader','Writer','CodeGen','Runtime'])

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

==============================================================================
--- hlvm/trunk/hlvm/Writer/XML/XMLWriter.cpp (original)
+++ hlvm/trunk/hlvm/Writer/XML/XMLWriter.cpp Sat Jul  7 18:59:59 2007
@@ -377,7 +377,10 @@
 XMLWriterImpl::WriterPass::put(ConstLiteralInteger* i)
 {
   startElement("dec");
-  writeString(llvm::utostr(i->getValue()));
+  if (cast<IntegerType>(i->getType())->isSigned())
+    writeString(llvm::itostr(i->getValue()));
+  else
+    writeString(llvm::utostr(i->getValue(0)));
 }
 
 void

Modified: hlvm/trunk/test/SConscript
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/SConscript?rev=38115&r1=38114&r2=38115&view=diff

==============================================================================
--- hlvm/trunk/test/SConscript (original)
+++ hlvm/trunk/test/SConscript Sat Jul  7 18:59:59 2007
@@ -24,4 +24,4 @@
 Import('env')
 if 'check' in COMMAND_LINE_TARGETS:
   from build import check
-  check.Check(env)
+  check.Check(env,['xml2xml','return0'])

Added: hlvm/trunk/test/lib/return0.exp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/lib/return0.exp?rev=38115&view=auto

==============================================================================
--- hlvm/trunk/test/lib/return0.exp (added)
+++ hlvm/trunk/test/lib/return0.exp Sat Jul  7 18:59:59 2007
@@ -0,0 +1,62 @@
+#===-test/lib/identity.exp - Script for identity tests ---------------------===#
+#
+#                      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
+# 
+#===------------------------------------------------------------------------===#
+proc hlvm-ret-zero-test { pat } {
+  global srcdir subdir objdir tmpdir objrootdir llcpath
+  set outdir [file join $objdir $subdir]
+  set compiler [file join $objrootdir tools hlvm-compiler hlvm-compiler ]
+  set source [file join $srcdir $subdir ]
+  set files [lsort [
+    glob -nocomplain -tails -types {f r} -directory $source $pat]]
+  set dirs [lsort [
+    glob -nocomplain -tails -types {d r} -directory $source *]]
+
+  if { [file isdirectory $outdir] } {
+    cd $outdir
+  } else {
+    if { [file exists $outdir] } {
+      fail "identity: $outdir exists and is not a directory. Remove it"
+      exit(2)
+    } else {
+      file mkdir $outdir
+    }
+  }
+  
+  foreach test $files {
+    set output [file join $outdir ${test}.out]
+    set testsrc [file join $source $test]
+    set testexe [file rootname $test]
+    set execout ""
+    set retval [ catch { exec -keepnewline $compiler $testsrc -llvmbc -o - | $llcpath -f -march x86 -o $testexe } msg ]
+    if { $retval != 0 } {
+      fail "$test: $testexe returned $retval\n$msg"
+    } else {
+      # Run the program compiled and see if it returns 0
+      set retval [ catch {exec $testexe } msg ]
+      if {$retval == 1} {
+        fail "$test: return 0 test failed:\n$msg"
+      } else {
+        pass "$test"
+      }
+    }
+  }
+}

Added: hlvm/trunk/test/return0/dg.exp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/return0/dg.exp?rev=38115&view=auto

==============================================================================
--- hlvm/trunk/test/return0/dg.exp (added)
+++ hlvm/trunk/test/return0/dg.exp Sat Jul  7 18:59:59 2007
@@ -0,0 +1,3 @@
+load_lib return0.exp
+
+hlvm-ret-zero-test "*.hlx"

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

==============================================================================
--- hlvm/trunk/test/return0/helloworld.hlx (added)
+++ hlvm/trunk/test/return0/helloworld.hlx Sat Jul  7 18:59:59 2007
@@ -0,0 +1,12 @@
+<?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 name="helloworld">
+    <var name="var" type="string"/>
+    <program name="helloworld">
+      <var name="stdin"/>
+      <store name="stdin"><open>pipe:///stdin</open></store>
+      <ret><int>0</int></ret>
+    </program>
+  </bundle>
+</hlvm>

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

==============================================================================
--- hlvm/trunk/test/return0/return0.hlx (added)
+++ hlvm/trunk/test/return0/return0.hlx Sat Jul  7 18:59:59 2007
@@ -0,0 +1,12 @@
+<?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/return.hlx">
+  <bundle name="return">
+    <program name="return">
+      <block>
+        <ret>
+          <dec>42</dec>
+        </ret>
+      </block>
+    </program>
+  </bundle>
+</hlvm>

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

==============================================================================
--- hlvm/trunk/test/xml2xml/return.hlx (original)
+++ hlvm/trunk/test/xml2xml/return.hlx Sat Jul  7 18:59:59 2007
@@ -1,5 +1,5 @@
 <?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">
+<hlvm xmlns="http://hlvm.org/src/hlvm/Reader/XML/HLVM.rng" pubid="http://hlvm.org/src/hlvm/test/xml2xml/return.hlx">
   <bundle name="return">
     <program name="return">
       <block>

Modified: hlvm/trunk/tools/SConscript
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/tools/SConscript?rev=38115&r1=38114&r2=38115&view=diff

==============================================================================
--- hlvm/trunk/tools/SConscript (original)
+++ hlvm/trunk/tools/SConscript Sat Jul  7 18:59:59 2007
@@ -22,4 +22,4 @@
 #===----------------------------------------------------------------------===#
 from build import hlvm
 Import('env')
-hlvm.Dirs(env,['hlvm-xml2xml','hlvm'])
+hlvm.Dirs(env,['hlvm-xml2xml','hlvm-compiler','hlvm'])

Added: hlvm/trunk/tools/hlvm-compiler/SConscript
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/tools/hlvm-compiler/SConscript?rev=38115&view=auto

==============================================================================
--- hlvm/trunk/tools/hlvm-compiler/SConscript (added)
+++ hlvm/trunk/tools/hlvm-compiler/SConscript Sat Jul  7 18:59:59 2007
@@ -0,0 +1,49 @@
+#===-- Build Script For tools/hlvm-xml2xml --------------------*- Python -*-===#
+#
+#                      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
+#
+#===----------------------------------------------------------------------===#
+from os.path import join as pjoin
+from build import hlvm
+Import('env')
+prog = env.Program('hlvm-compiler', hlvm.GetAllCXXFiles(env),
+ LIBS=[
+   'HLVMLLVMCG',
+   'HLVMXMLReader',
+   'HLVMXMLWriter',
+   'HLVMPass',
+   'HLVMAST',
+   'HLVMBase',
+   'xml2',
+   'LLVMLinker',
+   'LLVMSupport',
+   'LLVMSystem',
+   'apr-1',
+   'stdc++'
+  ],
+ LINKFLAGS=[
+   pjoin(env['LLVM_lib'],'LLVMCore') + env['OBJSUFFIX'],
+   pjoin(env['LLVM_lib'],'LLVMBCReader') + env['OBJSUFFIX'],
+   pjoin(env['LLVM_lib'],'LLVMBCWriter') + env['OBJSUFFIX'],
+   pjoin(env['LLVM_lib'],'LLVMbzip2') + env['OBJSUFFIX']
+ ]
+)
+hlvm.InstallProgram(env,prog)
+

Added: hlvm/trunk/tools/hlvm-compiler/hlvm-compiler.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/tools/hlvm-compiler/hlvm-compiler.cpp?rev=38115&view=auto

==============================================================================
--- hlvm/trunk/tools/hlvm-compiler/hlvm-compiler.cpp (added)
+++ hlvm/trunk/tools/hlvm-compiler/hlvm-compiler.cpp Sat Jul  7 18:59:59 2007
@@ -0,0 +1,142 @@
+//===-- HLVM Compiler -------------------------------------------*- 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 tools/hlvm/hlvm.cpp
+/// @author Reid Spencer <rspencer at reidspencer.com> (original author)
+/// @date 2006/05/23
+/// @since 0.1.0
+/// @brief Implements the main program for the HLVM Compiler 
+//===----------------------------------------------------------------------===//
+
+#include <hlvm/Base/Memory.h>
+#include <hlvm/Reader/XML/XMLReader.h>
+#include <hlvm/Writer/XML/XMLWriter.h>
+#include <hlvm/Pass/Pass.h>
+#include <hlvm/CodeGen/LLVM/LLVMGenerator.h>
+#include <llvm/Support/CommandLine.h>
+#include <llvm/System/Signals.h>
+#include <fstream>
+#include <iostream>
+
+using namespace llvm;
+using namespace hlvm;
+
+static cl::opt<std::string>
+InputFilename(cl::Positional, cl::desc("<input XML>"), cl::init("-"));
+
+static cl::opt<std::string>
+OutputFilename("o", cl::desc("Override output filename"),
+               cl::value_desc("filename"));
+
+static cl::opt<bool> Validate("validate", 
+  cl::desc("Validate input before generating code"));
+
+enum GenerationOptions {
+  GenLLVMBytecode,
+  GenLLVMAssembly
+};
+
+static cl::opt<GenerationOptions> WhatToGenerate(
+  cl::Optional,
+  cl::desc("Choose what kind of output to generate"),
+  cl::init(GenLLVMBytecode),
+  cl::values(
+    clEnumValN(GenLLVMBytecode, "llvmbc", "Generate LLVM Bytecode"),
+    clEnumValN(GenLLVMAssembly, "llvmasm", "Generate LLVM Assembly"),
+    clEnumValEnd
+  )
+);
+
+int main(int argc, char**argv) 
+{
+  try {
+    Base::initialize(argc,argv);
+    cl::ParseCommandLineOptions(argc, argv, 
+      "hlvm-xml2xml XML->AST->XML translator\n");
+
+    std::ostream *Out = &std::cout;  // Default to printing to stdout.
+
+    if (OutputFilename != "") {   // Specified an output filename?
+      if (OutputFilename != "-") { // Not stdout?
+        Out = new std::ofstream(OutputFilename.c_str());
+        sys::RemoveFileOnSignal(sys::Path(OutputFilename));
+      }
+    } else {
+      if (InputFilename == "-") {
+        OutputFilename = "-";
+      } else {
+        std::string IFN = InputFilename;
+        OutputFilename = InputFilename + ".out";
+
+        Out = new std::ofstream(OutputFilename.c_str());
+        sys::RemoveFileOnSignal(sys::Path(OutputFilename));
+      }
+    }
+
+    if (!Out->good()) {
+      std::cerr << argv[0] << ": error opening " << OutputFilename
+                << ": sending to stdout instead!\n";
+      Out = &std::cout;
+    }
+
+    if (InputFilename == "-" ) {
+      std::cerr << "Not supported yet: input from stdin\n";
+      exit(2);
+    } else {
+      llvm::sys::Path path(InputFilename);
+      if (!path.canRead()) {
+        std::cerr << argv[0] << ": can't read input file: " << InputFilename
+                  << "\n";
+        exit(2);
+      }
+    }
+
+    XMLReader* rdr = XMLReader::create(InputFilename);
+    rdr->read();
+    AST* node = rdr->get();
+    if (node && Validate) {
+      PassManager* PM = PassManager::create();
+      Pass* pass = Pass::new_ValidatePass(); 
+      PM->addPass( pass );
+      PM->runOn(node);
+      delete PM;
+      delete pass;
+    }
+    if (WhatToGenerate == GenLLVMBytecode) {
+      generateBytecode(node,*Out);
+    } else if (WhatToGenerate == GenLLVMAssembly) {
+      generateAssembly(node,*Out);
+    }
+    delete rdr;
+
+    if (Out != &std::cout) {
+      static_cast<std::ofstream*>(Out)->close();
+      delete Out;
+    }
+    return 0;
+  } catch (const std::string& msg) {
+    std::cerr << argv[0] << ": " << msg << "\n";
+  } catch (...) {
+    std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
+  }
+  return 1;
+}





More information about the llvm-commits mailing list