For the casual reader, in case other comments don't make this clear - this is not a general-purpose translation library, and probably will not work for whatever C codebase you have. It is a one-off tool built to migrate the specific subset of C used in the original go compilers, as part of the process of making the go toolchain self-hosting (go compilers written in go).<p>This translator produces a VERY literal translation, as the intention is for future human passes to clean it up and convert it to more idiomatic go.<p>See here for the full plan: <a href="https://docs.google.com/document/d/1P3BLR31VA8cvLJLfMibSuTdwTuF7WWLux71CYD0eeD8/edit" rel="nofollow">https://docs.google.com/document/d/1P3BLR31VA8cvLJLfMibSuTdw...</a>
I love the simplicity of the main function:<p><pre><code> rewriteTypes(cfg, prog)
rewriteSyntax(cfg, prog)
rewriteLen(cfg, prog)
fixGoTypes(cfg, prog)
renameDecls(cfg, prog)
exportDecls(cfg, prog)
writeGoFiles(cfg, prog)
</code></pre>
<a href="https://github.com/rsc/c2go/blob/f6c077dd7192b90f4a7ad0a4b8f4fa5b2649899b/main.go#L62-L76" rel="nofollow">https://github.com/rsc/c2go/blob/f6c077dd7192b90f4a7ad0a4b8f...</a>
GopherCon 2014 had a talk on "Go, from C to Go" by Russ Cox. Here's the slide deck and video for those interested [1, 2].<p>[1] <a href="http://talks.golang.org/2014/c2go.slide#1" rel="nofollow">http://talks.golang.org/2014/c2go.slide#1</a><p>[2] <a href="https://www.youtube.com/watch?v=QIE5nV5fDwA" rel="nofollow">https://www.youtube.com/watch?v=QIE5nV5fDwA</a>
Would be nice if this could be made into a more general tool, would be a cool way to modernize older libraries and reinvigorate new development into them
I already reused part of this a few months ago to automatically refactor a large body of C code (around 10k LOC)[1]. Some time ago, Go converted (by hand) the various Plan 9 linkers used into a library, and I had to do the same for the arm64 linker.<p>I'm not sure if I saved time or not (I think I did) for the effective work, but I definitely saved time (and stress) overall, as the conversion was without bugs. I know for sure that I would have introduced a lot of bugs if I did this manually.<p>Tools that understand source code are great, and I'm really excited about the new Go compilers.<p>[1] <a href="https://code.google.com/p/rbits/source/browse/7lfix/main.go" rel="nofollow">https://code.google.com/p/rbits/source/browse/7lfix/main.go</a>