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
+58 -25
+58 -25
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,
stream << std::endl << ".label TK__PACKED_AS_3N = $" << std::hex << +tk__packed_as_3n << const StringEncodedList &stringEncodedList)
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]; // For the dictionary we do not have any labels
const auto &stringEncodedList = stringEncodedLists[idxList]; if (stringEntryList.type == ListType::DICTIONARY) return;
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++)
{ {
@@ -1295,14 +1292,10 @@ void DataSet::prepareOutput()
} }
} }
// For the token list - put the number of tokens available void DataSet::prepareOutput_packed(std::ostringstream &stream,
const StringEntryList &stringEntryList,
if (stringEntryList.type == ListType::KEYWORDS) const StringEncodedList &stringEncodedList)
{ {
stream << std::endl << ".label TK__MAXTOKEN_" << stringEntryList.name << " = " <<
std::dec << stringEncodedList.size() << std::endl;
}
if (isCompressionLvl2(stringEntryList)) if (isCompressionLvl2(stringEntryList))
{ {
stream << std::endl << ".macro put_packed_dict_"; stream << std::endl << ".macro put_packed_dict_";
@@ -1368,6 +1361,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
stream << std::endl << "#endif // ROM_LAYOUT_" << layoutName() << std::endl; stream << std::endl << "#endif // ROM_LAYOUT_" << layoutName() << std::endl;