1 | # -*- coding: utf-8 -*-
|
---|
2 | #
|
---|
3 | # TECS Generator
|
---|
4 | # Generator for TOPPERS Embedded Component System
|
---|
5 | #
|
---|
6 | # Copyright (C) 2015-2018 by TOPPERS Project
|
---|
7 | #
|
---|
8 | #--
|
---|
9 | # ä¸è¨èä½æ¨©è
|
---|
10 | ã¯ï¼ä»¥ä¸ã®(1)ï½(4)ã®æ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§
|
---|
11 | # ã¢ï¼æ¬ã½ããã¦ã§ã¢ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹
|
---|
12 | # å¤ã»åé
|
---|
13 | å¸ï¼ä»¥ä¸ï¼å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
14 | # (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
15 | # 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
16 | # ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
17 | # (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
18 | # ç¨ã§ããå½¢ã§åé
|
---|
19 | å¸ããå ´åã«ã¯ï¼åé
|
---|
20 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
21 | # è
|
---|
22 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
23 | # ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
24 | # (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
25 | # ç¨ã§ããªãå½¢ã§åé
|
---|
26 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
27 | # ã¨ï¼
|
---|
28 | # (a) åé
|
---|
29 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
30 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
31 | # ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
32 | # (b) åé
|
---|
33 | å¸ã®å½¢æ
|
---|
34 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
35 | # å ±åãããã¨ï¼
|
---|
36 | # (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
37 | # 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
38 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
39 | 責ãããã¨ï¼
|
---|
40 | # ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®ã¦ã¼ã¶ã¾ãã¯ã¨ã³ãã¦ã¼ã¶ããã®ãããªãç
|
---|
41 | # ç±ã«åºã¥ãè«æ±ãããï¼ä¸è¨èä½æ¨©è
|
---|
42 | ããã³TOPPERSããã¸ã§ã¯ãã
|
---|
43 | # å
|
---|
44 | 責ãããã¨ï¼
|
---|
45 | #
|
---|
46 | # æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
47 | ã
|
---|
48 | # ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ç¹å®ã®ä½¿ç¨ç®ç
|
---|
49 | # ã«å¯¾ããé©åæ§ãå«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§
|
---|
50 | # ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ã
|
---|
51 | # ã®è²¬ä»»ãè² ããªãï¼
|
---|
52 | #
|
---|
53 | # $Id$
|
---|
54 | #++
|
---|
55 |
|
---|
56 | #== cell ã count åç¹°ãè¿ãã»ã«ãã©ã°ã¤ã³
|
---|
57 | # ä¸å®å
|
---|
58 | ¨ç¹ï¼
|
---|
59 | # æå®åã«å¯¾å¿ãã¦ããªã
|
---|
60 | # cell ã®æå®å (allocator, id)
|
---|
61 | # çµåã®æå®å (through)
|
---|
62 | class RepeatCellPlugin < CellPlugin
|
---|
63 |
|
---|
64 | @@plugin_list = []
|
---|
65 | RepeatCellPluginArgProc = {
|
---|
66 | "count" => Proc.new { |obj,rhs| obj.set_count rhs }
|
---|
67 | }
|
---|
68 |
|
---|
69 | def initialize( cell, option )
|
---|
70 | super
|
---|
71 | @@plugin_list << self
|
---|
72 | print "RepeatCellPlugin: #{@cell.get_name}\n"
|
---|
73 | # cell.show_tree 0
|
---|
74 | # @cell.get_join_list.get_items.each{ |j|
|
---|
75 | # print "Join: #{j.get_name} = #{j.get_rhs.to_s}\n"
|
---|
76 | # }
|
---|
77 | @count = 0
|
---|
78 | @plugin_arg_check_proc_tab = RepeatCellPluginArgProc
|
---|
79 | parse_plugin_arg
|
---|
80 | end
|
---|
81 |
|
---|
82 | def gen_cdl_file( file )
|
---|
83 | if $verbose then
|
---|
84 | print "#{self.class}: repeat #{@cell.get_name} #(num} times\n"
|
---|
85 | end
|
---|
86 |
|
---|
87 | nest = @cell.get_region.gen_region_str_pre file
|
---|
88 | indent_str = " " * nest
|
---|
89 | @cell.get_name.to_s =~ /.*[^0-9]([0-9]+)\z/
|
---|
90 | if $1 then
|
---|
91 | tail_zero = $1
|
---|
92 | bname = @cell.get_name.to_s.gsub( /[0-9]+\z/, "" )
|
---|
93 | else
|
---|
94 | cdl_error( "#{self.class}: #{@cell.get_name}'s name ends without '0-9'")
|
---|
95 | return
|
---|
96 | end
|
---|
97 | base_count = tail_zero.to_i
|
---|
98 |
|
---|
99 | count = 1
|
---|
100 | num = @count
|
---|
101 | file.print "/* #{num} times repeat of '#{@cell.get_name}' */\n"
|
---|
102 | while count < num
|
---|
103 |
|
---|
104 | # ã»ã«åã®ã«ã¦ã³ã
|
---|
105 | count_str = (count + base_count).to_s
|
---|
106 | if tail_zero.length > count_str.length then
|
---|
107 | leading_zero = "0" * ( tail_zero.length - count_str.length )
|
---|
108 | else
|
---|
109 | leading_zero = ""
|
---|
110 | end
|
---|
111 | cname = bname + leading_zero + count_str
|
---|
112 |
|
---|
113 | # "cell tCelltype Cell {"
|
---|
114 | file.print "#{indent_str}cell #{@cell.get_celltype.get_name} #{cname}{\n"
|
---|
115 |
|
---|
116 | # Join ã® CDL æååçæ
|
---|
117 | @cell.get_join_list.get_items.each{ |j|
|
---|
118 |
|
---|
119 | # Join ã®å³è¾ºã®è§£æ
|
---|
120 | res = j.get_rhs.analyze_cell_join_expression
|
---|
121 | if res then
|
---|
122 | nsp, subscript, port_name = res[0], res[1], res[2]
|
---|
123 | else
|
---|
124 | nsp = j.get_rhs.analyze_single_identifier
|
---|
125 | if nsp then
|
---|
126 | subscript, port_name = nil, nil
|
---|
127 | else
|
---|
128 | file.print "#{indent_str} #{j.get_name} = #{j.get_rhs.to_s};\n"
|
---|
129 | next
|
---|
130 | end
|
---|
131 | end
|
---|
132 |
|
---|
133 | # å³è¾ºã®ã»ã«å (æ«å°¾ã®æ°åãã«ã¦ã³ãã¢ãã)
|
---|
134 | nsp.get_name.to_s =~ /(.*[^0-9])([0-9]+)\z/
|
---|
135 | if $2 then
|
---|
136 | rhs_tail_num = $2
|
---|
137 | rhs_name_count = count + rhs_tail_num.to_i
|
---|
138 | if rhs_tail_num.length > rhs_name_count.to_s.length then
|
---|
139 | leading_zero = "0" * ( rhs_tail_num.length - rhs_name_count.to_s.length )
|
---|
140 | else
|
---|
141 | leading_zero = ""
|
---|
142 | end
|
---|
143 | rhs_cname = $1 + leading_zero + rhs_name_count.to_s
|
---|
144 | nsp = nsp.change_name_clone rhs_cname
|
---|
145 | end
|
---|
146 |
|
---|
147 | # Join æååã®åºå
|
---|
148 | if port_name then
|
---|
149 | # å³è¾ºã¯ ã»ã«ã®çµå
|
---|
150 | if subscript then
|
---|
151 | file.print "#{indent_str} #{j.get_name} = #{nsp.get_path_str}.#{port_name}[#{(count+subscript).to_s}];\n"
|
---|
152 | else
|
---|
153 | file.print "#{indent_str} #{j.get_name} = #{nsp.get_path_str}.#{port_name};\n"
|
---|
154 | end
|
---|
155 | else
|
---|
156 | # å³è¾ºã¯åä¸ã®èå¥å
|
---|
157 | file.print "#{indent_str} #{j.get_name} = #{nsp.get_path_str};\n"
|
---|
158 | end
|
---|
159 | }
|
---|
160 |
|
---|
161 | file.print "#{indent_str}};\n\n"
|
---|
162 | count += 1
|
---|
163 | end
|
---|
164 |
|
---|
165 | @cell.get_region.gen_region_str_post file
|
---|
166 | end
|
---|
167 |
|
---|
168 | #=== count ãªãã·ã§ã³ã®è§£æ
|
---|
169 | def set_count rhs
|
---|
170 | if rhs =~ /\A\d+\z/
|
---|
171 | @count = rhs.to_i
|
---|
172 | else
|
---|
173 | nsp = NamespacePath.new( rhs.to_sym, true )
|
---|
174 | expr = Expression.create_single_identifier( nsp, nil )
|
---|
175 | res = expr.eval_const( nil )
|
---|
176 | if res == nil then
|
---|
177 | cdl_error( "count value ($1): not single identifier or integer number", rhs.to_s )
|
---|
178 | @count = 0
|
---|
179 | else
|
---|
180 | @count = res
|
---|
181 | end
|
---|
182 | end
|
---|
183 | end
|
---|
184 |
|
---|
185 | end
|
---|