class
Crystal::Compiler
Overview
Main interface to the compiler.
A Compiler parses source code, type checks it and optionally generates an executable.
Defined in:
compiler/crystal/compiler.crConstant Summary
-
DEFAULT_LINKER =
ENV["CC"]? || ({{ (env("CRYSTAL_CONFIG_CC")) || "cc" }}) -
MSVC_LINKER =
ENV["CC"]? || ({{ (env("CRYSTAL_CONFIG_CC")) || "cl.exe" }})
Instance Method Summary
-
#cleanup=(cleanup : Bool)
By default the compiler cleans up the default cache directory to keep the most recent 10 directories used.
-
#cleanup? : Bool
By default the compiler cleans up the default cache directory to keep the most recent 10 directories used.
-
#codegen_target : Crystal::Codegen::Target
Codegen target to use in the compilation.
-
#codegen_target=(codegen_target : Crystal::Codegen::Target)
Codegen target to use in the compilation.
-
#color=(color : Bool)
If
false, color won't be used in output messages. -
#color? : Bool
If
false, color won't be used in output messages. -
#compile(source : Source | Array(Source), output_filename : String) : Result
Compiles the given source, with output_filename as the name of the generated executable.
-
#compile_configure_program(source : Source | Array(Source), output_filename : String, & : Program -> Nil) : Result
Compiles the given source, with output_filename as the name of the generated executable.
- #create_target_machine
-
#cross_compile=(cross_compile : Bool)
If
true, doesn't generate an executable but instead creates a.ofile and outputs a command line to link it in the target machine. -
#cross_compile? : Bool
If
true, doesn't generate an executable but instead creates a.ofile and outputs a command line to link it in the target machine. -
#debug : Crystal::Debug
If
true, the executable will be generated with debug code that can be understood bygdbandlldb. -
#debug=(debug : Crystal::Debug)
If
true, the executable will be generated with debug code that can be understood bygdbandlldb. - #dependency_printer : DependencyPrinter | Nil
- #dependency_printer=(dependency_printer : DependencyPrinter | Nil)
-
#dump_ll=(dump_ll : Bool)
If
true,.llfiles will be generated in the default cache directory for each generated LLVM module. -
#dump_ll? : Bool
If
true,.llfiles will be generated in the default cache directory for each generated LLVM module. -
#emit_base_filename : String | Nil
Base filename to use for
emitoutput. -
#emit_base_filename=(emit_base_filename : String | Nil)
Base filename to use for
emitoutput. -
#emit_targets : 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_targets=(emit_targets : 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
-
#flags : Array(String)
Compiler flags.
-
#flags=(flags : Array(String))
Compiler flags.
-
#frame_pointers : Crystal::FramePointers
Controls generation of frame pointers.
-
#frame_pointers=(frame_pointers : Crystal::FramePointers)
Controls generation of frame pointers.
-
#link_flags : String | Nil
Additional link flags to pass to the linker.
-
#link_flags=(link_flags : String | Nil)
Additional link flags to pass to the linker.
-
#mattr : String | Nil
Sets the mattr (features).
-
#mattr=(mattr : String | Nil)
Sets the mattr (features).
-
#mcmodel : LLVM::CodeModel
Sets the code model.
-
#mcmodel=(mcmodel : LLVM::CodeModel)
Sets the code model.
-
#mcpu : String | Nil
Sets the mcpu.
-
#mcpu=(mcpu : String | Nil)
Sets the mcpu.
-
#n_threads : Int32
Maximum number of LLVM modules that are compiled in parallel
-
#n_threads=(n_threads : Int32)
Maximum number of LLVM modules that are compiled in parallel
-
#no_cleanup=(no_cleanup : Bool)
If
true, skip cleanup process on semantic analysis. -
#no_cleanup? : Bool
If
true, skip cleanup process on semantic analysis. -
#no_codegen=(no_codegen : Bool)
If
true, no executable will be generated after compilation (useful to type-check a program) -
#no_codegen? : Bool
If
true, no executable will be generated after compilation (useful to type-check a program) -
#optimization_mode : Crystal::Compiler::OptimizationMode
Sets the Optimization mode.
-
#optimization_mode=(optimization_mode : Crystal::Compiler::OptimizationMode)
Sets the Optimization mode.
-
#prelude : String
Default prelude file to use.
-
#prelude=(prelude : String)
Default prelude file to use.
-
#program : Program
Program that was created for the last compilation.
-
#program=(program : Program)
Program that was created for the last compilation.
-
#program? : Program | Nil
Program that was created for the last compilation.
-
#progress_tracker : Crystal::ProgressTracker
A
ProgressTrackerobject which tracks compilation progress. -
#progress_tracker=(progress_tracker : Crystal::ProgressTracker)
A
ProgressTrackerobject which tracks compilation progress. -
#release!
Set maximum level of optimization.
- #release?
-
#show_error_trace=(show_error_trace : Bool)
Whether to show error trace
-
#show_error_trace? : Bool
Whether to show error trace
-
#single_module=(single_module : Bool)
If
true, generates a single LLVM module. -
#single_module? : Bool
If
true, generates a single LLVM module. -
#static=(static : Bool)
Whether to link statically
-
#static? : Bool
Whether to link statically
-
#stderr : IO
Default standard error to use in a compilation.
-
#stderr=(stderr : IO)
Default standard error to use in a compilation.
-
#stdout : IO
Default standard output to use in a compilation.
-
#stdout=(stdout : IO)
Default standard output to use in a compilation.
- #target_machine : LLVM::TargetMachine
-
#top_level_semantic(source : Source | Array(Source)) : Result
Runs the semantic pass on the given source, without generating an executable nor analyzing methods.
-
#verbose=(verbose : Bool)
If
true, prints the link command line that is performed to create the executable. -
#verbose? : Bool
If
true, prints the link command line that is performed to create the executable. -
#wants_doc=(wants_doc : Bool)
If
true, doc comments are attached to types and methods and can later be used to generate API docs. -
#wants_doc? : Bool
If
true, doc comments are attached to types and methods and can later be used to generate API docs. -
#warnings : Crystal::WarningCollection
Warning settings and all detected warnings.
-
#warnings=(warnings : Crystal::WarningCollection)
Warning settings and all detected warnings.
Instance methods inherited from class Reference
==(other : self)==(other : JSON::Any)
==(other : YAML::Any)
==(other) ==, dup dup, hash(hasher) hash, initialize initialize, inspect(io : IO) : Nil inspect, object_id : UInt64 object_id, pretty_print(pp) : Nil pretty_print, same?(other : Reference) : Bool
same?(other : Nil) same?, to_s(io : IO) : Nil to_s
Constructor methods inherited from class Reference
new
new,
unsafe_construct(address : Pointer, *args, **opts) : self
unsafe_construct
Class methods inherited from class Reference
pre_initialize(address : Pointer)
pre_initialize
Instance methods inherited from class Object
! : Bool
!,
!=(other)
!=,
!~(other)
!~,
==(other)
==,
===(other : JSON::Any)===(other : YAML::Any)
===(other) ===, =~(other) =~, as(type : Class) as, as?(type : Class) as?, class class, dup dup, hash(hasher)
hash hash, in?(collection : Object) : Bool
in?(*values : Object) : Bool in?, inspect(io : IO) : Nil
inspect : String inspect, is_a?(type : Class) : Bool is_a?, itself itself, nil? : Bool nil?, not_nil!(message)
not_nil! not_nil!, pretty_inspect(width = 79, newline = "\n", indent = 0) : String pretty_inspect, pretty_print(pp : PrettyPrint) : Nil pretty_print, responds_to?(name : Symbol) : Bool responds_to?, tap(&) tap, to_json(io : IO) : Nil
to_json : String to_json, to_pretty_json(indent : String = " ") : String
to_pretty_json(io : IO, indent : String = " ") : Nil to_pretty_json, to_s(io : IO) : Nil
to_s : String to_s, to_yaml(io : IO) : Nil
to_yaml : String to_yaml, try(&) try, unsafe_as(type : T.class) forall T unsafe_as
Class methods inherited from class Object
from_json(string_or_io : String | IO, root : String)from_json(string_or_io : String | IO) from_json, from_yaml(string_or_io : String | IO) from_yaml
Macros inherited from class Object
class_getter(*names, &block)
class_getter,
class_getter!(*names)
class_getter!,
class_getter?(*names, &block)
class_getter?,
class_property(*names, &block)
class_property,
class_property!(*names)
class_property!,
class_property?(*names, &block)
class_property?,
class_setter(*names)
class_setter,
def_clone
def_clone,
def_equals(*fields)
def_equals,
def_equals_and_hash(*fields)
def_equals_and_hash,
def_hash(*fields)
def_hash,
delegate(*methods, to object)
delegate,
forward_missing_to(delegate)
forward_missing_to,
getter(*names, &block)
getter,
getter!(*names)
getter!,
getter?(*names, &block)
getter?,
property(*names, &block)
property,
property!(*names)
property!,
property?(*names, &block)
property?,
setter(*names)
setter
Instance Method Detail
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.
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 to use in the compilation. If not set, asks LLVM the default one for the current machine.
Codegen target to use in the compilation. If not set, asks LLVM the default one for the current machine.
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.
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.
Yields a Program instance before compiling.
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.
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.
If true, the executable will be generated with debug code
that can be understood by gdb and lldb.
If true, the executable will be generated with debug code
that can be understood by gdb and lldb.
If true, .ll files will be generated in the default cache
directory for each generated LLVM module.
If true, .ll files will be generated in the default cache
directory for each generated LLVM module.
Base filename to use for emit output.
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
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
Compiler flags. These will be true when checked in macro
code by the flag?(...) macro method.
Compiler flags. These will be true when checked in macro
code by the flag?(...) macro method.
Controls generation of frame pointers.
Additional link flags to pass to the linker.
Sets the mattr (features). Check LLVM docs to learn about this.
Sets the mattr (features). Check LLVM docs to learn about this.
Maximum number of LLVM modules that are compiled in parallel
If true, skip cleanup process on semantic analysis.
If true, no executable will be generated after compilation
(useful to type-check a program)
If true, no executable will be generated after compilation
(useful to type-check a program)
Sets the Optimization mode.
Default prelude file to use. This ends up adding a
require "prelude" (or whatever name is set here) to
the source file to compile.
Default prelude file to use. This ends up adding a
require "prelude" (or whatever name is set here) to
the source file to compile.
A ProgressTracker object which tracks compilation progress.
A ProgressTracker object which tracks compilation progress.
If true, generates a single LLVM module. By default
one LLVM module is created for each type in a program.
--release automatically enable this option
If true, generates a single LLVM module. By default
one LLVM module is created for each type in a program.
--release automatically enable this option
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.
If true, prints the link command line that is performed
to create the executable.
If true, prints the link command line that is performed
to create the executable.
If true, doc comments are attached to types and methods
and can later be used to generate API docs.
If true, doc comments are attached to types and methods
and can later be used to generate API docs.