From 139b0174d8758fe8200bf7fb5de05ad9e70b148b Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Fri, 24 Jul 2015 13:23:56 +0300 Subject: [PATCH] to_s for reg instructions --- lib/register/instructions/branch.rb | 4 ++-- lib/register/instructions/function_call.rb | 7 ++++++- lib/register/instructions/function_return.rb | 7 ++++++- lib/register/instructions/get_slot.rb | 5 +++++ lib/register/instructions/load_constant.rb | 5 +++++ lib/register/instructions/register_transfer.rb | 7 ++++++- lib/register/instructions/save_return.rb | 5 +++++ lib/register/instructions/set_slot.rb | 4 ++++ lib/register/instructions/syscall.rb | 5 +++++ lib/register/register_reference.rb | 3 +++ 10 files changed, 47 insertions(+), 5 deletions(-) diff --git a/lib/register/instructions/branch.rb b/lib/register/instructions/branch.rb index 26019681..61857e02 100644 --- a/lib/register/instructions/branch.rb +++ b/lib/register/instructions/branch.rb @@ -8,10 +8,10 @@ module Register raise "No block" unless to @block = to end - attr_reader :block + attr_reader :block def to_s - "Branch(to: #{block.name})" + "Branch(block: #{block.name})" end end diff --git a/lib/register/instructions/function_call.rb b/lib/register/instructions/function_call.rb index 0adca526..0b65aa20 100644 --- a/lib/register/instructions/function_call.rb +++ b/lib/register/instructions/function_call.rb @@ -8,5 +8,10 @@ module Register @method = method end attr_reader :method + + def to_s + "FunctionCall(#{method.name})" + end + end -end \ No newline at end of file +end diff --git a/lib/register/instructions/function_return.rb b/lib/register/instructions/function_return.rb index cc837ca6..2b5ec518 100644 --- a/lib/register/instructions/function_return.rb +++ b/lib/register/instructions/function_return.rb @@ -9,5 +9,10 @@ module Register @index = index end attr_reader :register , :index + + def to_s + "FunctionReturn(#{register}: #{index})" + end + end -end \ No newline at end of file +end diff --git a/lib/register/instructions/get_slot.rb b/lib/register/instructions/get_slot.rb index d8737e22..0c4c0cd4 100644 --- a/lib/register/instructions/get_slot.rb +++ b/lib/register/instructions/get_slot.rb @@ -27,6 +27,11 @@ module Register raise "Not register #{array}" unless Register::RegisterReference.look_like_reg(array) end attr_accessor :register , :array , :index + + def to_s + "GetSlot(#{register}: #{array}[#{index}])" + end + end # Produce a GetSlot instruction. diff --git a/lib/register/instructions/load_constant.rb b/lib/register/instructions/load_constant.rb index 29e66735..708b1ade 100644 --- a/lib/register/instructions/load_constant.rb +++ b/lib/register/instructions/load_constant.rb @@ -10,5 +10,10 @@ module Register @constant = constant end attr_accessor :register , :constant + + def to_s + "LoadConstant(#{register}: #{constant})" + end + end end diff --git a/lib/register/instructions/register_transfer.rb b/lib/register/instructions/register_transfer.rb index bc3c5d65..7b7362df 100644 --- a/lib/register/instructions/register_transfer.rb +++ b/lib/register/instructions/register_transfer.rb @@ -15,11 +15,16 @@ module Register # First argument from # second arguemnt to # - # Note: this may be reversed from some assembler notations (also arm) + # Note: this may be reversed from some assembler notations (also arm) def initialize from , to @from = wrap_register(from) @to = wrap_register(to) end attr_reader :from, :to + + def to_s + "RegisterTransfer(#{from} -> #{to})" + end + end end diff --git a/lib/register/instructions/save_return.rb b/lib/register/instructions/save_return.rb index 77a19911..a4faffa3 100644 --- a/lib/register/instructions/save_return.rb +++ b/lib/register/instructions/save_return.rb @@ -12,6 +12,11 @@ module Register @index = index end attr_reader :register , :index + + def to_s + "SaveReturn(#{register}[#{index}])" + end + end # Produce a SaveReturn instruction. diff --git a/lib/register/instructions/set_slot.rb b/lib/register/instructions/set_slot.rb index f00eac50..b0e04e0b 100644 --- a/lib/register/instructions/set_slot.rb +++ b/lib/register/instructions/set_slot.rb @@ -26,6 +26,10 @@ module Register raise "Not register #{array}" unless Register::RegisterReference.look_like_reg(array) end attr_accessor :register , :array , :index + def to_s + "SetSlot(#{register}: #{array}[#{index}])" + end + end # Produce a SetSlot instruction. diff --git a/lib/register/instructions/syscall.rb b/lib/register/instructions/syscall.rb index d967ae9c..1da3f038 100644 --- a/lib/register/instructions/syscall.rb +++ b/lib/register/instructions/syscall.rb @@ -13,5 +13,10 @@ module Register @name = name end attr_reader :name + + def to_s + "Syscall(#{name})" + end + end end diff --git a/lib/register/register_reference.rb b/lib/register/register_reference.rb index a4f3020f..c4c0a36c 100644 --- a/lib/register/register_reference.rb +++ b/lib/register/register_reference.rb @@ -17,6 +17,9 @@ module Register @symbol = r end + def to_s + symbol.to_s + end def self.convert something return something unless something.is_a? Symbol return something unless look_like_reg(something)