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

Rewrite IR Interpreter #241

Closed
wants to merge 65 commits into from
Closed

Rewrite IR Interpreter #241

wants to merge 65 commits into from

Conversation

ailrst
Copy link
Contributor

@ailrst ailrst commented Sep 5, 2024

Rewrite of the interpreter in a FP state-monad style, supporting new features

  • breakpoints
  • traces
  • cycle count limit
  • intrinsic functions
  • partial memory region support
  • indirect call resolution
  • nondeterministic gotos handled via lookahead

This builds on the call-statement pr and includes the readelf loading changes.

  • It adds the tests DifferentialAnalysis which runs all the src/test/correct example programs through the static analysis, and compares the interpreter's final state, and execution trace to the un-transformed program. Many of these still fall over due to missing intrinsics (e.g. malloc), and memory initialisation.
  • Adds the test ConstPropInterpreterValidate which converts the const-prop results to boolean expressions, and runs the interpreter, asserting that the results hold at every code point.

For more details see https://github.com/UQ-PAC/BASIL/blob/interpreter/docs/development/interpreter.md

Incidentally on my computer the interpreter runs at approximately 345 kHz (basil instructions/second)

@ailrst ailrst changed the base branch from main to return-statement September 5, 2024 01:43
@ailrst ailrst changed the base branch from return-statement to call-statement September 5, 2024 01:44
@ailrst ailrst changed the base branch from call-statement to main September 11, 2024 05:00
Comment on lines 41 to 42
inputFile = s"examples/$name/$name.adt",
relfFile = s"examples/$name/$name.relf",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests should be updated to use inputs from the tests folder instead of the examples folder (which has mostly been removed)

@l-kent
Copy link
Contributor

l-kent commented Sep 19, 2024

I haven't had a deep look at this yet but:

  • The test "var load store" in InterpreterTests doesn't currently pass.
  • There are warnings about incorrect indentation and pattern match exhaustivity and deprecated casting which should be addressed.
  • In general we should have filenames correspond to class names where relevant, & put files in folders according to their package.
  • Significantly more commenting would make this much easier to understand, especially with so many complex type parameters, and the heavy use of tuples in place can make the code harder to follow.
  • There are a bunch of minor style issues like case classes don't need their parameters to be specified as 'val'

@ailrst ailrst mentioned this pull request Oct 9, 2024
l-kent added 4 commits November 8, 2024 14:10
# Conflicts:
#	src/main/scala/analysis/ExprSSAEval.scala
#	src/main/scala/ir/Interpreter.scala
#	src/main/scala/ir/Program.scala
#	src/main/scala/ir/eval/BitVectorEval.scala
#	src/main/scala/util/RunUtils.scala
#	src/test/scala/ir/InterpreterTests.scala

import scala.collection.mutable

class ConstPropInterpreterValidate extends AnyFunSuite {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't match the name of the file, it should have a consistent name.

@l-kent
Copy link
Contributor

l-kent commented Nov 8, 2024

I've merged main into this so it is up-to-date now but there are some outstanding issues with DifferentialAnalysis that should be addressed before this is merged into main:

  • DifferentialAnalysis fails in many cases, including cases such as syscall/gcc_O2:BAP where the interpreter throws an exception.
  • when DifferentialAnalysis prints text starting with "STDOUT" it is never anything useful and the formatting seems to be broken.

These issues existed before the merge.

This still holds too and would be very very good to have:

  • Significantly more commenting would make this much easier to understand, especially with so many complex type parameters, and the heavy use of tuples in place can make the code harder to follow.

There are a few formatting & organisational issues I intend to fix as well, such as fixing where the file structure doesn't match the package structure.

@ailrst
Copy link
Contributor Author

ailrst commented Nov 28, 2024

Since this took two months to merge these changes (and the parameter pr) have been included in #256 and it has been updated with the current main.

I don't intend to address any of the issues you mention here.

DifferentialAnalysis fails in many cases, including cases such as syscall/gcc_O2:BAP where the interpreter throws an exception

This is due to these programs having no main procedure, so the test cases are dubious to begin with.
The rest of the cases that fail due to the interpreter reaching an error stop are due to incompleteness in the interpreter (usual wrt initialisation, syscalls and missing procedures), which require substantial work to address (such linking a libc). This generally requires a more complete linker emulation, which I am not interested in working on right now. Having these tests pass spuriously would be pointless.

when DifferentialAnalysis prints text starting with "STDOUT" it is never anything useful and the formatting seems to be broken.

The formattting isn't broken. These show what is printed to stdout which is useful to know when the interepted program is printing to stdout. I'm not interested in making a complete implementation of sprintf in Scala to make this more useful in the case of format strings right now.

Significantly more commenting would make this much easier to understand, especially with so many complex type parameters, and the heavy use of tuples in place can make the code harder to follow.

Extensive documentation is provided here https://github.com/UQ-PAC/BASIL/pull/241/files#diff-4926c58a6f33f8324a92d12cf914e957622fb809f0692aee0777b7dad2d02c7a

In future, don't chuck a 300 line diff of superficial syntax and formatting changes on the end of my pr please.

I'm closing this as the changes are included in the other pr.

@ailrst ailrst closed this Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants