ACT Library
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Private Member Functions | Static Private Attributes | List of all members
TypeFactory Class Reference

This is the class used to create all instance types. It also caches types to reduce memory usage. More...

#include <types.h>

Public Member Functions

 TypeFactory ()
 
 ~TypeFactory ()
 
void * operator new (size_t)
 
void operator delete (void *)
 
InstTypeNewPInt ()
 
InstTypeNewPInts ()
 
InstTypeNewPBool ()
 
InstTypeNewPReal ()
 
InstTypeNewPType (Scope *s, InstType *t)
 
PTypeNewPType (InstType *t)
 
InstTypeNewBool (Type::direction dir)
 
InstTypeNewInt (Scope *s, Type::direction dir, int sig, Expr *w)
 
IntNewInt (int sig, int w)
 
InstTypeNewEnum (Scope *s, Type::direction dir, Expr *w)
 
InstTypeNewChan (Scope *s, Type::direction dir, InstType *l, InstType *ack)
 
ChanNewChan (InstType *l, InstType *ack)
 
InstTypeNewUserDef (Scope *s, InstType *it)
 

Static Public Member Functions

static ExprNewExpr (Expr *e)
 
static TypeFactoryFactory ()
 
static void Init ()
 
static int isDataType (const Type *t)
 
static int isDataType (const InstType *t)
 
static int isIntType (const Type *t)
 
static int isIntType (const InstType *t)
 
static int isPIntType (const Type *t)
 
static int isPIntType (const InstType *t)
 
static int isPIntsType (const Type *t)
 
static int isPIntsType (const InstType *t)
 
static int isBoolType (const Type *t)
 
static int isBoolType (const InstType *it)
 
static int isPBoolType (const Type *t)
 
static int isPBoolType (const InstType *it)
 
static int isPRealType (const Type *t)
 
static int isPRealType (const InstType *it)
 
static int isUserType (const Type *t)
 
static int isUserType (const InstType *it)
 
static int isChanType (const Type *t)
 
static int isChanType (const InstType *it)
 
static int isExactChanType (const Type *t)
 
static int isExactChanType (const InstType *it)
 
static int isValidChannelDataType (const Type *t)
 
static int isValidChannelDataType (const InstType *t)
 
static int isProcessType (const Type *t)
 
static int isProcessType (const InstType *it)
 
static int isFuncType (const Type *t)
 
static int isFuncType (const InstType *it)
 
static int isInterfaceType (const Type *t)
 
static int isInterfaceType (const InstType *it)
 
static int isPTypeType (const Type *t)
 
static int isPTypeType (const InstType *it)
 
static int isParamType (const Type *t)
 
static int isParamType (const InstType *it)
 
static int bitWidth (const Type *t)
 
static int bitWidth (const InstType *t)
 
static int bitWidthTwo (const Type *t)
 
static int bitWidthTwo (const InstType *t)
 
static int boolType (const Type *t)
 
static int boolType (const InstType *t)
 
static int isStructure (const Type *t)
 
static int isStructure (const InstType *it)
 
static int isUserEnum (const Type *t)
 
static int isUserEnum (const InstType *it)
 
static int isUserPureEnum (const Type *t)
 
static int isUserPureEnum (const InstType *it)
 
static int enumNum (const Type *t)
 
static int enumNum (const InstType *t)
 
static int isEnum (const Type *t)
 
static int isEnum (const InstType *t)
 
static int isBaseBoolType (const Type *t)
 
static int isBaseBoolType (const InstType *t)
 
static int isBaseIntType (const Type *t)
 
static int isBaseIntType (const InstType *t)
 
static InstTypegetChanDataType (const InstType *t)
 
static InstTypegetChanAckType (const InstType *t)
 

Static Private Member Functions

static int inthashfn (int, void *)
 
static int intmatchfn (void *, void *)
 
static void * intdupfn (void *)
 
static void intfreefn (void *)
 
static int chanhashfn (int, void *)
 
static int chanmatchfn (void *, void *)
 
static void * chandupfn (void *)
 
static void chanfreefn (void *)
 

Static Private Attributes

static TypeFactorytf
 
static InstTypepint
 
static InstTypepints
 
static InstTypepreal
 
static InstTypepbool
 
static InstTypebools [5]
 
static Exprexpr_true
 
static Exprexpr_false
 
static struct iHashtable * expr_int
 
static struct cHashtable * inthash
 
