cast_off 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. data/README +578 -0
  2. data/README.en +256 -0
  3. data/bin/CastOff +145 -0
  4. data/cast_off.gemspec +25 -0
  5. data/ext/cast_off/cast_off.c.rb +1386 -0
  6. data/ext/cast_off/cast_off.h +24 -0
  7. data/ext/cast_off/depend +70 -0
  8. data/ext/cast_off/extconf.rb +19 -0
  9. data/ext/cast_off/generated_c_include/inline_api.h +507 -0
  10. data/ext/cast_off/generated_c_include/iter_api.h +595 -0
  11. data/ext/cast_off/generated_c_include/unbox_api.h.rb +76 -0
  12. data/ext/cast_off/generated_c_include/vm_api.h +751 -0
  13. data/ext/cast_off/ruby_source/atomic.h +56 -0
  14. data/ext/cast_off/ruby_source/constant.h +34 -0
  15. data/ext/cast_off/ruby_source/debug.h +41 -0
  16. data/ext/cast_off/ruby_source/eval_intern.h +234 -0
  17. data/ext/cast_off/ruby_source/gc.h +98 -0
  18. data/ext/cast_off/ruby_source/id.h +175 -0
  19. data/ext/cast_off/ruby_source/insns.inc +179 -0
  20. data/ext/cast_off/ruby_source/insns_info.inc +695 -0
  21. data/ext/cast_off/ruby_source/internal.h +227 -0
  22. data/ext/cast_off/ruby_source/iseq.h +125 -0
  23. data/ext/cast_off/ruby_source/manual_update.h +135 -0
  24. data/ext/cast_off/ruby_source/method.h +105 -0
  25. data/ext/cast_off/ruby_source/node.h +503 -0
  26. data/ext/cast_off/ruby_source/thread_pthread.h +51 -0
  27. data/ext/cast_off/ruby_source/thread_win32.h +40 -0
  28. data/ext/cast_off/ruby_source/vm_core.h +756 -0
  29. data/ext/cast_off/ruby_source/vm_exec.h +184 -0
  30. data/ext/cast_off/ruby_source/vm_insnhelper.c +1748 -0
  31. data/ext/cast_off/ruby_source/vm_insnhelper.h +220 -0
  32. data/ext/cast_off/ruby_source/vm_opts.h +51 -0
  33. data/lib/cast_off.rb +15 -0
  34. data/lib/cast_off/compile.rb +629 -0
  35. data/lib/cast_off/compile/basicblock.rb +144 -0
  36. data/lib/cast_off/compile/cfg.rb +391 -0
  37. data/lib/cast_off/compile/code_manager.rb +284 -0
  38. data/lib/cast_off/compile/configuration.rb +2368 -0
  39. data/lib/cast_off/compile/dependency.rb +240 -0
  40. data/lib/cast_off/compile/information.rb +775 -0
  41. data/lib/cast_off/compile/instruction.rb +446 -0
  42. data/lib/cast_off/compile/ir/call_ir.rb +2348 -0
  43. data/lib/cast_off/compile/ir/guard_ir.rb +423 -0
  44. data/lib/cast_off/compile/ir/jump_ir.rb +223 -0
  45. data/lib/cast_off/compile/ir/operand.rb +934 -0
  46. data/lib/cast_off/compile/ir/param_ir.rb +98 -0
  47. data/lib/cast_off/compile/ir/return_ir.rb +92 -0
  48. data/lib/cast_off/compile/ir/simple_ir.rb +808 -0
  49. data/lib/cast_off/compile/ir/sub_ir.rb +212 -0
  50. data/lib/cast_off/compile/iseq.rb +454 -0
  51. data/lib/cast_off/compile/method_information.rb +1384 -0
  52. data/lib/cast_off/compile/namespace/namespace.rb +556 -0
  53. data/lib/cast_off/compile/namespace/uuid.rb +323 -0
  54. data/lib/cast_off/compile/stack.rb +65 -0
  55. data/lib/cast_off/compile/translator.rb +1562 -0
  56. data/lib/cast_off/suggestion.rb +98 -0
  57. data/lib/cast_off/util.rb +58 -0
  58. metadata +107 -0
@@ -0,0 +1,98 @@
1
+ module CastOff
2
+ class Suggestion
3
+ include CastOff::Util
4
+
5
+ def initialize(iseq, io)
6
+ raise ArgumentError("invalid io object") unless io.respond_to?(:puts)
7
+ @suggestion = []
8
+ @handler = []
9
+ @iseq = iseq
10
+ @io = io
11
+ end
12
+
13
+ def dump_at_exit()
14
+ return if @handler.empty?
15
+ at_exit do
16
+ @handler.each{|h| h.call}
17
+ if @suggestion.size() > 0
18
+ @io.puts("<<<<<<<<<< Suggestion(#{target_name()}) >>>>>>>>>>")
19
+ @suggestion.each do |s|
20
+ @io.puts s
21
+ @io.puts
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ def add_handler(&b)
28
+ bug() unless b.is_a?(Proc)
29
+ @handler << b
30
+ end
31
+
32
+ def add_suggestion(msg, titles, contents, pretty = true)
33
+ suggestion = []
34
+ l_msg = msg.length
35
+ column_size = titles.size
36
+ contents = contents.inject([]) do |ary, c|
37
+ bug() unless c.size == column_size
38
+ c.map! do |v|
39
+ v.split("\n")
40
+ end
41
+ max = c.inject(0) do |m, v|
42
+ l = v.size
43
+ m > l ? m : l
44
+ end
45
+ max.times do |i|
46
+ ary << c.map{|v| v[i] || ''}
47
+ end
48
+ ary
49
+ end
50
+ l_titles = contents.inject(titles.map{|t| t.length}) do |a0, a1|
51
+ bug() unless a0.size == a1.size
52
+ a0.zip(a1).map do |(v0, v1)|
53
+ length = v1.length
54
+ v0 > length ? v0 : length
55
+ end
56
+ end
57
+ title = titles.zip(l_titles).map{|(t, l)| t.center(l)}.join(" | ")
58
+ l_title = title.length
59
+ width = l_msg > l_title ? l_msg : l_title
60
+ if width != l_title
61
+ bonus = width - l_title
62
+ adjust = column_size - bonus % column_size
63
+ width += adjust
64
+ bonus += adjust
65
+ bonus /= column_size
66
+ l_titles.map!{|l| l + bonus}
67
+ title = titles.zip(l_titles).map{|(t, l)| t.center(l)}.join(" | ")
68
+ end
69
+ sep = "-" * width
70
+ suggestion << " #{sep} "
71
+ suggestion << "|#{msg.center(width)}|"
72
+ suggestion << "|#{sep}|"
73
+ suggestion << "|#{title.center(width)}|"
74
+ suggestion << "|#{sep}|"
75
+ if pretty
76
+ side = "|"
77
+ else
78
+ side = ""
79
+ end
80
+ contents.each do |line|
81
+ suggestion << "#{side}#{line.zip(l_titles).map{|c, l| pretty ? c.center(l) : c }.join(" | ")}#{side}"
82
+ end
83
+ suggestion << " #{sep} "
84
+ @suggestion << suggestion.join("\n")
85
+ end
86
+
87
+ private
88
+
89
+ def target_name()
90
+ ary = @iseq.to_a()
91
+ name = ary[5]
92
+ filepath = ary[7] || '<no file>'
93
+ line = ary[8]
94
+ "#{name}: #{filepath} #{line}"
95
+ end
96
+ end
97
+ end
98
+
@@ -0,0 +1,58 @@
1
+ module CastOff::Util
2
+ private
3
+
4
+ @@debug_level = 0
5
+ @@verbose_mode = false
6
+
7
+ DEBUG_LEVEL_MAX = 2
8
+ def self.set_debug_level(lv)
9
+ raise(ArgumentError.new("debug level should be Integer")) unless lv.is_a?(Integer)
10
+ raise(ArgumentError.new("debug level should be >= 0 && <= #{DEBUG_LEVEL_MAX}")) unless 0 <= lv && lv <= DEBUG_LEVEL_MAX
11
+ @@debug_level = lv
12
+ end
13
+
14
+ def self.set_verbose_mode(b)
15
+ @@verbose_mode = b
16
+ end
17
+
18
+ def dlog(message, level = 1)
19
+ if level <= @@debug_level
20
+ STDERR.puts(message)
21
+ end
22
+ end
23
+ public(:dlog)
24
+
25
+ def vlog(message)
26
+ if @@verbose_mode || @@debug_level > 0
27
+ STDERR.puts(message)
28
+ end
29
+ end
30
+ public(:vlog)
31
+
32
+ def bt_and_bye()
33
+ STDERR.puts("-------------------- backtrace --------------------")
34
+ begin
35
+ raise
36
+ rescue => e
37
+ STDERR.puts(e.backtrace)
38
+ end
39
+ exit
40
+ end
41
+
42
+ def todo(message = nil)
43
+ STDERR.puts("<<< TODO #{message} :#{caller[0]} >>>")
44
+ bt_and_bye()
45
+ end
46
+
47
+ def bug(message = nil)
48
+ STDERR.puts("<<< BUG #{message} :#{caller[0]} >>>")
49
+ bt_and_bye()
50
+ end
51
+
52
+ =begin
53
+ def method_missing(name, *args, &block)
54
+ STDERR.puts("No Method #{name}:#{caller[0]}")
55
+ bt_and_bye()
56
+ end
57
+ =end
58
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cast_off
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Satoshi Shiba
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-07 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ! 'CastOff is performance improvement tool for Ruby1.9.3
15
+
16
+ '
17
+ email: shiba@rvm.jp
18
+ executables:
19
+ - CastOff
20
+ extensions:
21
+ - ext/cast_off/extconf.rb
22
+ extra_rdoc_files:
23
+ - README
24
+ - README.en
25
+ files:
26
+ - lib/cast_off.rb
27
+ - lib/cast_off/compile.rb
28
+ - lib/cast_off/compile/cfg.rb
29
+ - lib/cast_off/compile/translator.rb
30
+ - lib/cast_off/compile/namespace/namespace.rb
31
+ - lib/cast_off/compile/namespace/uuid.rb
32
+ - lib/cast_off/compile/ir/jump_ir.rb
33
+ - lib/cast_off/compile/ir/param_ir.rb
34
+ - lib/cast_off/compile/ir/guard_ir.rb
35
+ - lib/cast_off/compile/ir/return_ir.rb
36
+ - lib/cast_off/compile/ir/sub_ir.rb
37
+ - lib/cast_off/compile/ir/operand.rb
38
+ - lib/cast_off/compile/ir/call_ir.rb
39
+ - lib/cast_off/compile/ir/simple_ir.rb
40
+ - lib/cast_off/compile/instruction.rb
41
+ - lib/cast_off/compile/information.rb
42
+ - lib/cast_off/compile/dependency.rb
43
+ - lib/cast_off/compile/code_manager.rb
44
+ - lib/cast_off/compile/stack.rb
45
+ - lib/cast_off/compile/iseq.rb
46
+ - lib/cast_off/compile/configuration.rb
47
+ - lib/cast_off/compile/method_information.rb
48
+ - lib/cast_off/compile/basicblock.rb
49
+ - lib/cast_off/util.rb
50
+ - lib/cast_off/suggestion.rb
51
+ - ext/cast_off/extconf.rb
52
+ - ext/cast_off/cast_off.c.rb
53
+ - ext/cast_off/depend
54
+ - ext/cast_off/generated_c_include/vm_api.h
55
+ - ext/cast_off/generated_c_include/iter_api.h
56
+ - ext/cast_off/generated_c_include/unbox_api.h.rb
57
+ - ext/cast_off/generated_c_include/inline_api.h
58
+ - ext/cast_off/cast_off.h
59
+ - ext/cast_off/ruby_source/method.h
60
+ - ext/cast_off/ruby_source/atomic.h
61
+ - ext/cast_off/ruby_source/vm_insnhelper.h
62
+ - ext/cast_off/ruby_source/constant.h
63
+ - ext/cast_off/ruby_source/id.h
64
+ - ext/cast_off/ruby_source/iseq.h
65
+ - ext/cast_off/ruby_source/debug.h
66
+ - ext/cast_off/ruby_source/insns.inc
67
+ - ext/cast_off/ruby_source/node.h
68
+ - ext/cast_off/ruby_source/internal.h
69
+ - ext/cast_off/ruby_source/manual_update.h
70
+ - ext/cast_off/ruby_source/insns_info.inc
71
+ - ext/cast_off/ruby_source/gc.h
72
+ - ext/cast_off/ruby_source/thread_win32.h
73
+ - ext/cast_off/ruby_source/vm_exec.h
74
+ - ext/cast_off/ruby_source/thread_pthread.h
75
+ - ext/cast_off/ruby_source/vm_opts.h
76
+ - ext/cast_off/ruby_source/vm_insnhelper.c
77
+ - ext/cast_off/ruby_source/vm_core.h
78
+ - ext/cast_off/ruby_source/eval_intern.h
79
+ - cast_off.gemspec
80
+ - README
81
+ - README.en
82
+ - bin/CastOff
83
+ homepage: http://github.com/soba1104/CastOff
84
+ licenses: []
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>'
93
+ - !ruby/object:Gem::Version
94
+ version: 1.9.2
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 1.8.11
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: performance improvement tool for Ruby1.9.3
107
+ test_files: []