diff options
Diffstat (limited to 'lib/Language/Elna/Backend/Allocator.hs')
| -rw-r--r-- | lib/Language/Elna/Backend/Allocator.hs | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/lib/Language/Elna/Backend/Allocator.hs b/lib/Language/Elna/Backend/Allocator.hs index 1ffc85d..701beb8 100644 --- a/lib/Language/Elna/Backend/Allocator.hs +++ b/lib/Language/Elna/Backend/Allocator.hs @@ -12,7 +12,7 @@ import Language.Elna.Location (Identifier(..)) newtype Store r = Store r newtype MachineConfiguration r = MachineConfiguration - { temporaryRegister :: r + { temporaryRegisters :: [r] } allocate @@ -30,14 +30,29 @@ allocate MachineConfiguration{..} = fmap function quadruple (ParameterQuadruple operand1) = ParameterQuadruple (operand operand1) quadruple (CallQuadruple name count) = CallQuadruple name count - quadruple (AddQuadruple operand1 operand2 _) = - AddQuadruple (operand operand1) (operand operand2) (Store temporaryRegister) - quadruple (SubtractionQuadruple operand1 operand2 _) = - SubtractionQuadruple (operand operand1) (operand operand2) (Store temporaryRegister) - quadruple (NegationQuadruple operand1 _) = - NegationQuadruple (operand operand1) (Store temporaryRegister) - quadruple (ProductQuadruple operand1 operand2 _) = - ProductQuadruple (operand operand1) (operand operand2) (Store temporaryRegister) + quadruple (AddQuadruple operand1 operand2 (TempVariable index)) + = AddQuadruple (operand operand1) (operand operand2) + $ Store + $ temporaryRegisters !! fromIntegral index + quadruple (SubtractionQuadruple operand1 operand2 (TempVariable index)) + = SubtractionQuadruple (operand operand1) (operand operand2) + $ Store + $ temporaryRegisters !! fromIntegral index + quadruple (NegationQuadruple operand1 (TempVariable index)) + = NegationQuadruple (operand operand1) + $ Store + $ temporaryRegisters !! fromIntegral index + quadruple (ProductQuadruple operand1 operand2 (TempVariable index)) + = ProductQuadruple (operand operand1) (operand operand2) + $ Store + $ temporaryRegisters !! fromIntegral index + quadruple (DivisionQuadruple operand1 operand2 (TempVariable index)) + = DivisionQuadruple (operand operand1) (operand operand2) + $ Store + $ temporaryRegisters !! fromIntegral index operand :: Operand Variable -> Operand (Store r) operand (IntOperand x) = IntOperand x - operand (VariableOperand _) = VariableOperand (Store temporaryRegister) + operand (VariableOperand (TempVariable index)) + = VariableOperand + $ Store + $ temporaryRegisters !! fromIntegral index |
