cleanup, requires, namespacing to actually get it to work

This commit is contained in:
Torsten Ruger 2014-04-14 21:52:16 +03:00
parent 5ad36bbd56
commit 2e6b90b12e
16 changed files with 379 additions and 299 deletions

10
Gemfile
View File

@ -1,10 +1,10 @@
source "http://rubygems.org"
group :development do
gem "minitest", ">= 0"
gem "minitest"
gem "rdoc", "~> 3.12"
gem "bundler", "~> 1.0"
gem "jeweler", "~> 2.0.1"
gem "simplecov", ">= 0"
gem "roodi", "~> 2.1.0"
gem "bundler"
gem "jeweler"
gem "simplecov"
gem "roodi"
end

72
Gemfile.lock Normal file
View File

@ -0,0 +1,72 @@
GEM
remote: http://rubygems.org/
specs:
addressable (2.3.6)
builder (3.2.2)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
docile (1.1.3)
faraday (0.9.0)
multipart-post (>= 1.2, < 3)
git (1.2.6)
github_api (0.11.3)
addressable (~> 2.3)
descendants_tracker (~> 0.0.1)
faraday (~> 0.8, < 0.10)
hashie (>= 1.2)
multi_json (>= 1.7.5, < 2.0)
nokogiri (~> 1.6.0)
oauth2
hashie (2.1.1)
highline (1.6.21)
jeweler (2.0.1)
builder
bundler (>= 1.0)
git (>= 1.2.5)
github_api
highline (>= 1.6.15)
nokogiri (>= 1.5.10)
rake
rdoc
json (1.8.1)
jwt (0.1.11)
multi_json (>= 1.5)
mini_portile (0.5.3)
minitest (5.3.2)
multi_json (1.9.2)
multi_xml (0.5.5)
multipart-post (2.0.0)
nokogiri (1.6.1)
mini_portile (~> 0.5.0)
oauth2 (0.9.3)
faraday (>= 0.8, < 0.10)
jwt (~> 0.1.8)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (~> 1.2)
rack (1.5.2)
rake (10.2.2)
rdoc (3.12.2)
json (~> 1.4)
roodi (2.1.0)
ruby_parser
ruby_parser (3.5.0)
sexp_processor (~> 4.1)
sexp_processor (4.4.3)
simplecov (0.8.2)
docile (~> 1.1.0)
multi_json
simplecov-html (~> 0.8.0)
simplecov-html (0.8.0)
thread_safe (0.3.3)
PLATFORMS
ruby
DEPENDENCIES
bundler
jeweler
minitest
rdoc (~> 3.12)
roodi
simplecov

View File

@ -1,4 +1,4 @@
class Asm::ARM::AddrTableObject
class Asm::Arm::AddrTableObject
def initialize
@table = []
@const = []
@ -21,8 +21,8 @@ class Asm::ARM::AddrTableObject
@table.each do |pair|
target_label, here_label = *pair
here_label.assemble io, as
as.add_relocation io.tell, target_label, Asm::ARM::R_ARM_ABS32,
Asm::ARM::Instruction::RelocHandler
as.add_relocation io.tell, target_label, Asm::Arm::R_ARM_ABS32,
Asm::Arm::Instruction::RelocHandler
io.write_uint32 0
end
@const.each do |pair|

View File

@ -1,4 +1,4 @@
require_relative 'assembler'
require 'asm/assembler'
module Asm
module Arm
@ -17,7 +17,7 @@ module Asm
# TODO actually find the closest somehow
def self.closest_addrtable(as)
as.objects.find do |obj|
obj.is_a?(Asm::ARM::AddrTableObject)
obj.is_a?(Asm::Arm::AddrTableObject)
end || (raise Asm::AssemblyError.new('could not find addrtable to use', nil))
end
@ -49,6 +49,6 @@ module Asm
raise 'unknown relocation type'
end
end
end
end

View File

@ -3,7 +3,7 @@ module Asm
# ADDRESSING MODE 1
# Complete!
class BuilderA
include Asm::ARM::InstructionTools
include Asm::Arm::InstructionTools
def initialize
@cond = 0b1110

View File

@ -1,9 +1,11 @@
require "asm/parser"
module Asm
module Arm
# ADDRESSING MODE 2
# Implemented: immediate offset with offset=0
class BuilderB
include Asm::ARM::InstructionTools
include Asm::Arm::InstructionTools
def initialize
@cond = 0b1110
@ -96,15 +98,15 @@ module Asm
(pre_post_index << 12+4+4+1+1+1+1) | (i << 12+4+4+1+1+1+1+1) |
(inst_class << 12+4+4+1+1+1+1+1+1) | (cond << 12+4+4+1+1+1+1+1+1+2)
if (@use_addrtable_reloc)
closest_addrtable = Asm::ARM.closest_addrtable(as)
closest_addrtable = Asm::Arm.closest_addrtable(as)
if (@addrtable_reloc_target.is_a?(Asm::Parser::LabelEquivAddrArgNode))
obj = ast_asm.object_for_label(@addrtable_reloc_target.label, inst)
ref_label = closest_addrtable.add_label(obj)
elsif (@addrtable_reloc_target.is_a?(Asm::Parser::NumEquivAddrArgNode))
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::Arm::R_ARM_PC12,
Asm::Arm::Instruction::RelocHandler
end
io.write_uint32 val
end

