[llvm-commits] [hlvm] r38337 - in /hlvm/trunk/hlvm: AST/AST.cpp AST/AST.h AST/Constants.cpp AST/Constants.h AST/ContainerType.cpp AST/ContainerType.h AST/Linkables.cpp AST/Linkables.h AST/Node.h AST/Type.h CodeGen/LLVMGenerator.cpp Pass/Validate.cpp Reader/XMLReader.cpp

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


Author: reid
Date: Sat Jul  7 19:02:27 2007
New Revision: 38337

URL: http://llvm.org/viewvc/llvm-project?rev=38337&view=rev
Log:
Implement missing ConstantValue classes so that we can have more lattitude in
writing a test case generator.

Modified:
    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/Linkables.cpp
    hlvm/trunk/hlvm/AST/Linkables.h
    hlvm/trunk/hlvm/AST/Node.h
    hlvm/trunk/hlvm/AST/Type.h
    hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp
    hlvm/trunk/hlvm/Pass/Validate.cpp
    hlvm/trunk/hlvm/Reader/XMLReader.cpp

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

==============================================================================
--- hlvm/trunk/hlvm/AST/AST.cpp (original)
+++ hlvm/trunk/hlvm/AST/AST.cpp Sat Jul  7 19:02:27 2007
@@ -481,7 +481,9 @@
 }
 
 StructureType*
-AST::new_StructureType(const std::string& id, const Locator* loc)
+AST::new_StructureType(
+  const std::string& id, 
+  const Locator* loc)
 {
   StructureType* result = new StructureType();
   result->setLocator(loc);
@@ -513,12 +515,84 @@
   return result;
 }
 
+ConstantAny* 
+AST::new_ConstantAny(
+  const std::string& name,
+  ConstantValue* val,
+  const Locator* loc)
+{
+  ConstantAny* result = new ConstantAny(val);
+  result->setLocator(loc);
+  result->setName(name);
+  result->setType(getPrimitiveType(AnyTypeID));
+  return result;
+}
+
+ConstantBoolean* 
+AST::new_ConstantBoolean(
+  const std::string& name,
+  bool t_or_f, 
+  const Locator* loc)
+{
+  ConstantBoolean* result = new ConstantBoolean(t_or_f);
+  result->setLocator(loc);
+  result->setName(name);
+  result->setType(getPrimitiveType(BooleanTypeID));
+  return result;
+}
+
+ConstantCharacter* 
+AST::new_ConstantCharacter(
+  const std::string& name,
+  const std::string& val,
+  const Locator* loc)
+{
+  ConstantCharacter* result = new ConstantCharacter(val);
+  result->setLocator(loc);
+  result->setName(name);
+  result->setType( getPrimitiveType(CharacterTypeID) );
+  return result;
+}
+
+ConstantEnumerator* 
+AST::new_ConstantEnumerator(
+  const std::string& name,///< The name of the constant
+  const std::string& val, ///< The value for the constant
+  const Type* Ty,         ///< The type of the enumerator
+  const Locator* loc      ///< The source locator
+)
+{
+  ConstantEnumerator* result = new ConstantEnumerator(val);
+  result->setLocator(loc);
+  result->setName(name);
+  result->setType(Ty);
+  return result;
+}
+
+ConstantOctet* 
+AST::new_ConstantOctet(
+  const std::string& name,
+  unsigned char val,
+  const Locator* loc)
+{
+  ConstantOctet* result = new ConstantOctet(val);
+  result->setLocator(loc);
+  result->setName(name);
+  result->setType( getPrimitiveType(OctetTypeID) );
+  return result;
+}
+
 ConstantInteger*
 AST::new_ConstantInteger(
-  const std::string&  v, uint16_t base, const Type* Ty, const Locator* loc)
+  const std::string& name,
+  const std::string&  v, 
+  uint16_t base, 
+  const Type* Ty, 
+  const Locator* loc)
 {
   ConstantInteger* result = new ConstantInteger(base);
   result->setLocator(loc);
+  result->setName(name);
   result->setValue(v);
   result->setBase(base);
   result->setType(Ty);
@@ -526,42 +600,112 @@
 }
 
 ConstantReal*
-AST::new_ConstantReal(const std::string& v, const Type* Ty, const Locator* loc)
+AST::new_ConstantReal(
+  const std::string& name,
+  const std::string& v, 
+  const Type* Ty, 
+  const Locator* loc)
 {
   ConstantReal* result = new ConstantReal();
   result->setLocator(loc);
+  result->setName(name);
   result->setValue(v);
   result->setType(Ty);
   return result;
 }
 
 ConstantString*
-AST::new_ConstantString(const std::string& v, const Locator* loc)
+AST::new_ConstantString(
+  const std::string& name,
+  const std::string& v, 
+  const Locator* loc)
 {
   ConstantString* result = new ConstantString();
   result->setLocator(loc);
+  result->setName(name);
   result->setValue(v);
   result->setType( getPrimitiveType(StringTypeID) );
   return result;
 }
 
-ConstantBoolean* 
-AST::new_ConstantBoolean(bool t_or_f, const Locator* loc)
+ConstantPointer* 
+AST::new_ConstantPointer(
+  const std::string& name,
+  ConstantValue* referent,
+  const Locator* loc
+)
 {
-  ASTImpl* ast = static_cast<ASTImpl*>(this);
-  if (t_or_f) {
-    if (!ast->BooleanTrueSingleton) {
-      ast->BooleanTrueSingleton = new ConstantBoolean(true);
-      ast->BooleanTrueSingleton->setType(getPrimitiveType(BooleanTypeID));
-    }
-    return ast->BooleanTrueSingleton;
-  } else {
-    if (!ast->BooleanFalseSingleton) {
-      ast->BooleanFalseSingleton = new ConstantBoolean(false);
-      ast->BooleanFalseSingleton->setType(getPrimitiveType(BooleanTypeID));
-    }
-    return ast->BooleanFalseSingleton;
+  ConstantPointer* result = new ConstantPointer(referent);
+  result->setLocator(loc);
+  result->setName(name);
+  result->setType( getPointerTo(referent->getType()) );
+  return result;
+}
+
+ConstantArray* 
+AST::new_ConstantArray(
+  const std::string& name,
+  const std::vector<ConstantValue*>& vals,
+  const ArrayType* VT,
+  const Locator* loc
+)
+{
+  ConstantArray* result = new ConstantArray();
+  result->setLocator(loc);
+  result->setName(name);
+  for (std::vector<ConstantValue*>::const_iterator I = vals.begin(),
+       E = vals.end(); I != E; ++I ) 
+  {
+    hlvmAssert((*I)->getType() == VT->getElementType());
+    result->addConstant(*I);
+  }
+  result->setType(VT);
+  return result;
+}
+
+ConstantVector* 
+AST::new_ConstantVector(
+  const std::string& name,
+  const std::vector<ConstantValue*>& vals,
+  const VectorType* AT,
+  const Locator* loc
+)
+{
+  ConstantVector* result = new ConstantVector();
+  result->setLocator(loc);
+  result->setName(name);
+  for (std::vector<ConstantValue*>::const_iterator I = vals.begin(),
+       E = vals.end(); I != E; ++I ) 
+  {
+    hlvmAssert((*I)->getType() == AT->getElementType());
+    result->addConstant(*I);
   }
+  result->setType(AT);
+  return result;
+}
+
+ConstantStructure* 
+AST::new_ConstantStructure(
+  const std::string& name,
+  const std::vector<ConstantValue*>& vals,
+  const StructureType* ST,
+  const Locator* loc
+)
+{
+  ConstantStructure* result = new ConstantStructure();
+  result->setLocator(loc);
+  result->setName(name);
+  StructureType::const_iterator STI = ST->begin();
+  for (std::vector<ConstantValue*>::const_iterator I = vals.begin(),
+       E = vals.end(); I != E; ++I ) 
+  {
+    hlvmAssert(STI != ST->end());
+    hlvmAssert((*I)->getType() == (*STI)->getElementType());
+    result->addConstant(*I);
+    ++STI;
+  }
+  result->setType(ST);
+  return result;
 }
 
 Variable*
@@ -574,8 +718,8 @@
   return result;
 }
 
-Argument* 
-AST::new_Argument(const std::string& id, Type* ty , const Locator* loc)
+Argument*
+AST::new_Argument(const std::string& id, const Type* ty , const Locator* loc)
 {
   Argument* result = new Argument();
   result->setLocator(loc);
@@ -597,9 +741,7 @@
   {
     const Type* Ty = (*I)->getElementType();
     assert(Ty && "Arguments can't be void type");
-    Argument* arg = new Argument();
-    arg->setType(Ty);
-    arg->setName((*I)->getName());
+    Argument* arg = new_Argument((*I)->getName(),Ty,loc);
     result->addArgument(arg);
   }
   return result;
@@ -800,6 +942,7 @@
   const Locator* loc
 )
 {
+  hlvmAssert(!oprnds.empty() && "No operands?");
   return new_MultiOp<OpClass>(oprnds[0]->getType(),oprnds,loc);
 }
 

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

==============================================================================
--- hlvm/trunk/hlvm/AST/AST.h (original)
+++ hlvm/trunk/hlvm/AST/AST.h Sat Jul  7 19:02:27 2007
@@ -53,10 +53,6 @@
 class Import;
 class Locator; 
 class Variable; 
-class ConstantBoolean;
-class ConstantInteger;
-class ConstantReal;
-class ConstantString;
 class Pool;
 class Operator;
 class AutoVarOp;
@@ -187,7 +183,7 @@
     /// value to a function.
     Argument* new_Argument(
       const std::string& id, ///< The name of the function argument
-      Type* ty,              ///< The type of the function argument 
+      const Type* ty,        ///< The type of the function argument 
       const Locator* loc = 0 ///< The source locator
     );
     /// Create a new Program node. Programs are like functions except that their
@@ -420,29 +416,92 @@
       const Type* ty,         ///< The type of the variable
       const Locator* loc = 0  ///< The source locator
     );
+    /// Createa new ConstantAny node
+    ConstantAny* new_ConstantAny(
+      const std::string& name,///< The name of the constant
+      ConstantValue* val,     ///< The value for the constant
+      const Locator* loc = 0  ///< The source locator
+    );
     /// Createa new ConstantBoolean node
     ConstantBoolean* new_ConstantBoolean(
+      const std::string& name,///< The name of the constant
       bool t_or_f,            ///< The value for the constant
       const Locator* loc = 0  ///< The source locator
     );
+    /// Createa new ConstantCharacter node
+    ConstantCharacter* new_ConstantCharacter(
+      const std::string& name,///< The name of the constant
+      const std::string& val, ///< The value for the constant
+      const Locator* loc = 0  ///< The source locator
+    );
+    /// Createa new ConstantEnumerator node
+    ConstantEnumerator* new_ConstantEnumerator(
+      const std::string& name,///< The name of the constant
+      const std::string& val, ///< The value for the constant
+      const Type* Ty,         ///< The type of the enumerator
+      const Locator* loc = 0  ///< The source locator
+    );
+    /// Createa new ConstantOctet node
+    ConstantOctet* new_ConstantOctet(
+      const std::string& name,///< The name of the constant
+      unsigned char val,      ///< The value for the constant
+      const Locator* loc = 0  ///< The source locator
+    );
     /// Create a new ConstantInteger node.
     ConstantInteger* new_ConstantInteger(
+      const std::string& name,///< The name of the constant
       const std::string& val, ///< The value of the ConstantInteger
       uint16_t base,          ///< The numeric base the value is encoded in
       const Type* Ty,         ///< The type of the integer
       const Locator* loc = 0  ///< The source locator
     );
-    /// Create a new ConstantInteger node.
+    /// Create a new ConstantReal node.
     ConstantReal* new_ConstantReal(
+      const std::string& name,///< The name of the constant
       const std::string& val, ///< The value of the ConstantReal
       const Type* Ty,         ///< The type of the real
       const Locator* loc = 0  ///< The source locator
     );
-    /// Create a new ConstantText node.
+    /// Create a new ConstantString node.
     ConstantString* new_ConstantString(
+      const std::string& name,///< The name of the constant
       const std::string& value, ///< The value of the ConstantText
       const Locator* loc = 0    ///< The source locator
     );
+    /// Create a new ConstantPointer node.
+    ConstantPointer* new_ConstantPointer(
+      const std::string& name,  ///< The name of the constant
+      ConstantValue* referent,          ///< The value pointed to
+      const Locator* loc = 0    ///< The source locator
+    );
+    /// Create a new ConstantArray node.
+    ConstantArray* new_ConstantArray(
+      const std::string& name,  ///< The name of the constant
+      const std::vector<ConstantValue*>& elems, ///< The elements of the array
+      const ArrayType* Ty,      ///< The type of the array
+      const Locator* loc = 0    ///< The source locator
+    );
+    /// Create a new ConstantVector node.
+    ConstantVector* new_ConstantVector(
+      const std::string& name,  ///< The name of the constant
+      const std::vector<ConstantValue*>& elems, ///< The elements of the array
+      const VectorType* Ty,     ///< The type of the array
+      const Locator* loc = 0    ///< The source locator
+    );
+    /// Create a new ConstantStructure node.
+    ConstantStructure* new_ConstantStructure(
+      const std::string& name,  ///< The name of the constant
+      const std::vector<ConstantValue*>& elems, ///< The elements of the array
+      const StructureType* Ty,  ///< The type of the array
+      const Locator* loc = 0    ///< The source locator
+    );
+    /// Create a new ConstantContinuation node.
+    ConstantContinuation* new_ConstantContinuation(
+      const std::string& name,  ///< The name of the constant
+      const std::vector<ConstantValue*>& elems, ///< The elements of the array
+      const ContinuationType* Ty,  ///< The type of the array
+      const Locator* loc = 0    ///< The source locator
+    );
     /// Create a unary ConstantExpression Node.
     Constant* new_UnaryCE(
       NodeIDs id,            ///< The operator for the constant expression

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Constants.cpp (original)
+++ hlvm/trunk/hlvm/AST/Constants.cpp Sat Jul  7 19:02:27 2007
@@ -29,14 +29,46 @@
 
 #include <hlvm/AST/Constants.h>
 #include <hlvm/AST/Type.h>
+#include <hlvm/Base/Assert.h>
+#include <llvm/Support/Casting.h>
 
 namespace hlvm {
 
 Constant::~Constant() { }
 ConstantValue::~ConstantValue() { }
+ConstantAny::~ConstantAny() { }
 ConstantBoolean::~ConstantBoolean() { }
+ConstantCharacter::~ConstantCharacter() { }
+ConstantEnumerator::~ConstantEnumerator() { }
+ConstantOctet::~ConstantOctet() { }
 ConstantInteger::~ConstantInteger() { }
 ConstantReal::~ConstantReal() { }
 ConstantString::~ConstantString() { }
+ConstantPointer::~ConstantPointer() { }
+ConstantAggregate::~ConstantAggregate() { }
+void 
+ConstantAggregate::insertChild(Node* n)
+{
+  hlvmAssert(llvm::isa<ConstantValue>(n));
+  ConstantValue* CV = llvm::cast<ConstantValue>(n);
+  elems.push_back(CV);
+}
+
+void 
+ConstantAggregate::removeChild(Node* n)
+{
+  hlvmAssert(llvm::isa<ConstantValue>(n));
+  ConstantValue* CV = llvm::cast<ConstantValue>(n);
+  for (ElementsList::iterator I = elems.begin(), E = elems.end(); I != E; ++I)
+    if (*I == CV) {
+      elems.erase(I);
+      break;
+    }
+}
+
+ConstantArray::~ConstantArray() { }
+ConstantVector::~ConstantVector() { }
+ConstantStructure::~ConstantStructure() { }
+ConstantContinuation::~ConstantContinuation() { }
 
 }

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Constants.h (original)
+++ hlvm/trunk/hlvm/AST/Constants.h Sat Jul  7 19:02:27 2007
@@ -106,6 +106,36 @@
 };
 
 /// This class provides an Abstract Syntax Tree node that yields a 
