GaloisInc / crucible

Crucible is a library for symbolic simulation of imperative programs
617 stars 42 forks source link

llvm: Refactor override matching #1197

Closed langston-barrett closed 3 months ago

langston-barrett commented 3 months ago

Figuring out whether a given override should apply to a given define or declare in an LLVM module is not as easy as seeing if their names match. For some C++ overrides, for example, checking if the override should apply requires demangling the function name, which is an expensive proposition.

For this reason, override matching happens in two "phases" in Crucible-LLVM: first, there is an initial, fast, string-based TemplateMatcher that is used to filter out overrides that definitely don't apply. Then, if any remain, there is a second phase that inspects the declaration in more detail to see if the override matches.

Previously, this second phase consisted of a RegOverrideM (i.e., OverrideSim) action that would actually perform the registration. This is unnecessarily flexible. The second phase is only really supposed to perform the inspection of the declaration, construct an override, and register it. Therefore, it's been replaced by a pure function that returns a Maybe (SomeLLVMOverride ...), which can then be registered by client code, if desired.

This more restrictive type should help clarify the intent of the override matching code, and reduce the potential for superfluous use of OverrideSim effects.