Git Product home page Git Product logo

sunshaoce / rvcc Goto Github PK

View Code? Open in Web Editor NEW
320.0 6.0 71.0 400 KB

本课程基于Rui的chibicc,@sunshaoce和@ksco将其由原来的X86架构改写为RISC-V 64架构,同时加入了大量的中文注释,并且配有316节对应于每一个commit的课程,帮助读者可以层层推进、逐步深入的学习编译器的构造。

License: MIT License

CMake 0.07% Makefile 0.56% C 96.94% Shell 2.43%
compiler course

rvcc's Issues

语法注释有歧义

第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的问题

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并退出。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.