Skip to content

Commit

Permalink
Parse multiple InstrSets (fixes llvm#14), optional boilerplate scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
mathis-s authored and PhilippvK committed Feb 22, 2024
1 parent 0e029ac commit 89d267e
Showing 1 changed file with 41 additions and 33 deletions.
74 changes: 41 additions & 33 deletions llvm/tools/pattern-gen/lib/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1091,45 +1091,53 @@ std::vector<CDSLInstr> ParseCoreDSL2(TokenStream& ts, llvm::Module* mod)
{
std::vector<CDSLInstr> instrs;

// boilerplate
pop_cur(ts, Identifier);
pop_cur(ts, Identifier);
if (pop_cur_if(ts, ExtendsKeyword))
pop_cur(ts, Identifier);
pop_cur(ts, CBrOpen);
pop_cur(ts, InstructionsKeyword);
pop_cur(ts, CBrOpen);

while (ts.Peek().type != CBrClose)
while(ts.Peek().type != None)
{
reset_globals();
Token ident = pop_cur(ts, Identifier);
pop_cur(ts, CBrOpen);
CDSLInstr instr{.name = std::string(ident.ident.str)};
curInstr = &instr;
bool parseBoilerplate = ts.Peek().type == Identifier && ts.Peek().ident.str == "InstructionSet";
if (parseBoilerplate)
{
pop_cur(ts, Identifier);
pop_cur(ts, Identifier);
if (pop_cur_if(ts, ExtendsKeyword))
pop_cur(ts, Identifier);
pop_cur(ts, CBrOpen);
pop_cur(ts, InstructionsKeyword);
pop_cur(ts, CBrOpen);
}

while (ts.Peek().type != CBrClose)
while (ts.Peek().type != CBrClose && ts.Peek().type != None)
{
switch (ts.Peek().type)
reset_globals();
Token ident = pop_cur(ts, Identifier);
pop_cur(ts, CBrOpen);
CDSLInstr instr{.name = std::string(ident.ident.str)};
curInstr = &instr;

while (ts.Peek().type != CBrClose)
{
case EncodingKeyword:
ParseEncoding(ts, instr);
break;
case AssemblyKeyword:
ParseArguments(ts, instr);
break;
case BehaviorKeyword:
ParseBehaviour(ts, instr, mod, ident);
break;
default: syntax_error(ts);
switch (ts.Peek().type)
{
case EncodingKeyword:
ParseEncoding(ts, instr);
break;
case AssemblyKeyword:
ParseArguments(ts, instr);
break;
case BehaviorKeyword:
ParseBehaviour(ts, instr, mod, ident);
break;
default: syntax_error(ts);
}
}
pop_cur(ts, CBrClose);
instrs.push_back(instr);
}

if (parseBoilerplate)
{
pop_cur(ts, CBrClose);
pop_cur(ts, CBrClose);
}
pop_cur(ts, CBrClose);
instrs.push_back(instr);
}

pop_cur(ts, CBrClose);
pop_cur(ts, CBrClose);

return instrs;
}

0 comments on commit 89d267e

Please sign in to comment.