If you're just interested in the symbols that make up the module's API, have you looked at -emit-api-descriptor? That might be more easily consumable than SIL.
The 6.1 compiler will also have a -dump-ast-format json feature that would provide this information (and much more) by dumping the entire AST in a parsable format.
Thank you very much for your pointers.
Unfortunately neither fulfills my need - I want to see for a source file, all the symbols it references (including types and functions) and which module they come from, not only its public-facing apis. In fact, I can get to know the public api by -emit-swift-interface as well.
-dump-ast-format does not resolve the type. If module Foo and Bar both have a doSomething() method, I couldn't possibly know which module's method this AST references.
Maybe -index-store-path could be the solution. Combined with index store parsers like below, I may be able to query all the symbol references and where they come from.
The JSON format does resolve the type for references like this. The type will be represented as a USR, which is just the mangling of the type which includes the fully qualified name (among other information).
Until that lands in a production compiler, indexstore might also be a viable approach, though not as complete as the full AST.