small code cleanup

This commit is contained in:
FeralChild64 committed 2020-06-23 20:26:01 +02:00
1 parent 3b4d1345db
commit 9e6dcd0b08
1 file changed
+61 -28
+61 -28
View File
@@ -491,6 +491,13 @@ private:
void encodeByFreq(const std::string &plain, StringEncoded &encoded) const; void encodeByFreq(const std::string &plain, StringEncoded &encoded) const;
void prepareOutput(); 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); void putCharEncoding(std::ostringstream &stream, uint8_t idx, char character, bool is3n);
@@ -796,6 +803,7 @@ void DictEncoder::optimizeOrder()
void DictEncoder::process(StringEntryList &outDictionary) void DictEncoder::process(StringEntryList &outDictionary)
{ {
if (dictionary.empty()) return;
// Optimize as long as it brings any improvement // Optimize as long as it brings any improvement
while (optimizeSplit() || optimizeJoin()) ; while (optimizeSplit() || optimizeJoin()) ;
@@ -1231,13 +1239,8 @@ void DataSet::putCharEncoding(std::ostringstream &stream, uint8_t idx, char char
stream << petscii << std::endl; 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; uint8_t idx;
// Export all nibble-encoded characters // Export all nibble-encoded characters
@@ -1266,21 +1269,15 @@ void DataSet::prepareOutput()
} }
stream << "}" << std::endl; 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; stream << std::endl;
for (uint8_t idxString = 0; idxString < stringEncodedList.size(); idxString++) 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; " = $" << 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)) if (isCompressionLvl2(stringEntryList))
{ {
stream << std::endl << ".macro put_packed_dict_"; stream << std::endl << ".macro put_packed_dict_";
@@ -1366,6 +1359,46 @@ void DataSet::prepareOutput()
} }
stream << "}" << std::endl; 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 // Finalize the file stream