diff --git a/lib/register/instructions/load_constant.rb b/lib/register/instructions/load_constant.rb index 10501ffd..4a40cae6 100644 --- a/lib/register/instructions/load_constant.rb +++ b/lib/register/instructions/load_constant.rb @@ -16,6 +16,9 @@ module Register "LoadConstant: #{register} <- #{constant_str}" end + def self.load source , constant , register + LoadConstant.new source , constant , register + end private def constant_str case @constant diff --git a/lib/register/instructions/operator_instruction.rb b/lib/register/instructions/operator_instruction.rb index 33f7b741..e1508bfb 100644 --- a/lib/register/instructions/operator_instruction.rb +++ b/lib/register/instructions/operator_instruction.rb @@ -13,6 +13,9 @@ module Register "OperatorInstruction: #{left} #{operator} #{right}" end + def self.op source , operator , left , right + OperatorInstruction.new source , operator , left , right + end end end diff --git a/lib/register/instructions/register_transfer.rb b/lib/register/instructions/register_transfer.rb index a26e0f33..6253fca4 100644 --- a/lib/register/instructions/register_transfer.rb +++ b/lib/register/instructions/register_transfer.rb @@ -29,5 +29,8 @@ module Register "RegisterTransfer: #{from} -> #{to}" end + def self.transfer source , from , to + RegisterTransfer.new source , from , to + end end end diff --git a/lib/soml/compiler.rb b/lib/soml/compiler.rb index 4e684308..f90aada7 100644 --- a/lib/soml/compiler.rb +++ b/lib/soml/compiler.rb @@ -119,6 +119,12 @@ module Soml return reg end + def copy reg , source + copied = use_reg reg.type + add_code Reister.transfer source , reg , copied + copied + end + # releasing a register (accuired by use_reg) makes it available for use again # thus avoiding possibly using too many registers def release_reg reg