renove Node class as it wasnt doing anything
This commit is contained in:
parent
8955cf31da
commit
1423b8a845
@ -17,24 +17,24 @@ module Asm
|
||||
rfp sl fp ip sp lr pc
|
||||
).each { |reg|
|
||||
define_method(reg) {
|
||||
Asm::RegisterNode.new(reg)
|
||||
Asm::Register.new(reg)
|
||||
}
|
||||
}
|
||||
|
||||
def instruction(name, *args)
|
||||
node = Asm::InstructionNode.new
|
||||
node = Asm::Instruction.new
|
||||
node.opcode = name.to_s
|
||||
node.args = []
|
||||
|
||||
args.each { |arg|
|
||||
if (arg.is_a?(Asm::RegisterNode))
|
||||
if (arg.is_a?(Asm::Register))
|
||||
node.args << arg
|
||||
elsif (arg.is_a?(Integer))
|
||||
node.args << Asm::NumLiteralNode.new(arg)
|
||||
node.args << Asm::NumLiteral.new(arg)
|
||||
elsif (arg.is_a?(String))
|
||||
node.args << add_string(arg)
|
||||
elsif (arg.is_a?(Symbol))
|
||||
node.args << Asm::LabelRefNode.new(arg.to_s)
|
||||
node.args << Asm::Label.new(arg.to_s)
|
||||
elsif (arg.is_a?(Asm::Arm::GeneratorLabel))
|
||||
node.args << arg
|
||||
else
|
||||
|
@ -97,15 +97,15 @@ module Asm
|
||||
builder.assemble io, as
|
||||
when :b, :bl
|
||||
arg = args[0]
|
||||
if (arg.is_a?(Asm::NumLiteralNode))
|
||||
if (arg.is_a?(Asm::NumLiteral))
|
||||
jmp_val = arg.value >> 2
|
||||
packed = [jmp_val].pack('l')
|
||||
# signed 32-bit, condense to 24-bit
|
||||
# TODO add check that the value fits into 24 bits
|
||||
io << packed[0,3]
|
||||
elsif (arg.is_a?(Asm::LabelObject) or arg.is_a?(Asm::LabelRefNode))
|
||||
elsif (arg.is_a?(Asm::LabelObject) or arg.is_a?(Asm::Label))
|
||||
#not yet tested/supported
|
||||
# arg = @ast_asm.object_for_label(arg.label, self) if arg.is_a?(Asm::LabelRefNode)
|
||||
# arg = @ast_asm.object_for_label(arg.label, self) if arg.is_a?(Asm::Label)
|
||||
# as.add_relocation(io.tell, arg, Asm::Arm::R_ARM_PC24, RelocHandler)
|
||||
#write 0 "for now" and let relocation happen
|
||||
io << "\x00\x00\x00"
|
||||
@ -115,7 +115,7 @@ module Asm
|
||||
io.write_uint8 OPCODES[opcode] | (COND_CODES[@cond] << 4)
|
||||
when :swi
|
||||
arg = args[0]
|
||||
if (arg.is_a?(Asm::NumLiteralNode))
|
||||
if (arg.is_a?(Asm::NumLiteral))
|
||||
packed = [arg.value].pack('L')[0,3]
|
||||
io << packed
|
||||
io.write_uint8 0b1111 | (COND_CODES[@cond] << 4)
|
||||
|
@ -36,7 +36,7 @@ module Asm
|
||||
OPC_STACK = 0b10
|
||||
|
||||
def reg_ref(arg)
|
||||
if (not arg.is_a?(Asm::RegisterNode))
|
||||
if (not arg.is_a?(Asm::Register))
|
||||
raise Asm::AssemblyError.new('argument must be a register', arg)
|
||||
end
|
||||
|
||||
|
@ -33,7 +33,7 @@ module Asm
|
||||
@pre_post_index = 0
|
||||
@w = 0
|
||||
@operand = 0
|
||||
if (arg.is_a?(Asm::RegisterNode))
|
||||
if (arg.is_a?(Asm::Register))
|
||||
@rn = reg_ref(arg)
|
||||
if(arg.offset != 0)
|
||||
@operand = arg.offset
|
||||
@ -48,7 +48,7 @@ module Asm
|
||||
raise Asm::AssemblyError.new('reference offset too large/small (max 4095)', argr.right)
|
||||
end
|
||||
end
|
||||
elsif (arg.is_a?(Asm::LabelRefNode) or arg.is_a?(Asm::NumLiteralNode))
|
||||
elsif (arg.is_a?(Asm::Label) or arg.is_a?(Asm::NumLiteral))
|
||||
@pre_post_index = 1
|
||||
@rn = 15 # pc
|
||||
@use_addrtable_reloc = true
|
||||
@ -72,10 +72,10 @@ module Asm
|
||||
# move towards simpler model
|
||||
if (@use_addrtable_reloc)
|
||||
# closest_addrtable = Asm::Arm.closest_addrtable(as)
|
||||
if (@addrtable_reloc_target.is_a?(Asm::LabelRefNode))
|
||||
if (@addrtable_reloc_target.is_a?(Asm::Label))
|
||||
obj = generator.object_for_label(@addrtable_reloc_target.label, inst)
|
||||
# ref_label = closest_addrtable.add_label(obj)
|
||||
elsif (@addrtable_reloc_target.is_a?(Asm::NumLiteralNode))
|
||||
elsif (@addrtable_reloc_target.is_a?(Asm::NumLiteral))
|
||||
# ref_label = closest_addrtable.add_const(@addrtable_reloc_target.value)
|
||||
end
|
||||
as.add_relocation io.tell, ref_label, Asm::Arm::R_ARM_PC12,
|
||||
|
@ -46,12 +46,12 @@ module Asm
|
||||
def build_operand(arg , position = 0)
|
||||
#position only needed for calculating relative addresses to data objects
|
||||
#there is a design stink here which makes my head ache. But shanti shanti
|
||||
if arg.is_a?(Asm::StringNode)
|
||||
if arg.is_a?(Asm::StringLiteral)
|
||||
# do pc relative addressing with the difference to the instuction
|
||||
# 8 is for the funny pipeline adjustment (ie oc pointing to fetch and not execute)
|
||||
arg = Asm::NumLiteralNode.new( arg.position - position - 8 )
|
||||
arg = Asm::NumLiteral.new( arg.position - position - 8 )
|
||||
end
|
||||
if (arg.is_a?(Asm::NumLiteralNode))
|
||||
if (arg.is_a?(Asm::NumLiteral))
|
||||
if (arg.value.fits_u8?)
|
||||
# no shifting needed
|
||||
@operand = arg.value
|
||||
@ -62,10 +62,10 @@ module Asm
|
||||
else
|
||||
raise Asm::AssemblyError.new(Asm::ERRSTR_NUMERIC_TOO_LARGE, arg)
|
||||
end
|
||||
elsif (arg.is_a?(Asm::RegisterNode))
|
||||
elsif (arg.is_a?(Asm::Register))
|
||||
@operand = reg_ref(arg)
|
||||
@i = 0
|
||||
elsif (arg.is_a?(Asm::ShiftNode))
|
||||
elsif (arg.is_a?(Asm::Shift))
|
||||
rm_ref = reg_ref(arg.argument)
|
||||
@i = 0
|
||||
shift_op = {'lsl' => 0b000, 'lsr' => 0b010, 'asr' => 0b100,
|
||||
@ -76,12 +76,12 @@ module Asm
|
||||
end
|
||||
|
||||
arg1 = arg.value
|
||||
if (arg1.is_a?(Asm::NumLiteralNode))
|
||||
if (arg1.is_a?(Asm::NumLiteral))
|
||||
if (arg1.value >= 32)
|
||||
raise Asm::AssemblyError.new('cannot shift by more than 31', arg1)
|
||||
end
|
||||
shift_imm = arg1.value
|
||||
elsif (arg1.is_a?(Asm::RegisterNode))
|
||||
elsif (arg1.is_a?(Asm::Register))
|
||||
shift_op |= 0x1;
|
||||
shift_imm = reg_ref(arg1) << 1
|
||||
elsif (arg.type == 'rrx')
|
||||
|
@ -16,7 +16,7 @@ module Asm
|
||||
def add_string str
|
||||
value = @string_table[str]
|
||||
return value if value
|
||||
data = Asm::StringNode.new(str)
|
||||
data = Asm::StringLiteral.new(str)
|
||||
@string_table[str] = data
|
||||
end
|
||||
|
||||
|
@ -1,13 +1,10 @@
|
||||
module Asm
|
||||
|
||||
class Node
|
||||
end
|
||||
|
||||
class InstructionNode < Node
|
||||
class Instruction
|
||||
attr_accessor :opcode, :args
|
||||
end
|
||||
|
||||
class ShiftNode < Node
|
||||
class Shift
|
||||
attr_accessor :type, :value, :argument
|
||||
end
|
||||
|
||||
@ -15,7 +12,7 @@ module Asm
|
||||
# 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 RegisterNode < Node
|
||||
class Register
|
||||
attr_accessor :name , :offset
|
||||
def initialize name
|
||||
@name = name
|
||||
@ -32,22 +29,22 @@ module Asm
|
||||
|
||||
#maybe not used at all as code_gen::instruction raises if used.
|
||||
# instead now using Arrays
|
||||
class RegisterListNode < Node
|
||||
class RegisterList
|
||||
attr_accessor :registers
|
||||
def initialize regs
|
||||
@registers = regs
|
||||
regs.each{ |reg| raise "not a reg #{sym} , #{reg}" unless reg.is_a?(Asm::RegisterNode) }
|
||||
regs.each{ |reg| raise "not a reg #{sym} , #{reg}" unless reg.is_a?(Asm::Register) }
|
||||
end
|
||||
end
|
||||
|
||||
class NumLiteralNode < Node
|
||||
class NumLiteral
|
||||
attr_accessor :value
|
||||
def initialize val
|
||||
@value = val
|
||||
end
|
||||
end
|
||||
|
||||
class LabelRefNode < Node
|
||||
class Label
|
||||
attr_accessor :label, :label_object
|
||||
def initialize label , object = nil
|
||||
@label = label
|
||||
|
@ -1,5 +1,5 @@
|
||||
module Asm
|
||||
class StringNode
|
||||
class StringLiteral
|
||||
def initialize(str)
|
||||
#align
|
||||
length = str.length
|
Loading…
Reference in New Issue
Block a user