Cerata
A library to generate structural hardware designs
cerata::Type Class Referenceabstract

A Type. More...

#include <type.h>

+ Inheritance diagram for cerata::Type:
+ Collaboration diagram for cerata::Type:

Public Types

enum  ID {
  BIT, VECTOR, INTEGER, STRING,
  BOOLEAN, RECORD
}
 The Type ID. Used for convenient type checking. More...
 

Public Member Functions

 Type (std::string name, ID id)
 Type constructor. More...
 
ID id () const
 Return the Type ID.
 
virtual bool IsEqual (const Type &other) const
 Determine if this Type is exactly equal to an other Type. More...
 
bool Is (ID type_id) const
 Return true if the Type ID is type_id, false otherwise.
 
virtual bool IsPhysical () const =0
 Return true if the Type has an immediate physical representation, false otherwise.
 
virtual bool IsNested () const =0
 Return true if the Type is a nested, false otherwise.
 
virtual bool IsGeneric () const =0
 Return true if the Type is a generic type.
 
virtual std::optional< Node * > width () const
 Return the width of the type, if it is synthesizable.
 
std::string ToString (bool show_meta=false, bool show_mappers=false) const
 Return the Type ID as a human-readable string.
 
std::vector< std::shared_ptr< TypeMapper > > mappers () const
 Return possible type mappers.
 
void AddMapper (const std::shared_ptr< TypeMapper > &mapper, bool remove_existing=true)
 Add a type mapper.
 
std::optional< std::shared_ptr< TypeMapper > > GetMapper (Type *other, bool generate_implicit=true)
 Get a mapper to another type, if it exists. Generates one, if possible, when generate_implicit = true.
 
int RemoveMappersTo (Type *other)
 Remove all mappers to a specific type.
 
std::optional< std::shared_ptr< TypeMapper > > GetMapper (const std::shared_ptr< Type > &other)
 Get a mapper to another type, if it exists.
 
virtual bool CanGenerateMapper (const Type &other) const
 Check if a mapper can be generated to another specific type.
 
virtual std::shared_ptr< TypeMapperGenerateMapper (Type *other)
 Generate a new mapper to a specific other type. Should be checked with CanGenerateMapper first, or throws.
 
virtual std::vector< Node * > GetGenerics () const
 Obtain any nodes that this type uses as generics.
 
virtual std::vector< Type * > GetNested () const
 Obtain any nested types.
 
virtual std::shared_ptr< TypeCopy (const NodeMap &rebinding) const =0
 Make a copy of the type, and rebind any type generic nodes that are keys in the rebinding to their values. More...
 
virtual std::shared_ptr< TypeCopy () const
 Make a copy of the type without rebinding. More...
 
std::shared_ptr< Typeoperator() (std::vector< Node * > nodes)
 Make a copy of the type, and rebind any type generic nodes in order of the GetGenerics call. More...
 
std::shared_ptr< Typeoperator() (const std::vector< std::shared_ptr< Node >> &nodes)
 Make a copy of the type, and rebind any type generic nodes in order of the GetGenerics call. More...
 
- Public Member Functions inherited from cerata::Named
 Named (std::string name)
 Named constructor.
 
std::string name () const
 Return the name of the object.
 
void SetName (std::string name)
 Change the name of the object.
 
virtual ~Named ()=default
 Destructor.
 

Public Attributes

std::unordered_map< std::string, std::string > meta
 KV storage for metadata of tools or specific backend implementations.
 

Protected Attributes

ID id_
 Type ID.
 
std::vector< std::shared_ptr< TypeMapper > > mappers_
 A list of mappers that can map this type to another type.
 

Detailed Description

A Type.

Types can logically be classified as follows.

Physical:

  • Yes. They can be immediately represented as bits in hardware.
  • No. They can not be represented as bits in hardware without a more elaborate definition.

Generic:

  • No. Not parametrized by some node.
  • Yes. Parameterized by some node.

Nested:

  • No. These types contain no subtype.
  • Yes. These types contain some subtype, and so other properties depend on the sub-types used.

Definition at line 63 of file type.h.

Member Enumeration Documentation

◆ ID

The Type ID. Used for convenient type checking.

Enumerator
BIT 

Yes | No | No.

VECTOR 

Yes | Yes | No.

INTEGER 

No | No | No.

STRING 

No | No | No.

BOOLEAN 

No | No | No.

RECORD 

? | ? | Yes

Definition at line 69 of file type.h.

Constructor & Destructor Documentation

◆ Type()

cerata::Type::Type ( std::string  name,
Type::ID  id 
)
explicit

Type constructor.

Parameters
nameThe name of the Type.
idThe Type::ID.

Definition at line 32 of file type.cc.

Member Function Documentation

◆ Copy() [1/2]

virtual std::shared_ptr<Type> cerata::Type::Copy ( ) const
inlinevirtual

Make a copy of the type without rebinding.

Returns
A copy.

Definition at line 147 of file type.h.

◆ Copy() [2/2]

virtual std::shared_ptr<Type> cerata::Type::Copy ( const NodeMap rebinding) const
pure virtual

Make a copy of the type, and rebind any type generic nodes that are keys in the rebinding to their values.

This is useful in case type generic nodes are on some instance graph and have to be copied over to a component graph, or vice versa. In that case, the new graph has to copy over these nodes and rebind the type generic nodes.

Returns
A copy of the type.

Implemented in cerata::Record, cerata::Vector, cerata::String, cerata::Integer, cerata::Boolean, and cerata::Bit.

◆ IsEqual()

bool cerata::Type::IsEqual ( const Type other) const
virtual

Determine if this Type is exactly equal to an other Type.

Parameters
otherThe other type.
Returns
True if exactly equal, false otherwise.

Reimplemented in cerata::Record, and cerata::Vector.

Definition at line 159 of file type.cc.

◆ operator()() [1/2]

std::shared_ptr< Type > cerata::Type::operator() ( const std::vector< std::shared_ptr< Node >> &  nodes)

Make a copy of the type, and rebind any type generic nodes in order of the GetGenerics call.

Parameters
nodesThe nodes to rebind the type to.
Returns
The rebound type.

Definition at line 180 of file type.cc.

◆ operator()() [2/2]

std::shared_ptr< Type > cerata::Type::operator() ( std::vector< Node * >  nodes)

Make a copy of the type, and rebind any type generic nodes in order of the GetGenerics call.

Parameters
nodesThe nodes to rebind the type to.
Returns
The rebound type.

Definition at line 163 of file type.cc.


The documentation for this class was generated from the following files: