Class: C2TECSBridgePlugin

Inherits:
SignaturePlugin show all
Defined in:
lib/tecsgen/plugin/C2TECSBridgePlugin.rb

Overview

C => TECS 受け口呼び出しのプラグイン

Constant Summary collapse

C2TECSBridgePluginArgProc =

プラグイン引数名と Proc

{
  "prefix" => Proc.new {|obj, rhs| obj.set_prefix rhs },
  "suffix" => Proc.new {|obj, rhs| obj.set_suffix rhs },
  "header_name" => Proc.new {|obj, rhs| obj.set_header_name rhs },
}
@@signature_list =
{ }

Constants inherited from Plugin

Plugin::PluginArgProc

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Plugin

#cdl_error, #check_plugin_arg, #gen_ep_func?, #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(signature, option) ⇒ C2TECSBridgePlugin

signature

Signature シグニチャ(インスタンス)



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/tecsgen/plugin/C2TECSBridgePlugin.rb', line 55

def initialize(signature, option)
  super

  @signature = signature
  @header_name = "#{$gen}/C2TECS_#{@signature.get_global_name}.h"
  @prefix = ""
  @suffix = ""
  @celltype_name = :"t#{@signature.get_global_name}"
  @plugin_arg_check_proc_tab = C2TECSBridgePluginArgProc
  parse_plugin_arg
end

Class Method Details

.gen_post_code(file) ⇒ Object

後ろのコードを生成

プラグインの後ろのコードを生成

file

File:



89
90
91
92
# File 'lib/tecsgen/plugin/C2TECSBridgePlugin.rb', line 89

def self.gen_post_code(file)
  # 複数のプラグインの post_code が一つのファイルに含まれるため、以下のような見出しをつけること
  # file.print "/* '#{self.class.name}' post code */\n"
end

Instance Method Details

#gen_cdl_file(file) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/tecsgen/plugin/C2TECSBridgePlugin.rb', line 67

def gen_cdl_file(file)
  if @@signature_list[@signature.get_global_name]
    @@signature_list[@signature.get_global_name] << self
    cdl_warning("C2TW001 signature '$1' duplicate. ignored current one", @signature.get_namespace_path)
    return
  end

  @@signature_list[@signature.get_global_name] = [self]
  print_msg "  C2TECSBridgePlugin: [celltype] C2TECS::#{@celltype_name}. Create cell then join the call port 'cCall' to the target cell\n"
  file.print <<EOT
namespace nC2TECS{
[singleton, active]    // this celltype is not active actually. 'active' is specified to prevent W1002.
celltype #{@celltype_name} {
  call #{@signature.get_namespace_path} cCall;
};
};
EOT
end

#gen_ep_func_body(file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params) ⇒ Object

受け口関数の本体(C言語)を生成する

通常であれば、ジェネレータは受け口関数のテンプレートを生成する
プラグインの場合、変更する必要のないセルタイプコードを生成する
file

FILE 出力先ファイル

b_singleton

bool true if singleton

ct_name

Symbol

global_ct_name

string

sig_name

string

ep_name

string

func_name

string

func_global_name

string

func_type

class derived from Type



106
107
108
# File 'lib/tecsgen/plugin/C2TECSBridgePlugin.rb', line 106

def gen_ep_func_body(file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params)
  # nothing to do
end

#gen_postamble(file, b_singleton, ct_name, global_name) ⇒ Object



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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
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
# File 'lib/tecsgen/plugin/C2TECSBridgePlugin.rb', line 110

def gen_postamble(file, b_singleton, ct_name, global_name)
  header_file = open(@header_name, "w")

  header_comment = <<EOT
/*
 * This file was generated by C2TECSBridgePlugin and has prototype
 * decalarations of functions in signature '#{@signature.get_namespace_path}'
 */

EOT

  file.print header_comment
  header_file.print header_comment
  header_file.print <<EOT
#ifndef #{@signature.get_global_name}__h
#define #{@signature.get_global_name}__h

/*
 * function prototype declarations
 *    signature: '#{@signature.get_namespace_path}'
 *
 * These functions can be called from C sources directly.
 * If function name collides, please consider to specify 'prefix' option for C2TECSBridgePlugin.
 */
EOT

  # generate C functions calling function of call port
  @signature.get_function_head_array.each {|func_head|
    func_name = func_head.get_name
    ret_type  = func_head.get_return_type
    params    = func_head.get_paramlist.get_items

    # p "celltype_name, sig_name, func_name, func_global_name"
    # p "#{ct_name}, #{sig_name}, #{func_name}, #{func_global_name}"

    # function header
    file.print("#{ret_type.get_type_str}\n")
    header_file.printf("%-16s", ret_type.get_type_str)
    file.print("#{@prefix}#{func_name}#{@suffix}(")
    header_file.print("#{@prefix}#{func_name}#{@suffix}(")

    delim = ""
    params.each{|param|
      file.printf("#{delim} #{param.get_type.get_type_str} #{param.get_name}#{param.get_type.get_type_str_post}")
      header_file.printf("#{delim} #{param.get_type.get_type_str} #{param.get_name}#{param.get_type.get_type_str_post}")
      delim = ","
    }
    file.print(" )\n{\n")
    header_file.print(" );\n")

    # call function in call port
    if !ret_type.is_void?
      file.print("  #{ret_type.get_type_str}  retval;\n")
      file.print("  retval = ")
    else
      file.print("  ")
    end

    file.print("cCall_#{func_name}(")

    delim = ""
    params.each{|param|
      file.printf("#{delim} #{param.get_name}")
      delim = ","
    }
    file.print(" );\n")

    if !ret_type.is_void?
      file.print("  return retval;\n")
    end
    file.print("}\n\n")
  }

  header_file.print <<EOT

#endif /* #{@signature.get_global_name}__h */

EOT

  header_file.close
end

#set_header_name(rhs) ⇒ Object

set_header_name - header_name プラグインオプション



203
204
205
206
207
208
# File 'lib/tecsgen/plugin/C2TECSBridgePlugin.rb', line 203

def set_header_name(rhs)
  @header_name = "#{$gen}/" + rhs.to_s
  if !(@header_name =~ /\.h\Z/)
    @header_name += ".h"
  end
end

#set_prefix(rhs) ⇒ Object

set_prefix - prefix プラグインオプション



193
194
195
# File 'lib/tecsgen/plugin/C2TECSBridgePlugin.rb', line 193

def set_prefix(rhs)
  @prefix = rhs.to_s
end

#set_suffix(rhs) ⇒ Object

set_suffix - suffix プラグインオプション



198
199
200
# File 'lib/tecsgen/plugin/C2TECSBridgePlugin.rb', line 198

def set_suffix(rhs)
  @suffix = rhs.to_s
end