[llvm-commits] [hlvm] r38364 - in /hlvm/trunk/hlvm: AST/AST.cpp AST/AST.h AST/Bundle.cpp AST/Bundle.h AST/ContainerType.cpp AST/Linkables.h AST/MemoryOps.h AST/SymbolTable.cpp AST/SymbolTable.h CodeGen/LLVMGenerator.cpp Pass/Pass.cpp Pass/Validate.cpp Reader/XMLReader.cpp

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


Author: reid
Date: Sat Jul  7 19:02:41 2007
New Revision: 38364

URL: http://llvm.org/viewvc/llvm-project?rev=38364&view=rev
Log:
Don't make Bundles differentiate between linkables and constant values. They 
are all just constants and share the same namespace. Make use of this in 
detecting rename situations and add a usecase to ensure we always catch
illegal renames.

Modified:
    hlvm/trunk/hlvm/AST/AST.cpp
    hlvm/trunk/hlvm/AST/AST.h
    hlvm/trunk/hlvm/AST/Bundle.cpp
    hlvm/trunk/hlvm/AST/Bundle.h
    hlvm/trunk/hlvm/AST/ContainerType.cpp
    hlvm/trunk/hlvm/AST/Linkables.h
    hlvm/trunk/hlvm/AST/MemoryOps.h
    hlvm/trunk/hlvm/AST/SymbolTable.cpp
    hlvm/trunk/hlvm/AST/SymbolTable.h
    hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp
    hlvm/trunk/hlvm/Pass/Pass.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=38364&r1=38363&r2=38364&view=diff

==============================================================================
--- hlvm/trunk/hlvm/AST/AST.cpp (original)
+++ hlvm/trunk/hlvm/AST/AST.cpp Sat Jul  7 19:02:41 2007
@@ -145,7 +145,7 @@
   if (n)
     return llvm::cast<OpaqueType>(n);
   OpaqueType* ot = this->new_OpaqueType(name);
-  unresolvedTypes.insert(ot->getName(), ot);
+  unresolvedTypes.insert(ot);
   return ot;
 }
 
@@ -158,7 +158,7 @@
     // FIXME: Replace all uses of "ot" with "ty"
     unresolvedTypes.erase(ot);
   }
-  types.insert(ty->getName(),ty);
+  types.insert(ty);
 }
 
 void
@@ -229,7 +229,7 @@
   PT->setElementType(Ty);
   PT->setName(ptr_name);
   PT->setParent(Ty->getContainingBundle());
-  ast->types.insert(ptr_name,PT);
+  ast->types.insert(PT);
   return PT;
 }
 
@@ -492,6 +492,18 @@
   return result;
 }
 
+ContinuationType*
+AST::new_ContinuationType(
+  const std::string& id, 
+  const Locator* loc)
+{
+  ContinuationType* result = new ContinuationType();
+  result->setLocator(loc);
+  result->setName(id);
+  static_cast<ASTImpl*>(this)->addType(result);
+  return result;
+}
+
 SignatureType*
 AST::new_SignatureType(
   const std::string& id, 
@@ -805,14 +817,14 @@
 AST::new_AutoVarOp(
     const std::string& name, 
     const Type* Ty, 
-    ConstantValue* op1,
+    Constant* init,
     const Locator* loc)
 {
   hlvmAssert(Ty != 0 && "AutoVarOp must have a Type!");
   AutoVarOp* result = new AutoVarOp();
   result->setType(Ty);
   result->setLocator(loc);
-  result->setInitializer(op1);
+  result->setInitializer(init);
   result->setName(name);
   return result;
 }

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

==============================================================================
--- hlvm/trunk/hlvm/AST/AST.h (original)
+++ hlvm/trunk/hlvm/AST/AST.h Sat Jul  7 19:02:41 2007
@@ -327,6 +327,13 @@
       const std::string& id,  ///< The name of the structure type
       const Locator* loc = 0  ///< The source locator
     );
+    /// Create a new ContinuationType node. A ContinuationType is a type that 
+    /// is an ordered sequential arrangement of memory locations of various but 
+    /// definite types combined with the data necessary to make a continuation.
+    ContinuationType* new_ContinuationType(
+      const std::string& id,  ///< The name of the structure type
+      const Locator* loc = 0  ///< The source locator
+    );
     /// Create a new SignatureType node. A SignatureType specifies the type of
     /// a Function. It identifies the names and types of the arguments of a
     /// function and the type of its result value.
