Class: ClassHDL::OpertorChain
- Inherits:
-
Object
- Object
- ClassHDL::OpertorChain
- Defined in:
- lib/tdl/class_hdl/hdl_redefine_opertor.rb
Instance Attribute Summary collapse
-
#belong_to_module ⇒ Object
readonly
Returns the value of attribute belong_to_module.
-
#instance_add_brackets ⇒ Object
Returns the value of attribute instance_add_brackets.
-
#slaver ⇒ Object
Returns the value of attribute slaver.
-
#tree ⇒ Object
Returns the value of attribute tree.
Class Method Summary collapse
Instance Method Summary collapse
- #brackets ⇒ Object
- #clog2 ⇒ Object
-
#initialize(arg, belong_to_module) ⇒ OpertorChain
constructor
A new instance of OpertorChain.
- #instance(type = :assign, block_belong_to_module = nil, show = nil) ⇒ Object
- #instance_inspect ⇒ Object
- #simple_op? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(arg, belong_to_module) ⇒ OpertorChain
Returns a new instance of OpertorChain.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/tdl/class_hdl/hdl_redefine_opertor.rb', line 43 def initialize(arg, belong_to_module) @tree = [] #[[inst0,symb0],[inst1,symb1],[other_chain,symb2],[other_chain,symb3]] # self <symb0> inst0 <symb1> inst1 <symb2> ( other_chain ) <symb3> ( other_chain ) if arg @tree << arg end @belong_to_module = belong_to_module unless @belong_to_module raise TdlError.new("OpertorChain must have belong_to_module") end end |
Instance Attribute Details
#belong_to_module ⇒ Object (readonly)
Returns the value of attribute belong_to_module.
42 43 44 |
# File 'lib/tdl/class_hdl/hdl_redefine_opertor.rb', line 42 def belong_to_module @belong_to_module end |
#instance_add_brackets ⇒ Object
Returns the value of attribute instance_add_brackets.
41 42 43 |
# File 'lib/tdl/class_hdl/hdl_redefine_opertor.rb', line 41 def instance_add_brackets @instance_add_brackets end |
#slaver ⇒ Object
Returns the value of attribute slaver.
41 42 43 |
# File 'lib/tdl/class_hdl/hdl_redefine_opertor.rb', line 41 def slaver @slaver end |
#tree ⇒ Object
Returns the value of attribute tree.
41 42 43 |
# File 'lib/tdl/class_hdl/hdl_redefine_opertor.rb', line 41 def tree @tree end |
Class Method Details
.define_op_flag(ruby_op, hdl_op) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/tdl/class_hdl/hdl_redefine_opertor.rb', line 136 def self.define_op_flag(ruby_op,hdl_op) define_method(ruby_op) do |b| if b.is_a? OpertorChain b.slaver = true unless b.simple_op? b.instance_add_brackets = true end end # 计算生成新的OpertorChain 是 self 也需要抛弃 self.slaver = true # return self new_op = OpertorChain.new(nil, belong_to_module) new_op.tree = new_op.tree + self.tree new_op.tree.push [b,hdl_op] if ClassHDL::AssignDefOpertor.curr_assign_block ClassHDL::AssignDefOpertor.curr_assign_block.opertor_chains.push(new_op) end new_op end end |
Instance Method Details
#brackets ⇒ Object
124 125 126 127 128 |
# File 'lib/tdl/class_hdl/hdl_redefine_opertor.rb', line 124 def brackets self.slaver = true bel = ( @tree[0][0].respond_to?(:belong_to_module) && @tree[0][0].belong_to_module ) new_op = OpertorChain.new(["(#{self.instance(:assign, belong_to_module || bel)})".to_nq], belong_to_module) end |
#clog2 ⇒ Object
130 131 132 133 134 |
# File 'lib/tdl/class_hdl/hdl_redefine_opertor.rb', line 130 def clog2 self.slaver = true bel = belong_to_module || ( @tree[0][0].respond_to?(:belong_to_module) && @tree[0][0].belong_to_module ) new_op = OpertorChain.new(["$clog2(#{self.instance(:aasign, bel)})".to_nq],belong_to_module) end |
#instance(type = :assign, block_belong_to_module = nil, show = nil) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 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 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/tdl/class_hdl/hdl_redefine_opertor.rb', line 166 def instance(type=:assign,block_belong_to_module=nil,show=nil) unless block_belong_to_module raise TdlError.new("OpertorChain must has block_belong_to_module") end AssignDefOpertor.with_rollback_opertors(:old) do str = '' # both_symb_used = false cnt = 0 @tree.each do |node| if cnt==1 if node[1].to_s=="<=" if type==:always_ff || type==:cond sb = " <= " else sb = " = " end else sb = "#{node[1].to_s}" end else sb = "#{node[1].to_s}" end if cnt==1 && show puts "tree[1][1]<#{node[1]}> 使用 #{sb}" end unless node[0].is_a? OpertorChain ## 判断是不是属于 Var <= "String" 形式 if (@tree.length == 2) && node[0].instance_of?(String) && !@slaver str += (sb + '"' + node[0].to_s + '"') if show puts "tree 长度等于2; tree[#{cnt}][0] is string; op is not slaver" end elsif node[0].instance_of?(String) # "如果是字符串 则原始输出" str += (sb + '"' + node[0].to_s + '"') if show puts "tree[#{cnt}][0] is string" end else # str += (sb + node[0].to_s) if block_belong_to_module if (node[0].respond_to?(:root_ref) && node[0].respond_to?(:belong_to_module) && node[0].belong_to_module && (node[0].belong_to_module != block_belong_to_module) && node[0].belong_to_module.top_tb_ref? ) str += (sb + node[0].root_ref) if show puts "tree[#{cnt}][0].belong_to_module<#{node[0].belong_to_module.module_name}> != block_belong_to_module<#{block_belong_to_module.module_name}>" end ## 反向添加到 TestUnitModule if block_belong_to_module.is_a?(TestUnitModule) block_belong_to_module.add_root_ref_ele(node[0]) if show puts "block_belong_to_module<#{block_belong_to_module.module_name}> is TestUnitModule" end end else str += (sb + node[0].to_s) if show mmm = node[0].respond_to?(:belong_to_module) && node[0].belong_to_module.module_name puts "tree[#{cnt}][0]<#{node[0].class}>: ref_root<#{node[0].respond_to?(:root_ref).to_s}> belong_to_module<#{mmm}> block_belong_to_module<#{block_belong_to_module.module_name}> ...." end end elsif(node[0].respond_to?(:root_ref) && node[0].respond_to?(:belong_to_module) && node[0].belong_to_module && (node[0].belong_to_module != belong_to_module) && node[0].belong_to_module.top_tb_ref? ) # sb = "#{node[1].root_ref.to_s}" str += (sb + node[0].root_ref) if show puts "tree[#{cnt}][0].belong_to_module<#{node[0].belong_to_module.module_name}> != op.belong_to_module<#{belong_to_module.module_name}>" end ## 反向添加到 TestUnitModule if belong_to_module.is_a?(TestUnitModule) belong_to_module.add_root_ref_ele(node[0]) if show puts "tree[#{cnt}][0]: op.belong_to_module<#{belong_to_module.module_name}> is TestUnitModule" end end else # sb = "#{node[1].to_s}" str += (sb + node[0].to_s) if show puts "tree[#{cnt}][0]: op.belong_to_module<#{belong_to_module.module_name}> ..." end end end else node[0].slaver = true # puts "--------" # p node[0].tree # puts "========" # if node[0].tree.length>2 && ["&","|","<",">"].include?(node[0].tree[1][1]) # else if sb =~/(\||&){2,2}/ str += " #{sb}#{node[0].instance(:slaver,block_belong_to_module || belong_to_module).to_s}" else str += "#{sb}(#{node[0].instance(:slaver,block_belong_to_module || belong_to_module).to_s})" end if show puts "tree[#{cnt}][0] is op, block_belong_to_module<#{block_belong_to_module.to_s}> op.belong_to_module<#{belong_to_module.to_s}>" end end cnt += 1 end ## 修饰 # if nege # str = "~(#{str})" # else # str # end if instance_add_brackets "(#{str})" else str end end end |
#instance_inspect ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/tdl/class_hdl/hdl_redefine_opertor.rb', line 55 def instance_inspect str = ["self belong_to_module:#{belong_to_module.module_name}"] index = 0 @tree.each do |node| bl = "#{node[0].respond_to?(:belong_to_module) ? "belong_to_module:#{node[0].belong_to_module.module_name }" : '' }" str << "{{ tree[#{index}][1]node[1]SYMB{#{node[1].to_s}} tree[#{index}][0]node[0]#{node[0].to_s} #{node[0].class} #{bl}}}" index += 1 end str.join(" ") end |
#simple_op? ⇒ Boolean
101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/tdl/class_hdl/hdl_redefine_opertor.rb', line 101 def simple_op? ## 判断是不是简单的运算 如 X > 0 ,x & y ##[[tmp0[0]], ["FALSE", "&"], [#<ClassHDL::OpertorChain:0x00005557046de088 @tree=[[a_inf.valid], ["1'b0", "|"]], @slaver=true>, "&"]] ##[[a_inf.valid], ["1'b0", "|"] rel = false AssignDefOpertor.with_rollback_opertors(:old) do if tree.size==2 && tree[0].size==1 && !(tree[0][0].is_a?(ClassHDL::OpertorChain)) && !(tree[1][0].is_a?(ClassHDL::OpertorChain)) rel = true else rel = false end end return rel end |
#to_s ⇒ Object
162 163 164 |
# File 'lib/tdl/class_hdl/hdl_redefine_opertor.rb', line 162 def to_s instance(type=:cond,belong_to_module || ( @tree[0][0].respond_to?(:belong_to_module) && @tree[0][0].belong_to_module ) ) end |