aboutsummaryrefslogtreecommitdiffstats
path: root/tool/ruby_vm/models
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-29 06:47:05 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-29 06:47:05 +0000
commit9a8b38cacfa029aa9bbc5f1600b1ead3903a8c88 (patch)
treee7e453f3dc0f360a00e2bf406b4e76134f177433 /tool/ruby_vm/models
parent582951e2c8995d6bab5ddaf98cd3816310f8d506 (diff)
downloadruby-9a8b38cacfa029aa9bbc5f1600b1ead3903a8c88.tar.gz
extensive use of instruction attributes
Instead of using magic numbers, let us define a series of attributes and use them from the VM core. Proper function declarations makes these attributes inlined in most modern compilers. On my machine exact same binary is generated with or without this changeset. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62085 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'tool/ruby_vm/models')
-rw-r--r--tool/ruby_vm/models/bare_instructions.rb37
1 files changed, 16 insertions, 21 deletions
diff --git a/tool/ruby_vm/models/bare_instructions.rb b/tool/ruby_vm/models/bare_instructions.rb
index 246222b03c..f2690501fc 100644
--- a/tool/ruby_vm/models/bare_instructions.rb
+++ b/tool/ruby_vm/models/bare_instructions.rb
@@ -49,15 +49,8 @@ class RubyVM::BareInstructions
end
def call_attribute name
- return sprintf 'CALL_ATTRIBUTE(%s)', [
- name, @name, @opes.map {|i| i[:name] }
- ].flatten.compact.join(', ')
- end
-
- def sp_inc
- return @attrs.fetch "sp_inc" do |k|
- return generate_attribute k, 'rb_snum_t', rets.size - pops.size
- end
+ return sprintf 'attr_%s_%s(%s)', name, @name, \
+ @opes.map {|i| i[:name] }.compact.join(', ')
end
def has_attribute? k
@@ -65,10 +58,6 @@ class RubyVM::BareInstructions
end
def attributes
- # need to generate predefined attribute defaults
- sp_inc
- # other_attribute
- # ...
return @attrs.values
end
@@ -120,19 +109,25 @@ class RubyVM::BareInstructions
private
- def generate_attribute k, t, v
- attr = RubyVM::Attribute.new \
- insn: self, \
- name: k, \
- type: t, \
- location: [], \
+ def generate_attribute t, k, v
+ @attrs[k] ||= RubyVM::Attribute.new \
+ insn: self, \
+ name: k, \
+ type: t, \
+ location: [], \
expr: v.to_s + ';'
return @attrs[k] ||= attr
end
def predefine_attributes
- generate_attribute 'sp_inc', 'rb_snum_t', rets.size - pops.size
- generate_attribute 'handles_frame', 'bool', \
+ generate_attribute 'const char*', 'name', "insn_name(#{bin})"
+ generate_attribute 'enum ruby_vminsn_type', 'bin', bin
+ generate_attribute 'rb_num_t', 'open', opes.size
+ generate_attribute 'rb_num_t', 'popn', pops.size
+ generate_attribute 'rb_num_t', 'retn', rets.size
+ generate_attribute 'rb_num_t', 'width', width
+ generate_attribute 'rb_num_t', 'sp_inc', rets.size - pops.size
+ generate_attribute 'bool', 'handles_frame', \
opes.any? {|o| /CALL_INFO/ =~ o[:type] }
end