better builder names and remove the funny make syntax

This commit is contained in:
Torsten Ruger 2014-04-21 00:07:33 +03:00
parent 2dffad61b8
commit 98a197a0ca
4 changed files with 26 additions and 42 deletions

View File

@ -1,8 +1,8 @@
require "asm/assembly_error" require "asm/assembly_error"
require "asm/arm/instruction_tools" require "asm/arm/instruction_tools"
require "asm/arm/builder_a" require "asm/arm/normal_builder"
require "asm/arm/builder_b" require "asm/arm/memory_access_builder"
require "asm/arm/builder_d" require "asm/arm/stack_builder"
module Asm module Asm
module Arm module Arm
@ -80,34 +80,34 @@ module Asm
s = @s ? 1 : 0 s = @s ? 1 : 0
case opcode case opcode
when :adc, :add, :and, :bic, :eor, :orr, :rsb, :rsc, :sbc, :sub when :adc, :add, :and, :bic, :eor, :orr, :rsb, :rsc, :sbc, :sub
a = BuilderA.make(OPC_DATA_PROCESSING, OPCODES[opcode], s) a = NormalBuilder.new(OPC_DATA_PROCESSING, OPCODES[opcode], s)
a.cond = COND_BITS[@cond] a.cond = COND_BITS[@cond]
a.rd = reg_ref(args[0]) a.rd = reg_ref(args[0])
a.rn = reg_ref(args[1]) a.rn = reg_ref(args[1])
a.build_operand args[2] a.build_operand args[2]
a.write io, as a.write io, as
when :cmn, :cmp, :teq, :tst when :cmn, :cmp, :teq, :tst
a = BuilderA.make(OPC_DATA_PROCESSING, OPCODES[opcode], 1) a = NormalBuilder.new(OPC_DATA_PROCESSING, OPCODES[opcode], 1)
a.cond = COND_BITS[@cond] a.cond = COND_BITS[@cond]
a.rn = reg_ref(args[0]) a.rn = reg_ref(args[0])
a.rd = 0 a.rd = 0
a.build_operand args[1] a.build_operand args[1]
a.write io, as a.write io, as
when :mov, :mvn when :mov, :mvn
a = BuilderA.make(OPC_DATA_PROCESSING, OPCODES[opcode], s) a = NormalBuilder.new(OPC_DATA_PROCESSING, OPCODES[opcode], s)
a.cond = COND_BITS[@cond] a.cond = COND_BITS[@cond]
a.rn = 0 a.rn = 0
a.rd = reg_ref(args[0]) a.rd = reg_ref(args[0])
a.build_operand args[1] a.build_operand args[1]
a.write io, as a.write io, as
when :strb, :str when :strb, :str
a = BuilderB.make(OPC_MEMORY_ACCESS, (opcode == :strb ? 1 : 0), 0) a = MemoryAccessBuilder.new(OPC_MEMORY_ACCESS, (opcode == :strb ? 1 : 0), 0)
a.cond = COND_BITS[@cond] a.cond = COND_BITS[@cond]
a.rd = reg_ref(args[1]) a.rd = reg_ref(args[1])
a.build_operand args[0] a.build_operand args[0]
a.write io, as, @ast_asm, self a.write io, as, @ast_asm, self
when :ldrb, :ldr when :ldrb, :ldr
a = BuilderB.make(OPC_MEMORY_ACCESS, (opcode == :ldrb ? 1 : 0), 1) a = MemoryAccessBuilder.new(OPC_MEMORY_ACCESS, (opcode == :ldrb ? 1 : 0), 1)
a.cond = COND_BITS[@cond] a.cond = COND_BITS[@cond]
a.rd = reg_ref(args[0]) a.rd = reg_ref(args[0])
a.build_operand args[1] a.build_operand args[1]
@ -116,13 +116,12 @@ module Asm
# downward growing, decrement before memory access # downward growing, decrement before memory access
# official ARM style stack as used by gas # official ARM style stack as used by gas
if (opcode == :push) if (opcode == :push)
a = BuilderD.make(1,0,1,0) a = StackBuilder.new(1,0,1,0)
else else
a = BuilderD.make(0,1,1,1) a = StackBuilder.new(0,1,1,1)
end end
a.cond = COND_BITS[@cond] a.cond = COND_BITS[@cond]
a.rn = 13 # sp a.rn = 13 # sp
puts "ARGS #{args.inspect}"
a.build_operand args a.build_operand args
a.write io, as a.write io, as
when :b, :bl when :b, :bl

