def get_kernel_code(self, openmp=False, as_filename=False, name='<STR_LIT>'):
assert self.kernel_ast is not None, "<STR_LIT>""<STR_LIT>"<EOL>file_name = '<STR_LIT>'<EOL>if openmp:<EOL><INDENT>file_name += '<STR_LIT>'<EOL><DEDENT>file_name += '<STR_LIT>'<EOL>fp, already_available = self._get_intermediate_file(<EOL>file_name, machine_and_compiler_dependent=False)<EOL>if already_available:<EOL><INDENT>code = fp.read()<EOL><DEDENT>else:<EOL><INDENT>array_declarations, array_dimensions = self._build_array_declarations()<EOL>if openmp:<EOL><INDENT>kernel = deepcopy(self.get_kernel_loop_nest())<EOL>for aref in find_node_type(kernel, c_ast.ArrayRef):<EOL><INDENT>transform_multidim_to_1d_ref(aref, array_dimensions)<EOL><DEDENT>omp_pragmas = [p for p in find_node_type(kernel, c_ast.Pragma)<EOL>if '<STR_LIT>' in p.string]<EOL>if not omp_pragmas:<EOL><INDENT>kernel.insert(<NUM_LIT:0>, c_ast.Pragma("<STR_LIT>"))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>kernel = deepcopy(self.get_kernel_loop_nest())<EOL>for aref in find_node_type(kernel, c_ast.ArrayRef):<EOL><INDENT>transform_multidim_to_1d_ref(aref, array_dimensions)<EOL><DEDENT><DEDENT>function_ast = c_ast.FuncDef(decl=c_ast.Decl(<EOL>name=name, type=self._build_kernel_function_declaration(name=name), quals=[],<EOL>storage=[], funcspec=[], init=None, bitsize=None),<EOL>body=c_ast.Compound(block_items=kernel),<EOL>param_decls=None)<EOL>code = CGenerator().visit(function_ast)<EOL>code = '<STR_LIT>' + code<EOL>fp.write(code)<EOL><DEDENT>fp.close()<EOL>if as_filename:<EOL><INDENT>return fp.name<EOL><DEDENT>else:<EOL><INDENT>return code<EOL><DEDENT>
Generate and return compilable source code with kernel function from AST.

:param openmp: if true, OpenMP code will be generated
:param as_filename: if true, will save to file and return filename
:param name: name of kernel function