示例#1
0
文件: genpup.py 项目: yqin/yaksa
            generate_define_kernels(b, emptylist)
            emptylist.pop()
            for d2 in gencomm.derived_types:
                for darray in darraylist:
                    darray.append(d1)
                    darray.append(d2)
                    generate_define_kernels(b, darray)
                    darray.pop()
                    darray.pop()
    yutils.display(OUTFILE, "\n")
    yutils.display(OUTFILE, "#endif  /* YAKSURI_ZEI_PUP_H_INCLUDED */\n")
    OUTFILE.close()

    ##### generate the pup makefile
    filename = "src/backend/ze/pup/Makefile.pup.mk"
    yutils.copyright_makefile(filename)
    OUTFILE = open(filename, "a")
    yutils.display(OUTFILE, "libyaksa_la_SOURCES += \\\n")
    for b in builtin_types:
        yutils.display(
            OUTFILE, "\tsrc/backend/ze/pup/yaksuri_zei_pup_%s.c \\\n" %
            b.replace(" ", "_"))
        for d1 in gencomm.derived_types:
            yutils.display(
                OUTFILE, "\tsrc/backend/ze/pup/yaksuri_zei_pup_%s_%s.c \\\n" %
                (d1, b.replace(" ", "_")))
            for d2 in gencomm.derived_types:
                yutils.display(
                    OUTFILE,
                    "\tsrc/backend/ze/pup/yaksuri_zei_pup_%s_%s_%s.c \\\n" %
                    (d1, d2, b.replace(" ", "_")))
示例#2
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()