145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** 245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \file libyasm/listfmt.h 345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \brief YASM list format interface. 445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \license 645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * Copyright (C) 2004-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 * - Redistributions of source code must retain the above copyright 1245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * notice, this list of conditions and the following disclaimer. 1345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * - 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_LISTFMT_H 3145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_LISTFMT_H 3245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 3345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#ifndef YASM_DOXYGEN 3445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Base #yasm_listfmt structure. Must be present as the first element in any 3545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * #yasm_listfmt implementation. 3645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 3745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_listfmt_base { 3845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /** #yasm_listfmt_module implementation for this list format. */ 3945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org const struct yasm_listfmt_module *module; 4045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} yasm_listfmt_base; 4145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#endif 4245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 4345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** YASM list format module interface. */ 4445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_listfmt_module { 4545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /** One-line description of the list format. */ 4645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org const char *name; 4745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 4845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /** Keyword used to select list format. */ 4945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org const char *keyword; 5045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 5145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /** Create list format. 5245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * Module-level implementation of yasm_listfmt_create(). 5345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * The filenames are provided solely for informational purposes. 5445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param in_filename primary input filename 5545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param obj_filename object filename 5645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return NULL if unable to initialize. 5745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 5845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /*@null@*/ /*@only@*/ yasm_listfmt * (*create) 5945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (const char *in_filename, const char *obj_filename); 6045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 6145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /** Module-level implementation of yasm_listfmt_destroy(). 6245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * Call yasm_listfmt_destroy() instead of calling this function. 6345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 6445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org void (*destroy) (/*@only@*/ yasm_listfmt *listfmt); 6545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 6645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /** Module-level implementation of yasm_listfmt_output(). 6745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * Call yasm_listfmt_output() instead of calling this function. 6845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 6945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org void (*output) (yasm_listfmt *listfmt, FILE *f, yasm_linemap *linemap, 7045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_arch *arch); 7145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} yasm_listfmt_module; 7245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 7345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Get the keyword used to select a list format. 7445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param listfmt list format 7545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return keyword 7645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 7745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgconst char *yasm_listfmt_keyword(const yasm_listfmt *listfmt); 7845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 7945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Initialize list format for use. Must call before any other list 8045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * format functions. The filenames are provided solely for informational 8145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * purposes. 8245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param module list format module 8345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param in_filename primary input filename 8445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param obj_filename object filename 8545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return NULL if object format does not provide needed support. 8645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 8745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/*@null@*/ /*@only@*/ yasm_listfmt *yasm_listfmt_create 8845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (const yasm_listfmt_module *module, const char *in_filename, 8945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org const char *obj_filename); 9045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 9145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Cleans up any allocated list format memory. 9245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param listfmt list format 9345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 9445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_listfmt_destroy(/*@only@*/ yasm_listfmt *listfmt); 9545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 9645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Write out list to the list file. 9745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * This function may call all read-only yasm_* functions as necessary. 9845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param listfmt list format 9945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param f output list file 10045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param linemap line mapping repository 10145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param arch architecture 10245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 10345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_listfmt_output(yasm_listfmt *listfmt, FILE *f, 10445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_linemap *linemap, yasm_arch *arch); 10545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 10645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#ifndef YASM_DOXYGEN 10745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 10845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* Inline macro implementations for listfmt functions */ 10945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 11045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define yasm_listfmt_keyword(listfmt) \ 11145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (((yasm_listfmt_base *)listfmt)->module->keyword) 11245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 11345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define yasm_listfmt_create(module, in_filename, obj_filename) \ 11445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org module->create(in_filename, obj_filename) 11545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 11645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define yasm_listfmt_destroy(listfmt) \ 11745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ((yasm_listfmt_base *)listfmt)->module->destroy(listfmt) 11845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 11945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define yasm_listfmt_output(listfmt, f, linemap, a) \ 12045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ((yasm_listfmt_base *)listfmt)->module->output(listfmt, f, linemap, a) 12145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 12245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#endif 12345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 12445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#endif 125