提交 5aff9b68 创建 作者: demo10's avatar demo10

modify

上级 3e586383
流水线 #859 已失败 于阶段
用时 36 秒
image: "registry.cn-hangzhou.aliyuncs.com/engintime/ubuntu_16.04_program:latest"
stages:
- make
- code-analysis
- case1
variables:
TEACHERCHECK_REPO: "engintime/cp-lab/teachers-packet/Lab011.git"
.codecode-runner: &codecode-runner
tags:
- ubuntu-16.04
- short-job
make:
stage: make
<<: *codecode-runner
script:
- make
- ./app < input1.txt > user_output1.txt
- execscore.sh 40
only:
- master
code-analysis:
stage: code-analysis
<<: *codecode-runner
script:
- make
- mkdir -p build
- cppcheck -v --force --enable=all --xml -I./ ./ 2> ./build/cppcheck-report.xml
- bash -c 'find ./ -regex ".*\.c\|.*\.h" | vera++ -S -s -d -c ./build/vera-report.xml'
- valgrind --xml=yes --xml-file=./build/valgrind-report.xml ./app < input1.txt
- sonar-scanner -Dsonar.projectKey=ProjectKey-$CI_PROJECT_ID -Dsonar.projectName=$CI_PROJECT_NAME -Dsonar.links.homepage=$CI_PROJECT_URL -Dsonar.host.url=$SONAR_URL -Dsonar.login=$SONAR_LOGIN -Dsonar.gitlab.commit_sha=$CI_COMMIT_SHA -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME -Dsonar.gitlab.project_id=$CI_PROJECT_ID -Dsonar.gitlab.url=$CODECODE_PROTOCOL$CODECODE_DOMAIN
allow_failure: true
only:
- master
case1:
stage: case1
<<: *codecode-runner
script:
- make
- ./app < input1.txt > user_output1.txt
- diff output1.txt user_output1.txt -b -B -y -i --suppress-common-lines
- execscore.sh 50
only:
- master
teacher-check1:
stage: case1
<<: *codecode-runner
script:
- make
- ./app < input1.txt
- git clone ${CODECODE_PROTOCOL}gitlab-ci-token:${CI_JOB_TOKEN}@${CODECODE_DOMAIN}/${CI_PROJECT_FORKSOURCE} template
- diff template/.gitlab-ci.yml .gitlab-ci.yml -b -B -y -i --suppress-common-lines
- diff template/input1.txt input1.txt -b -B -y -i --suppress-common-lines
- diff template/output1.txt output1.txt -b -B -y -i --suppress-common-lines
- fileidentity.sh
- git clone ${CODECODE_PROTOCOL}gitlab-ci-token:${CI_JOB_TOKEN}@${CODECODE_DOMAIN}/${TEACHERCHECK_REPO} teacher_check
- ./app < teacher_check/input1.txt > user_output1.txt
- diff teacher_check/output1.txt user_output1.txt -b -B -y -i --suppress-common-lines
- extracase.sh
only:
- master
when: manual
allow_failure: true
\ No newline at end of file
......@@ -4,7 +4,7 @@
<Configuration Name="Debug">
<Tool Name="PreBuildEventTool"/>
<Tool Name="CustomBuildTool"/>
<Tool Name="GCCCompilerTool" PreprocessorDefinitions="_DEBUG" GenerateDebugInformation="-1"/>
<Tool Name="GCCCompilerTool" PreprocessorDefinitions="_DEBUG" GenerateDebugInformation="-1" AdditionalOptions="-std=c99"/>
<Tool Name="PreLinkEventTool"/>
<Tool Name="GCCLinkerTool" AdditionalDependencies="&quot;$(CPLInstallDir)Dump\lib\T2P_Demo.o&quot;"/>
<Tool Name="PostBuildEventTool"/>
......@@ -18,7 +18,7 @@
<Configuration Name="Release">
<Tool Name="PreBuildEventTool"/>
<Tool Name="CustomBuildTool"/>
<Tool Name="GCCCompilerTool" PreprocessorDefinitions="NDEBUG"/>
<Tool Name="GCCCompilerTool" PreprocessorDefinitions="NDEBUG" AdditionalOptions="-std=c99"/>
<Tool Name="PreLinkEventTool"/>
<Tool Name="GCCLinkerTool"/>
<Tool Name="PostBuildEventTool"/>
......@@ -33,5 +33,11 @@
<File RelativePath=".\main.c">
</File>
</Filter>
<File RelativePath=".\input1.txt">
</File>
<File RelativePath=".\makefile">
</File>
<File RelativePath=".\output1.txt">
</File>
</Files>
</OSLProject>
......@@ -88,6 +88,8 @@ typedef struct _PCode{
void T2P(TCode* TCodeList, PCode* PCodeList);
void InitTCodeList(TCode* pTCodeList);
void InitTCodeList_CI(TCode* pTCodeList);
void OutputResult(PCode* PCodeList);
//
......
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
\ No newline at end of file
#include "T2P.h"
#include <stdlib.h>
#include <string.h>
char TCodeArray[MAX_CODE_COUNT][256];
int main()
{
TCode TCodeList[MAX_CODE_COUNT]; // 三地址码列表
......@@ -13,12 +15,21 @@ int main()
//
// 初始化三地址码列表
//
#ifdef CODECODE_CI
InitTCodeList_CI(TCodeList);
#else
InitTCodeList(TCodeList);
#endif
//
// 将三地址码转换为P-代码
//
T2P(TCodeList, PCodeList);
//
// 输出P-代码
//
OutputResult(PCodeList);
return 0;
}
......@@ -111,3 +122,181 @@ void InitTCodeList(TCode* pTCodeList)
}
}
/*
功能:
初始化三地址码列表(在执行流水线时调用)。
参数:
pTCodeList -- 三地址码列表指针。
*/
void InitTCodeList_CI(TCode* pTCodeList)
{
for(int i = 0; i < MAX_CODE_COUNT; i++)
{
gets(TCodeArray[i]);
int length = strlen(TCodeArray[i]);
if(length == 0)
{
break;
}
char unitArr[7][64] = {};
int k = 0, l = 0;
for(int j = 0; j < 256; j++)
{
if(TCodeArray[i][j] == '\0')
{
break;
}
if(TCodeArray[i][j] == 32)
{
k++;
l = 0;
continue;
}
unitArr[k][l++] = TCodeArray[i][j];
}
char kind[64] = {0};
strcpy(kind, unitArr[0]);
if(strcmp(kind, "t_rd") == 0)
{
pTCodeList[i].Kind = t_rd;
}
else if(strcmp(kind, "t_gt") == 0)
{
pTCodeList[i].Kind = t_gt;
}
else if(strcmp(kind, "t_if_f") == 0)
{
pTCodeList[i].Kind = t_if_f;
}
else if(strcmp(kind, "t_asn") == 0)
{
pTCodeList[i].Kind = t_asn;
}
else if(strcmp(kind, "t_lab") == 0)
{
pTCodeList[i].Kind = t_lab;
}
else if(strcmp(kind, "t_mul") == 0)
{
pTCodeList[i].Kind = t_mul;
}
else if(strcmp(kind, "t_sub") == 0)
{
pTCodeList[i].Kind = t_sub;
}
else if(strcmp(kind, "t_eq") == 0)
{
pTCodeList[i].Kind = t_eq;
}
else if(strcmp(kind, "t_wri") == 0)
{
pTCodeList[i].Kind = t_wri;
}
else if(strcmp(kind, "t_halt") == 0)
{
pTCodeList[i].Kind = t_halt;
}
for(int j = 1; j < k; j += 2)
{
if(strcmp(unitArr[j], "string") == 0)
{
if(j == 1)
{
pTCodeList[i].Addr1.Kind = string;
strcpy(pTCodeList[i].Addr1.Name,unitArr[j + 1]);
}
else if(j == 3)
{
pTCodeList[i].Addr2.Kind = string;
strcpy(pTCodeList[i].Addr2.Name,unitArr[j + 1]);
}
else if(j == 5)
{
pTCodeList[i].Addr3.Kind = string;
strcpy(pTCodeList[i].Addr3.Name,unitArr[j + 1]);
}
}
else if(strcmp(unitArr[j], "intconst") == 0)
{
if(j == 1)
{
pTCodeList[i].Addr1.Kind = intconst;
pTCodeList[i].Addr1.Value = atoi(unitArr[j + 1]);
}
else if(j == 3)
{
pTCodeList[i].Addr2.Kind = intconst;
pTCodeList[i].Addr2.Value = atoi(unitArr[j + 1]);
}
else if(j == 5)
{
pTCodeList[i].Addr3.Kind = intconst;
pTCodeList[i].Addr3.Value = atoi(unitArr[j + 1]);
}
}
}
}
}
/*
功能:
输出三地址码列表。
参数:
pCodeList -- P-代码列表指针。
*/
void OutputResult(PCode* PCodeList)
{
for(int PIndex = 0; PCodeList[PIndex].Kind != 0; PIndex++)
{
switch(PCodeList[PIndex].Kind)
{
case p_lda:
printf("lda%c%c%s\n", 32, 32, PCodeList[PIndex].Addr.Name);
break;
case p_rdi:
printf("rdi\n");
break;
case p_lod:
printf("lod%c%c%s\n", 32, 32, PCodeList[PIndex].Addr.Name);
break;
case p_ldc:
printf("ldc%c%c%d\n", 32, 32, PCodeList[PIndex].Addr.Value);
break;
case p_grt:
printf("grt\n");
break;
case p_fjp:
printf("fjp%c%c%s\n", 32, 32, PCodeList[PIndex].Addr.Name);
break;
case p_sto:
printf("sto\n");
break;
case p_lab:
printf("lab%c%c%s\n", 32, 32, PCodeList[PIndex].Addr.Name);
break;
case p_mpi:
printf("mpi\n");
break;
case p_sbi:
printf("sbi\n");
break;
case p_equ:
printf("equ\n");
break;
case p_wri:
printf("wri%c%c%s\n", 32, 32, PCodeList[PIndex].Addr.Name);
break;
case p_stp:
printf("stp\n");
break;
}
}
}
DIR_INC = .
DIR_SRC = .
DIR_OBJ = .
DIR_BIN = .
SRC = $(wildcard ${DIR_SRC}/*.c)
OBJ = $(patsubst %.c,${DIR_OBJ}/%.o,$(notdir ${SRC}))
TARGET = app
BIN_TARGET = ${DIR_BIN}/${TARGET}
CC = gcc
CFLAGS = -g -w -fmax-errors=10 -std=c99 -fsigned-char -I${DIR_INC} -D CODECODE_CI
${BIN_TARGET}:${OBJ}
$(CC) $(OBJ) -o $@
${DIR_OBJ}/%.o:${DIR_SRC}/%.c
$(CC) $(CFLAGS) -c $< -o $@
\ No newline at end of file
lda x
rdi
lda t1
lod x
ldc 2
mpi
sto
lda x
lod t1
sto
lod x
fjp L1
lod x
wri
lab L1
stp
# required metadata
sonar.language=c
# path to source directories (required)
sonar.sources=./
# path to the build artifact
sonar.artifact.path=build/app
# paths to the reports
sonar.c.cppcheck.reportPath=./build/cppcheck-report.xml
#sonar.c.pclint.reportPath=./build/pclint-report.xml
#sonar.c.coverage.reportPath=./build/gcovr-report*.xml
#sonar.c.coverage.itReportPath=./build/gcovr-report*.xml
#sonar.c.coverage.overallReportPath=./build/gcovr-report*.xml
sonar.c.valgrind.reportPath=./build/valgrind-report.xml
sonar.c.vera.reportPath=./build/vera-report.xml
#sonar.c.rats.reportPath=./build/rats-report.xml
#sonar.c.xunit.reportPath=./build/xunit-report.xml
#sonar.c.drmemory.reportPath=./build/drmemory-logs/**/results.txt
sonar.c.includeDirectories=/usr/include/,/usr/include/linux,/usr/include/x86_64-linux-gnu/bits,/usr/include/x86_64-linux-gnu/sys,/usr/include/c++/5/tr1,./
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论