dbgfmt.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /**
  2. * \file libyasm/dbgfmt.h
  3. * \brief YASM debug format interface.
  4. *
  5. * \license
  6. * Copyright (C) 2002-2007 Peter Johnson
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. * - Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * - Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS''
  18. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE
  21. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  22. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  23. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  24. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  25. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  26. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  27. * POSSIBILITY OF SUCH DAMAGE.
  28. * \endlicense
  29. */
  30. #ifndef YASM_DBGFMT_H
  31. #define YASM_DBGFMT_H
  32. #ifndef YASM_DOXYGEN
  33. /** Base #yasm_dbgfmt structure. Must be present as the first element in any
  34. * #yasm_dbgfmt implementation.
  35. */
  36. typedef struct yasm_dbgfmt_base {
  37. /** #yasm_dbgfmt_module implementation for this debug format. */
  38. const struct yasm_dbgfmt_module *module;
  39. } yasm_dbgfmt_base;
  40. #endif
  41. /** Debug format module interface. */
  42. struct yasm_dbgfmt_module {
  43. /** One-line description of the debug format. */
  44. const char *name;
  45. /** Keyword used to select debug format. */
  46. const char *keyword;
  47. /** NULL-terminated list of directives. NULL if none. */
  48. /*@null@*/ const yasm_directive *directives;
  49. /** Create debug format.
  50. * Module-level implementation of yasm_dbgfmt_create().
  51. * The filenames are provided solely for informational purposes.
  52. * \param object object
  53. * \return NULL if object format does not provide needed support.
  54. */
  55. /*@null@*/ /*@only@*/ yasm_dbgfmt * (*create) (yasm_object *object);
  56. /** Module-level implementation of yasm_dbgfmt_destroy().
  57. * Call yasm_dbgfmt_destroy() instead of calling this function.
  58. */
  59. void (*destroy) (/*@only@*/ yasm_dbgfmt *dbgfmt);
  60. /** Module-level implementation of yasm_dbgfmt_generate().
  61. * Call yasm_dbgfmt_generate() instead of calling this function.
  62. */
  63. void (*generate) (yasm_object *object, yasm_linemap *linemap,
  64. yasm_errwarns *errwarns);
  65. };
  66. /** Get the keyword used to select a debug format.
  67. * \param dbgfmt debug format
  68. * \return keyword
  69. */
  70. const char *yasm_dbgfmt_keyword(const yasm_dbgfmt *dbgfmt);
  71. /** Initialize debug output for use. Must call before any other debug
  72. * format functions. The filenames are provided solely for informational
  73. * purposes.
  74. * \param module debug format module
  75. * \param object object to generate debugging information for
  76. * \return NULL if object format does not provide needed support.
  77. */
  78. /*@null@*/ /*@only@*/ yasm_dbgfmt *yasm_dbgfmt_create
  79. (const yasm_dbgfmt_module *module, yasm_object *object);
  80. /** Cleans up any allocated debug format memory.
  81. * \param dbgfmt debug format
  82. */
  83. void yasm_dbgfmt_destroy(/*@only@*/ yasm_dbgfmt *dbgfmt);
  84. /** Generate debugging information bytecodes.
  85. * \param object object
  86. * \param linemap virtual/physical line mapping
  87. * \param errwarns error/warning set
  88. * \note Errors and warnings are stored into errwarns.
  89. */
  90. void yasm_dbgfmt_generate(yasm_object *object, yasm_linemap *linemap,
  91. yasm_errwarns *errwarns);
  92. #ifndef YASM_DOXYGEN
  93. /* Inline macro implementations for dbgfmt functions */
  94. #define yasm_dbgfmt_keyword(dbgfmt) \
  95. (((yasm_dbgfmt_base *)dbgfmt)->module->keyword)
  96. #define yasm_dbgfmt_create(module, object) \
  97. module->create(object)
  98. #define yasm_dbgfmt_destroy(dbgfmt) \
  99. ((yasm_dbgfmt_base *)dbgfmt)->module->destroy(dbgfmt)
  100. #define yasm_dbgfmt_generate(object, linemap, ews) \
  101. ((yasm_dbgfmt_base *)((object)->dbgfmt))->module->generate \
  102. (object, linemap, ews)
  103. #endif
  104. #endif