-
Notifications
You must be signed in to change notification settings - Fork 0
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
Serialise IL #79
Serialise IL #79
Conversation
override def visitMemory(node: Memory): Memory = { | ||
program ++= "Memory(" | ||
program ++= node.toString() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This results in outputting Memory(Memory(
since Memory's toString
also includes Memory(
override def visitUnaryExpr(node: UnaryExpr): Expr = { | ||
program ++= "UnaryExpr(" | ||
node.arg = visitExpr(node.arg) | ||
program ++= ")" | ||
node | ||
} | ||
|
||
override def visitBinaryExpr(node: BinaryExpr): Expr = { | ||
program ++= "BinaryExpr(" | ||
node.arg1 = visitExpr(node.arg1) | ||
program ++= ", " | ||
node.arg2 = visitExpr(node.arg2) | ||
program ++= ")" | ||
node | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should include the operators too.
import ir._ | ||
|
||
|
||
private class ILSerialiser extends Visitor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably better to extend ReadOnlyVisitor since this isn't editing the IR? You should use that as a base instead of the regular Visitor which is designed for mutating the IR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 🤦
override def visitExtract(node: Extract): Expr = { | ||
program ++= "Extract(" | ||
node.body = visitExpr(node.body) | ||
program ++= ")" | ||
node | ||
} | ||
|
||
override def visitRepeat(node: Repeat): Expr = { | ||
program ++= "Repeat(" | ||
node.body = visitExpr(node.body) | ||
program ++= ")" | ||
node | ||
} | ||
|
||
override def visitZeroExtend(node: ZeroExtend): Expr = { | ||
program ++= "ZeroExtend(" | ||
node.body = visitExpr(node.body) | ||
program ++= ")" | ||
node | ||
} | ||
|
||
override def visitSignExtend(node: SignExtend): Expr = { | ||
program ++= "SignExtend(" | ||
node.body = visitExpr(node.body) | ||
program ++= ")" | ||
node | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should include more than just the body for all of these, and don't need to be updating node.body
for anything since you aren't mutating the IR.
override def visitProgram(node: Program): Program = { | ||
for (i <- node.procedures.indices) { | ||
val updatedProcedure = visitProcedure(node.procedures(i)) | ||
val targetProcedure = node.procedures(i) | ||
if (targetProcedure == node.mainProcedure) { | ||
node.mainProcedure = updatedProcedure | ||
} | ||
node.procedures(i) = updatedProcedure | ||
} | ||
node | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to copy in methods from the base class that haven't been changed, but using this version which is designed for mutating the IR is incorrect.
This is good to have, but you're missing a bunch of things that weren't in the Visitor (because they're just integers etc. and don't need to be visited themselves), and you should have used ReadOnlyVisitor as a base instead, as you don't need all those |
Thanks for the review,
I'm not sure what's missing, e.g. Literal just forwards to |
Oh, I should have been more specific - things such as the Extract etc. parameters and the BinaryExpr operator that I highlighted. |
Looking at this again I think the main issue left is that the |
Yeah I wondered about that, I was thinking it might be better to include everything represented in the IL, e.g. its not automatically obvious that |
For debugging and regression detection it is good to have a text output of the intermediate language, this is a basic implementation of that, aiming to make it look close to the internal datastructures with some explanatory syntax.
E.g. for secret_write: