Skip to content

Commit d11d9ee

Browse files
committed
compiler: Callable.attributes
1 parent cfb6724 commit d11d9ee

3 files changed

Lines changed: 21 additions & 5 deletions

File tree

devito/ir/iet/efunc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ class DeviceFunction(Callable):
159159
"""
160160

161161
def __init__(self, name, body, retval='void', parameters=None,
162-
prefix='__global__', templates=None):
162+
prefix='__global__', templates=None, attributes=None):
163163
super().__init__(name, body, retval, parameters=parameters, prefix=prefix,
164-
templates=templates)
164+
templates=templates, attributes=attributes)
165165

166166

167167
class DeviceCall(Call):

devito/ir/iet/nodes.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,17 +718,21 @@ class Callable(Node):
718718
parameters : list of Basic, optional
719719
The objects in input to the Callable.
720720
prefix : list of str, optional
721-
Qualifiers to prepend to the Callable signature. None by defaults.
721+
Qualifiers to prepend to the Callable signature. None by default.
722722
templates : list of Basic, optional
723723
The template parameters of the Callable.
724+
attributes : list of str, optional
725+
Additional attributes to append to the Callable signature. An
726+
attributes is one or more keywords that appear in between the
727+
return type and the function name. None by default.
724728
"""
725729

726730
is_Callable = True
727731

728732
_traversable = ['body']
729733

730734
def __init__(self, name, body, retval, parameters=None, prefix=None,
731-
templates=None):
735+
templates=None, attributes=None):
732736
self.name = name
733737
if not isinstance(body, CallableBody):
734738
self.body = CallableBody(body)
@@ -738,6 +742,7 @@ def __init__(self, name, body, retval, parameters=None, prefix=None,
738742
self.prefix = as_tuple(prefix)
739743
self.parameters = as_tuple(parameters)
740744
self.templates = as_tuple(templates)
745+
self.attributes = as_tuple(attributes)
741746

742747
def __repr__(self):
743748
param_types = [ctypes_to_cstr(i._C_ctype) for i in self.parameters]

devito/ir/iet/visitors.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,14 +320,25 @@ def _args_call(self, args):
320320

321321
def _gen_signature(self, o, is_declaration=False):
322322
decls = self._args_decl(o.parameters)
323+
323324
prefix = ' '.join(o.prefix + (self._gen_rettype(o.retval),))
324-
signature = c.FunctionDeclaration(c.Value(prefix, o.name), decls)
325+
326+
if o.attributes:
327+
# NOTE: ugly, but I can't bother extending `c.FunctionDeclaration`
328+
# for such a tiny thing
329+
v = f"{' '.join(o.attributes)} {o.name}"
330+
else:
331+
v = o.name
332+
333+
signature = c.FunctionDeclaration(c.Value(prefix, v), decls)
334+
325335
if o.templates:
326336
tparams = ', '.join([i.inline() for i in self._args_decl(o.templates)])
327337
if is_declaration:
328338
signature = TemplateDecl(tparams, signature)
329339
else:
330340
signature = c.Template(tparams, signature)
341+
331342
return signature
332343

333344
def _blankline_logic(self, children):

0 commit comments

Comments
 (0)