llvm
Building, optimizing, running and linking code with LLVM.
import llvm
LLVM is the compiler infrastructure that also backs Salam. With this package you can build your own compiler or interpreter: make a Context and a Module, write the instructions with a Builder, test the module with Verify and then run it with the JIT or turn it into an object file.
If you have the IR as text, Run does the whole pipeline with one Options. For linking, LLD works inside the program itself for Linux with musl, Windows with MinGW and WASI; for the rest LinkExternal calls the system linker.
This package needs the libsalam_llvm library. The examples on the site are only checked.
Types
OptResult
struct OptResult| Name | Type | Description |
|---|---|---|
ok | bool = false | It worked. |
err | str = "" | The error message. |
import llvm
import os
func build(ctx: llvm.Context): llvm.Module:
mod := llvm.NewModule(ctx, "calc")
b := llvm.NewBuilder(ctx)
i32 := llvm.Int32Type(ctx)
mut two := Vector {} as Vector<llvm.Type>
two.push(i32)
two.push(i32)
fn := llvm.AddFunction(mod, "salam_add", llvm.FunctionType(i32, two, false))
llvm.PositionAtEnd(b, llvm.AppendBlock(ctx, fn, "entry"))
_ := llvm.Ret(b, llvm.Add(b, llvm.Param(fn, 0), llvm.Param(fn, 1), "s"))
llvm.FreeBuilder(b)
ret mod
end
func main:
llvm.InitTargets()
println llvm.DefaultTriple().len() > 0
println llvm.CodeGenLevelOf(llvm.OPT_O2) == llvm.CODEGEN_LEVEL_DEFAULT, llvm.PassPipelineOf(llvm.OPT_O3)
println llvm.OPT_O0, llvm.OPT_O1, llvm.OPT_OS, llvm.OPT_OZ
println llvm.CODEGEN_LEVEL_NONE, llvm.CODEGEN_LEVEL_LESS, llvm.CODEGEN_LEVEL_AGGRESSIVE
println llvm.CODEGEN_FILE_ASSEMBLY, llvm.CODEGEN_FILE_OBJECT, llvm.RELOC_DEFAULT, llvm.RELOC_PIC, llvm.CODE_MODEL_DEFAULT
machine := llvm.NewTargetMachine("", llvm.OPT_O2, false)
if not machine.ok:
println "the target machine was not built:", machine.err
ret
end
ctx := llvm.NewContext()
mod := build(ctx)
llvm.ApplyDataLayout(mod, machine.tm)
optimized := llvm.RunOpt(mod, machine.tm, llvm.OPT_O2)
println optimized.ok
dir := os.TempDir()
println llvm.EmitAsm(mod, machine.tm, dir + "/salam_add_en.s").ok
println llvm.EmitObject(mod, machine.tm, dir + "/salam_add_en.o").ok
println llvm.EmitBitcode(mod, dir + "/salam_add_en.bc").ok
println llvm.ParallelJobs() > 0
parts := llvm.ParallelPartitions(mod, 4)
println parts >= 1
mod2 := build(ctx)
parallel := llvm.OptimizeEmitParallel(mod2, machine.tm, llvm.OPT_O2, 2, dir + "/salam_part_en")
println parallel.ok, parallel.objects.len() >= 1
llvm.FreeModule(mod)
llvm.FreeModule(mod2)
llvm.FreeTargetMachine(machine.tm)
llvm.FreeContext(ctx)
endRunResult
struct RunResult| Name | Type | Description |
|---|---|---|
ok | bool = false | It worked. |
rc | int = 0 | What main returned. |
err | str = "" | The error message. |
import llvm
import io
import os
func main:
ctx := llvm.NewContext()
mod := llvm.NewModule(ctx, "fib")
b := llvm.NewBuilder(ctx)
i32 := llvm.Int32Type(ctx)
none := Vector {} as Vector<llvm.Type>
main_type := llvm.FunctionType(i32, none, false)
entry_fn := llvm.AddFunction(mod, "main", main_type)
start := llvm.AppendBlock(ctx, entry_fn, "entry")
body := llvm.AppendBlock(ctx, entry_fn, "loop")
tail := llvm.AppendBlock(ctx, entry_fn, "done")
llvm.PositionAtEnd(b, start)
_ := llvm.Br(b, body)
llvm.PositionAtEnd(b, body)
counter := llvm.Phi(b, i32, "i")
a := llvm.Phi(b, i32, "a")
c := llvm.Phi(b, i32, "b")
total := llvm.Add(b, a, c, "sum")
next := llvm.Add(b, counter, llvm.ConstInt(i32, 1), "inext")
more := llvm.ICmp(b, llvm.INT_SLT, next, llvm.ConstInt(i32, 10), "more")
_ := llvm.CondBr(b, more, body, tail)
mut sources := Vector {} as Vector<llvm.BasicBlock>
sources.push(start)
sources.push(body)
mut counter_in := Vector {} as Vector<llvm.Value>
counter_in.push(llvm.ConstInt(i32, 0))
counter_in.push(next)
llvm.AddIncoming(counter, counter_in, sources)
mut a_in := Vector {} as Vector<llvm.Value>
a_in.push(llvm.ConstInt(i32, 0))
a_in.push(c)
llvm.AddIncoming(a, a_in, sources)
mut c_in := Vector {} as Vector<llvm.Value>
c_in.push(llvm.ConstInt(i32, 1))
c_in.push(total)
llvm.AddIncoming(c, c_in, sources)
llvm.PositionAtEnd(b, tail)
_ := llvm.Ret(b, c)
checked := llvm.Verify(mod)
println checked.ok
print llvm.ModuleToString(mod)
path := os.TempDir() + "/salam_fib_en.ll"
_ := io.WriteFile(path, llvm.ModuleToString(mod))
r := llvm.RunJIT(path)
println r.ok, r.rc
llvm.FreeBuilder(b)
llvm.FreeModule(mod)
llvm.FreeContext(ctx)
endType
struct Type| Name | Type | Description |
|---|---|---|
handle | void* | The internal LLVM handle. |
The example for this item is shown with the ones above: llvm-Build.salam
Value
struct Value| Name | Type | Description |
|---|---|---|
handle | void* | The internal LLVM handle. |
The example for this item is shown with the ones above: llvm-Build.salam
BasicBlock
struct BasicBlock| Name | Type | Description |
|---|---|---|
handle | void* | The internal LLVM handle. |
The example for this item is shown with the ones above: llvm-Build.salam
Builder
struct Builder| Name | Type | Description |
|---|---|---|
handle | void* | The internal LLVM handle. |
The example for this item is shown with the ones above: llvm-Build.salam
ParallelResult
struct ParallelResult| Name | Type | Description |
|---|---|---|
ok | bool = false | It worked. |
err | str = "" | The error message. |
objects | Vector | The object files that were built. |
The example for this item is shown with the ones above: llvm-Target.salam
LinkResult
struct LinkResult| Name | Type | Description |
|---|---|---|
ok | bool = false | It worked. |
err | str = "" | The error message. |
import llvm
import io
import os
import mem
func main:
println llvm.Available()
dir := os.TempDir()
ll := dir + "/salam_args_en.ll"
_ := io.WriteFile(ll, `define i32 @main(i32 %argc, ptr %argv) {
entry:
%n = mul i32 %argc, 10
ret i32 %n
}
`)
parsed := llvm.ParseIR(ll)
println parsed.ok
checked := llvm.Verify(parsed.mod)
println checked.ok, llvm.VERIFY_RETURN_STATUS
llvm.SetTargetTriple(parsed.mod, llvm.DefaultTriple())
println llvm.TargetTripleOf(parsed.mod) == llvm.DefaultTriple()
llvm.FreeModule(parsed.mod)
llvm.FreeContext(parsed.ctx)
mut args := Vector {} as Vector<str>
args.push("a")
args.push("b")
println llvm.RunJITArgs(ll, args).rc
mut opts := llvm.OptionsDefault()
println opts.opt_level, opts.output_mode
opts.output_mode = llvm.OUT_JIT
opts.run_args = args
println llvm.Run(ll, opts).rc
opts.output_mode = llvm.OUT_OBJ
opts.output_file = dir + "/salam_args_en.o"
println llvm.Run(ll, opts).ok
opts.output_mode = llvm.OUT_ASM
opts.output_file = dir + "/salam_args_en.s"
println llvm.Run(ll, opts).ok
println llvm.OUT_IR, llvm.OUT_BITCODE, llvm.OUT_EXEC
println llvm.HostLinkTriple(), llvm.LldAvailable()
println llvm.CanLinkTriple("x86_64-unknown-linux-musl"), llvm.CanLinkTriple("x86_64-w64-windows-gnu"), llvm.CanLinkTriple("aarch64-apple-darwin")
println llvm.LLD_ELF, llvm.LLD_MINGW, llvm.LLD_COFF, llvm.LLD_MACHO, llvm.LLD_WASM
linked := llvm.LinkExternal(dir + "/salam_args_en.o", dir + "/salam_args_en", llvm.OptionsDefault())
println linked.ok, linked.err
if linked.ok:
println os.Run(dir + "/salam_args_en x y")
end
mut musl := llvm.OptionsDefault()
musl.target_triple = "x86_64-unknown-linux-musl"
println llvm.LinkAuto(dir + "/salam_args_en.o", dir + "/salam_args_en_musl", musl).ok
_ := llvm.LinkElf(dir + "/a.o", dir + "/a", musl)
_ := llvm.LinkMingw(dir + "/a.o", dir + "/a.exe", musl)
_ := llvm.LinkWasi(dir + "/a.o", dir + "/a.wasm", musl)
mut argv := mem.Allocate(64 as u64) as str*
argv[0] = "ld.lld"
argv[1] = "--version"
println llvm.Link(llvm.LLD_ELF, argv as void*, 2)
mem.Free(argv as void*)
endEmitResult
struct EmitResult| Name | Type | Description |
|---|---|---|
ok | bool = false | It worked. |
err | str = "" | The error message. |
The example for this item is shown with the ones above: llvm-Target.salam
Context
struct Context| Name | Type | Description |
|---|---|---|
handle | void* | The internal LLVM handle. |
The example for this item is shown with the ones above: llvm-Build.salam
Module
struct Module| Name | Type | Description |
|---|---|---|
handle | void* | The internal LLVM handle. |
The example for this item is shown with the ones above: llvm-Build.salam
ParseResult
struct ParseResult| Name | Type | Description |
|---|---|---|
ctx | Context | The context that was made; free it too. |
mod | Module | The module. |
ok | bool = false | It worked. |
err | str = "" | The error message. |
The example for this item is shown with the ones above: llvm-Run.salam
VerifyResult
struct VerifyResult| Name | Type | Description |
|---|---|---|
ok | bool = false | The module is correct. |
err | str = "" | What the error is. |
The example for this item is shown with the ones above: llvm-Build.salam
Options
struct OptionsRun pipeline.| Name | Type | Description |
|---|---|---|
opt_level | int = 0 | The optimization level. |
debug_info | bool = false | Keep the debug information. |
verify_module | bool = false | Verify the module before generating. |
native_cpu | bool = false | Optimize for this machine's own CPU. |
output_mode | int = 0 | The output kind, one of the OUT_... constants. |
output_file | str = "" | The output path. |
target_triple | str = "" | The target triple; empty means the module's triple. |
link_libs | Vector | The libraries that are linked. |
link_kinds | Vector | Each library's kind: static or dynamic. |
sysroot | str = "" | The target system's root for cross linking. |
lib_paths | Vector | The library search paths. |
extra_objects | Vector | Other object files to link. |
run_args | Vector | The arguments for running with the JIT. |
The example for this item is shown with the ones above: llvm-Run.salam
Output
struct OutputRun.| Name | Type | Description |
|---|---|---|
ok | bool = false | It worked. |
error | str = "" | The error message. |
rc | int = 0 | The program's exit code in JIT mode. |
The example for this item is shown with the ones above: llvm-Build.salam
TargetMachine
struct TargetMachine| Name | Type | Description |
|---|---|---|
handle | void* | The internal LLVM handle. |
The example for this item is shown with the ones above: llvm-Target.salam
TargetData
struct TargetData| Name | Type | Description |
|---|---|---|
handle | void* | The internal LLVM handle. |
The example for this item is shown with the ones above: llvm-Target.salam
TargetMachineResult
struct TargetMachineResult| Name | Type | Description |
|---|---|---|
tm | TargetMachine | The target machine. |
ok | bool = false | It worked. |
err | str = "" | The error message. |
The example for this item is shown with the ones above: llvm-Target.salam
Constants and variables
INT_EQ
const INT_EQ: i32 = 32import llvm
import io
import os
func main:
ctx := llvm.NewContext()
mod := llvm.NewModule(ctx, "hello")
b := llvm.NewBuilder(ctx)
i32 := llvm.Int32Type(ctx)
i64 := llvm.Int64Type(ctx)
f64 := llvm.DoubleType(ctx)
ptr := llvm.PointerType(ctx)
_ := llvm.Int1Type(ctx)
_ := llvm.Int8Type(ctx)
_ := llvm.Int16Type(ctx)
_ := llvm.FloatType(ctx)
_ := llvm.ArrayType(i32, 4)
mut fmt_params := Vector {} as Vector<llvm.Type>
fmt_params.push(ptr)
fmt_type := llvm.FunctionType(i32, fmt_params, true)
_ := llvm.AddFunction(mod, "printf", fmt_type)
printer := llvm.NamedFunction(mod, "printf")
mut two_numbers := Vector {} as Vector<llvm.Type>
two_numbers.push(i64)
two_numbers.push(i64)
calc_type := llvm.FunctionType(i64, two_numbers, false)
calc := llvm.AddFunction(mod, "calc", calc_type)
llvm.SetLinkage(calc, llvm.LINKAGE_INTERNAL)
llvm.PositionAtEnd(b, llvm.AppendBlock(ctx, calc, "entry"))
l := llvm.Param(calc, 0)
r := llvm.Param(calc, 1)
t := llvm.Sub(b, llvm.Mul(b, l, r, "m"), llvm.SDiv(b, l, r, "d"), "t")
_ := llvm.Ret(b, llvm.Add(b, t, llvm.SRem(b, l, r, "r"), "x"))
count := llvm.AddGlobal(mod, i64, "count")
llvm.SetInitializer(count, llvm.ConstInt(i64, 40))
pi := llvm.AddGlobal(mod, f64, "pi")
llvm.SetInitializer(pi, llvm.ConstReal(f64, 3.14))
llvm.SetGlobalConstant(pi, true)
none := Vector {} as Vector<llvm.Type>
entry_fn := llvm.AddFunction(mod, "main", llvm.FunctionType(i32, none, false))
llvm.PositionAtEnd(b, llvm.AppendBlock(ctx, entry_fn, "entry"))
println llvm.InsertBlock(b).handle != null
slot := llvm.Alloca(b, i64, "n")
_ := llvm.Store(b, llvm.Load(b, i64, count, "c"), slot)
mut args := Vector {} as Vector<llvm.Value>
args.push(llvm.Load(b, i64, slot, "n1"))
args.push(llvm.ConstInt(i64, 8))
result := llvm.Call(b, calc_type, calc, args, "v")
mut fmt_args := Vector {} as Vector<llvm.Value>
fmt_args.push(llvm.GlobalString(b, "calc(40, 8) = %lld\n", "fmt"))
fmt_args.push(result)
_ := llvm.Call(b, fmt_type, printer, fmt_args, "")
_ := llvm.Ret(b, llvm.ConstInt(i32, 0))
empty := Vector {} as Vector<llvm.Type>
noop := llvm.AddFunction(mod, "noop", llvm.FunctionType(llvm.VoidType(ctx), empty, false))
llvm.SetLinkage(noop, llvm.LINKAGE_PRIVATE)
llvm.PositionAtEnd(b, llvm.AppendBlock(ctx, noop, "entry"))
_ := llvm.RetVoid(b)
println llvm.LINKAGE_EXTERNAL, llvm.Verify(mod).ok
println llvm.INT_EQ, llvm.INT_NE, llvm.INT_UGT, llvm.INT_UGE, llvm.INT_ULT, llvm.INT_ULE
println llvm.INT_SGT, llvm.INT_SGE, llvm.INT_SLT, llvm.INT_SLE
path := os.TempDir() + "/salam_hello_en.ll"
_ := io.WriteFile(path, llvm.ModuleToString(mod))
println llvm.RunJIT(path).rc
llvm.FreeBuilder(b)
llvm.FreeModule(mod)
llvm.FreeContext(ctx)
endINT_NE
const INT_NE: i32 = 33The example for this item is shown with the ones above: llvm-Program.salam
INT_UGT
const INT_UGT: i32 = 34The example for this item is shown with the ones above: llvm-Program.salam
INT_UGE
const INT_UGE: i32 = 35The example for this item is shown with the ones above: llvm-Program.salam
INT_ULT
const INT_ULT: i32 = 36The example for this item is shown with the ones above: llvm-Program.salam
INT_ULE
const INT_ULE: i32 = 37The example for this item is shown with the ones above: llvm-Program.salam
INT_SGT
const INT_SGT: i32 = 38The example for this item is shown with the ones above: llvm-Program.salam
INT_SGE
const INT_SGE: i32 = 39The example for this item is shown with the ones above: llvm-Program.salam
INT_SLT
const INT_SLT: i32 = 40The example for this item is shown with the ones above: llvm-Build.salam
INT_SLE
const INT_SLE: i32 = 41The example for this item is shown with the ones above: llvm-Program.salam
LINKAGE_EXTERNAL
const LINKAGE_EXTERNAL: i32 = 0The example for this item is shown with the ones above: llvm-Program.salam
LINKAGE_INTERNAL
const LINKAGE_INTERNAL: i32 = 8The example for this item is shown with the ones above: llvm-Program.salam
LINKAGE_PRIVATE
const LINKAGE_PRIVATE: i32 = 9The example for this item is shown with the ones above: llvm-Program.salam
LLD_ELF
const LLD_ELF: i32 = 0The example for this item is shown with the ones above: llvm-Run.salam
LLD_MINGW
const LLD_MINGW: i32 = 1The example for this item is shown with the ones above: llvm-Run.salam
LLD_COFF
const LLD_COFF: i32 = 2The example for this item is shown with the ones above: llvm-Run.salam
LLD_MACHO
const LLD_MACHO: i32 = 3The example for this item is shown with the ones above: llvm-Run.salam
LLD_WASM
const LLD_WASM: i32 = 4The example for this item is shown with the ones above: llvm-Run.salam
VERIFY_RETURN_STATUS
const VERIFY_RETURN_STATUS: i32 = 1The example for this item is shown with the ones above: llvm-Run.salam
OPT_O0
const OPT_O0: i32 = 0The example for this item is shown with the ones above: llvm-Target.salam
OPT_O1
const OPT_O1: i32 = 1The example for this item is shown with the ones above: llvm-Target.salam
OPT_O2
const OPT_O2: i32 = 2The example for this item is shown with the ones above: llvm-Target.salam
OPT_O3
const OPT_O3: i32 = 3The example for this item is shown with the ones above: llvm-Target.salam
OPT_OS
const OPT_OS: i32 = 4The example for this item is shown with the ones above: llvm-Target.salam
OPT_OZ
const OPT_OZ: i32 = 5The example for this item is shown with the ones above: llvm-Target.salam
OUT_IR
const OUT_IR: i32 = 0The example for this item is shown with the ones above: llvm-Run.salam
OUT_ASM
const OUT_ASM: i32 = 1The example for this item is shown with the ones above: llvm-Run.salam
OUT_OBJ
const OUT_OBJ: i32 = 2The example for this item is shown with the ones above: llvm-Run.salam
OUT_BITCODE
const OUT_BITCODE: i32 = 3The example for this item is shown with the ones above: llvm-Run.salam
OUT_EXEC
const OUT_EXEC: i32 = 4The example for this item is shown with the ones above: llvm-Run.salam
OUT_JIT
const OUT_JIT: i32 = 5The example for this item is shown with the ones above: llvm-Run.salam
CODEGEN_FILE_ASSEMBLY
const CODEGEN_FILE_ASSEMBLY: i32 = 0The example for this item is shown with the ones above: llvm-Target.salam
CODEGEN_FILE_OBJECT
const CODEGEN_FILE_OBJECT: i32 = 1The example for this item is shown with the ones above: llvm-Target.salam
CODEGEN_LEVEL_NONE
const CODEGEN_LEVEL_NONE: i32 = 0The example for this item is shown with the ones above: llvm-Target.salam
CODEGEN_LEVEL_LESS
const CODEGEN_LEVEL_LESS: i32 = 1The example for this item is shown with the ones above: llvm-Target.salam
CODEGEN_LEVEL_DEFAULT
const CODEGEN_LEVEL_DEFAULT: i32 = 2The example for this item is shown with the ones above: llvm-Target.salam
CODEGEN_LEVEL_AGGRESSIVE
const CODEGEN_LEVEL_AGGRESSIVE: i32 = 3The example for this item is shown with the ones above: llvm-Target.salam
RELOC_DEFAULT
const RELOC_DEFAULT: i32 = 0The example for this item is shown with the ones above: llvm-Target.salam
RELOC_PIC
const RELOC_PIC: i32 = 2The example for this item is shown with the ones above: llvm-Target.salam
CODE_MODEL_DEFAULT
const CODE_MODEL_DEFAULT: i32 = 0The example for this item is shown with the ones above: llvm-Target.salam
Functions
RunOpt
func RunOpt(mod: Module, tm: TargetMachine, opt_level: int): OptResultThe example for this item is shown with the ones above: llvm-Target.salam
RunJIT
func RunJIT(ll_path: str): RunResult.ll file with the ORC JIT in this same process and calls main.The example for this item is shown with the ones above: llvm-Build.salam
RunJITArgs
func RunJITArgs(ll_path: str, args: Vector<str>): RunResultThe example for this item is shown with the ones above: llvm-Run.salam
NewModule
func NewModule(ctx: Context, name: str): ModuleThe example for this item is shown with the ones above: llvm-Build.salam
ModuleToString
func ModuleToString(mod: Module): strThe example for this item is shown with the ones above: llvm-Build.salam
Int1Type
func Int1Type(c: Context): TypeThe example for this item is shown with the ones above: llvm-Program.salam
Int8Type
func Int8Type(c: Context): TypeThe example for this item is shown with the ones above: llvm-Program.salam
Int16Type
func Int16Type(c: Context): TypeThe example for this item is shown with the ones above: llvm-Program.salam
Int32Type
func Int32Type(c: Context): TypeThe example for this item is shown with the ones above: llvm-Build.salam
Int64Type
func Int64Type(c: Context): TypeThe example for this item is shown with the ones above: llvm-Program.salam
VoidType
func VoidType(c: Context): TypeThe example for this item is shown with the ones above: llvm-Program.salam
FloatType
func FloatType(c: Context): TypeThe example for this item is shown with the ones above: llvm-Program.salam
DoubleType
func DoubleType(c: Context): TypeThe example for this item is shown with the ones above: llvm-Program.salam
PointerType
func PointerType(c: Context): Typeptr pointer type.The example for this item is shown with the ones above: llvm-Program.salam
ArrayType
func ArrayType(elem: Type, n: i64): TypeThe example for this item is shown with the ones above: llvm-Program.salam
FunctionType
func FunctionType(ret_ty: Type, params: Vector<Type>, vararg: bool): TypeThe example for this item is shown with the ones above: llvm-Build.salam
AddFunction
func AddFunction(mod: Module, name: str, fnty: Type): ValueThe example for this item is shown with the ones above: llvm-Build.salam
NamedFunction
func NamedFunction(mod: Module, name: str): ValueThe example for this item is shown with the ones above: llvm-Program.salam
Param
func Param(fn: Value, idx: int): ValueThe example for this item is shown with the ones above: llvm-Program.salam
SetLinkage
func SetLinkage(v: Value, linkage: int)The example for this item is shown with the ones above: llvm-Program.salam
AppendBlock
func AppendBlock(c: Context, fn: Value, name: str): BasicBlockThe example for this item is shown with the ones above: llvm-Build.salam
NewBuilder
func NewBuilder(c: Context): BuilderThe example for this item is shown with the ones above: llvm-Build.salam
PositionAtEnd
func PositionAtEnd(b: Builder, bb: BasicBlock)The example for this item is shown with the ones above: llvm-Build.salam
InsertBlock
func InsertBlock(b: Builder): BasicBlockThe example for this item is shown with the ones above: llvm-Program.salam
FreeBuilder
func FreeBuilder(b: Builder)The example for this item is shown with the ones above: llvm-Build.salam
ConstInt
func ConstInt(ty: Type, v: i64): ValueThe example for this item is shown with the ones above: llvm-Build.salam
ConstReal
func ConstReal(ty: Type, v: f64): ValueThe example for this item is shown with the ones above: llvm-Program.salam
Ret
func Ret(b: Builder, v: Value): ValueThe example for this item is shown with the ones above: llvm-Build.salam
RetVoid
func RetVoid(b: Builder): ValueThe example for this item is shown with the ones above: llvm-Program.salam
Add
func Add(b: Builder, l: Value, r: Value, name: str): ValueThe example for this item is shown with the ones above: llvm-Build.salam
Sub
func Sub(b: Builder, l: Value, r: Value, name: str): ValueThe example for this item is shown with the ones above: llvm-Program.salam
Mul
func Mul(b: Builder, l: Value, r: Value, name: str): ValueThe example for this item is shown with the ones above: llvm-Program.salam
SDiv
func SDiv(b: Builder, l: Value, r: Value, name: str): ValueThe example for this item is shown with the ones above: llvm-Program.salam
SRem
func SRem(b: Builder, l: Value, r: Value, name: str): ValueThe example for this item is shown with the ones above: llvm-Program.salam
ICmp
func ICmp(b: Builder, pred: int, l: Value, r: Value, name: str): ValueINT_... predicates; the result is an i1.The example for this item is shown with the ones above: llvm-Build.salam
Br
func Br(b: Builder, dest: BasicBlock): ValueThe example for this item is shown with the ones above: llvm-Build.salam
CondBr
func CondBr(b: Builder, cond: Value, t: BasicBlock, f: BasicBlock): ValueThe example for this item is shown with the ones above: llvm-Build.salam
Phi
func Phi(b: Builder, ty: Type, name: str): ValueThe example for this item is shown with the ones above: llvm-Build.salam
AddIncoming
func AddIncoming(phi: Value, vals: Vector<Value>, blocks: Vector<BasicBlock>)The example for this item is shown with the ones above: llvm-Build.salam
Call
func Call(b: Builder, fnty: Type, fn: Value, args: Vector<Value>, name: str): ValueThe example for this item is shown with the ones above: llvm-Program.salam
Alloca
func Alloca(b: Builder, ty: Type, name: str): ValueThe example for this item is shown with the ones above: llvm-Program.salam
Load
func Load(b: Builder, ty: Type, ptr: Value, name: str): ValueThe example for this item is shown with the ones above: llvm-Program.salam
Store
func Store(b: Builder, val: Value, ptr: Value): ValueThe example for this item is shown with the ones above: llvm-Program.salam
GlobalString
func GlobalString(b: Builder, s: str, name: str): ValueThe example for this item is shown with the ones above: llvm-Program.salam
AddGlobal
func AddGlobal(mod: Module, ty: Type, name: str): ValueThe example for this item is shown with the ones above: llvm-Program.salam
SetInitializer
func SetInitializer(g: Value, v: Value)The example for this item is shown with the ones above: llvm-Program.salam
SetGlobalConstant
func SetGlobalConstant(g: Value, flag: bool)The example for this item is shown with the ones above: llvm-Program.salam
ParallelJobs
func ParallelJobs(): intThe example for this item is shown with the ones above: llvm-Target.salam
ParallelPartitions
func ParallelPartitions(mod: Module, jobs: int): intThe example for this item is shown with the ones above: llvm-Target.salam
OptimizeEmitParallel
func OptimizeEmitParallel(mod: Module, tm: TargetMachine, opt_level: int, parts: int, out_prefix: str): ParallelResultThe example for this item is shown with the ones above: llvm-Target.salam
LldAvailable
func LldAvailable(): boolThe example for this item is shown with the ones above: llvm-Run.salam
Link
func Link(flavor: int, argv: void*, argc: int): boolThe example for this item is shown with the ones above: llvm-Program.salam
CanLinkTriple
func CanLinkTriple(t: str): boolThe example for this item is shown with the ones above: llvm-Run.salam
LinkExternal
func LinkExternal(obj: str, out_path: str, opts: Options): LinkResultThe example for this item is shown with the ones above: llvm-Run.salam
HostLinkTriple
func HostLinkTriple(): strThe example for this item is shown with the ones above: llvm-Run.salam
LinkElf
func LinkElf(obj: str, out_path: str, opts: Options): LinkResultThe example for this item is shown with the ones above: llvm-Run.salam
LinkWasi
func LinkWasi(obj: str, out_path: str, opts: Options): LinkResultThe example for this item is shown with the ones above: llvm-Run.salam
LinkMingw
func LinkMingw(obj: str, out_path: str, opts: Options): LinkResultThe example for this item is shown with the ones above: llvm-Run.salam
LinkAuto
func LinkAuto(obj: str, out_path: str, opts: Options): LinkResultThe example for this item is shown with the ones above: llvm-Run.salam
Available
func Available(): boolThe example for this item is shown with the ones above: llvm-Run.salam
Run
func Run(ll_path: str, opts: Options): Output.ll file with the options: parsing, optimizing and emitting the output or running with the JIT.The example for this item is shown with the ones above: llvm-Run.salam
EmitAsm
func EmitAsm(mod: Module, tm: TargetMachine, path: str): EmitResultThe example for this item is shown with the ones above: llvm-Target.salam
EmitObject
func EmitObject(mod: Module, tm: TargetMachine, path: str): EmitResultThe example for this item is shown with the ones above: llvm-Target.salam
EmitBitcode
func EmitBitcode(mod: Module, path: str): EmitResultThe example for this item is shown with the ones above: llvm-Target.salam
NewContext
func NewContext(): ContextThe example for this item is shown with the ones above: llvm-Build.salam
FreeContext
func FreeContext(ctx: Context)The example for this item is shown with the ones above: llvm-Build.salam
FreeModule
func FreeModule(mod: Module)The example for this item is shown with the ones above: llvm-Build.salam
ParseIR
func ParseIR(ll_path: str): ParseResult.ll file in a new context.The example for this item is shown with the ones above: llvm-Run.salam
Verify
func Verify(mod: Module): VerifyResultThe example for this item is shown with the ones above: llvm-Build.salam
TargetTripleOf
func TargetTripleOf(mod: Module): strThe example for this item is shown with the ones above: llvm-Run.salam
SetTargetTriple
func SetTargetTriple(mod: Module, triple: str)The example for this item is shown with the ones above: llvm-Run.salam
OptionsDefault
func OptionsDefault(): OptionsThe example for this item is shown with the ones above: llvm-Run.salam
InitTargets
func InitTargets()The example for this item is shown with the ones above: llvm-Target.salam
CodeGenLevelOf
func CodeGenLevelOf(opt_level: int): intThe example for this item is shown with the ones above: llvm-Target.salam
PassPipelineOf
func PassPipelineOf(opt_level: int): strdefault<O3>.The example for this item is shown with the ones above: llvm-Target.salam
DefaultTriple
func DefaultTriple(): strx86_64-unknown-linux-gnu.The example for this item is shown with the ones above: llvm-Target.salam
NewTargetMachine
func NewTargetMachine(triple: str, opt_level: int, native_cpu: bool): TargetMachineResultThe example for this item is shown with the ones above: llvm-Target.salam
FreeTargetMachine
func FreeTargetMachine(tm: TargetMachine)The example for this item is shown with the ones above: llvm-Target.salam
ApplyDataLayout
func ApplyDataLayout(mod: Module, tm: TargetMachine)The example for this item is shown with the ones above: llvm-Target.salam