removed arm subdirectory
This commit is contained in:
parent
1423b8a845
commit
ceefa05b2f
@ -1,14 +1,13 @@
|
||||
require 'asm/assembler'
|
||||
require 'asm/arm/arm_assembler'
|
||||
require 'asm/arm/instruction'
|
||||
require 'asm/arm/generator_label'
|
||||
require 'asm/arm_assembler'
|
||||
require 'asm/instruction'
|
||||
require 'asm/generator_label'
|
||||
require 'asm/nodes'
|
||||
require 'stream_reader'
|
||||
require 'stringio'
|
||||
require "asm/string_node"
|
||||
require "asm/string_literal"
|
||||
|
||||
module Asm
|
||||
module Arm
|
||||
|
||||
class ArmAssembler < Asm::Assembler
|
||||
|
||||
@ -22,27 +21,26 @@ module Asm
|
||||
}
|
||||
|
||||
def instruction(name, *args)
|
||||
node = Asm::Instruction.new
|
||||
node.opcode = name.to_s
|
||||
node.args = []
|
||||
opcode = name.to_s
|
||||
arg_nodes = []
|
||||
|
||||
args.each { |arg|
|
||||
if (arg.is_a?(Asm::Register))
|
||||
node.args << arg
|
||||
arg_nodes << arg
|
||||
elsif (arg.is_a?(Integer))
|
||||
node.args << Asm::NumLiteral.new(arg)
|
||||
arg_nodes << Asm::NumLiteral.new(arg)
|
||||
elsif (arg.is_a?(String))
|
||||
node.args << add_string(arg)
|
||||
arg_nodes << add_string(arg)
|
||||
elsif (arg.is_a?(Symbol))
|
||||
node.args << Asm::Label.new(arg.to_s)
|
||||
elsif (arg.is_a?(Asm::Arm::GeneratorLabel))
|
||||
node.args << arg
|
||||
arg_nodes << Asm::Label.new(arg.to_s)
|
||||
elsif (arg.is_a?(Asm::GeneratorLabel))
|
||||
arg_nodes << arg
|
||||
else
|
||||
raise 'Invalid argument `%s\' for instruction' % arg.inspect
|
||||
end
|
||||
}
|
||||
|
||||
add_value Asm::Arm::Instruction.new(node)
|
||||
add_value Asm::Instruction.new(opcode , arg_nodes)
|
||||
end
|
||||
|
||||
%w(adc add and bic eor orr rsb rsc sbc sub mov mvn cmn cmp teq tst b bl bx
|
||||
@ -119,6 +117,5 @@ module Asm
|
||||
raise 'unknown relocation type'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -32,7 +32,7 @@ module Asm
|
||||
end
|
||||
|
||||
def label
|
||||
label = Asm::Arm::GeneratorLabel.new(self)
|
||||
label = Asm::GeneratorLabel.new(self)
|
||||
@labels << label
|
||||
label
|
||||
end
|
||||
|
@ -1,6 +1,6 @@
|
||||
require "asm/label_object"
|
||||
|
||||
class Asm::Arm::GeneratorLabel < Asm::LabelObject
|
||||
class Asm::GeneratorLabel < Asm::LabelObject
|
||||
def initialize(asm)
|
||||
@asm = asm
|
||||
end
|
@ -1,20 +1,16 @@
|
||||
require "asm/assembly_error"
|
||||
require "asm/arm/instruction_tools"
|
||||
require "asm/arm/normal_builder"
|
||||
require "asm/arm/memory_access_builder"
|
||||
require "asm/arm/stack_builder"
|
||||
require "asm/instruction_tools"
|
||||
require "asm/normal_builder"
|
||||
require "asm/memory_access_builder"
|
||||
require "asm/stack_builder"
|
||||
|
||||
module Asm
|
||||
module Arm
|
||||
|
||||
class Instruction
|
||||
include InstructionTools
|
||||
|
||||
COND_POSTFIXES = Regexp.union(%w(eq ne cs cc mi pl vs vc hi ls ge lt gt le al)).source
|
||||
def initialize(node)
|
||||
@node = node
|
||||
opcode = node.opcode
|
||||
args = node.args
|
||||
def initialize(opcode , args)
|
||||
|
||||
opcode = opcode.downcase
|
||||
@cond = :al
|
||||
@ -106,7 +102,7 @@ module Asm
|
||||
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::Label)
|
||||
# as.add_relocation(io.tell, arg, Asm::Arm::R_ARM_PC24, RelocHandler)
|
||||
# as.add_relocation(io.tell, arg, Asm::R_ARM_PC24, RelocHandler)
|
||||
#write 0 "for now" and let relocation happen
|
||||
io << "\x00\x00\x00"
|
||||
else
|
||||
@ -123,9 +119,8 @@ module Asm
|
||||
raise Asm::AssemblyError.new(Asm::ERRSTR_INVALID_ARG, arg)
|
||||
end
|
||||
else
|
||||
raise Asm::AssemblyError.new("unknown instruction #{opcode}", @node)
|
||||
raise Asm::AssemblyError.new("unknown instruction #{opcode}", self)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,5 +1,5 @@
|
||||
module Asm
|
||||
module Arm
|
||||
|
||||
module InstructionTools
|
||||
OPCODES = {
|
||||
:adc => 0b0101, :add => 0b0100,
|
||||
@ -55,5 +55,4 @@ module Asm
|
||||
ref
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,11 +1,10 @@
|
||||
require "asm/nodes"
|
||||
|
||||
module Asm
|
||||
module Arm
|
||||
# ADDRESSING MODE 2
|
||||
# Implemented: immediate offset with offset=0
|
||||
class MemoryAccessBuilder
|
||||
include Asm::Arm::InstructionTools
|
||||
include Asm::InstructionTools
|
||||
|
||||
def initialize(inst_class, byte_access, load_store)
|
||||
@cond = 0b1110
|
||||
@ -78,11 +77,10 @@ module Asm
|
||||
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,
|
||||
Asm::Arm::Instruction::RelocHandler
|
||||
as.add_relocation io.tell, ref_label, Asm::R_ARM_PC12,
|
||||
Asm::Instruction::RelocHandler
|
||||
end
|
||||
io.write_uint32 val
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,9 +1,5 @@
|
||||
module Asm
|
||||
|
||||
class Instruction
|
||||
attr_accessor :opcode, :args
|
||||
end
|
||||
|
||||
class Shift
|
||||
attr_accessor :type, :value, :argument
|
||||
end
|
||||
|
@ -1,9 +1,8 @@
|
||||
module Asm
|
||||
module Arm
|
||||
# ADDRESSING MODE 1
|
||||
# Complete!
|
||||
class NormalBuilder
|
||||
include Asm::Arm::InstructionTools
|
||||
include Asm::InstructionTools
|
||||
|
||||
def initialize(inst_class, opcode, s)
|
||||
@cond = 0b1110
|
||||
@ -102,6 +101,4 @@ module Asm
|
||||
io.write_uint32 val
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
@ -1,12 +1,11 @@
|
||||
module Asm
|
||||
module Arm
|
||||
# ADDRESSING MODE 4
|
||||
class StackBuilder
|
||||
include Asm::Arm::InstructionTools
|
||||
include Asm::InstructionTools
|
||||
|
||||
def initialize(pre_post, up_down, write, store_load)
|
||||
@cond = 0b1110
|
||||
@inst_class = Asm::Arm::Instruction::OPC_STACK
|
||||
@inst_class = Asm::Instruction::OPC_STACK
|
||||
@pre_post_index = 0
|
||||
@up_down = 0
|
||||
@s = 0
|
||||
@ -43,5 +42,4 @@ module Asm
|
||||
io.write_uint32 val
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -30,4 +30,4 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'test'))
|
||||
|
||||
require 'crystal'
|
||||
require 'asm/object_writer'
|
||||
require "asm/arm/arm_assembler"
|
||||
require "asm/arm_assembler"
|
||||
|
@ -9,7 +9,7 @@ require_relative 'helper'
|
||||
class TestSmallProg < MiniTest::Test
|
||||
# need a code generator, for arm
|
||||
def setup
|
||||
@generator = Asm::Arm::ArmAssembler.new
|
||||
@generator = Asm::ArmAssembler.new
|
||||
end
|
||||
|
||||
def test_loop
|
||||
|
@ -1,5 +1,5 @@
|
||||
require_relative 'helper'
|
||||
require "asm/arm/arm_assembler"
|
||||
require "asm/arm_assembler"
|
||||
|
||||
# try to test that the generation of basic instructions works
|
||||
# one instruction at a time, reverse testing from objdump --demangle -Sfghxp
|
||||
@ -9,7 +9,7 @@ require "asm/arm/arm_assembler"
|
||||
class TestArmAsm < MiniTest::Test
|
||||
# need a code generator, for arm
|
||||
def setup
|
||||
@assembler = Asm::Arm::ArmAssembler.new
|
||||
@assembler = Asm::ArmAssembler.new
|
||||
end
|
||||
|
||||
# code is what the generator spits out, at least one instruction worth (.first)
|
||||
|
Loading…
Reference in New Issue
Block a user