Exemplo n.º 1
0
def populate_pupfns(pup_max_nesting, backend, blklens, builtin_types, builtin_maps):
    ##### generate the switching logic to select pup functions
    filename = "src/backend/%s/pup/yaksuri_%si_populate_pupfns.c" % (backend, backend)
    yutils.copyright_c(filename)
    OUTFILE = open(filename, "a")
    yutils.display(OUTFILE, "#include <stdio.h>\n")
    yutils.display(OUTFILE, "#include \"yaksi.h\"\n")
    yutils.display(OUTFILE, "#include \"yaksu.h\"\n")
    yutils.display(OUTFILE, "#include \"yaksuri_%si.h\"\n" % backend)
    yutils.display(OUTFILE, "#include \"yaksuri_%si_populate_pupfns.h\"\n" % backend)
    yutils.display(OUTFILE, "\n")
    yutils.display(OUTFILE, "int yaksuri_%si_populate_pupfns(yaksi_type_s * type)\n" % backend)
    yutils.display(OUTFILE, "{\n")
    yutils.display(OUTFILE, "int rc = YAKSA_SUCCESS;\n")
    yutils.display(OUTFILE, "yaksuri_%si_type_s *%s = (yaksuri_%si_type_s *) type->backend.%s.priv;\n" \
                   % (backend, backend, backend, backend))
    yutils.display(OUTFILE, "\n")
    yutils.display(OUTFILE, "%s->pack = NULL;\n" % backend)
    yutils.display(OUTFILE, "%s->unpack = NULL;\n" % backend)
    yutils.display(OUTFILE, "\n")
    yutils.display(OUTFILE, "switch (type->kind) {\n")
    for dtype1 in derived_types:
        yutils.display(OUTFILE, "case YAKSI_TYPE_KIND__%s:\n" % dtype1.upper())
        yutils.display(OUTFILE, "switch (type->u.%s.child->kind) {\n" % dtype1)
        for dtype2 in derived_types:
            yutils.display(OUTFILE, "case YAKSI_TYPE_KIND__%s:\n" % dtype2.upper())
            yutils.display(OUTFILE, "rc = yaksuri_%si_populate_pupfns_%s_%s(type);\n" % (backend, dtype1, dtype2))
            yutils.display(OUTFILE, "break;\n")
            yutils.display(OUTFILE, "\n")
        yutils.display(OUTFILE, "case YAKSI_TYPE_KIND__BUILTIN:\n")
        yutils.display(OUTFILE, "rc = yaksuri_%si_populate_pupfns_%s_builtin(type);\n" % (backend, dtype1))
        yutils.display(OUTFILE, "break;\n")
        yutils.display(OUTFILE, "\n")
        yutils.display(OUTFILE, "default:\n")
        yutils.display(OUTFILE, "    break;\n")
        yutils.display(OUTFILE, "}\n")
        yutils.display(OUTFILE, "break;\n")
        yutils.display(OUTFILE, "\n")
    yutils.display(OUTFILE, "default:\n")
    yutils.display(OUTFILE, "    break;\n")
    yutils.display(OUTFILE, "}\n")
    yutils.display(OUTFILE, "\n")
    yutils.display(OUTFILE, "    return rc;\n")
    yutils.display(OUTFILE, "}\n");
    OUTFILE.close()

    for dtype1 in derived_types:
        for dtype2 in derived_types:
            filename = "src/backend/%s/pup/yaksuri_%si_populate_pupfns_%s_%s.c" % (backend, backend, dtype1, dtype2)
            yutils.copyright_c(filename)
            OUTFILE = open(filename, "a")
            yutils.display(OUTFILE, "#include <stdio.h>\n")
            yutils.display(OUTFILE, "#include <stdlib.h>\n")
            yutils.display(OUTFILE, "#include <wchar.h>\n")
            yutils.display(OUTFILE, "#include \"yaksi.h\"\n")
            yutils.display(OUTFILE, "#include \"yaksu.h\"\n")
            yutils.display(OUTFILE, "#include \"yaksuri_%si.h\"\n" % backend)
            yutils.display(OUTFILE, "#include \"yaksuri_%si_populate_pupfns.h\"\n" % backend)
            yutils.display(OUTFILE, "#include \"yaksuri_%si_pup.h\"\n" % backend)
            yutils.display(OUTFILE, "\n")
            yutils.display(OUTFILE, "int yaksuri_%si_populate_pupfns_%s_%s(yaksi_type_s * type)\n" % (backend, dtype1, dtype2))
            yutils.display(OUTFILE, "{\n")
            yutils.display(OUTFILE, "int rc = YAKSA_SUCCESS;\n")
            yutils.display(OUTFILE, "yaksuri_%si_type_s *%s = (yaksuri_%si_type_s *) type->backend.%s.priv;\n" \
                           % (backend, backend, backend, backend))
            yutils.display(OUTFILE, "\n")
            yutils.display(OUTFILE, "char *str = getenv(\"YAKSA_ENV_MAX_NESTING_LEVEL\");\n")
            yutils.display(OUTFILE, "int max_nesting_level;\n")
            yutils.display(OUTFILE, "if (str) {\n")
            yutils.display(OUTFILE, "max_nesting_level = atoi(str);\n")
            yutils.display(OUTFILE, "} else {\n")
            yutils.display(OUTFILE, "max_nesting_level = YAKSI_ENV_DEFAULT_NESTING_LEVEL;\n")
            yutils.display(OUTFILE, "}\n")
            yutils.display(OUTFILE, "\n")

            pupstr = "pack_%s_%s" % (dtype1, dtype2)
            typelist = [ dtype1, dtype2 ]
            switcher(backend, OUTFILE, blklens, builtin_types, builtin_maps, typelist, pupstr, pup_max_nesting - 1)
            yutils.display(OUTFILE, "\n")
            yutils.display(OUTFILE, "return rc;\n")
            yutils.display(OUTFILE, "}\n")
            OUTFILE.close()

        filename = "src/backend/%s/pup/yaksuri_%si_populate_pupfns_%s_builtin.c" % (backend, backend, dtype1)
        yutils.copyright_c(filename)
        OUTFILE = open(filename, "a")
        yutils.display(OUTFILE, "#include <stdio.h>\n")
        yutils.display(OUTFILE, "#include <stdlib.h>\n")
        yutils.display(OUTFILE, "#include <wchar.h>\n")
        yutils.display(OUTFILE, "#include \"yaksi.h\"\n")
        yutils.display(OUTFILE, "#include \"yaksu.h\"\n")
        yutils.display(OUTFILE, "#include \"yaksuri_%si.h\"\n" % backend)
        yutils.display(OUTFILE, "#include \"yaksuri_%si_populate_pupfns.h\"\n" % backend)
        yutils.display(OUTFILE, "#include \"yaksuri_%si_pup.h\"\n" % backend)
        yutils.display(OUTFILE, "\n")
        yutils.display(OUTFILE, "int yaksuri_%si_populate_pupfns_%s_builtin(yaksi_type_s * type)\n" % (backend, dtype1))
        yutils.display(OUTFILE, "{\n")
        yutils.display(OUTFILE, "int rc = YAKSA_SUCCESS;\n")
        yutils.display(OUTFILE, "yaksuri_%si_type_s *%s = (yaksuri_%si_type_s *) type->backend.%s.priv;\n" \
                       % (backend, backend, backend, backend))
        yutils.display(OUTFILE, "\n")
        yutils.display(OUTFILE, "char *str = getenv(\"YAKSA_ENV_MAX_NESTING_LEVEL\");\n")
        yutils.display(OUTFILE, "int max_nesting_level;\n")
        yutils.display(OUTFILE, "if (str) {\n")
        yutils.display(OUTFILE, "max_nesting_level = atoi(str);\n")
        yutils.display(OUTFILE, "} else {\n")
        yutils.display(OUTFILE, "max_nesting_level = YAKSI_ENV_DEFAULT_NESTING_LEVEL;\n")
        yutils.display(OUTFILE, "}\n")
        yutils.display(OUTFILE, "\n")

        pupstr = "pack_%s" % dtype1
        typelist = [ dtype1 ]
        switcher_builtin(backend, OUTFILE, blklens, builtin_types, builtin_maps, typelist, pupstr)
        yutils.display(OUTFILE, "\n")
        yutils.display(OUTFILE, "return rc;\n")
        yutils.display(OUTFILE, "}\n")
        OUTFILE.close()

    ##### generate the Makefile for the pup function selection functions
    filename = "src/backend/%s/pup/Makefile.pup.mk" % backend
    yutils.copyright_makefile(filename)
    OUTFILE = open(filename, "a")
    yutils.display(OUTFILE, "libyaksa_la_SOURCES += \\\n")
    for dtype1 in derived_types:
        for dtype2 in derived_types:
            yutils.display(OUTFILE, "\tsrc/backend/%s/pup/yaksuri_%si_populate_pupfns_%s_%s.c \\\n" % (backend, backend, dtype1, dtype2))
        yutils.display(OUTFILE, "\tsrc/backend/%s/pup/yaksuri_%si_populate_pupfns_%s_builtin.c \\\n" % (backend, backend, dtype1))
    yutils.display(OUTFILE, "\tsrc/backend/%s/pup/yaksuri_%si_populate_pupfns.c\n" % (backend, backend))
    yutils.display(OUTFILE, "\n")
    yutils.display(OUTFILE, "noinst_HEADERS += \\\n")
    yutils.display(OUTFILE, "\tsrc/backend/%s/pup/yaksuri_%si_populate_pupfns.h \\\n" % (backend, backend))
    yutils.display(OUTFILE, "\tsrc/backend/%s/pup/yaksuri_%si_pup.h\n" % (backend, backend))
    OUTFILE.close()

    ##### generate the header file for the pup function selection functions
    filename = "src/backend/%s/pup/yaksuri_%si_populate_pupfns.h" % (backend, backend)
    yutils.copyright_c(filename)
    OUTFILE = open(filename, "a")
    yutils.display(OUTFILE, "#ifndef YAKSURI_%sI_POPULATE_PUPFNS_H_INCLUDED\n" % backend.upper())
    yutils.display(OUTFILE, "#define YAKSURI_%sI_POPULATE_PUPFNS_H_INCLUDED\n" % backend.upper())
    yutils.display(OUTFILE, "\n")
    for dtype1 in derived_types:
        for dtype2 in derived_types:
            yutils.display(OUTFILE, "int yaksuri_%si_populate_pupfns_%s_%s(yaksi_type_s * type);\n" % (backend, dtype1, dtype2))
        yutils.display(OUTFILE, "int yaksuri_%si_populate_pupfns_%s_builtin(yaksi_type_s * type);\n" % (backend, dtype1))
    yutils.display(OUTFILE, "\n")
    yutils.display(OUTFILE, "#endif  /* YAKSURI_%sI_POPULATE_PUPFNS_H_INCLUDED */\n" % backend.upper())
    OUTFILE.close()
Exemplo n.º 2
0
Arquivo: genpup.py Projeto: yqin/yaksa
    args = parser.parse_args()
    if (args.pup_max_nesting < 0):
        parser.print_help()
        print
        print("===> ERROR: pup-max-nesting must be positive")
        sys.exit(1)

    ##### generate the core pack/unpack kernels
    darraylist = []
    yutils.generate_darrays(gencomm.derived_types, darraylist,
                            args.pup_max_nesting - 2)

    for b in builtin_types:
        filename = "src/backend/ze/pup/yaksuri_zei_pup_%s.cl" % b.replace(
            " ", "_")
        yutils.copyright_c(filename)
        OUTFILE = open(filename, "a")
        write_headers()

        emptylist = []
        for op in gencomm.type_ops[b]:
            generate_kernels(b, emptylist, op)

        OUTFILE.close()

    for b in builtin_types:
        for d1 in gencomm.derived_types:
            ##### generate the core pack/unpack kernels (single level)
            filename = "src/backend/ze/pup/yaksuri_zei_pup_%s_%s.cl" % (
                d1, b.replace(" ", "_"))
            yutils.copyright_c(filename)
Exemplo n.º 3
0
import sys, os

# inline.py [infile] [outfile] [topdir] [native: 0|1]

infile = sys.argv[1]
outfile = sys.argv[2]
top_srcdir = sys.argv[3]
native = sys.argv[4]

base = os.path.basename(outfile)
basename = os.path.splitext(base)[0]

sys.path.append(top_srcdir + '/maint/')
import yutils

yutils.copyright_c(outfile)
OUTFILE = open(outfile, 'a')

if native == "1":
    OUTFILE.write("/* native format */\n\n")
else:
    OUTFILE.write("/* SPIR-V format */\n\n")
OUTFILE.write("#include <stdlib.h>\n\n")
OUTFILE.write("const unsigned char %s_str[] = {\n" % basename)

if os.path.exists(infile):
    bfile = open(infile, 'rb')
    char = bfile.read(1)
    OUTFILE.write("%s" % hex(ord(char)))
    while 1:
        char = bfile.read(1)