+/// constant any value. 
+/// @brief AST Constant Any Value Node
+class ConstantAny: public ConstantValue
+{
+  /// @name Constructors
+  /// @{
+  protected:
+    ConstantAny(ConstantValue* val) : ConstantValue(ConstantAnyID) {
+      value = val; }
+    virtual ~ConstantAny();
+
+  /// @}
+  /// @name Accessors
+  /// @{
+  public:
+    ConstantValue* getValue() const { return value; }
+    static inline bool classof(const ConstantAny*) { return true; }
+    static inline bool classof(const Node* N) 
+      { return N->is(ConstantAnyID); }
+
+  /// @}
+  /// @name Data
+  /// @{
+  private:
+    ConstantValue* value;
+  /// @}
+  friend class AST;
+};
+
+/// This class provides an Abstract Syntax Tree node that yields a 
 /// constant boolean value. 
 /// @brief AST Constant Boolean Node
 class ConstantBoolean: public ConstantValue
@@ -131,6 +161,96 @@
 };
 
 /// This class provides an Abstract Syntax Tree node that yields a 
+/// constant character value. 
+/// @brief AST Constant Character Node
+class ConstantCharacter: public ConstantValue
+{
+  /// @name Constructors
+  /// @{
+  protected:
+    ConstantCharacter(const std::string& val) 
+      : ConstantValue(ConstantCharacterID) { value = val; }
+    virtual ~ConstantCharacter();
+
+  /// @}
+  /// @name Accessors
+  /// @{
+  public:
+    const std::string& getValue() const { return value; }
+    static inline bool classof(const ConstantCharacter*) { return true; }
+    static inline bool classof(const Node* N) 
+      { return N->is(ConstantCharacterID); }
+
+  /// @}
+  /// @name Data
+  /// @{
+  public:
+    std::string value;
+  /// @}
+  friend class AST;
+};
+
+/// This class provides an Abstract Syntax Tree node that yields a 
+/// constant octet value. 
+/// @brief AST Constant Octet Node
+class ConstantOctet: public ConstantValue
+{
+  /// @name Constructors
+  /// @{
+  protected:
+    ConstantOctet(unsigned char val) : ConstantValue(ConstantOctetID) { 
+      value = val; }
+    virtual ~ConstantOctet();
+
+  /// @}
+  /// @name Accessors
+  /// @{
+  public:
+    unsigned char getValue() const { return value; }
+    static inline bool classof(const ConstantOctet*) { return true; }
+    static inline bool classof(const Node* N) 
+      { return N->is(ConstantOctetID); }
+
+  /// @}
+  /// @name Data
+  /// @{
+  public:
+    unsigned char value;
+  /// @}
+  friend class AST;
+};
+
+/// This class provides an Abstract Syntax Tree node that yields a 
+/// constant octet value. 
+/// @brief AST Constant Octet Node
+class ConstantEnumerator: public ConstantValue
+{
+  /// @name Constructors
+  /// @{
+  protected:
+    ConstantEnumerator(const std::string& val) 
+      : ConstantValue(ConstantEnumeratorID) { value = val; }
+    virtual ~ConstantEnumerator();
+
+  /// @}
+  /// @name Accessors
+  /// @{
+  public:
+    const std::string& getValue() const { return value; }
+    static inline bool classof(const ConstantEnumerator*) { return true; }
+    static inline bool classof(const Node* N) 
+      { return N->is(ConstantEnumeratorID); }
+
+  /// @}
+  /// @name Data
+  /// @{
+  public:
+    std::string value;
+  /// @}
+  friend class AST;
+};
+
+/// This class provides an Abstract Syntax Tree node that yields a 
 /// constant integer value. This kind of constant can represent integer valued
 /// constants of any of the signed or unsigned integer types of any bitsize.
 /// @see IntegerType
@@ -242,6 +362,36 @@
   friend class AST;
 };
 
+/// This class provides an Abstract Syntax Tree node that yields a constant 
+/// pointer value. 
+/// @brief AST Constant Pointer Node
+class ConstantPointer : public ConstantValue
+{
+  /// @name Constructors
+  /// @{
+  protected:
+    ConstantPointer(const ConstantValue* cv) 
+      : ConstantValue(ConstantPointerID)  { value = cv; }
+    virtual ~ConstantPointer();
+
+  /// @}
+  /// @name Accessors
+  /// @{
+  public:
+    const ConstantValue* getValue() const { return value; }
+    static inline bool classof(const ConstantPointer*) { return true; }
+    static inline bool classof(const Node* N) 
+      { return N->is(ConstantPointerID); }
+
+  /// @}
+  /// @name Data
+  /// @{
+  public:
+    const ConstantValue* value;
+  /// @}
+  friend class AST;
+};
+
 /// This class provides an Abstract Syntax Tree node that yields a constant
 /// aggregate. This can be used to specify constant values of aggregate types
 /// such as arrays, vectors, structures and continuations. It simply contains 
@@ -252,7 +402,7 @@
   /// @name Types
   /// @{
   public:
-    typedef std::vector<ConstantValue*> ElementsList;
+    typedef std::vector<const ConstantValue*> ElementsList;
     typedef ElementsList::iterator iterator;
     typedef ElementsList::const_iterator const_iterator;
 
@@ -260,7 +410,7 @@
   /// @name Constructors
   /// @{
   protected:
-    ConstantAggregate() : ConstantValue(ConstantAggregateID), elems()  {}
+    ConstantAggregate(NodeIDs id) : ConstantValue(id), elems()  {}
     virtual ~ConstantAggregate();
 
   /// @}
