cv-dbgfmt.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * CodeView debugging formats implementation for Yasm
  3. *
  4. * Copyright (C) 2006-2007 Peter Johnson
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS''
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE
  19. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  20. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  21. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  25. * POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #include <util.h>
  28. #include <libyasm.h>
  29. #include "cv-dbgfmt.h"
  30. yasm_dbgfmt_module yasm_cv8_LTX_dbgfmt;
  31. static /*@null@*/ /*@only@*/ yasm_dbgfmt *
  32. cv_dbgfmt_create(yasm_object *object, yasm_dbgfmt_module *module, int version)
  33. {
  34. yasm_dbgfmt_cv *dbgfmt_cv = yasm_xmalloc(sizeof(yasm_dbgfmt_cv));
  35. size_t i;
  36. dbgfmt_cv->dbgfmt.module = module;
  37. dbgfmt_cv->filenames_allocated = 32;
  38. dbgfmt_cv->filenames_size = 0;
  39. dbgfmt_cv->filenames =
  40. yasm_xmalloc(sizeof(cv_filename)*dbgfmt_cv->filenames_allocated);
  41. for (i=0; i<dbgfmt_cv->filenames_allocated; i++) {
  42. dbgfmt_cv->filenames[i].pathname = NULL;
  43. dbgfmt_cv->filenames[i].filename = NULL;
  44. dbgfmt_cv->filenames[i].str_off = 0;
  45. dbgfmt_cv->filenames[i].info_off = 0;
  46. }
  47. dbgfmt_cv->version = version;
  48. return (yasm_dbgfmt *)dbgfmt_cv;
  49. }
  50. static /*@null@*/ /*@only@*/ yasm_dbgfmt *
  51. cv8_dbgfmt_create(yasm_object *object)
  52. {
  53. return cv_dbgfmt_create(object, &yasm_cv8_LTX_dbgfmt, 8);
  54. }
  55. static void
  56. cv_dbgfmt_destroy(/*@only@*/ yasm_dbgfmt *dbgfmt)
  57. {
  58. yasm_dbgfmt_cv *dbgfmt_cv = (yasm_dbgfmt_cv *)dbgfmt;
  59. size_t i;
  60. for (i=0; i<dbgfmt_cv->filenames_size; i++) {
  61. if (dbgfmt_cv->filenames[i].pathname)
  62. yasm_xfree(dbgfmt_cv->filenames[i].pathname);
  63. }
  64. yasm_xfree(dbgfmt_cv->filenames);
  65. yasm_xfree(dbgfmt);
  66. }
  67. /* Add a bytecode to a section, updating offset on insertion;
  68. * no optimization necessary.
  69. */
  70. yasm_bytecode *
  71. yasm_cv__append_bc(yasm_section *sect, yasm_bytecode *bc)
  72. {
  73. yasm_bytecode *precbc = yasm_section_bcs_last(sect);
  74. bc->offset = yasm_bc_next_offset(precbc);
  75. yasm_section_bcs_append(sect, bc);
  76. return precbc;
  77. }
  78. static void
  79. cv_dbgfmt_generate(yasm_object *object, yasm_linemap *linemap,
  80. yasm_errwarns *errwarns)
  81. {
  82. yasm_cv__generate_symline(object, linemap, errwarns);
  83. yasm_cv__generate_type(object);
  84. }
  85. /* Define dbgfmt structure -- see dbgfmt.h for details */
  86. yasm_dbgfmt_module yasm_cv8_LTX_dbgfmt = {
  87. "CodeView debugging format for VC8",
  88. "cv8",
  89. NULL, /* no directives */
  90. cv8_dbgfmt_create,
  91. cv_dbgfmt_destroy,
  92. cv_dbgfmt_generate
  93. };