/src/wrappers/llvm/library/types/llvm_function_type.e
Specman e | 99 lines | 39 code | 15 blank | 45 comment | 0 complexity | 5547bd657fe1164475b5beac4abbd798 MD5 | raw file
1class LLVM_FUNCTION_TYPE 2-- A type representing a function. 3 4-- It is a COLLECTION of LLVM_TYPEs, the types of its arguments. 5 6-- TODO: ask 7 8inherit 9 LLVM_TYPE 10 --undefine fill_tagged_out_memory 11 redefine copy end 12 LLVM_TYPE_FACTORY 13 -- TODO: enable access to the type of the argument of the function; it may be a 14 -- C_ARRAY[LLVM_TYPE] 15 -- undefine is_equal -- use is_equal from LLVM_TYPE 16 -- redefine copy 17 -- end 18 -- but we shall ask LLVM developers if parameter list may change during 19 -- object's lifetime. In that case how to be notied?If they may change it 20 -- can hardly be a C_ARRAY, since it can change under our feets. 21 22insert 23 WRAPPER_HANDLER 24 ARRAYED_COLLECTION_HANDLER 25 26create {ANY} make, from_external_pointer 27 28feature {ANY} 29 make (a_return_type: LLVM_TYPE; some_parameters: COLLECTION[LLVM_TYPE]; a_variadic_function: BOOLEAN) 30 -- Create a function type with `a_return_type' and `some_parameters' 31 -- Variadic functions, allowed by LLVM don't fit Eiffel design rules therefore are not supported 32 33 -- TODO: currently `some_parameters' items will be copied into a newly 34 -- allocated C array passed to LLVM. This is plainly inefficient yet avoid 35 -- tricky bugs with current compiler. In future if `some_parameters' 36 -- conforms to a C_ARRAY its storage will be used directly; 37 require 38 a_return_type/=Void 39 some_parameters/=Void 40 do 41 handle := llvmfunction_type 42 (a_return_type.handle, 43 collection_to_c_array(some_parameters).storage.to_external, 44 some_parameters.count.to_natural_32, 0) 45 -- 0 stands for an eventual `a_variadic_function'.to_integer_32; if 46 -- `a_variadic_function' is True the Result will be variadic. 47 end 48 49 copy (another: like Current) 50 do 51 handle:=another.handle 52 --storage:=storage.calloc(another.count) 53 --storage.copy_from(another.storage,another.upper) 54 end 55feature {ANY} 56 return_type: LLVM_TYPE 57 do 58 Result:=type_wrapper(llvmget_return_type(handle)) 59 end 60 61 parameters_count: INTEGER_32 62 -- The number of parameters accepted by Current function 63 do 64 Result:=llvmcount_params(handle).to_integer_32 65 -- Note: the underlying C function have perhaps been renamed to unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy); 66 end 67 68 -- TODO: wrap void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef 69 -- *Dest); into parameters: COLLECTION[LLVM_TYPE]; actually it shall 70 -- require direct access to C++ API to implement it soundly, efficiently 71 -- and correctly. 72 73 is_var_arg: BOOLEAN 74 -- Does Current function accept a variable number of arguments? 75 76 -- Note: even if Liberty does not have variable-arguments calls we may handle functions compiled from other languages. 77 do 78 Result:=llvmis_function_var_arg(handle).to_boolean 79 end 80 81invariant type_kind.is_function_type_kind 82end -- LLVM_FUNCTION_TYPE 83 84-- Copyright (C) 2009-2017: Paolo Redaelli 85 86-- This file is part of LLVM wrappers for Liberty Eiffel. 87-- 88-- This library is free software: you can redistribute it and/or modify 89-- it under the terms of the GNU Lesser General Public License as published by 90-- the Free Software Foundation, version 3 of the License. 91-- 92-- Liberty Eiffel is distributed in the hope that it will be useful, 93-- but WITHOUT ANY WARRANTY; without even the implied warranty of 94-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 95-- GNU General Public License for more details. 96-- 97-- You should have received a copy of the GNU General Public License 98-- along with Liberty Eiffel. If not, see <http://www.gnu.org/licenses/>. 99--