Owen Anderson | d8c8788 | 2011-02-18 21:51:29 +0000 | [diff] [blame] | 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" |
Owen Anderson | d8c8788 | 2011-02-18 21:51:29 +0000 | [diff] [blame] | 19 | |
Peter Collingbourne | 7c78888 | 2011-10-01 16:41:13 +0000 | [diff] [blame] | 20 | #include "llvm/TableGen/TableGenBackend.h" |
Owen Anderson | d8c8788 | 2011-02-18 21:51:29 +0000 | [diff] [blame] | 21 | #include "llvm/Support/DataTypes.h" |
| 22 | |
| 23 | namespace llvm { |
| 24 | |
Owen Anderson | d1e38df | 2011-07-28 21:54:31 +0000 | [diff] [blame] | 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 | |
Owen Anderson | d8c8788 | 2011-02-18 21:51:29 +0000 | [diff] [blame] | 31 | struct OperandInfo { |
Owen Anderson | d1e38df | 2011-07-28 21:54:31 +0000 | [diff] [blame] | 32 | std::vector<EncodingField> Fields; |
Owen Anderson | d8c8788 | 2011-02-18 21:51:29 +0000 | [diff] [blame] | 33 | std::string Decoder; |
| 34 | |
Owen Anderson | d1e38df | 2011-07-28 21:54:31 +0000 | [diff] [blame] | 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() { return Fields.size(); } |
| 43 | |
| 44 | typedef std::vector<EncodingField>::iterator iterator; |
| 45 | |
| 46 | iterator begin() { return Fields.begin(); } |
| 47 | iterator end() { return Fields.end(); } |
Owen Anderson | d8c8788 | 2011-02-18 21:51:29 +0000 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | class FixedLenDecoderEmitter : public TableGenBackend { |
| 51 | public: |
Owen Anderson | 83e3f67 | 2011-08-17 17:44:15 +0000 | [diff] [blame] | 52 | FixedLenDecoderEmitter(RecordKeeper &R, |
James Molloy | a5d5856 | 2011-09-07 19:42:28 +0000 | [diff] [blame] | 53 | std::string PredicateNamespace, |
Owen Anderson | 83e3f67 | 2011-08-17 17:44:15 +0000 | [diff] [blame] | 54 | std::string GPrefix = "if (", |
Jim Grosbach | 9c826d2 | 2012-02-29 22:07:56 +0000 | [diff] [blame] | 55 | std::string GPostfix = " == MCDisassembler::Fail)" |
| 56 | " return MCDisassembler::Fail;", |
Owen Anderson | 83e3f67 | 2011-08-17 17:44:15 +0000 | [diff] [blame] | 57 | std::string ROK = "MCDisassembler::Success", |
| 58 | std::string RFail = "MCDisassembler::Fail", |
| 59 | std::string L = "") : |
Craig Topper | c007ba8 | 2012-03-13 06:39:00 +0000 | [diff] [blame] | 60 | Target(R), |
James Molloy | a5d5856 | 2011-09-07 19:42:28 +0000 | [diff] [blame] | 61 | PredicateNamespace(PredicateNamespace), |
Owen Anderson | 83e3f67 | 2011-08-17 17:44:15 +0000 | [diff] [blame] | 62 | GuardPrefix(GPrefix), GuardPostfix(GPostfix), |
| 63 | ReturnOK(ROK), ReturnFail(RFail), Locals(L) {} |
Owen Anderson | d8c8788 | 2011-02-18 21:51:29 +0000 | [diff] [blame] | 64 | |
| 65 | // run - Output the code emitter |
| 66 | void run(raw_ostream &o); |
| 67 | |
| 68 | private: |
Owen Anderson | d8c8788 | 2011-02-18 21:51:29 +0000 | [diff] [blame] | 69 | CodeGenTarget Target; |
Owen Anderson | 83e3f67 | 2011-08-17 17:44:15 +0000 | [diff] [blame] | 70 | public: |
James Molloy | a5d5856 | 2011-09-07 19:42:28 +0000 | [diff] [blame] | 71 | std::string PredicateNamespace; |
Owen Anderson | 83e3f67 | 2011-08-17 17:44:15 +0000 | [diff] [blame] | 72 | std::string GuardPrefix, GuardPostfix; |
| 73 | std::string ReturnOK, ReturnFail; |
| 74 | std::string Locals; |
Owen Anderson | d8c8788 | 2011-02-18 21:51:29 +0000 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | } // end llvm namespace |
| 78 | |
| 79 | #endif |