Skip to content

Fan-plus/WhuToyc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WhuToyC

介绍

简单的toyc编译器,实现从.tc源代码到.s的RISC-V 32汇编

本地运行

工具和环境

二者使用方法类似Tutorial4中的ocamllex 和 ocamlyacc,可以进行参考Tutorial4 如果还是不清楚,可以见自己动手写编译器

  • Cmake 构建工具
  • make 我自己采用的cmake生成Makefile 然后make的方式进行构建

可以Terminal中运行cmake --version flex --version等查看是否按安装成功

项目结构

.
├── build
├── include/
│   ├── ast.h
│   ├── codegen.h
│   ├── semantic.h
│   └── token.h
├── src/
│   ├── codegen.cpp
│   ├── lexer.l
│   ├── main.cpp
│   ├── parser.y
│   └── semantic.cpp
├── test
├── .gitnore
├── CMakeLists.txt
└── README.md

build文件夹没有上传

运行命令

进入拉取的项目后

mkdir build
cd build #进入build文件夹(源外生成保证源代码干净)

cmake -G "MinGW Makefiles" ..
# 此时build文件夹下出现 Makefile  lexyy.cc parser.tab.h等文件,也可以cmake -G 查看其他支持的构建系统并采用自己喜欢的

make (或mingw32-make 看自己make的名字)
# 此时build文件夹下生成 toycc.exe的可执行文件

Get-Content ..\test\16_complex_syntax.tc | .\toycc.exe(windows powershell)

toycc << ..\test\16_complex_syntax.tc(linux 或 wsl环境)

到此就可以看到汇编输出在屏幕上

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors