OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """code generator for GLES2 command buffers.""" | 6 """code generator for GLES2 command buffers.""" |
7 | 7 |
8 import itertools | 8 import itertools |
9 import os | 9 import os |
10 import os.path | 10 import os.path |
(...skipping 3156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3167 | 3167 |
3168 consts = func.GetCmdConstants() | 3168 consts = func.GetCmdConstants() |
3169 for const in consts: | 3169 for const in consts: |
3170 file.Write(" static const %s %s = %s;\n" % | 3170 file.Write(" static const %s %s = %s;\n" % |
3171 (const.cmd_type, const.name, const.GetConstantValue())) | 3171 (const.cmd_type, const.name, const.GetConstantValue())) |
3172 | 3172 |
3173 file.Write("};\n") | 3173 file.Write("};\n") |
3174 file.Write("\n") | 3174 file.Write("\n") |
3175 | 3175 |
3176 size = len(args) * _SIZE_OF_UINT32 + _SIZE_OF_COMMAND_HEADER | 3176 size = len(args) * _SIZE_OF_UINT32 + _SIZE_OF_COMMAND_HEADER |
3177 file.Write("COMPILE_ASSERT(sizeof(%s) == %d,\n" % (func.name, size)) | 3177 file.Write("static_assert(sizeof(%s) == %d,\n" % (func.name, size)) |
3178 file.Write(" Sizeof_%s_is_not_%d);\n" % (func.name, size)) | 3178 file.Write(" \"size of %s should be %d\");\n" % |
3179 file.Write("COMPILE_ASSERT(offsetof(%s, header) == 0,\n" % func.name) | 3179 (func.name, size)) |
3180 file.Write(" OffsetOf_%s_header_not_0);\n" % func.name) | 3180 file.Write("static_assert(offsetof(%s, header) == 0,\n" % func.name) |
| 3181 file.Write(" \"offset of %s header should be 0\");\n" % |
| 3182 func.name) |
3181 offset = _SIZE_OF_COMMAND_HEADER | 3183 offset = _SIZE_OF_COMMAND_HEADER |
3182 for arg in args: | 3184 for arg in args: |
3183 file.Write("COMPILE_ASSERT(offsetof(%s, %s) == %d,\n" % | 3185 file.Write("static_assert(offsetof(%s, %s) == %d,\n" % |
3184 (func.name, arg.name, offset)) | 3186 (func.name, arg.name, offset)) |
3185 file.Write(" OffsetOf_%s_%s_not_%d);\n" % | 3187 file.Write(" \"offset of %s %s should be %d\");\n" % |
3186 (func.name, arg.name, offset)) | 3188 (func.name, arg.name, offset)) |
3187 offset += _SIZE_OF_UINT32 | 3189 offset += _SIZE_OF_UINT32 |
3188 if not result == None and len(result) > 1: | 3190 if not result == None and len(result) > 1: |
3189 offset = 0; | 3191 offset = 0; |
3190 for line in result: | 3192 for line in result: |
3191 parts = line.split() | 3193 parts = line.split() |
3192 name = parts[-1] | 3194 name = parts[-1] |
3193 check = """ | 3195 check = """ |
3194 COMPILE_ASSERT(offsetof(%(cmd_name)s::Result, %(field_name)s) == %(offset)d, | 3196 static_assert(offsetof(%(cmd_name)s::Result, %(field_name)s) == %(offset)d, |
3195 OffsetOf_%(cmd_name)s_Result_%(field_name)s_not_%(offset)d); | 3197 "offset of %(cmd_name)s Result %(field_name)s should be " |
| 3198 "%(offset)d"); |
3196 """ | 3199 """ |
3197 file.Write((check.strip() + "\n") % { | 3200 file.Write((check.strip() + "\n") % { |
3198 'cmd_name': func.name, | 3201 'cmd_name': func.name, |
3199 'field_name': name, | 3202 'field_name': name, |
3200 'offset': offset, | 3203 'offset': offset, |
3201 }) | 3204 }) |
3202 offset += _SIZE_OF_UINT32 | 3205 offset += _SIZE_OF_UINT32 |
3203 file.Write("\n") | 3206 file.Write("\n") |
3204 | 3207 |
3205 def WriteHandlerImplementation(self, func, file): | 3208 def WriteHandlerImplementation(self, func, file): |
(...skipping 6027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9233 Format(gen.generated_cpp_filenames) | 9236 Format(gen.generated_cpp_filenames) |
9234 | 9237 |
9235 if gen.errors > 0: | 9238 if gen.errors > 0: |
9236 print "%d errors" % gen.errors | 9239 print "%d errors" % gen.errors |
9237 return 1 | 9240 return 1 |
9238 return 0 | 9241 return 0 |
9239 | 9242 |
9240 | 9243 |
9241 if __name__ == '__main__': | 9244 if __name__ == '__main__': |
9242 sys.exit(main(sys.argv[1:])) | 9245 sys.exit(main(sys.argv[1:])) |
OLD | NEW |