Skip to content

Commit

Permalink
Merge pull request #2026 from mrgriffin/preproc-enum-arbitrary-expr
Browse files Browse the repository at this point in the history
preproc: support arbitrary expressions in enums
  • Loading branch information
GriffinRichards authored Aug 26, 2024
2 parents ac28fc5 + 5c55cc3 commit bc7c46f
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions tools/preproc/asm_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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++;
}
Expand Down

0 comments on commit bc7c46f

Please sign in to comment.