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

http://github.com/tybor/Liberty · Specman e · 99 lines · 39 code · 15 blank · 45 comment · 0 complexity · 5547bd657fe1164475b5beac4abbd798 MD5 · raw file

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