@@ -541,7 +548,7 @@
     AutoVarOp* new_AutoVarOp(
       const std::string& name, ///< Name of the autovar in its scope
       const Type* Ty,          ///< Type of the autovar
-      ConstantValue* op1,      ///< Initializer for the autovar
+      Constant* init,          ///< Initializer for the autovar
       const Locator* loc       ///< The source locator
     );
 

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Bundle.cpp (original)
+++ hlvm/trunk/hlvm/AST/Bundle.cpp Sat Jul  7 19:02:41 2007
@@ -43,16 +43,11 @@
 Bundle::insertChild(Node* kid)
 {
   hlvmAssert(kid && "Null child!");
-  if (const Type* Ty = dyn_cast<Type>(kid))
-    types.insert(Ty->getName(), Ty);
+  if (Type* Ty = dyn_cast<Type>(kid))
+    types.insert(Ty);
   else if (Constant* C = dyn_cast<Constant>(kid)) {
-    const std::string& name = C->getName();
-    values.push_back(C);
-    if (isa<ConstantValue>(C)) {
-      cvals.insert(name, cast<ConstantValue>(kid));
-    } else if (isa<Linkable>(C)) {
-      linkables.insert(name, cast<Linkable>(kid));
-    }
+    clist.push_back(C);
+    ctable.insert(C);
   } else
     hlvmAssert("Don't know how to insert that in a Bundle");
 }
@@ -65,12 +60,9 @@
     types.erase(Ty->getName());
   else if (Constant* C = dyn_cast<Constant>(kid)) {
     // This is sucky slow, but we probably won't be removing nodes that much.
-    for (value_iterator I = value_begin(), E = value_end(); I != E; ++I )
-      if (*I == C) { values.erase(I); break; }
-    if (isa<ConstantValue>(C))
-      cvals.erase(cast<ConstantValue>(C)->getName());
-    else if (isa<Linkable>(C))
-      linkables.erase(cast<Linkable>(C)->getName());
+    for (clist_iterator I = clist_begin(), E = clist_end(); I != E; ++I )
+      if (*I == C) { clist.erase(I); break; }
+    ctable.erase(C->getName());
   } else 
     hlvmAssert(!"That node isn't my child");
 }
@@ -83,19 +75,11 @@
   return 0;
 }
 
-ConstantValue*  
-Bundle::find_cval(const std::string& name) const
-{
-  if (Node* result = cvals.lookup(name))
-    return llvm::cast<ConstantValue>(result);
-  return 0;
-}
-
-Linkable*  
-Bundle::find_linkable(const std::string& name) const
+Constant*  
+Bundle::find_const(const std::string& name) const
 {
-  if (Node* result = linkables.lookup(name))
-    return llvm::cast<Linkable>(result);
+  if (Constant* result = ctable.lookup(name))
+    return llvm::cast<Constant>(result);
   return 0;
 }
 

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Bundle.h (original)
+++ hlvm/trunk/hlvm/AST/Bundle.h Sat Jul  7 19:02:41 2007
@@ -54,27 +54,23 @@
   /// @name Types
   /// @{
   public:
-    typedef SymbolTable<Type> TypeList;
-    typedef TypeList::iterator type_iterator;
-    typedef TypeList::const_iterator type_const_iterator;
-
-    typedef std::vector<Value*> ValueList;
-    typedef ValueList::iterator value_iterator;
-    typedef ValueList::const_iterator value_const_iterator;
-
-    typedef SymbolTable<ConstantValue> CValList;
-    typedef CValList::iterator cval_iterator;
-    typedef CValList::const_iterator cval_const_iterator;
-
-    typedef SymbolTable<Linkable> LinkableList;
-    typedef LinkableList::iterator linkable_iterator;
-    typedef LinkableList::const_iterator linkable_const_iterator;
+    typedef SymbolTable<Type> TypeTable;
+    typedef TypeTable::iterator type_iterator;
+    typedef TypeTable::const_iterator type_const_iterator;
+
+    typedef std::vector<Constant*> ConstantList;
+    typedef ConstantList::iterator clist_iterator;
+    typedef ConstantList::const_iterator clist_const_iterator;
+
+    typedef SymbolTable<Constant> ConstantTable;
+    typedef ConstantTable::iterator ctable_iterator;
+    typedef ConstantTable::const_iterator ctable_const_iterator;
 
   /// @}
   /// @name Constructors
   /// @{
   protected:
