renove Node class as it wasnt doing anything
This commit is contained in:
@ -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')
|
||||
|
Reference in New Issue
Block a user