AMF-Placer  2.0
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
simpleJSON.h
Go to the documentation of this file.
1 
25 #ifndef _SIMPLEJSON
26 #define _SIMPLEJSON
27 
28 #include "strPrint.h"
29 #include "stringCheck.h"
30 #include <algorithm>
31 #include <assert.h>
32 #include <cstdio>
33 #include <fstream>
34 #include <iostream>
35 #include <map>
36 #include <set>
37 #include <sstream>
38 #include <string>
39 #include <sys/stat.h>
40 #include <unistd.h>
41 #include <vector>
42 
43 inline bool exists_test(const std::string &name)
44 {
45  struct stat buffer;
46  return (stat(name.c_str(), &buffer) == 0);
47 }
48 
49 std::map<std::string, std::string> parseJSONFile(std::string JSONFileName)
50 {
51  assert(exists_test(JSONFileName));
52  std::ifstream infile(JSONFileName.c_str());
53  assert(infile.good());
54  std::string line;
55 
56  std::string entireStr;
57  while (std::getline(infile, line))
58  {
59  if (line.find("//") == std::string::npos)
60  entireStr += line;
61  else
62  entireStr += line.substr(0, line.find("//"));
63  }
64 
65  std::map<std::string, std::string> res;
66  res.clear();
67 
68  entireStr = std::string(entireStr.begin() + 1, entireStr.end() - 1);
69  std::vector<std::string> jsonBlocks;
70  strSplit(entireStr, jsonBlocks, ",");
71 
72  for (auto jsonBlock : jsonBlocks)
73  {
74  if (jsonBlock.find(":") == std::string::npos)
75  continue;
76  if (jsonBlock.find("\"") == std::string::npos)
77  continue;
78 
79  int quote1Loc = jsonBlock.find("\"");
80  int quote2Loc = jsonBlock.find("\"", quote1Loc + 1);
81  int quote3Loc = jsonBlock.find("\"", quote2Loc + 1);
82  int quote4Loc = jsonBlock.find("\"", quote3Loc + 1);
83 
84  assert(quote1Loc >= 0 && quote2Loc >= 0 && quote3Loc >= 0 && quote4Loc >= 0 &&
85  "the json file has some syntax error");
86 
87  res[jsonBlock.substr(quote1Loc + 1, quote2Loc - quote1Loc - 1)] =
88  jsonBlock.substr(quote3Loc + 1, quote4Loc - quote3Loc - 1);
89  }
90 
91  if (res.find("dumpDirectory") == res.end())
92  {
93  res["dumpDirectory"] = "./";
94  }
95  else
96  {
97  res["dumpDirectory"] += "/";
98  }
99 
100  std::map<std::string, std::string>::iterator it;
101  for (it = res.begin(); it != res.end(); it++)
102  {
103  if (it->first == "dumpDirectory")
104  continue;
105  if (it->first.find("dump") != std::string::npos || it->first.find("Dump") != std::string::npos)
106  {
107  res[it->first] = res["dumpDirectory"] + "/" + it->second;
108  }
109  }
110 
111  print_warning("Placer configuration is loaded and the information is shown below, please check:");
112 
113  for (auto pair : res)
114  {
115  std::cout << " \"" << pair.first << "\" ==== \"" << pair.second << "\"\n";
116  }
117 
118  return res;
119 }
120 
121 #endif
removeFailurePartFromTcl.line
line
Definition: removeFailurePartFromTcl.py:32
exists_test
bool exists_test(const std::string &name)
Definition: simpleJSON.h:43
parseJSONFile
std::map< std::string, std::string > parseJSONFile(std::string JSONFileName)
Definition: simpleJSON.h:49
stringCheck.h
strPrint.h
print_warning
void print_warning(std::string tmp_string)
Definition: strPrint.cc:57
strSplit
void strSplit(const std::string &s, std::vector< std::string > &sv, const char *delim)
Definition: stringCheck.cc:35