本文整理汇总了Python中optimizer.Optimizer.compile方法的典型用法代码示例。如果您正苦于以下问题:Python Optimizer.compile方法的具体用法?Python Optimizer.compile怎么用?Python Optimizer.compile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类optimizer.Optimizer
的用法示例。
在下文中一共展示了Optimizer.compile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: compilePB
# 需要导入模块: from optimizer import Optimizer [as 别名]
# 或者: from optimizer.Optimizer import compile [as 别名]
def compilePB(pyBonCode: str, verbosity=0) -> str:
"""Compile Python Bonsai code and return Bonsai code.
This function combines the various stages of the compiler and optionally outputs the interim stages.
The stages called are (in order):
- Lexer
- Syntactic Analyzer (Parser)
- Semantic Analyzer
- Intermediate Code Generator
- Optimizer
- Intermediate Code Compiler
Parameters:
@param pyBonCode: the Python Bonsai code to be compiled as raw source
@param verbosity: the verbosity level defines which interim stages to print
@type pyBonCode: str
@type verbosity: int
"""
if verbosity is None:
verbosity = 0
tokens = Lexer(pyBonCode).tokens()
if verbosity > 1:
print("Tokens:", file=stderr)
for token in tokens:
print(token, file=stderr)
print("", file=stderr)
ast = SyntacticAnalysis(tokens)
SemanticAnalysis(ast)
ic = IntermediateCode()
ic.fromSyntaxTree(ast)
if verbosity > 2:
print("Original instructions:", file=stderr)
_print_instructions(ic)
print("\nSymbols:", file=stderr)
print(ic.symbolTable, file=stderr)
print("\nRegisters:", file=stderr)
print(ic.registers, file=stderr)
oc = Optimizer(ic)
bonCode = oc.compile()
if verbosity > 0:
print("\nOptimized instructions:", file=stderr)
_print_instructions(oc)
print("\nSymbols:", file=stderr)
print(oc.symbolTable, file=stderr)
print("\nRegisters:", file=stderr)
print(oc.registers, file=stderr)
print("\nCompiled Bonsai code:", file=stderr)
print(bonCode, file=stderr)
return bonCode