PageRenderTime 64ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/src/wrappers/llvm/library/llvm_builder.e

http://github.com/tybor/Liberty
Specman e | 1148 lines | 668 code | 124 blank | 356 comment | 12 complexity | dda55d99dc80970956936d6d86911cfc MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1, GPL-2.0
  1. class LLVM_BUILDER
  2. -- An instruction builder represents point within an LLVM_BASIC_BLOCK where it builds instructions.
  3. -- TODO: many preconditions requires its arguments to be of a specific type
  4. -- (most often integers, floating point numbers or vectors of integers or
  5. -- floats). Replace them - if possible - with more specific types of
  6. -- arguments.
  7. -- Note: Internally it uses the C interface so it doesn't has full-fledged
  8. -- access to the entire C++ API.
  9. inherit
  10. C_STRUCT redefine default_create end
  11. ARRAYED_COLLECTION_HANDLER redefine default_create end
  12. insert CORE_EXTERNALS redefine default_create end
  13. create {ANY} in_context, default_create, at_end_of
  14. feature {ANY} -- Creation
  15. in_context (a_context: LLVM_CONTEXT)
  16. -- Create an LLVM_BUILDER in `a_context'.
  17. require a_context/=Void
  18. do
  19. from_external_pointer(llvmcreate_builder_in_context(a_context.handle))
  20. end
  21. default_create
  22. do
  23. from_external_pointer(llvmcreate_builder)
  24. end
  25. at_end_of (a_block: LLVM_BASIC_BLOCK)
  26. -- Create a new builder positioned at the end of `a_block'; this
  27. -- commodity creation feature is a shortcut for (equivalent to) "create
  28. -- Result; Result.position_at_end_of(a_block)"
  29. require a_block/=Void
  30. do
  31. default_create
  32. position_at_end_of(a_block)
  33. end
  34. feature {ANY} -- Positioning
  35. set_position (a_block: LLVM_BASIC_BLOCK; an_instruction: LLVM_VALUE)
  36. -- TODO: description
  37. require
  38. a_block/=Void
  39. an_instruction/=Void
  40. do
  41. llvmposition_builder(handle,a_block.handle,an_instruction.handle)
  42. end
  43. position_before (an_instruction: LLVM_INSTRUCTION)
  44. -- Set Current position before `an_instruction'
  45. require an_instruction/=Void
  46. do
  47. llvmposition_builder_before(handle,an_instruction.handle)
  48. end
  49. position_at_end_of (a_block: LLVM_BASIC_BLOCK)
  50. -- Set Current position at the end of `a_block'
  51. require a_block/=Void
  52. do
  53. llvmposition_builder_at_end(handle,a_block.handle)
  54. end
  55. insert_block: LLVM_BASIC_BLOCK
  56. local p: POINTER
  57. do
  58. p := llvmget_insert_block(handle)
  59. if p.is_not_null then create Result.from_external_pointer(p) end
  60. end
  61. clear_insertion_position
  62. do
  63. llvmclear_insertion_position(handle)
  64. end
  65. insert_instruction (an_instruction: LLVM_INSTRUCTION)
  66. require an_instruction/=Void
  67. do
  68. llvminsert_into_builder(handle,an_instruction.handle)
  69. end
  70. insert_with_name (a_value: LLVM_VALUE; a_name: ABSTRACT_STRING)
  71. require
  72. a_value/=Void
  73. a_name/=Void
  74. do
  75. llvminsert_into_builder_with_name(handle,a_value.handle,a_name.to_external)
  76. end
  77. feature {ANY} -- Terminators
  78. return_void: LLVM_RETURN_INST
  79. do
  80. create Result.from_external_pointer(llvmbuild_ret_void(handle))
  81. end
  82. return (a_value: LLVM_VALUE): LLVM_RETURN_INST
  83. -- A "ret" instruction returing `a_value'
  84. require a_value/=Void
  85. do
  86. create Result.from_external_pointer(llvmbuild_ret(handle,a_value.handle))
  87. ensure Result/=Void
  88. end
  89. aggregate_return (some_values: COLLECTION[LLVM_VALUE]): LLVM_RETURN_INST
  90. -- A "ret" instruction returning `some_values'.
  91. require some_values/=Void; not some_values.is_empty
  92. local sv: FAST_ARRAY[POINTER]; i: ITERATOR[LLVM_VALUE]
  93. do
  94. create sv.with_capacity(some_values.count)
  95. from i:=some_values.new_iterator; i.start
  96. until i.is_off loop
  97. sv.add_last(i.item.handle); i.next
  98. end
  99. create Result.from_external_pointer
  100. (llvmbuild_aggregate_ret(handle,sv.to_external,some_values.count.to_natural_32))
  101. ensure Result/=Void
  102. end
  103. unconditional_branch (a_destination: LLVM_BASIC_BLOCK): LLVM_BRANCH_INST
  104. -- An unconditional branch "br" instruction that transfer the control
  105. -- flow to a different basic block in the current function.
  106. require a_destination/=Void
  107. do
  108. create Result.from_external_pointer(llvmbuild_br(handle,a_destination.handle))
  109. ensure Result/=Void
  110. end
  111. conditional_branch (an_if: LLVM_VALUE; a_then, an_else: LLVM_BASIC_BLOCK): LLVM_BRANCH_INST
  112. -- A conditional branch "br" instruction that will pass control flow to
  113. -- `a_then' if `an_if' evaluates to True, to `an_else' otherwise
  114. require
  115. an_if/=Void
  116. a_then/=Void
  117. an_else/=Void
  118. do
  119. create Result.from_external_pointer (llvmbuild_cond_br
  120. (handle, an_if.handle, a_then.handle, an_else.handle))
  121. ensure Result/=Void
  122. end
  123. switch (a_value: LLVM_VALUE; an_else: LLVM_BASIC_BLOCK; a_number_of_cases: NATURAL_32): LLVM_SWITCH_INST
  124. -- A 'switch' instruction, used to transfer control flow to one of
  125. -- several different places. It is a generalization of the 'br'
  126. -- instruction, allowing a branch to occur to one of many possible
  127. -- destinations. `an_else' is executed when `a_value' will not match
  128. -- one of the cases added later with `add_case' which must be exactly
  129. -- `a_number_of_cases'.
  130. require
  131. a_value/=Void
  132. an_else/=Void
  133. do
  134. create Result.from_external_pointer
  135. (llvmbuild_switch(handle,a_value.handle,an_else.handle,a_number_of_cases))
  136. ensure Result/=Void
  137. end
  138. invoke (a_function: LLVM_FUNCTION_TYPE; some_arguments: COLLECTION[LLVM_VALUE]; a_then, a_catch: LLVM_BASIC_BLOCK; a_name: ABSTRACT_STRING): LLVM_INVOKE_INST
  139. -- An "invoke" instruction. If `a_function' is parameterless `some_arguments' is not used and can be Void.
  140. -- TODO: specify the meaning of `a_then' and `a_catch'.
  141. require
  142. a_function/=Void
  143. a_then/=Void
  144. a_catch/=Void
  145. a_name/=Void
  146. some_arguments=Void implies a_function.parameters_count=0
  147. some_arguments/=Void implies a_function.parameters_count>0 and not some_arguments.is_empty
  148. local args: FAST_ARRAY[POINTER]; args_p: POINTER
  149. do
  150. if some_arguments/=Void and then not some_arguments.is_empty then
  151. args:=collection_to_c_array(some_arguments)
  152. args_p := args.to_external
  153. end
  154. create Result.from_external_pointer
  155. (llvmbuild_invoke(handle,a_function.handle,
  156. args_p,args.count.to_natural_32,
  157. a_then.handle,a_catch.handle, a_name.to_external))
  158. ensure Result/=Void
  159. end
  160. unreachable: LLVM_VALUE
  161. -- A newly create 'unreachable' instruction; it has no defined
  162. -- semantics. This instruction is used to inform the optimizer that a
  163. -- particular portion of the code is not reachable. This can be used to
  164. -- indicate that the code after a no-return function cannot be reached,
  165. -- and other facts.
  166. do
  167. create Result.from_external_pointer (llvmbuild_unreachable(handle))
  168. ensure Result/=Void
  169. end
  170. feature {ANY} -- Arithmetic
  171. add (a_left, a_right: LLVM_VALUE; a_name: ABSTRACT_STRING): LLVM_VALUE
  172. -- A newly created `add' instruction with `a_name' summing `a_left' and `a_right'.
  173. -- The two arguments to the 'add' instruction must be integer or vector
  174. -- of integer values. Both arguments must have identical types.
  175. -- If the sum has unsigned overflow, the result returned is the
  176. -- mathematical result modulo 2n, where n is the bit width of the
  177. -- result.
  178. -- Because LLVM integers use a two's complement representation, this
  179. -- instruction is appropriate for both signed and unsigned integers.
  180. -- The "nuw" and "nsw" variant of this instruction stand for "No
  181. -- Unsigned Wrap" and "No Signed Wrap", respectively. If the nuw and/or
  182. -- nsw keywords are present, the result value of the add is undefined
  183. -- if unsigned and/or signed overflow, respectively, occurs.
  184. require
  185. a_left/=Void
  186. a_right/=Void
  187. a_name/=Void
  188. identical_type: a_left.type ~ a_right.type
  189. integers_or_vectors: a_left.type.is_integer or a_left.is_constant_vector
  190. vectors_are_of_integers: a_left.is_constant_vector implies a_left.as_constant_vector.type.element_type.is_integer
  191. do
  192. create Result.from_external_pointer
  193. (llvmbuild_add(handle,a_left.handle, a_right.handle, a_name.to_external))
  194. ensure
  195. Result/=Void
  196. Result.type ~ a_left.type
  197. end
  198. no_signed_wrap_addition, nsw_add (a_left, a_right: LLVM_VALUE; a_name: ABSTRACT_STRING): LLVM_ADD_OPERATOR
  199. -- A newly created `no-signed-wrap-add' instruction with `a_name' summing `a_left' and `a_right'. See `add' for further informations.
  200. require
  201. a_left/=Void
  202. a_right/=Void
  203. a_name/=Void
  204. identical_type: a_left.type ~ a_right.type
  205. integers_or_vectors: a_left.type.is_integer or a_left.is_constant_vector
  206. vectors_are_of_integers: a_left.is_constant_vector implies a_left.as_constant_vector.type.element_type.is_integer
  207. do
  208. create Result.from_external_pointer
  209. (llvmbuild_nswadd(handle,a_left.handle,a_right.handle,a_name.to_external))
  210. ensure
  211. Result/=Void
  212. Result.type ~ a_left.type
  213. end
  214. float_add, fadd (a_left,a_right: LLVM_VALUE; a_name: ABSTRACT_STRING): LLVM_VALUE
  215. -- The 'fadd' instruction returns the sum of its two operands that must
  216. -- be floating point or vector of floating point values and must have
  217. -- identical types. The value produced is the floating point sum of the
  218. -- two operands.
  219. require
  220. a_left/=Void
  221. a_right/=Void
  222. a_name/=Void
  223. identical_type: a_left.type ~ a_right.type
  224. floating_points_or_vectors: a_left.is_constant_fp or a_left.is_constant_vector
  225. vectors_are_of_floats: a_left.is_constant_vector implies a_left.as_constant_vector.type.element_type.is_floating_point
  226. do
  227. create Result.from_external_pointer
  228. (llvmbuild_fadd(handle,a_left.handle,a_right.handle,a_name.to_external))
  229. ensure
  230. Result/=Void
  231. Result.type ~ a_left.type
  232. end
  233. sub (a_left, a_right: LLVM_VALUE; a_name: ABSTRACT_STRING): LLVM_SUB_OPERATOR
  234. -- An integer subtraction operation on `a_left' and `a_right'.
  235. require
  236. a_left/=Void
  237. a_right/=Void
  238. identical_type: a_left.type ~ a_right.type
  239. integers_or_vectors: a_left.type.is_integer or a_left.is_constant_vector
  240. vectors_are_of_integers: a_left.is_constant_vector implies a_left.as_constant_vector.type.element_type.is_integer
  241. do
  242. create Result.from_external_pointer(llvmbuild_sub(handle,a_left.handle,a_right.handle,a_name.to_external))
  243. ensure
  244. Result/=Void
  245. Result.type ~ a_left.type
  246. end
  247. mul (a_left, a_right: LLVM_VALUE; a_name: ABSTRACT_STRING): LLVM_VALUE
  248. -- Create a 'mul' instruction that multiplyies `a_left' and `a_right', with `a_name'.
  249. -- If the result of the multiplication has unsigned overflow, the
  250. -- result returned is the mathematical result modulo 2n, where n is the
  251. -- bit width of the result.
  252. -- Because LLVM integers use a two's complement representation, and the
  253. -- result is the same width as the operands, this instruction returns
  254. -- the correct result for both signed and unsigned integers. If a full
  255. -- product (e.g. i32xi32->i64) is needed, the operands should be
  256. -- sign-extended or zero-extended as appropriate to the width of the
  257. -- full product.
  258. -- nuw and nsw variants stand for "No Unsigned Wrap" and "No Signed
  259. -- Wrap", respectively. If the nuw and/or nsw keywords are present, the
  260. -- result value of the mul is undefined if unsigned and/or signed
  261. -- overflow, respectively, occurs.
  262. require
  263. a_left/=Void
  264. a_right/=Void
  265. a_name/=Void
  266. identical_type: a_left.type ~ a_right.type
  267. integers_or_vectors: a_left.type.is_integer or a_left.is_constant_vector
  268. vectors_are_of_integers: a_left.is_constant_vector implies a_left.as_constant_vector.type.element_type.is_integer
  269. do
  270. create Result.from_external_pointer
  271. (llvmbuild_mul(handle,a_left.handle, a_right.handle, a_name.to_external))
  272. ensure
  273. Result/=Void
  274. Result.type ~ a_left.type
  275. end
  276. float_multiplication, fmul (a_left, a_right: LLVM_VALUE; a_name: ABSTRACT_STRING): LLVM_VALUE
  277. -- The product of `a_left' and `a_right', labelled with `a_name'
  278. require
  279. a_left/=Void
  280. a_right/=Void
  281. a_name/=Void
  282. identical_type: a_left.type ~ a_right.type
  283. floating_points_or_vectors: a_left.is_constant_fp or a_left.is_constant_vector
  284. vectors_are_of_floats: a_left.is_constant_vector implies a_left.as_constant_vector.type.element_type.is_floating_point
  285. do
  286. create Result.from_external_pointer(llvmbuild_fmul(handle,a_left.handle,a_right.handle, a_name.to_external))
  287. ensure
  288. Result/=Void
  289. Result.type ~ a_left.type
  290. end
  291. udiv, unsigned_division (a_left, a_right: LLVM_VALUE; a_name: ABSTRACT_STRING): LLVM_VALUE
  292. -- The unsigned integer quotient of `a_left' divided by `a_right'.
  293. -- Note that unsigned integer division and signed integer division are
  294. -- distinct operations; for signed integer division, use 'sdiv'.
  295. -- Division by zero leads to undefined behavior.
  296. require
  297. a_left/=Void
  298. a_right/=Void
  299. a_name/=Void
  300. identical_type: a_left.type ~ a_right.type
  301. integers_or_vectors: a_left.type.is_integer or a_left.is_constant_vector
  302. vectors_are_of_integers: a_left.is_constant_vector implies a_left.as_constant_vector.type.element_type.is_integer
  303. do
  304. create Result.from_external_pointer(llvmbuild_udiv(handle,a_left.handle,a_right.handle,a_name.to_external))
  305. ensure
  306. Result/=Void
  307. Result.type ~ a_left.type
  308. end
  309. signed_division (a_left, a_right: LLVM_VALUE; a_name: ABSTRACT_STRING): LLVM_VALUE
  310. -- The signed integer quotient of `a_left' and `a_right' rounded towards zero.
  311. -- Note that signed integer division and unsigned integer division are
  312. -- distinct operations; for unsigned integer division, use 'udiv'.
  313. -- Division by zero leads to undefined behavior. Overflow also leads to
  314. -- undefined behavior; this is a rare case, but can occur, for example,
  315. -- by doing a 32-bit division of -2147483648 by -1.
  316. -- TODO: If the exact keyword is present, the result value of the sdiv
  317. -- is undefined if the result would be rounded or if overflow would
  318. -- occur.
  319. require
  320. a_left/=Void
  321. a_right/=Void
  322. a_name/=Void
  323. identical_type: a_left.type ~ a_right.type
  324. integers_or_vectors: a_left.type.is_integer or a_left.is_constant_vector
  325. vectors_are_of_integers: a_left.is_constant_vector implies a_left.as_constant_vector.type.element_type.is_integer
  326. do
  327. create Result.from_external_pointer(llvmbuild_udiv(handle,a_left.handle,a_right.handle,a_name.to_external))
  328. ensure
  329. Result/=Void
  330. Result.type ~ a_left.type
  331. end
  332. exact_signed_division (a_left, a_right: LLVM_VALUE; a_name: ABSTRACT_STRING): LLVM_VALUE
  333. -- An "exact sdiv" operation, the exact, signed integer quotient of
  334. -- `a_left' and `a_right' rounded towards zero.
  335. -- The result value of the sdiv is undefined if the result would be
  336. -- rounded or if overflow would occur.
  337. require
  338. a_left/=Void
  339. a_right/=Void
  340. a_name/=Void
  341. identical_type: a_left.type ~ a_right.type
  342. integers_or_vectors: a_left.type.is_integer or a_left.is_constant_vector
  343. vectors_are_of_integers: a_left.is_constant_vector implies a_left.as_constant_vector.type.element_type.is_integer
  344. do
  345. create Result.from_external_pointer(llvmbuild_exact_sdiv(handle,a_left.handle,a_right.handle,a_name.to_external))
  346. ensure
  347. Result/=Void
  348. Result.type ~ a_left.type
  349. end
  350. float_division (a_left, a_right: LLVM_VALUE; a_name: ABSTRACT_STRING): LLVM_VALUE
  351. -- An 'fdiv' instruction, the floating point quotient of `a_left' and `a_right'.
  352. require
  353. a_left/=Void
  354. a_right/=Void
  355. a_name/=Void
  356. identical_type: a_left.type ~ a_right.type
  357. floating_points_or_vectors: a_left.is_constant_fp or a_left.is_constant_vector
  358. vectors_are_of_floats: a_left.is_constant_vector implies a_left.as_constant_vector.type.element_type.is_floating_point
  359. do
  360. create Result.from_external_pointer(llvmbuild_fdiv(handle,a_left.handle,a_right.handle, a_name.to_external))
  361. ensure
  362. Result/=Void
  363. Result.type ~ a_left.type
  364. end
  365. unsigned_remainder (a_left, a_right: LLVM_VALUE; a_name: ABSTRACT_STRING): LLVM_VALUE
  366. -- A 'urem' instruction computing the unsigned integer remainder of the
  367. -- unsigned division of `a_left' and `a_right'.To get the remainder an
  368. -- unsigned division is always performed.
  369. -- Note that unsigned integer remainder and signed integer remainder
  370. -- are distinct operations; for signed integer remainder, use `srem'.
  371. -- Taking the remainder of a division by zero leads to undefined behavior.
  372. require
  373. a_left/=Void
  374. a_right/=Void
  375. a_name/=Void
  376. identical_type: a_left.type ~ a_right.type
  377. integers_or_vectors_of_integers: a_left.type.is_integer or else a_left.is_constant_vector and then a_left.as_constant_vector.type.element_type.is_integer
  378. do
  379. create Result.from_external_pointer(llvmbuild_urem(handle,a_left.handle,a_right.handle,a_name.to_external))
  380. ensure
  381. Result/=Void
  382. Result.type ~ a_left.type
  383. end
  384. signed_remainder (a_left, a_right: LLVM_VALUE; a_name: ABSTRACT_STRING): LLVM_VALUE
  385. -- A 'srem' instruction computing the signed integer remainder of the
  386. -- signed division of `a_left' and `a_right'.To get the remainder an
  387. -- signed division is always performed.
  388. -- This instruction returns the remainder of a division (where the
  389. -- result has the same sign as the dividend, `a_left'), not the modulo
  390. -- operator (where the result has the same sign as the divisor,
  391. -- 'a_right') of a value. For more information about the difference,
  392. -- see The Math Forum. For a table of how this is implemented in
  393. -- various languages, please see
  394. -- http://en.wikipedia.org/wiki/Modulo_operation
  395. -- Note that signed integer remainder and unsigned integer remainder
  396. -- are distinct operations; for unsigned integer remainder, use `urem'.
  397. -- Taking the remainder of a division by zero leads to undefined
  398. -- behavior. Overflow also leads to undefined behavior; this is a rare
  399. -- case, but can occur, for example, by taking the remainder of a
  400. -- 32-bit division of -2147483648 by -1. (The remainder doesn't
  401. -- actually overflow, but this rule lets srem be implemented using
  402. -- instructions that return both the result of the division and the
  403. -- remainder.)
  404. -- Note that unsigned integer remainder and signed integer remainder
  405. -- are distinct operations; for signed integer remainder, use `srem'.
  406. require
  407. a_left/=Void
  408. a_right/=Void
  409. a_name/=Void
  410. identical_type: a_left.type ~ a_right.type
  411. integers_or_vectors_of_integers: a_left.type.is_integer or else a_left.is_constant_vector and then a_left.as_constant_vector.type.element_type.is_integer
  412. do
  413. create Result.from_external_pointer(llvmbuild_srem(handle,a_left.handle,a_right.handle,a_name.to_external))
  414. ensure
  415. Result/=Void
  416. Result.type ~ a_left.type
  417. end
  418. float_remainder (a_left, a_right: LLVM_VALUE; a_name: ABSTRACT_STRING): LLVM_VALUE
  419. -- An 'frem' instruction computing the remainder of the division of `a_left' and `a_right'.
  420. -- The remainder has the same sign as the dividend.
  421. require
  422. a_left/=Void
  423. a_right/=Void
  424. a_name/=Void
  425. identical_type: a_left.type ~ a_right.type
  426. floating_points_or_vectors_of_floats: a_left.is_constant_fp or else a_left.is_constant_vector and then a_left.as_constant_vector.type.element_type.is_floating_point
  427. do
  428. create Result.from_external_pointer(llvmbuild_frem(handle,a_left.handle,a_right.handle,a_name.to_external))
  429. ensure
  430. Result/=Void
  431. Result.type ~ a_left.type
  432. end
  433. shift_left (a_left, a_right: LLVM_VALUE; a_name: ABSTRACT_STRING): LLVM_VALUE
  434. -- A 'shl' instruction that computes `a_left' shifted to the left by a number of bits specified in `a_right'.
  435. -- The value produced is op1 * 2op2 mod 2n, where n is the width of the result. If op2 is (statically or dynamically) negative or equal to or larger than the number of bits in op1, the result is undefined. If the arguments are vectors, each vector element of op1 is shifted by the corresponding shift amount in op2.
  436. require
  437. a_left/=Void
  438. a_right/=Void
  439. a_name/=Void
  440. identical_type: a_left.type ~ a_right.type
  441. integers_or_vectors_of_integers: a_left.type.is_integer or else a_left.is_constant_vector and then a_left.as_constant_vector.type.element_type.is_integer
  442. do
  443. create Result.from_external_pointer(llvmbuild_shl(handle,a_left.handle,a_right.handle,a_name.to_external))
  444. ensure
  445. Result/=Void
  446. Result.type ~ a_left.type
  447. end
  448. logical_shift_right (a_left, a_right: LLVM_VALUE; a_name: ABSTRACT_STRING): LLVM_VALUE
  449. -- A "lshr" instruction (logical shift right), computing `a_left' shifted to the right by the number of bits specified in `a_right' with zero fill.
  450. -- This instruction always performs a logical shift right operation.
  451. -- The most significant bits of the result will be filled with zero
  452. -- bits after the shift. If op2 is (statically or dynamically) equal to
  453. -- or larger than the number of bits in op1, the result is undefined.
  454. -- If the arguments are vectors, each vector element of op1 is shifted
  455. -- by the corresponding shift amount in op2.
  456. require
  457. a_left/=Void
  458. a_right/=Void
  459. a_name/=Void
  460. identical_type: a_left.type ~ a_right.type
  461. integers_or_vectors_of_integers: a_left.type.is_integer or else a_left.is_constant_vector and then a_left.as_constant_vector.type.element_type.is_integer
  462. do
  463. create Result.from_external_pointer(llvmbuild_lshr(handle,a_left.handle,a_right.handle,a_name.to_external))
  464. ensure
  465. Result/=Void
  466. Result.type ~ a_left.type
  467. end
  468. arithmetic_shift_right (a_left, a_right: LLVM_VALUE; a_name: ABSTRACT_STRING): LLVM_VALUE
  469. -- An "ashr" instruction (arithmetic shift right), computing `a_left shifted to the right by the number of bits specified in `a_right' with sign extension. `a_right' is treated as an unsigned value.
  470. -- This instruction always performs an arithmetic shift right operation, The most significant bits of the result will be filled with the sign bit of `a_left'. If `a_right' is (statically or dynamically) equal to or larger than the number of bits in `a_left', the result is undefined. If the arguments are vectors, each vector element of `a_left' is shifted by the corresponding shift amount in 'a_right'.
  471. require
  472. a_left/=Void
  473. a_right/=Void
  474. a_name/=Void
  475. identical_type: a_left.type ~ a_right.type
  476. integers_or_vectors_of_integers: a_left.type.is_integer or else a_left.is_constant_vector and then a_left.as_constant_vector.type.element_type.is_integer
  477. do
  478. create Result.from_external_pointer(llvmbuild_ashr(handle,a_left.handle,a_right.handle,a_name.to_external))
  479. ensure
  480. Result/=Void
  481. Result.type ~ a_left.type
  482. end
  483. feature {ANY} -- Logical operators
  484. logical_and (a_left, a_right: LLVM_VALUE; a_name: ABSTRACT_STRING): LLVM_VALUE
  485. -- An "and" instruction, the bitwise logical and of `a_left' and `a_right'.
  486. require
  487. a_left/=Void
  488. a_right/=Void
  489. a_name/=Void
  490. identical_type: a_left.type ~ a_right.type
  491. integers_or_vectors_of_integers: a_left.type.is_integer or else a_left.is_constant_vector and then a_left.as_constant_vector.type.element_type.is_integer
  492. do
  493. create Result.from_external_pointer(llvmbuild_and(handle,a_left.handle,a_right.handle,a_name.to_external))
  494. ensure
  495. Result/=Void
  496. Result.type ~ a_left.type
  497. end
  498. logical_or (a_left, a_right: LLVM_VALUE; a_name: ABSTRACT_STRING): LLVM_VALUE
  499. -- An "or" instruction, the bitwise logical or of `a_left' and `a_right'.
  500. require
  501. a_left/=Void
  502. a_right/=Void
  503. a_name/=Void
  504. identical_type: a_left.type ~ a_right.type
  505. integers_or_vectors_of_integers: a_left.type.is_integer or else a_left.is_constant_vector and then a_left.as_constant_vector.type.element_type.is_integer
  506. do
  507. create Result.from_external_pointer(llvmbuild_or(handle,a_left.handle,a_right.handle,a_name.to_external))
  508. ensure
  509. Result/=Void
  510. Result.type ~ a_left.type
  511. end
  512. logical_xor (a_left, a_right: LLVM_VALUE; a_name: ABSTRACT_STRING): LLVM_VALUE
  513. -- A "xor" instruction, the bitwise exclusive logical or of `a_left' and `a_right'.
  514. require
  515. a_left/=Void
  516. a_right/=Void
  517. a_name/=Void
  518. identical_type: a_left.type ~ a_right.type
  519. integers_or_vectors_of_integers: a_left.type.is_integer or else a_left.is_constant_vector and then a_left.as_constant_vector.type.element_type.is_integer
  520. do
  521. create Result.from_external_pointer(llvmbuild_xor(handle,a_left.handle,a_right.handle,a_name.to_external))
  522. ensure
  523. Result/=Void
  524. Result.type ~ a_left.type
  525. end
  526. logical_neg (a_value: LLVM_VALUE; a_name: ABSTRACT_STRING): LLVM_VALUE
  527. -- TODO: provide description, semating, preconditions and postconditions.
  528. require a_value/=Void
  529. do
  530. create Result.from_external_pointer(llvmbuild_neg(handle,a_value.handle,a_name.to_external))
  531. ensure Result/=Void
  532. end
  533. logical_not (a_value: LLVM_VALUE; a_name: ABSTRACT_STRING): LLVM_VALUE
  534. -- TODO: provide description, semating, preconditions and postconditions.
  535. require a_value/=Void
  536. do
  537. create Result.from_external_pointer(llvmbuild_not(handle,a_value.handle, a_name.to_external))
  538. ensure Result/=Void
  539. end
  540. feature {ANY} -- Memory
  541. malloc_inst (a_type: LLVM_TYPE; a_name: ABSTRACT_STRING): LLVM_MALLOC_INST
  542. -- A 'malloc' instruction allocating memory for `a_type' on the system heap and returning a pointer to it. The object is always allocated in the generic address space (address space zero). Memory is allocated using the system "malloc" function, and a pointer is returned. The result of a zero byte allocation is undefined. The result is null if there is insufficient memory available.
  543. -- TODO: LLVM assembly language allows to specify the alignment of the allocation but I coudln't figure how to implement if using the C bindings we are relying on.
  544. require
  545. a_type/=Void
  546. -- TODO type must be sized
  547. do
  548. create Result.from_external_pointer(llvmbuild_malloc(handle, a_type.handle,a_name.to_external))
  549. ensure Result/=Void
  550. end
  551. array_malloc (a_type: LLVM_TYPE; a_number: LLVM_VALUE; a_name: ABSTRACT_STRING): LLVM_MALLOC_INST
  552. -- A 'malloc' instruction allocateing memory from the system heap for
  553. -- `a_number' of objects of `a_type' returing a pointer to it. The
  554. -- object is always allocated in the generic address space (address
  555. -- space zero). The result of a zero byte allocation is undefined. The
  556. -- result is null if there is insufficient memory available.
  557. require
  558. a_type/=Void
  559. -- TODO type must be sized
  560. a_number/=Void
  561. a_number.type.is_integer
  562. a_name/=Void
  563. do
  564. create Result.from_external_pointer(llvmbuild_array_malloc(handle,a_type.handle, a_number.handle, a_name.to_external))
  565. ensure
  566. Result/=Void
  567. end
  568. alloca_inst (a_type: LLVM_TYPE; a_name: ABSTRACT_STRING): LLVM_ALLOCA_INST
  569. -- An "alloca" instruction allocating memory for an instance of
  570. -- `a_type' on the stack frame of the currently executing function, to
  571. -- be automatically released when this function returns to its caller.
  572. -- The object is always allocated in the generic address space (address
  573. -- space zero).
  574. -- The operation is undefined if there is insufficient stack space for
  575. -- the allocation. 'alloca'd memory is automatically released when the
  576. -- function returns. The 'alloca' instruction is commonly used to
  577. -- represent automatic variables that must have an address available.
  578. -- When the function returns (either with the ret or unwind
  579. -- instructions), the memory is reclaimed. Allocating zero bytes is
  580. -- legal, but the result is undefined.
  581. require
  582. a_type/=Void
  583. -- TODO: a_type.is_sized
  584. do
  585. create Result.from_external_pointer(llvmbuild_alloca(handle,a_type.handle,a_name.to_external))
  586. ensure
  587. Result/=Void
  588. end
  589. array_alloca (a_type: LLVM_TYPE; a_number: LLVM_VALUE; a_name: ABSTRACT_STRING): LLVM_ALLOCA_INST
  590. -- An "alloca" instruction allocating memory for `a_number' of instances of
  591. -- `a_type' on the stack frame of the currently executing function, to
  592. -- be automatically released when this function returns to its caller.
  593. -- See `alloca' for further informations.
  594. require
  595. a_type/=Void
  596. -- TODO: a_type.is_sized
  597. a_number/=Void
  598. a_number.type.is_integer
  599. do
  600. create Result.from_external_pointer(llvmbuild_array_alloca(handle,a_type.handle,a_number.handle,a_name.to_external))
  601. ensure
  602. Result/=Void
  603. end
  604. llvm_free (a_value: LLVM_VALUE): LLVM_FREE_INST
  605. -- A 'free' instruction returning memory back to the unused memory heap
  606. -- to be reallocated in the future.
  607. -- Access to the memory pointed to by the pointer is no longer defined
  608. -- after this instruction executes. If the pointer is null, the
  609. -- operation is a noop.
  610. require
  611. a_value/=Void
  612. a_value.type.is_pointer
  613. -- TODO: a value was allocated with a 'malloc' instruction
  614. do
  615. create Result.from_external_pointer(llvmbuild_free(handle, a_value.handle))
  616. ensure Result/=Void
  617. end
  618. load (a_location: LLVM_VALUE; a_name: ABSTRACT_STRING): LLVM_LOAD_INST
  619. -- A 'load' instruction that will read from memory `a_location' that
  620. -- specifies the memory address from which to load.
  621. -- TODO: LLVM allows to mark the load as volatile; this is currently
  622. -- not supported. If the load is marked as volatile, then the optimizer
  623. -- is not allowed to modify the number or order of execution of this
  624. -- load with other volatile load and store instructions.
  625. -- Semantics: The location of memory pointed to is loaded. If the value
  626. -- being loaded is of scalar type then the number of bytes read does
  627. -- not exceed the minimum number of bytes needed to hold all bits of
  628. -- the type. For example, loading an i24 reads at most three bytes.
  629. -- When loading a value of a type like i20 with a size that is not an
  630. -- integral number of bytes, the result is undefined if the value was
  631. -- not originally written using a store of the same type.
  632. require
  633. a_location/=Void
  634. -- TODO: a_location.is_pointer
  635. -- TODO: The pointer must point to a first class type.
  636. do
  637. create Result.from_external_pointer(llvmbuild_load(handle,a_location.handle,a_name.to_external))
  638. ensure Result/=Void
  639. end
  640. store (a_value: LLVM_VALUE; a_pointer: LLVM_VALUE): LLVM_STORE_INST
  641. -- A 'store' instruction that will update memory at `an_address' to
  642. -- contain `a_value'.
  643. -- If `a_value' is of scalar type then the number of bytes written does
  644. -- not exceed the minimum number of bytes needed to hold all bits of
  645. -- the type. For example, storing an i24 writes at most three bytes.
  646. -- When writing a value of a type like i20 with a size that is not an
  647. -- integral number of bytes, it is unspecified what happens to the
  648. -- extra bits that do not belong to the type, but they will typically
  649. -- be overwritten.
  650. -- TODO: volatile store is currently not supported so the following
  651. -- does not apply. If the store is marked as volatile, then the
  652. -- optimizer is not allowed to modify the number or order of execution
  653. -- of this store with other volatile load and store instructions.
  654. -- TODO: LLVM support specific alignement but it is currently not provided. The following does not apply.The optional constant "align" argument specifies the alignment of the operation (that is, the alignment of the memory address). A value of 0 or an omitted "align" argument means that the operation has the preferential alignment for the target. It is the responsibility of the code emitter to ensure that the alignment information is correct. Overestimating the alignment results in an undefined behavior. Underestimating the alignment may produce less efficient code. An alignment of 1 is always safe.
  655. require
  656. a_value/=Void
  657. a_pointer/=Void
  658. -- TODO: a_pointer.is_pointer
  659. -- TODO: a_pointer must be a pointer to the same type of a_value which must be a first class type.
  660. do
  661. create Result.from_external_pointer(llvmbuild_store(handle,a_value.handle,a_pointer.handle))
  662. ensure
  663. Result/=Void
  664. end
  665. get_element_pointer (a_pointer: LLVM_VALUE; some_indices: COLLECTION[LLVM_VALUE]; a_name: ABSTRACT_STRING): LLVM_GEP_OPERATOR
  666. -- A "get element pointer" intruction
  667. require
  668. -- TODO: a_pointer should point to what?
  669. a_name/=Void
  670. local indices: FAST_ARRAY[POINTER]
  671. do
  672. -- Intentionally avoiding WRAPPER_COLLECTION to avoid tricks with native arrays
  673. indices := collection_to_c_array(some_indices)
  674. create Result.from_external_pointer(llvmbuild_gep(handle, a_pointer.handle, indices.to_external, some_indices.count.to_natural_32, a_name.to_external))
  675. ensure Result/=Void
  676. end
  677. -- TODO: wrap LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
  678. -- LLVMValueRef *Indices, unsigned NumIndices,
  679. -- const char *Name);
  680. get_struct_element_pointer (a_pointer: LLVM_VALUE; an_index: NATURAL_32; a_name: ABSTRACT_STRING): LLVM_GEP_OPERATOR
  681. -- "getelementpointer" of a structure field
  682. require
  683. -- TODO: a_pointer should point to a struct
  684. a_name/=Void
  685. do
  686. -- LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
  687. -- unsigned Idx, const char *Name);
  688. create Result.from_external_pointer(llvmbuild_struct_gep(handle,a_pointer.handle, an_index, a_name.to_external))
  689. ensure
  690. Result/=Void
  691. end
  692. global_string (a_string, a_name: ABSTRACT_STRING): LLVM_GLOBAL_VARIABLE
  693. -- A global string with the content of `a_string' referrable by `a_name'.
  694. do
  695. create Result.from_external_pointer(llvmbuild_global_string
  696. (handle,a_string.to_external, a_name.to_external))
  697. ensure
  698. Result/=Void
  699. end
  700. -- TODO: discover the difference between LLVMBuildGlobalString and LLVMBuildGlobalStringPtr from Liberty point of view.
  701. -- LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
  702. -- const char *Name);
  703. --
  704. feature {ANY} -- Casts
  705. trunc (a_value: LLVM_VALUE; a_destination_type: LLVM_INTEGER_TYPE; a_name: ABSTRACT_STRING): LLVM_TRUNC_INST
  706. -- A "trunc" instruction; `a_value' an integer type larger than
  707. -- `a_destination_type' will be truncated to the size of
  708. -- `a_destination_type'. Equal sized types are not allowed.
  709. -- The "trunc" instruction truncates the high order bits in value and
  710. -- converts the remaining bits to `a_destination_type'. Since the
  711. -- source size must be larger than the destination size, "trunc" cannot
  712. -- be a no-op cast. It will always truncate bits.
  713. require
  714. a_value/=Void
  715. value_is_integer: a_value.type.is_integer
  716. -- TODO: value_width_larger_than_destination: a_value.type
  717. a_destination_type/=Void
  718. a_name/=Void
  719. do
  720. create Result.from_external_pointer(llvmbuild_trunc(handle,a_value.handle,a_destination_type.handle,a_name.to_external))
  721. ensure
  722. Result/=Void
  723. Result.type ~ a_destination_type
  724. end
  725. zero_extend, zext (a_value: LLVM_VALUE; a_destination_type: LLVM_INTEGER_TYPE; a_name: ABSTRACT_STRING): LLVM_ZEXT_INST
  726. -- A "zext" instruction; it will fill the high order bits of `a_value' until it reaches the size of `a_destination_type'.
  727. -- When zero extending from an "i1", the result will always be either 0 or 1.
  728. require
  729. a_value/=Void
  730. a_destination_type/=Void
  731. a_name/=Void
  732. do
  733. create Result.from_external_pointer(llvmbuild_zext(handle,a_value.handle,a_destination_type.handle,a_name.to_external))
  734. ensure
  735. Result/=Void
  736. end
  737. sign_extend, sext (a_value: LLVM_VALUE; a_destination_type: LLVM_TYPE; a_label: ABSTRACT_STRING): LLVM_SEXT_INST
  738. -- A new "sext" instruction, that will sign extend `a_value' to until fits `a_destination_type'.
  739. -- `a_value' must be of an integer type; also `a_destination_type' shall be of integer type.
  740. -- The bit size of the value must be smaller than the bit size of the destination type, ty2.
  741. -- A "sext" instruction performs a sign extension by copying the sign
  742. -- bit (highest order bit) of the value until it reaches the bit size
  743. -- of the type ty2.
  744. -- When sign extending from i1, the extension always results in -1 or 0.
  745. require
  746. a_value/=Void
  747. a_destination_type/=Void
  748. a_label/=Void
  749. --TODO a_value is an integer
  750. -- TODO: a_destination_type shall be an integer type
  751. do
  752. create Result.from_external_pointer
  753. (llvmbuild_sext(handle,a_value.handle,a_destination_type.handle,a_label.to_external))
  754. ensure Result/=Void
  755. end
  756. floating_point_to_unsigned_integer, fptoui (a_value: LLVM_VALUE; a_type: LLVM_TYPE; a_label: ABSTRACT_STRING): LLVM_FPTOUI_INST
  757. -- A new "fptoui" instruction that converts the floating point `a_value' to its unsigned integer equivalent of `a_type'.
  758. -- `a_value' must be a scalar or vector floating point value, and `a_type' must be an integer type. If ty is a vector floating point type, ty2 must be a vector integer type with the same number of elements as ty
  759. -- The 'fptoui' instruction converts its floating point operand into the nearest (rounding towards zero) unsigned integer value. If the value cannot fit in ty2, the results are undefined.
  760. require
  761. a_value/=Void
  762. a_type/=Void
  763. a_label/=Void
  764. float_or_float_vector: a_value.type.is_floating_point or a_value.type.is_vector and then a_value.type.as_vector.element_type.is_floating_point
  765. when_vector_destination_is_vector: a_value.type.is_vector implies a_type.is_vector and then a_value.type.as_vector.size = a_type.as_vector.size
  766. do
  767. create Result.from_external_pointer(llvmbuild_fpto_ui(handle,a_value.handle,a_type.handle,a_label.to_external))
  768. ensure Result/=Void
  769. end
  770. -- LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef, LLVMValueRef Val,
  771. -- LLVMTypeRef DestTy, const char *Name);
  772. -- LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef, LLVMValueRef Val,
  773. -- LLVMTypeRef DestTy, const char *Name);
  774. -- LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef, LLVMValueRef Val,
  775. -- LLVMTypeRef DestTy, const char *Name);
  776. -- LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef, LLVMValueRef Val,
  777. -- LLVMTypeRef DestTy, const char *Name);
  778. -- LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef, LLVMValueRef Val,
  779. -- LLVMTypeRef DestTy, const char *Name);
  780. -- LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef, LLVMValueRef Val,
  781. -- LLVMTypeRef DestTy, const char *Name);
  782. -- LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef, LLVMValueRef Val,
  783. -- LLVMTypeRef DestTy, const char *Name);
  784. bit_cast (a_value: LLVM_VALUE; a_destination_type: LLVM_TYPE; a_name: ABSTRACT_STRING): LLVM_BITCAST_INST
  785. -- An instruction casting `a_value' into `a_destination_type'.
  786. require
  787. a_value/=Void
  788. a_destination_type/=Void
  789. a_name/=Void
  790. do
  791. create Result.from_external_pointer(llvmbuild_bit_cast(handle,a_value.handle,a_destination_type.handle,a_name.to_external))
  792. ensure Result/=Void
  793. end
  794. -- LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
  795. -- LLVMTypeRef DestTy, const char *Name);
  796. -- LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
  797. -- LLVMTypeRef DestTy, const char *Name);
  798. -- LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
  799. -- LLVMTypeRef DestTy, const char *Name);
  800. -- LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef, LLVMValueRef Val,
  801. -- LLVMTypeRef DestTy, const char *Name);
  802. -- LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef, LLVMValueRef Val,
  803. -- LLVMTypeRef DestTy, const char *Name);
  804. -- LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef, LLVMValueRef Val,
  805. -- LLVMTypeRef DestTy, const char *Name);
  806. --
  807. feature {ANY} -- Comparisons
  808. icmp (a_predicate: LLVMINT_PREDICATE_ENUM; a_left,a_right: LLVM_VALUE;a_name: ABSTRACT_STRING): LLVM_ICMP_INST
  809. -- An 'icmp' instruction that will return a boolean value or a vector of boolean values based on comparison of its two integer, integer vector, or pointer operands. `a_predicate' is the condition code indicating the kind of comparison to perform. In LLVM assembler it is not a value, but a keyword. The possible condition code are:
  810. -- 1. eq: equal
  811. -- 2. ne: not equal
  812. -- 3. ugt: unsigned greater than
  813. -- 4. uge: unsigned greater or equal
  814. -- 5. ult: unsigned less than
  815. -- 6. ule: unsigned less or equal
  816. -- 7. sgt: signed greater than
  817. -- 8. sge: signed greater or equal
  818. -- 9. slt: signed less than
  819. -- 10. sle: signed less or equal
  820. --The remaining two arguments must be integer or pointer or integer vector typed. They must also be identical types.
  821. --Semantics:
  822. --
  823. --The 'icmp' compares op1 and op2 according to the condition code given as cond. The comparison performed always yields either an i1 or vector of i1 result, as follows:
  824. --
  825. -- 1. eq: yields true if the operands are equal, false otherwise. No sign interpretation is necessary or performed.
  826. -- 2. ne: yields true if the operands are unequal, false otherwise. No sign interpretation is necessary or performed.
  827. -- 3. ugt: interprets the operands as unsigned values and yields true if op1 is greater than op2.
  828. -- 4. uge: interprets the operands as unsigned values and yields true if op1 is greater than or equal to op2.
  829. -- 5. ult: interprets the operands as unsigned values and yields true if op1 is less than op2.
  830. -- 6. ule: interprets the operands as unsigned values and yields true if op1 is less than or equal to op2.
  831. -- 7. sgt: interprets the operands as signed values and yields true if op1 is greater than op2.
  832. -- 8. sge: interprets the operands as signed values and yields true if op1 is greater than or equal to op2.
  833. -- 9. slt: interprets the operands as signed values and yields true if op1 is less than op2.
  834. -- 10. sle: interprets the operands as signed values and yields true if op1 is less than or equal to op2.
  835. --
  836. --If the operands are pointer typed, the pointer values are compared as if they were integers.
  837. --
  838. --If the operands are integer vectors, then they are compared element by element. The result is an i1 vector with the same number of elements as the values being compared. Otherwise, the result is an i1.
  839. --
  840. require
  841. a_left/=Void
  842. a_right=Void
  843. same_type: a_left.type ~ a_right.type
  844. same_size_vectors: a_left.is_constant_vector implies a_left.as_constant_vector.type.size = a_right.as_constant_vector.type.size
  845. do
  846. create Result.from_external_pointer(llvmbuild_icmp(handle,a_predicate.value,
  847. a_left.handle,a_right.handle,a_name.to_external))
  848. ensure
  849. Result/=Void
  850. -- TODO: result type is an i1 or a vector
  851. -- TODO: a_left.is_constant_vector implies the-result-of-the-instruction.is_constant_vector and then a_left.as_constant_vector.type.size = Result.as
  852. end
  853. fcmp (a_predicate: LLVMREAL_PREDICATE_ENUM; a_left, a_right: LLVM_VALUE; a_name: ABSTRACT_STRING): LLVM_FCMP_INST
  854. -- Floating point comparison.
  855. -- TODO: adapt main LLVM documentation
  856. require
  857. a_left/=Void
  858. a_right/=Void
  859. a_name/=Void
  860. same_type: a_left.type ~ a_right.type
  861. -- TODO: provide remaining preconditions
  862. do
  863. create Result.from_external_pointer
  864. (llvmbuild_fcmp(handle, a_predicate.value, a_left.handle, a_right.handle, a_name.to_external))
  865. ensure
  866. Result/=Void
  867. end
  868. feature {ANY} -- Miscellaneous instructions
  869. -- LLVMValueRef LLVMBuildPhi(LLVMBuilderRef, LLVMTypeRef Ty, const char *Name);
  870. call (a_function: LLVM_FUNCTION; some_arguments: COLLECTION[LLVM_VALUE]; a_name: ABSTRACT_STRING): LLVM_CALL_INST
  871. -- A "call" instruction that will invoke `a_function' with `some_arguments'
  872. -- TODO: adapt main LLVM doc
  873. require
  874. a_function/=Void
  875. some_arguments/=Void
  876. -- TODO: allow some_arguments=Void for argument-less functions.
  877. a_name/=Void
  878. do
  879. create Result.from_external_pointer
  880. (llvmbuild_call(handle, a_function.handle, collection_to_c_array(some_arguments).storage.to_external,some_arguments.count.to_natural_32,a_name.to_external))
  881. ensure
  882. Result/=Void
  883. end
  884. select_inst (an_if, a_then, an_else: LLVM_VALUE; a_name: ABSTRACT_STRING): LLVM_SELECT_INST
  885. -- A new 'select' instruction which choose one value based on a condition, without branching.
  886. -- The 'select' instruction requires an 'i1' value or a vector of 'i1' values indicating the condition, and two values of the same first class type. If the val1/val2 are vectors and the condition is a scalar, then entire vectors are selected, not individual elements.
  887. -- If the condition is an i1 and it evaluates to 1, the instruction returns the first value argument; otherwise, it returns the second value argument. If the condition is a vector of i2, then the value arguments must be vectors of the same size, and the selection is done element by element.
  888. require
  889. an_if /= Void
  890. a_then /= Void
  891. an_else /= Void
  892. a_name /= Void
  893. an_if_is_boolean: {LLVM_INTEGER_TYPE} ?:= an_if.type
  894. do
  895. create Result.from_external_pointer(llvmbuild_select(handle,an_if.handle,a_then.handle,an_else.handle,a_name.to_external))
  896. ensure
  897. Result/=Void
  898. end
  899. -- LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef, LLVMValueRef List, LLVMTypeRef Ty,
  900. -- const char *Name);
  901. feature {ANY} -- Instructions on vectors
  902. extract_element(a_vector: LLVM_VALUE; an_index: LLVM_VALUE; a_name: ABSTRACT_STRING): LLVM_EXTRACT_VALUE_INST
  903. -- An "extract_element" instruction that will extract the element of `a_vector' referred by `an_index'.
  904. -- TODO: C API requires an_index to be a LLVMValueRef; currently Liberty wrappers do not distinguish them.
  905. require
  906. a_vector/=Void
  907. an_index/=Void
  908. a_name/=Void
  909. do
  910. create Result.from_external_pointer(llvmbuild_extract_element
  911. (handle,a_vector.handle,an_index.handle, a_name.to_external))
  912. ensure Result/=Void
  913. end
  914. insert_element (a_vector: LLVM_VALUE; an_element: LLVM_VALUE; an_index: LLVM_VALUE; a_name: ABSTRACT_STRING): LLVM_INSERT_ELEMENT_INST
  915. -- An "insertelement" instruction that will insert `an_element' into
  916. -- `a_vector' at `an_index'. The result of this instruction will be a
  917. -- vector of the same type as `a_vector'; its element values will be
  918. -- those of `a_vector' except at position `an_index', where it gets
  919. -- `an_element'. If `an_index' exceeds the length of `a_vector', the
  920. -- results are undefined (TODO: perhaps this shall be changed into a
  921. -- precondition).
  922. require
  923. a_vector/=Void
  924. an_element/=Void
  925. an_index/=Void
  926. a_vector.type.is_vector
  927. an_element_fits_into_a_vector: a_vector.type.as_vector.element_type.is_equal(an_element.type)
  928. do
  929. create Result.from_external_pointer(llvmbuild_insert_element
  930. (handle, a_vector.handle, an_element.handle, an_index.handle, a_name.to_external))
  931. ensure Result/=Void
  932. end
  933. shuffle_vector (a_vector, another_vector: LLVM_VALUE; a_mask: LLVM_VALUE; a_name: ABSTRACT_STRING): LLVM_SHUFFLE_VECTOR_INST
  934. -- A "shufflevector" instruction that will construct a permutation of
  935. -- elements from `a_vector' and `another_vector', returning a vector
  936. -- with the same element type as the input and length that is the same
  937. -- as the shuffle mask.
  938. -- The third argument is a shuffle mask whose element type is always
  939. -- 'i32'. The result of the instruction is a vector whose length is the
  940. -- same as the shuffle mask and whose element type is the same as the
  941. -- element type of the first two operands.
  942. -- The shuffle mask operand is required to be a constant vector with
  943. -- either constant integer or undef values. (TODO: turn it into a precondition).
  944. -- The elements of the two input vectors are numbered from left to
  945. -- right across both of the vectors. The shuffle mask operand
  946. -- specifies, for each element of the result vector, which element of
  947. -- the two input vectors the result element gets. The element selector
  948. -- may be undef (meaning "don't care") and the second operand may be
  949. -- undef if performing a shuffle from only one vector.
  950. require
  951. a_vector/=Void
  952. another_vector/=Void
  953. a_mask/=Void
  954. a_name/=Void
  955. vectors_fits: a_vector.type ~ another_vector.type
  956. both_are_vectors: a_vector.type.is_vector and another_vector.type.is_vector
  957. same_element_type: a_vector.type.as_vector.element_type ~ another_vector.type.as_vector.element_type
  958. mask_is_a_vector_of_32bit_integers: a_mask.type.is_vector and then a_mask.type.as_vector.element_type.is_integer and then a_mask.type.as_vector.element_type.as_integer.width.to_integer_32 = 32
  959. do
  960. create Result.from_external_pointer(llvmbuild_shuffle_vector
  961. (handle, a_vector.handle,another_vector.handle, a_mask.handle, a_name.to_external))
  962. ensure Result/=Void
  963. end
  964. feature {ANY} -- Instructions on aggregates (structures or arrays)
  965. extract_value (an_aggregate: LLVM_VALUE; an_index: NATURAL_32; a_name: ABSTRACT_STRING): LLVM_EXTRACT_VALUE_INST
  966. -- An "extractvalue" instruction that will extract the value of a struct field or array element from `an_aggregate' value.
  967. require
  968. an_aggregate/=Void
  969. a_name/=Void
  970. an_aggregate.type.is_struct or an_aggregate.type.is_array
  971. do
  972. create Result.from_external_pointer(llvmbuild_extract_value
  973. (handle, an_aggregate.handle, an_index, a_name.to_external))
  974. ensure Result/=Void
  975. end
  976. insert_value (an_aggregate: LLVM_VALUE; an_element: LLVM_VALUE; an_index: NATURAL_32; a_name: ABSTRACT_STRING): LLVM_INSERT_VALUE_INST
  977. -- An "insertvalue" instruction that will insert `an_element' at
  978. -- `an_index' into a struct field or array element in `an_aggregate'.
  979. -- The first operand of an 'insertvalue' instruction is a value of struct or array type. The second operand is a first-class value to insert. The following operands are constant indices indicating the position at which to insert the value in a similar manner as indices in a 'getelementptr' instruction. The value to insert must have the same type as the value identified by the indices.
  980. -- The result is an aggregate of the same type as val. Its value is that of val except that the value at the position specified by the indices is that of elt.
  981. require
  982. an_aggregate/=Void
  983. an_element/=Void
  984. a_name/=Void
  985. an_aggregate.type.is_struct or an_aggregate.type.is_array
  986. an_element_fits_at_an_index: an_element.type.is_equal(an_aggregate.type.as_struct.element(an_index.to_integer_32))
  987. do
  988. create Result.from_external_pointer(llvmbuild_insert_value
  989. (handle,an_aggregate.handle,an_element.handle,an_index,a_name.to_external))
  990. ensure Result/=Void
  991. end
  992. -- LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef, LLVMValueRef Val,
  993. -- const char *Name);
  994. -- LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef, LLVMValueRef Val,
  995. -- const char *Name);
  996. -- LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef, LLVMValueRef LHS,
  997. -- LLVMValueRef RHS, const char *Name);
  998. --
  999. --
  1000. feature {}
  1001. struct_size: like size_t
  1002. do
  1003. not_yet_implemented
  1004. end
  1005. dispose
  1006. do
  1007. llvmdispose_builder(handle)
  1008. end
  1009. end -- class LLVM_BUILDER
  1010. -- Copyright (C) 2009-2017: ,2010,2013 Paolo Redaelli - 2013 Cyril Adrian
  1011. -- This file is part of LLVM wrappers for Liberty Eiffel.
  1012. --
  1013. -- This library is free software: you can redistribute it and/or modify
  1014. -- it under the terms of the GNU Lesser General Public License as published by
  1015. -- the Free Software Foundation, version 3 of the License.
  1016. --
  1017. -- Liberty Eiffel is distributed in the hope that it will be useful,
  1018. -- but WITHOUT ANY WARRANTY; without even the implied warranty of
  1019. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1020. -- GNU General Public License for more details.
  1021. --
  1022. -- You should have received a copy of the GNU General Public License
  1023. -- along with Liberty Eiffel. If not, see <http://www.gnu.org/licenses/>.
  1024. --