-    Bundle() : Documentable(BundleID), name(), types(), linkables() {}
+    Bundle() : Documentable(BundleID), name(), types(), clist(), ctable() {}
     virtual ~Bundle();
 
   /// @}
@@ -97,9 +93,8 @@
   /// @name Finders
   /// @{
   public:
-    Type*              find_type(const std::string& n) const;
-    ConstantValue*     find_cval(const std::string& n) const;
-    Linkable*          find_linkable(const std::string& n) const;
+    Type*      find_type(const std::string& n) const;
+    Constant*  find_const(const std::string& n) const;
 
   /// @}
   /// @name Iterators
@@ -115,39 +110,30 @@
 
     /// Value Insertion Order Iteration
     //
-    value_iterator          value_begin()       { return values.begin(); }
-    value_const_iterator    value_begin() const { return values.begin(); }
-    value_iterator          value_end  ()       { return values.end(); }
-    value_const_iterator    value_end  () const { return values.end(); }
-    size_t                  value_size () const { return values.size(); }
-    bool                    value_empty() const { return values.empty(); }
+    clist_iterator          clist_begin()       { return clist.begin(); }
+    clist_const_iterator    clist_begin() const { return clist.begin(); }
+    clist_iterator          clist_end  ()       { return clist.end(); }
+    clist_const_iterator    clist_end  () const { return clist.end(); }
+    size_t                  clist_size () const { return clist.size(); }
+    bool                    clist_empty() const { return clist.empty(); }
 
     /// ConstantValue Symbol Table iteration
-    cval_iterator           cval_begin()       { return cvals.begin(); }
-    cval_const_iterator     cval_begin() const { return cvals.begin(); }
-    cval_iterator           cval_end  ()       { return cvals.end(); }
-    cval_const_iterator     cval_end  () const { return cvals.end(); }
-    size_t                  cval_size () const { return cvals.size(); }
-    bool                    cval_empty() const { return cvals.empty(); }
-
-    /// Linkable Symbol Table iteration
-    linkable_iterator       linkable_begin()       { return linkables.begin(); }
-    linkable_const_iterator linkable_begin() const { return linkables.begin(); }
-    linkable_iterator       linkable_end  ()       { return linkables.end(); }
-    linkable_const_iterator linkable_end  () const { return linkables.end(); }
-    size_t                  linkable_size () const { return linkables.size(); }
-    bool                    linkable_empty() const { return linkables.empty(); }
+    ctable_iterator         ctable_begin()       { return ctable.begin(); }
+    ctable_const_iterator   ctable_begin() const { return ctable.begin(); }
+    ctable_iterator         ctable_end  ()       { return ctable.end(); }
+    ctable_const_iterator   ctable_end  () const { return ctable.end(); }
+    size_t                  ctable_size () const { return ctable.size(); }
+    bool                    ctable_empty() const { return ctable.empty(); }
 
   /// @}
   /// @name Data
   /// @{
   protected:
-    std::string  name;      ///< The name for this bundle
-    TypeList     types;     ///< The list of types
-    TypeList     unresolvedTypes; ///< The list of forward referenced types
-    ValueList    values;    ///< The list of values in insertion order
-    CValList     cvals;     ///< The list of constant values
-    LinkableList linkables; ///< The list of linkables
+    std::string   name;      ///< The name for this bundle
+    TypeTable     types;     ///< The list of types
+    TypeTable     unresolvedTypes; ///< The list of forward referenced types
+    ConstantList  clist;    ///< The list of values in insertion order
+    ConstantTable ctable;
 
   /// @}
   friend class AST;

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

==============================================================================
--- hlvm/trunk/hlvm/AST/ContainerType.cpp (original)
+++ hlvm/trunk/hlvm/AST/ContainerType.cpp Sat Jul  7 19:02:41 2007
@@ -61,6 +61,7 @@
 }
 
 StructureType::~StructureType() { }
+ContinuationType::~ContinuationType() { }
 
 SignatureType::~SignatureType() { }
 

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

==============================================================================
--- hlvm/trunk/hlvm/AST/Linkables.h (original)
+++ hlvm/trunk/hlvm/AST/Linkables.h Sat Jul  7 19:02:41 2007
@@ -37,9 +37,6 @@
 namespace hlvm 
 {
 
-class Type; // Forward declare
-class Constant;
-
 /// This enumeration is used to specify the kinds of linkage that are
 /// permitted for a Linkable.
 /// @brief Enumeration of ways to link bundles
@@ -115,7 +112,7 @@
   /// @{
   public:
     bool isConstant() const { return flags & 0x0008; }
-    ConstantValue* getInitializer() const { return init; }
+    Constant* getInitializer() const { return init; }
     bool hasInitializer() const { return init != 0; }
     bool isZeroInitialized() const { return init == 0; }
     static inline bool classof(const Variable*) { return true; }
@@ -126,13 +123,13 @@
   /// @{
   public:
     void setIsConstant(bool v) { flags |= 0x0008; }
-    void setInitializer(ConstantValue* C) { init = C; }
+    void setInitializer(Constant* C) { init = C; }
 
   /// @}
   /// @name Data
   /// @{
   protected:
-    ConstantValue* init;
+    Constant* init;
   /// @}
   friend class AST;
 };

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

==============================================================================
--- hlvm/trunk/hlvm/AST/MemoryOps.h (original)
+++ hlvm/trunk/hlvm/AST/MemoryOps.h Sat Jul  7 19:02:41 2007
@@ -188,7 +188,7 @@
   public:
     const std::string& getName() const { return name; }
     bool hasInitializer() const { return initializer != 0; }
-    ConstantValue* getInitializer() const { return initializer; }
+    Constant* getInitializer() const { return initializer; }
     bool isZeroInitialized() const { return initializer == 0; }
     static inline bool classof(const AutoVarOp*) { return true; }
     static inline bool classof(const Node* N) { return N->is(AutoVarOpID); }
@@ -198,14 +198,14 @@
   /// @{
   public:
     void setName(const std::string& n) { name = n; }
-    void setInitializer(ConstantValue* C) { initializer = C; }
+    void setInitializer(Constant* C) { initializer = C; }
 
   /// @}
   /// @name Data
   /// @{
   protected:
     std::string name;
-    ConstantValue* initializer;
+    Constant* initializer;
   /// @}
   friend class AST;
 };

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

==============================================================================
--- hlvm/trunk/hlvm/AST/SymbolTable.cpp (original)
+++ hlvm/trunk/hlvm/AST/SymbolTable.cpp Sat Jul  7 19:02:41 2007
@@ -45,7 +45,7 @@
 
   // See if the name exists. Loop until we find a free name in the symbol table
   // by incrementing the last_unique_ counter.
-  while (map_.find(try_name) != end)
+  while (map_.find(&try_name) != end)
     try_name = base_name + 
       llvm::utostr(++last_unique_);
   return try_name;
@@ -54,7 +54,7 @@
 // lookup a node by name - returns null on failure
 template<class ElemType>
 ElemType* SymbolTable<ElemType>::lookup(const std::string& name) const {
-  const_iterator TI = map_.find(name);
+  const_iterator TI = map_.find(&name);
   if (TI != map_.end())
     return const_cast<ElemType*>(TI->second);
   return 0;
@@ -83,16 +83,15 @@
 
 // insert - Insert a node into the symbol table with the specified name...
 template<class ElemType>
-void SymbolTable<ElemType>::insert(const std::string& Name, const ElemType* N) {
+void SymbolTable<ElemType>::insert(ElemType* N) {
   hlvmAssert(N && "Can't insert null node into symbol table!");
 
   // Check to see if there is a naming conflict.  If so, rename this type!
-  std::string unique_name = Name;
-  if (lookup(Name))
-    unique_name = getUniqueName(Name);
+  if (lookup(N->getName()))
+    N->setName(getUniqueName(N->getName()));
 
   // Insert the map entry
-  map_.insert(make_pair(unique_name, N));
+  map_.insert(make_pair(&N->getName(), N));
 }
 
 /// rename - Given a value with a non-empty name, remove its existing entry
@@ -102,21 +101,18 @@
 /// symtab with that name (which could invalidate iterators to that plane).
 template<class ElemType>
 bool SymbolTable<ElemType>::rename(ElemType *N, const std::string &name) {
-  for (iterator NI = map_.begin(), NE = map_.end(); NI != NE; ++NI) {
-    if (NI->second == N) {
-      // Remove the old entry.
-      map_.erase(NI);
-      // Add the new entry.
-      this->insert(name,N);
-      return true;
-    }
+  iterator TI = map_.find(&name);
+  if (TI != map_.end()) {
+    map_.erase(TI);
+    N->setName(name);
+    this->insert(N);
+    return true;
   }
   return false;
 }
 
 // instantiate for Types and Linkabes
 template class SymbolTable<Type>;
-template class SymbolTable<ConstantValue>;
-template class SymbolTable<Linkable>;
+template class SymbolTable<Constant>;
 
 }

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

==============================================================================
--- hlvm/trunk/hlvm/AST/SymbolTable.h (original)
+++ hlvm/trunk/hlvm/AST/SymbolTable.h Sat Jul  7 19:02:41 2007
@@ -31,6 +31,7 @@
 #define HLVM_AST_SYMBOLTABLE_H
 
 #include <map>
+#include <string>
 
 namespace hlvm 
 {
@@ -43,8 +44,15 @@
 /// @name Types
 /// @{
 public:
+  struct StringPointerLess {
+    bool operator()(const std::string* A, const std::string* B) const {
+      return *A < *B;
+    }
+  };
+
   /// @brief A mapping of names to nodes.
-  typedef typename std::map<const std::string, const ElemType*> NodeMap;
+  typedef typename 
+    std::map<const std::string*, ElemType*, StringPointerLess> NodeMap;
 
   /// @brief An iterator over the NodeMap.
   typedef typename NodeMap::iterator iterator;
@@ -108,7 +116,7 @@
   /// be a many-to-one mapping between names and nodes. This method allows a 
   /// node with an existing entry in the symbol table to get a new name.
   /// @brief Insert a node under a new name.
-  void insert(const std::string &Name, const ElemType *N);
+  void insert(ElemType *N);
 
   /// Remove a node at the specified position in the symbol table.
   /// @returns the removed ElemType.
@@ -116,7 +124,7 @@
   ElemType* erase(iterator TI);
 
   /// Remove a node using a specific key
-  bool erase(const std::string& name) { return map_.erase(name) > 0; }
+  bool erase(const std::string& name) { return map_.erase(&name) > 0; }
 
   /// Remove a specific ElemType from the symbol table. This isn't fast, linear
   /// search, O(n), algorithm.
@@ -132,7 +140,8 @@
 /// @{
 private:
   NodeMap map_; ///< This is the mapping of names to types.
-  mutable unsigned long last_unique_; ///< Counter for tracking unique names
+  mutable uint64_t order_;  
+  mutable uint64_t last_unique_; ///< Counter for tracking unique names
 /// @}
 };
 

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

==============================================================================
--- hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp (original)
+++ hlvm/trunk/hlvm/CodeGen/LLVMGenerator.cpp Sat Jul  7 19:02:41 2007
@@ -87,7 +87,7 @@
   typedef std::map<const hlvm::Block*,llvm::Instruction*> ResultsMap;
   typedef std::map<const hlvm::Variable*,llvm::Value*> VariableMap;
   typedef std::map<const hlvm::AutoVarOp*,llvm::Value*> AutoVarMap;
-  typedef std::map<const hlvm::ConstantValue*,llvm::Constant*> ConstantMap;
+  typedef std::map<const hlvm::Constant*,llvm::Constant*> ConstantMap;
   typedef std::map<const hlvm::Function*,llvm::Function*> FunctionMap;
   ModuleList modules;           ///< The list of modules we construct
   llvm::Module*     lmod;       ///< The current module we're generation 
@@ -147,7 +147,7 @@
 
   /// Conversion functions
   const llvm::Type* getType(const hlvm::Type* ty);
-  llvm::Constant* getConstant(const hlvm::ConstantValue* C);
+  llvm::Constant* getConstant(const hlvm::Constant* C);
   llvm::Value* getVariable(const hlvm::Variable* V);
   llvm::Function* getFunction(const hlvm::Function* F);
   inline llvm::GlobalValue::LinkageTypes getLinkageTypes(LinkageKinds lk);
@@ -573,14 +573,14 @@
 }
 
 llvm::Constant*
-LLVMGeneratorPass::getConstant(const hlvm::ConstantValue* C)
+LLVMGeneratorPass::getConstant(const hlvm::Constant* C)
 {
   hlvmAssert(C!=0);
   hlvmAssert(C->isConstantValue());
 
   // First, lets see if its cached already
   ConstantMap::iterator I = 
-    consts.find(const_cast<hlvm::ConstantValue*>(C));
+    consts.find(const_cast<hlvm::Constant*>(C));
   if (I != consts.end())
     return I->second;
 
@@ -628,7 +628,7 @@
       break;
   }
   if (result)
-    consts[const_cast<hlvm::ConstantValue*>(C)] = result;
+    consts[const_cast<hlvm::Constant*>(C)] = result;
   else
     hlvmDeadCode("Didn't find constant");
   return result;

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

==============================================================================
--- hlvm/trunk/hlvm/Pass/Pass.cpp (original)
+++ hlvm/trunk/hlvm/Pass/Pass.cpp Sat Jul  7 19:02:41 2007
@@ -158,13 +158,13 @@
     runPreOrder(const_cast<Type*>(TI->second));
     runPostOrder(const_cast<Type*>(TI->second));
   }
-  for (Bundle::value_iterator CI = b->value_begin(), CE = b->value_end(); 
+  for (Bundle::clist_iterator CI = b->clist_begin(), CE = b->clist_end(); 
        CI != CE; ++CI) {
-    runPreOrder(const_cast<Value*>(*CI));
+    runPreOrder(const_cast<Constant*>(*CI));
     if (Function* F = dyn_cast<Function>(*CI))
       if (Block* B = F->getBlock())
         runOn(B);
-    runPostOrder(const_cast<Value*>(*CI));
+    runPostOrder(const_cast<Constant*>(*CI));
   }
   runPostOrder(b);
 }

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

==============================================================================
--- hlvm/trunk/hlvm/Pass/Validate.cpp (original)
+++ hlvm/trunk/hlvm/Pass/Validate.cpp Sat Jul  7 19:02:41 2007
@@ -1032,18 +1032,12 @@
         error(op,"ReferenceOp not in a function?");
       else if (F->getArgument(arg->getName()) != arg)
         error(F,"Referent does not match function argument");
-    } else if (const ConstantValue* cval = dyn_cast<ConstantValue>(referent)) {
+    } else if (const Constant* cval = dyn_cast<Constant>(referent)) {
       Bundle* B = op->getContainingBundle();
       if (!B)
         error(op,"ReferenceOp not in a bundle?");
-      else if (B->find_cval(cval->getName()) != cval)
-        error(cval,"Referent does not match constant value");
-    } else if (const Linkable* lnkbl = dyn_cast<Linkable>(referent)) {
-      Bundle* B = op->getContainingBundle();
-      if (!B)
-        error(op,"ReferenceOp not in a bundle?");
-      else if (B->find_linkable(lnkbl->getName()) != lnkbl)
-        error(lnkbl,"Referent does not match linkable by name");
+      else if (B->find_const(cval->getName()) != cval)
+        error(cval,"Referent does not value found in Bundle");
     } else {
       error(op,"Referent of unknown kind");
     }

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

