Fix #381: Better API for preoptimizer and optimizer.

The API is now focused on the content needed for the
optimizers to do their job, rather than on a file system-like
architecture.
Merge pull request #383 from sjrd/better-opt-api

Fix #381: Better API for preoptimizer and optimizer.