Skip to content

Commit

Permalink
Add support for --m* flags to crystal spec and crystal eval (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
yxhuvud authored Jan 29, 2022
1 parent 2d4c35f commit aa8bbd7
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions src/compiler/crystal/command.cr
Original file line number Diff line number Diff line change
Expand Up @@ -398,28 +398,7 @@ class Crystal::Command
opts.on("--link-flags FLAGS", "Additional flags to pass to the linker") do |some_link_flags|
link_flags << some_link_flags
end
opts.on("--mcpu CPU", "Target specific cpu type") do |cpu|
if cpu == "native"
compiler.mcpu = LLVM.host_cpu_name
else
compiler.mcpu = cpu
end
end
opts.on("--mattr CPU", "Target specific features") do |features|
compiler.mattr = features
end
opts.on("--mcmodel MODEL", "Target specific code model") do |mcmodel|
compiler.mcmodel = case mcmodel
when "default" then LLVM::CodeModel::Default
when "small" then LLVM::CodeModel::Small
when "kernel" then LLVM::CodeModel::Kernel
when "medium" then LLVM::CodeModel::Medium
when "large" then LLVM::CodeModel::Large
else
error "--mcmodel should be one of: default, kernel, small, medium, large"
raise "unreachable"
end
end
target_specific_opts(opts, compiler)
setup_compiler_warning_options(opts, compiler)
end

Expand Down Expand Up @@ -587,10 +566,36 @@ class Crystal::Command
@color = false
compiler.color = false
end
target_specific_opts(opts, compiler)
setup_compiler_warning_options(opts, compiler)
opts.invalid_option { }
end

private def target_specific_opts(opts, compiler)
opts.on("--mcpu CPU", "Target specific cpu type") do |cpu|
if cpu == "native"
compiler.mcpu = LLVM.host_cpu_name
else
compiler.mcpu = cpu
end
end
opts.on("--mattr CPU", "Target specific features") do |features|
compiler.mattr = features
end
opts.on("--mcmodel MODEL", "Target specific code model") do |mcmodel|
compiler.mcmodel = case mcmodel
when "default" then LLVM::CodeModel::Default
when "small" then LLVM::CodeModel::Small
when "kernel" then LLVM::CodeModel::Kernel
when "medium" then LLVM::CodeModel::Medium
when "large" then LLVM::CodeModel::Large
else
error "--mcmodel should be one of: default, kernel, small, medium, large"
raise "unreachable"
end
end
end

private def setup_compiler_warning_options(opts, compiler)
compiler.warnings_exclude << Crystal.normalize_path "lib"
warnings_exclude_default = true
Expand Down

0 comments on commit aa8bbd7

Please sign in to comment.