View File

@ -4,10 +4,10 @@ module Asm
module Arm module Arm
# ADDRESSING MODE 2 # ADDRESSING MODE 2
# Implemented: immediate offset with offset=0 # Implemented: immediate offset with offset=0
class BuilderB class MemoryAccessBuilder
include Asm::Arm::InstructionTools include Asm::Arm::InstructionTools
def initialize def initialize(inst_class, byte_access, load_store)
@cond = 0b1110 @cond = 0b1110
@inst_class = 0 @inst_class = 0
@i = 0 #I flag (third bit) @i = 0 #I flag (third bit)
@ -19,18 +19,13 @@ module Asm
@rn = 0 @rn = 0
@rd = 0 @rd = 0
@operand = 0 @operand = 0
@inst_class = inst_class
@byte_access = byte_access
@load_store = load_store
end end
attr_accessor :cond, :inst_class, :i, :pre_post_index, :add_offset, attr_accessor :cond, :inst_class, :i, :pre_post_index, :add_offset,
:byte_access, :w, :load_store, :rn, :rd, :operand :byte_access, :w, :load_store, :rn, :rd, :operand
def self.make(inst_class, byte_access, load_store)
a = new
a.inst_class = inst_class
a.byte_access = byte_access
a.load_store = load_store
a
end
# Build representation for target address # Build representation for target address
def build_operand(arg) def build_operand(arg)
#str / ldr are _seruous instructions. With BIG possibilities no half are implemented #str / ldr are _seruous instructions. With BIG possibilities no half are implemented

View File

@ -2,10 +2,10 @@ module Asm
module Arm module Arm
# ADDRESSING MODE 1 # ADDRESSING MODE 1
# Complete! # Complete!
class BuilderA class NormalBuilder
include Asm::Arm::InstructionTools include Asm::Arm::InstructionTools
def initialize def initialize(inst_class, opcode, s)
@cond = 0b1110 @cond = 0b1110
@inst_class = 0 @inst_class = 0
@i = 0 @i = 0
@ -14,18 +14,13 @@ module Asm
@rn = 0 @rn = 0
@rd = 0 @rd = 0
@operand = 0 @operand = 0
@inst_class = inst_class
@opcode = opcode
@s = s
end end
attr_accessor :cond, :inst_class, :i, :opcode, :s, attr_accessor :cond, :inst_class, :i, :opcode, :s,
:rn, :rd, :operand :rn, :rd, :operand
def self.make(inst_class, opcode, s)
a = new
a.inst_class = inst_class
a.opcode = opcode
a.s = s
a
end
def calculate_u8_with_rr(arg) def calculate_u8_with_rr(arg)
parts = arg.value.to_s(2).rjust(32,'0').scan(/^(0*)(.+?)0*$/).flatten parts = arg.value.to_s(2).rjust(32,'0').scan(/^(0*)(.+?)0*$/).flatten
pre_zeros = parts[0].length pre_zeros = parts[0].length

View File

@ -1,10 +1,10 @@
module Asm module Asm
module Arm module Arm
# ADDRESSING MODE 4 # ADDRESSING MODE 4
class BuilderD class StackBuilder
include Asm::Arm::InstructionTools include Asm::Arm::InstructionTools
def initialize def initialize(pre_post, up_down, write, store_load)
@cond = 0b1110 @cond = 0b1110
@inst_class = Asm::Arm::Instruction::OPC_STACK @inst_class = Asm::Arm::Instruction::OPC_STACK
@pre_post_index = 0 @pre_post_index = 0
@ -14,19 +14,14 @@ module Asm
@store_load = 0 @store_load = 0
@rn = 0 @rn = 0
@operand = 0 @operand = 0
@pre_post_index = pre_post
@up_down = up_down
@write_base = write
@store_load = store_load
end end
attr_accessor :cond, :inst_class, :pre_post_index, :up_down, attr_accessor :cond, :inst_class, :pre_post_index, :up_down,
:s, :write_base, :store_load, :rn, :operand :s, :write_base, :store_load, :rn, :operand
def self.make(pre_post, up_down, write, store_load)
a = new
a.pre_post_index = pre_post
a.up_down = up_down
a.write_base = write
a.store_load = store_load
a
end
# Build representation for source value # Build representation for source value
def build_operand(arg) def build_operand(arg)
if (arg.is_a?(Array)) if (arg.is_a?(Array))