Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 3 commits
  • 9 files changed
  • 0 comments
  • 1 contributor
10 lib/furnace/ssa.rb
... ... @@ -1,13 +1,9 @@
1 1 module Furnace
2 2 module SSA
3 3 def self.class_name_to_opcode(klass)
4   - klass.to_s.split('::').last.gsub(/([a-z]|^)([A-Z])/) do
5   - if $1.empty?
6   - $2.downcase
7   - else
8   - "#{$1}_#{$2.downcase}"
9   - end
10   - end.gsub(/_insn$/, '')
  4 + klass.to_s.split('::').last.
  5 + gsub(/([A-Z])/) { '_' + $1.downcase }.
  6 + gsub(/^_(.+)_insn$/, '\1')
11 7 end
12 8
13 9 def self.opcode_to_class_name(opcode)
2  lib/furnace/ssa/basic_block.rb
@@ -154,7 +154,7 @@ def awesome_print(p=AwesomePrinter.new)
154 154 p.newline
155 155 end
156 156
157   - def inspect_as_value(p=AwesomePrinter.new)
  157 + def awesome_print_as_value(p=AwesomePrinter.new)
158 158 p.keyword('label').
159 159 name(name)
160 160 end
2  lib/furnace/ssa/constant.rb
@@ -30,7 +30,7 @@ def ==(other)
30 30 end
31 31 end
32 32
33   - def inspect_as_value(p=AwesomePrinter.new)
  33 + def awesome_print_as_value(p=AwesomePrinter.new)
34 34 type.awesome_print(p)
35 35 p.text @value.inspect
36 36 p
2  lib/furnace/ssa/event_stream.rb
@@ -67,7 +67,7 @@ def update_instruction(insn)
67 67 operands = dump_all(insn.operands)
68 68 end
69 69
70   - params = insn.pretty_parameters(printer).to_s
  70 + params = insn.awesome_print_parameters(printer).to_s
