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
a0b2bd9d
Commit
a0b2bd9d
authored
Oct 10, 2022
by
李晓奇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
finish part1: hand write .ll file
parent
3b086a0e
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
252 additions
and
172 deletions
+252
-172
include/lightir/Type.h
include/lightir/Type.h
+19
-13
tests/2-ir-gen-warmup/c_cases/.gitignore
tests/2-ir-gen-warmup/c_cases/.gitignore
+1
-0
tests/2-ir-gen-warmup/stu_ll/assign_hand.ll
tests/2-ir-gen-warmup/stu_ll/assign_hand.ll
+14
-0
tests/2-ir-gen-warmup/stu_ll/fun_hand.ll
tests/2-ir-gen-warmup/stu_ll/fun_hand.ll
+9
-0
tests/2-ir-gen-warmup/stu_ll/if_hand.ll
tests/2-ir-gen-warmup/stu_ll/if_hand.ll
+11
-0
tests/2-ir-gen-warmup/stu_ll/while_hand.ll
tests/2-ir-gen-warmup/stu_ll/while_hand.ll
+25
-0
tests/2-ir-gen-warmup/ta_gcd/.gitignore
tests/2-ir-gen-warmup/ta_gcd/.gitignore
+1
-0
tests/2-ir-gen-warmup/ta_gcd/gcd_array_generator.cpp
tests/2-ir-gen-warmup/ta_gcd/gcd_array_generator.cpp
+172
-159
No files found.
include/lightir/Type.h
View file @
a0b2bd9d
...
...
@@ -11,7 +11,8 @@ class ArrayType;
class
PointerType
;
class
FloatType
;
class
Type
{
class
Type
{
public:
enum
TypeID
{
VoidTyID
,
// Void
...
...
@@ -73,11 +74,12 @@ class Type {
std
::
string
print
();
private:
TypeID
tid_
;
TypeID
tid_
;
Module
*
m_
;
};
class
IntegerType
:
public
Type
{
class
IntegerType
:
public
Type
{
public:
explicit
IntegerType
(
unsigned
num_bits
,
Module
*
m
);
...
...
@@ -89,7 +91,8 @@ class IntegerType : public Type {
unsigned
num_bits_
;
};
class
FunctionType
:
public
Type
{
class
FunctionType
:
public
Type
{
public:
FunctionType
(
Type
*
result
,
std
::
vector
<
Type
*>
params
);
...
...
@@ -100,17 +103,18 @@ class FunctionType : public Type {
unsigned
get_num_of_args
()
const
;
Type
*
get_param_type
(
unsigned
i
)
const
;
Type
*
get_param_type
(
unsigned
i
)
const
;
std
::
vector
<
Type
*>::
iterator
param_begin
()
{
return
args_
.
begin
();
}
std
::
vector
<
Type
*>::
iterator
param_end
()
{
return
args_
.
end
();
}
Type
*
get_return_type
()
const
;
Type
*
get_return_type
()
const
;
private:
Type
*
result_
;
Type
*
result_
;
std
::
vector
<
Type
*>
args_
;
};
class
ArrayType
:
public
Type
{
class
ArrayType
:
public
Type
{
public:
ArrayType
(
Type
*
contained
,
unsigned
num_elements
);
...
...
@@ -118,15 +122,16 @@ class ArrayType : public Type {
static
ArrayType
*
get
(
Type
*
contained
,
unsigned
num_elements
);
Type
*
get_element_type
()
const
{
return
contained_
;
}
Type
*
get_element_type
()
const
{
return
contained_
;
}
unsigned
get_num_of_elements
()
const
{
return
num_elements_
;
}
private:
Type
*
contained_
;
// The element type of the array.
Type
*
contained_
;
// The element type of the array.
unsigned
num_elements_
;
// Number of elements in the array.
};
class
PointerType
:
public
Type
{
class
PointerType
:
public
Type
{
public:
PointerType
(
Type
*
contained
);
Type
*
get_element_type
()
const
{
return
contained_
;
}
...
...
@@ -137,7 +142,8 @@ class PointerType : public Type {
Type
*
contained_
;
// The element type of the ptr.
};
class
FloatType
:
public
Type
{
class
FloatType
:
public
Type
{
public:
FloatType
(
Module
*
m
);
static
FloatType
*
get
(
Module
*
m
);
...
...
@@ -145,4 +151,4 @@ class FloatType : public Type {
private:
};
#endif // SYSYC_TYPE_H
\ No newline at end of file
#endif // SYSYC_TYPE_H
tests/2-ir-gen-warmup/c_cases/.gitignore
0 → 100644
View file @
a0b2bd9d
*.ll
tests/2-ir-gen-warmup/stu_ll/assign_hand.ll
View file @
a0b2bd9d
define
dso_local
i32
@main
()
#0
{
%a
=
alloca
[
10
x
i32
],
align
4
; ptr is the pointer with type i32*
%ptr
=
getelementptr
[
10
x
i32
],
[
10
x
i32
]*
%a
,
i64
0
,
i64
0
%a0
=
getelementptr
i32
,
i32
*
%ptr
,
i64
0
%a1
=
getelementptr
i32
,
i32
*
%ptr
,
i64
1
store
i32
10
,
i32
*
%a0
%v1
=
load
i32
,
i32
*
%a0
%v2
=
mul
i32
%v1
,
2
store
i32
%v2
,
i32
*
%a1
%r
=
load
i32
,
i32
*
%a1
ret
i32
%r
}
tests/2-ir-gen-warmup/stu_ll/fun_hand.ll
View file @
a0b2bd9d
define
dso_local
i32
@callee
(
i32
%0
)
#0
{
%r
=
mul
i32
%0
,
2
ret
i32
%r
}
define
dso_local
i32
@main
()
#0
{
%r
=
call
i32
@callee
(
i32
110
)
ret
i32
%r
}
tests/2-ir-gen-warmup/stu_ll/if_hand.ll
View file @
a0b2bd9d
define
i32
@main
(){
%a_ptr
=
alloca
float
store
float
0x40163851E0000000
,
float
*
%a_ptr
%a
=
load
float
,
float
*
%a_ptr
%cond
=
fcmp
ugt
float
%a
,
1.000000e+00
br
i1
%cond
,
label
%1
,
label
%2
1
:
ret
i32
233
2
:
ret
i32
0
}
tests/2-ir-gen-warmup/stu_ll/while_hand.ll
View file @
a0b2bd9d
define
dso_local
i32
@main
()
#0
{
%pa
=
alloca
i32
%pi
=
alloca
i32
store
i32
10
,
i32
*
%pa
store
i32
0
,
i32
*
%pi
br
label
%loop_head
loop_head:
%i
=
load
i32
,
i32
*
%pi
%cond
=
icmp
slt
i32
%i
,
10
br
i1
%cond
,
label
%loop_body
,
label
%over
loop_body:
%i_1
=
add
i32
%i
,
1
store
i32
%i_1
,
i32
*
%pi
%newi
=
load
i32
,
i32
*
%pi
%a
=
load
i32
,
i32
*
%pa
%a_i
=
add
i32
%a
,
%newi
store
i32
%a_i
,
i32
*
%pa
br
label
%loop_head
over:
%r
=
load
i32
,
i32
*
%pa
ret
i32
%r
}
tests/2-ir-gen-warmup/ta_gcd/.gitignore
0 → 100644
View file @
a0b2bd9d
*.ll
tests/2-ir-gen-warmup/ta_gcd/gcd_array_generator.cpp
View file @
a0b2bd9d
This diff is collapsed.
Click to expand it.
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