llvmliteir
¶
LLVM-IR builder.
Classes:
-
LLVMLiteIR–LLVM-IR transpiler and compiler.
-
LLVMLiteIRVisitor–LLVM-IR Translator.
-
VariablesLLVM–Store all the LLVM variables that is used for the code generation.
Functions:
-
emit_int_div–Emit signed or unsigned vector integer division.
-
is_fp_type–Return True if t is any floating-point LLVM type.
-
is_vector–Return True if v is an LLVM vector value.
-
safe_pop–Implement a safe pop operation for lists.
-
splat_scalar–Broadcast a scalar to all lanes of a vector.
LLVMLiteIR
¶
LLVMLiteIR()
Bases: Builder
LLVM-IR transpiler and compiler.
Methods:
-
build–Transpile the ASTx to LLVM-IR and build it to an executable file.
-
module–Create a new ASTx Module.
-
run–Run the generated executable.
-
translate–Transpile ASTx to LLVM-IR.
Source code in src/irx/builders/llvmliteir.py
2294 2295 2296 2297 | |
build
¶
build(node: AST, output_file: str) -> None
Transpile the ASTx to LLVM-IR and build it to an executable file.
Source code in src/irx/builders/llvmliteir.py
2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 | |
module
¶
module() -> Module
Create a new ASTx Module.
Source code in src/irx/builders/base.py
74 75 76 | |
LLVMLiteIRVisitor
¶
LLVMLiteIRVisitor()
Bases: BuilderVisitor
LLVM-IR Translator.
Methods:
-
create_entry_block_alloca–Create an alloca instruction in the entry block of the function.
-
fp_rank–Rank floating-point types: half < float < double.
-
get_function–Put the function defined by the given name to result stack.
-
initialize–Initialize self.
-
promote_operands–Promote two LLVM IR numeric operands to a common type.
-
translate–Translate an ASTx expression to string.
-
visit–Translate ASTx LiteralInt16 to LLVM-IR.
Source code in src/irx/builders/llvmliteir.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |
create_entry_block_alloca
¶
Create an alloca instruction in the entry block of the function.
This is used for mutable variables, etc.
Parameters:
Returns:
-
An llvm allocation instance.–
Source code in src/irx/builders/llvmliteir.py
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
fp_rank
¶
fp_rank(t: Type) -> int
Rank floating-point types: half < float < double.
Source code in src/irx/builders/llvmliteir.py
318 319 320 321 322 323 324 325 326 | |
get_function
¶
Put the function defined by the given name to result stack.
Source code in src/irx/builders/llvmliteir.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |
initialize
¶
initialize() -> None
Initialize self.
Source code in src/irx/builders/llvmliteir.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
promote_operands
¶
promote_operands(
lhs: Value, rhs: Value
) -> tuple[Value, Value]
Promote two LLVM IR numeric operands to a common type.
Parameters:
-
lhs(Value) –The left-hand operand.
-
rhs(Value) –The right-hand operand.
Returns:
-
tuple[Value, Value]–A tuple containing the promoted operands.
Source code in src/irx/builders/llvmliteir.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
translate
¶
translate(node: AST) -> str
Translate an ASTx expression to string.
Source code in src/irx/builders/llvmliteir.py
178 179 180 181 | |
visit
¶
visit(node: LiteralInt16) -> None
Translate ASTx LiteralInt16 to LLVM-IR.
Source code in src/irx/builders/llvmliteir.py
2283 2284 2285 2286 2287 | |
VariablesLLVM
¶
Store all the LLVM variables that is used for the code generation.
Methods:
-
get_data_type–Get the LLVM data type for the given type name.
get_data_type
¶
get_data_type(type_name: str) -> Type
Get the LLVM data type for the given type name.
Returns:
-
ir.Type: The LLVM data type.–
Source code in src/irx/builders/llvmliteir.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
emit_int_div
¶
emit_int_div(
ir_builder: "ir.IRBuilder",
lhs: "ir.Value",
rhs: "ir.Value",
unsigned: bool,
) -> "ir.Instruction"
Emit signed or unsigned vector integer division.
Source code in src/irx/builders/llvmliteir.py
45 46 47 48 49 50 51 52 53 54 55 56 | |
is_fp_type
¶
is_fp_type(t: 'ir.Type') -> bool
Return True if t is any floating-point LLVM type.
Source code in src/irx/builders/llvmliteir.py
32 33 34 35 36 37 | |
is_vector
¶
is_vector(v: 'ir.Value') -> bool
Return True if v is an LLVM vector value.
Source code in src/irx/builders/llvmliteir.py
40 41 42 | |
safe_pop
¶
safe_pop(lst: list[Value | Function]) -> Value | Function
Implement a safe pop operation for lists.
Source code in src/irx/builders/llvmliteir.py
71 72 73 74 75 76 77 | |
splat_scalar
¶
splat_scalar(
ir_builder: "ir.IRBuilder",
scalar: "ir.Value",
vec_type: "ir.VectorType",
) -> "ir.Value"
Broadcast a scalar to all lanes of a vector.
Source code in src/irx/builders/llvmliteir.py
59 60 61 62 63 64 65 66 67 68 | |