Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
2
2025ustc-jianmu-compiler
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
74
Issues
74
List
Boards
Labels
Service Desk
Milestones
Merge Requests
52
Merge Requests
52
CI / CD
CI / CD
Pipelines
Jobs
Schedules
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
compiler_staff
2025ustc-jianmu-compiler
Commits
5d4ea841
Commit
5d4ea841
authored
Nov 26, 2025
by
Yang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add lldb Type summary
parent
04681c6c
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
69 additions
and
32 deletions
+69
-32
.gitignore
.gitignore
+2
-1
.vscode/launch.json
.vscode/launch.json
+8
-2
include/lightir/BasicBlock.hpp
include/lightir/BasicBlock.hpp
+14
-3
include/lightir/Constant.hpp
include/lightir/Constant.hpp
+2
-1
lldb_formatters.py
lldb_formatters.py
+23
-0
src/lightir/Constant.cpp
src/lightir/Constant.cpp
+11
-5
src/lightir/Function.cpp
src/lightir/Function.cpp
+0
-15
src/lightir/Type.cpp
src/lightir/Type.cpp
+7
-4
tests/1-parser/.gitignore
tests/1-parser/.gitignore
+2
-1
No files found.
.gitignore
View file @
5d4ea841
...
@@ -4,3 +4,4 @@ build/
...
@@ -4,3 +4,4 @@ build/
out
out
CMakePresets.json
CMakePresets.json
Folder.DotSettings.user
Folder.DotSettings.user
.env
\ No newline at end of file
.vscode/launch.json
View file @
5d4ea841
...
@@ -16,7 +16,10 @@
...
@@ -16,7 +16,10 @@
//
程序运行的目录
//
程序运行的目录
"cwd"
:
"${workspaceFolder}"
,
"cwd"
:
"${workspaceFolder}"
,
//
程序运行前运行的命令(例如
build)
//
程序运行前运行的命令(例如
build)
"preLaunchTask"
:
"make cminusfc"
"preLaunchTask"
:
"make cminusfc"
,
"initCommands"
:
[
"command script import ${workspaceFolder}/lldb_formatters.py"
]
},
},
{
{
"type"
:
"lldb"
,
"type"
:
"lldb"
,
...
@@ -32,7 +35,10 @@
...
@@ -32,7 +35,10 @@
"./build/1.cminus"
"./build/1.cminus"
],
],
//
程序运行的目录
//
程序运行的目录
"cwd"
:
"${workspaceFolder}"
"cwd"
:
"${workspaceFolder}"
,
"initCommands"
:
[
"command script import ${workspaceFolder}/lldb_formatters.py"
]
}
}
]
]
}
}
\ No newline at end of file
include/lightir/BasicBlock.hpp
View file @
5d4ea841
...
@@ -27,9 +27,20 @@ class BasicBlock : public Value {
...
@@ -27,9 +27,20 @@ class BasicBlock : public Value {
std
::
list
<
BasicBlock
*>
&
get_pre_basic_blocks
()
{
return
pre_bbs_
;
}
std
::
list
<
BasicBlock
*>
&
get_pre_basic_blocks
()
{
return
pre_bbs_
;
}
std
::
list
<
BasicBlock
*>
&
get_succ_basic_blocks
()
{
return
succ_bbs_
;
}
std
::
list
<
BasicBlock
*>
&
get_succ_basic_blocks
()
{
return
succ_bbs_
;
}
void
add_pre_basic_block
(
BasicBlock
*
bb
)
{
pre_bbs_
.
push_back
(
bb
);
}
// 自动去重
void
add_succ_basic_block
(
BasicBlock
*
bb
)
{
succ_bbs_
.
push_back
(
bb
);
}
void
add_pre_basic_block
(
BasicBlock
*
bb
)
{
for
(
auto
i
:
pre_bbs_
)
if
(
i
==
bb
)
return
;
pre_bbs_
.
push_back
(
bb
);
}
// 自动去重
void
add_succ_basic_block
(
BasicBlock
*
bb
)
{
for
(
auto
i
:
succ_bbs_
)
if
(
i
==
bb
)
return
;
succ_bbs_
.
push_back
(
bb
);
}
void
remove_pre_basic_block
(
BasicBlock
*
bb
)
{
pre_bbs_
.
remove
(
bb
);
}
void
remove_pre_basic_block
(
BasicBlock
*
bb
)
{
pre_bbs_
.
remove
(
bb
);
}
// 若你将 br label0, label0 的其中一个 label0 改为 label1,并且调用 remove_suc label0,那 suc 集合中也将不再包含 label0
void
remove_succ_basic_block
(
BasicBlock
*
bb
)
{
succ_bbs_
.
remove
(
bb
);
}
void
remove_succ_basic_block
(
BasicBlock
*
bb
)
{
succ_bbs_
.
remove
(
bb
);
}
BasicBlock
*
get_entry_block_of_same_function
()
const
;
BasicBlock
*
get_entry_block_of_same_function
()
const
;
...
...
include/lightir/Constant.hpp
View file @
5d4ea841
...
@@ -15,12 +15,13 @@ public:
...
@@ -15,12 +15,13 @@ public:
Constant
(
Type
*
ty
,
const
std
::
string
&
name
=
""
)
:
User
(
ty
,
name
)
{}
Constant
(
Type
*
ty
,
const
std
::
string
&
name
=
""
)
:
User
(
ty
,
name
)
{}
~
Constant
()
override
;
~
Constant
()
override
;
protected:
};
};
class
ConstantInt
:
public
Constant
{
class
ConstantInt
:
public
Constant
{
private:
private:
int
value_
;
int
value_
;
ConstantInt
(
Type
*
ty
,
int
val
)
:
Constant
(
ty
,
""
),
value_
(
val
)
{}
ConstantInt
(
Type
*
ty
,
int
val
)
:
Constant
(
ty
,
""
),
value_
(
val
)
{}
public:
public:
int
get_value
()
const
{
return
value_
;
}
int
get_value
()
const
{
return
value_
;
}
...
...
lldb_formatters.py
0 → 100644
View file @
5d4ea841
import
lldb
def
parseString
(
val
:
lldb
.
SBValue
):
summary
=
val
.
GetSummary
()
or
val
.
GetValue
()
if
summary
:
# 去掉两端引号,只留裸文本(可选)
if
summary
.
startswith
(
'"'
)
and
summary
.
endswith
(
'"'
):
summary
=
summary
[
1
:
-
1
]
return
summary
return
""
def
TypePrinterSummary
(
valobj
:
lldb
.
SBValue
,
internal_dict
):
# 调用 print 函数进行显示
name
:
lldb
.
SBValue
=
valobj
.
EvaluateExpression
(
"print()"
);
return
parseString
(
name
)
def
__lldb_init_module
(
debugger
:
lldb
.
SBDebugger
,
internal_dict
):
types
=
[
"Type"
,
"IntegerType"
,
"FunctionType"
,
"ArrayType"
,
"PointerType"
,
"FloatType"
]
for
i
in
types
:
debugger
.
HandleCommand
(
f"type summary add -F lldb_formatters.TypePrinterSummary
{
i
}
-w my"
)
debugger
.
HandleCommand
(
"type category enable my"
)
\ No newline at end of file
src/lightir/Constant.cpp
View file @
5d4ea841
...
@@ -34,16 +34,18 @@ Constant::~Constant() = default;
...
@@ -34,16 +34,18 @@ Constant::~Constant() = default;
ConstantInt
*
ConstantInt
::
get
(
int
val
,
Module
*
m
)
{
ConstantInt
*
ConstantInt
::
get
(
int
val
,
Module
*
m
)
{
if
(
cached_int
.
find
(
std
::
make_pair
(
val
,
m
))
!=
cached_int
.
end
())
if
(
cached_int
.
find
(
std
::
make_pair
(
val
,
m
))
!=
cached_int
.
end
())
return
cached_int
[
std
::
make_pair
(
val
,
m
)].
get
();
return
cached_int
[
std
::
make_pair
(
val
,
m
)].
get
();
return
(
cached_int
[
std
::
make_pair
(
val
,
m
)]
=
std
::
unique_ptr
<
ConstantInt
>
(
ConstantInt
*
ret
=
(
cached_int
[
std
::
make_pair
(
val
,
m
)]
=
std
::
unique_ptr
<
ConstantInt
>
(
new
ConstantInt
(
m
->
get_int32_type
(),
val
)))
new
ConstantInt
(
m
->
get_int32_type
(),
val
)))
.
get
();
.
get
();
return
ret
;
}
}
ConstantInt
*
ConstantInt
::
get
(
bool
val
,
Module
*
m
)
{
ConstantInt
*
ConstantInt
::
get
(
bool
val
,
Module
*
m
)
{
if
(
cached_bool
.
find
(
std
::
make_pair
(
val
,
m
))
!=
cached_bool
.
end
())
if
(
cached_bool
.
find
(
std
::
make_pair
(
val
,
m
))
!=
cached_bool
.
end
())
return
cached_bool
[
std
::
make_pair
(
val
,
m
)].
get
();
return
cached_bool
[
std
::
make_pair
(
val
,
m
)].
get
();
return
(
cached_bool
[
std
::
make_pair
(
val
,
m
)]
=
std
::
unique_ptr
<
ConstantInt
>
(
auto
ret
=
(
cached_bool
[
std
::
make_pair
(
val
,
m
)]
=
std
::
unique_ptr
<
ConstantInt
>
(
new
ConstantInt
(
m
->
get_int1_type
(),
val
?
1
:
0
)))
new
ConstantInt
(
m
->
get_int1_type
(),
val
?
1
:
0
)))
.
get
();
.
get
();
return
ret
;
}
}
std
::
string
ConstantInt
::
print
()
{
std
::
string
ConstantInt
::
print
()
{
std
::
string
const_ir
;
std
::
string
const_ir
;
...
@@ -73,7 +75,8 @@ Constant *ConstantArray::get_element_value(int index) const
...
@@ -73,7 +75,8 @@ Constant *ConstantArray::get_element_value(int index) const
ConstantArray
*
ConstantArray
::
get
(
ArrayType
*
ty
,
ConstantArray
*
ConstantArray
::
get
(
ArrayType
*
ty
,
const
std
::
vector
<
Constant
*>
&
val
)
{
const
std
::
vector
<
Constant
*>
&
val
)
{
return
new
ConstantArray
(
ty
,
val
);
auto
ret
=
new
ConstantArray
(
ty
,
val
);
return
ret
;
}
}
std
::
string
ConstantArray
::
print
()
{
std
::
string
ConstantArray
::
print
()
{
...
@@ -98,9 +101,10 @@ std::string ConstantArray::print() {
...
@@ -98,9 +101,10 @@ std::string ConstantArray::print() {
ConstantFP
*
ConstantFP
::
get
(
float
val
,
Module
*
m
)
{
ConstantFP
*
ConstantFP
::
get
(
float
val
,
Module
*
m
)
{
if
(
cached_float
.
find
(
std
::
make_pair
(
val
,
m
))
!=
cached_float
.
end
())
if
(
cached_float
.
find
(
std
::
make_pair
(
val
,
m
))
!=
cached_float
.
end
())
return
cached_float
[
std
::
make_pair
(
val
,
m
)].
get
();
return
cached_float
[
std
::
make_pair
(
val
,
m
)].
get
();
return
(
cached_float
[
std
::
make_pair
(
val
,
m
)]
=
std
::
unique_ptr
<
ConstantFP
>
(
auto
ret
=
(
cached_float
[
std
::
make_pair
(
val
,
m
)]
=
std
::
unique_ptr
<
ConstantFP
>
(
new
ConstantFP
(
m
->
get_float_type
(),
val
)))
new
ConstantFP
(
m
->
get_float_type
(),
val
)))
.
get
();
.
get
();
return
ret
;
}
}
std
::
string
ConstantFP
::
print
()
{
std
::
string
ConstantFP
::
print
()
{
...
@@ -116,7 +120,9 @@ std::string ConstantFP::print() {
...
@@ -116,7 +120,9 @@ std::string ConstantFP::print() {
ConstantZero
*
ConstantZero
::
get
(
Type
*
ty
,
Module
*
m
)
{
ConstantZero
*
ConstantZero
::
get
(
Type
*
ty
,
Module
*
m
)
{
if
(
not
cached_zero
[
ty
])
if
(
not
cached_zero
[
ty
])
{
cached_zero
[
ty
]
=
std
::
unique_ptr
<
ConstantZero
>
(
new
ConstantZero
(
ty
));
cached_zero
[
ty
]
=
std
::
unique_ptr
<
ConstantZero
>
(
new
ConstantZero
(
ty
));
}
return
cached_zero
[
ty
].
get
();
return
cached_zero
[
ty
].
get
();
}
}
...
...
src/lightir/Function.cpp
View file @
5d4ea841
...
@@ -159,21 +159,6 @@ void Function::check_for_block_relation_error() const
...
@@ -159,21 +159,6 @@ void Function::check_for_block_relation_error() const
assert
((
bbs
.
count
(
i
))
&&
"函数 F 的基本块表中包含基本块 a, a 的前驱块表中的某基本块 b 不在 F 的基本块表中"
);
assert
((
bbs
.
count
(
i
))
&&
"函数 F 的基本块表中包含基本块 a, a 的前驱块表中的某基本块 b 不在 F 的基本块表中"
);
}
}
}
}
// 检查基本块的前驱和后继表不包含重复的基本块
/*
for (auto& bb : basic_blocks_)
{
bbs.clear();
for(auto suc: bb.get_succ_basic_blocks()){
assert((!bbs.count(suc)) && "基本块的后继表中包含重复项目");
bbs.emplace(suc);
}
for(auto suc: bb.get_pre_basic_blocks()){
assert((!bbs.count(suc)) && "基本块的前驱表中包含重复项目");
bbs.emplace(suc);
}
}
*/
// 检查基本块基本信息
// 检查基本块基本信息
for
(
auto
bb
:
basic_blocks_
)
for
(
auto
bb
:
basic_blocks_
)
{
{
...
...
src/lightir/Type.cpp
View file @
5d4ea841
...
@@ -112,14 +112,16 @@ std::string Type::print() const {
...
@@ -112,14 +112,16 @@ std::string Type::print() const {
}
}
IntegerType
::
IntegerType
(
unsigned
num_bits
,
Module
*
m
)
IntegerType
::
IntegerType
(
unsigned
num_bits
,
Module
*
m
)
:
Type
(
Type
::
IntegerTyID
,
m
),
num_bits_
(
num_bits
)
{}
:
Type
(
Type
::
IntegerTyID
,
m
),
num_bits_
(
num_bits
)
{
}
IntegerType
::~
IntegerType
()
=
default
;
IntegerType
::~
IntegerType
()
=
default
;
unsigned
IntegerType
::
get_num_bits
()
const
{
return
num_bits_
;
}
unsigned
IntegerType
::
get_num_bits
()
const
{
return
num_bits_
;
}
FunctionType
::
FunctionType
(
Type
*
result
,
const
std
::
vector
<
Type
*>&
params
)
FunctionType
::
FunctionType
(
Type
*
result
,
const
std
::
vector
<
Type
*>&
params
)
:
Type
(
Type
::
FunctionTyID
,
nullptr
)
{
:
Type
(
Type
::
FunctionTyID
,
result
->
get_module
()
)
{
assert
(
is_valid_return_type
(
result
)
&&
"Invalid return type for function!"
);
assert
(
is_valid_return_type
(
result
)
&&
"Invalid return type for function!"
);
result_
=
result
;
result_
=
result
;
...
@@ -171,7 +173,7 @@ ArrayType *ArrayType::get(Type *contained, unsigned num_elements) {
...
@@ -171,7 +173,7 @@ ArrayType *ArrayType::get(Type *contained, unsigned num_elements) {
PointerType
::
PointerType
(
Type
*
contained
)
PointerType
::
PointerType
(
Type
*
contained
)
:
Type
(
Type
::
PointerTyID
,
contained
->
get_module
()),
contained_
(
contained
)
{
:
Type
(
Type
::
PointerTyID
,
contained
->
get_module
()),
contained_
(
contained
)
{
static
constexpr
std
::
array
allowed_elem_type
=
{
static
constexpr
std
::
array
<
Type
::
TypeID
,
4
>
allowed_elem_type
=
{
Type
::
IntegerTyID
,
Type
::
FloatTyID
,
Type
::
ArrayTyID
,
Type
::
PointerTyID
};
Type
::
IntegerTyID
,
Type
::
FloatTyID
,
Type
::
ArrayTyID
,
Type
::
PointerTyID
};
auto
elem_type_id
=
contained
->
get_type_id
();
auto
elem_type_id
=
contained
->
get_type_id
();
assert
(
std
::
find
(
allowed_elem_type
.
begin
(),
allowed_elem_type
.
end
(),
assert
(
std
::
find
(
allowed_elem_type
.
begin
(),
allowed_elem_type
.
end
(),
...
@@ -185,7 +187,8 @@ PointerType *PointerType::get(Type *contained) {
...
@@ -185,7 +187,8 @@ PointerType *PointerType::get(Type *contained) {
return
contained
->
get_module
()
->
get_pointer_type
(
contained
);
return
contained
->
get_module
()
->
get_pointer_type
(
contained
);
}
}
FloatType
::
FloatType
(
Module
*
m
)
:
Type
(
Type
::
FloatTyID
,
m
)
{}
FloatType
::
FloatType
(
Module
*
m
)
:
Type
(
Type
::
FloatTyID
,
m
)
{
}
FloatType
::~
FloatType
()
=
default
;
FloatType
::~
FloatType
()
=
default
;
...
...
tests/1-parser/.gitignore
View file @
5d4ea841
output_student_ast
output_student_ast
output_student
\ No newline at end of file
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