@@ -465,3 +465,88 @@ def Compiled(pyFunc):
465465 f .resultTypeFor (* types )
466466
467467 return f
468+
469+
470+ def getNativeIRCode (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 ('no matching function definitions found - has the code been compiled (and run)?' )
493+
494+ return output_str
495+
496+
497+ def getNativeIRString (typedFunc : Function ) -> str :
498+ """
499+ Given a function compiled with Entrypoint, return a text representation
500+ of the generated native (one layer prior to LLVM) code.
501+
502+ Args:
503+ typedFunc (Function): a decorated python function.
504+
505+ Returns:
506+ A string for the function bodies generated (including constructors and destructors)
507+ """
508+ converter = Runtime .singleton ().llvm_compiler .converter
509+ function_name = typedFunc .__name__
510+ # relies on us maintaining our naming conventions (tests would break otherwise)
511+ output_str = ""
512+ for key , value in converter ._function_definitions .items ():
513+ if function_name in key :
514+ output_str += f"Function { key } " + "_" * 20 + "\n "
515+ output_str += str (value .body .body ) + "\n "
516+ output_str += "_" * 80 + "\n "
517+
518+ if not output_str :
519+ raise ValueError (
520+ "no matching function definitions found - has the code been compiled (and run)?"
521+ )
522+
523+ return output_str
524+
525+
526+ def getLLVMString (typedFunc : Function ) -> str :
527+ """
528+ Given a function compiled with Entrypoint, return a text representation
529+ of the generated LLVM code.
530+
531+ Args:
532+ typedFunc (Function): a decorated python function.
533+
534+ Returns:
535+ A string for the function bodies generated (including constructors and destructors)
536+ """
537+ converter = Runtime .singleton ().llvm_compiler .converter
538+ function_name = typedFunc .__name__
539+ # relies on us maintaining our naming conventions (tests would break otherwise)
540+ output_str = ""
541+ for key , value in converter ._functions_by_name .items ():
542+ if function_name in key :
543+ output_str += f"Function { key } " + "_" * 20 + "\n "
544+ output_str += str (value ) + "\n "
545+ output_str += "_" * 80 + "\n "
546+
547+ if not output_str :
548+ raise ValueError (
549+ "no matching function definitions found - has the code been compiled (and run)?"
550+ )
551+
552+ return output_str
0 commit comments