@@ -269,11 +419,14 @@
   public:
     static inline bool classof(const ConstantAggregate*) { return true; }
     static inline bool classof(const Node* N) 
-      { return N->is(ConstantAggregateID); }
+      { return N->isConstantAggregate(); }
 
   /// @}
   /// @name Mutators
   /// @{
+  public:
+    void addConstant(const ConstantValue* val) { elems.push_back(val); }
+
   protected:
     virtual void insertChild(Node* n);
     virtual void removeChild(Node* n);
@@ -288,9 +441,7 @@
     const_iterator       end  () const { return elems.end(); }
     size_t               size () const { return elems.size(); }
     bool                 empty() const { return elems.empty(); }
-    ConstantValue*       front()       { return elems.front(); }
     const ConstantValue* front() const { return elems.front(); }
-    ConstantValue*       back()        { return elems.back(); }
     const ConstantValue* back()  const { return elems.back(); }
 
   /// @}
@@ -303,6 +454,98 @@
   friend class AST;
 };
 
+/// This class provides an Abstract Syntax Tree node that yields a constant 
+/// array value. 
+/// @brief AST Constant Array Node
+class ConstantArray : public ConstantAggregate
+{
+  /// @name Constructors
+  /// @{
+  protected:
+    ConstantArray() : ConstantAggregate(ConstantArrayID) {}
+    virtual ~ConstantArray();
+
+  /// @}
+  /// @name Accessors
+  /// @{
+  public:
+    static inline bool classof(const ConstantArray*) { return true; }
+    static inline bool classof(const Node* N) { return N->is(ConstantArrayID); }
+
+  /// @}
+  friend class AST;
+};
+
+/// This class provides an Abstract Syntax Tree node that yields a constant 
+/// array value. 
+/// @brief AST Constant Vector Node
+class ConstantVector : public ConstantAggregate
+{
+  /// @name Constructors
+  /// @{
+  protected:
+    ConstantVector() : ConstantAggregate(ConstantVectorID) {}
+    virtual ~ConstantVector();
+
+  /// @}
+  /// @name Accessors
+  /// @{
+  public:
+    static inline bool classof(const ConstantVector*) { return true; }
+    static inline bool classof(const Node* N) { return N->is(ConstantVectorID);}
+
+  /// @}
+  friend class AST;
+};
+
+/// This class provides an Abstract Syntax Tree node that yields a constant 
+/// array value. 
+/// @brief AST Constant Vector Node
+class ConstantStructure : public ConstantAggregate
+{
+  /// @name Constructors
+  /// @{
+  protected:
+    ConstantStructure() : ConstantAggregate(ConstantStructureID) {}
+    virtual ~ConstantStructure();
+
+  /// @}
+  /// @name Accessors
+  /// @{
+  public:
+    static inline bool classof(const ConstantStructure*) { return true; }
+    static inline bool classof(const Node* N) { 
+      return N->is(ConstantStructureID);
+    }
+
+  /// @}
+  friend class AST;
+};
+
+/// This class provides an Abstract Syntax Tree node that yields a constant 
+/// continuation value. 
+/// @brief AST Constant Vector Node
+class ConstantContinuation : public ConstantAggregate
+{
+  /// @name Constructors
+  /// @{
+  protected:
+    ConstantContinuation() : ConstantAggregate(ConstantContinuationID) {}
+    virtual ~ConstantContinuation();
+
+  /// @}
+  /// @name Accessors
+  /// @{
+  public:
+    static inline bool classof(const ConstantContinuation*) { return true; }
+    static inline bool classof(const Node* N) { 
+      return N->is(ConstantContinuationID);
+    }
+
+  /// @}
+  friend class AST;
+};
+
 /// This class provides an Abstract Syntax Tree node that yields a constant
 /// expression. The expression uses a limited set of operator identifiers that
 /// can yield constants such as arithmetic or comparison operators. 

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

==============================================================================
--- hlvm/trunk/hlvm/AST/ContainerType.cpp (original)
+++ hlvm/trunk/hlvm/AST/ContainerType.cpp Sat Jul  7 19:02:27 2007
@@ -119,12 +119,14 @@
   hlvmAssert(!"That node isn't my child");
 }
 
-StructureType::~StructureType()
-{
-}
+StructureType::~StructureType() { }
 
-SignatureType::~SignatureType()
+void
+StructureType::setFields(const std::vector<FieldType*>& flds)
 {
+  contents.insert(contents.end(), flds.begin(),flds.end());
 }
 
+SignatureType::~SignatureType() { }
+
 }

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

==============================================================================
--- hlvm/trunk/hlvm/AST/ContainerType.h (original)
+++ hlvm/trunk/hlvm/AST/ContainerType.h Sat Jul  7 19:02:27 2007
@@ -322,6 +322,7 @@
   /// @name Mutators
   /// @{
   protected:
+    void setFields(const std::vector<FieldType*>& fields);
     void addField(FieldType* field) { contents.push_back(field); }
 
   /// @}

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Linkables.cpp (original)
+++ hlvm/trunk/hlvm/AST/Linkables.cpp Sat Jul  7 19:02:27 2007
@@ -46,7 +46,7 @@
 {
   for (const_iterator I = begin(), E = end(); I != E ; ++I )
     if ((*I)->getName() == name)
-      return *I;
+      return (*I);
   return 0;
 }
 

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Linkables.h (original)
+++ hlvm/trunk/hlvm/AST/Linkables.h Sat Jul  7 19:02:27 2007
@@ -148,7 +148,7 @@
   /// @name Constructors
   /// @{
   protected:
