1 Star 0 Fork 3

eaglexmw / MazuCC

forked from Gitee 极速下载 / MazuCC 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
BSD-2-Clause

MazuCC

MazuCC is a minimalist C compiler with x86_64 code generation. It is intended to support partial C99 language features while keeping the code as small and simple as possible.

Build

Run make to build:

$ make

MazuCC comes with unit tests. To run the tests, give "check" as an argument:

$ make check

MazuCC is known to work on both GNU/Linux and macOS.

Use MazuCC to compile C source:

$ ./mzcc < sample/nqueen.c

You will get the generated x86_64 assembly in AT&T syntax. The output can be assembled and linked into a valid executable:

$ ./mzcc < sample/nqueen.c > sample/nqueen.s
$ gcc -no-pie -o sample/nqueen sample/nqueen.s

If MazuCC is compiled and executed on macOS, the above argument -no-pie should be eliminated.

Reference output of MazuCC-compiled sample/nqueen:

Q . . . . . . .
. . . . Q . . .
. . . . . . . Q
. . . . . Q . .
. . Q . . . . .
. . . . . . Q .
. Q . . . . . .
. . . Q . . . .

Alternatively, you can dump internal abstract syntax tree:

echo 'struct {int x; char y; struct { int t; } z; } a;' | ./mzcc --dump-ast

The expected output in S-expression form:

(decl (struct (int)
              (char)
              ((struct (int)))) a)

Acknowledge

MazuCC is heavily inspired by 8cc.

License

MazuCC is freely redistributable under the BSD 2 clause license. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright (c) 2019 National Cheng Kung University, Taiwan. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

简介

Mazucc 是一个最低限度的C编译器,具有x86_代码生成功能 展开 收起
BSD-2-Clause
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/eaglexmw/MazuCC.git
git@gitee.com:eaglexmw/MazuCC.git
eaglexmw
MazuCC
MazuCC
master

搜索帮助