本文整理汇总了Python中Block.Block.get_block_name方法的典型用法代码示例。如果您正苦于以下问题:Python Block.get_block_name方法的具体用法?Python Block.get_block_name怎么用?Python Block.get_block_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Block.Block
的用法示例。
在下文中一共展示了Block.get_block_name方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_3address_code
# 需要导入模块: from Block import Block [as 别名]
# 或者: from Block.Block import get_block_name [as 别名]
def generate_3address_code(statement_list):
global block_counter
block = Block('B' + str(block_counter))
head = block
block_counter += 1
i = 0
statements = statement_list.get_statements()
while i < len(statements):
statement = statements[i]
if statement.get_name() == ':=':
left_expr = evaluate_expr(statement.get_left_expr(), block)
right_expr = evaluate_expr(statement.get_right_expr(), block)
instruction = Instruction('mov')
instruction.set_source_reg1(right_expr.get_register())
instruction.set_destination_reg(left_expr.get_register())
block.add_instructions_to_list(instruction)
elif statement.get_name() == 'while':
block2 = Block('B' + str(block_counter))
block_counter += 1
jump_instr = Instruction('jumpl')
jump_instr.set_label1(block2.get_block_name())
block.add_instructions_to_list(jump_instr)
block.add_next_block(block2)
cond_expr = evaluate_expr(statement.get_cond_expr(), block2)
success_block = generate_3address_code(statement.get_while_block_stmt_list())
success_block.add_instructions_to_list(jump_instr)
success_block.add_next_block(block2)
instruction = Instruction('cbr')
instruction.set_source_reg1(cond_expr.get_register())
instruction.set_label1(success_block.get_block_name())
block = Block('B' + str(block_counter))
block_counter += 1
instruction.set_label2(block.get_block_name())
block2.add_instructions_to_list(instruction)
block2.add_next_block(success_block)
block2.add_next_block(block)
elif statement.get_name() == 'if':
block2 = Block('B' + str(block_counter))
block_counter += 1
jump_instr = Instruction('jumpl')
jump_instr.set_label1(block2.get_block_name())
block.add_instructions_to_list(jump_instr)
block.add_next_block(block2)
cond_expr = evaluate_expr(statement.get_cond_expr(), block2)
if_block = generate_3address_code(statement.get_if_block_stmt_list())
else_block = generate_3address_code(statement.get_else_block_stmt_list())
instruction = Instruction('cbr')
instruction.set_source_reg1(cond_expr.get_register())
instruction.set_label1(if_block.get_block_name())
instruction.set_label2(else_block.get_block_name())
block2.add_instructions_to_list(instruction)
block2.add_next_block(if_block)
block2.add_next_block(else_block)
j = i + 1
if j < len(statements):
block = Block('B' + str(block_counter))
block_counter += 1
jump_instr.set_label1(block.get_block_name())
if_block.add_instructions_to_list(jump_instr)
else_block.add_instructions_to_list(jump_instr)
if_block.add_next_block(block)
else_block.add_next_block(block)
else:
expr = evaluate_expr(statement.get_expr(), block)
instruction = Instruction('writeint')
instruction.set_source_reg1(expr.get_register())
block.add_instructions_to_list(instruction)
i += 1
return head