B-Lang-org / bsc

Bluespec Compiler (BSC)
Other
924 stars 142 forks source link

enum encodings from bluetcl #395

Open neelgala opened 3 years ago

neelgala commented 3 years ago

I am using the tcl libraries here to dump out information of the structures used inside a design after compilation. However, I am unable to figure out the enum encodings that were used. Is there another way I could get this information ?

quark17 commented 3 years ago

The Blutecl commands are also documented in an appendix in the User Guide, here.

However, there are some Bluetcl commands which are not described here, such as the Bluetcl::browsetype command. That may be because they are intended to be used to implement a GUI and are not friendly for using interactively. (But we should still document them!) The Bluetcl::browsetype command is used by the BDW (Bluespec Development Workstation) GUI to implement its "Type Browser" window. You may want to have a look at the Tcl source code for BDW, in the repo here.

For interactive users, the typical command for querying a type is Bluetcl::type. However, I confirm that the enum encoding information is not displayed by that command. This is something that we could certainly improve! For example, with a package Test containing this type:

typedef enum {
  Red = 1,
  Blue = 3,
  Green = 17
} Color;

I see this behavior:

$ bluetcl
% Bluetcl::bpackage load Test
Test PreludeBSV Prelude
% Bluetcl::type full Color
Enum Test::Color {members {Red Blue Green}} {position {Test.bsv 5 3}}

The BDW GUI can connect to a waveform viewer (such as gtkwave) and tell the viewer that signals are enum types that should be displayed as their tags rather than as numbers. If BDW is able to do this for enums with custom encodings, then it must be getting the info from Bluetcl commands somehow. However, I have not yet tested whether BDW is properly handling custom enums (like the Color example above). BDW also has a type browser window -- as I mentioned, this is implemented with the Bluetcl::browsetype command -- and I would first test whether the custom values are visible there. Checking on the command-line, they don't appear to be:

bluetcl
% Bluetcl::bpackage load Test
Test PreludeBSV Prelude
% Bluetcl::browsetype
Error: Command is incomplete.  It is expected to continue with:
(add <type> | list <key> | clear | detail <key> | refresh | debug)
% Bluetcl::browsetype list 0
% Bluetcl::browsetype add Color
% Bluetcl::browsetype list 0
{1 {Color (enum)} {}}
% Bluetcl::browsetype list 1
% Bluetcl::browsetype detail 1
Enum Test::Color {members {Red Blue Green}} {position {Test.bsv 5 3}}

I'm also dubious, because the TypeAnalysis package in BSC's source does not include the encoding information in its output:

data TypeAnalysis =
    ...
    | Enum        Id [Id] (Maybe Integer)
    ...

Bluetcl just displays information that is determined by this package. We may need to extend the output and make it available Bluetcl commands.