File: GB_macrofy_user_op.c

package info (click to toggle)
suitesparse 1%3A7.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 254,920 kB
  • sloc: ansic: 1,134,743; cpp: 46,133; makefile: 4,875; fortran: 2,087; java: 1,826; sh: 996; ruby: 725; python: 495; asm: 371; sed: 166; awk: 44
file content (68 lines) | stat: -rw-r--r-- 2,356 bytes parent folder | download
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) ;
}