summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2024-12-11 21:44:32 +0100
committerEugen Wissner <belka@caraus.de>2024-12-11 21:44:32 +0100
commitfbd08f27078f2e86c7e0ae65fd8d89658c0c34bd (patch)
treea0b9877afe08fadaeec8bb463e6189c29b445141
parent7fc90f1d2d1686ccf928418b91c043b1d6d9ced2 (diff)
downloadelna-fbd08f27078f2e86c7e0ae65fd8d89658c0c34bd.tar.gz
Add more internal allocation errors
-rw-r--r--lib/Language/Elna/Architecture/RiscV.hs4
-rw-r--r--lib/Language/Elna/Backend/Allocator.hs33
-rw-r--r--lib/Language/Elna/Backend/Intermediate.hs4
-rw-r--r--lib/Language/Elna/CommandLine.hs4
-rw-r--r--lib/Language/Elna/Frontend/AST.hs4
-rw-r--r--lib/Language/Elna/Frontend/NameAnalysis.hs4
-rw-r--r--lib/Language/Elna/Frontend/Parser.hs4
-rw-r--r--lib/Language/Elna/Frontend/SymbolTable.hs4
-rw-r--r--lib/Language/Elna/Frontend/TypeAnalysis.hs4
-rw-r--r--lib/Language/Elna/Frontend/Types.hs4
-rw-r--r--lib/Language/Elna/Glue.hs4
-rw-r--r--lib/Language/Elna/Location.hs4
-rw-r--r--lib/Language/Elna/Object/Elf.hs4
-rw-r--r--lib/Language/Elna/Object/ElfCoder.hs4
-rw-r--r--lib/Language/Elna/Object/StringTable.hs4
-rw-r--r--lib/Language/Elna/RiscV/CodeGenerator.hs4
-rw-r--r--lib/Language/Elna/RiscV/ElfWriter.hs4
-rw-r--r--rakelib/cross.rake4
-rw-r--r--rakelib/shared.rb4
-rw-r--r--rakelib/tester.rake4
-rw-r--r--src/Main.hs4
-rw-r--r--tests/Language/Elna/NameAnalysisSpec.hs4
-rw-r--r--tests/Language/Elna/ParserSpec.hs4
-rw-r--r--tests/Spec.hs4
24 files changed, 116 insertions, 9 deletions
diff --git a/lib/Language/Elna/Architecture/RiscV.hs b/lib/Language/Elna/Architecture/RiscV.hs
index 6619160..ce64b14 100644
--- a/lib/Language/Elna/Architecture/RiscV.hs
+++ b/lib/Language/Elna/Architecture/RiscV.hs
@@ -1,3 +1,7 @@
+{- This Source Code Form is subject to the terms of the Mozilla Public License,
+ v. 2.0. If a copy of the MPL was not distributed with this file, You can
+ obtain one at https://mozilla.org/MPL/2.0/. -}
+
module Language.Elna.Architecture.RiscV
( BaseOpcode(..)
, RelocationType(..)
diff --git a/lib/Language/Elna/Backend/Allocator.hs b/lib/Language/Elna/Backend/Allocator.hs
index 15e8b6f..a56a73b 100644
--- a/lib/Language/Elna/Backend/Allocator.hs
+++ b/lib/Language/Elna/Backend/Allocator.hs
@@ -1,3 +1,7 @@
+{- This Source Code Form is subject to the terms of the Mozilla Public License,
+ v. 2.0. If a copy of the MPL was not distributed with this file, You can
+ obtain one at https://mozilla.org/MPL/2.0/. -}
+
module Language.Elna.Backend.Allocator
( MachineConfiguration(..)
, Store(..)
@@ -28,12 +32,19 @@ data Store r
= RegisterStore r
| StackStore Int32 r
-data AllocationError = AllocationError
+data AllocationError
+ = OutOfRegistersError
+ | UnexpectedProcedureInfoError Info
+ | UndefinedSymbolError Identifier
deriving Eq
instance Show AllocationError
where
- show = const "Ran out of registers during register allocation"
+ show OutOfRegistersError = "Ran out of registers during register allocation"
+ show (UnexpectedProcedureInfoError info) =
+ "Expected to encounter a procedure, got: " <> show info
+ show (UndefinedSymbolError identifier) =
+ concat ["Symbol \"", show identifier, "\" is not defined"]
newtype MachineConfiguration r = MachineConfiguration
{ temporaryRegisters :: [r]
@@ -74,10 +85,14 @@ allocate machineConfiguration globalTable = HashMap.traverseWithKey function
. runAllocator
. mapM quadruple
function :: Identifier -> Vector (Quadruple Variable) -> Either AllocationError (ProcedureQuadruples (Store r))
- function identifier quadruples' =
- let Just (ProcedureInfo localTable _) = SymbolTable.lookup identifier globalTable
- (result, lastState) = run localTable quadruples'
- in makeResult lastState <$> result
+ function procedureName quadruples' =
+ case SymbolTable.lookup procedureName globalTable of
+ Just (ProcedureInfo localTable _) ->
+ let (result, lastState) = run localTable quadruples'
+ in makeResult lastState <$> result
+ Just anotherInfo -> Left $ UnexpectedProcedureInfoError anotherInfo
+ Nothing -> Left $ UndefinedSymbolError procedureName
+
makeResult MachineState{ symbolTable } result = ProcedureQuadruples
{ quadruples = result
, stackSize = fromIntegral $ SymbolTable.size symbolTable * 4
@@ -155,13 +170,13 @@ operand (VariableOperand variableOperand) =
storeVariable :: Variable -> Allocator r (Store r)
storeVariable (TempVariable index) = do
temporaryRegisters' <- Allocator $ lift $ asks $ getField @"temporaryRegisters"
- maybe (Allocator $ throwE AllocationError) (pure . RegisterStore)
+ maybe (Allocator $ throwE OutOfRegistersError) (pure . RegisterStore)
$ temporaryRegisters' !? fromIntegral index
storeVariable (LocalVariable index) = do
temporaryRegisters' <- Allocator $ lift $ asks $ getField @"temporaryRegisters"
- maybe (Allocator $ throwE AllocationError) (pure . StackStore (fromIntegral (succ index) * (-4)))
+ maybe (Allocator $ throwE OutOfRegistersError) (pure . StackStore (fromIntegral (succ index) * (-4)))
$ temporaryRegisters' !? pred (length temporaryRegisters' - fromIntegral index)
storeVariable (ParameterVariable index) = do
temporaryRegisters' <- Allocator $ lift $ asks $ getField @"temporaryRegisters"
- maybe (Allocator $ throwE AllocationError) (pure . StackStore (fromIntegral index * 4))
+ maybe (Allocator $ throwE OutOfRegistersError) (pure . StackStore (fromIntegral index * 4))
$ temporaryRegisters' !? fromIntegral index
diff --git a/lib/Language/Elna/Backend/Intermediate.hs b/lib/Language/Elna/Backend/Intermediate.hs
index bb0ae7e..efc1a61 100644
--- a/lib/Language/Elna/Backend/Intermediate.hs
+++ b/lib/Language/Elna/Backend/Intermediate.hs
@@ -1,3 +1,7 @@
+{- This Source Code Form is subject to the terms of the Mozilla Public License,
+ v. 2.0. If a copy of the MPL was not distributed with this file, You can
+ obtain one at https://mozilla.org/MPL/2.0/. -}
+
module Language.Elna.Backend.Intermediate
( ProcedureQuadruples(..)
, Operand(..)
diff --git a/lib/Language/Elna/CommandLine.hs b/lib/Language/Elna/CommandLine.hs
index b23be7d..19898e2 100644
--- a/lib/Language/Elna/CommandLine.hs
+++ b/lib/Language/Elna/CommandLine.hs
@@ -1,3 +1,7 @@
+{- This Source Code Form is subject to the terms of the Mozilla Public License,
+ v. 2.0. If a copy of the MPL was not distributed with this file, You can
+ obtain one at https://mozilla.org/MPL/2.0/. -}
+
module Language.Elna.CommandLine
( CommandLine(..)
, commandLine
diff --git a/lib/Language/Elna/Frontend/AST.hs b/lib/Language/Elna/Frontend/AST.hs
index c9e05ef..32ca583 100644
--- a/lib/Language/Elna/Frontend/AST.hs
+++ b/lib/Language/Elna/Frontend/AST.hs
@@ -1,3 +1,7 @@
+{- This Source Code Form is subject to the terms of the Mozilla Public License,
+ v. 2.0. If a copy of the MPL was not distributed with this file, You can
+ obtain one at https://mozilla.org/MPL/2.0/. -}
+
module Language.Elna.Frontend.AST
( Declaration(..)
, Identifier(..)
diff --git a/lib/Language/Elna/Frontend/NameAnalysis.hs b/lib/Language/Elna/Frontend/NameAnalysis.hs
index 596ffb2..8e9e7c0 100644
--- a/lib/Language/Elna/Frontend/NameAnalysis.hs
+++ b/lib/Language/Elna/Frontend/NameAnalysis.hs
@@ -1,3 +1,7 @@
+{- This Source Code Form is subject to the terms of the Mozilla Public License,
+ v. 2.0. If a copy of the MPL was not distributed with this file, You can
+ obtain one at https://mozilla.org/MPL/2.0/. -}
+
module Language.Elna.Frontend.NameAnalysis
( nameAnalysis
, Error(..)
diff --git a/lib/Language/Elna/Frontend/Parser.hs b/lib/Language/Elna/Frontend/Parser.hs
index 4878b28..1e4499c 100644
--- a/lib/Language/Elna/Frontend/Parser.hs
+++ b/lib/Language/Elna/Frontend/Parser.hs
@@ -1,3 +1,7 @@
+{- This Source Code Form is subject to the terms of the Mozilla Public License,
+ v. 2.0. If a copy of the MPL was not distributed with this file, You can
+ obtain one at https://mozilla.org/MPL/2.0/. -}
+
module Language.Elna.Frontend.Parser
( Parser
, programP
diff --git a/lib/Language/Elna/Frontend/SymbolTable.hs b/lib/Language/Elna/Frontend/SymbolTable.hs
index 4333acc..5c2153d 100644
--- a/lib/Language/Elna/Frontend/SymbolTable.hs
+++ b/lib/Language/Elna/Frontend/SymbolTable.hs
@@ -1,3 +1,7 @@
+{- This Source Code Form is subject to the terms of the Mozilla Public License,
+ v. 2.0. If a copy of the MPL was not distributed with this file, You can
+ obtain one at https://mozilla.org/MPL/2.0/. -}
+
module Language.Elna.Frontend.SymbolTable
( SymbolTable
, Info(..)
diff --git a/lib/Language/Elna/Frontend/TypeAnalysis.hs b/lib/Language/Elna/Frontend/TypeAnalysis.hs
index 48be782..ea81c4e 100644
--- a/lib/Language/Elna/Frontend/TypeAnalysis.hs
+++ b/lib/Language/Elna/Frontend/TypeAnalysis.hs
@@ -1,3 +1,7 @@
+{- This Source Code Form is subject to the terms of the Mozilla Public License,
+ v. 2.0. If a copy of the MPL was not distributed with this file, You can
+ obtain one at https://mozilla.org/MPL/2.0/. -}
+
module Language.Elna.Frontend.TypeAnalysis
( typeAnalysis
, -- Error(..)
diff --git a/lib/Language/Elna/Frontend/Types.hs b/lib/Language/Elna/Frontend/Types.hs
index a3cc730..f7a7e9d 100644
--- a/lib/Language/Elna/Frontend/Types.hs
+++ b/lib/Language/Elna/Frontend/Types.hs
@@ -1,3 +1,7 @@
+{- This Source Code Form is subject to the terms of the Mozilla Public License,
+ v. 2.0. If a copy of the MPL was not distributed with this file, You can
+ obtain one at https://mozilla.org/MPL/2.0/. -}
+
module Language.Elna.Frontend.Types
( Type(..)
, addressByteSize
diff --git a/lib/Language/Elna/Glue.hs b/lib/Language/Elna/Glue.hs
index ebb0f69..15089e0 100644
--- a/lib/Language/Elna/Glue.hs
+++ b/lib/Language/Elna/Glue.hs
@@ -1,3 +1,7 @@
+{- This Source Code Form is subject to the terms of the Mozilla Public License,
+ v. 2.0. If a copy of the MPL was not distributed with this file, You can
+ obtain one at https://mozilla.org/MPL/2.0/. -}
+
module Language.Elna.Glue
( glue
) where
diff --git a/lib/Language/Elna/Location.hs b/lib/Language/Elna/Location.hs
index 875aa8d..ccd2c1a 100644
--- a/lib/Language/Elna/Location.hs
+++ b/lib/Language/Elna/Location.hs
@@ -1,3 +1,7 @@
+{- This Source Code Form is subject to the terms of the Mozilla Public License,
+ v. 2.0. If a copy of the MPL was not distributed with this file, You can
+ obtain one at https://mozilla.org/MPL/2.0/. -}
+
module Language.Elna.Location
( Identifier(..)
, Location(..)
diff --git a/lib/Language/Elna/Object/Elf.hs b/lib/Language/Elna/Object/Elf.hs
index 8d56dd6..ee1f1af 100644
--- a/lib/Language/Elna/Object/Elf.hs
+++ b/lib/Language/Elna/Object/Elf.hs
@@ -1,3 +1,7 @@
+{- This Source Code Form is subject to the terms of the Mozilla Public License,
+ v. 2.0. If a copy of the MPL was not distributed with this file, You can
+ obtain one at https://mozilla.org/MPL/2.0/. -}
+
module Language.Elna.Object.Elf
( ByteOrder(..)
, Elf32_Addr
diff --git a/lib/Language/Elna/Object/ElfCoder.hs b/lib/Language/Elna/Object/ElfCoder.hs
index b01045a..c94292f 100644
--- a/lib/Language/Elna/Object/ElfCoder.hs
+++ b/lib/Language/Elna/Object/ElfCoder.hs
@@ -1,3 +1,7 @@
+{- This Source Code Form is subject to the terms of the Mozilla Public License,
+ v. 2.0. If a copy of the MPL was not distributed with this file, You can
+ obtain one at https://mozilla.org/MPL/2.0/. -}
+
-- | Object file generation.
module Language.Elna.Object.ElfCoder
( ElfEnvironment(..)
diff --git a/lib/Language/Elna/Object/StringTable.hs b/lib/Language/Elna/Object/StringTable.hs
index e75f2c6..50193a4 100644
--- a/lib/Language/Elna/Object/StringTable.hs
+++ b/lib/Language/Elna/Object/StringTable.hs
@@ -1,3 +1,7 @@
+{- This Source Code Form is subject to the terms of the Mozilla Public License,
+ v. 2.0. If a copy of the MPL was not distributed with this file, You can
+ obtain one at https://mozilla.org/MPL/2.0/. -}
+
module Language.Elna.Object.StringTable
( StringTable
, append
diff --git a/lib/Language/Elna/RiscV/CodeGenerator.hs b/lib/Language/Elna/RiscV/CodeGenerator.hs
index fffbd39..94e0689 100644
--- a/lib/Language/Elna/RiscV/CodeGenerator.hs
+++ b/lib/Language/Elna/RiscV/CodeGenerator.hs
@@ -1,3 +1,7 @@
+{- This Source Code Form is subject to the terms of the Mozilla Public License,
+ v. 2.0. If a copy of the MPL was not distributed with this file, You can
+ obtain one at https://mozilla.org/MPL/2.0/. -}
+
module Language.Elna.RiscV.CodeGenerator
( Directive(..)
, Statement(..)
diff --git a/lib/Language/Elna/RiscV/ElfWriter.hs b/lib/Language/Elna/RiscV/ElfWriter.hs
index 165197d..d72b5af 100644
--- a/lib/Language/Elna/RiscV/ElfWriter.hs
+++ b/lib/Language/Elna/RiscV/ElfWriter.hs
@@ -1,3 +1,7 @@
+{- This Source Code Form is subject to the terms of the Mozilla Public License,
+ v. 2.0. If a copy of the MPL was not distributed with this file, You can
+ obtain one at https://mozilla.org/MPL/2.0/. -}
+
-- | Writer assembler to an object file.
module Language.Elna.RiscV.ElfWriter
( riscv32Elf
diff --git a/rakelib/cross.rake b/rakelib/cross.rake
index 700a8dd..03a69cb 100644
--- a/rakelib/cross.rake
+++ b/rakelib/cross.rake
@@ -1,3 +1,7 @@
+# This Source Code Form is subject to the terms of the Mozilla Public License,
+# v. 2.0. If a copy of the MPL was not distributed with this file, You can
+# obtain one at https://mozilla.org/MPL/2.0/. -}
+
require 'pathname'
require 'uri'
require 'net/http'
diff --git a/rakelib/shared.rb b/rakelib/shared.rb
index 8ecd8cb..d094511 100644
--- a/rakelib/shared.rb
+++ b/rakelib/shared.rb
@@ -1 +1,5 @@
+# This Source Code Form is subject to the terms of the Mozilla Public License,
+# v. 2.0. If a copy of the MPL was not distributed with this file, You can
+# obtain one at https://mozilla.org/MPL/2.0/. -}
+
TMP = Pathname.new('./build')
diff --git a/rakelib/tester.rake b/rakelib/tester.rake
index d164c2a..4caae20 100644
--- a/rakelib/tester.rake
+++ b/rakelib/tester.rake
@@ -1,3 +1,7 @@
+# This Source Code Form is subject to the terms of the Mozilla Public License,
+# v. 2.0. If a copy of the MPL was not distributed with this file, You can
+# obtain one at https://mozilla.org/MPL/2.0/. -}
+
require 'open3'
require 'rake/clean'
require_relative 'shared'
diff --git a/src/Main.hs b/src/Main.hs
index 164f8e1..aff5360 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -1,3 +1,7 @@
+{- This Source Code Form is subject to the terms of the Mozilla Public License,
+ v. 2.0. If a copy of the MPL was not distributed with this file, You can
+ obtain one at https://mozilla.org/MPL/2.0/. -}
+
module Main
( main
) where
diff --git a/tests/Language/Elna/NameAnalysisSpec.hs b/tests/Language/Elna/NameAnalysisSpec.hs
index 10e6ee0..2fd4c82 100644
--- a/tests/Language/Elna/NameAnalysisSpec.hs
+++ b/tests/Language/Elna/NameAnalysisSpec.hs
@@ -1,3 +1,7 @@
+{- This Source Code Form is subject to the terms of the Mozilla Public License,
+ v. 2.0. If a copy of the MPL was not distributed with this file, You can
+ obtain one at https://mozilla.org/MPL/2.0/. -}
+
module Language.Elna.NameAnalysisSpec
( spec
) where
diff --git a/tests/Language/Elna/ParserSpec.hs b/tests/Language/Elna/ParserSpec.hs
index 6c91a11..7a142d1 100644
--- a/tests/Language/Elna/ParserSpec.hs
+++ b/tests/Language/Elna/ParserSpec.hs
@@ -1,3 +1,7 @@
+{- This Source Code Form is subject to the terms of the Mozilla Public License,
+ v. 2.0. If a copy of the MPL was not distributed with this file, You can
+ obtain one at https://mozilla.org/MPL/2.0/. -}
+
module Language.Elna.ParserSpec
( spec
) where
diff --git a/tests/Spec.hs b/tests/Spec.hs
index a824f8c..feacffa 100644
--- a/tests/Spec.hs
+++ b/tests/Spec.hs
@@ -1 +1,5 @@
+{- This Source Code Form is subject to the terms of the Mozilla Public License,
+ v. 2.0. If a copy of the MPL was not distributed with this file, You can
+ obtain one at https://mozilla.org/MPL/2.0/. -}
+
{-# OPTIONS_GHC -F -pgmF hspec-discover #-}