Skip to content

Commit

Permalink
improvements in section
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorBaratta committed Jan 4, 2024
1 parent dee55f6 commit d06388c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions ffcx/codegeneration/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ def coefficient(self, mt, tabledata, quadrature_rule, access):
code += [L.VariableDecl(access, 0.0)]
code += [L.create_nested_for_loops([ic], body)]

code = L.Section("Coefficient definition", code)
pre_code = L.Section("Coefficient pre definition", pre_code)

return pre_code, code

def _define_coordinate_dofs_lincomb(self, mt, tabledata, quadrature_rule, access):
Expand Down
7 changes: 7 additions & 0 deletions ffcx/codegeneration/integral_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,13 @@ def generate_partition(self, symbol, F, mode, quadrature_rule):
# Backend specific modified terminal translation
vaccess = self.backend.access.get(mt, tabledata, quadrature_rule)
predef, vdef = self.backend.definitions.get(mt, tabledata, quadrature_rule, vaccess)

if isinstance(predef, L.Section):
predef = predef.statements

if isinstance(vdef, L.Section):
vdef = vdef.statements

if predef:
access = predef[0].symbol.name
pre_definitions[str(access)] = predef
Expand Down
5 changes: 3 additions & 2 deletions ffcx/codegeneration/lnodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,16 +728,17 @@ def as_statement(node):
class Section(LNode):
"""A section of code with a name and a list of statements."""

def __init__(self, name, statements):
def __init__(self, name: str, statements: LExpr, annotations: List[str] = None):
self.name = name
self.statements = [as_statement(st) for st in statements]
self.annotations = annotations or []

def __eq__(self, other):
return isinstance(other, type(self)) and self.name == other.name and self.statements == other.statements


class StatementList(LNode):
"""A simple sequence of statements. No new scopes are introduced."""
"""A simple sequence of statements."""

def __init__(self, statements):
self.statements = [as_statement(st) for st in statements]
Expand Down

0 comments on commit d06388c

Please sign in to comment.