예제 #1
0
 def visit_FunctionDecl(self, node):
     s = r""
     if node.static:
         s += r"static "
     if node.inline:
         s += r"inline "
     if node.kernel:
         s += r"__kernel "
     s += r"%s %s(...)" % (codegen_type(node.return_type), node.name)
     return s
예제 #2
0
 def visit_FunctionDecl(self, node):
     s = r""
     if node.static:
         s += r"static "
     if node.inline:
         s += r"inline "
     if node.kernel:
         s += r"__kernel "
     s += r"%s %s(...)" % (codegen_type(node.return_type), node.name)
     return s
예제 #3
0
 def visit_SymbolRef(self, node):
     s = ""
     if node._global:
         s += "__global "
     if node._local:
         s += "__local "
     if node._const:
         s += "const "
     if node.type is not None:
         s += "%s " % codegen_type(node.type)
     return "%s%s" % (s, node.name)
예제 #4
0
 def visit_SymbolRef(self, node):
     s = r""
     if node._global:
         s += r"__global "
     if node._local:
         s += r"__local "
     if node._const:
         s += r"__const "
     if node.type:
         s += r"%s " % codegen_type(node.type)
     s += r"%s" % node.name
     return s
예제 #5
0
 def visit_SymbolRef(self, node):
     s = r""
     if node._global:
         s += r"__global "
     if node._local:
         s += r"__local "
     if node._const:
         s += r"__const "
     if node.type:
         s += r"%s " % codegen_type(node.type)
     s += r"%s" % node.name
     return s
예제 #6
0
파일: codegen.py 프로젝트: i-Zaak/ctree
 def visit_FunctionDecl(self, node):
     params = ", ".join(map(str, node.params))
     s = ""
     if node.kernel:
         s += "__kernel "
     if node.static:
         s += "static "
     if node.inline:
         s += "inline "
     s += "%s %s(%s)" % (codegen_type(node.return_type), node.name, params)
     if node.defn:
         s += " %s" % self._genblock(node.defn)
     return s
예제 #7
0
 def visit_FunctionDecl(self, node):
     params = ", ".join(map(str, node.params))
     s = ""
     if node.kernel:
         s += "__kernel "
     if node.static:
         s += "static "
     if node.inline:
         s += "inline "
     s += "%s %s(%s)" % (codegen_type(node.return_type), node.name, params)
     if node.defn:
         s += " %s" % self._genblock(node.defn)
     return s
예제 #8
0
파일: codegen.py 프로젝트: i-Zaak/ctree
 def visit_SymbolRef(self, node):
     s = ""
     if node._global:
         s += "__global "
     if node._local:
         s += "__local "
     if node._static:
         s += "static "
     if node._const:
         s += "const "
     if node.type is not None:
         s += "%s " % codegen_type(node.type)
     return "%s%s" % (s, node.name)
예제 #9
0
파일: codegen.py 프로젝트: ucb-sejits/ctree
 def visit_FunctionDecl(self, node):
     params = ", ".join(map(str, node.params))
     s = []
     for attrib in node.attributes:
         s.append("__attribute__ (({}))".format(attrib))
     if node.kernel:
         s.append("__kernel")
     if node.static:
         s.append("static")
     if node.inline:
         s.append("inline")
     s.append("%s %s(%s)" % (codegen_type(node.return_type), node.name, params))
     if node.defn:
         s.append("%s" % self._genblock(node.defn))
     return " ".join(s)
예제 #10
0
파일: codegen.py 프로젝트: ucb-sejits/ctree
 def visit_FunctionDecl(self, node):
     params = ", ".join(map(str, node.params))
     s = []
     for attrib in node.attributes:
         s.append("__attribute__ (({}))".format(attrib))
     if node.kernel:
         s.append("__kernel")
     if node.static:
         s.append("static")
     if node.inline:
         s.append("inline")
     s.append("%s %s(%s)" %
              (codegen_type(node.return_type), node.name, params))
     if node.defn:
         s.append("%s" % self._genblock(node.defn))
     return " ".join(s)
