[llvm-commits] [hlvm] r37983 - in /hlvm/trunk/hlvm/AST: ContainerType.h Node.cpp Type.h
Reid Spencer
reid at x10sys.com
Sat Jul 7 16:58:38 PDT 2007
Author: reid
Date: Sat Jul 7 18:58:37 2007
New Revision: 37983
URL: http://llvm.org/viewvc/llvm-project?rev=37983&view=rev
Log:
Finish out the type hierarchy and add class query support.
Added:
hlvm/trunk/hlvm/AST/ContainerType.h
Modified:
hlvm/trunk/hlvm/AST/Node.cpp
hlvm/trunk/hlvm/AST/Type.h
Added: hlvm/trunk/hlvm/AST/ContainerType.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/ContainerType.h?rev=37983&view=auto
==============================================================================
--- hlvm/trunk/hlvm/AST/ContainerType.h (added)
+++ hlvm/trunk/hlvm/AST/ContainerType.h Sat Jul 7 18:58:37 2007
@@ -0,0 +1,202 @@
+//
+// Copyright (C) 2006 HLVM Group. All Rights Reserved.
+//
+// This program is open source software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License (GPL) as published by
+// the Free Software Foundation; either version 2 of the License, or (at your
+// option) any later version. You should have received a copy of the GPL in a
+// file named COPYING that was included with this program; if not, you can
+// obtain a copy of the license through the Internet at http://www.fsf.org/
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+//
+////////////////////////////////////////////////////////////////////////////////
+/// @file hlvm/AST/Type.h
+/// @author Reid Spencer <reid at hlvm.org> (original author)
+/// @date 2006/05/04
+/// @since 0.1.0
+/// @brief Declares the class hlvm::AST::Type
+////////////////////////////////////////////////////////////////////////////////
+
+#ifndef HLVM_AST_CONTAINERTYPE_H
+#define HLVM_AST_CONTAINERTYPE_H
+
+#include <hlvm/AST/Type.h>
+
+namespace hlvm {
+namespace AST {
+ /// This class represents a Type in the HLVM Abstract Syntax Tree.
+ /// A Type defines the format of storage.
+ /// @brief HLVM AST Type Node
+ class ContainerType : public Type
+ {
+ /// @name Constructors
+ /// @{
+ public:
+ ContainerType(
+ Node* parent, ///< The bundle in which the function is defined
+ const std::string& name, ///< The name of the function
+ TypeIDs type_id
+ ) : Type(parent,name,type_id) {}
+ 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 Data
+ /// @{
+ protected:
+ std::vector<Type*> types_; ///< The contained types
+ /// @}
+ };
+
+ /// This class represents a storage location that is a pointer to another
+ /// type.
+ class PointerType : public ContainerType
+ {
+ /// @name Constructors
+ /// @{
+ public:
+ PointerType(
+ Node* parent, ///< The bundle in which the function is defined
+ const std::string& name ///< The name of the function
+ ) : ContainerType(parent,name,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(); }
+ /// @}
+ /// @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(
+ Node* parent, ///< The bundle in which the function is defined
+ const std::string& name ///< The name of the function
+ ) : ContainerType(parent,name,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(); }
+ /// @}
+ /// @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(
+ Node* parent, ///< The bundle in which the function is defined
+ const std::string& name ///< The name of the function
+ ) : ContainerType(parent,name,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(); }
+ /// @}
+ /// @name Data
+ /// @{
+ protected:
+ /// @}
+ };
+
+ /// This class represents an HLVM type that is a sequence of data fields
+ /// of varying type.
+ class StructureType : public ContainerType
+ {
+ /// @name Constructors
+ /// @{
+ public:
+ StructureType(
+ Node* parent, ///< The bundle in which the function is defined
+ const std::string& name ///< The name of the function
+ ) : ContainerType(parent,name,StructureTypeID) {}
+ virtual ~StructureType();
+
+ /// @}
+ /// @name Accessors
+ /// @{
+ public:
+ // 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(); }
+ /// @}
+ /// @name Data
+ /// @{
+ protected:
+ /// @}
+ };
+
+ /// This class represents an HLVM type that is a sequence of data fields
+ /// of varying type.
+ class SignatureType : public ContainerType
+ {
+ /// @name Constructors
+ /// @{
+ public:
+ SignatureType(
+ Node* parent, ///< The bundle in which the function is defined
+ const std::string& name ///< The name of the function
+ ) : ContainerType(parent,name,SignatureTypeID) {}
+ virtual ~SignatureType();
+
+ /// @}
+ /// @name Accessors
+ /// @{
+ public:
+ // 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(); }
+ /// @}
+ /// @name Data
+ /// @{
+ protected:
+ Type* result_; ///< The result type of the function signature
+ bool isVarArgs; ///< Indicates variable arguments function
+ /// @}
+ };
+} // AST
+} // hlvm
+#endif
Modified: hlvm/trunk/hlvm/AST/Node.cpp
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Node.cpp?rev=37983&r1=37982&r2=37983&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Node.cpp (original)
+++ hlvm/trunk/hlvm/AST/Node.cpp Sat Jul 7 18:58:37 2007
@@ -22,10 +22,11 @@
////////////////////////////////////////////////////////////////////////////////
#include <hlvm/AST/Node.h>
+#include <hlvm/AST/Type.h>
+#include <hlvm/AST/ContainerType.h>
#include <hlvm/AST/Bundle.h>
#include <hlvm/AST/Function.h>
#include <hlvm/AST/Variable.h>
-#include <hlvm/AST/Type.h>
namespace hlvm
{
Modified: hlvm/trunk/hlvm/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/hlvm/trunk/hlvm/AST/Type.h?rev=37983&r1=37982&r2=37983&view=diff
==============================================================================
--- hlvm/trunk/hlvm/AST/Type.h (original)
+++ hlvm/trunk/hlvm/AST/Type.h Sat Jul 7 18:58:37 2007
@@ -25,9 +25,27 @@
#define HLVM_AST_TYPE_H
#include <hlvm/AST/Node.h>
+#include <llvm/Support/Casting.h>
namespace hlvm {
namespace AST {
+ /// This enumeration is used to identify a specific type
+ enum TypeIDs {
+ VoidTypeID = 0, ///< The Void Type
+ IntegerTypeID, ///< The Integer Type
+ RangeTypeID, ///< The Range Type
+ RealTypeID, ///< The Real Number Type
+ PointerTypeID, ///< The Pointer Type
+ ArrayTypeID, ///< The Array Type
+ VectorTypeID, ///< The Vector Type
+ StructureTypeID, ///< The Structure Type
+ SignatureTypeID, ///< The Function Signature Type
+
+ NumTypeIDs, ///< The number of type identifiers in the enum
+ LastPrimitiveTypeID = RealTypeID,
+ FirstContainerTypeID = PointerTypeID
+ };
+
/// This class represents a Type in the HLVM Abstract Syntax Tree.
/// A Type defines the format of storage.
/// @brief HLVM AST Type Node
@@ -38,15 +56,38 @@
public:
Type(
Node* parent, ///< The bundle in which the function is defined
- const std::string& name ///< The name of the function
- ) : Node(parent,name) {}
+ const std::string& name, ///< The name of the function
+ TypeIDs type_id ///< The Type identifier
+ ) : Node(parent,name), id_(type_id) {}
virtual ~Type();
/// @}
+ /// @name Accessors
+ /// @{
+ inline bool isPrimitiveType() const { return id_ <= LastPrimitiveTypeID; }
+ inline bool isIntegralType() const {
+ return id_ == IntegerTypeID || id_ == RangeTypeID;
+ }
+ inline bool isContainerType() const {
+ return id_ >= FirstContainerTypeID;
+ }
+ inline bool isIntegerType() const { return id_ == IntegerTypeID; }
+ inline bool isRangeType() const { return id_ == RangeTypeID; }
+ inline bool isRealType() const { return id_ == RealTypeID; }
+ inline bool isPointerType() const { return id_ == PointerTypeID; }
+ inline bool isArrayType() const { return id_ == ArrayTypeID; }
+ inline bool isVectorType() const { return id_ == VectorTypeID; }
+ inline bool isStructureType() const { return id_ == StructureTypeID; }
+ inline bool isSignatureType() const { return id_ == SignatureTypeID; }
+
+ // Methods to support type inquiry via is, cast, dyn_cast
+ static inline bool classof(const Type*) { return true; }
+
+ /// @}
/// @name Data
/// @{
protected:
- Type* type_; ///< The type of the variable
+ TypeIDs id_; ///< The type identifier
/// @}
};
@@ -63,10 +104,18 @@
IntegerType(
Node* parent, ///< The bundle in which the function is defined
const std::string& name ///< The name of the function
- ) : Type(parent,name) {}
+ ) : Type(parent,name,IntegerTypeID) {}
virtual ~IntegerType();
/// @}
+ /// @name Accessors
+ /// @{
+ public:
+ // 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(); }
+
+ /// @}
/// @name Data
/// @{
protected:
@@ -77,7 +126,7 @@
/// A RangeType is an IntegerType that allows the range of values to be
/// constricted. The use of RangeType implies range checking whenever the
/// value of a RangeType variable is assigned.
- class RangeType: public IntegerType
+ class RangeType: public Type
{
/// @name Constructors
/// @{
@@ -85,10 +134,17 @@
RangeType(
Node* parent, ///< The bundle in which the function is defined
const std::string& name ///< The name of the function
- ) : IntegerType(parent,name) {}
+ ) : Type(parent,name,RangeTypeID) {}
virtual ~RangeType();
/// @}
+ /// @name Accessors
+ /// @{
+ public:
+ // 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(); }
+ /// @}
/// @name Data
/// @{
protected:
@@ -111,33 +167,16 @@
RealType(
Node* parent, ///< The bundle in which the function is defined
const std::string& name ///< The name of the function
- ) : Type(parent,name) {}
+ ) : Type(parent,name,RealTypeID) {}
virtual ~RealType();
/// @}
- /// @name Data
- /// @{
- protected:
- uint32_t precision_; ///< Number of decimal digits of precision
- uint32_t mantissa_; ///< Number of decimal digits in mantissa
- /// @}
- };
-
- /// 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
+ /// @name Accessors
/// @{
public:
- VectorType(
- Node* parent, ///< The bundle in which the function is defined
- const std::string& name ///< The name of the function
- ) : Type(parent,name) {}
- virtual ~VectorType();
-
+ // 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(); }
/// @}
/// @name Data
/// @{
More information about the llvm-commits
mailing list