[llvm-commits] [hlvm] r38056 - in /hlvm/trunk: hlvm/AST/AST.cpp hlvm/AST/AST.h hlvm/AST/ContainerType.cpp hlvm/AST/ContainerType.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/alias.hlx test/xml2xml/array.hlx test/xml2xml/pointer.hlx test/xml2xml/signature.hlx test/xml2xml/structure.hlx test/xml2xml/vector.hlx
Reid Spencer
reid at x10sys.com
Sat Jul 7 16:59:23 PDT 2007
Author: reid
Date: Sat Jul 7 18:59:23 2007
New Revision: 38056
URL: http://llvm.org/viewvc/llvm-project?rev=38056&view=rev
Log:
Add support for container types. Write framework for type resolution.
Added:
hlvm/trunk/test/xml2xml/alias.hlx
hlvm/trunk/test/xml2xml/array.hlx
hlvm/trunk/test/xml2xml/pointer.hlx
hlvm/trunk/test/xml2xml/signature.hlx
hlvm/trunk/test/xml2xml/structure.hlx
hlvm/trunk/test/xml2xml/vector.hlx
Modified:
hlvm/trunk/hlvm/AST/AST.cpp
hlvm/trunk/hlvm/AST/AST.h
hlvm/trunk/hlvm/AST/ContainerType.cpp
hlvm/trunk/hlvm/AST/ContainerType.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=38056&r1=38055&r2=38056&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/AST.cpp (original)
+++ hlvm/trunk/hlvm/AST/AST.cpp Sat Jul 7 18:59:23 2007
@@ -33,16 +33,84 @@
#include <hlvm/AST/Function.h>
#include <hlvm/AST/Import.h>
#include <hlvm/AST/Variable.h>
+#include <hlvm/AST/SymbolTable.h>
+
+using namespace hlvm::AST;
+
+namespace {
+class ASTImpl : public AST
+{
+ public:
+ ASTImpl() {}
+ ~ASTImpl();
+
+ private:
+ // Pool pool;
+ SymbolTable types;
+ SymbolTable vars;
+ SymbolTable funcs;
+ SymbolTable unresolvedTypes;
+
+ public:
+ Type* resolveType(const std::string& name);
+ void addType(Type*);
+};
+
+ASTImpl::~ASTImpl()
+{
+}
+
+Type*
+ASTImpl::resolveType(const std::string& name)
+{
+ Node* n = types.lookup(name);
+ if (n)
+ return llvm::cast<Type>(n);
+ n = unresolvedTypes.lookup(name);
+ if (n)
+ return llvm::cast<OpaqueType>(n);
+ OpaqueType* ot = this->new_OpaqueType(name);
+ unresolvedTypes.insert(ot->getName(), ot);
+ return ot;
+}
+
+void
+ASTImpl::addType(Type* ty)
+{
+ Node* n = unresolvedTypes.lookup(ty->getName());
+ if (n) {
+ OpaqueType* ot = llvm::cast<OpaqueType>(n);
+ // FIXME: Replace all uses of "ot" with "ty"
+ unresolvedTypes.erase(ot);
+ }
+ types.insert(ty->getName(),ty);
+}
+
+}
namespace hlvm {
namespace AST {
+AST*
+AST::create()
+{
+ return new ASTImpl();
+}
+
+void
+AST::destroy(AST* ast)
+{
+ delete static_cast<ASTImpl*>(ast);
+}
+
+AST::~AST()
+{
+}
+
Type*
-AST::resolveType(const std::string& name) const
+AST::resolveType(const std::string& name)
{
- IntegerType* result = new IntegerType();
- result->setName(name);
- return result;
+ return static_cast<const ASTImpl*>(this)->resolveType(name);
}
Bundle*
@@ -72,7 +140,7 @@
return result;
}
-Type*
+IntegerType*
AST::new_IntegerType(
const Locator&loc,
const std::string& id,
@@ -84,10 +152,23 @@
result->setSigned(isSigned);
result->setLocator(loc);
result->setName(id);
+ static_cast<ASTImpl*>(this)->addType(result);
return result;
}
-Type*
+RangeType*
+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);
+ static_cast<ASTImpl*>(this)->addType(result);
+ return result;
+}
+
+RealType*
AST::new_RealType(
const Locator&loc,
const std::string& id,
@@ -99,70 +180,138 @@
result->setExponent(exponent);
result->setLocator(loc);
result->setName(id);
+ static_cast<ASTImpl*>(this)->addType(result);
return result;
}
-Type*
+AnyType*
AST::new_AnyType(const Locator&loc, const std::string& id)
{
AnyType* result = new AnyType();
result->setLocator(loc);
result->setName(id);
+ static_cast<ASTImpl*>(this)->addType(result);
return result;
}
-Type*
+BooleanType*
AST::new_BooleanType(const Locator&loc, const std::string& id)
{
BooleanType* result = new BooleanType();
result->setLocator(loc);
result->setName(id);
+ static_cast<ASTImpl*>(this)->addType(result);
return result;
}
-Type*
+CharacterType*
AST::new_CharacterType(const Locator&loc, const std::string& id)
{
CharacterType* result = new CharacterType();
result->setLocator(loc);
result->setName(id);
+ static_cast<ASTImpl*>(this)->addType(result);
return result;
}
-Type*
+OctetType*
AST::new_OctetType(const Locator&loc, const std::string& id)
{
OctetType* result = new OctetType();
result->setLocator(loc);
result->setName(id);
+ static_cast<ASTImpl*>(this)->addType(result);
return result;
}
-Type*
+VoidType*
AST::new_VoidType(const Locator&loc, const std::string& id)
{
VoidType* result = new VoidType();
result->setLocator(loc);
result->setName(id);
+ static_cast<ASTImpl*>(this)->addType(result);
return result;
}
-Type*
-AST::new_RangeType(const Locator&loc, const std::string& id, int64_t min, int64_t max)
+PointerType*
+AST::new_PointerType(
+ const Locator& loc,
+ const std::string& id,
+ Type* target
+)
{
- RangeType* result = new RangeType();
+ PointerType* result = new PointerType();
result->setLocator(loc);
result->setName(id);
- result->setMin(min);
- result->setMax(max);
+ result->setTargetType(target);
+ static_cast<ASTImpl*>(this)->addType(result);
+ return result;
+}
+
+ArrayType*
+AST::new_ArrayType(
+ const Locator& loc,
+ const std::string& id,
+ Type* elemType,
+ uint64_t maxSize
+)
+{
+ ArrayType* result = new ArrayType();
+ result->setLocator(loc);
+ result->setName(id);
+ result->setElementType(elemType);
+ result->setMaxSize(maxSize);
+ static_cast<ASTImpl*>(this)->addType(result);
+ return result;
+}
+
+VectorType*
+AST::new_VectorType(
+ const Locator& loc,
+ const std::string& id,
+ Type* elemType,
+ uint64_t size
+)
+{
+ VectorType* result = new VectorType();
+ result->setLocator(loc);
+ result->setName(id);
+ result->setElementType(elemType);
+ result->setSize(size);
+ static_cast<ASTImpl*>(this)->addType(result);
+ return result;
+}
+
+AliasType*
+AST::new_AliasType(const Locator& loc, const std::string& id, Type* referrant)
+{
+ AliasType* result = new AliasType();
+ result->setLocator(loc);
+ result->setName(id);
+ result->setType(referrant);
+ static_cast<ASTImpl*>(this)->addType(result);
return result;
}
+
+StructureType*
+AST::new_StructureType(const Locator& loc, const std::string& id)
+{
+ StructureType* result = new StructureType();
+ result->setLocator(loc);
+ result->setName(id);
+ static_cast<ASTImpl*>(this)->addType(result);
+ return result;
+}
+
SignatureType*
-AST::new_SignatureType(const Locator& loc, const std::string& id)
+AST::new_SignatureType(const Locator& loc, const std::string& id, Type* ty)
{
SignatureType* result = new SignatureType();
result->setLocator(loc);
result->setName(id);
+ result->setResultType(ty);
+ static_cast<ASTImpl*>(this)->addType(result);
return result;
}
@@ -175,4 +324,10 @@
return result;
}
+OpaqueType*
+AST::new_OpaqueType(const std::string& id)
+{
+ return new OpaqueType(id);
+}
+
}}
Modified: hlvm/trunk/hlvm/AST/AST.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/AST.h?rev=38056&r1=38055&r2=38056&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/AST.h (original)
+++ hlvm/trunk/hlvm/AST/AST.h Sat Jul 7 18:59:23 2007
@@ -48,6 +48,21 @@
class SignatureType;
class Type;
class Variable;
+ class AnyType;
+ class BooleanType;
+ class CharacterType;
+ class OctetType;
+ class VoidType;
+ class IntegerType;
+ class RangeType;
+ class RealType;
+ class PointerType;
+ class VectorType;
+ class ArrayType;
+ class AliasType;
+ class StructureType;
+ class SignatureType;
+ class OpaqueType;
/// This class is used to hold or contain an Abstract Syntax Tree. It provides
/// those aspects of the tree that are not part of the tree itself.
@@ -57,7 +72,12 @@
/// @name Constructors
/// @{
public:
+ static AST* create();
+ static void destroy(AST* ast);
+
+ protected:
AST() : sysid(), pubid(), root(0) {}
+ ~AST();
/// @}
/// @name Accessors
@@ -79,7 +99,7 @@
/// @name Lookup
/// @{
public:
- Type* resolveType(const std::string& name) const;
+ Type* resolveType(const std::string& name);
/// @}
/// @name Factories
@@ -88,31 +108,93 @@
Bundle* new_Bundle(const Locator& loc, const std::string& id);
Function* new_Function(const Locator& loc, const std::string& id);
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(
+ IntegerType* 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(
+ RangeType* 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(
+ RealType* 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);
+ AnyType* new_AnyType(const Locator&loc, const std::string& id);
+ BooleanType*
+ new_BooleanType(const Locator&loc, const std::string& id);
+ CharacterType*
+ new_CharacterType(const Locator&loc, const std::string& id);
+ OctetType*
+ new_OctetType(const Locator&loc, const std::string& id);
+ VoidType* new_VoidType(const Locator&loc, const std::string& id);
+ PointerType* new_PointerType(
+ const Locator& loc,
+ const std::string& id,
+ Type* target
+ );
+ ArrayType* new_ArrayType(
+ const Locator& loc,
+ const std::string& id,
+ Type* elemType,
+ uint64_t maxSize
+ );
+ VectorType* new_VectorType(
+ const Locator& loc,
+ const std::string& id,
+ Type* elemType,
+ uint64_t size
+ );
+ AliasType* new_AliasType(
+ const Locator& loc,
+ const std::string& id,
+ Type* referrant
+ );
+ StructureType*
+ new_StructureType(const Locator& l, const std::string& id);
+ SignatureType* new_SignatureType(
+ const Locator& loc,
+ const std::string& id,
+ Type *resultType
+ );
+ OpaqueType* new_OpaqueType(const std::string& id);
+ RealType* new_f128(const Locator& l, const std::string& id)
+ { return new_RealType(l,id,112,15); }
+ RealType* new_f80(const Locator& l, const std::string& id)
+ { return new_RealType(l,id,64,15); }
+ RealType* new_f64(const Locator& l, const std::string& id)
+ { return new_RealType(l,id,52,11); }
+ RealType* new_f43(const Locator& l, const std::string& id)
+ { return new_RealType(l,id,32,11); }
+ RealType* new_f32(const Locator& l, const std::string& id)
+ { return new_RealType(l,id,23,8); }
+ IntegerType* new_s128(const Locator& l, const std::string& id)
+ { return new_IntegerType(l,id,128,true); }
+ IntegerType* new_s64(const Locator& l, const std::string& id)
+ { return new_IntegerType(l,id,64,true); }
+ IntegerType* new_s32(const Locator& l, const std::string& id)
+ { return new_IntegerType(l,id,32,true); }
+ IntegerType* new_s16(const Locator& l, const std::string& id)
+ { return new_IntegerType(l,id,16,true); }
+ IntegerType* new_s8(const Locator& l, const std::string& id)
+ { return new_IntegerType(l,id,8,true); }
+ IntegerType* new_u128(const Locator& l, const std::string& id)
+ { return new_IntegerType(l,id,128,false); }
+ IntegerType* new_u64(const Locator& l, const std::string& id)
+ { return new_IntegerType(l,id,64,false); }
+ IntegerType* new_u32(const Locator& l, const std::string& id)
+ { return new_IntegerType(l,id,32,false); }
+ IntegerType* new_u16(const Locator& l, const std::string& id)
+ { return new_IntegerType(l,id,16,false); }
+ IntegerType* new_u8(const Locator& l, const std::string& id)
+ { return new_IntegerType(l,id,8,false); }
/// @}
/// @name Data
/// @{
Modified: hlvm/trunk/hlvm/AST/ContainerType.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/ContainerType.cpp?rev=38056&r1=38055&r2=38056&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/ContainerType.cpp (original)
+++ hlvm/trunk/hlvm/AST/ContainerType.cpp Sat Jul 7 18:59:23 2007
@@ -61,39 +61,6 @@
return 0;
}
-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()
{
}
@@ -101,8 +68,8 @@
void
StructureType::insertChild(Node* n)
{
- assert(isa<NamedType>(n) && "Can't insert those here");
- types.push_back(cast<NamedType>(n));
+ assert(isa<AliasType>(n) && "Can't insert those here");
+ types.push_back(cast<AliasType>(n));
}
SignatureType::~SignatureType()
@@ -112,8 +79,8 @@
void
SignatureType::insertChild(Node* n)
{
- assert(isa<NamedType>(n) && "Can't insert those here");
- types.push_back(cast<NamedType>(n));
+ assert(isa<AliasType>(n) && "Can't insert those here");
+ types.push_back(cast<AliasType>(n));
}
}}
Modified: hlvm/trunk/hlvm/AST/ContainerType.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/ContainerType.h?rev=38056&r1=38055&r2=38056&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/ContainerType.h (original)
+++ hlvm/trunk/hlvm/AST/ContainerType.h Sat Jul 7 18:59:23 2007
@@ -94,104 +94,6 @@
/// @}
};
- /// This class represents a storage location that is a pointer to another
- /// type.
- class PointerType : public ContainerType
- {
- /// @name Constructors
- /// @{
- public:
- PointerType() : ContainerType(PointerTypeID) {}
- virtual ~PointerType();
-
- /// @}
- /// @name Accessors
- /// @{
- public:
- // Methods to support type inquiry via is, cast, dyn_cast
- static inline bool classof(const PointerType*) { return true; }
- static inline bool classof(const 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
- /// @{
- protected:
- /// @}
- };
-
- /// This class represents a resizeable, aligned array of some other type. The
- /// Array references a Type that specifies the type of elements in the array.
- class ArrayType : public ContainerType
- {
- /// @name Constructors
- /// @{
- public:
- ArrayType() : ContainerType(ArrayTypeID) {}
- virtual ~ArrayType();
-
- /// @}
- /// @name Accessors
- /// @{
- public:
- // 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
- /// @{
- protected:
- /// @}
- };
-
- /// This class represents a fixed size, packed vector of some other type.
- /// Where possible, HLVM will attempt to generate code that makes use of a
- /// machines vector instructions to process such types. If not possible, HLVM
- /// will treat the vector the same as an Array.
- class VectorType : public ContainerType
- {
- /// @name Constructors
- /// @{
- public:
- VectorType() : ContainerType(VectorTypeID) {}
- virtual ~VectorType();
-
- /// @}
- /// @name Accessors
- /// @{
- public:
- // 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
- /// @{
- protected:
- /// @}
- };
-
/// This class represents an HLVM type that is a sequence of data fields
/// of varying type.
class StructureType : public ContainerType
@@ -232,13 +134,17 @@
/// @name Constructors
/// @{
public:
- SignatureType() : ContainerType(SignatureTypeID) {}
+ SignatureType()
+ : ContainerType(SignatureTypeID), result(0), varargs(false) {}
virtual ~SignatureType();
/// @}
/// @name Accessors
/// @{
public:
+ Type* getResultType() const { return result; }
+ bool isVarArgs() const { return varargs; }
+
// 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(); }
@@ -249,14 +155,16 @@
/// @name Accessors
/// @{
public:
+ void setResultType(Type* ty) { result = ty; }
+ void setIsVarArgs(bool is) { varargs = is; }
virtual void insertChild(Node* n);
/// @}
/// @name Data
/// @{
protected:
- Type* result_; ///< The result type of the function signature
- bool isVarArgs; ///< Indicates variable arguments function
+ Type* result; ///< The result type of the function signature
+ bool varargs; ///< Indicates variable arguments function
/// @}
friend class AST;
};
Modified: hlvm/trunk/hlvm/AST/LinkageItem.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/LinkageItem.h?rev=38056&r1=38055&r2=38056&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/LinkageItem.h (original)
+++ hlvm/trunk/hlvm/AST/LinkageItem.h Sat Jul 7 18:59:23 2007
@@ -65,6 +65,12 @@
/// @}
/// @name Mutators
/// @{
+ public:
+ static inline bool classof(const LinkageItem*) { return true; }
+ static inline bool classof(const Node* N) { return N->isLinkageItem(); }
+ /// @}
+ /// @name Mutators
+ /// @{
/// @}
/// @name Data
Modified: hlvm/trunk/hlvm/AST/Node.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Node.cpp?rev=38056&r1=38055&r2=38056&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Node.cpp (original)
+++ hlvm/trunk/hlvm/AST/Node.cpp Sat Jul 7 18:59:23 2007
@@ -45,6 +45,13 @@
return isType() || isBundle() || isFunction() || isProgram() || isVariable();
}
+bool
+Node::isLinkageItem() const
+{
+ return isFunction() || isType() || isProgram() || isVariable();
+}
+
+
void
Node::insertChild(Node* child)
{
Modified: hlvm/trunk/hlvm/AST/Node.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Node.h?rev=38056&r1=38055&r2=38056&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Node.h (original)
+++ hlvm/trunk/hlvm/AST/Node.h Sat Jul 7 18:59:23 2007
@@ -56,13 +56,14 @@
StringTypeID, ///< The String Type (Array of UTF-16 chars + length)
// Container Types
+ AliasTypeID, ///< A new name for an existing type
PointerTypeID, ///< The Pointer Type (Pointer To storage of other Type)
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)
- NamedTypeID, ///< The name and type combo for fields and arguments
SignatureTypeID, ///< The Function Signature Type
ContinuationTypeID, ///< A Continuation Type (data passing to continuations)
+ OpaqueTypeID, ///< A placeholder for unresolved types
// Class Constructs (TBD)
InterfaceID, ///< The Interface Type (set of Signatures)
@@ -184,7 +185,9 @@
FirstContainerTypeID = PointerTypeID, ///< First Container Type
LastContainerTypeID = ContinuationTypeID, ///< Last Container Type
FirstOperatorID = CallOpID, ///< First Operator
- LastOperatorID = StructureOpID ///< Last Operator
+ LastOperatorID = StructureOpID, ///< Last Operator
+ FirstTypeID = VoidTypeID,
+ LastTypeID = OpaqueTypeID
};
class ParentNode;
@@ -222,7 +225,7 @@
/// Determine if the node is a Type
inline bool isType() const {
- return id >= FirstPrimitiveTypeID && id <= LastPrimitiveTypeID;
+ return id >= FirstTypeID && id <= LastTypeID;
}
/// Determine if the node is any of the Operators
inline bool isOperator() const {
@@ -232,6 +235,9 @@
/// Determine if the node is a ParentNode
bool isNamedNode() const ;
+ /// Determine if the node is a LinkageItem
+ bool isLinkageItem() const;
+
/// Determine if the node is a Block
inline bool isBlock() const { return id == BlockID; }
/// Determine if the node is a Bundle
Modified: hlvm/trunk/hlvm/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Type.cpp?rev=38056&r1=38055&r2=38056&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Type.cpp (original)
+++ hlvm/trunk/hlvm/AST/Type.cpp Sat Jul 7 18:59:23 2007
@@ -42,6 +42,12 @@
assert(!"This type doesn't accept children!");
}
+const char*
+Type::getPrimitiveName()
+{
+ return 0;
+}
+
AnyType::~AnyType()
{
}
@@ -197,4 +203,30 @@
return "void";
}
+PointerType::~PointerType()
+{
+}
+
+ArrayType::~ArrayType()
+{
+}
+
+VectorType::~VectorType()
+{
+}
+
+AliasType::~AliasType()
+{
+}
+
+const char*
+AliasType::getPrimitiveName()
+{
+ return type->getPrimitiveName();
+}
+
+OpaqueType::~OpaqueType()
+{
+}
+
}}
Modified: hlvm/trunk/hlvm/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Type.h?rev=38056&r1=38055&r2=38056&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Type.h (original)
+++ hlvm/trunk/hlvm/AST/Type.h Sat Jul 7 18:59:23 2007
@@ -48,14 +48,13 @@
Type(
NodeIDs id ///< The Type identifier
) : LinkageItem(id) {}
- public:
virtual ~Type();
/// @}
/// @name Accessors
/// @{
public:
- virtual const char* getPrimitiveName() = 0;
+ virtual const char* getPrimitiveName();
bool isPrimitive() { return getPrimitiveName() != 0; }
/// @}
@@ -105,56 +104,11 @@
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:
- virtual const char* getPrimitiveName();
- // 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:
+ protected:
AnyType() : Type(AnyTypeID) {}
virtual ~AnyType();
@@ -175,7 +129,7 @@
{
/// @name Constructors
/// @{
- public:
+ protected:
BooleanType() : Type(BooleanTypeID) {}
virtual ~BooleanType();
@@ -196,7 +150,7 @@
{
/// @name Constructors
/// @{
- public:
+ protected:
CharacterType() : Type(CharacterTypeID) {}
virtual ~CharacterType();
@@ -218,7 +172,7 @@
{
/// @name Constructors
/// @{
- public:
+ protected:
OctetType() : Type(OctetTypeID) {}
virtual ~OctetType();
@@ -239,7 +193,7 @@
{
/// @name Constructors
/// @{
- public:
+ protected:
VoidType() : Type(VoidTypeID) {}
virtual ~VoidType();
@@ -265,8 +219,9 @@
{
/// @name Constructors
/// @{
- public:
+ protected:
IntegerType() : Type(IntegerTypeID), numBits(32), signedness(true) {}
+ public:
virtual ~IntegerType();
/// @}
@@ -314,8 +269,9 @@
{
/// @name Constructors
/// @{
- public:
+ protected:
RangeType() : Type(RangeTypeID), min(0), max(256) {}
+ public:
virtual ~RangeType();
/// @}
@@ -364,8 +320,9 @@
{
/// @name Constructors
/// @{
- public:
+ protected:
RealType() : Type(RealTypeID), mantissa(52), exponent(11) {}
+ public:
virtual ~RealType();
/// @}
@@ -403,6 +360,204 @@
/// @}
friend class AST;
};
+
+ /// This class represents a storage location that is a pointer to another
+ /// type.
+ class PointerType : public Type
+ {
+ /// @name Constructors
+ /// @{
+ protected:
+ PointerType() : Type(PointerTypeID) {}
+ virtual ~PointerType();
+
+ /// @}
+ /// @name Accessors
+ /// @{
+ public:
+ // Get the target type
+ Type* getTargetType() { return type; }
+
+ // Methods to support type inquiry via is, cast, dyn_cast
+ static inline bool classof(const PointerType*) { return true; }
+ static inline bool classof(const Type* T) { return T->isPointerType(); }
+ static inline bool classof(const Node* T) { return T->is(PointerTypeID); }
+
+ /// @}
+ /// @name Mutators
+ /// @{
+ public:
+ void setTargetType(Type* t) { type = t; }
+
+ /// @}
+ /// @name Data
+ /// @{
+ protected:
+ Type* type;
+ /// @}
+ friend class AST;
+ };
+
+ /// This class represents a resizeable, aligned array of some other type. The
+ /// Array references a Type that specifies the type of elements in the array.
+ class ArrayType : public Type
+ {
+ /// @name Constructors
+ /// @{
+ protected:
+ ArrayType() : Type(ArrayTypeID), type(0), maxSize(0) {}
+ public:
+ virtual ~ArrayType();
+
+ /// @}
+ /// @name Accessors
+ /// @{
+ public:
+ /// Get the type of the array's elements.
+ Type* getElementType() const { return type; }
+
+ /// Get the maximum size the array can grow to.
+ uint64_t getMaxSize() const { return maxSize; }
+
+ // Methods to support type inquiry via is, cast, dyn_cast
+ static inline bool classof(const ArrayType*) { return true; }
+ static inline bool classof(const Type* T) { return T->isArrayType(); }
+ static inline bool classof(const Node* T) { return T->is(ArrayTypeID); }
+
+ /// @}
+ /// @name Mutators
+ /// @{
+ public:
+ /// Set the type of the array's elements.
+ void setElementType(Type* t) { type = t; }
+
+ /// Set the maximum size the array can grow to.
+ void setMaxSize(uint64_t max) { maxSize = max; }
+
+ /// @}
+ /// @name Data
+ /// @{
+ protected:
+ Type* type; ///< The type of the elements of the array
+ uint64_t maxSize; ///< The maximum number of elements in the array
+ /// @}
+ friend class AST;
+ };
+
+ /// This class represents a fixed size, packed vector of some other type.
+ /// Where possible, HLVM will attempt to generate code that makes use of a
+ /// machines vector instructions to process such types. If not possible, HLVM
+ /// will treat the vector the same as an Array.
+ class VectorType : public Type
+ {
+ /// @name Constructors
+ /// @{
+ protected:
+ VectorType() : Type(VectorTypeID), type(0), size(0) {}
+ virtual ~VectorType();
+
+ /// @}
+ /// @name Accessors
+ /// @{
+ public:
+ /// Get the type of the array's elements.
+ Type* getElementType() const { return type; }
+
+ /// Get the maximum size the array can grow to.
+ uint64_t getSize() const { return size; }
+
+ // Methods to support type inquiry via is, cast, dyn_cast
+ static inline bool classof(const VectorType*) { return true; }
+ static inline bool classof(const Type* T) { return T->isVectorType(); }
+ static inline bool classof(const Node* T) { return T->is(VectorTypeID); }
+
+ /// @}
+ /// @name Accessors
+ /// @{
+ public:
+ /// Set the type of the vector's elements.
+ void setElementType(Type* t) { type = t; }
+
+ /// Set the size of the vector.
+ void setSize(uint64_t max) { size = max; }
+
+ /// @}
+ /// @name Data
+ /// @{
+ protected:
+ Type* type; ///< The type of the vector's elements.
+ uint64_t size; ///< The (fixed) size of the vector
+ /// @}
+ friend class AST;
+ };
+
+ /// This class is type that combines a name with an arbitrary type. This
+ /// construct is used any where a named and typed object is needed such as
+ /// the parameter to a function or the field of a structure.
+ class AliasType : public Type
+ {
+ /// @name Constructors
+ /// @{
+ public:
+ AliasType() : Type(AliasTypeID) {}
+ virtual ~AliasType();
+
+ /// @}
+ /// @name Accessors
+ /// @{
+ public:
+ virtual const char* getPrimitiveName();
+ // 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 AliasType*) { return true; }
+ static inline bool classof(const Node* T) { return T->is(AliasTypeID); }
+
+ /// @}
+ /// @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 OpaqueType : public Type
+ {
+ /// @name Constructors
+ /// @{
+ protected:
+ OpaqueType(const std::string& nm) :
+ Type(OpaqueTypeID) { this->setName(nm); }
+ public:
+ virtual ~OpaqueType();
+
+ /// @}
+ /// @name Accessors
+ /// @{
+ public:
+ static inline bool classof(const OpaqueType*) { return true; }
+ static inline bool classof(const Node* N)
+ { return N->is(OpaqueTypeID); }
+
+ /// @}
+ friend class AST;
+ };
+
} // AST
} // hlvm
#endif
Modified: hlvm/trunk/hlvm/Reader/XML/HLVM.rng
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Reader/XML/HLVM.rng?rev=38056&r1=38055&r2=38056&view=diff
==============================================================================
--- hlvm/trunk/hlvm/Reader/XML/HLVM.rng (original)
+++ hlvm/trunk/hlvm/Reader/XML/HLVM.rng Sat Jul 7 18:59:23 2007
@@ -168,7 +168,14 @@
<choice>
<ref name="Bundle.elem"/>
<ref name="Function.elem"/>
- <ref name="Type.pat"/>
+ <ref name="Alias.elem"/>
+ <ref name="Atom.elem"/>
+ <ref name="Enumeration.elem"/>
+ <ref name="Pointer.elem"/>
+ <ref name="Array.elem"/>
+ <ref name="Vector.elem"/>
+ <ref name="Structure.elem"/>
+ <ref name="Signature.elem"/>
<ref name="Variable.elem"/>
</choice>
</zeroOrMore>
@@ -188,19 +195,6 @@
<!--PATTERNS FOR DEFINING TYPES -->
- <define name="Type.pat">
- <choice>
- <ref name="Alias.elem"/>
- <ref name="Atom.elem"/>
- <ref name="Enumeration.elem"/>
- <ref name="Pointer.elem"/>
- <ref name="Array.elem"/>
- <ref name="Vector.elem"/>
- <ref name="Structure.elem"/>
- <ref name="Signature.elem"/>
- </choice>
- </define>
-
<define name="Alias.elem">
<element name="alias">
<ref name="Named_Element.pat"/>
@@ -311,10 +305,10 @@
<define name="Vector.elem">
<element name="vector">
<ref name="Named_Element.pat"/>
- <attribute name="length"><data type="nonNegativeInteger"/></attribute>
<attribute name="of">
<ref name="Intrinsic_Atoms.type"/>
</attribute>
+ <attribute name="length"><data type="nonNegativeInteger"/></attribute>
</element>
</define>
Modified: hlvm/trunk/hlvm/Reader/XML/XMLReader.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Reader/XML/XMLReader.cpp?rev=38056&r1=38055&r2=38056&view=diff
==============================================================================
--- hlvm/trunk/hlvm/Reader/XML/XMLReader.cpp (original)
+++ hlvm/trunk/hlvm/Reader/XML/XMLReader.cpp Sat Jul 7 18:59:23 2007
@@ -60,13 +60,13 @@
XMLReaderImpl(const std::string& p)
: path(p), ast(0)
{
- ast = new AST::AST();
+ ast = AST::AST::create();
ast->setSystemID(p);
}
virtual ~XMLReaderImpl()
{
- if (ast) delete ast;
+ if (ast) AST::AST::destroy(ast);
if (doc) xmlFreeDoc(doc);
}
@@ -89,8 +89,8 @@
AST::Bundle* parseBundle(xmlNodePtr& cur);
AST::Function* parseFunction(xmlNodePtr& cur);
AST::Import* parseImport(xmlNodePtr& cur);
- AST::Type* parseType(xmlNodePtr& cur);
AST::Variable* parseVariable(xmlNodePtr& cur);
+ AST::AliasType*parseAlias(xmlNodePtr& cur);
AST::Type* parseAtom(xmlNodePtr& cur);
AST::Type* parsePointer(xmlNodePtr& cur);
AST::Type* parseArray(xmlNodePtr& cur);
@@ -181,10 +181,14 @@
}
inline const char*
-getAttribute(xmlNodePtr cur,const char*name)
+getAttribute(xmlNodePtr cur,const char*name,bool required = true)
{
- return reinterpret_cast<const char*>(
- xmlGetNoNsProp(cur,reinterpret_cast<const xmlChar*>(name)));
+ const char* result = reinterpret_cast<const char*>(
+ xmlGetNoNsProp(cur,reinterpret_cast<const xmlChar*>(name)));
+ if (!result && required) {
+ assert(!"Missing Attribute");
+ }
+ return result;
}
inline int
@@ -221,6 +225,16 @@
return imp;
}
+AST::AliasType*
+XMLReaderImpl::parseAlias(xmlNodePtr& cur)
+{
+ assert(getToken(cur->name)==TKN_alias);
+ AST::Locator loc(cur->line,0,&ast->getSystemID());
+ std::string name = getAttribute(cur,"name");
+ std::string type = getAttribute(cur,"renames");
+ return ast->new_AliasType(loc,name,ast->resolveType(type));
+}
+
AST::Type*
XMLReaderImpl::parseAtom(xmlNodePtr& cur)
{
@@ -242,22 +256,22 @@
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_f128: result=ast->new_f128(loc,name); break;
+ case TKN_f32: result=ast->new_f32(loc,name); break;
+ case TKN_f43: result=ast->new_f43(loc,name); break;
+ case TKN_f64: result=ast->new_f64(loc,name); break;
+ case TKN_f80: result=ast->new_f80(loc,name); 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_s128: result=ast->new_s128(loc,name); break;
+ case TKN_s16: result=ast->new_s16(loc,name); break;
+ case TKN_s32: result=ast->new_s32(loc,name); break;
+ case TKN_s64: result=ast->new_s64(loc,name); break;
+ case TKN_s8: result=ast->new_s8(loc,name); break;
+ case TKN_u128: result=ast->new_u128(loc,name); break;
+ case TKN_u16: result=ast->new_u16(loc,name); break;
+ case TKN_u32: result=ast->new_u32(loc,name); break;
+ case TKN_u64: result=ast->new_u64(loc,name); break;
+ case TKN_u8: result=ast->new_u8(loc,name); break;
case TKN_void: result=ast->new_VoidType(loc,name); break;
default:
assert(!"Invalid intrinsic kind");
@@ -314,48 +328,78 @@
AST::Type*
XMLReaderImpl::parsePointer(xmlNodePtr& cur)
{
- return 0;
+ assert(getToken(cur->name)==TKN_pointer);
+ AST::Locator loc(cur->line,0,&ast->getSystemID());
+ std::string name = getAttribute(cur,"name");
+ std::string type = getAttribute(cur,"to");
+ return ast->new_PointerType(loc,name,ast->resolveType(type));
}
AST::Type*
XMLReaderImpl::parseArray(xmlNodePtr& cur)
{
- return 0;
+ assert(getToken(cur->name)==TKN_array);
+ AST::Locator loc(cur->line,0,&ast->getSystemID());
+ std::string name = getAttribute(cur,"name");
+ std::string type = getAttribute(cur,"of");
+ const char* len = getAttribute(cur,"length");
+ return ast->new_ArrayType(loc, name, ast->resolveType(type),
+ recognize_nonNegativeInteger(len));
}
AST::Type*
XMLReaderImpl::parseVector(xmlNodePtr& cur)
{
- return 0;
+ assert(getToken(cur->name)==TKN_vector);
+ AST::Locator loc(cur->line,0,&ast->getSystemID());
+ std::string name = getAttribute(cur,"name");
+ std::string type = getAttribute(cur,"of");
+ const char* len = getAttribute(cur,"length");
+ return ast->new_VectorType(loc,name,ast->resolveType(type),
+ recognize_nonNegativeInteger(len));
}
AST::Type*
XMLReaderImpl::parseStructure(xmlNodePtr& cur)
{
- return 0;
+ assert(getToken(cur->name)==TKN_structure);
+ AST::Locator loc(cur->line,0,&ast->getSystemID());
+ std::string name = getAttribute(cur,"name");
+ AST::StructureType* struc = ast->new_StructureType(loc,name);
+ xmlNodePtr child = cur->children;
+ while (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE) {
+ assert(getToken(child->name) == TKN_field && "Structure only has fields");
+ std::string name = getAttribute(child,"name");
+ std::string type = getAttribute(child,"type");
+ AST::AliasType* nt = ast->new_AliasType(loc,name,ast->resolveType(type));
+ nt->setParent(struc);
+ child = child->next;
+ }
+ return struc;
}
AST::Type*
XMLReaderImpl::parseSignature(xmlNodePtr& cur)
{
- return 0;
-}
-
-AST::Type*
-XMLReaderImpl::parseType(xmlNodePtr& cur)
-{
- 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!");
+ assert(getToken(cur->name)==TKN_signature);
+ AST::Locator loc(cur->line,0,&ast->getSystemID());
+ std::string name = getAttribute(cur,"name");
+ std::string result = getAttribute(cur,"result");
+ const char* varargs = getAttribute(cur,"varargs",false);
+ AST::SignatureType* sig =
+ ast->new_SignatureType(loc,name,ast->resolveType(result));
+ if (varargs)
+ sig->setIsVarArgs(recognize_boolean(varargs));
+ xmlNodePtr child = cur->children;
+ while (child && skipBlanks(child) && child->type == XML_ELEMENT_NODE) {
+ assert(getToken(child->name) == TKN_arg && "Structure only has fields");
+ std::string name = getAttribute(child,"name");
+ std::string type = getAttribute(child,"type");
+ AST::AliasType* nt = ast->new_AliasType(loc,name,ast->resolveType(type));
+ nt->setParent(sig);
+ child = child->next;
}
- return T;
+ return sig;
}
AST::Variable*
@@ -386,7 +430,13 @@
case TKN_import : n = parseImport(child); break;
case TKN_bundle : n = parseBundle(child); break;
case TKN_function : n = parseFunction(child); break;
- case TKN_atom : n = parseType(child); break;
+ case TKN_alias : n = parseAlias(child); break;
+ case TKN_atom : n = parseAtom(child); break;
+ case TKN_pointer : n = parsePointer(child); break;
+ case TKN_array : n = parseArray(child); break;
+ case TKN_vector : n = parseVector(child); break;
+ case TKN_structure: n = parseStructure(child); break;
+ case TKN_signature: n = parseSignature(child); break;
case TKN_var : n = parseVariable(child); break;
default:
assert(!"Invalid content for bundle");
Modified: hlvm/trunk/hlvm/Writer/XML/XMLWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/Writer/XML/XMLWriter.cpp?rev=38056&r1=38055&r2=38056&view=diff
==============================================================================
--- hlvm/trunk/hlvm/Writer/XML/XMLWriter.cpp (original)
+++ hlvm/trunk/hlvm/Writer/XML/XMLWriter.cpp Sat Jul 7 18:59:23 2007
@@ -79,6 +79,10 @@
reinterpret_cast<const xmlChar*>(val)); }
inline void writeAttribute(const char* name, const std::string& val)
{ writeAttribute(name, val.c_str()); }
+ inline void writeAttribute(const char* name, AST::Type* t)
+ { writeAttribute(name, t->getName()); }
+ inline void writeAttribute(const char* name, uint64_t val)
+ { writeAttribute(name, llvm::utostr(val)); }
inline void writeElement(const char* elem, const char* body)
{ xmlTextWriterWriteElement(writer,
reinterpret_cast<const xmlChar*>(elem),
@@ -86,10 +90,10 @@
inline void putHeader();
inline void putFooter();
- inline void put(AST::Node* node);
inline void put(AST::Bundle* b);
inline void put(AST::Variable* v);
inline void put(AST::Function* f);
+ inline void put(AST::AliasType* t);
inline void put(AST::AnyType* t);
inline void put(AST::BooleanType* t);
inline void put(AST::CharacterType* t);
@@ -98,6 +102,11 @@
inline void put(AST::RealType* t);
inline void put(AST::OctetType* t);
inline void put(AST::VoidType* t);
+ inline void put(AST::PointerType* t);
+ inline void put(AST::ArrayType* t);
+ inline void put(AST::VectorType* t);
+ inline void put(AST::StructureType* t);
+ inline void put(AST::SignatureType* t);
};
@@ -116,16 +125,24 @@
xmlTextWriterEndDocument(writer);
}
-inline void
+void
XMLWriterImpl::put(AST::Function* f)
{
}
void
+XMLWriterImpl::put(AST::AliasType* t)
+{
+ startElement("alias");
+ writeAttribute("name",t->getName());
+ writeAttribute("renames",t->getType());
+ endElement();
+}
+void
XMLWriterImpl::put(AST::AnyType* t)
{
startElement("atom");
- writeAttribute("name",t->getName().c_str());
+ writeAttribute("name",t->getName());
startElement("intrinsic");
writeAttribute("is","any");
endElement();
@@ -213,14 +230,75 @@
XMLWriterImpl::put(AST::VoidType* t)
{
startElement("atom");
- writeAttribute("name",t->getName().c_str());
+ writeAttribute("name",t->getName());
startElement("intrinsic");
writeAttribute("is","void");
endElement();
endElement();
}
-inline void
+void
+XMLWriterImpl::put(AST::PointerType* t)
+{
+ startElement("pointer");
+ writeAttribute("name", t->getName());
+ writeAttribute("to", t->getTargetType());
+ endElement();
+}
+
+void
+XMLWriterImpl::put(AST::ArrayType* t)
+{
+ startElement("array");
+ writeAttribute("name", t->getName());
+ writeAttribute("of", t->getElementType());
+ writeAttribute("length", t->getMaxSize());
+ endElement();
+}
+
+void
+XMLWriterImpl::put(AST::VectorType* t)
+{
+ startElement("vector");
+ writeAttribute("name", t->getName());
+ writeAttribute("of", t->getElementType());
+ writeAttribute("length", t->getSize());
+ endElement();
+}
+
+void
+XMLWriterImpl::put(AST::StructureType* t)
+{
+ startElement("structure");
+ writeAttribute("name",t->getName());
+ for (AST::StructureType::iterator I = t->begin(), E = t->end(); I != E; ++I) {
+ startElement("field");
+ AST::AliasType* nt = cast<AST::AliasType>(*I);
+ writeAttribute("name",nt->getName());
+ writeAttribute("type",nt->getType());
+ endElement();
+ }
+ endElement();
+}
+
+void
+XMLWriterImpl::put(AST::SignatureType* t)
+{
+ startElement("signature");
+ writeAttribute("name",t->getName());
+ writeAttribute("result",t->getResultType());
+ writeAttribute("varargs",t->isVarArgs() ? "true" : "false");
+ for (AST::SignatureType::iterator I = t->begin(), E = t->end(); I != E; ++I) {
+ startElement("arg");
+ AST::AliasType* nt = cast<AST::AliasType>(*I);
+ writeAttribute("name",nt->getName());
+ writeAttribute("type",nt->getType());
+ endElement();
+ }
+ endElement();
+}
+
+void
XMLWriterImpl::put(AST::Variable* v)
{
startElement("var");
@@ -229,7 +307,7 @@
endElement();
}
-inline void
+void
XMLWriterImpl::put(AST::Bundle* b)
{
startElement("bundle");
@@ -240,6 +318,7 @@
{
case AST::VariableID: put(cast<AST::Variable>(*I)); break;
case AST::FunctionID: put(cast<AST::Function>(*I)); break;
+ case AST::AliasTypeID: put(cast<AST::AliasType>(*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;
@@ -248,6 +327,11 @@
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;
+ case AST::PointerTypeID: put(cast<AST::PointerType>(*I)); break;
+ case AST::ArrayTypeID: put(cast<AST::ArrayType>(*I)); break;
+ case AST::VectorTypeID: put(cast<AST::VectorType>(*I)); break;
+ case AST::StructureTypeID: put(cast<AST::StructureType>(*I)); break;
+ case AST::SignatureTypeID: put(cast<AST::SignatureType>(*I)); break;
default:
assert(!"Invalid bundle content");
}
@@ -256,124 +340,6 @@
}
void
-XMLWriterImpl::put(AST::Node* node)
-{
- switch (node->getID())
- {
- case hlvm::AST::VoidTypeID: break;
- case hlvm::AST::AnyTypeID: break;
- case hlvm::AST::BooleanTypeID: break;
- case hlvm::AST::CharacterTypeID: break;
- case hlvm::AST::OctetTypeID: break;
- case hlvm::AST::IntegerTypeID: break;
- case hlvm::AST::RangeTypeID: break;
- case hlvm::AST::RealTypeID: break;
- case hlvm::AST::RationalTypeID: break;
- case hlvm::AST::StringTypeID: break;
- 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::SignatureTypeID: break;
- case hlvm::AST::ContinuationTypeID: break;
- case hlvm::AST::InterfaceID: break;
- case hlvm::AST::ClassID: break;
- case hlvm::AST::MethodID: break;
- case hlvm::AST::ImplementsID: break;
- case hlvm::AST::VariableID: break;
- case hlvm::AST::FunctionID: break;
- case hlvm::AST::ProgramID: break;
- case hlvm::AST::BundleID:
- put(llvm::cast<hlvm::AST::Bundle>(node));
- break;
- case hlvm::AST::BlockID: break;
- case hlvm::AST::CallOpID: break;
- case hlvm::AST::InvokeOpID: break;
- case hlvm::AST::DispatchOpID: break;
- case hlvm::AST::CreateContOpID: break;
- case hlvm::AST::CallWithContOpID: break;
- case hlvm::AST::ReturnOpID: break;
- case hlvm::AST::ThrowOpID: break;
- case hlvm::AST::JumpToOpID: break;
- case hlvm::AST::BreakOpID: break;
- case hlvm::AST::IfOpID: break;
- case hlvm::AST::LoopOpID: break;
- case hlvm::AST::SelectOpID: break;
- case hlvm::AST::WithOpID: break;
- case hlvm::AST::LoadOpID: break;
- case hlvm::AST::StoreOpID: break;
- case hlvm::AST::AllocateOpID: break;
- case hlvm::AST::FreeOpID: break;
- case hlvm::AST::ReallocateOpID: break;
- case hlvm::AST::StackAllocOpID: break;
- case hlvm::AST::ReferenceOpID: break;
- case hlvm::AST::DereferenceOpID: break;
- case hlvm::AST::NegateOpID: break;
- case hlvm::AST::ComplementOpID: break;
- case hlvm::AST::PreIncrOpID: break;
- case hlvm::AST::PostIncrOpID: break;
- case hlvm::AST::PreDecrOpID: break;
- case hlvm::AST::PostDecrOpID: break;
- case hlvm::AST::AddOpID: break;
- case hlvm::AST::SubtractOpID: break;
- case hlvm::AST::MultiplyOpID: break;
- case hlvm::AST::DivideOpID: break;
- case hlvm::AST::ModulusOpID: break;
- case hlvm::AST::BAndOpID: break;
- case hlvm::AST::BOrOpID: break;
- case hlvm::AST::BXOrOpID: break;
- case hlvm::AST::AndOpID: break;
- case hlvm::AST::OrOpID: break;
- case hlvm::AST::NorOpID: break;
- case hlvm::AST::XorOpID: break;
- case hlvm::AST::NotOpID: break;
- case hlvm::AST::LTOpID: break;
- case hlvm::AST::GTOpID: break;
- case hlvm::AST::LEOpID: break;
- case hlvm::AST::GEOpID: break;
- case hlvm::AST::EQOpID: break;
- case hlvm::AST::NEOpID: break;
- case hlvm::AST::IsPInfOpID: break;
- case hlvm::AST::IsNInfOpID: break;
- case hlvm::AST::IsNaNOpID: break;
- case hlvm::AST::TruncOpID: break;
- case hlvm::AST::RoundOpID: break;
- case hlvm::AST::FloorOpID: break;
- case hlvm::AST::CeilingOpID: break;
- case hlvm::AST::PowerOpID: break;
- case hlvm::AST::LogEOpID: break;
- case hlvm::AST::Log2OpID: break;
- case hlvm::AST::Log10OpID: break;
- case hlvm::AST::SqRootOpID: break;
- case hlvm::AST::RootOpID: break;
- case hlvm::AST::FactorialOpID: break;
- case hlvm::AST::GCDOpID: break;
- case hlvm::AST::LCMOpID: break;
- case hlvm::AST::MungeOpID: break;
- case hlvm::AST::LengthOpID: break;
- case hlvm::AST::IntOpID: break;
- case hlvm::AST::RealOpID: break;
- case hlvm::AST::PInfOpID: break;
- case hlvm::AST::NInfOpID: break;
- case hlvm::AST::NaNOpID: break;
- case hlvm::AST::StringOpID: break;
- case hlvm::AST::ArrayOpID: break;
- case hlvm::AST::VectorOpID: break;
- case hlvm::AST::StructureOpID: break;
- case hlvm::AST::MapFileOpID: break;
- case hlvm::AST::OpenOpID: break;
- case hlvm::AST::CloseOpID: break;
- case hlvm::AST::ReadOpID: break;
- case hlvm::AST::WriteOpID: break;
- case hlvm::AST::PositionOpID: break;
- default:
- assert(!"Invalid Node ID");
- break;
- }
-}
-
-void
XMLWriterImpl::write(AST::AST* ast)
{
node = ast;
Added: hlvm/trunk/test/xml2xml/alias.hlx
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/xml2xml/alias.hlx?rev=38056&view=auto
==============================================================================
--- hlvm/trunk/test/xml2xml/alias.hlx (added)
+++ hlvm/trunk/test/xml2xml/alias.hlx Sat Jul 7 18:59:23 2007
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<hlvm xmlns="http://hlvm.org/src/hlvm/Reader/XML/HLVM.rng">
+ <bundle pubid="bundle">
+ <atom name="someType">
+ <intrinsic is="any"/>
+ </atom>
+ <alias name="anAlias" renames="someType"/>
+ </bundle>
+</hlvm>
Added: hlvm/trunk/test/xml2xml/array.hlx
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/xml2xml/array.hlx?rev=38056&view=auto
==============================================================================
--- hlvm/trunk/test/xml2xml/array.hlx (added)
+++ hlvm/trunk/test/xml2xml/array.hlx Sat Jul 7 18:59:23 2007
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<hlvm xmlns="http://hlvm.org/src/hlvm/Reader/XML/HLVM.rng">
+ <bundle pubid="bundle">
+ <atom name="someType">
+ <intrinsic is="any"/>
+ </atom>
+ <array name="anArray" of="someType" length="128"/>
+ </bundle>
+</hlvm>
Added: hlvm/trunk/test/xml2xml/pointer.hlx
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/xml2xml/pointer.hlx?rev=38056&view=auto
==============================================================================
--- hlvm/trunk/test/xml2xml/pointer.hlx (added)
+++ hlvm/trunk/test/xml2xml/pointer.hlx Sat Jul 7 18:59:23 2007
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<hlvm xmlns="http://hlvm.org/src/hlvm/Reader/XML/HLVM.rng">
+ <bundle pubid="bundle">
+ <atom name="someType">
+ <intrinsic is="any"/>
+ </atom>
+ <pointer name="aPointerType" to="someType"/>
+ </bundle>
+</hlvm>
Added: hlvm/trunk/test/xml2xml/signature.hlx
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/xml2xml/signature.hlx?rev=38056&view=auto
==============================================================================
--- hlvm/trunk/test/xml2xml/signature.hlx (added)
+++ hlvm/trunk/test/xml2xml/signature.hlx Sat Jul 7 18:59:23 2007
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<hlvm xmlns="http://hlvm.org/src/hlvm/Reader/XML/HLVM.rng">
+ <bundle pubid="bundle">
+ <atom name="someType">
+ <intrinsic is="any"/>
+ </atom>
+ <signature name="sig1" result="someType" varargs="false">
+ <arg name="arg1" type="someType"/>
+ </signature>
+ <signature name="struct2" result="someType" varargs="true">
+ <arg name="arg1" type="someType"/>
+ <arg name="arg1" type="someType"/>
+ </signature>
+ </bundle>
+</hlvm>
Added: hlvm/trunk/test/xml2xml/structure.hlx
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/xml2xml/structure.hlx?rev=38056&view=auto
==============================================================================
--- hlvm/trunk/test/xml2xml/structure.hlx (added)
+++ hlvm/trunk/test/xml2xml/structure.hlx Sat Jul 7 18:59:23 2007
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<hlvm xmlns="http://hlvm.org/src/hlvm/Reader/XML/HLVM.rng">
+ <bundle pubid="bundle">
+ <atom name="someType">
+ <intrinsic is="any"/>
+ </atom>
+ <structure name="struct1">
+ <field name="field1" type="someType"/>
+ </structure>
+ <structure name="struct2">
+ <field name="field1" type="someType"/>
+ <field name="field2" type="someType"/>
+ </structure>
+ </bundle>
+</hlvm>
Added: hlvm/trunk/test/xml2xml/vector.hlx
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/test/xml2xml/vector.hlx?rev=38056&view=auto
==============================================================================
--- hlvm/trunk/test/xml2xml/vector.hlx (added)
+++ hlvm/trunk/test/xml2xml/vector.hlx Sat Jul 7 18:59:23 2007
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<hlvm xmlns="http://hlvm.org/src/hlvm/Reader/XML/HLVM.rng">
+ <bundle pubid="bundle">
+ <vector name="aVector" of="f32" length="128"/>
+ </bundle>
+</hlvm>
More information about the llvm-commits
mailing list