llvm.org GIT mirror llvm / 5c468e3
llvm-mc/AsmParser: Allow .td users to redefine the names of the methods to call on target specific operands for testing class membership and converting to MCInst operands. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78597 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Dunbar 10 years ago
3 changed file(s) with 40 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
289289 /// match a subset of some other class, in which case the super class field
290290 /// should be defined.
291291 class AsmOperandClass {
292 /// The name to use for this class, this should be usable as an enum value,
293 /// and will be used to generated the names for the methods to test whether a
294 /// particular target specific operand matches this class, and the method to
295 /// convert an operand of this class into an MCInst operand.
292 /// The name to use for this class, which should be usable as an enum value.
296293 string Name = ?;
297294
298295 /// The super class of this operand.
299296 AsmOperandClass SuperClass = ?;
297
298 /// The name of the method on the target specific operand to call to test
299 /// whether the operand is an instance of this class. If not set, this will
300 /// default to "isFoo", where Foo is the AsmOperandClass name. The method
301 /// signature should be:
302 /// bool isFoo() const;
303 string PredicateMethod = ?;
304
305 /// The name of the method on the target specific operand to call to add the
306 /// target specific operand to an MCInst. If not set, this will default to
307 /// "addFooOperands", where Foo is the AsmOperandClass name. The method
308 /// signature should be:
309 /// void addFooOperands(MCInst &Inst, unsigned N) const;
310 string RenderMethod = ?;
300311 }
301312
302313 def ImmAsmOperand : AsmOperandClass {
153153
154154 bool isReg() const { return Kind == Register; }
155155
156 void addRegOperands(MCInst &Inst, unsigned N) {
156 void addRegOperands(MCInst &Inst, unsigned N) const {
157157 assert(N == 1 && "Invalid number of operands!");
158158 Inst.addOperand(MCOperand::CreateReg(getReg()));
159159 }
160160
161 void addImmOperands(MCInst &Inst, unsigned N) {
161 void addImmOperands(MCInst &Inst, unsigned N) const {
162162 assert(N == 1 && "Invalid number of operands!");
163163 Inst.addOperand(MCOperand::CreateMCValue(getImm()));
164164 }
165165
166 void addImmSExt8Operands(MCInst &Inst, unsigned N) {
166 void addImmSExt8Operands(MCInst &Inst, unsigned N) const {
167167 // FIXME: Support user customization of the render method.
168168 assert(N == 1 && "Invalid number of operands!");
169169 Inst.addOperand(MCOperand::CreateMCValue(getImm()));
170170 }
171171
172 void addMemOperands(MCInst &Inst, unsigned N) {
172 void addMemOperands(MCInst &Inst, unsigned N) const {
173173 assert((N == 4 || N == 5) && "Invalid number of operands!");
174174
175175 Inst.addOperand(MCOperand::CreateReg(getMemBaseReg()));
588588 CI->ClassName = (*it)->getValueAsString("Name");
589589 CI->Name = "MCK_" + CI->ClassName;
590590 CI->ValueName = (*it)->getName();
591 CI->PredicateMethod = "is" + CI->ClassName;
592 CI->RenderMethod = "add" + CI->ClassName + "Operands";
591
592 // Get or construct the predicate method name.
593 Init *PMName = (*it)->getValueInit("PredicateMethod");
594 if (StringInit *SI = dynamic_cast(PMName)) {
595 CI->PredicateMethod = SI->getValue();
596 } else {
597 assert(dynamic_cast(PMName) &&
598 "Unexpected PredicateMethod field!");
599 CI->PredicateMethod = "is" + CI->ClassName;
600 }
601
602 // Get or construct the render method name.
603 Init *RMName = (*it)->getValueInit("RenderMethod");
604 if (StringInit *SI = dynamic_cast(RMName)) {
605 CI->RenderMethod = SI->getValue();
606 } else {
607 assert(dynamic_cast(RMName) &&
608 "Unexpected RenderMethod field!");
609 CI->RenderMethod = "add" + CI->ClassName + "Operands";
610 }
611
593612 AsmOperandClasses[*it] = CI;
594613 Classes.push_back(CI);
595614 }