[llvm-commits] [hlvm] r38054 - in /hlvm/trunk: hlvm/AST/AST.cpp hlvm/AST/AST.h hlvm/AST/Block.h hlvm/AST/Bundle.cpp hlvm/AST/Bundle.h hlvm/AST/ContainerType.cpp hlvm/AST/ContainerType.h hlvm/AST/Function.cpp hlvm/AST/Function.h hlvm/AST/Import.h hlvm/AST/LinkageItem.h hlvm/AST/Node.cpp hlvm/AST/Node.h hlvm/AST/Type.cpp hlvm/AST/Type.h hlvm/Reader/XML/HLVM.rng hlvm/Reader/XML/XMLReader.cpp hlvm/Writer/XML/XMLWriter.cpp test/xml2xml/intrinsics.hlx
Reid Spencer
reid at x10sys.com
Sat Jul 7 16:59:21 PDT 2007
Author: reid
Date: Sat Jul 7 18:59:21 2007
New Revision: 38054
URL: http://llvm.org/viewvc/llvm-project?rev=38054&view=rev
Log:
Add the ability to specify any of the intrinsic types as an atom.
Added:
hlvm/trunk/test/xml2xml/intrinsics.hlx
Modified:
hlvm/trunk/hlvm/AST/AST.cpp
hlvm/trunk/hlvm/AST/AST.h
hlvm/trunk/hlvm/AST/Block.h
hlvm/trunk/hlvm/AST/Bundle.cpp
hlvm/trunk/hlvm/AST/Bundle.h
hlvm/trunk/hlvm/AST/ContainerType.cpp
hlvm/trunk/hlvm/AST/ContainerType.h
hlvm/trunk/hlvm/AST/Function.cpp
hlvm/trunk/hlvm/AST/Function.h
hlvm/trunk/hlvm/AST/Import.h
hlvm/trunk/hlvm/AST/LinkageItem.h
hlvm/trunk/hlvm/AST/Node.cpp
hlvm/trunk/hlvm/AST/Node.h
hlvm/trunk/hlvm/AST/Type.cpp
hlvm/trunk/hlvm/AST/Type.h
hlvm/trunk/hlvm/Reader/XML/HLVM.rng
hlvm/trunk/hlvm/Reader/XML/XMLReader.cpp
hlvm/trunk/hlvm/Writer/XML/XMLWriter.cpp
Modified: hlvm/trunk/hlvm/AST/AST.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/AST.cpp?rev=38054&r1=38053&r2=38054&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/AST.cpp (original)
+++ hlvm/trunk/hlvm/AST/AST.cpp Sat Jul 7 18:59:21 2007
@@ -72,6 +72,91 @@
return result;
}
+Type*
+AST::new_IntegerType(
+ const Locator&loc,
+ const std::string& id,
+ uint64_t bits,
+ bool isSigned )
+{
+ IntegerType* result = new IntegerType();
+ result->setBits(bits);
+ result->setSigned(isSigned);
+ result->setLocator(loc);
+ result->setName(id);
+ return result;
+}
+
+Type*
+AST::new_RealType(
+ const Locator&loc,
+ const std::string& id,
+ uint32_t mantissa,
+ uint32_t exponent)
+{
+ RealType* result = new RealType();
+ result->setMantissa(mantissa);
+ result->setExponent(exponent);
+ result->setLocator(loc);
+ result->setName(id);
+ return result;
+}
+
+Type*
+AST::new_AnyType(const Locator&loc, const std::string& id)
+{
+ AnyType* result = new AnyType();
+ result->setLocator(loc);
+ result->setName(id);
+ return result;
+}
+
+Type*
+AST::new_BooleanType(const Locator&loc, const std::string& id)
+{
+ BooleanType* result = new BooleanType();
+ result->setLocator(loc);
+ result->setName(id);
+ return result;
+}
+
+Type*
+AST::new_CharacterType(const Locator&loc, const std::string& id)
+{
+ CharacterType* result = new CharacterType();
+ result->setLocator(loc);
+ result->setName(id);
+ return result;
+}
+
+Type*
+AST::new_OctetType(const Locator&loc, const std::string& id)
+{
+ OctetType* result = new OctetType();
+ result->setLocator(loc);
+ result->setName(id);
+ return result;
+}
+
+Type*
+AST::new_VoidType(const Locator&loc, const std::string& id)
+{
+ VoidType* result = new VoidType();
+ result->setLocator(loc);
+ result->setName(id);
+ return result;
+}
+
+Type*
+AST::new_RangeType(const Locator&loc, const std::string& id, int64_t min, int64_t max)
+{
+ RangeType* result = new RangeType();
+ result->setLocator(loc);
+ result->setName(id);
+ result->setMin(min);
+ result->setMax(max);
+ return result;
+}
SignatureType*
AST::new_SignatureType(const Locator& loc, const std::string& id)
{
Modified: hlvm/trunk/hlvm/AST/AST.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/AST.h?rev=38054&r1=38053&r2=38054&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/AST.h (original)
+++ hlvm/trunk/hlvm/AST/AST.h Sat Jul 7 18:59:21 2007
@@ -90,7 +90,29 @@
Import* new_Import(const Locator& loc, const std::string& id);
SignatureType* new_SignatureType(const Locator& l, const std::string& id);
Variable* new_Variable(const Locator& loc, const std::string& id);
-
+ Type* new_IntegerType(
+ const Locator&loc, ///< The locator of the declaration
+ const std::string& id, ///< The name of the atom
+ uint64_t bits = 32, ///< The number of bits
+ bool isSigned = true ///< The signedness
+ );
+ Type* new_RangeType(
+ const Locator&loc, ///< The locator of the declaration
+ const std::string& id, ///< The name of the atom
+ int64_t min, ///< The minimum value accepted in range
+ int64_t max ///< The maximum value accepted in range
+ );
+ Type* new_RealType(
+ const Locator&loc, ///< The locator of the declaration
+ const std::string& id, ///< The name of the atom
+ uint32_t mantissa = 52, ///< The bits in the mantissa (fraction)
+ uint32_t exponent = 11 ///< The bits in the exponent
+ );
+ Type* new_AnyType(const Locator&loc, const std::string& id);
+ Type* new_BooleanType(const Locator&loc, const std::string& id);
+ Type* new_CharacterType(const Locator&loc, const std::string& id);
+ Type* new_OctetType(const Locator&loc, const std::string& id);
+ Type* new_VoidType(const Locator&loc, const std::string& id);
/// @}
/// @name Data
/// @{
Modified: hlvm/trunk/hlvm/AST/Block.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Block.h?rev=38054&r1=38053&r2=38054&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Block.h (original)
+++ hlvm/trunk/hlvm/AST/Block.h Sat Jul 7 18:59:21 2007
@@ -43,12 +43,20 @@
/// contained in a Bundle. Local variables are always contained in a
/// Function.
/// @brief HLVM AST Variable Node
- class Block : public ParentNode
+ class Block : public Node
{
+ /// @name Types
+ /// @{
+ public:
+ typedef std::vector<Operator*> NodeList;
+ typedef NodeList::iterator iterator;
+ typedef NodeList::const_iterator const_iterator;
+
+ /// @}
/// @name Constructors
/// @{
public:
- Block() : ParentNode(BlockID), ops_() {}
+ Block() : Node(BlockID), ops() {}
virtual ~Block();
/// @}
@@ -59,10 +67,25 @@
static inline bool classof(const Node* N) { return N->isBlock(); }
/// @}
+ /// @name Iterators
+ /// @{
+ public:
+ iterator begin() { return ops.begin(); }
+ const_iterator begin() const { return ops.begin(); }
+ iterator end () { return ops.end(); }
+ const_iterator end () const { return ops.end(); }
+ size_t size () const { return ops.size(); }
+ bool empty() const { return ops.empty(); }
+ Operator* front() { return ops.front(); }
+ const Operator*front() const { return ops.front(); }
+ Operator* back() { return ops.back(); }
+ const Operator*back() const { return ops.back(); }
+
+ /// @}
/// @name Data
/// @{
protected:
- std::vector<Operator*> ops_; ///< The operators the Block contains
+ std::vector<Operator*> ops; ///< The operators the Block contains
/// @}
friend class AST;
};
Modified: hlvm/trunk/hlvm/AST/Bundle.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Bundle.cpp?rev=38054&r1=38053&r2=38054&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Bundle.cpp (original)
+++ hlvm/trunk/hlvm/AST/Bundle.cpp Sat Jul 7 18:59:21 2007
@@ -28,13 +28,11 @@
//===----------------------------------------------------------------------===//
#include <hlvm/AST/Bundle.h>
+#include <hlvm/AST/LinkageItem.h>
-namespace hlvm {
-namespace AST {
+using namespace llvm;
-Bundle::~Bundle()
-{
-}
+namespace hlvm { namespace AST {
Bundle*
Bundle::create(const Locator& loc, const std::string& id)
@@ -45,4 +43,26 @@
return result;
}
+Bundle::~Bundle()
+{
+}
+
+void
+Bundle::insertChild(Node* kid)
+{
+ assert(isa<LinkageItem>(kid) && "Can't insert that here");
+ kids.push_back(cast<LinkageItem>(kid));
+}
+
+void
+Bundle::removeChild(Node* kid)
+{
+ assert(isa<LinkageItem>(kid) && "Can't remove that 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 == kid) { kids.erase(I); return; }
+ }
+ assert(!"That node isn't my child");
+}
+
}}
Modified: hlvm/trunk/hlvm/AST/Bundle.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Bundle.h?rev=38054&r1=38053&r2=38054&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Bundle.h (original)
+++ hlvm/trunk/hlvm/AST/Bundle.h Sat Jul 7 18:59:21 2007
@@ -32,23 +32,33 @@
#include <hlvm/AST/Node.h>
-namespace hlvm {
-namespace AST {
+namespace hlvm { namespace AST {
+
+ class LinkageItem;
+
/// This class represents an HLVM Bundle. A Bundle is simply a collection of
/// declarations and definitions. It is the root of the AST tree and also
/// the grouping and namespace construct in HLVM. Every compilation unit is
/// a Bundle. Bundles can also be nested in other Bundles. All programming
/// constructs are defined as child nodes of some Bundle.
/// @brief HLVM AST Bundle Node
- class Bundle : public ParentNode
+ class Bundle : public NamedNode
{
+ /// @name Types
+ /// @{
+ public:
+ typedef std::vector<LinkageItem*> NodeList;
+ typedef NodeList::iterator iterator;
+ typedef NodeList::const_iterator const_iterator;
+
+ /// @}
/// @name Constructors
/// @{
public:
static Bundle* create(const Locator& location, const std::string& pubid);
protected:
- Bundle() : ParentNode(BundleID) {}
+ Bundle() : NamedNode(BundleID) {}
virtual ~Bundle();
/// @}
@@ -59,9 +69,32 @@
static inline bool classof(const Node* N) { return N->isBundle(); }
/// @}
+ /// @name Mutators
+ /// @{
+ public:
+ virtual void insertChild(Node* kid);
+ virtual void removeChild(Node* kid);
+
+ /// @}
+ /// @name Iterators
+ /// @{
+ public:
+ iterator begin() { return kids.begin(); }
+ const_iterator begin() const { return kids.begin(); }
+ iterator end () { return kids.end(); }
+ const_iterator end () const { return kids.end(); }
+ size_t size () const { return kids.size(); }
+ bool empty() const { return kids.empty(); }
+ LinkageItem* front() { return kids.front(); }
+ const LinkageItem* front() const { return kids.front(); }
+ LinkageItem* back() { return kids.back(); }
+ const LinkageItem* back() const { return kids.back(); }
+
+ /// @}
/// @name Data
/// @{
protected:
+ NodeList kids; ///< The vector of children nodes.
/// @}
friend class AST;
};
Modified: hlvm/trunk/hlvm/AST/ContainerType.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/ContainerType.cpp?rev=38054&r1=38053&r2=38054&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/ContainerType.cpp (original)
+++ hlvm/trunk/hlvm/AST/ContainerType.cpp Sat Jul 7 18:59:21 2007
@@ -29,14 +29,85 @@
#include <hlvm/AST/ContainerType.h>
+using namespace llvm;
+
namespace hlvm { namespace AST {
ContainerType::~ContainerType()
{
}
+void
+ContainerType::insertChild(Node* n)
+{
+ assert(isa<Type>(n) && "Can't insert those here");
+ types.push_back(cast<Type>(n));
+}
+
+void
+ContainerType::removeChild(Node* n)
+{
+ assert(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; }
+ }
+ assert(!"That node isn't my child");
+}
+
+PointerType::~PointerType()
+{
+}
+
+void
+PointerType::insertChild(Node* n)
+{
+ assert(this->empty() && "Can't point to multiple types");
+ ContainerType::insertChild(n);
+}
+
+ArrayType::~ArrayType()
+{
+}
+
+void
+ArrayType::insertChild(Node* n)
+{
+ assert(this->empty() && "Can't have multi-typed arrays");
+ ContainerType::insertChild(n);
+}
+
+VectorType::~VectorType()
+{
+}
+
+void
+VectorType::insertChild(Node* n)
+{
+ assert(this->empty() && "Can't have multi-typed vectors");
+ ContainerType::insertChild(n);
+}
+
+StructureType::~StructureType()
+{
+}
+
+void
+StructureType::insertChild(Node* n)
+{
+ assert(isa<NamedType>(n) && "Can't insert those here");
+ types.push_back(cast<NamedType>(n));
+}
+
SignatureType::~SignatureType()
{
}
+void
+SignatureType::insertChild(Node* n)
+{
+ assert(isa<NamedType>(n) && "Can't insert those here");
+ types.push_back(cast<NamedType>(n));
+}
+
}}
Modified: hlvm/trunk/hlvm/AST/ContainerType.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/ContainerType.h?rev=38054&r1=38053&r2=38054&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/ContainerType.h (original)
+++ hlvm/trunk/hlvm/AST/ContainerType.h Sat Jul 7 18:59:21 2007
@@ -39,27 +39,57 @@
/// @brief HLVM AST Type Node
class ContainerType : public Type
{
+ /// @name Types
+ /// @{
+ public:
+ typedef std::vector<Type*> TypeList;
+ typedef TypeList::iterator iterator;
+ typedef TypeList::const_iterator const_iterator;
+
+ /// @}
/// @name Constructors
/// @{
public:
ContainerType(
NodeIDs id ///< The node id of the subclass
- ) : Type(id) {}
+ ) : Type(id), types() {}
virtual ~ContainerType();
/// @}
/// @name Accessors
/// @{
public:
-
// Methods to support type inquiry via is, cast, dyn_cast
static inline bool classof(const ContainerType*) { return true; }
static inline bool classof(const Type* T) { return T->isContainerType(); }
+
+ /// @}
+ /// @name Accessors
+ /// @{
+ public:
+ virtual void insertChild(Node* n);
+ virtual void removeChild(Node* n);
+
+ /// @}
+ /// @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(); }
+
/// @}
/// @name Data
/// @{
protected:
- std::vector<Type*> types_; ///< The contained types
+ std::vector<Type*> types; ///< The contained types
/// @}
};
@@ -80,6 +110,13 @@
// Methods to support type inquiry via is, cast, dyn_cast
static inline bool classof(const PointerType*) { return true; }
static inline bool classof(const Type* T) { return T->isPointerType(); }
+ static inline bool classof(const Node* T) { return T->is(PointerTypeID); }
+
+ /// @}
+ /// @name Accessors
+ /// @{
+ public:
+ virtual void insertChild(Node* n);
/// @}
/// @name Data
@@ -105,6 +142,14 @@
// Methods to support type inquiry via is, cast, dyn_cast
static inline bool classof(const ArrayType*) { return true; }
static inline bool classof(const Type* T) { return T->isArrayType(); }
+ static inline bool classof(const Node* T) { return T->is(ArrayTypeID); }
+
+ /// @}
+ /// @name Accessors
+ /// @{
+ public:
+ virtual void insertChild(Node* n);
+
/// @}
/// @name Data
/// @{
@@ -131,6 +176,14 @@
// Methods to support type inquiry via is, cast, dyn_cast
static inline bool classof(const VectorType*) { return true; }
static inline bool classof(const Type* T) { return T->isVectorType(); }
+ static inline bool classof(const Node* T) { return T->is(VectorTypeID); }
+
+ /// @}
+ /// @name Accessors
+ /// @{
+ public:
+ virtual void insertChild(Node* n);
+
/// @}
/// @name Data
/// @{
@@ -155,6 +208,15 @@
// Methods to support type inquiry via is, cast, dyn_cast
static inline bool classof(const StructureType*) { return true; }
static inline bool classof(const Type* T) { return T->isStructureType(); }
+ static inline bool classof(const Node* T)
+ { return T->is(StructureTypeID); }
+
+ /// @}
+ /// @name Accessors
+ /// @{
+ public:
+ virtual void insertChild(Node* n);
+
/// @}
/// @name Data
/// @{
@@ -179,6 +241,15 @@
// Methods to support type inquiry via is, cast, dyn_cast
static inline bool classof(const SignatureType*) { return true; }
static inline bool classof(const Type* T) { return T->isSignatureType(); }
+ static inline bool classof(const Node* T)
+ { return T->is(SignatureTypeID); }
+
+ /// @}
+ /// @name Accessors
+ /// @{
+ public:
+ virtual void insertChild(Node* n);
+
/// @}
/// @name Data
/// @{
Modified: hlvm/trunk/hlvm/AST/Function.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Function.cpp?rev=38054&r1=38053&r2=38054&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Function.cpp (original)
+++ hlvm/trunk/hlvm/AST/Function.cpp Sat Jul 7 18:59:21 2007
@@ -29,10 +29,37 @@
#include <hlvm/AST/Function.h>
-namespace hlvm {
-namespace AST {
+using namespace llvm;
+
+namespace hlvm { namespace AST {
Function::~Function()
{
}
+
+void
+Function::insertChild(Node* kid)
+{
+ if (isa<SignatureType>(kid)) {
+ if (signature)
+ signature->setParent(0);
+ signature = cast<SignatureType>(kid);
+ } else if (isa<Block>(kid)) {
+ if (block)
+ block->setParent(0);
+ block = cast<Block>(kid);
+ } else {
+ assert(!"Can't insert one of those here");
+ }
+}
+
+void
+Function::removeChild(Node* kid)
+{
+ if (isa<SignatureType>(kid)) {
+ } else if (isa<Block>(kid)) {
+ } else {
+ assert(!"Can't insert one of those here");
+ }
+}
}}
Modified: hlvm/trunk/hlvm/AST/Function.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Function.h?rev=38054&r1=38053&r2=38054&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Function.h (original)
+++ hlvm/trunk/hlvm/AST/Function.h Sat Jul 7 18:59:21 2007
@@ -31,14 +31,10 @@
#define HLVM_AST_FUNCTION_H
#include <hlvm/AST/LinkageItem.h>
+#include <hlvm/AST/ContainerType.h>
+#include <hlvm/AST/Block.h>
-namespace hlvm
-{
-namespace AST
-{
- // Forward declarations
- class Block;
- class SignatureType;
+namespace hlvm { namespace AST {
/// This class represents a Function in the HLVM Abstract Syntax Tree.
/// A Function is a callable block of code that accepts parameters and
@@ -69,7 +65,10 @@
/// @name Mutators
/// @{
public:
- void setSignature(SignatureType* SigTy) { signature = SigTy; }
+ virtual void insertChild(Node* kid);
+ virtual void removeChild(Node* kid);
+ //void setSignature(SignatureType* sig) { sig->Node::setParent(this); }
+ //void setBlock(Block* blk) { blk->Node::setParent(this); }
/// @}
/// @name Data
/// @{
Modified: hlvm/trunk/hlvm/AST/Import.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Import.h?rev=38054&r1=38053&r2=38054&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Import.h (original)
+++ hlvm/trunk/hlvm/AST/Import.h Sat Jul 7 18:59:21 2007
@@ -30,7 +30,7 @@
#ifndef HLVM_AST_IMPORT_H
#define HLVM_AST_IMPORT_H
-#include <hlvm/AST/Node.h>
+#include <hlvm/AST/LinkageItem.h>
namespace hlvm { namespace AST {
@@ -40,12 +40,13 @@
/// has a name, a set of formal arguments, a return type, and a block of
/// code to execute.
/// @brief HLVM AST Function Node
- class Import : public Node
+ class Import : public LinkageItem
{
/// @name Constructors
/// @{
protected:
- Import() : Node(ImportID) {}
+ Import() : LinkageItem(ImportID) {}
+
public:
virtual ~Import();
Modified: hlvm/trunk/hlvm/AST/LinkageItem.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/LinkageItem.h?rev=38054&r1=38053&r2=38054&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/LinkageItem.h (original)
+++ hlvm/trunk/hlvm/AST/LinkageItem.h Sat Jul 7 18:59:21 2007
@@ -51,17 +51,22 @@
/// elsewhere and linked into another bundle to resolve the reference. The
/// LinkageItem declares what kind of linkage is to be performed.
/// @brief HLVM AST Bundle Node
- class LinkageItem : public ParentNode
+ class LinkageItem : public NamedNode
{
/// @name Constructors
/// @{
- public:
+ protected:
LinkageItem(
NodeIDs id ///< Subclass's node identifier
- ) : ParentNode(id) {}
+ ) : NamedNode(id) {}
+ public:
virtual ~LinkageItem();
/// @}
+ /// @name Mutators
+ /// @{
+
+ /// @}
/// @name Data
/// @{
protected:
Modified: hlvm/trunk/hlvm/AST/Node.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Node.cpp?rev=38054&r1=38053&r2=38054&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Node.cpp (original)
+++ hlvm/trunk/hlvm/AST/Node.cpp Sat Jul 7 18:59:21 2007
@@ -33,23 +33,42 @@
Node::~Node()
{
- removeFromTree();
}
-ParentNode::~ParentNode()
+NamedNode::~NamedNode()
{
}
-void
-Node::removeFromTree()
+bool
+Node::isNamedNode() const
{
+ return isType() || isBundle() || isFunction() || isProgram() || isVariable();
}
-void
-Node::setParent(ParentNode* p)
+void
+Node::insertChild(Node* child)
+{
+ assert(!"This node doesn't accept child nodes");
+}
+
+void
+Node::removeChild(Node* child)
+{
+ assert(!"This node doesn't have child nodes");
+}
+
+void
+Node::setParent(Node* p)
{
+ if (p == 0)
+ {
+ parent->removeChild(this);
+ }
parent = p;
- p->addChild(this);
+ if (p != 0)
+ {
+ p->insertChild(this);
+ }
}
#ifndef _NDEBUG
@@ -59,10 +78,4 @@
}
#endif
-void
-ParentNode::addChild(Node* n)
-{
- kids.push_back(n);
-}
-
}}
Modified: hlvm/trunk/hlvm/AST/Node.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Node.h?rev=38054&r1=38053&r2=38054&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Node.h (original)
+++ hlvm/trunk/hlvm/AST/Node.h Sat Jul 7 18:59:21 2007
@@ -40,8 +40,7 @@
/// This enumeration is used to identify a specific type. 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. In particular the
- /// ParentNode group needs to be distinguished.
+ /// group things by inheritance rather than by function.
enum NodeIDs {
NoTypeID = 0, ///< Use this for an invalid type ID.
// Primitive Types (no child nodes)
@@ -61,9 +60,8 @@
ArrayTypeID, ///< The Array Type (Linear array of some type)
VectorTypeID, ///< The Vector Type (Packed Fixed Size Vector)
StructureTypeID, ///< The Structure Type (Sequence of various types)
- FieldID, ///< Declare name and type of Structure Field
+ NamedTypeID, ///< The name and type combo for fields and arguments
SignatureTypeID, ///< The Function Signature Type
- ArgumentID, ///< Declare name and type of Signature Argument
ContinuationTypeID, ///< A Continuation Type (data passing to continuations)
// Class Constructs (TBD)
@@ -186,9 +184,7 @@
FirstContainerTypeID = PointerTypeID, ///< First Container Type
LastContainerTypeID = ContinuationTypeID, ///< Last Container Type
FirstOperatorID = CallOpID, ///< First Operator
- LastOperatorID = StructureOpID, ///< Last Operator
- FirstParentNodeID = PointerTypeID,
- LastParentNodeID = PositionOpID
+ LastOperatorID = StructureOpID ///< Last Operator
};
class ParentNode;
@@ -234,9 +230,7 @@
}
/// Determine if the node is a ParentNode
- inline bool isParentNode() const {
- return id >= FirstParentNodeID && id <= LastParentNodeID;
- }
+ bool isNamedNode() const ;
/// Determine if the node is a Block
inline bool isBlock() const { return id == BlockID; }
@@ -255,15 +249,17 @@
/// @}
/// @name Mutators
/// @{
- protected:
- virtual void removeFromTree();
- virtual void setParent(ParentNode *n);
+ public:
void setLocator(const Locator& l) { loc = l; }
void setFlags(unsigned f) {
assert(f < 1 << 24 && "Flags out of range");
flags = f;
}
+ virtual void setParent(Node* parent);
+ protected:
+ virtual void insertChild(Node* child);
+ virtual void removeChild(Node* child);
/// @}
/// @name Utilities
/// @{
@@ -284,22 +280,13 @@
friend class AST;
};
- class ParentNode : public Node {
- /// @name Types
- /// @{
- public:
- typedef std::vector<Node*> NodeList;
- typedef NodeList::iterator iterator;
- typedef NodeList::const_iterator const_iterator;
-
- /// @}
+ class NamedNode : public Node {
/// @name Constructors
/// @{
protected:
- ParentNode(NodeIDs id)
- : Node(id), name(), kids() {}
+ NamedNode(NodeIDs id) : Node(id), name() {}
public:
- virtual ~ParentNode();
+ virtual ~NamedNode();
/// @}
/// @name Accessors
@@ -308,40 +295,20 @@
/// Get the name of the node
inline const std::string& getName() { return name; }
- /// Determine if the node has child nodes
- inline bool hasKids() const { return !kids.empty(); }
-
- static inline bool classof(const ParentNode*) { return true; }
- static inline bool classof(const Node* N) { return N->isParentNode(); }
+ static inline bool classof(const NamedNode*) { return true; }
+ static inline bool classof(const Node* N) { return N->isNamedNode(); }
/// @}
/// @name Mutators
/// @{
public:
void setName(const std::string& n) { name = n; }
- virtual void addChild(Node* n);
-
- /// @}
- /// @name Iterators
- /// @{
- public:
- iterator begin() { return kids.begin(); }
- const_iterator begin() const { return kids.begin(); }
- iterator end () { return kids.end(); }
- const_iterator end () const { return kids.end(); }
- size_t size () const { return kids.size(); }
- bool empty() const { return kids.empty(); }
- Node* front() { return kids.front(); }
- const Node* front() const { return kids.front(); }
- Node* back() { return kids.back(); }
- const Node* back() const { return kids.back(); }
/// @}
/// @name Data
/// @{
protected:
std::string name; ///< The name of this node.
- NodeList kids; ///< The vector of children nodes.
/// @}
friend class AST;
};
Modified: hlvm/trunk/hlvm/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Type.cpp?rev=38054&r1=38053&r2=38054&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Type.cpp (original)
+++ hlvm/trunk/hlvm/AST/Type.cpp Sat Jul 7 18:59:21 2007
@@ -36,8 +36,42 @@
{
}
+void
+Type::insertChild(Node* n)
+{
+ assert(!"This type doesn't accept children!");
+}
+
+AnyType::~AnyType()
+{
+}
+
+BooleanType::~BooleanType()
+{
+}
+
+CharacterType::~CharacterType()
+{
+}
+
IntegerType::~IntegerType()
{
}
+OctetType::~OctetType()
+{
+}
+
+RangeType::~RangeType()
+{
+}
+
+RealType::~RealType()
+{
+}
+
+VoidType::~VoidType()
+{
+}
+
}}
Modified: hlvm/trunk/hlvm/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Type.h?rev=38054&r1=38053&r2=38054&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Type.h (original)
+++ hlvm/trunk/hlvm/AST/Type.h Sat Jul 7 18:59:21 2007
@@ -30,27 +30,31 @@
#ifndef HLVM_AST_TYPE_H
#define HLVM_AST_TYPE_H
-#include <hlvm/AST/Node.h>
+#include <hlvm/AST/LinkageItem.h>
namespace hlvm {
namespace AST {
+ class IntrinsicType;
+
/// This class represents a Type in the HLVM Abstract Syntax Tree.
/// A Type defines the format of storage.
/// @brief HLVM AST Type Node
- class Type : public ParentNode
+ class Type : public LinkageItem
{
/// @name Constructors
/// @{
- public:
+ protected:
Type(
NodeIDs id ///< The Type identifier
- ) : ParentNode(id ) {}
+ ) : LinkageItem(id) {}
+ public:
virtual ~Type();
/// @}
/// @name Accessors
/// @{
+ public:
inline bool isPrimitiveType() const { return id <= LastPrimitiveTypeID; }
inline bool isIntegralType() const {
return id == IntegerTypeID || id == RangeTypeID;
@@ -58,6 +62,10 @@
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; }
@@ -67,22 +75,173 @@
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 Node*) { return true; }
static inline bool classof(const Type*) { return true; }
+ static inline bool classof(const Node* n) { return n->isType(); }
+
+ /// @}
+ /// @name Mutators
+ /// @{
+ public:
+ // We override receiveChild generically here to produce an error. Most
+ // Type subclasses can't receive children. Those that do, can override
+ // again.
+ virtual void insertChild(Node* n);
+
+ /// @}
+ /// @name Data
+ /// @{
+ protected:
+ /// @}
+ friend class AST;
+ };
+
+ /// This class is type that combines a name with an arbitrary type. This
+ /// construct is used any where a named and typed object is needed such as
+ /// the parameter to a function or the field of a structure.
+ class NamedType : public Type
+ {
+ /// @name Constructors
+ /// @{
+ public:
+ NamedType() : Type(NamedTypeID) {}
+ virtual ~NamedType();
+
+ /// @}
+ /// @name Accessors
+ /// @{
+ public:
+ // Get the name for the type
+ const std::string& getName() const { return name; }
+
+ // Get the type for the name
+ Type * getType() const { return type; }
+
+ // Methods to support type inquiry via is, cast, dyn_cast
+ static inline bool classof(const NamedType*) { return true; }
+ static inline bool classof(const Node* T) { return T->is(NamedTypeID); }
+
+ /// @}
+ /// @name Mutators
+ /// @{
+ public:
+ // Set the name for the type
+ void setName(const std::string& n) { name = n; }
+
+ // Set the type for the name
+ void setType(Type * t) { type = t; }
/// @}
/// @name Data
/// @{
protected:
+ Type* type;
+ std::string name;
+ /// @}
+ };
+
+ class AnyType : public Type
+ {
+ /// @name Constructors
+ /// @{
+ public:
+ AnyType() : Type(AnyTypeID) {}
+ virtual ~AnyType();
+
+ /// @}
+ /// @name Accessors
+ /// @{
+ public:
+ // Methods to support type inquiry via is, cast, dyn_cast
+ static inline bool classof(const AnyType*) { return true; }
+ static inline bool classof(const Type* T) { return T->isAnyType(); }
+ static inline bool classof(const Node* T) { return T->is(AnyTypeID); }
+ /// @}
+ friend class AST;
+ };
+
+ class BooleanType : public Type
+ {
+ /// @name Constructors
+ /// @{
+ public:
+ BooleanType() : Type(BooleanTypeID) {}
+ virtual ~BooleanType();
+
+ /// @}
+ /// @name Accessors
+ /// @{
+ public:
+ // Methods to support type inquiry via is, cast, dyn_cast
+ static inline bool classof(const BooleanType*) { return true; }
+ static inline bool classof(const Type* T) { return T->isBooleanType(); }
+ static inline bool classof(const Node* T) { return T->is(BooleanTypeID); }
+ /// @}
+ friend class AST;
+ };
+
+ class CharacterType : public Type
+ {
+ /// @name Constructors
+ /// @{
+ public:
+ CharacterType() : Type(CharacterTypeID) {}
+ virtual ~CharacterType();
+
+ /// @}
+ /// @name Accessors
+ /// @{
+ public:
+ // Methods to support type inquiry via is, cast, dyn_cast
+ static inline bool classof(const CharacterType*) { return true; }
+ static inline bool classof(const Type* T) { return T->isCharacterType(); }
+ static inline bool classof(const Node* T)
+ { return T->is(CharacterTypeID); }
+ /// @}
+ friend class AST;
+ };
+
+ class OctetType : public Type
+ {
+ /// @name Constructors
+ /// @{
+ public:
+ OctetType() : Type(OctetTypeID) {}
+ virtual ~OctetType();
+
+ /// @}
+ /// @name Accessors
+ /// @{
+ public:
+ // Methods to support type inquiry via is, cast, dyn_cast
+ static inline bool classof(const OctetType*) { return true; }
+ static inline bool classof(const Type* T) { return T->isOctetType(); }
+ static inline bool classof(const Node* T) { return T->is(OctetTypeID); }
/// @}
friend class AST;
};
- /// A NamedType is simply a pair involving a name and a pointer to a Type.
- /// This is so frequently needed, it is declared here for convenience.
- typedef std::pair<std::string,Type*> NamedType;
+ class VoidType : public Type
+ {
+ /// @name Constructors
+ /// @{
+ public:
+ VoidType() : Type(VoidTypeID) {}
+ virtual ~VoidType();
+
+ /// @}
+ /// @name Accessors
+ /// @{
+ public:
+ // Methods to support type inquiry via is, cast, dyn_cast
+ static inline bool classof(const VoidType*) { return true; }
+ static inline bool classof(const Type* T) { return T->isVoidType(); }
+ static inline bool classof(const Node* T) { return T->is(VoidTypeID); }
+ /// @}
+ friend class AST;
+ };
/// This class represents all HLVM integer types. An integer type declares the
/// the minimum number of bits that are required to store the integer type.
@@ -94,22 +253,42 @@
/// @name Constructors
/// @{
public:
- IntegerType() : Type(IntegerTypeID), numBits(32) {}
+ IntegerType() : Type(IntegerTypeID), numBits(32), signedness(true) {}
virtual ~IntegerType();
/// @}
/// @name Accessors
/// @{
public:
+
+ /// Return the number of bits
+ uint64_t getBits() const { return numBits; }
+
+ /// Return the signedness of the type
+ bool isSigned() const { return signedness ; }
+
// 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); }
+
+ /// @}
+ /// @name Accessors
+ /// @{
+ public:
+ /// Set the number of bits for this integer type
+ void setBits(uint64_t bits) { numBits = bits; }
+
+ /// Set the signedness of the type
+ void setSigned(bool isSigned) { signedness = isSigned; }
/// @}
/// @name Data
/// @{
protected:
uint32_t numBits; ///< Minimum number of bits
+ bool signedness; ///< Whether the integer type is signed or not
+
/// @}
friend class AST;
};
@@ -122,22 +301,40 @@
/// @name Constructors
/// @{
public:
- RangeType() : Type(RangeTypeID) {}
+ RangeType() : Type(RangeTypeID), min(0), max(256) {}
virtual ~RangeType();
/// @}
/// @name Accessors
/// @{
public:
+ /// Get min value of range
+ int64_t getMin() { return min; }
+
+ /// Get max value of range
+ int64_t getMax() { return max; }
+
// Methods to support type inquiry via is, cast, dyn_cast
static inline bool classof(const RangeType*) { return true; }
static inline bool classof(const Type* T) { return T->isRangeType(); }
+ static inline bool classof(const Node* T) { return T->is(RangeTypeID); }
+
+ /// @}
+ /// @name Accessors
+ /// @{
+ public:
+ /// Set min value of range
+ void setMin(int64_t val) { min = val; }
+
+ /// Set max value of range
+ void setMax(int64_t val) { max = val; }
+
/// @}
/// @name Data
/// @{
protected:
- uint64_t min_value_; ///< Lowest value accepted
- uint64_t max_value_; ///< Highest value accepted
+ int64_t min; ///< Lowest value accepted
+ int64_t max; ///< Highest value accepted
/// @}
friend class AST;
};
@@ -153,22 +350,40 @@
/// @name Constructors
/// @{
public:
- RealType() : Type(RealTypeID) {}
+ RealType() : Type(RealTypeID), mantissa(52), exponent(11) {}
virtual ~RealType();
/// @}
/// @name Accessors
/// @{
public:
+ /// Get the mantissa bits
+ uint32_t getMantissa() { return mantissa; }
+
+ /// Get the exponent bits
+ uint32_t getExponent() { return exponent; }
+
// Methods to support type inquiry via is, cast, dyn_cast
static inline bool classof(const RealType*) { return true; }
static inline bool classof(const Type* T) { return T->isRealType(); }
+ static inline bool classof(const Node* T) { return T->is(RealTypeID); }
+
+ /// @}
+ /// @name Mutators
+ /// @{
+ public:
+ /// Set the mantissa bits
+ void setMantissa(uint32_t bits) { mantissa = bits; }
+
+ /// Set the exponent bits
+ void setExponent(uint32_t bits) { exponent = bits; }
+
/// @}
/// @name Data
/// @{
protected:
- uint32_t precision_; ///< Number of decimal digits of precision
- uint32_t mantissa_; ///< Number of decimal digits in mantissa
+ uint32_t mantissa; ///< Number of decimal digits in mantissa
+ uint32_t exponent; ///< Number of decimal digits of precision
/// @}
friend class AST;
};
Modified: hlvm/trunk/hlvm/Reader/XML/HLVM.rng
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Reader/XML/HLVM.rng?rev=38054&r1=38053&r2=38054&view=diff
==============================================================================
--- hlvm/trunk/hlvm/Reader/XML/HLVM.rng (original)
+++ hlvm/trunk/hlvm/Reader/XML/HLVM.rng Sat Jul 7 18:59:21 2007
@@ -208,29 +208,83 @@
</element>
</define>
- <define name="Atom.elem">
- <element name="atom">
- <ref name="Named_Element.pat"/>
+ <define name="Intrinsic.elem">
+ <element name="intrinsic">
<attribute name="is">
<ref name="Intrinsic_Atoms.type"/>
</attribute>
</element>
</define>
+ <define name="Signed.elem">
+ <element name="signed">
+ <attribute name="bits">
+ <ref name="Integer.type"/>
+ </attribute>
+ </element>
+ </define>
+
+ <define name="Unsigned.elem">
+ <element name="unsigned">
+ <attribute name="bits">
+ <ref name="Integer.type"/>
+ </attribute>
+ </element>
+ </define>
+
+ <define name="Range.elem">
+ <element name="range">
+ <attribute name="min">
+ <ref name="Integer.type"/>
+ </attribute>
+ <attribute name="max">
+ <ref name="Integer.type"/>
+ </attribute>
+ </element>
+ </define>
+
+ <define name="Real.elem">
+ <element name="real">
+ <attribute name="precision">
+ <ref name="Integer.type"/>
+ </attribute>
+ </element>
+ </define>
+
+ <define name="Atom.elem">
+ <element name="atom">
+ <ref name="Named_Element.pat"/>
+ <choice>
+ <ref name="Intrinsic.elem"/>
+ <ref name="Signed.elem"/>
+ <ref name="Unsigned.elem"/>
+ <ref name="Range.elem"/>
+ <ref name="Real.elem"/>
+ </choice>
+ </element>
+ </define>
+
<define name="Intrinsic_Atoms.type">
<choice>
+ <value>any</value>
<value>bool</value>
<value>char</value>
<value>f32</value>
+ <value>f43</value>
<value>f64</value>
- <value>i8</value>
- <value>i16</value>
- <value>i32</value>
- <value>i64</value>
+ <value>f80</value>
+ <value>f128</value>
+ <value>octet</value>
+ <value>s8</value>
+ <value>s16</value>
+ <value>s32</value>
+ <value>s64</value>
+ <value>s128</value>
<value>u8</value>
<value>u16</value>
<value>u32</value>
<value>u64</value>
+ <value>u128</value>
<value>void</value>
</choice>
</define>
@@ -241,7 +295,7 @@
<oneOrMore>
<element name="value">
<ref name="Named_Element.pat"/>
- <ref name="Constant.pat"/>
+ <ref name="IntegerLiteral.pat"/>
</element>
</oneOrMore>
</element>
@@ -389,10 +443,7 @@
<define name="Literal.pat">
<choice>
- <ref name="Binary_Literal.elem"/>
- <ref name="Octal_Literal.elem"/>
- <ref name="Decimal_Literal.elem"/>
- <ref name="Hexadecimal_Literal.elem"/>
+ <ref name="IntegerLiteral.pat"/>
<ref name="Boolean_Literal.elem"/>
<ref name="Character_Literal.elem"/>
<ref name="Real_Literal.elem"/>
@@ -404,6 +455,24 @@
</choice>
</define>
+ <define name="IntegerLiteral.pat">
+ <choice>
+ <ref name="Binary_Literal.elem"/>
+ <ref name="Octal_Literal.elem"/>
+ <ref name="Decimal_Literal.elem"/>
+ <ref name="Hexadecimal_Literal.elem"/>
+ </choice>
+ </define>
+
+ <define name="Integer.type">
+ <choice>
+ <ref name="Binary.type"/>
+ <ref name="Octal.type"/>
+ <ref name="Decimal.type"/>
+ <ref name="Hexadecimal.type"/>
+ </choice>
+ </define>
+
<define name="Typed_Literal.pat">
<optional>
<attribute name="type"><ref name="Identifier.type"/></attribute>
Modified: hlvm/trunk/hlvm/Reader/XML/XMLReader.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Reader/XML/XMLReader.cpp?rev=38054&r1=38053&r2=38054&view=diff
==============================================================================
--- hlvm/trunk/hlvm/Reader/XML/XMLReader.cpp (original)
+++ hlvm/trunk/hlvm/Reader/XML/XMLReader.cpp Sat Jul 7 18:59:21 2007
@@ -91,6 +91,12 @@
AST::Import* parseImport(xmlNodePtr& cur);
AST::Type* parseType(xmlNodePtr& cur);
AST::Variable* parseVariable(xmlNodePtr& cur);
+ AST::Type* parseAtom(xmlNodePtr& cur);
+ AST::Type* parsePointer(xmlNodePtr& cur);
+ AST::Type* parseArray(xmlNodePtr& cur);
+ AST::Type* parseVector(xmlNodePtr& cur);
+ AST::Type* parseStructure(xmlNodePtr& cur);
+ AST::Type* parseSignature(xmlNodePtr& cur);
private:
};
@@ -128,7 +134,8 @@
reader->handleValidationError(error);
}
-bool
+
+inline bool
skipBlanks(xmlNodePtr &cur)
{
while (cur &&
@@ -141,6 +148,38 @@
return cur != 0;
}
+uint64_t
+recognize_nonNegativeInteger(const char* str)
+{
+ return uint64_t(::atoll(str));
+}
+
+int64_t
+recognize_Integer(const char * str)
+{
+ return ::atoll(str);
+}
+
+inline bool
+recognize_boolean(const std::string& str)
+{
+ switch (str[0])
+ {
+ case 'F': if (str == "FALSE") return false; break;
+ case 'N': if (str == "NO") return false; break;
+ case 'T': if (str == "TRUE") return true; break;
+ case 'Y': if (str == "YES") return true; break;
+ case 'f': if (str == "false") return false; break;
+ case 'n': if (str == "no") return false; break;
+ case 't': if (str == "true") return true; break;
+ case 'y': if (str == "yes") return true; break;
+ case '0': if (str == "0") return false; break;
+ case '1': if (str == "1") return true; break;
+ default: break;
+ }
+ assert(!"Invalid boolean value");
+}
+
inline const char*
getAttribute(xmlNodePtr cur,const char*name)
{
@@ -182,10 +221,141 @@
return imp;
}
+AST::Type*
+XMLReaderImpl::parseAtom(xmlNodePtr& cur)
+{
+ assert(getToken(cur->name)==TKN_atom);
+ AST::Locator loc(cur->line,0,&ast->getSystemID());
+ std::string name = getAttribute(cur,"name");
+
+ xmlNodePtr child = cur->children;
+ if (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE) {
+ int tkn = getToken(child->name);
+ switch (tkn) {
+ case TKN_intrinsic: {
+ const char* is = getAttribute(child,"is");
+ if (!is)
+ assert(!"intrinsic element requires 'is' attribute");
+ AST::Type* result = 0;
+ int typeTkn = getToken(reinterpret_cast<const xmlChar*>(is));
+ switch (typeTkn) {
+ case TKN_any: result=ast->new_AnyType(loc,name); break;
+ case TKN_bool: result=ast->new_BooleanType(loc,name); break;
+ case TKN_char: result=ast->new_CharacterType(loc,name); break;
+ case TKN_f128: result=ast->new_RealType(loc,name,112,15); break;
+ case TKN_f32: result=ast->new_RealType(loc,name,23,8); break;
+ case TKN_f43: result=ast->new_RealType(loc,name,32,11); break;
+ case TKN_f64: result=ast->new_RealType(loc,name,52,11); break;
+ case TKN_f80: result=ast->new_RealType(loc,name,64,15); break;
+ case TKN_octet:result=ast->new_OctetType(loc,name); break;
+ case TKN_s128: result=ast->new_IntegerType(loc,name,128,true); break;
+ case TKN_s16: result=ast->new_IntegerType(loc,name,16,true); break;
+ case TKN_s32: result=ast->new_IntegerType(loc,name,32,true); break;
+ case TKN_s64: result=ast->new_IntegerType(loc,name,64,true); break;
+ case TKN_s8: result=ast->new_IntegerType(loc,name,8,true); break;
+ case TKN_u128: result=ast->new_IntegerType(loc,name,128,false); break;
+ case TKN_u16: result=ast->new_IntegerType(loc,name,16,false); break;
+ case TKN_u32: result=ast->new_IntegerType(loc,name,32,false); break;
+ case TKN_u64: result=ast->new_IntegerType(loc,name,64,false); break;
+ case TKN_u8: result=ast->new_IntegerType(loc,name,8,false); break;
+ case TKN_void: result=ast->new_VoidType(loc,name); break;
+ default:
+ assert(!"Invalid intrinsic kind");
+ }
+ return result;
+ }
+ case TKN_signed: {
+ const char* bits = getAttribute(child,"bits");
+ if (bits) {
+ uint64_t numBits = recognize_nonNegativeInteger(bits);
+ return ast->new_IntegerType(loc,name,numBits,/*signed=*/true);
+ }
+ assert(!"Missing 'bits' attribute");
+ break;
+ }
+ case TKN_unsigned: {
+ const char* bits = getAttribute(child,"bits");
+ if (bits) {
+ uint64_t numBits = recognize_nonNegativeInteger(bits);
+ return ast->new_IntegerType(loc,name,numBits,/*signed=*/false);
+ }
+ assert(!"Missing 'bits' attribute");
+ break;
+ }
+ case TKN_range: {
+ const char* min = getAttribute(child, "min");
+ const char* max = getAttribute(child, "max");
+ if (min && max) {
+ int64_t minVal = recognize_Integer(min);
+ int64_t maxVal = recognize_Integer(max);
+ return ast->new_RangeType(loc,name,minVal,maxVal);
+ }
+ assert(!"Missing 'min' or 'max' attribute");
+ break;
+ }
+ case TKN_real: {
+ const char* mantissa = getAttribute(child, "mantissa");
+ const char* exponent = getAttribute(child, "exponent");
+ if (mantissa && exponent) {
+ int32_t mantVal = recognize_nonNegativeInteger(mantissa);
+ int32_t expoVal = recognize_nonNegativeInteger(exponent);
+ return ast->new_RealType(loc,name,mantVal,expoVal);
+ }
+ break;
+ }
+ default:
+ assert(!"Invalid content for bundle");
+ break;
+ }
+ }
+ assert(!"Atom definition element expected");
+}
+
+AST::Type*
+XMLReaderImpl::parsePointer(xmlNodePtr& cur)
+{
+ return 0;
+}
+
+AST::Type*
+XMLReaderImpl::parseArray(xmlNodePtr& cur)
+{
+ return 0;
+}
+
+AST::Type*
+XMLReaderImpl::parseVector(xmlNodePtr& cur)
+{
+ return 0;
+}
+
+AST::Type*
+XMLReaderImpl::parseStructure(xmlNodePtr& cur)
+{
+ return 0;
+}
+
+AST::Type*
+XMLReaderImpl::parseSignature(xmlNodePtr& cur)
+{
+ return 0;
+}
+
AST::Type*
XMLReaderImpl::parseType(xmlNodePtr& cur)
{
- return 0;
+ AST::Type* T = 0;
+ switch (getToken(cur->name)) {
+ case TKN_atom: T = parseAtom(cur); break;
+ case TKN_pointer: T = parsePointer(cur); break;
+ case TKN_array: T = parseArray(cur); break;
+ case TKN_vector: T = parseVector(cur); break;
+ case TKN_structure: T = parseStructure(cur); break;
+ case TKN_signature: T = parseSignature(cur); break;
+ default:
+ assert(!"Invalid Type!");
+ }
+ return T;
}
AST::Variable*
@@ -216,14 +386,14 @@
case TKN_import : n = parseImport(child); break;
case TKN_bundle : n = parseBundle(child); break;
case TKN_function : n = parseFunction(child); break;
- case TKN_type: n = parseType(child); break;
- case TKN_var: n = parseVariable(child); break;
+ case TKN_atom : n = parseType(child); break;
+ case TKN_var : n = parseVariable(child); break;
default:
assert(!"Invalid content for bundle");
break;
}
if (n)
- bundle->addChild(n);
+ n->setParent(bundle);
child = child->next;
}
return bundle;
Modified: hlvm/trunk/hlvm/Writer/XML/XMLWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Writer/XML/XMLWriter.cpp?rev=38054&r1=38053&r2=38054&view=diff
==============================================================================
--- hlvm/trunk/hlvm/Writer/XML/XMLWriter.cpp (original)
+++ hlvm/trunk/hlvm/Writer/XML/XMLWriter.cpp Sat Jul 7 18:59:21 2007
@@ -34,6 +34,7 @@
#include <hlvm/AST/Import.h>
#include <hlvm/AST/ContainerType.h>
#include <hlvm/AST/Variable.h>
+#include <llvm/ADT/StringExtras.h>
#include <libxml/xmlwriter.h>
#include <iostream>
#include <cassert>
@@ -76,6 +77,8 @@
{ xmlTextWriterWriteAttribute(writer,
reinterpret_cast<const xmlChar*>(name),
reinterpret_cast<const xmlChar*>(val)); }
+ inline void writeAttribute(const char* name, const std::string& val)
+ { writeAttribute(name, val.c_str()); }
inline void writeElement(const char* elem, const char* body)
{ xmlTextWriterWriteElement(writer,
reinterpret_cast<const xmlChar*>(elem),
@@ -87,6 +90,14 @@
inline void put(AST::Bundle* b);
inline void put(AST::Variable* v);
inline void put(AST::Function* f);
+ inline void put(AST::AnyType* t);
+ inline void put(AST::BooleanType* t);
+ inline void put(AST::CharacterType* t);
+ inline void put(AST::IntegerType* t);
+ inline void put(AST::RangeType* t);
+ inline void put(AST::RealType* t);
+ inline void put(AST::OctetType* t);
+ inline void put(AST::VoidType* t);
};
@@ -110,6 +121,167 @@
{
}
+void
+XMLWriterImpl::put(AST::AnyType* t)
+{
+ startElement("atom");
+ writeAttribute("name",t->getName().c_str());
+ startElement("intrinsic");
+ writeAttribute("is","any");
+ endElement();
+ endElement();
+}
+
+void
+XMLWriterImpl::put(AST::BooleanType* t)
+{
+ startElement("atom");
+ writeAttribute("name",t->getName().c_str());
+ startElement("intrinsic");
+ writeAttribute("is","bool");
+ endElement();
+ endElement();
+}
+
+void
+XMLWriterImpl::put(AST::CharacterType* t)
+{
+ startElement("atom");
+ writeAttribute("name",t->getName().c_str());
+ startElement("intrinsic");
+ writeAttribute("is","char");
+ endElement();
+ endElement();
+}
+
+void
+XMLWriterImpl::put(AST::IntegerType* t)
+{
+ startElement("atom");
+ writeAttribute("name",t->getName().c_str());
+ if (t->getBits() <= 128) {
+ if (t->isSigned()) {
+ switch (t->getBits()) {
+ case 128: startElement("intrinsic"); writeAttribute("is","s128"); break;
+ case 64: startElement("intrinsic"); writeAttribute("is","s64"); break;
+ case 32: startElement("intrinsic"); writeAttribute("is","s32"); break;
+ case 16: startElement("intrinsic"); writeAttribute("is","s16"); break;
+ case 8 : startElement("intrinsic"); writeAttribute("is","s8"); break;
+ default:
+ startElement("signed");
+ writeAttribute("bits", llvm::utostr(t->getBits()));
+ break;
+ }
+ } else {
+ switch (t->getBits()) {
+ case 128: startElement("intrinsic"); writeAttribute("is","u128"); break;
+ case 64: startElement("intrinsic"); writeAttribute("is","u64"); break;
+ case 32: startElement("intrinsic"); writeAttribute("is","u32"); break;
+ case 16: startElement("intrinsic"); writeAttribute("is","u16"); break;
+ case 8 : startElement("intrinsic"); writeAttribute("is","u8"); break;
+ default:
+ startElement("unsigned");
+ writeAttribute("bits", llvm::utostr(t->getBits()));
+ break;
+ }
+ }
+ endElement();
+ } else {
+ if (t->isSigned()) {
+ startElement("signed");
+ } else {
+ startElement("unsigned");
+ }
+ writeAttribute("bits", llvm::utostr(t->getBits()));
+ endElement();
+ }
+ endElement();
+}
+
+void
+XMLWriterImpl::put(AST::RangeType* t)
+{
+}
+
+void
+XMLWriterImpl::put(AST::RealType* t)
+{
+ startElement("atom");
+ writeAttribute("name",t->getName().c_str());
+ bool done = false;
+ switch (t->getMantissa()) {
+ case 23:
+ if (t->getExponent() == 8) {
+ startElement("intrinsic");
+ writeAttribute("is","f32");
+ done = true;
+ }
+ break;
+ case 32:
+ if (t->getExponent() == 11) {
+ startElement("intrinsic");
+ writeAttribute("is","f43");
+ done = true;
+ }
+ break;
+ case 52:
+ if (t->getExponent() == 11) {
+ startElement("intrinsic");
+ writeAttribute("is","f64");
+ done = true;
+ }
+ break;
+ case 64:
+ if (t->getExponent() == 15) {
+ startElement("intrinsic");
+ writeAttribute("is","f80");
+ done = true;
+ }
+ break;
+ case 112:
+ if (t->getExponent() == 15) {
+ startElement("intrinsic");
+ writeAttribute("is","f128");
+ done = true;
+ }
+ break;
+ default:
+ break;
+ }
+
+ if (done) {
+ endElement();
+ } else {
+ startElement("real");
+ writeAttribute("mantissa", llvm::utostr(t->getMantissa()));
+ writeAttribute("exponent", llvm::utostr(t->getExponent()));
+ endElement();
+ }
+ endElement();
+}
+
+void
+XMLWriterImpl::put(AST::OctetType* t)
+{
+ startElement("atom");
+ writeAttribute("name",t->getName().c_str());
+ startElement("intrinsic");
+ writeAttribute("is","octet");
+ endElement();
+ endElement();
+}
+
+void
+XMLWriterImpl::put(AST::VoidType* t)
+{
+ startElement("atom");
+ writeAttribute("name",t->getName().c_str());
+ startElement("intrinsic");
+ writeAttribute("is","void");
+ endElement();
+ endElement();
+}
+
inline void
XMLWriterImpl::put(AST::Variable* v)
{
@@ -124,12 +296,20 @@
{
startElement("bundle");
writeAttribute("pubid",b->getName().c_str());
- for (AST::ParentNode::const_iterator I = b->begin(),E = b->end(); I != E; ++I)
+ for (AST::Bundle::const_iterator I = b->begin(),E = b->end(); I != E; ++I)
{
switch ((*I)->getID())
{
- case AST::VariableID: put(cast<AST::Variable>(*I)); break;
- case AST::FunctionID: put(cast<AST::Function>(*I)); break;
+ case AST::VariableID: put(cast<AST::Variable>(*I)); break;
+ case AST::FunctionID: put(cast<AST::Function>(*I)); break;
+ case AST::AnyTypeID: put(cast<AST::AnyType>(*I)); break;
+ case AST::BooleanTypeID: put(cast<AST::BooleanType>(*I)); break;
+ case AST::CharacterTypeID: put(cast<AST::CharacterType>(*I)); break;
+ case AST::IntegerTypeID: put(cast<AST::IntegerType>(*I)); break;
+ case AST::RangeTypeID: put(cast<AST::RangeType>(*I)); break;
+ case AST::RealTypeID: put(cast<AST::RealType>(*I)); break;
+ case AST::OctetTypeID: put(cast<AST::OctetType>(*I)); break;
+ case AST::VoidTypeID: put(cast<AST::VoidType>(*I)); break;
default:
assert(!"Invalid bundle content");
}
@@ -155,10 +335,9 @@
case hlvm::AST::PointerTypeID: break;
case hlvm::AST::ArrayTypeID: break;
case hlvm::AST::VectorTypeID: break;
+ case hlvm::AST::NamedTypeID: break;
case hlvm::AST::StructureTypeID: break;
- case hlvm::AST::FieldID: break;
case hlvm::AST::SignatureTypeID: break;
- case hlvm::AST::ArgumentID: break;
case hlvm::AST::ContinuationTypeID: break;
case hlvm::AST::InterfaceID: break;
case hlvm::AST::ClassID: break;
Added: hlvm/trunk/test/xml2xml/intrinsics.hlx
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/xml2xml/intrinsics.hlx?rev=38054&view=auto
==============================================================================
--- hlvm/trunk/test/xml2xml/intrinsics.hlx (added)
+++ hlvm/trunk/test/xml2xml/intrinsics.hlx Sat Jul 7 18:59:21 2007
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<hlvm xmlns="http://hlvm.org/src/hlvm/Reader/XML/HLVM.rng">
+ <bundle pubid="bundle">
+ <atom name="1">
+ <intrinsic is="any"/>
+ </atom>
+ <atom name="2">
+ <intrinsic is="bool"/>
+ </atom>
+ <atom name="3">
+ <intrinsic is="char"/>
+ </atom>
+ <atom name="4">
+ <intrinsic is="f128"/>
+ </atom>
+ <atom name="5">
+ <intrinsic is="f80"/>
+ </atom>
+ <atom name="6">
+ <intrinsic is="f64"/>
+ </atom>
+ <atom name="7">
+ <intrinsic is="f43"/>
+ </atom>
+ <atom name="8">
+ <intrinsic is="f32"/>
+ </atom>
+ <atom name="9">
+ <intrinsic is="s128"/>
+ </atom>
+ <atom name="10">
+ <intrinsic is="s64"/>
+ </atom>
+ <atom name="11">
+ <intrinsic is="s32"/>
+ </atom>
+ <atom name="12">
+ <intrinsic is="s16"/>
+ </atom>
+ <atom name="13">
+ <intrinsic is="s8"/>
+ </atom>
+ <atom name="14">
+ <intrinsic is="octet"/>
+ </atom>
+ <atom name="15">
+ <intrinsic is="u128"/>
+ </atom>
+ <atom name="16">
+ <intrinsic is="u64"/>
+ </atom>
+ <atom name="17">
+ <intrinsic is="u32"/>
+ </atom>
+ <atom name="18">
+ <intrinsic is="u16"/>
+ </atom>
+ <atom name="19">
+ <intrinsic is="u8"/>
+ </atom>
+ <atom name="20">
+ <intrinsic is="void"/>
+ </atom>
+ </bundle>
+</hlvm>
More information about the llvm-commits
mailing list