summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-02-06 01:03:55 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-02-06 01:03:55 +0000
commit4102b12e1f763e6aae6a9eaa421ac84aa355a76c ()
tree99d7ad30fbf8237d044bcd84161cdbc31123d6e3
parenta4a81019653287291f88563964d482798da6221f (diff)
* common.mk (*.inc): use VPATH.
* vm_opts.h: renamed from vm_opts.h.base. * tool/insns2vm.rb: use vm_opts.h in VPATH. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11636 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog8
-rw-r--r--tool/insns2vm.rb290
-rw-r--r--vm_opts.h.base47
3 files changed, 205 insertions, 140 deletions
@@ -1,3 +1,11 @@
Tue Feb 6 03:47:58 2007 Koichi Sasada <[email protected]>
* proc.c: support Binding#eval.
@@ -5,8 +5,71 @@
# $verbose = true
# $use_const = true
require 'pp'
require 'erb'
class InsnsDef
class InsnInfo
@@ -95,20 +158,51 @@ class InsnsDef
end
end
- def initialize file, optopfile, uniffile
@insns = []
@insn_map = {}
-
load_insns_def file
-
load_opt_operand_def optopfile
load_insn_unification_def uniffile
- make_stackcaching_insns if $opts['OPT_STACK_CACHING']
end
attr_reader :insns
attr_reader :insn_map
SKIP_COMMENT_PATTERN = Regexp.compile(Regexp.escape('/** ##skip'))
include Enumerable
@@ -169,12 +263,12 @@ class InsnsDef
:j => j,
}
end
-
def load_insns_def file
body = insn = opes = pops = rets = nil
comment = ''
-
- open(file){|f|
f.instance_variable_set(:@line_no, 0)
class << f
def line_no
@@ -231,6 +325,7 @@ class InsnsDef
when /^\}/
if insn_in
body.instance_variable_set(:@line_no, line_no)
insn = make_insn(insn, opes, pops, rets, comment, body, sp_inc)
insn_in = false
comment = ''
@@ -248,7 +343,7 @@ class InsnsDef
## opt op
def load_opt_operand_def file
- open(file){|f| f.each{|line|
line = line.gsub(/\#.*/, '').strip
next if line.length == 0
break if /__END__/ =~ line
@@ -256,7 +351,7 @@ class InsnsDef
insn = $1
opts = $2
add_opt_operand insn, opts.split(/,/).map{|e| e.strip}
- }}
end
def label_escape label
@@ -300,7 +395,7 @@ class InsnsDef
## insn unif
def load_insn_unification_def file
- open(file){|f| f.each{|line|
line = line.gsub(/\#.*/, '').strip
next if line.length == 0
break if /__END__/ =~ line
@@ -308,7 +403,7 @@ class InsnsDef
raise "unknown insn: #{e}" unless @insn_map[e]
@insn_map[e]
}
- }}
end
def all_combination sets
@@ -329,7 +424,7 @@ class InsnsDef
end
def make_unified_insns insns
- if $opts['OPT_UNIFY_ALL_COMBINATION']
insn_sets = insns.map{|insn|
[insn] + insn.optimized
}
@@ -633,7 +728,7 @@ class InsnsDef
vars.each{|e|
next if e[1] == '*'
- if $use_const
ret << " const #{e[0][0]} #{e[0][1]} = #{e[1]};"
else
ret << " #define #{e[0][1]} #{e[1]}"
@@ -643,7 +738,7 @@ class InsnsDef
end
def make_footer_default_operands insn
- if $use_const
"\n"
else
ret = []
@@ -720,23 +815,23 @@ class InsnsDef
def make_header insn
ret = "\nINSN_ENTRY(#{insn.name}){\n"
- ret += " /* prepare stack status */\n" if $verbose
ret += make_header_prepare_stack insn
ret += "{\n"
- ret += " /* declare stack push val */\n" if $verbose
ret += make_header_stack_val insn
- ret += " /* declare and initialize default opes */\n" if $verbose
ret += make_header_default_operands insn
- ret += " /* declare and get from iseq */\n" if $verbose
ret += make_header_operands insn
- ret += " /* declare and pop from stack */\n" if $verbose
ret += make_header_stack_pops insn
- ret += " /* declare temporary vars */\n" if $verbose
ret += make_header_temporary_vars insn
- ret += " /* for debug */\n" if $verbose
ret += " DEBUG_ENTER_INSN(\"#{insn.name}\");\n"
- ret += " /* management */\n" if $verbose
ret += " ADD_PC(1+#{@opn});\n"
ret += " PREFETCH(GET_PC());\n"
ret += " POPN(#{@popn});\n" if @popn > 0
@@ -756,7 +851,7 @@ class InsnsDef
def make_footer insn
ret = ''
- ret = " /* push stack val */\n" if $verbose
ret += make_footer_stack_val insn
# debug info
@@ -773,7 +868,8 @@ class InsnsDef
def make_insn_def insn
ret = make_header insn
if line = insn.body.instance_variable_get(:@line_no)
- ret << "#line #{line+1} \"#{$insns_def}\"" << "\n"
ret << insn.body
ret << '#line __CURRENT_LINE__ "vm.inc"' << "\n"
else
@@ -790,7 +886,7 @@ class InsnsDef
vm_body << "\n"
vm_body << make_insn_def(insn)
}
- src = File.read(File.join($srcdir, '/template/vm.inc.tmpl'))
ERB.new(src).result(binding)
end
@@ -809,7 +905,7 @@ class InsnsDef
insns_end_table << " ELABEL_PTR(#{insn.name}),\n"
}
- ERB.new(File.read($srcdir + '/template/vmtc.inc.tmpl')).result(binding)
end
@@ -903,7 +999,7 @@ class InsnsDef
}
EOS
}
- ERB.new(File.read($srcdir + '/template/insns_info.inc.tmpl')).result(binding)
end
@@ -916,7 +1012,7 @@ class InsnsDef
insns << " %-30s = %d,\n" % ["BIN(#{insn.name})", i]
i+=1
}
- ERB.new(File.read($srcdir + '/template/insns.inc.tmpl')).result(binding)
end
@@ -930,7 +1026,7 @@ class InsnsDef
["\"I#{insn.name}\"", i]
i+=1
}
- ERB.new(File.read($srcdir + '/template/minsns.inc.tmpl')).result(binding)
end
@@ -1005,7 +1101,7 @@ class InsnsDef
}
rule += " break;\n";
}
- ERB.new(File.read($srcdir + '/template/optinsn.inc.tmpl')).result(binding)
end
@@ -1043,7 +1139,7 @@ class InsnsDef
}
unif_insns_data = "static int **unified_insns_data[] = {\n" +
unif_insns_data.join(",\n") + "};\n"
- ERB.new(File.read($srcdir + '/template/optunifs.inc.tmpl')).result(binding)
end
###################################################################
@@ -1063,9 +1159,9 @@ class InsnsDef
sc_insn_next = @insns.map{|insn|
" SCS_#{complement_name(insn.nextsc).upcase}" +
- ($verbose ? " /* #{insn.name} */" : '')
}.join(",\n")
- ERB.new(File.read($srcdir + '/template/opt_sc.inc.tmpl')).result(binding)
end
###################################################################
@@ -1075,7 +1171,7 @@ class InsnsDef
@insns.each_with_index{|insn, i|
insn_id2no << " :#{insn.name} => #{i},\n"
}
- ERB.new(File.read($srcdir + '/template/yasmdata.rb.tmpl')).result(binding)
end
###################################################################
@@ -1106,18 +1202,18 @@ class InsnsDef
def desc_ja
d = desc :j
- ERB.new(File.read($srcdir + '/template/yarvarch.ja')).result(binding)
end
def desc_en
d = desc :e
- ERB.new(File.read($srcdir + '/template/yarvarch.en')).result(binding)
end
def vm_macro_inc
ret = ''
flag = false
- File.read($srcdir + '/vm_macro.def').each_line{|line|
line.rstrip!
if /^MACRO\s/ =~ line
line.sub!(/^MACRO/, '#define')
@@ -1144,77 +1240,85 @@ class InsnsDef
'vm_macro.inc' => :vm_macro_inc,
}
- def self.make_sources insns_def, opopt_def, unif_def, args = []
- insns = InsnsDef.new(insns_def, opopt_def, unif_def)
-
args = Files.keys if args.empty?
-
- args.each{|fn|
- s = Files[fn]
- open(fn, 'w'){|f|
- f.puts(insns.__send__(s))
- }
}
end
-end
-
-##############################################
-files = []
-$opts = {}
-$srcdir = '.'
-insns_def = 'insns.def'
-opope_def = 'opt_operand.def'
-unif_def = 'opt_insn_unif.def'
-
-ARGV.each{|e|
- case e
- when /\A\-D(\w+)/
- $opts[$1] = true
- when /\A--srcdir=(.+)/
- $srcdir = $1
- when /\A--insnsdef=(.+)/
- insns_def = $1
- when /\A--opt-operanddef=(.+)/
- opope_def = $1
- when /\A--opt-insnunifdef=(.+)/
- unif_def = $1
- when /\A-/
- # ignore
- else
- files << e
- end
-}
-optfile = File.join(Dir.pwd, 'vm_opts.h')
-basefile = File.join($srcdir, 'vm_opts.h.base')
-if !FileTest.exist?(optfile) || File.mtime(optfile) < File.mtime(basefile)
- require 'fileutils'
- FileUtils.cp(File.join($srcdir, 'vm_opts.h.base'), optfile)
-end
-if optfile
- open(optfile){|f|
- f.each_line{|line|
- if /^\#define\s+(OPT_[A-Z_]+)\s+1/ =~ line
- $opts[$1] = true
- end
}
- }
end
-$insns_def = File.join($srcdir, insns_def)
-$opope_def = File.join($srcdir, opope_def)
-$unif_def = File.join($srcdir, unif_def)
-def insns_def_new
- InsnsDef.new $insns_def, $opope_def, $unif_def
end
if $0 == __FILE__
- InsnsDef.make_sources $insns_def, $opope_def, $unif_def, files
end
@@ -1,47 +0,0 @@
-/*-*-c-*-*/
-/**********************************************************************
-
- vm_opts.h.base - VM optimize option
-
- $Author$
- $Date$
-
- Copyright (C) 2004-2006 Koichi Sasada
-
-**********************************************************************/
-
-
-#ifndef VM_OPTS_H_INCLUDED
-#define VM_OPTS_H_INCLUDED
-
-/* C compiler depend */
-#define OPT_DIRECT_THREADED_CODE 1
-#define OPT_CALL_THREADED_CODE 0
-
-/* architecture independent */
-
-/* VM running option */
-#define OPT_CHECKED_RUN 1
-
-/* at compile */
-#define OPT_INLINE_CONST_CACHE 1
-#define OPT_PEEPHOLE_OPTIMIZATION 1
-#define OPT_SPECIALISED_INSTRUCTION 1
-
-/* at runtime */
-#define OPT_INLINE_METHOD_CACHE 1
-#define OPT_BLOCKINLINING 0
-
-/* architecture independent, affects generated code */
-#define OPT_OPERANDS_UNIFICATION 0
-#define OPT_INSTRUCTIONS_UNIFICATION 0
-
-/* code generation parameter */
-#define OPT_UNIFY_ALL_COMBINATION 0
-#define OPT_STACK_CACHING 0
-
-/* misc */
-#define SUPPORT_JOKE 0
-
-#endif /* VM_OPTS_H_INCLUDED */
-