PageRenderTime 48ms CodeModel.GetById 38ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/vm/jit.hpp

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