mirror of
https://github.com/safiire/n65.git
synced 2024-12-12 00:29:03 +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'
|
t.pattern = 'test/test*.rb'
|
||||||
end
|
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
|
assembler.fulfill_promises
|
||||||
puts " Done." unless options[:quiet]
|
puts " Done." unless options[:quiet]
|
||||||
|
|
||||||
|
## Optionally write out a symbol map
|
||||||
if options[:write_symbol_table]
|
if options[:write_symbol_table]
|
||||||
print "Writing symbol table to #{output_file}.yaml..." unless options[:quiet]
|
print "Writing symbol table to #{output_file}.yaml..." unless options[:quiet]
|
||||||
File.open("#{output_file}.yaml", 'w') do |fp|
|
File.open("#{output_file}.yaml", 'w') do |fp|
|
||||||
@ -51,6 +52,15 @@ module N65
|
|||||||
puts "Done." unless options[:quiet]
|
puts "Done." unless options[:quiet]
|
||||||
end
|
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
|
## Emit the complete binary ROM
|
||||||
rom = assembler.emit_binary_rom
|
rom = assembler.emit_binary_rom
|
||||||
File.open(output_file, 'w') do |fp|
|
File.open(output_file, 'w') do |fp|
|
||||||
@ -111,6 +121,15 @@ module N65
|
|||||||
unless parsed_object.nil?
|
unless parsed_object.nil?
|
||||||
exec_result = parsed_object.exec(self)
|
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
|
## If we have returned a promise save it for the second pass
|
||||||
@promises << exec_result if exec_result.kind_of?(Proc)
|
@promises << exec_result if exec_result.kind_of?(Proc)
|
||||||
end
|
end
|
||||||
|
@ -59,7 +59,7 @@ module N65
|
|||||||
promise = assembler.with_saved_state do |saved_assembler|
|
promise = assembler.with_saved_state do |saved_assembler|
|
||||||
@bytes_array.map! do |byte|
|
@bytes_array.map! do |byte|
|
||||||
case byte
|
case byte
|
||||||
when Fixnum
|
when Integer
|
||||||
byte
|
byte
|
||||||
when String
|
when String
|
||||||
saved_assembler.symbol_table.resolve_symbol(byte)
|
saved_assembler.symbol_table.resolve_symbol(byte)
|
||||||
@ -77,7 +77,7 @@ module N65
|
|||||||
## And just write 0xDE for a placeholder
|
## And just write 0xDE for a placeholder
|
||||||
placeholder_bytes = @bytes_array.map do |byte|
|
placeholder_bytes = @bytes_array.map do |byte|
|
||||||
case bytes
|
case bytes
|
||||||
when Fixnum
|
when Integer
|
||||||
byte
|
byte
|
||||||
when String
|
when String
|
||||||
0xDE
|
0xDE
|
||||||
|
@ -11,7 +11,7 @@ module N65
|
|||||||
####
|
####
|
||||||
## Initialize with ARGV commandline
|
## Initialize with ARGV commandline
|
||||||
def initialize(argv)
|
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
|
@argv = argv.dup
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -57,6 +57,7 @@ module N65
|
|||||||
N65::Assembler.from_file(input_file, @options)
|
N65::Assembler.from_file(input_file, @options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
####
|
####
|
||||||
@ -73,6 +74,10 @@ module N65
|
|||||||
@options[:write_symbol_table] = true
|
@options[:write_symbol_table] = true
|
||||||
end
|
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
|
opts.on('-q', '--quiet', 'No output on success') do
|
||||||
@options[:quiet] = true
|
@options[:quiet] = true
|
||||||
end
|
end
|
||||||
|
@ -6,7 +6,7 @@ module N65
|
|||||||
####
|
####
|
||||||
## Represents a single 6502 Instruction
|
## Represents a single 6502 Instruction
|
||||||
class 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
|
## Custom Exceptions
|
||||||
class InvalidInstruction < StandardError; end
|
class InvalidInstruction < StandardError; end
|
||||||
|
@ -18,6 +18,19 @@ module N65
|
|||||||
}
|
}
|
||||||
@anonymous_scope_number = 0
|
@anonymous_scope_number = 0
|
||||||
@scope_stack = [:global]
|
@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
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -29,7 +42,6 @@ module N65
|
|||||||
name = name.to_sym
|
name = name.to_sym
|
||||||
scope = current_scope
|
scope = current_scope
|
||||||
if scope.has_key?(name)
|
if scope.has_key?(name)
|
||||||
#path_string = generate_scope_path(path_ary)
|
|
||||||
fail(InvalidScope, "Scope: #{name} already exists")
|
fail(InvalidScope, "Scope: #{name} already exists")
|
||||||
end
|
end
|
||||||
scope[name] = {}
|
scope[name] = {}
|
||||||
@ -135,6 +147,13 @@ module N65
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
####
|
||||||
|
## Export a cycle count for top level subroutines
|
||||||
|
def export_cycle_count_yaml
|
||||||
|
@subroutine_cycles.to_yaml
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
####
|
####
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
module N65
|
module N65
|
||||||
VERSION ||= "1.5.2"
|
VERSION ||= "1.5.3"
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user