Abstract Syntax Tree

class pystencils.backend.ast.astnode.PsAstNode

Base class for all nodes in the pystencils AST.

This base class provides a common interface to inspect and update the AST’s branching structure. The two methods get_children and set_child must be implemented by each subclass. Subclasses are also responsible for doing the necessary type checks if they place restrictions on the types of their children.

abstract clone()

Perform a deep copy of the AST.

Return type:

PsAstNode

structurally_equal(other)

Check two ASTs for structural equality.

By default this method checks the node’s type and children. If an AST node has additional internal state, it MUST override this method.

Return type:

bool

Parameters:

other (PsAstNode) –

class pystencils.backend.ast.astnode.PsLeafMixIn

Mix-in for AST leaves.

class pystencils.backend.ast.structural.PsBlock(cs)
Parameters:

cs (Sequence[PsAstNode]) –

clone()

Perform a deep copy of the AST.

Return type:

PsBlock

class pystencils.backend.ast.structural.PsStatement(expr)
Parameters:

expr (PsExpression) –

clone()

Perform a deep copy of the AST.

Return type:

PsStatement

class pystencils.backend.ast.structural.PsAssignment(lhs, rhs)
Parameters:
clone()

Perform a deep copy of the AST.

Return type:

PsAssignment

class pystencils.backend.ast.structural.PsDeclaration(lhs, rhs)
Parameters:
clone()

Perform a deep copy of the AST.

Return type:

PsDeclaration

class pystencils.backend.ast.structural.PsLoop(ctr, start, stop, step, body)
Parameters:
clone()

Perform a deep copy of the AST.

Return type:

PsLoop

class pystencils.backend.ast.structural.PsConditional(cond, branch_true, branch_false=None)

Conditional branch

Parameters:
clone()

Perform a deep copy of the AST.

Return type:

PsConditional

class pystencils.backend.ast.structural.PsComment(text)
Parameters:

text (str) –

clone()

Perform a deep copy of the AST.

Return type:

PsComment

structurally_equal(other)

Check two ASTs for structural equality.

By default this method checks the node’s type and children. If an AST node has additional internal state, it MUST override this method.

Return type:

bool

Parameters:

other (PsAstNode) –

class pystencils.backend.ast.expressions.PsExpression(dtype=None)

Base class for all expressions.

Types: Each expression should be annotated with its type. Upon construction, the dtype property of most expression nodes is unset; only constant expressions, symbol expressions, and array accesses immediately inherit their type from their constant, symbol, or array, respectively.

The canonical way to add types to newly constructed expressions is through the Typifier. It should be run at least once on any expression constructed by the backend.

The type annotations are used by various transformation passes to make decisions, e.g. in function materialization and intrinsic selection.

Parameters:

dtype (PsType | None) –

abstract clone()

Perform a deep copy of the AST.

Return type:

PsExpression

class pystencils.backend.ast.expressions.PsLvalue

Mix-in for all expressions that may occur as an lvalue

class pystencils.backend.ast.expressions.PsSymbolExpr(symbol)

A single symbol as an expression.

Parameters:

symbol (PsSymbol) –

clone()

Perform a deep copy of the AST.

Return type:

PsSymbolExpr

structurally_equal(other)

Check two ASTs for structural equality.

By default this method checks the node’s type and children. If an AST node has additional internal state, it MUST override this method.

Return type:

bool

Parameters:

other (PsAstNode) –

class pystencils.backend.ast.expressions.PsConstantExpr(constant)
Parameters:

constant (PsConstant) –

clone()

Perform a deep copy of the AST.

Return type:

PsConstantExpr

structurally_equal(other)

Check two ASTs for structural equality.

By default this method checks the node’s type and children. If an AST node has additional internal state, it MUST override this method.

Return type:

bool

Parameters:

other (PsAstNode) –

class pystencils.backend.ast.expressions.PsLiteralExpr(literal)
Parameters:

literal (PsLiteral) –

clone()

Perform a deep copy of the AST.

Return type:

PsLiteralExpr

structurally_equal(other)

Check two ASTs for structural equality.

By default this method checks the node’s type and children. If an AST node has additional internal state, it MUST override this method.

Return type:

bool

Parameters:

other (PsAstNode) –

class pystencils.backend.ast.expressions.PsSubscript(base, index)
Parameters:
clone()

Perform a deep copy of the AST.

Return type:

PsSubscript

class pystencils.backend.ast.expressions.PsArrayAccess(base_ptr, index)
Parameters:
clone()

Perform a deep copy of the AST.

