llvm.org GIT mirror llvm / 254ce94
TableGen: Refactor AsmWriterEmitter to keep AsmWriterInsts. These used to be referenced by the CGI->AWI map (in AsmWriterEmitter), but stored in a vector local to EmitPrintInstruction. Move the vector to AsmWriterEmitter too. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193525 91177308-0d34-0410-b5e6-96231b3b80d8 Ahmed Bougacha 7 years ago
1 changed file(s) with 26 addition(s) and 26 deletion(s). Raw diff Collapse all Expand all
3131 namespace {
3232 class AsmWriterEmitter {
3333 RecordKeeper &Records;
34 CodeGenTarget Target;
3435 std::map CGIAWIMap;
3536 std::vector NumberedInstructions;
37 std::vector Instructions;
3638 public:
37 AsmWriterEmitter(RecordKeeper &R) : Records(R) {}
39 AsmWriterEmitter(RecordKeeper &R);
3840
3941 void run(raw_ostream &o);
4042
272274 }
273275
274276 /// EmitPrintInstruction - Generate the code for the "printInstruction" method
275 /// implementation.
277 /// implementation. Destroys all instances of AsmWriterInst information, by
278 /// clearing the Instructions vector.
276279 void AsmWriterEmitter::EmitPrintInstruction(raw_ostream &O) {
277 CodeGenTarget Target(Records);
278280 Record *AsmWriter = Target.getAsmWriter();
279281 std::string ClassName = AsmWriter->getValueAsString("AsmWriterClassName");
280282 bool isMC = AsmWriter->getValueAsBit("isMCAsmWriter");
286288 "void " << Target.getName() << ClassName
287289 << "::printInstruction(const " << MachineInstrClassName
288290 << " *MI, raw_ostream &O) {\n";
289
290 std::vector Instructions;
291
292 for (CodeGenTarget::inst_iterator I = Target.inst_begin(),
293 E = Target.inst_end(); I != E; ++I)
294 if (!(*I)->AsmString.empty() &&
295 (*I)->TheDef->getName() != "PHI")
296 Instructions.push_back(
297 AsmWriterInst(**I,
298 AsmWriter->getValueAsInt("Variant"),
299 AsmWriter->getValueAsInt("FirstOperandColumn"),
300 AsmWriter->getValueAsInt("OperandSpacing")));
301
302 // Get the instruction numbering.
303 NumberedInstructions = Target.getInstructionsByEnumValue();
304
305 // Compute the CodeGenInstruction -> AsmWriterInst mapping. Note that not
306 // all machine instructions are necessarily being printed, so there may be
307 // target instructions not in this map.
308 for (unsigned i = 0, e = Instructions.size(); i != e; ++i)
309 CGIAWIMap.insert(std::make_pair(Instructions[i].CGI, &Instructions[i]));
310291
311292 // Build an aggregate string, and build a table of offsets into it.
312293 SequenceToOffsetTable StringTable;
591572 }
592573
593574 void AsmWriterEmitter::EmitGetRegisterName(raw_ostream &O) {
594 CodeGenTarget Target(Records);
595575 Record *AsmWriter = Target.getAsmWriter();
596576 std::string ClassName = AsmWriter->getValueAsString("AsmWriterClassName");
597577 const std::vector &Registers =
781761 }
782762
783763 void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) {
784 CodeGenTarget Target(Records);
785764 Record *AsmWriter = Target.getAsmWriter();
786765
787766 if (!AsmWriter->getValueAsBit("isMCAsmWriter"))
999978 O << "#endif // PRINT_ALIAS_INSTR\n";
1000979 }
1001980
981 AsmWriterEmitter::AsmWriterEmitter(RecordKeeper &R) : Records(R), Target(R) {
982 Record *AsmWriter = Target.getAsmWriter();
983 for (CodeGenTarget::inst_iterator I = Target.inst_begin(),
984 E = Target.inst_end();
985 I != E; ++I)
986 if (!(*I)->AsmString.empty() && (*I)->TheDef->getName() != "PHI")
987 Instructions.push_back(
988 AsmWriterInst(**I, AsmWriter->getValueAsInt("Variant"),
989 AsmWriter->getValueAsInt("FirstOperandColumn"),
990 AsmWriter->getValueAsInt("OperandSpacing")));
991
992 // Get the instruction numbering.
993 NumberedInstructions = Target.getInstructionsByEnumValue();
994
995 // Compute the CodeGenInstruction -> AsmWriterInst mapping. Note that not
996 // all machine instructions are necessarily being printed, so there may be
997 // target instructions not in this map.
998 for (unsigned i = 0, e = Instructions.size(); i != e; ++i)
999 CGIAWIMap.insert(std::make_pair(Instructions[i].CGI, &Instructions[i]));
1000 }
1001
10021002 void AsmWriterEmitter::run(raw_ostream &O) {
10031003 EmitPrintInstruction(O);
10041004 EmitGetRegisterName(O);