| OLD | NEW |
| 1 #!/usr/bin/python2.4 | 1 #!/usr/bin/python2.4 |
| 2 # Copyright 2009, Google Inc. | 2 # Copyright (c) 2011 The Native Client Authors. All rights reserved. |
| 3 # All rights reserved. | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 4 # | 5 # |
| 5 # Redistribution and use in source and binary forms, with or without | 6 # Redistribution and use in source and binary forms, with or without |
| 6 # modification, are permitted provided that the following conditions are | 7 # modification, are permitted provided that the following conditions are |
| 7 # met: | 8 # met: |
| 8 # | 9 # |
| 9 # * Redistributions of source code must retain the above copyright | 10 # * Redistributions of source code must retain the above copyright |
| 10 # notice, this list of conditions and the following disclaimer. | 11 # notice, this list of conditions and the following disclaimer. |
| 11 # * Redistributions in binary form must reproduce the above | 12 # * Redistributions in binary form must reproduce the above |
| 12 # copyright notice, this list of conditions and the following disclaimer | 13 # copyright notice, this list of conditions and the following disclaimer |
| 13 # in the documentation and/or other materials provided with the | 14 # in the documentation and/or other materials provided with the |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 # Generate a header file defining the enumeration, and the corresponding functio
n | 188 # Generate a header file defining the enumeration, and the corresponding functio
n |
| 188 # to print out symbolic names for each constant. | 189 # to print out symbolic names for each constant. |
| 189 def _GenerateHeader(enumfile, constants): | 190 def _GenerateHeader(enumfile, constants): |
| 190 filename = _GetHeaderFilename(enumfile) | 191 filename = _GetHeaderFilename(enumfile) |
| 191 outfile = open(filename, "w") | 192 outfile = open(filename, "w") |
| 192 simplified_filename = _GetSimplifiedFilename(filename) | 193 simplified_filename = _GetSimplifiedFilename(filename) |
| 193 _AddDoNotEditMessage(outfile, filename, enumfile) | 194 _AddDoNotEditMessage(outfile, filename, enumfile) |
| 194 enumname = _GetEnumName(enumfile) | 195 enumname = _GetEnumName(enumfile) |
| 195 print >>outfile, "#ifndef %s__" % _GetDefineName(simplified_filename) | 196 print >>outfile, "#ifndef %s__" % _GetDefineName(simplified_filename) |
| 196 print >>outfile, "#define %s__" % _GetDefineName(simplified_filename) | 197 print >>outfile, "#define %s__" % _GetDefineName(simplified_filename) |
| 198 print >>outfile, "" |
| 199 print >>outfile, '#include "native_client/src/include/portability.h"' |
| 200 print >>outfile, "" |
| 201 print >>outfile, "EXTERN_C_BEGIN" |
| 197 print >>outfile, "typedef enum %s {" % enumname | 202 print >>outfile, "typedef enum %s {" % enumname |
| 198 enum_value = 0 | 203 enum_value = 0 |
| 199 for constant in constants: | 204 for constant in constants: |
| 200 print >>outfile, " %s = %d," % (_GetPrintName(constant), enum_value) | 205 print >>outfile, " %s = %d," % (_GetPrintName(constant), enum_value) |
| 201 enum_value += 1 | 206 enum_value += 1 |
| 202 if _ClOptions['add_size']: | 207 if _ClOptions['add_size']: |
| 203 print >>outfile, (" %sEnumSize = %d, " + | 208 print >>outfile, (" %sEnumSize = %d, " + |
| 204 "/* special size marker */") % (enumname, enum_value) | 209 "/* special size marker */") % (enumname, enum_value) |
| 205 print >>outfile, "} %s;" % enumname | 210 print >>outfile, "} %s;" % enumname |
| 206 print >>outfile, "" | 211 print >>outfile, "" |
| 207 print >>outfile, "/* Returns the name of an %s constant. */" % enumname | 212 print >>outfile, "/* Returns the name of an %s constant. */" % enumname |
| 208 print >>outfile, "extern const char* %sName(%s name);" % (enumname, enumname) | 213 print >>outfile, "extern const char* %sName(%s name);" % (enumname, enumname) |
| 209 print >>outfile, "" | 214 print >>outfile, "" |
| 215 print >>outfile, "EXTERN_C_END" |
| 216 print >>outfile, "" |
| 210 print >>outfile, "#endif /* %s__ */" % _GetDefineName(simplified_filename) | 217 print >>outfile, "#endif /* %s__ */" % _GetDefineName(simplified_filename) |
| 211 | 218 |
| 212 # Given the enumeration file name, and the constants defined within that file, | 219 # Given the enumeration file name, and the constants defined within that file, |
| 213 # Generate an implementation file defining the corresponding function to print | 220 # Generate an implementation file defining the corresponding function to print |
| 214 # out symbolic names for each constant. | 221 # out symbolic names for each constant. |
| 215 def _GenerateSource(enumfile, constants): | 222 def _GenerateSource(enumfile, constants): |
| 216 filename = _GetSourceFilename(enumfile) | 223 filename = _GetSourceFilename(enumfile) |
| 217 outfile = open(filename, "w") | 224 outfile = open(filename, "w") |
| 218 _AddDoNotEditMessage(outfile, filename, enumfile) | 225 _AddDoNotEditMessage(outfile, filename, enumfile) |
| 219 enumname = _GetEnumName(enumfile) | 226 enumname = _GetEnumName(enumfile) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 return 1 | 272 return 1 |
| 266 enumfile = command[0] | 273 enumfile = command[0] |
| 267 _ValidateFilename(enumfile) | 274 _ValidateFilename(enumfile) |
| 268 constants = _ApplyFilters(_ReadConstants(enumfile)) | 275 constants = _ApplyFilters(_ReadConstants(enumfile)) |
| 269 _GenerateHeader(enumfile, constants) | 276 _GenerateHeader(enumfile, constants) |
| 270 _GenerateSource(enumfile, constants) | 277 _GenerateSource(enumfile, constants) |
| 271 return 0 | 278 return 0 |
| 272 | 279 |
| 273 if __name__ == '__main__': | 280 if __name__ == '__main__': |
| 274 sys.exit(main(sys.argv[1:])) | 281 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |