2
* \file libyasm/linemap.h
3
* \brief YASM virtual line mapping interface.
6
* Copyright (C) 2002-2007 Peter Johnson
8
* Redistribution and use in source and binary forms, with or without
9
* modification, are permitted provided that the following conditions
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.
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.
30
#ifndef YASM_LINEMAP_H
31
#define YASM_LINEMAP_H
37
/** Create a new line mapping repository.
38
* \return New repository.
41
yasm_linemap *yasm_linemap_create(void);
43
/** Clean up any memory allocated for a repository.
44
* \param linemap line mapping repository
47
void yasm_linemap_destroy(yasm_linemap *linemap);
49
/** Get the current line position in a repository.
50
* \param linemap line mapping repository
51
* \return Current virtual line.
54
unsigned long yasm_linemap_get_current(yasm_linemap *linemap);
56
/** Get bytecode and source line information, if any, for a virtual line.
57
* \param linemap line mapping repository
58
* \param line virtual line
59
* \param bcp pointer to return bytecode into
60
* \param sourcep pointer to return source code line pointer into
61
* \return Zero if source line information available for line, nonzero if not.
62
* \note If source line information is not available, bcp and sourcep targets
66
int yasm_linemap_get_source(yasm_linemap *linemap, unsigned long line,
67
/*@null@*/ yasm_bytecode **bcp,
68
const char **sourcep);
70
/** Add bytecode and source line information to the current virtual line.
71
* \attention Deletes any existing bytecode and source line information for
72
* the current virtual line.
73
* \param linemap line mapping repository
74
* \param bc bytecode (if any)
75
* \param source source code line
76
* \note The source code line pointer is NOT kept, it is strdup'ed.
79
void yasm_linemap_add_source(yasm_linemap *linemap,
80
/*@null@*/ yasm_bytecode *bc,
83
/** Go to the next line (increments the current virtual line).
84
* \param linemap line mapping repository
85
* \return The current (new) virtual line.
88
unsigned long yasm_linemap_goto_next(yasm_linemap *linemap);
90
/** Set a new file/line physical association starting point at the specified
91
* virtual line. line_inc indicates how much the "real" line is incremented
92
* by for each virtual line increment (0 is perfectly legal).
93
* \param linemap line mapping repository
94
* \param filename physical file name (if NULL, not changed)
95
* \param virtual_line virtual line number (if 0, linemap->current is used)
96
* \param file_line physical line number
97
* \param line_inc line increment
100
void yasm_linemap_set(yasm_linemap *linemap, /*@null@*/ const char *filename,
101
unsigned long virtual_line, unsigned long file_line,
102
unsigned long line_inc);
104
/** Poke a single file/line association, restoring the original physical
105
* association starting point. Caution: increments the current virtual line
107
* \param linemap line mapping repository
108
* \param filename physical file name (if NULL, not changed)
109
* \param file_line physical line number
110
* \return The virtual line number of the poked association.
113
unsigned long yasm_linemap_poke(yasm_linemap *linemap,
114
/*@null@*/ const char *filename,
115
unsigned long file_line);
117
/** Look up the associated physical file and line for a virtual line.
118
* \param linemap line mapping repository
119
* \param line virtual line
120
* \param filename physical file name (output)
121
* \param file_line physical line number (output)
124
void yasm_linemap_lookup(yasm_linemap *linemap, unsigned long line,
125
/*@out@*/ const char **filename,
126
/*@out@*/ unsigned long *file_line);
128
/** Traverses all filenames used in a linemap, calling a function on each
130
* \param linemap line mapping repository
131
* \param d data pointer passed to func on each call
132
* \param func function
133
* \return Stops early (and returns func's return value) if func returns a
134
* nonzero value; otherwise 0.
137
int yasm_linemap_traverse_filenames
138
(yasm_linemap *linemap, /*@null@*/ void *d,
139
int (*func) (const char *filename, void *d));