==============================================================================
--- hlvm/trunk/hlvm/Reader/XMLReader.cpp (original)
+++ hlvm/trunk/hlvm/Reader/XMLReader.cpp Sat Jul  7 19:02:41 2007
@@ -395,7 +395,7 @@
     const std::string& name,
     const Type* Ty)
 {
-  if (!name.empty() && bundle->find_linkable(name) != 0) {
+  if (!name.empty() && bundle->find_const(name) != 0) {
     error(getLocator(cur),std::string("Constant '") + name 
           + "' already exists.");
     return 0;
@@ -489,10 +489,9 @@
       std::string id = getAttribute(cur,"id");
       std::string name = actualName.empty() ? std::string("ptr_") + id :
           actualName;
-      Constant* referent =  bundle->find_cval(id);
-      // Didn't find a constant? Try a linkable
+      Constant* referent = bundle->find_const(id);
       if (!referent)
-        referent = bundle->find_linkable(id);
+        error(loc,"Unkown referent for constant pointer");
       C = ast->new_ConstantPointer(name,Ty,referent,loc);
       break;
     }
@@ -620,6 +619,8 @@
 {
   Locator* loc = getLocator(cur);
   std::string name = getAttribute(cur,"id");
+  if (bundle->find_type(name))
+    error(loc,"Type '" + name + "' was already defined");
   const char* is = getAttribute(cur,"is");
   xmlNodePtr child = cur->children;
   Documentation* theDoc = parse<Documentation>(child);
@@ -637,6 +638,8 @@
 {
   Locator* loc = getLocator(cur);
   std::string name = getAttribute(cur,"id");
+  if (bundle->find_type(name))
+    error(loc,"Type '" + name + "' was already defined");
   const char* bits = getAttribute(cur,"bits");
   xmlNodePtr child = cur->children;
   Documentation* theDoc = parse<Documentation>(child);
@@ -656,6 +659,8 @@
 {
   Locator* loc = getLocator(cur);
   std::string name = getAttribute(cur,"id");
+  if (bundle->find_type(name))
+    error(loc,"Type '" + name + "' was already defined");
   const char* min = getAttribute(cur, "min");
   const char* max = getAttribute(cur, "max");
   xmlNodePtr child = cur->children;
@@ -677,6 +682,8 @@
 {
   Locator* loc = getLocator(cur);
   std::string name = getAttribute(cur,"id");
+  if (bundle->find_type(name))
+    error(loc,"Type '" + name + "' was already defined");
   const char* mantissa = getAttribute(cur, "mantissa");
   const char* exponent = getAttribute(cur, "exponent");
   xmlNodePtr child = cur->children;
@@ -699,6 +706,8 @@
   hlvmAssert(getToken(cur->name)==TKN_enumeration);
   Locator* loc = getLocator(cur);
   std::string name = getAttribute(cur,"id");
+  if (bundle->find_type(name))
+    error(loc,"Type '" + name + "' was already defined");
   EnumerationType* en = ast->new_EnumerationType(name,loc);
   xmlNodePtr child = checkDoc(cur,en);
   while (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE) {
@@ -716,6 +725,8 @@
   hlvmAssert(getToken(cur->name)==TKN_pointer);
   Locator* loc = getLocator(cur);
   std::string name = getAttribute(cur,"id");
+  if (bundle->find_type(name))
+    error(loc,"Type '" + name + "' was already defined");
   std::string type = getAttribute(cur,"to");
   PointerType* result = 
     ast->new_PointerType(name,getType(type),loc);
@@ -729,6 +740,8 @@
   hlvmAssert(getToken(cur->name)==TKN_array);
   Locator* loc = getLocator(cur);
   std::string name = getAttribute(cur,"id");
+  if (bundle->find_type(name))
+    error(loc,"Type '" + name + "' was already defined");
   std::string type = getAttribute(cur,"of");
   const char* len = getAttribute(cur,"length");
   ArrayType* result = ast->new_ArrayType(
@@ -743,6 +756,8 @@
   hlvmAssert(getToken(cur->name)==TKN_vector);
   Locator* loc = getLocator(cur);
   std::string name = getAttribute(cur,"id");
+  if (bundle->find_type(name))
+    error(loc,"Type '" + name + "' was already defined");
   std::string type = getAttribute(cur,"of");
   const char* len  = getAttribute(cur,"length");
   VectorType* result =
@@ -758,6 +773,8 @@
   hlvmAssert(getToken(cur->name)==TKN_structure);
   Locator* loc = getLocator(cur);
   std::string name = getAttribute(cur,"id");
+  if (bundle->find_type(name))
+    error(loc,"Type '" + name + "' was already defined");
   StructureType* struc = ast->new_StructureType(name,loc);
   xmlNodePtr child = checkDoc(cur,struc); 
   while (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE) {
@@ -774,12 +791,38 @@
   return struc;
 }
 
+template<> ContinuationType*
+XMLReaderImpl::parse<ContinuationType>(xmlNodePtr& cur)
+{
+  hlvmAssert(getToken(cur->name)==TKN_structure);
+  Locator* loc = getLocator(cur);
+  std::string name = getAttribute(cur,"id");
+  if (bundle->find_type(name))
+    error(loc,"Type '" + name + "' was already defined");
+  ContinuationType* cont = ast->new_ContinuationType(name,loc);
+  xmlNodePtr child = checkDoc(cur,cont); 
+  while (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE) {
+    hlvmAssert(getToken(child->name) == TKN_field && 
+               "Continuation only has fields");
+    std::string name = getAttribute(child,"id");
+    std::string type = getAttribute(child,"type");
+    Locator* fldLoc = getLocator(child);
+    Field* fld = ast->new_Field(name,getType(type),fldLoc);
+    cont->addField(fld);
+    checkDoc(child,fld);
+    child = child->next;
+  }
+  return cont;
+}
+
 template<> SignatureType*
 XMLReaderImpl::parse<SignatureType>(xmlNodePtr& cur)
 {
   hlvmAssert(getToken(cur->name)==TKN_signature);
   Locator* loc = getLocator(cur);
   std::string name = getAttribute(cur,"id");
+  if (bundle->find_type(name))
+    error(loc,"Type '" + name + "' was already defined");
   std::string result = getAttribute(cur,"result");
   const char* varargs = getAttribute(cur,"varargs",false);
   SignatureType* sig = 
@@ -804,8 +847,10 @@
 XMLReaderImpl::parse<OpaqueType>(xmlNodePtr& cur)
 {
   hlvmAssert(getToken(cur->name)==TKN_opaque);
-  Locator* loc = getLocator(cur);
   std::string name = getAttribute(cur,"id");
+  if (bundle->find_type(name))
+    error(loc,"Type '" + name + "' was already defined");
+  Locator* loc = getLocator(cur);
   OpaqueType* result = ast->new_OpaqueType(name,loc);
   checkDoc(cur,result);
   return result;
@@ -818,6 +863,8 @@
   Locator* loc = getLocator(cur);
   std::string name, type;
   getNameType(cur, name, type);
+  if (Constant* lkbl = bundle->find_const(name)) 
+    error(loc, "Name '" + name + "' is already in use");
   const char* cnst = getAttribute(cur, "const", false);
   const char* lnkg = getAttribute(cur, "linkage", false);
   const char* init = getAttribute(cur, "init", false);
@@ -828,7 +875,7 @@
   if (lnkg)
     var->setLinkageKind(recognize_LinkageKinds(lnkg));
   if (init) {
-    ConstantValue* initializer = bundle->find_cval(init);
+    Constant* initializer = bundle->find_const(init);
     if (initializer)
       var->setInitializer(initializer);
     else 
@@ -847,12 +894,11 @@
   getNameType(cur, name, type);
   const Type* Ty = getType(type);
   const char* init = getAttribute(cur,"init",false);
-  ConstantValue *initializer = 0;
+  Constant*initializer = 0;
   if (init) {
-    initializer = bundle->find_cval(init);
+    initializer = bundle->find_const(init);
     if (!initializer)
-      error(loc,std::string("Constant '") + init + 
-            "' not found in initializer.");
+      error(loc,std::string("Initializer '") + init + "' not found .");
   }
   AutoVarOp* autovar = ast->AST::new_AutoVarOp(name,Ty,initializer,loc);
   checkDoc(cur,autovar);
@@ -884,12 +930,8 @@
 
   // Didn't find an autovar? Try a constant value.
   if (!referent)
-    referent= bundle->find_cval(id);
+    referent= bundle->find_const(id);
     
-  // Didn't find an constant? Try a linkable
-  if (!referent)
-    referent = bundle->find_linkable(id);
-
   // Didn't find a linkable? Try an error message for size
   if (!referent)
       error(loc,std::string("Referent '") + id + "' not found");
@@ -1027,7 +1069,7 @@
   Locator* loc = getLocator(cur);
   std::string name, type;
   getNameType(cur, name, type);
-  Linkable* lkbl = bundle->find_linkable(name);
+  Constant* lkbl = bundle->find_const(name);
   if (lkbl) {
     if (llvm::isa<Function>(lkbl)) {
       func = llvm::cast<Function>(lkbl);





More information about the llvm-commits mailing list