mirror of
https://github.com/safiire/n65.git
synced 2024-12-11 08:49:42 +00:00
Added a subroutine cycle count option, fixed a warning with the usage of Fixnum
This commit is contained in:
parent
eca1831e35
commit
afb78e4c0d
5
Rakefile
5
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
|
||||
|
19
lib/n65.rb
19
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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
####
|
||||
|
@ -1,3 +1,3 @@
|
||||
module N65
|
||||
VERSION ||= "1.5.2"
|
||||
VERSION ||= "1.5.3"
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user