Fix for JRUBY-2164. Add appropriate waitReadable and waitWritable to important places.
[jruby.git] / tool / yarvinsns.rb
blob84470dc9325cc0d177298aea0c3bcc7e47f7534d
2 # Run this file to regenerate all files automatically created
3 # from instruction information.
5 # The parameters provided points to Ruby trunk defs files
7 # ex: 
8 # ruby yarvinsns.rb ~/src/ruby-trunk/insns.def ~/src/ruby-trunk/opt_insn_unif.def ~/src/ruby-trunk/opt_operand.def
10 insnsFile = ARGV[0]
11 uniFile = ARGV[1]
12 operandFile = ARGV[2]
14 defs = []
15 in_def = false
16 cur_def = ""
17 open(insnsFile) do |f|
18   f.each_line do |l|
19     if !in_def && /^DEFINE_INSN$/ =~ l
20       in_def = true
21     else
22       if in_def && /^\{$/ =~ l
23         in_def = false
24         defs << cur_def
25         cur_def = ""
26       end
27       if in_def
28         cur_def << l
29       end
30     end
31   end
32 end
34 $typeMappings = {
35   'ISEQ' => 'YARVMachine.InstructionSequence',
36   'dindex_t' => 'long',
37   'lindex_t' => 'long',
38   'num_t' => 'long',
39   'OFFSET' => 'long',
40   'CDHASH' => 'CDHASH???',
41   'IC' => 'IC???',
42   'GENTRY' => 'GENTRY???',
43   'ID' => 'ID???',
44   'VALUE' => 'IRubyObject',
45   '...' => :any,
48 class Value
49   attr_accessor :type, :name
50   def initialize(type, name='any')
51     @type, @name = $typeMappings[type], name
52   end
53 end
55 class Instruction
56   attr_accessor :name, :ops, :pops, :rets
57 end
60 instructions = []
62 def get_instruction(str)
63   i = Instruction.new
64   sarr = str.split(/\n/)
65   i.name = sarr[0]
66   i.ops = sarr[1][/\(.*?\)/][1..-2].split(/,/).map {|v| Value.new *v.strip.split(/ +/)}
67   i.pops = sarr[2][/\(.*?\)/][1..-2].split(/,/).map {|v| Value.new *v.strip.split(/ +/)}
68   i.rets = sarr[3][/\(.*?\)/][1..-2].split(/,/).map {|v| Value.new *v.strip.split(/ +/)}
69   i
70 end
72 for idef in defs
73   instructions << get_instruction(idef)
74 end
76 def reformat(v)
77   if "*" == v
78     '_wc_'
79   elsif /^int2fix\((.*)\)$/ =~ v
80     "int2fix_0_#{$1}_c_"
81   else
82     v
83   end
84 end
86 open(operandFile) do |f|
87   f.each do |l|
88     if /^#|__END__|^$/ =~ l.strip
89       next
90     end
91     i = Instruction.new
92     nm = l[/^[^ ]+/]
93     rest = l[nm.length+1..-1].strip
94     i.name = nm + "_op_" + rest.split(/, /).map {|n| reformat(n.downcase) }.join('_')
95     i.ops = []
96     i.pops = []
97     i.rets = []
98     instructions << i
99   end
102 open(uniFile) do |f|
103   f.each do |l|
104     if /^#|__END__|^$/ =~ l.strip
105       next
106     end
107     i = Instruction.new
108     i.name = "unified_#{l.strip.split(/ +/).join('_')}"
109     i.ops = []
110     i.pops = []
111     i.rets = []
112     instructions << i
113   end
116 INSTRUCTIONS = instructions
118 b = binding
120 require 'erb'
122 Dir["**/*.template"].each do |file|
123   $stderr.puts "Processing #{file}"
124   f = ERB.new(File.read(file))
125   File.open(file[0..-10],"w") do |of|
126     of.write(f.result(b))
127   end