PageRenderTime 4ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/src/wrappers/llvm/library/types/llvm_type.e

http://github.com/tybor/Liberty
Specman e | 149 lines | 69 code | 22 blank | 58 comment | 0 complexity | ab2bb4c873c82546460b1c0309eb8561 MD5 | raw file
  1deferred class LLVM_TYPE
  2--      Type is a superclass of all type classes.
  3--      Every Value has a Type. Type cannot be
  4--      instantiated directly but only through its
  5--      subclasses. Certain primitive types
  6--      (VoidType, LabelType, FloatType and
  7--      DoubleType) have hidden subclasses. They are
  8--      hidden because they offer no useful
  9--      functionality beyond what the Type class
 10--      offers except to distinguish themselves from
 11--      other subclasses of Type.
 12
 13-- All other types are subclasses of
 14-- DerivedType. Types can be named, but this is
 15-- not a requirement. There exists exactly one
 16-- instance of a given shape at any one time.
 17-- This allows type equality to be performed
 18-- with address equality of the Type Instance.
 19-- That is, given two Type* values, the types
 20-- are identical if the pointers are identical.
 21
 22-- The representation of the base type of all datatypes in LLVM. Anchestor
 23-- of all hierarchy of types. See
 24-- http://llvm.org/doxygen/classllvm_1_1Type.html for a clean graph of its
 25-- heirs.
 26
 27
 28-- TODO: when implementing `refine' remember to redefine it in LLVM_STRUCT_TYPE to take in count about cyclic type
 29inherit
 30   C_STRUCT
 31   C_OWNED
 32
 33insert CORE_EXTERNALS
 34
 35feature {ANY} -- Queries
 36   type_kind: LLVMTYPE_KIND_ENUM
 37         -- The actual type of Current
 38      do
 39         Result.change_value (llvmget_type_kind(handle))
 40      end
 41
 42
 43   -- TODO: C binding offers a call "LLVMTypeRef
 44   -- LLVMGetElementType(LLVMTypeRef Ty);"; provide a meaningful Eiffel
 45   -- equivalent.
 46   context: LLVM_CONTEXT
 47      do
 48		  create Result.from_external_pointer(llvmget_type_context(handle))
 49      end
 50
 51   struct_size: like size_t
 52         -- LLVM_TYPE actually wraps a polymorphic C++ class; temporarly this query always fails.
 53      require implemented: False
 54      do
 55         not_yet_implemented -- or mostly unuseful
 56      end
 57
 58   is_boolean: BOOLEAN
 59         -- Is Current a one-bit integer?
 60      do
 61         Result := is_integer and then as_integer.width=1.to_natural_32
 62      end
 63
 64   is_integer: BOOLEAN
 65         -- Is Current an integer type?
 66      do
 67         Result := type_kind.is_integer_type_kind
 68      end
 69
 70   is_floating_point: BOOLEAN
 71         -- Is Current a floating point type?
 72      do
 73         Result := type_kind.is_double_type_kind or else
 74         type_kind.is_x86_fp80type_kind or else
 75         type_kind.is_fp128type_kind or else
 76         type_kind.is_ppc_fp128type_kind
 77      end
 78
 79   is_vector: BOOLEAN
 80         -- Is Current a vector?
 81      do
 82         Result := type_kind.is_vector_type_kind
 83      end
 84
 85   is_pointer: BOOLEAN
 86         -- Is Current a pointer?
 87      do
 88         Result := type_kind.is_pointer_type_kind
 89      end
 90
 91   is_struct: BOOLEAN
 92         -- Is Current a struct type?
 93      do
 94         Result := type_kind.is_struct_type_kind
 95      end
 96
 97   is_array: BOOLEAN
 98         -- Is Current an array type?
 99      do
100         Result := type_kind.is_array_type_kind
101      end
102
103   -- is_abstract: BOOLEAN is -- is Current abstract, i.e. does it contain opaque type anywhere in its definition.
104   -- is_sized: BOOLEAN is -- Has the type a known size? Things that don't have a size are abstract types, labels and void.
105
106feature {ANY}
107   as_integer: LLVM_INTEGER_TYPE
108         -- Downcasting to integer type
109      require is_integer
110      do
111         -- Forced assignment is allowed because of the precondition.
112         Result ::= Current
113      ensure Result/=Void
114      end
115
116   as_struct: LLVM_STRUCT_TYPE
117         -- Downcasting to struct type
118      require is_struct
119      do
120         -- Safe forced assignment because of the precondition
121         Result ::= Current
122      end
123
124   as_vector: LLVM_VECTOR_TYPE
125         -- Downcasting to integer type
126      require is_vector
127      do
128         -- Forced assignment is safe because of the precondition.
129         Result::=Current
130      ensure Result/=Void
131      end
132end -- class LLVM_TYPE
133
134
135-- Copyright (C) 2009-2017: Paolo Redaelli
136-- This file is part of LLVM wrappers for Liberty Eiffel.
137--
138-- This library is free software: you can redistribute it and/or modify
139-- it under the terms of the GNU Lesser General Public License as published by
140-- the Free Software Foundation, version 3 of the License.
141--
142-- Liberty Eiffel is distributed in the hope that it will be useful,
143-- but WITHOUT ANY WARRANTY; without even the implied warranty of
144-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
145-- GNU General Public License for more details.
146--
147-- You should have received a copy of the GNU General Public License
148-- along with Liberty Eiffel.  If not, see <http://www.gnu.org/licenses/>.
149--