145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/**
245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \file libyasm/arch.h
345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \brief YASM architecture 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 *  - 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_ARCH_H
3145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_ARCH_H
3245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
3345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Errors that may be returned by yasm_arch_module::create(). */
3445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef enum yasm_arch_create_error {
3545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    YASM_ARCH_CREATE_OK = 0,            /**< No error. */
3645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    YASM_ARCH_CREATE_BAD_MACHINE,       /**< Unrecognized machine name. */
3745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    YASM_ARCH_CREATE_BAD_PARSER         /**< Unrecognized parser name. */
3845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} yasm_arch_create_error;
3945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
4045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Return values for yasm_arch_module::parse_check_insnprefix(). */
4145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef enum yasm_arch_insnprefix {
4245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    YASM_ARCH_NOTINSNPREFIX = 0,        /**< Unrecognized */
4345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    YASM_ARCH_INSN,                     /**< An instruction */
4445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    YASM_ARCH_PREFIX                    /**< An instruction prefix */
4545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} yasm_arch_insnprefix;
4645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
4745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Types of registers / target modifiers that may be returned by
4845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * yasm_arch_module::parse_check_regtmod().
4945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
5045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef enum yasm_arch_regtmod {
5145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    YASM_ARCH_NOTREGTMOD = 0,           /**< Unrecognized */
5245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    YASM_ARCH_REG,                      /**< A "normal" register */
5345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    YASM_ARCH_REGGROUP,                 /**< A group of indexable registers */
5445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    YASM_ARCH_SEGREG,                   /**< A segment register */
5545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    YASM_ARCH_TARGETMOD                 /**< A target modifier (for jumps) */
5645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} yasm_arch_regtmod;
5745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
5845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#ifndef YASM_DOXYGEN
5945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Base #yasm_arch structure.  Must be present as the first element in any
6045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * #yasm_arch implementation.
6145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
6245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_arch_base {
6345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** #yasm_arch_module implementation for this architecture. */
6445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    const struct yasm_arch_module *module;
6545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} yasm_arch_base;
6645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#endif
6745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
6845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** YASM machine subtype.  A number of different machine types may be
6945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * associated with a single architecture.  These may be specific CPU's, but
7045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * the ABI used to interface with the architecture should be the primary
7145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * differentiator between machines.  Some object formats (ELF) use the machine
7245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * to determine parameters within the generated output.
7345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
7445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_arch_machine {
7545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** One-line description of the machine. */
7645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    const char *name;
7745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
7845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** Keyword used to select machine. */
7945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    const char *keyword;
8045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} yasm_arch_machine;
8145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
8245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** YASM architecture module interface.
8345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \note All "data" in parser-related functions (yasm_arch_parse_*) needs to
8445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *       start the parse initialized to 0 to make it okay for a parser-related
8545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *       function to use/check previously stored data to see if it's been
8645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *       called before on the same piece of data.
8745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
8845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_arch_module {
8945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** One-line description of the architecture.
9045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * Call yasm_arch_name() to get the name of a particular #yasm_arch.
9145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     */
9245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    const char *name;
9345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
9445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** Keyword used to select architecture.
9545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * Call yasm_arch_keyword() to get the keyword of a particular #yasm_arch.
9645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     */
9745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    const char *keyword;
9845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
9945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** NULL-terminated list of directives.  NULL if none. */
10045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /*@null@*/ const yasm_directive *directives;
10145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
10245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** Create architecture.
10345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * Module-level implementation of yasm_arch_create().
10445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * Call yasm_arch_create() instead of calling this function.
10545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     */
10645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /*@only@*/ yasm_arch * (*create) (const char *machine, const char *parser,
10745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                                      /*@out@*/ yasm_arch_create_error *error);
10845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
10945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** Module-level implementation of yasm_arch_destroy().
11045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * Call yasm_arch_destroy() instead of calling this function.
11145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     */
11245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    void (*destroy) (/*@only@*/ yasm_arch *arch);
11345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
11445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** Module-level implementation of yasm_arch_get_machine().
11545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * Call yasm_arch_get_machine() instead of calling this function.
11645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     */
11745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    const char * (*get_machine) (const yasm_arch *arch);
11845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
11945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** Module-level implementation of yasm_arch_get_address_size().
12045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * Call yasm_arch_get_address_size() instead of calling this function.
12145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     */
12245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    unsigned int (*get_address_size) (const yasm_arch *arch);
12345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
12445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** Module-level implementation of yasm_arch_set_var().
12545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * Call yasm_arch_set_var() instead of calling this function.
12645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     */
12745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    int (*set_var) (yasm_arch *arch, const char *var, unsigned long val);
12845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
12945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** Module-level implementation of yasm_arch_parse_check_insnprefix().
13045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * Call yasm_arch_parse_check_insnprefix() instead of calling this function.
13145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     */
13245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    yasm_arch_insnprefix (*parse_check_insnprefix)
13345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        (yasm_arch *arch, const char *id, size_t id_len, unsigned long line,
13445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org         /*@out@*/ /*@only@*/ yasm_bytecode **bc, /*@out@*/ uintptr_t *prefix);
13545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
13645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** Module-level implementation of yasm_arch_parse_check_regtmod().
13745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * Call yasm_arch_parse_check_regtmod() instead of calling this function.
13845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     */
13945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    yasm_arch_regtmod (*parse_check_regtmod)
14045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        (yasm_arch *arch, const char *id, size_t id_len,
14145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org         /*@out@*/ uintptr_t *data);
14245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
14345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** Module-level implementation of yasm_arch_get_fill().
14445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * Call yasm_arch_get_fill() instead of calling this function.
14545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     */
14645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    const unsigned char ** (*get_fill) (const yasm_arch *arch);
14745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
14845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** Module-level implementation of yasm_arch_floatnum_tobytes().
14945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * Call yasm_arch_floatnum_tobytes() instead of calling this function.
15045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     */
15145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    int (*floatnum_tobytes) (yasm_arch *arch, const yasm_floatnum *flt,
15245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                             unsigned char *buf, size_t destsize,
15345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                             size_t valsize, size_t shift, int warn);
15445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
15545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** Module-level implementation of yasm_arch_intnum_tobytes().
15645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * Call yasm_arch_intnum_tobytes() instead of calling this function.
15745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     */
15845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    int (*intnum_tobytes) (yasm_arch *arch, const yasm_intnum *intn,
15945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                           unsigned char *buf, size_t destsize, size_t valsize,
16045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                           int shift, const yasm_bytecode *bc,
16145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                           int warn);
16245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
16345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** Module-level implementation of yasm_arch_get_reg_size().
16445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * Call yasm_arch_get_reg_size() instead of calling this function.
16545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     */
16645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    unsigned int (*get_reg_size) (yasm_arch *arch, uintptr_t reg);
16745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
16845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** Module-level implementation of yasm_arch_reggroup_get_reg().
16945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * Call yasm_arch_reggroup_get_reg() instead of calling this function.
17045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     */
17145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    uintptr_t (*reggroup_get_reg) (yasm_arch *arch, uintptr_t reggroup,
17245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                                   unsigned long regindex);
17345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
17445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** Module-level implementation of yasm_arch_reg_print().
17545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * Call yasm_arch_reg_print() instead of calling this function.
17645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     */
17745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    void (*reg_print) (yasm_arch *arch, uintptr_t reg, FILE *f);
17845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
17945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** Module-level implementation of yasm_arch_segreg_print().
18045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * Call yasm_arch_segreg_print() instead of calling this function.
18145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     */
18245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    void (*segreg_print) (yasm_arch *arch, uintptr_t segreg, FILE *f);
18345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
18445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** Module-level implementation of yasm_arch_ea_create().
18545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * Call yasm_arch_ea_create() instead of calling this function.
18645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     */
18745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    yasm_effaddr * (*ea_create) (yasm_arch *arch, /*@keep@*/ yasm_expr *e);
18845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
18945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** Module-level implementation of yasm_arch_ea_destroy().
19045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * Call yasm_arch_ea_destroy() instead of calling this function.
19145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     */
19245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    void (*ea_destroy) (/*@only@*/ yasm_effaddr *ea);
19345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
19445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** Module-level implementation of yasm_arch_ea_print().
19545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * Call yasm_arch_ea_print() instead of calling this function.
19645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     */
19745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    void (*ea_print) (const yasm_effaddr *ea, FILE *f, int indent_level);
19845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
19945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** Module-level implementation of yasm_arch_create_empty_insn().
20045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * Call yasm_arch_create_empty_insn() instead of calling this function.
20145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     */
20245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /*@only@*/ yasm_bytecode * (*create_empty_insn) (yasm_arch *arch,
20345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                                                     unsigned long line);
20445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
20545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** NULL-terminated list of machines for this architecture.
20645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * Call yasm_arch_get_machine() to get the active machine of a particular
20745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * #yasm_arch.
20845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     */
20945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    const yasm_arch_machine *machines;
21045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
21145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** Default machine keyword.
21245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * Call yasm_arch_get_machine() to get the active machine of a particular
21345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * #yasm_arch.
21445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     */
21545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    const char *default_machine_keyword;
21645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
21745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** Canonical "word" size in bits.
21845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * Call yasm_arch_wordsize() to get the word size of a particular
21945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * #yasm_arch.
22045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     */
22145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    unsigned int wordsize;
22245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
22345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** Worst case minimum instruction length in bytes.
22445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * Call yasm_arch_min_insn_len() to get the minimum instruction length of
22545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * a particular #yasm_arch.
22645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     */
22745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    unsigned int min_insn_len;
22845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} yasm_arch_module;
22945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
23045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Get the one-line description of an architecture.
23145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param arch      architecture
23245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return One-line description of architecture.
23345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
23445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgconst char *yasm_arch_name(const yasm_arch *arch);
23545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
23645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Get the keyword used to select an architecture.
23745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param arch      architecture
23845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Architecture keyword.
23945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
24045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgconst char *yasm_arch_keyword(const yasm_arch *arch);
24145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
24245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Get the word size of an architecture.
24345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param arch      architecture
24445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Word size (in bits).
24545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
24645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgunsigned int yasm_arch_wordsize(const yasm_arch *arch);
24745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
24845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Get the minimum instruction length of an architecture.
24945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param arch      architecture
25045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Minimum instruction length (in bytes).
25145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
25245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgunsigned int yasm_arch_min_insn_len(const yasm_arch *arch);
25345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
25445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Create architecture.
25545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param module        architecture module
25645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param machine       keyword of machine in use (must be one listed in
25745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *                      #yasm_arch_module.machines)
25845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param parser        keyword of parser in use
25945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param error         error return value
26045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return NULL on error (error returned in error parameter), otherwise new
26145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *         architecture.
26245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
26345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/*@only@*/ yasm_arch *yasm_arch_create(const yasm_arch_module *module,
26445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                                       const char *machine, const char *parser,
26545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                                       /*@out@*/ yasm_arch_create_error *error);
26645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
26745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Clean up, free any architecture-allocated memory.
26845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param arch  architecture
26945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
27045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_arch_destroy(/*@only@*/ yasm_arch *arch);
27145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
27245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Get architecture's active machine name.
27345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param arch  architecture
27445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Active machine name.
27545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
27645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgconst char *yasm_arch_get_machine(const yasm_arch *arch);
27745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
27845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Get architecture's active address size, in bits.
27945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param arch  architecture
28045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Active address size (in bits).
28145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
28245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgunsigned int yasm_arch_get_address_size(const yasm_arch *arch);
28345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
28445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Set any arch-specific variables.  For example, "mode_bits" in x86.
28545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param arch  architecture
28645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param var   variable name
28745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param val   value to set
28845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Zero on success, non-zero on failure (variable does not exist).
28945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
29045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgint yasm_arch_set_var(yasm_arch *arch, const char *var, unsigned long val);
29145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
29245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Check an generic identifier to see if it matches architecture specific
29345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * names for instructions or instruction prefixes.  Unrecognized identifiers
29445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * should return #YASM_ARCH_NOTINSNPREFIX so they can be treated as normal
29545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * symbols.  Any additional data beyond just the type (almost always necessary)
29645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * should be returned into the space provided by the data parameter.
29745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param arch          architecture
29845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param id            identifier as in the input file
29945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param id_len        length of id string
30045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param line          virtual line
30145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param bc            for instructions, yasm_insn-based bytecode is returned
30245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *                      (and NULL otherwise)
30345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param prefix        for prefixes, yasm_arch-specific value is returned
30445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *                      (and 0 otherwise)
30545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Identifier type (#YASM_ARCH_NOTINSNPREFIX if unrecognized)
30645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
30745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgyasm_arch_insnprefix yasm_arch_parse_check_insnprefix
30845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    (yasm_arch *arch, const char *id, size_t id_len, unsigned long line,
30945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     /*@out@*/ /*@only@*/ yasm_bytecode **bc, /*@out@*/ uintptr_t *prefix);
31045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
31145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Check an generic identifier to see if it matches architecture specific
31245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * names for registers or target modifiers.  Unrecognized identifiers should
31345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * return #YASM_ARCH_NOTREGTMOD.  Any additional data beyond just the type
31445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * (almost always necessary) should be returned into the space provided by the
31545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * data parameter.
31645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param arch          architecture
31745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param id            identifier as in the input file
31845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param id_len        length of id string
31945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param data          extra identification information (yasm_arch-specific)
32045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *                      [output]
32145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Identifier type (#YASM_ARCH_NOTREGTMOD if unrecognized)
32245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
32345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgyasm_arch_regtmod yasm_arch_parse_check_regtmod
32445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    (yasm_arch *arch, const char *id, size_t id_len,
32545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     /*@out@*/ uintptr_t *data);
32645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
32745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Get NOP fill patterns for 1-15 bytes of fill.
32845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param arch          architecture
32945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return 16-entry array of arrays; [0] is unused, [1] - [15] point to arrays
33045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * of 1-15 bytes (respectively) in length.
33145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
33245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgconst unsigned char **yasm_arch_get_fill(const yasm_arch *arch);
33345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
33445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Output #yasm_floatnum to buffer.  Puts the value into the least
33545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * significant bits of the destination, or may be shifted into more
33645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * significant bits by the shift parameter.  The destination bits are
33745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * cleared before being set.
33845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * Architecture-specific because of endianness.
33945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param arch          architecture
34045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param flt           floating point value
34145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param buf           buffer to write into
34245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param destsize      destination size (in bytes)
34345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param valsize       size (in bits)
34445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param shift         left shift (in bits)
34545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param warn          enables standard overflow/underflow warnings
34645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Nonzero on error.
34745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
34845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgint yasm_arch_floatnum_tobytes(yasm_arch *arch, const yasm_floatnum *flt,
34945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                               unsigned char *buf, size_t destsize,
35045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                               size_t valsize, size_t shift, int warn);
35145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
35245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Output #yasm_intnum to buffer.  Puts the value into the least
35345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * significant bits of the destination, or may be shifted into more
35445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * significant bits by the shift parameter.  The destination bits are
35545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * cleared before being set.
35645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param arch          architecture
35745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param intn          integer value
35845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param buf           buffer to write into
35945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param destsize      destination size (in bytes)
36045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param valsize       size (in bits)
36145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param shift         left shift (in bits); may be negative to specify right
36245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *                      shift (standard warnings include truncation to boundary)
36345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param bc            bytecode being output ("parent" of value)
36445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param warn          enables standard warnings (value doesn't fit into
36545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *                      valsize bits)
36645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Nonzero on error.
36745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
36845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgint yasm_arch_intnum_tobytes(yasm_arch *arch, const yasm_intnum *intn,
36945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                             unsigned char *buf, size_t destsize,
37045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                             size_t valsize, int shift,
37145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                             const yasm_bytecode *bc, int warn);
37245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
37345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Get the equivalent size of a register in bits.
37445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param arch  architecture
37545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param reg   register
37645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return 0 if there is no suitable equivalent size, otherwise the size.
37745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
37845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgunsigned int yasm_arch_get_reg_size(yasm_arch *arch, uintptr_t reg);
37945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
38045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Get a specific register of a register group, based on the register
38145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * group and the index within the group.
38245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param arch          architecture
38345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param reggroup      register group
38445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param regindex      register index
38545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return 0 if regindex is not valid for that register group, otherwise the
38645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *         specific register value.
38745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
38845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orguintptr_t yasm_arch_reggroup_get_reg(yasm_arch *arch, uintptr_t reggroup,
38945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                                     unsigned long regindex);
39045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
39145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Print a register.  For debugging purposes.
39245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param arch          architecture
39345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param reg           register
39445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param f             file
39545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
39645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_arch_reg_print(yasm_arch *arch, uintptr_t reg, FILE *f);
39745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
39845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Print a segment register.  For debugging purposes.
39945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param arch          architecture
40045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param segreg        segment register
40145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param f             file
40245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
40345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_arch_segreg_print(yasm_arch *arch, uintptr_t segreg, FILE *f);
40445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
40545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Create an effective address from an expression.
40645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param arch  architecture
40745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param e     expression (kept, do not delete)
40845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Newly allocated effective address.
40945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
41045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgyasm_effaddr *yasm_arch_ea_create(yasm_arch *arch, /*@keep@*/ yasm_expr *e);
41145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
41245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Delete (free allocated memory for) an effective address.
41345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param arch  architecture
41445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param ea    effective address (only pointer to it).
41545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
41645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_arch_ea_destroy(yasm_arch *arch, /*@only@*/ yasm_effaddr *ea);
41745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
41845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Print an effective address.  For debugging purposes.
41945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param arch          architecture
42045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param ea            effective address
42145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param f             file
42245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param indent_level  indentation level
42345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
42445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_arch_ea_print(const yasm_arch *arch, const yasm_effaddr *ea,
42545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                        FILE *f, int indent_level);
42645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
42745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Create a bytecode that represents a single empty (0 length) instruction.
42845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * This is used for handling solitary prefixes.
42945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param arch          architecture
43045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param line          virtual line (from yasm_linemap)
43145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Newly allocated bytecode.
43245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
43345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/*@only@*/ yasm_bytecode *yasm_arch_create_empty_insn(yasm_arch *arch,
43445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                                                      unsigned long line);
43545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
43645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#ifndef YASM_DOXYGEN
43745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
43845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* Inline macro implementations for arch functions */
43945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
44045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define yasm_arch_name(arch) \
44145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    (((yasm_arch_base *)arch)->module->name)
44245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define yasm_arch_keyword(arch) \
44345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    (((yasm_arch_base *)arch)->module->keyword)
44445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define yasm_arch_wordsize(arch) \
44545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    (((yasm_arch_base *)arch)->module->wordsize)
44645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define yasm_arch_min_insn_len(arch) \
44745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    (((yasm_arch_base *)arch)->module->min_insn_len)
44845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
44945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define yasm_arch_create(module, machine, parser, error) \
45045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    module->create(machine, parser, error)
45145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
45245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define yasm_arch_destroy(arch) \
45345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    ((yasm_arch_base *)arch)->module->destroy(arch)
45445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define yasm_arch_get_machine(arch) \
45545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    ((yasm_arch_base *)arch)->module->get_machine(arch)
45645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define yasm_arch_get_address_size(arch) \
45745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    ((yasm_arch_base *)arch)->module->get_address_size(arch)
45845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define yasm_arch_set_var(arch, var, val) \
45945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    ((yasm_arch_base *)arch)->module->set_var(arch, var, val)
46045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define yasm_arch_parse_check_insnprefix(arch, id, id_len, line, bc, prefix) \
46145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    ((yasm_arch_base *)arch)->module->parse_check_insnprefix \
46245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        (arch, id, id_len, line, bc, prefix)
46345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define yasm_arch_parse_check_regtmod(arch, id, id_len, data) \
46445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    ((yasm_arch_base *)arch)->module->parse_check_regtmod \
46545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        (arch, id, id_len, data)
46645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define yasm_arch_get_fill(arch) \
46745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    ((yasm_arch_base *)arch)->module->get_fill(arch)
46845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define yasm_arch_floatnum_tobytes(arch, flt, buf, destsize, valsize, shift, \
46945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                                   warn) \
47045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    ((yasm_arch_base *)arch)->module->floatnum_tobytes \
47145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        (arch, flt, buf, destsize, valsize, shift, warn)
47245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define yasm_arch_intnum_tobytes(arch, intn, buf, destsize, valsize, shift, \
47345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                                 bc, warn) \
47445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    ((yasm_arch_base *)arch)->module->intnum_tobytes \
47545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        (arch, intn, buf, destsize, valsize, shift, bc, warn)
47645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define yasm_arch_get_reg_size(arch, reg) \
47745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    ((yasm_arch_base *)arch)->module->get_reg_size(arch, reg)
47845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define yasm_arch_reggroup_get_reg(arch, regg, regi) \
47945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    ((yasm_arch_base *)arch)->module->reggroup_get_reg(arch, regg, regi)
48045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define yasm_arch_reg_print(arch, reg, f) \
48145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    ((yasm_arch_base *)arch)->module->reg_print(arch, reg, f)
48245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define yasm_arch_segreg_print(arch, segreg, f) \
48345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    ((yasm_arch_base *)arch)->module->segreg_print(arch, segreg, f)
48445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define yasm_arch_ea_create(arch, e) \
48545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    ((yasm_arch_base *)arch)->module->ea_create(arch, e)
48645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define yasm_arch_ea_destroy(arch, ea) \
48745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    ((yasm_arch_base *)arch)->module->ea_destroy(ea)
48845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define yasm_arch_ea_print(arch, ea, f, i) \
48945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    ((yasm_arch_base *)arch)->module->ea_print(ea, f, i)
49045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define yasm_arch_create_empty_insn(arch, line) \
49145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    ((yasm_arch_base *)arch)->module->create_empty_insn(arch, line)
49245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
49345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#endif
49445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
49545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#endif
496