TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

C to Go translation tool supporting Go toolchain migration

85 点作者 thinxer超过 10 年前

7 条评论

azernik超过 10 年前
For the casual reader, in case other comments don&#x27;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:&#x2F;&#x2F;docs.google.com&#x2F;document&#x2F;d&#x2F;1P3BLR31VA8cvLJLfMibSuTdw...</a>
peterwaller超过 10 年前
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:&#x2F;&#x2F;github.com&#x2F;rsc&#x2F;c2go&#x2F;blob&#x2F;f6c077dd7192b90f4a7ad0a4b8f...</a>
评论 #8922695 未加载
WestCoastJustin超过 10 年前
GopherCon 2014 had a talk on &quot;Go, from C to Go&quot; by Russ Cox. Here&#x27;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:&#x2F;&#x2F;talks.golang.org&#x2F;2014&#x2F;c2go.slide#1</a><p>[2] <a href="https://www.youtube.com/watch?v=QIE5nV5fDwA" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=QIE5nV5fDwA</a>
评论 #8915737 未加载
评论 #8915868 未加载
eklavya超过 10 年前
I wish for something similar for C++ -&gt; Rust and C -&gt; Rust.
评论 #8915908 未加载
kanwisher超过 10 年前
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
评论 #8916262 未加载
评论 #8917141 未加载
评论 #8915880 未加载
评论 #8915979 未加载
4ad超过 10 年前
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&#x27;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&#x27;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:&#x2F;&#x2F;code.google.com&#x2F;p&#x2F;rbits&#x2F;source&#x2F;browse&#x2F;7lfix&#x2F;main.go</a>
qb45超过 10 年前
This should be written in C and have sufficient C language coverage to understand and translate itself. Functional tests for free :)