145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/**
245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \file libyasm/insn.h
345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \brief YASM mnenomic instruction.
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_INSN_H
3145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define YASM_INSN_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/** Base structure for an effective address.  As with all base
3845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * structures, must be present as the first element in any
3945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * #yasm_arch implementation of an effective address.
4045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
4145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstruct yasm_effaddr {
4245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    yasm_value disp;            /**< address displacement */
4345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
4445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** Segment register override (0 if none). */
4545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    uintptr_t segreg;
4645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
4745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** 1 if length of disp must be >0. */
4845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    unsigned int need_nonzero_len:1;
4945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
5045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** 1 if a displacement should be present in the output. */
5145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    unsigned int need_disp:1;
5245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
5345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** 1 if reg*2 should not be split into reg+reg. (0 if not).
5445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * This flag indicates (for architectures that support complex effective
5545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * addresses such as x86) if various types of complex effective addresses
5645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * can be split into different forms in order to minimize instruction
5745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * length.
5845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     */
5945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    unsigned int nosplit:1;
6045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
6145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** 1 if effective address is /definitely/ an effective address.
6245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * This is used in e.g. the GAS parser to differentiate
6345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * between "expr" (which might or might not be an effective address) and
6445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * "expr(,1)" (which is definitely an effective address).
6545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     */
6645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    unsigned int strong:1;
6745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
6845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** 1 if effective address is forced PC-relative. */
6945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    unsigned int pc_rel:1;
7045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
7145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** 1 if effective address is forced non-PC-relative. */
7245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    unsigned int not_pc_rel:1;
7345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
7445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** length of pointed data (in bytes), 0 if unknown. */
7545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    unsigned int data_len;
7645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org};
7745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
7845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** An instruction operand (opaque type). */
7945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct yasm_insn_operand yasm_insn_operand;
8045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
8145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** The type of an instruction operand. */
8245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef enum yasm_insn_operand_type {
8345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    YASM_INSN__OPERAND_REG = 1,     /**< A register. */
8445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    YASM_INSN__OPERAND_SEGREG,      /**< A segment register. */
8545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    YASM_INSN__OPERAND_MEMORY,      /**< An effective address
8645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                                     *   (memory reference). */
8745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    YASM_INSN__OPERAND_IMM          /**< An immediate or jump target. */
8845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} yasm_insn_operand_type;
8945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
9045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** An instruction operand. */
9145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstruct yasm_insn_operand {
9245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** Link for building linked list of operands.  \internal */
9345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /*@reldef@*/ STAILQ_ENTRY(yasm_insn_operand) link;
9445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
9545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** Operand data. */
9645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    union {
9745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        uintptr_t reg;      /**< Arch data for reg/segreg. */
9845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        yasm_effaddr *ea;   /**< Effective address for memory references. */
9945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        yasm_expr *val;     /**< Value of immediate or jump target. */
10045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    } data;
10145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
10245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    yasm_expr *seg;         /**< Segment expression */
10345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
10445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    uintptr_t targetmod;        /**< Arch target modifier, 0 if none. */
10545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
10645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** Specified size of the operand, in bits.  0 if not user-specified. */
10745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    unsigned int size:16;
10845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
10945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** Nonzero if dereference.  Used for "*foo" in GAS.
11045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * The reason for this is that by default in GAS, an unprefixed value
11145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * is a memory address, except for jumps/calls, in which case it needs a
11245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * "*" prefix to become a memory address (otherwise it's an immediate).
11345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * This isn't knowable in the parser stage, so the parser sets this flag
11445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * to indicate the "*" prefix has been used, and the arch needs to adjust
11545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * the operand type appropriately depending on the instruction type.
11645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     */
11745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    unsigned int deref:1;
11845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
11945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** Nonzero if strict.  Used for "strict foo" in NASM.
12045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * This is used to inhibit optimization on otherwise "sized" values.
12145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * For example, the user may just want to be explicit with the size on
12245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * "push dword 4", but not actually want to force the immediate size to
12345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * 4 bytes (rather wanting the optimizer to optimize it down to 1 byte as
12445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * though "dword" was not specified).  To indicate the immediate should
12545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * actually be forced to 4 bytes, the user needs to write
12645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     * "push strict dword 4", which sets this flag.
12745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     */
12845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    unsigned int strict:1;
12945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
13045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** Operand type. */
13145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    unsigned int type:4;
13245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org};
13345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
13445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Base structure for "instruction" bytecodes.  These are the mnenomic
13545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * (rather than raw) representation of instructions.  As with all base
13645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * structures, must be present as the first element in any
13745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * #yasm_arch implementation of mnenomic instruction bytecodes.
13845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
13945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstruct yasm_insn {
14045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** Linked list of operands. */
14145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /*@reldef@*/ STAILQ_HEAD(yasm_insn_operands, yasm_insn_operand) operands;
14245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
14345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** Array of prefixes. */
14445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /*@null@*/ uintptr_t *prefixes;
14545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
14645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /** Array of segment prefixes. */
14745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    /*@null@*/ uintptr_t *segregs;
14845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
14945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    unsigned int num_operands;       /**< Number of operands. */
15045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    unsigned int num_prefixes;       /**< Number of prefixes. */
15145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    unsigned int num_segregs;        /**< Number of segment prefixes. */
15245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org};
15345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
15445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Set segment override for an effective address.
15545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * Some architectures (such as x86) support segment overrides on effective
15645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * addresses.  A override of an override will result in a warning.
15745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param ea            effective address
15845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param segreg        segment register (0 if none)
15945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
16045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL
16145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_ea_set_segreg(yasm_effaddr *ea, uintptr_t segreg);
16245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
16345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Create an instruction operand from a register.
16445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param reg   register
16545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Newly allocated operand.
16645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
16745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL
16845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgyasm_insn_operand *yasm_operand_create_reg(uintptr_t reg);
16945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
17045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Create an instruction operand from a segment register.
17145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param segreg        segment register
17245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Newly allocated operand.
17345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
17445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL
17545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgyasm_insn_operand *yasm_operand_create_segreg(uintptr_t segreg);
17645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
17745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Create an instruction operand from an effective address.
17845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param ea    effective address
17945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Newly allocated operand.
18045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
18145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL
18245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgyasm_insn_operand *yasm_operand_create_mem(/*@only@*/ yasm_effaddr *ea);
18345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
18445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Create an instruction operand from an immediate expression.
18545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * Looks for cases of a single register and creates a register variant of
18645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * #yasm_insn_operand.
18745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param val   immediate expression
18845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Newly allocated operand.
18945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
19045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL
19145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgyasm_insn_operand *yasm_operand_create_imm(/*@only@*/ yasm_expr *val);
19245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
19345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Get the first operand in an instruction.
19445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param insn          instruction
19545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return First operand (NULL if no operands).
19645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
19745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgyasm_insn_operand *yasm_insn_ops_first(yasm_insn *insn);
19845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define yasm_insn_ops_first(insn)   STAILQ_FIRST(&((insn)->operands))
19945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
20045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Get the next operand in an instruction.
20145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param op            previous operand
20245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return Next operand (NULL if op was the last operand).
20345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
20445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgyasm_insn_operand *yasm_insn_op_next(yasm_insn_operand *op);
20545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define yasm_insn_op_next(cur)      STAILQ_NEXT(cur, link)
20645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
20745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Add operand to the end of an instruction.
20845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \note Does not make a copy of the operand; so don't pass this function
20945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *       static or local variables, and discard the op pointer after calling
21045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *       this function.
21145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param insn          instruction
21245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param op            operand (may be NULL)
21345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \return If operand was actually appended (it wasn't NULL), the operand;
21445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org *         otherwise NULL.
21545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
21645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL
21745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/*@null@*/ yasm_insn_operand *yasm_insn_ops_append
21845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    (yasm_insn *insn,
21945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org     /*@returned@*/ /*@null@*/ yasm_insn_operand *op);
22045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
22145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Associate a prefix with an instruction.
22245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param insn          instruction
22345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param prefix        data that identifies the prefix
22445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
22545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL
22645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_insn_add_prefix(yasm_insn *insn, uintptr_t prefix);
22745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
22845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Associate a segment prefix with an instruction.
22945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param insn          instruction
23045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param segreg        data that identifies the segment register
23145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
23245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL
23345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_insn_add_seg_prefix(yasm_insn *insn, uintptr_t segreg);
23445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
23545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Initialize the common parts of an instruction.
23645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \internal For use by yasm_arch implementations only.
23745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param insn          instruction
23845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
23945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL
24045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_insn_initialize(/*@out@*/ yasm_insn *insn);
24145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
24245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Delete the common parts of an instruction.
24345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \internal For use by yasm_arch implementations only.
24445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param insn          instruction
24545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param content       if nonzero, deletes content of each operand
24645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param arch          architecture
24745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
24845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL
24945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_insn_delete(yasm_insn *insn,
25045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                      void (*ea_destroy) (/*@only@*/ yasm_effaddr *));
25145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
25245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Print a list of instruction operands.  For debugging purposes.
25345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \internal For use by yasm_arch implementations only.
25445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param insn          instruction
25545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param f             file
25645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param indent_level  indentation level
25745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param arch          architecture
25845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
25945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL
26045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_insn_print(const yasm_insn *insn, FILE *f, int indent_level);
26145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
26245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/** Finalize the common parts of an instruction.
26345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \internal For use by yasm_arch implementations only.
26445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * \param insn          instruction
26545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */
26645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgYASM_LIB_DECL
26745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid yasm_insn_finalize(yasm_insn *insn);
26845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
26945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#endif
270