简体   繁体   English

主function中的编译器设计前端计算Clang和Zig

[英]Compiler design frontend calculation in the main function for Clang and Zig

I have started reading the source code of clang and zig-lang .我已经开始阅读clangzig-lang的源代码。 Unfortunately, the source codes are complicated and I am not able to find out where is frontend of these compilers are called in the main function.不幸的是,源代码很复杂,我无法找出这些编译器的前端在主要 function 中调用的位置。

In clang , the closer place I have found is here but it does not look like processing the compilation frontend.clang中,我找到的更近的地方是这里,但它看起来不像处理编译前端。

In zig-lang , the main function is even messier and very hard to understand.zig-lang中,主要的 function 更加混乱且难以理解。 I just could find the de facto main function (main0) here .我只能在这里找到事实上的主要 function (main0)。

Though, explaining the stages of these compilers and pointing to their code is appreciated, just the point of where frontends computations are called is sufficient for me.虽然,解释这些编译器的阶段并指向他们的代码是值得赞赏的,但对我来说,仅仅调用前端计算的地方就足够了。

The main zig compiler is executed from Compilation.performAllTheWork .主 zig 编译器从Compilation.performAllTheWork执行。 This function loops over all the compilation items and compiles them.这个 function 循环遍历所有编译项并编译它们。 ( main()buildOutputTypeupdateModuleCompilation.update → Compilation.performAllTheWork) ( main()buildOutputTypeupdateModuleCompilation.update → Compilation.performAllTheWork)

Stage1 (the default compiler in zig 0.8.0, written in C++) is called when stage1_module items are found in the work queue from Compilation.updateStage1Module .当从Compilation.updateStage1Module的工作队列中找到 stage1_module 项时,将调用 Stage1(zig 0.8.0 中的默认编译器,用 C++ 编写)。 The bulk of compilation happens from codegen_build_object (called from zig_stage1_build_object )大部分编译发生在codegen_build_object (从zig_stage1_build_object调用)

Stage2 (the work-in-progress faster compiler written in Zig) is more tightly integrated into the work queue because it supports incremental compilation and is called in these branches of the work queue switch. Stage2(用 Zig 编写的工作中更快的编译器)更紧密地集成到工作队列中,因为它支持增量编译并在工作队列切换的这些分支中调用。


Clang starts somewhere, maybe in clang.lib.frontend.CompilerInvocation ? Clang 从某个地方开始,可能在clang.lib.frontend.CompilerInvocation中?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM