[337] | 1 | # -*- coding: utf-8 -*-
|
---|
| 2 | #
|
---|
[374] | 3 | # TECS Generator
|
---|
| 4 | # Generator for TOPPERS Embedded Component System
|
---|
| 5 | #
|
---|
[337] | 6 | # Copyright (C) 2015 by Ushio Laboratory
|
---|
| 7 | # Graduate School of Engineering Science, Osaka Univ., JAPAN
|
---|
| 8 | # Copyright (C) 2015-2016 by Embedded and Real-Time Systems Laboratory
|
---|
| 9 | # Graduate School of Information Science, Nagoya Univ., JAPAN
|
---|
[374] | 10 | # Copyright (C) 2015-2018 by TOPPERS Project
|
---|
[337] | 11 | #
|
---|
[374] | 12 | #--
|
---|
| 13 | # 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
|
---|
| 14 | # ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
|
---|
| 15 | # 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
|
---|
| 16 | # (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
| 17 | # 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
| 18 | # スコード中に含まれていること.
|
---|
| 19 | # (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
| 20 | # 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
| 21 | # 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
| 22 | # の無保証規定を掲載すること.
|
---|
| 23 | # (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
| 24 | # 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
|
---|
| 25 | # と.
|
---|
| 26 | # (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
| 27 | # 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
| 28 | # (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
|
---|
| 29 | # 報告すること.
|
---|
| 30 | # (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
| 31 | # 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
| 32 | # また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
|
---|
| 33 | # 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
|
---|
| 34 | # 免責すること.
|
---|
| 35 | #
|
---|
| 36 | # 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
| 37 | # よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
|
---|
| 38 | # に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
|
---|
| 39 | # アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
|
---|
| 40 | # の責任を負わない.
|
---|
| 41 | #
|
---|
| 42 | # $Id$
|
---|
| 43 | #++
|
---|
[337] | 44 |
|
---|
| 45 | NotifierPluginArgProc = {
|
---|
| 46 | "factory" => Proc.new { |obj, rhs| obj.set_factory(rhs) },
|
---|
| 47 | "output_file" => Proc.new { |obj, rhs| obj.set_factory_output_file(rhs) }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | class NotifierPlugin < CelltypePlugin
|
---|
| 51 |
|
---|
| 52 | # ---------- アダプタ関数の生成 -------------
|
---|
| 53 | #
|
---|
| 54 | # siHandlerBodyの受け口関数は,タイムイベント通知の通知先として直接指定する
|
---|
| 55 | # ことはできない.シグネチャが一致していないことが理由である.このため,アダ
|
---|
| 56 | # プタとして動作する関数を生成し,カーネルからの呼出しをTECSの呼出しに変換で
|
---|
| 57 | # きるようにする必要がある.
|
---|
| 58 | #
|
---|
| 59 | # 基本的には,受け口毎にアダプタ関数を生成すれば十分である.しかし,これでは
|
---|
| 60 | # メモリ消費量が不必要に増加してしまう.そこで,通知先関数にintptr_t型の引数
|
---|
| 61 | # を渡せることに着目し,関数の"一般化"を図る.すなわち受け口のある属性(ここ
|
---|
| 62 | # では,結合先のセル,添字などを指す)を,アダプタ関数の引数として受け取れる
|
---|
| 63 | # ようにし,1個のアダプタ関数を2個以上の結合に対し用いることができるように
|
---|
| 64 | # する.
|
---|
| 65 | #
|
---|
| 66 | # アダプタ関数の属性について整理すると,
|
---|
| 67 | # - 受け口関数 - 一般化を行うと,実行時コストが大きく増大してしまうことが
|
---|
| 68 | # 確認されている.このため,一般化は行わない.EntryPropertyにも含めない.
|
---|
| 69 | # - セルインデックス - CELLIDX型で,型の規定はないが,"ホ゜インタ値て゛あったり
|
---|
| 70 | # 整数値て゛あったりする。" (TECS 5.3.6) より,インデックスかポインタある
|
---|
| 71 | # ことが分かる.インデックスだとすると,この値はセルCBのアドレッシングに
|
---|
| 72 | # 使用されるので,intptr_tに収まる筈である.ポインタの場合,当然intptr_t
|
---|
| 73 | # に収まる.
|
---|
| 74 | # - 受け口配列の添字 - int_t.同様にintptr_tに収まる筈である.
|
---|
| 75 | # これらのうち,セルインデックスと受け口配列の添字はパラメータに含めることが
|
---|
| 76 | # できそうであるが,両方は無理である.
|
---|
| 77 | # 両方を格納した配列を生成し,その配列の要素へのポインタを渡すようにするとい
|
---|
| 78 | # う選択肢も可能であるが,実行速度を優先するために,この方法はとらなかった.
|
---|
| 79 | #
|
---|
| 80 | # このため,一般化は以下のパターンに分類して行う.
|
---|
| 81 | #
|
---|
| 82 | # 1. セルインデックスのみ一般化.セルインデックスのパターン数が受け口配列の
|
---|
| 83 | # 添字のパターン数より多いか,あるいは受け口が配列でない場合に行われる.
|
---|
| 84 | # 2. 受け口配列の添字のみ一般化.この場合,セルごとに異なる関数を用いる.
|
---|
| 85 | #
|
---|
| 86 | # これより,各受け口関数について,アダプタ関数の生成個数は,
|
---|
| 87 | # O(min{セルインデックスのパターン数, 添字のパターン数})
|
---|
| 88 | # となる.
|
---|
| 89 | #
|
---|
| 90 | # プラグインでの処理をワンパスで行うために,tecsgen.cfgではアダプタ関数を直
|
---|
| 91 | # 接指定するのではなく,代わりにアダプタ関数を表すマクロを使用する.この
|
---|
| 92 | # マクロはアダプタ関数ハンドルと呼ぶことにする.
|
---|
| 93 | # アダプタ関数ハンドルは,次の2個の要素から成る.
|
---|
| 94 | # - アダプタ関数へののポインタ
|
---|
| 95 | # - アダプタ関数の引数
|
---|
| 96 | #
|
---|
[359] | 97 | # $Id$
|
---|
[337] | 98 |
|
---|
| 99 | # @private
|
---|
| 100 | class AdapterGenerator
|
---|
| 101 |
|
---|
| 102 | # 結合先に関する属性を含む.セル,受け口配列の添字から成る.
|
---|
| 103 | # 同一のEntryPropertyとなる結合は,全く同じ方法でその受け口関数を呼び
|
---|
| 104 | # 出せる.
|
---|
| 105 | # @private
|
---|
| 106 | class EntryProperty
|
---|
| 107 | # @return [Cell] 受け口側のセル.
|
---|
| 108 | attr_reader :cell
|
---|
| 109 |
|
---|
| 110 | # @return [Integer, nil] 受け口配列の添字.配列でない場合はnil.
|
---|
| 111 | attr_reader :subscript
|
---|
| 112 |
|
---|
| 113 | def initialize(cell, subscript)
|
---|
| 114 | @cell = cell
|
---|
| 115 | @subscript = subscript
|
---|
| 116 | end
|
---|
| 117 |
|
---|
| 118 | def self.from_join(join)
|
---|
| 119 | EntryProperty.new(join.get_rhs_cell, join.get_rhs_subscript)
|
---|
| 120 | end
|
---|
| 121 |
|
---|
| 122 | # 同値性の定義.Hashのキーとして使用するのに必要.
|
---|
| 123 | def eql?(o) @cell == o.cell && @subscript == o.subscript end
|
---|
| 124 | def hash() @cell.hash ^ @subscript.hash end
|
---|
| 125 | end
|
---|
| 126 |
|
---|
| 127 | # @private
|
---|
| 128 | class EntryPort
|
---|
| 129 | # @param [Port] port 結合先のセルのセルタイプの受け口.
|
---|
| 130 | def initialize(port, prefix)
|
---|
| 131 | @port = port
|
---|
| 132 | @global_name = "#{prefix}_#{@port.get_celltype.get_global_name}_#{@port.get_name}"
|
---|
| 133 |
|
---|
| 134 | # 受け口関数名.siHandlerBodyを想定しているので,関数名はmainで固定である.
|
---|
| 135 | @entry_fn_name = "#{@port.get_celltype.get_global_name}_#{@port.get_name}_main"
|
---|
| 136 |
|
---|
| 137 | @props = [] # Array<EntryProperty>
|
---|
| 138 | @prop_map = {} # Hash<EntryProperty, Integer>
|
---|
| 139 | end
|
---|
| 140 |
|
---|
| 141 | # @return [String] グローバルに一意(なものとして扱えるよう)な識別子.
|
---|
| 142 | attr_reader :global_name
|
---|
| 143 |
|
---|
| 144 | # @return [Port]
|
---|
| 145 | attr_reader :port
|
---|
| 146 |
|
---|
| 147 | # 指定したEntryPropertyに対応するアダプタ関数ハンドルを取得する.
|
---|
| 148 | # @param [EntryProperty] ep
|
---|
| 149 | # @return [String] アダプタ関数ハンドル.
|
---|
| 150 | # @private
|
---|
| 151 | def adapter_handle_for_entry_property(ep)
|
---|
| 152 | index = @prop_map.fetch(ep)
|
---|
| 153 | return [
|
---|
| 154 | "#{@global_name}_#{index}_fp",
|
---|
| 155 | "#{@global_name}_#{index}_arg"
|
---|
| 156 | ]
|
---|
| 157 | end
|
---|
| 158 |
|
---|
| 159 | # 結合先の情報に応じたアダプタ関数をソース・ヘッダーに出力する.
|
---|
| 160 | # 一般化指定は,`cell`または`subscript`の一方のみ行うことができる.
|
---|
| 161 | #
|
---|
| 162 | # @param [AdapterGenerator] context
|
---|
| 163 | # @param [String] fn_name 関数名.
|
---|
| 164 | # @param [Cell, Symbol] cell セル.セルについて一般化する場合は `:generic`
|
---|
| 165 | # @param [Integer, Symbol, nil] subscript 添字.添字について一般化する場合は `:generic`
|
---|
[374] | 166 | # @param [Celltype] 呼び先のセルタイプ、cell==:generic の場合のみ有効
|
---|
[337] | 167 | # @private
|
---|
[374] | 168 | def generate_inner(context, fn_name, cell, subscript, callee_ct=nil)
|
---|
[337] | 169 | source_file = context.source_file
|
---|
| 170 | header_file = context.header_file
|
---|
| 171 |
|
---|
| 172 | source_file.print "void #{fn_name}(intptr_t extinf) {\n"
|
---|
| 173 |
|
---|
| 174 | params = []
|
---|
| 175 | ct = @port.get_celltype
|
---|
| 176 |
|
---|
| 177 | # シングルトンセルタイプ以外では,CELLIDXの指定が必要.
|
---|
| 178 | unless ct.is_singleton?
|
---|
| 179 | if cell == :generic
|
---|
[374] | 180 | params << "(#{callee_ct.get_global_name}_IDX)extinf"
|
---|
| 181 | # params << "(CELLIDX)extinf"
|
---|
[337] | 182 | else
|
---|
| 183 | # セルのCELLIDXを得る
|
---|
| 184 | if ct.has_INIB? || ct.has_CB?
|
---|
| 185 | params << ct.get_name_array(cell)[7]
|
---|
| 186 | else
|
---|
| 187 | params << "0"
|
---|
| 188 | end
|
---|
| 189 | end
|
---|
| 190 | end
|
---|
| 191 |
|
---|
| 192 | # 受け口配列の添字.
|
---|
| 193 | if @port.get_array_size
|
---|
| 194 | if subscript == :generic
|
---|
| 195 | params << "(int_t)extinf"
|
---|
| 196 | else
|
---|
| 197 | params << "#{subscript}"
|
---|
| 198 | end
|
---|
| 199 | end
|
---|
| 200 |
|
---|
| 201 | params_str = params.join(", ")
|
---|
| 202 |
|
---|
| 203 | source_file.print "\t#{@entry_fn_name}(#{params_str});\n"
|
---|
| 204 | source_file.print "}\n\n"
|
---|
| 205 |
|
---|
| 206 | header_file.print "extern void #{fn_name}(intptr_t extinf);\n\n"
|
---|
| 207 |
|
---|
| 208 | end
|
---|
| 209 |
|
---|
| 210 | # 指定したJoinに対応するアダプタ関数ハンドルを取得する.
|
---|
| 211 | # @return [Array] アダプタ関数ハンドル.
|
---|
| 212 | def make_adapter_handle(join)
|
---|
| 213 | prop = EntryProperty.from_join(join)
|
---|
| 214 | unless @prop_map.has_key?(prop)
|
---|
| 215 | @prop_map[prop] = @props.length
|
---|
| 216 | @props << prop
|
---|
| 217 | end
|
---|
| 218 | return adapter_handle_for_entry_property(prop)
|
---|
| 219 | end
|
---|
| 220 |
|
---|
| 221 | # ソース・ヘッダーの記述を生成する.
|
---|
| 222 | # @param [AdapterGenerator] context
|
---|
| 223 | def generate(context)
|
---|
| 224 | header_file = context.header_file
|
---|
| 225 | return if @props.empty?
|
---|
| 226 |
|
---|
| 227 | ct = @port.get_celltype
|
---|
| 228 |
|
---|
| 229 | header_file.print "/*\n * #{@global_name}\n"
|
---|
| 230 |
|
---|
| 231 | cells = @props.group_by { |prop| prop.cell }
|
---|
| 232 | subscripts = @props.group_by { |prop| prop.subscript }
|
---|
| 233 | no_cellidx = false
|
---|
| 234 | if !(ct.has_INIB? || ct.has_CB?)
|
---|
| 235 | # CB, INIB最適化により,CB, INIBが両方不要になったケース.
|
---|
| 236 | # CELLIDXが不要であるので,セルについて一般化しても意味
|
---|
| 237 | # はないので,添字による一般化を選択する.
|
---|
| 238 | generalize_by_cell_idx = false
|
---|
| 239 | no_cellidx = true
|
---|
| 240 |
|
---|
| 241 | # 全てのセルを同一視する.
|
---|
| 242 | cells = { @props[0].cell => @props }
|
---|
| 243 |
|
---|
| 244 | header_file.print " * No INIB & CB: generalized by subscript\n"
|
---|
| 245 | elsif @port.get_array_size
|
---|
| 246 | # 一般化パターンの分類を行うために,受け口側セルや添字の
|
---|
| 247 | # パターン数を分析して,最適な方を選択する.
|
---|
| 248 | generalize_by_cell_idx = cells.length >= subscripts.length
|
---|
| 249 | if generalize_by_cell_idx
|
---|
| 250 | header_file.print " * more cells than subscripts: generalized by cell\n"
|
---|
| 251 | else
|
---|
| 252 | header_file.print " * more subscripts than cells: generalized by subscript\n"
|
---|
| 253 | end
|
---|
| 254 | else
|
---|
| 255 | # 常にCELLIDXで一般化
|
---|
| 256 | generalize_by_cell_idx = true
|
---|
| 257 | header_file.print " * non-array entry port: generalized by cell\n"
|
---|
| 258 | end
|
---|
| 259 |
|
---|
| 260 | header_file.print " */\n\n"
|
---|
| 261 |
|
---|
| 262 | if generalize_by_cell_idx
|
---|
| 263 | # CELLIDXについて一般化
|
---|
| 264 | subscripts.each { |subscript, props|
|
---|
| 265 | if subscript
|
---|
| 266 | fn_name = "#{@global_name}_adap_#{subscript}"
|
---|
| 267 | else
|
---|
| 268 | # 受け口配列でない場合
|
---|
| 269 | fn_name = "#{@global_name}_adap"
|
---|
| 270 | end
|
---|
| 271 |
|
---|
| 272 | generate_inner context, fn_name,
|
---|
[374] | 273 | :generic, subscript, ct
|
---|
[337] | 274 |
|
---|
| 275 | props.each { |prop|
|
---|
| 276 | handle = adapter_handle_for_entry_property(prop)
|
---|
| 277 |
|
---|
| 278 | # セルのCELLIDXを得る
|
---|
| 279 | if ct.has_INIB? || ct.has_CB?
|
---|
| 280 | idx = ct.get_name_array(prop.cell)[7]
|
---|
| 281 | else
|
---|
| 282 | idx = "0"
|
---|
| 283 | end
|
---|
| 284 | header_file.print "\#define #{handle[0]} &#{fn_name}\n"
|
---|
| 285 | header_file.print "\#define #{handle[1]} #{idx}\n\n"
|
---|
| 286 | }
|
---|
| 287 | }
|
---|
| 288 | else
|
---|
| 289 | # 添字について一般化
|
---|
| 290 | cells.each { |cell, props|
|
---|
| 291 | if no_cellidx
|
---|
| 292 | # CB/INIB なし
|
---|
| 293 | fn_name = "#{@global_name}_adap"
|
---|
| 294 | else
|
---|
| 295 | fn_name = "#{@global_name}_adap_#{cell.get_global_name}"
|
---|
| 296 | end
|
---|
| 297 |
|
---|
| 298 | generate_inner context, fn_name,
|
---|
| 299 | cell, :generic
|
---|
| 300 |
|
---|
| 301 | props.each { |prop|
|
---|
| 302 | handle = adapter_handle_for_entry_property(prop)
|
---|
| 303 |
|
---|
| 304 | header_file.print "\#define #{handle[0]} &#{fn_name}\n"
|
---|
| 305 | header_file.print "\#define #{handle[1]} #{prop.subscript || 0}\n\n"
|
---|
| 306 | }
|
---|
| 307 | }
|
---|
| 308 | end
|
---|
| 309 | end
|
---|
| 310 | end
|
---|
| 311 |
|
---|
| 312 | # @private
|
---|
| 313 | attr :source_file
|
---|
| 314 |
|
---|
| 315 | # @private
|
---|
| 316 | attr :header_file
|
---|
| 317 |
|
---|
| 318 | # @param [String] celltype_name ハンドラ関数のセルタイプ.
|
---|
| 319 | # @param [String] prefix 名前衝突を防ぐためのプレフィックス.
|
---|
| 320 | def initialize(celltype_name, prefix)
|
---|
| 321 | @celltype_name = celltype_name
|
---|
| 322 | @prefix = prefix
|
---|
| 323 |
|
---|
| 324 | # Hash<Port, EntryPort>
|
---|
| 325 | @entry_ports = {}
|
---|
| 326 | end
|
---|
| 327 |
|
---|
| 328 | # ===AdapterGenerator#make_adapter_handle===
|
---|
| 329 | # 指定した結合の呼出しを行うためのアダプタ関数ハンドルを生成する.
|
---|
| 330 | # @return [Array] アダプタ関数ハンドル.
|
---|
| 331 | def make_adapter_handle(join)
|
---|
| 332 | entry_port = @entry_ports[join.get_rhs_port]
|
---|
| 333 | unless entry_port
|
---|
| 334 | entry_port = EntryPort.new(join.get_rhs_port,
|
---|
| 335 | "#{@celltype_name}_#{@prefix}")
|
---|
| 336 | @entry_ports[join.get_rhs_port] = entry_port
|
---|
| 337 | end
|
---|
| 338 | return entry_port.make_adapter_handle(join)
|
---|
| 339 | end
|
---|
| 340 |
|
---|
| 341 | # ===AdapterGenerator#finish===
|
---|
| 342 | # 各受け口に対し,アダプタ関数を生成する.
|
---|
| 343 | def finish
|
---|
| 344 | @source_file = AppFile.open( "#{$gen}/#{@celltype_name}.c" )
|
---|
| 345 | @source_file.print "\n/* Generated by #{self.class.name} */\n\n"
|
---|
| 346 | @source_file.print "\#include \"#{@celltype_name}_aux.h\"\n\n"
|
---|
| 347 | @source_file.print "\#include \"#{@celltype_name}_tecsgen.h\"\n\n"
|
---|
| 348 |
|
---|
| 349 | @header_file = AppFile.open( "#{$gen}/#{@celltype_name}.h" )
|
---|
| 350 | @header_file.print "\n/* Generated by #{self.class.name} */\n\n"
|
---|
| 351 |
|
---|
| 352 | # NotifierPluginを使用するセルタイプが複数ある場合,それぞれに
|
---|
| 353 | # 対しAdapterGenerator#finishが呼び出される.tTimeEventHandler.hに
|
---|
| 354 | # 続けて書き込んでしまうと,ヘッダーガードの関係で2回目以降の記述
|
---|
| 355 | # が読み込まれなくなってしまう.このため,ファイル名 + セルタイプ名
|
---|
| 356 | # という少し特殊なヘッダーガードを用いる.
|
---|
| 357 | header_guard = "#{@celltype_name}_H_#{@prefix}"
|
---|
| 358 |
|
---|
| 359 | @header_file.print "\#ifndef #{header_guard}\n"
|
---|
| 360 | @header_file.print "\#define #{header_guard}\n\n"
|
---|
| 361 |
|
---|
| 362 | # カーネルコンフィギュレータを実行する際,ハンドラ受け口のセルタイプ
|
---|
| 363 | # のセルCBの定義が必要な場合がある.
|
---|
| 364 | @header_file.print "\#include \"#{@celltype_name}_aux.h\"\n\n"
|
---|
| 365 |
|
---|
| 366 | # 結合先のセルタイプの定義は,自分のセルのtecsgen.hよりも先に
|
---|
| 367 | # 読み込まなければならないが,このプラグインが複数実行されると,
|
---|
| 368 | # 順序が崩れてしまう.そこで,結合先のセルタイプの定義はもう一つの
|
---|
| 369 | # ヘッダーファイル(tCelltypeName_aux.h)から読み込むようにする.
|
---|
| 370 | aux_header_file = AppFile.open( "#{$gen}/#{@celltype_name}_aux.h" )
|
---|
| 371 | aux_header_file.print "\n/* Generated by #{self.class.name} */\n\n"
|
---|
| 372 |
|
---|
| 373 | aux_header_guard = "#{@celltype_name}_AUX_H_#{@prefix}"
|
---|
| 374 |
|
---|
| 375 | aux_header_file.print "\#ifndef #{aux_header_guard}\n"
|
---|
| 376 | aux_header_file.print "\#define #{aux_header_guard}\n\n"
|
---|
| 377 |
|
---|
| 378 | cb_type_only_guard = "#{@celltype_name}_AUX_H_#{@prefix}_CB_TYPE_ONLY"
|
---|
| 379 |
|
---|
| 380 | # 結合先のセルタイプの定義を読み込む
|
---|
| 381 | aux_header_file.print "#ifndef TOPPERS_CB_TYPE_ONLY\n"
|
---|
| 382 | aux_header_file.print "#define TOPPERS_CB_TYPE_ONLY\n"
|
---|
| 383 | aux_header_file.print "#define #{cb_type_only_guard}\n"
|
---|
| 384 | aux_header_file.print "#endif\n"
|
---|
| 385 | @entry_ports.values.map { |ep|
|
---|
| 386 | ep.port.get_celltype
|
---|
| 387 | }.uniq.each { |ct|
|
---|
| 388 | hname = "#{ct.get_global_name}_tecsgen.#{$h_suffix}"
|
---|
| 389 | aux_header_file.print "\#include \"#{hname}\"\n"
|
---|
| 390 | }
|
---|
| 391 | aux_header_file.print "#ifdef #{cb_type_only_guard}\n"
|
---|
| 392 | aux_header_file.print "#undef #{cb_type_only_guard}\n"
|
---|
| 393 | aux_header_file.print "#undef TOPPERS_CB_TYPE_ONLY\n"
|
---|
| 394 | aux_header_file.print "#endif\n\n"
|
---|
| 395 |
|
---|
| 396 | aux_header_file.print "\#endif\n"
|
---|
| 397 | aux_header_file.close
|
---|
| 398 |
|
---|
| 399 | @entry_ports.each { |port, entry_port|
|
---|
| 400 | entry_port.generate self
|
---|
| 401 | }
|
---|
| 402 |
|
---|
| 403 | @header_file.print "\#endif\n"
|
---|
| 404 |
|
---|
| 405 | @source_file.close
|
---|
| 406 | @header_file.close
|
---|
| 407 | end
|
---|
| 408 |
|
---|
| 409 | end
|
---|
| 410 |
|
---|
| 411 | # ------ 通知のハンドラの種類の定義 -------
|
---|
| 412 |
|
---|
| 413 | class Handler
|
---|
| 414 | def initialize(call_port_name)
|
---|
| 415 | @call_port_name = call_port_name
|
---|
| 416 | end
|
---|
| 417 |
|
---|
| 418 | attr :call_port_name
|
---|
| 419 | end
|
---|
| 420 |
|
---|
| 421 | # 通常のハンドラ
|
---|
| 422 | EVENT_HANDLER = Handler::new("ciNotificationHandler")
|
---|
| 423 |
|
---|
| 424 | # エラーハンドラ (通常のハンドラが失敗した場合に呼び出される)
|
---|
| 425 | ERROR_HANDLER = Handler::new("ciErrorNotificationHandler")
|
---|
| 426 |
|
---|
| 427 | HANDLERS = [
|
---|
| 428 | EVENT_HANDLER,
|
---|
| 429 | ERROR_HANDLER
|
---|
| 430 | ]
|
---|
| 431 |
|
---|
| 432 | class HandlerAttribute
|
---|
| 433 | def initialize(name, error_name = nil)
|
---|
| 434 | @name = name
|
---|
| 435 | @error_name = error_name || (name + 'ForError')
|
---|
| 436 | end
|
---|
| 437 |
|
---|
| 438 | def name_for_handler(handler)
|
---|
| 439 | case handler
|
---|
| 440 | when EVENT_HANDLER then return @name
|
---|
| 441 | when ERROR_HANDLER then return @error_name
|
---|
| 442 | else raise "unknown handler #{handler}"
|
---|
| 443 | end
|
---|
| 444 | end
|
---|
| 445 | end
|
---|
| 446 |
|
---|
| 447 | # ------ 通知の属性の定義 -------
|
---|
| 448 | #
|
---|
| 449 | # ハンドラタイプに合致しない属性が指定された場合に
|
---|
| 450 | # エラーを出力できるよう、全ての属性をここで列挙する。
|
---|
| 451 |
|
---|
| 452 | SETVAR_ADDR_ATTR = HandlerAttribute::new("setVariableAddress")
|
---|
| 453 | SETVAR_VALUE_ATTR = HandlerAttribute::new("setVariableValue")
|
---|
| 454 | INCVAR_ADDR_ATTR = HandlerAttribute::new("incrementedVariableAddress")
|
---|
| 455 | SNDDTQ_VALUE_ATTR = HandlerAttribute::new("dataqueueSentValue")
|
---|
| 456 | SETFLG_FLAG_ATTR = HandlerAttribute::new("flagPattern")
|
---|
| 457 |
|
---|
| 458 | ATTRS = [
|
---|
| 459 | SETVAR_ADDR_ATTR,
|
---|
| 460 | SETVAR_VALUE_ATTR,
|
---|
| 461 | INCVAR_ADDR_ATTR,
|
---|
| 462 | SNDDTQ_VALUE_ATTR,
|
---|
| 463 | SETFLG_FLAG_ATTR
|
---|
| 464 | ]
|
---|
| 465 |
|
---|
| 466 | # ------ ハンドラタイプの定義 -------
|
---|
| 467 |
|
---|
| 468 | class BaseHandlerType
|
---|
| 469 |
|
---|
| 470 | def initialize()
|
---|
| 471 | super
|
---|
| 472 |
|
---|
| 473 | # HandlerAttribute[]
|
---|
| 474 | @required_attributes = []
|
---|
| 475 | end
|
---|
| 476 |
|
---|
| 477 | attr :required_attributes
|
---|
| 478 |
|
---|
| 479 | #=== NotifierPlugin#BaseHandlerType#validate_join
|
---|
| 480 | # 指定したセルの結合先が、このハンドラタイプに該当するかを検証
|
---|
| 481 | # handler:: Handler : ハンドラ
|
---|
| 482 | # cell:: Cell : セル
|
---|
| 483 | # join:: Join : 結合 (declarationがPortであるもの)
|
---|
| 484 | def validate_join(handler, cell, join)
|
---|
[374] | 485 | return !generate_attr_map(handler, cell).nil?
|
---|
[337] | 486 | end
|
---|
| 487 |
|
---|
| 488 | #=== NotifierPlugin#BaseHandlerType#generate_attr_map
|
---|
| 489 | # 指定したセルの属性と、既知のHandlerAttributeのマッピングを
|
---|
| 490 | # 生成し、Hash<HandlerAttribute, Join> (各属性とそれに対応する
|
---|
| 491 | # Join(declarationがDeclのもの)を表すHash)、あるいは、
|
---|
| 492 | # マッピングが行えない場合(属性の不足、過剰)はnilを返す。
|
---|
| 493 | #
|
---|
| 494 | # handler:: Handler : ハンドラ
|
---|
| 495 | # cell:: Cell : セル
|
---|
| 496 | def generate_attr_map(handler, cell)
|
---|
| 497 | map = {}
|
---|
| 498 |
|
---|
| 499 | join_list = cell.get_join_list
|
---|
| 500 |
|
---|
| 501 | ATTRS.each { |known_attr|
|
---|
| 502 | attr_name = known_attr.name_for_handler(handler)
|
---|
| 503 | join = join_list.get_item(attr_name.to_sym)
|
---|
| 504 |
|
---|
| 505 | # このセルタイプにおいて必須の属性か?
|
---|
| 506 | is_required = @required_attributes.include?(known_attr)
|
---|
| 507 |
|
---|
| 508 | # 属性の指定が不足している? or 過剰?
|
---|
| 509 | # 注: ハンドラタイプの判別には、セルで値が指定されているか
|
---|
| 510 | # が考慮される。セルタイプで初期値が指定されていても、
|
---|
| 511 | # それはハンドラタイプの決定に影響しない。
|
---|
| 512 | return nil if join.nil? != !is_required
|
---|
| 513 |
|
---|
| 514 | # 必要のない属性であり、指定もされていないので飛ばす
|
---|
| 515 | next if join.nil?
|
---|
| 516 |
|
---|
| 517 | # TODO: attrの結合であることを検証
|
---|
| 518 |
|
---|
| 519 | map[known_attr] = join
|
---|
| 520 | }
|
---|
| 521 |
|
---|
| 522 | return map
|
---|
| 523 | end
|
---|
| 524 |
|
---|
| 525 | #=== NotifierPlugin#BaseHandlerType#gen_cfg_handler_type
|
---|
| 526 | # タイムイベントの通知の種類を表すコンフィギュレータの記述を生成し、Stringまたはnilを返す
|
---|
| 527 | # handler:: Handler : ハンドラ
|
---|
| 528 | def gen_cfg_handler_type(handler)
|
---|
| 529 | raise "called abstract method gen_cfg_handler_type"
|
---|
| 530 | end
|
---|
| 531 |
|
---|
| 532 | #=== NotifierPlugin#BaseHandlerType#gen_cfg_handler_parameters
|
---|
| 533 | # タイムイベントの通知の引数を表すコンフィギュレータの記述を生成し、String[]を返す
|
---|
| 534 | # handler:: Handler : ハンドラ
|
---|
| 535 | # join:: Join : 結合 (declarationがPortであるもの)
|
---|
| 536 | # attrMap:: Hash<HandlerAttribute, Join> :
|
---|
| 537 | # 各属性とそれに対応するJoin (declarationがDeclのもの)
|
---|
| 538 | # cell:: Cell : セル
|
---|
| 539 | # adpt_gen:: AdapterGenerator : アダプタ関数を生成するオブジェクト
|
---|
| 540 | def gen_cfg_handler_parameters(handler, join, attrMap, cell, adpt_gen)
|
---|
| 541 | return nil
|
---|
| 542 | end
|
---|
| 543 |
|
---|
| 544 | #=== NotifierPlugin#BaseHandlerType#might_fail
|
---|
| 545 | # 通知の際、エラーが発生し、その結果エラー通知を呼ぶ必要が生じる
|
---|
| 546 | # かどうかを返す。
|
---|
| 547 | def might_fail
|
---|
| 548 | return false
|
---|
| 549 | end
|
---|
| 550 |
|
---|
| 551 | end
|
---|
| 552 | class BaseTaskHandlerType < BaseHandlerType
|
---|
| 553 | def validate_join(handler, cell, join, *args)
|
---|
| 554 | return super(handler, cell, join, *args) &&
|
---|
| 555 | join && join.get_rhs_cell.get_celltype.get_name == :tTask
|
---|
| 556 | end
|
---|
| 557 | def gen_cfg_handler_parameters(handler, join, attrMap, cell, adpt_gen)
|
---|
| 558 | taskCell = join.get_cell
|
---|
| 559 | id_attr_join = taskCell.get_join_list.get_item(:id)
|
---|
| 560 | id_attr = join.get_rhs_cell.get_celltype.find(:id)
|
---|
| 561 | if id_attr_join
|
---|
| 562 | # セル生成時に初期化する場合
|
---|
| 563 | id = id_attr_join.get_rhs.to_s
|
---|
| 564 | else
|
---|
| 565 | # セルタイプの初期化値を使う場合
|
---|
| 566 | id = id_attr.get_initializer.to_s
|
---|
| 567 | end
|
---|
| 568 |
|
---|
| 569 | # $id$等の置換
|
---|
| 570 | name_array = taskCell.get_celltype.get_name_array(taskCell)
|
---|
| 571 | id = taskCell.get_celltype.subst_name(id, name_array)
|
---|
| 572 |
|
---|
| 573 | return [id]
|
---|
| 574 | end
|
---|
| 575 | def might_fail
|
---|
| 576 | return true
|
---|
| 577 | end
|
---|
| 578 | end
|
---|
| 579 | class ActivateTaskHandlerType < BaseTaskHandlerType
|
---|
| 580 | def validate_join(handler, cell, join, *args)
|
---|
| 581 | return super(handler, cell, join, *args) &&
|
---|
| 582 | join.get_port_name == :eiActivateNotificationHandler
|
---|
| 583 | end
|
---|
| 584 | def gen_cfg_handler_type(handler)
|
---|
| 585 | case handler
|
---|
| 586 | when EVENT_HANDLER then return "TNFY_ACTTSK"
|
---|
| 587 | when ERROR_HANDLER then return "TENFY_ACTTSK"
|
---|
| 588 | else raise "unknown handler #{handler}"
|
---|
| 589 | end
|
---|
| 590 | end
|
---|
| 591 | end
|
---|
| 592 | class WakeUpTaskHandlerType < BaseTaskHandlerType
|
---|
| 593 | def validate_join(handler, cell, join, *args)
|
---|
| 594 | return super(handler, cell, join, *args) &&
|
---|
| 595 | join.get_port_name == :eiWakeUpNotificationHandler
|
---|
| 596 | end
|
---|
| 597 | def gen_cfg_handler_type(handler)
|
---|
| 598 | case handler
|
---|
| 599 | when EVENT_HANDLER then return "TNFY_WUPTSK"
|
---|
| 600 | when ERROR_HANDLER then return "TENFY_WUPTSK"
|
---|
| 601 | else raise "unknown handler #{handler}"
|
---|
| 602 | end
|
---|
| 603 | end
|
---|
| 604 | end
|
---|
| 605 | class SetVariableHandlerType < BaseHandlerType
|
---|
| 606 | def initialize()
|
---|
| 607 | super
|
---|
| 608 | @required_attributes = [
|
---|
| 609 | SETVAR_ADDR_ATTR,
|
---|
| 610 | SETVAR_VALUE_ATTR
|
---|
| 611 | ] # .to_set
|
---|
| 612 | end
|
---|
| 613 | def validate_join(handler, cell, join, *args)
|
---|
| 614 | return super(handler, cell, join, *args) &&
|
---|
| 615 | join.nil? &&
|
---|
| 616 | handler == EVENT_HANDLER
|
---|
| 617 | end
|
---|
| 618 | def gen_cfg_handler_parameters(handler, join, attrMap, cell, adpt_gen)
|
---|
| 619 | var_addr = attrMap[SETVAR_ADDR_ATTR].get_rhs.to_s
|
---|
| 620 | var_value = attrMap[SETVAR_VALUE_ATTR].get_rhs.to_s
|
---|
| 621 |
|
---|
| 622 | # $id$等の置換
|
---|
| 623 | name_array = cell.get_celltype.get_name_array(cell)
|
---|
| 624 | var_addr = cell.get_celltype.subst_name(var_addr, name_array)
|
---|
| 625 | var_value = cell.get_celltype.subst_name(var_value, name_array)
|
---|
| 626 |
|
---|
| 627 | return [var_addr, var_value]
|
---|
| 628 | end
|
---|
| 629 | def gen_cfg_handler_type(handler)
|
---|
| 630 | case handler
|
---|
| 631 | when EVENT_HANDLER then return "TNFY_SETVAR"
|
---|
| 632 | else raise "unknown handler #{handler}"
|
---|
| 633 | end
|
---|
| 634 | end
|
---|
| 635 | end
|
---|
| 636 | class SetVariableToErrorCodeHandlerType < BaseHandlerType
|
---|
| 637 | def initialize()
|
---|
| 638 | super
|
---|
| 639 | @required_attributes = [
|
---|
| 640 | SETVAR_ADDR_ATTR
|
---|
| 641 | ] # .to_set
|
---|
| 642 | end
|
---|
| 643 | def validate_join(handler, cell, join, *args)
|
---|
| 644 | return super(handler, cell, join, *args) &&
|
---|
| 645 | join.nil? &&
|
---|
| 646 | handler == ERROR_HANDLER
|
---|
| 647 | end
|
---|
| 648 | def gen_cfg_handler_parameters(handler, join, attrMap, cell, adpt_gen)
|
---|
| 649 | var_addr = attrMap[SETVAR_ADDR_ATTR].get_rhs.to_s
|
---|
| 650 |
|
---|
| 651 | # $id$等の置換
|
---|
| 652 | name_array = cell.get_celltype.get_name_array(cell)
|
---|
| 653 | var_addr = cell.get_celltype.subst_name(var_addr, name_array)
|
---|
| 654 |
|
---|
| 655 | return [var_addr]
|
---|
| 656 | end
|
---|
| 657 | def gen_cfg_handler_type(handler)
|
---|
| 658 | case handler
|
---|
| 659 | when ERROR_HANDLER then return "TENFY_SETVAR"
|
---|
| 660 | else raise "unknown handler #{handler}"
|
---|
| 661 | end
|
---|
| 662 | end
|
---|
| 663 | end
|
---|
| 664 | class IncrementVariableHandlerType < BaseHandlerType
|
---|
| 665 | def initialize()
|
---|
| 666 | super
|
---|
| 667 | @required_attributes = [
|
---|
| 668 | INCVAR_ADDR_ATTR
|
---|
| 669 | ] # .to_set
|
---|
| 670 | end
|
---|
| 671 | def validate_join(handler, cell, join, *args)
|
---|
| 672 | return super(handler, cell, join, *args) &&
|
---|
| 673 | join.nil?
|
---|
| 674 | end
|
---|
| 675 | def gen_cfg_handler_parameters(handler, join, attrMap, cell, adpt_gen)
|
---|
| 676 | var_addr = attrMap[INCVAR_ADDR_ATTR].get_rhs.to_s
|
---|
| 677 |
|
---|
| 678 | # $id$等の置換
|
---|
| 679 | name_array = cell.get_celltype.get_name_array(cell)
|
---|
| 680 | var_addr = cell.get_celltype.subst_name(var_addr, name_array)
|
---|
| 681 |
|
---|
| 682 | return [var_addr]
|
---|
| 683 | end
|
---|
| 684 | def gen_cfg_handler_type(handler)
|
---|
| 685 | case handler
|
---|
| 686 | when EVENT_HANDLER then return "TNFY_INCVAR"
|
---|
| 687 | when ERROR_HANDLER then return "TENFY_INCVAR"
|
---|
| 688 | else raise "unknown handler #{handler}"
|
---|
| 689 | end
|
---|
| 690 | end
|
---|
| 691 | end
|
---|
| 692 | class SignalSemaphoreHandlerType < BaseHandlerType
|
---|
| 693 | def validate_join(handler, cell, join, *args)
|
---|
| 694 | return super(handler, cell, join, *args) &&
|
---|
| 695 | join && join.get_rhs_cell.get_celltype.get_name == :tSemaphore
|
---|
| 696 | end
|
---|
| 697 | def gen_cfg_handler_parameters(handler, join, attrMap, cell, adpt_gen)
|
---|
| 698 | semaphoreCell = join.get_cell
|
---|
| 699 | id_attr_join = semaphoreCell.get_join_list.get_item(:id)
|
---|
| 700 | id_attr = join.get_rhs_cell.get_celltype.find(:id)
|
---|
| 701 | if id_attr_join
|
---|
| 702 | # セル生成時に初期化する場合
|
---|
| 703 | id = id_attr_join.get_rhs.to_s
|
---|
| 704 | else
|
---|
| 705 | # セルタイプの初期化値を使う場合
|
---|
| 706 | id = id_attr.get_initializer.to_s
|
---|
| 707 | end
|
---|
| 708 |
|
---|
| 709 | # $id$等の置換
|
---|
| 710 | name_array = semaphoreCell.get_celltype.get_name_array(semaphoreCell)
|
---|
| 711 | id = semaphoreCell.get_celltype.subst_name(id, name_array)
|
---|
| 712 |
|
---|
| 713 | return [id]
|
---|
| 714 | end
|
---|
| 715 | def might_fail
|
---|
| 716 | return true
|
---|
| 717 | end
|
---|
| 718 | def gen_cfg_handler_type(handler)
|
---|
| 719 | case handler
|
---|
| 720 | when EVENT_HANDLER then return "TNFY_SIGSEM"
|
---|
| 721 | when ERROR_HANDLER then return "TENFY_SIGSEM"
|
---|
| 722 | else raise "unknown handler #{handler}"
|
---|
| 723 | end
|
---|
| 724 | end
|
---|
| 725 | end
|
---|
| 726 | class SetEventflagHandlerType < BaseHandlerType
|
---|
| 727 | def initialize()
|
---|
| 728 | super
|
---|
| 729 | @required_attributes = [
|
---|
| 730 | SETFLG_FLAG_ATTR
|
---|
| 731 | ] # .to_set
|
---|
| 732 | end
|
---|
| 733 | def validate_join(handler, cell, join, *args)
|
---|
| 734 | return super(handler, cell, join, *args) &&
|
---|
| 735 | join && join.get_rhs_cell.get_celltype.get_name == :tEventflag
|
---|
| 736 | end
|
---|
| 737 | def gen_cfg_handler_parameters(handler, join, attrMap, cell, adpt_gen)
|
---|
| 738 | eventflagCell = join.get_cell
|
---|
| 739 | id_attr_join = eventflagCell.get_join_list.get_item(:id)
|
---|
| 740 | id_attr = join.get_rhs_cell.get_celltype.find(:id)
|
---|
| 741 | if id_attr_join
|
---|
| 742 | # セル生成時に初期化する場合
|
---|
| 743 | id = id_attr_join.get_rhs.to_s
|
---|
| 744 | else
|
---|
| 745 | # セルタイプの初期化値を使う場合
|
---|
| 746 | id = id_attr.get_initializer.to_s
|
---|
| 747 | end
|
---|
| 748 | flg_pattern = attrMap[SETFLG_FLAG_ATTR].get_rhs.to_s
|
---|
| 749 |
|
---|
| 750 | # $id$等の置換
|
---|
| 751 | name_array = eventflagCell.get_celltype.get_name_array(eventflagCell)
|
---|
| 752 | id = eventflagCell.get_celltype.subst_name(id, name_array)
|
---|
| 753 |
|
---|
| 754 | name_array = cell.get_celltype.get_name_array(cell)
|
---|
| 755 | flg_pattern = cell.get_celltype.subst_name(flg_pattern, name_array)
|
---|
| 756 |
|
---|
| 757 | return [id, flg_pattern]
|
---|
| 758 | end
|
---|
| 759 | def might_fail
|
---|
| 760 | return true
|
---|
| 761 | end
|
---|
| 762 | def gen_cfg_handler_type(handler)
|
---|
| 763 | case handler
|
---|
| 764 | when EVENT_HANDLER then return "TNFY_SETFLG"
|
---|
| 765 | when ERROR_HANDLER then return "TENFY_SETFLG"
|
---|
| 766 | else raise "unknown handler #{handler}"
|
---|
| 767 | end
|
---|
| 768 | end
|
---|
| 769 | end
|
---|
| 770 | class DataqueueHandlerType < BaseHandlerType
|
---|
| 771 | def initialize()
|
---|
| 772 | super
|
---|
| 773 | end
|
---|
| 774 | def validate_join(handler, cell, join, *args)
|
---|
| 775 | return super(handler, cell, join, *args) &&
|
---|
| 776 | join && join.get_rhs_cell.get_celltype.get_name == :tDataqueue
|
---|
| 777 | end
|
---|
| 778 | def gen_cfg_handler_parameters(handler, join, attrMap, cell, adpt_gen)
|
---|
| 779 | dataqueueCell = join.get_cell
|
---|
| 780 | id_attr_join = dataqueueCell.get_join_list.get_item(:id)
|
---|
| 781 | id_attr = join.get_rhs_cell.get_celltype.find(:id)
|
---|
| 782 | if id_attr_join
|
---|
| 783 | # セル生成時に初期化する場合
|
---|
| 784 | id = id_attr_join.get_rhs.to_s
|
---|
| 785 | else
|
---|
| 786 | # セルタイプの初期化値を使う場合
|
---|
| 787 | id = id_attr.get_initializer.to_s
|
---|
| 788 | end
|
---|
| 789 |
|
---|
| 790 | # $id$等の置換
|
---|
| 791 | name_array = dataqueueCell.get_celltype.get_name_array(dataqueueCell)
|
---|
| 792 | id = dataqueueCell.get_celltype.subst_name(id, name_array)
|
---|
| 793 |
|
---|
| 794 | name_array = cell.get_celltype.get_name_array(cell)
|
---|
| 795 |
|
---|
| 796 | return [id]
|
---|
| 797 | end
|
---|
| 798 | def might_fail
|
---|
| 799 | return true
|
---|
| 800 | end
|
---|
| 801 | end
|
---|
| 802 | class SendToDataqueueHandlerType < DataqueueHandlerType
|
---|
| 803 | def initialize()
|
---|
| 804 | super
|
---|
| 805 | @required_attributes = [
|
---|
| 806 | SNDDTQ_VALUE_ATTR
|
---|
| 807 | ] # .to_set
|
---|
| 808 | end
|
---|
| 809 | def validate_join(handler, cell, join, *args)
|
---|
| 810 | return super(handler, cell, join, *args) && handler == EVENT_HANDLER
|
---|
| 811 | end
|
---|
| 812 | def gen_cfg_handler_parameters(handler, join, attrMap, cell, adpt_gen)
|
---|
| 813 | params = super(handler, join, attrMap, cell, adpt_gen)
|
---|
| 814 |
|
---|
| 815 | sent_value = attrMap[SNDDTQ_VALUE_ATTR].get_rhs.to_s
|
---|
| 816 |
|
---|
| 817 | # $id$等の置換
|
---|
| 818 | name_array = cell.get_celltype.get_name_array(cell)
|
---|
| 819 | sent_value = cell.get_celltype.subst_name(sent_value, name_array)
|
---|
| 820 |
|
---|
| 821 | params << sent_value
|
---|
| 822 |
|
---|
| 823 | return params
|
---|
| 824 | end
|
---|
| 825 | def gen_cfg_handler_type(handler)
|
---|
| 826 | case handler
|
---|
| 827 | when EVENT_HANDLER then return "TNFY_SNDDTQ"
|
---|
| 828 | else raise "unknown handler #{handler}"
|
---|
| 829 | end
|
---|
| 830 | end
|
---|
| 831 | end
|
---|
| 832 | class SendErrorCodeToDataqueueHandlerType < DataqueueHandlerType
|
---|
| 833 | def initialize()
|
---|
| 834 | super
|
---|
| 835 | end
|
---|
| 836 | def validate_join(handler, cell, join, *args)
|
---|
| 837 | return super(handler, cell, join, *args) && handler == ERROR_HANDLER
|
---|
| 838 | end
|
---|
| 839 | def gen_cfg_handler_type(handler)
|
---|
| 840 | case handler
|
---|
| 841 | when ERROR_HANDLER then return "TENFY_SNDDTQ"
|
---|
| 842 | else raise "unknown handler #{handler}"
|
---|
| 843 | end
|
---|
| 844 | end
|
---|
| 845 | end
|
---|
| 846 | class UserHandlerType < BaseHandlerType
|
---|
| 847 | def validate_join(handler, cell, join, *args)
|
---|
| 848 | return super(handler, cell, join, *args) &&
|
---|
| 849 | handler != ERROR_HANDLER && # invalid for error handler
|
---|
| 850 | join && join.get_rhs_cell.get_celltype.get_name == :tTimeEventHandler
|
---|
| 851 | end
|
---|
| 852 | def gen_cfg_handler_type(handler)
|
---|
| 853 | case handler
|
---|
| 854 | when EVENT_HANDLER then return "TNFY_HANDLER"
|
---|
| 855 | else raise "unknown handler #{handler}"
|
---|
| 856 | end
|
---|
| 857 | end
|
---|
| 858 | def gen_cfg_handler_parameters(handler, join, attrMap, cell, adpt_gen)
|
---|
| 859 | # tTimeEventHandlerの結合先を取得
|
---|
| 860 | handler_cell = join.get_rhs_cell
|
---|
| 861 | call_join = handler_cell.get_join_list.get_item(:ciHandlerBody)
|
---|
| 862 |
|
---|
| 863 | # 結合されていない場合はtecsgenがエラーを出すはずなのでここでは
|
---|
| 864 | # エラーにせず無視する.
|
---|
| 865 | return [] unless call_join
|
---|
| 866 |
|
---|
| 867 | # アダプタ関数ハンドルを取得
|
---|
| 868 | adapter_handle = adpt_gen.make_adapter_handle(call_join)
|
---|
| 869 | return [adapter_handle[1], adapter_handle[0]]
|
---|
| 870 | end
|
---|
| 871 | end
|
---|
| 872 | class NullHandlerType < BaseHandlerType
|
---|
| 873 | def validate_join(handler, cell, join, *args)
|
---|
| 874 | return super(handler, cell, join, *args) &&
|
---|
| 875 | join.nil? &&
|
---|
| 876 | handler != EVENT_HANDLER # handler is mandatory for normal handler!
|
---|
| 877 | end
|
---|
| 878 | def gen_cfg_handler_type(handler)
|
---|
| 879 | case handler
|
---|
| 880 | when ERROR_HANDLER then return nil
|
---|
| 881 | else raise "unknown handler #{handler}"
|
---|
| 882 | end
|
---|
| 883 | end
|
---|
| 884 | end
|
---|
| 885 |
|
---|
| 886 | HANDLER_TYPES = [
|
---|
| 887 | ActivateTaskHandlerType.new,
|
---|
| 888 | WakeUpTaskHandlerType.new,
|
---|
| 889 | SetVariableHandlerType.new,
|
---|
| 890 | SetVariableToErrorCodeHandlerType.new,
|
---|
| 891 | IncrementVariableHandlerType.new,
|
---|
| 892 | SignalSemaphoreHandlerType.new,
|
---|
| 893 | SetEventflagHandlerType.new,
|
---|
| 894 | SendToDataqueueHandlerType.new,
|
---|
| 895 | SendErrorCodeToDataqueueHandlerType.new,
|
---|
| 896 | UserHandlerType.new,
|
---|
| 897 | NullHandlerType.new
|
---|
| 898 | ]
|
---|
| 899 |
|
---|
| 900 | #@celltype:: Celltype
|
---|
| 901 | #@option:: String :オプション文字列
|
---|
| 902 | def initialize( celltype, option )
|
---|
| 903 | super
|
---|
| 904 | @plugin_arg_check_proc_tab = NotifierPluginArgProc
|
---|
| 905 | @plugin_arg_str = option
|
---|
| 906 | @plugin_arg_str = option.gsub( /\A"(.*)/, '\1' ) # 前後の "" を取り除く
|
---|
| 907 | @plugin_arg_str.sub!( /(.*)"\z/, '\1' )
|
---|
| 908 | @factory = nil
|
---|
| 909 | @output_file = nil
|
---|
| 910 | parse_plugin_arg
|
---|
| 911 | unless @factory
|
---|
[374] | 912 | cdl_error("NTF1003 celltype $1: option factory is not specified",
|
---|
[337] | 913 | celltype.get_name)
|
---|
| 914 | end
|
---|
| 915 | unless @output_file
|
---|
[374] | 916 | cdl_error("NTF1003 celltype $1: option output_file is not specified",
|
---|
[337] | 917 | celltype.get_name)
|
---|
| 918 | end
|
---|
| 919 | end
|
---|
| 920 |
|
---|
| 921 | def set_factory(template_string)
|
---|
| 922 | unless @factory.nil?
|
---|
[374] | 923 | cdl_error("NTF1003 celltype $1: option factory was specified more than once",
|
---|
[337] | 924 | celltype.get_name)
|
---|
| 925 | end
|
---|
| 926 | @factory = template_string
|
---|
| 927 | end
|
---|
| 928 |
|
---|
| 929 | def set_factory_output_file(output_file)
|
---|
| 930 | unless @output_file.nil?
|
---|
[374] | 931 | cdl_error("NTF1003 celltype $1: option output_file was specified more than once",
|
---|
[337] | 932 | celltype.get_name)
|
---|
| 933 | end
|
---|
| 934 | @output_file = output_file
|
---|
| 935 | end
|
---|
| 936 |
|
---|
| 937 | def gen_factory file
|
---|
[374] | 938 | # puts "===== begin #{@celltype.get_name.to_s} plugin ====="
|
---|
[337] | 939 |
|
---|
| 940 | kernelCfg = AppFile.open( "#{$gen}/#{@output_file}" )
|
---|
| 941 | kernelCfg.print "\n/* Generated by #{self.class.name} */\n"
|
---|
| 942 | kernelCfg.print "\#include \"tTimeEventHandler.h\"\n"
|
---|
| 943 |
|
---|
| 944 | # アダプタ関数を生成する準備
|
---|
| 945 | @adpt_gen = AdapterGenerator.new("tTimeEventHandler", @celltype.get_global_name)
|
---|
| 946 |
|
---|
| 947 | # 属性置換が行えることを検証する。
|
---|
| 948 | # ここで行うのは、factoryで指定された属性名が
|
---|
| 949 | # 存在することを確認し、しなければエラーを出力することのみである。
|
---|
| 950 | # セルごとの処理の最中にエラーを出力することも可能ではあるが、
|
---|
| 951 | # そうするとセルタイプ側の問題であるのにもかかわらず、セルごとに
|
---|
| 952 | # エラーが表示されてしまう。
|
---|
| 953 | # {{attribute_name}} -> attribute_value
|
---|
| 954 | @factory.scan(/\{\{([a-zA-Z0-9_]*?)\}\}/) { |match|
|
---|
| 955 | name = $1.to_sym
|
---|
| 956 |
|
---|
| 957 | # {{_handler_params_}} はハンドラに関する指定。プラグイン内で値が生成される
|
---|
| 958 | next if name == :_handler_params_
|
---|
| 959 |
|
---|
| 960 | subst_attr = @celltype.find(name)
|
---|
| 961 | unless subst_attr
|
---|
[374] | 962 | cdl_error( "NTF1007 celltype $1: additional_param: attribute $2 does not exist.",
|
---|
[337] | 963 | @celltype.get_name, name)
|
---|
| 964 | end
|
---|
| 965 | }
|
---|
| 966 |
|
---|
| 967 | @celltype.get_cell_list.each { |cell|
|
---|
| 968 | gen_factory_for_cell kernelCfg, cell
|
---|
| 969 | }
|
---|
| 970 |
|
---|
| 971 | # アダプタ関数の生成を完了させる
|
---|
| 972 | @adpt_gen.finish
|
---|
| 973 |
|
---|
| 974 | kernelCfg.close
|
---|
[374] | 975 | # puts "===== end #{@celltype.get_name.to_s} plugin ====="
|
---|
[337] | 976 | end
|
---|
| 977 |
|
---|
| 978 | def gen_factory_for_cell(kernelCfg, cell)
|
---|
[374] | 979 | # print "########## gen_factory_for_cell cell=#{cell.get_name}\n"
|
---|
[337] | 980 | handler_flags = []
|
---|
| 981 | handler_args = []
|
---|
| 982 |
|
---|
| 983 | event_handler_might_fail = true
|
---|
| 984 | handler_flag = nil
|
---|
| 985 |
|
---|
| 986 | # ignoreErrorsを取得
|
---|
| 987 | ignoreErrors_attr_join = cell.get_join_list.get_item(:ignoreErrors)
|
---|
| 988 | ignoreErrors_attr = cell.get_celltype.find(:ignoreErrors)
|
---|
| 989 | if ignoreErrors_attr_join
|
---|
| 990 | # セル生成時に初期化する場合
|
---|
| 991 | ignoreErrors = ignoreErrors_attr_join.get_rhs.to_s
|
---|
| 992 | else
|
---|
| 993 | # セルタイプの初期化値を使う場合
|
---|
| 994 | ignoreErrors = ignoreErrors_attr.get_initializer.to_s
|
---|
| 995 | end
|
---|
| 996 | case ignoreErrors
|
---|
| 997 | when 'true' then ignoreErrors = true
|
---|
| 998 | when 'false' then ignoreErrors = false
|
---|
| 999 | else
|
---|
[374] | 1000 | cdl_warning2( cell.get_locale, "NTF1005 cell $1: unrecognized value '$2' specified for ignoreErrors",
|
---|
[337] | 1001 | cell.get_name, ignoreErrors )
|
---|
| 1002 | ignoreErrors = false
|
---|
| 1003 | end
|
---|
| 1004 |
|
---|
[374] | 1005 | # ドメイン指定用文字列
|
---|
| 1006 | pre_text = ""
|
---|
| 1007 | post_text = "\n"
|
---|
| 1008 | indent = ""
|
---|
| 1009 |
|
---|
[337] | 1010 | [EVENT_HANDLER, ERROR_HANDLER].each { |handler|
|
---|
| 1011 | # 呼び口の結合を取得
|
---|
| 1012 | call_join = cell.get_join_list.get_item(handler.call_port_name.to_sym)
|
---|
[374] | 1013 | domain_root = cell.get_region.get_domain_root
|
---|
| 1014 | if cell.get_region.get_domain_root.get_domain_type then
|
---|
| 1015 | # print "cell=#{cell.get_name} domain_root=#{domain_root.get_name} domain_type=#{domain_root.get_domain_type.get_name} domain_option=#{domain_root.get_domain_type.get_option}\n"
|
---|
| 1016 | else
|
---|
| 1017 | # print "cell=#{cell.get_name} domain_root=#{cell.get_region.get_domain_root.get_name}\n"
|
---|
| 1018 | end
|
---|
| 1019 | if call_join
|
---|
| 1020 | # print "validate_join: hanlder=#{handler.class.name} cell=#{cell.get_name} join=#{call_join.get_name} rhs_cell=#{call_join.get_cell}\n"
|
---|
| 1021 | else
|
---|
| 1022 | # print "validate_join: hanlder=#{handler.class.name} cell=#{cell.get_name}\n"
|
---|
| 1023 | end
|
---|
[337] | 1024 |
|
---|
| 1025 | # ハンドラタイプを判別する
|
---|
| 1026 | matches = HANDLER_TYPES.select { |handler_type|
|
---|
| 1027 | handler_type.validate_join(handler, cell, call_join)
|
---|
| 1028 | }
|
---|
| 1029 |
|
---|
| 1030 | if matches.length == 0
|
---|
[374] | 1031 | cdl_error2( cell.get_locale, "NTF1001 cell $1: no matching handler type found for $2", cell.get_name, handler.call_port_name )
|
---|
[337] | 1032 | next
|
---|
[374] | 1033 | end
|
---|
[337] | 1034 |
|
---|
| 1035 | # 最初に見つかった有効なハンドラタイプを使用
|
---|
| 1036 | ht = matches[0]
|
---|
| 1037 |
|
---|
[374] | 1038 | # ドメインプラグインが指定されている場合、所属ドメインのチェック
|
---|
| 1039 | domain_root = cell.get_region.get_domain_root
|
---|
| 1040 | if domain_root.get_domain_type then
|
---|
| 1041 | if domain_root.get_domain_type.get_name == :HRP then
|
---|
| 1042 | option = domain_root.get_domain_type.get_option
|
---|
| 1043 | matches.each{ |match|
|
---|
| 1044 | # p "match:#{match}"
|
---|
| 1045 | case match
|
---|
| 1046 | when ActivateTaskHandlerType, WakeUpTaskHandlerType,
|
---|
| 1047 | SetVariableHandlerType, SetVariableToErrorCodeHandlerType,
|
---|
| 1048 | IncrementVariableHandlerType, SignalSemaphoreHandlerType,
|
---|
| 1049 | SetEventflagHandlerType, SendToDataqueueHandlerType,
|
---|
| 1050 | SendErrorCodeToDataqueueHandlerType
|
---|
| 1051 | if option == "OutOfDomain" then
|
---|
| 1052 | cdl_error2( cell.get_locale, "NTF9999: NotifierPlugin: $1 cannot be placed out of domain", cell.get_name )
|
---|
| 1053 | elsif call_join.get_cell.get_region.get_domain_root == nil ||
|
---|
| 1054 | call_join.get_cell.get_region.get_domain_root != domain_root then
|
---|
| 1055 | cdl_error2( cell.get_locale, "NTF9999: NotifierPlugin: $1 and $2 must be placed in same domain", cell.get_name, call_join.get_cell.get_name )
|
---|
| 1056 | end
|
---|
| 1057 | dbgPrint "#{self.class.name}: match pattern 1.\n"
|
---|
| 1058 | when UserHandlerType
|
---|
| 1059 | if option != "kernel" then
|
---|
| 1060 | cdl_error2( cell.get_locale, "NTF9999: NotifierPlugin: $1 can be placed in kernel domain only, because notify target is handler", cell.get_name )
|
---|
| 1061 | elsif call_join.get_cell.get_region.get_domain_root == nil ||
|
---|
| 1062 | call_join.get_cell.get_region.get_domain_root != domain_root then
|
---|
| 1063 | cdl_error2( cell.get_locale, "NTF9999: NotifierPlugin: $1 and $2 must be placed in same domain", cell.get_name, call_join.get_cell.get_name )
|
---|
| 1064 | end
|
---|
| 1065 | dbgPrint "#{self.class.name}: match pattern 2.\n"
|
---|
| 1066 | when NullHandlerType.new # エラー通知を指定していない
|
---|
| 1067 | dbgPrint "#{self.class.name}: match pattern 3.\n"
|
---|
| 1068 | end
|
---|
| 1069 | }
|
---|
| 1070 |
|
---|
| 1071 | # if cell.get_region.get_param == :KERNEL_DOMAIN
|
---|
| 1072 | if option == "kernel"
|
---|
| 1073 | pre_text = "KERNEL_DOMAIN{\n"
|
---|
| 1074 | post_text = "}\n"
|
---|
| 1075 | indent = "\t"
|
---|
| 1076 | elsif option != "OutOfDomain" then
|
---|
| 1077 | pre_text = "DOMAIN(#{domain_root.get_name.to_s}){\n"
|
---|
| 1078 | post_text = "}\n"
|
---|
| 1079 | indent = "\t"
|
---|
| 1080 | end
|
---|
| 1081 | else
|
---|
| 1082 | cdl_error( "NTF9999: NotifierPlugin: unknown domain type $1", domain_root.get_domain_type.get_name )
|
---|
| 1083 | end
|
---|
| 1084 |
|
---|
| 1085 | end
|
---|
| 1086 |
|
---|
[337] | 1087 | # 通知ハンドラで「エラーが発生するはずがない」のに「エラーハンドラが指定されている」
|
---|
| 1088 | # もしくはその逆のパターンを検出する。
|
---|
| 1089 | # (handler_flagがnilである場合、ハンドラタイプが不明であり、エラーが発生するか不明
|
---|
| 1090 | # なため、検出は行わない。)
|
---|
| 1091 | if handler == ERROR_HANDLER && !ht.is_a?(NullHandlerType) && !event_handler_might_fail
|
---|
[374] | 1092 | cdl_error2( cell.get_locale, "NTF1004 cell $1: handler type $2 which never raises an error was inferred for the normal notification handler, but an error notification handler was specified.",
|
---|
[337] | 1093 | cell.get_name, handler_flag)
|
---|
| 1094 | end
|
---|
| 1095 | if handler == ERROR_HANDLER && ht.is_a?(NullHandlerType) && event_handler_might_fail && !ignoreErrors
|
---|
[374] | 1096 | cdl_warning2( cell.get_locale, "NTF1006 cell $1: handler type $2 which might raise an error was inferred for the normal notificaton handler, but an error notification handler was not specified.",
|
---|
[337] | 1097 | cell.get_name, handler_flag)
|
---|
| 1098 | end
|
---|
| 1099 |
|
---|
| 1100 | # assertion
|
---|
| 1101 | unless ht.validate_join(handler, cell, call_join)
|
---|
| 1102 | raise "!validate_join"
|
---|
| 1103 | end
|
---|
| 1104 |
|
---|
| 1105 | # 通知方法の静的API記述を生成する
|
---|
| 1106 | handler_flag = ht.gen_cfg_handler_type(handler)
|
---|
| 1107 | handler_flags << handler_flag if handler_flag
|
---|
| 1108 |
|
---|
| 1109 | attr_map = ht.generate_attr_map(handler, cell)
|
---|
| 1110 |
|
---|
| 1111 | handler_arg = ht.gen_cfg_handler_parameters(handler, call_join, attr_map, cell, @adpt_gen)
|
---|
| 1112 | handler_args += handler_arg if handler_arg
|
---|
| 1113 |
|
---|
| 1114 | if handler == EVENT_HANDLER
|
---|
| 1115 | event_handler_might_fail = ht.might_fail
|
---|
| 1116 | end
|
---|
| 1117 | }
|
---|
| 1118 |
|
---|
| 1119 | # $id$等の置換
|
---|
| 1120 | name_array = cell.get_celltype.get_name_array(cell)
|
---|
| 1121 | handler_args.collect! { |e|
|
---|
| 1122 | if e == "$cbp$"
|
---|
| 1123 | cell.get_celltype.subst_name(e, name_array)
|
---|
| 1124 | else
|
---|
| 1125 | e
|
---|
| 1126 | end
|
---|
| 1127 | }
|
---|
| 1128 |
|
---|
| 1129 | # tecsgen.cfgの記述を生成する。
|
---|
| 1130 | # factoryに対し、パラメータ置換を行う。
|
---|
| 1131 | # {{attribute_name}} -> attribute_value
|
---|
| 1132 | text = @factory.gsub(/\{\{([a-zA-Z0-9_]*?)\}\}/) { |match|
|
---|
| 1133 | name = $1.to_sym
|
---|
| 1134 | subst_attr = cell.get_celltype.find(name)
|
---|
| 1135 |
|
---|
| 1136 | # {{_handler_params_}} はハンドラの指定に置換する。
|
---|
| 1137 | if name == :_handler_params_
|
---|
| 1138 | args_joined = handler_flags.join(' | ')
|
---|
| 1139 | if handler_args.length > 0
|
---|
| 1140 | args_joined << ", "
|
---|
| 1141 | args_joined << handler_args.join(', ')
|
---|
| 1142 | end
|
---|
| 1143 | next args_joined
|
---|
| 1144 | end
|
---|
| 1145 |
|
---|
| 1146 | unless subst_attr
|
---|
| 1147 | # 属性が見つからないというエラーはすでに報告されているので
|
---|
| 1148 | # ここではダミー値を返しておくだけである。
|
---|
| 1149 | next ""
|
---|
| 1150 | end
|
---|
| 1151 |
|
---|
| 1152 | subst_attr_join = cell.get_join_list.get_item(name)
|
---|
| 1153 | if subst_attr_join
|
---|
| 1154 | # セル生成時に初期化する場合
|
---|
| 1155 | subst = subst_attr_join.get_rhs.to_s
|
---|
| 1156 | else
|
---|
| 1157 | # セルタイプの初期化値を使う場合
|
---|
| 1158 | subst = subst_attr.get_initializer.to_s
|
---|
| 1159 | end
|
---|
| 1160 |
|
---|
| 1161 | # $id$等の置換
|
---|
| 1162 | cell.get_celltype.subst_name(subst, name_array)
|
---|
[374] | 1163 | }
|
---|
[337] | 1164 |
|
---|
[374] | 1165 | # 出力 (CRE_xxx)
|
---|
| 1166 | kernelCfg.print pre_text
|
---|
| 1167 | kernelCfg.print indent, text, "\n"
|
---|
| 1168 | gen_sac kernelCfg, cell, indent
|
---|
| 1169 | kernelCfg.print post_text
|
---|
| 1170 | end
|
---|
[337] | 1171 |
|
---|
[374] | 1172 | def gen_sac file, cell, indent
|
---|
| 1173 | domain_root = cell.get_region.get_domain_root
|
---|
| 1174 | if domain_root.get_domain_type then
|
---|
| 1175 | id = (cell.get_attr_initializer :id).to_s
|
---|
| 1176 | name_array = cell.get_celltype.get_name_array(cell)
|
---|
| 1177 | case cell.get_celltype.get_name
|
---|
| 1178 | when :tCyclicNotifier
|
---|
| 1179 | obj_type = "CYC"
|
---|
| 1180 | when :tAlarmNotifier
|
---|
| 1181 | obj_type = "ALM"
|
---|
| 1182 | else
|
---|
| 1183 | raise "NotifierPlugin: unknown celltype #{cell.get_celltype.get_name}"
|
---|
| 1184 | end
|
---|
| 1185 | id = cell.get_celltype.subst_name(id, name_array)
|
---|
| 1186 | # p obj_type
|
---|
| 1187 | # p HRPPlugin.get_sac_str cell
|
---|
| 1188 | file.print indent, "SAC_#{obj_type}( #{id}, #{HRPPlugin.get_sac_str cell} );\n"
|
---|
| 1189 | end
|
---|
| 1190 | end
|
---|
| 1191 | private :gen_factory_for_cell
|
---|
[337] | 1192 |
|
---|
| 1193 | end
|
---|