Browse files

Fix opcode name inference.

  • Loading branch information...
1 parent e7ca9b6 commit dc9acecd3d0f56c7056f4b6cff15d3dfbb8d77cf @whitequark committed Mar 21, 2013
Showing with 8 additions and 7 deletions.
  1. +3 −7 lib/furnace/ssa.rb
  2. +5 −0 test/test_ssa.rb
View
10 lib/furnace/ssa.rb
@@ -1,13 +1,9 @@
module Furnace
module SSA
def self.class_name_to_opcode(klass)
- klass.to_s.split('::').last.gsub(/([a-z]|^)([A-Z])/) do
- if $1.empty?
- $2.downcase
- else
- "#{$1}_#{$2.downcase}"
- end
- end.gsub(/_insn$/, '')
+ klass.to_s.split('::').last.
+ gsub(/([A-Z])/) { '_' + $1.downcase }.
+ gsub(/^_(.+)_insn$/, '\1')
end
def self.opcode_to_class_name(opcode)
View
5 test/test_ssa.rb
@@ -36,6 +36,9 @@ def exits?
end
end
+ class IsBInsn < SSA::Instruction
+ end
+
module TestScope
include SSA
@@ -75,12 +78,14 @@ def insn_binary(left, right)
SSA.class_name_to_opcode(DupInsn).should == 'dup'
SSA.class_name_to_opcode(TupleConcatInsn).should == 'tuple_concat'
SSA.class_name_to_opcode(TestScope::NestedInsn).should == 'nested'
+ SSA.class_name_to_opcode(IsBInsn).should == 'is_b'
end
it 'converts opcodes to class names' do
SSA.opcode_to_class_name('foo').should == 'FooInsn'
SSA.opcode_to_class_name('foo_bar').should == 'FooBarInsn'
SSA.opcode_to_class_name(:foo_bar).should == 'FooBarInsn'
+ SSA.opcode_to_class_name(:is_b).should == 'IsBInsn'
end
describe SSA::Value do

0 comments on commit dc9acec

Please sign in to comment.