1 /*BEGIN_LEGAL
2 
3 Copyright (c) 2018 Intel Corporation
4 
5   Licensed under the Apache License, Version 2.0 (the "License");
6   you may not use this file except in compliance with the License.
7   You may obtain a copy of the License at
8 
9       http://www.apache.org/licenses/LICENSE-2.0
10 
11   Unless required by applicable law or agreed to in writing, software
12   distributed under the License is distributed on an "AS IS" BASIS,
13   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   See the License for the specific language governing permissions and
15   limitations under the License.
16 
17 END_LEGAL */
18 /// @file xed-encode.c
19 
20 ////////////////////////////////////////////////////////////////////////////
21 // This file contains the public interface to the encoder.
22 ////////////////////////////////////////////////////////////////////////////
23 #include "xed-internal-header.h"
24 #include "xed-encode-private.h"
25 #include "xed-operand-accessors.h"
26 
xed_encoder_request_init_from_decode(xed_decoded_inst_t * d)27 void  xed_encoder_request_init_from_decode(xed_decoded_inst_t* d) {
28     // copy the non-suppressed operands to the encode order array
29     const xed_inst_t* inst = d->_inst;
30     const xed_uint_t noperands = xed_inst_noperands(inst);
31     xed_uint_t i, eops=0;
32     for( i=0;i<noperands;i++) {
33         const xed_operand_t* o = xed_inst_operand(inst,i);
34         const xed_operand_visibility_enum_t vis = xed_operand_operand_visibility(o);
35         if (vis != XED_OPVIS_SUPPRESSED) {
36             xed_assert(eops < XED_ENCODE_ORDER_MAX_OPERANDS);
37             d->_operand_order[eops++] = xed_operand_name(o);
38         }
39     }
40     d->_n_operand_order=eops;
41 
42     // the decoder does not set the iclass field
43     xed3_operand_set_iclass(d,xed_decoded_inst_get_iclass(d));
44 
45     if (xed3_operand_get_mem0(d))
46         xed_decoded_inst_cache_memory_operand_length(d);
47 
48 
49     xed3_operand_set_rex(d,0);
50     xed3_operand_set_rexb(d,0);
51     xed3_operand_set_rexr(d,0);
52     xed3_operand_set_rexw(d,0);
53     xed3_operand_set_rexx(d,0);
54     xed3_operand_set_norex(d,0);
55     xed3_operand_set_needrex(d,0);
56     xed3_operand_set_osz(d,0);
57 }
58