I have a question about MCExpr and its subclasses defined in MCExpr.h. I am trying to get Mips' direct object emission working. Line 283 of MCElfStreamer.cpp reads like this: 00283 case MCExpr::Target: llvm_unreachable("Can't handle target exprs yet!"); Does this mean that if I use a subclass of MCTargetExpr to lower MachineOperands to MCOperands, it won't work? Currently, symbol operands are lowered to MipsMCSymbolRefExpr (a subclass of MCTargetExpr) objects.
That just means the ELF writer doesn't know yet how to deal with the target-specific data. It needs taught how to map them onto relocations and such. Do you really need to subclass MCTargetExpr? That's ordinarily only for operands that aren't representable via the normal MC stuff (for example, the ARM movw/movt relocations). You should be able represent normal symbol operands w/o needing a MCTargetExpr instance. The ARM or x86 targets may me useful reference points. -Jim On Oct 17, 2011, at 5:10 PM, Akira Hatanaka wrote:> I have a question about MCExpr and its subclasses defined in MCExpr.h. > I am trying to get Mips' direct object emission working. > > Line 283 of MCElfStreamer.cpp reads like this: > 00283 case MCExpr::Target: llvm_unreachable("Can't handle target exprs yet!"); > > Does this mean that if I use a subclass of MCTargetExpr to lower > MachineOperands to MCOperands, it won't work? > Currently, symbol operands are lowered to MipsMCSymbolRefExpr (a > subclass of MCTargetExpr) objects. > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
I guess that means I should be calling MCSymbolRefExpr::Create, like ARM does, when I lower symbol operands. Is that right? If MCSymbolRefExpr objects should be created, am I supposed to add code to MCExpr::print (MCExpr.cpp:37) in order to print symbol operands for MIps? I am hesitant to add my code here, since it looks a little disorganized already. Also, wtih MCSymbolRefExpr, how do I print symbols with offsets? lw $7, %lo(f1.s1+4)($16) I tried creating MCBinaryExpr with MCSymbolRefExpr and MCConstantExpr operands, but I am getting something like this, which is not what I want: lw $7, %lo(f1.s1)+4($16) On Mon, Oct 17, 2011 at 5:30 PM, Jim Grosbach <grosbach at apple.com> wrote:> That just means the ELF writer doesn't know yet how to deal with the target-specific data. It needs taught how to map them onto relocations and such. > > Do you really need to subclass MCTargetExpr? That's ordinarily only for operands that aren't representable via the normal MC stuff (for example, the ARM movw/movt relocations). You should be able represent normal symbol operands w/o needing a MCTargetExpr instance. The ARM or x86 targets may me useful reference points. > > -Jim > > > On Oct 17, 2011, at 5:10 PM, Akira Hatanaka wrote: > >> I have a question about MCExpr and its subclasses defined in MCExpr.h. >> I am trying to get Mips' direct object emission working. >> >> Line 283 of MCElfStreamer.cpp reads like this: >> 00283 case MCExpr::Target: llvm_unreachable("Can't handle target exprs yet!"); >> >> Does this mean that if I use a subclass of MCTargetExpr to lower >> MachineOperands to MCOperands, it won't work? >> Currently, symbol operands are lowered to MipsMCSymbolRefExpr (a >> subclass of MCTargetExpr) objects. >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >
HI Akira, Please include the mailing list on replies. Using an MCExpr is the right way to build up things like symbol+offset. ARM has examples for that, as well, which may prove useful. For printing, the target libraries can do that however they want, including using the generic print method for expressions (or not). Often, the generic printing is sufficient, but not always. You can register a custom operand print method on complex operands via the "PrintMethod" attribute. ARM makes heavy use of this for all manner of things. -Jim On Oct 17, 2011, at 6:02 PM, Akira Hatanaka wrote:> I guess that means I should be calling MCSymbolRefExpr::Create, like > ARM does, when I lower symbol operands. Is that right? > > If MCSymbolRefExpr objects should be created, am I supposed to add > code to MCExpr::print (MCExpr.cpp:37) in order to print symbol > operands for MIps? I am hesitant to add my code here, since it looks a > little disorganized already. > > Also, wtih MCSymbolRefExpr, how do I print symbols with offsets? > lw $7, %lo(f1.s1+4)($16) > > I tried creating MCBinaryExpr with MCSymbolRefExpr and MCConstantExpr > operands, but I am getting something like this, which is not what I > want: > lw $7, %lo(f1.s1)+4($16) > > On Mon, Oct 17, 2011 at 5:30 PM, Jim Grosbach <grosbach at apple.com> wrote: >> That just means the ELF writer doesn't know yet how to deal with the target-specific data. It needs taught how to map them onto relocations and such. >> >> Do you really need to subclass MCTargetExpr? That's ordinarily only for operands that aren't representable via the normal MC stuff (for example, the ARM movw/movt relocations). You should be able represent normal symbol operands w/o needing a MCTargetExpr instance. The ARM or x86 targets may me useful reference points. >> >> -Jim >> >> >> On Oct 17, 2011, at 5:10 PM, Akira Hatanaka wrote: >> >>> I have a question about MCExpr and its subclasses defined in MCExpr.h. >>> I am trying to get Mips' direct object emission working. >>> >>> Line 283 of MCElfStreamer.cpp reads like this: >>> 00283 case MCExpr::Target: llvm_unreachable("Can't handle target exprs yet!"); >>> >>> Does this mean that if I use a subclass of MCTargetExpr to lower >>> MachineOperands to MCOperands, it won't work? >>> Currently, symbol operands are lowered to MipsMCSymbolRefExpr (a >>> subclass of MCTargetExpr) objects. >>> _______________________________________________ >>> LLVM Developers mailing list >>> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >> >>
Okay, I think I can check whether an expression is of binary MCExpr type in function printOperand and handle it differently. If that doesn't work, I will consider defining custom printing methods. Thank you for your advice. On Wed, Oct 19, 2011 at 11:46 AM, Jim Grosbach <grosbach at apple.com> wrote:> HI Akira, > > Please include the mailing list on replies. > > Using an MCExpr is the right way to build up things like symbol+offset. ARM has examples for that, as well, which may prove useful. > > For printing, the target libraries can do that however they want, including using the generic print method for expressions (or not). Often, the generic printing is sufficient, but not always. You can register a custom operand print method on complex operands via the "PrintMethod" attribute. ARM makes heavy use of this for all manner of things. > > -Jim > > On Oct 17, 2011, at 6:02 PM, Akira Hatanaka wrote: > >> I guess that means I should be calling MCSymbolRefExpr::Create, like >> ARM does, when I lower symbol operands. Is that right? >> >> If MCSymbolRefExpr objects should be created, am I supposed to add >> code to MCExpr::print (MCExpr.cpp:37) in order to print symbol >> operands for MIps? I am hesitant to add my code here, since it looks a >> little disorganized already. >> >> Also, wtih MCSymbolRefExpr, how do I print symbols with offsets? >> lw $7, %lo(f1.s1+4)($16) >> >> I tried creating MCBinaryExpr with MCSymbolRefExpr and MCConstantExpr >> operands, but I am getting something like this, which is not what I >> want: >> lw $7, %lo(f1.s1)+4($16) >> >> On Mon, Oct 17, 2011 at 5:30 PM, Jim Grosbach <grosbach at apple.com> wrote: >>> That just means the ELF writer doesn't know yet how to deal with the target-specific data. It needs taught how to map them onto relocations and such. >>> >>> Do you really need to subclass MCTargetExpr? That's ordinarily only for operands that aren't representable via the normal MC stuff (for example, the ARM movw/movt relocations). You should be able represent normal symbol operands w/o needing a MCTargetExpr instance. The ARM or x86 targets may me useful reference points. >>> >>> -Jim >>> >>> >>> On Oct 17, 2011, at 5:10 PM, Akira Hatanaka wrote: >>> >>>> I have a question about MCExpr and its subclasses defined in MCExpr.h. >>>> I am trying to get Mips' direct object emission working. >>>> >>>> Line 283 of MCElfStreamer.cpp reads like this: >>>> 00283 case MCExpr::Target: llvm_unreachable("Can't handle target exprs yet!"); >>>> >>>> Does this mean that if I use a subclass of MCTargetExpr to lower >>>> MachineOperands to MCOperands, it won't work? >>>> Currently, symbol operands are lowered to MipsMCSymbolRefExpr (a >>>> subclass of MCTargetExpr) objects. >>>> _______________________________________________ >>>> LLVM Developers mailing list >>>> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >>> >>> > >
Apparently Analagous Threads
- [LLVMdev] Question about MCExpr and subclasses
- [LLVMdev] Question about MCExpr and subclasses
- [LLVMdev] 3.4.1 Release Plans
- [LLVMdev] [llvm-commits] [patch] ARM/MC/ELF add new stub for movt/movw in ARMFixupKinds
- [LLVMdev] How to get ELF section virtual starting address from MCSymbolRefExpr?