2 # Run this file to regenerate all files automatically created
3 # from instruction information.
5 # The parameters provided points to Ruby trunk defs files
8 # ruby yarvinsns.rb ~/src/ruby-trunk/insns.def ~/src/ruby-trunk/opt_insn_unif.def ~/src/ruby-trunk/opt_operand.def
17 open(insnsFile) do |f|
19 if !in_def && /^DEFINE_INSN$/ =~ l
22 if in_def && /^\{$/ =~ l
35 'ISEQ' => 'YARVMachine.InstructionSequence',
40 'CDHASH' => 'CDHASH???',
42 'GENTRY' => 'GENTRY???',
44 'VALUE' => 'IRubyObject',
49 attr_accessor :type, :name
50 def initialize(type, name='any')
51 @type, @name = $typeMappings[type], name
56 attr_accessor :name, :ops, :pops, :rets
62 def get_instruction(str)
64 sarr = str.split(/\n/)
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(/ +/)}
73 instructions << get_instruction(idef)
79 elsif /^int2fix\((.*)\)$/ =~ v
86 open(operandFile) do |f|
88 if /^#|__END__|^$/ =~ l.strip
93 rest = l[nm.length+1..-1].strip
94 i.name = nm + "_op_" + rest.split(/, /).map {|n| reformat(n.downcase) }.join('_')
104 if /^#|__END__|^$/ =~ l.strip
108 i.name = "unified_#{l.strip.split(/ +/).join('_')}"
116 INSTRUCTIONS = instructions
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))