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