finch_assembly
AssemblyCFGBuilder
Incrementally builds control-flow graph for Finch Assembly IR.
Source code in src/finch/finch_assembly/cfg_builder.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 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 317 318 319 320 321 322 323 324 325 326 327 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 383 384 385 386 | |
emit(stmt)
Add a statement to the current block.
Source code in src/finch/finch_assembly/cfg_builder.py
268 269 270 | |
AssemblyCopyPropagation
Bases: AbstractAssemblyDataflow
Copy propagation for FinchAssembly.
Lattice:
- defs: mapping { var_name: sid | None } describing a unique reaching
definition id for each variable (None means "not uniquely defined").
- copies: mapping { dst_var: (src_var, src_def_id) } describing a direct
copy dst_var = src_var that is valid only if src_var still has the
same unique reaching definition src_def_id.
Source code in src/finch/finch_assembly/dataflow.py
127 128 129 130 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 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 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 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
collect_copy_replacements()
Collect per-statement copy replacements.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[tuple[int, str], str]
|
Mapping |
Source code in src/finch/finch_assembly/dataflow.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
direction()
Copy propagation is a forward analysis.
Source code in src/finch/finch_assembly/dataflow.py
138 139 140 | |
get_lattice_value(state, stmt)
Collect lattice annotations for variables used in a stmt or expr.
Source code in src/finch/finch_assembly/dataflow.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
join(state_1, state_2)
Meet operator for must copy-propagation.
- defs join: keep a def id only if both agree, else None.
- copies join: keep a copy only if both agree exactly, and it remains consistent with the joined defs.
Source code in src/finch/finch_assembly/dataflow.py
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 | |
transfer(stmts, state)
Transfer function over a sequence of statements.
Applies copy-propagation effects of each statement in order, returning the updated lattice mapping. Only copies of variables are recorded; any existing mappings that point to a variable being reassigned are invalidated first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stmts
|
Iterable[Any]
|
Iterable of Assembly statements in a basic block. |
required |
state
|
dict
|
Incoming lattice mapping. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
The outgoing lattice mapping after processing |
Source code in src/finch/finch_assembly/dataflow.py
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 | |
AssemblyExpression
Bases: AssemblyNode, ExpressionTerm
Assembly AST expression base class.
An assembly expression is a program node which evaluates to a value.
Source code in src/finch/finch_assembly/nodes.py
67 68 69 70 71 72 73 74 75 76 77 78 | |
result_type
abstractmethod
property
Returns the type of the expression.
AssemblyInterpreter
Bases: UnvalidatedForm, AssemblyLoader
An interpreter for FinchAssembly.
Source code in src/finch/finch_assembly/interpreter.py
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 94 95 96 97 98 99 100 101 102 103 104 105 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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 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 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 282 283 284 285 286 287 288 289 290 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 317 318 319 320 321 322 323 324 325 326 327 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 383 384 385 386 | |
__call__(prgm, *, mode=None)
__call__(
prgm: asm.Module, *, mode: CompilerMode | None = None
) -> AssemblyLibrary
__call__(prgm: asm.AssemblyNode) -> Any
Run the program.
Source code in src/finch/finch_assembly/interpreter.py
150 151 152 153 154 155 156 | |
scope(bindings=None, slots=None, types=None, loop_state=None, function_state=None, stdout=None, mode=None)
Create a new scope for the interpreter. This allows for nested scopes and variable shadowing.
Source code in src/finch/finch_assembly/interpreter.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
should_halt()
Check if the interpreter should halt execution. This is used to stop execution in loops or when a return statement is encountered.
Source code in src/finch/finch_assembly/interpreter.py
125 126 127 128 129 130 131 132 133 134 135 136 | |
AssemblyInterpreterKernel
Bases: AssemblyKernel
A kernel for interpreting FinchAssembly code. This is a simple interpreter that executes the assembly code.
Source code in src/finch/finch_assembly/interpreter.py
14 15 16 17 18 19 20 21 22 23 24 25 | |
AssemblyKernel
A callable implementation of an AssemblyKernelFType.
Source code in src/finch/finch_assembly/stages.py
49 50 51 52 53 54 55 56 57 58 59 60 | |
AssemblyKernelFType
dataclass
Bases: CallableFType
The identity and signature of a function defined in a Finch module.
Source code in src/finch/finch_assembly/stages.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
AssemblyLibrary
Bases: ABC
Represents a module containing assembly kernels.
Source code in src/finch/finch_assembly/stages.py
63 64 65 66 67 68 69 70 71 72 73 | |
__getattr__(name)
abstractmethod
Get the assembly Kernel corresponding to the given name.
Source code in src/finch/finch_assembly/stages.py
68 69 70 71 72 73 | |
AssemblyLoader
Bases: Stage
Source code in src/finch/finch_assembly/stages.py
76 77 78 79 80 81 82 83 | |
lower(term, *, mode=None)
abstractmethod
Load the given assembly program into a runnable module.
Source code in src/finch/finch_assembly/stages.py
77 78 79 80 81 82 83 | |
AssemblyNode
Bases: Term
AssemblyNode
Represents a FinchAssembly IR node. FinchAssembly is the final intermediate representation before code generation (translation to the output language). It is a low-level imperative description of the program, with control flow, linear memory regions called "buffers", and explicit memory management.
Source code in src/finch/finch_assembly/nodes.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
__str__()
Returns a string representation of the node.
Source code in src/finch/finch_assembly/nodes.py
53 54 55 56 57 | |
from_children(*children)
classmethod
Creates a term from the given children. This is used to create terms from the children of a node.
Source code in src/finch/finch_assembly/nodes.py
45 46 47 48 49 50 51 | |
head()
classmethod
Returns the head of the node.
Source code in src/finch/finch_assembly/nodes.py
35 36 37 38 | |
make_term(head, *args)
classmethod
Creates a term with the given head and arguments.
Source code in src/finch/finch_assembly/nodes.py
40 41 42 43 | |
AssemblyTransform
Bases: Stage
Source code in src/finch/finch_assembly/stages.py
86 87 88 89 90 91 | |
lower(term)
abstractmethod
Transform the given assembly term into another assembly term.
Source code in src/finch/finch_assembly/stages.py
87 88 89 90 91 | |
AssemblyTypeChecker
A type checker for FinchAssembly
Source code in src/finch/finch_assembly/type_checker.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 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 94 95 96 97 98 99 100 101 102 103 104 105 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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 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 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 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
Assert
dataclass
Bases: AssemblyTree, AssemblyStatement
Checks that an expression is true at runtime. Also used in dataflow analysis to record conditions in conditionals and loops.
Attributes:
| Name | Type | Description |
|---|---|---|
exp |
AssemblyExpression
|
Expression which is being asserted. |
Source code in src/finch/finch_assembly/nodes.py
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 | |
children
property
Returns the children of the node.
Assign
dataclass
Bases: AssemblyTree, AssemblyStatement
Represents a logical AST statement that evaluates rhs, binding the result
to lhs.
Attributes:
| Name | Type | Description |
|---|---|---|
lhs |
Variable
|
The left-hand side of the binding. |
rhs |
AssemblyExpression
|
The right-hand side to evaluate. |
Source code in src/finch/finch_assembly/nodes.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |
children
property
Returns the children of the node.
Block
dataclass
Bases: AssemblyTree, AssemblyStatement
Represents a statement that executes a sequence of statements bodies....
Attributes:
| Name | Type | Description |
|---|---|---|
bodies |
tuple[AssemblyStatement | AssemblyExpression, ...]
|
The sequence of statements to execute. |
Source code in src/finch/finch_assembly/nodes.py
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 | |
children
property
Returns the children of the node.
Break
dataclass
Bases: AssemblyTree, AssemblyStatement
Represents a break statement that exits the current loop.
Source code in src/finch/finch_assembly/nodes.py
549 550 551 552 553 554 555 556 557 558 | |
children
property
Returns the children of the node.
Buffer
Bases: FTyped[BufferFType[FT]], ABC
Abstract base class for buffer-like data structures. Buffers support random access, and can be resized. They are used to store data in a way that allows for efficient reading and writing of elements.
Source code in src/finch/finch_assembly/buffer.py
42 43 44 45 46 47 48 49 50 51 52 53 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 | |
element_type
property
Return the type of elements stored in the buffer. This is typically the same as the dtype used to create the buffer.
length_type
property
Return the type of indices used to access elements in the buffer. This is typically an integer type.
length()
abstractmethod
Return the length of the buffer.
Source code in src/finch/finch_assembly/buffer.py
52 53 54 55 56 57 | |
resize(len)
abstractmethod
Resize the buffer to the new length.
Source code in src/finch/finch_assembly/buffer.py
81 82 83 84 85 86 | |
BufferFType
Abstract base class for the ftype of arguments. The ftype defines how the data structures store data, and can construct a data structure with the call method.
Source code in src/finch/finch_assembly/buffer.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
element_type
abstractmethod
property
Return the type of elements stored in the buffer. This is typically the same as the dtype used to create the buffer.
length_type
property
Returns the type used for the length of the buffer.
__call__(*args, **kwargs)
abstractmethod
Create an instance of an object in this ftype with the given arguments.
Source code in src/finch/finch_assembly/buffer.py
18 19 20 21 22 23 | |
BufferLoop
dataclass
Bases: AssemblyTree, AssemblyStatement
Represents a loop that iterates over the elements of a buffer.
Attributes:
| Name | Type | Description |
|---|---|---|
buffer |
AssemblyExpression
|
The buffer to iterate over. |
var |
Variable
|
The loop variable for each element in the buffer. |
body |
AssemblyStatement
|
The body of the loop to execute for each element. |
Source code in src/finch/finch_assembly/nodes.py
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 | |
children
property
Returns the children of the node.
Call
dataclass
Bases: AssemblyExpression, AssemblyTree, CallTerm
Represents an expression for calling the function op on args....
Attributes:
| Name | Type | Description |
|---|---|---|
op |
AssemblyExpression
|
The function to call. |
args |
tuple[AssemblyExpression, ...]
|
The arguments to call on the function. |
Source code in src/finch/finch_assembly/nodes.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
children
property
Returns the children of the node.
result_type
property
Returns the type of the expression.
ForLoop
dataclass
Bases: AssemblyTree, AssemblyStatement
Represents a for loop that iterates over a range of values.
Attributes:
| Name | Type | Description |
|---|---|---|
var |
Variable
|
The loop variable. |
start |
AssemblyExpression
|
The starting value of the range. |
end |
AssemblyExpression
|
The ending value of the range. |
body |
AssemblyStatement
|
The body of the loop to execute. |
Source code in src/finch/finch_assembly/nodes.py
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | |
children
property
Returns the children of the node.
Function
dataclass
Bases: AssemblyTree
A module-level function definition with arguments args....
Attributes:
| Name | Type | Description |
|---|---|---|
name |
Variable
|
The function variable, annotated with its AssemblyKernelFType. |
args |
tuple[Variable, ...]
|
The arguments to the function. |
body |
AssemblyStatement
|
The body of the function. If it does not contain a return statement,
the function returns the value of |
Source code in src/finch/finch_assembly/nodes.py
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 | |
children
property
Returns the children of the node.
from_children(*children)
classmethod
Creates a term with the given head and arguments.
Source code in src/finch/finch_assembly/nodes.py
524 525 526 527 528 | |
GetAttr
dataclass
Bases: AssemblyExpression, AssemblyTree
Represents a getter for an attribute attr of an object obj.
Attributes:
obj: The object to get the attribute from.
attr: The name of the attribute to get.
Source code in src/finch/finch_assembly/nodes.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
children
property
Returns the children of the node.
result_type
property
Returns the type of the expression.
If
dataclass
Bases: AssemblyTree, AssemblyStatement
Represents an if statement that executes the body if the condition is true.
Attributes:
| Name | Type | Description |
|---|---|---|
condition |
AssemblyExpression
|
The condition to evaluate for the if to execute the body. |
body |
AssemblyStatement
|
The body of the if statement to execute. |
Source code in src/finch/finch_assembly/nodes.py
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 | |
children
property
Returns the children of the node.
IfElse
dataclass
Bases: AssemblyTree, AssemblyStatement
Represents an if-else statement that executes the body if the condition is true, otherwise executes else_body.
Attributes:
| Name | Type | Description |
|---|---|---|
condition |
AssemblyExpression
|
The condition to evaluate for the if to execute the body. |
body |
AssemblyStatement
|
The body of the if statement to execute. |
else_body |
AssemblyStatement
|
An alternative body to execute if the condition is false. |
Source code in src/finch/finch_assembly/nodes.py
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 | |
children
property
Returns the children of the node.
Length
dataclass
Bases: AssemblyExpression, AssemblyTree
Represents getting the length of a buffer.
Attributes:
| Name | Type | Description |
|---|---|---|
buffer |
AssemblyExpression
|
The buffer whose length is queried. |
Source code in src/finch/finch_assembly/nodes.py
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | |
result_type
property
Returns the type of the expression.
Literal
dataclass
Bases: AssemblyExpression, LiteralTerm[T]
Represents the literal value val.
Attributes:
| Name | Type | Description |
|---|---|---|
val |
T
|
The literal value. |
Source code in src/finch/finch_assembly/nodes.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
result_type
property
Returns the type of the expression.
Load
dataclass
Bases: AssemblyExpression, AssemblyTree
Represents loading a value from a buffer at a given index.
Attributes:
| Name | Type | Description |
|---|---|---|
buffer |
AssemblyExpression
|
The buffer to load from. |
index |
AssemblyExpression
|
The index to load at. |
Source code in src/finch/finch_assembly/nodes.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | |
result_type
property
Returns the type of the expression.
Module
dataclass
Bases: AssemblyTree
Represents a group of functions. This is the toplevel translation unit for FinchAssembly.
Attributes:
| Name | Type | Description |
|---|---|---|
funcs |
tuple[Function, ...]
|
The functions defined in the module. |
Source code in src/finch/finch_assembly/nodes.py
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 | |
children
property
Returns the children of the node.
NumberedStatement
dataclass
Bases: AssemblyStatement
Wrapper for AssemblyStatement that assigns a unique id to each statement for easier tracking in the CFG.
Attributes:
| Name | Type | Description |
|---|---|---|
stmt |
AssemblyStatement
|
The original AssemblyStatement being wrapped. |
sid |
int
|
A unique integer identifier for the statement. |
Source code in src/finch/finch_assembly/cfg_builder.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
Repack
dataclass
Bases: AssemblyTree, AssemblyStatement
Registers updates from a symbolic object val with the original
object. The original object may now be accessed and modified.
Attributes:
| Name | Type | Description |
|---|---|---|
slot |
The symbolic object to read from. |
Source code in src/finch/finch_assembly/nodes.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
children
property
Returns the children of the node.
Resize
dataclass
Bases: AssemblyTree, AssemblyStatement
Represents resizing a buffer to a new size.
Attributes:
| Name | Type | Description |
|---|---|---|
buffer |
AssemblyExpression
|
The buffer to resize. |
new_size |
AssemblyExpression
|
The new size for the buffer. |
Source code in src/finch/finch_assembly/nodes.py
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | |
Return
dataclass
Bases: AssemblyTree, AssemblyStatement
Represents a return statement that returns arg from the current function.
Halts execution of the function body.
Attributes:
| Name | Type | Description |
|---|---|---|
arg |
AssemblyExpression
|
The argument to return. |
Source code in src/finch/finch_assembly/nodes.py
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 | |
children
property
Returns the children of the node.
SetAttr
dataclass
Bases: AssemblyTree, AssemblyStatement
Represents a setter for an attribute attr of an object obj.
Attributes:
obj: The object to set the attribute on.
attr: The name of the attribute to set.
value: The value to set the attribute to.
Source code in src/finch/finch_assembly/nodes.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | |
children
property
Returns the children of the node.
Slot
dataclass
Bases: AssemblyExpression
Represents a register to a symbolic object. Using a register in an expression creates a copy of the object.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the symbolic object to register. |
type |
Any
|
The type of the symbolic object. |
Source code in src/finch/finch_assembly/nodes.py
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 | |
result_type
property
Returns the type of the expression.
Store
dataclass
Bases: AssemblyTree, AssemblyStatement
Represents storing a value into a buffer at a given index.
Attributes:
| Name | Type | Description |
|---|---|---|
buffer |
AssemblyExpression
|
The buffer to store into. |
index |
AssemblyExpression
|
The index to store at. |
value |
AssemblyExpression
|
The value to store. |
Source code in src/finch/finch_assembly/nodes.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | |
Unpack
dataclass
Bases: AssemblyTree, AssemblyStatement
Attempts to convert rhs into a symbolic, which can be registerd with
lhs. The original object must not be accessed or modified until the
corresponding Repack node is reached.
Attributes:
| Name | Type | Description |
|---|---|---|
lhs |
Slot
|
The symbolic object to write to. |
rhs |
AssemblyExpression
|
The original object to read from. |
Source code in src/finch/finch_assembly/nodes.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
children
property
Returns the children of the node.
Variable
dataclass
Bases: AssemblyExpression, NamedTerm
Represents a logical AST expression for a variable named name, which
will hold a value of type type.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the variable. |
type |
FType
|
The type of the variable. |
Source code in src/finch/finch_assembly/nodes.py
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 | |
result_type
property
Returns the type of the expression.
WhileLoop
dataclass
Bases: AssemblyTree, AssemblyStatement
Represents a while loop that executes as long as the condition is true.
Attributes:
| Name | Type | Description |
|---|---|---|
condition |
AssemblyExpression
|
The condition to evaluate for the loop to continue. |
body |
AssemblyStatement
|
The body of the loop to execute. |
Source code in src/finch/finch_assembly/nodes.py
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 | |
children
property
Returns the children of the node.
assembly_copy_propagation(node)
Apply copy-propagation to a FinchAssembly node. Args: node: Root FinchAssembly node to optimize. Returns: AssemblyNode: The optimized FinchAssembly node.
Source code in src/finch/finch_assembly/dataflow.py
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 94 95 96 97 98 99 100 101 102 103 | |
assembly_dataflow_analyze(node, analysis_cls)
Run preprocessing + CFG build + analysis for a dataflow pass.
Returns:
| Type | Description |
|---|---|
tuple[AnalysisT, AssemblyNode]
|
(analysis_ctx, preprocessed_node) |
Source code in src/finch/finch_assembly/dataflow.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
assembly_dataflow_run(node, analysis_cls, apply)
Run a full dataflow pass (preprocess -> analyze -> apply -> postprocess).
Source code in src/finch/finch_assembly/dataflow.py
47 48 49 50 51 52 53 54 55 56 57 | |
length_type(arg)
The length type of the given argument. The length type is the type of the value returned by len(arg).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
FTyped | FType
|
The object to determine the length type for. |
required |
Returns:
| Type | Description |
|---|---|
FDTypeInteger
|
The length type of the given object. |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the length type is not implemented for the given type. |
Source code in src/finch/finch_assembly/buffer.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
parse_assembly(code, vars, position_type=np.intp)
Parse Finch Assembly code and convert it to assembly node objects.
Takes a string containing Finch Assembly code and transforms it into a structured representation using assembly nodes. The parser supports assignments, increments, for/while loops, if/if-else statements, buffer and field accesses, and calls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
The Finch Assembly code to parse. Should start with "finch" or "finch-asm" followed by assembly statements. Comments (C/C++ style) are supported. |
required |
vars
|
dict[str, AssemblyExpression]
|
Dictionary mapping names to Assembly expressions. Used to resolve variable references in the assembly code. |
required |
position_type
|
type
|
NumPy integer type to use for integer literals. Affects the dtype of parsed integer constants. (default: np.intp) |
intp
|
Returns:
| Type | Description |
|---|---|
Block
|
A Finch Assembly Block representing the parsed code. |
Raises:
| Type | Description |
|---|---|
Exception
|
If the parser encounters unrecognized syntax or tree nodes. |
Example
from finch.finch_assembly import nodes as asm vars = {"i": asm.Variable("i", int), "arr": asm.Variable("arr", np.ndarray)} code = '''finch ... arr[i] = 42 ... ''' stmt = parse_assembly(code, vars)
Source code in src/finch/finch_assembly/parser.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |