some helper functions

for when i started the assembler div10
in the end i did the div10 in some, so no need
This commit is contained in:
Torsten Ruger 2015-11-13 20:47:08 +02:00
parent 4a8bb32039
commit 9ab3de234d
4 changed files with 15 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -29,5 +29,8 @@ module Register
"RegisterTransfer: #{from} -> #{to}"
end
def self.transfer source , from , to
RegisterTransfer.new source , from , to
end
end
end

View File

@ -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