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
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)
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
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
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)
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)
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})
def codegen_ndptr(ndptr): prefix = "" if getattr(ndptr, "_global", False): prefix += "__global " return prefix + "%s*" % codegen_type(ndptr._dtype_.type())
def visit_Cast(self, node): value = self._parenthesize(node, node.value) return "(%s) %s" % (codegen_type(node.type), value)
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({
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 })