71 71
72 72 emit("update_instruction",
73 73 name: insn.name,
12 lib/furnace/ssa/instruction.rb
@@ -91,13 +91,13 @@ def awesome_print(p=AwesomePrinter.new)
91 91
92 92 p.keyword(opcode)
93 93
94   - pretty_parameters(p)
95   - pretty_operands(p)
  94 + awesome_print_parameters(p)
  95 + awesome_print_operands(p)
96 96
97 97 p
98 98 end
99 99
100   - def inspect_as_value(p=AwesomePrinter.new)
  100 + def awesome_print_as_value(p=AwesomePrinter.new)
101 101 if type == Type::Bottom.new
102 102 p.nest(type)
103 103 else
@@ -105,14 +105,14 @@ def inspect_as_value(p=AwesomePrinter.new)
105 105 end
106 106 end
107 107
108   - def pretty_parameters(p=AwesomePrinter.new)
  108 + def awesome_print_parameters(p=AwesomePrinter.new)
109 109 p
110 110 end
111 111
112   - def pretty_operands(p=AwesomePrinter.new)
  112 + def awesome_print_operands(p=AwesomePrinter.new)
113 113 if @operands
114 114 p.collection('', ', ', '', @operands) do |operand|
115   - operand.inspect_as_value(p)
  115 + operand.awesome_print_as_value(p)
116 116 end
117 117 else
118 118 p.text('<DETACHED>')
12 lib/furnace/ssa/instructions/phi.rb
@@ -29,13 +29,11 @@ def translate_operands(map)
29 29
30 30 protected
31 31
32   - def pretty_operands(p)
33   - @operands.each_with_index do |(basic_block, value), index|
34   - p.name basic_block.name
35   - p.text '=>'
36   - value.inspect_as_value p
37   -
38   - p.append ',' if index < @operands.count - 1
  32 + def awesome_print_operands(p)
  33 + p.collection('', ', ', '', @operands) do |basic_block, value|
  34 + p.name(basic_block.name).
  35 + text('=>')
  36 + value.awesome_print_as_value p
39 37 end
40 38 end
41 39
2  lib/furnace/ssa/named_value.rb
@@ -32,7 +32,7 @@ def detach
32 32 @function = nil
33 33 end
34 34
35   - def inspect_as_value(p=AwesomePrinter.new)
  35 + def awesome_print_as_value(p=AwesomePrinter.new)
36 36 p.name(@name)
37 37 end
38 38
4 lib/furnace/ssa/value.rb
@@ -52,10 +52,10 @@ def ==(other)
52 52 end
53 53
54 54 def awesome_print(p=AwesomePrinter.new)
55   - inspect_as_value(p)
  55 + awesome_print_as_value(p)
56 56 end
57 57
58   - def inspect_as_value(p=AwesomePrinter.new)
  58 + def awesome_print_as_value(p=AwesomePrinter.new)
59 59 p.text inspect
60 60 end
61 61 end
17 test/test_ssa.rb
@@ -36,6 +36,9 @@ def exits?
36 36 end
37 37 end
38 38
  39 + class IsBInsn < SSA::Instruction
  40 + end
  41 +
39 42 module TestScope
40 43 include SSA
41 44
@@ -75,12 +78,14 @@ def insn_binary(left, right)
75 78 SSA.class_name_to_opcode(DupInsn).should == 'dup'
76 79 SSA.class_name_to_opcode(TupleConcatInsn).should == 'tuple_concat'
77 80 SSA.class_name_to_opcode(TestScope::NestedInsn).should == 'nested'
  81 + SSA.class_name_to_opcode(IsBInsn).should == 'is_b'
78 82 end
79 83
80 84 it 'converts opcodes to class names' do
81 85 SSA.opcode_to_class_name('foo').should == 'FooInsn'
82 86 SSA.opcode_to_class_name('foo_bar').should == 'FooBarInsn'
83 87 SSA.opcode_to_class_name(:foo_bar).should == 'FooBarInsn'
  88 + SSA.opcode_to_class_name(:is_b).should == 'IsBInsn'
84 89 end
85 90
86 91 describe SSA::Value do
@@ -339,23 +344,23 @@ def insn_binary(left, right)
339 344 dup = DupInsn.new([SSA::Constant.new(Integer, 1)])
340 345 dup.basic_block = @basic_block
341 346 dup.awesome_print.should =~ /\^Integer %\d+ = dup \^Integer 1/
342   - dup.inspect_as_value.should =~ /^%\d+/
  347 + dup.awesome_print_as_value.should =~ /^%\d+/
343 348
344 349 concat = TupleConcatInsn.new(
345 350 [SSA::Constant.new(Array, [1]), SSA::Constant.new(Array, [2,3])])
346 351 concat.basic_block = @basic_block
347 352 concat.awesome_print.should =~ /\^Array %\d+ = tuple_concat \^Array \[1\], \^Array \[2, 3\]/
348   - concat.inspect_as_value.should =~ /^%\d+/
  353 + concat.awesome_print_as_value.should =~ /^%\d+/
349 354
350 355 zero_arity = BindingInsn.new
351 356 zero_arity.basic_block = @basic_block
352 357 zero_arity.awesome_print.should =~ /\^Binding %\d+ = binding/
353   - zero_arity.inspect_as_value.should =~ /^%\d+/
  358 + zero_arity.awesome_print_as_value.should =~ /^%\d+/
354 359
355 360 zero_all = TestScope::NestedInsn.new
356 361 zero_all.basic_block = @basic_block
357 362 zero_all.awesome_print.should == 'nested'
358   - zero_all.inspect_as_value.should == 'bottom'
  363 + zero_all.awesome_print_as_value.should == 'bottom'
359 364 end
360 365
361 366 describe SSA::GenericInstruction do
@@ -515,7 +520,7 @@ def i.exits?; true; end
515 520 end
516 521
517 522 it 'inspects as value' do
518   - @basic_block.inspect_as_value.should == 'label %1'
  523 + @basic_block.awesome_print_as_value.should == 'label %1'
519 524 end
520 525
521 526 it 'is constant' do
@@ -667,7 +672,7 @@ def i.exits?; true; end
667 672 SSA::Constant.new(SSA::Function, @function.name)
668 673
669 674 @function.name = 'foo'
670   - @function.to_value.inspect_as_value.should ==
  675 + @function.to_value.awesome_print_as_value.should ==
671 676 'function "foo"'
672 677 end
673 678

No commit comments for this range

Something went wrong with that request. Please try again.