llvm.org GIT mirror llvm / f8107eb
C++ has a bool type! (And C's had one too, for 15 years...) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206723 91177308-0d34-0410-b5e6-96231b3b80d8 Richard Smith 6 years ago
2 changed file(s) with 33 addition(s) and 38 deletion(s). Raw diff Collapse all Expand all
4646
4747 #include "X86GenDisassemblerTables.inc"
4848
49 #define TRUE 1
50 #define FALSE 0
51
5249 #ifndef NDEBUG
5350 #define debug(s) do { Debug(__FILE__, __LINE__, s); } while (0)
5451 #else
7774 * contextForAttrs.
7875 * @param opcode - The last byte of the instruction's opcode, not counting
7976 * ModR/M extensions and escapes.
80 * @return - TRUE if the ModR/M byte is required, FALSE otherwise.
77 * @return - true if the ModR/M byte is required, false otherwise.
8178 */
8279 static int modRMRequired(OpcodeType type,
8380 InstructionContext insnContext,
308305 * @param location - The location to query.
309306 * @return - Whether the prefix is at that location.
310307 */
311 static BOOL isPrefixAtLocation(struct InternalInstruction* insn,
308 static bool isPrefixAtLocation(struct InternalInstruction* insn,
312309 uint8_t prefix,
313310 uint64_t location)
314311 {
315312 if (insn->prefixPresent[prefix] == 1 &&
316313 insn->prefixLocations[prefix] == location)
317 return TRUE;
314 return true;
318315 else
319 return FALSE;
316 return false;
320317 }
321318
322319 /*
329326 * bytes, and no prefixes conflicted; nonzero otherwise.
330327 */
331328 static int readPrefixes(struct InternalInstruction* insn) {
332 BOOL isPrefix = TRUE;
333 BOOL prefixGroups[4] = { FALSE };
329 bool isPrefix = true;
330 bool prefixGroups[4] = { false };
334331 uint64_t prefixLocation;
335332 uint8_t byte = 0;
336333 uint8_t nextByte;
337334
338 BOOL hasAdSize = FALSE;
339 BOOL hasOpSize = FALSE;
335 bool hasAdSize = false;
336 bool hasOpSize = false;
340337
341338 dbgprintf(insn, "readPrefixes()");
342339
368365 if ((byte == 0xf2 || byte == 0xf3) &&
369366 ((nextByte == 0xf0) |
370367 ((nextByte & 0xfe) == 0x86 || (nextByte & 0xf8) == 0x90)))
371 insn->xAcquireRelease = TRUE;
368 insn->xAcquireRelease = true;
372369 /*
373370 * Also if the byte is 0xf3, and the following condition is met:
374371 * - it is followed by a "mov mem, reg" (opcode 0x88/0x89) or
378375 if (byte == 0xf3 &&
379376 (nextByte == 0x88 || nextByte == 0x89 ||
380377 nextByte == 0xc6 || nextByte == 0xc7))
381 insn->xAcquireRelease = TRUE;
378 insn->xAcquireRelease = true;
382379 if (insn->mode == MODE_64BIT && (nextByte & 0xf0) == 0x40) {
383380 if (consumeByte(insn, &nextByte))
384381 return -1;
396393 case 0xf3: /* REP or REPE/REPZ */
397394 if (prefixGroups[0])
398395 dbgprintf(insn, "Redundant Group 1 prefix");
399 prefixGroups[0] = TRUE;
396 prefixGroups[0] = true;
400397 setPrefixPresent(insn, byte, prefixLocation);
401398 break;
402399 case 0x2e: /* CS segment override -OR- Branch not taken */
430427 }
431428 if (prefixGroups[1])
432429 dbgprintf(insn, "Redundant Group 2 prefix");
433 prefixGroups[1] = TRUE;
430 prefixGroups[1] = true;
434431 setPrefixPresent(insn, byte, prefixLocation);
435432 break;
436433 case 0x66: /* Operand-size override */
437434 if (prefixGroups[2])
438435 dbgprintf(insn, "Redundant Group 3 prefix");
439 prefixGroups[2] = TRUE;
440 hasOpSize = TRUE;
436 prefixGroups[2] = true;
437 hasOpSize = true;
441438 setPrefixPresent(insn, byte, prefixLocation);
442439 break;
443440 case 0x67: /* Address-size override */
444441 if (prefixGroups[3])
445442 dbgprintf(insn, "Redundant Group 4 prefix");
446 prefixGroups[3] = TRUE;
447 hasAdSize = TRUE;
443 prefixGroups[3] = true;
444 hasAdSize = true;
448445 setPrefixPresent(insn, byte, prefixLocation);
449446 break;
450447 default: /* Not a prefix byte */
451 isPrefix = FALSE;
448 isPrefix = false;
452449 break;
453450 }
454451
573570 default:
574571 break;
575572 case VEX_PREFIX_66:
576 hasOpSize = TRUE;
573 hasOpSize = true;
577574 break;
578575 }
579576
619616 default:
620617 break;
621618 case VEX_PREFIX_66:
622 hasOpSize = TRUE;
619 hasOpSize = true;
623620 break;
624621 }
625622
814811 static int getIDWithAttrMask(uint16_t* instructionID,
815812 struct InternalInstruction* insn,
816813 uint16_t attrMask) {
817 BOOL hasModRMExtension;
814 bool hasModRMExtension;
818815
819816 InstructionContext instructionClass = contextForAttrs(attrMask);
820817
847844 * @param orig - The instruction that is not 16-bit
848845 * @param equiv - The instruction that is 16-bit
849846 */
850 static BOOL is16BitEquivalent(const char* orig, const char* equiv) {
847 static bool is16BitEquivalent(const char* orig, const char* equiv) {
851848 off_t i;
852849
853850 for (i = 0;; i++) {
854851 if (orig[i] == '\0' && equiv[i] == '\0')
855 return TRUE;
852 return true;
856853 if (orig[i] == '\0' || equiv[i] == '\0')
857 return FALSE;
854 return false;
858855 if (orig[i] != equiv[i]) {
859856 if ((orig[i] == 'Q' || orig[i] == 'L') && equiv[i] == 'W')
860857 continue;
862859 continue;
863860 if ((orig[i] == '4' || orig[i] == '2') && equiv[i] == '6')
864861 continue;
865 return FALSE;
862 return false;
866863 }
867864 }
868865 }
11071104 if (insn->consumedSIB)
11081105 return 0;
11091106
1110 insn->consumedSIB = TRUE;
1107 insn->consumedSIB = true;
11111108
11121109 switch (insn->addressSize) {
11131110 case 2:
12051202 if (insn->consumedDisplacement)
12061203 return 0;
12071204
1208 insn->consumedDisplacement = TRUE;
1205 insn->consumedDisplacement = true;
12091206 insn->displacementOffset = insn->readerCursor - insn->startLocation;
12101207
12111208 switch (insn->eaDisplacement) {
12121209 case EA_DISP_NONE:
1213 insn->consumedDisplacement = FALSE;
1210 insn->consumedDisplacement = false;
12141211 break;
12151212 case EA_DISP_8:
12161213 if (consumeInt8(insn, &d8))
12291226 break;
12301227 }
12311228
1232 insn->consumedDisplacement = TRUE;
1229 insn->consumedDisplacement = true;
12331230 return 0;
12341231 }
12351232
12501247
12511248 if (consumeByte(insn, &insn->modRM))
12521249 return -1;
1253 insn->consumedModRM = TRUE;
1250 insn->consumedModRM = true;
12541251
12551252 mod = modFromModRM(insn->modRM);
12561253 rm = rmFromModRM(insn->modRM);
472472 TYPE_XOP = 0x4
473473 };
474474
475 typedef uint8_t BOOL;
476
477475 /// \brief Type for the byte reader that the consumer must provide to
478476 /// the decoder. Reads a single byte from the instruction's address space.
479477 /// \param arg A baton that the consumer can associate with any internal
540538 // The segment override type
541539 SegmentOverride segmentOverride;
542540 // 1 if the prefix byte, 0xf2 or 0xf3 is xacquire or xrelease
543 BOOL xAcquireRelease;
541 bool xAcquireRelease;
544542
545543 // Sizes of various critical pieces of data, in bytes
546544 uint8_t registerSize;
582580
583581 // The ModR/M byte, which contains most register operands and some portion of
584582 // all memory operands.
585 BOOL consumedModRM;
583 bool consumedModRM;
586584 uint8_t modRM;
587585
588586 // The SIB byte, used for more complex 32- or 64-bit memory operands
589 BOOL consumedSIB;
587 bool consumedSIB;
590588 uint8_t sib;
591589
592590 // The displacement, used for memory operands
593 BOOL consumedDisplacement;
591 bool consumedDisplacement;
594592 int32_t displacement;
595593
596594 // Immediates. There can be two in some cases