CIRCT 23.0.0git
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Member Functions | List of all members
esiaccel.codegen.CppTypeEmitter Class Reference

Public Member Functions

None __init__ (self, CppTypePlanner planner)
 
str type_identifier (self, types.ESIType type)
 
None write_header (self, Path output_dir, str system_name)
 

Public Attributes

 type_id_map
 
 ordered_types
 
 has_cycle
 

Protected Member Functions

str _cpp_string_literal (self, str value)
 
str _get_bitvector_str (self, types.ESIType type)
 
str _storage_type (self, int bit_width, bool signed)
 
int _type_byte_width (self, types.ESIType wrapped)
 
Tuple[str, List[int]] _array_base_and_dims (self, types.ArrayType array_type)
 
str _std_array_type (self, types.ArrayType array_type)
 
str _cpp_type (self, types.ESIType wrapped)
 
types.ESIType _unwrap_aliases (self, types.ESIType wrapped)
 
str _format_window_field_decl (self, str field_name, types.ESIType field_type)
 
str _format_window_ctor_param (self, str field_name, types.ESIType field_type)
 
None _emit_window_field_copy (self, TextIO hdr, str dest_expr, str src_expr, types.ESIType field_type)
 
int _field_byte_width (self, types.ESIType field_type)
 
Optional[int] _safe_byte_width (self, types.ESIType esi_type)
 
None _emit_size_assert (self, TextIO hdr, str type_name, Optional[int] expected_bytes, str indent="")
 
 _analyze_window (self, types.WindowType window_type)
 
None _emit_struct (self, TextIO hdr, types.StructType struct_type)
 
None _emit_union (self, TextIO hdr, types.UnionType union_type)
 
None _emit_window (self, TextIO hdr, types.WindowType window_type)
 
None _emit_window_data_accessors (self, TextIO hdr, info)
 
None _emit_window_deserializer (self, TextIO hdr, info)
 
None _emit_alias (self, TextIO hdr, types.TypeAlias alias_type)
 

Detailed Description

Emit C++ headers from precomputed type ordering.

Definition at line 1029 of file codegen.py.

Constructor & Destructor Documentation

◆ __init__()

None esiaccel.codegen.CppTypeEmitter.__init__ (   self,
CppTypePlanner  planner 
)

Member Function Documentation

◆ _analyze_window()

esiaccel.codegen.CppTypeEmitter._analyze_window (   self,
types.WindowType  window_type 
)
protected

◆ _array_base_and_dims()

Tuple[str, List[int]] esiaccel.codegen.CppTypeEmitter._array_base_and_dims (   self,
types.ArrayType  array_type 
)
protected
Return the base C++ type and outer-to-inner dimensions of a nested array.

Definition at line 1079 of file codegen.py.

References esiaccel.codegen.CppTypeEmitter._cpp_type().

Referenced by esiaccel.codegen.CppTypeEmitter._std_array_type().

◆ _cpp_string_literal()

str esiaccel.codegen.CppTypeEmitter._cpp_string_literal (   self,
str  value 
)
protected
Escape a Python string for use as a C++ string literal.

Definition at line 1041 of file codegen.py.

◆ _cpp_type()

str esiaccel.codegen.CppTypeEmitter._cpp_type (   self,
types.ESIType  wrapped 
)
protected

◆ _emit_alias()

None esiaccel.codegen.CppTypeEmitter._emit_alias (   self,
TextIO  hdr,
types.TypeAlias  alias_type 
)
protected
Emit a using alias when the alias targets a different C++ type.

Definition at line 1652 of file codegen.py.

References esiaccel.codegen.CppTypeEmitter._cpp_type(), and esiaccel.codegen.CppTypeEmitter.type_id_map.

Referenced by esiaccel.codegen.CppTypeEmitter.write_header().

◆ _emit_size_assert()

None esiaccel.codegen.CppTypeEmitter._emit_size_assert (   self,
TextIO  hdr,
str  type_name,
Optional[int]  expected_bytes,
str   indent = "" 
)
protected
Emit a `static_assert` that pins the C++ `sizeof` of a packed type to
the byte width derived from the manifest.

`std::array` and bit-field layout are technically implementation-defined,
so this assertion is the safety net that catches a toolchain that lays
them out differently from the wire format.  Skipped silently for types
without a bounded static size.

