summaryrefslogtreecommitdiff
path: root/src/Language/Fiddle/Ast/Internal/SyntaxTree.hs
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2024-10-07 17:33:18 -0600
committerJosh Rahm <joshuarahm@gmail.com>2024-10-07 17:33:18 -0600
commit6a19d9c24de9b450cf6d66859345ee5f02087ee0 (patch)
treef519cfadd2e86e2aada2f59ef33eb80d3b251cbf /src/Language/Fiddle/Ast/Internal/SyntaxTree.hs
parentc407758a424dcf5abaf6192c6d17ce46853a5f60 (diff)
downloadfiddle-6a19d9c24de9b450cf6d66859345ee5f02087ee0.tar.gz
fiddle-6a19d9c24de9b450cf6d66859345ee5f02087ee0.tar.bz2
fiddle-6a19d9c24de9b450cf6d66859345ee5f02087ee0.zip
Add offset information to some AST elements.wip
Diffstat (limited to 'src/Language/Fiddle/Ast/Internal/SyntaxTree.hs')
-rw-r--r--src/Language/Fiddle/Ast/Internal/SyntaxTree.hs23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/Language/Fiddle/Ast/Internal/SyntaxTree.hs b/src/Language/Fiddle/Ast/Internal/SyntaxTree.hs
index 73c4303..1e9ace7 100644
--- a/src/Language/Fiddle/Ast/Internal/SyntaxTree.hs
+++ b/src/Language/Fiddle/Ast/Internal/SyntaxTree.hs
@@ -13,6 +13,8 @@ module Language.Fiddle.Ast.Internal.SyntaxTree
FiddleUnitInterface,
QualificationMetadata,
CommonQualificationData (..),
+ RegisterOffset,
+ BitsOffset,
-- Witness Types
Witness (..),
WitnessType,
@@ -59,6 +61,7 @@ import Data.Text (Text)
import Data.Type.Bool
import Data.Typeable
import Data.Void (Void)
+import Data.Word (Word32)
import GHC.Generics
import Language.Fiddle.Ast.Internal.Instances
import Language.Fiddle.Ast.Internal.Kinds
@@ -73,6 +76,16 @@ newtype CommonQualificationData
}
deriving (Eq, Ord, Show)
+type BitsOffset stage = RegisterOffset stage
+
+-- | Type used for the RegisterOffset type. This is populated in the check
+-- stage, which will attach the appropriate offset to the register. This helps
+-- backends so they don't have to recalculate this offset.
+type family RegisterOffset stage where
+ RegisterOffset stage = If (stage < Checked) () Word32
+
+-- | Type which stores metadata after qualification. Before qualification, this
+-- metadata has not been calculated and so is unset.
type family QualificationMetadata stage t where
QualificationMetadata stage t =
If (stage < Qualified) () t
@@ -470,7 +483,10 @@ data ObjTypeDecl stage f a where
ObjTypeDecl stage f a
-- | A register declaration.
RegisterDecl ::
- { -- | Optional register modifier.
+ { -- | Offset within the register. Calculated during the consistency check.
+ -- The offset is calculated from the top-level structure.
+ regOffset :: RegisterOffset stage,
+ -- | Optional register modifier.
regModifier :: Maybe (Modifier f a),
-- | Optional register identifier.
regIdent :: Maybe (Identifier f a),
@@ -569,7 +585,10 @@ data RegisterBitsDecl stage f a where
RegisterBitsDecl stage f a
-- | Declaration for defined bits in a register.
DefinedBits ::
- { -- | Optional modifier for the bits.
+ { -- | The offset for these bits. This is calculated during the
+ -- ConsistencyCheck phase, so until this phase it's just ().
+ definedBitsOffset :: BitsOffset stage,
+ -- | Optional modifier for the bits.
definedBitsModifier :: Maybe (Modifier f a),
-- | Identifier for the bits.
definedBitsIdent :: Identifier f a,