diff options
author | Peter Johnson <peter@tortall.net> | 2010-01-03 01:58:23 +0000 |
---|---|---|
committer | Peter Johnson <peter@tortall.net> | 2010-01-03 01:58:23 +0000 |
commit | b3d84a814873f7e4376d6d7fdc138b525097ad31 (patch) | |
tree | 62f48aa782518e2137ae4b3e6ab3f5ad62c80b05 /libyasm | |
parent | 5501768adbef05e82ffb5b62a0fc40a702b3f49a (diff) | |
download | yasm-b3d84a814873f7e4376d6d7fdc138b525097ad31.tar.gz |
Implement some linemap changes required for the GAS preprocessor.
Contributed by: Alexei Svitkine <alexei.svitkine@gmail.com>
- yasm_linemap_set() now takes virtual_line as a parameter, instead of
always using linemap->current. If 0 is passed for the virtual_line,
then linemap->current is used, as before.
This is because linemap->current was only incremented by the parser
(and never decremented), so the preprocessor was not able to set
mappings during the preprocessing phase (whereas with these changes,
it now does).
Additionally, setting a mapping for a line number will now delete any
existing mappings for line numbers equal or greater to that line
number. This allows the code to correctly handle the case when the
preprocessor first sets mappings from pre-pp lines to post-pp lines,
and later those mappings getting superseded by .line directives in the
original source.
This change also required making a change to yasm_linemap_lookup() to
set *file_line to 0 when line is 0 (i.e. preventing line 0 - which
means "don't display line number in output" - from getting mapped).
svn path=/trunk/yasm/; revision=2259
Diffstat (limited to 'libyasm')
-rw-r--r-- | libyasm/linemap.c | 48 | ||||
-rw-r--r-- | libyasm/linemap.h | 6 |
2 files changed, 37 insertions, 17 deletions
diff --git a/libyasm/linemap.c b/libyasm/linemap.c index 926c3102..abee7482 100644 --- a/libyasm/linemap.c +++ b/libyasm/linemap.c @@ -80,22 +80,40 @@ filename_delete_one(/*@only@*/ void *d) void yasm_linemap_set(yasm_linemap *linemap, const char *filename, - unsigned long file_line, unsigned long line_inc) + unsigned long virtual_line, unsigned long file_line, + unsigned long line_inc) { char *copy; + unsigned long i; int replace = 0; - line_mapping *mapping; + line_mapping *mapping = NULL; - /* Create a new mapping in the map */ - if (linemap->map_size >= linemap->map_allocated) { - /* allocate another size bins when full for 2x space */ - linemap->map_vector = - yasm_xrealloc(linemap->map_vector, 2*linemap->map_allocated - *sizeof(line_mapping)); - linemap->map_allocated *= 2; + if (virtual_line == 0) { + virtual_line = linemap->current; + } + + /* Replace all existing mappings that have line numbers >= this one. */ + for (i = linemap->map_size; i > 0; i--) { + if (linemap->map_vector[i-1].line < virtual_line) { + if (i < linemap->map_size) { + mapping = &linemap->map_vector[i]; + linemap->map_size = i + 1; + } + break; + } + } + + if (mapping == NULL) { + /* Create a new mapping in the map */ + if (linemap->map_size >= linemap->map_allocated) { + /* allocate another size bins when full for 2x space */ + linemap->map_vector = yasm_xrealloc(linemap->map_vector, + 2*linemap->map_allocated*sizeof(line_mapping)); + linemap->map_allocated *= 2; + } + mapping = &linemap->map_vector[linemap->map_size]; + linemap->map_size++; } - mapping = &linemap->map_vector[linemap->map_size]; - linemap->map_size++; /* Fill it */ @@ -115,7 +133,7 @@ yasm_linemap_set(yasm_linemap *linemap, const char *filename, /*@=aliasunique@*/ } - mapping->line = linemap->current; + mapping->line = virtual_line; mapping->file_line = file_line; mapping->line_inc = line_inc; } @@ -128,14 +146,14 @@ yasm_linemap_poke(yasm_linemap *linemap, const char *filename, line_mapping *mapping; linemap->current++; - yasm_linemap_set(linemap, filename, file_line, 0); + yasm_linemap_set(linemap, filename, 0, file_line, 0); mapping = &linemap->map_vector[linemap->map_size-1]; line = linemap->current; linemap->current++; - yasm_linemap_set(linemap, mapping->filename, + yasm_linemap_set(linemap, mapping->filename, 0, mapping->file_line + mapping->line_inc*(linemap->current-2-mapping->line), mapping->line_inc); @@ -249,7 +267,7 @@ yasm_linemap_lookup(yasm_linemap *linemap, unsigned long line, mapping = &linemap->map_vector[vindex]; *filename = mapping->filename; - *file_line = mapping->file_line + mapping->line_inc*(line-mapping->line); + *file_line = (line ? mapping->file_line + mapping->line_inc*(line-mapping->line) : 0); } int diff --git a/libyasm/linemap.h b/libyasm/linemap.h index 03912551..e916c6d0 100644 --- a/libyasm/linemap.h +++ b/libyasm/linemap.h @@ -91,17 +91,19 @@ void yasm_linemap_add_source(yasm_linemap *linemap, YASM_LIB_DECL unsigned long yasm_linemap_goto_next(yasm_linemap *linemap); -/** Set a new file/line physical association starting point at the current +/** Set a new file/line physical association starting point at the specified * virtual line. line_inc indicates how much the "real" line is incremented * by for each virtual line increment (0 is perfectly legal). * \param linemap line mapping repository * \param filename physical file name (if NULL, not changed) + * \param virtual_line virtual line number (if 0, linemap->current is used) * \param file_line physical line number * \param line_inc line increment */ YASM_LIB_DECL void yasm_linemap_set(yasm_linemap *linemap, /*@null@*/ const char *filename, - unsigned long file_line, unsigned long line_inc); + unsigned long virtual_line, unsigned long file_line, + unsigned long line_inc); /** Poke a single file/line association, restoring the original physical * association starting point. Caution: increments the current virtual line |