145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** 245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \file libyasm/linemap.h 345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \brief YASM virtual line mapping interface. 445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \license 645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * Copyright (C) 2002-2007 Peter Johnson 745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * Redistribution and use in source and binary forms, with or without 945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * modification, are permitted provided that the following conditions 1045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * are met: 1145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 1. Redistributions of source code must retain the above copyright 1245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * notice, this list of conditions and the following disclaimer. 1345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 2. Redistributions in binary form must reproduce the above copyright 1445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * notice, this list of conditions and the following disclaimer in the 1545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * documentation and/or other materials provided with the distribution. 1645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 1745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS'' 1845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE 2145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * POSSIBILITY OF SUCH DAMAGE. 2845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \endlicense 2945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 3045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#ifndef YASM_LINEMAP_H 3145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_LINEMAP_H 3245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 3345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#ifndef YASM_LIB_DECL 3445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_LIB_DECL 3545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#endif 3645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 3745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Create a new line mapping repository. 3845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return New repository. 3945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 4045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 4145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgyasm_linemap *yasm_linemap_create(void); 4245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 4345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Clean up any memory allocated for a repository. 4445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param linemap line mapping repository 4545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 4645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 4745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_linemap_destroy(yasm_linemap *linemap); 4845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 4945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Get the current line position in a repository. 5045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param linemap line mapping repository 5145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Current virtual line. 5245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 5345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 5445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgunsigned long yasm_linemap_get_current(yasm_linemap *linemap); 5545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 5645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Get bytecode and source line information, if any, for a virtual line. 5745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param linemap line mapping repository 5845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param line virtual line 5945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param bcp pointer to return bytecode into 6045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param sourcep pointer to return source code line pointer into 6145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Zero if source line information available for line, nonzero if not. 6245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \note If source line information is not available, bcp and sourcep targets 6345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * are set to NULL. 6445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 6545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 6645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgint yasm_linemap_get_source(yasm_linemap *linemap, unsigned long line, 6745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /*@null@*/ yasm_bytecode **bcp, 6845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org const char **sourcep); 6945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 7045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Add bytecode and source line information to the current virtual line. 7145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \attention Deletes any existing bytecode and source line information for 7245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * the current virtual line. 7345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param linemap line mapping repository 7445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param bc bytecode (if any) 7545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param source source code line 7645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \note The source code line pointer is NOT kept, it is strdup'ed. 7745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 7845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 7945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_linemap_add_source(yasm_linemap *linemap, 8045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /*@null@*/ yasm_bytecode *bc, 8145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org const char *source); 8245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 8345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Go to the next line (increments the current virtual line). 8445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param linemap line mapping repository 8545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return The current (new) virtual line. 8645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 8745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 8845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgunsigned long yasm_linemap_goto_next(yasm_linemap *linemap); 8945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 90a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org/** Set a new file/line physical association starting point at the specified 9145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * virtual line. line_inc indicates how much the "real" line is incremented 9245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * by for each virtual line increment (0 is perfectly legal). 9345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param linemap line mapping repository 9445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param filename physical file name (if NULL, not changed) 95a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org * \param virtual_line virtual line number (if 0, linemap->current is used) 9645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param file_line physical line number 9745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param line_inc line increment 9845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 9945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 10045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_linemap_set(yasm_linemap *linemap, /*@null@*/ const char *filename, 101a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org unsigned long virtual_line, unsigned long file_line, 102a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org unsigned long line_inc); 10345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 10445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Poke a single file/line association, restoring the original physical 10545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * association starting point. Caution: increments the current virtual line 10645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * twice. 10745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param linemap line mapping repository 10845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param filename physical file name (if NULL, not changed) 10945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param file_line physical line number 11045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return The virtual line number of the poked association. 11145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 11245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 11345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgunsigned long yasm_linemap_poke(yasm_linemap *linemap, 11445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /*@null@*/ const char *filename, 11545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org unsigned long file_line); 11645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 11745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Look up the associated physical file and line for a virtual line. 11845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param linemap line mapping repository 11945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param line virtual line 12045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param filename physical file name (output) 12145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param file_line physical line number (output) 12245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 12345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 12445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_linemap_lookup(yasm_linemap *linemap, unsigned long line, 12545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /*@out@*/ const char **filename, 12645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /*@out@*/ unsigned long *file_line); 12745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 12845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Traverses all filenames used in a linemap, calling a function on each 12945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * filename. 13045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param linemap line mapping repository 13145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param d data pointer passed to func on each call 13245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param func function 13345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Stops early (and returns func's return value) if func returns a 13445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * nonzero value; otherwise 0. 13545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 13645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL 13745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgint yasm_linemap_traverse_filenames 13845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (yasm_linemap *linemap, /*@null@*/ void *d, 13945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org int (*func) (const char *filename, void *d)); 14045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 14145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#endif 142