rubyx/lib/asm/nodes.rb

45 lines
1.1 KiB
Ruby
Raw Normal View History

2014-04-16 11:03:39 +02:00
module Asm
class Shift
2014-04-16 11:03:39 +02:00
attr_accessor :type, :value, :argument
end
# Registers have off course a name (r1-16 for arm)
# but also refer to an address. In other words they can be an operand for instructions.
# Arm has addressing modes abound, and so can add to a register before actually using it
# If can actually shift or indeed shift what it adds, but not implemented
class Register
attr_accessor :name , :offset , :bits
def initialize name , bits
@name = name
@bits = bits
@offset = 0
end
# this is for the dsl, so we can write pretty code like r1 + 4
# when we want to access the next word (4) after r1
def + number
@offset = number
self
end
2014-04-16 11:03:39 +02:00
end
2014-04-23 12:52:34 +02:00
# maybe not used at all as code_gen::instruction raises if used.
# instead now using Arrays
class RegisterList
2014-04-16 11:03:39 +02:00
attr_accessor :registers
def initialize regs
@registers = regs
regs.each{ |reg| raise "not a reg #{sym} , #{reg}" unless reg.is_a?(Asm::Register) }
end
2014-04-16 11:03:39 +02:00
end
class NumLiteral
2014-04-16 11:03:39 +02:00
attr_accessor :value
def initialize val
@value = val
end
2014-04-16 11:03:39 +02:00
end
end