From 8c67849879f70393d81d16dcd23c68e6460cc3fc Mon Sep 17 00:00:00 2001 From: t <970370568@qq.com> Date: Sat, 6 Jan 2024 13:57:20 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=99=E5=9B=9E=E6=A0=B7=E4=BE=8B=E9=83=BD?= =?UTF-8?q?=E8=BF=87=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phase4/splc.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/phase4/splc.py b/phase4/splc.py index b74f8c7..1c256cc 100644 --- a/phase4/splc.py +++ b/phase4/splc.py @@ -8,7 +8,7 @@ max_var_num = 500 register_table = [None] * num_registers stack = ['empty'] -queue = Queue() +queue = [] argmap = {} varmap = {} fun_save = [] @@ -175,7 +175,8 @@ def translate(tac: str): # 传参 for p in argmap[f]: - arg = reg(queue.get()) + # arg = reg(queue.get()) + arg=reg(queue.pop()) para = reg(p) from_heap2heap(arg, para, fi_command) @@ -233,7 +234,8 @@ def translate(tac: str): # command.append(f'{n}') if re.fullmatch(f'ARG {id}', tac): # IF x == y GOTO z _, n = re.split('ARG | ', tac) - queue.put(n) + # queue.put(n) + queue.append(n) if re.fullmatch(f'WRITE {id}', tac): # IF x == y GOTO z _, n = re.split('WRITE | ', tac) fi_command.append(f'lw $4, {reg(n)}') @@ -275,7 +277,7 @@ def translate(tac: str): else: with open(sys.argv[1]+'.s','a') as s: s.write("\n".join(res)) - s.write("\n") + s.write("\n\n") with open(sys.argv[1] + '.s', 'a') as s: s.write('end:')