[LLVMdev] Emitting assembler code

Vladimir Prus ghost at cs.msu.su
Mon Jun 7 08:41:01 PDT 2004


Hello,
I'm trying to write assembler code writer, and of course, have new questions.
I'd like the structure my implementation like this:

   if (/*binary instruction*/) {
	// print destination
	O << " = ";
	// print first operand
	O << opcode;
	// print second operand.
   }
   if (/* unary instruction */ ) {
        ....
   }
   if (/*control instruction*/) {
	....
   }

The question is how to write those checks for binary/unary/control/etc 
instructions. Ideally, I'd like to write this in .td file:

   class Binary : ....


    def add : Binary<....>;
    def sub : Binary<....>;

It seems that X86 does something like this. The .td. file define:

   def Pseudo     : Format<0>; def RawFrm     : Format<1>;

and there are parallel definitions in X86InstrInfo.h:

    Pseudo         = 0,
    RawFrm         = 1,

Those definitions are used in codegen, and and TableGen somehow passes the 
instruction format information to X86GenInstInfo.inc -- specifically, it 
encodes it in the TSFlags field of the TargetInstrDescriptor class.

So the question is: how the information about format should be specified 
in .td files? I've tried this:

  class Format<bits<5> val> {
     bits<5> Value = val;
  }

 def F1 : Format<4>;

  class NMI<string nam> : Instruction {
     let Namespace = "NM";

     let Name = nam;

     Format Form = F1;
    bits<5> FormBits = 4;
 }

But the values of the TSFlags field for did not change.

TIA,
Volodya







More information about the llvm-dev mailing list