linemap.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /**
  2. * \file libyasm/linemap.h
  3. * \brief YASM virtual line mapping 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. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. 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_LINEMAP_H
  31. #define YASM_LINEMAP_H
  32. #ifndef YASM_LIB_DECL
  33. #define YASM_LIB_DECL
  34. #endif
  35. /** Create a new line mapping repository.
  36. * \return New repository.
  37. */
  38. YASM_LIB_DECL
  39. yasm_linemap *yasm_linemap_create(void);
  40. /** Clean up any memory allocated for a repository.
  41. * \param linemap line mapping repository
  42. */
  43. YASM_LIB_DECL
  44. void yasm_linemap_destroy(yasm_linemap *linemap);
  45. /** Get the current line position in a repository.
  46. * \param linemap line mapping repository
  47. * \return Current virtual line.
  48. */
  49. YASM_LIB_DECL
  50. unsigned long yasm_linemap_get_current(yasm_linemap *linemap);
  51. /** Get bytecode and source line information, if any, for a virtual line.
  52. * \param linemap line mapping repository
  53. * \param line virtual line
  54. * \param bcp pointer to return bytecode into
  55. * \param sourcep pointer to return source code line pointer into
  56. * \return Zero if source line information available for line, nonzero if not.
  57. * \note If source line information is not available, bcp and sourcep targets
  58. * are set to NULL.
  59. */
  60. YASM_LIB_DECL
  61. int yasm_linemap_get_source(yasm_linemap *linemap, unsigned long line,
  62. /*@null@*/ yasm_bytecode **bcp,
  63. const char **sourcep);
  64. /** Add bytecode and source line information to the current virtual line.
  65. * \attention Deletes any existing bytecode and source line information for
  66. * the current virtual line.
  67. * \param linemap line mapping repository
  68. * \param bc bytecode (if any)
  69. * \param source source code line
  70. * \note The source code line pointer is NOT kept, it is strdup'ed.
  71. */
  72. YASM_LIB_DECL
  73. void yasm_linemap_add_source(yasm_linemap *linemap,
  74. /*@null@*/ yasm_bytecode *bc,
  75. const char *source);
  76. /** Go to the next line (increments the current virtual line).
  77. * \param linemap line mapping repository
  78. * \return The current (new) virtual line.
  79. */
  80. YASM_LIB_DECL
  81. unsigned long yasm_linemap_goto_next(yasm_linemap *linemap);
  82. /** Set a new file/line physical association starting point at the specified
  83. * virtual line. line_inc indicates how much the "real" line is incremented
  84. * by for each virtual line increment (0 is perfectly legal).
  85. * \param linemap line mapping repository
  86. * \param filename physical file name (if NULL, not changed)
  87. * \param virtual_line virtual line number (if 0, linemap->current is used)
  88. * \param file_line physical line number
  89. * \param line_inc line increment
  90. */
  91. YASM_LIB_DECL
  92. void yasm_linemap_set(yasm_linemap *linemap, /*@null@*/ const char *filename,
  93. unsigned long virtual_line, unsigned long file_line,
  94. unsigned long line_inc);
  95. /** Poke a single file/line association, restoring the original physical
  96. * association starting point. Caution: increments the current virtual line
  97. * twice.
  98. * \param linemap line mapping repository
  99. * \param filename physical file name (if NULL, not changed)
  100. * \param file_line physical line number
  101. * \return The virtual line number of the poked association.
  102. */
  103. YASM_LIB_DECL
  104. unsigned long yasm_linemap_poke(yasm_linemap *linemap,
  105. /*@null@*/ const char *filename,
  106. unsigned long file_line);
  107. /** Look up the associated physical file and line for a virtual line.
  108. * \param linemap line mapping repository
  109. * \param line virtual line
  110. * \param filename physical file name (output)
  111. * \param file_line physical line number (output)
  112. */
  113. YASM_LIB_DECL
  114. void yasm_linemap_lookup(yasm_linemap *linemap, unsigned long line,
  115. /*@out@*/ const char **filename,
  116. /*@out@*/ unsigned long *file_line);
  117. /** Traverses all filenames used in a linemap, calling a function on each
  118. * filename.
  119. * \param linemap line mapping repository
  120. * \param d data pointer passed to func on each call
  121. * \param func function
  122. * \return Stops early (and returns func's return value) if func returns a
  123. * nonzero value; otherwise 0.
  124. */
  125. YASM_LIB_DECL
  126. int yasm_linemap_traverse_filenames
  127. (yasm_linemap *linemap, /*@null@*/ void *d,
  128. int (*func) (const char *filename, void *d));
  129. #endif