Compare commits
No commits in common. "2ed2a4932c2a5f0fe6b7b295b8e2e0e54e2bd302" and "4de89d98a1b7877eca07ec5510450ba9beea6ac2" have entirely different histories.
2ed2a4932c
...
4de89d98a1
@ -12,7 +12,7 @@ module Chalk
|
|||||||
def initialize(@config : Ui::Config)
|
def initialize(@config : Ui::Config)
|
||||||
@logger = Logger.new STDOUT
|
@logger = Logger.new STDOUT
|
||||||
@logger.debug("Initialized compiler")
|
@logger.debug("Initialized compiler")
|
||||||
@logger.level = @config.loglevel
|
@logger.level = Logger::DEBUG
|
||||||
end
|
end
|
||||||
|
|
||||||
# Reads a file an extracts instances of
|
# Reads a file an extracts instances of
|
||||||
@ -180,7 +180,7 @@ module Chalk
|
|||||||
all_instructions << Ir::ReturnInstruction.new
|
all_instructions << Ir::ReturnInstruction.new
|
||||||
end
|
end
|
||||||
|
|
||||||
file = File.open(@config.output, "w")
|
file = File.open("out.ch8", "w")
|
||||||
generate_binary(table, all_instructions, file)
|
generate_binary(table, all_instructions, file)
|
||||||
file.close
|
file.close
|
||||||
end
|
end
|
||||||
|
@ -22,20 +22,10 @@ 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.
|
|
||||||
getter loglevel : Logger::Severity
|
|
||||||
# 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.
|
# Creates a new configuration.
|
||||||
def initialize(@file = "",
|
def initialize(@file = "",
|
||||||
@mode = OutputMode::Tree,
|
@mode = OutputMode::Tree)
|
||||||
@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.
|
||||||
@ -44,35 +34,20 @@ module Chalk
|
|||||||
OptionParser.parse! do |parser|
|
OptionParser.parse! do |parser|
|
||||||
parser.banner = "Usage: chalk [arguments]"
|
parser.banner = "Usage: chalk [arguments]"
|
||||||
parser.on("-m", "--mode=MODE", "Set the mode of the compiler.") do |mode|
|
parser.on("-m", "--mode=MODE", "Set the mode of the compiler.") do |mode|
|
||||||
hash = {
|
case mode.downcase
|
||||||
"tree" => OutputMode::Tree,
|
when "tree", "t"
|
||||||
"t" => OutputMode::Tree,
|
config.mode = OutputMode::Tree
|
||||||
"intermediate" => OutputMode::Intermediate,
|
when "intermediate", "i"
|
||||||
"i" => OutputMode::Intermediate,
|
config.mode = OutputMode::Intermediate
|
||||||
"binary" => OutputMode::Binary,
|
when "binary", "b"
|
||||||
"b" => OutputMode::Binary
|
config.mode = OutputMode::Binary
|
||||||
}
|
else
|
||||||
puts "Invalid mode type. Using default." if !hash.has_key?(mode)
|
puts "Invalid mode type. Using default."
|
||||||
config.mode = hash[mode]? || OutputMode::Tree
|
end
|
||||||
end
|
end
|
||||||
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|
|
|
||||||
hash = {
|
|
||||||
"debug" => Logger::Severity::DEBUG,
|
|
||||||
"fatal" => Logger::Severity::FATAL,
|
|
||||||
"error" => Logger::Severity::ERROR,
|
|
||||||
"info" => Logger::Severity::INFO,
|
|
||||||
"unknown" => Logger::Severity::UNKNOWN,
|
|
||||||
"warn" => Logger::Severity::WARN
|
|
||||||
}
|
|
||||||
puts "Invalid log level. Using default." if !hash.has_key?(log)
|
|
||||||
config.loglevel = hash[log]? || Logger::Severity::DEBUG
|
|
||||||
end
|
|
||||||
parser.on("-h", "--help", "Show this message.") { puts parser }
|
parser.on("-h", "--help", "Show this message.") { puts parser }
|
||||||
end
|
end
|
||||||
return config
|
return config
|
||||||
|
Loading…
Reference in New Issue
Block a user