-    Argument() : Value(ArgumentID) {}
+    Argument() : Value(ArgumentID), name() {}
     virtual ~Argument();
 
   /// @}
@@ -163,7 +163,8 @@
   /// @name Mutators
   /// @{
   public:
-    void setName(const std::string& N) { name = N; }
+    void setName(const std::string& nm) { name = nm; }
+
   /// @}
   /// @name Data
   /// @{

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Node.h (original)
+++ hlvm/trunk/hlvm/AST/Node.h Sat Jul  7 19:02:27 2007
@@ -132,13 +132,23 @@
 FirstValueID = ArgumentID,
 
   // Constants
+  ConstantAnyID,           ///< A constant any value
+FirstConstantID = ConstantAnyID,
+FirstConstantValueID = ConstantAnyID,
   ConstantBooleanID,       ///< A constant boolean value
-FirstConstantID = ConstantBooleanID,
-FirstConstantValueID = ConstantBooleanID,
+  ConstantCharacterID,     ///< A constant UTF-8 character value
+  ConstantOctetID,         ///< A constant 8-bit value
+  ConstantEnumeratorID,    ///< A constant enumeration value
   ConstantIntegerID,       ///< A constant integer value
   ConstantRealID,          ///< A constant real value
   ConstantStringID,        ///< A constant string value
-  ConstantAggregateID,     ///< A constant aggregate for arrays, structures, etc
+  ConstantPointerID,       ///< A constant pointer value
+  ConstantArrayID,         ///< A constant array value
+FirstConstantAggregateID = ConstantArrayID,
+  ConstantVectorID,        ///< A constant vector value
+  ConstantStructureID,     ///< A constant structure value
+  ConstantContinuationID,  ///< A constant continuation value
+LastConstantAggregateID = ConstantContinuationID,
   ConstantExpressionID,    ///< A constant expression
 LastConstantValueID = ConstantExpressionID,
 
@@ -375,6 +385,10 @@
     inline bool isConstantValue() const {
       return id >= FirstConstantValueID && id <= LastConstantValueID; }
 
+    /// Determine if the node is one of the ConstantAggregate values.
+    inline bool isConstantAggregate() const {
+      return id >= FirstConstantAggregateID && id <= LastConstantAggregateID; }
+
     /// Determine if the node is a Linkable
     inline bool isLinkable() const {
       return id >= FirstLinkableID && id <= LastLinkableID; }

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Type.h (original)
+++ hlvm/trunk/hlvm/AST/Type.h Sat Jul  7 19:02:27 2007
@@ -313,10 +313,10 @@
   public:
     virtual const char* getPrimitiveName() const;
     /// Get min value of range
-    int64_t getMin() { return min; }
+    int64_t getMin() const { return min; }
 
     /// Get max value of range
-    int64_t getMax() { return max; }
+    int64_t getMax() const { return max; }
 
     // Methods to support type inquiry via is, cast, dyn_cast
     static inline bool classof(const RangeType*) { return true; }

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

==============================================================================
--- hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp (original)
+++ hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp Sat Jul  7 19:02:27 2007
@@ -43,20 +43,24 @@
 #include <hlvm/Base/Assert.h>
 #include <hlvm/Pass/Pass.h>
 #include <llvm/Module.h>
+#include <llvm/PassManager.h>
 #include <llvm/BasicBlock.h>
-#include <llvm/Function.h>
-#include <llvm/GlobalVariable.h>
 #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/Analysis/LoadValueNumbering.h>
+#include <llvm/Analysis/Verifier.h>
+#include <llvm/Assembly/Parser.h>
 #include <llvm/Bytecode/Writer.h>
-#include <llvm/PassManager.h>
+#include <llvm/Target/TargetData.h>
+#include <llvm/Transforms/IPO.h>
+#include <llvm/Transforms/Scalar.h>
+#include <llvm/Analysis/Dominators.h>
 #include <llvm/Assembly/PrintModulePass.h>
