intrinsics.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import jit
  2. import tree_ir
  3. BINARY_INTRINSICS = {
  4. 'value_eq' : '==',
  5. 'value_neq' : '!=',
  6. 'bool_and' : 'and',
  7. 'bool_or' : 'or',
  8. 'integer_addition' : '+',
  9. 'integer_subtraction' : '-',
  10. 'integer_multiplication' : '*',
  11. 'integer_division' : '/',
  12. 'integer_gt' : '>',
  13. 'integer_gte' : '>=',
  14. 'integer_lt' : '<',
  15. 'integer_lte' : '<=',
  16. 'float_addition' : '+',
  17. 'float_subtraction' : '-',
  18. 'float_multiplication' : '*',
  19. 'float_division' : '/',
  20. 'float_gt' : '>',
  21. 'float_gte' : '>=',
  22. 'float_lt' : '<',
  23. 'float_lte' : '<='
  24. }
  25. UNARY_INTRINSICS = {
  26. 'bool_not' : 'not',
  27. 'integer_neg' : '-',
  28. 'float_neg' : '-'
  29. }
  30. MISC_INTRINSICS = {
  31. 'element_eq' : (
  32. lambda lhs, rhs:
  33. tree_ir.CreateNodeWithValueInstruction(
  34. tree_ir.BinaryInstruction(lhs, '==', rhs))),
  35. 'element_neq' : (
  36. lambda lhs, rhs:
  37. tree_ir.CreateNodeWithValueInstruction(
  38. tree_ir.BinaryInstruction(lhs, '!=', rhs)))
  39. }
  40. def register_intrinsics(target_jit):
  41. """Registers all intrinsics in the module with the given JIT."""
  42. for (key, value) in BINARY_INTRINSICS.items():
  43. target_jit.register_binary_intrinsic(key, value)
  44. for (key, value) in UNARY_INTRINSICS.items():
  45. target_jit.register_unary_intrinsic(key, value)
  46. for (key, value) in MISC_INTRINSICS.items():
  47. target_jit.register_intrinsic(key, value)