Re: [myhdl-list] Setting of enum values
Brought to you by:
jandecaluwe
From: Christopher F. <chr...@gm...> - 2016-01-21 16:34:35
|
On 1/21/2016 5:15 AM, Marcel Hellwig wrote: > 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. > Disclaimer: I quickly review the previous posts in this thread (I might not understand the intent) - if this is off base ignore. You should be able to use constant values in an object, this code snip might help: from myhdl import * class MyConstants(object): def __init__(self): self.const1 = int(intbv("1111_0001")) self.const2 = int(intbv("1010_0101")) def const_select(sel, x): const = MyConstants() @always_comb def beh_select(): if sel == 1: x.next = const.const1 elif sel == 2: x.next = const.const2 else: x.next = 0 return beh_select The above converts as expected. You could also convert the object to a tuple of ints, something like (for this example): rom = [int(v) for k, v in vars(const)] Regards, Chris |