Return type:

PsArrayAccess

class pystencils.backend.ast.expressions.PsVectorArrayAccess(base_ptr, base_index, vector_entries, stride=1, alignment=0)
Parameters:
clone()

Perform a deep copy of the AST.

Return type:

PsVectorArrayAccess

structurally_equal(other)

Check two ASTs for structural equality.

By default this method checks the node’s type and children. If an AST node has additional internal state, it MUST override this method.

Return type:

bool

Parameters:

other (PsAstNode) –

class pystencils.backend.ast.expressions.PsLookup(aggregate, member_name)
Parameters:
clone()

Perform a deep copy of the AST.

Return type:

PsLookup

class pystencils.backend.ast.expressions.PsCall(function, args)
Parameters:
  • function (PsFunction) –

  • args (Sequence[PsExpression]) –

clone()

Perform a deep copy of the AST.

Return type:

PsCall

structurally_equal(other)

Check two ASTs for structural equality.

By default this method checks the node’s type and children. If an AST node has additional internal state, it MUST override this method.

Return type:

bool

Parameters:

other (PsAstNode) –

class pystencils.backend.ast.expressions.PsNumericOpTrait

Trait for operations valid only on numerical types

class pystencils.backend.ast.expressions.PsIntOpTrait

Trait for operations valid only on integer types

class pystencils.backend.ast.expressions.PsBoolOpTrait

Trait for boolean operations

class pystencils.backend.ast.expressions.PsUnOp(operand)
Parameters:

operand (PsExpression) –

clone()

Perform a deep copy of the AST.

Return type:

PsUnOp

class pystencils.backend.ast.expressions.PsNeg(operand)
Parameters:

operand (PsExpression) –

class pystencils.backend.ast.expressions.PsDeref(operand)
Parameters:

operand (PsExpression) –

class pystencils.backend.ast.expressions.PsAddressOf(operand)
Parameters:

operand (PsExpression) –

class pystencils.backend.ast.expressions.PsCast(target_type, operand)
Parameters:
clone()

Perform a deep copy of the AST.

Return type:

PsUnOp

structurally_equal(other)

Check two ASTs for structural equality.

By default this method checks the node’s type and children. If an AST node has additional internal state, it MUST override this method.

Return type:

bool

Parameters:

other (PsAstNode) –

class pystencils.backend.ast.expressions.PsBinOp(op1, op2)
Parameters:
clone()

Perform a deep copy of the AST.

Return type:

PsBinOp

class pystencils.backend.ast.expressions.PsAdd(op1, op2)
Parameters:
class pystencils.backend.ast.expressions.PsSub(op1, op2)
Parameters:
class pystencils.backend.ast.expressions.PsMul(op1, op2)
Parameters:
class pystencils.backend.ast.expressions.PsDiv(op1, op2)
Parameters:
class pystencils.backend.ast.expressions.PsIntDiv(op1, op2)

C-like integer division (round to zero).

Parameters:
class pystencils.backend.ast.expressions.PsLeftShift(op1, op2)
Parameters:
class pystencils.backend.ast.expressions.PsRightShift(op1, op2)
Parameters:
class pystencils.backend.ast.expressions.PsBitwiseAnd(op1, op2)
Parameters:
class pystencils.backend.ast.expressions.PsBitwiseXor(op1, op2)
Parameters:
class pystencils.backend.ast.expressions.PsBitwiseOr(op1, op2)
Parameters:
class pystencils.backend.ast.expressions.PsAnd(op1, op2)
Parameters:
class pystencils.backend.ast.expressions.PsOr(op1, op2)
Parameters:
class pystencils.backend.ast.expressions.PsNot(operand)
Parameters:

operand (PsExpression) –

class pystencils.backend.ast.expressions.PsRel(op1, op2)

Base class for binary relational operators

Parameters:
class pystencils.backend.ast.expressions.PsEq(op1, op2)
Parameters:
class pystencils.backend.ast.expressions.PsNe(op1, op2)
Parameters:
class pystencils.backend.ast.expressions.PsGe(op1, op2)
Parameters:
class pystencils.backend.ast.expressions.PsLe(op1, op2)
Parameters:
class pystencils.backend.ast.expressions.PsGt(op1, op2)
Parameters:
class pystencils.backend.ast.expressions.PsLt(op1, op2)
Parameters:
class pystencils.backend.ast.expressions.PsArrayInitList(items)
Parameters:

items (Sequence[PsExpression]) –

clone()

Perform a deep copy of the AST.

Return type:

PsExpression