Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: AvailableMemory mbed-rtos mbed
Parser.cpp
00001 #include "Parser.h" 00002 00003 void Parser::parseSDFG(char *path, SDFG *sdfg){ 00004 // printf("Parsing SDF config... ", path); // Drive should be marked as removed 00005 FILE *fp=fopen(path, "r"); 00006 if(!fp) { 00007 error("ERROR: no file located at \"%s\"\r\n",path); 00008 exit(1); 00009 } 00010 else 00011 { 00012 // printf("File opened!\n\r"); 00013 } 00014 int n1=-1, n2=-1; 00015 char line[1024], delim[]=" ", *cur=NULL, symbol; 00016 for(int i=0; i<1024; i++)line[i]=0; 00017 int nodeId=0; 00018 while(fgets(line, 1024, fp)!=NULL){ 00019 int temp, params[256], count=0; 00020 cur=strtok(line, delim); 00021 if(n1<0 && n2<0){ 00022 n1=atoi(cur); 00023 cur=strtok(NULL,delim); 00024 n2=atoi(cur); 00025 sdfg->setNumOfNodes(n1); 00026 sdfg->setNumOfFIFOs(n2); 00027 }else if(strlen(cur)!=1){ 00028 error("BAD SDFG FORMAT\r\n"); 00029 exit(1); 00030 }else{ 00031 symbol = cur[0]; 00032 for(int i=0; i<256; i++)params[i]=0; 00033 count=0; 00034 cur=strtok(NULL,delim); 00035 while(cur){ 00036 temp=atoi(cur); 00037 params[count++]=temp; 00038 cur=strtok(NULL,delim); 00039 } 00040 switch (symbol){ 00041 case 'I': sdfg->getINode(nodeId++, params, count); 00042 break; 00043 case 'O': sdfg->getONode(nodeId++, params, count); 00044 break; 00045 case 'A': sdfg->getANode(nodeId++, params, count); 00046 break; 00047 case 'S': sdfg->getSNode(nodeId++, params, count); 00048 break; 00049 case 'M': sdfg->getMNode(nodeId++, params, count); 00050 break; 00051 case 'D': sdfg->getDNode(nodeId++, params, count); 00052 break; 00053 case 'U': sdfg->getUNode(nodeId++, params, count); 00054 break; 00055 case 'C': sdfg->getCNode(nodeId++, params, count); 00056 break; 00057 case 'F': sdfg->getFNode(nodeId++, params, count); 00058 break; 00059 case 'E': sdfg->addDelay(params, count); 00060 break; 00061 default: error("ERROR: BAD SDFG FORMAT\r\n"); 00062 exit(1); 00063 break; 00064 } 00065 } 00066 for(int i=0; i<256; i++)params[i]=0; 00067 for(int i=0; i<1024; i++)line[i]=0; 00068 } 00069 //printf("Closing File...\r\n"); 00070 fclose(fp); 00071 sdfg->buildTopologyMatrix(); 00072 } 00073 00074 void Parser::parseInput(char *path, RingBuffer *buf){ 00075 //printf("Parsing input...\r\n"); 00076 FILE *fp=fopen(path, "r"); 00077 if(!fp){ 00078 error("ERROR: no file located at \"%s\"\r\n",path); 00079 exit(1); 00080 } 00081 int count=0; 00082 int N=0; 00083 char line[20]; 00084 for(int i=0; i<20; i++)line[i]=0; 00085 while(fgets(line, 20, fp)!=NULL){ 00086 if(count==0){ 00087 N=atoi(line); 00088 if(N<0){ 00089 error("ERROR: BAD INPUT FORMAT\r\n"); 00090 exit(1); 00091 } 00092 }else{ 00093 buf->insert(atoi(line)); 00094 } 00095 count++; 00096 for(int i=0; i<20; i++) line[i]=0; 00097 } 00098 fclose(fp); 00099 if(N!=count-1){ 00100 error("ERROR: BAD INPUT FORMAT\r\n"); 00101 exit(1); 00102 } 00103 else 00104 { 00105 // printf("File closed.\n\r"); 00106 } 00107 }
Generated on Tue Jul 12 2022 18:43:44 by
1.7.2