ytljit 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +29 -0
- data/Rakefile +22 -0
- data/ext/code_alloc.c +266 -0
- data/ext/extconf.rb +3 -0
- data/ext/ytljit.c +527 -0
- data/ext/ytljit.h +285 -0
- data/lib/ytljit/asm.rb +205 -0
- data/lib/ytljit/asmext.rb +199 -0
- data/lib/ytljit/asmext_x64.rb +212 -0
- data/lib/ytljit/asmext_x86.rb +128 -0
- data/lib/ytljit/asmutil.rb +182 -0
- data/lib/ytljit/codespace.rb +92 -0
- data/lib/ytljit/error.rb +7 -0
- data/lib/ytljit/instruction.rb +138 -0
- data/lib/ytljit/instruction_ia.rb +1298 -0
- data/lib/ytljit/instruction_x64.rb +41 -0
- data/lib/ytljit/instruction_x86.rb +11 -0
- data/lib/ytljit/marshal.rb +133 -0
- data/lib/ytljit/matcher.rb +235 -0
- data/lib/ytljit/rubyvm.rb +63 -0
- data/lib/ytljit/struct.rb +125 -0
- data/lib/ytljit/type.rb +112 -0
- data/lib/ytljit/util.rb +63 -0
- data/lib/ytljit/vm.rb +1649 -0
- data/lib/ytljit/vm_codegen.rb +491 -0
- data/lib/ytljit/vm_inline_method.rb +85 -0
- data/lib/ytljit/vm_inspect.rb +74 -0
- data/lib/ytljit/vm_sendnode.rb +561 -0
- data/lib/ytljit/vm_trans.rb +508 -0
- data/lib/ytljit/vm_type.rb +299 -0
- data/lib/ytljit/vm_type_gen.rb +158 -0
- data/lib/ytljit/vm_typeinf.rb +98 -0
- data/lib/ytljit.rb +46 -0
- data/test/asmsample.rb +117 -0
- data/test/cstest.rb +61 -0
- data/test/marshaltest.rb +27 -0
- data/test/test_assemble.rb +148 -0
- data/test/test_assemble2.rb +286 -0
- data/test/test_codespace.rb +102 -0
- data/test/test_typeinf.rb +21 -0
- data/test/tivmtest.rb +54 -0
- data/test/vmtest.rb +59 -0
- data/test/vmtest2.rb +41 -0
- data/test/vmtest3.rb +22 -0
- data/test/vmtest_compile_only.rb +41 -0
- data/test/vmtest_execute_only.rb +22 -0
- metadata +121 -0
data/test/vmtest.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# test program
|
2
|
+
require 'ytljit'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
include YTLJit
|
6
|
+
is = RubyVM::InstructionSequence.compile(
|
7
|
+
# "class Foo; def test(x);a = 0; x= 1;lambda {a = a + 1};p a;end;end","", "", 0,
|
8
|
+
# "b = 0;def test(x);a = 0;lambda {a = a + 1};p a;end;test(0)","", "", 0,
|
9
|
+
# "def test(x);a = x + 1;p a; p x;end;test(3)","", "", 0,
|
10
|
+
# "def test(x);if x then a = 1 else a = 3 end;p a end;test(3)","", "", 0,
|
11
|
+
# "def test(x);if x == 3 then a = 1 else a = 3 end;p a end;test(3)","", "", 0,
|
12
|
+
# "def fib(x);if x < 2 then 1 else fib(x + -1) + fib(x + -2) end;end;p fib(35)","", "", 0,
|
13
|
+
# "def ffib(x);if x < 2 then 1.0 else ffib(x + -1) + ffib(x + -2) end;end;p ffib(5)","", "", 0,
|
14
|
+
# "def foo; [1, 2, 3][0] + [1, 2, 3][1] end; p foo", "", "", 0,
|
15
|
+
# "def foo(x); if x then x = 1 else x = 2 end; x; end; p foo(1)", "", "", 0,
|
16
|
+
# "def foo(x); if x then x = 2.0 else x = 1 end; x; end; p foo(1)", "", "", 0,
|
17
|
+
"def foo(x); yield(x) + 2; end; p foo(1) {|a| a + 1}", "", "", 0,
|
18
|
+
# "def id(x); x; end; p id(1); p id(1.0)", "", "", 0,
|
19
|
+
# "1.1","", "", 0,
|
20
|
+
{ :peephole_optimization => true,
|
21
|
+
:inline_const_cache => false,
|
22
|
+
:specialized_instruction => false,}
|
23
|
+
).to_a
|
24
|
+
iseq = VMLib::InstSeqTree.new(nil, is)
|
25
|
+
pp iseq
|
26
|
+
|
27
|
+
tr = VM::YARVTranslatorSimple.new([iseq])
|
28
|
+
#tr.translate.compile(context)
|
29
|
+
tnode = tr.translate
|
30
|
+
# tnode.inspect_by_graph
|
31
|
+
context = VM::CollectInfoContext.new(tnode)
|
32
|
+
tnode.collect_info(context)
|
33
|
+
context = VM::TypeInferenceContext.new(tnode)
|
34
|
+
begin
|
35
|
+
pp "do type inference"
|
36
|
+
tnode.collect_candidate_type(context, [], [])
|
37
|
+
pp context.convergent
|
38
|
+
end until context.convergent
|
39
|
+
tnode.collect_candidate_type(context, [], [])
|
40
|
+
|
41
|
+
tnode = Marshal.load(Marshal.dump(tnode))
|
42
|
+
context = VM::CompileContext.new(tnode)
|
43
|
+
tnode.compile(context)
|
44
|
+
# context.code_space.disassemble
|
45
|
+
p tnode.code_space
|
46
|
+
# tnode.code_space.disassemble
|
47
|
+
=begin
|
48
|
+
asm = Assembler.new(tnode.code_space)
|
49
|
+
asm.with_retry do
|
50
|
+
end
|
51
|
+
tnode.code_space.disassemble
|
52
|
+
=end
|
53
|
+
tnode.code_space_tab.each do |cs|
|
54
|
+
cs.fill_disasm_cache
|
55
|
+
end
|
56
|
+
tnode.code_space.disassemble
|
57
|
+
|
58
|
+
tnode.code_space.call(tnode.code_space.base_address)
|
59
|
+
|
data/test/vmtest2.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# test program
|
2
|
+
require 'ytljit'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
include YTLJit
|
6
|
+
is = RubyVM::InstructionSequence.compile(
|
7
|
+
# "class Foo; def test(x);a = 0; x= 1;lambda {a = a + 1};p a;end;end","", "", 0,
|
8
|
+
# "b = 0;def test(x);a = 0;lambda {a = a + 1};p a;end;test(0)","", "", 0,
|
9
|
+
# "def test(x);a = x + 1;p a; p x;end;test(3)","", "", 0,
|
10
|
+
# "def test(x);if x then a = 1 else a = 3 end;p a end;test(3)","", "", 0,
|
11
|
+
# "def test(x);if x == 3 then a = 1 else a = 3 end;p a end;test(3)","", "", 0,
|
12
|
+
# "def fib(x);if x < 2 then 1 else fib(x + -1) + fib(x + -2) end;end;p fib(35)","", "", 0,
|
13
|
+
# "def ffib(x);if x < 2 then 1.0 else ffib(x + -1) + ffib(x + -2) end;end;p ffib(5)","", "", 0,
|
14
|
+
# "def foo; [1, 2, 3][0] + [1, 2, 3][1] end; p foo", "", "", 0,
|
15
|
+
# "def foo(x); if x then x = 1 else x = 2 end; x; end; p foo(1)", "", "", 0,
|
16
|
+
# "def foo(x); if x then x = 2.0 else x = 1 end; x; end; p foo(1)", "", "", 0,
|
17
|
+
"def foo(x); yield(x); end; p foo(1) {|a| a + 1}", "", "", 0,
|
18
|
+
# "1.1","", "", 0,
|
19
|
+
{ :peephole_optimization => true,
|
20
|
+
:inline_const_cache => false,
|
21
|
+
:specialized_instruction => false,}
|
22
|
+
).to_a
|
23
|
+
iseq = VMLib::InstSeqTree.new(nil, is)
|
24
|
+
pp iseq
|
25
|
+
|
26
|
+
tr = VM::YARVTranslatorSimple.new([iseq])
|
27
|
+
tnode = tr.translate
|
28
|
+
context = VM::CollectInfoContext.new(tnode)
|
29
|
+
tnode.collect_info(context)
|
30
|
+
context = VM::TypeInferenceContext.new(tnode)
|
31
|
+
tnode.collect_candidate_type(context, [], [])
|
32
|
+
tnode.collect_candidate_type(context, [], [])
|
33
|
+
|
34
|
+
context = VM::CompileContext.new(tnode)
|
35
|
+
tnode.compile(context)
|
36
|
+
p tnode.code_space
|
37
|
+
|
38
|
+
File.open("out.marshal", "w") do |fp|
|
39
|
+
fp.print Marshal.dump(tnode)
|
40
|
+
end
|
41
|
+
|
data/test/vmtest3.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# test program
|
2
|
+
require 'ytljit'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
include YTLJit
|
6
|
+
tnode = nil
|
7
|
+
|
8
|
+
File.open("out.marshal") do |fp|
|
9
|
+
tnode = Marshal.load(fp.read)
|
10
|
+
end
|
11
|
+
tnode.code_space_tab.each do |cs|
|
12
|
+
cs.update_refer
|
13
|
+
end
|
14
|
+
|
15
|
+
tnode.code_space_tab.each do |cs|
|
16
|
+
cs.fill_disasm_cache
|
17
|
+
end
|
18
|
+
tnode.code_space.disassemble
|
19
|
+
|
20
|
+
tnode.code_space.call(tnode.code_space.base_address)
|
21
|
+
|
22
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# test program
|
2
|
+
require 'ytljit'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
include YTLJit
|
6
|
+
is = RubyVM::InstructionSequence.compile(
|
7
|
+
# "class Foo; def test(x);a = 0; x= 1;lambda {a = a + 1};p a;end;end","", "", 0,
|
8
|
+
# "b = 0;def test(x);a = 0;lambda {a = a + 1};p a;end;test(0)","", "", 0,
|
9
|
+
# "def test(x);a = x + 1;p a; p x;end;test(3)","", "", 0,
|
10
|
+
# "def test(x);if x then a = 1 else a = 3 end;p a end;test(3)","", "", 0,
|
11
|
+
# "def test(x);if x == 3 then a = 1 else a = 3 end;p a end;test(3)","", "", 0,
|
12
|
+
"def fib(x);if x < 2 then 1 else fib(x + -1) + fib(x + -2) end;end;p fib(35)","", "", 0,
|
13
|
+
# "def ffib(x);if x < 2 then 1.0 else ffib(x + -1) + ffib(x + -2) end;end;p ffib(5)","", "", 0,
|
14
|
+
# "def foo; [1, 2, 3][0] + [1, 2, 3][1] end; p foo", "", "", 0,
|
15
|
+
# "def foo(x); if x then x = 1 else x = 2 end; x; end; p foo(1)", "", "", 0,
|
16
|
+
# "def foo(x); if x then x = 2.0 else x = 1 end; x; end; p foo(1)", "", "", 0,
|
17
|
+
# "def foo(x); yield(x); end; p foo(1) {|a| a + 1}", "", "", 0,
|
18
|
+
# "1.1","", "", 0,
|
19
|
+
{ :peephole_optimization => true,
|
20
|
+
:inline_const_cache => false,
|
21
|
+
:specialized_instruction => false,}
|
22
|
+
).to_a
|
23
|
+
iseq = VMLib::InstSeqTree.new(nil, is)
|
24
|
+
pp iseq
|
25
|
+
|
26
|
+
tr = VM::YARVTranslatorSimple.new([iseq])
|
27
|
+
tnode = tr.translate
|
28
|
+
context = VM::CollectInfoContext.new(tnode)
|
29
|
+
tnode.collect_info(context)
|
30
|
+
File.open("out.marshal", "w") do |fp|
|
31
|
+
fp.print Marshal.dump(tnode)
|
32
|
+
end
|
33
|
+
context = VM::TypeInferenceContext.new(tnode)
|
34
|
+
tnode.collect_candidate_type(context, [], [])
|
35
|
+
tnode.collect_candidate_type(context, [], [])
|
36
|
+
|
37
|
+
context = VM::CompileContext.new(tnode)
|
38
|
+
tnode.compile(context)
|
39
|
+
p tnode.code_space
|
40
|
+
|
41
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# test program
|
2
|
+
require 'ytljit'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
include YTLJit
|
6
|
+
tnode = nil
|
7
|
+
|
8
|
+
File.open("out.marshal") do |fp|
|
9
|
+
tnode = Marshal.load(fp.read)
|
10
|
+
end
|
11
|
+
tnode.code_space_tab.each do |cs|
|
12
|
+
cs.update_refer
|
13
|
+
end
|
14
|
+
|
15
|
+
tnode.code_space_tab.each do |cs|
|
16
|
+
cs.fill_disasm_cache
|
17
|
+
end
|
18
|
+
tnode.code_space.disassemble
|
19
|
+
|
20
|
+
tnode.code_space.call(tnode.code_space.base_address)
|
21
|
+
|
22
|
+
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ytljit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Hideki Miura
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-10-18 00:00:00 +09:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description:
|
22
|
+
email:
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions:
|
26
|
+
- ext/extconf.rb
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- lib/ytljit.rb
|
31
|
+
- lib/ytljit/asm.rb
|
32
|
+
- lib/ytljit/asmext.rb
|
33
|
+
- lib/ytljit/asmext_x64.rb
|
34
|
+
- lib/ytljit/asmext_x86.rb
|
35
|
+
- lib/ytljit/asmutil.rb
|
36
|
+
- lib/ytljit/codespace.rb
|
37
|
+
- lib/ytljit/error.rb
|
38
|
+
- lib/ytljit/instruction.rb
|
39
|
+
- lib/ytljit/instruction_ia.rb
|
40
|
+
- lib/ytljit/instruction_x64.rb
|
41
|
+
- lib/ytljit/instruction_x86.rb
|
42
|
+
- lib/ytljit/marshal.rb
|
43
|
+
- lib/ytljit/matcher.rb
|
44
|
+
- lib/ytljit/rubyvm.rb
|
45
|
+
- lib/ytljit/struct.rb
|
46
|
+
- lib/ytljit/type.rb
|
47
|
+
- lib/ytljit/util.rb
|
48
|
+
- lib/ytljit/vm.rb
|
49
|
+
- lib/ytljit/vm_codegen.rb
|
50
|
+
- lib/ytljit/vm_inline_method.rb
|
51
|
+
- lib/ytljit/vm_inspect.rb
|
52
|
+
- lib/ytljit/vm_sendnode.rb
|
53
|
+
- lib/ytljit/vm_trans.rb
|
54
|
+
- lib/ytljit/vm_type.rb
|
55
|
+
- lib/ytljit/vm_typeinf.rb
|
56
|
+
- lib/ytljit/vm_type_gen.rb
|
57
|
+
- ext/code_alloc.c
|
58
|
+
- ext/ytljit.c
|
59
|
+
- ext/ytljit.h
|
60
|
+
- ext/extconf.rb
|
61
|
+
- test/asmsample.rb
|
62
|
+
- test/cstest.rb
|
63
|
+
- test/marshaltest.rb
|
64
|
+
- test/test_assemble.rb
|
65
|
+
- test/test_assemble2.rb
|
66
|
+
- test/test_codespace.rb
|
67
|
+
- test/test_typeinf.rb
|
68
|
+
- test/tivmtest.rb
|
69
|
+
- test/vmtest.rb
|
70
|
+
- test/vmtest2.rb
|
71
|
+
- test/vmtest3.rb
|
72
|
+
- test/vmtest_compile_only.rb
|
73
|
+
- test/vmtest_execute_only.rb
|
74
|
+
- README
|
75
|
+
- Rakefile
|
76
|
+
has_rdoc: true
|
77
|
+
homepage:
|
78
|
+
licenses: []
|
79
|
+
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
version: "0"
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
version: "0"
|
101
|
+
requirements: []
|
102
|
+
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 1.3.7
|
105
|
+
signing_key:
|
106
|
+
specification_version: 3
|
107
|
+
summary: native code generator for ruby compiler
|
108
|
+
test_files:
|
109
|
+
- test/asmsample.rb
|
110
|
+
- test/cstest.rb
|
111
|
+
- test/marshaltest.rb
|
112
|
+
- test/test_assemble.rb
|
113
|
+
- test/test_assemble2.rb
|
114
|
+
- test/test_codespace.rb
|
115
|
+
- test/test_typeinf.rb
|
116
|
+
- test/tivmtest.rb
|
117
|
+
- test/vmtest.rb
|
118
|
+
- test/vmtest2.rb
|
119
|
+
- test/vmtest3.rb
|
120
|
+
- test/vmtest_compile_only.rb
|
121
|
+
- test/vmtest_execute_only.rb
|