Merge pull request #2026 from mrgriffin/preproc-enum-arbitrary-expr

preproc: support arbitrary expressions in enums
This commit is contained in:
GriffinR 2024-08-26 00:02:41 -04:00 committed by GitHub
commit bc7c46ffe2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -520,6 +520,7 @@ bool AsmFile::ParseEnum()
long currentHeaderLine = SkipWhitespaceAndEol();
std::string enumName = ReadIdentifier();
currentHeaderLine += SkipWhitespaceAndEol();
std::string enumBase = "0";
long enumCounter = 0;
long symbolCount = 0;
@ -542,11 +543,28 @@ bool AsmFile::ParseEnum()
if (m_buffer[m_pos] == '=')
{
m_pos++;
currentHeaderLine += SkipWhitespaceAndEol();
enumCounter = ReadInteger(headerFilename, currentHeaderLine);
currentHeaderLine += SkipWhitespaceAndEol();
SkipWhitespace();
enumBase.clear();
for (;;)
{
if (m_pos == m_size)
RaiseError("unexpected EOF");
if (m_buffer[m_pos] == ',')
break;
if (m_buffer[m_pos] == '\n')
{
currentHeaderLine++;
enumBase.push_back(' ');
}
else
{
enumBase.push_back(m_buffer[m_pos]);
}
m_pos++;
}
enumCounter = 0;
}
std::printf(".equiv %s, %ld\n", currentIdentName.c_str(), enumCounter);
std::printf(".equiv %s, (%s) + %ld\n", currentIdentName.c_str(), enumBase.c_str(), enumCounter);
enumCounter++;
symbolCount++;
}