static struct cHashtable * enumhash
 
static struct cHashtable * ptypehash
 
static struct cHashtable * chanhash
 

Detailed Description

This is the class used to create all instance types. It also caches types to reduce memory usage.

All types should be created using the static TypeFactory methods. In addition, the TypeFactory provides methods that can be used to inspect attributes of types (e.g. is this a user-defined type?)

Constructor & Destructor Documentation

◆ TypeFactory()

TypeFactory::TypeFactory ( )

◆ ~TypeFactory()

TypeFactory::~TypeFactory ( )

Member Function Documentation

◆ bitWidth() [1/2]

static int TypeFactory::bitWidth ( const InstType t)
static

see other bitWidth() method

◆ bitWidth() [2/2]

static int TypeFactory::bitWidth ( const Type t)
static

Determines the bit-width of the type. The type must be either a channel or a data type. If it isn't, the function returns -1. If the type is an enumeration, the bitwidth is the smallest # of bits needed to hold the enumeration count.

Returns
the bit-width of the type, or the type sent over the channel in the case of channel types.

◆ bitWidthTwo() [1/2]

static int TypeFactory::bitWidthTwo ( const InstType t)
static

see other bitWidthTwo() method

◆ bitWidthTwo() [2/2]

static int TypeFactory::bitWidthTwo ( const Type t)
static

For bidirectional channels only. Returns 0 for normal channels, -1 for non-channels. This returns the bit-width (like the bitWidth() method) for the acknowledge type for the channel.

Returns
the bit-width of the acknowledgment end of the channel.

◆ boolType() [1/2]

static int TypeFactory::boolType ( const InstType t)
static

see other boolType() method

◆ boolType() [2/2]

static int TypeFactory::boolType ( const Type t)
static

1 if a boolean within a channel or a boolean type, -1 if NULL parent

Returns
1 if this is a Boolean data type or a channel that carries a Boolean data type.

◆ chandupfn()

static void * TypeFactory::chandupfn ( void *  )
staticprivate

◆ chanfreefn()

static void TypeFactory::chanfreefn ( void *  )
staticprivate

◆ chanhashfn()

static int TypeFactory::chanhashfn ( int  ,
void *   
)
staticprivate

Helper functions for hash table operations

◆ chanmatchfn()

static int TypeFactory::chanmatchfn ( void *  ,
void *   
)
staticprivate

◆ enumNum() [1/2]

static int TypeFactory::enumNum ( const InstType t)
static

◆ enumNum() [2/2]

static int TypeFactory::enumNum ( const Type t)
static

Used to determine the # of values in the enumeration. Return enumeartion width, -1 if not a nenumeration. Works for channels too, except it refers to the type within the channel.

Returns
the number of values in the enumeration, or the enumeration for the channel type.

◆ Factory()

static TypeFactory * TypeFactory::Factory ( )
inlinestatic
Returns
the TypeFactory used by the program/library.

◆ getChanAckType()

static InstType * TypeFactory::getChanAckType ( const InstType t)
static
Returns
the ack type for the channel specified (the data type for the acknowledge end in the case of a bi-directional channel), NULL on error.

◆ getChanDataType()

static InstType * TypeFactory::getChanDataType ( const InstType t)
static
Returns
the data type for the channel specified, NULL on an error

◆ Init()

static void TypeFactory::Init ( )
static

Initialize and allocate the first type factory object.

◆ intdupfn()

static void * TypeFactory::intdupfn ( void *  )
staticprivate

◆ intfreefn()

static void TypeFactory::intfreefn ( void *  )
staticprivate

◆ inthashfn()

static int TypeFactory::inthashfn ( int  ,
void *   
)
staticprivate

Helper functions for hash table operations. ALSO used for enumeration hashes.

◆ intmatchfn()

static int TypeFactory::intmatchfn ( void *  ,
void *   
)
staticprivate

◆ isBaseBoolType() [1/2]

static int TypeFactory::isBaseBoolType ( const InstType t)
static

see other isBaseBoolType() method

◆ isBaseBoolType() [2/2]

static int TypeFactory::isBaseBoolType ( const Type t)
static

This is used to check if a user type that is rooted in a bool or a bool itself

Returns
1 if the base type is a bool, 0 otherwise

◆ isBaseIntType() [1/2]

static int TypeFactory::isBaseIntType ( const InstType t)
static

see other isBaseIntType() method

◆ isBaseIntType() [2/2]

static int TypeFactory::isBaseIntType ( const Type t)
static

This is used to check if a user type that is rooted in an int/int-enum or an int/int-enum itself. An "int-enum" is an enum that can also be treated as an int.

Returns
1 if the base type is a bool, 0 otherwise

◆ isBoolType() [1/2]

static int TypeFactory::isBoolType ( const InstType it)
static

see other isBoolType() method

◆ isBoolType() [2/2]

static int TypeFactory::isBoolType ( const Type t)
static

Determines if the specified type is a built-in bool type.

Parameters
tis the type to be inspected
Returns
1 if it is a bool, 0 otherwise

◆ isChanType() [1/2]

static int TypeFactory::isChanType ( const InstType it)
static

see other isChanType() method

◆ isChanType() [2/2]

static int TypeFactory::isChanType ( const Type t)
static

Determines if the specified type is a channel type or not. This returns 1 if it is a user-defined channel or a built-in channel type.

Parameters
tis the type to be inspected
Returns
1 if it is a valid channel type, 0 otherwise

◆ isDataType() [1/2]

static int TypeFactory::isDataType ( const InstType t)
static

see the other isDataType() method

◆ isDataType() [2/2]

static int TypeFactory::isDataType ( const Type t)
static

Determines if the specified type is a data type or not. Note: if the type is a structure, then isDataType will return 0.

Parameters
tis the type to be inspected
Returns
1 if it is a valid data type, 0 otherwise

◆ isEnum() [1/2]

static int TypeFactory::isEnum ( const InstType t)
static

see other isEnum() method

◆ isEnum() [2/2]

static int TypeFactory::isEnum ( const Type t)
static

Test if a type is an enumeration (user-defined or built-in)

Returns
1 if this is a user-defined or built-in enumeration

◆ isExactChanType() [1/2]

static int TypeFactory::isExactChanType ( const InstType it)
static

see other isExactChanType() method

◆ isExactChanType() [2/2]

static int TypeFactory::isExactChanType ( const Type t)
static

Determines if the specified type is a built-in chan(...) type.

Parameters
tis the type to be inspected
Returns
1 if it is a valid built-in channel type, 0 otherwise

◆ isFuncType() [1/2]

static int TypeFactory::isFuncType ( const InstType it)
static

see other isFuncType() method

◆ isFuncType() [2/2]

static int TypeFactory::isFuncType ( const Type t)
static

Determines if the specified type is a function type or not

Parameters
tis the type to be inspected
Returns
1 if it is a valid function, 0 otherwise

◆ isInterfaceType() [1/2]

static int TypeFactory::isInterfaceType ( const InstType it)
static

see other isInterfaceType() method

◆ isInterfaceType() [2/2]

static int TypeFactory::isInterfaceType ( const Type t)
static

Determines if the specified type is an interface type or not

Parameters
tis the type to be inspected
Returns
1 if it is a valid process/cell, 0 otherwise

◆ isIntType() [1/2]

static int TypeFactory::isIntType ( const InstType t)
static

see the other isIntType() method

◆ isIntType() [2/2]

static int TypeFactory::isIntType ( const Type t)
static

Determines if the specified type is a built-in int<> type.

Parameters
tis the type to be inspected
Returns
1 if it is an int<>, 0 otherwise

◆ isParamType() [1/2]

static int TypeFactory::isParamType ( const InstType it)
static

see other isParamType() method

◆ isParamType() [2/2]

static int TypeFactory::isParamType ( const Type t)
static

Determines if the specified type is a parameter type (pint, pints (UNUSED), pbool, preal, ptype).

Parameters
tis the type to be inspected
Returns
1 if it is a valid ptype type, 0 otherwise

◆ isPBoolType() [1/2]

static int TypeFactory::isPBoolType ( const InstType it)
static

see other isPBoolType() method

◆ isPBoolType() [2/2]

static int TypeFactory::isPBoolType ( const Type t)
static

Determines if the specified type is a built-in pbool type.

Parameters
tis the type to be inspected
Returns
1 if it is a pbool, 0 otherwise

◆ isPIntsType() [1/2]

static int TypeFactory::isPIntsType ( const InstType t)
static

see other isPIntsType() method

◆ isPIntsType() [2/2]

static int TypeFactory::isPIntsType ( const Type t)
static

Determines if the specified type is a built-in pints type.