-#include <llvm/Analysis/Verifier.h>
+#include <llvm/Support/CommandLine.h>
 
 namespace llvm {
   void dump(llvm::Value* V) {
@@ -2099,6 +2103,69 @@
   return linker.releaseModule();
 }
 
+
+llvm::cl::opt<bool>
+  NoInline("no-inlining", 
+    llvm::cl::desc("Do not run the LLVM inliner pass"));
+
+llvm::cl::opt<bool>
+  NoOptimizations("no-optimization",
+    llvm::cl::desc("Do not run any LLVM optimization passes"));
+
+void 
+getCleanupPasses(llvm::PassManager& PM)
+{
+  
+  PM.add(llvm::createLowerSetJmpPass());          // Lower llvm.setjmp/.longjmp
+  PM.add(llvm::createFunctionResolvingPass());    // Resolve (...) functions
+  if (NoOptimizations)
+    return;
+
+  PM.add(llvm::createRaiseAllocationsPass());     // call %malloc -> malloc inst
+  PM.add(llvm::createCFGSimplificationPass());    // Clean up disgusting code
+  PM.add(llvm::createPromoteMemoryToRegisterPass());// Kill useless allocas
+  PM.add(llvm::createGlobalOptimizerPass());      // Optimize out global vars
+  PM.add(llvm::createGlobalDCEPass());            // Remove unused fns and globs
+  PM.add(llvm::createIPConstantPropagationPass());// IP Constant Propagation
+  PM.add(llvm::createDeadArgEliminationPass());   // Dead argument elimination
+  PM.add(llvm::createInstructionCombiningPass()); // Clean up after IPCP & DAE
+  PM.add(llvm::createCFGSimplificationPass());    // Clean up after IPCP & DAE
+  PM.add(llvm::createPruneEHPass());              // Remove dead EH info
+  if (!NoInline)
+    PM.add(llvm::createFunctionInliningPass());   // Inline small functions
+  PM.add(llvm::createSimplifyLibCallsPass());     // Library Call Optimizations
+  PM.add(llvm::createArgumentPromotionPass());    // Scalarize uninlined fn args
+  PM.add(llvm::createRaisePointerReferencesPass());// Recover type information
+  PM.add(llvm::createTailDuplicationPass());      // Simplify cfg by copying 
+  PM.add(llvm::createCFGSimplificationPass());    // Merge & remove BBs
+  PM.add(llvm::createScalarReplAggregatesPass()); // Break up aggregate allocas
+  PM.add(llvm::createInstructionCombiningPass()); // Combine silly seq's
+  PM.add(llvm::createCondPropagationPass());      // Propagate conditionals
+  PM.add(llvm::createTailCallEliminationPass());  // Eliminate tail calls
+  PM.add(llvm::createCFGSimplificationPass());    // Merge & remove BBs
+  PM.add(llvm::createReassociatePass());          // Reassociate expressions
+  PM.add(llvm::createLICMPass());                 // Hoist loop invariants
+  PM.add(llvm::createLoopUnswitchPass());         // Unswitch loops.
+  PM.add(llvm::createInstructionCombiningPass()); // Clean up after LICM/reassoc
+  PM.add(llvm::createIndVarSimplifyPass());       // Canonicalize indvars
+  PM.add(llvm::createLoopUnrollPass());           // Unroll small loops
+  PM.add(llvm::createInstructionCombiningPass()); // Clean up after the unroller
+  PM.add(llvm::createLoadValueNumberingPass());   // GVN for load instructions
+  PM.add(llvm::createGCSEPass());                 // Remove common subexprs
+  PM.add(llvm::createSCCPPass());                 // Constant prop with SCCP
+
+  // Run instcombine after redundancy elimination to exploit opportunities
+  // opened up by them.
+  PM.add(llvm::createInstructionCombiningPass());
+  PM.add(llvm::createCondPropagationPass());      // Propagate conditionals
+
+  PM.add(llvm::createDeadStoreEliminationPass()); // Delete dead stores
+  PM.add(llvm::createAggressiveDCEPass());        // SSA based 'Aggressive DCE'
+  PM.add(llvm::createCFGSimplificationPass());    // Merge & remove BBs
+  PM.add(llvm::createDeadTypeEliminationPass());  // Eliminate dead types
+  PM.add(llvm::createConstantMergePass());        // Merge dup global constants
+}
+
 }
 
 bool
@@ -2111,10 +2178,16 @@
   delete PM;
   llvm::Module* mod = genPass.linkModules();
   bool result = false;
-  if (!llvm::verifyModule(*mod, llvm::PrintMessageAction)) {
-    llvm::WriteBytecodeToFile(mod, output, /*compress= */ true);
-    result = true;
-  }
+  llvm::PassManager Passes;
+  Passes.add(new llvm::TargetData(mod));
+  if (verify)
+    Passes.add(llvm::createVerifierPass());
+  getCleanupPasses(Passes);
+  if (verify)
+    Passes.add(llvm::createVerifierPass());
+  Passes.run(*mod);
+  llvm::WriteBytecodeToFile(mod, output, /*compress= */ true);
+  result = true;
   delete mod;
   return result;
 }
@@ -2129,12 +2202,37 @@
   delete PM;
   llvm::Module* mod = genPass.linkModules();
   bool result = false;
-  if (!llvm::verifyModule(*mod, llvm::PrintMessageAction)) {
-    llvm::PassManager Passes;
-    Passes.add(new llvm::PrintModulePass(&output));
-    Passes.run(*mod);
-    result = true;
-  }
+  llvm::PassManager lPM;
+  lPM.add(new llvm::TargetData(mod));
+  if (verify)
+    lPM.add(llvm::createVerifierPass());
+  getCleanupPasses(lPM);
+  if (verify)
+    lPM.add(llvm::createVerifierPass());
+  lPM.add(new llvm::PrintModulePass(&output));
+  lPM.run(*mod);
+  result = true;
   delete mod;
   return result;
 }
+
+llvm::Module* 
+hlvm::generateModule(AST* tree, bool verify)
+{
+  hlvm::PassManager* PM = hlvm::PassManager::create();
+  LLVMGeneratorPass genPass(tree);
+  PM->addPass(&genPass);
+  PM->runOn(tree);
+  delete PM;
+  llvm::Module* mod = genPass.linkModules();
+  llvm::PassManager lPM;
+  lPM.add(new llvm::TargetData(mod));
+  if (verify)
+    lPM.add(llvm::createVerifierPass());
+  getCleanupPasses(lPM);
+  if (verify)
+    lPM.add(llvm::createVerifierPass());
+  lPM.run(*mod);
+  return mod;
+}
+

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

==============================================================================
--- hlvm/trunk/hlvm/Pass/Validate.cpp (original)
+++ hlvm/trunk/hlvm/Pass/Validate.cpp Sat Jul  7 19:02:27 2007
@@ -545,9 +545,37 @@
 }
 
 template<> inline void
-ValidateImpl::validate(ConstantAggregate* n)
+ValidateImpl::validate(ConstantPointer* n)
 {
-  checkConstant(n,ConstantAggregateID);
+  checkConstant(n,ConstantPointerID);
+  // FIXME: validate fields vs. type
+}
+
+template<> inline void
+ValidateImpl::validate(ConstantArray* n)
+{
+  checkConstant(n,ConstantArrayID);
+  // FIXME: validate fields vs. type
+}
+
+template<> inline void
+ValidateImpl::validate(ConstantVector* n)
+{
+  checkConstant(n,ConstantVectorID);
+  // FIXME: validate fields vs. type
+}
+
+template<> inline void
+ValidateImpl::validate(ConstantStructure* n)
+{
+  checkConstant(n,ConstantStructureID);
+  // FIXME: validate fields vs. type
+}
+
+template<> inline void
+ValidateImpl::validate(ConstantContinuation* n)
+{
+  checkConstant(n,ConstantContinuationID);
   // FIXME: validate fields vs. type
 }
 
@@ -1503,7 +1531,11 @@
     case ConstantIntegerID:      validate(cast<ConstantInteger>(n)); break;
     case ConstantRealID:         validate(cast<ConstantReal>(n)); break;
     case ConstantStringID:       validate(cast<ConstantString>(n)); break;
-    case ConstantAggregateID:    validate(cast<ConstantAggregate>(n)); break;
+    case ConstantPointerID:      validate(cast<ConstantPointer>(n)); break;
+    case ConstantArrayID:        validate(cast<ConstantArray>(n)); break;
+    case ConstantVectorID:       validate(cast<ConstantVector>(n)); break;
+    case ConstantStructureID:    validate(cast<ConstantStructure>(n)); break;
+    case ConstantContinuationID: validate(cast<ConstantContinuation>(n)); break;
     case ConstantExpressionID:   validate(cast<ConstantExpression>(n)); break;
       break; // Not implemented yet
     case DocumentationID:

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

==============================================================================
--- hlvm/trunk/hlvm/Reader/XMLReader.cpp (original)
+++ hlvm/trunk/hlvm/Reader/XMLReader.cpp Sat Jul  7 19:02:27 2007
@@ -410,20 +410,14 @@
   switch (token) {
     case TKN_false:   
     {
-      C = ast->new_ConstantBoolean(false, getLocator(cur)); 
-      if (actualName.empty())
-        C->setName("bool_false");
-      else
-        C->setName(actualName);
+      std::string name = actualName.empty() ? "bool_false" : actualName;
+      C = ast->new_ConstantBoolean(name, false, getLocator(cur)); 
       break;
     }
     case TKN_true:
     {
-      C = ast->new_ConstantBoolean(true, getLocator(cur));
-      if (actualName.empty())
-        C->setName("bool_true");
-      else
-        C->setName(actualName);
+      std::string name = actualName.empty() ? "bool_true" : actualName;
+      C = ast->new_ConstantBoolean(name,true, getLocator(cur));
       break;
     }
     case TKN_bool:
@@ -433,11 +427,9 @@
       xmlNodePtr child = cur->children;
       getTextContent(child,buffer);
       bool value = recognize_boolean( buffer.c_str() );
-      C = ast->new_ConstantBoolean(value, getLocator(cur));
-      if (actualName.empty())
-        C->setName(std::string("bool_") + (value?"true":"false"));
-      else
-        C->setName(actualName);
+      std::string name = actualName.empty() ? std::string("bool_") + 
+        (value?"true_":"false") : actualName;
+      C = ast->new_ConstantBoolean(name, value, getLocator(cur));
       break;
     }
     case TKN_bin:
@@ -451,11 +443,9 @@
       getTextContent(child,value);
       uint16_t base = (token == TKN_dec ? 10 : (token == TKN_hex ? 16 : 
                       (token == TKN_oct ? 8 : (token == TKN_bin ? 2 : 10))));
-      C = ast->new_ConstantInteger(value, base, Ty, getLocator(cur));
-      if (actualName.empty())
-        C->setName(std::string("int_") + value);
-      else
-        C->setName(actualName);
+      std::string name = actualName.empty() ? 
+        std::string("int_") + value : actualName;
+      C = ast->new_ConstantInteger(name, value, base, Ty, getLocator(cur));
       break;
     }
     case TKN_flt:
@@ -466,11 +456,9 @@
       std::string value;
       xmlNodePtr child = cur->children;
       getTextContent(child,value);
-      C = ast->new_ConstantReal(value, Ty, getLocator(cur));
-      if (actualName.empty())
-        C->setName(std::string("real_") + value);
-      else
-        C->setName(actualName);
+      std::string name = actualName.empty() ? std::string("real_") + value :
+          actualName;
+      C = ast->new_ConstantReal(name,value, Ty, getLocator(cur));
       break;
     }
     case TKN_string:
@@ -479,11 +467,9 @@
       std::string value;
       xmlNodePtr child = cur->children;
       getTextContent(child,value);
-      C =  ast->new_ConstantString(value,getLocator(cur));
-      if (actualName.empty())
-        C->setName(std::string("str_") + value);
-      else
-        C->setName(actualName);
+      std::string name = actualName.empty() ? std::string("str_") + value :
+          actualName;
+      C =  ast->new_ConstantString(name,value,getLocator(cur));
       break;
     }
     default:





More information about the llvm-commits mailing list