Class: ClassHDL::EnumStruct

Inherits:
Object
  • Object
show all
Includes:
TdlSpace::ExCreateTP
Defined in:
lib/tdl/exlib/test_point.rb,
lib/tdl/class_hdl/hdl_block_ifelse.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TdlSpace::ExCreateTP

#create_tp

Constructor Details

#initialize(sdl_m, *args) ⇒ EnumStruct

Returns a new instance of EnumStruct.



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/tdl/class_hdl/hdl_block_ifelse.rb', line 186

def initialize(sdl_m,*args)
    args.each do |e|
        unless e.is_a? String 
            raise TdlError.new("Enum Def element[#{e}] must be String")
        end 

        define_singleton_method(e) do |&block|
            unless block_given?
                e.to_nq
            else
                WHEN(e.to_nq,&block) 
            end
        end
    end
    @args = args
    @sdl_m = sdl_m
    @belong_to_module = sdl_m
    # @name = name
    
end

Instance Attribute Details

#belong_to_moduleObject

attr_accessor :sdl_m



185
186
187
# File 'lib/tdl/class_hdl/hdl_block_ifelse.rb', line 185

def belong_to_module
  @belong_to_module
end

Instance Method Details

#-(defname) ⇒ Object



226
227
228
229
230
231
232
233
234
# File 'lib/tdl/class_hdl/hdl_block_ifelse.rb', line 226

def -(defname)
    @name = defname.to_s
    @sdl_m.Logic_inst.push(enum_inst(defname.to_s,*@args))
    _self = self
    @sdl_m.define_singleton_method(defname.to_s) do 
        _self 
    end
    self
end

#cstateObject Also known as: C



207
208
209
# File 'lib/tdl/class_hdl/hdl_block_ifelse.rb', line 207

def cstate
    "CSTATE_#{@name}".to_nq
end

#enum_inst(name, *args) ⇒ Object



218
219
220
# File 'lib/tdl/class_hdl/hdl_block_ifelse.rb', line 218

def enum_inst(name,*args)
    str = "typedef enum { \n#{args.map{|e| "    #{e}" }.join(",\n")}\n} SE_STATE_#{name};\nSE_STATE_#{name} CSTATE_#{name},NSTATE_#{name};\n"
end

#nstateObject Also known as: N



211
212
213
# File 'lib/tdl/class_hdl/hdl_block_ifelse.rb', line 211

def nstate
    "NSTATE_#{@name}".to_nq
end

#path_refs(nstateq = true, &block) ⇒ Object

获取信号的绝对路径



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/tdl/exlib/test_point.rb', line 224

def path_refs(nstateq=true,&block)
    collects = []
    @belong_to_module.parents_inst_tree do |tree|
        ll = ["$root"]
        rt = tree.reverse
        rt.each_index do |index|
            if rt[index].respond_to? :module_name
                ll << rt[index].module_name 
            else 
                ll << rt[index].inst_name
            end
        end
        if nstateq
            ll << nstate
        else
            ll << cstate
        end
        new_name = ll.join('.').to_nq
        if block_given?
            if yield(new_name)
                collects << new_name
            end 
        else
            collects << new_name
        end
    end
    collects
end

#root_ref(nstateq = true, &block) ⇒ Object



210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/tdl/exlib/test_point.rb', line 210

def root_ref(nstateq=true,&block)
    ClassHDL::AssignDefOpertor.with_rollback_opertors(:old) do 
        rels = path_refs(nstateq,&block)
        if rels.size == 1
            rels[0]
        elsif rels.size == 0
            raise TdlError.new "#{self} Cant find root ref"
        else
            raise TdlError.new "#{self} Find multi root refs \n#{rels.join("\n")}\n"
        end
    end
end

#typedef_nameObject



222
223
224
# File 'lib/tdl/class_hdl/hdl_block_ifelse.rb', line 222

def typedef_name
    "SE_STATE_#{@name}".to_nq
end