Yasm Assembler mainline development tree (ffmpeg 依赖)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
4.0 KiB

/*
* CodeView debugging formats implementation for Yasm
*
* Copyright (C) 2006 Peter Johnson
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <util.h>
/*@unused@*/ RCSID("$Id$");
#define YASM_LIB_INTERNAL
#define YASM_BC_INTERNAL
#include <libyasm.h>
#include "cv-dbgfmt.h"
yasm_dbgfmt_module yasm_cv8_LTX_dbgfmt;
static /*@null@*/ /*@only@*/ yasm_dbgfmt *
cv_dbgfmt_create(yasm_object *object, yasm_objfmt *of, yasm_arch *a,
yasm_dbgfmt_module *module, int version)
{
yasm_dbgfmt_cv *dbgfmt_cv = yasm_xmalloc(sizeof(yasm_dbgfmt_cv));
size_t i;
dbgfmt_cv->dbgfmt.module = module;
dbgfmt_cv->object = object;
dbgfmt_cv->symtab = yasm_object_get_symtab(object);
dbgfmt_cv->linemap = yasm_object_get_linemap(object);
dbgfmt_cv->arch = a;
dbgfmt_cv->filenames_allocated = 32;
dbgfmt_cv->filenames_size = 0;
dbgfmt_cv->filenames =
yasm_xmalloc(sizeof(cv_filename)*dbgfmt_cv->filenames_allocated);
for (i=0; i<dbgfmt_cv->filenames_allocated; i++) {
dbgfmt_cv->filenames[i].pathname = NULL;
dbgfmt_cv->filenames[i].filename = NULL;
dbgfmt_cv->filenames[i].str_off = 0;
dbgfmt_cv->filenames[i].info_off = 0;
}
dbgfmt_cv->version = version;
return (yasm_dbgfmt *)dbgfmt_cv;
}
static /*@null@*/ /*@only@*/ yasm_dbgfmt *
cv8_dbgfmt_create(yasm_object *object, yasm_objfmt *of, yasm_arch *a)
{
return cv_dbgfmt_create(object, of, a, &yasm_cv8_LTX_dbgfmt, 8);
}
static void
cv_dbgfmt_destroy(/*@only@*/ yasm_dbgfmt *dbgfmt)
{
yasm_dbgfmt_cv *dbgfmt_cv = (yasm_dbgfmt_cv *)dbgfmt;
size_t i;
for (i=0; i<dbgfmt_cv->filenames_size; i++) {
if (dbgfmt_cv->filenames[i].pathname)
yasm_xfree(dbgfmt_cv->filenames[i].pathname);
}
yasm_xfree(dbgfmt_cv->filenames);
yasm_xfree(dbgfmt);
}
/* Add a bytecode to a section, updating offset on insertion;
* no optimization necessary.
*/
yasm_bytecode *
yasm_cv__append_bc(yasm_section *sect, yasm_bytecode *bc)
{
yasm_bytecode *precbc = yasm_section_bcs_last(sect);
bc->offset = yasm_bc_next_offset(precbc);
yasm_section_bcs_append(sect, bc);
return precbc;
}
static void
Revamp error/warning handling, using a model similar to Python's internal exception handling. There are now two layers an error or warning goes through before it hits the user: first an error is logged via yasm_error_set() (or yasm_warn_set() for a warning). Only one error may be set, whereas multiple warnings can be set (yasm_warn_set maintains a linked list). Then, calling yasm_errwarn_propagate() propagates any error and/or warning(s) to an errwarns structure and associates the errors/warnings with a line number at that time; this call also clears the pending errors/warnings and allows new ones to be set. The propagate function can safely be called when there are no pending error/warnings. In addition, there are some helper errwarn functions that allow clearing of an error/warning without propagating, getting it separately, etc. Still yet to be done: changing most/all uses of yasm_internal_error() into yasm_error_set(YASM_ERROR_ASSERTION). The main advantage this change has is making libyasm functions feel much more library like, and separating the user code line numbers from the inner function error handling (e.g. intnum create functions only needed the line number to trigger errors; this is no longer required). The set/propagate/etc functions use global data structures to avoid passing around a pointer to every function. This would need to be made thread-local data in a threaded app. Errwarns containers (that keep associated line numbers) are no longer global, so multiple source streams can be processed separately with no conflict (at least if there's only a single thread of execution). svn path=/trunk/yasm/; revision=1521
19 years ago
cv_dbgfmt_generate(yasm_dbgfmt *dbgfmt, yasm_errwarns *errwarns)
{
yasm_dbgfmt_cv *dbgfmt_cv = (yasm_dbgfmt_cv *)dbgfmt;
Revamp error/warning handling, using a model similar to Python's internal exception handling. There are now two layers an error or warning goes through before it hits the user: first an error is logged via yasm_error_set() (or yasm_warn_set() for a warning). Only one error may be set, whereas multiple warnings can be set (yasm_warn_set maintains a linked list). Then, calling yasm_errwarn_propagate() propagates any error and/or warning(s) to an errwarns structure and associates the errors/warnings with a line number at that time; this call also clears the pending errors/warnings and allows new ones to be set. The propagate function can safely be called when there are no pending error/warnings. In addition, there are some helper errwarn functions that allow clearing of an error/warning without propagating, getting it separately, etc. Still yet to be done: changing most/all uses of yasm_internal_error() into yasm_error_set(YASM_ERROR_ASSERTION). The main advantage this change has is making libyasm functions feel much more library like, and separating the user code line numbers from the inner function error handling (e.g. intnum create functions only needed the line number to trigger errors; this is no longer required). The set/propagate/etc functions use global data structures to avoid passing around a pointer to every function. This would need to be made thread-local data in a threaded app. Errwarns containers (that keep associated line numbers) are no longer global, so multiple source streams can be processed separately with no conflict (at least if there's only a single thread of execution). svn path=/trunk/yasm/; revision=1521
19 years ago
yasm_cv__generate_symline(dbgfmt_cv, errwarns);
yasm_cv__generate_type(dbgfmt_cv);
}
static int
cv_dbgfmt_directive(yasm_dbgfmt *dbgfmt, const char *name,
yasm_section *sect, yasm_valparamhead *valparams,
unsigned long line)
{
return 1; /* TODO */
}
/* Define dbgfmt structure -- see dbgfmt.h for details */
yasm_dbgfmt_module yasm_cv8_LTX_dbgfmt = {
"CodeView debugging format for VC8",
"cv8",
cv8_dbgfmt_create,
cv_dbgfmt_destroy,
cv_dbgfmt_directive,
cv_dbgfmt_generate
};