This is not entirely complete (some errors are not handled properly) but it's a start.
This is required for adding S140 support. It relies on the following TinyGo PR: https://github.com/tinygo-org/tinygo/pull/942