def run_definition(self, i, d): from pecan.lang.typed_ir_lowering import TypedIRLowering from pecan.lang.optimizer.optimizer import UntypedOptimizer, Optimizer if isinstance(d, NamedPred): settings.log( 1, lambda: '[DEBUG] Type inference and IR lowering for: {}'. format(d.name)) transformed_def = TypedIRLowering(self).transform( self.type_infer(d)) if settings.opt_enabled(): settings.log( 1, lambda: '[DEBUG] Performing typed optimization on: {}'. format(d.name)) transformed_def = Optimizer(self).optimize(transformed_def) transformed_def = TypedIRLowering(self).transform(transformed_def) settings.log(1, lambda: 'Lowered IR:') settings.log(1, lambda: transformed_def) self.defs[i] = transformed_def self.preds[d.name] = self.defs[i] self.preds[d.name].evaluate(self) settings.log(0, lambda: self.preds[d.name]) else: return d.evaluate(self)
def from_source(source_code, *args, **kwargs): prog = pecan_parser.parse(source_code) settings.log(4, lambda: 'Parsed program:') settings.log(4, lambda: prog) prog.search_paths = make_search_paths( filename=kwargs.get('filename', None)) prog.loader = load if settings.get_extract_implications(): prog.extract_implications() prog = ASTToIR().transform(prog) settings.log(0, lambda: 'Search path: {}'.format(prog.search_paths)) # Load the standard library prog = settings.include_stdlib(prog, load, args, kwargs) if settings.opt_enabled(): prog = UntypedOptimizer(prog).optimize() settings.log(1, lambda: '(Untyped) Optimized program:') settings.log(1, lambda: prog) return prog