Definition at line 1199 of file codegen.py.

Referenced by esiaccel.codegen.CppTypeEmitter._emit_struct(), esiaccel.codegen.CppTypeEmitter._emit_union(), and esiaccel.codegen.CppTypeEmitter._emit_window().

◆ _emit_struct()

None esiaccel.codegen.CppTypeEmitter._emit_struct (   self,
TextIO  hdr,
types.StructType  struct_type 
)
protected

◆ _emit_union()

None esiaccel.codegen.CppTypeEmitter._emit_union (   self,
TextIO  hdr,
types.UnionType  union_type 
)
protected
Emit a packed union declaration plus its type id string.

Fields narrower than the union width get wrapper structs with a `_pad`
byte array so the data sits at the MSB end, matching SV packed union
layout where padding occupies the LSBs / lower addresses.

Definition at line 1367 of file codegen.py.

References esiaccel.codegen.CppTypeEmitter._cpp_type(), esiaccel.codegen.CppTypeEmitter._emit_size_assert(), esiaccel.codegen.CppTypeEmitter._field_byte_width(), and esiaccel.codegen.CppTypeEmitter.type_id_map.

Referenced by esiaccel.codegen.CppTypeEmitter.write_header().

◆ _emit_window()

None esiaccel.codegen.CppTypeEmitter._emit_window (   self,
TextIO  hdr,
types.WindowType  window_type 
)
protected

◆ _emit_window_data_accessors()

None esiaccel.codegen.CppTypeEmitter._emit_window_data_accessors (   self,
TextIO  hdr,
  info 
)
protected
Emit accessors for the header and data fields of a window helper.

Exposes each static header field as a scalar accessor, the count of data
frames, and one vector-valued accessor per data field so decoded values
are easy to inspect on the read side.

Definition at line 1546 of file codegen.py.

References esiaccel.codegen.CppTypeEmitter._cpp_type(), esiaccel.codegen.CppTypePlanner._unwrap_aliases(), and esiaccel.codegen.CppTypeEmitter._unwrap_aliases().

Referenced by esiaccel.codegen.CppTypeEmitter._emit_window().

◆ _emit_window_deserializer()

None esiaccel.codegen.CppTypeEmitter._emit_window_deserializer (   self,
TextIO  hdr,
  info 
)
protected
Emit a few bridge helpers + a `TypeDeserializer` alias.

The actual decoder lives in `esi::SerialListTypeDeserializer<T>`, which
walks the header/data/footer burst protocol generically. Each window
helper only has to expose:

  - `_headerCount(const header_frame &)` -> `count_type`
  - `_fromFrames(const header_frame &, std::vector<data_frame> &&)`
    -> `std::unique_ptr<T>`

plus a `friend class esi::SerialListTypeDeserializer<T>;` so the template
can reach the (private) `header_frame` definition.

Definition at line 1607 of file codegen.py.

Referenced by esiaccel.codegen.CppTypeEmitter._emit_window().

◆ _emit_window_field_copy()

None esiaccel.codegen.CppTypeEmitter._emit_window_field_copy (   self,
TextIO  hdr,
str  dest_expr,
str  src_expr,
types.ESIType  field_type 
)
protected
Copy a generated window field.

Definition at line 1178 of file codegen.py.

Referenced by esiaccel.codegen.CppTypeEmitter._emit_window().

◆ _field_byte_width()

int esiaccel.codegen.CppTypeEmitter._field_byte_width (   self,
types.ESIType  field_type 
)
protected
Compute the byte width of a field type, rounding up to full bytes.

Definition at line 1183 of file codegen.py.

Referenced by esiaccel.codegen.CppTypeEmitter._emit_union().

◆ _format_window_ctor_param()

str esiaccel.codegen.CppTypeEmitter._format_window_ctor_param (   self,
str  field_name,
types.ESIType  field_type 
)
protected
Emit a constructor parameter for generated window helpers.

Small scalar header fields are cheaper to pass by value than by reference.
Larger aggregates stay as const references.

Definition at line 1165 of file codegen.py.

References esiaccel.codegen.CppTypeEmitter._cpp_type(), esiaccel.codegen.CppTypePlanner._unwrap_aliases(), and esiaccel.codegen.CppTypeEmitter._unwrap_aliases().

Referenced by esiaccel.codegen.CppTypeEmitter._emit_struct(), and esiaccel.codegen.CppTypeEmitter._emit_window().

◆ _format_window_field_decl()

str esiaccel.codegen.CppTypeEmitter._format_window_field_decl (   self,
str  field_name,
types.ESIType  field_type 
)
protected
Emit a packed field declaration for generated window helpers.

Arrays use `std::array` (handled by `_cpp_type`), so no bracket syntax is
needed and a single uniform declaration form covers every type.

Definition at line 1151 of file codegen.py.

References esiaccel.codegen.CppTypeEmitter._cpp_type(), esiaccel.codegen.CppTypePlanner._unwrap_aliases(), and esiaccel.codegen.CppTypeEmitter._unwrap_aliases().

Referenced by esiaccel.codegen.CppTypeEmitter._emit_window().

◆ _get_bitvector_str()

str esiaccel.codegen.CppTypeEmitter._get_bitvector_str (   self,
types.ESIType  type 
)
protected
Get the textual code for the storage class of an integer type.

Definition at line 1046 of file codegen.py.

References esiaccel.codegen.CppTypeEmitter._storage_type().

Referenced by esiaccel.codegen.CppTypeEmitter._cpp_type().

◆ _safe_byte_width()

Optional[int] esiaccel.codegen.CppTypeEmitter._safe_byte_width (   self,
types.ESIType  esi_type 
)
protected
Return the bounded byte width of `esi_type`, or `None` if it has no
well-defined static size (e.g. unbounded `!esi.any` or recursive types).

Definition at line 1187 of file codegen.py.

Referenced by esiaccel.codegen.CppTypeEmitter._emit_struct().

◆ _std_array_type()

str esiaccel.codegen.CppTypeEmitter._std_array_type (   self,
types.ArrayType  array_type 
)
protected
Return the equivalent nested `std::array<...>` type for an array.

`std::array<T, N>` is layout-compatible in practice with `T[N]` on every
major implementation (and identical under `#pragma pack(1)`), so the
generator uses it everywhere a fixed-size array would appear.  This keeps
field/value/ctor types storable in `std::vector` and assignable with `=`.

Definition at line 1090 of file codegen.py.

References esiaccel.codegen.CppTypeEmitter._array_base_and_dims().

Referenced by esiaccel.codegen.CppTypeEmitter._cpp_type().

◆ _storage_type()

str esiaccel.codegen.CppTypeEmitter._storage_type (   self,
int  bit_width,
bool  signed 
)
protected
Get the textual code for a byte-addressable integer storage type.

Definition at line 1053 of file codegen.py.

Referenced by esiaccel.codegen.CppTypeEmitter._analyze_window(), and esiaccel.codegen.CppTypeEmitter._get_bitvector_str().

◆ _type_byte_width()

int esiaccel.codegen.CppTypeEmitter._type_byte_width (   self,
types.ESIType  wrapped 
)
protected
Return the size of a fixed-width type in bytes.

Definition at line 1073 of file codegen.py.

Referenced by esiaccel.codegen.CppTypeEmitter._analyze_window().

◆ _unwrap_aliases()

types.ESIType esiaccel.codegen.CppTypeEmitter._unwrap_aliases (   self,
types.ESIType  wrapped 
)
protected

◆ type_identifier()

str esiaccel.codegen.CppTypeEmitter.type_identifier (   self,
types.ESIType  type 
)
Get the C++ type string for an ESI type.

Definition at line 1037 of file codegen.py.

References esiaccel.codegen.CppTypeEmitter._cpp_type().

◆ write_header()

None esiaccel.codegen.CppTypeEmitter.write_header (   self,
Path  output_dir,
str  system_name 
)

Member Data Documentation

◆ has_cycle

esiaccel.codegen.CppTypeEmitter.has_cycle

Definition at line 1035 of file codegen.py.

Referenced by esiaccel.codegen.CppTypeEmitter.write_header().

◆ ordered_types

esiaccel.codegen.CppTypeEmitter.ordered_types

◆ type_id_map

esiaccel.codegen.CppTypeEmitter.type_id_map

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