Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
L
Lab11
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
CP Lab Group
实验项目模板
Lab11
提交
3e586383
提交
3e586383
12月 18, 2018
创建
作者:
赵鹏翀
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
init template
上级
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
250 行增加
和
0 行删除
+250
-0
.gitignore
.gitignore
+2
-0
T2P.cplproj
T2P.cplproj
+37
-0
T2P.h
T2P.h
+98
-0
T2P.puo
T2P.puo
+0
-0
main.c
main.c
+113
-0
没有找到文件。
.gitignore
0 → 100644
浏览文件 @
3e586383
/Debug
/Release
T2P.cplproj
0 → 100644
浏览文件 @
3e586383
<?xml version="1.0" encoding="gb2312"?>
<OSLProject
Version=
"1.00"
Name=
"T2P"
SubjectID=
"11c951f4-9b13-40e1-8b73-39ba7d73b89b"
ProjectTemplateID=
"fd94d6b7-a1cb-476c-9ed6-754f09d7a263"
>
<Configurations>
<Configuration
Name=
"Debug"
>
<Tool
Name=
"PreBuildEventTool"
/>
<Tool
Name=
"CustomBuildTool"
/>
<Tool
Name=
"GCCCompilerTool"
PreprocessorDefinitions=
"_DEBUG"
GenerateDebugInformation=
"-1"
/>
<Tool
Name=
"PreLinkEventTool"
/>
<Tool
Name=
"GCCLinkerTool"
AdditionalDependencies=
""$(CPLInstallDir)Dump\lib\T2P_Demo.o""
/>
<Tool
Name=
"PostBuildEventTool"
/>
<VisualContext>
<WatchPoints>
<WatchPoint
FunctionName=
"T2P"
ObserverID=
"6AD9E1B5-8136-4c4d-AD6F-8782E69D5C3B"
>
</WatchPoint>
</WatchPoints>
</VisualContext>
</Configuration>
<Configuration
Name=
"Release"
>
<Tool
Name=
"PreBuildEventTool"
/>
<Tool
Name=
"CustomBuildTool"
/>
<Tool
Name=
"GCCCompilerTool"
PreprocessorDefinitions=
"NDEBUG"
/>
<Tool
Name=
"PreLinkEventTool"
/>
<Tool
Name=
"GCCLinkerTool"
/>
<Tool
Name=
"PostBuildEventTool"
/>
</Configuration>
</Configurations>
<Files>
<Filter
Name=
"ͷļ"
Filter=
"h;hpp;hxx"
>
<File
RelativePath=
".\T2P.h"
>
</File>
</Filter>
<Filter
Name=
"Դļ"
Filter=
"cpp;c;cc;cxx"
>
<File
RelativePath=
".\main.c"
>
</File>
</Filter>
</Files>
</OSLProject>
T2P.h
0 → 100644
浏览文件 @
3e586383
#ifndef _T2P_H_
#define _T2P_H_
//
// 在此处包含 C 标准库头文件
//
#include <stdio.h>
//
// 在此处包含其他头文件
//
//
// 在此处定义数据结构
//
#define MAX_STR_LENGTH 64
#define MAX_CODE_COUNT 64
// 地址类型
typedef
enum
_AddrKind
{
empty
,
// 空
intconst
,
// 整数常量
string
// 字符串
}
AddrKind
;
// 地址
typedef
struct
_Address
{
AddrKind
Kind
;
// 地址的类型。这个域是一个枚举类型
int
Value
;
// 地址的值。地址类型为整数常量时,这个域有效
char
Name
[
MAX_STR_LENGTH
];
// 地址的值。地址类型为字符串时,这个域有效
}
Address
;
// 三地址码指令类型
typedef
enum
_TOpKind
{
t_rd
=
1
,
// 注意,从 1 开始
t_gt
,
t_if_f
,
t_asn
,
t_lab
,
t_mul
,
t_sub
,
t_eq
,
t_wri
,
t_halt
}
TOpKind
;
// 三地址码
typedef
struct
_TCode
{
TOpKind
Kind
;
// 三地址码指令类型
Address
Addr1
,
Addr2
,
Addr3
;
// 三个地址
}
TCode
;
// P-代码指令类型
typedef
enum
_POpKind
{
p_lda
=
1
,
// 注意,从 1 开始
p_rdi
,
p_lod
,
p_ldc
,
p_grt
,
p_fjp
,
p_sto
,
p_lab
,
p_mpi
,
p_sbi
,
p_equ
,
p_wri
,
p_stp
}
POpKind
;
// P-代码
typedef
struct
_PCode
{
POpKind
Kind
;
// P-代码指令类型
Address
Addr
;
// 地址
}
PCode
;
//
// 在此处声明函数
//
void
T2P
(
TCode
*
TCodeList
,
PCode
*
PCodeList
);
void
InitTCodeList
(
TCode
*
pTCodeList
);
//
// 在此声明全局变量
//
#endif // _T2P_H_
T2P.puo
0 → 100644
浏览文件 @
3e586383
添加文件
main.c
0 → 100644
浏览文件 @
3e586383
#include "T2P.h"
int
main
()
{
TCode
TCodeList
[
MAX_CODE_COUNT
];
// 三地址码列表
PCode
PCodeList
[
MAX_CODE_COUNT
];
// P-代码列表
// 将三地址码列表和P-代码列表的内容清空
memset
(
TCodeList
,
0
,
sizeof
(
TCodeList
));
memset
(
PCodeList
,
0
,
sizeof
(
PCodeList
));
//
// 初始化三地址码列表
//
InitTCodeList
(
TCodeList
);
//
// 将三地址码转换为P-代码
//
T2P
(
TCodeList
,
PCodeList
);
return
0
;
}
/*
功能:
将三地址码转换为 P-代码。
参数:
TCodeList -- 三地址码列表指针。
PCodeList -- P-代码列表指针。
*/
void
T2P
(
TCode
*
TCodeList
,
PCode
*
PCodeList
)
{
int
TIndex
=
0
;
// 三地址码列表游标
int
PIndex
=
0
;
// P-代码列表游标
//
// TODO: 在此添加代码
//
}
typedef
struct
_AddressEntry
{
AddrKind
Kind
;
const
char
*
Content
;
}
AddressEntry
;
typedef
struct
_TCodeEntry
{
TOpKind
Kind
;
AddressEntry
Addr1
,
Addr2
,
Addr3
;
}
TCodeEntry
;
static
const
TCodeEntry
TCodeTable
[]
=
{
{
t_rd
,
{
string
,
"x"
}
},
{
t_mul
,
{
string
,
"x"
},
{
intconst
,
"2"
},
{
string
,
"t1"
}
},
{
t_asn
,
{
string
,
"t1"
},
{
string
,
"x"
}
},
{
t_if_f
,
{
string
,
"x"
},
{
string
,
"L1"
}
},
{
t_wri
,
{
string
,
"x"
}
},
{
t_lab
,
{
string
,
"L1"
}
},
{
t_halt
}
};
/*
功能:
初始化地址。
参数:
pEntry -- 用于初始化地址的结构体。
pAddr -- 地址指针。
*/
void
InitAddress
(
const
AddressEntry
*
pEntry
,
Address
*
pAddr
)
{
pAddr
->
Kind
=
pEntry
->
Kind
;
switch
(
pAddr
->
Kind
)
{
case
empty
:
break
;
case
intconst
:
pAddr
->
Value
=
atoi
(
pEntry
->
Content
);
break
;
case
string
:
strcpy
(
pAddr
->
Name
,
pEntry
->
Content
);
break
;
}
}
/*
功能:
初始化三地址码列表。
参数:
pTCodeList -- 三地址码列表指针。
*/
void
InitTCodeList
(
TCode
*
pTCodeList
)
{
int
i
;
int
EntryCount
=
sizeof
(
TCodeTable
)
/
sizeof
(
TCodeTable
[
0
]);
for
(
i
=
0
;
i
<
EntryCount
;
i
++
)
{
pTCodeList
[
i
].
Kind
=
TCodeTable
[
i
].
Kind
;
InitAddress
(
&
TCodeTable
[
i
].
Addr1
,
&
pTCodeList
[
i
].
Addr1
);
InitAddress
(
&
TCodeTable
[
i
].
Addr2
,
&
pTCodeList
[
i
].
Addr2
);
InitAddress
(
&
TCodeTable
[
i
].
Addr3
,
&
pTCodeList
[
i
].
Addr3
);
}
}
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论