Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
2
2022fall-Compiler_CMinus
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李晓奇
2022fall-Compiler_CMinus
Commits
720f0a57
Commit
720f0a57
authored
Nov 04, 2022
by
张钏楠
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(lab3): update README and lab ddl
- fix cmake cmd in README - show more-tips by lq - update lab3 ddl
parent
49c4e204
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
155 additions
and
3 deletions
+155
-3
Documentations/3-ir-gen/README.md
Documentations/3-ir-gen/README.md
+4
-2
Documentations/3-ir-gen/more-tips.md
Documentations/3-ir-gen/more-tips.md
+150
-0
README.md
README.md
+1
-1
No files found.
Documentations/3-ir-gen/README.md
View file @
720f0a57
...
...
@@ -33,6 +33,7 @@ Lab3 实验建立在 Lab2 的基础上,带领大家进一步理解源代码到
2.
助教们在
`cminusf_builder.cpp`
提供的部分函数是不完整的,无法通过所有测试用例。需要你补充代码的地方已经用
`TODO`
标出。我们提供的
`cminusf_builder.cpp`
只可以满足测试用例
`lv0_1`
中的
`return.cminus`
。虽然
`eval.py`
会显示其他一些测试用例也是
`success`
,但它对应的
`.ll`
文件是不正确的,不要因其显示
`success`
忽略了对应的代码补充,那会影响你后面较复杂样例的正确性。
3.
简要阅读
`cminusf_builder.hpp`
和其他头文件中定义的函数和变量,理解项目框架也会为你的实验提供很大的帮助。
4.
请独立完成实验,不要抄袭他人代码。
5.
为方便同学们更好完成实验,补充提示文档,参见
[
Lab3 More Tips
](
./more-tips.md
)
。
## 1. 实验框架
...
...
@@ -64,6 +65,7 @@ bool in_global();
```
sh
mkdir
build
&&
cd
build
cmake ..
make clean
make
-j
# 安装库 libcminus_io.a 至系统目录
...
...
@@ -179,8 +181,8 @@ cminusfc test.cminus
*
禁止执行恶意代码,违者本次实验0分处理
*
迟交规定
*
`Soft Deadline`
: 2022/11/
07
23:59:59 (北京标准时间,UTC+8)
*
`Hard Deadline`
: 2022/11/
14
23:59:59 (北京标准时间,UTC+8)
*
`Soft Deadline`
: 2022/11/
13
23:59:59 (北京标准时间,UTC+8)
*
`Hard Deadline`
: 2022/11/
20
23:59:59 (北京标准时间,UTC+8)
*
迟交需要邮件通知TA:
*
邮箱:
`lq_2019@mail.ustc.edu.cn`
抄送
`edwardzcn@mail.ustc.edu.cn`
*
邮件主题: lab3迟交-学号-姓名
...
...
Documentations/3-ir-gen/more-tips.md
0 → 100644
View file @
720f0a57
# Lab3 补充说明
## 重要提醒
希望同学们仔细阅读实验文档
`cminusf.md`
和
`LightIR.md`
,在lab3编写的过程中也结合自己在lab2所做的工作。
如果在编写过程中不知道具体用哪些函数,可以去查看给出代码中的函数所在的头文件,里面包含部分其他需要用的函数。
## 部分函数的注释
```
c++
//存储当前value
Value
*
tmp_val
=
nullptr
;
// 当前函数
Function
*
cur_fun
=
nullptr
;
// 表示是否在之前已经进入scope,用于CompoundStmt
// 进入CompoundStmt不仅包括通过Fundeclaration进入,也包括selection-stmt等。
// pre_enter_scope用于控制是否在CompoundStmt中添加scope.enter,scope.exit
bool
pre_enter_scope
=
false
;
// types
Type
*
VOID_T
;
Type
*
INT1_T
;
Type
*
INT32_T
;
Type
*
INT32PTR_T
;
Type
*
FLOAT_T
;
Type
*
FLOATPTR_T
;
/*
* use CMinusfBuilder::Scope to construct scopes
* scope.enter: enter a new scope
* scope.exit: exit current scope
* scope.push: add a new binding to current scope
* scope.find: find and return the value bound to the name
*/
void
CminusfBuilder
::
visit
(
ASTProgram
&
node
)
{
VOID_T
=
Type
::
get_void_type
(
module
.
get
());
INT1_T
=
Type
::
get_int1_type
(
module
.
get
());
INT32_T
=
Type
::
get_int32_type
(
module
.
get
());
INT32PTR_T
=
Type
::
get_int32_ptr_type
(
module
.
get
());
FLOAT_T
=
Type
::
get_float_type
(
module
.
get
());
FLOATPTR_T
=
Type
::
get_float_ptr_type
(
module
.
get
());
for
(
auto
decl
:
node
.
declarations
)
{
// program -> declaration-list
decl
->
accept
(
*
this
);
//进入下一层函数
}
}
void
CminusfBuilder
::
visit
(
ASTFunDeclaration
&
node
)
{
FunctionType
*
fun_type
;
Type
*
ret_type
;
std
::
vector
<
Type
*>
param_types
;
if
(
node
.
type
==
TYPE_INT
)
//函数返回值类型
ret_type
=
INT32_T
;
else
if
(
node
.
type
==
TYPE_FLOAT
)
ret_type
=
FLOAT_T
;
else
ret_type
=
VOID_T
;
for
(
auto
&
param
:
node
.
params
)
{
//补全param_types
//TODO:
//根据param的类型分类
//需要考虑int型数组,int型,float型数组,float型
//对于不同的类型,向param_types中添加不同的Type
//param_types.push_back
}
fun_type
=
FunctionType
::
get
(
ret_type
,
param_types
);
auto
fun
=
Function
::
create
(
fun_type
,
node
.
id
,
module
.
get
());
//定义函数变量
scope
.
push
(
node
.
id
,
fun
);
cur_fun
=
fun
;
auto
funBB
=
BasicBlock
::
create
(
module
.
get
(),
"entry"
,
fun
);
//创建基本块
builder
->
set_insert_point
(
funBB
);
scope
.
enter
();
pre_enter_scope
=
true
;
std
::
vector
<
Value
*>
args
;
for
(
auto
arg
=
fun
->
arg_begin
();
arg
!=
fun
->
arg_end
();
arg
++
)
{
args
.
push_back
(
*
arg
);
}
for
(
int
i
=
0
;
i
<
node
.
params
.
size
();
++
i
)
{
//TODO:
//需要考虑int型数组,int型,float型数组,float型
//builder->create_alloca创建alloca语句
//builder->create_store创建store语句
//scope.push
}
node
.
compound_stmt
->
accept
(
*
this
);
//fun-declaration -> type-specifier ID ( params ) compound-stmt
if
(
builder
->
get_insert_block
()
->
get_terminator
()
==
nullptr
){
//创建ret语句
if
(
cur_fun
->
get_return_type
()
->
is_void_type
())
builder
->
create_void_ret
();
else
if
(
cur_fun
->
get_return_type
()
->
is_float_type
())
builder
->
create_ret
(
CONST_FP
(
0.
));
else
builder
->
create_ret
(
CONST_INT
(
0
));
}
scope
.
exit
();
}
void
CminusfBuilder
::
visit
(
ASTParam
&
node
)
{
}
void
CminusfBuilder
::
visit
(
ASTCompoundStmt
&
node
)
{
//TODO:此函数为完整实现
bool
need_exit_scope
=
!
pre_enter_scope
;
//添加need_exit_scope变量
if
(
pre_enter_scope
)
{
pre_enter_scope
=
false
;
}
else
{
scope
.
enter
();
}
for
(
auto
&
decl
:
node
.
local_declarations
)
{
//compound-stmt -> { local-declarations statement-list }
decl
->
accept
(
*
this
);
}
for
(
auto
&
stmt
:
node
.
statement_list
)
{
stmt
->
accept
(
*
this
);
if
(
builder
->
get_insert_block
()
->
get_terminator
()
!=
nullptr
)
break
;
}
if
(
need_exit_scope
)
{
scope
.
exit
();
}
}
void
CminusfBuilder
::
visit
(
ASTReturnStmt
&
node
)
{
//return-stmt -> return ; | return expression ;
if
(
node
.
expression
==
nullptr
)
{
builder
->
create_void_ret
();
}
else
{
//TODO:
//需要考虑类型转换
//函数返回值和表达式值类型不同时,转换成函数返回值的类型
//用cur_fun获取当前函数返回值类型
//类型转换:builder->create_fptosi
//ret语句
}
}
```
README.md
View file @
720f0a57
...
...
@@ -11,7 +11,7 @@
+
DDL:2022-10-23 23:59:59 (UTC+8)
*
[
lab3
](
./Documentations/3-ir-gen/
)
+
DDL:2022-11-
07
23:59:59 (UTC+8)
+
DDL:2022-11-
13
23:59:59 (UTC+8)
## FAQ: How to merge upstream remote branches
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment