From 2ed2a4932c2a5f0fe6b7b295b8e2e0e54e2bd302 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Sat, 4 Aug 2018 13:49:29 -0700 Subject: [PATCH] Add an output file parameter. --- src/chalk/compiler.cr | 2 +- src/chalk/config.cr | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/chalk/compiler.cr b/src/chalk/compiler.cr index 53baf58..65244fd 100644 --- a/src/chalk/compiler.cr +++ b/src/chalk/compiler.cr @@ -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 diff --git a/src/chalk/config.cr b/src/chalk/config.cr index 1b5e20d..8e083c8 100644 --- a/src/chalk/config.cr +++ b/src/chalk/config.cr @@ -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,