diff options
| author | Eugen Wissner <belka@caraus.de> | 2024-10-06 18:07:57 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2024-10-06 18:09:08 +0200 |
| commit | 699cc8684b1571d2501bac2c8bdf461127a420a1 (patch) | |
| tree | 9caecb24007eda52a074f348bbd613da033a2069 /lib/Language/Elna/Backend/Allocator.hs | |
| parent | 35742aa52587400950cf25170c2247f98f498d4d (diff) | |
| download | elna-699cc8684b1571d2501bac2c8bdf461127a420a1.tar.gz | |
Implement division
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 |
