2014-04-16 11:03:39 +02:00
|
|
|
module Asm
|
|
|
|
|
|
|
|
class Node
|
|
|
|
end
|
|
|
|
|
|
|
|
class InstructionNode < Node
|
|
|
|
attr_accessor :opcode, :args
|
|
|
|
end
|
|
|
|
|
|
|
|
class ShiftNode < Node
|
|
|
|
attr_accessor :type, :value, :argument
|
|
|
|
end
|
|
|
|
|
|
|
|
class MathNode < Node
|
|
|
|
attr_accessor :left, :right, :op
|
|
|
|
alias_method :argument, :left
|
|
|
|
alias_method :argument=, :left=
|
|
|
|
end
|
|
|
|
|
2014-04-21 16:35:38 +02:00
|
|
|
class RegisterNode < Node
|
2014-04-16 11:03:39 +02:00
|
|
|
attr_accessor :name
|
2014-04-18 18:19:57 +02:00
|
|
|
def initialize name
|
|
|
|
@name = name
|
|
|
|
end
|
2014-04-16 11:03:39 +02:00
|
|
|
end
|
|
|
|
|
2014-04-20 22:48:04 +02:00
|
|
|
#maybe not used at all as code_gen::instruction raises if used.
|
|
|
|
# instead now using Arrays
|
2014-04-21 16:35:38 +02:00
|
|
|
class RegisterListNode < Node
|
2014-04-16 11:03:39 +02:00
|
|
|
attr_accessor :registers
|
2014-04-20 22:48:04 +02:00
|
|
|
def initialize regs
|
|
|
|
@registers = regs.collect{ |sym , reg| (sym == :reg) ? reg : "not a reg #{sym} , #{reg}" }
|
|
|
|
end
|
2014-04-16 11:03:39 +02:00
|
|
|
end
|
|
|
|
|
2014-04-21 16:35:38 +02:00
|
|
|
class NumLiteralNode < Node
|
2014-04-16 11:03:39 +02:00
|
|
|
attr_accessor :value
|
2014-04-18 18:19:57 +02:00
|
|
|
def initialize val
|
|
|
|
@value = val
|
|
|
|
end
|
2014-04-16 11:03:39 +02:00
|
|
|
end
|
|
|
|
|
2014-04-21 16:35:38 +02:00
|
|
|
class LabelRefNode < Node
|
2014-04-16 11:03:39 +02:00
|
|
|
attr_accessor :label, :label_object
|
2014-04-18 18:19:57 +02:00
|
|
|
def initialize label , object = nil
|
|
|
|
@label = label
|
|
|
|
@label_object = object
|
|
|
|
end
|
2014-04-16 11:03:39 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
class ParseError < StandardError
|
|
|
|
def initialize(message, s)
|
|
|
|
super(message)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|