diff --git a/Rakefile b/Rakefile index 275d7ff..a80fba8 100644 --- a/Rakefile +++ b/Rakefile @@ -5,3 +5,8 @@ Rake::TestTask.new do |t| t.pattern = 'test/test*.rb' end + +## Check the syntax of all ruby files +task :syntax do |t| + sh "find . -name *.rb -type f -exec ruby -c {} \\; -exec echo {} \\;" +end diff --git a/lib/n65.rb b/lib/n65.rb index 70fda67..2f1e7d8 100644 --- a/lib/n65.rb +++ b/lib/n65.rb @@ -43,6 +43,7 @@ module N65 assembler.fulfill_promises puts " Done." unless options[:quiet] + ## Optionally write out a symbol map if options[:write_symbol_table] print "Writing symbol table to #{output_file}.yaml..." unless options[:quiet] File.open("#{output_file}.yaml", 'w') do |fp| @@ -51,6 +52,15 @@ module N65 puts "Done." unless options[:quiet] end + ## Optionally write out cycle count for subroutines + if options[:cycle_count] + print "Writing subroutine cycle counts to #{output_file}.cycles.yaml..." unless options[:quiet] + File.open("#{output_file}.cycles.yaml", 'w') do |fp| + fp.write(assembler.symbol_table.export_cycle_count_yaml) + end + puts "Done." unless options[:quiet] + end + ## Emit the complete binary ROM rom = assembler.emit_binary_rom File.open(output_file, 'w') do |fp| @@ -111,6 +121,15 @@ module N65 unless parsed_object.nil? exec_result = parsed_object.exec(self) + ## TODO + ## I could perhaps keep a tally of cycles used per top level scope here + if parsed_object.respond_to?(:cycles) + #puts "Line: #{line}" + #puts "Cycles #{parsed_object.cycles}" + #puts "Sym: #{@symbol_table.scope_stack}" + @symbol_table.add_cycles(parsed_object.cycles) + end + ## If we have returned a promise save it for the second pass @promises << exec_result if exec_result.kind_of?(Proc) end diff --git a/lib/n65/directives/bytes.rb b/lib/n65/directives/bytes.rb index 4418101..808c6aa 100644 --- a/lib/n65/directives/bytes.rb +++ b/lib/n65/directives/bytes.rb @@ -59,7 +59,7 @@ module N65 promise = assembler.with_saved_state do |saved_assembler| @bytes_array.map! do |byte| case byte - when Fixnum + when Integer byte when String saved_assembler.symbol_table.resolve_symbol(byte) @@ -77,7 +77,7 @@ module N65 ## And just write 0xDE for a placeholder placeholder_bytes = @bytes_array.map do |byte| case bytes - when Fixnum + when Integer byte when String 0xDE diff --git a/lib/n65/front_end.rb b/lib/n65/front_end.rb index 6801bff..4493cda 100644 --- a/lib/n65/front_end.rb +++ b/lib/n65/front_end.rb @@ -11,7 +11,7 @@ module N65 #### ## Initialize with ARGV commandline def initialize(argv) - @options = {output_file: nil, write_symbol_table: false, quiet: false} + @options = {output_file: nil, write_symbol_table: false, quiet: false, cycle_count: false} @argv = argv.dup end @@ -57,6 +57,7 @@ module N65 N65::Assembler.from_file(input_file, @options) end + private #### @@ -73,6 +74,10 @@ module N65 @options[:write_symbol_table] = true end + opts.on('-c', '--cycles', 'Outputs a cycle count yaml document') do + @options[:cycle_count] = true + end + opts.on('-q', '--quiet', 'No output on success') do @options[:quiet] = true end diff --git a/lib/n65/instruction.rb b/lib/n65/instruction.rb index b0ea4b8..00dfac6 100644 --- a/lib/n65/instruction.rb +++ b/lib/n65/instruction.rb @@ -6,7 +6,7 @@ module N65 #### ## Represents a single 6502 Instruction class Instruction - attr_reader :op, :arg, :mode, :hex, :description, :length, :cycle, :boundry_add, :flags, :address + attr_reader :op, :arg, :mode, :hex, :description, :length, :cycles, :boundry_add, :flags, :address ## Custom Exceptions class InvalidInstruction < StandardError; end diff --git a/lib/n65/symbol_table.rb b/lib/n65/symbol_table.rb index 347fccb..67ea5a9 100644 --- a/lib/n65/symbol_table.rb +++ b/lib/n65/symbol_table.rb @@ -18,6 +18,19 @@ module N65 } @anonymous_scope_number = 0 @scope_stack = [:global] + @subroutine_cycles = {} + end + + + #### + ## Add a running cycle count to current top level scopes (ie subroutines) + def add_cycles(cycles) + cycles ||= 0 + top_level_subroutine = @scope_stack[1] + unless top_level_subroutine.nil? + @subroutine_cycles[top_level_subroutine] ||= 0 + @subroutine_cycles[top_level_subroutine] += cycles + end end @@ -29,7 +42,6 @@ module N65 name = name.to_sym scope = current_scope if scope.has_key?(name) - #path_string = generate_scope_path(path_ary) fail(InvalidScope, "Scope: #{name} already exists") end scope[name] = {} @@ -135,6 +147,13 @@ module N65 end + #### + ## Export a cycle count for top level subroutines + def export_cycle_count_yaml + @subroutine_cycles.to_yaml + end + + private #### diff --git a/lib/n65/version.rb b/lib/n65/version.rb index 0736b5e..7897e10 100644 --- a/lib/n65/version.rb +++ b/lib/n65/version.rb @@ -1,3 +1,3 @@ module N65 - VERSION ||= "1.5.2" + VERSION ||= "1.5.3" end