Question about MCExpr and subclasses

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

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)

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

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.