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
b8f14d6d
Commit
b8f14d6d
authored
Oct 27, 2022
by
李晓奇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
73, very good
parent
6d308da4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
10 deletions
+31
-10
Reports/3-ir-gen/report.md
Reports/3-ir-gen/report.md
+7
-1
include/cminusf_builder.hpp
include/cminusf_builder.hpp
+1
-0
src/cminusfc/cminusf_builder.cpp
src/cminusfc/cminusf_builder.cpp
+22
-8
tests/3-ir-gen/testcases/lv1/assign_int_array_local.cminus
tests/3-ir-gen/testcases/lv1/assign_int_array_local.cminus
+1
-1
No files found.
Reports/3-ir-gen/report.md
View file @
b8f14d6d
...
...
@@ -91,7 +91,7 @@ PB20111654 李晓奇
-
全局变量要特殊对待
-
数组下标为负时要调用
`neg_idx_except()`
-
数组下标为负时要调用
`neg_idx_except()`
,这个函数的call后边也要加上br
-
神奇,bool变量不能比较,所以在比较、计算的时候要做类型转换
...
...
@@ -106,6 +106,10 @@ PB20111654 李晓奇
但后来发现,原来问题出在调用GEP,我直接吧0传入了,“胡闹吗这不是”。
-
不要乱给lable命名,因为lable的命名不会自动(针对自定义)去重。
-
发现ifelse语句忘了无条件跳转了……
-
返现布尔表达式必须使用i1类型,类型要求真的太严格了!!
## 实验设计
...
...
@@ -121,6 +125,8 @@ PB20111654 李晓奇
此次实验有什么收获
不管多困难,先开始。~~因为更多的困难在动手前是永远想不到的~~。
### 实验反馈 (可选 不计入评分)
对本次实验的建议
include/cminusf_builder.hpp
View file @
b8f14d6d
...
...
@@ -97,6 +97,7 @@ class CminusfBuilder : public ASTVisitor {
virtual
void
visit
(
ASTCall
&
)
override
final
;
void
biop_type_check
(
Value
*&
,
Value
*&
,
std
::
string
=
"computation"
);
void
cast_to_i1
(
Value
*&
);
std
::
unique_ptr
<
IRBuilder
>
builder
;
Scope
scope
;
...
...
src/cminusfc/cminusf_builder.cpp
View file @
b8f14d6d
...
...
@@ -81,6 +81,16 @@ void CminusfBuilder::biop_type_check(Value *&lvalue, Value *&rvalue, std::string
}
}
// this function makes sure value is a bool type
void
CminusfBuilder
::
cast_to_i1
(
Value
*&
value
)
{
assert
(
value
->
get_type
()
->
is_integer_type
()
or
value
->
get_type
()
->
is_float_type
());
if
(
value
->
get_type
()
->
is_float_type
())
// value = builder->create_fptosi(value, INT1_T);
value
=
builder
->
create_fcmp_ne
(
value
,
CONST_FP
(
0
));
else
if
(
Type
::
is_eq_type
(
value
->
get_type
(),
INT32_T
))
value
=
builder
->
create_icmp_ne
(
value
,
CONST_INT
(
0
));
}
void
CminusfBuilder
::
visit
(
ASTProgram
&
node
)
{
VOID_T
=
Type
::
get_void_type
(
module
.
get
());
INT1_T
=
Type
::
get_int1_type
(
module
.
get
());
...
...
@@ -303,16 +313,19 @@ void CminusfBuilder::visit(ASTSelectionStmt &node) {
scope
.
enter
();
node
.
expression
->
accept
(
*
this
);
auto
cond
=
cur_value
;
cast_to_i1
(
cond
);
auto
TBB
=
BasicBlock
::
create
(
builder
->
get_module
(),
""
,
cur_fun
);
auto
pass
BB
=
BasicBlock
::
create
(
builder
->
get_module
(),
""
,
cur_fun
);
builder
->
create_cond_br
(
cond
,
TBB
,
pass
BB
);
auto
F
BB
=
BasicBlock
::
create
(
builder
->
get_module
(),
""
,
cur_fun
);
builder
->
create_cond_br
(
cond
,
TBB
,
F
BB
);
builder
->
set_insert_point
(
TBB
);
node
.
if_statement
->
accept
(
*
this
);
builder
->
create_br
(
FBB
);
builder
->
set_insert_point
(
pass
BB
);
if
(
node
.
else_statement
)
builder
->
set_insert_point
(
F
BB
);
if
(
node
.
else_statement
)
{
node
.
else_statement
->
accept
(
*
this
);
}
scope
.
exit
();
}
...
...
@@ -330,6 +343,7 @@ void CminusfBuilder::visit(ASTIterationStmt &node) {
builder
->
set_insert_point
(
HEAD
);
node
.
expression
->
accept
(
*
this
);
auto
cond
=
cur_value
;
cast_to_i1
(
cond
);
builder
->
create_cond_br
(
cond
,
BODY
,
END
);
builder
->
set_insert_point
(
BODY
);
...
...
@@ -397,14 +411,14 @@ void CminusfBuilder::visit(ASTVar &node) {
auto
cond
=
builder
->
create_icmp_lt
(
cur_value
,
CONST_INT
(
0
));
auto
except_func
=
scope
.
find
(
"neg_idx_except"
);
auto
TBB
=
BasicBlock
::
create
(
builder
->
get_module
(),
""
,
cur_fun
);
auto
F
BB
=
BasicBlock
::
create
(
builder
->
get_module
(),
""
,
cur_fun
);
builder
->
create_cond_br
(
cond
,
TBB
,
F
BB
);
auto
pass
BB
=
BasicBlock
::
create
(
builder
->
get_module
(),
""
,
cur_fun
);
builder
->
create_cond_br
(
cond
,
TBB
,
pass
BB
);
builder
->
set_insert_point
(
TBB
);
builder
->
create_call
(
except_func
,
{});
builder
->
create_br
(
F
BB
);
builder
->
create_br
(
pass
BB
);
builder
->
set_insert_point
(
F
BB
);
builder
->
set_insert_point
(
pass
BB
);
addr
=
builder
->
create_gep
(
memory
,
{
CONST_INT
(
0
),
cur_value
});
...
...
tests/3-ir-gen/testcases/lv1/assign_int_array_local.cminus
View file @
b8f14d6d
void main(void) {
int a[10];
/* a[3] = 1234; */
a[3] = 1234;
output(a[3]);
return;
}
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