From 060496fc6ee331e2710ff8ade23317a0a79cbd6c Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Wed, 6 Nov 2024 22:23:49 +0100 Subject: Parse local variables --- lib/Language/Elna/Backend/Allocator.hs | 36 ++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'lib/Language/Elna/Backend/Allocator.hs') diff --git a/lib/Language/Elna/Backend/Allocator.hs b/lib/Language/Elna/Backend/Allocator.hs index 2b410a3..0c3e5c3 100644 --- a/lib/Language/Elna/Backend/Allocator.hs +++ b/lib/Language/Elna/Backend/Allocator.hs @@ -30,26 +30,21 @@ allocate MachineConfiguration{..} = fmap function quadruple (ParameterQuadruple operand1) = ParameterQuadruple (operand operand1) quadruple (CallQuadruple name count) = CallQuadruple name count - quadruple (AddQuadruple operand1 operand2 (TempVariable index)) + quadruple (AddQuadruple operand1 operand2 variable) = AddQuadruple (operand operand1) (operand operand2) - $ Store - $ temporaryRegisters !! fromIntegral index - quadruple (SubtractionQuadruple operand1 operand2 (TempVariable index)) + $ storeVariable variable + quadruple (SubtractionQuadruple operand1 operand2 variable) = SubtractionQuadruple (operand operand1) (operand operand2) - $ Store - $ temporaryRegisters !! fromIntegral index - quadruple (NegationQuadruple operand1 (TempVariable index)) + $ storeVariable variable + quadruple (NegationQuadruple operand1 variable) = NegationQuadruple (operand operand1) - $ Store - $ temporaryRegisters !! fromIntegral index - quadruple (ProductQuadruple operand1 operand2 (TempVariable index)) + $ storeVariable variable + quadruple (ProductQuadruple operand1 operand2 variable) = ProductQuadruple (operand operand1) (operand operand2) - $ Store - $ temporaryRegisters !! fromIntegral index - quadruple (DivisionQuadruple operand1 operand2 (TempVariable index)) + $ storeVariable variable + quadruple (DivisionQuadruple operand1 operand2 variable) = DivisionQuadruple (operand operand1) (operand operand2) - $ Store - $ temporaryRegisters !! fromIntegral index + $ storeVariable variable quadruple (LabelQuadruple label) = LabelQuadruple label quadruple (GoToQuadruple label) = GoToQuadruple label quadruple (EqualQuadruple operand1 operand2 goToLabel) = @@ -64,9 +59,20 @@ allocate MachineConfiguration{..} = fmap function LessOrEqualQuadruple (operand operand1) (operand operand2) goToLabel quadruple (GreaterOrEqualQuadruple operand1 operand2 goToLabel) = GreaterOrEqualQuadruple (operand operand1) (operand operand2) goToLabel + quadruple (AssignQuadruple operand1 variable) + = AssignQuadruple (operand operand1) + $ storeVariable variable operand :: Operand Variable -> Operand (Store r) operand (IntOperand x) = IntOperand x operand (VariableOperand (TempVariable index)) = VariableOperand $ Store $ temporaryRegisters !! fromIntegral index + operand (VariableOperand (LocalVariable index)) + = VariableOperand + $ Store + $ temporaryRegisters !! fromIntegral index + storeVariable (TempVariable index) = + Store $ temporaryRegisters !! fromIntegral index + storeVariable (LocalVariable index) = + Store $ temporaryRegisters !! fromIntegral index -- cgit v1.2.3