Home | History | Annotate | Download | only in TableGen
      1 //===------------ FixedLenDecoderEmitter.h - Decoder Generator --*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // It contains the tablegen backend that emits the decoder functions for
     11 // targets with fixed length instruction set.
     12 //
     13 //===----------------------------------------------------------------------===//
     14 
     15 #ifndef FixedLenDECODEREMITTER_H
     16 #define FixedLenDECODEREMITTER_H
     17 
     18 #include "CodeGenTarget.h"
     19 
     20 #include "llvm/TableGen/TableGenBackend.h"
     21 #include "llvm/Support/DataTypes.h"
     22 
     23 namespace llvm {
     24 
     25 struct EncodingField {
     26   unsigned Base, Width, Offset;
     27   EncodingField(unsigned B, unsigned W, unsigned O)
     28     : Base(B), Width(W), Offset(O) { }
     29 };
     30 
     31 struct OperandInfo {
     32   std::vector<EncodingField> Fields;
     33   std::string Decoder;
     34 
     35   OperandInfo(std::string D)
     36     : Decoder(D) { }
     37 
     38   void addField(unsigned Base, unsigned Width, unsigned Offset) {
     39     Fields.push_back(EncodingField(Base, Width, Offset));
     40   }
     41 
     42   unsigned numFields() const { return Fields.size(); }
     43 
     44   typedef std::vector<EncodingField>::const_iterator const_iterator;
     45 
     46   const_iterator begin() const { return Fields.begin(); }
     47   const_iterator end() const   { return Fields.end();   }
     48 };
     49 
     50 class FixedLenDecoderEmitter : public TableGenBackend {
     51 public:
     52   FixedLenDecoderEmitter(RecordKeeper &R,
     53                          std::string PredicateNamespace,
     54                          std::string GPrefix  = "if (",
     55                          std::string GPostfix = " == MCDisassembler::Fail)"
     56                          " return MCDisassembler::Fail;",
     57                          std::string ROK      = "MCDisassembler::Success",
     58                          std::string RFail    = "MCDisassembler::Fail",
     59                          std::string L        = "") :
     60     Target(R),
     61     PredicateNamespace(PredicateNamespace),
     62     GuardPrefix(GPrefix), GuardPostfix(GPostfix),
     63     ReturnOK(ROK), ReturnFail(RFail), Locals(L) {}
     64 
     65   // run - Output the code emitter
     66   void run(raw_ostream &o);
     67 
     68 private:
     69   CodeGenTarget Target;
     70 public:
     71   std::string PredicateNamespace;
     72   std::string GuardPrefix, GuardPostfix;
     73   std::string ReturnOK, ReturnFail;
     74   std::string Locals;
     75 };
     76 
     77 } // end llvm namespace
     78 
     79 #endif
     80