70 lines · c
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_UTILS_TABLEGEN_DECODERTABLEEMITTER_H10#define LLVM_UTILS_TABLEGEN_DECODERTABLEEMITTER_H11 12#include "DecoderTree.h"13#include "llvm/Support/FormattedStream.h"14 15namespace llvm {16 17struct DecoderTableInfo {18 bool HasCheckPredicate = false;19 bool HasSoftFail = false;20};21 22class DecoderTableEmitter {23 DecoderTableInfo &TableInfo;24 formatted_raw_ostream OS;25 26 /// The number of positions occupied by the index in the output. Used to27 /// right-align indices and left-align the text that follows them.28 unsigned IndexWidth;29 30 /// The current position in the output stream. After the table is emitted,31 /// this is its size.32 unsigned CurrentIndex;33 34 /// The index of the first byte of the table row. Used as a label in the35 /// comment following the row.36 unsigned LineStartIndex;37 38public:39 DecoderTableEmitter(DecoderTableInfo &TableInfo, raw_ostream &OS)40 : TableInfo(TableInfo), OS(OS) {}41 42 void emitTable(StringRef TableName, unsigned BitWidth,43 const DecoderTreeNode *Root);44 45private:46 unsigned computeNodeSize(const DecoderTreeNode *Node) const;47 unsigned computeTableSize(const DecoderTreeNode *Root,48 unsigned BitWidth) const;49 50 void emitStartLine();51 void emitOpcode(StringRef Name);52 void emitByte(uint8_t Val);53 void emitUInt8(unsigned Val);54 void emitULEB128(uint64_t Val);55 raw_ostream &emitComment(indent Indent);56 57 void emitCheckAnyNode(const CheckAnyNode *N, indent Indent);58 void emitCheckAllNode(const CheckAllNode *N, indent Indent);59 void emitSwitchFieldNode(const SwitchFieldNode *N, indent Indent);60 void emitCheckFieldNode(const CheckFieldNode *N, indent Indent);61 void emitCheckPredicateNode(const CheckPredicateNode *N, indent Indent);62 void emitSoftFailNode(const SoftFailNode *N, indent Indent);63 void emitDecodeNode(const DecodeNode *N, indent Indent);64 void emitNode(const DecoderTreeNode *N, indent Indent);65};66 67} // namespace llvm68 69#endif // LLVM_UTILS_TABLEGEN_DECODERTABLEEMITTER_H70