lib/furnace/ssa/instruction.rb in furnace-0.4.0.beta.1 vs lib/furnace/ssa/instruction.rb in furnace-0.4.0.beta.2

- old
+ new

@@ -6,87 +6,102 @@ def self.syntax(&block) SSA::InstructionSyntax.new(self).evaluate(&block) end - attr_accessor :basic_block + attr_reader :basic_block - def initialize(basic_block, operands=[], name=nil) - super(basic_block.function, operands, name) - @basic_block = basic_block + def opcode + self.class.opcode end - def initialize_copy(original) - super + def basic_block=(basic_block) + if @basic_block && @basic_block != basic_block + @basic_block.remove self + end - @operands = nil + if basic_block + self.function = basic_block.function + end + + @basic_block = basic_block + + SSA.instrument(self) end - def opcode - self.class.opcode + def detach + @basic_block = nil + + super end def remove - @basic_block.remove self - detach + @basic_block.remove self if @basic_block end + def erase + remove + drop_references + end + def replace_with(value) replace_all_uses_with value if value.is_a? SSA::Instruction @basic_block.replace self, value - detach + drop_references else - remove + erase end end + def replace_type_with(type, replacement) + end + def has_side_effects? false end def terminator? false end - def pretty_print(p=SSA::PrettyPrinter.new) - unless type == SSA.void - p.type type - p.name name - p.text '=' + def awesome_print(p=AwesomePrinter.new) + unless type == Type::Bottom.new + p.nest(type). + name(name). + text('=') end - if valid? - p.keyword opcode - else - p.keyword_invalid opcode - end + p.keyword(opcode) - pretty_parameters(p) - pretty_operands(p) + awesome_print_parameters(p) + awesome_print_operands(p) p end - def inspect_as_value(p=SSA::PrettyPrinter.new) - if type == SSA.void - p.type type + def awesome_print_as_value(p=AwesomePrinter.new) + if type == Type::Bottom.new + p.nest(type) else super end end - protected - - def pretty_parameters(p) + def awesome_print_parameters(p=AwesomePrinter.new) + p end - def pretty_operands(p) + def awesome_print_operands(p=AwesomePrinter.new) if @operands - p.values @operands + p.collection('', ', ', '', @operands) do |operand| + operand.awesome_print_as_value(p) + end else - p.text '<DETACHED>' + p.text('<DETACHED>') end end + + protected :function= end -end \ No newline at end of file +end