Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve PPC grammar and visitor #762

Merged
merged 8 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
More improvemes to PPC grammar
Signed-off-by: Hernan Ponce de Leon <zeta96@gmail.com>
  • Loading branch information
hernanponcedeleon committed Oct 25, 2024
commit cc8f2c527c055eea92a2435ef330ba0487be2837
3 changes: 2 additions & 1 deletion dartagnan/src/main/antlr4/LitmusPPC.g4
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ fence

location
: Identifier
| LBracket Identifier RBracket
;

register
Expand Down Expand Up @@ -240,7 +241,7 @@ Register
;

Label
: 'LC' DigitSequence
: 'L' Identifier
;

LitmusLanguage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,11 @@ public Object visitCmpw(LitmusPPCParser.CmpwContext ctx) {
public Object visitBranchCond(LitmusPPCParser.BranchCondContext ctx) {
Label label = programBuilder.getOrCreateLabel(mainThread, ctx.Label().getText());
CmpInstruction cmp = lastCmpInstructionPerThread.put(mainThread, null);
if(cmp == null){
throw new ParsingException("Invalid syntax near " + ctx.getText());
}
Expression expr = expressions.makeIntCmp(cmp.left, ctx.cond().op, cmp.right);
Expression expr = cmp == null ?
// In PPC, when there is no previous comparison instruction,
// the value of r0 is used as the branching condition
expressions.makeBooleanCast(programBuilder.getOrNewRegister(mainThread, "r0")) :
expressions.makeIntCmp(cmp.left, ctx.cond().op, cmp.right);
return programBuilder.addChild(mainThread, EventFactory.newJump(expr, label));
}

Expand Down