[388] | 1 | # -*- coding: utf-8 -*-
|
---|
| 2 | #
|
---|
| 3 | # mruby => TECS bridge
|
---|
| 4 | #
|
---|
| 5 | # Copyright (C) 2008-2017 by TOPPERS Project
|
---|
| 6 | #
|
---|
| 7 | # ä¸è¨èä½æ¨©è
|
---|
| 8 | ã¯ï¼ä»¥ä¸ã®(1)ï½(4)ã®æ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§
|
---|
| 9 | # ã¢ï¼æ¬ã½ããã¦ã§ã¢ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹
|
---|
| 10 | # å¤ã»åé
|
---|
| 11 | å¸ï¼ä»¥ä¸ï¼å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
| 12 | # (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
| 13 | # 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
| 14 | # ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
| 15 | # (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 16 | # ç¨ã§ããå½¢ã§åé
|
---|
| 17 | å¸ããå ´åã«ã¯ï¼åé
|
---|
| 18 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
| 19 | # è
|
---|
| 20 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
| 21 | # ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 22 | # (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 23 | # ç¨ã§ããªãå½¢ã§åé
|
---|
| 24 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
| 25 | # ã¨ï¼
|
---|
| 26 | # (a) åé
|
---|
| 27 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
| 28 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
| 29 | # ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 30 | # (b) åé
|
---|
| 31 | å¸ã®å½¢æ
|
---|
| 32 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
| 33 | # å ±åãããã¨ï¼
|
---|
| 34 | # (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
| 35 | # 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
| 36 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
| 37 | 責ãããã¨ï¼
|
---|
| 38 | # ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®ã¦ã¼ã¶ã¾ãã¯ã¨ã³ãã¦ã¼ã¶ããã®ãããªãç
|
---|
| 39 | # ç±ã«åºã¥ãè«æ±ãããï¼ä¸è¨èä½æ¨©è
|
---|
| 40 | ããã³TOPPERSããã¸ã§ã¯ãã
|
---|
| 41 | # å
|
---|
| 42 | 責ãããã¨ï¼
|
---|
| 43 | #
|
---|
| 44 | # æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
| 45 | ã
|
---|
| 46 | # ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ç¹å®ã®ä½¿ç¨ç®ç
|
---|
| 47 | # ã«å¯¾ããé©åæ§ãå«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§
|
---|
| 48 | # ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ã
|
---|
| 49 | # ã®è²¬ä»»ãè² ããªãï¼
|
---|
| 50 | #
|
---|
| 51 | # $Id$
|
---|
| 52 | #
|
---|
| 53 |
|
---|
| 54 | # Todo:
|
---|
| 55 | # çæãããã®
|
---|
| 56 | # gen_cdl_file
|
---|
| 57 | # ããªãã¸åæåã»ã«ã¿ã¤ã (ã·ã°ããã£ãã¨)
|
---|
| 58 | # @@init_celltypes ã«è¨é²
|
---|
| 59 | # ããªãã¸ã»ã«ã¿ã¤ã (ã·ã°ããã£ãã¨)
|
---|
| 60 | # @@celltypes ã«è¨é²
|
---|
| 61 | # æ§é ä½ã»ã«ã¿ã¤ã
|
---|
| 62 | # @@struct_list ã«è¨é²
|
---|
| 63 | # new_cell
|
---|
| 64 | # TECS åæåã»ã«(ãããã¿ã¤ã宣è¨)
|
---|
| 65 | # @@VM_init_cells ã«è¨é²
|
---|
| 66 | # @@VM_struct_list ã«è¨é²
|
---|
| 67 | # @@VM_ptr_list ã«è¨é²
|
---|
| 68 | # gen_post_code
|
---|
| 69 | # æ§é ä½åæåã»ã«
|
---|
| 70 | # ãã¤ã³ã¿åæåã»ã«
|
---|
| 71 | # TECS åæåã»ã«
|
---|
| 72 | #
|
---|
| 73 | # ep_func ã®ä½æ
|
---|
| 74 | # signature, ãã¤ã³ã¿ãæ§é ä½ â¦ åæååãå£ï¼mruby VM ã¸ã®ç»é²
|
---|
| 75 | # ãã¤ã³ã¿
|
---|
| 76 | # preamble ã®ä½æ
|
---|
| 77 | # ãã¤ã³ã¿ãæ§é ä½ â¦ ã¢ã¯ã»ã¹ç¨ã³ã¼ãã®çæ
|
---|
| 78 | # signature ⦠ããªãã¸é¢æ°ã®ãããã¿ã¤ã宣è¨
|
---|
| 79 | # postamble ã®ä½æ
|
---|
| 80 | # signature ⦠ããªãã¸é¢æ°ã®å®ç¾©
|
---|
| 81 |
|
---|
| 82 | class MrubyBridgeSignaturePlugin < SignaturePlugin
|
---|
| 83 |
|
---|
| 84 | # ãã©ã°ã¤ã³å¼æ°å => Proc
|
---|
| 85 | MrubyBridgePluginArgProc = {
|
---|
| 86 | "ignoreUnsigned" => Proc.new { |obj,rhs| obj.set_ignoreUnsigned rhs },
|
---|
| 87 | "include" => Proc.new { |obj,rhs| obj.set_include rhs },
|
---|
| 88 | "exclude" => Proc.new { |obj,rhs| obj.set_exclude rhs },
|
---|
| 89 | "auto_exclude" => Proc.new { |obj,rhs| obj.set_auto_exclude rhs },
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | @@b_no_banner = false #
|
---|
| 93 | @@b_gen_post_code_by_dependent = false # true if gen_post_code is called by MrubyBridgeCellPlugin
|
---|
| 94 | @@celltypes = { } # {celltype_name => [ BridgePlugin ã®ã¤ã³ã¹ã¿ã³ã¹ã®é
|
---|
| 95 | å }
|
---|
| 96 | @@init_celltypes = { } # {celltype_name => [ BridgePlugin ã®ã¤ã³ã¹ã¿ã³ã¹ã®é
|
---|
| 97 | å }
|
---|
| 98 | @@struct_list = { } # {struct_name=>StructType}
|
---|
| 99 | @@ptr_list = { } # {ptr_celltype_name=> @@TYPE_MAP ã®å¯¾å¿ãããã®}
|
---|
| 100 | @@VM_list = { } # VM_name => true
|
---|
| 101 | @@VM_celltypes = { } # VM_name => { @celltype_name => ã»ã«ã®é
|
---|
| 102 | å }
|
---|
| 103 | @@VM_struct_list = { } # {name=>StructType}
|
---|
| 104 | @@VM_ptr_list = { } # { VM_name => {name=> @@TYPE_MAP ã®å¯¾å¿ãããã®} }
|
---|
| 105 | @@TYPE_MAP = { # type_str class GET_SET
|
---|
| 106 | :char_t => [:char_t, "Char", :Char, :INT ],
|
---|
| 107 | :uchar_t => [:uchar_t, "UChar", :Char, :INT ],
|
---|
| 108 | :schar_t => [:schar_t, "SChar", :Char, :INT ],
|
---|
| 109 |
|
---|
| 110 | :bool_t => [:bool_t, "Bool", :Bool, :BOOL ],
|
---|
| 111 | :int8_t => [:int8_t, "Int8", :Int, :INT ],
|
---|
| 112 | :int16_t => [:int16_t, "Int16", :Int, :INT ],
|
---|
| 113 | :int32_t => [:int32_t, "Int32", :Int, :INT ],
|
---|
| 114 | :int64_t => [:int64_t, "Int64", :Int, :INT ],
|
---|
| 115 | :uint8_t => [:uint8_t, "UInt8", :Int, :INT ],
|
---|
| 116 | :uint16_t => [:uint16_t, "UInt16", :Int, :INT ],
|
---|
| 117 | :uint32_t => [:uint32_t, "UInt32", :Int, :INT ],
|
---|
| 118 | :uint64_t => [:uint64_t, "UInt64", :Int, :INT ],
|
---|
| 119 |
|
---|
| 120 | :int => [:int, "Int", :Int, :INT ],
|
---|
| 121 | :char => [:char, "Char", :Char, :INT ], # char 㯠char_t ã¨ãã¦æ±ã
|
---|
| 122 | :short => [:short, "Short", :Int, :INT ],
|
---|
| 123 | :long => [:long, "Long", :Int, :INT ],
|
---|
| 124 |
|
---|
| 125 | :"unsigned char" => [:uchar_t, "UChar", :Char, :INT ],
|
---|
| 126 | :"unsigned int" => [:"unsigned int", "UInt", :Int, :INT ],
|
---|
| 127 | :"unsigned short" => [:"unsigned short", "UShort", :Int, :INT ],
|
---|
| 128 | :"unsigned long" => [:"unsigned long", "ULong", :Int, :INT ],
|
---|
| 129 | :"signed char" => [:schar_t, "SChar", :Char, :INT ],
|
---|
| 130 | :"signed int" => [:int, "Int", :Int, :INT ],
|
---|
| 131 | :"signed short" => [:short, "Short", :Int, :INT ],
|
---|
| 132 | :"signed long" => [:long, "Long", :Int, :INT ],
|
---|
| 133 |
|
---|
| 134 | :float32_t => [:float32_t, "Float32", :Float, :FLOAT ],
|
---|
| 135 | :double64_t => [:double64_t,"Double64", :Float, :FLOAT ],
|
---|
| 136 |
|
---|
| 137 | :float => [:float, "Float32", :Float, :FLOAT ],
|
---|
| 138 | :double => [:double, "Double64", :Float, :FLOAT ]
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | # included or excluded functions
|
---|
| 142 |
|
---|
| 143 | ### ãã¼ããããæç¹ã§å®è¡ããã ###
|
---|
| 144 |
|
---|
| 145 | # -I ã« $(TECSPATH)/mruby ã追å
|
---|
| 146 | # TECSGEN::Makefile.add_obj "$(MRUBY_MAIN_OBJ)"
|
---|
| 147 | TECSGEN::Makefile.add_ldflag "-lmruby -L$(MRUBYPATH)/lib -lm"
|
---|
| 148 | TECSGEN::Makefile.add_search_path "$(MRUBYPATH)/include"
|
---|
| 149 | TECSGEN::Makefile.add_var "MRUBYPATH", "..", "CHANGE this to suitable path"
|
---|
| 150 | # TECSGEN::Makefile.add_var "MRUBY_MAIN_OBJ", "$(_TECS_OBJ_DIR)tecs_mruby.o", "CHANGE this if your have your main"
|
---|
| 151 |
|
---|
| 152 | #=== ãã©ã°ã¤ã³ã¤ã³ã¹ã¿ã³ã¹ã®åæå
|
---|
| 153 | # æ»ãå¤ãå¼æ°ã®åã使ç¨å¯è½ãªãã®ããã§ãã¯ãã
|
---|
| 154 | #
|
---|
| 155 | def initialize( signature, option )
|
---|
| 156 | super
|
---|
| 157 |
|
---|
| 158 | if ! @@b_no_banner
|
---|
| 159 | STDERR << "MrubyBridgePlugin: version 1.3.0 (Suitable for mruby ver 1.3.0 & ver 1.2.0). \n"
|
---|
| 160 | @@b_no_banner = true
|
---|
| 161 | end
|
---|
| 162 |
|
---|
| 163 | @b_ignoreUnsigned = false
|
---|
| 164 | @includes = []
|
---|
| 165 | @excludes = []
|
---|
| 166 | @struct_list = { }
|
---|
| 167 | @ptr_list = { }
|
---|
| 168 | @auto_exclude_list = {}
|
---|
| 169 | @b_auto_exclude = true # auto_exclude = true by default
|
---|
| 170 |
|
---|
| 171 | @plugin_arg_check_proc_tab = MrubyBridgePluginArgProc
|
---|
| 172 | parse_plugin_arg
|
---|
| 173 |
|
---|
| 174 | @celltype_name = :"t#{@signature.get_global_name}"
|
---|
| 175 | @init_celltype_name = :"#{@celltype_name}_Initializer"
|
---|
| 176 | # this variable is sometimes not used. rhs coded directry.
|
---|
| 177 | @class_name = :"T#{@signature.get_global_name}"
|
---|
| 178 |
|
---|
| 179 | @func_head_array = []
|
---|
| 180 | fh_array = []
|
---|
| 181 | if @includes.length > 0 && @excludes.length > 0 then
|
---|
| 182 | cdl_error( "MRB1011 both include && exclude are specified" )
|
---|
| 183 | end
|
---|
| 184 |
|
---|
| 185 | if signature.get_function_head_array == nil then
|
---|
| 186 | return # 以åã«ææ³ã¨ã©ã¼çºç
|
---|
| 187 | end
|
---|
| 188 |
|
---|
| 189 | signature.get_function_head_array.each{ |func_head|
|
---|
| 190 | if @includes.length > 0 then
|
---|
| 191 | if @includes.index func_head.get_name then
|
---|
| 192 | dbgPrint "MrubyBridgePlugin: #{func_head.get_name} INCLUDED\n"
|
---|
| 193 | fh_array << func_head
|
---|
| 194 | else
|
---|
| 195 | dbgPrint "MrubyBridgePlugin: #{func_head.get_name} NOT included\n"
|
---|
| 196 | end
|
---|
| 197 | elsif @excludes.length > 0 then
|
---|
| 198 | if @excludes.index( func_head.get_name ) == nil then
|
---|
| 199 | dbgPrint "MrubyBridgePlugin: #{func_head.get_name} NOT excluded\n"
|
---|
| 200 | fh_array << func_head
|
---|
| 201 | else
|
---|
| 202 | dbgPrint "MrubyBridgePlugin: #{func_head.get_name} EXCLUDED\n"
|
---|
| 203 | end
|
---|
| 204 | else
|
---|
| 205 | fh_array << func_head
|
---|
| 206 | end
|
---|
| 207 | }
|
---|
| 208 |
|
---|
| 209 | check_name_and_return_type fh_array
|
---|
| 210 | check_parameter_type fh_array
|
---|
| 211 |
|
---|
| 212 | fh_array.each{ |fh|
|
---|
| 213 | if @auto_exclude_list[ fh.get_name ] == nil then
|
---|
| 214 | @func_head_array << fh
|
---|
| 215 | else
|
---|
| 216 | dbgPrint "MrubyBridgePlugin: auto_exclude #{fh.get_name}\n"
|
---|
| 217 | end
|
---|
| 218 | }
|
---|
| 219 |
|
---|
| 220 | if @func_head_array.length == 0 then
|
---|
| 221 | cdl_error( "MRB1012 '$1' no function remained by exclude", @signature.get_name )
|
---|
| 222 | end
|
---|
| 223 | end
|
---|
| 224 |
|
---|
| 225 | #=== check function name & return type
|
---|
| 226 | def check_name_and_return_type func_head_array
|
---|
| 227 | b_init = false; b_init_cell = false
|
---|
| 228 | func_head_array.each{ |func_head|
|
---|
| 229 | if( func_head.get_name == :initialize )then
|
---|
| 230 | cdl_warning( "MRW2001 initialize: internally defined. change to initialize_cell in ruby" )
|
---|
| 231 | b_init = true
|
---|
| 232 | elsif( func_head.get_name == :initialize_cell )then
|
---|
| 233 | b_init_cell = true
|
---|
| 234 | end
|
---|
| 235 | rtype = func_head.get_return_type.get_original_type
|
---|
| 236 | case rtype
|
---|
| 237 | when BoolType, IntType, FloatType, VoidType
|
---|
| 238 | else
|
---|
| 239 | if @b_auto_exclude then
|
---|
| 240 | cdl_info( "MRI0001 cannot return type $1, $2 automatcally excluded", rtype.get_type_str, func_head.get_name )
|
---|
| 241 | @auto_exclude_list[ func_head.get_name ] = func_head
|
---|
| 242 | else
|
---|
| 243 | cdl_error( "MRB1001 cannot return type $1", rtype.get_type_str )
|
---|
| 244 | end
|
---|
| 245 | end
|
---|
| 246 | }
|
---|
| 247 | if( b_init && b_init_cell )then
|
---|
| 248 | cdl_warning( "MRB1002 initialize: internally defined. change to initialize_cell in ruby" )
|
---|
| 249 | end
|
---|
| 250 | end
|
---|
| 251 |
|
---|
| 252 | #=== check paramter type
|
---|
| 253 | def check_parameter_type func_head_array
|
---|
| 254 | # check type of parameters
|
---|
| 255 | func_head_array.each{ |fh|
|
---|
| 256 | fh.get_paramlist.get_items.each{ |param_decl|
|
---|
| 257 | case param_decl.get_direction
|
---|
| 258 | when :SEND, :RECEIVE
|
---|
| 259 | if @b_auto_exclude then
|
---|
| 260 | cdl_info( "MRI0002 $1: $2 parameter cannot be used in mruby Bridge, $3 automatcally excluded",
|
---|
| 261 | param_decl.get_name, param_decl.get_direction.to_s.downcase, fh.get_name )
|
---|
| 262 | @auto_exclude_list[ fh.get_name ] = fh
|
---|
| 263 | else
|
---|
| 264 | cdl_error( "MRB1003 $1: $2 parameter cannot be used in mruby Bridge", param_decl.get_name, param_decl.get_direction.to_s.downcase )
|
---|
| 265 | end
|
---|
| 266 | end
|
---|
| 267 | type = param_decl.get_type
|
---|
| 268 | type_org = type.get_original_type
|
---|
| 269 | type_str = type.get_type_str + type.get_type_str_post
|
---|
| 270 |
|
---|
| 271 | b_ng = false
|
---|
| 272 | case type_org
|
---|
| 273 | when IntType
|
---|
| 274 | case type_org.get_bit_size
|
---|
| 275 | when 8, 16, 32, 64
|
---|
| 276 | when -1, -2, -3, -4, -11
|
---|
| 277 | else
|
---|
| 278 | b_ng = true
|
---|
| 279 | end
|
---|
| 280 | when BoolType
|
---|
| 281 | when FloatType
|
---|
| 282 | when PtrType
|
---|
| 283 | ttype_org = type_org.get_type # ãã¤ã³ã¿ã®æãã¦ããå
|
---|
| 284 | ã®å
|
---|
| 285 | ttype = ttype_org.get_original_type # ä¸è¨ã® typedef ããã¦ããå ´åãå
|
---|
| 286 | ã®å
|
---|
| 287 | register_ptr_type ttype_org, fh
|
---|
| 288 |
|
---|
| 289 | if( type_org.get_string.to_s == "-1" ) then
|
---|
| 290 | case param_decl.get_direction
|
---|
| 291 | when :OUT, :INOUT
|
---|
| 292 | if @b_auto_exclude then
|
---|
| 293 | cdl_info( "MRB9999 string specifier without length cannot be used for out & inout parameter, $1 automatcally excluded",
|
---|
| 294 | fh.get_name )
|
---|
| 295 | @auto_exclude_list[ fh.get_name ] = fh
|
---|
| 296 | else
|
---|
| 297 | cdl_error( "MRB9999 string specifier without length cannot be used for out & inout parameter")
|
---|
| 298 | end
|
---|
| 299 | end
|
---|
| 300 | end
|
---|
| 301 |
|
---|
| 302 | case ttype
|
---|
| 303 | when IntType
|
---|
| 304 | bit_size = ttype.get_bit_size
|
---|
| 305 | # if bit_size < 0 && bit_size != -1 then
|
---|
| 306 | # b_ng = true
|
---|
| 307 | # end
|
---|
| 308 | when FloatType
|
---|
| 309 | when BoolType
|
---|
| 310 | when StructType
|
---|
| 311 | if( type_org.get_size || type_org.get_string || type_org.get_count ) then
|
---|
| 312 | if @b_auto_exclude then
|
---|
| 313 | cdl_info( "MRI9999 $1: size_is, count_is, string cannot be specified for struct pointer, $2 automatcally excluded",
|
---|
| 314 | param_decl.get_name, fh.get_name )
|
---|
| 315 | @auto_exclude_list[ fh.get_name ] = fh
|
---|
| 316 | else
|
---|
| 317 | cdl_error( "MRB1004 $1: size_is, count_is, string cannot be specified for struct pointer", param_decl.get_name )
|
---|
| 318 | end
|
---|
| 319 | end
|
---|
| 320 | check_struct_member ttype_org, fh
|
---|
| 321 | else
|
---|
| 322 | b_ng = true
|
---|
| 323 | end
|
---|
| 324 | when StructType
|
---|
| 325 | check_struct_member type_org, fh
|
---|
| 326 | else # ArrayType, FuncType, EnumType, VoidType
|
---|
| 327 | b_ng = true
|
---|
| 328 | end
|
---|
| 329 | if b_ng then
|
---|
| 330 | if @b_auto_exclude then
|
---|
| 331 | cdl_info( "MRI9999 $1: type $2 cannot be used in mruby Bridge, $3 automatcally excluded",
|
---|
| 332 | param_decl.get_name, type_str, fh.get_name )
|
---|
| 333 | @auto_exclude_list[ fh.get_name ] = fh
|
---|
| 334 | else
|
---|
| 335 | cdl_error( "MRB1005 $1: type $2 cannot be used in mruby Bridge", param_decl.get_name, type_str )
|
---|
| 336 | end
|
---|
| 337 | end
|
---|
| 338 | }
|
---|
| 339 | }
|
---|
| 340 | end
|
---|
| 341 |
|
---|
| 342 | #=== æ§é ä½ã®ã¡ã³ãã¼ã®åã®ãã§ãã¯
|
---|
| 343 | def check_struct_member struct_type, fh
|
---|
| 344 | #p "tag name:#{struct_type.get_name}"
|
---|
| 345 | # sttype = Namespace.find_tag( struct_type.get_name )
|
---|
| 346 | sttype = struct_type.get_original_type
|
---|
| 347 | if sttype.get_name == nil then
|
---|
| 348 | if @b_auto_exclude then
|
---|
| 349 | cdl_info( "MRI9999 tagless-struct cannot be handled, $1 automatcally excluded", fh.get_name )
|
---|
| 350 | @auto_exclude_list[ fh.get_name ] = fh
|
---|
| 351 | return # ç»é²ããªãããã«æã¡åã
|
---|
| 352 | else
|
---|
| 353 | cdl_error( "MRB10007 tagless-struct cannot be handled")
|
---|
| 354 | end
|
---|
| 355 | end
|
---|
| 356 | sttype.get_members_decl.get_items.each { |d|
|
---|
| 357 | t = d.get_type.get_original_type
|
---|
| 358 | case t
|
---|
| 359 | when IntType, FloatType, BoolType
|
---|
| 360 | else
|
---|
| 361 | if @b_auto_exclude then
|
---|
| 362 | cdl_info( "MRI9999 $1: type $2 not allowed for struct member, $3 automatcally excluded",
|
---|
| 363 | d.get_name, d.get_type.get_type_str + d.get_type.get_type_str_post, fh.get_name )
|
---|
| 364 | @auto_exclude_list[ fh.get_name ] = fh
|
---|
| 365 | return # ç»é²ããªãããã«æã¡åã
|
---|
| 366 | else
|
---|
| 367 | cdl_error( "MRB1006 $1: type $2 not allowed for struct member", d.get_name, d.get_type.get_type_str + d.get_type.get_type_str_post )
|
---|
| 368 | end
|
---|
| 369 | end
|
---|
| 370 | }
|
---|
| 371 | st_name = :"t{}"
|
---|
| 372 | if @struct_list[ sttype.get_name ] == nil then
|
---|
| 373 | # print_msg " MrubyBridgePlugin: [struct] #{struct_type.get_type_str} => class TECS::Struct#{sttype.get_name}\n"
|
---|
| 374 | print " MrubyBridgePlugin: [struct] #{struct_type.get_type_str} => class TECS::Struct#{sttype.get_name}\n"
|
---|
| 375 | @struct_list[ sttype.get_name ] = sttype
|
---|
| 376 | end
|
---|
| 377 | end
|
---|
| 378 |
|
---|
| 379 | def register_ptr_type ttype, fh
|
---|
| 380 | t_org = ttype.get_original_type
|
---|
| 381 | tment = get_type_map_ent t_org
|
---|
| 382 | if tment == nil then
|
---|
| 383 | return
|
---|
| 384 | # cdl_error( "MRB1008 unknown pointer type '$1'", ttype.get_type_str )
|
---|
| 385 | end
|
---|
| 386 | ptr_celltype_name = :"t#{tment[1]}Pointer"
|
---|
| 387 | if @@ptr_list[ ptr_celltype_name ] == nil then
|
---|
| 388 | # print_msg " MrubyBridgePlugin: [pointer] #{ttype.get_type_str}* => class TECS::#{tment[1]}Pointer\n"
|
---|
| 389 | print " MrubyBridgePlugin: [pointer] #{ttype.get_type_str}* => class TECS::#{tment[1]}Pointer\n"
|
---|
| 390 | @@ptr_list[ ptr_celltype_name ] = tment
|
---|
| 391 | end
|
---|
| 392 | if @ptr_list[ ptr_celltype_name ] == nil then
|
---|
| 393 | @ptr_list[ ptr_celltype_name ] = tment
|
---|
| 394 | end
|
---|
| 395 | end
|
---|
| 396 |
|
---|
| 397 | def get_type_map_ent ttype
|
---|
| 398 | # structure type is registerd in check_struct_member
|
---|
| 399 | if ttype.kind_of? StructType
|
---|
| 400 | return
|
---|
| 401 | end
|
---|
| 402 | tstr = ttype.get_type_str.sub( /const /, "" ) # const ã¯ç¡è¦
|
---|
| 403 | tstr = tstr.sub( /volatile /, "" ) # volatile ãç¡è¦
|
---|
| 404 | if @b_ignoreUnsigned then
|
---|
| 405 | tstr = tstr.sub( /unsigned /, "" ) # volatile ãç¡è¦
|
---|
| 406 | tstr = tstr.sub( /uint/, "int" ) # volatile ãç¡è¦
|
---|
| 407 | tstr = tstr.sub( /[cs]char/, "char" ) # volatile ãç¡è¦
|
---|
| 408 | end
|
---|
| 409 | return @@TYPE_MAP[ tstr.to_sym ]
|
---|
| 410 | end
|
---|
| 411 |
|
---|
| 412 | #=== CDL ãã¡ã¤ã«ã®çæ
|
---|
| 413 | # typedef, signature, celltype, cell ã³ã¼ããçæ
|
---|
| 414 | #file:: FILE çæãããã¡ã¤ã«
|
---|
| 415 | def gen_cdl_file(file)
|
---|
| 416 |
|
---|
| 417 | # ããªãã¸ã»ã«ã¿ã¤ãã®çæ
|
---|
| 418 | if @@celltypes[ @celltype_name ] == nil then
|
---|
| 419 | @@celltypes[ @celltype_name ] = [ self ]
|
---|
| 420 | @@init_celltypes[ @init_celltype_name ] = true
|
---|
| 421 | print_msg <<EOT
|
---|
| 422 | MrubyBridgePlugin: [signature] #{@signature.get_namespace_path} => [celltype] nMruby::#{@celltype_name} => [class] TECS::#{@class_name}
|
---|
| 423 | EOT
|
---|
| 424 |
|
---|
| 425 | file.print <<EOT
|
---|
| 426 | /*
|
---|
| 427 | * MrubyBridgeSignaturePlugin:
|
---|
| 428 | * signature=#{@signature.get_namespace_path}
|
---|
| 429 | *
|
---|
| 430 | * => celltype=nMruby::#{@celltype_name}
|
---|
| 431 | * (bridge cell's celltype; generated in this file)
|
---|
| 432 | * cell nMruby::#{@celltype_name} BridgeCellName { cTECS = CellName.eEntry; };
|
---|
| 433 | * where eEntry's signature must be #{@signature.get_namespace_path}.
|
---|
| 434 | * => class=TECS::#{@class_name}
|
---|
| 435 | * (mruby's class; accessible from your script)
|
---|
| 436 | * bridge = TECS::#{@class_name}.new("BridgeCellName")
|
---|
| 437 | */
|
---|
| 438 | import( <mruby.cdl> );
|
---|
| 439 |
|
---|
| 440 | /**** Ruby => TECS Bridge Celltype (MBP500) ****/
|
---|
| 441 | namespace nMruby{
|
---|
| 442 | // bridge celltype
|
---|
| 443 | [idx_is_id,active] // not actually active, to avoid warning W1002, W1007
|
---|
| 444 | celltype #{@celltype_name} {
|
---|
| 445 | call #{@signature.get_namespace_path.to_s} cTECS;
|
---|
| 446 | attr {
|
---|
| 447 | [omit]
|
---|
| 448 | char_t *VMname = "VM";
|
---|
| 449 | [omit]
|
---|
| 450 | char_t *bridgeName = C_EXP( "$cell$" );
|
---|
| 451 | };
|
---|
| 452 | };
|
---|
| 453 | // bridge initializer celltype
|
---|
| 454 | celltype #{@init_celltype_name} {
|
---|
| 455 | entry sInitializeTECSBridge eInitialize;
|
---|
| 456 | };
|
---|
| 457 | };
|
---|
| 458 | EOT
|
---|
| 459 |
|
---|
| 460 | # æ§é ä½ã»ã«ã¿ã¤ãã®çæ
|
---|
| 461 | @struct_list.each{ |name, sttype|
|
---|
| 462 | if @@struct_list[ name ] == nil then
|
---|
| 463 | file.print <<EOT
|
---|
| 464 | namespace nMruby{
|
---|
| 465 | [singleton]
|
---|
| 466 | celltype #{name} {
|
---|
| 467 | entry sInitializeTECSBridge eInitialize;
|
---|
| 468 | };
|
---|
| 469 | };
|
---|
| 470 | EOT
|
---|
| 471 | @@struct_list[ name ] = sttype
|
---|
| 472 | end
|
---|
| 473 | }
|
---|
| 474 |
|
---|
| 475 | else
|
---|
| 476 | cdl_info( "MRBW001 MrubyBridgePlugin: signature '$1' duplicate. ignored current one", @signature.get_namespace_path )
|
---|
| 477 | @@celltypes[ @celltype_name ] << self
|
---|
| 478 | end
|
---|
| 479 | end
|
---|
| 480 |
|
---|
| 481 | #=== gen_cdl_file ã§å®ç¾©ããã»ã«ã¿ã¤ãã« æ°ããã»ã«ãå®ç¾©ããã
|
---|
| 482 | # cell ã®ã»ã«ã¿ã¤ãã®åå㯠@celltype_name
|
---|
| 483 | def new_cell cell
|
---|
| 484 | if cell.get_celltype.get_name != @celltype_name then
|
---|
| 485 | return
|
---|
| 486 | end
|
---|
| 487 |
|
---|
| 488 | join = cell.get_join_list.get_item :VMname
|
---|
| 489 | if join then
|
---|
| 490 | vm_name = CDLString.remove_dquote(join.get_rhs.to_s).to_sym
|
---|
| 491 | else
|
---|
| 492 | vm_name = :"VM"
|
---|
| 493 | end
|
---|
| 494 |
|
---|
| 495 | if @@VM_list[ vm_name ] == nil then
|
---|
| 496 | @@VM_list[ vm_name ] = true
|
---|
| 497 |
|
---|
| 498 | initializer_celltype_cdl = "#{$gen}/#{cell.get_name}Initializer.cdl"
|
---|
| 499 | file = CFile.open( initializer_celltype_cdl, "w" )
|
---|
| 500 |
|
---|
| 501 | # TECS åæåã»ã«(ãããã¿ã¤ã宣è¨)
|
---|
| 502 | print_msg " MrubyBridgePlugin: join your VM's cInitialize to #{vm_name}_TECSInitializer.eInitialize\n"
|
---|
| 503 |
|
---|
| 504 | file.print <<EOT
|
---|
| 505 |
|
---|
| 506 | // prototype of TECSInitializer (MBP510)
|
---|
| 507 | cell nMruby::tTECSInitializer #{vm_name}_TECSInitializer;
|
---|
| 508 | EOT
|
---|
| 509 | file.close
|
---|
| 510 |
|
---|
| 511 | Generator.parse( initializer_celltype_cdl, self )
|
---|
| 512 | end
|
---|
| 513 |
|
---|
| 514 | if @@VM_celltypes[ vm_name ] then
|
---|
| 515 | vma = @@VM_celltypes[ vm_name ]
|
---|
| 516 |
|
---|
| 517 | if vma[ @celltype_name ] then
|
---|
| 518 | vma[ @celltype_name ] << cell
|
---|
| 519 | else
|
---|
| 520 | vma[ @celltype_name ] = [cell]
|
---|
| 521 | @@VM_celltypes[ vm_name ] = vma
|
---|
| 522 | end
|
---|
| 523 | else
|
---|
| 524 | vma = { }
|
---|
| 525 | vma[ @celltype_name ] = [cell]
|
---|
| 526 | @@VM_celltypes[ vm_name ] = vma
|
---|
| 527 | end
|
---|
| 528 |
|
---|
| 529 | @struct_list.each{ |stname, sttype|
|
---|
| 530 | if @@VM_struct_list[ vm_name ] then
|
---|
| 531 | @@VM_struct_list[ vm_name ][ sttype.get_name ] = sttype
|
---|
| 532 | else
|
---|
| 533 | @@VM_struct_list[ vm_name ] = { sttype.get_name => sttype }
|
---|
| 534 | end
|
---|
| 535 | }
|
---|
| 536 | @ptr_list.each{ |ptr_celltype_name, tment|
|
---|
| 537 | if @@VM_ptr_list[ vm_name ] then
|
---|
| 538 | @@VM_ptr_list[ vm_name ][ ptr_celltype_name ] = tment
|
---|
| 539 | else
|
---|
| 540 | @@VM_ptr_list[ vm_name ] = { ptr_celltype_name => tment }
|
---|
| 541 | end
|
---|
| 542 | }
|
---|
| 543 |
|
---|
| 544 | end
|
---|
| 545 |
|
---|
| 546 | #=== ãã©ã°ã¤ã³ã CDL ã® POST ã³ã¼ããçæ
|
---|
| 547 | # tmp_plugin_post_code.cdl ã¸ã®åºå
|
---|
| 548 | def self.gen_post_code file
|
---|
| 549 | dbgPrint "#{self.name}: gen_post_code\n"
|
---|
| 550 | if ! @@b_gen_post_code_by_dependent then
|
---|
| 551 | gen_post_code_body file
|
---|
| 552 | end
|
---|
| 553 | end
|
---|
| 554 |
|
---|
| 555 | def self.set_gen_post_code_by_dependent # by MrubyBriddeCellPlugin
|
---|
| 556 | dbgPrint "#{self.name}: set_gen_post_code_by_dependent\n"
|
---|
| 557 | @@b_gen_post_code_by_dependent = true
|
---|
| 558 | end
|
---|
| 559 |
|
---|
| 560 | def self.gen_post_code_body file
|
---|
| 561 | dbgPrint "#{self.name}: gen_post_code_body\n"
|
---|
| 562 |
|
---|
| 563 | # file.print <<EOT
|
---|
| 564 | # namespace nMruby {
|
---|
| 565 | # EOT
|
---|
| 566 | #
|
---|
| 567 | # @@ptr_list.each{ |name,tment|
|
---|
| 568 | # file.print <<EOT
|
---|
| 569 | #
|
---|
| 570 | # // MBP600
|
---|
| 571 | # [singleton]
|
---|
| 572 | # celltype #{name} {
|
---|
| 573 | # entry sInitializeTECSBridge eInitialize;
|
---|
| 574 | # };
|
---|
| 575 | # EOT
|
---|
| 576 | # }
|
---|
| 577 | #
|
---|
| 578 | # file.print <<EOT
|
---|
| 579 | # };
|
---|
| 580 | # EOT
|
---|
| 581 |
|
---|
| 582 | # gen_post_code ã§çæãã celltype 㯠gen_ep_func ãå¼ã³åºãããªã #847
|
---|
| 583 | # @@struct_list.each{ |name,sttype|
|
---|
| 584 | # file.print <<EOT
|
---|
| 585 | #
|
---|
| 586 | # [singleton]
|
---|
| 587 | # celltype #{name} {
|
---|
| 588 | # entry sInitializeTECSBridge eInitialize;
|
---|
| 589 | # };
|
---|
| 590 | #EOT
|
---|
| 591 | # }
|
---|
| 592 |
|
---|
| 593 | file.print "\n // MrubyBridgeSignaturePlugin: MBP601\n"
|
---|
| 594 | @@VM_celltypes.each{ |vm_name, instance_list|
|
---|
| 595 | instance_list.each { |celltype_name, array|
|
---|
| 596 | cell = array[0]
|
---|
| 597 | if cell.get_celltype then
|
---|
| 598 | ct_name = cell.get_celltype.get_name
|
---|
| 599 | file.print <<EOT
|
---|
| 600 | cell nMruby::#{ct_name}_Initializer #{vm_name}_#{ct_name}_Initializer{ };
|
---|
| 601 | EOT
|
---|
| 602 | end
|
---|
| 603 | }
|
---|
| 604 | }
|
---|
| 605 |
|
---|
| 606 | file.print " // MBP602\n"
|
---|
| 607 | @@ptr_list.each{ |name,tment|
|
---|
| 608 | file.print <<EOT
|
---|
| 609 | cell nMruby::#{name} C#{name} { };
|
---|
| 610 | EOT
|
---|
| 611 | }
|
---|
| 612 |
|
---|
| 613 | file.print " // MBP603\n"
|
---|
| 614 | @@struct_list.each{ |name,sttype|
|
---|
| 615 | file.print <<EOT
|
---|
| 616 | cell nMruby::#{name} C#{name} { };
|
---|
| 617 | EOT
|
---|
| 618 | }
|
---|
| 619 |
|
---|
| 620 | if @@VM_celltypes == nil
|
---|
| 621 | raise "MrubyBridgeSignaturePlugin: are0"
|
---|
| 622 | end
|
---|
| 623 | @@VM_celltypes.each{ |vm_name, instance_list|
|
---|
| 624 | file.print " /* === VM name is '#{vm_name}' === (MBP610) */\n"
|
---|
| 625 | init_cell_name = "#{vm_name}_TECSInitializer"
|
---|
| 626 |
|
---|
| 627 | file.print " cell nMruby::tTECSInitializer #{init_cell_name} {\n"
|
---|
| 628 |
|
---|
| 629 | instance_list.each { |celltype_name, array|
|
---|
| 630 | # array.each{ |cell|
|
---|
| 631 | # ct_name = cell.get_celltype.get_name
|
---|
| 632 | ct_name = celltype_name
|
---|
| 633 | file.print " cInitialize[] = #{vm_name}_#{ct_name}_Initializer.eInitialize;\n"
|
---|
| 634 | # }
|
---|
| 635 | }
|
---|
| 636 | if @@VM_ptr_list[vm_name] then
|
---|
| 637 | @@VM_ptr_list[vm_name].each{ |name, tment|
|
---|
| 638 | file.print " cInitialize[] = C#{name}.eInitialize;\n"
|
---|
| 639 | }
|
---|
| 640 | end
|
---|
| 641 | if @@VM_struct_list[vm_name] then
|
---|
| 642 | @@VM_struct_list[vm_name].each{ |name, sttype|
|
---|
| 643 | file.print " cInitialize[] = C#{name}.eInitialize;\n"
|
---|
| 644 | }
|
---|
| 645 | end
|
---|
| 646 | file.print " };"
|
---|
| 647 | }
|
---|
| 648 |
|
---|
| 649 | end
|
---|
| 650 |
|
---|
| 651 | ####### 以ä¸ã³ã¼ãçæ段é ######
|
---|
| 652 |
|
---|
| 653 | #=== åãå£é¢æ°ã®æ¬ä½ã³ã¼ããçæï¼é é¨ã¨æ«å°¾ã¯å¥éåºåï¼
|
---|
| 654 | #ct_name:: Symbol (ãã©ã°ã¤ã³ã§çæããã) ã»ã«ã¿ã¤ãå ï¼Symbol ã¨ãã¦éããã¦ãã
|
---|
| 655 | 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 )
|
---|
| 656 | if @@celltypes[ ct_name ] then
|
---|
| 657 | gen_ep_func_body_bridge( file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params )
|
---|
| 658 | elsif @@init_celltypes[ ct_name ] then
|
---|
| 659 | gen_ep_func_body_bridge_init( file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params )
|
---|
| 660 | elsif @@ptr_list[ ct_name ] then
|
---|
| 661 | gen_ep_func_body_ptr( file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params )
|
---|
| 662 | elsif @@struct_list[ ct_name ] then
|
---|
| 663 | gen_ep_func_body_struct( file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params )
|
---|
| 664 | else
|
---|
| 665 | raise "MrubyBridgeSignaturePlugin: Unknown #{ct_name}"
|
---|
| 666 | end
|
---|
| 667 | end
|
---|
| 668 |
|
---|
| 669 | def gen_ep_func_body_bridge( file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params )
|
---|
| 670 | raise "MrubyBridgeSignaturePlugin: unexpected "
|
---|
| 671 | end
|
---|
| 672 |
|
---|
| 673 | def gen_ep_func_body_bridge_init( file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params )
|
---|
| 674 | file.print <<EOT
|
---|
| 675 | // CELLCB *p_cellcb = GET_CELLCB( idx ); /* no error check */ /* MBP700 */
|
---|
| 676 | struct RClass *rc;
|
---|
| 677 |
|
---|
| 678 | rc = mrb_define_class_under( mrb, TECS, \"#{@class_name}\", mrb->object_class );
|
---|
| 679 | mrb_define_method( mrb, rc, "initialize", MrubyBridge_#{@celltype_name}_initialize, MRB_ARGS_REQ(1) );
|
---|
| 680 | MRB_SET_INSTANCE_TT(rc, MRB_TT_DATA);
|
---|
| 681 | EOT
|
---|
| 682 |
|
---|
| 683 | @func_head_array.each{ |f|
|
---|
| 684 | if ! f.is_function? then
|
---|
| 685 | next
|
---|
| 686 | end
|
---|
| 687 | if f.get_name != :initialize then
|
---|
| 688 | func_name = f.get_name
|
---|
| 689 | else
|
---|
| 690 | func_name = :initialize_cell
|
---|
| 691 | end
|
---|
| 692 |
|
---|
| 693 | ret_type = f.get_return_type
|
---|
| 694 | n_param = 0
|
---|
| 695 | f.get_paramlist.get_items.each{ |param|
|
---|
| 696 | case param.get_direction
|
---|
| 697 | when :IN, :INOUT, :OUT
|
---|
| 698 | n_param += 1
|
---|
| 699 | when :SEND, :RECEIVE
|
---|
| 700 | raise "MrubyBridgeSignaturePlugin: send, receive"
|
---|
| 701 | end
|
---|
| 702 | }
|
---|
| 703 | if n_param > 0 then
|
---|
| 704 | p_str = "MRB_ARGS_REQ( #{n_param} )"
|
---|
| 705 | else
|
---|
| 706 | p_str = "MRB_ARGS_NONE()"
|
---|
| 707 | end
|
---|
| 708 | file.print <<EOT
|
---|
| 709 | mrb_define_method( mrb, rc, "#{func_name}", MrubyBridge_#{@celltype_name}_#{func_name}, #{p_str} );
|
---|
| 710 | EOT
|
---|
| 711 | }
|
---|
| 712 | end
|
---|
| 713 |
|
---|
| 714 | def gen_ep_func_body_ptr( file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params )
|
---|
| 715 |
|
---|
| 716 | t = @@ptr_list[ct_name]
|
---|
| 717 | type = t[1]
|
---|
| 718 | file.print <<EOT
|
---|
| 719 | struct RClass *a; /* MBP710 */
|
---|
| 720 |
|
---|
| 721 | a = mrb_define_class_under(mrb, TECS, "#{type}Pointer", mrb->object_class);
|
---|
| 722 | MRB_SET_INSTANCE_TT(a, MRB_TT_DATA);
|
---|
| 723 |
|
---|
| 724 | mrb_define_method(mrb, a, "initialize", #{type}Pointer_initialize, MRB_ARGS_REQ(1));
|
---|
| 725 | mrb_define_method(mrb, a, "[]", #{type}Pointer_aget, MRB_ARGS_REQ(1));
|
---|
| 726 | mrb_define_method(mrb, a, "value", #{type}Pointer_get_val, MRB_ARGS_NONE());
|
---|
| 727 | mrb_define_method(mrb, a, "[]=", #{type}Pointer_aset, MRB_ARGS_REQ(2));
|
---|
| 728 | mrb_define_method(mrb, a, "value=", #{type}Pointer_set_val, MRB_ARGS_REQ(1));
|
---|
| 729 | mrb_define_method(mrb, a, "size", #{type}Pointer_size, MRB_ARGS_NONE());
|
---|
| 730 | mrb_define_method(mrb, a, "length", #{type}Pointer_size, MRB_ARGS_NONE());
|
---|
| 731 | EOT
|
---|
| 732 |
|
---|
| 733 | if t[2] == :Char then
|
---|
| 734 | file.print <<EOT
|
---|
| 735 | mrb_define_method(mrb, a, "to_s", CharPointer_to_s, MRB_ARGS_NONE());
|
---|
| 736 | mrb_define_method(mrb, a, "from_s", CharPointer_from_s, MRB_ARGS_REQ(1));
|
---|
| 737 | EOT
|
---|
| 738 | end
|
---|
| 739 | end
|
---|
| 740 |
|
---|
| 741 | def gen_ep_func_body_struct( file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params )
|
---|
| 742 | tag = ct_name
|
---|
| 743 | structType = @@struct_list[ tag ]
|
---|
| 744 | file.print <<EOT
|
---|
| 745 | struct RClass *a; /* MBP720 */
|
---|
| 746 |
|
---|
| 747 | a = mrb_define_class_under(mrb, TECS, "Struct#{tag}", mrb->object_class);
|
---|
| 748 | MRB_SET_INSTANCE_TT(a, MRB_TT_DATA);
|
---|
| 749 |
|
---|
| 750 | mrb_define_method(mrb, a, "initialize", Struct_#{tag}_initialize, MRB_ARGS_NONE());
|
---|
| 751 | EOT
|
---|
| 752 |
|
---|
| 753 | structType.get_members_decl.get_items.each{ |d|
|
---|
| 754 | file.print " STRUCT_INIT_MEMBER( #{tag}, #{d.get_name} )\n"
|
---|
| 755 | }
|
---|
| 756 | end
|
---|
| 757 |
|
---|
| 758 | #=== åãå£é¢æ°ã® preamble (Cè¨èª)ãçæãã
|
---|
| 759 | # å¿
|
---|
| 760 | è¦ãªã preamble é¨ã«åºåãã
|
---|
| 761 | #file:: FILE åºåå
|
---|
| 762 | ãã¡ã¤ã«
|
---|
| 763 | #b_singleton:: bool true if singleton
|
---|
| 764 | #ct_name:: Symbol
|
---|
| 765 | #global_ct_name:: string
|
---|
| 766 | def gen_preamble( file, b_singleton, ct_name, global_ct_name )
|
---|
| 767 | if @@celltypes[ ct_name ] then
|
---|
| 768 | gen_preamble_mruby( file, b_singleton, ct_name, global_ct_name )
|
---|
| 769 | gen_preamble_instance( file, b_singleton, ct_name, global_ct_name )
|
---|
| 770 | gen_preamble_instance_initialize( file, b_singleton, ct_name, global_ct_name )
|
---|
| 771 | gen_preamble_bridge_func( file, b_singleton, ct_name, global_ct_name )
|
---|
| 772 | elsif @@init_celltypes[ ct_name ] then
|
---|
| 773 | gen_preamble_mruby( file, b_singleton, ct_name, global_ct_name )
|
---|
| 774 | gen_preamble_instance_proto( file, b_singleton, ct_name, global_ct_name )
|
---|
| 775 | elsif @@ptr_list[ ct_name ] then
|
---|
| 776 | gen_preamble_ptr( file, b_singleton, ct_name, global_ct_name )
|
---|
| 777 | elsif @@struct_list[ ct_name ] then
|
---|
| 778 | gen_preamble_struct( file, b_singleton, ct_name, global_ct_name )
|
---|
| 779 | else
|
---|
| 780 | raise "MrubyBridgeSignaturePlugin: MrubyBridgeSignaturePlugin: Unknown #{ct_name}"
|
---|
| 781 | end
|
---|
| 782 | end
|
---|
| 783 |
|
---|
| 784 | def gen_preamble_mruby( file, b_singleton, ct_name, global_ct_name )
|
---|
| 785 | file.print <<EOT
|
---|
| 786 | /* MBP: MrubyBridgePlugin: MBP000 */
|
---|
| 787 | #include "mruby.h"
|
---|
| 788 | #include "mruby/class.h"
|
---|
| 789 | #include "mruby/data.h"
|
---|
| 790 | #include "mruby/string.h"
|
---|
| 791 | #include "TECSPointer.h"
|
---|
| 792 | #include "TECSStruct.h"
|
---|
| 793 |
|
---|
| 794 | #if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
|
---|
| 795 | #define DLLEXPORT __declspec(dllexport)
|
---|
| 796 | #else
|
---|
| 797 | #define DLLEXPORT
|
---|
| 798 | #endif
|
---|
| 799 |
|
---|
| 800 | #ifndef NULL
|
---|
| 801 | #define NULL 0
|
---|
| 802 | #endif
|
---|
| 803 | EOT
|
---|
| 804 | end
|
---|
| 805 |
|
---|
| 806 | def gen_preamble_instance( file, b_singleton, ct_name, global_ct_name )
|
---|
| 807 | # ã#1005 MrubyBridgePlugin-test ã®ãã«ãã«å¤±æãã«ã¦è¿½å
|
---|
| 808 | # ã#1004 idx_is_id ã true ã®å ´å(domain ã®å ´åã¯æªæå®ã§ã true) ã® CBP ã®ãããã¿ã¤ã宣è¨ãã«ã¦ä¸è¦ã«ãªãè¦è¾¼ã¿
|
---|
| 809 | nsp = NamespacePath.new( :nMruby, true )
|
---|
| 810 | nsp.append! ct_name
|
---|
| 811 | ct = Namespace.find nsp
|
---|
| 812 | if ct.idx_is_id_act? then
|
---|
| 813 | if ct.has_CB? then
|
---|
| 814 | inib_cb = "CB"
|
---|
| 815 | elsif ct.has_INIB? then
|
---|
| 816 | inib_cb = "INIB"
|
---|
| 817 | else
|
---|
| 818 | inib_cb = nil
|
---|
| 819 | end
|
---|
| 820 | if inib_cb then
|
---|
| 821 | ct.get_cell_list.each{ |cell|
|
---|
| 822 | if cell.is_generate? then
|
---|
| 823 | name_array = ct.get_name_array( cell )
|
---|
| 824 | file.print "extern #{ct.get_global_name}_CB #{cell.get_global_name}_#{inib_cb};\n"
|
---|
| 825 | end
|
---|
| 826 | }
|
---|
| 827 | end
|
---|
| 828 | end
|
---|
| 829 |
|
---|
| 830 | file.print <<EOT
|
---|
| 831 |
|
---|
| 832 | /* RData MBP001 */
|
---|
| 833 | static void
|
---|
| 834 | #{@celltype_name}_free( mrb_state *mrb, void *p )
|
---|
| 835 | {
|
---|
| 836 | if( p )
|
---|
| 837 | (void)mrb_free( mrb, p );
|
---|
| 838 | }
|
---|
| 839 |
|
---|
| 840 | /* RData MBP002 */
|
---|
| 841 | struct mrb_data_type data_type_#{@celltype_name} =
|
---|
| 842 | {
|
---|
| 843 | "#{@celltype_name}",
|
---|
| 844 | #{@celltype_name}_free
|
---|
| 845 | };
|
---|
| 846 |
|
---|
| 847 | /* RData MBP003 */
|
---|
| 848 | struct tecs_#{@celltype_name} {
|
---|
| 849 | CELLCB *cbp;
|
---|
| 850 | };
|
---|
| 851 |
|
---|
| 852 | /* name_to_cbp MBP010 */
|
---|
| 853 | const struct name_to_cbp_#{@celltype_name} {
|
---|
| 854 | char *name; /* Cell Name */
|
---|
| 855 | CELLCB *cbp;
|
---|
| 856 | } Name_to_cbp_#{@celltype_name}[] = {
|
---|
| 857 | EOT
|
---|
| 858 |
|
---|
| 859 | nsp = NamespacePath.new( :nMruby, true )
|
---|
| 860 | nsp.append! ct_name
|
---|
| 861 | ct = Namespace.find nsp
|
---|
| 862 |
|
---|
| 863 | ct.get_cell_list.each{ |cell|
|
---|
| 864 | if cell.is_generate? then
|
---|
| 865 | join_list = cell.get_join_list
|
---|
| 866 | join = join_list.get_item( :bridgeName )
|
---|
| 867 | if join == nil then
|
---|
| 868 | name = "\"#{cell.get_name}\""
|
---|
| 869 | else
|
---|
| 870 | rhs = join.get_rhs
|
---|
| 871 | attr_list = cell.get_celltype.get_attribute_list
|
---|
| 872 | name = rhs.eval_const join_list, attr_list
|
---|
| 873 | end
|
---|
| 874 |
|
---|
| 875 | name_array = ct.get_name_array( cell )
|
---|
| 876 | file.print "\t{ #{name}, #{name_array[8]} },\n"
|
---|
| 877 | end
|
---|
| 878 | }
|
---|
| 879 |
|
---|
| 880 | file.print <<EOT
|
---|
| 881 | \t{ 0, 0 },
|
---|
| 882 | };
|
---|
| 883 |
|
---|
| 884 | EOT
|
---|
| 885 |
|
---|
| 886 | end
|
---|
| 887 |
|
---|
| 888 | def gen_preamble_ptr( file, b_singleton, ct_name, global_ct_name )
|
---|
| 889 | tment = @@ptr_list[ ct_name ]
|
---|
| 890 | file.print <<EOT
|
---|
| 891 |
|
---|
| 892 | GET_SET_#{tment[3]}( #{tment[1]}, #{tment[0]} )
|
---|
| 893 | POINTER_CLASS( #{tment[1]}, #{tment[0]} )
|
---|
| 894 | EOT
|
---|
| 895 | end
|
---|
| 896 |
|
---|
| 897 | def gen_preamble_struct( file, b_singleton, ct_name, global_ct_name )
|
---|
| 898 | tag = ct_name
|
---|
| 899 | structType = @@struct_list[ tag ]
|
---|
| 900 | file.print <<EOT
|
---|
| 901 | /* struct #{tag} */
|
---|
| 902 | STRUCT_CLASS( #{tag} )
|
---|
| 903 | EOT
|
---|
| 904 |
|
---|
| 905 | structType.get_members_decl.get_items.each{ |d|
|
---|
| 906 | type = d.get_type.get_original_type
|
---|
| 907 | case type
|
---|
| 908 | when IntType, CIntType
|
---|
| 909 | bit_size = type.get_bit_size
|
---|
| 910 | case bit_size
|
---|
| 911 | when -11, -1
|
---|
| 912 | tType = "Char"
|
---|
| 913 | ttype = "char"
|
---|
| 914 | when -2
|
---|
| 915 | tType = "Short"
|
---|
| 916 | ttype = "short"
|
---|
| 917 | when -3
|
---|
| 918 | tType = "Int"
|
---|
| 919 | ttype = "int"
|
---|
| 920 | when -4
|
---|
| 921 | tType = "Long"
|
---|
| 922 | ttype = "long"
|
---|
| 923 | when -5
|
---|
| 924 | tType = "IntPtr"
|
---|
| 925 | ttype = "intptr"
|
---|
| 926 | when 8, 16, 32, 64
|
---|
| 927 | tType = "Int#{bit_size}"
|
---|
| 928 | ttype = "int#{bit_size}"
|
---|
| 929 | else
|
---|
| 930 | raise "MrubyBridgeSignaturePlugin: MrubyBridgeSignaturePlugin: cannot handle bit_size #{bit_size}"
|
---|
| 931 | end
|
---|
| 932 | file.print "MEMBER_GET_SET_INT( #{tag}, #{d.get_name}, #{tType}, #{ttype} )\n"
|
---|
| 933 | when FloatType, CFloatType
|
---|
| 934 | file.print "MEMBER_GET_SET_FLOAT( #{tag}, #{d.get_name} )\n"
|
---|
| 935 | else
|
---|
| 936 | raise "MrubyBridgeSignaturePlugin: MrubyBridgeSignaturePlugin: cannot handle type"
|
---|
| 937 | end
|
---|
| 938 | }
|
---|
| 939 |
|
---|
| 940 | end
|
---|
| 941 |
|
---|
| 942 | def gen_preamble_instance_proto( file, b_singleton, ct_name, global_ct_name )
|
---|
| 943 | file.print <<EOT
|
---|
| 944 | // Prototype MBP400
|
---|
| 945 | mrb_value MrubyBridge_#{@celltype_name}_initialize( mrb_state *mrb, mrb_value self);
|
---|
| 946 | EOT
|
---|
| 947 |
|
---|
| 948 | @func_head_array.each{ |f|
|
---|
| 949 | if ! f.is_function? then
|
---|
| 950 | next
|
---|
| 951 | end
|
---|
| 952 | if f.get_name != :initialize then
|
---|
| 953 | func_name = f.get_name
|
---|
| 954 | else
|
---|
| 955 | func_name = :initialize_cell
|
---|
| 956 | end
|
---|
| 957 |
|
---|
| 958 | ret_type = f.get_return_type
|
---|
| 959 | ret_type0 = f.get_return_type.get_original_type
|
---|
| 960 | b_void = ret_type0.is_void?
|
---|
| 961 | plist = f.get_paramlist.get_items
|
---|
| 962 |
|
---|
| 963 | file.print <<EOT
|
---|
| 964 | mrb_value MrubyBridge_#{@celltype_name}_#{func_name}( mrb_state *mrb, mrb_value self );
|
---|
| 965 | EOT
|
---|
| 966 | }
|
---|
| 967 | end
|
---|
| 968 |
|
---|
| 969 | def gen_preamble_instance_initialize( file, b_singleton, ct_name, global_ct_name )
|
---|
| 970 | file.print <<EOT
|
---|
| 971 |
|
---|
| 972 | /* MBP100 */
|
---|
| 973 | mrb_value
|
---|
| 974 | MrubyBridge_#{@celltype_name}_initialize( mrb_state *mrb, mrb_value self)
|
---|
| 975 | {
|
---|
| 976 | mrb_value name;
|
---|
| 977 | struct tecs_#{@celltype_name} *tecs_cb;
|
---|
| 978 | const struct name_to_cbp_#{@celltype_name} *ntc;
|
---|
| 979 |
|
---|
| 980 | /* set DATA_TYPE earlier to avoid SEGV */
|
---|
| 981 | DATA_TYPE( self ) = &data_type_#{@celltype_name};
|
---|
| 982 |
|
---|
| 983 | mrb_get_args(mrb, "o", &name );
|
---|
| 984 | if( mrb_type( name ) != MRB_TT_STRING ){
|
---|
| 985 | mrb_raise(mrb, E_NAME_ERROR, "cell name not string");
|
---|
| 986 | }
|
---|
| 987 | for( ntc = &Name_to_cbp_#{@celltype_name}[0]; ntc->name != NULL; ntc++ ){
|
---|
| 988 | if( strcmp( ntc->name, RSTRING_PTR( name ) ) == 0 )
|
---|
| 989 | break;
|
---|
| 990 | }
|
---|
| 991 | if( ntc->name == 0 ){
|
---|
| 992 | mrb_raise(mrb, E_ARGUMENT_ERROR, "cell not found");
|
---|
| 993 | }
|
---|
| 994 | tecs_cb = (struct tecs_#{@celltype_name} *)mrb_malloc(mrb, sizeof(struct tecs_#{@celltype_name}) );
|
---|
| 995 | tecs_cb->cbp = ntc->cbp;
|
---|
| 996 | DATA_PTR( self ) = (void *)tecs_cb;
|
---|
| 997 |
|
---|
| 998 | return self;
|
---|
| 999 | }
|
---|
| 1000 | EOT
|
---|
| 1001 | end
|
---|
| 1002 |
|
---|
| 1003 | def gen_preamble_bridge_func( file, b_singleton, ct_name, global_ct_name )
|
---|
| 1004 |
|
---|
| 1005 | @func_head_array.each{ |f|
|
---|
| 1006 | if ! f.is_function? then
|
---|
| 1007 | next
|
---|
| 1008 | end
|
---|
| 1009 | if f.get_name != :initialize then
|
---|
| 1010 | func_name = f.get_name
|
---|
| 1011 | else
|
---|
| 1012 | func_name = :initialize_cell
|
---|
| 1013 | end
|
---|
| 1014 |
|
---|
| 1015 | ret_type = f.get_return_type
|
---|
| 1016 | ret_type0 = f.get_return_type.get_original_type
|
---|
| 1017 | b_void = ret_type0.is_void?
|
---|
| 1018 | plist = f.get_paramlist.get_items
|
---|
| 1019 |
|
---|
| 1020 | file.print <<EOT
|
---|
| 1021 |
|
---|
| 1022 | /* bridge function (MBP101) */
|
---|
| 1023 | mrb_value
|
---|
| 1024 | MrubyBridge_#{ct_name}_#{func_name}( mrb_state *mrb, mrb_value self )
|
---|
| 1025 | {
|
---|
| 1026 | /* cellcbp (MBP105) */
|
---|
| 1027 | CELLCB *p_cellcb = ((struct tecs_#{@celltype_name} *)DATA_PTR(self))->cbp;
|
---|
| 1028 | EOT
|
---|
| 1029 |
|
---|
| 1030 | file.print " /* variables for return & parameter (MBP110) */\n"
|
---|
| 1031 | if ! b_void then
|
---|
| 1032 | file.print " ", ret_type.get_type_str, "\tret_val", ret_type.get_type_str_post, ";\n"
|
---|
| 1033 | end
|
---|
| 1034 | arg_str = ""
|
---|
| 1035 | n_param = 0
|
---|
| 1036 | n_scalar = 0
|
---|
| 1037 | n_ptr = 0
|
---|
| 1038 | n_struct = 0
|
---|
| 1039 | plist.each{ |param|
|
---|
| 1040 | case param.get_direction
|
---|
| 1041 | when :IN, :INOUT, :OUT
|
---|
| 1042 | type = param.get_type.get_original_type
|
---|
| 1043 | case type
|
---|
| 1044 | when IntType
|
---|
| 1045 | file.print " mrb_int mrb_", param.get_name, ";\n"
|
---|
| 1046 | file.print " #{param.get_type.get_type_str} #{param.get_name}#{param.get_type.get_type_str_post};\n"
|
---|
| 1047 | arg_str += "i"
|
---|
| 1048 | n_param += 1
|
---|
| 1049 | n_scalar += 1
|
---|
| 1050 | when FloatType
|
---|
| 1051 | file.print " mrb_float mrb_", param.get_name, ";\n"
|
---|
| 1052 | file.print " #{param.get_type.get_type_str} #{param.get_name}#{param.get_type.get_type_str_post};\n"
|
---|
| 1053 | arg_str += "f"
|
---|
| 1054 | n_param += 1
|
---|
| 1055 | n_scalar += 1
|
---|
| 1056 | when BoolType
|
---|
| 1057 | file.print " mrb_value mrb_", param.get_name, ";\n"
|
---|
| 1058 | file.print " #{param.get_type.get_type_str} #{param.get_name}#{param.get_type.get_type_str_post};\n"
|
---|
| 1059 | arg_str += "o"
|
---|
| 1060 | n_param += 1
|
---|
| 1061 | n_scalar += 1
|
---|
| 1062 | when PtrType
|
---|
| 1063 | file.print " mrb_value mrb_", param.get_name, ";\n"
|
---|
| 1064 | file.print " #{param.get_type.get_type_str} #{param.get_name}#{param.get_type.get_type_str_post};\n"
|
---|
| 1065 | arg_str += "o"
|
---|
| 1066 | n_param += 1
|
---|
| 1067 | n_ptr += 1
|
---|
| 1068 | when StructType
|
---|
| 1069 | file.print " mrb_value mrb_", param.get_name, ";\n"
|
---|
| 1070 | file.print " #{param.get_type.get_type_str} *#{param.get_name}#{param.get_type.get_type_str_post};\n"
|
---|
| 1071 | arg_str += "o"
|
---|
| 1072 | n_param += 1
|
---|
| 1073 | n_struct += 1
|
---|
| 1074 | else
|
---|
| 1075 | raise "MrubyBridgeSignaturePlugin: Unknown type"
|
---|
| 1076 | end
|
---|
| 1077 | end
|
---|
| 1078 | }
|
---|
| 1079 |
|
---|
| 1080 | if n_param > 0 then
|
---|
| 1081 | file.print " /* retrieve arguments (MBP111) */\n"
|
---|
| 1082 | file.print " mrb_get_args(mrb, \"#{arg_str}\""
|
---|
| 1083 | plist.each{ |param|
|
---|
| 1084 | case param.get_direction
|
---|
| 1085 | when :IN, :INOUT, :OUT
|
---|
| 1086 | type = param.get_type.get_original_type
|
---|
| 1087 | case type
|
---|
| 1088 | when IntType
|
---|
| 1089 | file.print ", &mrb_", param.get_name
|
---|
| 1090 | when FloatType
|
---|
| 1091 | file.print ", &mrb_", param.get_name
|
---|
| 1092 | when BoolType
|
---|
| 1093 | file.print ", &mrb_", param.get_name
|
---|
| 1094 | when PtrType
|
---|
| 1095 | file.print ", &mrb_", param.get_name
|
---|
| 1096 | when StructType
|
---|
| 1097 | file.print ", &mrb_", param.get_name
|
---|
| 1098 | else
|
---|
| 1099 | raise "MrubyBridgeSignaturePlugin: Unknown type"
|
---|
| 1100 | end
|
---|
| 1101 | end
|
---|
| 1102 | }
|
---|
| 1103 | file.print " );\n"
|
---|
| 1104 |
|
---|
| 1105 | if n_scalar > 0 || n_struct > 0 then
|
---|
| 1106 | file.print " /* convert mrb to C (MBP112) */\n"
|
---|
| 1107 | end
|
---|
| 1108 | plist.each{ |param|
|
---|
| 1109 | case param.get_direction
|
---|
| 1110 | when :IN, :INOUT, :OUT
|
---|
| 1111 | type = param.get_type.get_original_type
|
---|
| 1112 | case type
|
---|
| 1113 | when IntType
|
---|
| 1114 | ttype = type.get_original_type
|
---|
| 1115 | tment = get_type_map_ent ttype
|
---|
| 1116 | file.print " VALCHECK_#{tment[1]}( mrb, mrb_#{param.get_name} );\n"
|
---|
| 1117 | file.print " #{param.get_name} = (#{param.get_type.get_type_str})mrb_#{param.get_name};\n"
|
---|
| 1118 | when FloatType
|
---|
| 1119 | file.print " #{param.get_name} = (#{param.get_type.get_type_str})mrb_#{param.get_name};\n"
|
---|
| 1120 | when BoolType
|
---|
| 1121 | file.print " #{param.get_name} = mrb_test( mrb_#{param.get_name} );\n"
|
---|
| 1122 | when PtrType
|
---|
| 1123 | ttype = type.get_type.get_original_type
|
---|
| 1124 | case ttype
|
---|
| 1125 | when StructType
|
---|
| 1126 | file.print " CHECK_STRUCT( #{ttype.get_name}, mrb_#{param.get_name} );\n"
|
---|
| 1127 | file.print " #{param.get_name} = (struct #{ttype.get_name}*)DATA_PTR(mrb_#{param.get_name});\n"
|
---|
| 1128 | when IntType
|
---|
| 1129 | when FloatType
|
---|
| 1130 | when BoolType
|
---|
| 1131 | else
|
---|
| 1132 | raise "MrubyBridgeSignaturePlugin: cannot handle type"
|
---|
| 1133 | end
|
---|
| 1134 | when StructType
|
---|
| 1135 | file.print " CHECK_STRUCT( #{type.get_name}, mrb_#{param.get_name} );\n"
|
---|
| 1136 | file.print " #{param.get_name} = (struct #{type.get_name}*)DATA_PTR(mrb_#{param.get_name});\n"
|
---|
| 1137 | else
|
---|
| 1138 | raise( "MrubyBridgeSignaturePlugin: canot treat class" )
|
---|
| 1139 | end
|
---|
| 1140 | end
|
---|
| 1141 | }
|
---|
| 1142 |
|
---|
| 1143 | if n_ptr > 0 then
|
---|
| 1144 | file.print " /* convert mrb to C for pointer types (MBP113) */\n"
|
---|
| 1145 | end
|
---|
| 1146 | plist.each{ |param|
|
---|
| 1147 | case param.get_direction
|
---|
| 1148 | when :IN, :INOUT, :OUT
|
---|
| 1149 | type = param.get_type.get_original_type
|
---|
| 1150 | case type
|
---|
| 1151 | when IntType
|
---|
| 1152 | when FloatType
|
---|
| 1153 | when BoolType
|
---|
| 1154 | when PtrType
|
---|
| 1155 | case type.get_type.get_original_type
|
---|
| 1156 | when StructType
|
---|
| 1157 | when IntType
|
---|
| 1158 | ptrMrb2C file, type, param
|
---|
| 1159 | when FloatType
|
---|
| 1160 | ptrMrb2C file, type, param
|
---|
| 1161 | when BoolType
|
---|
| 1162 | ptrMrb2C file, type, param
|
---|
| 1163 | else
|
---|
| 1164 | raise "MrubyBridgeSignaturePlugin: cannot handle type"
|
---|
| 1165 | end
|
---|
| 1166 | when StructType
|
---|
| 1167 | else
|
---|
| 1168 | raise( "MrubyBridgeSignaturePlugin: canot treat class" )
|
---|
| 1169 | end
|
---|
| 1170 | end
|
---|
| 1171 | }
|
---|
| 1172 |
|
---|
| 1173 | end
|
---|
| 1174 |
|
---|
| 1175 | file.print " /* calling target (MBP120) */\n"
|
---|
| 1176 | if ! b_void then
|
---|
| 1177 | file.print " ret_val = "
|
---|
| 1178 | else
|
---|
| 1179 | file.print " "
|
---|
| 1180 | end
|
---|
| 1181 | delim = ""
|
---|
| 1182 | file.print "cTECS_", f.get_name, "( "
|
---|
| 1183 | plist.each{ |param|
|
---|
| 1184 | if param.get_type.get_original_type.kind_of? StructType then
|
---|
| 1185 | aster = "*"
|
---|
| 1186 | else
|
---|
| 1187 | aster = ""
|
---|
| 1188 | end
|
---|
| 1189 | file.print delim, aster, param.get_name
|
---|
| 1190 | delim = ", "
|
---|
| 1191 | }
|
---|
| 1192 | file.print " );\n"
|
---|
| 1193 |
|
---|
| 1194 | file.print " /* return (MBP130) */\n"
|
---|
| 1195 | case ret_type0
|
---|
| 1196 | when BoolType
|
---|
| 1197 | file.print " return ret_val ? mrb_true_value() : mrb_false_value();\n"
|
---|
| 1198 | when IntType
|
---|
| 1199 | file.print " return mrb_fixnum_value( ret_val );\n"
|
---|
| 1200 | when FloatType
|
---|
| 1201 | file.print " return mrb_float_value( mrb, ret_val );\n"
|
---|
| 1202 | when VoidType
|
---|
| 1203 | file.print " return mrb_nil_value();\n"
|
---|
| 1204 | else
|
---|
| 1205 | raise "MrubyBridgeSignaturePlugin: unknown type"
|
---|
| 1206 | end
|
---|
| 1207 |
|
---|
| 1208 | file.print "}\n"
|
---|
| 1209 | }
|
---|
| 1210 | end
|
---|
| 1211 |
|
---|
| 1212 | def ptrMrb2C file, type, param
|
---|
| 1213 | ttype = type.get_type.get_original_type
|
---|
| 1214 | tment = get_type_map_ent ttype
|
---|
| 1215 | tstr = tment[1]
|
---|
| 1216 | =begin
|
---|
| 1217 | case ttype
|
---|
| 1218 | when IntType
|
---|
| 1219 | bit_size = ttype.get_bit_size
|
---|
| 1220 | case bit_size
|
---|
| 1221 | when -1, -11
|
---|
| 1222 | tstr = "Char"
|
---|
| 1223 | when 8, 16, 32, 64
|
---|
| 1224 | tstr = "Int#{bit_size}"
|
---|
| 1225 | when -2
|
---|
| 1226 | tstr = "Short"
|
---|
| 1227 | when -3
|
---|
| 1228 | tstr = "Int"
|
---|
| 1229 | when -4
|
---|
| 1230 | tstr = "Long"
|
---|
| 1231 | when -5
|
---|
| 1232 | tstr = "IntPtr"
|
---|
| 1233 | else
|
---|
| 1234 | raise "MrubyBridgeSignaturePlugin: not handle type"
|
---|
| 1235 | end
|
---|
| 1236 | when FloatType
|
---|
| 1237 | if ttype.get_bit_size == 32 then
|
---|
| 1238 | tstr = "Float32"
|
---|
| 1239 | else
|
---|
| 1240 | tstr = "Double64"
|
---|
| 1241 | end
|
---|
| 1242 | when BoolType
|
---|
| 1243 | tstr = "Bool"
|
---|
| 1244 | when StructType
|
---|
| 1245 | raise "MrubyBridgeSignaturePlugin: not handle type 2 #{ttype}"
|
---|
| 1246 | else
|
---|
| 1247 | raise "MrubyBridgeSignaturePlugin: not handle type 2 #{ttype}"
|
---|
| 1248 | end
|
---|
| 1249 | =end
|
---|
| 1250 | if( param.get_size ) then
|
---|
| 1251 | sz_str = param.get_size.to_s
|
---|
| 1252 | elsif param.get_string then # mikan ã¨ãããã size_is 㨠string ã®åææå® (äºéãã¤ã³ã¿) ã¯ãªã
|
---|
| 1253 | sz_str = param.get_string.to_s
|
---|
| 1254 | else
|
---|
| 1255 | sz_str = "1"
|
---|
| 1256 | end
|
---|
| 1257 | # unsigned åã®å ´åã«ã¯ cast ãå¿
|
---|
| 1258 | è¦
|
---|
| 1259 | if ttype.get_original_type.get_type_str != param.get_type.get_type.get_type_str then
|
---|
| 1260 | cast_str = "(#{param.get_type.get_type_str})"
|
---|
| 1261 | else
|
---|
| 1262 | cast_str = ""
|
---|
| 1263 | end
|
---|
| 1264 |
|
---|
| 1265 | modify = ""
|
---|
| 1266 | case param.get_direction
|
---|
| 1267 | when :OUT, :INOUT
|
---|
| 1268 | case tstr
|
---|
| 1269 | when "Char", "SChar", "UChar"
|
---|
| 1270 | modify = "Mod"
|
---|
| 1271 | end
|
---|
| 1272 | end
|
---|
| 1273 | if param.is_nullable? then
|
---|
| 1274 | nullable = "Nullable"
|
---|
| 1275 | else
|
---|
| 1276 | nullable = ""
|
---|
| 1277 | end
|
---|
| 1278 |
|
---|
| 1279 | # file.print " CHECK_POINTER( #{tstr}, mrb_#{param.get_name}, #{sz_str} );\n"
|
---|
| 1280 | # file.print " #{param.get_name} = #{cast_str}((struct #{tstr}PointerBody*)(DATA_PTR(mrb_#{param.get_name})))->buf;\n"
|
---|
| 1281 | file.print " #{param.get_name} = CheckAndGet#{tstr}Pointer#{modify}#{nullable}( mrb, mrb_#{param.get_name}, #{sz_str} );\n"
|
---|
| 1282 | end
|
---|
| 1283 |
|
---|
| 1284 | def get_celltype_name
|
---|
| 1285 | @celltype_name
|
---|
| 1286 | end
|
---|
| 1287 |
|
---|
| 1288 | #=== ãã©ã°ã¤ã³å¼æ° ignoreUnsigned
|
---|
| 1289 | def set_ignoreUnsigned rhs
|
---|
| 1290 | if rhs == "true" || rhs == nil then
|
---|
| 1291 | @b_ignoreUnsigned = true
|
---|
| 1292 | end
|
---|
| 1293 | end
|
---|
| 1294 | #=== ãã©ã°ã¤ã³å¼æ° include
|
---|
| 1295 | def set_include rhs
|
---|
| 1296 | funcs = rhs.split ','
|
---|
| 1297 | funcs.each{ |rhs_func|
|
---|
| 1298 | found = false
|
---|
| 1299 | rhs_func.gsub!( /\s/, "" )
|
---|
| 1300 | @signature.get_function_head_array.each{ |a|
|
---|
| 1301 | if rhs_func.to_sym == a.get_name then
|
---|
| 1302 | found = true
|
---|
| 1303 | end
|
---|
| 1304 | }
|
---|
| 1305 | if found == false then
|
---|
| 1306 | cdl_error( "MRB1009 include function '$1' not found in signagture '$2'", rhs, @signature.get_name )
|
---|
| 1307 | else
|
---|
| 1308 | @includes << rhs_func.to_sym
|
---|
| 1309 | end
|
---|
| 1310 | }
|
---|
| 1311 | end
|
---|
| 1312 | #=== ãã©ã°ã¤ã³å¼æ° exclude
|
---|
| 1313 | def set_exclude rhs
|
---|
| 1314 | funcs = rhs.split ','
|
---|
| 1315 | funcs.each{ |rhs_func|
|
---|
| 1316 | rhs_func.gsub!( /\s/, "" )
|
---|
| 1317 | func_head = @signature.get_function_head rhs_func.to_sym
|
---|
| 1318 | if func_head == false then
|
---|
| 1319 | cdl_error( "MRB1010 exclude function '$1' not found in signagture '$2", rhs, @signature.get_name )
|
---|
| 1320 | else
|
---|
| 1321 | @excludes << rhs_func.to_sym
|
---|
| 1322 | end
|
---|
| 1323 | }
|
---|
| 1324 | end
|
---|
| 1325 | #=== ãã©ã°ã¤ã³å¼æ° auto_exclude
|
---|
| 1326 | def set_auto_exclude rhs
|
---|
| 1327 | if rhs == "false" then
|
---|
| 1328 | @b_auto_exclude = false
|
---|
| 1329 | elsif rhs == "true" then
|
---|
| 1330 | @b_auto_exclude = true # auto_exclude = true by default
|
---|
| 1331 | else
|
---|
| 1332 | cdl_warning( "MRB9999 auto_exclude: unknown rhs value ignored. specify true or false" )
|
---|
| 1333 | end
|
---|
| 1334 | end
|
---|
| 1335 | end
|
---|
| 1336 |
|
---|