sunshaoce / rvcc Goto Github PK
View Code? Open in Web Editor NEW本课程基于Rui的chibicc,@sunshaoce和@ksco将其由原来的X86架构改写为RISC-V 64架构,同时加入了大量的中文注释,并且配有316节对应于每一个commit的课程,帮助读者可以层层推进、逐步深入的学习编译器的构造。
License: MIT License
本课程基于Rui的chibicc,@sunshaoce和@ksco将其由原来的X86架构改写为RISC-V 64架构,同时加入了大量的中文注释,并且配有316节对应于每一个commit的课程,帮助读者可以层层推进、逐步深入的学习编译器的构造。
License: MIT License
第25个commit, 零参数的函数定义中函数语法是这样给出的
// functionDefinition = declspec declarator? ident "(" ")" "{" compoundStmt*
然后declarator的语法要求必须有标识符的
// declarator = "" ident typeSuffix
这样一个函数声明就有两个标识符了
另外functionDefinition 中对declarator 标记了"?",然后function函数实现中, 逻辑中要求必须有declarator
函数实现的语法 应该是 // functionDefinition = declspec declarator"{" compoundStmt*
// foo.h
struct foo {
float f;
union { int x; };
};
int foo(struct foo);
// foo.c
#include "foo.h"
int foo(struct foo in) {
return in.x;
}
// test.c
#include "foo.h"
int printf(const char *, ... );
int main() {
printf("%d\n", foo((struct foo){1, 2}));
return 0;
}
当使用rvcc与gcc混合编译时
./rvcc foo.c -S -o foo.s
riscv64-unknown-linux-gnu-gcc foo.s test.c
qemu-riscv64 a.out # print 0
使用gcc编译
riscv64-unknown-linux-gnu-gcc foo.c test.c
qemu-riscv64 a.out # print 2
rvcc的调用约定对union的处理是错误的。标准中没有要求对不超过8字节的union特殊处理。
stage2/rvcc 是riscv版本的,于是只能在qemu上运行,但是运行起来后会有奇怪的报错信息,例如:
stage2/rvcc: 1: ELF��@�8: not found
stage2/rvcc: 3: Syntax error: "(" unexpected
猜测可能是fork-exec模型的问题。执行execvp函数后把qemu也覆盖掉了,然后尝试直接在x86环境下运行riscv版本的rvcc导致的错误。如果不去执行fork-exec,例如只是用--help打印信息就能正常在qemu里运行stage2/rvcc并退出。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.