OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright 2010, Google Inc. | 2 # Copyright 2010, Google Inc. |
3 # All rights reserved. | 3 # All rights reserved. |
4 # | 4 # |
5 # Redistribution and use in source and binary forms, with or without | 5 # Redistribution and use in source and binary forms, with or without |
6 # modification, are permitted provided that the following conditions are | 6 # modification, are permitted provided that the following conditions are |
7 # met: | 7 # met: |
8 # | 8 # |
9 # * Redistributions of source code must retain the above copyright | 9 # * Redistributions of source code must retain the above copyright |
10 # notice, this list of conditions and the following disclaimer. | 10 # notice, this list of conditions and the following disclaimer. |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 88 |
89 types = {'bool': ['b', 'bool', 'u.bval', ''], | 89 types = {'bool': ['b', 'bool', 'u.bval', ''], |
90 'char[]': ['C', 'char*', 'arrays.carr', 'u.count'], | 90 'char[]': ['C', 'char*', 'arrays.carr', 'u.count'], |
91 'double': ['d', 'double', 'u.dval', ''], | 91 'double': ['d', 'double', 'u.dval', ''], |
92 'double[]': ['D', 'double*', 'arrays.darr', 'u.count'], | 92 'double[]': ['D', 'double*', 'arrays.darr', 'u.count'], |
93 'handle': ['h', 'NaClSrpcImcDescType', 'u.hval', ''], | 93 'handle': ['h', 'NaClSrpcImcDescType', 'u.hval', ''], |
94 'int32_t': ['i', 'int32_t', 'u.ival', ''], | 94 'int32_t': ['i', 'int32_t', 'u.ival', ''], |
95 'int32_t[]': ['I', 'int32_t*', 'arrays.iarr', 'u.count'], | 95 'int32_t[]': ['I', 'int32_t*', 'arrays.iarr', 'u.count'], |
96 'int64_t': ['l', 'int64_t', 'u.lval', ''], | 96 'int64_t': ['l', 'int64_t', 'u.lval', ''], |
97 'int64_t[]': ['L', 'int64_t', 'arrays.larr', 'u.count'], | 97 'int64_t[]': ['L', 'int64_t', 'arrays.larr', 'u.count'], |
| 98 'PP_Instance': ['l', 'PP_Instance', 'u.lval', ''], |
| 99 'PP_Module': ['l', 'PP_Module', 'u.lval', ''], |
| 100 'PP_Resource': ['l', 'PP_Resource', 'u.lval', ''], |
98 'string': ['s', 'char*', 'arrays.str', ''], | 101 'string': ['s', 'char*', 'arrays.str', ''], |
99 } | 102 } |
100 | 103 |
101 | 104 |
| 105 def AddHeader(name): |
| 106 """Adds a header to both the .cc and .h files.""" |
| 107 global HEADER_START |
| 108 global SOURCE_FILE_INCLUDES |
| 109 |
| 110 HEADER_START += "#include \"%s\"\n" % name |
| 111 SOURCE_FILE_INCLUDES += "#include \"%s\"\n" % name |
| 112 |
| 113 |
102 def CountName(name): | 114 def CountName(name): |
103 """Returns the name of the auxiliary count member used for array typed.""" | 115 """Returns the name of the auxiliary count member used for array typed.""" |
104 return '%s_bytes' % name | 116 return '%s_bytes' % name |
105 | 117 |
106 | 118 |
107 def FormatRpcPrototype(is_server, class_name, indent, rpc): | 119 def FormatRpcPrototype(is_server, class_name, indent, rpc): |
108 """Returns a string for the prototype of an individual RPC.""" | 120 """Returns a string for the prototype of an individual RPC.""" |
109 | 121 |
110 def FormatArgs(is_output, args): | 122 def FormatArgs(is_output, args): |
111 """Returns a string containing the formatted arguments for an RPC.""" | 123 """Returns a string containing the formatted arguments for an RPC.""" |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 def MakePath(name): | 329 def MakePath(name): |
318 paths = name.split(os.sep) | 330 paths = name.split(os.sep) |
319 path = os.sep.join(paths[:-1]) | 331 path = os.sep.join(paths[:-1]) |
320 try: | 332 try: |
321 os.makedirs(path) | 333 os.makedirs(path) |
322 except OSError: | 334 except OSError: |
323 return | 335 return |
324 | 336 |
325 | 337 |
326 def main(argv): | 338 def main(argv): |
327 usage = 'Usage: srpcgen.py <-c | -s> [--include=<name>] <iname> <gname>' | 339 usage = 'Usage: srpcgen.py <-c | -s> [--include=<name>] [--ppapi]' |
328 usage = usage + ' <.h> <.cc> <specs>' | 340 usage = usage + ' <iname> <gname> <.h> <.cc> <specs>' |
329 | 341 |
330 mode = None | 342 mode = None |
| 343 ppapi = False |
331 try: | 344 try: |
332 long_opts = ['include='] | 345 long_opts = ['include=', 'ppapi'] |
333 opts, pargs = getopt.getopt(argv[1:], 'cs', long_opts) | 346 opts, pargs = getopt.getopt(argv[1:], 'cs', long_opts) |
334 except getopt.error, e: | 347 except getopt.error, e: |
335 print >>sys.stderr, 'Illegal option:', str(e) | 348 print >>sys.stderr, 'Illegal option:', str(e) |
336 print >>sys.stderr, usage | 349 print >>sys.stderr, usage |
337 return 1 | 350 return 1 |
338 | 351 |
339 # Get the class name for the interface. | 352 # Get the class name for the interface. |
340 interface_name = pargs[0] | 353 interface_name = pargs[0] |
341 # Get the name for the token used as a multiple inclusion guard in the header. | 354 # Get the name for the token used as a multiple inclusion guard in the header. |
342 include_guard_name = pargs[1] | 355 include_guard_name = pargs[1] |
343 # Get the name of the header file to be generated. | 356 # Get the name of the header file to be generated. |
344 h_file_name = pargs[2] | 357 h_file_name = pargs[2] |
345 MakePath(h_file_name) | 358 MakePath(h_file_name) |
346 h_file = open(h_file_name, 'w') | 359 h_file = open(h_file_name, 'w') |
347 # Get the name of the source file to be generated. Depending upon whether | 360 # Get the name of the source file to be generated. Depending upon whether |
348 # -c or -s is generated, this file contains either client or server methods. | 361 # -c or -s is generated, this file contains either client or server methods. |
349 cc_file_name = pargs[3] | 362 cc_file_name = pargs[3] |
350 MakePath(cc_file_name) | 363 MakePath(cc_file_name) |
351 cc_file = open(cc_file_name, 'w') | 364 cc_file = open(cc_file_name, 'w') |
352 # The remaining arguments are the spec files to be compiled. | 365 # The remaining arguments are the spec files to be compiled. |
353 spec_files = pargs[4:] | 366 spec_files = pargs[4:] |
354 | 367 |
355 for opt, val in opts: | 368 for opt, val in opts: |
356 if opt == '-c': | 369 if opt == '-c': |
357 mode = 'client' | 370 mode = 'client' |
358 elif opt == '-s': | 371 elif opt == '-s': |
359 mode = 'server' | 372 mode = 'server' |
360 elif opt == '--include': | 373 elif opt == '--include': |
361 h_file_name = val | 374 h_file_name = val |
| 375 elif opt == '--ppapi': |
| 376 ppapi = True |
| 377 |
| 378 if ppapi: |
| 379 AddHeader("ppapi/c/pp_instance.h") |
| 380 AddHeader("ppapi/c/pp_module.h") |
| 381 AddHeader("ppapi/c/pp_resource.h") |
362 | 382 |
363 # Convert to forward slash paths if needed | 383 # Convert to forward slash paths if needed |
364 h_file_name = "/".join(h_file_name.split("\\")) | 384 h_file_name = "/".join(h_file_name.split("\\")) |
365 | 385 |
366 # Verify we picked server or client mode | 386 # Verify we picked server or client mode |
367 if not mode: | 387 if not mode: |
368 print >>sys.stderr, 'Neither -c nor -s specified' | 388 print >>sys.stderr, 'Neither -c nor -s specified' |
369 usage() | 389 usage() |
370 return 1 | 390 return 1 |
371 | 391 |
372 # Combine the rpc specs from spec_files into rpcs. | 392 # Combine the rpc specs from spec_files into rpcs. |
373 specs = [] | 393 specs = [] |
374 for spec_file in spec_files: | 394 for spec_file in spec_files: |
375 code_obj = compile(open(spec_file, 'r').read(), 'file', 'eval') | 395 code_obj = compile(open(spec_file, 'r').read(), 'file', 'eval') |
376 specs.append(eval(code_obj)) | 396 specs.append(eval(code_obj)) |
377 # Print out the requested files. | 397 # Print out the requested files. |
378 if mode == 'client': | 398 if mode == 'client': |
379 PrintHeaderFile(h_file, False, include_guard_name, interface_name, specs) | 399 PrintHeaderFile(h_file, False, include_guard_name, interface_name, specs) |
380 PrintClientFile(cc_file, h_file_name, specs) | 400 PrintClientFile(cc_file, h_file_name, specs) |
381 elif mode == 'server': | 401 elif mode == 'server': |
382 PrintHeaderFile(h_file, True, include_guard_name, interface_name, specs) | 402 PrintHeaderFile(h_file, True, include_guard_name, interface_name, specs) |
383 PrintServerFile(cc_file, h_file_name, interface_name, specs) | 403 PrintServerFile(cc_file, h_file_name, interface_name, specs) |
384 | 404 |
385 return 0 | 405 return 0 |
386 | 406 |
387 | 407 |
388 if __name__ == '__main__': | 408 if __name__ == '__main__': |
389 sys.exit(main(sys.argv)) | 409 sys.exit(main(sys.argv)) |
OLD | NEW |