如何创建一个C编译器没有一个C本地编译器 [英] How create a C compiler without a C native compiler

查看:191
本文介绍了如何创建一个C编译器没有一个C本地编译器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个简单的问题。如果编译C编译器需要一个C编译器...也许直接与装配code?也许内核为转换C到汇编并创建一个不断升级的基础设施的基本工具?这是一个愚蠢的问题,但也是我在如何从0设计一个操作系统(不是我)与CPU和内存进行互动很感兴趣。

It's a simple question. If to compile the C compiler is needed a C compiler... Maybe directly with assembly code? Perhaps the kernel provides a basic tool for converting C to assembler and create an escalating infrastructure? It's a stupid question also but I'm really interested in how to design an operating system (not me) from 0 to interact with the CPU and memory.

推荐答案

这来源于一句,自己拉由您白手起家,如果你想看看它。引导是一个简单的过程,但它是一个大量的工作。

Bootstrapping

This comes from the phrase, "pulling yourself up by your bootstraps", if you want to look it up. Bootstrapping is a straightforward process, but it is a lot of work.


  1. 将在其他语言的C编译器。

  1. Write a C compiler in another language.

写在C C编译器。

使用步骤#1编译器编译步骤#2的编译器。

Use the compiler from step #1 to compile the compiler from step #2.

一些其他的编译器已经被自举,而不仅仅是那些C.例如, GHC 必须使用自己编译

Some other compilers have to be bootstrapped, not just those for C. For example, GHC must be used to compile itself.

注意引导,只需要如果同时满足下列条件:

Note that bootstrapping is only necessary if both of the following are true:


  1. 正在发明一种新的语言,所以有没有现成的编译器。

  1. You are inventing a new language, so there are no existing compilers.

您想要写您正在编译语言的编译器。

You want to write the compiler in the language you are compiling.

这已无关的操作系统。如果你正在设计一个操作系统,你有足够的工作之前,你已经。如果你的新操作系统不具备C编译器的是,你可以交叉编译从不同的操作系统的编译器。这是工作将大为减少。 - 也许几个小时或几天,代替月或数年

This has nothing to do with operating systems. If you are designing an operating system, you have enough work ahead of you already. If your new operating system does not have a C compiler yet, you can cross-compile the compiler from a different operating system. This is much less work — maybe a few hours or days, instead of months or years.

这篇关于如何创建一个C编译器没有一个C本地编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