/vm/jit.hpp

http://github.com/abeaumont/factor · C++ Header · 78 lines · 60 code · 16 blank · 2 comment · 2 complexity · 68d889f79167684ef79da0afa2d25af8 MD5 · raw file

  1. namespace factor
  2. {
  3. struct jit {
  4. code_block_type type;
  5. data_root<object> owner;
  6. growable_byte_array code;
  7. growable_byte_array relocation;
  8. growable_array parameters;
  9. growable_array literals;
  10. bool computing_offset_p;
  11. fixnum position;
  12. cell offset;
  13. factor_vm *parent;
  14. explicit jit(code_block_type type, cell owner, factor_vm *parent);
  15. ~jit();
  16. void compute_position(cell offset);
  17. void emit_relocation(cell relocation_template);
  18. void emit(cell code_template);
  19. void parameter(cell parameter) { parameters.add(parameter); }
  20. void emit_with_parameter(cell code_template_, cell parameter_);
  21. void literal(cell literal) { literals.add(literal); }
  22. void emit_with_literal(cell code_template_, cell literal_);
  23. void push(cell literal)
  24. {
  25. emit_with_literal(parent->special_objects[JIT_PUSH_IMMEDIATE],literal);
  26. }
  27. void word_jump(cell word_)
  28. {
  29. data_root<word> word(word_,parent);
  30. #ifndef FACTOR_AMD64
  31. literal(tag_fixnum(xt_tail_pic_offset));
  32. #endif
  33. literal(word.value());
  34. emit(parent->special_objects[JIT_WORD_JUMP]);
  35. }
  36. void word_call(cell word)
  37. {
  38. emit_with_literal(parent->special_objects[JIT_WORD_CALL],word);
  39. }
  40. bool emit_subprimitive(cell word_, bool tail_call_p, bool stack_frame_p);
  41. fixnum get_position()
  42. {
  43. if(computing_offset_p)
  44. {
  45. /* If this is still on, emit() didn't clear it,
  46. so the offset was out of bounds */
  47. return -1;
  48. }
  49. else
  50. return position;
  51. }
  52. void set_position(fixnum position_)
  53. {
  54. if(computing_offset_p)
  55. position = position_;
  56. }
  57. code_block *to_code_block(cell frame_size);
  58. private:
  59. jit(const jit&);
  60. void operator=(const jit&);
  61. };
  62. }