Use FuncDecl::needsCodegen() and related checks.

* Some tests are still in FuncDecl::toObjFile, copy them.
* Ensure entrypoint is a root module, otherwise main would no
  longer be emitted.
* Update struct emission check to what dmd does.