提交 b8622b1b 创建 作者: 宋海霞's avatar 宋海霞

modify main.c

上级 f1204a35
......@@ -46,11 +46,193 @@ void T2P(TCode* TCodeList, PCode* PCodeList)
{
int TIndex = 0; // 三地址码列表游标
int PIndex = 0; // P-代码列表游标
//
// TODO: 在此添加代码
//
for( ; TCodeList[TIndex].Kind != 0; TIndex++)
{
switch(TCodeList[TIndex].Kind)
{
case t_rd:
// 产生一条 lda 指令
PCodeList[PIndex].Kind = p_lda;
PCodeList[PIndex].Addr.Kind = string;
strcpy(PCodeList[PIndex].Addr.Name, TCodeList[TIndex].Addr1.Name);
PIndex++;
// 产生一条 rdi 指令
PCodeList[PIndex].Kind = p_rdi;
PIndex++;
break;
case t_gt:
// 将 gt 指令转换成 P-代码
//
// TODO: 在此添加代码
//
break;
case t_if_f:
if(TCodeList[TIndex].Addr1.Kind == intconst)
{
// 产生一条 ldc 指令
PCodeList[PIndex].Kind = p_ldc;
PCodeList[PIndex].Addr.Kind = intconst;
PCodeList[PIndex].Addr.Value = TCodeList[TIndex].Addr1.Value;
}
else
{
// 产生一条 lod 指令
PCodeList[PIndex].Kind = p_lod;
PCodeList[PIndex].Addr.Kind = string;
strcpy(PCodeList[PIndex].Addr.Name, TCodeList[TIndex].Addr1.Name);
}
PIndex++;
// 产生一条 fjp 指令
PCodeList[PIndex].Kind = p_fjp;
PCodeList[PIndex].Addr.Kind = string;
strcpy(PCodeList[PIndex].Addr.Name, TCodeList[TIndex].Addr2.Name);
PIndex++;
break;
case t_asn:
// 产生一条 lda 指令
PCodeList[PIndex].Kind = p_lda;
PCodeList[PIndex].Addr.Kind = string;
strcpy(PCodeList[PIndex].Addr.Name, TCodeList[TIndex].Addr2.Name);
PIndex++;
if(TCodeList[TIndex].Addr1.Kind == intconst)
{
// 产生一条 ldc 指令
PCodeList[PIndex].Kind = p_ldc;
PCodeList[PIndex].Addr.Kind = intconst;
PCodeList[PIndex].Addr.Value = TCodeList[TIndex].Addr1.Value;
}
else
{
// 产生一条 lod 指令
PCodeList[PIndex].Kind = p_lod;
PCodeList[PIndex].Addr.Kind = string;
strcpy(PCodeList[PIndex].Addr.Name, TCodeList[TIndex].Addr1.Name);
}
PIndex++;
// 产生一条 sto 指令
PCodeList[PIndex].Kind = p_sto;
PIndex++;
break;
case t_lab:
// 将 lab 指令转换成 P-代码
//
// TODO: 在此添加代码
//
break;
case t_mul:
// 产生一条 lda 指令
PCodeList[PIndex].Kind = p_lda;
PCodeList[PIndex].Addr.Kind = string;
strcpy(PCodeList[PIndex].Addr.Name, TCodeList[TIndex].Addr3.Name);
PIndex++;
if(TCodeList[TIndex].Addr1.Kind == intconst)
{
// 产生一条 ldc 指令
PCodeList[PIndex].Kind = p_ldc;
PCodeList[PIndex].Addr.Kind = intconst;
PCodeList[PIndex].Addr.Value = TCodeList[TIndex].Addr1.Value;
}
else
{
// 产生一条 lod 指令
PCodeList[PIndex].Kind = p_lod;
PCodeList[PIndex].Addr.Kind = string;
strcpy(PCodeList[PIndex].Addr.Name, TCodeList[TIndex].Addr1.Name);
}
PIndex++;
if(TCodeList[TIndex].Addr1.Kind == intconst)
{
// 产生一条 ldc 指令
PCodeList[PIndex].Kind = p_ldc;
PCodeList[PIndex].Addr.Kind = intconst;
PCodeList[PIndex].Addr.Value = TCodeList[TIndex].Addr2.Value;
}
else
{
// 产生一条 lod 指令
PCodeList[PIndex].Kind = p_lod;
PCodeList[PIndex].Addr.Kind = string;
strcpy(PCodeList[PIndex].Addr.Name, TCodeList[TIndex].Addr2.Name);
}
PIndex++;
// 产生一条 mpi 指令
PCodeList[PIndex].Kind = p_mpi;
PIndex++;
// 产生一条 sto 指令
PCodeList[PIndex].Kind = p_sto;
PIndex++;
break;
case t_sub:
// 将 sub 指令转换成 P-代码
//
// TODO: 在此添加代码
//
break;
case t_eq:
// 将 eq 指令转换成 P-代码
//
// TODO: 在此添加代码
//
break;
case t_wri:
// 将 wri 指令转换成 P-代码
//
// TODO: 在此添加代码
//
break;
case t_halt:
// 将 halt 指令转换成 P-代码
//
// TODO: 在此添加代码
//
break;
}
}
}
typedef struct _AddressEntry
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论