Add an output file parameter.

This commit is contained in:
Danila Fedorin 2018-08-04 13:49:29 -07:00
parent 1150e2b3ef
commit 2ed2a4932c
2 changed files with 12 additions and 4 deletions

View File

@ -180,7 +180,7 @@ module Chalk
all_instructions << Ir::ReturnInstruction.new all_instructions << Ir::ReturnInstruction.new
end end
file = File.open("out.ch8", "w") file = File.open(@config.output, "w")
generate_binary(table, all_instructions, file) generate_binary(table, all_instructions, file)
file.close file.close
end end

View File

@ -22,15 +22,20 @@ module Chalk
getter mode : OutputMode getter mode : OutputMode
# Sets the mode in which the compiler should operate. # Sets the mode in which the compiler should operate.
setter mode : OutputMode setter mode : OutputMode
# Gets the log level # Gets the log level.
getter loglevel : Logger::Severity getter loglevel : Logger::Severity
# Sets the log level # Sets the log level.
setter loglevel : Logger::Severity setter loglevel : Logger::Severity
# Gets the output file destination.
getter output : String
# Sets the output file destination.
setter output : String
# Creates a new configuration. # Creates a new configuration.
def initialize(@file = "", def initialize(@file = "",
@mode = OutputMode::Tree, @mode = OutputMode::Tree,
@loglevel = Logger::Severity::DEBUG) @loglevel = Logger::Severity::DEBUG,
@output : String = "out.ch8")
end end
# Reads a configuration from the command line options. # Reads a configuration from the command line options.
@ -53,6 +58,9 @@ module Chalk
parser.on("-f", "--file=FILE", "Set the input file to compile.") do |file| parser.on("-f", "--file=FILE", "Set the input file to compile.") do |file|
config.file = file config.file = file
end end
parser.on("-o", "--output=OUT", "Sets the output file.") do |out|
config.output = out
end
parser.on("-l", "--log=LOG", "Set the log level of the compiler.") do |log| parser.on("-l", "--log=LOG", "Set the log level of the compiler.") do |log|
hash = { hash = {
"debug" => Logger::Severity::DEBUG, "debug" => Logger::Severity::DEBUG,