Skip to content

class Crystal::Compiler
inherits Reference

Main interface to the compiler.

A Compiler parses source code, type checks it and optionally generates an executable.

Constants

CC = ENV["CC"]? || "cc"

CL = "cl.exe"

Methods

#cleanup=(cleanup)

By default the compiler cleans up the default cache directory to keep the most recent 10 directories used. If this is set to false that cleanup is not performed.

View source

#cleanup? : Bool

By default the compiler cleans up the default cache directory to keep the most recent 10 directories used. If this is set to false that cleanup is not performed.

View source

#codegen_target : Crystal::Codegen::Target

Codegen target to use in the compilation. If not set, asks LLVM the default one for the current machine.

View source

#codegen_target=(codegen_target)

Codegen target to use in the compilation. If not set, asks LLVM the default one for the current machine.

View source

#color=(color)

If false, color won't be used in output messages.

View source

#color? : Bool

If false, color won't be used in output messages.

View source

#compile(source : Source | Array(Source), output_filename : String) : Result

Compiles the given source, with output_filename as the name of the generated executable.

Raises Crystal::CodeError if there's an error in the source code.

Raises InvalidByteSequenceError if the source code is not valid UTF-8.

View source

#cross_compile : Bool

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.

View source

#cross_compile=(cross_compile)

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.

View source

#debug : Crystal::Debug

If true, the executable will be generated with debug code that can be understood by gdb and lldb.

View source

#debug=(debug)

If true, the executable will be generated with debug code that can be understood by gdb and lldb.

View source

#dump_ll=(dump_ll)

If true, .ll files will be generated in the default cache directory for each generated LLVM module.

View source

#dump_ll? : Bool

If true, .ll files will be generated in the default cache directory for each generated LLVM module.

View source

#emit : EmitTarget?

Can be set to a set of flags to emit other files other than the executable file: * asm: assembly files * llvm-bc: LLVM bitcode * llvm-ir: LLVM IR * obj: object file

View source

#emit=(emit : EmitTarget?)

Can be set to a set of flags to emit other files other than the executable file: * asm: assembly files * llvm-bc: LLVM bitcode * llvm-ir: LLVM IR * obj: object file

View source

#emit_base_filename : String?

Base filename to use for emit output.

View source

#emit_base_filename=(emit_base_filename : String?)

Base filename to use for emit output.

View source

#error_on_warnings : Bool

If true compiler will error if warnings are found.

View source

#error_on_warnings=(error_on_warnings : Bool)

If true compiler will error if warnings are found.

View source

#flags : Array(String)

Compiler flags. These will be true when checked in macro code by the flag?(...) macro method.

View source

#flags=(flags)

Compiler flags. These will be true when checked in macro code by the flag?(...) macro method.

View source

Additional link flags to pass to the linker.

View source

Additional link flags to pass to the linker.

View source

#mattr : String?

Sets the mattr (features). Check LLVM docs to learn about this.

View source

#mattr=(mattr : String?)

Sets the mattr (features). Check LLVM docs to learn about this.

View source

#mcmodel : LLVM::CodeModel

Sets the code model. Check LLVM docs to learn about this.

View source

#mcmodel=(mcmodel)

Sets the code model. Check LLVM docs to learn about this.

View source

#mcpu : String?

Sets the mcpu. Check LLVM docs to learn about this.

View source

#mcpu=(mcpu : String?)

Sets the mcpu. Check LLVM docs to learn about this.

View source

#n_threads : Int32

Maximum number of LLVM modules that are compiled in parallel

View source

#n_threads=(n_threads : Int32)

Maximum number of LLVM modules that are compiled in parallel

View source

#no_cleanup=(no_cleanup)

If true, skip cleanup process on semantic analysis.

View source

#no_cleanup? : Bool

If true, skip cleanup process on semantic analysis.

View source

#no_codegen=(no_codegen)

If true, no executable will be generated after compilation (useful to type-check a program)

View source

#no_codegen? : Bool

If true, no executable will be generated after compilation (useful to type-check a program)

View source

#prelude : String

Default prelude file to use. This ends up adding a require "prelude" (or whatever name is set here) to the source file to compile.

View source

#prelude=(prelude)

Default prelude file to use. This ends up adding a require "prelude" (or whatever name is set here) to the source file to compile.

View source

#program : Program

Program that was created for the last compilation.

#program=(program : Program)

Program that was created for the last compilation.

View source

#program? : Program?

Program that was created for the last compilation.

#progress_tracker : Crystal::ProgressTracker

A ProgressTracker object which tracks compilation progress.

View source

#progress_tracker=(progress_tracker)

A ProgressTracker object which tracks compilation progress.

View source

#release=(release)

If true, runs LLVM optimizations.

View source

#release? : Bool

If true, runs LLVM optimizations.

View source

#show_error_trace=(show_error_trace)

Whether to show error trace

View source

#show_error_trace? : Bool

Whether to show error trace

View source

#single_module=(single_module)

If true, generates a single LLVM module. By default one LLVM module is created for each type in a program.

View source

#single_module? : Bool

If true, generates a single LLVM module. By default one LLVM module is created for each type in a program.

View source

#static=(static)

Whether to link statically

View source

#static? : Bool

Whether to link statically

View source

#stderr : IO

Default standard error to use in a compilation.

View source

#stderr=(stderr : IO)

Default standard error to use in a compilation.

View source

#stdout : IO

Default standard output to use in a compilation.

View source

#stdout=(stdout : IO)

Default standard output to use in a compilation.

View source

#target_machine : LLVM::TargetMachine

View source

#thin_lto : Bool

Whether to use llvm ThinLTO for linking

View source

#thin_lto=(thin_lto)

Whether to use llvm ThinLTO for linking

View source

#top_level_semantic(source : Source | Array(Source)) : Result

Runs the semantic pass on the given source, without generating an executable nor analyzing methods. The returned Program in the result will contain all types and methods. This can be useful to generate API docs, analyze type relationships, etc.

Raises Crystal::CodeError if there's an error in the source code.

Raises InvalidByteSequenceError if the source code is not valid UTF-8.

View source

#verbose=(verbose)

If true, prints the link command line that is performed to create the executable.

View source

#verbose? : Bool

If true, prints the link command line that is performed to create the executable.

View source

#wants_doc=(wants_doc)

If true, doc comments are attached to types and methods and can later be used to generate API docs.

View source

#wants_doc? : Bool

If true, doc comments are attached to types and methods and can later be used to generate API docs.

View source

#warnings : Warnings

Which kind of warnings wants to be detected.

View source

#warnings=(warnings : Warnings)

Which kind of warnings wants to be detected.

View source

#warnings_exclude : Array(String)

Paths to ignore for warnings detection.

View source

#warnings_exclude=(warnings_exclude : Array(String))

Paths to ignore for warnings detection.

View source