X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=utils%2FTableGen%2FSequenceToOffsetTable.h;h=e6ab66426fb12a2c89a94095487aecebea046312;hb=087ab613f42890b2e84fb8a058f346ead2bfd595;hp=26e705841f2b64256c6a5cca0da6682dfebdcf46;hpb=184440e8085379f8c3749f04dcffee8d9f16f435;p=oota-llvm.git diff --git a/utils/TableGen/SequenceToOffsetTable.h b/utils/TableGen/SequenceToOffsetTable.h index 26e705841f2..e6ab66426fb 100644 --- a/utils/TableGen/SequenceToOffsetTable.h +++ b/utils/TableGen/SequenceToOffsetTable.h @@ -17,10 +17,12 @@ #define TBLGEN_SEQUENCE_TO_OFFSET_TABLE_H #include "llvm/Support/raw_ostream.h" -#include #include -#include #include +#include +#include +#include +#include namespace llvm { @@ -28,8 +30,8 @@ namespace llvm { /// Compute the layout of a table that contains all the sequences, possibly by /// reusing entries. /// -/// @param SeqT The sequence container. (vector or string). -/// @param Less A stable comparator for SeqT elements. +/// @tparam SeqT The sequence container. (vector or string). +/// @tparam Less A stable comparator for SeqT elements. template > class SequenceToOffsetTable { typedef typename SeqT::value_type ElemT; @@ -80,6 +82,8 @@ public: Seqs.erase(I); } + bool empty() const { return Seqs.empty(); } + /// layout - Computes the final table layout. void layout() { assert(Entries == 0 && "Can only call layout() once"); @@ -103,7 +107,9 @@ public: /// emit - Print out the table as the body of an array initializer. /// Use the Print function to print elements. - void emit(raw_ostream &OS, void (*Print)(raw_ostream&, ElemT)) const { + void emit(raw_ostream &OS, + void (*Print)(raw_ostream&, ElemT), + const char *Term = "0") const { assert(Entries && "Call layout() before emit()"); for (typename SeqMap::const_iterator I = Seqs.begin(), E = Seqs.end(); I != E; ++I) { @@ -113,11 +119,24 @@ public: Print(OS, *SI); OS << ", "; } - OS << "0,\n"; + OS << Term << ",\n"; } } }; +// Helper function for SequenceToOffsetTable. +static inline void printChar(raw_ostream &OS, char C) { + unsigned char UC(C); + if (isalnum(UC) || ispunct(UC)) { + OS << '\''; + if (C == '\\' || C == '\'') + OS << '\\'; + OS << C << '\''; + } else { + OS << unsigned(UC); + } +} + } // end namespace llvm #endif