예제 #11
0
    ctypes.c_double:
    lambda t: "double",
    ctypes.c_char:
    lambda t: "char",
    ctypes.c_char_p:
    lambda t: "char*",
    ctypes.c_void_p:
    lambda t: "void*",
    ctypes.c_bool:
    lambda t: "bool",
    ctypes.c_ulong:
    lambda t: "size_t",
    ctypes.c_uint32:
    lambda t: "uint32_t",
    type(None):
    lambda n: "void",
    _ctypes.Array:
    lambda ct: "%s*" % codegen_type(ct._type_()),
    _ctypes._Pointer:
    lambda ct: "%s*" % codegen_type(ct._type_()),
})

#register version specific nodes

if sys.version_info >= (3, 0):
    pass

else:

    register_type_recognizers({long: ctypes.c_long})
예제 #12
0
def codegen_ndptr(ndptr):
    prefix = ""
    if getattr(ndptr, "_global", False):
        prefix += "__global "
    return prefix + "%s*" % codegen_type(ndptr._dtype_.type())
예제 #13
0
파일: codegen.py 프로젝트: ucb-sejits/ctree
 def visit_Cast(self, node):
     value = self._parenthesize(node, node.value)
     return "(%s) %s" % (codegen_type(node.type), value)
예제 #14
0
 def visit_Cast(self, node):
     value = self._parenthesize(node, node.value)
     return "(%s) %s" % (codegen_type(node.type), value)
예제 #15
0
        type(None): lambda t: None,
    })

    register_type_codegenerators({
        ctypes.c_int: lambda t: "int",
        ctypes.c_long: lambda t: "long",
        ctypes.c_float: lambda t: "float",
        ctypes.c_double: lambda t: "double",
        ctypes.c_char: lambda t: "char",
        ctypes.c_char_p: lambda t: "char*",
        ctypes.c_void_p: lambda t: "void*",
        ctypes.c_bool: lambda t: "bool",
        ctypes.c_ulong: lambda t: "size_t",
        type(None): lambda n: "void",

        _ctypes.Array: lambda ct: "%s*" % codegen_type(ct._type_()),
        _ctypes._Pointer: lambda ct: "%s*" % codegen_type(ct._type_()),

    })
else:
    register_type_recognizers({
        types.IntType: lambda t: ctypes.c_long(t),
        types.LongType: lambda t: ctypes.c_long(t),
        types.BooleanType: lambda t: ctypes.c_bool(t),
        types.FloatType: lambda t: ctypes.c_double(t),
        types.StringType: lambda t: ctypes.c_char(t) if len(t) == 1 else
        ctypes.c_char_p(t),
        types.NoneType: lambda t: None,
    })

    register_type_codegenerators({
예제 #16
0
register_type_codegenerators({
    ctypes.c_short: lambda t: "short",
    ctypes.c_int: lambda t: "int",
    ctypes.c_long: lambda t: "long" if X64_BIT else "int",
    ctypes.c_float: lambda t: "float",
    ctypes.c_double: lambda t: "double",
    ctypes.c_char: lambda t: "char",
    ctypes.c_char_p: lambda t: "char*",
    ctypes.c_void_p: lambda t: "void*",
    ctypes.c_bool: lambda t: "bool",
    ctypes.c_ulong: lambda t: "size_t",
    ctypes.c_uint32: lambda t: "uint32_t",
    type(None): lambda n: "void",

    _ctypes.Array: lambda ct: "%s*" % codegen_type(ct._type_()),
    _ctypes._Pointer: lambda ct: "%s*" % codegen_type(ct._type_()),

})

#register version specific nodes

if sys.version_info >= (3, 0):
    pass

else:

    register_type_recognizers({
        long: ctypes.c_long
    })
예제 #17
0
파일: __init__.py 프로젝트: i-Zaak/ctree
def codegen_ndptr(ndptr):
    prefix = ""
    if getattr(ndptr, "_global", False):
        prefix += "__global "
    return prefix + "%s*" % codegen_type(ndptr._dtype_.type())