For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).
compile_info
def compile_info[func_type: TrivialRegisterPassable, //, func: func_type, /, *, emission_kind: StringSlice[StaticConstantOrigin] = StringSlice("asm"), target: __mlir_type.`!kgen.target` = _current_target(), compile_options: StringSlice[StaticConstantOrigin] = CompilationTarget.default_compile_options(), link_options: StringSlice[StaticConstantOrigin] = StringSlice("")]() -> CompiledFunctionInfo[func_type, func, target]
Compiles a function and returns detailed compilation information.
This function takes a Mojo function and compiles it, providing access to the generated assembly code, linkage information, and other compilation artifacts. It can be used for inspection, debugging, and low-level optimization.
Example:
from std.compile import compile_info
def my_func(x: Int) -> Int:
return x
info = compile_info[my_func]()
print(info) # Print assembly
Note: The compilation is always performed, even if the function is not used. For performance-critical code, consider caching the compilation results.
Parameters:
- func_type (
TrivialRegisterPassable): Type of the function to compile. Must be a trivially-copyable register type. - func (
func_type): The function to compile. Must match the specified func_type. - emission_kind (
StringSlice[StaticConstantOrigin]): The desired output format. Valid options are:- "asm": Assembly code (default).
- "llvm": Unoptimized LLVM IR.
- "llvm-opt": Optimized LLVM IR.
- "object": Object code.
- target (
__mlir_type.`!kgen.target`): The target architecture to compile for. Defaults to current architecture. - compile_options (
StringSlice[StaticConstantOrigin]): Additional compiler flags and options as a string. - link_options (
StringSlice[StaticConstantOrigin]): Additional linking flags and options as a string.
Returns:
CompiledFunctionInfo[func_type, func, target]: A CompiledFunctionInfo struct containing:
- asm: The generated code in the requested format
- linkage_name: The mangled function name for linking
- module_hash: A unique hash of the compiled module
- num_captures: Number of captured variables
- error: Any error message (empty if successful)
- failed: Boolean indicating if compilation failed