~boringcactus/crowbar-reference-compiler

65afa06491818dc3187399c3f16dbf284bec761d — Melody Horn 1 year, 4 months ago 2a17d13
retain function call return value
1 files changed, 7 insertions(+), 4 deletions(-)

M crowbar_reference_compiler/ssagen.py
M crowbar_reference_compiler/ssagen.py => crowbar_reference_compiler/ssagen.py +7 -4
@@ 89,7 89,10 @@ def _(target: FunctionCallExpression, context: CompileContext) -> SsaResult:
        result += compile_to_ssa(expr, context)
        arg_dest = context.next_temp - 1
        args += [f"l %t{arg_dest}"]
    result.code.append(f"call ${target.function.name}({','.join(args)}, ...)")
    result_dest = context.next_temp
    context.next_temp += 1
    # TODO size
    result.code.append(f"%t{result_dest} =l call ${target.function.name}({','.join(args)})")
    return result




@@ 291,7 294,7 @@ def _(target: ArrayIndexExpression, context: CompileContext) -> SsaResult:
    # TODO types
    result.code.append(f"%t{offset} =l mul %t{index}, {scale}")
    result.code.append(f"%t{address} =l add %t{base}, %t{offset}")
    result.code.append(f"%t{dest} =l loadsw %t{address}")
    result.code.append(f"%t{dest} =l loadl %t{address}")
    return result




@@ 326,7 329,7 @@ def _(target: StructPointerElementExpression, context: CompileContext) -> SsaRes
    context.next_temp += 1
    # TODO types
    result.code.append(f"%t{temp} =l add %t{base_dest}, {offset}")
    result.code.append(f"%t{result_dest} =l loadsw %t{temp}")
    result.code.append(f"%t{result_dest} =l loadl %t{temp}")
    return result




@@ 352,7 355,7 @@ def _(target: DirectAssignment, context: CompileContext) -> SsaResult:
        last_instr = sub_result.code.pop()
        _, _, _, location = last_instr.split(' ')
        # TODO type
        sub_result.code.append(f"storew %t{result_dest}, {location}")
        sub_result.code.append(f"storel %t{result_dest}, {location}")
        result += sub_result
    else:
        raise NotImplementedError('assign to ' + str(type(target.destination)))