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"
¶
ENV["CC"]? || "cc"
CL = "cl.exe"
¶
"cl.exe"
Methods¶
#cleanup=(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.
#cleanup? : Bool
¶
: 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.
#codegen_target : Crystal::Codegen::Target
¶
: Crystal::Codegen::Target
Codegen target to use in the compilation. If not set, asks LLVM the default one for the current machine.
#codegen_target=(codegen_target)
¶
(codegen_target)
Codegen target to use in the compilation. If not set, asks LLVM the default one for the current machine.
#compile(source : Source | Array(Source), output_filename : String) : Result
¶
(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.
#cross_compile : Bool
¶
: 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.
#cross_compile=(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.
#debug : Crystal::Debug
¶
: Crystal::Debug
If true
, the executable will be generated with debug code
that can be understood by gdb
and lldb
.
#debug=(debug)
¶
(debug)
If true
, the executable will be generated with debug code
that can be understood by gdb
and lldb
.
#dump_ll=(dump_ll)
¶
(dump_ll)
If true
, .ll
files will be generated in the default cache
directory for each generated LLVM module.
#dump_ll? : Bool
¶
: Bool
If true
, .ll
files will be generated in the default cache
directory for each generated LLVM module.
#emit : EmitTarget?
¶
: 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
#emit=(emit : EmitTarget?)
¶
(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
#emit_base_filename=(emit_base_filename : String?)
¶
(emit_base_filename : String?)
Base filename to use for emit
output.
#error_on_warnings=(error_on_warnings : Bool)
¶
(error_on_warnings : Bool)
If true
compiler will error if warnings are found.
#flags : Array(String)
¶
: Array(String)
Compiler flags. These will be true when checked in macro
code by the flag?(...)
macro method.
#flags=(flags)
¶
(flags)
Compiler flags. These will be true when checked in macro
code by the flag?(...)
macro method.
#mattr=(mattr : String?)
¶
(mattr : String?)
Sets the mattr (features). Check LLVM docs to learn about this.
#n_threads=(n_threads : Int32)
¶
(n_threads : Int32)
Maximum number of LLVM modules that are compiled in parallel
#no_codegen=(no_codegen)
¶
(no_codegen)
If true
, no executable will be generated after compilation
(useful to type-check a program)
#no_codegen? : Bool
¶
: Bool
If true
, no executable will be generated after compilation
(useful to type-check a program)
#prelude : String
¶
: 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.
#prelude=(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.
#progress_tracker : Crystal::ProgressTracker
¶
: Crystal::ProgressTracker
A ProgressTracker
object which tracks compilation progress.
#progress_tracker=(progress_tracker)
¶
(progress_tracker)
A ProgressTracker
object which tracks compilation progress.
#single_module=(single_module)
¶
(single_module)
If true
, generates a single LLVM module. By default
one LLVM module is created for each type in a program.
#single_module? : Bool
¶
: Bool
If true
, generates a single LLVM module. By default
one LLVM module is created for each type in a program.
#top_level_semantic(source : Source | Array(Source)) : Result
¶
(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.
#verbose=(verbose)
¶
(verbose)
If true
, prints the link command line that is performed
to create the executable.
#verbose? : Bool
¶
: Bool
If true
, prints the link command line that is performed
to create the executable.
#wants_doc=(wants_doc)
¶
(wants_doc)
If true
, doc comments are attached to types and methods
and can later be used to generate API docs.
#wants_doc? : Bool
¶
: Bool
If true
, doc comments are attached to types and methods
and can later be used to generate API docs.
#warnings_exclude=(warnings_exclude : Array(String))
¶
(warnings_exclude : Array(String))
Paths to ignore for warnings detection.