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:
-
safe_pop
–Implement a safe pop operation for lists.
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
1646 1647 1648 1649 |
|
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
1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 |
|
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.
-
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
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
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
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 |
|
get_function
¶
Put the function defined by the given name to result stack.
Source code in src/irx/builders/llvmliteir.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
|
initialize
¶
initialize() -> None
Initialize self.
Source code in src/irx/builders/llvmliteir.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
|
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
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
|
translate
¶
translate(node: AST) -> str
Translate an ASTx expression to string.
Source code in src/irx/builders/llvmliteir.py
126 127 128 129 |
|
visit
¶
visit(node: LiteralInt16) -> None
Translate ASTx LiteralInt16 to LLVM-IR.
Source code in src/irx/builders/llvmliteir.py
1635 1636 1637 1638 1639 |
|
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
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
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
23 24 25 26 27 28 29 |
|