@@ -392,6 +392,64 @@ def resultTypeForCall(self, funcObj, argTypes, kwargTypes):
392392 _resultTypeCache [key ] = mergeTypeWrappers (possibleTypes )
393393 return _resultTypeCache [key ]
394394
395+ @staticmethod
396+ def getNativeIRString (typedFunc : Function ) -> str :
397+ """
398+ Given a function compiled with Entrypoint, return a text representation
399+ of the generated native (one layer prior to LLVM) code.
400+
401+ Args:
402+ typedFunc (Function): a decorated python function.
403+
404+ Returns:
405+ A string for the function bodies generated (including constructors and destructors)
406+ """
407+ converter = Runtime .singleton ().llvm_compiler .converter
408+ function_name = typedFunc .__name__
409+ # relies on us maintaining our naming conventions (tests would break otherwise)
410+ output_str = ""
411+ for key , value in converter ._function_definitions .items ():
412+ if function_name in key :
413+ output_str += f"Function { key } " + "_" * 20 + "\n "
414+ output_str += str (value .body .body ) + "\n "
415+ output_str += "_" * 80 + "\n "
416+
417+ if not output_str :
418+ raise ValueError (
419+ "no matching function definitions found - has the code been compiled (and run)?"
420+ )
421+
422+ return output_str
423+
424+ @staticmethod
425+ def getLLVMString (typedFunc : Function ) -> str :
426+ """
427+ Given a function compiled with Entrypoint, return a text representation
428+ of the generated LLVM code.
429+
430+ Args:
431+ typedFunc (Function): a decorated python function.
432+
433+ Returns:
434+ A string for the function bodies generated (including constructors and destructors)
435+ """
436+ converter = Runtime .singleton ().llvm_compiler .converter
437+ function_name = typedFunc .__name__
438+ # relies on us maintaining our naming conventions (tests would break otherwise)
439+ output_str = ""
440+ for key , value in converter ._functions_by_name .items ():
441+ if function_name in key :
442+ output_str += f"Function { key } " + "_" * 20 + "\n "
443+ output_str += str (value ) + "\n "
444+ output_str += "_" * 80 + "\n "
445+
446+ if not output_str :
447+ raise ValueError (
448+ "no matching function definitions found - has the code been compiled (and run)?"
449+ )
450+
451+ return output_str
452+
395453
396454def NotCompiled (pyFunc , returnTypeOverride = None ):
397455 """Decorate 'pyFunc' to prevent it from being compiled.
@@ -465,61 +523,3 @@ def Compiled(pyFunc):
465523 f .resultTypeFor (* types )
466524
467525 return f
468-
469-
470- def getNativeIRString (typedFunc : Function ) -> str :
471- """
472- Given a function compiled with Entrypoint, return a text representation
473- of the generated native (one layer prior to LLVM) code.
474-
475- Args:
476- typedFunc (Function): a decorated python function.
477-
478- Returns:
479- A string for the function bodies generated (including constructors and destructors)
480- """
481- converter = Runtime .singleton ().llvm_compiler .converter
482- function_name = typedFunc .__name__
483- # relies on us maintaining our naming conventions (tests would break otherwise)
484- output_str = ""
485- for key , value in converter ._function_definitions .items ():
486- if function_name in key :
487- output_str += f"Function { key } " + "_" * 20 + "\n "
488- output_str += str (value .body .body ) + "\n "
489- output_str += "_" * 80 + "\n "
490-
491- if not output_str :
492- raise ValueError (
493- "no matching function definitions found - has the code been compiled (and run)?"
494- )
495-
496- return output_str
497-
498-
499- def getLLVMString (typedFunc : Function ) -> str :
500- """
501- Given a function compiled with Entrypoint, return a text representation
502- of the generated LLVM code.
503-
504- Args:
505- typedFunc (Function): a decorated python function.
506-
507- Returns:
508- A string for the function bodies generated (including constructors and destructors)
509- """
510- converter = Runtime .singleton ().llvm_compiler .converter
511- function_name = typedFunc .__name__
512- # relies on us maintaining our naming conventions (tests would break otherwise)
513- output_str = ""
514- for key , value in converter ._functions_by_name .items ():
515- if function_name in key :
516- output_str += f"Function { key } " + "_" * 20 + "\n "
517- output_str += str (value ) + "\n "
518- output_str += "_" * 80 + "\n "
519-
520- if not output_str :
521- raise ValueError (
522- "no matching function definitions found - has the code been compiled (and run)?"
523- )
524-
525- return output_str
0 commit comments