listfmt.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /**
  2. * \file libyasm/listfmt.h
  3. * \brief YASM list format interface.
  4. *
  5. * \license
  6. * Copyright (C) 2004-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_LISTFMT_H
  31. #define YASM_LISTFMT_H
  32. #ifndef YASM_DOXYGEN
  33. /** Base #yasm_listfmt structure. Must be present as the first element in any
  34. * #yasm_listfmt implementation.
  35. */
  36. typedef struct yasm_listfmt_base {
  37. /** #yasm_listfmt_module implementation for this list format. */
  38. const struct yasm_listfmt_module *module;
  39. } yasm_listfmt_base;
  40. #endif
  41. /** YASM list format module interface. */
  42. typedef struct yasm_listfmt_module {
  43. /** One-line description of the list format. */
  44. const char *name;
  45. /** Keyword used to select list format. */
  46. const char *keyword;
  47. /** Create list format.
  48. * Module-level implementation of yasm_listfmt_create().
  49. * The filenames are provided solely for informational purposes.
  50. * \param in_filename primary input filename
  51. * \param obj_filename object filename
  52. * \return NULL if unable to initialize.
  53. */
  54. /*@null@*/ /*@only@*/ yasm_listfmt * (*create)
  55. (const char *in_filename, const char *obj_filename);
  56. /** Module-level implementation of yasm_listfmt_destroy().
  57. * Call yasm_listfmt_destroy() instead of calling this function.
  58. */
  59. void (*destroy) (/*@only@*/ yasm_listfmt *listfmt);
  60. /** Module-level implementation of yasm_listfmt_output().
  61. * Call yasm_listfmt_output() instead of calling this function.
  62. */
  63. void (*output) (yasm_listfmt *listfmt, FILE *f, yasm_linemap *linemap,
  64. yasm_arch *arch);
  65. } yasm_listfmt_module;
  66. /** Get the keyword used to select a list format.
  67. * \param listfmt list format
  68. * \return keyword
  69. */
  70. const char *yasm_listfmt_keyword(const yasm_listfmt *listfmt);
  71. /** Initialize list format for use. Must call before any other list
  72. * format functions. The filenames are provided solely for informational
  73. * purposes.
  74. * \param module list format module
  75. * \param in_filename primary input filename
  76. * \param obj_filename object filename
  77. * \return NULL if object format does not provide needed support.
  78. */
  79. /*@null@*/ /*@only@*/ yasm_listfmt *yasm_listfmt_create
  80. (const yasm_listfmt_module *module, const char *in_filename,
  81. const char *obj_filename);
  82. /** Cleans up any allocated list format memory.
  83. * \param listfmt list format
  84. */
  85. void yasm_listfmt_destroy(/*@only@*/ yasm_listfmt *listfmt);
  86. /** Write out list to the list file.
  87. * This function may call all read-only yasm_* functions as necessary.
  88. * \param listfmt list format
  89. * \param f output list file
  90. * \param linemap line mapping repository
  91. * \param arch architecture
  92. */
  93. void yasm_listfmt_output(yasm_listfmt *listfmt, FILE *f,
  94. yasm_linemap *linemap, yasm_arch *arch);
  95. #ifndef YASM_DOXYGEN
  96. /* Inline macro implementations for listfmt functions */
  97. #define yasm_listfmt_keyword(listfmt) \
  98. (((yasm_listfmt_base *)listfmt)->module->keyword)
  99. #define yasm_listfmt_create(module, in_filename, obj_filename) \
  100. module->create(in_filename, obj_filename)
  101. #define yasm_listfmt_destroy(listfmt) \
  102. ((yasm_listfmt_base *)listfmt)->module->destroy(listfmt)
  103. #define yasm_listfmt_output(listfmt, f, linemap, a) \
  104. ((yasm_listfmt_base *)listfmt)->module->output(listfmt, f, linemap, a)
  105. #endif
  106. #endif