【发布时间】:2016-09-30 14:47:15
【问题描述】:
我在 Racket 中为类似方案的语言编写了一个小型编译器。现在我想为我的编译器实现 TCO。
我的想法是:我需要在将尾调用转换为中间表示之前检测它们。但是从这个page 看来,TCO 通常是通过将call 更改为jmp 在装配级别完成的。我有点卡在这里。
任何建议将不胜感激。
编辑:我的目标是 x86 汇编代码。我使用的 IR 是三地址码。
这里是我的编译器的 12 个通道,扁平通道是我将源代码转换为 IR 的地方
(define test-passes
(list
`("uniquify" ,(uniquify '()) ,interp-scheme)
`("reveal-functions" ,(reveal-functions '()) ,interp-F)
`("convert-to-closures" ,convert-to-closure ,interp-F)
`("expose allocation" ,expose-allocation ,interp-F)
`("flatten" ,(flatten #f) ,interp-C)
`("instruction selection" ,select-instructions ,interp-x86)
`("liveness analysis" ,(uncover-live (void)) ,interp-x86)
`("build interference" ,(build-interference (void) (void) (void) (void)) ,interp-x86)
`("allocate register" ,allocate-registers ,interp-x86)
`("lower-conditionals" ,lower-conditionals ,interp-x86)
`("patch-instructions" ,patch-instructions ,interp-x86)
`("x86" ,print-x86 #f)
))
【问题讨论】:
-
为什么在进入 IR 之前需要这样做,而不是在 ANF(或 CPS)中这样做?
-
啊,是的,感谢您提供这些链接。
-
@WillNess 嗨,如果我已经有 IR 怎么办?
-
这真的取决于你的 IR。此外,对于许多不同的 IR,语言对您来说并不少见,例如,请查看 nanopass.org。
标签: compiler-construction scheme racket tail-call-optimization