intrinsics.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. MISC_INTRINSICS = {
  26. 'element_eq' : (
  27. lambda lhs, rhs:
  28. tree_ir.CreateNodeWithValueInstruction(
  29. tree_ir.BinaryInstruction(lhs, '==', rhs))),
  30. 'element_neq' : (
  31. lambda lhs, rhs:
  32. tree_ir.CreateNodeWithValueInstruction(
  33. tree_ir.BinaryInstruction(lhs, '!=', rhs)))
  34. }
  35. def register_intrinsics(target_jit):
  36. """Registers all intrinsics in the module with the given JIT."""
  37. for (key, value) in BINARY_INTRINSICS.items():
  38. target_jit.register_binary_intrinsic(key, value)
  39. for (key, value) in MISC_INTRINSICS.items():
  40. target_jit.register_intrinsic(key, value)