Class: RepeatCellPlugin

Inherits:
CellPlugin show all
Defined in:
lib/tecsgen/plugin/RepeatCellPlugin.rb

Overview

cell を count 個繰り返すセルプラグイン

不完全点:

指定子に対応していない
   cell の指定子 (allocator, id)
   結合の指定子 (through)

Constant Summary collapse

RepeatCellPluginArgProc =
{
  "count" => Proc.new {|obj, rhs| obj.set_count rhs }
}
@@plugin_list =
[]

Constants inherited from Plugin

Plugin::PluginArgProc

Instance Method Summary collapse

Methods inherited from CellPlugin

gen_post_code

Methods inherited from Plugin

#cdl_error, #check_plugin_arg, #gen_ep_func?, #gen_postamble, #gen_preamble, #new_cell, #parse_plugin_arg, #print_msg, #set_locale, #set_silent

Methods inherited from Node

#cdl_error, #cdl_error2, #cdl_error3, #cdl_info, #cdl_info2, #cdl_warning, #cdl_warning2, #get_locale, #locale_str, #set_locale

Constructor Details

#initialize(cell, option) ⇒ RepeatCellPlugin

Returns a new instance of RepeatCellPlugin.



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/tecsgen/plugin/RepeatCellPlugin.rb', line 51

def initialize(cell, option)
  super
  @@plugin_list << self
  print "RepeatCellPlugin: #{@cell.get_name}\n"
  # cell.show_tree 0
  # @cell.get_join_list.get_items.each{ |j|
  #  print "Join: #{j.get_name} = #{j.get_rhs.to_s}\n"
  # }
  @count = 0
  @plugin_arg_check_proc_tab = RepeatCellPluginArgProc
  parse_plugin_arg
end

Instance Method Details

#gen_cdl_file(file) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/tecsgen/plugin/RepeatCellPlugin.rb', line 64

def gen_cdl_file(file)
  if $verbose
    print "#{self.class}: repeat #{@cell.get_name} #(num} times\n"
  end

  nest = @cell.get_region.gen_region_str_pre file
  indent_str = "  " * nest
  @cell.get_name.to_s =~ /.*[^0-9]([0-9]+)\z/
  if $1
    tail_zero = $1
    bname = @cell.get_name.to_s.gsub(/[0-9]+\z/, "")
  else
    cdl_error("#{self.class}: #{@cell.get_name}'s name ends without '0-9'")
    return
  end
  base_count = tail_zero.to_i

  count = 1
  num = @count
  file.print "/*  #{num} times repeat of '#{@cell.get_name}' */\n"
  while count < num

    # セル名のカウント
    count_str = (count + base_count).to_s
    if tail_zero.length > count_str.length
      leading_zero = "0" * (tail_zero.length - count_str.length)
    else
      leading_zero = ""
    end
    cname = bname + leading_zero + count_str

    #   "cell tCelltype Cell {"
    file.print "#{indent_str}cell #{@cell.get_celltype.get_name} #{cname}{\n"

    # Join の CDL 文字列生成
    @cell.get_join_list.get_items.each{|j|

      # Join の右辺の解析
      res = j.get_rhs.analyze_cell_join_expression
      if res
        nsp, subscript, port_name = res[0], res[1], res[2]
      else
        nsp = j.get_rhs.analyze_single_identifier
        if nsp
          subscript, port_name = nil, nil
        else
          file.print "#{indent_str}  #{j.get_name} = #{j.get_rhs};\n"
          next
        end
      end

      # 右辺のセル名 (末尾の数字をカウントアップ)
      nsp.get_name.to_s =~ /(.*[^0-9])([0-9]+)\z/
      if $2
        rhs_tail_num = $2
        rhs_name_count = count + rhs_tail_num.to_i
        if rhs_tail_num.length > rhs_name_count.to_s.length
          leading_zero = "0" * (rhs_tail_num.length - rhs_name_count.to_s.length)
        else
          leading_zero = ""
        end
        rhs_cname = $1 + leading_zero + rhs_name_count.to_s
        nsp = nsp.change_name_clone rhs_cname
      end

      # Join 文字列の出力
      if port_name
        # 右辺は セルの結合
        if subscript
          file.print "#{indent_str}  #{j.get_name} = #{nsp.get_path_str}.#{port_name}[#{(count + subscript)}];\n"
        else
          file.print "#{indent_str}  #{j.get_name} = #{nsp.get_path_str}.#{port_name};\n"
        end
      else
        # 右辺は単一の識別子
        file.print "#{indent_str}  #{j.get_name} = #{nsp.get_path_str};\n"
      end
    }

    file.print "#{indent_str}};\n\n"
    count += 1
  end

  @cell.get_region.gen_region_str_post file
end

#set_count(rhs) ⇒ Object

count オプションの解析



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/tecsgen/plugin/RepeatCellPlugin.rb', line 151

def set_count(rhs)
  if rhs =~ /\A\d+\z/
    @count = rhs.to_i
  else
    nsp = NamespacePath.new(rhs.to_sym, true)
    expr = Expression.create_single_identifier(nsp, nil)
    res = expr.eval_const(nil)
    if res.nil?
      cdl_error("count value ($1): not single identifier or integer number", rhs.to_s)
      @count = 0
    else
      @count = res
    end
  end
end