small code cleanup
This commit is contained in:
1 parent
3b4d1345db
commit
9e6dcd0b08
1 file changed
+61
-28
+61
-28
@@ -491,6 +491,13 @@ private:
|
||||
void encodeByFreq(const std::string &plain, StringEncoded &encoded) const;
|
||||
|
||||
void prepareOutput();
|
||||
void prepareOutput_1n_3n(std::ostringstream &stream);
|
||||
void prepareOutput_labels(std::ostringstream &stream,
|
||||
const StringEntryList &stringEntryList,
|
||||
const StringEncodedList &stringEncodedList);
|
||||
void prepareOutput_packed(std::ostringstream &stream,
|
||||
const StringEntryList &stringEntryList,
|
||||
const StringEncodedList &stringEncodedList);
|
||||
|
||||
void putCharEncoding(std::ostringstream &stream, uint8_t idx, char character, bool is3n);
|
||||
|
||||
@@ -796,6 +803,7 @@ void DictEncoder::optimizeOrder()
|
||||
|
||||
void DictEncoder::process(StringEntryList &outDictionary)
|
||||
{
|
||||
if (dictionary.empty()) return;
|
||||
// Optimize as long as it brings any improvement
|
||||
|
||||
while (optimizeSplit() || optimizeJoin()) ;
|
||||
@@ -1231,13 +1239,8 @@ void DataSet::putCharEncoding(std::ostringstream &stream, uint8_t idx, char char
|
||||
stream << petscii << std::endl;
|
||||
}
|
||||
|
||||
void DataSet::prepareOutput()
|
||||
void DataSet::prepareOutput_1n_3n(std::ostringstream &stream)
|
||||
{
|
||||
// Convert our encoded strings to a KickAssembler source
|
||||
|
||||
std::ostringstream stream;
|
||||
stream << std::endl << "#if ROM_LAYOUT_" << layoutName() << std::endl;
|
||||
|
||||
uint8_t idx;
|
||||
|
||||
// Export all nibble-encoded characters
|
||||
@@ -1266,21 +1269,15 @@ void DataSet::prepareOutput()
|
||||
}
|
||||
|
||||
stream << "}" << std::endl;
|
||||
}
|
||||
|
||||
// Export additional data for the tokenizer
|
||||
void DataSet::prepareOutput_labels(std::ostringstream &stream,
|
||||
const StringEntryList &stringEntryList,
|
||||
const StringEncodedList &stringEncodedList)
|
||||
{
|
||||
// For the dictionary we do not have any labels
|
||||
if (stringEntryList.type == ListType::DICTIONARY) return;
|
||||
|
||||
stream << std::endl << ".label TK__PACKED_AS_3N = $" << std::hex << +tk__packed_as_3n <<
|
||||
std::endl << ".label TK__MAX_KEYWORD_LEN = " << std::dec << +tk__max_keyword_len << std::endl;
|
||||
|
||||
// Export encoded strings
|
||||
|
||||
for (uint8_t idxList = 0; idxList < stringEntryLists.size(); idxList++)
|
||||
{
|
||||
const auto &stringEntryList = stringEntryLists[idxList];
|
||||
const auto &stringEncodedList = stringEncodedLists[idxList];
|
||||
|
||||
if (stringEntryList.type != ListType::DICTIONARY)
|
||||
{
|
||||
stream << std::endl;
|
||||
for (uint8_t idxString = 0; idxString < stringEncodedList.size(); idxString++)
|
||||
{
|
||||
@@ -1293,16 +1290,12 @@ void DataSet::prepareOutput()
|
||||
" = $" << std::uppercase << std::hex << std::setfill('0') << std::setw(2) << +idxString << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// For the token list - put the number of tokens available
|
||||
|
||||
if (stringEntryList.type == ListType::KEYWORDS)
|
||||
{
|
||||
stream << std::endl << ".label TK__MAXTOKEN_" << stringEntryList.name << " = " <<
|
||||
std::dec << stringEncodedList.size() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void DataSet::prepareOutput_packed(std::ostringstream &stream,
|
||||
const StringEntryList &stringEntryList,
|
||||
const StringEncodedList &stringEncodedList)
|
||||
{
|
||||
if (isCompressionLvl2(stringEntryList))
|
||||
{
|
||||
stream << std::endl << ".macro put_packed_dict_";
|
||||
@@ -1366,6 +1359,46 @@ void DataSet::prepareOutput()
|
||||
}
|
||||
|
||||
stream << "}" << std::endl;
|
||||
}
|
||||
|
||||
void DataSet::prepareOutput()
|
||||
{
|
||||
// Convert our encoded strings to a KickAssembler source
|
||||
|
||||
std::ostringstream stream;
|
||||
stream << std::endl << "#if ROM_LAYOUT_" << layoutName() << std::endl;
|
||||
|
||||
// Export 1-nibble and 3-nibble encoding data
|
||||
|
||||
prepareOutput_1n_3n(stream);
|
||||
|
||||
// Export additional data for the tokenizer
|
||||
|
||||
stream << std::endl << ".label TK__PACKED_AS_3N = $" << std::hex << +tk__packed_as_3n <<
|
||||
std::endl << ".label TK__MAX_KEYWORD_LEN = " << std::dec << +tk__max_keyword_len << std::endl;
|
||||
|
||||
// Export encoded strings
|
||||
|
||||
for (uint8_t idx = 0; idx < stringEntryLists.size(); idx++)
|
||||
{
|
||||
const auto &stringEntryList = stringEntryLists[idx];
|
||||
const auto &stringEncodedList = stringEncodedLists[idx];
|
||||
|
||||
// Export labels for the current list
|
||||
|
||||
prepareOutput_labels(stream, stringEntryList, stringEncodedList);
|
||||
|
||||
// For the token list - put the number of tokens available
|
||||
|
||||
if (stringEntryList.type == ListType::KEYWORDS)
|
||||
{
|
||||
stream << std::endl << ".label TK__MAXTOKEN_" << stringEntryList.name << " = " <<
|
||||
std::dec << stringEncodedList.size() << std::endl;
|
||||
}
|
||||
|
||||
// Export the packed data
|
||||
|
||||
prepareOutput_packed(stream, stringEntryList, stringEncodedList);
|
||||
}
|
||||
|
||||
// Finalize the file stream
|
||||
|
||||
Reference in new issue
Block a user