View File

@ -2,11 +2,11 @@ module Asm
module Arm
# ADDRESSING MODE 4
class BuilderD
include Asm::ARM::InstructionTools
include Asm::Arm::InstructionTools
def initialize
@cond = 0b1110
@inst_class = Asm::ARM::Instruction::OPC_STACK
@inst_class = Asm::Arm::Instruction::OPC_STACK
@pre_post_index = 0
@up_down = 0
@s = 0

View File

@ -1,5 +1,8 @@
require_relative 'arm_assembler'
require_relative 'parser'
require 'asm/arm/arm_assembler'
require 'asm/arm/instruction'
require 'asm/label_object'
require 'asm/parser'
require 'stream_reader'
require 'stringio'
module Asm
@ -51,7 +54,7 @@ module Asm
end
}
@asm.add_object Asm::ARM::Instruction.new(node)
@asm.add_object Asm::Arm::Instruction.new(node)
end
%w(adc add and bic eor orr rsb rsc sbc sub

View File

@ -1,7 +1,13 @@
require "asm/arm/instruction_tools"
require "asm/arm/builder_a"
require "asm/arm/builder_b"
require "asm/arm/builder_d"
module Asm
module Arm
class Asm::ARM::Instruction
include Asm::ARM::InstructionTools
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, ast_asm = nil)
@ -63,7 +69,7 @@ module Asm
:vs => 0b0110
}
RelocHandler = Asm::ARM.method(:write_resolved_relocation)
RelocHandler = Asm::Arm.method(:write_resolved_relocation)
def assemble(io, as)
s = @s ? 1 : 0
@ -123,7 +129,7 @@ module Asm
io << packed[0,3]
elsif (arg.is_a?(Asm::LabelObject) or arg.is_a?(Asm::Parser::LabelRefArgNode))
arg = @ast_asm.object_for_label(arg.label, self) if arg.is_a?(Asm::Parser::LabelRefArgNode)
as.add_relocation(io.tell, arg, Asm::ARM::R_ARM_PC24, RelocHandler)
as.add_relocation(io.tell, arg, Asm::Arm::R_ARM_PC24, RelocHandler)
io << "\x00\x00\x00"
end
io.write_uint8 OPCODES[opcode] | (COND_BITS[@cond] << 4)

View File

@ -1,6 +1,6 @@
module Asm
module Arm
module Asm::ARM::InstructionTools
module Asm::Arm::InstructionTools
def reg_ref(arg)
if (not arg.is_a?(Asm::Parser::RegisterArgNode))
raise Asm::AssemblyError.new('argument must be a register', arg)

View File

@ -39,8 +39,8 @@ module Asm
elsif (cmd.name == "asciz")
str = eval(cmd.value) + "\x00"
@asm.add_object Asm::DataObject.new(str)
elsif (defined?(Asm::ARM) and cmd.name == 'addrtable')
@asm.add_object Asm::ARM::AddrTableObject.new
elsif (defined?(Asm::Arm) and cmd.name == 'addrtable')
@asm.add_object Asm::Arm::AddrTableObject.new
else
raise Asm::AssemblyError.new('unknown directive', cmd)
end

View File

@ -86,7 +86,7 @@ module Asm
case options.target
when :arm
require_relative 'arm_assembler.rb'
as_module = Asm::ARM
as_module = Asm::Arm
as_target = Elf::Constants::TARGET_ARM
when :ttk91
require_relative 'ttk91_assembler.rb'

View File

@ -1,6 +1,6 @@
require_relative 'str_scanner'
module AS
module Asm
class ParseError < StandardError
def initialize(message, s)
super(message)
@ -10,9 +10,8 @@ module AS
end
attr_reader :line, :column
end
end
class Asm::Parser
class Parser
def initialize(str)
scanner = Asm::Scanner.new(str)
@ -264,6 +263,8 @@ class Asm::Parser
end
end
end
if (__FILE__ == $0)
p Asm::Parser.parse ARGV[0]
end

View File

@ -1,6 +1,6 @@
if (__FILE__ == $0)
gen = Asm::ARMCodeGenerator.new
gen = Asm::ArmCodeGenerator.new
gen.instance_eval {
mov r0, 5

View File

@ -8,7 +8,7 @@ end
SimpleCov.configure do
clean_filters
load_adapter 'test_frameworks'
load_profile 'test_frameworks'
end
ENV["COVERAGE"] && SimpleCov.start do
@ -23,13 +23,9 @@ rescue Bundler::BundlerError => e
$stderr.puts "Run `bundle install` to install missing gems"
exit e.status_code
end
require 'minitest/unit'
require "minitest/autorun"
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'test'))
require 'crystal'
class MiniTest::Unit::TestCase
end
MiniTest::Unit.autorun