def only_functions_and_definitions_file(self, defns_and_fns): assert isinstance(defns_and_fns, list) assert all(isinstance(el, tuple) for el in defns_and_fns) defns = sum([defns for defns, fns in defns_and_fns], []) fns = sum([fns for defns, fns in defns_and_fns], []) if len(fns) == 0: return astnodes.MLIRFile(defns, []) else: fns = [astnodes.Operation([], fn) for fn in fns] return astnodes.MLIRFile(defns, [ astnodes.Module(None, None, astnodes.Region([astnodes.Block(None, fns)])) ])
def only_functions_and_definitions_file(self, defns_and_fns): assert isinstance(defns_and_fns, list) assert all(isinstance(el, tuple) for el in defns_and_fns) defns = sum([defns for defns, fns in defns_and_fns], []) fns = sum([fns for defns, fns in defns_and_fns], []) return astnodes.MLIRFile( defns, astnodes.Module(None, None, astnodes.Region(fns)))
def make_mlir_file(module: Optional[mast.Module] = None) -> mast.MLIRFile: """ Returns an instance of :class:`mlir.astnodes.MLIRFile` for *module*. If *module* is *None*, defaults it with an empty :class:`mlir.astnodes.Module`. """ if module is None: module = mast.Module(None, None, mast.Region([])) return mast.MLIRFile([], [module])
def mlir_file_as_definition_and_module_list(self, defns_and_mods): assert isinstance(defns_and_mods, list) assert all(isinstance(el, tuple) for el in defns_and_mods) defns = sum([defns for defns, mods in defns_and_mods], []) mods = sum([mods for defns, mods in defns_and_mods], []) if len(mods) == 1: module = mods[0] else: module = astnodes.Module(None, None, astnodes.Region(mods)) return astnodes.MLIRFile(defns, module)
def mlir_file_as_definition_and_module_list(self, defns_and_mods): assert isinstance(defns_and_mods, list) assert all(isinstance(el, tuple) for el in defns_and_mods) defns = sum([defns for defns, mods in defns_and_mods], []) mods = sum([mods for defns, mods in defns_and_mods], []) return astnodes.MLIRFile(defns, mods)