1 2 3 4 5 6 7 8 9 10 11 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 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
|
//------------------------------------------------------------------------------
// GB_macrofy_user_op: construct a user defined operator
//------------------------------------------------------------------------------
// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2025, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
//------------------------------------------------------------------------------
#include "GB.h"
#include "jitifyer/GB_stringify.h"
void GB_macrofy_user_op // construct a user-defined operator
(
// output:
FILE *fp, // target file to write, already open
// input:
const GB_Operator op // op to construct in a JIT kernel
)
{
//--------------------------------------------------------------------------
// check inputs
//--------------------------------------------------------------------------
if (op->hash == 0 || op->hash == UINT64_MAX)
{
// skip if op is builtin or cannot be used in the JIT
return ;
}
//--------------------------------------------------------------------------
// construct the name
//--------------------------------------------------------------------------
fprintf (fp, "#define GB_USER_OP_FUNCTION %s\n", op->name) ;
//--------------------------------------------------------------------------
// construct the typedefs
//--------------------------------------------------------------------------
GB_macrofy_typedefs (fp, NULL, NULL, NULL,
op->xtype, op->ytype, op->ztype) ;
//--------------------------------------------------------------------------
// construct the function prototype
//--------------------------------------------------------------------------
for (char *p = op->defn ; *p ; p++)
{
int c = (int) (*p) ;
if (c == '{')
{
fprintf (fp, ";\n") ;
break ;
}
fputc (c, fp) ;
}
//--------------------------------------------------------------------------
// construct the user function itself
//--------------------------------------------------------------------------
fprintf (fp, "\n%s\n", op->defn) ;
GB_macrofy_string (fp, op->name, op->defn) ;
fprintf (fp, "#define GB_USER_OP_DEFN GB_%s_USER_DEFN\n", op->name) ;
}
|