Skip to content

Commit

Permalink
make static
Browse files Browse the repository at this point in the history
  • Loading branch information
William Grant committed Sep 28, 2022
1 parent efda6f8 commit de7cca1
Showing 1 changed file with 58 additions and 58 deletions.
116 changes: 58 additions & 58 deletions typed_python/compiler/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,64 @@ def resultTypeForCall(self, funcObj, argTypes, kwargTypes):
_resultTypeCache[key] = mergeTypeWrappers(possibleTypes)
return _resultTypeCache[key]

@staticmethod
def getNativeIRString(typedFunc: Function) -> str:
"""
Given a function compiled with Entrypoint, return a text representation
of the generated native (one layer prior to LLVM) code.
Args:
typedFunc (Function): a decorated python function.
Returns:
A string for the function bodies generated (including constructors and destructors)
"""
converter = Runtime.singleton().llvm_compiler.converter
function_name = typedFunc.__name__
# relies on us maintaining our naming conventions (tests would break otherwise)
output_str = ""
for key, value in converter._function_definitions.items():
if function_name in key:
output_str += f"Function {key}" + "_" * 20 + "\n"
output_str += str(value.body.body) + "\n"
output_str += "_" * 80 + "\n"

if not output_str:
raise ValueError(
"no matching function definitions found - has the code been compiled (and run)?"
)

return output_str

@staticmethod
def getLLVMString(typedFunc: Function) -> str:
"""
Given a function compiled with Entrypoint, return a text representation
of the generated LLVM code.
Args:
typedFunc (Function): a decorated python function.
Returns:
A string for the function bodies generated (including constructors and destructors)
"""
converter = Runtime.singleton().llvm_compiler.converter
function_name = typedFunc.__name__
# relies on us maintaining our naming conventions (tests would break otherwise)
output_str = ""
for key, value in converter._functions_by_name.items():
if function_name in key:
output_str += f"Function {key}" + "_" * 20 + "\n"
output_str += str(value) + "\n"
output_str += "_" * 80 + "\n"

if not output_str:
raise ValueError(
"no matching function definitions found - has the code been compiled (and run)?"
)

return output_str


def NotCompiled(pyFunc, returnTypeOverride=None):
"""Decorate 'pyFunc' to prevent it from being compiled.
Expand Down Expand Up @@ -465,61 +523,3 @@ def Compiled(pyFunc):
f.resultTypeFor(*types)

return f


def getNativeIRString(typedFunc: Function) -> str:
"""
Given a function compiled with Entrypoint, return a text representation
of the generated native (one layer prior to LLVM) code.
Args:
typedFunc (Function): a decorated python function.
Returns:
A string for the function bodies generated (including constructors and destructors)
"""
converter = Runtime.singleton().llvm_compiler.converter
function_name = typedFunc.__name__
# relies on us maintaining our naming conventions (tests would break otherwise)
output_str = ""
for key, value in converter._function_definitions.items():
if function_name in key:
output_str += f"Function {key}" + "_" * 20 + "\n"
output_str += str(value.body.body) + "\n"
output_str += "_" * 80 + "\n"

if not output_str:
raise ValueError(
"no matching function definitions found - has the code been compiled (and run)?"
)

return output_str


def getLLVMString(typedFunc: Function) -> str:
"""
Given a function compiled with Entrypoint, return a text representation
of the generated LLVM code.
Args:
typedFunc (Function): a decorated python function.
Returns:
A string for the function bodies generated (including constructors and destructors)
"""
converter = Runtime.singleton().llvm_compiler.converter
function_name = typedFunc.__name__
# relies on us maintaining our naming conventions (tests would break otherwise)
output_str = ""
for key, value in converter._functions_by_name.items():
if function_name in key:
output_str += f"Function {key}" + "_" * 20 + "\n"
output_str += str(value) + "\n"
output_str += "_" * 80 + "\n"

if not output_str:
raise ValueError(
"no matching function definitions found - has the code been compiled (and run)?"
)

return output_str

0 comments on commit de7cca1

Please sign in to comment.