Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.54 KB | None | 0 0
  1. #include <clock_edge_recognizer.h>
  2. #include <root_class.h>
  3. #include <mach7_includes.h>
  4. #include <iostream>
  5.  
  6. namespace mch {
  7. template <> struct bindings<ExpUNot> {
  8. Members(ExpUNot::operand1_);
  9. };
  10.  
  11. template <> struct bindings<ExpCharacter> {
  12. Members(ExpCharacter::value_);
  13. };
  14.  
  15. template <> struct bindings<ExpAttribute> {
  16. Members(ExpAttribute::name_);
  17. };
  18.  
  19. template <> struct bindings<ExpLogical> {
  20. Members(ExpLogical::operand1_,
  21. ExpLogical::operand2_,
  22. ExpLogical::fun_);
  23. };
  24.  
  25. template <> struct bindings<ExpFunc> {
  26. Members(ExpFunc::name_,
  27. ExpFunc::argv_);
  28. };
  29.  
  30. template <> struct bindings<ExpName> {
  31. //TODO: add prefix
  32. Members(//ExpName::prefix_, // unique_ptr<ExpName>
  33. ExpName::name_,
  34. ExpName::indices_);
  35. };
  36.  
  37. template <> struct bindings<ExpRelation> {
  38. Members(ExpRelation::operand1_,
  39. ExpRelation::operand2_,
  40. ExpRelation::fun_);
  41. };
  42. };
  43.  
  44. void ClockEdgeRecognizer::reset(void){
  45. containsClockEdge = false;
  46. numberClockEdges = 0;
  47. direction = NetlistGenerator::edge_spec::UNDEF;
  48.  
  49. clockNameExp = NULL;
  50. clockFuncExp = NULL;
  51. }
  52.  
  53. int ClockEdgeRecognizer::operator()(const Expression *n){
  54. using namespace mch;
  55.  
  56. auto checkHelper = [this](var<perm_string> attrName,
  57. var<char> charVal,
  58. const ExpName *tmp,
  59. const char *checkAttrName,
  60. var<ExpLogical::fun_t> logOp,
  61. var<ExpRelation::fun_t> relOp)
  62. -> void {
  63. if (tmp == NULL)
  64. std::cout << "ClockEdgeRecognizer checkHelper. Impossible!"
  65. << std::endl;
  66.  
  67. if ((charVal == '0' || charVal == '1') &&
  68. (relOp == ExpRelation::fun_t::EQ) &&
  69. (logOp == ExpLogical::fun_t::AND) &&
  70. (!strcmp(attrName, checkAttrName))){
  71.  
  72. clockNameExp = tmp;
  73. containsClockEdge = true;
  74. numberClockEdges++;
  75. if (charVal == '0')
  76. direction = NetlistGenerator::edge_spec::FALLING;
  77. else
  78. direction = NetlistGenerator::edge_spec::RISING;
  79. }
  80. };
  81.  
  82. var<perm_string> attrName, name, funcName;
  83. var<char> charVal;
  84. var<vector<Expression*>> params;
  85. var<ExpLogical::fun_t> logOp;
  86. var<ExpRelation::fun_t> relOp;
  87.  
  88. Match(n){
  89.  
  90. Case(C<ExpFunc>(funcName, params)){
  91. if (params.size() == 1 &&
  92. (!strcmp(funcName, "falling_edge") ||
  93. !strcmp(funcName, "rising_edge" ))) {
  94. containsClockEdge = true;
  95. numberClockEdges++;
  96. }
  97.  
  98. clockFuncExp = dynamic_cast<const ExpFunc*>(n);
  99.  
  100. if (!strcmp(funcName, "falling_edge"))
  101. direction = NetlistGenerator::edge_spec::FALLING;
  102. if (!strcmp(funcName, "rising_edge"))
  103. direction = NetlistGenerator::edge_spec::RISING;
  104.  
  105. break;
  106. }
  107.  
  108. // case 1
  109. Case(C<ExpLogical>(
  110. C<ExpRelation>(
  111. C<ExpName>(name),
  112. C<ExpCharacter>(charVal),
  113. relOp),
  114. C<ExpAttribute>(attrName),
  115. logOp)){
  116.  
  117. std::cout << "HERE" << std::endl;
  118.  
  119. checkHelper(attrName, charVal,
  120. dynamic_cast<const ExpName *>(
  121. dynamic_cast<const ExpRelation *>(
  122. dynamic_cast<const ExpLogical *>(n)
  123. ->operand1_)
  124. ->operand1_),
  125. "event", logOp, relOp);
  126. break;
  127. }
  128. Case(C<ExpLogical>(
  129. C<ExpRelation>(
  130. C<ExpCharacter>(charVal),
  131. C<ExpName>(name),
  132. relOp),
  133. C<ExpAttribute>(attrName),
  134. logOp)){
  135.  
  136. std::cout << "HERE1" << std::endl;
  137. checkHelper(attrName, charVal,
  138. dynamic_cast<const ExpName *>(
  139. dynamic_cast<const ExpRelation *>(
  140. dynamic_cast<const ExpLogical *>(n)
  141. ->operand1_)
  142. ->operand2_),
  143. "event", logOp, relOp);
  144. break;
  145. }
  146.  
  147. // case 2
  148. Case(C<ExpLogical>(
  149. C<ExpRelation>(
  150. C<ExpName>(name),
  151. C<ExpCharacter>(charVal),
  152. relOp),
  153. C<ExpUNot>(
  154. C<ExpAttribute>(attrName)),
  155. logOp)){
  156.  
  157. std::cout << "HERE3" << std::endl;
  158. checkHelper(attrName, charVal,
  159. dynamic_cast<const ExpName *>(
  160. dynamic_cast<const ExpRelation *>(
  161. dynamic_cast<const ExpLogical *>(n)
  162. ->operand1_)
  163. ->operand1_),
  164. "stable", logOp, relOp);
  165. break;
  166. }
  167. Case(C<ExpLogical>(
  168. C<ExpRelation>(
  169. C<ExpCharacter>(charVal),
  170. C<ExpName>(name),
  171. relOp),
  172. C<ExpUNot>(
  173. C<ExpAttribute>(attrName)),
  174. logOp)){
  175.  
  176. std::cout << "HERE4" << std::endl;
  177. checkHelper(attrName, charVal,
  178. dynamic_cast<const ExpName *>(
  179. dynamic_cast<const ExpRelation *>(
  180. dynamic_cast<const ExpLogical *>(n)
  181. ->operand1_)
  182. ->operand2_),
  183. "stable", logOp, relOp);
  184. break;
  185. }
  186.  
  187. // mirror cases for case 1
  188. Case(C<ExpLogical>(
  189. C<ExpAttribute>(attrName),
  190. C<ExpRelation>(
  191. C<ExpName>(name),
  192. C<ExpCharacter>(charVal),
  193. relOp),
  194. logOp)){
  195.  
  196. checkHelper(attrName, charVal,
  197. dynamic_cast<const ExpName *>(
  198. dynamic_cast<const ExpRelation *>(
  199. dynamic_cast<const ExpLogical *>(n)
  200. ->operand2_)
  201. ->operand1_),
  202. "event", logOp, relOp);
  203. break;
  204. }
  205. Case(C<ExpLogical>(
  206. C<ExpAttribute>(attrName),
  207. C<ExpRelation>(
  208. C<ExpCharacter>(charVal),
  209. C<ExpName>(name),
  210. relOp),
  211. logOp)){
  212.  
  213. checkHelper(attrName, charVal,
  214. dynamic_cast<const ExpName *>(
  215. dynamic_cast<const ExpRelation *>(
  216. dynamic_cast<const ExpLogical *>(n)
  217. ->operand2_)
  218. ->operand2_),
  219. "event", logOp, relOp);
  220. break;
  221. }
  222.  
  223. // mirror cases for case 2
  224. Case(C<ExpLogical>(
  225. C<ExpUNot>(
  226. C<ExpAttribute>(attrName)),
  227. C<ExpRelation>(
  228. C<ExpName>(name),
  229. C<ExpCharacter>(charVal),
  230. relOp),
  231. logOp)){
  232.  
  233. checkHelper(attrName, charVal,
  234. dynamic_cast<const ExpName *>(
  235. dynamic_cast<const ExpRelation *>(
  236. dynamic_cast<const ExpLogical *>(n)
  237. ->operand2_)
  238. ->operand1_),
  239. "stable", logOp, relOp);
  240. break;
  241. }
  242. Case(C<ExpLogical>(
  243. C<ExpUNot>(
  244. C<ExpAttribute>(attrName)),
  245. C<ExpRelation>(
  246. C<ExpCharacter>(charVal),
  247. C<ExpName>(name),
  248. relOp),
  249. logOp)){
  250.  
  251. checkHelper(attrName, charVal,
  252. dynamic_cast<const ExpName *>(
  253. dynamic_cast<const ExpRelation *>(
  254. dynamic_cast<const ExpLogical *>(n)
  255. ->operand2_)
  256. ->operand2_),
  257. "stable", logOp, relOp);
  258. break;
  259. }
  260. Otherwise(){ break; }
  261. } EndMatch;
  262. return 0;
  263. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement