Home | History | Annotate | Download | only in vulkan-validation-layers
      1 #!/usr/bin/env python3
      2 #
      3 # Copyright (c) 2015-2016 The Khronos Group Inc.
      4 # Copyright (c) 2015-2016 Valve Corporation
      5 # Copyright (c) 2015-2016 LunarG, Inc.
      6 # Copyright (c) 2015-2016 Google Inc.
      7 #
      8 # Permission is hereby granted, free of charge, to any person obtaining a copy
      9 # of this software and/or associated documentation files (the "Materials"), to
     10 # deal in the Materials without restriction, including without limitation the
     11 # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
     12 # sell copies of the Materials, and to permit persons to whom the Materials
     13 # are furnished to do so, subject to the following conditions:
     14 #
     15 # The above copyright notice(s) and this permission notice shall be included
     16 # in all copies or substantial portions of the Materials.
     17 #
     18 # THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     19 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     20 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
     21 #
     22 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
     23 # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
     24 # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
     25 # USE OR OTHER DEALINGS IN THE MATERIALS
     26 #
     27 # Author: Tobin Ehlis <tobin (at] lunarg.com>
     28 
     29 from inspect import currentframe, getframeinfo
     30 
     31 # This is a wrapper class for inspect module that returns a formatted line
     32 #  with details of the source file and line number of python code who called
     33 #  into this class. The result can them be added to codegen to simplify
     34 #  debug as it shows where code was generated from.
     35 class sourcelineinfo():
     36     def __init__(self):
     37         self.general_prefix = "// CODEGEN : "
     38         self.file_prefix = "file "
     39         self.line_prefix = "line #"
     40         self.enabled = True
     41 
     42     def get(self):
     43         if self.enabled:
     44             frameinfo = getframeinfo(currentframe().f_back)
     45             return "%s%s%s %s%s" % (self.general_prefix, self.file_prefix, frameinfo.filename, self.line_prefix, frameinfo.lineno)
     46         return ""
     47