summaryrefslogtreecommitdiff
path: root/src/Language/Fiddle/Ast/Internal/SyntaxTree.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Language/Fiddle/Ast/Internal/SyntaxTree.hs')
-rw-r--r--src/Language/Fiddle/Ast/Internal/SyntaxTree.hs50
1 files changed, 41 insertions, 9 deletions
diff --git a/src/Language/Fiddle/Ast/Internal/SyntaxTree.hs b/src/Language/Fiddle/Ast/Internal/SyntaxTree.hs
index ec62c84..5a8aa6d 100644
--- a/src/Language/Fiddle/Ast/Internal/SyntaxTree.hs
+++ b/src/Language/Fiddle/Ast/Internal/SyntaxTree.hs
@@ -14,8 +14,10 @@ module Language.Fiddle.Ast.Internal.SyntaxTree
RegisterOffset,
BitsOffset,
QMd,
- NamedUnit(..),
+ NamedUnit (..),
FieldSpan (..),
+ QRegMetadata (..),
+ QBitsMetadata (..),
-- Witness Types
Witness (..),
-- AST Types
@@ -81,6 +83,38 @@ data FieldSpan u where
FieldSpan u
deriving (Eq, Ord, Show, Generic, ToJSON, FromJSON)
+-- | Metadata about a register.
+data QRegMetadata (checkStage :: Bool) where
+ QRegMetadata ::
+ { -- | The span of the register. Only reified in the Check stage.
+ regSpan :: When checkStage (FieldSpan Bytes),
+ -- | Is this a reified "reserved" register?
+ regIsPadding :: Bool,
+ -- | Was this register unnamed? This implies that the register should not
+ -- emit getters and setters.
+ regIsUnnamed :: Bool,
+ -- | Full path to the register.
+ regFullPath :: NonEmpty String
+ } ->
+ QRegMetadata checkStage
+ deriving (Generic, ToJSON)
+
+deriving instance
+ (FromJSON (When s (FieldSpan Bytes))) =>
+ FromJSON (QRegMetadata s)
+
+data QBitsMetadata (checkStage :: Bool) where
+ QBitsMetadata ::
+ { bitsSpan :: When checkStage (FieldSpan Bits),
+ bitsFullPath :: NonEmpty String
+ } ->
+ QBitsMetadata checkStage
+ deriving (Generic, ToJSON)
+
+deriving instance
+ (FromJSON (When s (FieldSpan Bits))) =>
+ FromJSON (QBitsMetadata s)
+
type BitsOffset stage = RegisterOffset stage
-- | Type used for the RegisterOffset type. This is populated in the check
@@ -461,9 +495,9 @@ data ObjTypeDecl stage f a where
RegisterDecl ::
{ -- | Offset within the register. Calculated during the consistency check.
-- The offset is calculated from the top-level structure.
- regSpan :: When (stage .>= Checked) (FieldSpan Bytes),
+ qRegMeta :: When (stage .>= Qualified) (QRegMetadata (stage .>= Checked)),
-- | Optional register modifier.
- regModifier :: Maybe (Modifier f a),
+ regModifier :: Guaranteed (stage .>= Qualified) (Modifier f a),
-- | Optional register identifier. This is guaranteed to exist after
-- Qualification, where a generated identifier will be provided if it
-- doesn't exist.
@@ -478,10 +512,8 @@ data ObjTypeDecl stage f a where
ObjTypeDecl stage f a
-- | A reserved declaration for padding or alignment.
ReservedDecl ::
- { -- | Offset and size of this reserved block.
- regSpan :: When (stage .>= Checked) (FieldSpan Bytes),
- -- | Generated identifier for this reserved field.
- reservedIdent :: When (stage .>= Qualified) String,
+ { -- | Reserved "registers" should be reified in the qualification phase.
+ noReservedAfterQualification :: Witness (stage .< Qualified),
-- | The expression for reserved space.
reservedExpr :: Expression Bits stage f a,
-- | Annotation for the reserved declaration.
@@ -512,7 +544,7 @@ data Modifier f a where
deriving (Generic, Annotated, Alter, Typeable, Walk)
-- | Enumerates the different types of register modifiers.
-data ModifierKeyword = Rw | Ro | Wo
+data ModifierKeyword = Rw | Ro | Wo | Pr
deriving (Eq, Ord, Show, Read, Typeable)
-- | Represents a deferred register body, consisting of a list of bit
@@ -568,7 +600,7 @@ data RegisterBitsDecl stage f a where
DefinedBits ::
{ -- | The offset for these bits. This is calculated during the
-- ConsistencyCheck phase, so until this phase it's just ().
- definedBitsSpan :: When (stage .>= Checked) (FieldSpan Bits),
+ qBitsMetadata :: When (stage .>= Qualified) (QBitsMetadata (stage .>= Checked)),
-- | Bit declarations.
-- | Optional modifier for the bits.
definedBitsModifier :: Maybe (Modifier f a),