展示 HN:C 编译器,用于编译 TCC 以进行实时自举。
Show HN: C-compiler to compile TCC for live-bootstrap

原始链接: https://github.com/FransFaase/MES-replacement

该项目旨在通过用自编译的C编译器替换GNU Mes编译器,来简化live-bootstrap的初始阶段(stage0)。其核心是实现一个C编译器(tcc_cc.c),能够编译Tiny C Compiler (TCC) 0.9.26版本,该版本生成Stack-C中间代码。然后可以汇编或解释该代码。 第一阶段已经完成,专注于i386实现,需要现有的stage0可执行文件(hex2等)、标准Linux工具以及GCC进行初始编译。提供了一个`makefile`和一个`test.sh`脚本,用于构建和验证编译器bootstrap TCC的能力。 下一阶段将通过新创建的C编译器构建stage0可执行文件,从而消除对stage0可执行文件的依赖。初步可行性研究包括分析所需的C语法子集,并产生了一个最小的C预处理器(`min_tcc_preprocessor.cpp`)和一个解析器(`CParser.c`)。 这项工作是更大的“验证和记录live-bootstrap”项目的一部分,由NGI0 Core Fund资助。

Hacker News 新闻 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 Show HN: C 编译器编译 TCC 用于实时自举 (github.com/fransfaase) 8 分,由 fjfaase 1小时前发布 | 隐藏 | 过去 | 收藏 | 1 条评论 stevefan1999 3分钟前 [–] 我认为现在运行来自 SectorLisp 的 Common Lisp/Scheme 已经不远了 回复 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:
相关文章

原文

The goal of this project is to simplify stage0 of live-bootstrap, which involves implementing a replacement for the GNU Mes compiler by implementing a C-compiler in C that can compile the Tiny C Compiler version 0.9.26.

The motivation for this project is given in the presentation Reviewing live-bootstrap.

For blog article related to reviewing the live bootstrap project and this project see the section 'Live-bootstrap' on this page.

The first stage of this project is to implement said C-compiler for i386. The source of the C-compiler is the file tcc_cc.c. This compiler produces intermediate code for a stack based language called Stack-C. The compiler also includes the file stdlib.c, that contains a minimal version of the C standard library.

The intermediage code can be compiled with the program stack_c.c to M1 assembly or interpreted with the program stack_c_interpreter.c.

This stage depends on a number of executables from stage0. Namely:

  • hex2
  • M1
  • blood-elf
  • catm
  • match
  • sha256sum

These need to be present in the directory of the repository.

Furthermore it requires the usual Linux commands and the GNU C compiler. A makefile is included to build and test the C-compiler tcc_cc.

The sources of the Tiny C Compiler should be placed in a directory with the name tcc_sources that should also have sub directory lib.

There should also be a directory mes with the contents of the GNU Mes compiler, which is needed to build the standard library that the Tiny C Compiler needs.

To build and test the Tiny C Compiler, the test.sh shell script is provided. This script first compiles the Tiny C Compiler with GNU C-compiler, resulting in tcc_g and with tcc_cc compiler, resulting in tcc_s. Next is uses these to bootstrap the Tiny C Compiler from the sources. The script compares the results for the various steps using tcc_g and tcc_c.

Remark: The test.sh script assumes that this repository is cloned in the git directory in the home directory. Please update the BINDIR to point to the repository containing the repository.

This stage has been implemented.

The second stage will focus on removing the dependency of the executables from stage0 by building these with the C-compiler.

For a first feasability study to analyzing what part of the C-grammar that is needed for compiling TCC. For this I wrote a minimal C preprocessor: min_tcc_preprocessor.cpp and CParser.c that is heavily based on RawParser.

The work in this repository falls under the project Verifying and documenting live-bootstrap, which was funded through the NGI0 Core Fund, a fund established by NLnet with financial support from the European Commission's Next Generation Internet programme, under the aegis of DG Communications Networks, Content and Technology under grant agreement Nₒ 101092990.

联系我们 contact @ memedata.com