Debian Codegraph @

include/fcml_common.hpp

raw
1 /*
2 * FCML - Free Code Manipulation Library.
3 * Copyright (C) 2010-2020 Slawomir Wojtasiak
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 /** @file fcml_common.hpp
21 * C++ wrappers common classes.
22 *
23 * @copyright Copyright (C) 2010-2020 Slawomir Wojtasiak. All rights reserved.
24 * This project is released under the GNU Lesser General Public License.
25 */
26
27 #ifndef FCML_COMMON_HPP_
28 #define FCML_COMMON_HPP_
29
30 #include <stdlib.h>
31 #include <string.h>
32 #include <new>
33 #include <iostream>
34 #include <sstream>
35 #include <stdexcept>
36 #include <memory>
37 #include <vector>
38
39 #include "fcml_types.h"
40 #include "fcml_common.h"
41 #include "fcml_common_utils.h"
42 #include "fcml_errors.h"
43
44 namespace fcml {
45
46 #define FCML_TO_CPP_BOOL( x ) ( (x) ? true : false )
47
48 /**
49 * By using this type definition here, it will be definitely much
50 * easier to support UNICODE in future releases.
51 * @since 1.1.0
52 */
53 typedef std::basic_string<fcml_char> fcml_cstring;
54
55 /**
56 * String output stream.
57 * @since 1.1.0
58 */
59 typedef std::basic_ostringstream<fcml_char> fcml_costream;
60
61 /**
62 * Exposes API responsible for environment specific operations, even if standard CPP library is used
63 * to implement them.
64 *
65 * @since 1.1.0
66 * @remarks Internal API, not intended to be used outside.
67 */
68 class Env {
69 public:
70 /**
71 * @throw std::bad_alloc
72 * @since 1.1.0
73 */
74 static fcml_string strDup( const fcml_string str ) {
75 if ( !str ) {
76 return NULL;
77 }
78 #if defined(FCML_MSCC)
79 fcml_string newStr = _strdup( str );
80 #else
81 fcml_string newStr = strdup( str );
82 #endif
83 if ( !newStr ) {
84 throw std::bad_alloc();
85 }
86 return newStr;
87 }
88 static void strFree( fcml_string str ) {
89 free( str );
90 }
91 };
92
93 /**
94 * A base iterator interface.
95 * @since 1.1.0
96 */
97 template <typename T>
98 class Iterator {
99 public:
100
101 Iterator() {}
102
103 virtual ~Iterator() {}
104
105 /**
106 * Gets true if there is an another element in the iterator.
107 */
108 virtual bool hasNext() = 0;
109
110 /**
111 * Gets a next element from the iterator.
112 */
113 virtual T next() = 0;
114 };
115
116 /** Wrapper for nullable value types.
117 * @since 1.1.0
118 */
119 template<typename T>
120 class Nullable {
121 public:
122
123 Nullable( const T& value, bool is_not_null = true ) :
124 _value( value ), _is_not_null( is_not_null ) {
125 }
126
127 Nullable() :
128 _is_not_null( false ) {
129 }
130
131 bool isNotNull() const {
132 return _is_not_null;
133 }
134
135 void setNotNull(bool isNull) {
136 _is_not_null = isNull;
137 }
138
139 T getValue() const {
140 return _value;
141 }
142
143 T& getValue() {
144 return _value;
145 }
146
147 void setValue(const T& value) {
148 this->_value = value;
149 }
150
151 public:
152
153 /**
154 * Checks if two nullable values are equal.
155 *
156 * @param nullable The source nullable value.
157 * @return True if they are equal; otherwise false.
158 * @since 1.2.0
159 */
160 bool operator==(const Nullable &nullable) const {
161 return _value == nullable._value &&
162 _is_not_null == nullable._is_not_null;
163 }
164
165 /**
166 * Checks if two nullable values are not equal.
167 *
168 * @param nullable The source nullable value.
169 * @return True if they are not equal; otherwise false.
170 * @since 1.2.0
171 */
172 bool operator!=(const Nullable &nullable) const {
173 return !(nullable == *this);
174 }
175
176 private:
177 /** Value. */
178 T _value;
179 /** Information if value is set or not. */
180 bool _is_not_null;
181 };
182
183 /**
184 * Base exception for all exceptions exposed by FCML library.
185 * @since 1.1.0
186 */
187 class BaseException {
188 public:
189 BaseException( fcml_ceh_error error = FCML_CEH_GEC_NO_ERROR ) {
190 this->_error = error;
191 }
192 BaseException( const fcml_cstring &msg, fcml_ceh_error error = FCML_CEH_GEC_NO_ERROR ) {
193 this->_msg = msg;
194 this->_error = error;
195 }
196 BaseException( const BaseException &cpy ) {
197 this->_msg = cpy._msg;
198 this->_error = cpy._error;
199 }
200 virtual ~BaseException() {
201 }
202 BaseException& operator=( const BaseException &exc ) {
203 if ( &exc != this ) {
204 this->_msg = exc._msg;
205 this->_error = exc._error;
206 }
207 return *this;
208 }
209 public:
210 const fcml_cstring getMsg() const {
211 return _msg;
212 }
213 const fcml_ceh_error& getError() const {
214 return _error;
215 }
216 private:
217 void* operator new( size_t size ) {
218 return ::operator new( size );
219 }
220 private:
221 /** Error message. */
222 fcml_cstring _msg;
223 /** Error code */
224 fcml_ceh_error _error;
225 };
226
227 /**
228 * Component can not be initialized correctly.
229 * @since 1.1.0
230 */
231 class InitException: public BaseException {
232 public:
233 InitException( const fcml_cstring &msg, fcml_ceh_error error = FCML_CEH_GEC_NO_ERROR ) :
234 BaseException( msg, error ) {
235 }
236 };
237
238 /**
239 * Bad arguments.
240 * @since 1.1.0
241 */
242 class BadArgumentException: public BaseException {
243 public:
244 BadArgumentException( const fcml_cstring &msg, fcml_ceh_error error = FCML_CEH_GEC_NO_ERROR ) :
245 BaseException( msg, error ) {
246 }
247 };
248
249 /**
250 * Illegal state exception.
251 * @since 1.1.0
252 */
253 class IllegalStateException: public BaseException {
254 public:
255 IllegalStateException( const fcml_cstring &msg, fcml_ceh_error error = FCML_CEH_GEC_NO_ERROR ) :
256 BaseException( msg, error ) {
257 }
258 };
259
260 /**
261 * Illegal argument exception.
262 * @since 1.1.0
263 */
264 class IllegalArgumentException: public BaseException {
265 public:
266 IllegalArgumentException( const fcml_cstring &msg, fcml_ceh_error error = FCML_CEH_GEC_NO_ERROR ) :
267 BaseException( msg, error ) {
268 }
269 };
270
271 /**
272 * Operation is not supported.
273 * @since 1.1.0
274 */
275 class OperationNotSupportedException: public BaseException {
276 public:
277 OperationNotSupportedException( const fcml_cstring &msg ) :
278 BaseException( msg ) {
279 }
280 OperationNotSupportedException() {
281 }
282 };
283
284 /**
285 * Object which shouldn't be copied can inherit from this class.
286 * @since 1.1.0
287 */
288 class NonCopyable {
289 protected:
290 NonCopyable() {
291 }
292 private:
293 /**
294 * @throw OperationNotSupportedException
295 */
296 NonCopyable( const NonCopyable &cpy ) {
297 throw OperationNotSupportedException();
298 }
299 /**
300 * @throw OperationNotSupportedException
301 */
302 NonCopyable& operator=( const NonCopyable &exc ) {
303 throw OperationNotSupportedException();
304 }
305 };
306
307 /** Wraps instruction prefix and prepares factory methods for the hints.
308 * The static method "create" is used here just to avoid the constructor overloading
309 * what can be a bit problematic because fcml_prefix is an ordinal integer type.
310 * @since 1.1.0
311 */
312 class InstructionPrefix {
313 private:
314 /**
315 * Creates an instance of the instruction prefix for the given FCML prefix.
316 * @param prefix The native FCML prefix.
317 * @return Instruction prefix instance.
318 */
319 static InstructionPrefix create( fcml_prefixes prefix ) {
320 InstructionPrefix instructionPrefix;
321 instructionPrefix._prefix = prefix;
322 return instructionPrefix;
323 }
324 public:
325 /**
326 * Creates instruction prefix: LOCK.
327 * @return Created instruction prefix.
328 */
329 static const InstructionPrefix LOCK() {
330 return create(FCML_PREFIX_LOCK);
331 }
332 /**
333 * Creates instruction prefix: REPNE.
334 * @return Created instruction prefix.
335 */
336 static const InstructionPrefix REPNE() {
337 return create(FCML_PREFIX_REPNE);
338 }
339 /**
340 * Creates instruction prefix: REPNZ.
341 * @return Created instruction prefix.
342 */
343 static const InstructionPrefix REPNZ() {
344 return create(FCML_PREFIX_REPNZ);
345 }
346 /**
347 * Creates instruction prefix: REP.
348 * @return Created instruction prefix.
349 */
350 static const InstructionPrefix REP() {
351 return create(FCML_PREFIX_REP);
352 }
353 /**
354 * Creates instruction prefix: REPE.
355 * @return Created instruction prefix.
356 */
357 static const InstructionPrefix REPE() {
358 return create(FCML_PREFIX_REPE);
359 }
360 /**
361 * Creates instruction prefix: REPZ.
362 * @return Created instruction prefix.
363 */
364 static const InstructionPrefix REPZ() {
365 return create(FCML_PREFIX_REPZ);
366 }
367 /**
368 * Creates instruction prefix: XACQUIRE.
369 * @return Created instruction prefix.
370 */
371 static const InstructionPrefix XACQUIRE() {
372 return create(FCML_PREFIX_XACQUIRE);
373 }
374 /**
375 * Creates instruction prefix: XRELEASE.
376 * @return Created instruction prefix.
377 */
378 static const InstructionPrefix XRELEASE() {
379 return create(FCML_PREFIX_XRELEASE);
380 }
381 /**
382 * Creates instruction prefix: BRANCH_HINT.
383 * @return Created instruction prefix.
384 */
385 static const InstructionPrefix BRANCH_HINT() {
386 return create(FCML_PREFIX_BRANCH_HINT);
387 }
388 /**
389 * Creates instruction prefix: NOBRANCH_HINT.
390 * @return Created instruction prefix.
391 */
392 static const InstructionPrefix NOBRANCH_HINT() {
393 return create(FCML_PREFIX_NOBRANCH_HINT);
394 }
395 public:
396 fcml_prefixes _prefix;
397 };
398
399 /** Wraps instruction hint and exposes factory methods for instruction hints.
400 * @since 1.1.0
401 */
402 struct InstructionHint {
403 private:
404 /**
405 * Creates an instruction level hints for given native FCML hints.
406 * @param hints The hints set.
407 */
408 InstructionHint(fcml_en_instruction_hints hints) :
409 _hint(hints) {
410 }
411 public:
412 /**
413 * Creates instruction hint: NO_HINTS.
414 * @return Instruction hint.
415 */
416 static const InstructionHint NO_HINTS() {
417 return InstructionHint(FCML_HINT_NO_HINTS);
418 }
419 /**
420 * Creates instruction hint: NEAR_POINTER.
421 * @return Instruction hint.
422 */
423 static const InstructionHint NEAR_POINTER() {
424 return InstructionHint(FCML_HINT_NEAR_POINTER);
425 }
426 /**
427 * Creates instruction hint: FAR_POINTER.
428 * @return Instruction hint.
429 */
430 static const InstructionHint FAR_POINTER() {
431 return InstructionHint(FCML_HINT_FAR_POINTER);
432 }
433 /**
434 * Creates instruction hint: LONG_FORM_POINTER.
435 * @return Instruction hint.
436 */
437 static const InstructionHint LONG_FORM_POINTER() {
438 return InstructionHint(FCML_HINT_LONG_FORM_POINTER);
439 }
440 /**
441 * Creates instruction hint: INDIRECT_POINTER.
442 * @return Instruction hint.
443 */
444 static const InstructionHint INDIRECT_POINTER() {
445 return InstructionHint(FCML_HINT_INDIRECT_POINTER);
446 }
447 /**
448 * Creates instruction hint: DIRECT_POINTER.
449 * @return Instruction hint.
450 */
451 static const InstructionHint DIRECT_POINTER() {
452 return InstructionHint(FCML_HINT_DIRECT_POINTER);
453 }
454 public:
455 fcml_en_instruction_hints _hint;
456 };
457
458 /** Wraps operand hint and exposes factory methods for instruction hints.
459 * @since 1.1.0
460 */
461 struct OperandHint {
462 private:
463 OperandHint(fcml_en_operand_hints hint) :
464 _hint(hint) {
465 }
466 public:
467 /**
468 * Creates operand level hint: UNDEFIEND.
469 * @return Operand level hint.
470 */
471 static const OperandHint UNDEFIEND() {
472 return OperandHint(FCML_OP_HINT_UNDEFIEND);
473 }
474 /**
475 * Creates operand level hint: MULTIMEDIA_INSTRUCTION.
476 * @return Operand level hint.
477 */
478 static const OperandHint MULTIMEDIA() {
479 return OperandHint(FCML_OP_HINT_MULTIMEDIA_INSTRUCTION);
480 }
481 /**
482 * Creates operand level hint: DISPLACEMENT_RELATIVE_ADDRESS.
483 * @return Operand level hint.
484 */
485 static const OperandHint DISPLACEMENT_RELATIVE_ADDRESS() {
486 return OperandHint(FCML_OP_HINT_DISPLACEMENT_RELATIVE_ADDRESS);
487 }
488 /**
489 * Creates operand level hint: PSEUDO_OPCODE.
490 * @return Operand level hint.
491 */
492 static const OperandHint PSEUDO_OPCODE() {
493 return OperandHint(FCML_OP_HINT_PSEUDO_OPCODE);
494 }
495 /**
496 * Creates operand level hint: ABSOLUTE_ADDRESSING.
497 * @return Operand level hint.
498 */
499 static const OperandHint ABSOLUTE_ADDRESSING() {
500 return OperandHint(FCML_OP_HINT_ABSOLUTE_ADDRESSING);
501 }
502 /**
503 * Creates operand level hint: RELATIVE_ADDRESSING.
504 * @return Operand level hint.
505 */
506 static const OperandHint RELATIVE_ADDRESSING() {
507 return OperandHint(FCML_OP_HINT_RELATIVE_ADDRESSING);
508 }
509 /**
510 * Creates operand level hint: SIB_ENCODING.
511 * @return Operand level hint.
512 */
513 static const OperandHint SIB_ENCODING() {
514 return OperandHint(FCML_OP_HINT_SIB_ENCODING);
515 }
516 public:
517 fcml_en_operand_hints _hint;
518 };
519
520 /**
521 * Holds instruction pointer, processor operating mode and memory segment flags.
522 * @since 1.1.0
523 */
524 class EntryPoint {
525 public:
526
527 /**
528 * Supported operating modes.
529 * @since 1.1.0
530 */
531 enum OperatingMode {
532 OM_16_BIT = FCML_OM_16_BIT,
533 OM_32_BIT = FCML_OM_32_BIT,
534 OM_64_BIT = FCML_OM_64_BIT
535 };
536
537 /**
538 * Creates an empty entry point instance.
539 * @since 1.1.0
540 */
541 EntryPoint() :
542 _opMode(OM_32_BIT),
543 _addressSizeAttribute(FCML_DS_32),
544 _operandSizeAttribute(FCML_DS_32),
545 _ip(0) {
546 }
547
548 /**
549 * Creates an entry point instance for given processor operating mode, instruction pointer and optionally size attributes.
550 * @param opMode The processor operating mode.
551 * @param ip The instruction pointer.
552 * @param addressSizeAttribute The optional address size attribute.
553 * @param operandSizeAttribute The optional operand size attribute.
554 * @since 1.1.0
555 */
556 EntryPoint(OperatingMode opMode, fcml_ip ip = 0, fcml_usize addressSizeAttribute = FCML_DS_UNDEF, fcml_usize operandSizeAttribute = FCML_DS_UNDEF ) :
557 _opMode(opMode),
558 _addressSizeAttribute(addressSizeAttribute),
559 _operandSizeAttribute(operandSizeAttribute),
560 _ip(ip) {
561 }
562
563 virtual ~EntryPoint() {
564 }
565
566 public:
567
568 /**
569 * Checks if two entry points are equal.
570 *
571 * @param ep The source entry point.
572 * @return True if they are equal; otherwise false.
573 * @since 1.1.0
574 */
575 bool operator==( const EntryPoint &ep ) const {
576 return _opMode == ep._opMode &&
577 _ip == ep._ip &&
578 _operandSizeAttribute == ep._operandSizeAttribute &&
579 _addressSizeAttribute == ep._addressSizeAttribute;
580 }
581
582 /**
583 * Checks if two entry points are not equal.
584 *
585 * @param ep The source entry point.
586 * @return True if they are not equal; otherwise false.
587 * @since 1.1.0
588 */
589 bool operator!=( const EntryPoint &ep ) const {
590 return !(ep == *this);
591 }
592
593 public:
594
595 /**
596 * Gets address size attribute held by the entry point.
597 *
598 * @return Address size attribute.
599 * @since 1.1.0
600 */
601 fcml_usize getAddressSizeAttribute() const {
602 return _addressSizeAttribute;
603 }
604
605 /**
606 * Sets a new address size attribute for the entry point.
607 *
608 * @param addressSizeAttribute The address size attribute.
609 * @since 1.1.0
610 */
611 void setAddressSizeAttribute( fcml_usize addressSizeAttribute ) {
612 _addressSizeAttribute = addressSizeAttribute;
613 }
614
615 /**
616 * Gets operand size attribute held by the entry point.
617 *
618 * @return Operand size attribute.
619 * @since 1.1.0
620 */
621 fcml_usize getOperandSizeAttribute() const {
622 return _operandSizeAttribute;
623 }
624
625 /**
626 * Sets a new operand size attribute for the entry point.
627 *
628 * @param operandSizeAttribute The operand size attribute.
629 * @since 1.1.0
630 */
631 void setOperandSizeAttribute( fcml_usize operandSizeAttribute ) {
632 _operandSizeAttribute = operandSizeAttribute;
633 }
634
635 /**
636 * Gets instruction pointer held by the entry point.
637 *
638 * @return Instruction pointer.
639 * @since 1.1.0
640 */
641 fcml_ip getIP() const {
642 return _ip;
643 }
644
645 /**
646 * Sets a new instruction pointer for the entry point.
647 *
648 * @param ip The new instruction pointer.
649 * @since 1.1.0
650 */
651 void setIP( fcml_ip ip ) {
652 _ip = ip;
653 }
654
655 /**
656 * Gets processor operating mode.
657 *
658 * @return Processor operating mode.
659 * @since 1.1.0
660 */
661 OperatingMode getOpMode() const {
662 return _opMode;
663 }
664
665 /**
666 * Sets a new processor operating mode for the entry point.
667 *
668 * @param opMode The new processor operating mode.
669 * @since 1.1.0
670 */
671 void setOpMode( OperatingMode opMode ) {
672 _opMode = opMode;
673 }
674
675 /**
676 * Increments the instruction pointer by given number of bytes.
677 *
678 * @param ip Number for bytes the instruction pointer should be incremented by.
679 * @since 1.1.0
680 */
681 void incrementIP( fcml_ip ip ) {
682 _ip += ip;
683 }
684
685 private:
686 /** Processor operating mode */
687 OperatingMode _opMode;
688 /** Size of the address size attribute. */
689 fcml_usize _addressSizeAttribute;
690 /** Size of the operand size attribute. */
691 fcml_usize _operandSizeAttribute;
692 /** Instruction pointer. Content of the EIP/RIP register. */
693 fcml_ip _ip;
694 };
695
696 /**
697 * Represents integer value.
698 * @since 1.1.0
699 */
700 class Integer {
701 public:
702
703 /** @since 1.1.0 */
704 Integer() :
705 _size( FCML_DS_64 ), _isSigned( FCML_FALSE ), _vint8( 0 ), _vint16( 0 ), _vint32( 0 ), _vint64( 0 ) {
706 }
707
708 /** @since 1.1.0 */
709 Integer( fcml_int8_t value ) :
710 _size( FCML_DS_8 ), _isSigned( FCML_TRUE ), _vint8( value ), _vint16( 0 ), _vint32( 0 ), _vint64( 0 ) {
711 }
712
713 /** @since 1.1.0 */
714 Integer( fcml_int16_t value ) :
715 _size( FCML_DS_16 ), _isSigned( FCML_TRUE ), _vint8( 0 ), _vint16( value ), _vint32( 0 ), _vint64( 0 ) {
716 }
717
718 /** @since 1.1.0 */
719 Integer( fcml_int32_t value ) :
720 _size( FCML_DS_32 ), _isSigned( FCML_TRUE ), _vint8( 0 ), _vint16( 0 ), _vint32( value ), _vint64( 0 ) {
721 }
722
723 /** @since 1.1.0 */
724 Integer( fcml_int64_t value ) :
725 _size( FCML_DS_64 ), _isSigned( FCML_TRUE ), _vint8( 0 ), _vint16( 0 ), _vint32( 0 ), _vint64( value ) {
726 }
727
728 /** @since 1.1.0 */
729 Integer( fcml_uint8_t value ) :
730 _size( FCML_DS_8 ), _isSigned( FCML_FALSE ), _vint8( static_cast<fcml_uint8_t>( value ) ), _vint16( 0 ), _vint32( 0 ), _vint64( 0 ) {
731 }
732
733 /** @since 1.1.0 */
734 Integer( fcml_uint16_t value ) :
735 _size( FCML_DS_16 ), _isSigned( FCML_FALSE ), _vint8( 0 ), _vint16( static_cast<fcml_uint16_t>( value ) ), _vint32( 0 ), _vint64( 0 ) {
736 }
737
738 /** @since 1.1.0 */
739 Integer( fcml_uint32_t value ) :
740 _size( FCML_DS_32 ), _isSigned( FCML_FALSE ), _vint8( 0 ), _vint16( 0 ), _vint32( static_cast<fcml_uint32_t>( value ) ), _vint64( 0 ) {
741 }
742
743 /** @since 1.1.0 */
744 Integer( fcml_uint64_t value ) :
745 _size( FCML_DS_64 ), _isSigned( FCML_FALSE ), _vint8( 0 ), _vint16( 0 ), _vint32( 0 ), _vint64( static_cast<fcml_uint64_t>( value ) ) {
746 }
747
748 /** @since 1.1.0 */
749 virtual ~Integer() {
750 }
751
752 public:
753
754 /** @since 1.1.0 */
755 fcml_int16_t getInt16() const {
756 return _vint16;
757 }
758
759 /** @since 1.1.0 */
760 Integer& setInt16( fcml_int16_t int16 ) {
761 _vint16 = int16;
762 return *this;
763 }
764
765 /** @since 1.1.0 */
766 fcml_int32_t getInt32() const {
767 return _vint32;
768 }
769
770 /** @since 1.1.0 */
771 Integer& setInt32( fcml_int32_t int32 ) {
772 _vint32 = int32;
773 return *this;
774 }
775
776 /** @since 1.1.0 */
777 fcml_int64_t getInt64() const {
778 return _vint64;
779 }
780
781 /** @since 1.1.0 */
782 Integer& setInt64( fcml_int64_t int64 ) {
783 _vint64 = int64;
784 return *this;
785 }
786
787 /** @since 1.1.0 */
788 fcml_int8_t getInt8() const {
789 return _vint8;
790 }
791
792 /** @since 1.1.0 */
793 Integer& setInt8( fcml_int8_t int8 ) {
794 _vint8 = int8;
795 return *this;
796 }
797
798 /** @since 1.1.0 */
799 fcml_bool isSigned() const {
800 return _isSigned;
801 }
802
803 /** @since 1.1.0 */
804 Integer& setSigned( fcml_bool isSigned ) {
805 _isSigned = isSigned;
806 return *this;
807 }
808
809 /** @since 1.1.0 */
810 fcml_usize getSize() const {
811 return _size;
812 }
813
814 /** @since 1.1.0 */
815 Integer& setSize( fcml_usize size ) {
816 _size = size;
817 return *this;
818 }
819
820 /**
821 * Checks if the integer is equal to the passed value.
822 *
823 * @param value The source value to be compared with the integer.
824 * @return True if values are equal; otherwise false.
825 * @since 1.1.0
826 */
827 bool operator==( const fcml_uint8_t value ) const {
828 return _isSigned ? static_cast<fcml_int64_t>( *this ) == static_cast<fcml_int64_t>( value ) : static_cast<fcml_uint64_t>( *this ) == static_cast<fcml_uint64_t>( value );
829 }
830
831 /**
832 * Checks if the integer is equal to the passed value.
833 *
834 * @param value The source value to be compared with the integer.
835 * @return True if values are equal; otherwise false.
836 * @since 1.1.0
837 */
838 bool operator==( const fcml_int8_t value ) const {
839 return _isSigned ? static_cast<fcml_int64_t>( *this ) == static_cast<fcml_int64_t>( value ) : static_cast<fcml_uint64_t>( *this ) == static_cast<fcml_uint64_t>( value );
840 }
841
842 /**
843 * Checks if the integer is equal to the passed value.
844 *
845 * @param value The source value to be compared with the integer.
846 * @return True if values are equal; otherwise false.
847 * @since 1.1.0
848 */
849 bool operator==( const fcml_uint16_t value ) const {
850 return _isSigned ? static_cast<fcml_int64_t>( *this ) == static_cast<fcml_int64_t>( value ) : static_cast<fcml_uint64_t>( *this ) == static_cast<fcml_uint64_t>( value );
851 }
852
853 /**
854 * Checks if the integer is equal to the passed value.
855 *
856 * @param value The source value to be compared with the integer.
857 * @return True if values are equal; otherwise false.
858 * @since 1.1.0
859 */
860 bool operator==( const fcml_int16_t value ) const {
861 return _isSigned ? static_cast<fcml_int64_t>( *this ) == static_cast<fcml_int64_t>( value ) : static_cast<fcml_uint64_t>( *this ) == static_cast<fcml_uint64_t>( value );
862 }
863
864 /**
865 * Checks if the integer is equal to the passed value.
866 *
867 * @param value The source value to be compared with the integer.
868 * @return True if values are equal; otherwise false.
869 * @since 1.1.0
870 */
871 bool operator==( const fcml_uint32_t value ) const {
872 return _isSigned ? static_cast<fcml_int64_t>( *this ) == static_cast<fcml_int64_t>( value ) : static_cast<fcml_uint64_t>( *this ) == static_cast<fcml_uint64_t>( value );
873 }
874
875 /**
876 * Checks if the integer is equal to the passed value.
877 *
878 * @param value The source value to be compared with the integer.
879 * @return True if values are equal; otherwise false.
880 * @since 1.1.0
881 */
882 bool operator==( const fcml_int32_t value ) const {
883 return _isSigned ? static_cast<fcml_int64_t>( *this ) == static_cast<fcml_int64_t>( value ) : static_cast<fcml_uint64_t>( *this ) == static_cast<fcml_uint64_t>( value );
884 }
885
886 /**
887 * Checks if the integer is equal to the passed value.
888 *
889 * @param value The source value to be compared with the integer.
890 * @return True if values are equal; otherwise false.
891 * @since 1.1.0
892 */
893 bool operator==( const fcml_uint64_t value ) const {
894 return _isSigned ? static_cast<fcml_int64_t>( *this ) == static_cast<fcml_int64_t>( value ) : static_cast<fcml_uint64_t>( *this ) == static_cast<fcml_uint64_t>( value );
895 }
896
897 /**
898 * Checks if the integer is equal to the passed value.
899 *
900 * @param value The source value to be compared with the integer.
901 * @return True if values are equal; otherwise false.
902 * @since 1.1.0
903 */
904 bool operator==( const fcml_int64_t value ) const {
905 return _isSigned ? static_cast<fcml_int64_t>( *this ) == static_cast<fcml_int64_t>( value ) : static_cast<fcml_uint64_t>( *this ) == static_cast<fcml_uint64_t>( value );
906 }
907
908 /**
909 * Checks if the integer is equal to the passed value.
910 *
911 * @param value The source value to be compared with the integer.
912 * @return True if values are equal; otherwise false.
913 * @since 1.1.0
914 */
915 bool operator==( const Integer &value ) const {
916 return _isSigned ? static_cast<fcml_int64_t>( *this ) == static_cast<fcml_int64_t>( value ) : static_cast<fcml_uint64_t>( *this ) == static_cast<fcml_uint64_t>( value );
917 }
918
919 /**
920 * Checks if the integer is not equal to the passed value.
921 *
922 * @param value The source value to be compared with the integer.
923 * @return True if values are not equal; otherwise false.
924 * @since 1.1.0
925 */
926 bool operator!=( const fcml_uint8_t value ) const {
927 return _isSigned ? static_cast<fcml_int64_t>( *this ) != static_cast<fcml_int64_t>( value ) : static_cast<fcml_uint64_t>( *this ) != static_cast<fcml_uint64_t>( value );
928 }
929
930 /**
931 * Checks if the integer is not equal to the passed value.
932 *
933 * @param value The source value to be compared with the integer.
934 * @return True if values are not equal; otherwise false.
935 * @since 1.1.0
936 */
937 bool operator!=( const fcml_int8_t value ) const {
938 return _isSigned ? static_cast<fcml_int64_t>( *this ) != static_cast<fcml_int64_t>( value ) : static_cast<fcml_uint64_t>( *this ) != static_cast<fcml_uint64_t>( value );
939 }
940
941 /**
942 * Checks if the integer is not equal to the passed value.
943 *
944 * @param value The source value to be compared with the integer.
945 * @return True if values are not equal; otherwise false.
946 * @since 1.1.0
947 */
948 bool operator!=( const fcml_uint16_t value ) const {
949 return _isSigned ? static_cast<fcml_int64_t>( *this ) != static_cast<fcml_int64_t>( value ) : static_cast<fcml_uint64_t>( *this ) != static_cast<fcml_uint64_t>( value );
950 }
951
952 /**
953 * Checks if the integer is not equal to the passed value.
954 *
955 * @param value The source value to be compared with the integer.
956 * @return True if values are not equal; otherwise false.
957 * @since 1.1.0
958 */
959 bool operator!=( const fcml_int16_t value ) const {
960 return _isSigned ? static_cast<fcml_int64_t>( *this ) != static_cast<fcml_int64_t>( value ) : static_cast<fcml_uint64_t>( *this ) != static_cast<fcml_uint64_t>( value );
961 }
962
963 /**
964 * Checks if the integer is not equal to the passed value.
965 *
966 * @param value The source value to be compared with the integer.
967 * @return True if values are not equal; otherwise false.
968 * @since 1.1.0
969 */
970 bool operator!=( const fcml_uint32_t value ) const {
971 return _isSigned ? static_cast<fcml_int64_t>( *this ) != static_cast<fcml_int64_t>( value ) : static_cast<fcml_uint64_t>( *this ) != static_cast<fcml_uint64_t>( value );
972 }
973
974 /**
975 * Checks if the integer is not equal to the passed value.
976 *
977 * @param value The source value to be compared with the integer.
978 * @return True if values are not equal; otherwise false.
979 * @since 1.1.0
980 */
981 bool operator!=( const fcml_int32_t value ) const {
982 return _isSigned ? static_cast<fcml_int64_t>( *this ) != static_cast<fcml_int64_t>( value ) : static_cast<fcml_uint64_t>( *this ) != static_cast<fcml_uint64_t>( value );
983 }
984
985 /**
986 * Checks if the integer is not equal to the passed value.
987 *
988 * @param value The source value to be compared with the integer.
989 * @return True if values are not equal; otherwise false.
990 * @since 1.1.0
991 */
992 bool operator!=( const fcml_uint64_t value ) const {
993 return _isSigned ? static_cast<fcml_int64_t>( *this ) != static_cast<fcml_int64_t>( value ) : static_cast<fcml_uint64_t>( *this ) != static_cast<fcml_uint64_t>( value );
994 }
995
996 /**
997 * Checks if the integer is not equal to the passed value.
998 *
999 * @param value The source value to be compared with the integer.
1000 * @return True if values are not equal; otherwise false.
1001 * @since 1.1.0
1002 */
1003 bool operator!=( const fcml_int64_t value ) const {
1004 return _isSigned ? static_cast<fcml_int64_t>( *this ) != static_cast<fcml_int64_t>( value ) : static_cast<fcml_uint64_t>( *this ) != static_cast<fcml_uint64_t>( value );
1005 }
1006
1007 /**
1008 * Checks if the integer is not equal to the passed value.
1009 *
1010 * @param value The source value to be compared with the integer.
1011 * @return True if values are not equal; otherwise false.
1012 * @since 1.1.0
1013 */
1014 bool operator!=( const Integer &value ) const {
1015 return _isSigned ? static_cast<fcml_int64_t>( *this ) != static_cast<fcml_int64_t>( value ) : static_cast<fcml_uint64_t>( *this ) != static_cast<fcml_uint64_t>( value );
1016 }
1017
1018 /**
1019 * A casting operator.
1020 * @since 1.1.0
1021 * @throw BadArgumentException Wrong data size.
1022 */
1023 operator fcml_int8_t() const {
1024 fcml_int8_t result;
1025 switch ( _size ) {
1026 case FCML_DS_8:
1027 result = static_cast<fcml_int8_t>( _isSigned ? _vint8 : (fcml_uint8_t)_vint8 );
1028 break;
1029 case FCML_DS_16:
1030 result = static_cast<fcml_int8_t>( _isSigned ? _vint16 : (fcml_uint16_t)_vint16 );
1031 break;
1032 case FCML_DS_32:
1033 result = static_cast<fcml_int8_t>( _isSigned ? _vint32 : (fcml_uint32_t)_vint32 );
1034 break;
1035 case FCML_DS_64:
1036 result = static_cast<fcml_int8_t>( _isSigned ? _vint64 : (fcml_uint64_t)_vint64 );
1037 break;
1038 default:
1039 throw BadArgumentException( FCML_TEXT( "Wrong size." ) );
1040 }
1041 return result;
1042 }
1043 /**
1044 * A casting operator.
1045 * @since 1.1.0
1046 * @throw BadArgumentException Wrong indeger size.
1047 */
1048 operator fcml_uint8_t() const {
1049 fcml_uint8_t result;
1050 switch ( _size ) {
1051 case FCML_DS_8:
1052 result = static_cast<fcml_uint8_t>( _isSigned ? _vint8 : (fcml_uint8_t)_vint8 );
1053 break;
1054 case FCML_DS_16:
1055 result = static_cast<fcml_uint8_t>( _isSigned ? _vint16 : (fcml_uint16_t)_vint16 );
1056 break;
1057 case FCML_DS_32:
1058 result = static_cast<fcml_uint8_t>( _isSigned ? _vint32 : (fcml_uint32_t)_vint32 );
1059 break;
1060 case FCML_DS_64:
1061 result = static_cast<fcml_uint8_t>( _isSigned ? _vint64 : (fcml_uint64_t)_vint64 );
1062 break;
1063 default:
1064 throw BadArgumentException( FCML_TEXT( "Wrong size." ) );
1065 }
1066 return result;
1067 }
1068
1069 /**
1070 * A casting operator.
1071 * @since 1.1.0
1072 * @throw BadArgumentException Wrong integer size.
1073 */
1074 operator fcml_int16_t() const {
1075 fcml_int16_t result;
1076 switch ( _size ) {
1077 case FCML_DS_8:
1078 result = static_cast<fcml_int16_t>( _isSigned ? _vint8 : (fcml_uint8_t)_vint8 );
1079 break;
1080 case FCML_DS_16:
1081 result = static_cast<fcml_int16_t>( _isSigned ? _vint16 : (fcml_uint16_t)_vint16 );
1082 break;
1083 case FCML_DS_32:
1084 result = static_cast<fcml_int16_t>( _isSigned ? _vint32 : (fcml_uint32_t)_vint32 );
1085 break;
1086 case FCML_DS_64:
1087 result = static_cast<fcml_int16_t>( _isSigned ? _vint64 : (fcml_uint64_t)_vint64 );
1088 break;
1089 default:
1090 throw BadArgumentException( FCML_TEXT( "Wrong size." ) );
1091 }
1092 return result;
1093 }
1094
1095 /**
1096 * A casting operator.
1097 * @since 1.1.0
1098 * @throw BadArgumentException Wrong integer size.
1099 */
1100 operator fcml_uint16_t() const {
1101 fcml_uint16_t result;
1102 switch ( _size ) {
1103 case FCML_DS_8:
1104 result = static_cast<fcml_uint16_t>( _isSigned ? _vint8 : (fcml_uint8_t)_vint8 );
1105 break;
1106 case FCML_DS_16:
1107 result = static_cast<fcml_uint16_t>( _isSigned ? _vint16 : (fcml_uint16_t)_vint16 );
1108 break;
1109 case FCML_DS_32:
1110 result = static_cast<fcml_uint16_t>( _isSigned ? _vint32 : (fcml_uint32_t)_vint32 );
1111 break;
1112 case FCML_DS_64:
1113 result = static_cast<fcml_uint16_t>( _isSigned ? _vint64 : (fcml_uint64_t)_vint64 );
1114 break;
1115 default:
1116 throw BadArgumentException( FCML_TEXT( "Wrong size." ) );
1117 }
1118 return result;
1119 }
1120
1121 /**
1122 * A casting operator.
1123 * @since 1.1.0
1124 * @throw BadArgumentException Wrong integer size.
1125 */
1126 operator fcml_int32_t() const {
1127 fcml_int32_t result;
1128 switch ( _size ) {
1129 case FCML_DS_8:
1130 result = static_cast<fcml_int32_t>( _isSigned ? _vint8 : (fcml_uint8_t)_vint8 );
1131 break;
1132 case FCML_DS_16:
1133 result = static_cast<fcml_int32_t>( _isSigned ? _vint16 : (fcml_uint16_t)_vint16 );
1134 break;
1135 case FCML_DS_32:
1136 result = static_cast<fcml_int32_t>( _isSigned ? _vint32 : (fcml_uint32_t)_vint32 );
1137 break;
1138 case FCML_DS_64:
1139 result = static_cast<fcml_int32_t>( _isSigned ? _vint64 : (fcml_uint64_t)_vint64 );
1140 break;
1141 default:
1142 throw BadArgumentException( FCML_TEXT( "Wrong size." ) );
1143 }
1144 return result;
1145 }
1146
1147 /**
1148 * A casting operator.
1149 * @since 1.1.0
1150 * @throw BadArgumentException Wrong integer size.
1151 */
1152 operator fcml_uint32_t() const {
1153 fcml_uint32_t result;
1154 switch ( _size ) {
1155 case FCML_DS_8:
1156 result = static_cast<fcml_uint32_t>( _isSigned ? _vint8 : (fcml_uint8_t)_vint8 );
1157 break;
1158 case FCML_DS_16:
1159 result = static_cast<fcml_uint32_t>( _isSigned ? _vint16 : (fcml_uint16_t)_vint16 );
1160 break;
1161 case FCML_DS_32:
1162 result = static_cast<fcml_uint32_t>( _isSigned ? _vint32 : (fcml_uint32_t)_vint32 );
1163 break;
1164 case FCML_DS_64:
1165 result = static_cast<fcml_uint32_t>( _isSigned ? _vint64 : (fcml_uint64_t)_vint64 );
1166 break;
1167 default:
1168 throw BadArgumentException( FCML_TEXT( "Wrong size." ) );
1169 }
1170 return result;
1171 }
1172
1173 /**
1174 * A casting operator.
1175 * @since 1.1.0
1176 * @throw BadArgumentException Wrong integer size.
1177 */
1178 operator fcml_int64_t() const {
1179 fcml_int64_t result;
1180 switch ( _size ) {
1181 case FCML_DS_8:
1182 result = static_cast<fcml_int64_t>( _isSigned ? _vint8 : (fcml_uint8_t)_vint8 );
1183 break;
1184 case FCML_DS_16:
1185 result = static_cast<fcml_int64_t>( _isSigned ? _vint16 : (fcml_uint16_t)_vint16 );
1186 break;
1187 case FCML_DS_32:
1188 result = static_cast<fcml_int64_t>( _isSigned ? _vint32 : (fcml_uint32_t)_vint32 );
1189 break;
1190 case FCML_DS_64:
1191 result = static_cast<fcml_int64_t>( _isSigned ? _vint64 : (fcml_uint64_t)_vint64 );
1192 break;
1193 default:
1194 throw BadArgumentException( FCML_TEXT( "Wrong size." ) );
1195 }
1196 return result;
1197 }
1198
1199 /**
1200 * A casting operator.
1201 * @since 1.1.0
1202 * @throw BadArgumentException Wrong integer size.
1203 */
1204 operator fcml_uint64_t() const {
1205 fcml_uint64_t result;
1206 switch ( _size ) {
1207 case FCML_DS_8:
1208 result = static_cast<fcml_uint64_t>( _isSigned ? _vint8 : (fcml_uint8_t)_vint8 );
1209 break;
1210 case FCML_DS_16:
1211 result = static_cast<fcml_uint64_t>( _isSigned ? _vint16 : (fcml_uint16_t)_vint16 );
1212 break;
1213 case FCML_DS_32:
1214 result = static_cast<fcml_uint64_t>( _isSigned ? _vint32 : (fcml_uint32_t)_vint32 );
1215 break;
1216 case FCML_DS_64:
1217 result = static_cast<fcml_uint64_t>( _isSigned ? _vint64 : (fcml_uint64_t)_vint64 );
1218 break;
1219 default:
1220 throw BadArgumentException( FCML_TEXT( "Wrong size." ) );
1221 }
1222 return result;
1223 }
1224
1225 /**
1226 * Addition assignment.
1227 * @since 1.1.0
1228 */
1229 Integer& operator +=( const Integer &arg ) {
1230 plus( *this, arg );
1231 return ( *this );
1232 }
1233
1234 /**
1235 * Multiplication assignment.
1236 * @since 1.1.0
1237 */
1238 Integer& operator *=( const Integer &arg ) {
1239 mul( *this, arg );
1240 return ( *this );
1241 }
1242
1243 /**
1244 * Division assignment.
1245 * @since 1.1.0
1246 */
1247 Integer& operator /=( const Integer &arg ) {
1248 div( *this, arg );
1249 return ( *this );
1250 }
1251
1252 /**
1253 * Subtraction assignment.
1254 * @since 1.1.0
1255 */
1256 Integer& operator -=( const Integer &arg ) {
1257 minus( *this, arg );
1258 return ( *this );
1259 }
1260
1261 /**
1262 * Addition operator.
1263 * @since 1.1.0
1264 */
1265 Integer operator+( const Integer &src ) const {
1266 const Integer &thisRef = *this;
1267 Integer result( thisRef );
1268 plus( result, src );
1269 return result;
1270 }
1271
1272 /**
1273 * Subtraction operator.
1274 * @since 1.1.0
1275 */
1276 Integer operator-( const Integer &src ) const {
1277 const Integer &thisRef = *this;
1278 Integer result( thisRef );
1279 minus( result, src );
1280 return result;
1281 }
1282
1283 /**
1284 * Multiplication operator.
1285 * @since 1.1.0
1286 */
1287 Integer operator*( const Integer &src ) const {
1288 const Integer &thisRef = *this;
1289 Integer result( thisRef );
1290 mul( result, src );
1291 return result;
1292 }
1293
1294 /**
1295 * Division operator.
1296 * @since 1.1.0
1297 */
1298 Integer operator/( const Integer &src ) const {
1299 const Integer &thisRef = *this;
1300 Integer result( thisRef );
1301 div( result, src );
1302 return result;
1303 }
1304
1305 public:
1306
1307 /**
1308 * Factory method which creates an instance fo the Integer for given parameter.
1309 * @param value The value for the newly created Integer.
1310 * @return The created Integer instance.
1311 * @since 1.1.0
1312 */
1313 static Integer int8( fcml_int8_t value ) {
1314 return Integer( value );
1315 }
1316
1317 /**
1318 * Factory method which creates an instance fo the Integer for given parameter.
1319 * @param value The value for the newly created Integer.
1320 * @return The created Integer instance.
1321 * @since 1.1.0
1322 */
1323 static Integer uint8( fcml_uint8_t value ) {
1324 return Integer( value );
1325 }
1326
1327 /**
1328 * Factory method which creates an instance fo the Integer for given parameter.
1329 * @param value The value for the newly created Integer.
1330 * @return The created Integer instance.
1331 * @since 1.1.0
1332 */
1333 static Integer int16( fcml_int16_t value ) {
1334 return Integer( value );
1335 }
1336
1337 /**
1338 * Factory method which creates an instance fo the Integer for given parameter.
1339 * @param value The value for the newly created Integer.
1340 * @return The created Integer instance.
1341 * @since 1.1.0
1342 */
1343 static Integer uint16( fcml_uint16_t value ) {
1344 return Integer( value );
1345 }
1346
1347 /**
1348 * Factory method which creates an insatnce fo the Integer for given parameter.
1349 * @param value The value for the newly created Integer.
1350 * @return The created Integer instance.
1351 * @since 1.1.0
1352 */
1353 static Integer int32( fcml_int32_t value ) {
1354 return Integer( value );
1355 }
1356
1357 /**
1358 * Factory method which creates an insatnce fo the Integer for given parameter.
1359 * @param value The value for the newly created Integer.
1360 * @return The created Integer instance.
1361 * @since 1.1.0
1362 */
1363 static Integer uint32( fcml_uint32_t value ) {
1364 return Integer( value );
1365 }
1366
1367 /**
1368 * Factory method which creates an insatnce fo the Integer for given parameter.
1369 * @param value The value for the newly created Integer.
1370 * @return The created Integer instance.
1371 * @since 1.1.0
1372 */
1373 static Integer int64( fcml_int64_t value ) {
1374 return Integer( value );
1375 }
1376
1377 /**
1378 * Factory method which creates an insatnce fo the Integer for given parameter.
1379 * @param value The value for the newly created Integer.
1380 * @return The created Integer instance.
1381 * @since 1.1.0
1382 */
1383 static Integer uint64( fcml_uint64_t value ) {
1384 return Integer( value );
1385 }
1386
1387 private:
1388
1389 /**
1390 * @remark An internal API.
1391 * @since 1.1.0
1392 */
1393 void minus( Integer &result, const Integer &src ) const {
1394 callMathExpression( &doMinus, &doUMinus, result, src );
1395 }
1396
1397 /**
1398 * @remark An internal API.
1399 * @since 1.1.0
1400 */
1401 void mul( Integer &result, const Integer &src ) const {
1402 callMathExpression( &doMul, &doUMul, result, src );
1403 }
1404
1405 /**
1406 * @remark An internal API.
1407 * @since 1.1.0
1408 */
1409 void div( Integer &result, const Integer &src ) const {
1410 callMathExpression( &doDiv, &doUDiv, result, src );
1411 }
1412
1413 /**
1414 * @remark An internal API.
1415 * @since 1.1.0
1416 */
1417 void plus( Integer &result, const Integer &src ) const {
1418 callMathExpression( &doPlus, &doUPlus, result, src );
1419 }
1420
1421 private:
1422
1423 /**
1424 * @remark An internal API.
1425 * @since 1.1.0
1426 */
1427 static fcml_int64_t doPlus( fcml_int64_t thisValue, fcml_int64_t thatValue ) {
1428 return thisValue + thatValue;
1429 }
1430
1431 /**
1432 * @remark An internal API.
1433 * @since 1.1.0
1434 */
1435 static fcml_int64_t doMinus( fcml_int64_t thisValue, fcml_int64_t thatValue ) {
1436 return thisValue - thatValue;
1437 }
1438
1439 /**
1440 * @remark An internal API.
1441 * @since 1.1.0
1442 */
1443 static fcml_int64_t doMul( fcml_int64_t thisValue, fcml_int64_t thatValue ) {
1444 return thisValue * thatValue;
1445 }
1446
1447 /**
1448 * @remark An internal API.
1449 * @since 1.1.0
1450 */
1451 static fcml_int64_t doDiv( fcml_int64_t thisValue, fcml_int64_t thatValue ) {
1452 return thisValue / thatValue;
1453 }
1454
1455 /**
1456 * @remark An internal API.
1457 * @since 1.1.0
1458 */
1459 static fcml_uint64_t doUPlus( fcml_uint64_t thisValue, fcml_uint64_t thatValue ) {
1460 return thisValue + thatValue;
1461 }
1462
1463 /**
1464 * @remark An internal API.
1465 * @since 1.1.0
1466 */
1467 static fcml_uint64_t doUMinus( fcml_uint64_t thisValue, fcml_uint64_t thatValue ) {
1468 return thisValue - thatValue;
1469 }
1470
1471 /**
1472 * @remark An internal API.
1473 * @since 1.1.0
1474 */
1475 static fcml_uint64_t doUMul( fcml_uint64_t thisValue, fcml_uint64_t thatValue ) {
1476 return thisValue * thatValue;
1477 }
1478
1479 /**
1480 * @remark An internal API.
1481 * @since 1.1.0
1482 */
1483 static fcml_uint64_t doUDiv( fcml_uint64_t thisValue, fcml_uint64_t thatValue ) {
1484 return thisValue / thatValue;
1485 }
1486
1487 /**
1488 * @remark An internal API.
1489 * @since 1.1.0
1490 */
1491 void callMathExpression( fcml_int64_t (*signedExpressionFn)( fcml_int64_t thisValue, fcml_int64_t thatValue ),
1492 fcml_uint64_t (*unsignedExpressionFn)( fcml_uint64_t thisValue, fcml_uint64_t thatValue ),
1493 Integer &result, const Integer &src ) const {
1494
1495 if( _isSigned ) {
1496
1497 fcml_int64_t thisValue;
1498 fcml_int64_t thatValue;
1499
1500 // Prepare "that". It has to be converted to the same sign.
1501 switch( src._size ) {
1502 case FCML_DS_8:
1503 thatValue = src._isSigned ? src._vint8 : static_cast<fcml_uint8_t>( src._vint8 );
1504 break;
1505 case FCML_DS_16:
1506 thatValue = src._isSigned ? src._vint16 : static_cast<fcml_uint16_t>( src._vint16 );
1507 break;
1508 case FCML_DS_32:
1509 thatValue = src._isSigned ? src._vint32 : static_cast<fcml_uint32_t>( src._vint32 );
1510 break;
1511 case FCML_DS_64:
1512 thatValue = src._isSigned ? src._vint64 : static_cast<fcml_uint64_t>( src._vint64 );
1513 break;
1514 }
1515
1516 // Now "this".
1517 switch( result._size ) {
1518 case FCML_DS_8:
1519 thisValue = result._isSigned ? result._vint8 : static_cast<fcml_uint8_t>(result._vint8 );
1520 thisValue = (*signedExpressionFn)( thisValue, thatValue );
1521 result._vint8 = static_cast<fcml_int8_t>( thisValue );
1522 break;
1523 case FCML_DS_16:
1524 thisValue = result._isSigned ? result._vint16 : static_cast<fcml_uint16_t>( result._vint16 );
1525 thisValue = (*signedExpressionFn)( thisValue, thatValue );
1526 result._vint16 = static_cast<fcml_int16_t>( thisValue );
1527 break;
1528 case FCML_DS_32:
1529 thisValue = result._isSigned ? result._vint32 : static_cast<fcml_uint32_t>( result._vint32 );
1530 thisValue = (*signedExpressionFn)( thisValue, thatValue );
1531 result._vint32 = static_cast<fcml_int32_t>( thisValue );
1532 break;
1533 case FCML_DS_64:
1534 thisValue = result._isSigned ? result._vint64 : static_cast<fcml_uint64_t>( result._vint64 );
1535 thisValue = (*signedExpressionFn)( thisValue, thatValue );
1536 result._vint64 = thisValue;
1537 break;
1538 }
1539
1540 } else {
1541
1542 fcml_uint64_t thisValue;
1543 fcml_uint64_t thatValue;
1544
1545 // Prepare "that". It has to be converted to the same sign.
1546 switch( src._size ) {
1547 case FCML_DS_8:
1548 thatValue = src._isSigned ? src._vint8 : static_cast<fcml_uint8_t>( src._vint8 );
1549 break;
1550 case FCML_DS_16:
1551 thatValue = src._isSigned ? src._vint16 : static_cast<fcml_uint16_t>( src._vint16 );
1552 break;
1553 case FCML_DS_32:
1554 thatValue = src._isSigned ? src._vint32 : static_cast<fcml_uint32_t>( src._vint32 );
1555 break;
1556 case FCML_DS_64:
1557 thatValue = src._isSigned ? src._vint64 : static_cast<fcml_uint64_t>( src._vint64 );
1558 break;
1559 }
1560
1561 // Now "this".
1562 switch( result._size ) {
1563 case FCML_DS_8:
1564 thisValue = result._isSigned ? result._vint8 : static_cast<fcml_uint8_t>( result._vint8 );
1565 thisValue = (*unsignedExpressionFn)( thisValue, thatValue );
1566 result._vint8 = static_cast<fcml_int8_t>( thisValue );
1567 break;
1568 case FCML_DS_16:
1569 thisValue = result._isSigned ? result._vint16 : static_cast<fcml_uint16_t>( result._vint16 );
1570 thisValue = (*unsignedExpressionFn)( thisValue, thatValue );
1571 result._vint16 = static_cast<fcml_int16_t>( thisValue );
1572 break;
1573 case FCML_DS_32:
1574 thisValue = result._isSigned ? result._vint32 : static_cast<fcml_uint32_t>( result._vint32 );
1575 thisValue = (*unsignedExpressionFn)( thisValue, thatValue );
1576 result._vint32 = static_cast<fcml_int32_t>( thisValue );
1577 break;
1578 case FCML_DS_64:
1579 thisValue = result._isSigned ? result._vint64 : static_cast<fcml_uint64_t>( result._vint64 );
1580 thisValue = (*unsignedExpressionFn)( thisValue, thatValue );
1581 result._vint64 = thisValue;
1582 break;
1583 }
1584 }
1585
1586 }
1587
1588 private:
1589 fcml_usize _size;
1590 fcml_bool _isSigned;
1591 fcml_int8_t _vint8;
1592 fcml_int16_t _vint16;
1593 fcml_int32_t _vint32;
1594 fcml_int64_t _vint64;
1595 };
1596
1597 /**
1598 * x86 - 64 register representation.
1599 * @since 1.1.0
1600 */
1601 class Register {
1602 public:
1603
1604 // TODO: Do we need this REG_ prefix here?
1605 /** Register types.
1606 * @since 1.1.0
1607 */
1608 enum RegisterType {
1609 /** Undefined register type. */
1610 REG_UNDEFINED = FCML_REG_UNDEFINED,
1611 /** General purpose register. */
1612 REG_GPR = FCML_REG_GPR,
1613 /** SIMD (SSE, MMX) register. */
1614 REG_SIMD = FCML_REG_SIMD,
1615 /** FPU register. */
1616 REG_FPU = FCML_REG_FPU,
1617 /** Segment register */
1618 REG_SEG = FCML_REG_SEG,
1619 /** Control register. */
1620 REG_CR = FCML_REG_CR,
1621 /** Debug register */
1622 REG_DR = FCML_REG_DR,
1623 /** Instruction pointer register. Used for relative RIP addressing. */
1624 REG_IP = FCML_REG_IP,
1625 /** Opmask register
1626 * @since 1.2.0
1627 */
1628 REG_OPMASK = FCML_REG_OPMASK
1629 };
1630
1631 /**
1632 * Creates an empty register instance.
1633 * @since 1.1.0
1634 */
1635 Register() :
1636 _type(REG_UNDEFINED),
1637 _size(0),
1638 _reg(0),
1639 _x64_exp(FCML_FALSE) {
1640 }
1641
1642 /**
1643 * Creates a register instance for given register structure.
1644 * @param reg The source register as the FCML structure.
1645 * @since 1.1.0
1646 */
1647 Register( const fcml_st_register &reg ) :
1648 _type(static_cast<RegisterType>( reg.type )),
1649 _size(reg.size),
1650 _reg(reg.reg),
1651 _x64_exp(reg.x64_exp? true : false) {
1652 }
1653
1654 /**
1655 * Creates a register instance for given parameters.
1656 * @param reg The FCML register number.
1657 * @param size The register size.
1658 * @param type The register type.
1659 * @param x64_exp True if it's a 8-bit general purpose register for REX aware instruction. See manual.
1660 * @since 1.1.0
1661 */
1662 Register( fcml_uint8_t reg, fcml_usize size, RegisterType type = REG_GPR, fcml_bool x64_exp = FCML_FALSE ) :
1663 _type(type),
1664 _size(size),
1665 _reg(reg),
1666 _x64_exp(x64_exp?true:false) {
1667 }
1668
1669 /**
1670 * @since 1.1.0
1671 */
1672 virtual ~Register() {
1673 }
1674
1675 public:
1676
1677 /**
1678 * Gets the register number.
1679 * @return The register number.
1680 * @since 1.1.0
1681 */
1682 fcml_uint8_t getReg() const {
1683 return _reg;
1684 }
1685
1686 /**
1687 * Sets the register number.
1688 * @param reg The register number.
1689 * @since 1.1.0
1690 */
1691 void setReg( fcml_uint8_t reg ) {
1692 _reg = reg;
1693 }
1694
1695 /**
1696 * Gets the register size.
1697 * @return The register size.
1698 * @since 1.1.0
1699 */
1700 fcml_usize getSize() const {
1701 return _size;
1702 }
1703
1704 /**
1705 * Sets the register size.
1706 * @param size The register size.
1707 * @since 1.1.0
1708 */
1709 void setSize( fcml_usize size ) {
1710 _size = size;
1711 }
1712
1713 /**
1714 * Gets the register type.
1715 * @return The register type.
1716 * @since 1.1.0
1717 */
1718 RegisterType getType() const {
1719 return _type;
1720 }
1721
1722 /**
1723 * Sets the register type.
1724 * @param type The register type.
1725 * @since 1.1.0
1726 */
1727 void setType( RegisterType type ) {
1728 _type = type;
1729 }
1730
1731 /**
1732 * Gets true if it's a 8-bit general purpose register for REX aware instruction. See manual.
1733 * @return True if it's a 8-bit general purpose register for REX aware instruction. See manual..
1734 * @since 1.1.0
1735 */
1736 bool getX64Exp() const {
1737 return _x64_exp;
1738 }
1739
1740 /**
1741 * Sets x64exp flag, see manual.
1742 * @param x64Exp The flag value.
1743 * @since 1.1.0
1744 */
1745 void setX64Exp( bool x64Exp ) {
1746 _x64_exp = x64Exp;
1747 }
1748
1749 public:
1750
1751 /**
1752 * Compares registers.
1753 * @param reg The source register.
1754 * @return True if registers are equal.
1755 * @since 1.1.0
1756 */
1757 bool operator==( const Register &reg ) const {
1758 return _reg == reg._reg && _type == reg._type && _size == reg._size && _x64_exp == reg._x64_exp;
1759 }
1760
1761 /**
1762 * Compares registers.
1763 * @param reg The source register.
1764 * @return True if registers are NOT equal.
1765 * @since 1.1.0
1766 */
1767 bool operator!=( const Register &reg ) const {
1768 return !( reg == *this );
1769 }
1770
1771 public:
1772
1773 /**
1774 * Factory method for an undefined register.
1775 * @return A register instance.
1776 * @since 1.1.0
1777 */
1778 static const Register UNDEF() {
1779 Register reg( 0, 0, Register::REG_UNDEFINED, FCML_FALSE );
1780 return reg;
1781 }
1782
1783 /**
1784 * Factory method for a register.
1785 * @return A register instance.
1786 * @since 1.1.0
1787 */
1788 static const Register AL() {
1789 Register reg( ::fcml_reg_AL );
1790 return reg;
1791 }
1792
1793 /**
1794 * Factory method for a register.
1795 * @return A register instance.
1796 * @since 1.1.0
1797 */
1798 static const Register AX() {
1799 Register reg( ::fcml_reg_AX );
1800 return reg;
1801 }
1802
1803 /**
1804 * Factory method for a register.
1805 * @return A register instance.
1806 * @since 1.1.0
1807 */
1808 static const Register EAX() {
1809 Register reg( ::fcml_reg_EAX );
1810 return reg;
1811 }
1812
1813 /**
1814 * Factory method for a register.
1815 * @return A register instance.
1816 * @since 1.1.0
1817 */
1818 static const Register RAX() {
1819 Register reg( ::fcml_reg_RAX );
1820 return reg;
1821 }
1822
1823 /**
1824 * Factory method for a register.
1825 * @return A register instance.
1826 * @since 1.1.0
1827 */
1828 static const Register MM0() {
1829 Register reg( ::fcml_reg_MM0 );
1830 return reg;
1831 }
1832
1833 /**
1834 * Factory method for a register.
1835 * @return A register instance.
1836 * @since 1.1.0
1837 */
1838 static const Register XMM0() {
1839 Register reg( ::fcml_reg_XMM0 );
1840 return reg;
1841 }
1842
1843 /**
1844 * Factory method for a register.
1845 * @return A register instance.
1846 * @since 1.1.0
1847 */
1848 static const Register YMM0() {
1849 Register reg( ::fcml_reg_YMM0 );
1850 return reg;
1851 }
1852
1853 /**
1854 * Factory method for a register.
1855 * @return A register instance.
1856 * @since 1.2.0
1857 */
1858 static const Register ZMM0() {
1859 Register reg( ::fcml_reg_ZMM0 );
1860 return reg;
1861 }
1862
1863 /**
1864 * Factory method for a register.
1865 * @return A register instance.
1866 * @since 1.1.0
1867 */
1868 static const Register CL() {
1869 Register reg( ::fcml_reg_CL );
1870 return reg;
1871 }
1872
1873 /**
1874 * Factory method for a register.
1875 * @return A register instance.
1876 * @since 1.1.0
1877 */
1878 static const Register CX() {
1879 Register reg( ::fcml_reg_CX );
1880 return reg;
1881 }
1882
1883 /**
1884 * Factory method for a register.
1885 * @return A register instance.
1886 * @since 1.1.0
1887 */
1888 static const Register ECX() {
1889 Register reg( ::fcml_reg_ECX );
1890 return reg;
1891 }
1892
1893 /**
1894 * Factory method for a register.
1895 * @return A register instance.
1896 * @since 1.1.0
1897 */
1898 static const Register RCX() {
1899 Register reg( ::fcml_reg_RCX );
1900 return reg;
1901 }
1902
1903 /**
1904 * Factory method for a register.
1905 * @return A register instance.
1906 * @since 1.1.0
1907 */
1908 static const Register MM1() {
1909 Register reg( ::fcml_reg_MM1 );
1910 return reg;
1911 }
1912
1913 /**
1914 * Factory method for a register.
1915 * @return A register instance.
1916 * @since 1.1.0
1917 */
1918 static const Register XMM1() {
1919 Register reg( ::fcml_reg_XMM1 );
1920 return reg;
1921 }
1922
1923 /**
1924 * Factory method for a register.
1925 * @return A register instance.
1926 * @since 1.1.0
1927 */
1928 static const Register YMM1() {
1929 Register reg( ::fcml_reg_YMM1 );
1930 return reg;
1931 }
1932
1933 /**
1934 * Factory method for a register.
1935 * @return A register instance.
1936 * @since 1.2.0
1937 */
1938 static const Register ZMM1() {
1939 Register reg( ::fcml_reg_ZMM1 );
1940 return reg;
1941 }
1942
1943 /**
1944 * Factory method for a register.
1945 * @return A register instance.
1946 * @since 1.1.0
1947 */
1948 static const Register DL() {
1949 Register reg( ::fcml_reg_DL );
1950 return reg;
1951 }
1952
1953 /**
1954 * Factory method for a register.
1955 * @return A register instance.
1956 * @since 1.1.0
1957 */
1958 static const Register DX() {
1959 Register reg( ::fcml_reg_DX );
1960 return reg;
1961 }
1962
1963 /**
1964 * Factory method for a register.
1965 * @return A register instance.
1966 * @since 1.1.0
1967 */
1968 static const Register EDX() {
1969 Register reg( ::fcml_reg_EDX );
1970 return reg;
1971 }
1972
1973 /**
1974 * Factory method for a register.
1975 * @return A register instance.
1976 * @since 1.1.0
1977 */
1978 static const Register RDX() {
1979 Register reg( ::fcml_reg_RDX );
1980 return reg;
1981 }
1982
1983 /**
1984 * Factory method for a register.
1985 * @return A register instance.
1986 * @since 1.1.0
1987 */
1988 static const Register MM2() {
1989 Register reg( ::fcml_reg_MM2 );
1990 return reg;
1991 }
1992
1993 /**
1994 * Factory method for a register.
1995 * @return A register instance.
1996 * @since 1.1.0
1997 */
1998 static const Register XMM2() {
1999 Register reg( ::fcml_reg_XMM2 );
2000 return reg;
2001 }
2002
2003 /**
2004 * Factory method for a register.
2005 * @return A register instance.
2006 * @since 1.1.0
2007 */
2008 static const Register YMM2() {
2009 Register reg( ::fcml_reg_YMM2 );
2010 return reg;
2011 }
2012
2013 /**
2014 * Factory method for a register.
2015 * @return A register instance.
2016 * @since 1.2.0
2017 */
2018 static const Register ZMM2() {
2019 Register reg( ::fcml_reg_ZMM2 );
2020 return reg;
2021 }
2022
2023 /**
2024 * Factory method for a register.
2025 * @return A register instance.
2026 * @since 1.1.0
2027 */
2028 static const Register BL() {
2029 Register reg( ::fcml_reg_BL );
2030 return reg;
2031 }
2032
2033 /**
2034 * Factory method for a register.
2035 * @return A register instance.
2036 * @since 1.1.0
2037 */
2038 static const Register BX() {
2039 Register reg( ::fcml_reg_BX );
2040 return reg;
2041 }
2042
2043 /**
2044 * Factory method for a register.
2045 * @return A register instance.
2046 * @since 1.1.0
2047 */
2048 static const Register EBX() {
2049 Register reg( ::fcml_reg_EBX );
2050 return reg;
2051 }
2052
2053 /**
2054 * Factory method for a register.
2055 * @return A register instance.
2056 * @since 1.1.0
2057 */
2058 static const Register RBX() {
2059 Register reg( ::fcml_reg_RBX );
2060 return reg;
2061 }
2062
2063 /**
2064 * Factory method for a register.
2065 * @return A register instance.
2066 * @since 1.1.0
2067 */
2068 static const Register MM3() {
2069 Register reg( ::fcml_reg_MM3 );
2070 return reg;
2071 }
2072
2073 /**
2074 * Factory method for a register.
2075 * @return A register instance.
2076 * @since 1.1.0
2077 */
2078 static const Register XMM3() {
2079 Register reg( ::fcml_reg_XMM3 );
2080 return reg;
2081 }
2082
2083 /**
2084 * Factory method for a register.
2085 * @return A register instance.
2086 * @since 1.1.0
2087 */
2088 static const Register YMM3() {
2089 Register reg( ::fcml_reg_YMM3 );
2090 return reg;
2091 }
2092
2093 /**
2094 * Factory method for a register.
2095 * @return A register instance.
2096 * @since 1.2.0
2097 */
2098 static const Register ZMM3() {
2099 Register reg( ::fcml_reg_ZMM3 );
2100 return reg;
2101 }
2102
2103 /**
2104 * Factory method for a register.
2105 * @return A register instance.
2106 * @since 1.1.0
2107 */
2108 static const Register AH() {
2109 Register reg( ::fcml_reg_AH );
2110 return reg;
2111 }
2112
2113 /**
2114 * Factory method for a register.
2115 * @return A register instance.
2116 * @since 1.1.0
2117 */
2118 static const Register SPL() {
2119 Register reg( ::fcml_reg_SPL );
2120 return reg;
2121 }
2122
2123 /**
2124 * Factory method for a register.
2125 * @return A register instance.
2126 * @since 1.1.0
2127 */
2128 static const Register SP() {
2129 Register reg( ::fcml_reg_SP );
2130 return reg;
2131 }
2132
2133 /**
2134 * Factory method for a register.
2135 * @return A register instance.
2136 * @since 1.1.0
2137 */
2138 static const Register ESP() {
2139 Register reg( ::fcml_reg_ESP );
2140 return reg;
2141 }
2142
2143 /**
2144 * Factory method for a register.
2145 * @return A register instance.
2146 * @since 1.1.0
2147 */
2148 static const Register RSP() {
2149 Register reg( ::fcml_reg_RSP );
2150 return reg;
2151 }
2152
2153 /**
2154 * Factory method for a register.
2155 * @return A register instance.
2156 * @since 1.1.0
2157 */
2158 static const Register MM4() {
2159 Register reg( ::fcml_reg_MM4 );
2160 return reg;
2161 }
2162
2163 /**
2164 * Factory method for a register.
2165 * @return A register instance.
2166 * @since 1.1.0
2167 */
2168 static const Register XMM4() {
2169 Register reg( ::fcml_reg_XMM4 );
2170 return reg;
2171 }
2172
2173 /**
2174 * Factory method for a register.
2175 * @return A register instance.
2176 * @since 1.1.0
2177 */
2178 static const Register YMM4() {
2179 Register reg( ::fcml_reg_YMM4 );
2180 return reg;
2181 }
2182
2183 /**
2184 * Factory method for a register.
2185 * @return A register instance.
2186 * @since 1.2.0
2187 */
2188 static const Register ZMM4() {
2189 Register reg( ::fcml_reg_ZMM4 );
2190 return reg;
2191 }
2192
2193
2194 /**
2195 * Factory method for a register.
2196 * @return A register instance.
2197 * @since 1.1.0
2198 */
2199 static const Register CH() {
2200 Register reg( ::fcml_reg_CH );
2201 return reg;
2202 }
2203
2204 /**
2205 * Factory method for a register.
2206 * @return A register instance.
2207 * @since 1.1.0
2208 */
2209 static const Register BPL() {
2210 Register reg( ::fcml_reg_BPL );
2211 return reg;
2212 }
2213
2214 /**
2215 * Factory method for a register.
2216 * @return A register instance.
2217 * @since 1.1.0
2218 */
2219 static const Register BP() {
2220 Register reg( ::fcml_reg_BP );
2221 return reg;
2222 }
2223
2224 /**
2225 * Factory method for a register.
2226 * @return A register instance.
2227 * @since 1.1.0
2228 */
2229 static const Register EBP() {
2230 Register reg( ::fcml_reg_EBP );
2231 return reg;
2232 }
2233
2234 /**
2235 * Factory method for a register.
2236 * @return A register instance.
2237 * @since 1.1.0
2238 */
2239 static const Register RBP() {
2240 Register reg( ::fcml_reg_RBP );
2241 return reg;
2242 }
2243
2244 /**
2245 * Factory method for a register.
2246 * @return A register instance.
2247 * @since 1.1.0
2248 */
2249 static const Register MM5() {
2250 Register reg( ::fcml_reg_MM5 );
2251 return reg;
2252 }
2253
2254 /**
2255 * Factory method for a register.
2256 * @return A register instance.
2257 * @since 1.1.0
2258 */
2259 static const Register XMM5() {
2260 Register reg( ::fcml_reg_XMM5 );
2261 return reg;
2262 }
2263
2264 /**
2265 * Factory method for a register.
2266 * @return A register instance.
2267 * @since 1.1.0
2268 */
2269 static const Register YMM5() {
2270 Register reg( ::fcml_reg_YMM5 );
2271 return reg;
2272 }
2273
2274 /**
2275 * Factory method for a register.
2276 * @return A register instance.
2277 * @since 1.2.0
2278 */
2279 static const Register ZMM5() {
2280 Register reg( ::fcml_reg_ZMM5 );
2281 return reg;
2282 }
2283
2284 /**
2285 * Factory method for a register.
2286 * @return A register instance.
2287 * @since 1.1.0
2288 */
2289 static const Register DH() {
2290 Register reg( ::fcml_reg_DH );
2291 return reg;
2292 }
2293
2294 /**
2295 * Factory method for a register.
2296 * @return A register instance.
2297 * @since 1.1.0
2298 */
2299 static const Register SIL() {
2300 Register reg( ::fcml_reg_SIL );
2301 return reg;
2302 }
2303
2304 /**
2305 * Factory method for a register.
2306 * @return A register instance.
2307 * @since 1.1.0
2308 */
2309 static const Register SI() {
2310 Register reg( ::fcml_reg_SI );
2311 return reg;
2312 }
2313
2314 /**
2315 * Factory method for a register.
2316 * @return A register instance.
2317 * @since 1.1.0
2318 */
2319 static const Register ESI() {
2320 Register reg( ::fcml_reg_ESI );
2321 return reg;
2322 }
2323
2324 /**
2325 * Factory method for a register.
2326 * @return A register instance.
2327 * @since 1.1.0
2328 */
2329 static const Register RSI() {
2330 Register reg( ::fcml_reg_RSI );
2331 return reg;
2332 }
2333
2334 /**
2335 * Factory method for a register.
2336 * @return A register instance.
2337 * @since 1.1.0
2338 */
2339 static const Register MM6() {
2340 Register reg( ::fcml_reg_MM6 );
2341 return reg;
2342 }
2343
2344 /**
2345 * Factory method for a register.
2346 * @return A register instance.
2347 * @since 1.1.0
2348 */
2349 static const Register XMM6() {
2350 Register reg( ::fcml_reg_XMM6 );
2351 return reg;
2352 }
2353
2354 /**
2355 * Factory method for a register.
2356 * @return A register instance.
2357 * @since 1.1.0
2358 */
2359 static const Register YMM6() {
2360 Register reg( ::fcml_reg_YMM6 );
2361 return reg;
2362 }
2363
2364 /**
2365 * Factory method for a register.
2366 * @return A register instance.
2367 * @since 1.2.0
2368 */
2369 static const Register ZMM6() {
2370 Register reg( ::fcml_reg_ZMM6 );
2371 return reg;
2372 }
2373
2374
2375 /**
2376 * Factory method for a register.
2377 * @return A register instance.
2378 * @since 1.1.0
2379 */
2380 static const Register BH() {
2381 Register reg( ::fcml_reg_BH );
2382 return reg;
2383 }
2384
2385 /**
2386 * Factory method for a register.
2387 * @return A register instance.
2388 * @since 1.1.0
2389 */
2390 static const Register DIL() {
2391 Register reg( ::fcml_reg_DIL );
2392 return reg;
2393 }
2394
2395 /**
2396 * Factory method for a register.
2397 * @return A register instance.
2398 * @since 1.1.0
2399 */
2400 static const Register DI() {
2401 Register reg( ::fcml_reg_DI );
2402 return reg;
2403 }
2404
2405 /**
2406 * Factory method for a register.
2407 * @return A register instance.
2408 * @since 1.1.0
2409 */
2410 static const Register EDI() {
2411 Register reg( ::fcml_reg_EDI );
2412 return reg;
2413 }
2414
2415 /**
2416 * Factory method for a register.
2417 * @return A register instance.
2418 * @since 1.1.0
2419 */
2420 static const Register RDI() {
2421 Register reg( ::fcml_reg_RDI );
2422 return reg;
2423 }
2424
2425 /**
2426 * Factory method for a register.
2427 * @return A register instance.
2428 * @since 1.1.0
2429 */
2430 static const Register MM7() {
2431 Register reg( ::fcml_reg_MM7 );
2432 return reg;
2433 }
2434
2435 /**
2436 * Factory method for a register.
2437 * @return A register instance.
2438 * @since 1.1.0
2439 */
2440 static const Register XMM7() {
2441 Register reg( ::fcml_reg_XMM7 );
2442 return reg;
2443 }
2444
2445 /**
2446 * Factory method for a register.
2447 * @return A register instance.
2448 * @since 1.1.0
2449 */
2450 static const Register YMM7() {
2451 Register reg( ::fcml_reg_YMM7 );
2452 return reg;
2453 }
2454
2455 /**
2456 * Factory method for a register.
2457 * @return A register instance.
2458 * @since 1.2.0
2459 */
2460 static const Register ZMM7() {
2461 Register reg( ::fcml_reg_ZMM7 );
2462 return reg;
2463 }
2464
2465 /**
2466 * Factory method for a register.
2467 * @return A register instance.
2468 * @since 1.1.0
2469 */
2470 static const Register R8L() {
2471 Register reg( ::fcml_reg_R8L );
2472 return reg;
2473 }
2474
2475 /**
2476 * Factory method for a register.
2477 * @return A register instance.
2478 * @since 1.1.0
2479 */
2480 static const Register R8W() {
2481 Register reg( ::fcml_reg_R8W );
2482 return reg;
2483 }
2484
2485 /**
2486 * Factory method for a register.
2487 * @return A register instance.
2488 * @since 1.1.0
2489 */
2490 static const Register R8D() {
2491 Register reg( ::fcml_reg_R8D );
2492 return reg;
2493 }
2494
2495 /**
2496 * Factory method for a register.
2497 * @return A register instance.
2498 * @since 1.1.0
2499 */
2500 static const Register R8() {
2501 Register reg( ::fcml_reg_R8 );
2502 return reg;
2503 }
2504
2505 /**
2506 * Factory method for a register.
2507 * @return A register instance.
2508 * @since 1.1.0
2509 */
2510 static const Register XMM8() {
2511 Register reg( ::fcml_reg_XMM8 );
2512 return reg;
2513 }
2514
2515 /**
2516 * Factory method for a register.
2517 * @return A register instance.
2518 * @since 1.1.0
2519 */
2520 static const Register YMM8() {
2521 Register reg( ::fcml_reg_YMM8 );
2522 return reg;
2523 }
2524
2525 /**
2526 * Factory method for a register.
2527 * @return A register instance.
2528 * @since 1.2.0
2529 */
2530 static const Register ZMM8() {
2531 Register reg( ::fcml_reg_ZMM8 );
2532 return reg;
2533 }
2534
2535 /**
2536 * Factory method for a register.
2537 * @return A register instance.
2538 * @since 1.1.0
2539 */
2540 static const Register R9L() {
2541 Register reg( ::fcml_reg_R9L );
2542 return reg;
2543 }
2544
2545 /**
2546 * Factory method for a register.
2547 * @return A register instance.
2548 * @since 1.1.0
2549 */
2550 static const Register R9W() {
2551 Register reg( ::fcml_reg_R9W );
2552 return reg;
2553 }
2554
2555 /**
2556 * Factory method for a register.
2557 * @return A register instance.
2558 * @since 1.1.0
2559 */
2560 static const Register R9D() {
2561 Register reg( ::fcml_reg_R9D );
2562 return reg;
2563 }
2564
2565 /**
2566 * Factory method for a register.
2567 * @return A register instance.
2568 * @since 1.1.0
2569 */
2570 static const Register R9() {
2571 Register reg( ::fcml_reg_R9 );
2572 return reg;
2573 }
2574
2575 /**
2576 * Factory method for a register.
2577 * @return A register instance.
2578 * @since 1.1.0
2579 */
2580 static const Register XMM9() {
2581 Register reg( ::fcml_reg_XMM9 );
2582 return reg;
2583 }
2584
2585 /**
2586 * Factory method for a register.
2587 * @return A register instance.
2588 * @since 1.1.0
2589 */
2590 static const Register YMM9() {
2591 Register reg( ::fcml_reg_YMM9 );
2592 return reg;
2593 }
2594
2595 /**
2596 * Factory method for a register.
2597 * @return A register instance.
2598 * @since 1.2.0
2599 */
2600 static const Register ZMM9() {
2601 Register reg( ::fcml_reg_ZMM9 );
2602 return reg;
2603 }
2604
2605 /**
2606 * Factory method for a register.
2607 * @return A register instance.
2608 * @since 1.1.0
2609 */
2610 static const Register R10L() {
2611 Register reg( ::fcml_reg_R10L );
2612 return reg;
2613 }
2614
2615 /**
2616 * Factory method for a register.
2617 * @return A register instance.
2618 * @since 1.1.0
2619 */
2620 static const Register R10W() {
2621 Register reg( ::fcml_reg_R10W );
2622 return reg;
2623 }
2624
2625 /**
2626 * Factory method for a register.
2627 * @return A register instance.
2628 * @since 1.1.0
2629 */
2630 static const Register R10D() {
2631 Register reg( ::fcml_reg_R10D );
2632 return reg;
2633 }
2634
2635 /**
2636 * Factory method for a register.
2637 * @return A register instance.
2638 * @since 1.1.0
2639 */
2640 static const Register R10() {
2641 Register reg( ::fcml_reg_R10 );
2642 return reg;
2643 }
2644
2645 /**
2646 * Factory method for a register.
2647 * @return A register instance.
2648 * @since 1.1.0
2649 */
2650 static const Register XMM10() {
2651 Register reg( ::fcml_reg_XMM10 );
2652 return reg;
2653 }
2654
2655 /**
2656 * Factory method for a register.
2657 * @return A register instance.
2658 * @since 1.1.0
2659 */
2660 static const Register YMM10() {
2661 Register reg( ::fcml_reg_YMM10 );
2662 return reg;
2663 }
2664
2665 /**
2666 * Factory method for a register.
2667 * @return A register instance.
2668 * @since 1.2.0
2669 */
2670 static const Register ZMM10() {
2671 Register reg( ::fcml_reg_ZMM10 );
2672 return reg;
2673 }
2674
2675 /**
2676 * Factory method for a register.
2677 * @return A register instance.
2678 * @since 1.1.0
2679 */
2680 static const Register R11L() {
2681 Register reg( ::fcml_reg_R11L );
2682 return reg;
2683 }
2684
2685 /**
2686 * Factory method for a register.
2687 * @return A register instance.
2688 * @since 1.1.0
2689 */
2690 static const Register R11W() {
2691 Register reg( ::fcml_reg_R11W );
2692 return reg;
2693 }
2694
2695 /**
2696 * Factory method for a register.
2697 * @return A register instance.
2698 * @since 1.1.0
2699 */
2700 static const Register R11D() {
2701 Register reg( ::fcml_reg_R11D );
2702 return reg;
2703 }
2704
2705 /**
2706 * Factory method for a register.
2707 * @return A register instance.
2708 * @since 1.1.0
2709 */
2710 static const Register R11() {
2711 Register reg( ::fcml_reg_R11 );
2712 return reg;
2713 }
2714
2715 /**
2716 * Factory method for a register.
2717 * @return A register instance.
2718 * @since 1.1.0
2719 */
2720 static const Register XMM11() {
2721 Register reg( ::fcml_reg_XMM11 );
2722 return reg;
2723 }
2724
2725 /**
2726 * Factory method for a register.
2727 * @return A register instance.
2728 * @since 1.1.0
2729 */
2730 static const Register YMM11() {
2731 Register reg( ::fcml_reg_YMM11 );
2732 return reg;
2733 }
2734
2735 /**
2736 * Factory method for a register.
2737 * @return A register instance.
2738 * @since 1.2.0
2739 */
2740 static const Register ZMM11() {
2741 Register reg( ::fcml_reg_ZMM11 );
2742 return reg;
2743 }
2744
2745 /**
2746 * Factory method for a register.
2747 * @return A register instance.
2748 * @since 1.1.0
2749 */
2750 static const Register R12L() {
2751 Register reg( ::fcml_reg_R12L );
2752 return reg;
2753 }
2754
2755 /**
2756 * Factory method for a register.
2757 * @return A register instance.
2758 * @since 1.1.0
2759 */
2760 static const Register R12W() {
2761 Register reg( ::fcml_reg_R12W );
2762 return reg;
2763 }
2764
2765 /**
2766 * Factory method for a register.
2767 * @return A register instance.
2768 * @since 1.1.0
2769 */
2770 static const Register R12D() {
2771 Register reg( ::fcml_reg_R12D );
2772 return reg;
2773 }
2774
2775 /**
2776 * Factory method for a register.
2777 * @return A register instance.
2778 * @since 1.1.0
2779 */
2780 static const Register R12() {
2781 Register reg( ::fcml_reg_R12 );
2782 return reg;
2783 }
2784
2785 /**
2786 * Factory method for a register.
2787 * @return A register instance.
2788 * @since 1.1.0
2789 */
2790 static const Register XMM12() {
2791 Register reg( ::fcml_reg_XMM12 );
2792 return reg;
2793 }
2794
2795 /**
2796 * Factory method for a register.
2797 * @return A register instance.
2798 * @since 1.1.0
2799 */
2800 static const Register YMM12() {
2801 Register reg( ::fcml_reg_YMM12 );
2802 return reg;
2803 }
2804
2805 /**
2806 * Factory method for a register.
2807 * @return A register instance.
2808 * @since 1.2.0
2809 */
2810 static const Register ZMM12() {
2811 Register reg( ::fcml_reg_ZMM12 );
2812 return reg;
2813 }
2814
2815 /**
2816 * Factory method for a register.
2817 * @return A register instance.
2818 * @since 1.1.0
2819 */
2820 static const Register R13L() {
2821 Register reg( ::fcml_reg_R13L );
2822 return reg;
2823 }
2824
2825 /**
2826 * Factory method for a register.
2827 * @return A register instance.
2828 * @since 1.1.0
2829 */
2830 static const Register R13W() {
2831 Register reg( ::fcml_reg_R13W );
2832 return reg;
2833 }
2834
2835 /**
2836 * Factory method for a register.
2837 * @return A register instance.
2838 * @since 1.1.0
2839 */
2840 static const Register R13D() {
2841 Register reg( ::fcml_reg_R13D );
2842 return reg;
2843 }
2844
2845 /**
2846 * Factory method for a register.
2847 * @return A register instance.
2848 * @since 1.1.0
2849 */
2850 static const Register R13() {
2851 Register reg( ::fcml_reg_R13 );
2852 return reg;
2853 }
2854
2855 /**
2856 * Factory method for a register.
2857 * @return A register instance.
2858 * @since 1.1.0
2859 */
2860 static const Register XMM13() {
2861 Register reg( ::fcml_reg_XMM13 );
2862 return reg;
2863 }
2864
2865 /**
2866 * Factory method for a register.
2867 * @return A register instance.
2868 * @since 1.1.0
2869 */
2870 static const Register YMM13() {
2871 Register reg( ::fcml_reg_YMM13 );
2872 return reg;
2873 }
2874
2875 /**
2876 * Factory method for a register.
2877 * @return A register instance.
2878 * @since 1.2.0
2879 */
2880 static const Register ZMM13() {
2881 Register reg( ::fcml_reg_ZMM13 );
2882 return reg;
2883 }
2884
2885 /**
2886 * Factory method for a register.
2887 * @return A register instance.
2888 * @since 1.1.0
2889 */
2890 static const Register R14L() {
2891 Register reg( ::fcml_reg_R14L );
2892 return reg;
2893 }
2894
2895 /**
2896 * Factory method for a register.
2897 * @return A register instance.
2898 * @since 1.1.0
2899 */
2900 static const Register R14W() {
2901 Register reg( ::fcml_reg_R14W );
2902 return reg;
2903 }
2904
2905 /**
2906 * Factory method for a register.
2907 * @return A register instance.
2908 * @since 1.1.0
2909 */
2910 static const Register R14D() {
2911 Register reg( ::fcml_reg_R14D );
2912 return reg;
2913 }
2914
2915 /**
2916 * Factory method for a register.
2917 * @return A register instance.
2918 * @since 1.1.0
2919 */
2920 static const Register R14() {
2921 Register reg( ::fcml_reg_R14 );
2922 return reg;
2923 }
2924
2925 /**
2926 * Factory method for a register.
2927 * @return A register instance.
2928 * @since 1.1.0
2929 */
2930 static const Register XMM14() {
2931 Register reg( ::fcml_reg_XMM14 );
2932 return reg;
2933 }
2934
2935 /**
2936 * Factory method for a register.
2937 * @return A register instance.
2938 * @since 1.1.0
2939 */
2940 static const Register YMM14() {
2941 Register reg( ::fcml_reg_YMM14 );
2942 return reg;
2943 }
2944
2945 /**
2946 * Factory method for a register.
2947 * @return A register instance.
2948 * @since 1.2.0
2949 */
2950 static const Register ZMM14() {
2951 Register reg( ::fcml_reg_ZMM14 );
2952 return reg;
2953 }
2954
2955 /**
2956 * Factory method for a register.
2957 * @return A register instance.
2958 * @since 1.1.0
2959 */
2960 static const Register R15L() {
2961 Register reg( ::fcml_reg_R15L );
2962 return reg;
2963 }
2964
2965 /**
2966 * Factory method for a register.
2967 * @return A register instance.
2968 * @since 1.1.0
2969 */
2970 static const Register R15W() {
2971 Register reg( ::fcml_reg_R15W );
2972 return reg;
2973 }
2974
2975 /**
2976 * Factory method for a register.
2977 * @return A register instance.
2978 * @since 1.1.0
2979 */
2980 static const Register R15D() {
2981 Register reg( ::fcml_reg_R15D );
2982 return reg;
2983 }
2984
2985 /**
2986 * Factory method for a register.
2987 * @return A register instance.
2988 * @since 1.1.0
2989 */
2990 static const Register R15() {
2991 Register reg( ::fcml_reg_R15 );
2992 return reg;
2993 }
2994
2995 /**
2996 * Factory method for a register.
2997 * @return A register instance.
2998 * @since 1.1.0
2999 */
3000 static const Register XMM15() {
3001 Register reg( ::fcml_reg_XMM15 );
3002 return reg;
3003 }
3004
3005 /**
3006 * Factory method for a register.
3007 * @return A register instance.
3008 * @since 1.1.0
3009 */
3010 static const Register YMM15() {
3011 Register reg( ::fcml_reg_YMM15 );
3012 return reg;
3013 }
3014
3015 /**
3016 * Factory method for a register.
3017 * @return A register instance.
3018 * @since 1.2.0
3019 */
3020 static const Register ZMM15() {
3021 Register reg( ::fcml_reg_ZMM15 );
3022 return reg;
3023 }
3024
3025 /**
3026 * Factory method for a register.
3027 * @return A register instance.
3028 * @since 1.2.0
3029 */
3030 static const Register XMM16() {
3031 Register reg( ::fcml_reg_XMM16 );
3032 return reg;
3033 }
3034
3035 /**
3036 * Factory method for a register.
3037 * @return A register instance.
3038 * @since 1.2.0
3039 */
3040 static const Register YMM16() {
3041 Register reg( ::fcml_reg_YMM16 );
3042 return reg;
3043 }
3044
3045 /**
3046 * Factory method for a register.
3047 * @return A register instance.
3048 * @since 1.2.0
3049 */
3050 static const Register ZMM16() {
3051 Register reg( ::fcml_reg_ZMM16 );
3052 return reg;
3053 }
3054
3055 /**
3056 * Factory method for a register.
3057 * @return A register instance.
3058 * @since 1.2.0
3059 */
3060 static const Register XMM17() {
3061 Register reg( ::fcml_reg_XMM17 );
3062 return reg;
3063 }
3064
3065 /**
3066 * Factory method for a register.
3067 * @return A register instance.
3068 * @since 1.2.0
3069 */
3070 static const Register YMM17() {
3071 Register reg( ::fcml_reg_YMM17 );
3072 return reg;
3073 }
3074
3075 /**
3076 * Factory method for a register.
3077 * @return A register instance.
3078 * @since 1.2.0
3079 */
3080 static const Register ZMM17() {
3081 Register reg( ::fcml_reg_ZMM17 );
3082 return reg;
3083 }
3084
3085 /**
3086 * Factory method for a register.
3087 * @return A register instance.
3088 * @since 1.2.0
3089 */
3090 static const Register XMM18() {
3091 Register reg( ::fcml_reg_XMM18 );
3092 return reg;
3093 }
3094
3095 /**
3096 * Factory method for a register.
3097 * @return A register instance.
3098 * @since 1.2.0
3099 */
3100 static const Register YMM18() {
3101 Register reg( ::fcml_reg_YMM18 );
3102 return reg;
3103 }
3104
3105 /**
3106 * Factory method for a register.
3107 * @return A register instance.
3108 * @since 1.2.0
3109 */
3110 static const Register ZMM18() {
3111 Register reg( ::fcml_reg_ZMM18 );
3112 return reg;
3113 }
3114
3115 /**
3116 * Factory method for a register.
3117 * @return A register instance.
3118 * @since 1.2.0
3119 */
3120 static const Register XMM19() {
3121 Register reg( ::fcml_reg_XMM19 );
3122 return reg;
3123 }
3124
3125 /**
3126 * Factory method for a register.
3127 * @return A register instance.
3128 * @since 1.2.0
3129 */
3130 static const Register YMM19() {
3131 Register reg( ::fcml_reg_YMM19 );
3132 return reg;
3133 }
3134
3135 /**
3136 * Factory method for a register.
3137 * @return A register instance.
3138 * @since 1.2.0
3139 */
3140 static const Register ZMM19() {
3141 Register reg( ::fcml_reg_ZMM19 );
3142 return reg;
3143 }
3144
3145 /**
3146 * Factory method for a register.
3147 * @return A register instance.
3148 * @since 1.2.0
3149 */
3150 static const Register XMM20() {
3151 Register reg( ::fcml_reg_XMM20 );
3152 return reg;
3153 }
3154
3155 /**
3156 * Factory method for a register.
3157 * @return A register instance.
3158 * @since 1.2.0
3159 */
3160 static const Register YMM20() {
3161 Register reg( ::fcml_reg_YMM20 );
3162 return reg;
3163 }
3164
3165 /**
3166 * Factory method for a register.
3167 * @return A register instance.
3168 * @since 1.2.0
3169 */
3170 static const Register ZMM20() {
3171 Register reg( ::fcml_reg_ZMM20 );
3172 return reg;
3173 }
3174
3175 /**
3176 * Factory method for a register.
3177 * @return A register instance.
3178 * @since 1.2.0
3179 */
3180 static const Register XMM21() {
3181 Register reg( ::fcml_reg_XMM21 );
3182 return reg;
3183 }
3184
3185 /**
3186 * Factory method for a register.
3187 * @return A register instance.
3188 * @since 1.2.0
3189 */
3190 static const Register YMM21() {
3191 Register reg( ::fcml_reg_YMM21 );
3192 return reg;
3193 }
3194
3195 /**
3196 * Factory method for a register.
3197 * @return A register instance.
3198 * @since 1.2.0
3199 */
3200 static const Register ZMM21() {
3201 Register reg( ::fcml_reg_ZMM21 );
3202 return reg;
3203 }
3204
3205 /**
3206 * Factory method for a register.
3207 * @return A register instance.
3208 * @since 1.2.0
3209 */
3210 static const Register XMM22() {
3211 Register reg( ::fcml_reg_XMM22 );
3212 return reg;
3213 }
3214
3215 /**
3216 * Factory method for a register.
3217 * @return A register instance.
3218 * @since 1.2.0
3219 */
3220 static const Register YMM22() {
3221 Register reg( ::fcml_reg_YMM22 );
3222 return reg;
3223 }
3224
3225 /**
3226 * Factory method for a register.
3227 * @return A register instance.
3228 * @since 1.2.0
3229 */
3230 static const Register ZMM22() {
3231 Register reg( ::fcml_reg_ZMM22 );
3232 return reg;
3233 }
3234
3235 /**
3236 * Factory method for a register.
3237 * @return A register instance.
3238 * @since 1.2.0
3239 */
3240 static const Register XMM23() {
3241 Register reg( ::fcml_reg_XMM23 );
3242 return reg;
3243 }
3244
3245 /**
3246 * Factory method for a register.
3247 * @return A register instance.
3248 * @since 1.2.0
3249 */
3250 static const Register YMM23() {
3251 Register reg( ::fcml_reg_YMM23 );
3252 return reg;
3253 }
3254
3255 /**
3256 * Factory method for a register.
3257 * @return A register instance.
3258 * @since 1.2.0
3259 */
3260 static const Register ZMM23() {
3261 Register reg( ::fcml_reg_ZMM23 );
3262 return reg;
3263 }
3264
3265 /**
3266 * Factory method for a register.
3267 * @return A register instance.
3268 * @since 1.2.0
3269 */
3270 static const Register XMM24() {
3271 Register reg( ::fcml_reg_XMM24 );
3272 return reg;
3273 }
3274
3275 /**
3276 * Factory method for a register.
3277 * @return A register instance.
3278 * @since 1.2.0
3279 */
3280 static const Register YMM24() {
3281 Register reg( ::fcml_reg_YMM24 );
3282 return reg;
3283 }
3284
3285 /**
3286 * Factory method for a register.
3287 * @return A register instance.
3288 * @since 1.2.0
3289 */
3290 static const Register ZMM24() {
3291 Register reg( ::fcml_reg_ZMM24 );
3292 return reg;
3293 }
3294
3295 /**
3296 * Factory method for a register.
3297 * @return A register instance.
3298 * @since 1.2.0
3299 */
3300 static const Register XMM25() {
3301 Register reg( ::fcml_reg_XMM25 );
3302 return reg;
3303 }
3304
3305 /**
3306 * Factory method for a register.
3307 * @return A register instance.
3308 * @since 1.2.0
3309 */
3310 static const Register YMM25() {
3311 Register reg( ::fcml_reg_YMM25 );
3312 return reg;
3313 }
3314
3315 /**
3316 * Factory method for a register.
3317 * @return A register instance.
3318 * @since 1.2.0
3319 */
3320 static const Register ZMM25() {
3321 Register reg( ::fcml_reg_ZMM25 );
3322 return reg;
3323 }
3324
3325 /**
3326 * Factory method for a register.
3327 * @return A register instance.
3328 * @since 1.2.0
3329 */
3330 static const Register XMM26() {
3331 Register reg( ::fcml_reg_XMM26 );
3332 return reg;
3333 }
3334
3335 /**
3336 * Factory method for a register.
3337 * @return A register instance.
3338 * @since 1.2.0
3339 */
3340 static const Register YMM26() {
3341 Register reg( ::fcml_reg_YMM26 );
3342 return reg;
3343 }
3344
3345 /**
3346 * Factory method for a register.
3347 * @return A register instance.
3348 * @since 1.2.0
3349 */
3350 static const Register ZMM26() {
3351 Register reg( ::fcml_reg_ZMM26 );
3352 return reg;
3353 }
3354
3355 /**
3356 * Factory method for a register.
3357 * @return A register instance.
3358 * @since 1.2.0
3359 */
3360 static const Register XMM27() {
3361 Register reg( ::fcml_reg_XMM27 );
3362 return reg;
3363 }
3364
3365 /**
3366 * Factory method for a register.
3367 * @return A register instance.
3368 * @since 1.2.0
3369 */
3370 static const Register YMM27() {
3371 Register reg( ::fcml_reg_YMM27 );
3372 return reg;
3373 }
3374
3375 /**
3376 * Factory method for a register.
3377 * @return A register instance.
3378 * @since 1.2.0
3379 */
3380 static const Register ZMM27() {
3381 Register reg( ::fcml_reg_ZMM27 );
3382 return reg;
3383 }
3384
3385 /**
3386 * Factory method for a register.
3387 * @return A register instance.
3388 * @since 1.2.0
3389 */
3390 static const Register XMM28() {
3391 Register reg( ::fcml_reg_XMM28 );
3392 return reg;
3393 }
3394
3395 /**
3396 * Factory method for a register.
3397 * @return A register instance.
3398 * @since 1.2.0
3399 */
3400 static const Register YMM28() {
3401 Register reg( ::fcml_reg_YMM28 );
3402 return reg;
3403 }
3404
3405 /**
3406 * Factory method for a register.
3407 * @return A register instance.
3408 * @since 1.2.0
3409 */
3410 static const Register ZMM28() {
3411 Register reg( ::fcml_reg_ZMM28 );
3412 return reg;
3413 }
3414
3415 /**
3416 * Factory method for a register.
3417 * @return A register instance.
3418 * @since 1.2.0
3419 */
3420 static const Register XMM29() {
3421 Register reg( ::fcml_reg_XMM29 );
3422 return reg;
3423 }
3424
3425 /**
3426 * Factory method for a register.
3427 * @return A register instance.
3428 * @since 1.2.0
3429 */
3430 static const Register YMM29() {
3431 Register reg( ::fcml_reg_YMM29 );
3432 return reg;
3433 }
3434
3435 /**
3436 * Factory method for a register.
3437 * @return A register instance.
3438 * @since 1.2.0
3439 */
3440 static const Register ZMM29() {
3441 Register reg( ::fcml_reg_ZMM29 );
3442 return reg;
3443 }
3444
3445 /**
3446 * Factory method for a register.
3447 * @return A register instance.
3448 * @since 1.2.0
3449 */
3450 static const Register XMM30() {
3451 Register reg( ::fcml_reg_XMM30 );
3452 return reg;
3453 }
3454
3455 /**
3456 * Factory method for a register.
3457 * @return A register instance.
3458 * @since 1.2.0
3459 */
3460 static const Register YMM30() {
3461 Register reg( ::fcml_reg_YMM30 );
3462 return reg;
3463 }
3464
3465 /**
3466 * Factory method for a register.
3467 * @return A register instance.
3468 * @since 1.2.0
3469 */
3470 static const Register ZMM30() {
3471 Register reg( ::fcml_reg_ZMM30 );
3472 return reg;
3473 }
3474
3475 /**
3476 * Factory method for a register.
3477 * @return A register instance.
3478 * @since 1.2.0
3479 */
3480 static const Register XMM31() {
3481 Register reg( ::fcml_reg_XMM31 );
3482 return reg;
3483 }
3484
3485 /**
3486 * Factory method for a register.
3487 * @return A register instance.
3488 * @since 1.2.0
3489 */
3490 static const Register YMM31() {
3491 Register reg( ::fcml_reg_YMM31 );
3492 return reg;
3493 }
3494
3495 /**
3496 * Factory method for a register.
3497 * @return A register instance.
3498 * @since 1.2.0
3499 */
3500 static const Register ZMM31() {
3501 Register reg( ::fcml_reg_ZMM31 );
3502 return reg;
3503 }
3504
3505 /**
3506 * Factory method for a register.
3507 * @return A register instance.
3508 * @since 1.1.0
3509 */
3510 static const Register ES() {
3511 Register reg( ::fcml_reg_ES );
3512 return reg;
3513 }
3514
3515 /**
3516 * Factory method for a register.
3517 * @return A register instance.
3518 * @since 1.1.0
3519 */
3520 static const Register CS() {
3521 Register reg( ::fcml_reg_CS );
3522 return reg;
3523 }
3524
3525 /**
3526 * Factory method for a register.
3527 * @return A register instance.
3528 * @since 1.1.0
3529 */
3530 static const Register SS() {
3531 Register reg( ::fcml_reg_SS );
3532 return reg;
3533 }
3534
3535 /**
3536 * Factory method for a register.
3537 * @return A register instance.
3538 * @since 1.1.0
3539 */
3540 static const Register DS() {
3541 Register reg( ::fcml_reg_DS );
3542 return reg;
3543 }
3544
3545 /**
3546 * Factory method for a register.
3547 * @return A register instance.
3548 * @since 1.1.0
3549 */
3550 static const Register FS() {
3551 Register reg( ::fcml_reg_FS );
3552 return reg;
3553 }
3554
3555 /**
3556 * Factory method for a register.
3557 * @return A register instance.
3558 * @since 1.1.0
3559 */
3560 static const Register GS() {
3561 Register reg( ::fcml_reg_GS );
3562 return reg;
3563 }
3564
3565 /**
3566 * Factory method for a register.
3567 * @return A register instance.
3568 * @since 1.1.0
3569 */
3570 static const Register ST0() {
3571 Register reg( ::fcml_reg_ST0 );
3572 return reg;
3573 }
3574
3575 /**
3576 * Factory method for a register.
3577 * @return A register instance.
3578 * @since 1.1.0
3579 */
3580 static const Register ST1() {
3581 Register reg( ::fcml_reg_ST1 );
3582 return reg;
3583 }
3584
3585 /**
3586 * Factory method for a register.
3587 * @return A register instance.
3588 * @since 1.1.0
3589 */
3590 static const Register ST2() {
3591 Register reg( ::fcml_reg_ST2 );
3592 return reg;
3593 }
3594
3595 /**
3596 * Factory method for a register.
3597 * @return A register instance.
3598 * @since 1.1.0
3599 */
3600 static const Register ST3() {
3601 Register reg( ::fcml_reg_ST3 );
3602 return reg;
3603 }
3604
3605 /**
3606 * Factory method for a register.
3607 * @return A register instance.
3608 * @since 1.1.0
3609 */
3610 static const Register ST4() {
3611 Register reg( ::fcml_reg_ST4 );
3612 return reg;
3613 }
3614
3615 /**
3616 * Factory method for a register.
3617 * @return A register instance.
3618 * @since 1.1.0
3619 */
3620 static const Register ST5() {
3621 Register reg( ::fcml_reg_ST5 );
3622 return reg;
3623 }
3624
3625 /**
3626 * Factory method for a register.
3627 * @return A register instance.
3628 * @since 1.1.0
3629 */
3630 static const Register ST6() {
3631 Register reg( ::fcml_reg_ST6 );
3632 return reg;
3633 }
3634
3635 /**
3636 * Factory method for a register.
3637 * @return A register instance.
3638 * @since 1.1.0
3639 */
3640 static const Register ST7() {
3641 Register reg( ::fcml_reg_ST7 );
3642 return reg;
3643 }
3644
3645 /**
3646 * Factory method for a register.
3647 * @return A register instance.
3648 * @since 1.1.0
3649 */
3650 static const Register CR0() {
3651 Register reg( ::fcml_reg_CR0 );
3652 return reg;
3653 }
3654
3655 /**
3656 * Factory method for a register.
3657 * @return A register instance.
3658 * @since 1.1.0
3659 */
3660 static const Register CR2() {
3661 Register reg( ::fcml_reg_CR2 );
3662 return reg;
3663 }
3664
3665 /**
3666 * Factory method for a register.
3667 * @return A register instance.
3668 * @since 1.1.0
3669 */
3670 static const Register CR3() {
3671 Register reg( ::fcml_reg_CR3 );
3672 return reg;
3673 }
3674
3675 /**
3676 * Factory method for a register.
3677 * @return A register instance.
3678 * @since 1.1.0
3679 */
3680 static const Register CR4() {
3681 Register reg( ::fcml_reg_CR4 );
3682 return reg;
3683 }
3684
3685 /**
3686 * Factory method for a register.
3687 * @return A register instance.
3688 * @since 1.1.0
3689 */
3690 static const Register CR8() {
3691 Register reg( ::fcml_reg_CR8 );
3692 return reg;
3693 }
3694
3695 /**
3696 * Factory method for a register.
3697 * @return A register instance.
3698 * @since 1.1.0
3699 */
3700 static const Register DR0() {
3701 Register reg( ::fcml_reg_DR0 );
3702 return reg;
3703 }
3704
3705 /**
3706 * Factory method for a register.
3707 * @return A register instance.
3708 * @since 1.1.0
3709 */
3710 static const Register DR1() {
3711 Register reg( ::fcml_reg_DR1 );
3712 return reg;
3713 }
3714
3715 /**
3716 * Factory method for a register.
3717 * @return A register instance.
3718 * @since 1.1.0
3719 */
3720 static const Register DR2() {
3721 Register reg( ::fcml_reg_DR2 );
3722 return reg;
3723 }
3724
3725 /**
3726 * Factory method for a register.
3727 * @return A register instance.
3728 * @since 1.1.0
3729 */
3730 static const Register DR3() {
3731 Register reg( ::fcml_reg_DR3 );
3732 return reg;
3733 }
3734
3735 /**
3736 * Factory method for a register.
3737 * @return A register instance.
3738 * @since 1.1.0
3739 */
3740 static const Register DR4() {
3741 Register reg( ::fcml_reg_DR4 );
3742 return reg;
3743 }
3744
3745 /**
3746 * Factory method for a register.
3747 * @return A register instance.
3748 * @since 1.1.0
3749 */
3750 static const Register DR5() {
3751 Register reg( ::fcml_reg_DR5 );
3752 return reg;
3753 }
3754
3755 /**
3756 * Factory method for a register.
3757 * @return A register instance.
3758 * @since 1.1.0
3759 */
3760 static const Register DR6() {
3761 Register reg( ::fcml_reg_DR6 );
3762 return reg;
3763 }
3764
3765 /**
3766 * Factory method for a register.
3767 * @return A register instance.
3768 * @since 1.1.0
3769 */
3770 static const Register DR7() {
3771 Register reg( ::fcml_reg_DR7 );
3772 return reg;
3773 }
3774
3775 /**
3776 * Factory method for a register.
3777 * @return A register instance.
3778 * @since 1.1.0
3779 */
3780 static const Register IP() {
3781 Register reg( ::fcml_reg_IP );
3782 return reg;
3783 }
3784
3785 /**
3786 * Factory method for a register.
3787 * @return A register instance.
3788 * @since 1.1.0
3789 */
3790 static const Register EIP() {
3791 Register reg( ::fcml_reg_EIP );
3792 return reg;
3793 }
3794
3795 /**
3796 * Factory method for a register.
3797 * @return A register instance.
3798 * @since 1.1.0
3799 */
3800 static const Register RIP() {
3801 Register reg( ::fcml_reg_RIP );
3802 return reg;
3803 }
3804
3805 /**
3806 * Factory method for a register.
3807 * @return A register instance.
3808 * @since 1.2.0
3809 */
3810 static const Register K0() {
3811 Register reg( ::fcml_reg_K0 );
3812 return reg;
3813 }
3814
3815 /**
3816 * Factory method for a register.
3817 * @return A register instance.
3818 * @since 1.2.0
3819 */
3820 static const Register K1() {
3821 Register reg( ::fcml_reg_K1 );
3822 return reg;
3823 }
3824
3825 /**
3826 * Factory method for a register.
3827 * @return A register instance.
3828 * @since 1.2.0
3829 */
3830 static const Register K2() {
3831 Register reg( ::fcml_reg_K2 );
3832 return reg;
3833 }
3834
3835 /**
3836 * Factory method for a register.
3837 * @return A register instance.
3838 * @since 1.2.0
3839 */
3840 static const Register K3() {
3841 Register reg( ::fcml_reg_K3 );
3842 return reg;
3843 }
3844
3845 /**
3846 * Factory method for a register.
3847 * @return A register instance.
3848 * @since 1.2.0
3849 */
3850 static const Register K4() {
3851 Register reg( ::fcml_reg_K4 );
3852 return reg;
3853 }
3854
3855 /**
3856 * Factory method for a register.
3857 * @return A register instance.
3858 * @since 1.2.0
3859 */
3860 static const Register K5() {
3861 Register reg( ::fcml_reg_K5 );
3862 return reg;
3863 }
3864
3865 /**
3866 * Factory method for a register.
3867 * @return A register instance.
3868 * @since 1.2.0
3869 */
3870 static const Register K6() {
3871 Register reg( ::fcml_reg_K6 );
3872 return reg;
3873 }
3874
3875 /**
3876 * Factory method for a register.
3877 * @return A register instance.
3878 * @since 1.2.0
3879 */
3880 static const Register K7() {
3881 Register reg( ::fcml_reg_K7 );
3882 return reg;
3883 }
3884
3885 private:
3886
3887 /** Register type. */
3888 RegisterType _type;
3889 /** Register size in bits. */
3890 fcml_usize _size;
3891 /** Register itself as a positive integer. @see REGISTERS_GROUP */
3892 fcml_uint8_t _reg;
3893 /** In case of SPL,BPL,SIL,DIL GPR registers has to be set to true. */
3894 bool _x64_exp;
3895
3896 };
3897
3898 /**
3899 * Describes far pointer.
3900 * @since 1.1.0
3901 */
3902 class FarPointer {
3903
3904 public:
3905
3906 /**
3907 * Creates an far pointer instance.
3908 * @since 1.1.0
3909 */
3910 FarPointer() :
3911 _segment(0),
3912 _offset_size(0),
3913 _offset16(0),
3914 _offset32(0) {
3915 }
3916
3917 /**
3918 * Creates an far pointer instance.
3919 * @param segment A segment selector.
3920 * @param offset16 A 16-bit offset in the given segment.
3921 * @since 1.1.0
3922 */
3923 FarPointer( fcml_uint16_t segment, fcml_int16_t offset16 ) :
3924 _segment(segment),
3925 _offset_size(FCML_DS_16),
3926 _offset16(offset16),
3927 _offset32(0) {
3928 }
3929 /**
3930 * Creates an far pointer instance.
3931 * @param segment A segment selector.
3932 * @param offset32 A 32-bit offset in the given segment.
3933 * @since 1.1.0
3934 */
3935 FarPointer( fcml_uint16_t segment, fcml_int32_t offset32 ) :
3936 _segment(segment),
3937 _offset_size(FCML_DS_32),
3938 _offset16(0),
3939 _offset32(offset32) {
3940 }
3941
3942 virtual ~FarPointer() {
3943 }
3944
3945 public:
3946
3947 /**
3948 * Compares two far pointers.
3949 * @param fp The far pointer to be compared with the current one.
3950 * @return True if they are equal.
3951 * @since 1.1.0
3952 */
3953 bool operator==( const FarPointer &fp ) const {
3954 fcml_int32_t thisOffset;
3955 switch( _offset_size ) {
3956 case FCML_DS_32:
3957 thisOffset = _offset32;
3958 break;
3959 case FCML_DS_16:
3960 thisOffset = _offset16;
3961 break;
3962 }
3963 fcml_int32_t thatOffset;
3964 switch( fp._offset_size ) {
3965 case FCML_DS_32:
3966 thatOffset = fp._offset32;
3967 break;
3968 case FCML_DS_16:
3969 thatOffset = fp._offset16;
3970 break;
3971 }
3972 return thisOffset == thatOffset;
3973 }
3974
3975 /**
3976 * Compares two far pointers.
3977 * @param fp The far pointer to be compared with the current one.
3978 * @return True if they are NOT equal.
3979 * @since 1.1.0
3980 */
3981 bool operator!=( const FarPointer &fp) const {
3982 return !(fp == *this);
3983 }
3984
3985 public:
3986
3987 /**
3988 * Creates FarPointer instance for 16 bit segment and 16-bit offset.
3989 *
3990 * @param segment Segment selector.
3991 * @param offset 16-bit address.
3992 * @return FarPointer instance.
3993 * @since 1.1.0
3994 */
3995 static FarPointer off16( fcml_uint16_t segment, fcml_int16_t offset ) {
3996 return FarPointer(segment, offset);
3997 }
3998
3999 /**
4000 * Creates FarPointer instance for 16 bit segment and 32-bit offset.
4001 *
4002 * @param segment Segment selector.
4003 * @param offset 32-bit address.
4004 * @return FarPointer instance.
4005 */
4006 static FarPointer off32( fcml_uint16_t segment, fcml_int32_t offset ) {
4007 return FarPointer(segment, offset);
4008 }
4009
4010 public:
4011
4012 /**
4013 * Gets offset size.
4014 *
4015 * @return Offset size.
4016 * @since 1.1.0
4017 */
4018 fcml_usize getOffsetSize() const {
4019 return _offset_size;
4020 }
4021
4022 /**
4023 * Sets offset size.
4024 *
4025 * @param offsetSize The new offset size to be set.
4026 * @since 1.1.0
4027 */
4028 void setOffsetSize( fcml_usize offsetSize ) {
4029 _offset_size = offsetSize;
4030 }
4031
4032 /**
4033 * Gets the 16-bit offset.
4034 *
4035 * @return 16-bit offset.
4036 * @since 1.1.0
4037 */
4038 fcml_int16_t getOffset16() const {
4039 return _offset16;
4040 }
4041
4042 /**
4043 * Sets 16-bit offset.
4044 *
4045 * @param offset16 Sets 16-bit offset.
4046 * @since 1.1.0
4047 */
4048 void setOffset16( fcml_int16_t offset16 ) {
4049 _offset16 = offset16;
4050 }
4051
4052 /**
4053 * Gets 32-bit offset.
4054 *
4055 * @return 32-bit offset.
4056 * @since 1.1.0
4057 */
4058 fcml_int32_t getOffset32() const {
4059 return _offset32;
4060 }
4061
4062 /**
4063 * Sets 32-bit offset.
4064 *
4065 * @param offset32 Sets 32-bit offset.
4066 * @since 1.1.0
4067 */
4068 void setOffset32( fcml_int32_t offset32 ) {
4069 _offset32 = offset32;
4070 }
4071
4072 /**
4073 * Gets segment selector.
4074 *
4075 * @return 16-bit segment selector.
4076 * @since 1.1.0
4077 */
4078 fcml_uint16_t getSegment() const {
4079 return _segment;
4080 }
4081
4082 /**
4083 * Sets segment selector.
4084 *
4085 * @param segment Segment selector.
4086 * @since 1.1.0
4087 */
4088 void setSegment( fcml_uint16_t segment ) {
4089 _segment = segment;
4090 }
4091
4092 private:
4093
4094 /** 16-bit Code segment. */
4095 fcml_uint16_t _segment;
4096 /** Size of the offset. */
4097 fcml_usize _offset_size;
4098 /** 16-bit offset. */
4099 fcml_int16_t _offset16;
4100 /** 32-bit offset. */
4101 fcml_int32_t _offset32;
4102
4103 };
4104
4105 /**
4106 * Describes segment register.
4107 * @since 1.1.0
4108 */
4109 class SegmentSelector {
4110 public:
4111
4112 /**
4113 * Creates an empty segment selector instance.
4114 * @since 1.1.0
4115 */
4116 SegmentSelector() :
4117 _segmentSelector(),
4118 _isDefaultReg(false) {
4119 }
4120
4121 /**
4122 * Creates a segment selector instance for given parameters.
4123 * @param segmentSelector A segment register.
4124 * @param isDefaultReg Information if the register is the default one.
4125 * @since 1.1.0
4126 */
4127 SegmentSelector( const Register &segmentSelector, bool isDefaultReg = FCML_TRUE ) :
4128 _segmentSelector(segmentSelector),
4129 _isDefaultReg(isDefaultReg) {
4130 }
4131
4132 virtual ~SegmentSelector() {
4133 }
4134
4135 public:
4136
4137 /**
4138 * Checks if two segment selector are equal.
4139 * @param segmentSelector The source segment selector.
4140 * @return True if they are equal.
4141 * @since 1.1.0
4142 */
4143 bool operator==( const SegmentSelector &segmentSelector ) const {
4144 // It really doesn't matter if it is the default segment register in a given context.
4145 return segmentSelector._segmentSelector == _segmentSelector;
4146 }
4147
4148 /**
4149 * Checks if two segment selector are not equal.
4150 * @param segmentSelector The source segment selector.
4151 * @return True if they are NOT equal.
4152 * @since 1.1.0
4153 */
4154 bool operator!=( const SegmentSelector &segmentSelector ) const {
4155 return !(*this == segmentSelector);
4156 }
4157
4158 /**
4159 * Casting operator.
4160 * @return The segment register.
4161 * @since 1.1.0
4162 */
4163 operator Register() const {
4164 return _segmentSelector;
4165 }
4166
4167 /**
4168 * Copies one segment selector to another.
4169 * @param reg The source segment selector.
4170 * @return The destination segment selector.
4171 * @since 1.1.0
4172 */
4173 SegmentSelector& operator=( const SegmentSelector &reg ) {
4174 if( &reg != this ) {
4175 _isDefaultReg = reg._isDefaultReg;
4176 _segmentSelector = reg._segmentSelector;
4177 }
4178 return *this;
4179 }
4180
4181 public:
4182
4183 /**
4184 * Creates segment selector for the given register.
4185 *
4186 * @param segmentSelector Segment register.
4187 * @param isDefaultReg True if the register is the default one in the given context.
4188 * @return Prepared segment selector.
4189 * @since 1.1.0
4190 */
4191 static SegmentSelector seg( const Register &segmentSelector, bool isDefaultReg ) {
4192 return SegmentSelector( segmentSelector, isDefaultReg );
4193 }
4194
4195 public:
4196
4197 /**
4198 * Returns true if a register stored in the segment selector is the default one
4199 * in the context the segment selector is used.
4200 *
4201 * @return True if register is the default one.
4202 * @since 1.1.0
4203 */
4204 bool isDefaultReg() const {
4205 return _isDefaultReg;
4206 }
4207
4208 /**
4209 * Sets "default" flag for the segment selector.
4210 *
4211 * @param isDefaultReg True if the register is the default one in the given context.
4212 * @since 1.1.0
4213 */
4214 void setDefaultReg( bool isDefaultReg ) {
4215 _isDefaultReg = isDefaultReg;
4216 }
4217
4218 /**
4219 * Gets constant segment register associated with the selector.
4220 *
4221 * @return Constant segment register.
4222 * @since 1.1.0
4223 */
4224 const Register& getSegmentSelector() const {
4225 return _segmentSelector;
4226 }
4227
4228 /**
4229 * Gets segment register associated with the selector.
4230 *
4231 * @return Segment register.
4232 * @since 1.1.0
4233 */
4234 Register& getSegmentSelector() {
4235 return _segmentSelector;
4236 }
4237
4238 /**
4239 * Sets segment register for the selector.
4240 *
4241 * @param segmentSelector Segment register.
4242 * @since 1.1.0
4243 */
4244 void setSegmentSelector( const Register& segmentSelector ) {
4245 _segmentSelector = segmentSelector;
4246 }
4247
4248 private:
4249 /** Segment register. */
4250 Register _segmentSelector;
4251 /** True if this is a default segment register. */
4252 bool _isDefaultReg;
4253 };
4254
4255 /**
4256 * Describes effective address.
4257 *
4258 * It's a counterpart to the fcml_st_effective_address structure.
4259 * @since 1.1.0
4260 */
4261 class EffectiveAddress {
4262 public:
4263
4264 /**
4265 * Creates an empry effective address.
4266 * @since 1.1.0
4267 */
4268 EffectiveAddress() :
4269 _scaleFactor(0){
4270 }
4271
4272 /**
4273 * Creates an effective address instance with the displacement only.
4274 * @param displacement The displacement value.
4275 * @since 1.1.0
4276 */
4277 EffectiveAddress( const Integer &displacement ) :
4278 _scaleFactor(0),
4279 _displacement(displacement) {
4280 }
4281
4282 /**
4283 * Creates an effective address instance with the base register only.
4284 * @param base The base register.
4285 * @since 1.1.0
4286 */
4287 EffectiveAddress( const Register &base ) :
4288 _base(base),
4289 _scaleFactor(0) {
4290 }
4291
4292 /**
4293 * Creates an effective address instance with the base register and displacement only.
4294 * @param base The base register.
4295 * @param displacement The displacement value.
4296 * @since 1.1.0
4297 */
4298 EffectiveAddress( const Register &base, const Integer &displacement ) :
4299 _base(base),
4300 _scaleFactor(0),
4301 _displacement(displacement) {
4302 }
4303
4304 /**
4305 * Creates an effective address instance with the index register, scale factor and displacement.
4306 * @param index The index register.
4307 * @param scaleFactor The scale factor value.
4308 * @param displacement The displacement.
4309 * @since 1.1.0
4310 */
4311 EffectiveAddress( const Register &index, fcml_uint8_t scaleFactor, const Integer &displacement ) :
4312 _index(index),
4313 _scaleFactor(scaleFactor),
4314 _displacement(displacement) {
4315 }
4316
4317 /**
4318 * Creates an effective address instance with the base register and index register.
4319 * @param base The base register.
4320 * @param index The index register.
4321 * @since 1.1.0
4322 */
4323 EffectiveAddress( const Register &base, const Register &index ) :
4324 _base(base),
4325 _index(index),
4326 _scaleFactor(0) {
4327 }
4328
4329 /**
4330 * Creates an effective address instance with the base register, index register and scale factor set.
4331 * @param base The base register.
4332 * @param index THe index register.
4333 * @param scaleFactor The scale factor.
4334 * @since 1.1.0
4335 */
4336 EffectiveAddress( const Register &base, const Register &index, fcml_uint8_t scaleFactor ) :
4337 _base(base),
4338 _index(index),
4339 _scaleFactor(scaleFactor) {
4340 }
4341
4342 /**
4343 * Creates an effective address instance with the base register, index register, scale factor and displacement set.
4344 * @param base The base register.
4345 * @param index The index register.
4346 * @param scaleFactor The scale factor value.
4347 * @param displacement The displacement.
4348 * @since 1.1.0
4349 */
4350 EffectiveAddress( const Register &base, const Register &index, fcml_uint8_t scaleFactor, const Integer &displacement ) :
4351 _base(base),
4352 _index(index),
4353 _scaleFactor(scaleFactor),
4354 _displacement(displacement) {
4355 }
4356
4357 /**
4358 * @since 1.1.0
4359 */
4360 virtual ~EffectiveAddress() {
4361 }
4362
4363 public:
4364
4365 /**
4366 * Checks whether two effective addresses are equal or not.
4367 * @param address The source address to be compared.
4368 * @return True if they are equal.
4369 * @since 1.1.0
4370 */
4371 bool operator==( const EffectiveAddress &address ) const {
4372 if( &address == this ) {
4373 return true;
4374 }
4375 return _base == address._base &&
4376 _index == address._index &&
4377 _scaleFactor == address._scaleFactor &&
4378 _displacement == address._displacement;
4379 }
4380
4381 /**
4382 * Checks whether two effective addresses are equal or not.
4383 * @param address The source address to be compared.
4384 * @return True if they are NOT equal.
4385 * @since 1.1.0
4386 */
4387 bool operator!=( const EffectiveAddress &address ) const {
4388 return !(address == *this);
4389 }
4390
4391 public:
4392
4393 /**
4394 * Factory method which creates an effective address instance with the displacement only.
4395 * @param displacement The displacement value.
4396 * @since 1.1.0
4397 */
4398 static EffectiveAddress addr( const Integer &displacement ) {
4399 return EffectiveAddress( displacement );
4400 }
4401
4402 /**
4403 * Factory method which creates an effective address instance with the base register only.
4404 * @param base The base register.
4405 * @since 1.1.0
4406 */
4407 static EffectiveAddress addr( const Register &base ) {
4408 return EffectiveAddress( base );
4409 }
4410
4411 /**
4412 * Factory method which creates an effective address instance with the base register and displacement.
4413 * @param base The base register.
4414 * @param displacement The displacement value.
4415 * @since 1.1.0
4416 */
4417 static EffectiveAddress addr( const Register &base, const Integer &displacement ) {
4418 return EffectiveAddress( base, displacement );
4419 }
4420
4421 /**
4422 * Factory method which creates an effective address instance with the index register, scale factor and displacement.
4423 * @param index The index register.
4424 * @param scaleFactor The scale factor.
4425 * @param displacement The displacement value.
4426 * @since 1.1.0
4427 */
4428 static EffectiveAddress addr( const Register &index, fcml_uint8_t scaleFactor, const Integer &displacement ) {
4429 return EffectiveAddress( index, scaleFactor, displacement );
4430 }
4431
4432 /**
4433 * Factory method which creates an effective address instance with the base register and index register.
4434 * @param base The base register.
4435 * @param index The index register.
4436 * @since 1.1.0
4437 */
4438 static EffectiveAddress addr( const Register &base, const Register &index ) {
4439 return EffectiveAddress( base, index, 0 );
4440 }
4441
4442 /**
4443 * Factory method which creates an effective address instance with the base register, index register and scale factor.
4444 * @param base The base register.
4445 * @param index The index register.
4446 * @param scaleFactor The scale factor.
4447 * @since 1.1.0
4448 */
4449 static EffectiveAddress addr( const Register &base, const Register &index, fcml_uint8_t scaleFactor ) {
4450 return EffectiveAddress( base, index, scaleFactor );
4451 }
4452
4453 /**
4454 * Factory method which creates an effective address instance with the base register, index register, scale factor and displacement.
4455 * @param base The base register.
4456 * @param index The index register.
4457 * @param scaleFactor The scale factor.
4458 * @param displacement The displacement value.
4459 * @since 1.1.0
4460 */
4461 static EffectiveAddress addr( const Register &base, const Register &index, fcml_uint8_t scaleFactor, const Integer &displacement ) {
4462 return EffectiveAddress( base, index, scaleFactor, displacement );
4463 }
4464
4465 public:
4466
4467 /**
4468 * Gets the constant base register associated with the effective address.
4469 *
4470 * @return The constant base register.
4471 * @since 1.1.0
4472 */
4473 const Register& getBase() const {
4474 return _base;
4475 }
4476
4477 /**
4478 * Gets the base register associated with the effective address.
4479 *
4480 * @return The base register.
4481 * @since 1.1.0
4482 */
4483 Register& getBase() {
4484 return _base;
4485 }
4486
4487 /**
4488 * Sets a new base register for the effective address.
4489 *
4490 * @param base The new base register to be set.
4491 * @return Effective address itself.
4492 * @since 1.1.0
4493 */
4494 EffectiveAddress& setBase( const Register &base ) {
4495 _base = base;
4496 return *this;
4497 }
4498
4499 /**
4500 * Gets the constant displacement associated with the effective address.
4501 *
4502 * @return The constant displacement.
4503 * @since 1.1.0
4504 */
4505 const Integer& getDisplacement() const {
4506 return _displacement;
4507 }
4508
4509 /**
4510 * Gets the displacement associated with the effective address.
4511 *
4512 * @return The displacement.
4513 * @since 1.1.0
4514 */
4515 Integer& getDisplacement() {
4516 return _displacement;
4517 }
4518
4519 /**
4520 * Sets a new displacement value for the effective address.
4521 *
4522 * @param displacement The new displacement for effective address.
4523 * @return The effective address itself.
4524 * @since 1.1.0
4525 */
4526 EffectiveAddress& setDisplacement( const Integer &displacement ) {
4527 _displacement = displacement;
4528 return *this;
4529 }
4530
4531 /**
4532 * Gets the constant index register associated with the effective address.
4533 *
4534 * @return The index register.
4535 * @since 1.1.0
4536 */
4537 const Register& getIndex() const {
4538 return _index;
4539 }
4540
4541 /**
4542 * Gets the index register associated with the effective address.
4543 *
4544 * @return The index register.
4545 * @since 1.1.0
4546 */
4547 Register& getIndex() {
4548 return _index;
4549 }
4550
4551 /**
4552 * Sets a new index register for the effective address.
4553 *
4554 * @param index The new index register for the effective address.
4555 * @return The effective address itself.
4556 * @since 1.1.0
4557 */
4558 EffectiveAddress& setIndex( const Register &index ) {
4559 _index = index;
4560 return *this;
4561 }
4562
4563 /**
4564 * Gets a scale factor value associated with the effective address.
4565 *
4566 * @return The scale factor.
4567 * @since 1.1.0
4568 */
4569 fcml_uint8_t getScaleFactor() const {
4570 return _scaleFactor;
4571 }
4572
4573 /**
4574 * Sets a new scale factor for the effective address.
4575 *
4576 * @param scaleFactor The new scale factor value.
4577 * @return Effective address itself.
4578 * @since 1.1.0
4579 */
4580 EffectiveAddress& setScaleFactor( fcml_uint8_t scaleFactor ) {
4581 _scaleFactor = scaleFactor;
4582 return *this;
4583 }
4584
4585 private:
4586 /** Base register. */
4587 Register _base;
4588 /** Index register. */
4589 Register _index;
4590 /** Scale factor. */
4591 fcml_uint8_t _scaleFactor;
4592 /** Displacement. */
4593 Integer _displacement;
4594 };
4595
4596 /** Address operand.
4597 *
4598 * It's a counterpart to the fcml_st_address structure.
4599 * @since 1.1.0
4600 */
4601 class Address {
4602
4603 public:
4604
4605 /** Addressing type, see fcml_en_address_form enumerator.
4606 * @since 1.1.0
4607 */
4608 enum AddressForm {
4609 /** Default value set if memory addressing hasn't been configured. */
4610 AF_UNDEFINED = FCML_AF_UNDEFINED,
4611 /** Absolute offset (address). */
4612 AF_OFFSET = FCML_AF_OFFSET,
4613 /** Effective address combined from address components like base register, index registers, factor, displacement etc... */
4614 AF_COMBINED = FCML_AF_COMBINED
4615 };
4616
4617 /**
4618 * Creates an empty address.
4619 * @since 1.1.0
4620 */
4621 Address() :
4622 _size_operator( FCML_DS_UNDEF ),
4623 _address_form( AF_UNDEFINED ) {
4624 }
4625
4626 /**
4627 * Creates an address instance with an offset and optional size operator set.
4628 *
4629 * @param offset Offset to be set for the address.
4630 * @param sizeOperator The optional size operator, set to FCML_DS_UNDEF by default.
4631 * @since 1.1.0
4632 */
4633 Address( const Integer &offset, fcml_usize sizeOperator = FCML_DS_UNDEF ) :
4634 _size_operator( sizeOperator ),
4635 _address_form( AF_OFFSET ),
4636 _offset( offset ) {
4637 }
4638
4639 /**
4640 * Creates an address instance with an effective address and optional size operator set.
4641 *
4642 * @param effectiveAddress The effective address to be set for the address.
4643 * @param sizeOperator The optional size operator, set to FCML_DS_UNDEF by default.
4644 * @since 1.1.0
4645 */
4646 Address( const EffectiveAddress &effectiveAddress, fcml_usize sizeOperator = FCML_DS_UNDEF ) :
4647 _size_operator( sizeOperator ),
4648 _address_form( AF_COMBINED ),
4649 _effective_address( effectiveAddress ) {
4650 }
4651
4652 /**
4653 * Creates an address instance with an effective address, segment selector and optional size operator set.
4654 *
4655 * @param effectiveAddress The effective address to be set for the address.
4656 * @param segmentSelector The segment selector.
4657 * @param sizeOperator The optional size operator, set to FCML_DS_UNDEF by default.
4658 * @since 1.1.0
4659 */
4660 Address( const EffectiveAddress &effectiveAddress, const SegmentSelector &segmentSelector, fcml_usize sizeOperator = FCML_DS_UNDEF ) :
4661 _size_operator( sizeOperator ),
4662 _address_form( AF_COMBINED ),
4663 _segment_selector( segmentSelector ),
4664 _effective_address( effectiveAddress ) {
4665 }
4666
4667 /** @since 1.1.0 */
4668 virtual ~Address() {
4669 }
4670
4671 public:
4672
4673 /**
4674 * Factory method which creates an effective address instance with the displacement only.
4675 * @param displacement The displacement value.
4676 * @param sizeOperator Size operator.
4677 * @since 1.1.0
4678 */
4679 static Address effective( const Integer &displacement, fcml_usize sizeOperator = FCML_DS_UNDEF ) {
4680 return effective( EffectiveAddress( displacement ), sizeOperator );
4681 }
4682
4683 /**
4684 * Factory method which creates an effective address instance with the base register only.
4685 * @param base The base register.
4686 * @param sizeOperator Size operator.
4687 * @since 1.1.0
4688 */
4689 static Address effective( const Register &base, fcml_usize sizeOperator = FCML_DS_UNDEF ) {
4690 return effective( EffectiveAddress( base ), sizeOperator );
4691 }
4692
4693 /**
4694 * Factory method which creates an effective address instance with the base register and displacement.
4695 * @param base The base register.
4696 * @param displacement The displacement value.
4697 * @param sizeOperator Size operator.
4698 * @since 1.1.0
4699 */
4700 static Address effective( const Register &base, const Integer &displacement, fcml_usize sizeOperator = FCML_DS_UNDEF ) {
4701 return effective( EffectiveAddress( base, displacement ), sizeOperator );
4702 }
4703
4704 /**
4705 * Factory method which creates an effective address instance with the index register, scale factor and displacement.
4706 * @param index The index register.
4707 * @param scaleFactor The scale factor.
4708 * @param displacement The displacement value.
4709 * @param sizeOperator Size operator.
4710 * @since 1.1.0
4711 */
4712 static Address effective( const Register &index, fcml_uint8_t scaleFactor, const Integer &displacement, fcml_usize sizeOperator = FCML_DS_UNDEF ) {
4713 return effective( EffectiveAddress( index, scaleFactor, displacement ), sizeOperator );
4714 }
4715
4716 /**
4717 * Factory method which creates an effective address instance with the base register and index register.
4718 * @param base The base register.
4719 * @param index The index register.
4720 * @param sizeOperator Size operator.
4721 * @since 1.1.0
4722 */
4723 static Address effective( const Register &base, const Register &index, fcml_usize sizeOperator = FCML_DS_UNDEF ) {
4724 return effective( EffectiveAddress( base, index, 0 ), sizeOperator );
4725 }
4726
4727 /**
4728 * Factory method which creates an effective address instance with the base register, index register and scale factor.
4729 * @param base The base register.
4730 * @param index The index register.
4731 * @param scaleFactor The scale factor.
4732 * @param sizeOperator Size operator.
4733 * @since 1.1.0
4734 */
4735 static Address effective( const Register &base, const Register &index, fcml_uint8_t scaleFactor, fcml_usize sizeOperator = FCML_DS_UNDEF ) {
4736 return effective( EffectiveAddress( base, index, scaleFactor ), sizeOperator );
4737 }
4738
4739 /**
4740 * Factory method which creates an effective address instance with the base register, index register, scale factor and displacement.
4741 * @param base The base register.
4742 * @param index The index register.
4743 * @param scaleFactor The scale factor.
4744 * @param displacement The displacement value.
4745 * @param sizeOperator Size operator.
4746 * @since 1.1.0
4747 */
4748 static Address effective( const Register &base, const Register &index, fcml_uint8_t scaleFactor, const Integer &displacement, fcml_usize sizeOperator = FCML_DS_UNDEF ) {
4749 return effective( EffectiveAddress( base, index, scaleFactor, displacement ), sizeOperator );
4750 }
4751
4752
4753 public:
4754
4755 /**
4756 * Checks if two addresses are equal or not.
4757 * @param address The address to be compared with the current one.
4758 * @return True if they are equal.
4759 * @since 1.1.0
4760 */
4761 bool operator==( const Address &address ) const {
4762 if( &address == this ) {
4763 return true;
4764 }
4765 return _size_operator == address._size_operator &&
4766 _address_form == address._address_form &&
4767 _segment_selector == address._segment_selector &&
4768 _effective_address == address._effective_address &&
4769 _offset == address._offset;
4770 }
4771
4772 /**
4773 * Checks if two addresses are equal or not.
4774 * @param address The address to be compared with the current one.
4775 * @return True if they are NOT equal.
4776 * @since 1.1.0
4777 */
4778 bool operator!=( const Address &address ) const {
4779 return !(address == *this );
4780 }
4781
4782 public:
4783
4784 /**
4785 * Factor method which creates an instance of the address for an effective address, segment selector and optional size operator.
4786 *
4787 * @param effectiveAddress The effective address to be set for the address.
4788 * @param segmentSelector The segment selector.
4789 * @param sizeOperator The optional size operator, set to FCML_DS_UNDEF by default.
4790 * @return The created address instance.
4791 * @since 1.1.0
4792 */
4793 static Address effective( const EffectiveAddress &effectiveAddress, const SegmentSelector &segmentSelector, fcml_usize sizeOperator = FCML_DS_UNDEF ) {
4794 return Address( effectiveAddress, segmentSelector, sizeOperator );
4795 }
4796
4797 /**
4798 * Factor method which creates an address instance with an effective address and optional size operator set.
4799 *
4800 * @param effectiveAddress The effective address to be set for the address.
4801 * @param sizeOperator The optional size operator, set to FCML_DS_UNDEF by default.
4802 * @return The created address instance.
4803 * @since 1.1.0
4804 */
4805 static Address effective( const EffectiveAddress &effectiveAddress, fcml_usize sizeOperator = FCML_DS_UNDEF ) {
4806 return Address( effectiveAddress, sizeOperator );
4807 }
4808
4809 /**
4810 * Factor method which creates an address instance with an offset and optional size operator set.
4811 *
4812 * @param offset The offset to be set for the address.
4813 * @param sizeOperator The optional size operator, set to FCML_DS_UNDEF by default.
4814 * @return The created address instance.
4815 * @since 1.1.0
4816 */
4817 static Address offset( const Integer &offset, fcml_usize sizeOperator = FCML_DS_UNDEF ) {
4818 return Address( offset, sizeOperator );
4819 }
4820
4821 public:
4822
4823 /**
4824 * Returns true if address holds effective address.
4825 *
4826 * @return Returns true if address holds effective address.
4827 * @since 1.1.0
4828 */
4829 bool isEffectiveAddress() const {
4830 return _address_form == AF_COMBINED;
4831 }
4832
4833 /**
4834 * Returns true if address holds an offset only.
4835 *
4836 * @return Returns true if address holds an offset only.
4837 * @since 1.1.0
4838 */
4839 bool isOffset() const {
4840 return _address_form == AF_OFFSET;
4841 }
4842
4843 /**
4844 * Gets an address form. See fcml_en_address_form for more details.
4845 *
4846 * @return The address form.
4847 * @since 1.1.0
4848 */
4849 AddressForm getAddressForm() const {
4850 return _address_form;
4851 }
4852
4853 /**
4854 * Sets a new address form for the effective address.
4855 *
4856 * @param addressForm The address form to be set for the effective address.
4857 *
4858 * @return Address itself.
4859 * @since 1.1.0
4860 */
4861 Address& setAddressForm( AddressForm addressForm ) {
4862 _address_form = addressForm;
4863 return *this;
4864 }
4865
4866 /**
4867 * Gets reference to the constant effective address associated with the address.
4868 *
4869 * @return The constant effective address.
4870 * @since 1.1.0
4871 */
4872 const EffectiveAddress& getEffectiveAddress() const {
4873 return _effective_address;
4874 }
4875
4876 /**
4877 * Gets reference to the effective address associated with the address.
4878 *
4879 * @return The effective address.
4880 * @since 1.1.0
4881 */
4882 EffectiveAddress& getEffectiveAddress() {
4883 return _effective_address;
4884 }
4885
4886 /**
4887 * Sets a new effective address for the address.
4888 *
4889 * @param effectiveAddress The new address to be set for the effective address.
4890 * @return The address itself.
4891 * @since 1.1.0
4892 */
4893 Address& setEffectiveAddress( const EffectiveAddress& effectiveAddress ) {
4894 _effective_address = effectiveAddress;
4895 return *this;
4896 }
4897
4898 /**
4899 * Gets the constant offset associated with the address.
4900 *
4901 * @return The offset associated with the address.
4902 * @since 1.1.0
4903 */
4904 const Integer& getOffset() const {
4905 return _offset;
4906 }
4907
4908 /**
4909 * Gets the offset associated with the address.
4910 *
4911 * @return The offset associated with the address.
4912 * @since 1.1.0
4913 */
4914 Integer& getOffset() {
4915 return _offset;
4916 }
4917
4918 /**
4919 * Sets a new offset for the address.
4920 *
4921 * @param offset The enw offset to be set for the address.
4922 * @return The address itself.
4923 * @since 1.1.0
4924 */
4925 Address& setOffset( const Integer &offset ) {
4926 this->_offset = offset;
4927 return *this;
4928 }
4929
4930 /**
4931 * Gets the constant segment selector associated with the address.
4932 *
4933 * @return The segment selector associated with the address.
4934 * @since 1.1.0
4935 */
4936 const SegmentSelector& getSegmentSelector() const {
4937 return _segment_selector;
4938 }
4939
4940 /**
4941 * Gets the segment selector associated with the address.
4942 *
4943 * @return The segment selector associated with the address.
4944 * @since 1.1.0
4945 */
4946 SegmentSelector& getSegmentSelector() {
4947 return _segment_selector;
4948 }
4949
4950 /**
4951 * Sets a new segment selector for the address.
4952 *
4953 * @param segmentSelector The new segment selector for the address.
4954 * @return The address itself.
4955 * @since 1.1.0
4956 */
4957 Address& setSegmentSelector( const SegmentSelector &segmentSelector ) {
4958 _segment_selector = segmentSelector;
4959 return *this;
4960 }
4961
4962 /**
4963 * Gets the size operator associated with the address.
4964 *
4965 * @return The size operator.
4966 * @since 1.1.0
4967 */
4968 fcml_usize getSizeOperator() const {
4969 return _size_operator;
4970 }
4971
4972 /**
4973 * Sets a new size operator for the address.
4974 *
4975 * @param sizeOperator The size operator.
4976 * @since 1.1.0
4977 */
4978 Address& setSizeOperator( fcml_usize sizeOperator ) {
4979 _size_operator = sizeOperator;
4980 return *this;
4981 }
4982
4983 private:
4984
4985 /** Size of data accessed in memory.*/
4986 fcml_usize _size_operator;
4987 /** Memory addressing format: absolute offset/effective address. @see fcml_en_effective_address_form*/
4988 AddressForm _address_form;
4989 /** Segment register.*/
4990 SegmentSelector _segment_selector;
4991 /** Memory address for FCML_AF_COMBINED form.*/
4992 EffectiveAddress _effective_address;
4993 /** Memory address for FCML_AF_OFFSET form.*/
4994 Integer _offset;
4995
4996 };
4997
4998 /** Holds operand decorators.
4999 * @since 1.2.0
5000 */
5001 class Decorators {
5002 public:
5003
5004 /**
5005 * Rounding mode.
5006 */
5007 enum EmbeededRoundingControl {
5008 FCML_ERC_RNE = 0,
5009 FCML_ERC_RD,
5010 FCML_ERC_RU,
5011 FCML_ERC_RZ
5012 };
5013
5014 /**
5015 * Creates an empty operand decorators container.
5016 * @since 1.2.0
5017 */
5018 Decorators() : _z(FCML_FALSE), _operandMaskReg(Register::UNDEF()),
5019 _sae(FCML_FALSE) {
5020 }
5021
5022 /**
5023 * Sets a new AVX-512 {z} decorator.
5024 *
5025 * @param z {z} decorator.
5026 * @return Decorators.
5027 * @since 1.2.0
5028 */
5029 Decorators& setZ(fcml_bool z) {
5030 _z = z;
5031 return *this;
5032 }
5033
5034 /**
5035 * Sets a new AVX-512 {bcast} decorator.
5036 *
5037 * @param bcast Decorator value.
5038 * @return Decorators..
5039 * @since 1.2.0
5040 */
5041 Decorators& setBcast(const Nullable<fcml_uint8_t> &bcast) {
5042 _bcast = bcast;
5043 return *this;
5044 }
5045
5046 /**
5047 * Sets AVX-512 opmask register for {k} decorator.
5048 *
5049 * @param opmaskReg Opmask register.
5050 * @since 1.2.0
5051 */
5052 Decorators& setOpmaskReg( const Register& opmaskReg ) {
5053 _operandMaskReg = opmaskReg;
5054 return *this;
5055 }
5056
5057 /**
5058 * Sets AVX-512 {er} decorator.
5059 *
5060 * @param er {er} decorator.
5061 * @since 1.2.0
5062 */
5063 Decorators& setEr(const Nullable<EmbeededRoundingControl> &er) {
5064 _er = er;
5065 return *this;
5066 }
5067
5068 /**
5069 * Sets AVX-512 {sae} decorator.
5070 *
5071 * @param sae {sae} decorator.
5072 * @since 1.2.0
5073 */
5074 Decorators& setSae(const fcml_bool sae) {
5075 _sae = sae;
5076 return *this;
5077 }
5078
5079 /**
5080 * Gets AVX-512 {z} operator.
5081 *
5082 * @return {z} operator.
5083 * @since 1.2.0
5084 */
5085 fcml_bool isZ() const {
5086 return _z;
5087 }
5088
5089 /**
5090 * Gets AVX-512 {bcast} decorator.
5091 *
5092 * @return Value of {bcast} decorator.
5093 * @since 1.2.0
5094 */
5095 const Nullable<fcml_uint8_t>& getBcast() const {
5096 return _bcast;
5097 }
5098
5099 /**
5100 * Gets constant AVX-512 opmask register for {k} decorator.
5101 *
5102 * @return Opmask register.
5103 * @since 1.2.0
5104 */
5105 const Register& getOpmaskReg() const {
5106 return _operandMaskReg;
5107 }
5108
5109 /**
5110 * Gets AVX-512 opmask register for {k} decorator.
5111 *
5112 * @return Opmask register.
5113 * @since 1.2.0
5114 */
5115 Register& getOpmaskReg() {
5116 return _operandMaskReg;
5117 }
5118
5119 /**
5120 * Gets AVX-512 {er} decorator.
5121 *
5122 * @return Value of {er} decorator.
5123 * @since 1.2.0
5124 */
5125 const Nullable<EmbeededRoundingControl>& getEr() const {
5126 return _er;
5127 }
5128
5129 /**
5130 * Gets AVX-512 {sae} decorator.
5131 *
5132 * @return True if {sae} is set.
5133 * @since 1.2.0
5134 */
5135 fcml_bool isSae() const {
5136 return _sae;
5137 }
5138
5139 public:
5140
5141 /**
5142 * Checks if two decorators containers are equal or not.
5143 * @param decorators Decorators.
5144 * @return True if they are equal.
5145 * @since 1.2.0
5146 */
5147 bool operator==(const Decorators &decorators) const {
5148 if(&decorators == this) {
5149 return true;
5150 }
5151 return _z == decorators._z &&
5152 _bcast == decorators._bcast &&
5153 _operandMaskReg == decorators._operandMaskReg &&
5154 _er == decorators._er &&
5155 _sae == decorators._sae;
5156 }
5157
5158 /**
5159 * Checks if two decorators are equal or not.
5160 * @param decorators Decorators.
5161 * @return True if they are NOT equal.
5162 * @since 1.2.0
5163 */
5164 bool operator!=(const Decorators &decorators) const {
5165 return !(decorators == *this);
5166 }
5167
5168 private:
5169 /** Broadcasting: 2, 4, 8, 16, 32, 64. */
5170 Nullable<fcml_uint8_t> _bcast;
5171 /** Zeroing masking. */
5172 fcml_bool _z;
5173 /** The 64-bit k registers are: k0 through k7. */
5174 Register _operandMaskReg;
5175 /** Embedded rounding control. */
5176 Nullable<EmbeededRoundingControl> _er;
5177 /** Indicates support for SAE (Suppress All Exceptions). */
5178 fcml_bool _sae;
5179 };
5180
5181 /** Instruction operand.
5182 * @since 1.1.0
5183 */
5184 class Operand {
5185 public:
5186
5187 /** See fcml_en_operand_type structure for more details.
5188 * @since 1.1.0
5189 */
5190 enum OperandType {
5191 /** Operand not used. */
5192 OT_NONE = FCML_OT_NONE,
5193 /** Immediate integer value. */
5194 OT_IMMEDIATE = FCML_OT_IMMEDIATE,
5195 /** Direct far pointer. */
5196 OT_FAR_POINTER = FCML_OT_FAR_POINTER,
5197 /** Memory address. */
5198 OT_ADDRESS = FCML_OT_ADDRESS,
5199 /** Processor register. */
5200 OT_REGISTER = FCML_OT_REGISTER,
5201 /** Virtual operand */
5202 OT_VIRTUAL = FCML_OT_VIRTUAL
5203 };
5204
5205 /**
5206 * Creates an undefined operand.
5207 * @since 1.1.0
5208 */
5209 Operand() :
5210 _hints( FCML_OP_HINT_UNDEFIEND ),
5211 _operandType( OT_NONE ) {
5212 }
5213
5214 /**
5215 * Creates an immediate value operand for given integer.
5216 *
5217 * @param imm The immediate value as integer.
5218 * @param hints Optional operand level hints.
5219 * @since 1.1.0
5220 */
5221 Operand( const Integer &imm, fcml_hints hints = FCML_OP_HINT_UNDEFIEND ) :
5222 _hints( hints ),
5223 _operandType(OT_IMMEDIATE ),
5224 _immediate( imm ) {
5225 }
5226
5227 /**
5228 * Creates a far pointer operand for given far pointer.
5229 *
5230 * @param pointer The far pointer for the operand.
5231 * @param hints Optional operand level hints.
5232 * @since 1.1.0
5233 */
5234 Operand( const FarPointer &pointer, fcml_hints hints = FCML_OP_HINT_UNDEFIEND ) :
5235 _hints( hints ),
5236 _operandType( OT_FAR_POINTER ),
5237 _farPointer( pointer ) {
5238 }
5239
5240 /**
5241 * Creates an address operand for given address.
5242 *
5243 * @param address The address for the created operand.
5244 * @param hints Optional operand level hints.
5245 * @since 1.1.0
5246 */
5247 Operand( const Address &address, fcml_hints hints = FCML_OP_HINT_UNDEFIEND ) :
5248 _hints( hints ),
5249 _operandType( OT_ADDRESS ),
5250 _address( address ) {
5251 }
5252
5253 /**
5254 * Creates a new register operand for given register.
5255 *
5256 * @param reg The register for the new operand being created.
5257 * @param hints Optional operand level hints.
5258 * @since 1.1.0
5259 */
5260 Operand( const Register &reg, fcml_hints hints = FCML_OP_HINT_UNDEFIEND ) :
5261 _hints( hints ),
5262 _operandType( OT_REGISTER ),
5263 _register( reg ) {
5264 }
5265
5266 public:
5267
5268 /**
5269 * Checks if two operands are equal or not.
5270 *
5271 * @param op The operand to be compared with the current one.
5272 * @return True if the operands are equal.
5273 * @since 1.1.0
5274 */
5275 bool operator==( const Operand &op ) const {
5276 if( &op == this ) {
5277 return true;
5278 }
5279 bool equal = false;
5280 switch( _operandType ) {
5281 case OT_ADDRESS:
5282 equal = _address == op._address;
5283 break;
5284 case OT_FAR_POINTER:
5285 equal = _farPointer == op._farPointer;
5286 break;
5287 case OT_IMMEDIATE:
5288 equal = _immediate == op._immediate;
5289 break;
5290 case OT_REGISTER:
5291 equal = _register == op._register;
5292 break;
5293 case OT_VIRTUAL:
5294 equal = true;
5295 break;
5296 case OT_NONE:
5297 equal = true;
5298 break;
5299 }
5300 return equal && op._hints == _hints && op._decorators == _decorators;
5301 }
5302
5303 /**
5304 * Checks if two operands are equal or not.
5305 *
5306 * @param op The operand to be compared with the current one.
5307 * @return True if the operands are NOT equal.
5308 * @since 1.1.0
5309 */
5310 bool operator!=( const Operand &op ) const {
5311 return !(op == *this);
5312 }
5313
5314 public:
5315
5316 /**
5317 * Converts operand to the undefined one.
5318 * @since 1.1.0
5319 */
5320 void undef() {
5321 _operandType = OT_NONE;
5322 }
5323
5324 /**
5325 * Sets given immediate value for the operand and makes it to be an immediate operand.
5326 *
5327 * @param imm The immediate value.
5328 * @since 1.1.0
5329 */
5330 void imm( const Integer &imm ) {
5331 _operandType = OT_IMMEDIATE;
5332 _immediate = imm;
5333 }
5334
5335 /**
5336 * Converts operand to the far pointer and sets the segment selector and offset for it.
5337 *
5338 * @param seg The segment selector.
5339 * @param addr Offset.
5340 * @since 1.1.0
5341 */
5342 void far_ptr( fcml_uint16_t seg, fcml_int16_t addr ) {
5343 _operandType = OT_FAR_POINTER;
5344 _farPointer = FarPointer( seg, addr );
5345 }
5346
5347 /**
5348 * Prepares far pointer operand for given components.
5349 *
5350 * @param seg The segment selector.
5351 * @param addr The offset.
5352 * @since 1.1.0
5353 */
5354 void far_ptr( fcml_uint16_t seg, fcml_int32_t addr ) {
5355 _operandType = OT_FAR_POINTER;
5356 _farPointer = FarPointer( seg, addr );
5357 }
5358
5359 /**
5360 * Prepares far pointer operand for given far pointer.
5361 *
5362 * @param pointer Far pointer to be set for the operand.
5363 * @since 1.1.0
5364 */
5365 void far_ptr( const FarPointer &pointer ) {
5366 _operandType = OT_FAR_POINTER;
5367 _farPointer = pointer;
5368 }
5369
5370 /**
5371 * Prepares address operand for given address.
5372 *
5373 * @param address The address to be set for the operand.
5374 * @since 1.1.0
5375 */
5376 void addr( const Address &address ) {
5377 _operandType = OT_ADDRESS;
5378 _address = address;
5379 }
5380
5381 /**
5382 * Prepares address operand for given offset.
5383 *
5384 * @param offset The offset to be set for the operand.
5385 * @param sizeOperator The size operator to be set for the address.
5386 * @since 1.1.0
5387 */
5388 void off( const Integer &offset, fcml_usize sizeOperator = FCML_DS_UNDEF ) {
5389 _operandType = OT_ADDRESS;
5390 _address = Address( offset, sizeOperator );
5391 }
5392
5393 /**
5394 * Prepares an address operand for given effective address and optional size operator.
5395 *
5396 * @param effectiveAddress The effective address.
5397 * @param sizeOperator The size operator.
5398 * @since 1.1.0
5399 */
5400 void addr( const EffectiveAddress &effectiveAddress, fcml_usize sizeOperator = FCML_DS_UNDEF ) {
5401 _operandType = OT_ADDRESS;
5402 _address = Address( effectiveAddress, sizeOperator );
5403 }
5404
5405 /**
5406 * Prepares address operator for given parameters.
5407 *
5408 * @param effectiveAddress The effective address.
5409 * @param segmentSelector The segment selector.
5410 * @param sizeOperator The size operator.
5411 * @since 1.1.0
5412 */
5413 void addr( const EffectiveAddress &effectiveAddress, const SegmentSelector &segmentSelector, fcml_usize sizeOperator = FCML_DS_UNDEF ) {
5414 _operandType = OT_ADDRESS;
5415 _address = Address( effectiveAddress, segmentSelector, sizeOperator );
5416 }
5417
5418 /**
5419 * Prepares operator for the given register.
5420 *
5421 * @param reg The register for the operator.
5422 * @since 1.1.0
5423 */
5424 void reg( const Register &reg ) {
5425 _operandType = OT_REGISTER;
5426 _register = reg;
5427 }
5428
5429 /**
5430 * Prepares an register operator for given register compounds.
5431 *
5432 * @param reg A register number.
5433 * @param size A register size.
5434 * @param type A register type.
5435 * @param x64_exp An optional marker for the SPL, BPL, SIL etc. registers. See manual for more information.
5436 * @since 1.1.0
5437 */
5438 void reg( fcml_uint8_t reg, fcml_usize size, Register::RegisterType type = Register::REG_GPR, fcml_bool x64_exp = FCML_FALSE ) {
5439 _operandType = OT_REGISTER;
5440 _register = Register( reg, size, type, x64_exp );
5441 }
5442
5443 public:
5444
5445 /**
5446 * Returns true if operand is an immediate value operand.
5447 *
5448 * @return True if operand is an immediate value operand.
5449 * @since 1.1.0
5450 */
5451 bool isImm() const {
5452 return _operandType == OT_IMMEDIATE;
5453 }
5454
5455 /**
5456 * Returns true if operand is a register operand.
5457 *
5458 * @return True if operand is a register operand.
5459 * @since 1.1.0
5460 */
5461 bool isReg() const {
5462 return _operandType == OT_REGISTER;
5463 }
5464
5465 /**
5466 * Returns true if operand is an address operand.
5467 *
5468 * @return True if operand is an address operand.
5469 * @since 1.1.0
5470 */
5471 bool isAddr() const {
5472 return _operandType == OT_ADDRESS;
5473 }
5474
5475 /**
5476 * Returns true if operand is a far pointer operand.
5477 *
5478 * @return True if operand is a far pointer operand.
5479 * @since 1.1.0
5480 */
5481 bool isFar() const {
5482 return _operandType == OT_FAR_POINTER;
5483 }
5484
5485 /**
5486 * Gets reference to the constant address associated with the operand.
5487 *
5488 * @return The reference to the address.
5489 * @since 1.1.0
5490 */
5491 const Address& getAddress() const {
5492 return _address;
5493 }
5494
5495 /**
5496 * Gets reference to the address associated with the operand.
5497 *
5498 * @return The reference to the address.
5499 * @since 1.1.0
5500 */
5501 Address& getAddress() {
5502 return _address;
5503 }
5504
5505 /**
5506 * Sets a new address for the operand.
5507 *
5508 * @param address The new address.
5509 * @return The operand itself.
5510 * @since 1.1.0
5511 */
5512 Operand& setAddress( const Address &address ) {
5513 _address = address;
5514 return *this;
5515 }
5516
5517 /**
5518 * Gets a reference to the constant far pointer instance associated with the address.
5519 *
5520 * @return The far pointer instance associated with the address.
5521 * @since 1.1.0
5522 */
5523 const FarPointer& getFarPointer() const {
5524 return _farPointer;
5525 }
5526
5527 /**
5528 * Gets a reference to the far pointer instance associated with the address.
5529 *
5530 * @return The far pointer instance associated with the address.
5531 * @since 1.1.0
5532 */
5533 FarPointer& getFarPointer() {
5534 return _farPointer;
5535 }
5536
5537 /**
5538 * Sets a new far pointer for the operand.
5539 *
5540 * @param farPointer The new far pointer instance.
5541 * @return The operand itself.
5542 * @since 1.1.0
5543 */
5544 Operand& setFarPointer( const FarPointer &farPointer ) {
5545 _farPointer = farPointer;
5546 return *this;
5547 }
5548
5549 /**
5550 * Gets a reference to the constant immediate value associated with the operand.
5551 *
5552 * @return The immediate value.
5553 * @since 1.1.0
5554 */
5555 const Integer& getImmediate() const {
5556 return _immediate;
5557 }
5558
5559 /**
5560 * Gets a reference to the immediate value associated with the operand.
5561 *
5562 * @return The immediate value.
5563 * @since 1.1.0
5564 */
5565 Integer& getImmediate() {
5566 return _immediate;
5567 }
5568
5569 /**
5570 * Sets a new immediate value for the address.
5571 *
5572 * @param immediate The new immediate value.
5573 * @return The operand itself.
5574 * @since 1.1.0
5575 */
5576 Operand& setImmediate( const Integer &immediate ) {
5577 _immediate = immediate;
5578 return *this;
5579 }
5580
5581 /**
5582 * Gets operand type.
5583 *
5584 * @return The operand type.
5585 * @since 1.1.0
5586 */
5587 OperandType getOperandType() const {
5588 return _operandType;
5589 }
5590
5591 /**
5592 * Sets a new operand type.
5593 *
5594 * @param operandType The new operand type.
5595 * @return The operand itself.
5596 * @since 1.1.0
5597 */
5598 Operand& setOperandType( OperandType operandType ) {
5599 _operandType = operandType;
5600 return *this;
5601 }
5602
5603 /**
5604 * Returns a reference to the constant register associated with the operand.
5605 *
5606 * @return The reference to the register associated with the operand.
5607 * @since 1.1.0
5608 */
5609 const Register& getRegister() const {
5610 return _register;
5611 }
5612
5613 /**
5614 * Returns a reference to the register associated with the operand.
5615 *
5616 * @return The reference to the register associated with the operand.
5617 * @since 1.1.0
5618 */
5619 Register& getRegister() {
5620 return _register;
5621 }
5622
5623 /**
5624 * Sets a new register for the operand.
5625 *
5626 * @param reg The new register.
5627 * @return The operand itself.
5628 * @since 1.1.0
5629 */
5630 Operand& setRegister( const Register &reg ) {
5631 this->_register = reg;
5632 return *this;
5633 }
5634
5635 /**
5636 * Gets hits associated with the operand.
5637 *
5638 * @return The hits associated with the operand.
5639 * @since 1.1.0
5640 */
5641 fcml_hints getHints() const {
5642 return _hints;
5643 }
5644
5645 /**
5646 * Sets new operand level hits for the operand.
5647 *
5648 * @param hints The new hits to be set.
5649 * @return The operand itself.
5650 * @since 1.1.0
5651 */
5652 Operand& setHints( fcml_hints hints ) {
5653 _hints = hints;
5654 return *this;
5655 }
5656
5657 /**
5658 * Gets constant decorators associated with the operand.
5659 *
5660 * @return The decorators associated with the operand.
5661 * @since 1.2.0
5662 */
5663 const Decorators& getDecorators() const {
5664 return _decorators;
5665 }
5666
5667 /**
5668 * Gets decorators associated with the operand.
5669 *
5670 * @return The decorators associated with the operand.
5671 * @since 1.2.0
5672 */
5673 Decorators& getDecorators() {
5674 return _decorators;
5675 }
5676
5677 /**
5678 * Sets new operand decorators for the operand.
5679 *
5680 * @param decorators The new decorators to be set.
5681 * @return The operand itself.
5682 * @since 1.2.0
5683 */
5684 Operand& setDecorators(const Decorators& decorators) {
5685 _decorators = decorators;
5686 return *this;
5687 }
5688
5689 // Hints
5690
5691 /**
5692 * Returns information if the operand is multimedia one or not. For more details about the
5693 * multimedia operand head over to the manual pages.
5694 *
5695 * @return true if it's a multimedia operand.
5696 * @since 1.1.0
5697 */
5698 bool isMultimedia() const {
5699 return _hints & FCML_OP_HINT_MULTIMEDIA_INSTRUCTION;
5700 }
5701
5702 /**
5703 * Returns true if it's an displacement relative address.
5704 *
5705 * @return True if it's an displacement relative address.
5706 * @since 1.1.0
5707 */
5708 bool isDisRelativeAddress() const {
5709 return ( _hints & FCML_OP_HINT_DISPLACEMENT_RELATIVE_ADDRESS ) ? true : false;
5710 }
5711
5712 /**
5713 * Returns true if it's pseudo opcode operand. More information
5714 * about pseudo opcodes in the manual.
5715 *
5716 * @return True if it's pseudo opcode operand.
5717 * @since 1.1.0
5718 */
5719 bool isPseudoOpcode() const {
5720 return ( _hints & FCML_OP_HINT_PSEUDO_OPCODE ) ? true : false;
5721 }
5722
5723 /**
5724 * Returns true if it's an absolute offset being set in the operand.
5725 *
5726 * @return True in case of absolute addressing being used.
5727 * @since 1.1.0
5728 */
5729 bool isAbsoluteAddressing() const {
5730 return ( _hints & FCML_OP_HINT_ABSOLUTE_ADDRESSING ) ? true : false;
5731 }
5732
5733 /**
5734 * Returns true is relative addressing is used.
5735 *
5736 * @return True in case of relative addressing.
5737 * @since 1.1.0
5738 */
5739 bool isRelativeAddressing() const {
5740 return ( _hints & FCML_OP_HINT_RELATIVE_ADDRESSING ) ? true : false;
5741 }
5742
5743 /**
5744 * Returns true if the SIB byte is used.
5745 *
5746 * @return True if the SIB byte is used.
5747 * @since 1.1.0
5748 */
5749 bool isSIBEncoding() const {
5750 return ( _hints & FCML_OP_HINT_SIB_ENCODING ) ? true : false;
5751 }
5752
5753 public:
5754
5755 /**
5756 * A casting operator.
5757 * @since 1.1.0
5758 */
5759 operator const Integer&() const {
5760 return _immediate;
5761 }
5762
5763 /**
5764 * A casting operator.
5765 * @since 1.1.0
5766 */
5767 operator const FarPointer&() const {
5768 return _farPointer;
5769 }
5770
5771 /**
5772 * A casting operator.
5773 * @since 1.1.0
5774 */
5775 operator const Address&() const {
5776 return _address;
5777 }
5778
5779 /**
5780 * A casting operator.
5781 * @since 1.1.0
5782 */
5783 operator const Register&() const {
5784 return _register;
5785 }
5786
5787 private:
5788
5789 /** Operand hints */
5790 fcml_hints _hints;
5791 /** Operand type */
5792 OperandType _operandType;
5793 /** Describes immediate operand */
5794 Integer _immediate;
5795 /** Describes far pointer. */
5796 FarPointer _farPointer;
5797 /** Describes address. */
5798 Address _address;
5799 /** Describes register. */
5800 Register _register;
5801 /** Operand decorators.
5802 * since 1.2.0
5803 */
5804 Decorators _decorators;
5805
5806 };
5807
5808 /** Operand builder.
5809 * A builder that exposes various factory methods that can be used to create
5810 * several types of the instruction operands. These methods are very simple
5811 * so no API documentation has been provided for now. Just take a look at
5812 * the source code.
5813 *
5814 * @since 1.1.0
5815 */
5816 class OB {
5817 public:
5818
5819 /**
5820 * Factory method which builds an empty operand.
5821 * @return The empty operand.
5822 * @since 1.1.0
5823 */
5824 static Operand undef() {
5825 return Operand();
5826 }
5827
5828 /**
5829 * Factory method which builds an immediate operand.
5830 * @return The immediate operand.
5831 * @since 1.1.0
5832 */
5833 static Operand imm( const Integer &imm ) {
5834 return Operand( imm );
5835 }
5836
5837 /**
5838 * Factory method which builds a far pointer operand.
5839 * @param seg A segment selector.
5840 * @param addr An 16-bit offset value.
5841 * @return The far pointer operand.
5842 * @since 1.1.0
5843 */
5844 static Operand far_ptr( fcml_uint16_t seg, fcml_int16_t addr ) {
5845 return Operand( FarPointer( seg, addr ) );
5846 }
5847
5848 /**
5849 * Factory method which builds a far pointer operand.
5850 * @param seg A segment selector.
5851 * @param addr An 32-bit offset value.
5852 * @return The far pointer operand.
5853 * @since 1.1.0
5854 */
5855 static Operand far_ptr( fcml_uint16_t seg, fcml_int32_t addr ) {
5856 return Operand( FarPointer( seg, addr ) );
5857 }
5858
5859 /**
5860 * Factory method which builds a far pointer operand.
5861 * @param pointer A far pointer instance.
5862 * @return The far pointer operand.
5863 * @since 1.1.0
5864 */
5865 static Operand far_ptr( const FarPointer &pointer ) {
5866 return Operand( pointer );
5867 }
5868
5869 /**
5870 * Factory method which builds an address operand.
5871 * @param address An address instance.
5872 * @return The address operand.
5873 * @since 1.1.0
5874 */
5875 static Operand addr( const Address &address ) {
5876 return Operand( address );
5877 }
5878
5879 /**
5880 * Factory method which builds an address operand.
5881 * @param offset An offset instance.
5882 * @param sizeOperator An optional size operator.
5883 * @return The address operand.
5884 * @since 1.1.0
5885 */
5886 static Operand off( const Integer &offset, fcml_usize sizeOperator = FCML_DS_UNDEF ) {
5887 return Operand( Address( offset, sizeOperator ) );
5888 }
5889
5890 /**
5891 * Factory method which builds an offset based address operand with byte size operator.
5892 * @param offset An offset instance.
5893 * @return The address operand.
5894 * @since 1.1.0
5895 */
5896 static Operand offb( const Integer &offset ) {
5897 return Operand( Address( offset, FCML_DS_8 ) );
5898 }
5899
5900 /**
5901 * Factory method which builds an offset based address operand with word size operator.
5902 * @param offset An offset instance.
5903 * @return The address operand.
5904 * @since 1.1.0
5905 */
5906 static Operand offw( const Integer &offset ) {
5907 return Operand( Address( offset, FCML_DS_16 ) );
5908 }
5909
5910 /**
5911 * Factory method which builds an offset based address operand with double word size operator.
5912 * @param offset An offset instance.
5913 * @return The address operand.
5914 * @since 1.1.0
5915 */
5916 static Operand offd( const Integer &offset ) {
5917 return Operand( Address( offset, FCML_DS_32 ) );
5918 }
5919
5920 /**
5921 * Factory method which builds an offset based address operand with quadro word size operator.
5922 * @param offset An offset instance.
5923 * @return The address operand.
5924 * @since 1.1.0
5925 */
5926 static Operand offq( const Integer &offset ) {
5927 return Operand( Address( offset, FCML_DS_64 ) );
5928 }
5929
5930 /**
5931 * Factory method which creates address type operand for given effective address and optional size operator.
5932 * @param effectiveAddress The effective address.
5933 * @param sizeOperator The optional size operator.
5934 * @return The created operator.
5935 * @since 1.1.0
5936 */
5937 static Operand addr( const EffectiveAddress &effectiveAddress, fcml_usize sizeOperator = FCML_DS_UNDEF ) {
5938 return Operand( Address( effectiveAddress, sizeOperator ) );
5939 }
5940
5941 /**
5942 * Factory method which creates address type operand for given effective address and byte size operator.
5943 * @param effectiveAddress The effective address.
5944 * @return The created operator.
5945 * @since 1.1.0
5946 */
5947 static Operand addrb( const EffectiveAddress &effectiveAddress ) {
5948 return Operand( Address( effectiveAddress, FCML_DS_8 ) );
5949 }
5950
5951 /**
5952 * Factory method which creates address type operand for given effective address and word size operator.
5953 * @param effectiveAddress The effective address.
5954 * @return The created operator.
5955 * @since 1.1.0
5956 */
5957 static Operand addrw( const EffectiveAddress &effectiveAddress ) {
5958 return Operand( Address( effectiveAddress, FCML_DS_16 ) );
5959 }
5960
5961 /**
5962 * Factory method which creates address type operand for given effective address and double word size operator.
5963 * @param effectiveAddress The effective address.
5964 * @return The created operator.
5965 * @since 1.1.0
5966 */
5967 static Operand addrd( const EffectiveAddress &effectiveAddress ) {
5968 return Operand( Address( effectiveAddress, FCML_DS_32 ) );
5969 }
5970
5971 /**
5972 * Factory method which creates address type operand for given effective address and quadro word size operator.
5973 * @param effectiveAddress The effective address.
5974 * @return The created operator.
5975 * @since 1.1.0
5976 */
5977 static Operand addrq( const EffectiveAddress &effectiveAddress ) {
5978 return Operand( Address( effectiveAddress, FCML_DS_64 ) );
5979 }
5980
5981 /**
5982 * Factory method which creates address type operand for given segment selector, effective address and optional size operator.
5983 * @param effectiveAddress The effective address.
5984 * @param segmentSelector The segment selector.
5985 * @param sizeOperator The optional size operator.
5986 * @return The created operator.
5987 * @since 1.1.0
5988 */
5989 static Operand addr( const EffectiveAddress &effectiveAddress, const SegmentSelector &segmentSelector, fcml_usize sizeOperator = FCML_DS_UNDEF ) {
5990 return Operand( Address( effectiveAddress, segmentSelector, sizeOperator ) );
5991 }
5992
5993 /**
5994 * Factory method which creates address type operand for given effective address and byte size operator.
5995 * @param effectiveAddress The effective address.
5996 * @param segmentSelector The segment selector.
5997 * @return The created operator.
5998 * @since 1.1.0
5999 */
6000 static Operand addrb( const EffectiveAddress &effectiveAddress, const SegmentSelector &segmentSelector ) {
6001 return Operand( Address( effectiveAddress, segmentSelector, FCML_DS_8 ) );
6002 }
6003
6004 /**
6005 * Factory method which creates address type operand for given effective address and word size operator.
6006 * @param effectiveAddress The effective address.
6007 * @param segmentSelector The segment selector.
6008 * @return The created operator.
6009 * @since 1.1.0
6010 */
6011 static Operand addrw( const EffectiveAddress &effectiveAddress, const SegmentSelector &segmentSelector ) {
6012 return Operand( Address( effectiveAddress, segmentSelector, FCML_DS_16 ) );
6013 }
6014
6015 /**
6016 * Factory method which creates address type operand for given effective address and double word size operator.
6017 * @param effectiveAddress The effective address.
6018 * @param segmentSelector The segment selector.
6019 * @return The created operator.
6020 * @since 1.1.0
6021 */
6022 static Operand addrd( const EffectiveAddress &effectiveAddress, const SegmentSelector &segmentSelector ) {
6023 return Operand( Address( effectiveAddress, segmentSelector, FCML_DS_32 ) );
6024 }
6025
6026 /**
6027 * Factory method which creates address type operand for given effective address and quadro word size operator.
6028 * @param effectiveAddress The effective address.
6029 * @param segmentSelector The segment selector.
6030 * @return The created operator.
6031 * @since 1.1.0
6032 */
6033 static Operand addrq( const EffectiveAddress &effectiveAddress, const SegmentSelector &segmentSelector ) {
6034 return Operand( Address( effectiveAddress, segmentSelector, FCML_DS_64 ) );
6035 }
6036
6037 /**
6038 * Factory method which creates an register based operator for given register.
6039 * @param reg The register.
6040 * @return The created operator.
6041 * @since 1.1.0
6042 */
6043 static Operand reg( const Register &reg ) {
6044 return Operand( reg );
6045 }
6046
6047 /**
6048 * Factory method which creates an register based operator for given parameters.
6049 * @param reg The FCML register number.
6050 * @param size The register size.
6051 * @param type The register type.
6052 * @param x64_exp See manual for more information.
6053 * @return The created operator.
6054 * @since 1.1.0
6055 */
6056 static Operand reg( fcml_uint8_t reg, fcml_usize size, Register::RegisterType type = Register::REG_GPR, fcml_bool x64_exp = FCML_FALSE ) {
6057 return Operand( Register( reg, size, type, x64_exp ) );
6058 }
6059
6060 /**
6061 * Factory method which creates an effective address based operator for a displacement and optional size operator.
6062 * @param displacement The displacement value.
6063 * @param sizeOperator The size operator.
6064 * @return The created operator.
6065 * @since 1.1.0
6066 */
6067 static Operand eff( const Integer &displacement, fcml_usize sizeOperator = FCML_DS_UNDEF ) {
6068 return addr( EffectiveAddress( displacement ), sizeOperator );
6069 }
6070
6071 /**
6072 * Factory method which creates an effective address based operator for a displacement and byte size operator.
6073 * @param displacement The displacement value.
6074 * @return The created operator.
6075 * @since 1.1.0
6076 */
6077 static Operand effb( const Integer &displacement ) {
6078 return addr( EffectiveAddress( displacement ), FCML_DS_8 );
6079 }
6080
6081 /**
6082 * Factory method which creates an effective address based operator for a displacement and word size operator.
6083 * @param displacement The displacement value.
6084 * @return The created operator.
6085 * @since 1.1.0
6086 */
6087 static Operand effw( const Integer &displacement ) {
6088 return addr( EffectiveAddress( displacement ), FCML_DS_16 );
6089 }
6090
6091 /**
6092 * Factory method which creates an effective address based operator for a displacement and double word size operator.
6093 * @param displacement The displacement value.
6094 * @return The created operator.
6095 * @since 1.1.0
6096 */
6097 static Operand effd( const Integer &displacement ) {
6098 return addr( EffectiveAddress( displacement ), FCML_DS_32 );
6099 }
6100
6101 /**
6102 * Factory method which creates an effective address based operator for a displacement and quadro byte size operator.
6103 * @param displacement The displacement value.
6104 * @return The created operator.
6105 * @since 1.1.0
6106 */
6107 static Operand effq( const Integer &displacement ) {
6108 return addr( EffectiveAddress( displacement ), FCML_DS_64 );
6109 }
6110
6111 /**
6112 * Factory method which creates an effective address based operator for a base register and optional size operator.
6113 * @param base The base register.
6114 * @param sizeOperator The optional size operator.
6115 * @return The created operator.
6116 * @since 1.1.0
6117 */
6118 static Operand eff( const Register &base, fcml_usize sizeOperator = FCML_DS_UNDEF ) {
6119 return addr( EffectiveAddress( base ), sizeOperator );
6120 }
6121
6122 /**
6123 * Factory method which creates an effective address based operator for a base register and byte size operator.
6124 * @param base The base register.
6125 * @return The created operator.
6126 * @since 1.1.0
6127 */
6128 static Operand effb( const Register &base ) {
6129 return addr( EffectiveAddress( base ), FCML_DS_8 );
6130 }
6131
6132 /**
6133 * Factory method which creates an effective address based operator for a base register and word size operator.
6134 * @param base The base register.
6135 * @return The created operator.
6136 * @since 1.1.0
6137 */
6138 static Operand effw( const Register &base ) {
6139 return addr( EffectiveAddress( base ), FCML_DS_16 );
6140 }
6141
6142 /**
6143 * Factory method which creates an effective address based operator for a base register and double word size operator.
6144 * @param base The base register.
6145 * @return The created operator.
6146 * @since 1.1.0
6147 */
6148 static Operand effd( const Register &base ) {
6149 return addr( EffectiveAddress( base ), FCML_DS_32 );
6150 }
6151
6152 /**
6153 * Factory method which creates an effective address based operator for a base register and quadro word size operator.
6154 * @param base The base register.
6155 * @return The created operator.
6156 * @since 1.1.0
6157 */
6158 static Operand effq( const Register &base ) {
6159 return addr( EffectiveAddress( base ), FCML_DS_64 );
6160 }
6161
6162 /**
6163 * Factory method which creates an effective address based operator for a base register, displacement and optional size operator.
6164 * @param base The base register.
6165 * @param displacement The displacement value.
6166 * @param sizeOperator The optional size operator.
6167 * @return The created operator.
6168 * @since 1.1.0
6169 */
6170 static Operand eff( const Register &base, const Integer &displacement, fcml_usize sizeOperator = FCML_DS_UNDEF ) {
6171 return addr( EffectiveAddress( base, displacement ), sizeOperator );
6172 }
6173
6174 /**
6175 * Factory method which creates an effective address based operator for a base register, displacement and byte size operator.
6176 * @param base The base register.
6177 * @param displacement The displacement value.
6178 * @return The created operator.
6179 * @since 1.1.0
6180 */
6181 static Operand effb( const Register &base, const Integer &displacement ) {
6182 return addr( EffectiveAddress( base, displacement ), FCML_DS_8 );
6183 }
6184
6185 /**
6186 * Factory method which creates an effective address based operator for a base register, displacement and word size operator.
6187 * @param base The base register.
6188 * @param displacement The displacement value.
6189 * @return The created operator.
6190 * @since 1.1.0
6191 */
6192 static Operand effw( const Register &base, const Integer &displacement ) {
6193 return addr( EffectiveAddress( base, displacement ), FCML_DS_16 );
6194 }
6195
6196 /**
6197 * Factory method which creates an effective address based operator for a base register, displacement and double word size operator.
6198 * @param base The base register.
6199 * @param displacement The displacement value.
6200 * @return The created operator.
6201 * @since 1.1.0
6202 */
6203 static Operand effd( const Register &base, const Integer &displacement ) {
6204 return addr( EffectiveAddress( base, displacement ), FCML_DS_32 );
6205 }
6206
6207 /**
6208 * Factory method which creates an effective address based operator for a base register, displacement and quadro word size operator.
6209 * @param base The base register.
6210 * @param displacement The displacement value.
6211 * @return The created operator.
6212 * @since 1.1.0
6213 */
6214 static Operand effq( const Register &base, const Integer &displacement ) {
6215 return addr( EffectiveAddress( base, displacement ), FCML_DS_64 );
6216 }
6217
6218 /**
6219 * Factory method which creates an effective address based operator for an index register, scaleFactor, displacement and optional size operator.
6220 * @param index The index register.
6221 * @param scaleFactor The scale factor.
6222 * @param displacement The displacement value.
6223 * @param sizeOperator The optional size operator.
6224 * @return The created operator.
6225 * @since 1.1.0
6226 */
6227 static Operand eff( const Register &index, fcml_uint8_t scaleFactor, const Integer &displacement, fcml_usize sizeOperator = FCML_DS_UNDEF ) {
6228 return addr( EffectiveAddress( index, scaleFactor, displacement ), sizeOperator );
6229 }
6230
6231 /**
6232 * Factory method which creates an effective address based operator for an index register, scaleFactor, displacement and byte size operator.
6233 * @param index The index register.
6234 * @param scaleFactor The scale factor.
6235 * @param displacement The displacement value.
6236 * @return The created operator.
6237 * @since 1.1.0
6238 */
6239 static Operand effb( const Register &index, fcml_uint8_t scaleFactor, const Integer &displacement ) {
6240 return addr( EffectiveAddress( index, scaleFactor, displacement ), FCML_DS_8 );
6241 }
6242
6243 /**
6244 * Factory method which creates an effective address based operator for an index register, scaleFactor, displacement and word size operator.
6245 * @param index The index register.
6246 * @param scaleFactor The scale factor.
6247 * @param displacement The displacement value.
6248 * @return The created operator.
6249 * @since 1.1.0
6250 */
6251 static Operand effw( const Register &index, fcml_uint8_t scaleFactor, const Integer &displacement ) {
6252 return addr( EffectiveAddress( index, scaleFactor, displacement ), FCML_DS_16 );
6253 }
6254
6255 /**
6256 * Factory method which creates an effective address based operator for an index register, scaleFactor, displacement and double word size operator.
6257 * @param index The index register.
6258 * @param scaleFactor The scale factor.
6259 * @param displacement The displacement value.
6260 * @return The created operator.
6261 * @since 1.1.0
6262 */
6263 static Operand effd( const Register &index, fcml_uint8_t scaleFactor, const Integer &displacement ) {
6264 return addr( EffectiveAddress( index, scaleFactor, displacement ), FCML_DS_32 );
6265 }
6266
6267 /**
6268 * Factory method which creates an effective address based operator for an index register, scaleFactor, displacement and quadro word size operator.
6269 * @param index The index register.
6270 * @param scaleFactor The scale factor.
6271 * @param displacement The displacement value.
6272 * @return The created operator.
6273 * @since 1.1.0
6274 */
6275 static Operand effq( const Register &index, fcml_uint8_t scaleFactor, const Integer &displacement ) {
6276 return addr( EffectiveAddress( index, scaleFactor, displacement ), FCML_DS_64 );
6277 }
6278
6279 /**
6280 * Factory method which creates an effective address based operator for a base register, index register and optional size operator.
6281 * @param base The base register.
6282 * @param index The index register.
6283 * @param sizeOperator The optional size operator.
6284 * @return The created operator.
6285 * @since 1.1.0
6286 */
6287 static Operand eff( const Register &base, const Register &index, fcml_usize sizeOperator = FCML_DS_UNDEF ) {
6288 return addr( EffectiveAddress( base, index ), sizeOperator );
6289 }
6290
6291 /**
6292 * Factory method which creates an effective address based operator for a base register, index register and byte size operator.
6293 * @param base The base register.
6294 * @param index The index register.
6295 * @return The created operator.
6296 * @since 1.1.0
6297 */
6298 static Operand effb( const Register &base, const Register &index ) {
6299 return addr( EffectiveAddress( base, index ), FCML_DS_8 );
6300 }
6301
6302 /**
6303 * Factory method which creates an effective address based operator for a base register, index register and word size operator.
6304 * @param base The base register.
6305 * @param index The index register.
6306 * @return The created operator.
6307 * @since 1.1.0
6308 */
6309 static Operand effw( const Register &base, const Register &index ) {
6310 return addr( EffectiveAddress( base, index ), FCML_DS_16 );
6311 }
6312
6313 /**
6314 * Factory method which creates an effective address based operator for a base register, index register and double word size operator.
6315 * @param base The base register.
6316 * @param index The index register.
6317 * @return The created operator.
6318 * @since 1.1.0
6319 */
6320 static Operand effd( const Register &base, const Register &index ) {
6321 return addr( EffectiveAddress( base, index ), FCML_DS_32 );
6322 }
6323
6324 /**
6325 * Factory method which creates an effective address based operator for a base register, index register and quadro word size operator.
6326 * @param base The base register.
6327 * @param index The index register.
6328 * @return The created operator.
6329 * @since 1.1.0
6330 */
6331 static Operand effq( const Register &base, const Register &index ) {
6332 return addr( EffectiveAddress( base, index ), FCML_DS_64 );
6333 }
6334
6335 /**
6336 * Factory method which creates an effective address based operator for a base register, index register, scale factor and optional size operator.
6337 * @param base The base register.
6338 * @param index The index register.
6339 * @param scaleFactor The scale factor.
6340 * @param sizeOperator The optional size operator.
6341 * @return The created operator.
6342 * @since 1.1.0
6343 */
6344 static Operand eff( const Register &base, const Register &index, fcml_uint8_t scaleFactor, fcml_usize sizeOperator = FCML_DS_UNDEF ) {
6345 return addr( EffectiveAddress( base, index, scaleFactor ), sizeOperator );
6346 }
6347
6348 /**
6349 * Factory method which creates an effective address based operator for a base register, index register, scale factor and byte size operator.
6350 * @param base The base register.
6351 * @param index The index register.
6352 * @param scaleFactor The scale factor.
6353 * @return The created operator.
6354 * @since 1.1.0
6355 */
6356 static Operand effb( const Register &base, const Register &index, fcml_uint8_t scaleFactor ) {
6357 return addr( EffectiveAddress( base, index, scaleFactor ), FCML_DS_8 );
6358 }
6359
6360 /**
6361 * Factory method which creates an effective address based operator for a base register, index register, scale factor and word size operator.
6362 * @param base The base register.
6363 * @param index The index register.
6364 * @param scaleFactor The scale factor.
6365 * @return The created operator.
6366 * @since 1.1.0
6367 */
6368 static Operand effw( const Register &base, const Register &index, fcml_uint8_t scaleFactor ) {
6369 return addr( EffectiveAddress( base, index, scaleFactor ), FCML_DS_16 );
6370 }
6371
6372 /**
6373 * Factory method which creates an effective address based operator for a base register, index register, scale factor and double word size operator.
6374 * @param base The base register.
6375 * @param index The index register.
6376 * @param scaleFactor The scale factor.
6377 * @return The created operator.
6378 * @since 1.1.0
6379 */
6380 static Operand effd( const Register &base, const Register &index, fcml_uint8_t scaleFactor ) {
6381 return addr( EffectiveAddress( base, index, scaleFactor ), FCML_DS_32 );
6382 }
6383
6384 /**
6385 * Factory method which creates an effective address based operator for a base register, index register, scale factor and quadro word size operator.
6386 * @param base The base register.
6387 * @param index The index register.
6388 * @param scaleFactor The scale factor.
6389 * @return The created operator.
6390 * @since 1.1.0
6391 */
6392 static Operand effq( const Register &base, const Register &index, fcml_uint8_t scaleFactor ) {
6393 return addr( EffectiveAddress( base, index, scaleFactor ), FCML_DS_64 );
6394 }
6395
6396 /**
6397 * Factory method which creates an effective address based operator for a base register, index register, scale factor and optional size operator.
6398 * @param base The base register.
6399 * @param index The index register.
6400 * @param scaleFactor The scale factor.
6401 * @param displacement The displacement value.
6402 * @param sizeOperator The optional size operator.
6403 * @return The created operator.
6404 * @since 1.1.0
6405 */
6406 static Operand eff( const Register &base, const Register &index, fcml_uint8_t scaleFactor, const Integer &displacement, fcml_usize sizeOperator = FCML_DS_UNDEF ) {
6407 return addr( EffectiveAddress( base, index, scaleFactor, displacement ), sizeOperator );
6408 }
6409
6410 /**
6411 * Factory method which creates an effective address based operator for a base register, index register, scale factor and byte size operator.
6412 * @param base The base register.
6413 * @param index The index register.
6414 * @param scaleFactor The scale factor.
6415 * @param displacement The displacement value.
6416 * @return The created operator.
6417 * @since 1.1.0
6418 */
6419 static Operand effb( const Register &base, const Register &index, fcml_uint8_t scaleFactor, const Integer &displacement ) {
6420 return addr( EffectiveAddress( base, index, scaleFactor, displacement ), FCML_DS_8 );
6421 }
6422
6423 /**
6424 * Factory method which creates an effective address based operator for a base register, index register, scale factor and word size operator.
6425 * @param base The base register.
6426 * @param index The index register.
6427 * @param scaleFactor The scale factor.
6428 * @param displacement The displacement value.
6429 * @return The created operator.
6430 * @since 1.1.0
6431 */
6432 static Operand effw( const Register &base, const Register &index, fcml_uint8_t scaleFactor, const Integer &displacement ) {
6433 return addr( EffectiveAddress( base, index, scaleFactor, displacement ), FCML_DS_16 );
6434 }
6435
6436 /**
6437 * Factory method which creates an effective address based operator for a base register, index register, scale factor and double word size operator.
6438 * @param base The base register.
6439 * @param index The index register.
6440 * @param scaleFactor The scale factor.
6441 * @param displacement The displacement value.
6442 * @return The created operator.
6443 * @since 1.1.0
6444 */
6445 static Operand effd( const Register &base, const Register &index, fcml_uint8_t scaleFactor, const Integer &displacement ) {
6446 return addr( EffectiveAddress( base, index, scaleFactor, displacement ), FCML_DS_32 );
6447 }
6448
6449 /**
6450 * Factory method which creates an effective address based operator for a base register, index register, scale factor and quardo word size operator.
6451 * @param base The base register.
6452 * @param index The index register.
6453 * @param scaleFactor The scale factor.
6454 * @param displacement The displacement value.
6455 * @return The created operator.
6456 * @since 1.1.0
6457 */
6458 static Operand effq( const Register &base, const Register &index, fcml_uint8_t scaleFactor, const Integer &displacement ) {
6459 return addr( EffectiveAddress( base, index, scaleFactor, displacement ), FCML_DS_64 );
6460 }
6461
6462 };
6463
6464 /** Instruction condition.
6465 *
6466 * It's counterpart to the fcml_st_condition structure.
6467 *
6468 * @since 1.1.0
6469 */
6470 class Condition {
6471
6472 public:
6473
6474 /** See fcml_st_condition for more details.
6475 * @since 1.1.0
6476 */
6477 enum ConditionType {
6478 /** 0 Overflow*/
6479 CONDITION_O = FCML_CONDITION_O,
6480 /** 1 Below*/
6481 CONDITION_B = FCML_CONDITION_B,
6482 /** 2 Equal*/
6483 CONDITION_E = FCML_CONDITION_E,
6484 /** 3 Below or equal*/
6485 CONDITION_BE = FCML_CONDITION_BE,
6486 /** 4 Sign*/
6487 CONDITION_S = FCML_CONDITION_S,
6488 /** 5 Parity*/
6489 CONDITION_P = FCML_CONDITION_P,
6490 /** 6 Less than*/
6491 CONDITION_L = FCML_CONDITION_L,
6492 /** 7 Less than or equal to*/
6493 CONDITION_LE = FCML_CONDITION_LE
6494 };
6495
6496 /**
6497 * Creates an empty condition.
6498 * @since 1.1.0
6499 */
6500 Condition() :
6501 _conditionType(CONDITION_O),
6502 _isNegation(false) {
6503 }
6504
6505 /**
6506 * Creates a condition for given parameters.
6507 *
6508 * @param type A condition type.
6509 * @param negation True in order to negate condition.
6510 * @since 1.1.0
6511 */
6512 Condition( ConditionType type, bool negation = false ) :
6513 _conditionType( type ),
6514 _isNegation( negation ) {
6515 }
6516
6517 public:
6518
6519 /**
6520 * Gets true the condition is of a given type.
6521 * @return True the condition is of a given type.
6522 * @since 1.1.0
6523 */
6524 bool isO() const {
6525 return check( CONDITION_O );
6526 }
6527
6528 /**
6529 * Factory method which creates a condition of a given type.
6530 * @return The condition with a type described by the method name.
6531 * @since 1.1.0
6532 */
6533 static const Condition O() {
6534 const Condition condition( CONDITION_O );
6535 return condition;
6536 }
6537
6538 /**
6539 * Gets true the condition is of a given type.
6540 * @return True the condition is of a given type.
6541 * @since 1.1.0
6542 */
6543 bool isNO() const {
6544 return check( CONDITION_O, true );
6545 }
6546
6547 /**
6548 * Factory method which creates a condition of a given type.
6549 * @return The condition with a type described by the method name.
6550 * @since 1.1.0
6551 */
6552 static const Condition NO() {
6553 const Condition condition( CONDITION_O );
6554 return condition;
6555 }
6556
6557 /**
6558 * Gets true the condition is of a given type.
6559 * @return True the condition is of a given type.
6560 * @since 1.1.0
6561 */
6562 bool isB() const {
6563 return check( CONDITION_B );
6564 }
6565
6566 /**
6567 * Factory method which creates a condition of a given type.
6568 * @return The condition with a type described by the method name.
6569 * @since 1.1.0
6570 */
6571 static const Condition B() {
6572 const Condition condition( CONDITION_B );
6573 return condition;
6574 }
6575
6576 /**
6577 * Gets true the condition is of a given type.
6578 * @return True the condition is of a given type.
6579 * @since 1.1.0
6580 */
6581 bool isNB() const {
6582 return check( CONDITION_B, true );
6583 }
6584
6585 /**
6586 * Factory method which creates a condition of a given type.
6587 * @return The condition with a type described by the method name.
6588 * @since 1.1.0
6589 */
6590 static const Condition NB() {
6591 const Condition condition( CONDITION_B, true );
6592 return condition;
6593 }
6594
6595 /**
6596 * Gets true the condition is of a given type.
6597 * @return True the condition is of a given type.
6598 * @since 1.1.0
6599 */
6600 bool isNAE() const {
6601 return check( CONDITION_B );
6602 }
6603
6604 /**
6605 * Factory method which creates a condition of a given type.
6606 * @return The condition with a type described by the method name.
6607 * @since 1.1.0
6608 */
6609 static const Condition NAE() {
6610 const Condition condition( CONDITION_B );
6611 return condition;
6612 }
6613
6614 /**
6615 * Gets true the condition is of a given type.
6616 * @return True the condition is of a given type.
6617 * @since 1.1.0
6618 */
6619 bool isAE() const {
6620 return check( CONDITION_B, true );
6621 }
6622
6623 /**
6624 * Factory method which creates a condition of a given type.
6625 * @return The condition with a type described by the method name.
6626 * @since 1.1.0
6627 */
6628 static const Condition AE() {
6629 const Condition condition( CONDITION_B, true );
6630 return condition;
6631 }
6632
6633 /**
6634 * Gets true the condition is of a given type.
6635 * @return True the condition is of a given type.
6636 * @since 1.1.0
6637 */
6638 bool isC() const {
6639 return check( CONDITION_B );
6640 }
6641
6642 /**
6643 * Factory method which creates a condition of a given type.
6644 * @return The condition with a type described by the method name.
6645 * @since 1.1.0
6646 */
6647 static const Condition C() {
6648 const Condition condition( CONDITION_B );
6649 return condition;
6650 }
6651
6652 /**
6653 * Gets true the condition is of a given type.
6654 * @return True the condition is of a given type.
6655 * @since 1.1.0
6656 */
6657 bool isNC() const {
6658 return check( CONDITION_B, true );
6659 }
6660
6661 /**
6662 * Factory method which creates a condition of a given type.
6663 * @return The condition with a type described by the method name.
6664 * @since 1.1.0
6665 */
6666 static const Condition NC() {
6667 const Condition condition( CONDITION_B, true );
6668 return condition;
6669 }
6670
6671 /**
6672 * Gets true the condition is of a given type.
6673 * @return True the condition is of a given type.
6674 * @since 1.1.0
6675 */
6676 bool isE() const {
6677 return check( CONDITION_E );
6678 }
6679
6680 /**
6681 * Factory method which creates a condition of a given type.
6682 * @return The condition with a type described by the method name.
6683 * @since 1.1.0
6684 */
6685 static const Condition E() {
6686 const Condition condition( CONDITION_E );
6687 return condition;
6688 }
6689
6690 /**
6691 * Gets true the condition is of a given type.
6692 * @return True the condition is of a given type.
6693 * @since 1.1.0
6694 */
6695 bool isZ() const {
6696 return check( CONDITION_E );
6697 }
6698
6699 /**
6700 * Factory method which creates a condition of a given type.
6701 * @return The condition with a type described by the method name.
6702 * @since 1.1.0
6703 */
6704 static const Condition Z() {
6705 const Condition condition( CONDITION_E );
6706 return condition;
6707 }
6708
6709 /**
6710 * Gets true the condition is of a given type.
6711 * @return True the condition is of a given type.
6712 * @since 1.1.0
6713 */
6714 bool isNE() const {
6715 return check( CONDITION_E, true );
6716 }
6717
6718 /**
6719 * Factory method which creates a condition of a given type.
6720 * @return The condition with a type described by the method name.
6721 * @since 1.1.0
6722 */
6723 static const Condition NE() {
6724 const Condition condition( CONDITION_E, true );
6725 return condition;
6726 }
6727
6728 /**
6729 * Gets true the condition is of a given type.
6730 * @return True the condition is of a given type.
6731 * @since 1.1.0
6732 */
6733 bool isNZ() const {
6734 return check( CONDITION_E, true );
6735 }
6736
6737 /**
6738 * Factory method which creates a condition of a given type.
6739 * @return The condition with a type described by the method name.
6740 * @since 1.1.0
6741 */
6742 static const Condition NZ() {
6743 const Condition condition( CONDITION_E, true );
6744 return condition;
6745 }
6746
6747 /**
6748 * Gets true the condition is of a given type.
6749 * @return True the condition is of a given type.
6750 * @since 1.1.0
6751 */
6752 bool isBE() const {
6753 return check( CONDITION_BE );
6754 }
6755
6756 /**
6757 * Factory method which creates a condition of a given type.
6758 * @return The condition with a type described by the method name.
6759 * @since 1.1.0
6760 */
6761 static const Condition BE() {
6762 const Condition condition( CONDITION_BE );
6763 return condition;
6764 }
6765
6766 /**
6767 * Gets true the condition is of a given type.
6768 * @return True the condition is of a given type.
6769 * @since 1.1.0
6770 */
6771 bool isNA() const {
6772 return check( CONDITION_BE );
6773 }
6774
6775 /**
6776 * Factory method which creates a condition of a given type.
6777 * @return The condition with a type described by the method name.
6778 * @since 1.1.0
6779 */
6780 static const Condition NA() {
6781 const Condition condition( CONDITION_BE );
6782 return condition;
6783 }
6784
6785 /**
6786 * Gets true the condition is of a given type.
6787 * @return True the condition is of a given type.
6788 * @since 1.1.0
6789 */
6790 bool isNBE() const {
6791 return check( CONDITION_BE, true );
6792 }
6793
6794 /**
6795 * Factory method which creates a condition of a given type.
6796 * @return The condition with a type described by the method name.
6797 * @since 1.1.0
6798 */
6799 static const Condition NBE() {
6800 const Condition condition( CONDITION_BE, true );
6801 return condition;
6802 }
6803
6804 /**
6805 * Gets true the condition is of a given type.
6806 * @return True the condition is of a given type.
6807 * @since 1.1.0
6808 */
6809 bool isA() const {
6810 return check( CONDITION_BE, true );
6811 }
6812
6813 /**
6814 * Factory method which creates a condition of a given type.
6815 * @return The condition with a type described by the method name.
6816 * @since 1.1.0
6817 */
6818 static const Condition A() {
6819 const Condition condition( CONDITION_BE, true );
6820 return condition;
6821 }
6822
6823 /**
6824 * Gets true the condition is of a given type.
6825 * @return True the condition is of a given type.
6826 * @since 1.1.0
6827 */
6828 bool isS() const {
6829 return check( CONDITION_S );
6830 }
6831
6832 /**
6833 * Factory method which creates a condition of a given type.
6834 * @return The condition with a type described by the method name.
6835 * @since 1.1.0
6836 */
6837 static const Condition S() {
6838 const Condition condition( CONDITION_S );
6839 return condition;
6840 }
6841
6842 /**
6843 * Gets true the condition is of a given type.
6844 * @return True the condition is of a given type.
6845 * @since 1.1.0
6846 */
6847 bool isNS() const {
6848 return check( CONDITION_S, true );
6849 }
6850
6851 /**
6852 * Factory method which creates a condition of a given type.
6853 * @return The condition with a type described by the method name.
6854 * @since 1.1.0
6855 */
6856 static const Condition NS() {
6857 const Condition condition( CONDITION_S, true );
6858 return condition;
6859 }
6860
6861 /**
6862 * Gets true the condition is of a given type.
6863 * @return True the condition is of a given type.
6864 * @since 1.1.0
6865 */
6866 bool isP() const {
6867 return check( CONDITION_P );
6868 }
6869
6870 /**
6871 * Factory method which creates a condition of a given type.
6872 * @return The condition with a type described by the method name.
6873 * @since 1.1.0
6874 */
6875 static const Condition P() {
6876 const Condition condition( CONDITION_P );
6877 return condition;
6878 }
6879
6880 /**
6881 * Gets true the condition is of a given type.
6882 * @return True the condition is of a given type.
6883 * @since 1.1.0
6884 */
6885 bool isPE() const {
6886 return check( CONDITION_P );
6887 }
6888
6889 /**
6890 * Factory method which creates a condition of a given type.
6891 * @return The condition with a type described by the method name.
6892 * @since 1.1.0
6893 */
6894 static const Condition PE() {
6895 const Condition condition( CONDITION_P );
6896 return condition;
6897 }
6898
6899 /**
6900 * Gets true the condition is of a given type.
6901 * @return True the condition is of a given type.
6902 * @since 1.1.0
6903 */
6904 bool isNP() const {
6905 return check( CONDITION_P, true );
6906 }
6907
6908 /**
6909 * Factory method which creates a condition of a given type.
6910 * @return The condition with a type described by the method name.
6911 * @since 1.1.0
6912 */
6913 static const Condition NP() {
6914 const Condition condition( CONDITION_P, true );
6915 return condition;
6916 }
6917
6918 /**
6919 * Gets true the condition is of a given type.
6920 * @return True the condition is of a given type.
6921 * @since 1.1.0
6922 */
6923 bool isPO() const {
6924 return check( CONDITION_P, true );
6925 }
6926
6927 /**
6928 * Factory method which creates a condition of a given type.
6929 * @return The condition with a type described by the method name.
6930 * @since 1.1.0
6931 */
6932 static const Condition PO() {
6933 const Condition condition( CONDITION_P, true );
6934 return condition;
6935 }
6936
6937 /**
6938 * Gets true the condition is of a given type.
6939 * @return True the condition is of a given type.
6940 * @since 1.1.0
6941 */
6942 bool isL() const {
6943 return check( CONDITION_L );
6944 }
6945
6946 /**
6947 * Factory method which creates a condition of a given type.
6948 * @return The condition with a type described by the method name.
6949 * @since 1.1.0
6950 */
6951 static const Condition L() {
6952 const Condition condition( CONDITION_L );
6953 return condition;
6954 }
6955
6956 /**
6957 * Gets true the condition is of a given type.
6958 * @return True the condition is of a given type.
6959 * @since 1.1.0
6960 */
6961 bool isNGE() const {
6962 return check( CONDITION_L );
6963 }
6964
6965 /**
6966 * Factory method which creates a condition of a given type.
6967 * @return The condition with a type described by the method name.
6968 * @since 1.1.0
6969 */
6970 static const Condition NGE() {
6971 const Condition condition( CONDITION_L );
6972 return condition;
6973 }
6974
6975 /**
6976 * Gets true the condition is of a given type.
6977 * @return True the condition is of a given type.
6978 * @since 1.1.0
6979 */
6980 bool isNL() const {
6981 return check( CONDITION_L, true );
6982 }
6983
6984 /**
6985 * Factory method which creates a condition of a given type.
6986 * @return The condition with a type described by the method name.
6987 * @since 1.1.0
6988 */
6989 static const Condition NL() {
6990 const Condition condition( CONDITION_L, true );
6991 return condition;
6992 }
6993
6994 /**
6995 * Gets true the condition is of a given type.
6996 * @return True the condition is of a given type.
6997 * @since 1.1.0
6998 */
6999 bool isGE() const {
7000 return check( CONDITION_L, true );
7001 }
7002
7003 /**
7004 * Factory method which creates a condition of a given type.
7005 * @return The condition with a type described by the method name.
7006 * @since 1.1.0
7007 */
7008 static const Condition GE() {
7009 const Condition condition( CONDITION_L, true );
7010 return condition;
7011 }
7012
7013 /**
7014 * Gets true the condition is of a given type.
7015 * @return True the condition is of a given type.
7016 * @since 1.1.0
7017 */
7018 bool isLE() const {
7019 return check( CONDITION_LE );
7020 }
7021
7022 /**
7023 * Factory method which creates a condition of a given type.
7024 * @return The condition with a type described by the method name.
7025 * @since 1.1.0
7026 */
7027 static const Condition LE() {
7028 const Condition condition( CONDITION_LE );
7029 return condition;
7030 }
7031
7032 /**
7033 * Gets true the condition is of a given type.
7034 * @return True the condition is of a given type.
7035 * @since 1.1.0
7036 */
7037 bool isNG() const {
7038 return check( CONDITION_LE );
7039 }
7040
7041 /**
7042 * Factory method which creates a condition of a given type.
7043 * @return The condition with a type described by the method name.
7044 * @since 1.1.0
7045 */
7046 static const Condition NG() {
7047 const Condition condition( CONDITION_LE );
7048 return condition;
7049 }
7050
7051 /**
7052 * Gets true the condition is of a given type.
7053 * @return True the condition is of a given type.
7054 * @since 1.1.0
7055 */
7056 bool isNLE() const {
7057 return check( CONDITION_LE, true );
7058 }
7059
7060 /**
7061 * Factory method which creates a condition of a given type.
7062 * @return The condition with a type described by the method name.
7063 * @since 1.1.0
7064 */
7065 static const Condition NLE() {
7066 const Condition condition( CONDITION_LE, true );
7067 return condition;
7068 }
7069
7070 /**
7071 * Gets true the condition is of a given type.
7072 * @return True the condition is of a given type.
7073 * @since 1.1.0
7074 */
7075 bool isG() const {
7076 return check( CONDITION_LE, true );
7077 }
7078
7079 /**
7080 * Factory method which creates a condition of a given type.
7081 * @return The condition with a type described by the method name.
7082 * @since 1.1.0
7083 */
7084 static const Condition G() {
7085 const Condition condition( CONDITION_LE, true );
7086 return condition;
7087 }
7088
7089 public:
7090
7091 /**
7092 * Checks if two condition are equal.
7093 *
7094 * @param cond The condition to be compared to the current one.
7095 * @return True if they are equal.
7096 * @since 1.1.0
7097 */
7098 bool operator==( const Condition &cond ) const {
7099 return cond._conditionType == _conditionType && cond._isNegation == _isNegation;
7100 }
7101
7102 /**
7103 * Checks if two condition are equal.
7104 *
7105 * @param cond The condition to be compared to the current one.
7106 * @return True if they are NOT equal.
7107 * @since 1.1.0
7108 */
7109 bool operator!=( const Condition &cond ) const {
7110 return !(*this == cond);
7111 }
7112
7113 public:
7114
7115 /**
7116 * Gets a type of the condition.
7117 *
7118 * @return The type of the condition.
7119 * @since 1.1.0
7120 */
7121 ConditionType getConditionType() const {
7122 return _conditionType;
7123 }
7124
7125 /**
7126 * Sets condition type.
7127 *
7128 * @param conditionType The condition type to be set.
7129 * @since 1.1.0
7130 */
7131 Condition& setConditionType( ConditionType conditionType ) {
7132 _conditionType = conditionType;
7133 return *this;
7134 }
7135
7136 /**
7137 * Returns true if condition is negated.
7138 *
7139 * @return True if condition is negated.
7140 * @since 1.1.0
7141 */
7142 bool isNegation() const {
7143 return _isNegation;
7144 }
7145
7146 /**
7147 * Sets negation flag for the condition.
7148 *
7149 * @param isNegation The negation flag.
7150 * @since 1.1.0
7151 */
7152 Condition& setNegation( bool isNegation ) {
7153 _isNegation = isNegation;
7154 return *this;
7155 }
7156
7157 private:
7158
7159 /**
7160 * Checks if the condition is of given type and negation flag.
7161 *
7162 * @param type The condition type.
7163 * @param negation The negation flag.
7164 * @return True if the condition has the same type and negation set.
7165 * @since 1.1.0
7166 */
7167 bool check( ConditionType type, bool negation = false ) const {
7168 return _conditionType == type && _isNegation == negation;
7169 }
7170
7171 private:
7172
7173 /* Condition type.*/
7174 ConditionType _conditionType;
7175 /* True if condition should be negated.*/
7176 bool _isNegation;
7177
7178 };
7179
7180 /** Describes an instruction.
7181 *
7182 * It's counterpart to the fcml_st_instruction structure.
7183 * @since 1.1.0
7184 */
7185 class Instruction {
7186 public:
7187
7188 /**
7189 * Creates an empty instruction.
7190 * @since 1.1.0
7191 */
7192 Instruction() :
7193 _prefixes(0),
7194 _hints(FCML_HINT_NO_HINTS),
7195 _isConditional(false),
7196 _operandsCount(0) {
7197 }
7198
7199 /**
7200 * Creates an empty instruction for given mnemonic.
7201 *
7202 * @param mnemonic The mnemonic for the newly created instruction.
7203 * @since 1.1.0
7204 */
7205 Instruction( const fcml_cstring &mnemonic ) :
7206 _prefixes(0),
7207 _hints(FCML_HINT_NO_HINTS),
7208 _mnemonic(mnemonic),
7209 _isConditional(false),
7210 _operandsCount(0) {
7211 }
7212
7213 public:
7214
7215 /**
7216 * Adds a new operand to the instruction.
7217 *
7218 * @param operand The operand to be added to the instruction.
7219 * @throw IllegalStateException No more operands allowed.
7220 * @since 1.1.0
7221 */
7222 void add( const Operand &operand ) {
7223 if( _operandsCount == FCML_OPERANDS_COUNT ) {
7224 throw IllegalStateException( FCML_TEXT( "No more operands allowed." ) );
7225 }
7226 _operands[_operandsCount++] = operand;
7227 }
7228
7229 /**
7230 * Sets a new oeprand for the instruction at given index.
7231 *
7232 * @param operand The operand to be set.
7233 * @param index The index operand should be set at.
7234 * @throw IllegalStateException Operand's number exceeds maximal number of operands allowed.
7235 * @since 1.1.0
7236 */
7237 void setOperand( const Operand &operand, fcml_int index ) {
7238 if( index >= FCML_OPERANDS_COUNT ) {
7239 throw IllegalStateException( FCML_TEXT( "Operand's number exceeds maximal number of operands allowed." ) );
7240 }
7241 _operands[index] = operand;
7242 }
7243
7244 /**
7245 * Gets reference to the constant operand at given index.
7246 *
7247 * @param index The operand index.
7248 * @return The operand available at given index.
7249 * @since 1.1.0
7250 */
7251 const Operand & operator[]( fcml_int index ) const {
7252 checkArrayAccess(index);
7253 return _operands[index];
7254 }
7255
7256 /**
7257 * Gets reference to the operand at given index.
7258 *
7259 * @param index The operand index.
7260 * @return The operand available at given index.
7261 * @since 1.1.0
7262 */
7263 Operand & operator[]( fcml_int index ) {
7264 checkArrayAccess(index);
7265 return _operands[index];
7266 }
7267
7268 /**
7269 * Cleans the instruction by removing all operands from it.
7270 * @since 1.1.0
7271 */
7272 void clean() {
7273 for( int i = 0; i < FCML_OPERANDS_COUNT; i++ ) {
7274 // Clean the operand.
7275 _operands[i] = Operand();
7276 }
7277 _operandsCount = 0;
7278 }
7279
7280 public:
7281
7282 /**
7283 * Gets a pointer to the constant condition associated with the instruction.
7284 *
7285 * @return A reference to the condition.
7286 * @since 1.1.0
7287 */
7288 const Condition& getCondition() const {
7289 return _condition;
7290 }
7291
7292 /**
7293 * Gets a pointer to the condition associated with the instruction.
7294 *
7295 * @return A reference to the condition.
7296 * @since 1.1.0
7297 */
7298 Condition& getCondition() {
7299 return _condition;
7300 }
7301
7302 /**
7303 * Sets a new condition for the instruction.
7304 *
7305 * @param condition The condition to be set for the instruction.
7306 * @return The instruction itself.
7307 * @since 1.1.0
7308 */
7309 Instruction& setCondition( const Condition &condition ) {
7310 _condition = condition;
7311 return *this;
7312 }
7313
7314 /**
7315 * Gets instruction level hits associated with the instruction.
7316 *
7317 * @return The instruction level hits associated with the instruction.
7318 * @since 1.1.0
7319 */
7320 fcml_hints getHints() const {
7321 return _hints;
7322 }
7323
7324 /**
7325 * Sets new instruction hints.
7326 *
7327 * @param hints The hints to be set.
7328 * @return The instruction itself.
7329 * @since 1.1.0
7330 */
7331 Instruction& setHints( fcml_hints hints ) {
7332 _hints = hints;
7333 return *this;
7334 }
7335
7336 /**
7337 * Gets true if it's a conditional instruction.
7338 *
7339 * @return True in case of the conditional instruction.
7340 * @since 1.1.0
7341 */
7342 bool isConditional() const {
7343 return _isConditional;
7344 }
7345
7346 /**
7347 * Sets conditional flag for the instruction.
7348 *
7349 * @param isConditional Set to true in order to mark instruction as conditional one.
7350 * @return The instruction itself.
7351 * @since 1.1.0
7352 */
7353 Instruction& setConditional( bool isConditional ) {
7354 _isConditional = isConditional;
7355 return *this;
7356 }
7357
7358 /**
7359 * Gets the mnemonic associated with the instruction.
7360 *
7361 * @return The mnemonic associated with the instruction.
7362 * @since 1.1.0
7363 */
7364 const fcml_cstring& getMnemonic() const {
7365 return _mnemonic;
7366 }
7367
7368 /**
7369 * Sets a new mnemonic for the instruction.
7370 *
7371 * @param mnemonic The new mnemonic.
7372 * @return The instruction itself.
7373 * @since 1.1.0
7374 */
7375 Instruction& setMnemonic( const fcml_cstring &mnemonic ) {
7376 _mnemonic = mnemonic;
7377 return *this;
7378 }
7379
7380 /**
7381 * Gets number of operands associated with the instruction.
7382 *
7383 * @return The number of operands in the instruction.
7384 * @since 1.1.0
7385 */
7386 fcml_int getOperandsCount() const {
7387 return _operandsCount;
7388 }
7389
7390 /**
7391 * Sets number of operands available in the instruction.
7392 *
7393 * @param operandsCount Number of operands.
7394 * @return The number of instructions.
7395 * @since 1.1.0
7396 */
7397 Instruction& setOperandsCount( fcml_int operandsCount ) {
7398 _operandsCount = operandsCount;
7399 return *this;
7400 }
7401
7402 /**
7403 * Gets prefixes associated with the instruction.
7404 *
7405 * @return The prefixes.
7406 * @since 1.1.0
7407 */
7408 fcml_prefixes getPrefixes() const {
7409 return _prefixes;
7410 }
7411
7412 /**
7413 * Sets a new set of prefixes for the instruction.
7414 *
7415 * @param prefixes The set of prefixes to be set for the instruction.
7416 * @return The instruction itself.
7417 * @since 1.1.0
7418 */
7419 Instruction& setPrefixes( fcml_prefixes prefixes ) {
7420 _prefixes = prefixes;
7421 return *this;
7422 }
7423
7424 public:
7425
7426 // Helper methods to identify prefixes and hints.
7427
7428 /**
7429 * Returns true if lock prefix is set.
7430 * @return True if lock prefix is set.
7431 * @since 1.1.0
7432 */
7433 bool isLock() const {
7434 return ( _prefixes & FCML_PREFIX_LOCK ) ? true : false;
7435 }
7436
7437 /**
7438 * Returns true if repne prefix is set.
7439 * @return True if repne prefix is set.
7440 * @since 1.1.0
7441 */
7442 bool isRepne() const {
7443 return ( _prefixes & FCML_PREFIX_REPNE ) ? true : false;
7444 }
7445
7446 /**
7447 * Returns true if lock repnz is set.
7448 * @return True if lock repnz is set.
7449 * @since 1.1.0
7450 */
7451 bool isRepnz() const {
7452 return ( _prefixes & FCML_PREFIX_REPNZ ) ? true : false;
7453 }
7454
7455 /**
7456 * Returns true if rep prefix is set.
7457 * @return True if rep prefix is set.
7458 * @since 1.1.0
7459 */
7460 bool isRep() const {
7461 return ( _prefixes & FCML_PREFIX_REP ) ? true : false;
7462 }
7463
7464 /**
7465 * Returns true if repe prefix is set.
7466 * @return True if repe prefix is set.
7467 * @since 1.1.0
7468 */
7469 bool isRepe() const {
7470 return ( _prefixes & FCML_PREFIX_REPE ) ? true : false;
7471 }
7472
7473 /**
7474 * Returns true if repz prefix is set.
7475 * @return True if repz prefix is set.
7476 * @since 1.1.0
7477 */
7478 bool isRepz() const {
7479 return ( _prefixes & FCML_PREFIX_REPZ ) ? true : false;
7480 }
7481
7482 /**
7483 * Returns true if xacquire prefix is set.
7484 * @return True if xacquire prefix is set.
7485 * @since 1.1.0
7486 */
7487 bool isXAcquire() const {
7488 return ( _prefixes & FCML_PREFIX_XACQUIRE ) ? true : false;
7489 }
7490
7491 /**
7492 * Returns true if xrelease prefix is set.
7493 * @return True if xrelease prefix is set.
7494 * @since 1.1.0
7495 */
7496 bool isXRelease() const {
7497 return ( _prefixes & FCML_PREFIX_XRELEASE ) ? true : false;
7498 }
7499
7500 /**
7501 * Returns true if branch_hint prefix is set.
7502 * @return True if branch_hint prefix is set.
7503 * @since 1.1.0
7504 */
7505 bool isBranchHint() const {
7506 return ( _prefixes & FCML_PREFIX_BRANCH_HINT ) ? true : false;
7507 }
7508
7509 /**
7510 * Returns true if no_branch_hint prefix is set.
7511 * @return True if no_branch_hint prefix is set.
7512 * @since 1.1.0
7513 */
7514 bool isNoBranchHint() const {
7515 return ( _prefixes & FCML_PREFIX_NOBRANCH_HINT ) ? true : false;
7516 }
7517
7518 /**
7519 * Returns true if far pointer hint is set.
7520 * @return True if far pointer hint is set.
7521 * @since 1.1.0
7522 */
7523 bool isFarPointer() const {
7524 return ( _hints & FCML_HINT_FAR_POINTER ) ? true : false;
7525 }
7526
7527 /**
7528 * Returns true if near pointer hint is set.
7529 * @return True if near pointer hint is set.
7530 * @since 1.1.0
7531 */
7532 bool isNearPointer() const {
7533 return ( _hints & FCML_HINT_NEAR_POINTER ) ? true : false;
7534 }
7535
7536 /**
7537 * Returns true if long form pointer hint is set. See manual for more information about this hint.
7538 * @return True if long form pointer hint is set.
7539 * @since 1.1.0
7540 */
7541 bool isLongFormPointer() const {
7542 return ( _hints & FCML_HINT_LONG_FORM_POINTER ) ? true : false;
7543 }
7544
7545 /**
7546 * Returns true if indirect pointer hint is set.
7547 * @return True if indirect pointer hint is set.
7548 * @since 1.1.0
7549 */
7550 bool isIndirectPointer() const {
7551 return ( _hints & FCML_HINT_INDIRECT_POINTER ) ? true : false;
7552 }
7553
7554 /**
7555 * Returns true if direct pointer hint is set.
7556 * @return True if direct pointer hint is set.
7557 * @since 1.1.0
7558 */
7559 bool isDirectPointer() const {
7560 return ( _hints & FCML_HINT_DIRECT_POINTER ) ? true : false;
7561 }
7562
7563 private:
7564
7565 /**
7566 * Throws if given operand index is wrong.
7567 * @throw BadArgumentException Index exceeds the allowed number of operands.
7568 * @remarks An internal API, not intended to be used outside.
7569 */
7570 void checkArrayAccess( fcml_int index) const {
7571 if( index < 0 || index >= FCML_OPERANDS_COUNT ) {
7572 throw BadArgumentException( FCML_TEXT( "Index exceeds the allowed number of operands." ) );
7573 }
7574 }
7575
7576 private:
7577
7578 /** Describes explicit instruction prefixes. @ref PREFIX_GROUP "List of explicit prefixes." */
7579 fcml_prefixes _prefixes;
7580 /** Holds instruction level hints. */
7581 fcml_hints _hints;
7582 /** Dialect-dependent instruction mnemonic. @see fcml_en_instruction_hints */
7583 fcml_cstring _mnemonic;
7584 /** True for conditional instructions. */
7585 bool _isConditional;
7586 /** Describes condition used by assembled/disassembled conditional instruction. */
7587 Condition _condition;
7588 /** Fixed size array of instruction operands. */
7589 Operand _operands[FCML_OPERANDS_COUNT];
7590 /** Number of operands defined for instruction. */
7591 fcml_int _operandsCount;
7592
7593 };
7594
7595 /** An instruction builder.
7596 *
7597 * A classic builder that can be used to prepare instruction in a
7598 * more convenient way than doing it manually using setters.
7599 *
7600 * @since 1.1.0
7601 */
7602 class IB {
7603
7604 public:
7605
7606 /** Creates builder for the given mnemonic.
7607 *
7608 * @param mnemonic Mnemonic for the instruction being created.
7609 * @since 1.1.0
7610 */
7611 IB( const fcml_cstring &mnemonic ) :
7612 _hints(FCML_HINT_NO_HINTS),
7613 _prefixes(0),
7614 _mnemonic(mnemonic),
7615 _operandsCount(0) {
7616 }
7617
7618 /**
7619 * Creates builder for the given mnemonic and prefixes.
7620 *
7621 * @param prefixes The prefixes for the new instruction.
7622 * @param mnemonic Mnemonic for the instruction being created.
7623 * @since 1.1.0
7624 */
7625 IB( fcml_prefixes prefixes, const fcml_cstring &mnemonic ) :
7626 _hints(FCML_HINT_NO_HINTS),
7627 _prefixes(prefixes),
7628 _mnemonic(mnemonic),
7629 _operandsCount(0) {
7630 }
7631
7632 /**
7633 * Creates an instruction builder for given mnemonic and hints.
7634 *
7635 * @param mnemonic The instruction mnemonic.
7636 * @param hints The instruction hints.
7637 * @since 1.1.0
7638 */
7639 IB( const fcml_cstring &mnemonic, fcml_hints hints) :
7640 _hints(hints),
7641 _prefixes(0),
7642 _mnemonic(mnemonic),
7643 _operandsCount(0) {
7644 }
7645
7646 /**
7647 * Creates an instruction builder for given prefixes, mnemonic and hints.
7648 *
7649 * @param prefixes The instruction prefixes.
7650 * @param mnemonic The instruction mnemonic.
7651 * @param hints The instruction hints.
7652 * @since 1.1.0
7653 */
7654 IB( fcml_prefixes prefixes, const fcml_cstring &mnemonic, fcml_hints hints ) :
7655 _hints(hints),
7656 _prefixes(prefixes),
7657 _mnemonic(mnemonic),
7658 _operandsCount(0) {
7659 }
7660
7661 /**
7662 * Converts builder to the instruction instance.
7663 * @since 1.1.0
7664 * @return The built instruction.
7665 */
7666 operator Instruction() const {
7667 return build();
7668 }
7669
7670 /**
7671 * Builds an instruction instance for the current state of the builder.
7672 *
7673 * @return The built instruction instance.
7674 * @since 1.1.0
7675 */
7676 Instruction build() const {
7677 Instruction instruction(_mnemonic);
7678 instruction.setHints(_hints);
7679 instruction.setPrefixes(_prefixes);
7680 instruction.setOperandsCount(_operandsCount);
7681 for( int i = 0; i < FCML_OPERANDS_COUNT; i++ ) {
7682 instruction.setOperand( _operands[i], i );
7683 }
7684 return instruction;
7685 }
7686
7687 /**
7688 * Sets a next operand for the instruction.
7689 *
7690 * @param operand The next operand to be added to the instruction.
7691 * @throw IllegalStateException No more operands allowed.
7692 * @since 1.1.0
7693 */
7694 void op( const Operand &operand ) {
7695 if( _operandsCount == FCML_OPERANDS_COUNT ) {
7696 throw IllegalStateException( FCML_TEXT( "No more operands allowed." ) );
7697 }
7698 _operands[_operandsCount++] = operand;
7699 }
7700
7701 /**
7702 * Factory method that can be used to create instruction builder.
7703 *
7704 * @param mnemonic The mnemonic for the instruction builder.
7705 * @return Instruction builder instance.
7706 * @since 1.1.0
7707 */
7708 static IB inst( const fcml_cstring &mnemonic ) {
7709 return IB(mnemonic);
7710 }
7711
7712 // Hints.
7713
7714 /**
7715 * Creates a hint instance described by the name of the method. Such a hint can be then used
7716 * together with shift operator overridden by the builder in order to set an appropriate hint
7717 * for the instruction being built.
7718 * @return The hint indicator for the builder.
7719 * @since 1.1.0
7720 */
7721 static const InstructionHint FAR_PTR() {
7722 return InstructionHint::FAR_POINTER();
7723 }
7724
7725 /**
7726 * Sets a hint described by the name of the method for the instruction being built.
7727 * @return The instruction builder with the appropriate hint set.
7728 * @since 1.1.0
7729 */
7730 IB& farPtr() {
7731 _hints |= FCML_HINT_FAR_POINTER;
7732 return *this;
7733 }
7734
7735 /**
7736 * Creates a hint instance described by the name of the method. Such a hint can be then used
7737 * together with shift operator overridden by the builder in order to set an appropriate hint
7738 * for the instruction being built.
7739 * @return The hint indicator for the builder.
7740 * @since 1.1.0
7741 */
7742 static const InstructionHint NEAR_PTR() {
7743 return InstructionHint::NEAR_POINTER();
7744 }
7745
7746 /**
7747 * Sets a hint described by the name of the method for the instruction being built.
7748 * @return The instruction builder with the appropriate hint set.
7749 * @since 1.1.0
7750 */
7751 IB& nearPtr() {
7752 _hints |= FCML_HINT_NEAR_POINTER;
7753 return *this;
7754 }
7755
7756 /**
7757 * Creates a hint instance described by the name of the method. Such a hint can be then used
7758 * together with shift operator overridden by the builder in order to set an appropriate hint
7759 * for the instruction being built.
7760 * @return The hint indicator for the builder.
7761 * @since 1.1.0
7762 */
7763 static const InstructionHint LONG_FORM_PTR() {
7764 return InstructionHint::LONG_FORM_POINTER();
7765 }
7766
7767 /**
7768 * Sets a hint described by the name of the method for the instruction being built.
7769 * @return The instruction builder with the appropriate hint set.
7770 * @since 1.1.0
7771 */
7772 IB& longFormPtr() {
7773 _hints |= FCML_HINT_LONG_FORM_POINTER;
7774 return *this;
7775 }
7776
7777 /**
7778 * Creates a hint instance described by the name of the method. Such a hint can be then used
7779 * together with shift operator overridden by the builder in order to set an appropriate hint
7780 * for the instruction being built.
7781 * @return The hint indicator for the builder.
7782 * @since 1.1.0
7783 */
7784 static const InstructionHint INDIRECT_PTR() {
7785 return InstructionHint::INDIRECT_POINTER();
7786 }
7787
7788 /**
7789 * Sets a hint described by the name of the method for the instruction being built.
7790 * @return The instruction builder with the appropriate hint set.
7791 * @since 1.1.0
7792 */
7793 IB& indirectPtr() {
7794 _hints |= FCML_HINT_INDIRECT_POINTER;
7795 return *this;
7796 }
7797
7798 /**
7799 * Creates a hint instance described by the name of the method. Such a hint can be then used
7800 * together with shift operator overridden by the builder in order to set an appropriate hint
7801 * for the instruction being built.
7802 * @return The hint indicator for the builder.
7803 * @since 1.1.0
7804 */
7805 static const InstructionHint DIRECT_PTR() {
7806 return InstructionHint::DIRECT_POINTER();
7807 }
7808
7809 /**
7810 * Sets a hint described by the name of the method for the instruction being built.
7811 * @return The instruction builder with the appropriate hint set.
7812 * @since 1.1.0
7813 */
7814 IB& directPtr() {
7815 _hints |= FCML_HINT_DIRECT_POINTER;
7816 return *this;
7817 }
7818
7819 // Prefixes.
7820
7821 /**
7822 * Creates a prefix instance described by the name of the method. Such a prefix can be then used
7823 * together with the shift operator overridden by the builder in order to set an appropriate prefix
7824 * for the instruction being built.
7825 * @return The prefix indicator for the builder.
7826 * @since 1.1.0
7827 */
7828 static const InstructionPrefix LOCK() {
7829 return InstructionPrefix::LOCK();
7830 }
7831
7832 /**
7833 * Sets a prefix described by the name of the method for the instruction being built.
7834 * @return The instruction builder with the appropriate prefix set.
7835 * @since 1.1.0
7836 */
7837 IB& lock() {
7838 _prefixes |= FCML_PREFIX_LOCK;
7839 return *this;
7840 }
7841
7842 /**
7843 * Creates a prefix instance described by the name of the method. Such a prefix can be then used
7844 * together with the shift operator overridden by the builder in order to set an appropriate prefix
7845 * for the instruction being built.
7846 * @return The prefix indicator for the builder.
7847 * @since 1.1.0
7848 */
7849 static const InstructionPrefix REPNE() {
7850 return InstructionPrefix::REPNE();
7851 }
7852
7853 /**
7854 * Sets a prefix described by the name of the method for the instruction being built.
7855 * @return The instruction builder with the appropriate prefix set.
7856 * @since 1.1.0
7857 */
7858 IB& repne() {
7859 _prefixes |= FCML_PREFIX_REPNE;
7860 return *this;
7861 }
7862
7863 /**
7864 * Creates a prefix instance described by the name of the method. Such a prefix can be then used
7865 * together with the shift operator overridden by the builder in order to set an appropriate prefix
7866 * for the instruction being built.
7867 * @return The prefix indicator for the builder.
7868 * @since 1.1.0
7869 */
7870 static const InstructionPrefix REPNZ() {
7871 return InstructionPrefix::REPNZ();
7872 }
7873
7874 /**
7875 * Sets a prefix described by the name of the method for the instruction being built.
7876 * @return The instruction builder with the appropriate prefix set.
7877 * @since 1.1.0
7878 */
7879 IB& repnz() {
7880 _prefixes |= FCML_PREFIX_REPNZ;
7881 return *this;
7882 }
7883
7884 /**
7885 * Creates a prefix instance described by the name of the method. Such a prefix can be then used
7886 * together with the shift operator overridden by the builder in order to set an appropriate prefix
7887 * for the instruction being built.
7888 * @return The prefix indicator for the builder.
7889 * @since 1.1.0
7890 */
7891 static const InstructionPrefix REP() {
7892 return InstructionPrefix::REP();
7893 }
7894
7895 /**
7896 * Sets a prefix described by the name of the method for the instruction being built.
7897 * @return The instruction builder with the appropriate prefix set.
7898 * @since 1.1.0
7899 */
7900 IB& rep() {
7901 _prefixes |= FCML_PREFIX_REP;
7902 return *this;
7903 }
7904
7905 /**
7906 * Creates a prefix instance described by the name of the method. Such a prefix can be then used
7907 * together with the shift operator overridden by the builder in order to set an appropriate prefix
7908 * for the instruction being built.
7909 * @return The prefix indicator for the builder.
7910 * @since 1.1.0
7911 */
7912 static const InstructionPrefix REPE() {
7913 return InstructionPrefix::REPE();
7914 }
7915
7916 /**
7917 * Sets a prefix described by the name of the method for the instruction being built.
7918 * @return The instruction builder with the appropriate prefix set.
7919 * @since 1.1.0
7920 */
7921 IB& repe() {
7922 _prefixes |= FCML_PREFIX_REPE;
7923 return *this;
7924 }
7925
7926 /**
7927 * Creates a prefix instance described by the name of the method. Such a prefix can be then used
7928 * together with the shift operator overridden by the builder in order to set an appropriate prefix
7929 * for the instruction being built.
7930 * @return The prefix indicator for the builder.
7931 * @since 1.1.0
7932 */
7933 static const InstructionPrefix REPZ() {
7934 return InstructionPrefix::REPZ();
7935 }
7936
7937 /**
7938 * Sets a prefix described by the name of the method for the instruction being built.
7939 * @return The instruction builder with the appropriate prefix set.
7940 * @since 1.1.0
7941 */
7942 IB& repz() {
7943 _prefixes |= FCML_PREFIX_REPZ;
7944 return *this;
7945 }
7946
7947 /**
7948 * Creates a prefix instance described by the name of the method. Such a prefix can be then used
7949 * together with the shift operator overridden by the builder in order to set an appropriate prefix
7950 * for the instruction being built.
7951 * @return The prefix indicator for the builder.
7952 * @since 1.1.0
7953 */
7954 static const InstructionPrefix XACQUIRE() {
7955 return InstructionPrefix::XACQUIRE();
7956 }
7957
7958 /**
7959 * Sets a prefix described by the name of the method for the instruction being built.
7960 * @return The instruction builder with the appropriate prefix set.
7961 * @since 1.1.0
7962 */
7963 IB& xacquire() {
7964 _prefixes |= FCML_PREFIX_XACQUIRE;
7965 return *this;
7966 }
7967
7968 /**
7969 * Creates a prefix instance described by the name of the method. Such a prefix can be then used
7970 * together with the shift operator overridden by the builder in order to set an appropriate prefix
7971 * for the instruction being built.
7972 * @return The prefix indicator for the builder.
7973 * @since 1.1.0
7974 */
7975 static const InstructionPrefix XRELEASE() {
7976 return InstructionPrefix::XRELEASE();
7977 }
7978
7979 /**
7980 * Sets a prefix described by the name of the method for the instruction being built.
7981 * @return The instruction builder with the appropriate prefix set.
7982 * @since 1.1.0
7983 */
7984 IB& xrelease() {
7985 _prefixes |= FCML_PREFIX_XRELEASE;
7986 return *this;
7987 }
7988
7989 /**
7990 * Creates a prefix instance described by the name of the method. Such a prefix can be then used
7991 * together with the shift operator overridden by the builder in order to set an appropriate prefix
7992 * for the instruction being built.
7993 * @return The prefix indicator for the builder.
7994 * @since 1.1.0
7995 */
7996 static const InstructionPrefix BRANCH() {
7997 return InstructionPrefix::BRANCH_HINT();
7998 }
7999
8000 /**
8001 * Sets a prefix described by the name of the method for the instruction being built.
8002 * @return The instruction builder with the appropriate prefix set.
8003 * @since 1.1.0
8004 */
8005 IB& branchHint() {
8006 _prefixes |= FCML_PREFIX_BRANCH_HINT;
8007 return *this;
8008 }
8009
8010 /**
8011 * Creates a prefix instance described by the name of the method. Such a prefix can be then used
8012 * together with the shift operator overridden by the builder in order to set an appropriate prefix
8013 * for the instruction being built.
8014 * @return The prefix indicator for the builder.
8015 * @since 1.1.0
8016 */
8017 static const InstructionPrefix NO_BRANCH() {
8018 return InstructionPrefix::NOBRANCH_HINT();
8019 }
8020
8021 /**
8022 * Sets a prefix described by the name of the method for the instruction being built.
8023 * @return The instruction builder with the appropriate prefix set.
8024 * @since 1.1.0
8025 */
8026 IB& nobranchHint() {
8027 _prefixes |= FCML_PREFIX_NOBRANCH_HINT;
8028 return *this;
8029 }
8030
8031 /**
8032 * Gets multimedia hint for the operand.
8033 * @return The multimedia hint.
8034 */
8035 static const OperandHint OP_MULTIMEDIA_HINT() {
8036 return OperandHint::MULTIMEDIA();
8037 }
8038
8039 /**
8040 * Gets relative address hint for the operand.
8041 * @return The multimedia hint.
8042 */
8043 static const OperandHint OP_RELATIVE_ADDRESSING() {
8044 return OperandHint::RELATIVE_ADDRESSING();
8045 }
8046
8047 /**
8048 * Gets absolute hint for the operand.
8049 * @return The multimedia hint.
8050 */
8051 static const OperandHint OP_ABSOLUTE_ADDRESSING() {
8052 return OperandHint::ABSOLUTE_ADDRESSING();
8053 }
8054
8055 /**
8056 * Gets SIB encoding hint for the operand.
8057 * @return The SIB encoding hint.
8058 */
8059 static const OperandHint OP_SIB_ENCODING() {
8060 return OperandHint::SIB_ENCODING();
8061 }
8062
8063 /**
8064 * Marks the lastly added operand as a multimedia one.
8065 * @return The instruction builder itself.
8066 */
8067 IB& operandMultimediaHint() {
8068 set( OP_MULTIMEDIA_HINT() );
8069 return *this;
8070 }
8071
8072 /**
8073 * Marks the lastly added address operand as a relative one.
8074 * @return The instruction builder itself.
8075 */
8076 IB& operandRelativeHint() {
8077 set( OP_MULTIMEDIA_HINT() );
8078 return *this;
8079 }
8080
8081 /**
8082 * Marks the lastly added address operand as a absolute one.
8083 * @return The instruction builder itself.
8084 */
8085 IB& operandAbsoluteHint() {
8086 set( OP_MULTIMEDIA_HINT() );
8087 return *this;
8088 }
8089
8090 /**
8091 * Sets preferred encoding to SIB for the lastly added ModR/M operand.
8092 * @return The instruction builder itself.
8093 */
8094 IB& operandSIBEncodingHint() {
8095 set( OP_MULTIMEDIA_HINT() );
8096 return *this;
8097 }
8098
8099 // Operands.
8100
8101 /**
8102 * Adds an immediate operand.
8103 * @return The immediate operand.
8104 * @since 1.1.0
8105 */
8106 IB& imm( const Integer &imm ) {
8107 sanityCheck();
8108 _operands[_operandsCount++].imm(imm);
8109 return *this;
8110 }
8111
8112 /**
8113 * Adds a far pointer operand.
8114 * @param seg A segment selector.
8115 * @param addr An 16-bit offset value.
8116 * @return The far pointer operand.
8117 * @since 1.1.0
8118 */
8119 IB& far_ptr( fcml_uint16_t seg, fcml_int16_t addr ) {
8120 sanityCheck();
8121 _operands[_operandsCount++].far_ptr(seg, addr);
8122 return *this;
8123 }
8124
8125 /**
8126 * Adds a far pointer operand.
8127 * @param seg A segment selector.
8128 * @param addr An 32-bit offset value.
8129 * @return The far pointer operand.
8130 * @since 1.1.0
8131 */
8132 IB& far_ptr( fcml_uint16_t seg, fcml_int32_t addr ) {
8133 sanityCheck();
8134 _operands[_operandsCount++].far_ptr(seg, addr);
8135 return *this;
8136 }
8137
8138 /**
8139 * Adds a far pointer operand.
8140 * @param pointer A far pointer instance.
8141 * @return The far pointer operand.
8142 * @since 1.1.0
8143 */
8144 IB& far_ptr( const FarPointer &pointer ) {
8145 sanityCheck();
8146 _operands[_operandsCount++].far_ptr( pointer );
8147 return *this;
8148 }
8149
8150 /**
8151 * Adds an address operand.
8152 * @param address An address instance.
8153 * @return The address operand.
8154 * @since 1.1.0
8155 */
8156 IB& addr( const Address &address ) {
8157 sanityCheck();
8158 _operands[_operandsCount++].addr(address);
8159 return *this;
8160 }
8161
8162 /**
8163 * Adds an offset operand.
8164 * @param offset An offset instance.
8165 * @param sizeOperator An optional size operator.
8166 * @return The address operand.
8167 * @since 1.1.0
8168 */
8169 IB& off( const Integer &offset, fcml_usize sizeOperator = FCML_DS_UNDEF ) {
8170 sanityCheck();
8171 _operands[_operandsCount++].off( offset, sizeOperator );
8172 return *this;
8173 }
8174
8175 /**
8176 * Adds an offset based address operand with byte size operator.
8177 * @param offset An offset instance.
8178 * @return The address operand.
8179 * @since 1.1.0
8180 */
8181 IB& offb( const Integer &offset ) {
8182 sanityCheck();
8183 _operands[_operandsCount++].off( offset, FCML_DS_8 );
8184 return *this;
8185 }
8186
8187 /**
8188 * Adds an offset based address operand with word size operator.
8189 * @param offset An offset instance.
8190 * @return The address operand.
8191 * @since 1.1.0
8192 */
8193 IB& offw( const Integer &offset ) {
8194 sanityCheck();
8195 _operands[_operandsCount++].off( offset, FCML_DS_16 );
8196 return *this;
8197 }
8198
8199 /**
8200 * Adds an offset based address operand with double word size operator.
8201 * @param offset An offset instance.
8202 * @return The address operand.
8203 * @since 1.1.0
8204 */
8205 IB& offd( const Integer &offset ) {
8206 sanityCheck();
8207 _operands[_operandsCount++].off( offset, FCML_DS_32 );
8208 return *this;
8209 }
8210
8211 /**
8212 * Adds an offset based address operand with quadro word size operator.
8213 * @param offset An offset instance.
8214 * @return The address operand.
8215 * @since 1.1.0
8216 */
8217 IB& offq( const Integer &offset ) {
8218 sanityCheck();
8219 _operands[_operandsCount++].off( offset, FCML_DS_64 );
8220 return *this;
8221 }
8222
8223 /**
8224 * Adds an address type operand for given effective address and optional size operator.
8225 * @param effectiveAddress The effective address.
8226 * @param sizeOperator The optional size operator.
8227 * @return The created operator.
8228 * @since 1.1.0
8229 */
8230 IB& addr( const EffectiveAddress &effectiveAddress, fcml_usize sizeOperator = FCML_DS_UNDEF ) {
8231 sanityCheck();
8232 _operands[_operandsCount++].addr( effectiveAddress, sizeOperator );
8233 return *this;
8234 }
8235
8236 /**
8237 * Adds an address type operand for given effective address and byte size operator.
8238 * @param effectiveAddress The effective address.
8239 * @return The created operator.
8240 * @since 1.1.0
8241 */
8242 IB& addrb( const EffectiveAddress &effectiveAddress ) {
8243 sanityCheck();
8244 _operands[_operandsCount++].addr( effectiveAddress, FCML_DS_8 );
8245 return *this;
8246 }
8247
8248 /**
8249 * Adds an address type operand for given effective address and word size operator.
8250 * @param effectiveAddress The effective address.
8251 * @return The created operator.
8252 * @since 1.1.0
8253 */
8254 IB& addrw( const EffectiveAddress &effectiveAddress ) {
8255 sanityCheck();
8256 _operands[_operandsCount++].addr( effectiveAddress, FCML_DS_16 );
8257 return *this;
8258 }
8259
8260 /**
8261 * Adds an address type operand for given effective address and double word size operator.
8262 * @param effectiveAddress The effective address.
8263 * @return The created operator.
8264 * @since 1.1.0
8265 */
8266 IB& addrd( const EffectiveAddress &effectiveAddress ) {
8267 sanityCheck();
8268 _operands[_operandsCount++].addr( effectiveAddress, FCML_DS_32 );
8269 return *this;
8270 }
8271
8272 /**
8273 * Adds an address type operand for given effective address and quadro word size operator.
8274 * @param effectiveAddress The effective address.
8275 * @return The created operator.
8276 * @since 1.1.0
8277 */
8278 IB& addrq( const EffectiveAddress &effectiveAddress ) {
8279 sanityCheck();
8280 _operands[_operandsCount++].addr( effectiveAddress, FCML_DS_64 );
8281 return *this;
8282 }
8283
8284 /**
8285 * Adds an address type operand for given segment selector, effective address and optional size operator.
8286 * @param effectiveAddress The effective address.
8287 * @param segmentSelector The segment selector.
8288 * @param sizeOperator The optional size operator.
8289 * @return The created operator.
8290 * @since 1.1.0
8291 */
8292 IB& addr( const EffectiveAddress &effectiveAddress, const SegmentSelector &segmentSelector, fcml_usize sizeOperator = FCML_DS_UNDEF ) {
8293 sanityCheck();
8294 _operands[_operandsCount++].addr( effectiveAddress, segmentSelector, sizeOperator );
8295 return *this;
8296 }
8297
8298 /**
8299 * Adds an address type operand for given effective address and byte size operator.
8300 * @param effectiveAddress The effective address.
8301 * @param segmentSelector The segment selector.
8302 * @return The created operator.
8303 * @since 1.1.0
8304 */
8305 IB& addrb( const EffectiveAddress &effectiveAddress, const SegmentSelector &segmentSelector ) {
8306 sanityCheck();
8307 _operands[_operandsCount++].addr( effectiveAddress, segmentSelector, FCML_DS_8 );
8308 return *this;
8309 }
8310
8311 /**
8312 * Adds an address type operand for given effective address and byte size operator.
8313 * @param effectiveAddress The effective address.
8314 * @param segmentSelector The segment selector.
8315 * @return The created operator.
8316 * @since 1.1.0
8317 */
8318 IB& addrw( const EffectiveAddress &effectiveAddress, const SegmentSelector &segmentSelector ) {
8319 sanityCheck();
8320 _operands[_operandsCount++].addr( effectiveAddress, segmentSelector, FCML_DS_8 );
8321 return *this;
8322 }
8323
8324 /**
8325 * Adds an address type operand for given effective address and double word size operator.
8326 * @param effectiveAddress The effective address.
8327 * @param segmentSelector The segment selector.
8328 * @return The created operator.
8329 * @since 1.1.0
8330 */
8331 IB& addrd( const EffectiveAddress &effectiveAddress, const SegmentSelector &segmentSelector ) {
8332 sanityCheck();
8333 _operands[_operandsCount++].addr( effectiveAddress, segmentSelector, FCML_DS_8 );
8334 return *this;
8335 }
8336
8337 /**
8338 * Adds an address type operand for given effective address and quadro word size operator.
8339 * @param effectiveAddress The effective address.
8340 * @param segmentSelector The segment selector.
8341 * @return The created operator.
8342 * @since 1.1.0
8343 */
8344 IB& addrq( const EffectiveAddress &effectiveAddress, const SegmentSelector &segmentSelector ) {
8345 sanityCheck();
8346 _operands[_operandsCount++].addr( effectiveAddress, segmentSelector, FCML_DS_8 );
8347 return *this;
8348 }
8349
8350 /**
8351 * Adds an an register based operator for given register.
8352 * @param reg The register.
8353 * @return The created operator.
8354 * @since 1.1.0
8355 */
8356 IB& reg( const Register &reg ) {
8357 sanityCheck();
8358 _operands[_operandsCount++].reg( reg );
8359 return *this;
8360 }
8361
8362 /**
8363 * Adds an an register based operator for given parameters.
8364 * @param reg The FCML register number.
8365 * @param size The register size.
8366 * @param type The register type.
8367 * @param x64_exp See manual for more information.
8368 * @return The created operator.
8369 * @since 1.1.0
8370 */
8371 IB& reg( fcml_uint8_t reg, fcml_usize size, Register::RegisterType type = Register::REG_GPR, fcml_bool x64_exp = FCML_FALSE ) {
8372 sanityCheck();
8373 _operands[_operandsCount++].reg( Register( reg, size, type, x64_exp ) );
8374 return *this;
8375 }
8376
8377 /**
8378 * Adds an an effective address based operator for a displacement and optional size operator.
8379 * @param displacement The displacement value.
8380 * @param sizeOperator The size operator.
8381 * @return The created operator.
8382 * @since 1.1.0
8383 */
8384 IB& eff( const Integer &displacement, fcml_usize sizeOperator = FCML_DS_UNDEF ) {
8385 next().addr( EffectiveAddress(displacement), sizeOperator );
8386 return *this;
8387 }
8388
8389 /**
8390 * Adds an an effective address based operator for a displacement and byte size operator.
8391 * @param displacement The displacement value.
8392 * @return The created operator.
8393 * @since 1.1.0
8394 */
8395 IB& effb( const Integer &displacement ) {
8396 next().addr( EffectiveAddress(displacement), FCML_DS_8 );
8397 return *this;
8398 }
8399
8400 /**
8401 * Adds an an effective address based operator for a displacement and word size operator.
8402 * @param displacement The displacement value.
8403 * @return The created operator.
8404 * @since 1.1.0
8405 */
8406 IB& effw( const Integer &displacement ) {
8407 next().addr( EffectiveAddress(displacement), FCML_DS_16 );
8408 return *this;
8409 }
8410
8411 /**
8412 * Adds an an effective address based operator for a displacement and double word size operator.
8413 * @param displacement The displacement value.
8414 * @return The created operator.
8415 * @since 1.1.0
8416 */
8417 IB& effd( const Integer &displacement ) {
8418 next().addr( EffectiveAddress(displacement), FCML_DS_32 );
8419 return *this;
8420 }
8421
8422 /**
8423 * Adds an an effective address based operator for a displacement and quadro byte size operator.
8424 * @param displacement The displacement value.
8425 * @return The created operator.
8426 * @since 1.1.0
8427 */
8428 IB& effq( const Integer &displacement ) {
8429 next().addr( EffectiveAddress(displacement), FCML_DS_64 );
8430 return *this;
8431 }
8432
8433 /**
8434 * Adds an an effective address based operator for a base register and optional size operator.
8435 * @param base The base register.
8436 * @param sizeOperator The optional size operator.
8437 * @return The created operator.
8438 * @since 1.1.0
8439 */
8440 IB& eff( const Register &base, fcml_usize sizeOperator = FCML_DS_UNDEF ) {
8441 next().addr( EffectiveAddress(base), sizeOperator );
8442 return *this;
8443 }
8444
8445 /**
8446 * Adds an an effective address based operator for a base register and byte size operator.
8447 * @param base The base register.
8448 * @return The created operator.
8449 * @since 1.1.0
8450 */
8451 IB& effb( const Register &base ) {
8452 next().addr( EffectiveAddress(base), FCML_DS_8 );
8453 return *this;
8454 }
8455
8456 /**
8457 * Adds an an effective address based operator for a base register and word size operator.
8458 * @param base The base register.
8459 * @return The created operator.
8460 * @since 1.1.0
8461 */
8462 IB& effw( const Register &base ) {
8463 next().addr( EffectiveAddress(base), FCML_DS_16 );
8464 return *this;
8465 }
8466
8467 /**
8468 * Adds an an effective address based operator for a base register and double word size operator.
8469 * @param base The base register.
8470 * @return The created operator.
8471 * @since 1.1.0
8472 */
8473 IB& effd( const Register &base ) {
8474 next().addr( EffectiveAddress(base), FCML_DS_32 );
8475 return *this;
8476 }
8477
8478 /**
8479 * Adds an an effective address based operator for a base register and quadro word size operator.
8480 * @param base The base register.
8481 * @return The created operator.
8482 * @since 1.1.0
8483 */
8484 IB& effq( const Register &base ) {
8485 next().addr( EffectiveAddress(base), FCML_DS_64 );
8486 return *this;
8487 }
8488
8489 /**
8490 * Adds an an effective address based operator for a base register, displacement and optional size operator.
8491 * @param base The base register.
8492 * @param displacement The displacement value.
8493 * @param sizeOperator The optional size operator.
8494 * @return The created operator.
8495 * @since 1.1.0
8496 */
8497 IB& eff( const Register &base, const Integer &displacement, fcml_usize sizeOperator = FCML_DS_UNDEF ) {
8498 next().addr( EffectiveAddress( base, displacement ), sizeOperator );
8499 return *this;
8500 }
8501
8502 /**
8503 * Adds an an effective address based operator for a base register, displacement and byte size operator.
8504 * @param base The base register.
8505 * @param displacement The displacement value.
8506 * @return The created operator.
8507 * @since 1.1.0
8508 */
8509 IB& effb( const Register &base, const Integer &displacement ) {
8510 next().addr( EffectiveAddress( base, displacement ), FCML_DS_8 );
8511 return *this;
8512 }
8513
8514 /**
8515 * Adds an an effective address based operator for a base register, displacement and word size operator.
8516 * @param base The base register.
8517 * @param displacement The displacement value.
8518 * @return The created operator.
8519 * @since 1.1.0
8520 */
8521 IB& effw( const Register &base, const Integer &displacement ) {
8522 next().addr( EffectiveAddress( base, displacement ), FCML_DS_16 );
8523 return *this;
8524 }
8525
8526 /**
8527 * Adds an an effective address based operator for a base register, displacement and double word size operator.
8528 * @param base The base register.
8529 * @param displacement The displacement value.
8530 * @return The created operator.
8531 * @since 1.1.0
8532 */
8533 IB& effd( const Register &base, const Integer &displacement ) {
8534 next().addr( EffectiveAddress( base, displacement ), FCML_DS_32 );
8535 return *this;
8536 }
8537
8538 /**
8539 * Adds an an effective address based operator for a base register, displacement and quadro word size operator.
8540 * @param base The base register.
8541 * @param displacement The displacement value.
8542 * @return The created operator.
8543 * @since 1.1.0
8544 */
8545 IB& effq( const Register &base, const Integer &displacement ) {
8546 next().addr( EffectiveAddress( base, displacement ), FCML_DS_64 );
8547 return *this;
8548 }
8549
8550 /**
8551 * Adds an an effective address based operator for an index register, scaleFactor, displacement and optional size operator.
8552 * @param index The index register.
8553 * @param scaleFactor The scale factor.
8554 * @param displacement The displacement value.
8555 * @param sizeOperator The optional size operator.
8556 * @return The created operator.
8557 * @since 1.1.0
8558 */
8559 IB& eff( const Register &index, fcml_uint8_t scaleFactor, const Integer &displacement, fcml_usize sizeOperator = FCML_DS_UNDEF ) {
8560 next().addr( EffectiveAddress( index, scaleFactor, displacement ), sizeOperator );
8561 return *this;
8562 }
8563
8564 /**
8565 * Adds an an effective address based operator for an index register, scaleFactor, displacement and byte size operator.
8566 * @param index The index register.
8567 * @param scaleFactor The scale factor.
8568 * @param displacement The displacement value.
8569 * @return The created operator.
8570 * @since 1.1.0
8571 */
8572 IB& effb( const Register &index, fcml_uint8_t scaleFactor, const Integer &displacement ) {
8573 next().addr( EffectiveAddress( index, scaleFactor, displacement ), FCML_DS_8 );
8574 return *this;
8575 }
8576
8577 /**
8578 * Adds an an effective address based operator for an index register, scaleFactor, displacement and word size operator.
8579 * @param index The index register.
8580 * @param scaleFactor The scale factor.
8581 * @param displacement The displacement value.
8582 * @return The created operator.
8583 * @since 1.1.0
8584 */
8585 IB& effw( const Register &index, fcml_uint8_t scaleFactor, const Integer &displacement ) {
8586 next().addr( EffectiveAddress( index, scaleFactor, displacement ), FCML_DS_16 );
8587 return *this;
8588 }
8589
8590 /**
8591 * Adds an an effective address based operator for an index register, scaleFactor, displacement and double word size operator.
8592 * @param index The index register.
8593 * @param scaleFactor The scale factor.
8594 * @param displacement The displacement value.
8595 * @return The created operator.
8596 * @since 1.1.0
8597 */
8598 IB& effd( const Register &index, fcml_uint8_t scaleFactor, const Integer &displacement ) {
8599 next().addr( EffectiveAddress( index, scaleFactor, displacement ), FCML_DS_32 );
8600 return *this;
8601 }
8602
8603 /**
8604 * Adds an an effective address based operator for an index register, scaleFactor, displacement and quadro word size operator.
8605 * @param index The index register.
8606 * @param scaleFactor The scale factor.
8607 * @param displacement The displacement value.
8608 * @return The created operator.
8609 * @since 1.1.0
8610 */
8611 IB& effq( const Register &index, fcml_uint8_t scaleFactor, const Integer &displacement ) {
8612 next().addr( EffectiveAddress( index, scaleFactor, displacement ), FCML_DS_64 );
8613 return *this;
8614 }
8615
8616 /**
8617 * Adds an an effective address based operator for a base register, index register and optional size operator.
8618 * @param base The base register.
8619 * @param index The index register.
8620 * @param sizeOperator The optional size operator.
8621 * @return The created operator.
8622 * @since 1.1.0
8623 */
8624 IB& eff( const Register &base, const Register &index, fcml_usize sizeOperator = FCML_DS_UNDEF ) {
8625 next().addr( EffectiveAddress( base, index ), sizeOperator );
8626 return *this;
8627 }
8628
8629 /**
8630 * Adds an an effective address based operator for a base register, index register and byte size operator.
8631 * @param base The base register.
8632 * @param index The index register.
8633 * @return The created operator.
8634 * @since 1.1.0
8635 */
8636 IB& effb( const Register &base, const Register &index ) {
8637 next().addr( EffectiveAddress( base, index ), FCML_DS_8 );
8638 return *this;
8639 }
8640
8641 /**
8642 * Adds an an effective address based operator for a base register, index register and word size operator.
8643 * @param base The base register.
8644 * @param index The index register.
8645 * @return The created operator.
8646 * @since 1.1.0
8647 */
8648 IB& effw( const Register &base, const Register &index ) {
8649 next().addr( EffectiveAddress( base, index ), FCML_DS_16 );
8650 return *this;
8651 }
8652
8653 /**
8654 * Adds an an effective address based operator for a base register, index register and double word size operator.
8655 * @param base The base register.
8656 * @param index The index register.
8657 * @return The created operator.
8658 * @since 1.1.0
8659 */
8660 IB& effd( const Register &base, const Register &index ) {
8661 next().addr( EffectiveAddress( base, index ), FCML_DS_32 );
8662 return *this;
8663 }
8664
8665 /**
8666 * Adds an an effective address based operator for a base register, index register and quadro word size operator.
8667 * @param base The base register.
8668 * @param index The index register.
8669 * @return The created operator.
8670 * @since 1.1.0
8671 */
8672 IB& effq( const Register &base, const Register &index ) {
8673 next().addr( EffectiveAddress( base, index ), FCML_DS_64 );
8674 return *this;
8675 }
8676
8677 /**
8678 * Adds an an effective address based operator for a base register, index register, scale factor and optional size operator.
8679 * @param base The base register.
8680 * @param index The index register.
8681 * @param scaleFactor The scale factor.
8682 * @param sizeOperator The optional size operator.
8683 * @return The created operator.
8684 * @since 1.1.0
8685 */
8686 IB& eff( const Register &base, const Register &index, fcml_uint8_t scaleFactor, fcml_usize sizeOperator = FCML_DS_UNDEF ) {
8687 next().addr( EffectiveAddress( base, index, scaleFactor ), sizeOperator );
8688 return *this;
8689 }
8690
8691 /**
8692 * Adds an an effective address based operator for a base register, index register, scale factor and byte size operator.
8693 * @param base The base register.
8694 * @param index The index register.
8695 * @param scaleFactor The scale factor.
8696 * @return The created operator.
8697 * @since 1.1.0
8698 */
8699 IB& effb( const Register &base, const Register &index, fcml_uint8_t scaleFactor ) {
8700 next().addr( EffectiveAddress( base, index, scaleFactor ), FCML_DS_8 );
8701 return *this;
8702 }
8703
8704 /**
8705 * Adds an an effective address based operator for a base register, index register, scale factor and word size operator.
8706 * @param base The base register.
8707 * @param index The index register.
8708 * @param scaleFactor The scale factor.
8709 * @return The created operator.
8710 * @since 1.1.0
8711 */
8712 IB& effw( const Register &base, const Register &index, fcml_uint8_t scaleFactor ) {
8713 next().addr( EffectiveAddress( base, index, scaleFactor ), FCML_DS_16 );
8714 return *this;
8715 }
8716
8717 /**
8718 * Adds an an effective address based operator for a base register, index register, scale factor and double word size operator.
8719 * @param base The base register.
8720 * @param index The index register.
8721 * @param scaleFactor The scale factor.
8722 * @return The created operator.
8723 * @since 1.1.0
8724 */
8725 IB& effd( const Register &base, const Register &index, fcml_uint8_t scaleFactor ) {
8726 next().addr( EffectiveAddress( base, index, scaleFactor ), FCML_DS_32 );
8727 return *this;
8728 }
8729
8730 /**
8731 * Adds an an effective address based operator for a base register, index register, scale factor and quadro word size operator.
8732 * @param base The base register.
8733 * @param index The index register.
8734 * @param scaleFactor The scale factor.
8735 * @return The created operator.
8736 * @since 1.1.0
8737 */
8738 IB& effq( const Register &base, const Register &index, fcml_uint8_t scaleFactor ) {
8739 next().addr( EffectiveAddress( base, index, scaleFactor ), FCML_DS_64 );
8740 return *this;
8741 }
8742
8743 /**
8744 * Adds an an effective address based operator for a base register, index register, scale factor and optional size operator.
8745 * @param base The base register.
8746 * @param index The index register.
8747 * @param scaleFactor The scale factor.
8748 * @param displacement The displacement value.
8749 * @param sizeOperator The optional size operator.
8750 * @return The created operator.
8751 * @since 1.1.0
8752 */
8753 IB& eff( const Register &base, const Register &index, fcml_uint8_t scaleFactor, const Integer &displacement, fcml_usize sizeOperator = FCML_DS_UNDEF ) {
8754 next().addr( EffectiveAddress( base, index, scaleFactor, displacement ), sizeOperator );
8755 return *this;
8756 }
8757
8758 /**
8759 * Adds an an effective address based operator for a base register, index register, scale factor and byte size operator.
8760 * @param base The base register.
8761 * @param index The index register.
8762 * @param scaleFactor The scale factor.
8763 * @param displacement The displacement value.
8764 * @return The created operator.
8765 * @since 1.1.0
8766 */
8767 IB& effb( const Register &base, const Register &index, fcml_uint8_t scaleFactor, const Integer &displacement ) {
8768 next().addr( EffectiveAddress( base, index, scaleFactor, displacement ), FCML_DS_8 );
8769 return *this;
8770 }
8771
8772 /**
8773 * Adds an an effective address based operator for a base register, index register, scale factor and word size operator.
8774 * @param base The base register.
8775 * @param index The index register.
8776 * @param scaleFactor The scale factor.
8777 * @param displacement The displacement value.
8778 * @return The created operator.
8779 * @since 1.1.0
8780 */
8781 IB& effw( const Register &base, const Register &index, fcml_uint8_t scaleFactor, const Integer &displacement ) {
8782 next().addr( EffectiveAddress( base, index, scaleFactor, displacement ), FCML_DS_16 );
8783 return *this;
8784 }
8785
8786 /**
8787 * Adds an an effective address based operator for a base register, index register, scale factor and double word size operator.
8788 * @param base The base register.
8789 * @param index The index register.
8790 * @param scaleFactor The scale factor.
8791 * @param displacement The displacement value.
8792 * @return The created operator.
8793 * @since 1.1.0
8794 */
8795 IB& effd( const Register &base, const Register &index, fcml_uint8_t scaleFactor, const Integer &displacement ) {
8796 next().addr( EffectiveAddress( base, index, scaleFactor, displacement ), FCML_DS_32 );
8797 return *this;
8798 }
8799
8800 /**
8801 * Adds an an effective address based operator for a base register, index register, scale factor and quardo word size operator.
8802 * @param base The base register.
8803 * @param index The index register.
8804 * @param scaleFactor The scale factor.
8805 * @param displacement The displacement value.
8806 * @return The created operator.
8807 * @since 1.1.0
8808 */
8809 IB& effq( const Register &base, const Register &index, fcml_uint8_t scaleFactor, const Integer &displacement ) {
8810 next().addr( EffectiveAddress( base, index, scaleFactor, displacement ), FCML_DS_64 );
8811 return *this;
8812 }
8813
8814 /**
8815 * Adds an operand to the instruction being built.
8816 * @param operand The operand to be added.
8817 * @return The instruction builder with the new operand added to it.
8818 * @since 1.1.0
8819 */
8820 IB& operator <<(const Operand &operand) {
8821 next() = operand;
8822 return *this;
8823 }
8824
8825 /**
8826 * Adds a prefix to the instruction being built.
8827 * @param prefix The prefix to be added.
8828 * @return The instruction builder with the new prefix set for it.
8829 * @since 1.1.0
8830 */
8831 IB& operator <<(const InstructionPrefix &prefix) {
8832 return set(prefix);
8833 }
8834
8835 /**
8836 * Adds an instruction level hint to the instruction being built.
8837 * @param hint The hint to be added.
8838 * @return The instruction builder with the new hint added to it.
8839 * @since 1.1.0
8840 */
8841 IB& operator <<(const InstructionHint &hint) {
8842 return set( hint );
8843 }
8844
8845 /**
8846 * Adds an operand level hint to the instruction being built.
8847 * @param hint The hint to be added.
8848 * @return The instruction builder with the new hint added to it.
8849 * @since 1.1.0
8850 */
8851 IB& operator <<(const OperandHint &hint) {
8852 return set( hint );
8853 }
8854
8855 /**
8856 * Adds a prefix to the instruction being built.
8857 * @param prefix The prefix to be added.
8858 * @return The instruction builder with the new prefix set for it.
8859 * @since 1.1.0
8860 */
8861 IB& set( const InstructionPrefix &prefix ) {
8862 _prefixes |= prefix._prefix;
8863 return *this;
8864 }
8865
8866 /**
8867 * Adds an instruction level hint to the instruction being built.
8868 * @param hint The hint to be added.
8869 * @return The instruction builder with the new hint added to it.
8870 * @since 1.1.0
8871 */
8872 IB& set( const InstructionHint &hint ) {
8873 _hints |= hint._hint;
8874 return *this;
8875 }
8876
8877 /**
8878 * Adds an operand level hint to the instruction being built.
8879 * @param hint The hint to be added.
8880 * @return The instruction builder with the new hint added to it.
8881 * @since 1.1.0
8882 */
8883 IB& set( const OperandHint &hint ) {
8884 if( _operandsCount == 0 ) {
8885 throw IllegalStateException( FCML_TEXT( "There are no operands yet for the current instruction.." ) );
8886 }
8887 _operands[_operandsCount-1].setHints( _operands[_operandsCount-1].getHints() | hint._hint );
8888 return *this;
8889 }
8890
8891 private:
8892
8893 /**
8894 * Gets the next instruction operand.
8895 * @return A reference to the next instruction operand.
8896 * @since 1.1.0
8897 */
8898 Operand& next() {
8899 sanityCheck();
8900 return _operands[_operandsCount++];
8901 }
8902
8903 /**
8904 * Throws exception if there is no more space for new operands in the builder.
8905 * @throw IllegalStateException Operand's number exceeds maximal number of operands allowed.
8906 * @since 1.1.0
8907 */
8908 void sanityCheck() const {
8909 if( _operandsCount == FCML_OPERANDS_COUNT ) {
8910 throw IllegalStateException( FCML_TEXT( "Operand's number exceeds maximal number of operands allowed." ) );
8911 }
8912 }
8913
8914 private:
8915
8916 /** Instruction hints. */
8917 fcml_hints _hints;
8918 /** Instruction prefixes.*/
8919 fcml_prefixes _prefixes;
8920 /** Instruction mnemonic. */
8921 fcml_cstring _mnemonic;
8922 /** Number of operands available in the builder. */
8923 fcml_int _operandsCount;
8924 /** Operands for the built instruction. */
8925 Operand _operands[FCML_OPERANDS_COUNT];
8926
8927 };
8928
8929 /** Two way conversion for common types.
8930 * @since 1.1.0
8931 * @remarks Internal API, not intended to be used outside.
8932 */
8933 class TypeConverter {
8934 public:
8935
8936 static void convert( const fcml_st_entry_point &src, EntryPoint &dest ) {
8937 dest.setIP( src.ip );
8938 dest.setOpMode( static_cast<EntryPoint::OperatingMode>( src.op_mode ) );
8939 dest.setAddressSizeAttribute( src.address_size_attribute );
8940 dest.setOperandSizeAttribute( src.operand_size_attribute );
8941 }
8942
8943 static void convert( const EntryPoint &src, fcml_st_entry_point &dest ) {
8944 dest.ip = src.getIP();
8945 dest.op_mode = static_cast<fcml_en_operating_mode>( src.getOpMode() );
8946 dest.address_size_attribute = src.getAddressSizeAttribute();
8947 dest.operand_size_attribute = src.getOperandSizeAttribute();
8948 }
8949
8950 static void convert( const fcml_st_integer &src, Integer &dest ) {
8951 dest.setInt8( src.int8 );
8952 dest.setInt16( src.int16 );
8953 dest.setInt32( src.int32 );
8954 dest.setInt64( src.int64 );
8955 dest.setSigned( src.is_signed );
8956 dest.setSize( src.size );
8957 }
8958
8959 static void convert( const Integer &src, fcml_st_integer &dest ) {
8960 dest.int8 = src.getInt8();
8961 dest.int16 = src.getInt16();
8962 dest.int32 = src.getInt32();
8963 dest.int64 = src.getInt64();
8964 dest.is_signed = src.isSigned();
8965 dest.size = src.getSize();
8966 }
8967
8968 static void convert( const fcml_st_offset &src, Integer &dest ) {
8969 dest.setInt16( src.off16 );
8970 dest.setInt32( src.off32 );
8971 dest.setInt64( src.off64 );
8972 dest.setSigned( src.is_signed );
8973 dest.setSize( src.size );
8974 }
8975
8976 static void convert( const Integer &src, fcml_st_offset &dest ) {
8977 dest.off16 = src.getSize() == FCML_DS_8 ? src.getInt8() : src.getInt16();
8978 dest.off32 = src.getInt32();
8979 dest.off64 = src.getInt64();
8980 dest.is_signed = src.isSigned();
8981 dest.size = src.getSize();
8982 }
8983
8984 static void convert( const fcml_st_register &src, Register &dest ) {
8985 dest.setReg( src.reg );
8986 dest.setSize( src.size );
8987 dest.setType( static_cast<Register::RegisterType>( src.type ) );
8988 dest.setX64Exp( src.x64_exp ? true : false );
8989 }
8990
8991 static void convert( const Register &src, fcml_st_register &dest ) {
8992 dest.reg = src.getReg();
8993 dest.size = src.getSize();
8994 dest.type = static_cast<fcml_en_register>( src.getType() );
8995 dest.x64_exp = src.getX64Exp();
8996 }
8997
8998 static void convert( const fcml_st_far_pointer &src, FarPointer &dest ) {
8999 dest.setOffset16( src.offset16 );
9000 dest.setOffset32( src.offset32 );
9001 dest.setOffsetSize( src.offset_size );
9002 dest.setSegment( src.segment );
9003 }
9004
9005 static void convert( const FarPointer &src, fcml_st_far_pointer &dest ) {
9006 dest.offset16 = src.getOffset16();
9007 dest.offset32 = src.getOffset32();
9008 dest.offset_size = src.getOffsetSize();
9009 dest.segment = src.getSegment();
9010 }
9011
9012 static void convert( const fcml_st_segment_selector &src, SegmentSelector &dest ) {
9013 dest.setDefaultReg( src.is_default_reg ? true : false );
9014 convert( src.segment_selector, dest.getSegmentSelector() );
9015 }
9016
9017 static void convert( const SegmentSelector &src, fcml_st_segment_selector &dest ) {
9018 dest.is_default_reg = src.isDefaultReg();
9019 convert( src.getSegmentSelector(), dest.segment_selector );
9020 }
9021
9022 static void convert( const fcml_st_effective_address &src, EffectiveAddress &dest ) {
9023 convert( src.base, dest.getBase() );
9024 convert( src.index, dest.getIndex() );
9025 convert( src.displacement, dest.getDisplacement() );
9026 dest.setScaleFactor(src.scale_factor);
9027 }
9028
9029 static void convert( const EffectiveAddress &src, fcml_st_effective_address &dest ) {
9030 convert( src.getBase(), dest.base );
9031 convert( src.getIndex(), dest.index );
9032 convert( src.getDisplacement(), dest.displacement );
9033 dest.scale_factor = src.getScaleFactor();
9034 }
9035
9036 static void convert( const fcml_st_address &src, Address &dest ) {
9037 dest.setAddressForm( static_cast<Address::AddressForm>( src.address_form ) );
9038 dest.setSizeOperator( src.size_operator );
9039 convert( src.segment_selector, dest.getSegmentSelector() );
9040 convert( src.effective_address, dest.getEffectiveAddress() );
9041 convert( src.offset, dest.getOffset() );
9042 }
9043
9044 static void convert( const Address &src, fcml_st_address &dest ) {
9045 dest.address_form = static_cast<fcml_en_effective_address_form>( src.getAddressForm() );
9046 dest.size_operator = src.getSizeOperator();
9047 convert( src.getSegmentSelector(), dest.segment_selector );
9048 convert( src.getEffectiveAddress(), dest.effective_address );
9049 convert( src.getOffset(), dest.offset );
9050 }
9051
9052 static void convert(const fcml_st_operand &src, Operand &dest) {
9053 dest.setHints(src.hints);
9054 dest.setOperandType(static_cast<Operand::OperandType>(src.type));
9055 convert(src.address, dest.getAddress());
9056 convert(src.far_pointer, dest.getFarPointer());
9057 convert(src.immediate, dest.getImmediate());
9058 convert(src.reg, dest.getRegister());
9059 convert(src.decorators, dest.getDecorators());
9060 }
9061
9062 static void convert(const Operand &src, fcml_st_operand &dest) {
9063 dest.hints = src.getHints();
9064 dest.type = static_cast<fcml_en_operand_type>(src.getOperandType());
9065 convert(src.getAddress(), dest.address);
9066 convert(src.getFarPointer(), dest.far_pointer);
9067 convert(src.getImmediate(), dest.immediate);
9068 convert(src.getRegister(), dest.reg);
9069 convert(src.getDecorators(), dest.decorators);
9070 }
9071
9072 static void convert(const fcml_st_operand_decorators &src,
9073 Decorators &dest) {
9074 Nullable<fcml_uint8_t> bcast;
9075 bcast.setNotNull(FCML_TO_CPP_BOOL(src.bcast.is_not_null));
9076 bcast.setValue(src.bcast.value);
9077 dest.setBcast(bcast);
9078 Nullable<Decorators::EmbeededRoundingControl> er;
9079 er.setNotNull(FCML_TO_CPP_BOOL(src.er.is_not_null));
9080 er.setValue(static_cast<Decorators::EmbeededRoundingControl>(src.er.value));
9081 dest.setEr(er);
9082 dest.setZ(src.z);
9083 dest.setSae(src.sae);
9084 convert(src.operand_mask_reg, dest.getOpmaskReg());
9085 }
9086
9087 static void convert(const Decorators &src, fcml_st_operand_decorators &dest) {
9088 dest.bcast.is_not_null = src.getBcast().isNotNull();
9089 dest.bcast.value = src.getBcast().getValue();
9090 dest.er.is_not_null = src.getEr().isNotNull();
9091 dest.er.value = static_cast<fcml_uint8_t>(src.getEr().getValue());
9092 dest.z = src.isZ();
9093 dest.sae = src.isSae();
9094 convert(src.getOpmaskReg(), dest.operand_mask_reg);
9095 }
9096
9097 static void convert( const fcml_st_condition &src, Condition &dest ) {
9098 dest.setConditionType( static_cast<Condition::ConditionType>( src.condition_type ) );
9099 dest.setNegation( src.is_negation ? true : false );
9100 }
9101
9102 static void convert( const Condition &src, fcml_st_condition &dest ) {
9103 dest.condition_type = static_cast<fcml_en_condition_type>( src.getConditionType() );
9104 dest.is_negation = src.isNegation();
9105 }
9106
9107 static void convert( const fcml_st_instruction &src, Instruction &dest ) {
9108 dest.setMnemonic( src.mnemonic );
9109 convert( src.condition, dest.getCondition() );
9110 dest.setHints( src.hints );
9111 dest.setPrefixes( src.prefixes );
9112 dest.setConditional( src.is_conditional ? true : false );
9113 for( int i = 0; i < FCML_OPERANDS_COUNT; i++ ) {
9114 convert( src.operands[i], dest[i] );
9115 }
9116 dest.setOperandsCount(src.operands_count);
9117 }
9118
9119 static void convert( const Instruction &src, fcml_st_instruction &dest ) {
9120 // Bear in mind that you are responsible for freeing mnemonic duplicated here.
9121 dest.mnemonic = Env::strDup( src.getMnemonic().c_str() );
9122 convert( src.getCondition(), dest.condition );
9123 dest.hints = src.getHints();
9124 dest.prefixes = src.getPrefixes();
9125 dest.is_conditional = src.isConditional();
9126 for( int i = 0; i < FCML_OPERANDS_COUNT; i++ ) {
9127 convert( src[i], dest.operands[i] );
9128 }
9129 dest.operands_count = src.getOperandsCount();
9130 }
9131
9132 static void free( fcml_st_instruction &instruction ) {
9133 if( instruction.mnemonic ) {
9134 Env::strFree( instruction.mnemonic );
9135 instruction.mnemonic = NULL;
9136 }
9137 }
9138 };
9139
9140 }
9141
9142 #endif //FCML_COMMON_HPP_