Parameters
tis the type to be inspected
Returns
1 if it is a pints, 0 otherwise

◆ isPIntType() [1/2]

static int TypeFactory::isPIntType ( const InstType t)
static

see other isPIntType() method

◆ isPIntType() [2/2]

static int TypeFactory::isPIntType ( const Type t)
static

Determines if the specified type is a built-in pint type.

Parameters
tis the type to be inspected
Returns
1 if it is a pint, 0 otherwise

◆ isPRealType() [1/2]

static int TypeFactory::isPRealType ( const InstType it)
static

see other isPRealType() method

◆ isPRealType() [2/2]

static int TypeFactory::isPRealType ( const Type t)
static

Determines if the specified type is a built-in preal type.

Parameters
tis the type to be inspected
Returns
1 if it is a preal, 0 otherwise

◆ isProcessType() [1/2]

static int TypeFactory::isProcessType ( const InstType it)
static

see other isProcessType() method

◆ isProcessType() [2/2]

static int TypeFactory::isProcessType ( const Type t)
static

Determines if the specified type is a process type or not

Parameters
tis the type to be inspected
Returns
1 if it is a valid process/cell, 0 otherwise

◆ isPTypeType() [1/2]

static int TypeFactory::isPTypeType ( const InstType it)
static

see other isPTypeType() method

◆ isPTypeType() [2/2]

static int TypeFactory::isPTypeType ( const Type t)
static

Determines if the specified type is a ptype or not

Parameters
tis the type to be inspected
Returns
1 if it is a valid ptype type, 0 otherwise

◆ isStructure() [1/2]

static int TypeFactory::isStructure ( const InstType it)
static

see other isStructure() method

◆ isStructure() [2/2]

static int TypeFactory::isStructure ( const Type t)
static

A UserDef that is a Data type can hold a structure. A data type is a structure when it does not implement a built-in data type. Note that currently structures cannot contain arrays.

Returns
1 if this is a structure, 0 otherwise

◆ isUserEnum() [1/2]

static int TypeFactory::isUserEnum ( const InstType it)
static

see other isUserEnum() method

◆ isUserEnum() [2/2]

static int TypeFactory::isUserEnum ( const Type t)
static

Is this a user-defined enumeration?

Returns
1 if this is a user-defined enumeration type, 0 otherwise

◆ isUserPureEnum() [1/2]

static int TypeFactory::isUserPureEnum ( const InstType it)
static

see other isUserPureEnum() method

◆ isUserPureEnum() [2/2]

static int TypeFactory::isUserPureEnum ( const Type t)
static

Is this a user-defined pure enumeration (one that cannot be used as an integer)

Returns
1 if this is a user-defined pure enumeration type, 0 otherwise

◆ isUserType() [1/2]

static int TypeFactory::isUserType ( const InstType it)
static

see other isUserType() method

◆ isUserType() [2/2]

static int TypeFactory::isUserType ( const Type t)
static

Determines if the specified type is a user-defined type

Parameters
tis the type to be inspected
Returns
1 if it is a UserDef type, 0 otherwise

◆ isValidChannelDataType() [1/2]

static int TypeFactory::isValidChannelDataType ( const InstType t)
static

see other isValidChannelDataType() method

◆ isValidChannelDataType() [2/2]

static int TypeFactory::isValidChannelDataType ( const Type t)
static

Determines if the specified type is a valid type to be included within the data type for a built-in chan(..).

Assumes that "t" is in fact a data type as a pre-condition.

Parameters
tis the type to be inspected
Returns
1 if it is a valid channel data type, 0 otherwise

◆ NewBool()

InstType * TypeFactory::NewBool ( Type::direction  dir)

Return unique pointer to the bool type

Parameters
diris the direction flag for the type
Returns
a unique Bool * corresponding to the type

◆ NewChan() [1/2]

Chan * TypeFactory::NewChan ( InstType l,
InstType ack 
)

Similar to NewChan(), but returns the Chan type rather than an InstType.

◆ NewChan() [2/2]

InstType * TypeFactory::NewChan ( Scope s,
Type::direction  dir,
InstType l,
InstType ack 
)

Return unique pointer to the chan type

Parameters
diris the direction flag for the type
sis the scope in which the channel is created
lis the data type for the channel
ackis the "ack" type for the channel (bi-directional channels)
Returns
a unique pointer to the specified channel type

◆ NewEnum()

InstType * TypeFactory::NewEnum ( Scope s,
Type::direction  dir,
Expr w 
)

Return unique pointer to the enum type

Parameters
diris the direction flag for the type
wis an integer expression that specifies the width of the integer (if it is a constant expression, the type can be finalized)
sis the scope in which this integer is created. This scope is used to evaluate any variables specified in w
Returns
a unique pointer to the specified type

◆ NewExpr()

static Expr * TypeFactory::NewExpr ( Expr e)
static

Returns a unique pointer to a constant expression. This expression pointer is cached so this should never be free'ed.

Returns
a cached expression pointer that is equal to the one passed in.

◆ NewInt() [1/2]

Int * TypeFactory::NewInt ( int  sig,
int  w 
)

◆ NewInt() [2/2]

InstType * TypeFactory::NewInt ( Scope s,
Type::direction  dir,
int  sig,
Expr w 
)

Return unique pointer to the int type

Parameters
diris the direction flag for the type
wis an integer expression that specifies the width of the integer (if it is a constant expression, the type can be finalized)
sis the scope in which this integer is created. This scope is used to evaluate any variables specified in w
sigis 1 if this is a signed integer, 0 otherwise
Returns
a unique pointer to the specified type

◆ NewPBool()

InstType * TypeFactory::NewPBool ( )
inline
Returns
the unique pointer to a pbool

◆ NewPInt()

InstType * TypeFactory::NewPInt ( )
inline
Returns
the unique pointer to a pint

◆ NewPInts()

InstType * TypeFactory::NewPInts ( )
inline
Returns
the unique pointer to a pints

◆ NewPReal()

InstType * TypeFactory::NewPReal ( )
inline
Returns
the unique pointer to a preal

◆ NewPType() [1/2]

PType * TypeFactory::NewPType ( InstType t)
Returns
the unique pointer to a Ptype

◆ NewPType() [2/2]

InstType * TypeFactory::NewPType ( Scope s,
InstType t 
)
Returns
the unique pointer to the ptype InstType

◆ NewUserDef()

InstType * TypeFactory::NewUserDef ( Scope s,
InstType it 
)

Returns a unique pointer to the instance type specified

Parameters
itis the input instance type. This MAY BE FREE'D
sis the scope in which the user-defined type is being created
Returns
a unique pointer to the specified instance type

◆ operator delete()

void TypeFactory::operator delete ( void *  )

◆ operator new()

void * TypeFactory::operator new ( size_t  )

Member Data Documentation

◆ bools

InstType* TypeFactory::bools[5]
staticprivate

Five types of bool types: NONE, IN, OUT, INOUT, OUTIN.

◆ chanhash

struct cHashtable* TypeFactory::chanhash
staticprivate

Hash table for channel types parameterized by direction, and type list

◆ enumhash

struct cHashtable* TypeFactory::enumhash
staticprivate

Hash table for enumeration types parameterized by the range of the enumeration and direction flags.

◆ expr_false

Expr* TypeFactory::expr_false
staticprivate

Constant expr E_FALSE. This is used to cache expressions.

◆ expr_int

struct iHashtable* TypeFactory::expr_int
staticprivate

Constant expr E_INT. This is used to cache constant integer expressions. The hash table maps integers to the Expr *.

◆ expr_true

Expr* TypeFactory::expr_true
staticprivate

Constant expr E_TRUE. This is used to cache expressions.

◆ inthash

struct cHashtable* TypeFactory::inthash
staticprivate

Hash table for integer types parameterized by bit-width and direction flags.

◆ pbool

InstType* TypeFactory::pbool
staticprivate

Built-in parameter type for a pbool: only one copy of this type can exist, since there are no parameters.

◆ pint

InstType* TypeFactory::pint
staticprivate

Built-in parameter type for a pint: only one copy of this type can exist, since there are no parameters.

◆ pints

InstType* TypeFactory::pints
staticprivate

Built-in parameter type for a pints: only one copy of this type can exist, since there are no parameters. NOTE: THIS IS UNUSED

◆ preal

InstType* TypeFactory::preal
staticprivate

Built-in parameter type for a preal: only one copy of this type can exist, since there are no parameters.

◆ ptypehash

struct cHashtable* TypeFactory::ptypehash
staticprivate

Hash table for ptype types. Uses channel hash functions.

◆ tf

TypeFactory* TypeFactory::tf
staticprivate

there can only be one TypeFactory in the system, and this is it.


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