[LLVMdev] Question about MCExpr and subclasses
grosbach at apple.com
Wed Oct 19 11:46:46 PDT 2011
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.
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
> 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.
>> 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
More information about the llvm-dev