Re: [myhdl-list] Setting of enum values
Brought to you by:
jandecaluwe
From: Marcel H. <1he...@in...> - 2016-01-21 11:15:28
|
On 21.01.2016 09:47, Thomas Heller wrote: > [...] > I had the same problem and currently only see these two possibilities: > > 1. Import each constant and assign it in the myhdl code, like this: > > from cpumode import CpuMode > cpumode_User = CpuMode.User > ... ugly as hell :D but yeah, it kind of works... > > 2. Define the constants as module level constants > and use 'from mymodule import *' in the myhdl code. I decided myself to this design. Would be nice though to have some kind of namespace seperation. On 21.01.2016 01:33, Jan Coombs wrote: > Agreed, it is a complex one, and I accept the reasons for not > pursuing this I have an Idea and would like to know your thoughts about this: > from myhdl import enum > > procmode = enum(('User', 0b10001, ('System', 0b11111), (...), ...) so giving them tuples (or a dict) with predefined values? This means that you can pass constant values and names to it. You can check the nrbits and everything else while creating the enum. I find this is an quite elegant solution. What do you thinK? Greetings, Marcel |