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"
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"
33 ///////////////////////////////////////////////////////////
34 // Support classes for emitting nested C data structures //
35 ///////////////////////////////////////////////////////////
42 std::vector<std::string> Entries;
44 EnumEmitter(const char *N) : Name(N) {
46 int addEntry(const char *e) {
47 Entries.push_back(std::string(e));
48 return Entries.size() - 1;
50 void emit(raw_ostream &o, unsigned int &i) {
51 o.indent(i) << "enum " << Name.c_str() << " {" << "\n";
54 unsigned int index = 0;
55 unsigned int numEntries = Entries.size();
56 for (index = 0; index < numEntries; ++index) {
57 o.indent(i) << Entries[index];
58 if (index < (numEntries - 1))
64 o.indent(i) << "};" << "\n";
67 void emitAsFlags(raw_ostream &o, unsigned int &i) {
68 o.indent(i) << "enum " << Name.c_str() << " {" << "\n";
71 unsigned int index = 0;
72 unsigned int numEntries = Entries.size();
73 unsigned int flag = 1;
74 for (index = 0; index < numEntries; ++index) {
75 o.indent(i) << Entries[index] << " = " << format("0x%x", flag);
76 if (index < (numEntries - 1))
83 o.indent(i) << "};" << "\n";
90 typedef std::pair<const char*, const char*> member;
91 std::vector< member > Members;
93 StructEmitter(const char *N) : Name(N) {
95 void addMember(const char *t, const char *n) {
99 void emit(raw_ostream &o, unsigned int &i) {
100 o.indent(i) << "struct " << Name.c_str() << " {" << "\n";
103 unsigned int index = 0;
104 unsigned int numMembers = Members.size();
105 for (index = 0; index < numMembers; ++index) {
106 o.indent(i) << Members[index].first << " ";
107 o.indent(i) << Members[index].second << ";" << "\n";
111 o.indent(i) << "};" << "\n";
115 class ConstantEmitter {
117 virtual ~ConstantEmitter() { }
118 virtual void emit(raw_ostream &o, unsigned int &i) = 0;
121 class LiteralConstantEmitter : public ConstantEmitter {
129 LiteralConstantEmitter(const char *string) :
133 LiteralConstantEmitter(int number = 0) :
137 void set(const char *string) {
142 void set(int number) {
147 bool is(const char *string) {
148 return !strcmp(String, string);
150 void emit(raw_ostream &o, unsigned int &i) {
158 class CompoundConstantEmitter : public ConstantEmitter {
160 unsigned int Padding;
161 std::vector<ConstantEmitter *> Entries;
163 CompoundConstantEmitter(unsigned int padding = 0) : Padding(padding) {
165 CompoundConstantEmitter &addEntry(ConstantEmitter *e) {
166 Entries.push_back(e);
170 ~CompoundConstantEmitter() {
171 while (Entries.size()) {
172 ConstantEmitter *entry = Entries.back();
177 void emit(raw_ostream &o, unsigned int &i) {
182 unsigned int numEntries = Entries.size();
184 unsigned int numToPrint;
187 if (numEntries > Padding) {
188 fprintf(stderr, "%u entries but %u padding\n", numEntries, Padding);
189 llvm_unreachable("More entries than padding");
191 numToPrint = Padding;
193 numToPrint = numEntries;
196 for (index = 0; index < numToPrint; ++index) {
198 if (index < numEntries)
199 Entries[index]->emit(o, i);
203 if (index < (numToPrint - 1))
213 class FlagsConstantEmitter : public ConstantEmitter {
215 std::vector<std::string> Flags;
217 FlagsConstantEmitter() {
219 FlagsConstantEmitter &addEntry(const char *f) {
220 Flags.push_back(std::string(f));
223 void emit(raw_ostream &o, unsigned int &i) {
225 unsigned int numFlags = Flags.size();
229 for (index = 0; index < numFlags; ++index) {
230 o << Flags[index].c_str();
231 if (index < (numFlags - 1))
238 EDEmitter::EDEmitter(RecordKeeper &R) : Records(R) {
241 /// populateOperandOrder - Accepts a CodeGenInstruction and generates its
242 /// AsmWriterInst for the desired assembly syntax, giving an ordered list of
243 /// operands in the order they appear in the printed instruction. Then, for
244 /// each entry in that list, determines the index of the same operand in the
245 /// CodeGenInstruction, and emits the resulting mapping into an array, filling
246 /// in unused slots with -1.
248 /// @arg operandOrder - The array that will be populated with the operand
249 /// mapping. Each entry will contain -1 (invalid index
250 /// into the operands present in the AsmString) or a number
251 /// representing an index in the operand descriptor array.
252 /// @arg inst - The instruction to use when looking up the operands
253 /// @arg syntax - The syntax to use, according to LLVM's enumeration
254 void populateOperandOrder(CompoundConstantEmitter *operandOrder,
255 const CodeGenInstruction &inst,
257 unsigned int numArgs = 0;
259 AsmWriterInst awInst(inst, syntax, -1, -1);
261 std::vector<AsmWriterOperand>::iterator operandIterator;
263 for (operandIterator = awInst.Operands.begin();
264 operandIterator != awInst.Operands.end();
266 if (operandIterator->OperandType ==
267 AsmWriterOperand::isMachineInstrOperand) {
268 operandOrder->addEntry(
269 new LiteralConstantEmitter(operandIterator->CGIOpNo));
275 /////////////////////////////////////////////////////
276 // Support functions for handling X86 instructions //
277 /////////////////////////////////////////////////////
279 #define SET(flag) { type->set(flag); return 0; }
281 #define REG(str) if (name == str) SET("kOperandTypeRegister");
282 #define MEM(str) if (name == str) SET("kOperandTypeX86Memory");
283 #define LEA(str) if (name == str) SET("kOperandTypeX86EffectiveAddress");
284 #define IMM(str) if (name == str) SET("kOperandTypeImmediate");
285 #define PCR(str) if (name == str) SET("kOperandTypeX86PCRelative");
287 /// X86TypeFromOpName - Processes the name of a single X86 operand (which is
288 /// actually its type) and translates it into an operand type
290 /// @arg flags - The type object to set
291 /// @arg name - The name of the operand
292 static int X86TypeFromOpName(LiteralConstantEmitter *type,
293 const std::string &name) {
351 PCR("i64i32imm_pcrel");
370 /// X86PopulateOperands - Handles all the operands in an X86 instruction, adding
371 /// the appropriate flags to their descriptors
373 /// @operandFlags - A reference the array of operand flag objects
374 /// @inst - The instruction to use as a source of information
375 static void X86PopulateOperands(
376 LiteralConstantEmitter *(&operandTypes)[EDIS_MAX_OPERANDS],
377 const CodeGenInstruction &inst) {
378 if (!inst.TheDef->isSubClassOf("X86Inst"))
382 unsigned int numOperands = inst.OperandList.size();
384 for (index = 0; index < numOperands; ++index) {
385 const CodeGenInstruction::OperandInfo &operandInfo =
386 inst.OperandList[index];
387 Record &rec = *operandInfo.Rec;
389 if (X86TypeFromOpName(operandTypes[index], rec.getName())) {
390 errs() << "Operand type: " << rec.getName().c_str() << "\n";
391 errs() << "Operand name: " << operandInfo.Name.c_str() << "\n";
392 errs() << "Instruction mame: " << inst.TheDef->getName().c_str() << "\n";
393 llvm_unreachable("Unhandled type");
398 /// decorate1 - Decorates a named operand with a new flag
400 /// @operandFlags - The array of operand flag objects, which don't have names
401 /// @inst - The CodeGenInstruction, which provides a way to translate
402 /// between names and operand indices
403 /// @opName - The name of the operand
404 /// @flag - The name of the flag to add
405 static inline void decorate1(
406 FlagsConstantEmitter *(&operandFlags)[EDIS_MAX_OPERANDS],
407 const CodeGenInstruction &inst,
409 const char *opFlag) {
412 opIndex = inst.getOperandNamed(std::string(opName));
414 operandFlags[opIndex]->addEntry(opFlag);
417 #define DECORATE1(opName, opFlag) decorate1(operandFlags, inst, opName, opFlag)
419 #define MOV(source, target) { \
420 instType.set("kInstructionTypeMove"); \
421 DECORATE1(source, "kOperandFlagSource"); \
422 DECORATE1(target, "kOperandFlagTarget"); \
425 #define BRANCH(target) { \
426 instType.set("kInstructionTypeBranch"); \
427 DECORATE1(target, "kOperandFlagTarget"); \
430 #define PUSH(source) { \
431 instType.set("kInstructionTypePush"); \
432 DECORATE1(source, "kOperandFlagSource"); \
435 #define POP(target) { \
436 instType.set("kInstructionTypePop"); \
437 DECORATE1(target, "kOperandFlagTarget"); \
440 #define CALL(target) { \
441 instType.set("kInstructionTypeCall"); \
442 DECORATE1(target, "kOperandFlagTarget"); \
446 instType.set("kInstructionTypeReturn"); \
449 /// X86ExtractSemantics - Performs various checks on the name of an X86
450 /// instruction to determine what sort of an instruction it is and then adds
451 /// the appropriate flags to the instruction and its operands
453 /// @arg instType - A reference to the type for the instruction as a whole
454 /// @arg operandFlags - A reference to the array of operand flag object pointers
455 /// @arg inst - A reference to the original instruction
456 static void X86ExtractSemantics(
457 LiteralConstantEmitter &instType,
458 FlagsConstantEmitter *(&operandFlags)[EDIS_MAX_OPERANDS],
459 const CodeGenInstruction &inst) {
460 const std::string &name = inst.TheDef->getName();
462 if (name.find("MOV") != name.npos) {
463 if (name.find("MOV_V") != name.npos) {
464 // ignore (this is a pseudoinstruction)
465 } else if (name.find("MASK") != name.npos) {
466 // ignore (this is a masking move)
467 } else if (name.find("r0") != name.npos) {
468 // ignore (this is a pseudoinstruction)
469 } else if (name.find("PS") != name.npos ||
470 name.find("PD") != name.npos) {
471 // ignore (this is a shuffling move)
472 } else if (name.find("MOVS") != name.npos) {
473 // ignore (this is a string move)
474 } else if (name.find("_F") != name.npos) {
475 // TODO handle _F moves to ST(0)
476 } else if (name.find("a") != name.npos) {
477 // TODO handle moves to/from %ax
478 } else if (name.find("CMOV") != name.npos) {
480 } else if (name.find("PC") != name.npos) {
487 if (name.find("JMP") != name.npos ||
488 name.find("J") == 0) {
489 if (name.find("FAR") != name.npos && name.find("i") != name.npos) {
496 if (name.find("PUSH") != name.npos) {
497 if (name.find("FS") != name.npos ||
498 name.find("GS") != name.npos) {
499 instType.set("kInstructionTypePush");
500 // TODO add support for fixed operands
501 } else if (name.find("F") != name.npos) {
502 // ignore (this pushes onto the FP stack)
503 } else if (name[name.length() - 1] == 'm') {
505 } else if (name.find("i") != name.npos) {
512 if (name.find("POP") != name.npos) {
513 if (name.find("POPCNT") != name.npos) {
514 // ignore (not a real pop)
515 } else if (name.find("FS") != name.npos ||
516 name.find("GS") != name.npos) {
517 instType.set("kInstructionTypePop");
518 // TODO add support for fixed operands
519 } else if (name.find("F") != name.npos) {
520 // ignore (this pops from the FP stack)
521 } else if (name[name.length() - 1] == 'm') {
528 if (name.find("CALL") != name.npos) {
529 if (name.find("ADJ") != name.npos) {
530 // ignore (not a call)
531 } else if (name.find("SYSCALL") != name.npos) {
532 // ignore (doesn't go anywhere we know about)
533 } else if (name.find("VMCALL") != name.npos) {
534 // ignore (rather different semantics than a regular call)
535 } else if (name.find("FAR") != name.npos && name.find("i") != name.npos) {
542 if (name.find("RET") != name.npos) {
554 /////////////////////////////////////////////////////
555 // Support functions for handling ARM instructions //
556 /////////////////////////////////////////////////////
558 #define SET(flag) { type->set(flag); return 0; }
560 #define REG(str) if (name == str) SET("kOperandTypeRegister");
561 #define IMM(str) if (name == str) SET("kOperandTypeImmediate");
563 #define MISC(str, type) if (name == str) SET(type);
565 /// ARMFlagFromOpName - Processes the name of a single ARM operand (which is
566 /// actually its type) and translates it into an operand type
568 /// @arg type - The type object to set
569 /// @arg name - The name of the operand
570 static int ARMFlagFromOpName(LiteralConstantEmitter *type,
571 const std::string &name) {
586 IMM("bf_inv_mask_imm");
587 IMM("jtblock_operand");
589 IMM("cpinst_operand");
598 IMM("jt2block_operand");
602 MISC("brtarget", "kOperandTypeARMBranchTarget"); // ?
603 MISC("so_reg", "kOperandTypeARMSoReg"); // R, R, I
604 MISC("t2_so_reg", "kOperandTypeThumb2SoReg"); // R, I
605 MISC("so_imm", "kOperandTypeARMSoImm"); // I
606 MISC("t2_so_imm", "kOperandTypeThumb2SoImm"); // I
607 MISC("so_imm2part", "kOperandTypeARMSoImm2Part"); // I
608 MISC("pred", "kOperandTypeARMPredicate"); // I, R
609 MISC("it_pred", "kOperandTypeARMPredicate"); // I
610 MISC("addrmode2", "kOperandTypeARMAddrMode2"); // R, R, I
611 MISC("am2offset", "kOperandTypeARMAddrMode2Offset"); // R, I
612 MISC("addrmode3", "kOperandTypeARMAddrMode3"); // R, R, I
613 MISC("am3offset", "kOperandTypeARMAddrMode3Offset"); // R, I
614 MISC("addrmode4", "kOperandTypeARMAddrMode4"); // R, I
615 MISC("addrmode5", "kOperandTypeARMAddrMode5"); // R, I
616 MISC("addrmode6", "kOperandTypeARMAddrMode6"); // R, R, I, I
617 MISC("am6offset", "kOperandTypeARMAddrMode6Offset"); // R, I, I
618 MISC("addrmodepc", "kOperandTypeARMAddrModePC"); // R, I
619 MISC("reglist", "kOperandTypeARMRegisterList"); // I, R, ...
620 MISC("it_mask", "kOperandTypeThumbITMask"); // I
621 MISC("t2addrmode_imm8", "kOperandTypeThumb2AddrModeImm8"); // R, I
622 MISC("t2am_imm8_offset", "kOperandTypeThumb2AddrModeImm8Offset");//I
623 MISC("t2addrmode_imm12", "kOperandTypeThumb2AddrModeImm12"); // R, I
624 MISC("t2addrmode_so_reg", "kOperandTypeThumb2AddrModeSoReg"); // R, R, I
625 MISC("t2addrmode_imm8s4", "kOperandTypeThumb2AddrModeImm8s4"); // R, I
626 MISC("t2am_imm8s4_offset", "kOperandTypeThumb2AddrModeImm8s4Offset");
628 MISC("tb_addrmode", "kOperandTypeARMTBAddrMode"); // I
629 MISC("t_addrmode_s1", "kOperandTypeThumbAddrModeS1"); // R, I, R
630 MISC("t_addrmode_s2", "kOperandTypeThumbAddrModeS2"); // R, I, R
631 MISC("t_addrmode_s4", "kOperandTypeThumbAddrModeS4"); // R, I, R
632 MISC("t_addrmode_rr", "kOperandTypeThumbAddrModeRR"); // R, R
633 MISC("t_addrmode_sp", "kOperandTypeThumbAddrModeSP"); // R, I
649 /// ARMPopulateOperands - Handles all the operands in an ARM instruction, adding
650 /// the appropriate flags to their descriptors
652 /// @operandFlags - A reference the array of operand flag objects
653 /// @inst - The instruction to use as a source of information
654 static void ARMPopulateOperands(
655 LiteralConstantEmitter *(&operandTypes)[EDIS_MAX_OPERANDS],
656 const CodeGenInstruction &inst) {
657 if (!inst.TheDef->isSubClassOf("InstARM") &&
658 !inst.TheDef->isSubClassOf("InstThumb"))
662 unsigned int numOperands = inst.OperandList.size();
664 if (numOperands > EDIS_MAX_OPERANDS) {
665 errs() << "numOperands == " << numOperands << " > " <<
666 EDIS_MAX_OPERANDS << '\n';
667 llvm_unreachable("Too many operands");
670 for (index = 0; index < numOperands; ++index) {
671 const CodeGenInstruction::OperandInfo &operandInfo =
672 inst.OperandList[index];
673 Record &rec = *operandInfo.Rec;
675 if (ARMFlagFromOpName(operandTypes[index], rec.getName())) {
676 errs() << "Operand type: " << rec.getName() << '\n';
677 errs() << "Operand name: " << operandInfo.Name << '\n';
678 errs() << "Instruction mame: " << inst.TheDef->getName() << '\n';
679 llvm_unreachable("Unhandled type");
684 #define BRANCH(target) { \
685 instType.set("kInstructionTypeBranch"); \
686 DECORATE1(target, "kOperandFlagTarget"); \
689 /// ARMExtractSemantics - Performs various checks on the name of an ARM
690 /// instruction to determine what sort of an instruction it is and then adds
691 /// the appropriate flags to the instruction and its operands
693 /// @arg instType - A reference to the type for the instruction as a whole
694 /// @arg operandTypes - A reference to the array of operand type object pointers
695 /// @arg operandFlags - A reference to the array of operand flag object pointers
696 /// @arg inst - A reference to the original instruction
697 static void ARMExtractSemantics(
698 LiteralConstantEmitter &instType,
699 LiteralConstantEmitter *(&operandTypes)[EDIS_MAX_OPERANDS],
700 FlagsConstantEmitter *(&operandFlags)[EDIS_MAX_OPERANDS],
701 const CodeGenInstruction &inst) {
702 const std::string &name = inst.TheDef->getName();
704 if (name == "tBcc" ||
713 if (name == "tBLr9" ||
714 name == "BLr9_pred" ||
715 name == "tBLXi_r9" ||
716 name == "tBLXr_r9" ||
723 opIndex = inst.getOperandNamed("func");
724 if (operandTypes[opIndex]->is("kOperandTypeImmediate"))
725 operandTypes[opIndex]->set("kOperandTypeARMBranchTarget");
731 /// populateInstInfo - Fills an array of InstInfos with information about each
732 /// instruction in a target
734 /// @arg infoArray - The array of InstInfo objects to populate
735 /// @arg target - The CodeGenTarget to use as a source of instructions
736 static void populateInstInfo(CompoundConstantEmitter &infoArray,
737 CodeGenTarget &target) {
738 const std::vector<const CodeGenInstruction*> &numberedInstructions =
739 target.getInstructionsByEnumValue();
742 unsigned int numInstructions = numberedInstructions.size();
744 for (index = 0; index < numInstructions; ++index) {
745 const CodeGenInstruction& inst = *numberedInstructions[index];
747 CompoundConstantEmitter *infoStruct = new CompoundConstantEmitter;
748 infoArray.addEntry(infoStruct);
750 LiteralConstantEmitter *instType = new LiteralConstantEmitter;
751 infoStruct->addEntry(instType);
753 LiteralConstantEmitter *numOperandsEmitter =
754 new LiteralConstantEmitter(inst.OperandList.size());
755 infoStruct->addEntry(numOperandsEmitter);
757 CompoundConstantEmitter *operandTypeArray = new CompoundConstantEmitter;
758 infoStruct->addEntry(operandTypeArray);
760 LiteralConstantEmitter *operandTypes[EDIS_MAX_OPERANDS];
762 CompoundConstantEmitter *operandFlagArray = new CompoundConstantEmitter;
763 infoStruct->addEntry(operandFlagArray);
765 FlagsConstantEmitter *operandFlags[EDIS_MAX_OPERANDS];
767 for (unsigned operandIndex = 0;
768 operandIndex < EDIS_MAX_OPERANDS;
770 operandTypes[operandIndex] = new LiteralConstantEmitter;
771 operandTypeArray->addEntry(operandTypes[operandIndex]);
773 operandFlags[operandIndex] = new FlagsConstantEmitter;
774 operandFlagArray->addEntry(operandFlags[operandIndex]);
777 unsigned numSyntaxes = 0;
779 if (target.getName() == "X86") {
780 X86PopulateOperands(operandTypes, inst);
781 X86ExtractSemantics(*instType, operandFlags, inst);
784 else if (target.getName() == "ARM") {
785 ARMPopulateOperands(operandTypes, inst);
786 ARMExtractSemantics(*instType, operandTypes, operandFlags, inst);
790 CompoundConstantEmitter *operandOrderArray = new CompoundConstantEmitter;
792 infoStruct->addEntry(operandOrderArray);
794 for (unsigned syntaxIndex = 0;
795 syntaxIndex < EDIS_MAX_SYNTAXES;
797 CompoundConstantEmitter *operandOrder =
798 new CompoundConstantEmitter(EDIS_MAX_OPERANDS);
800 operandOrderArray->addEntry(operandOrder);
802 if (syntaxIndex < numSyntaxes) {
803 populateOperandOrder(operandOrder, inst, syntaxIndex);
811 static void emitCommonEnums(raw_ostream &o, unsigned int &i) {
812 EnumEmitter operandTypes("OperandTypes");
813 operandTypes.addEntry("kOperandTypeNone");
814 operandTypes.addEntry("kOperandTypeImmediate");
815 operandTypes.addEntry("kOperandTypeRegister");
816 operandTypes.addEntry("kOperandTypeX86Memory");
817 operandTypes.addEntry("kOperandTypeX86EffectiveAddress");
818 operandTypes.addEntry("kOperandTypeX86PCRelative");
819 operandTypes.addEntry("kOperandTypeARMBranchTarget");
820 operandTypes.addEntry("kOperandTypeARMSoReg");
821 operandTypes.addEntry("kOperandTypeARMSoImm");
822 operandTypes.addEntry("kOperandTypeARMSoImm2Part");
823 operandTypes.addEntry("kOperandTypeARMPredicate");
824 operandTypes.addEntry("kOperandTypeARMAddrMode2");
825 operandTypes.addEntry("kOperandTypeARMAddrMode2Offset");
826 operandTypes.addEntry("kOperandTypeARMAddrMode3");
827 operandTypes.addEntry("kOperandTypeARMAddrMode3Offset");
828 operandTypes.addEntry("kOperandTypeARMAddrMode4");
829 operandTypes.addEntry("kOperandTypeARMAddrMode5");
830 operandTypes.addEntry("kOperandTypeARMAddrMode6");
831 operandTypes.addEntry("kOperandTypeARMAddrMode6Offset");
832 operandTypes.addEntry("kOperandTypeARMAddrModePC");
833 operandTypes.addEntry("kOperandTypeARMRegisterList");
834 operandTypes.addEntry("kOperandTypeARMTBAddrMode");
835 operandTypes.addEntry("kOperandTypeThumbITMask");
836 operandTypes.addEntry("kOperandTypeThumbAddrModeS1");
837 operandTypes.addEntry("kOperandTypeThumbAddrModeS2");
838 operandTypes.addEntry("kOperandTypeThumbAddrModeS4");
839 operandTypes.addEntry("kOperandTypeThumbAddrModeRR");
840 operandTypes.addEntry("kOperandTypeThumbAddrModeSP");
841 operandTypes.addEntry("kOperandTypeThumb2SoReg");
842 operandTypes.addEntry("kOperandTypeThumb2SoImm");
843 operandTypes.addEntry("kOperandTypeThumb2AddrModeImm8");
844 operandTypes.addEntry("kOperandTypeThumb2AddrModeImm8Offset");
845 operandTypes.addEntry("kOperandTypeThumb2AddrModeImm12");
846 operandTypes.addEntry("kOperandTypeThumb2AddrModeSoReg");
847 operandTypes.addEntry("kOperandTypeThumb2AddrModeImm8s4");
848 operandTypes.addEntry("kOperandTypeThumb2AddrModeImm8s4Offset");
849 operandTypes.emit(o, i);
853 EnumEmitter operandFlags("OperandFlags");
854 operandFlags.addEntry("kOperandFlagSource");
855 operandFlags.addEntry("kOperandFlagTarget");
856 operandFlags.emitAsFlags(o, i);
860 EnumEmitter instructionTypes("InstructionTypes");
861 instructionTypes.addEntry("kInstructionTypeNone");
862 instructionTypes.addEntry("kInstructionTypeMove");
863 instructionTypes.addEntry("kInstructionTypeBranch");
864 instructionTypes.addEntry("kInstructionTypePush");
865 instructionTypes.addEntry("kInstructionTypePop");
866 instructionTypes.addEntry("kInstructionTypeCall");
867 instructionTypes.addEntry("kInstructionTypeReturn");
868 instructionTypes.emit(o, i);
873 void EDEmitter::run(raw_ostream &o) {
876 CompoundConstantEmitter infoArray;
877 CodeGenTarget target;
879 populateInstInfo(infoArray, target);
881 emitCommonEnums(o, i);
883 o << "namespace {\n";
885 o << "llvm::EDInstInfo instInfo" << target.getName().c_str() << "[] = ";
886 infoArray.emit(o, i);
892 void EDEmitter::runHeader(raw_ostream &o) {
893 EmitSourceFileHeader("Enhanced Disassembly Info Header", o);
895 o << "#ifndef EDInfo_" << "\n";
896 o << "#define EDInfo_" << "\n";
898 o << "#define EDIS_MAX_OPERANDS " << format("%d", EDIS_MAX_OPERANDS) << "\n";
899 o << "#define EDIS_MAX_SYNTAXES " << format("%d", EDIS_MAX_SYNTAXES) << "\n";
904 emitCommonEnums(o, i);
907 o << "#endif" << "\n";