Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/compiler/crystal/command.cr
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ class Crystal::Command
unless no_codegen
unless run
opts.on("--cross-compile", "cross-compile") do |cross_compile|
compiler.cross_compile = true
compiler.cross_compile!
end
end
opts.on("-d", "--debug", "Add full symbolic debug info") do
Expand Down Expand Up @@ -424,7 +424,7 @@ class Crystal::Command
valid_emit_values.map!(&.gsub('_', '-').downcase)

opts.on("--emit [#{valid_emit_values.join('|')}]", "Comma separated list of types of output for the compiler to emit") do |emit_values|
compiler.emit_targets |= validate_emit_values(emit_values.split(',').map(&.strip))
compiler.add_emit_targets validate_emit_values(emit_values.split(',').map(&.strip))
end
end

Expand Down
18 changes: 14 additions & 4 deletions src/compiler/crystal/compiler.cr
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module Crystal
# If `true`, doesn't generate an executable but instead
# creates a `.o` file and outputs a command line to link
# it in the target machine.
property? cross_compile = false
getter? cross_compile = false

# Compiler flags. These will be true when checked in macro
# code by the `flag?(...)` macro method.
Expand Down Expand Up @@ -177,7 +177,7 @@ module Crystal
# * llvm-bc: LLVM bitcode
# * llvm-ir: LLVM IR
# * obj: object file
property emit_targets : EmitTarget = EmitTarget::None
getter emit_targets : EmitTarget = EmitTarget::None

# Base filename to use for `emit` output.
property emit_base_filename : String?
Expand Down Expand Up @@ -258,13 +258,24 @@ module Crystal
@optimization_mode.o3? && @single_module
end

def cross_compile!
@cross_compile = true
@single_module = true
end

def add_emit_targets(emit_targets)
@emit_targets |= emit_targets
@single_module = true unless @emit_targets.none?
end

private def new_program(sources)
@program = program = Program.new
program.compiler = self
program.filename = sources.first.filename
program.codegen_target = codegen_target
program.target_machine = create_target_machine
program.flags << "release" if release?
program.flags << "single_module" if single_module?
program.flags << "debug" unless debug.none?
program.flags << "static" if static?
program.flags.concat @flags
Expand Down Expand Up @@ -322,8 +333,7 @@ module Crystal

private def codegen(program, node : ASTNode, sources, output_filename)
llvm_modules = @progress_tracker.stage("Codegen (crystal)") do
program.codegen node, debug: debug, frame_pointers: frame_pointers,
single_module: @single_module || @cross_compile || !@emit_targets.none?
program.codegen node, debug: debug, frame_pointers: frame_pointers, single_module: single_module?
end

output_dir = CacheDir.instance.directory_for(sources)
Expand Down
1 change: 0 additions & 1 deletion src/compiler/crystal/macros/macros.cr
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ class Crystal::Program
host_compiler.mcpu = compiler.mcpu
host_compiler.mattr = compiler.mattr
host_compiler.mcmodel = compiler.mcmodel
host_compiler.single_module = compiler.single_module?
host_compiler.static = compiler.static?
end

Expand Down