From 2e6b90b12e4f938e7ad833af61f9e7203a8c7e93 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Mon, 14 Apr 2014 21:52:16 +0300 Subject: [PATCH] cleanup, requires, namespacing to actually get it to work --- Gemfile | 10 +- Gemfile.lock | 72 +++ lib/asm/arm/addr_table_object.rb | 6 +- lib/asm/arm/arm_assembler.rb | 82 ++-- lib/asm/arm/builder_a.rb | 2 +- lib/asm/arm/builder_b.rb | 10 +- lib/asm/arm/builder_d.rb | 4 +- lib/asm/arm/code_generator.rb | 9 +- lib/asm/arm/instruction.rb | 14 +- lib/asm/arm/instruction_tools.rb | 2 +- lib/asm/ast_assembler.rb | 4 +- lib/asm/command_line.rb | 2 +- lib/asm/parser.rb | 447 +++++++++--------- lib/{asm/streamreader.rb => stream_reader.rb} | 0 test/code_generator.rb | 2 +- test/helper.rb | 12 +- 16 files changed, 379 insertions(+), 299 deletions(-) create mode 100644 Gemfile.lock rename lib/{asm/streamreader.rb => stream_reader.rb} (100%) diff --git a/Gemfile b/Gemfile index c22793f5..cb6c8693 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 00000000..18c1f6fe --- /dev/null +++ b/Gemfile.lock @@ -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 diff --git a/lib/asm/arm/addr_table_object.rb b/lib/asm/arm/addr_table_object.rb index 89b21e34..13c16dd9 100644 --- a/lib/asm/arm/addr_table_object.rb +++ b/lib/asm/arm/addr_table_object.rb @@ -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| diff --git a/lib/asm/arm/arm_assembler.rb b/lib/asm/arm/arm_assembler.rb index bfbc683c..8346df63 100644 --- a/lib/asm/arm/arm_assembler.rb +++ b/lib/asm/arm/arm_assembler.rb @@ -1,54 +1,54 @@ -require_relative 'assembler' +require 'asm/assembler' module Asm module Arm - # Relocation constants - # Note that in this assembler, a relocation simply means any - # reference to a label that can only be determined at assembly time - # or later (as in the normal meaning) + # Relocation constants + # Note that in this assembler, a relocation simply means any + # reference to a label that can only be determined at assembly time + # or later (as in the normal meaning) - R_ARM_PC24 = 0x01 - R_ARM_ABS32 = 0x02 + R_ARM_PC24 = 0x01 + R_ARM_ABS32 = 0x02 - # Unofficial (cant be used for extern relocations) - R_ARM_PC12 = 0xF0 + # Unofficial (cant be used for extern relocations) + R_ARM_PC12 = 0xF0 - # TODO actually find the closest somehow - def self.closest_addrtable(as) - as.objects.find do |obj| - obj.is_a?(Asm::ARM::AddrTableObject) - end || (raise Asm::AssemblyError.new('could not find addrtable to use', nil)) - end + # TODO actually find the closest somehow + def self.closest_addrtable(as) + as.objects.find do |obj| + obj.is_a?(Asm::Arm::AddrTableObject) + end || (raise Asm::AssemblyError.new('could not find addrtable to use', nil)) + end - def self.write_resolved_relocation(io, addr, type) - case type - when R_ARM_PC24 - diff = addr - io.tell - 8 - packed = [diff >> 2].pack('l') - io << packed[0,3] - when R_ARM_ABS32 - packed = [addr].pack('l') - io << packed - when R_ARM_PC12 - diff = addr - io.tell - 8 - if (diff.abs > 2047) - raise Asm::AssemblyError.new('offset too large for R_ARM_PC12 relocation', - nil) + def self.write_resolved_relocation(io, addr, type) + case type + when R_ARM_PC24 + diff = addr - io.tell - 8 + packed = [diff >> 2].pack('l') + io << packed[0,3] + when R_ARM_ABS32 + packed = [addr].pack('l') + io << packed + when R_ARM_PC12 + diff = addr - io.tell - 8 + if (diff.abs > 2047) + raise Asm::AssemblyError.new('offset too large for R_ARM_PC12 relocation', + nil) + end + + val = diff.abs + sign = (diff>0)?1:0 + + curr = io.read_uint32 + io.seek(-4, IO::SEEK_CUR) + + io.write_uint32 (curr & ~0b00000000100000000000111111111111) | + val | (sign << 23) + else + raise 'unknown relocation type' end - - val = diff.abs - sign = (diff>0)?1:0 - - curr = io.read_uint32 - io.seek(-4, IO::SEEK_CUR) - - io.write_uint32 (curr & ~0b00000000100000000000111111111111) | - val | (sign << 23) - else - raise 'unknown relocation type' end end - end diff --git a/lib/asm/arm/builder_a.rb b/lib/asm/arm/builder_a.rb index fb033faa..77c0149c 100644 --- a/lib/asm/arm/builder_a.rb +++ b/lib/asm/arm/builder_a.rb @@ -3,7 +3,7 @@ module Asm # ADDRESSING MODE 1 # Complete! class BuilderA - include Asm::ARM::InstructionTools + include Asm::Arm::InstructionTools def initialize @cond = 0b1110 diff --git a/lib/asm/arm/builder_b.rb b/lib/asm/arm/builder_b.rb index 17dddf33..f5faa444 100644 --- a/lib/asm/arm/builder_b.rb +++ b/lib/asm/arm/builder_b.rb @@ -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 diff --git a/lib/asm/arm/builder_d.rb b/lib/asm/arm/builder_d.rb index f15d7b64..deac6306 100644 --- a/lib/asm/arm/builder_d.rb +++ b/lib/asm/arm/builder_d.rb @@ -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 diff --git a/lib/asm/arm/code_generator.rb b/lib/asm/arm/code_generator.rb index 8a89f54d..8329a56a 100644 --- a/lib/asm/arm/code_generator.rb +++ b/lib/asm/arm/code_generator.rb @@ -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 diff --git a/lib/asm/arm/instruction.rb b/lib/asm/arm/instruction.rb index e3ab99d9..7868001a 100644 --- a/lib/asm/arm/instruction.rb +++ b/lib/asm/arm/instruction.rb @@ -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) diff --git a/lib/asm/arm/instruction_tools.rb b/lib/asm/arm/instruction_tools.rb index 4e437aca..36585b79 100644 --- a/lib/asm/arm/instruction_tools.rb +++ b/lib/asm/arm/instruction_tools.rb @@ -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) diff --git a/lib/asm/ast_assembler.rb b/lib/asm/ast_assembler.rb index 3438cb1b..2b4422fd 100644 --- a/lib/asm/ast_assembler.rb +++ b/lib/asm/ast_assembler.rb @@ -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 diff --git a/lib/asm/command_line.rb b/lib/asm/command_line.rb index ba665062..e184cf87 100644 --- a/lib/asm/command_line.rb +++ b/lib/asm/command_line.rb @@ -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' diff --git a/lib/asm/parser.rb b/lib/asm/parser.rb index 24bdf581..4a99cb81 100644 --- a/lib/asm/parser.rb +++ b/lib/asm/parser.rb @@ -1,6 +1,6 @@ require_relative 'str_scanner' -module AS +module Asm class ParseError < StandardError def initialize(message, s) super(message) @@ -10,258 +10,259 @@ module AS end attr_reader :line, :column end -end -class Asm::Parser - def initialize(str) - scanner = Asm::Scanner.new(str) + class Parser + def initialize(str) + scanner = Asm::Scanner.new(str) - @ast = parse_toplevel scanner - end - attr_reader :ast + @ast = parse_toplevel scanner + end + attr_reader :ast - def self.parse(str) - new(str).ast - end + def self.parse(str) + new(str).ast + end - class Node - def initialize(s = nil) - if (s) - @line = s.prev_line - @column = s.prev_column - else - @line = 0 - @column = 0 + class Node + def initialize(s = nil) + if (s) + @line = s.prev_line + @column = s.prev_column + else + @line = 0 + @column = 0 + end + + yield self if block_given? end - - yield self if block_given? + attr_reader :line, :column end - attr_reader :line, :column - end - class ToplevelNode < Node - attr_accessor :children - end - def parse_toplevel(s) - node = ToplevelNode.new(s) - node.children = [] - while (not s.eos?) - node.children << parse(s) + class ToplevelNode < Node + attr_accessor :children end - node - end - - def parse(s) - s.scan /\s*/ - node = nil - %w(comment directive label instruction).each { |em| - if (node = send('parse_'+em, s)) - break - end - } - raise Asm::ParseError.new('could not parse element', s) unless node - s.scan /\s*/ - node - end - - class CommentNode < Node; end - def parse_comment(s) - if (s.scan(/;.*?$/)) - CommentNode.new(s) - end - end - - class DirectiveNode < Node - attr_accessor :name, :value - end - def parse_directive(s) - if (m = s.scan(/\.(\w+)(?:(?!$)\s+(.+)\s*?$)?/)) - DirectiveNode.new(s) { |n| - n.name = m[0] - n.value = m[1] - } - end - end - - class LabelNode < Node - attr_accessor :name - end - def parse_label(s) - if (m = s.scan(/(\/*\w+):/)) - LabelNode.new(s) { |n| - n.name = m[0] - } - end - end - - class InstructionNode < Node - attr_accessor :opcode, :args - end - def parse_instruction(s) - if (m = s.scan(/(\w+)/)) - node = InstructionNode.new(s) { |n| - n.opcode = m[0] - n.args = [] - } - if (not s.scan(/\s*($|;)/)) - loop { - arg = parse_arg(s) - node.args << arg - break if not s.scan(/\s*,/) - } + def parse_toplevel(s) + node = ToplevelNode.new(s) + node.children = [] + while (not s.eos?) + node.children << parse(s) end node end - end - class ArgNode < Node - end - def parse_arg(s) - s.scan /\s*/ - node = nil - %w(reference register register_list num_literal label_ref).each { |em| - if (node = send('parse_'+em, s)) - break - end - } - raise Asm::ParseError.new('expected argument but none found', s) unless node - - if (node2 = parse_arg_op(s)) - node2.argument = node - node = node2 - end - - s.scan /\s*/ - node - end - - def parse_arg_op(s) - s.scan /\s*/ - node = nil - %w(shift math).each do |em| - if (node = send('parse_'+em, s)) - break - end - end - s.scan /\s*/ - node - end - - class ShiftNode < Node - attr_accessor :type, :value, :argument - end - def parse_shift(s) - if (m = s.scan(/(lsl|lsr|asr|ror|rrx)\s+/i)) - op = m[0].downcase - if (op == 'rrx' or arg = parse_arg(s)) - ShiftNode.new(s) { |n| - n.type = m[0].downcase - n.value = arg - } - else - nil - end - end - end - - class MathNode < Node - attr_accessor :left, :right, :op - alias_method :argument, :left - alias_method :argument=, :left= - end - def parse_math(s) - if (m = s.scan_str(/[\+\-]/)) - if (arg1 = parse_arg(s)) - MathNode.new(s) do |n| - n.right = arg1 - n.op = m + def parse(s) + s.scan /\s*/ + node = nil + %w(comment directive label instruction).each { |em| + if (node = send('parse_'+em, s)) + break end - else - raise Asm::ParseError.new('expected right side for arithmetic op', s) - end - end - end - - REGISTER_REGEXP = Regexp.union(*%w(r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 - r13 r14 r15 a1 a2 a3 a4 v1 v2 v3 v4 v5 v6 - rfp sl fp ip sp lr pc - )) - class RegisterArgNode < ArgNode - attr_accessor :name - end - def parse_register(s) - if (m = s.scan_str(REGISTER_REGEXP)) - RegisterArgNode.new(s) { |n| - n.name = m } + raise Asm::ParseError.new('could not parse element', s) unless node + s.scan /\s*/ + node end - end - - class RegisterListArgNode < ArgNode - attr_accessor :registers - end - def parse_register_list(s) - if (m = s.scan(/\{/)) - node = RegisterListArgNode.new(s) do |n| - n.registers = [] + + class CommentNode < Node; end + def parse_comment(s) + if (s.scan(/;.*?$/)) + CommentNode.new(s) end - loop do - s.scan /\s*/ - reg = parse_register(s) - if (not reg) - return nil + end + + class DirectiveNode < Node + attr_accessor :name, :value + end + def parse_directive(s) + if (m = s.scan(/\.(\w+)(?:(?!$)\s+(.+)\s*?$)?/)) + DirectiveNode.new(s) { |n| + n.name = m[0] + n.value = m[1] + } + end + end + + class LabelNode < Node + attr_accessor :name + end + def parse_label(s) + if (m = s.scan(/(\/*\w+):/)) + LabelNode.new(s) { |n| + n.name = m[0] + } + end + end + + class InstructionNode < Node + attr_accessor :opcode, :args + end + def parse_instruction(s) + if (m = s.scan(/(\w+)/)) + node = InstructionNode.new(s) { |n| + n.opcode = m[0] + n.args = [] + } + if (not s.scan(/\s*($|;)/)) + loop { + arg = parse_arg(s) + node.args << arg + break if not s.scan(/\s*,/) + } end - s.scan /\s*,?/ - - node.registers << reg - - if (s.scan(/\}/)) + node + end + end + + class ArgNode < Node + end + def parse_arg(s) + s.scan /\s*/ + node = nil + %w(reference register register_list num_literal label_ref).each { |em| + if (node = send('parse_'+em, s)) + break + end + } + raise Asm::ParseError.new('expected argument but none found', s) unless node + + if (node2 = parse_arg_op(s)) + node2.argument = node + node = node2 + end + + s.scan /\s*/ + node + end + + def parse_arg_op(s) + s.scan /\s*/ + node = nil + %w(shift math).each do |em| + if (node = send('parse_'+em, s)) break end end + s.scan /\s*/ node end - end - class NumLiteralArgNode < ArgNode - attr_accessor :value - end - class NumEquivAddrArgNode < NumLiteralArgNode - end - def parse_num_literal(s) - if (m = s.scan(/(=?)#(-?(?:0x)?[0-9A-Fa-f]+)/)) - (m[0] == '=' ? NumEquivAddrArgNode : NumLiteralArgNode).new(s) { |n| - n.value = Integer(m[1]) - } + class ShiftNode < Node + attr_accessor :type, :value, :argument end - end - - class LabelRefArgNode < ArgNode - attr_accessor :label, :label_object - end - class LabelEquivAddrArgNode < LabelRefArgNode - end - def parse_label_ref(s) - if (m = s.scan(/(=?)(\/*\w+)/)) - (m[0] == '=' ? LabelEquivAddrArgNode : LabelRefArgNode).new(s) { |n| - n.label = m[1] - } + def parse_shift(s) + if (m = s.scan(/(lsl|lsr|asr|ror|rrx)\s+/i)) + op = m[0].downcase + if (op == 'rrx' or arg = parse_arg(s)) + ShiftNode.new(s) { |n| + n.type = m[0].downcase + n.value = arg + } + else + nil + end + end end - end - class ReferenceArgNode < ArgNode - attr_accessor :argument - end - def parse_reference(s) - if (m = s.scan(/\[/)) - arg = parse_arg(s) - if (arg and s.scan(/\]/)) - ReferenceArgNode.new(s) do |n| - n.argument = arg + class MathNode < Node + attr_accessor :left, :right, :op + alias_method :argument, :left + alias_method :argument=, :left= + end + def parse_math(s) + if (m = s.scan_str(/[\+\-]/)) + if (arg1 = parse_arg(s)) + MathNode.new(s) do |n| + n.right = arg1 + n.op = m + end + else + raise Asm::ParseError.new('expected right side for arithmetic op', s) + end + end + end + + REGISTER_REGEXP = Regexp.union(*%w(r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 + r13 r14 r15 a1 a2 a3 a4 v1 v2 v3 v4 v5 v6 + rfp sl fp ip sp lr pc + )) + class RegisterArgNode < ArgNode + attr_accessor :name + end + def parse_register(s) + if (m = s.scan_str(REGISTER_REGEXP)) + RegisterArgNode.new(s) { |n| + n.name = m + } + end + end + + class RegisterListArgNode < ArgNode + attr_accessor :registers + end + def parse_register_list(s) + if (m = s.scan(/\{/)) + node = RegisterListArgNode.new(s) do |n| + n.registers = [] + end + loop do + s.scan /\s*/ + reg = parse_register(s) + if (not reg) + return nil + end + s.scan /\s*,?/ + + node.registers << reg + + if (s.scan(/\}/)) + break + end + end + node + end + end + + class NumLiteralArgNode < ArgNode + attr_accessor :value + end + class NumEquivAddrArgNode < NumLiteralArgNode + end + def parse_num_literal(s) + if (m = s.scan(/(=?)#(-?(?:0x)?[0-9A-Fa-f]+)/)) + (m[0] == '=' ? NumEquivAddrArgNode : NumLiteralArgNode).new(s) { |n| + n.value = Integer(m[1]) + } + end + end + + class LabelRefArgNode < ArgNode + attr_accessor :label, :label_object + end + class LabelEquivAddrArgNode < LabelRefArgNode + end + def parse_label_ref(s) + if (m = s.scan(/(=?)(\/*\w+)/)) + (m[0] == '=' ? LabelEquivAddrArgNode : LabelRefArgNode).new(s) { |n| + n.label = m[1] + } + end + end + + class ReferenceArgNode < ArgNode + attr_accessor :argument + end + def parse_reference(s) + if (m = s.scan(/\[/)) + arg = parse_arg(s) + if (arg and s.scan(/\]/)) + ReferenceArgNode.new(s) do |n| + n.argument = arg + end end end end end + end if (__FILE__ == $0) diff --git a/lib/asm/streamreader.rb b/lib/stream_reader.rb similarity index 100% rename from lib/asm/streamreader.rb rename to lib/stream_reader.rb diff --git a/test/code_generator.rb b/test/code_generator.rb index 65d5f593..602b8a91 100644 --- a/test/code_generator.rb +++ b/test/code_generator.rb @@ -1,6 +1,6 @@ if (__FILE__ == $0) - gen = Asm::ARMCodeGenerator.new + gen = Asm::ArmCodeGenerator.new gen.instance_eval { mov r0, 5 diff --git a/test/helper.rb b/test/helper.rb index 755a5a0b..d1184495 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -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