source: azure_iot_hub/trunk/asp3_dcre/tecsgen/tecslib/plugin/RepeatCellPlugin.rb@ 388

Last change on this file since 388 was 388, checked in by coas-nagasima, 5 years ago

Azure IoT Hub Device C SDK を使ったサンプルの追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-ruby
File size: 6.2 KB
Line 
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)
62class 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
185end
Note: See TracBrowser for help on using the repository browser.