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
end
file = File.open("out.ch8", "w")
file = File.open(@config.output, "w")
generate_binary(table, all_instructions, file)
file.close
end

View File

@ -22,15 +22,20 @@ module Chalk
getter mode : OutputMode
# Sets the mode in which the compiler should operate.
setter mode : OutputMode
# Gets the log level
# Gets the log level.
getter loglevel : Logger::Severity
# Sets the log level
# Sets the log level.
setter loglevel : Logger::Severity
# Gets the output file destination.
getter output : String
# Sets the output file destination.
setter output : String
# Creates a new configuration.
def initialize(@file = "",
@mode = OutputMode::Tree,
@loglevel = Logger::Severity::DEBUG)
@loglevel = Logger::Severity::DEBUG,
@output : String = "out.ch8")
end
# 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|
config.file = file
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|
hash = {
"debug" => Logger::Severity::DEBUG,