Skip to content

Using --no-codegen blocks --emit options #5820

Open
@bew

Description

When we do: crystal build hello.cr --emit llvm-ir --no-codegen
It'll not generate the hello.ll file even though it was asked for.

This is because the emit options are handled all-in-one-place in the CompilationUnit#emit method

def emit(value : String, output_filename)
case value
when "asm"
compiler.target_machine.emit_asm_to_file llvm_mod, "#{output_filename}.s"
when "llvm-bc"
FileUtils.cp(bc_name, "#{output_filename}.bc")
when "llvm-ir"
llvm_mod.print_to_file "#{output_filename}.ll"
when "obj"
FileUtils.cp(object_name, "#{output_filename}.o")
end
end

Which is called in the codegen block:

@progress_tracker.stage("Codegen (bc+obj)") do
@progress_tracker.stage_progress_total = units.size
if units.size == 1
first_unit = units.first
first_unit.compile
reused << first_unit.name if first_unit.reused_previous_compilation?
if emit = @emit
first_unit.emit(emit, emit_base_filename || output_filename)
end
else
reused = codegen_many_units(program, units, target_triple)
end
end

At line 348.

I think it should emit what was asked for as soon as it get it, so the llvm-ir after it was built, the obj in the codegen phase, etc..

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    kind:bugA bug in the code. Does not apply to documentation, specs, etc.topic:compiler

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions