llvm.org GIT mirror llvm / 59fc42d
llvm-mc/AsmParser: Allow target to specific a comment delimiter, which will be used to strip hard coded comments out of .td assembly strings. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78716 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Dunbar 10 years ago
3 changed file(s) with 43 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
483483 // used to support targets that need to parser multiple formats for the
484484 // assembly language.
485485 int Variant = 0;
486
487 // CommentDelimiter - If given, the delimiter string used to recognize
488 // comments which are hard coded in the .td assembler strings for individual
489 // instructions.
490 string CommentDelimiter = "";
491
492 // RegisterPrefix - If given, the token prefix which indicates a register
493 // token. This is used by the matcher to automatically recognize hard coded
494 // register tokens as constrained registers, instead of tokens, for the
495 // purposes of matching.
496 string RegisterPrefix = "";
486497 }
487498 def DefaultAsmParser : AsmParser;
488499
181181 def ATTAsmParser : AsmParser {
182182 string AsmParserClassName = "ATTAsmParser";
183183 int Variant = 0;
184
185 // Discard comments in assembly strings.
186 string CommentDelimiter = "#";
187
188 // Recognize hard coded registers.
189 string RegisterPrefix = "%";
184190 }
185191
186192 // The X86 target supports two different syntaxes for emitting machine code.
500500
501501 class AsmMatcherInfo {
502502 public:
503 /// The tablegen AsmParser record.
504 Record *AsmParser;
505
506 /// The AsmParser "CommentDelimiter" value.
507 std::string CommentDelimiter;
508
509 /// The AsmParser "RegisterPrefix" value.
510 std::string RegisterPrefix;
511
503512 /// The classes which are needed for matching.
504513 std::vector Classes;
505514
536545 void BuildOperandClasses(CodeGenTarget &Target);
537546
538547 public:
548 AsmMatcherInfo(Record *_AsmParser);
549
539550 /// BuildInfo - Construct the various tables used during matching.
540551 void BuildInfo(CodeGenTarget &Target);
541552 };
777788 }
778789 }
779790
791 AsmMatcherInfo::AsmMatcherInfo(Record *_AsmParser)
792 : AsmParser(_AsmParser),
793 CommentDelimiter(AsmParser->getValueAsString("CommentDelimiter")),
794 RegisterPrefix(AsmParser->getValueAsString("RegisterPrefix"))
795 {
796 }
797
780798 void AsmMatcherInfo::BuildInfo(CodeGenTarget &Target) {
781799 // Build info for the register classes.
782800 BuildRegisterClasses(Target);
799817 II->InstrName = it->first;
800818 II->Instr = &it->second;
801819 II->AsmString = FlattenVariants(CGI.AsmString, 0);
820
821 // Remove comments from the asm string.
822 if (!CommentDelimiter.empty()) {
823 size_t Idx = StringRef(II->AsmString).find(CommentDelimiter);
824 if (Idx != StringRef::npos)
825 II->AsmString = II->AsmString.substr(0, Idx);
826 }
802827
803828 TokenizeAsmString(II->AsmString, II->Tokens);
804829
13081333 EmitMatchRegisterName(Target, AsmParser, OS);
13091334
13101335 // Compute the information on the instructions to match.
1311 AsmMatcherInfo Info;
1336 AsmMatcherInfo Info(AsmParser);
13121337 Info.BuildInfo(Target);
13131338
13141339 // Sort the instruction table using the partial order on classes.