1 //===- EDEmitter.cpp - Generate instruction descriptions for ED -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This tablegen backend is responsible for emitting a description of each
11 // instruction in a format that the enhanced disassembler can use to tokenize
12 // and parse instructions.
14 //===----------------------------------------------------------------------===//
16 #include "EDEmitter.h"
18 #include "AsmWriterInst.h"
19 #include "CodeGenTarget.h"
21 #include "llvm/TableGen/Record.h"
22 #include "llvm/MC/EDInstInfo.h"
23 #include "llvm/Support/ErrorHandling.h"
24 #include "llvm/Support/Format.h"
25 #include "llvm/Support/raw_ostream.h"
32 ///////////////////////////////////////////////////////////
33 // Support classes for emitting nested C data structures //
34 ///////////////////////////////////////////////////////////
41 std::vector<std::string> Entries;
43 EnumEmitter(const char *N) : Name(N) {
45 int addEntry(const char *e) {
46 Entries.push_back(std::string(e));
47 return Entries.size() - 1;
49 void emit(raw_ostream &o, unsigned int &i) {
50 o.indent(i) << "enum " << Name.c_str() << " {" << "\n";
53 unsigned int index = 0;
54 unsigned int numEntries = Entries.size();
55 for (index = 0; index < numEntries; ++index) {
56 o.indent(i) << Entries[index];
57 if (index < (numEntries - 1))
63 o.indent(i) << "};" << "\n";
66 void emitAsFlags(raw_ostream &o, unsigned int &i) {
67 o.indent(i) << "enum " << Name.c_str() << " {" << "\n";
70 unsigned int index = 0;
71 unsigned int numEntries = Entries.size();
72 unsigned int flag = 1;
73 for (index = 0; index < numEntries; ++index) {
74 o.indent(i) << Entries[index] << " = " << format("0x%x", flag);
75 if (index < (numEntries - 1))
82 o.indent(i) << "};" << "\n";
86 class ConstantEmitter {
88 virtual ~ConstantEmitter() { }
89 virtual void emit(raw_ostream &o, unsigned int &i) = 0;
92 class LiteralConstantEmitter : public ConstantEmitter {
100 LiteralConstantEmitter(int number = 0) :
104 void set(const char *string) {
109 bool is(const char *string) {
110 return !strcmp(String, string);
112 void emit(raw_ostream &o, unsigned int &i) {
120 class CompoundConstantEmitter : public ConstantEmitter {
122 unsigned int Padding;
123 std::vector<ConstantEmitter *> Entries;
125 CompoundConstantEmitter(unsigned int padding = 0) : Padding(padding) {
127 CompoundConstantEmitter &addEntry(ConstantEmitter *e) {
128 Entries.push_back(e);
132 ~CompoundConstantEmitter() {
133 while (Entries.size()) {
134 ConstantEmitter *entry = Entries.back();
139 void emit(raw_ostream &o, unsigned int &i) {
144 unsigned int numEntries = Entries.size();
146 unsigned int numToPrint;
149 if (numEntries > Padding) {
150 fprintf(stderr, "%u entries but %u padding\n", numEntries, Padding);
151 llvm_unreachable("More entries than padding");
153 numToPrint = Padding;
155 numToPrint = numEntries;
158 for (index = 0; index < numToPrint; ++index) {
160 if (index < numEntries)
161 Entries[index]->emit(o, i);
165 if (index < (numToPrint - 1))
175 class FlagsConstantEmitter : public ConstantEmitter {
177 std::vector<std::string> Flags;
179 FlagsConstantEmitter() {
181 FlagsConstantEmitter &addEntry(const char *f) {
182 Flags.push_back(std::string(f));
185 void emit(raw_ostream &o, unsigned int &i) {
187 unsigned int numFlags = Flags.size();
191 for (index = 0; index < numFlags; ++index) {
192 o << Flags[index].c_str();
193 if (index < (numFlags - 1))
200 EDEmitter::EDEmitter(RecordKeeper &R) : Records(R) {
203 /// populateOperandOrder - Accepts a CodeGenInstruction and generates its
204 /// AsmWriterInst for the desired assembly syntax, giving an ordered list of
205 /// operands in the order they appear in the printed instruction. Then, for
206 /// each entry in that list, determines the index of the same operand in the
207 /// CodeGenInstruction, and emits the resulting mapping into an array, filling
208 /// in unused slots with -1.
210 /// @arg operandOrder - The array that will be populated with the operand
211 /// mapping. Each entry will contain -1 (invalid index
212 /// into the operands present in the AsmString) or a number
213 /// representing an index in the operand descriptor array.
214 /// @arg inst - The instruction to use when looking up the operands
215 /// @arg syntax - The syntax to use, according to LLVM's enumeration
216 void populateOperandOrder(CompoundConstantEmitter *operandOrder,
217 const CodeGenInstruction &inst,
219 unsigned int numArgs = 0;
221 AsmWriterInst awInst(inst, syntax, -1, -1);
223 std::vector<AsmWriterOperand>::iterator operandIterator;
225 for (operandIterator = awInst.Operands.begin();
226 operandIterator != awInst.Operands.end();
228 if (operandIterator->OperandType ==
229 AsmWriterOperand::isMachineInstrOperand) {
230 operandOrder->addEntry(
231 new LiteralConstantEmitter(operandIterator->CGIOpNo));
237 /////////////////////////////////////////////////////
238 // Support functions for handling X86 instructions //
239 /////////////////////////////////////////////////////
241 #define SET(flag) { type->set(flag); return 0; }
243 #define REG(str) if (name == str) SET("kOperandTypeRegister");
244 #define MEM(str) if (name == str) SET("kOperandTypeX86Memory");
245 #define LEA(str) if (name == str) SET("kOperandTypeX86EffectiveAddress");
246 #define IMM(str) if (name == str) SET("kOperandTypeImmediate");
247 #define PCR(str) if (name == str) SET("kOperandTypeX86PCRelative");
249 /// X86TypeFromOpName - Processes the name of a single X86 operand (which is
250 /// actually its type) and translates it into an operand type
252 /// @arg flags - The type object to set
253 /// @arg name - The name of the operand
254 static int X86TypeFromOpName(LiteralConstantEmitter *type,
255 const std::string &name) {
321 PCR("i64i32imm_pcrel");
328 PCR("uncondbrtarget");
331 // all I, ARM mode only, conditional/unconditional
345 /// X86PopulateOperands - Handles all the operands in an X86 instruction, adding
346 /// the appropriate flags to their descriptors
348 /// @operandFlags - A reference the array of operand flag objects
349 /// @inst - The instruction to use as a source of information
350 static void X86PopulateOperands(
351 LiteralConstantEmitter *(&operandTypes)[EDIS_MAX_OPERANDS],
352 const CodeGenInstruction &inst) {
353 if (!inst.TheDef->isSubClassOf("X86Inst"))
357 unsigned int numOperands = inst.Operands.size();
359 for (index = 0; index < numOperands; ++index) {
360 const CGIOperandList::OperandInfo &operandInfo = inst.Operands[index];
361 Record &rec = *operandInfo.Rec;
363 if (X86TypeFromOpName(operandTypes[index], rec.getName()) &&
364 !rec.isSubClassOf("PointerLikeRegClass")) {
365 errs() << "Operand type: " << rec.getName().c_str() << "\n";
366 errs() << "Operand name: " << operandInfo.Name.c_str() << "\n";
367 errs() << "Instruction name: " << inst.TheDef->getName().c_str() << "\n";
368 llvm_unreachable("Unhandled type");
373 /// decorate1 - Decorates a named operand with a new flag
375 /// @operandFlags - The array of operand flag objects, which don't have names
376 /// @inst - The CodeGenInstruction, which provides a way to translate
377 /// between names and operand indices
378 /// @opName - The name of the operand
379 /// @flag - The name of the flag to add
380 static inline void decorate1(
381 FlagsConstantEmitter *(&operandFlags)[EDIS_MAX_OPERANDS],
382 const CodeGenInstruction &inst,
384 const char *opFlag) {
387 opIndex = inst.Operands.getOperandNamed(std::string(opName));
389 operandFlags[opIndex]->addEntry(opFlag);
392 #define DECORATE1(opName, opFlag) decorate1(operandFlags, inst, opName, opFlag)
394 #define MOV(source, target) { \
395 instType.set("kInstructionTypeMove"); \
396 DECORATE1(source, "kOperandFlagSource"); \
397 DECORATE1(target, "kOperandFlagTarget"); \
400 #define BRANCH(target) { \
401 instType.set("kInstructionTypeBranch"); \
402 DECORATE1(target, "kOperandFlagTarget"); \
405 #define PUSH(source) { \
406 instType.set("kInstructionTypePush"); \
407 DECORATE1(source, "kOperandFlagSource"); \
410 #define POP(target) { \
411 instType.set("kInstructionTypePop"); \
412 DECORATE1(target, "kOperandFlagTarget"); \
415 #define CALL(target) { \
416 instType.set("kInstructionTypeCall"); \
417 DECORATE1(target, "kOperandFlagTarget"); \
421 instType.set("kInstructionTypeReturn"); \
424 /// X86ExtractSemantics - Performs various checks on the name of an X86
425 /// instruction to determine what sort of an instruction it is and then adds
426 /// the appropriate flags to the instruction and its operands
428 /// @arg instType - A reference to the type for the instruction as a whole
429 /// @arg operandFlags - A reference to the array of operand flag object pointers
430 /// @arg inst - A reference to the original instruction
431 static void X86ExtractSemantics(
432 LiteralConstantEmitter &instType,
433 FlagsConstantEmitter *(&operandFlags)[EDIS_MAX_OPERANDS],
434 const CodeGenInstruction &inst) {
435 const std::string &name = inst.TheDef->getName();
437 if (name.find("MOV") != name.npos) {
438 if (name.find("MOV_V") != name.npos) {
439 // ignore (this is a pseudoinstruction)
440 } else if (name.find("MASK") != name.npos) {
441 // ignore (this is a masking move)
442 } else if (name.find("r0") != name.npos) {
443 // ignore (this is a pseudoinstruction)
444 } else if (name.find("PS") != name.npos ||
445 name.find("PD") != name.npos) {
446 // ignore (this is a shuffling move)
447 } else if (name.find("MOVS") != name.npos) {
448 // ignore (this is a string move)
449 } else if (name.find("_F") != name.npos) {
450 // TODO handle _F moves to ST(0)
451 } else if (name.find("a") != name.npos) {
452 // TODO handle moves to/from %ax
453 } else if (name.find("CMOV") != name.npos) {
455 } else if (name.find("PC") != name.npos) {
462 if (name.find("JMP") != name.npos ||
463 name.find("J") == 0) {
464 if (name.find("FAR") != name.npos && name.find("i") != name.npos) {
471 if (name.find("PUSH") != name.npos) {
472 if (name.find("CS") != name.npos ||
473 name.find("DS") != name.npos ||
474 name.find("ES") != name.npos ||
475 name.find("FS") != name.npos ||
476 name.find("GS") != name.npos ||
477 name.find("SS") != name.npos) {
478 instType.set("kInstructionTypePush");
479 // TODO add support for fixed operands
480 } else if (name.find("F") != name.npos) {
481 // ignore (this pushes onto the FP stack)
482 } else if (name.find("A") != name.npos) {
483 // ignore (pushes all GP registoers onto the stack)
484 } else if (name[name.length() - 1] == 'm') {
486 } else if (name.find("i") != name.npos) {
493 if (name.find("POP") != name.npos) {
494 if (name.find("POPCNT") != name.npos) {
495 // ignore (not a real pop)
496 } else if (name.find("CS") != name.npos ||
497 name.find("DS") != name.npos ||
498 name.find("ES") != name.npos ||
499 name.find("FS") != name.npos ||
500 name.find("GS") != name.npos ||
501 name.find("SS") != name.npos) {
502 instType.set("kInstructionTypePop");
503 // TODO add support for fixed operands
504 } else if (name.find("F") != name.npos) {
505 // ignore (this pops from the FP stack)
506 } else if (name.find("A") != name.npos) {
507 // ignore (pushes all GP registoers onto the stack)
508 } else if (name[name.length() - 1] == 'm') {
515 if (name.find("CALL") != name.npos) {
516 if (name.find("ADJ") != name.npos) {
517 // ignore (not a call)
518 } else if (name.find("SYSCALL") != name.npos) {
519 // ignore (doesn't go anywhere we know about)
520 } else if (name.find("VMCALL") != name.npos) {
521 // ignore (rather different semantics than a regular call)
522 } else if (name.find("FAR") != name.npos && name.find("i") != name.npos) {
529 if (name.find("RET") != name.npos) {
541 /////////////////////////////////////////////////////
542 // Support functions for handling ARM instructions //
543 /////////////////////////////////////////////////////
545 #define SET(flag) { type->set(flag); return 0; }
547 #define REG(str) if (name == str) SET("kOperandTypeRegister");
548 #define IMM(str) if (name == str) SET("kOperandTypeImmediate");
550 #define MISC(str, type) if (name == str) SET(type);
552 /// ARMFlagFromOpName - Processes the name of a single ARM operand (which is
553 /// actually its type) and translates it into an operand type
555 /// @arg type - The type object to set
556 /// @arg name - The name of the operand
557 static int ARMFlagFromOpName(LiteralConstantEmitter *type,
558 const std::string &name) {
576 IMM("i32imm_hilo16");
577 IMM("bf_inv_mask_imm");
580 IMM("jtblock_operand");
586 IMM("cpinst_operand");
604 IMM("imm0_65535_expr");
608 IMM("jt2block_operand");
609 IMM("t_imm0_1020s4");
617 IMM("neon_vcvt_imm32");
624 IMM("postidx_imm8s4");
628 MISC("brtarget", "kOperandTypeARMBranchTarget"); // ?
629 MISC("uncondbrtarget", "kOperandTypeARMBranchTarget"); // ?
630 MISC("t_brtarget", "kOperandTypeARMBranchTarget"); // ?
631 MISC("t_bcctarget", "kOperandTypeARMBranchTarget"); // ?
632 MISC("t_cbtarget", "kOperandTypeARMBranchTarget"); // ?
633 MISC("bltarget", "kOperandTypeARMBranchTarget"); // ?
635 MISC("br_target", "kOperandTypeARMBranchTarget"); // ?
636 MISC("bl_target", "kOperandTypeARMBranchTarget"); // ?
637 MISC("blx_target", "kOperandTypeARMBranchTarget"); // ?
639 MISC("t_bltarget", "kOperandTypeARMBranchTarget"); // ?
640 MISC("t_blxtarget", "kOperandTypeARMBranchTarget"); // ?
641 MISC("so_reg_imm", "kOperandTypeARMSoRegReg"); // R, R, I
642 MISC("so_reg_reg", "kOperandTypeARMSoRegImm"); // R, R, I
643 MISC("shift_so_reg_reg", "kOperandTypeARMSoRegReg"); // R, R, I
644 MISC("shift_so_reg_imm", "kOperandTypeARMSoRegImm"); // R, R, I
645 MISC("t2_so_reg", "kOperandTypeThumb2SoReg"); // R, I
646 MISC("so_imm", "kOperandTypeARMSoImm"); // I
647 MISC("rot_imm", "kOperandTypeARMRotImm"); // I
648 MISC("t2_so_imm", "kOperandTypeThumb2SoImm"); // I
649 MISC("so_imm2part", "kOperandTypeARMSoImm2Part"); // I
650 MISC("pred", "kOperandTypeARMPredicate"); // I, R
651 MISC("it_pred", "kOperandTypeARMPredicate"); // I
652 MISC("addrmode_imm12", "kOperandTypeAddrModeImm12"); // R, I
653 MISC("ldst_so_reg", "kOperandTypeLdStSOReg"); // R, R, I
654 MISC("postidx_reg", "kOperandTypeARMAddrMode3Offset"); // R, I
655 MISC("addrmode2", "kOperandTypeARMAddrMode2"); // R, R, I
656 MISC("am2offset_reg", "kOperandTypeARMAddrMode2Offset"); // R, I
657 MISC("am2offset_imm", "kOperandTypeARMAddrMode2Offset"); // R, I
658 MISC("addrmode3", "kOperandTypeARMAddrMode3"); // R, R, I
659 MISC("am3offset", "kOperandTypeARMAddrMode3Offset"); // R, I
660 MISC("ldstm_mode", "kOperandTypeARMLdStmMode"); // I
661 MISC("addrmode5", "kOperandTypeARMAddrMode5"); // R, I
662 MISC("addrmode6", "kOperandTypeARMAddrMode6"); // R, R, I, I
663 MISC("am6offset", "kOperandTypeARMAddrMode6Offset"); // R, I, I
664 MISC("addrmode6dup", "kOperandTypeARMAddrMode6"); // R, R, I, I
665 MISC("addrmode6oneL32", "kOperandTypeARMAddrMode6"); // R, R, I, I
666 MISC("addrmodepc", "kOperandTypeARMAddrModePC"); // R, I
667 MISC("addr_offset_none", "kOperandTypeARMAddrMode7"); // R
668 MISC("reglist", "kOperandTypeARMRegisterList"); // I, R, ...
669 MISC("dpr_reglist", "kOperandTypeARMDPRRegisterList"); // I, R, ...
670 MISC("spr_reglist", "kOperandTypeARMSPRRegisterList"); // I, R, ...
671 MISC("it_mask", "kOperandTypeThumbITMask"); // I
672 MISC("t2addrmode_reg", "kOperandTypeThumb2AddrModeReg"); // R
673 MISC("t2addrmode_posimm8", "kOperandTypeThumb2AddrModeImm8"); // R, I
674 MISC("t2addrmode_negimm8", "kOperandTypeThumb2AddrModeImm8"); // R, I
675 MISC("t2addrmode_imm8", "kOperandTypeThumb2AddrModeImm8"); // R, I
676 MISC("t2am_imm8_offset", "kOperandTypeThumb2AddrModeImm8Offset");//I
677 MISC("t2addrmode_imm12", "kOperandTypeThumb2AddrModeImm12"); // R, I
678 MISC("t2addrmode_so_reg", "kOperandTypeThumb2AddrModeSoReg"); // R, R, I
679 MISC("t2addrmode_imm8s4", "kOperandTypeThumb2AddrModeImm8s4"); // R, I
680 MISC("t2addrmode_imm0_1020s4", "kOperandTypeThumb2AddrModeImm8s4"); // R, I
681 MISC("t2am_imm8s4_offset", "kOperandTypeThumb2AddrModeImm8s4Offset");
683 MISC("tb_addrmode", "kOperandTypeARMTBAddrMode"); // I
684 MISC("t_addrmode_rrs1", "kOperandTypeThumbAddrModeRegS1"); // R, R
685 MISC("t_addrmode_rrs2", "kOperandTypeThumbAddrModeRegS2"); // R, R
686 MISC("t_addrmode_rrs4", "kOperandTypeThumbAddrModeRegS4"); // R, R
687 MISC("t_addrmode_is1", "kOperandTypeThumbAddrModeImmS1"); // R, I
688 MISC("t_addrmode_is2", "kOperandTypeThumbAddrModeImmS2"); // R, I
689 MISC("t_addrmode_is4", "kOperandTypeThumbAddrModeImmS4"); // R, I
690 MISC("t_addrmode_rr", "kOperandTypeThumbAddrModeRR"); // R, R
691 MISC("t_addrmode_sp", "kOperandTypeThumbAddrModeSP"); // R, I
692 MISC("t_addrmode_pc", "kOperandTypeThumbAddrModePC"); // R, I
693 MISC("addrmode_tbb", "kOperandTypeThumbAddrModeRR"); // R, R
694 MISC("addrmode_tbh", "kOperandTypeThumbAddrModeRR"); // R, R
705 /// ARMPopulateOperands - Handles all the operands in an ARM instruction, adding
706 /// the appropriate flags to their descriptors
708 /// @operandFlags - A reference the array of operand flag objects
709 /// @inst - The instruction to use as a source of information
710 static void ARMPopulateOperands(
711 LiteralConstantEmitter *(&operandTypes)[EDIS_MAX_OPERANDS],
712 const CodeGenInstruction &inst) {
713 if (!inst.TheDef->isSubClassOf("InstARM") &&
714 !inst.TheDef->isSubClassOf("InstThumb"))
718 unsigned int numOperands = inst.Operands.size();
720 if (numOperands > EDIS_MAX_OPERANDS) {
721 errs() << "numOperands == " << numOperands << " > " <<
722 EDIS_MAX_OPERANDS << '\n';
723 llvm_unreachable("Too many operands");
726 for (index = 0; index < numOperands; ++index) {
727 const CGIOperandList::OperandInfo &operandInfo = inst.Operands[index];
728 Record &rec = *operandInfo.Rec;
730 if (ARMFlagFromOpName(operandTypes[index], rec.getName())) {
731 errs() << "Operand type: " << rec.getName() << '\n';
732 errs() << "Operand name: " << operandInfo.Name << '\n';
733 errs() << "Instruction name: " << inst.TheDef->getName() << '\n';
734 llvm_unreachable("Unhandled type");
739 #define BRANCH(target) { \
740 instType.set("kInstructionTypeBranch"); \
741 DECORATE1(target, "kOperandFlagTarget"); \
744 /// ARMExtractSemantics - Performs various checks on the name of an ARM
745 /// instruction to determine what sort of an instruction it is and then adds
746 /// the appropriate flags to the instruction and its operands
748 /// @arg instType - A reference to the type for the instruction as a whole
749 /// @arg operandTypes - A reference to the array of operand type object pointers
750 /// @arg operandFlags - A reference to the array of operand flag object pointers
751 /// @arg inst - A reference to the original instruction
752 static void ARMExtractSemantics(
753 LiteralConstantEmitter &instType,
754 LiteralConstantEmitter *(&operandTypes)[EDIS_MAX_OPERANDS],
755 FlagsConstantEmitter *(&operandFlags)[EDIS_MAX_OPERANDS],
756 const CodeGenInstruction &inst) {
757 const std::string &name = inst.TheDef->getName();
759 if (name == "tBcc" ||
768 if (name == "tBLr9" ||
769 name == "BLr9_pred" ||
770 name == "tBLXi_r9" ||
771 name == "tBLXr_r9" ||
778 opIndex = inst.Operands.getOperandNamed("func");
779 if (operandTypes[opIndex]->is("kOperandTypeImmediate"))
780 operandTypes[opIndex]->set("kOperandTypeARMBranchTarget");
786 /// populateInstInfo - Fills an array of InstInfos with information about each
787 /// instruction in a target
789 /// @arg infoArray - The array of InstInfo objects to populate
790 /// @arg target - The CodeGenTarget to use as a source of instructions
791 static void populateInstInfo(CompoundConstantEmitter &infoArray,
792 CodeGenTarget &target) {
793 const std::vector<const CodeGenInstruction*> &numberedInstructions =
794 target.getInstructionsByEnumValue();
797 unsigned int numInstructions = numberedInstructions.size();
799 for (index = 0; index < numInstructions; ++index) {
800 const CodeGenInstruction& inst = *numberedInstructions[index];
802 // We don't need to do anything for pseudo-instructions, as we'll never
803 // see them here. We'll only see real instructions.
807 CompoundConstantEmitter *infoStruct = new CompoundConstantEmitter;
808 infoArray.addEntry(infoStruct);
810 LiteralConstantEmitter *instType = new LiteralConstantEmitter;
811 infoStruct->addEntry(instType);
813 LiteralConstantEmitter *numOperandsEmitter =
814 new LiteralConstantEmitter(inst.Operands.size());
815 infoStruct->addEntry(numOperandsEmitter);
817 CompoundConstantEmitter *operandTypeArray = new CompoundConstantEmitter;
818 infoStruct->addEntry(operandTypeArray);
820 LiteralConstantEmitter *operandTypes[EDIS_MAX_OPERANDS];
822 CompoundConstantEmitter *operandFlagArray = new CompoundConstantEmitter;
823 infoStruct->addEntry(operandFlagArray);
825 FlagsConstantEmitter *operandFlags[EDIS_MAX_OPERANDS];
827 for (unsigned operandIndex = 0;
828 operandIndex < EDIS_MAX_OPERANDS;
830 operandTypes[operandIndex] = new LiteralConstantEmitter;
831 operandTypeArray->addEntry(operandTypes[operandIndex]);
833 operandFlags[operandIndex] = new FlagsConstantEmitter;
834 operandFlagArray->addEntry(operandFlags[operandIndex]);
837 unsigned numSyntaxes = 0;
839 if (target.getName() == "X86") {
840 X86PopulateOperands(operandTypes, inst);
841 X86ExtractSemantics(*instType, operandFlags, inst);
844 else if (target.getName() == "ARM") {
845 ARMPopulateOperands(operandTypes, inst);
846 ARMExtractSemantics(*instType, operandTypes, operandFlags, inst);
850 CompoundConstantEmitter *operandOrderArray = new CompoundConstantEmitter;
852 infoStruct->addEntry(operandOrderArray);
854 for (unsigned syntaxIndex = 0;
855 syntaxIndex < EDIS_MAX_SYNTAXES;
857 CompoundConstantEmitter *operandOrder =
858 new CompoundConstantEmitter(EDIS_MAX_OPERANDS);
860 operandOrderArray->addEntry(operandOrder);
862 if (syntaxIndex < numSyntaxes) {
863 populateOperandOrder(operandOrder, inst, syntaxIndex);
871 static void emitCommonEnums(raw_ostream &o, unsigned int &i) {
872 EnumEmitter operandTypes("OperandTypes");
873 operandTypes.addEntry("kOperandTypeNone");
874 operandTypes.addEntry("kOperandTypeImmediate");
875 operandTypes.addEntry("kOperandTypeRegister");
876 operandTypes.addEntry("kOperandTypeX86Memory");
877 operandTypes.addEntry("kOperandTypeX86EffectiveAddress");
878 operandTypes.addEntry("kOperandTypeX86PCRelative");
879 operandTypes.addEntry("kOperandTypeARMBranchTarget");
880 operandTypes.addEntry("kOperandTypeARMSoRegReg");
881 operandTypes.addEntry("kOperandTypeARMSoRegImm");
882 operandTypes.addEntry("kOperandTypeARMSoImm");
883 operandTypes.addEntry("kOperandTypeARMRotImm");
884 operandTypes.addEntry("kOperandTypeARMSoImm2Part");
885 operandTypes.addEntry("kOperandTypeARMPredicate");
886 operandTypes.addEntry("kOperandTypeAddrModeImm12");
887 operandTypes.addEntry("kOperandTypeLdStSOReg");
888 operandTypes.addEntry("kOperandTypeARMAddrMode2");
889 operandTypes.addEntry("kOperandTypeARMAddrMode2Offset");
890 operandTypes.addEntry("kOperandTypeARMAddrMode3");
891 operandTypes.addEntry("kOperandTypeARMAddrMode3Offset");
892 operandTypes.addEntry("kOperandTypeARMLdStmMode");
893 operandTypes.addEntry("kOperandTypeARMAddrMode5");
894 operandTypes.addEntry("kOperandTypeARMAddrMode6");
895 operandTypes.addEntry("kOperandTypeARMAddrMode6Offset");
896 operandTypes.addEntry("kOperandTypeARMAddrMode7");
897 operandTypes.addEntry("kOperandTypeARMAddrModePC");
898 operandTypes.addEntry("kOperandTypeARMRegisterList");
899 operandTypes.addEntry("kOperandTypeARMDPRRegisterList");
900 operandTypes.addEntry("kOperandTypeARMSPRRegisterList");
901 operandTypes.addEntry("kOperandTypeARMTBAddrMode");
902 operandTypes.addEntry("kOperandTypeThumbITMask");
903 operandTypes.addEntry("kOperandTypeThumbAddrModeImmS1");
904 operandTypes.addEntry("kOperandTypeThumbAddrModeImmS2");
905 operandTypes.addEntry("kOperandTypeThumbAddrModeImmS4");
906 operandTypes.addEntry("kOperandTypeThumbAddrModeRegS1");
907 operandTypes.addEntry("kOperandTypeThumbAddrModeRegS2");
908 operandTypes.addEntry("kOperandTypeThumbAddrModeRegS4");
909 operandTypes.addEntry("kOperandTypeThumbAddrModeRR");
910 operandTypes.addEntry("kOperandTypeThumbAddrModeSP");
911 operandTypes.addEntry("kOperandTypeThumbAddrModePC");
912 operandTypes.addEntry("kOperandTypeThumb2AddrModeReg");
913 operandTypes.addEntry("kOperandTypeThumb2SoReg");
914 operandTypes.addEntry("kOperandTypeThumb2SoImm");
915 operandTypes.addEntry("kOperandTypeThumb2AddrModeImm8");
916 operandTypes.addEntry("kOperandTypeThumb2AddrModeImm8Offset");
917 operandTypes.addEntry("kOperandTypeThumb2AddrModeImm12");
918 operandTypes.addEntry("kOperandTypeThumb2AddrModeSoReg");
919 operandTypes.addEntry("kOperandTypeThumb2AddrModeImm8s4");
920 operandTypes.addEntry("kOperandTypeThumb2AddrModeImm8s4Offset");
921 operandTypes.emit(o, i);
925 EnumEmitter operandFlags("OperandFlags");
926 operandFlags.addEntry("kOperandFlagSource");
927 operandFlags.addEntry("kOperandFlagTarget");
928 operandFlags.emitAsFlags(o, i);
932 EnumEmitter instructionTypes("InstructionTypes");
933 instructionTypes.addEntry("kInstructionTypeNone");
934 instructionTypes.addEntry("kInstructionTypeMove");
935 instructionTypes.addEntry("kInstructionTypeBranch");
936 instructionTypes.addEntry("kInstructionTypePush");
937 instructionTypes.addEntry("kInstructionTypePop");
938 instructionTypes.addEntry("kInstructionTypeCall");
939 instructionTypes.addEntry("kInstructionTypeReturn");
940 instructionTypes.emit(o, i);
945 void EDEmitter::run(raw_ostream &o) {
948 CompoundConstantEmitter infoArray;
949 CodeGenTarget target(Records);
951 populateInstInfo(infoArray, target);
953 emitCommonEnums(o, i);
955 o << "namespace {\n";
957 o << "llvm::EDInstInfo instInfo" << target.getName().c_str() << "[] = ";
958 infoArray.emit(o, i);