<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class="">forgot to cc the list in an earlier email...</div><div class=""><br class=""></div><div class="">Hi David,</div><div class=""><br class=""></div><div class="">Not all identifier have an unfolding in the .hi files… you’d have to recompile all shipped libraries with: -fexpose-all-unfoldings.</div><div class="">Even then, identifiers that evaluate to bottom will, annoyingly, still not get an unfolding in the .hi files.</div><div class="">Many identifiers do, however, have an unfolding!</div><div class=""><br class=""></div><div class="">With that out of the way, I’ve created a whole-program transformation compiler that converts “structural” Haskell to Hardware (VHDL/Verilog).</div><div class="">You can take a look at: <a href="https://github.com/clash-lang/clash-compiler/tree/master/clash-ghc/src-ghc/CLaSH/GHC" class="">https://github.com/clash-lang/clash-compiler/tree/master/clash-ghc/src-ghc/CLaSH/GHC</a></div><div class="">for all the modules that interact with the GHC API.</div><div class="">Especially look at: <a href="https://github.com/clash-lang/clash-compiler/blob/master/clash-ghc/src-ghc/CLaSH/GHC/LoadModules.hs#L56" class="">https://github.com/clash-lang/clash-compiler/blob/master/clash-ghc/src-ghc/CLaSH/GHC/LoadModules.hs#L56</a></div><div class="">Which, given a module name “A", gives you all binders from the module “A", and all the binders from other modules that are needed by the binders in “A”</div><div class="">It uses: <a href="https://github.com/clash-lang/clash-compiler/blob/master/clash-ghc/src-ghc/CLaSH/GHC/LoadInterfaceFiles.hs#L59" class="">https://github.com/clash-lang/clash-compiler/blob/master/clash-ghc/src-ghc/CLaSH/GHC/LoadInterfaceFiles.hs#L59</a></div><div class="">to load the unfoldings from “.hi” files.</div><div class=""><br class=""></div><div class="">The code is pretty much hacked together as I was exploring the GHC API to get the things I wanted.</div><div class="">So my apologies for the poor readability.</div><div class=""><br class=""></div><div class="">Cheers,</div><div class=""><br class=""></div><div class="">Christiaan</div></div><br class=""><div style=""><blockquote type="cite" class=""><div class="">On 16 Mar 2015, at 18:34, David Darais <<a href="mailto:darais@cs.umd.edu" class="">darais@cs.umd.edu</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">Hello cafe,<br class=""><br class="">I'm currently implementing a whole-program analysis for Haskell programs using the GHC api. I have a GHC plugin written and I'm successfully slurping in programs and processing them with my analysis tools.<br class=""><br class="">I'm getting stuck when my tool encounters an identifier that lives in another module. I'd like to unfold the identifier and retrieve its source code, allowing me to do whole-program analysis.<br class=""><br class="">Assuming I have the source code of the whole program, and that I get to (re)compile everything with my plugin enabled, I'm wondering:<br class=""><br class="">1) Does the GHC api already support a nice way of doing this?<br class="">2) I see that there is support for unfolding identifiers if they've been specially marked in .hi files. Is there a way to mark everything to support unfolding, and would this give me the information I'm looking for?<br class="">3) Does anybody have experience with implementing a whole-program analysis for GHC as a plugin, and if so, how did you go about it?<br class=""><br class="">Many Thanks,<br class="">David<br class="">_______________________________________________<br class="">Haskell-Cafe mailing list<br class=""><a href="mailto:Haskell-Cafe@haskell.org" class="">Haskell-Cafe@haskell.org</a><br class="">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe<br class=""></div></blockquote></div><br class=""></body></html>