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
d2f3c996
Commit
d2f3c996
authored
Oct 27, 2022
by
李晓奇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
53 points!
parent
1de803c9
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
28 deletions
+14
-28
Reports/3-ir-gen/report.md
Reports/3-ir-gen/report.md
+2
-0
src/cminusfc/cminusf_builder.cpp
src/cminusfc/cminusf_builder.cpp
+12
-9
tests/3-ir-gen/testcases/lv1/assign_int_var_local.ll
tests/3-ir-gen/testcases/lv1/assign_int_var_local.ll
+0
-19
No files found.
Reports/3-ir-gen/report.md
View file @
d2f3c996
...
@@ -99,6 +99,8 @@ PB20111654 李晓奇
...
@@ -99,6 +99,8 @@ PB20111654 李晓奇
-
神奇,bool变量不能比较,所以在比较、计算的时候要做类型转换
-
神奇,bool变量不能比较,所以在比较、计算的时候要做类型转换
-
store的顺序颠倒了!!
## 实验设计
## 实验设计
请写明为了顺利完成本次实验,加入了哪些亮点设计,并对这些设计进行解释。
请写明为了顺利完成本次实验,加入了哪些亮点设计,并对这些设计进行解释。
...
...
src/cminusfc/cminusf_builder.cpp
View file @
d2f3c996
...
@@ -136,18 +136,20 @@ void CminusfBuilder::visit(ASTVarDeclaration &node) {
...
@@ -136,18 +136,20 @@ void CminusfBuilder::visit(ASTVarDeclaration &node) {
case
TYPE_INT
:
{
case
TYPE_INT
:
{
auto
I32Array_T
=
Type
::
get_array_type
(
INT32_T
,
size
);
auto
I32Array_T
=
Type
::
get_array_type
(
INT32_T
,
size
);
if
(
global
)
if
(
global
)
cur_value
=
GlobalVariable
::
create
(
node
.
id
,
builder
->
get_module
(),
I32Array_T
,
false
,
I32Initializer
);
GlobalVariable
::
create
(
node
.
id
,
builder
->
get_module
(),
I32Array_T
,
false
,
I32Initializer
);
else
else
builder
->
create_alloca
(
I32Array_T
);
cur_value
=
builder
->
create_alloca
(
I32Array_T
);
break
;
break
;
}
}
case
TYPE_FLOAT
:
{
case
TYPE_FLOAT
:
{
auto
FloatArray_T
=
Type
::
get_array_type
(
FLOAT_T
,
size
);
auto
FloatArray_T
=
Type
::
get_array_type
(
FLOAT_T
,
size
);
if
(
global
)
if
(
global
)
cur_value
=
GlobalVariable
::
create
(
node
.
id
,
builder
->
get_module
(),
FloatArray_T
,
false
,
FloatInitializer
);
GlobalVariable
::
create
(
node
.
id
,
builder
->
get_module
(),
FloatArray_T
,
false
,
FloatInitializer
);
else
else
builder
->
create_alloca
(
FloatArray_T
);
cur_value
=
builder
->
create_alloca
(
FloatArray_T
);
break
;
break
;
}
}
default:
default:
...
@@ -159,16 +161,17 @@ void CminusfBuilder::visit(ASTVarDeclaration &node) {
...
@@ -159,16 +161,17 @@ void CminusfBuilder::visit(ASTVarDeclaration &node) {
switch
(
node
.
type
)
{
switch
(
node
.
type
)
{
case
TYPE_INT
:
case
TYPE_INT
:
if
(
global
)
if
(
global
)
GlobalVariable
::
create
(
node
.
id
,
builder
->
get_module
(),
INT32_T
,
false
,
I32Initializer
);
cur_value
=
GlobalVariable
::
create
(
node
.
id
,
builder
->
get_module
(),
INT32_T
,
false
,
I32Initializer
);
else
else
builder
->
create_alloca
(
INT32_T
);
cur_value
=
builder
->
create_alloca
(
INT32_T
);
break
;
break
;
case
TYPE_FLOAT
:
case
TYPE_FLOAT
:
if
(
global
)
if
(
global
)
cur_value
=
GlobalVariable
::
create
(
node
.
id
,
builder
->
get_module
(),
FLOAT_T
,
false
,
FloatInitializer
);
GlobalVariable
::
create
(
node
.
id
,
builder
->
get_module
(),
FLOAT_T
,
false
,
FloatInitializer
);
else
else
builder
->
create_alloca
(
INT32_T
);
cur_value
=
builder
->
create_alloca
(
INT32_T
);
break
;
break
;
default:
default:
error_exit
(
"Variable type(not array) is not int or float"
);
error_exit
(
"Variable type(not array) is not int or float"
);
...
@@ -432,7 +435,7 @@ void CminusfBuilder::visit(ASTAssignExpression &node) {
...
@@ -432,7 +435,7 @@ void CminusfBuilder::visit(ASTAssignExpression &node) {
error_exit
(
"bad type for assignment"
);
error_exit
(
"bad type for assignment"
);
}
}
// gen code
// gen code
builder
->
create_store
(
addr
,
cur_value
);
builder
->
create_store
(
cur_value
,
addr
);
}
}
// Done
// Done
...
...
tests/3-ir-gen/testcases/lv1/assign_int_var_local.ll
deleted
100644 → 0
View file @
1de803c9
; ModuleID = 'cminus'
source_filename
=
"assign_int_var_local.cminus"
declare
i32
@input
()
declare
void
@output
(
i32
)
declare
void
@outputFloat
(
float
)
declare
void
@neg_idx_except
()
define
void
@main
()
{
label_entry:
%op0
=
alloca
i32
store
i32
*
%op0
,
i32
1234
%op1
=
load
i32
,
i32
*
%op0
call
void
@output
(
i32
%op1
)
ret
void
}
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