├── EDIFParserFunctors.hpp ├── EDIFReader.cpp ├── EDIFReader.hpp ├── Makefile ├── README.md ├── example2.edif ├── fibex_example.edif ├── full_adder_nl.edif └── main.cpp /EDIFParserFunctors.hpp: -------------------------------------------------------------------------------- 1 | /**********************************************************************/ 2 | /* Author: Sumanish */ 3 | /* Modified By: Sumanish */ 4 | /* */ 5 | /* This source code can be downloaded, use, modify, distribute */ 6 | /* freely with this headed intact. Please don't delete this header. */ 7 | /**********************************************************************/ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | using namespace std; 15 | 16 | typedef std::vector CharList; 17 | typedef std::vector::const_iterator ConstCharIter; 18 | typedef std::vector::iterator CharIter; 19 | 20 | 21 | struct PrintInteger { 22 | void operator () (const int& arg) const 23 | { 24 | cout << " " << arg ; 25 | } 26 | PrintInteger() {} 27 | }; 28 | 29 | struct PrintStr { 30 | void operator () (ConstCharIter start, ConstCharIter end) const 31 | { 32 | std::string s(start, end); 33 | cout << " " << s; 34 | } 35 | PrintStr() {} 36 | }; 37 | 38 | struct PrintStrLit { 39 | void operator () (ConstCharIter start, ConstCharIter end) const 40 | { 41 | std::string s(start, end); 42 | cout << " " << "\"" << s << "\""; 43 | } 44 | PrintStrLit() {} 45 | }; 46 | 47 | struct PrintTag { 48 | void operator () (ConstCharIter start, ConstCharIter end) const 49 | { 50 | std::string s(start, end); 51 | cout << " " << s; 52 | } 53 | PrintTag() {} 54 | }; 55 | 56 | struct PrintChar { 57 | void operator () (char c) const 58 | { 59 | cout << c; 60 | } 61 | PrintChar() {} 62 | 63 | }; 64 | 65 | struct PrintNewLine { 66 | void operator () (ConstCharIter start, ConstCharIter end) const 67 | { 68 | cout << "\n"; 69 | } 70 | PrintNewLine() {} 71 | 72 | }; 73 | -------------------------------------------------------------------------------- /EDIFReader.cpp: -------------------------------------------------------------------------------- 1 | /**********************************************************************/ 2 | /* Author: Sumanish */ 3 | /* Modified By: Sumanish */ 4 | /* */ 5 | /* This source code can be downloaded, use, modify, distribute */ 6 | /* freely with this headed intact. Please don't delete this header. */ 7 | /**********************************************************************/ 8 | 9 | #include "EDIFReader.hpp" 10 | #include 11 | #include 12 | 13 | #include "EDIFParserFunctors.hpp" 14 | 15 | // Skip parser 16 | struct skip_grammar : public grammar 17 | { 18 | template 19 | struct definition 20 | { 21 | definition(skip_grammar const&) 22 | { 23 | EOL = ch_p('\n'); 24 | skip 25 | = comment_p("//") 26 | | comment_p("/*", "*/") 27 | | EOL [PrintNewLine()] 28 | ; 29 | } 30 | 31 | rule skip; 32 | rule EOL; 33 | rule const& 34 | start() const { return skip; } 35 | }; 36 | }; 37 | 38 | 39 | //EDIF grammar 40 | struct edif_grammar : public boost::spirit::grammar 41 | { 42 | 43 | template 44 | struct definition 45 | { 46 | 47 | definition(edif_grammar const& self ) : EDIF("edif"), 48 | EDIFVERSION("edifVersion"), EDIFLEVEL("edifLevel"), STATUS("status"), WRITTEN("written"), 49 | TIMESTAMP("timeStamp"), PROGRAM("program"), PROGVERSION1("Version"), PROGVERSION2("version"), DATAORIGIN("dataOrigin"), 50 | AUTHOR("author"), KEYWORDMAP("keywordMap"), KEYWORDLEVEL("keywordLevel"), 51 | EXTERNAL("external"), TECHNOLOGY("technology"), NUMBERDEFINITION("numberDefinition"), 52 | CELL("cell"), CELLTYPE("cellType"), GENERICUp("GENERIC"), GENERICLow("generic"), TIE("TIE"), RIPPER("RIPPER"), VIEW("view"), 53 | VIEWTYPE("viewType"), BEHAVIOR("BEHAVIOR"), DOCUMENT("DOCUMENT"), GRAPHIC("GRAPHIC"), LOGICMODEL("LOGICMODEL"), 54 | MASKLAYOUT("MASKLAYOUT"), NETLISTUp("NETLIST"), NETLISTLow("netlist"), PCBLAYOUT("PCBLAYOUT"), SCHEMATIC("SCHEMATIC"), 55 | STRANGER("STRANGER"), SYMBOLIC("SYMBOLIC"), INTERFACE("interface"), PORT("port"), DIRECTION("direction"), 56 | INPUT("INPUT"), OUTPUT("OUTPUT"), INOUT("INOUT"), CONTENTS("contents"), INSTANCE("instance"), 57 | VIEWREF("viewRef"), CELLREF("cellRef"), LIBRARYREF("libraryRef"), 58 | NET("net"), JOINED("joined"), MUSTJOIN("mustjoin"), CRITICALSIGNAL("criticalsignal"), 59 | PORTREF("portRef"), INSTANCEREF("instanceRef"), LIBRARY("library"), DESIGN("design"), 60 | SCALE("scale"), UNIT("unit"), PROPERTY("property"), INTEGER("integer"), STRING("string"), OWNER("owner"), 61 | RENAME("rename") 62 | { 63 | using namespace phoenix; 64 | LEFT_BRACE = ch_p('{') ;//[PrintChar()]; 65 | RIGHT_BRACE = ch_p('}') ;//[PrintChar()]; 66 | LEFT_PARAN = ch_p('(') ;//[PrintChar()]; 67 | RIGHT_PARAN = ch_p(')') ;//[PrintChar()]; 68 | SPACE = *space_p ;//[PrintChar()]; 69 | any_string = ch_p('"') 70 | >> string_val [PrintStrLit()] 71 | >> ch_p('"') 72 | ; 73 | 74 | string_val 75 | = *(anychar_p - ch_p('"')); 76 | 77 | edifversion_section 78 | = LEFT_PARAN 79 | >> EDIFVERSION [PrintTag()] 80 | >> *(SPACE >> int_p [PrintInteger()]) 81 | >> RIGHT_PARAN 82 | ; 83 | 84 | ediflevel_section 85 | = LEFT_PARAN 86 | >> SPACE 87 | >> EDIFLEVEL [PrintTag()] 88 | >> SPACE 89 | >> int_p [PrintInteger()] 90 | >> SPACE 91 | >> RIGHT_PARAN 92 | ; 93 | 94 | timestamp_section 95 | = LEFT_PARAN 96 | >> SPACE 97 | >> TIMESTAMP [PrintTag()] 98 | >> *(SPACE >> int_p [PrintInteger()]) 99 | >> SPACE 100 | >> RIGHT_PARAN 101 | ; 102 | 103 | programversion_section 104 | = LEFT_PARAN 105 | >> SPACE 106 | >> (PROGVERSION1|PROGVERSION2) [PrintTag()] 107 | >> SPACE 108 | >> any_string 109 | >> SPACE 110 | >> RIGHT_PARAN 111 | ; 112 | 113 | program_section 114 | = LEFT_PARAN 115 | >> SPACE 116 | >> PROGRAM [PrintTag()] 117 | >> SPACE 118 | >> any_string 119 | >> SPACE 120 | >> programversion_section 121 | >> SPACE 122 | >> RIGHT_PARAN 123 | ; 124 | 125 | dataorigin_setion 126 | = LEFT_PARAN 127 | >> SPACE 128 | >> DATAORIGIN [PrintTag()] 129 | >> SPACE 130 | >> any_string 131 | >> SPACE 132 | >> RIGHT_PARAN 133 | ; 134 | 135 | author_section 136 | = LEFT_PARAN 137 | >> SPACE 138 | >> AUTHOR [PrintTag()] 139 | >> SPACE 140 | >> any_string 141 | >> SPACE 142 | >> RIGHT_PARAN 143 | ; 144 | 145 | written_section 146 | = LEFT_PARAN 147 | >> SPACE 148 | >> WRITTEN [PrintTag()] 149 | >> SPACE 150 | >> timestamp_section 151 | >> SPACE 152 | >> program_section 153 | >> *(SPACE >> dataorigin_setion) 154 | >> *(SPACE >> author_section) 155 | >> SPACE 156 | >> RIGHT_PARAN 157 | ; 158 | 159 | keywordlevel_section 160 | = LEFT_PARAN 161 | >> SPACE 162 | >> KEYWORDLEVEL [PrintTag()] 163 | >> SPACE 164 | >> int_p [PrintInteger()] 165 | >> SPACE 166 | >> RIGHT_PARAN 167 | ; 168 | 169 | keyword_section 170 | = LEFT_PARAN 171 | >> SPACE 172 | >> KEYWORDMAP [PrintTag()] 173 | >> SPACE 174 | >> keywordlevel_section 175 | >> SPACE 176 | >> RIGHT_PARAN 177 | ; 178 | 179 | status_section 180 | = LEFT_PARAN 181 | >> SPACE 182 | >> STATUS [PrintTag()] 183 | >> SPACE 184 | >> written_section 185 | >> SPACE 186 | >> RIGHT_PARAN 187 | ; 188 | 189 | section_name 190 | = *(anychar_p - space_p - ch_p('(') - ch_p(')')) ; 191 | 192 | string_without_right_paran 193 | = *(anychar_p - ch_p(')')) ; 194 | 195 | only_string 196 | = *(anychar_p - ch_p(')') - space_p) ; 197 | 198 | celltypesec_name 199 | = GENERICUp|GENERICLow|TIE|RIPPER; 200 | 201 | viewtype_name 202 | = BEHAVIOR|DOCUMENT|GRAPHIC|LOGICMODEL|MASKLAYOUT 203 | |NETLISTUp|NETLISTLow|PCBLAYOUT|SCHEMATIC|STRANGER|SYMBOLIC; 204 | 205 | alnum_name 206 | = *alnum_p ; 207 | 208 | scalefactor_section 209 | = LEFT_PARAN 210 | >> SPACE 211 | >> alpha_p [PrintChar()] 212 | >> SPACE 213 | >> int_p [PrintInteger()] 214 | >> SPACE 215 | >> int_p [PrintInteger()] 216 | >> SPACE 217 | >> RIGHT_PARAN 218 | ; 219 | 220 | scaleunit_section 221 | = LEFT_PARAN 222 | >> SPACE 223 | >> UNIT [PrintTag()] 224 | >> SPACE 225 | >> string_without_right_paran [PrintStr()] 226 | >> SPACE 227 | >> RIGHT_PARAN 228 | ; 229 | 230 | scale_section 231 | = LEFT_PARAN 232 | >> SPACE 233 | >> SCALE [PrintTag()] 234 | >> SPACE 235 | >> int_p [PrintInteger()] 236 | >> SPACE 237 | >> scalefactor_section 238 | >> SPACE 239 | >> scaleunit_section 240 | >> SPACE 241 | >> RIGHT_PARAN 242 | ; 243 | 244 | numberdefinition_section 245 | = LEFT_PARAN 246 | >> SPACE 247 | >> NUMBERDEFINITION [PrintTag()] 248 | >> *(SPACE >> scale_section) 249 | >> SPACE 250 | >> RIGHT_PARAN 251 | ; 252 | 253 | technolgy_section 254 | = LEFT_PARAN 255 | >> SPACE 256 | >> TECHNOLOGY [PrintTag()] 257 | >> SPACE 258 | >> numberdefinition_section 259 | >> SPACE 260 | >> RIGHT_PARAN 261 | ; 262 | 263 | celltype_section 264 | = LEFT_PARAN 265 | >> SPACE 266 | >> CELLTYPE [PrintTag()] 267 | >> SPACE 268 | >> celltypesec_name [PrintStr()] 269 | >> SPACE 270 | >> RIGHT_PARAN 271 | ; 272 | 273 | viewtype_section 274 | = LEFT_PARAN 275 | >> SPACE 276 | >> VIEWTYPE [PrintTag()] 277 | >> SPACE 278 | >> viewtype_name [PrintStr()] 279 | >> SPACE 280 | >> RIGHT_PARAN 281 | ; 282 | 283 | direction_str 284 | = INPUT | OUTPUT | INOUT ; 285 | 286 | direction_section 287 | = LEFT_PARAN 288 | >> SPACE 289 | >> DIRECTION [PrintTag()] 290 | >> SPACE 291 | >> direction_str [PrintStr()] 292 | >> SPACE 293 | >> RIGHT_PARAN 294 | ; 295 | 296 | rename_section 297 | = LEFT_PARAN 298 | >> SPACE 299 | >> RENAME [PrintTag()] 300 | >> SPACE 301 | >> section_name [PrintStr()] 302 | >> SPACE 303 | >> any_string 304 | >> SPACE 305 | >> RIGHT_PARAN 306 | ; 307 | 308 | section_name_or_rename 309 | = rename_section 310 | | section_name [PrintStr()] 311 | ; 312 | 313 | port_section 314 | = LEFT_PARAN 315 | >> SPACE 316 | >> PORT [PrintTag()] 317 | >> SPACE 318 | >> section_name_or_rename 319 | >> SPACE 320 | >> direction_section 321 | >> SPACE 322 | >> RIGHT_PARAN 323 | ; 324 | 325 | integerval_section 326 | = LEFT_PARAN 327 | >> SPACE 328 | >> INTEGER [PrintTag()] 329 | >> SPACE 330 | >> int_p [PrintInteger()] 331 | >> SPACE 332 | >> RIGHT_PARAN 333 | ; 334 | 335 | stringval_section 336 | = LEFT_PARAN 337 | >> SPACE 338 | >> STRING [PrintTag()] 339 | >> *(SPACE >> any_string) 340 | >> SPACE 341 | >> RIGHT_PARAN 342 | ; 343 | 344 | owner_section 345 | = LEFT_PARAN 346 | >> SPACE 347 | >> OWNER [PrintTag()] 348 | >> *(SPACE >> any_string) 349 | >> SPACE 350 | >> RIGHT_PARAN 351 | ; 352 | 353 | propertyval_section 354 | = integerval_section | stringval_section | owner_section; 355 | 356 | property_section 357 | = LEFT_PARAN 358 | >> SPACE 359 | >> PROPERTY [PrintTag()] 360 | >> SPACE 361 | >> section_name [PrintStr()] 362 | >> +(SPACE >> propertyval_section) 363 | >> SPACE 364 | >> RIGHT_PARAN 365 | ; 366 | 367 | ifcontent_section 368 | = port_section | property_section; 369 | 370 | interface_section 371 | = LEFT_PARAN 372 | >> SPACE 373 | >> INTERFACE [PrintTag()] 374 | >> *(SPACE >> ifcontent_section) 375 | >> SPACE 376 | >> RIGHT_PARAN 377 | ; 378 | 379 | libraryref_section 380 | = LEFT_PARAN 381 | >> SPACE 382 | >> LIBRARYREF [PrintTag()] 383 | >> SPACE 384 | >> string_without_right_paran [PrintStr()] 385 | >> SPACE 386 | >> RIGHT_PARAN 387 | ; 388 | 389 | cellref_section 390 | = LEFT_PARAN 391 | >> SPACE 392 | >> CELLREF [PrintTag()] 393 | >> SPACE 394 | >> section_name [PrintStr()] 395 | >> *(SPACE >> libraryref_section) 396 | >> SPACE 397 | >> RIGHT_PARAN 398 | ; 399 | 400 | viewref_section 401 | = LEFT_PARAN 402 | >> SPACE 403 | >> VIEWREF [PrintTag()] 404 | >> SPACE 405 | >> section_name [PrintStr()] 406 | >> SPACE 407 | >> cellref_section 408 | >> SPACE 409 | >> RIGHT_PARAN 410 | ; 411 | 412 | instance_section 413 | = LEFT_PARAN 414 | >> SPACE 415 | >> INSTANCE [PrintTag()] 416 | >> SPACE 417 | >> section_name_or_rename 418 | >> SPACE 419 | >> viewref_section 420 | >> *(SPACE >> property_section) 421 | >> SPACE 422 | >> RIGHT_PARAN 423 | ; 424 | 425 | connection_type 426 | = JOINED | MUSTJOIN | CRITICALSIGNAL; 427 | 428 | instanceref_section 429 | = LEFT_PARAN 430 | >> SPACE 431 | >> INSTANCEREF [PrintTag()] 432 | >> SPACE 433 | >> only_string [PrintStr()] 434 | >> SPACE 435 | >> RIGHT_PARAN 436 | ; 437 | 438 | connections 439 | = LEFT_PARAN 440 | >> SPACE 441 | >> PORTREF [PrintTag()] 442 | >> SPACE 443 | >> only_string [PrintStr()] 444 | >> *(SPACE >> instanceref_section) 445 | >> SPACE 446 | >> RIGHT_PARAN 447 | ; 448 | 449 | routing_section 450 | = LEFT_PARAN 451 | >> SPACE 452 | >> connection_type [PrintStr()] 453 | >> *(SPACE >> connections) 454 | >> SPACE 455 | >> RIGHT_PARAN 456 | ; 457 | 458 | 459 | 460 | net_section 461 | = LEFT_PARAN 462 | >> SPACE 463 | >> NET [PrintTag()] 464 | >> SPACE 465 | >> section_name_or_rename 466 | >> SPACE 467 | >> routing_section 468 | >> SPACE 469 | >> RIGHT_PARAN 470 | ; 471 | 472 | contents_section 473 | = LEFT_PARAN 474 | >> SPACE 475 | >> CONTENTS [PrintTag()] 476 | >> *(SPACE >> instance_section) 477 | >> *(SPACE >> net_section) 478 | >> SPACE 479 | >> RIGHT_PARAN 480 | ; 481 | 482 | view_section 483 | = LEFT_PARAN 484 | >> SPACE 485 | >> VIEW [PrintTag()] 486 | >> SPACE 487 | >> section_name [PrintStr()] 488 | >> SPACE 489 | >> viewtype_section 490 | >> SPACE 491 | >> interface_section 492 | >> *(SPACE >> contents_section) 493 | >> SPACE 494 | >> RIGHT_PARAN 495 | ; 496 | 497 | cell_section 498 | = LEFT_PARAN 499 | >> SPACE 500 | >> CELL [PrintTag()] 501 | >> SPACE 502 | >> section_name_or_rename 503 | >> SPACE 504 | >> celltype_section 505 | >> SPACE 506 | >> view_section 507 | >> SPACE 508 | >> RIGHT_PARAN 509 | ; 510 | 511 | 512 | external_section 513 | = LEFT_PARAN 514 | >> SPACE 515 | >> EXTERNAL [PrintTag()] 516 | >> SPACE 517 | >> section_name [PrintStr()] 518 | >> SPACE 519 | >> ediflevel_section 520 | >> SPACE 521 | >> technolgy_section 522 | >> *(SPACE >> cell_section) 523 | >> SPACE 524 | >> RIGHT_PARAN 525 | ; 526 | 527 | library_section 528 | = LEFT_PARAN 529 | >> SPACE 530 | >> LIBRARY [PrintTag()] 531 | >> SPACE 532 | >> only_string [PrintStr()] 533 | >> SPACE 534 | >> ediflevel_section 535 | >> SPACE 536 | >> technolgy_section 537 | >> *(SPACE >> cell_section) 538 | >> SPACE 539 | >> RIGHT_PARAN 540 | ; 541 | 542 | design_section 543 | = LEFT_PARAN 544 | >> SPACE 545 | >> DESIGN [PrintTag()] 546 | >> SPACE 547 | >> section_name_or_rename 548 | >> SPACE 549 | >> cellref_section 550 | >> *(SPACE >> property_section) 551 | >> SPACE 552 | >> RIGHT_PARAN 553 | ; 554 | 555 | 556 | edif_section 557 | = LEFT_PARAN 558 | >> EDIF [PrintTag()] 559 | >> SPACE 560 | >> section_name_or_rename 561 | >> SPACE 562 | >> edifversion_section 563 | >> SPACE 564 | >> ediflevel_section 565 | >> SPACE 566 | >> keyword_section 567 | >> *(SPACE >> status_section) 568 | >> *(SPACE >> external_section) 569 | >> *(SPACE >> library_section) 570 | >> *(SPACE >> design_section) 571 | >> SPACE 572 | >> RIGHT_PARAN 573 | ; 574 | 575 | top = edif_section 576 | >> end_p ; 577 | } 578 | 579 | strlit<> EDIF, EDIFVERSION, EDIFLEVEL, STATUS, WRITTEN, TIMESTAMP, PROGRAM, PROGVERSION1, PROGVERSION2, 580 | DATAORIGIN, AUTHOR, KEYWORDMAP, KEYWORDLEVEL, EXTERNAL, TECHNOLOGY, NUMBERDEFINITION, 581 | CELL, CELLTYPE, GENERICUp, GENERICLow, TIE, RIPPER; 582 | 583 | strlit<> VIEW, VIEWTYPE, BEHAVIOR, DOCUMENT, GRAPHIC, LOGICMODEL, MASKLAYOUT, 584 | NETLISTUp, NETLISTLow, PCBLAYOUT, SCHEMATIC, STRANGER, SYMBOLIC; 585 | 586 | strlit<> INTERFACE, PORT, DIRECTION, INPUT, OUTPUT, INOUT; 587 | 588 | strlit<> CONTENTS, INSTANCE, VIEWREF, CELLREF, LIBRARYREF, 589 | NET, JOINED, MUSTJOIN, CRITICALSIGNAL, PORTREF, INSTANCEREF; 590 | 591 | strlit<> LIBRARY, DESIGN, SCALE, UNIT, PROPERTY, INTEGER, STRING, RENAME, OWNER; 592 | 593 | rule top; 594 | 595 | rule 596 | space, section_name, edif_section, edifversion_section, 597 | ediflevel_section, status_section, written_section, timestamp_section, 598 | program_section, programversion_section, dataorigin_setion, author_section, 599 | keyword_section, keywordlevel_section, external_section, technolgy_section, 600 | numberdefinition_section; 601 | 602 | rule 603 | cell_section, celltype_section, celltypesec_name, view_section, viewtype_section, 604 | viewtype_name, direction_section, direction_str, 605 | contents_section, instance_section, viewref_section, cellref_section; 606 | 607 | rule 608 | libraryref_section, net_section, routing_section, connections, 609 | connection_type, module_port_ref, instance_con, module_port, instanceref_section, 610 | library_section, design_section, scale_section, scalefactor_section, scaleunit_section; 611 | 612 | rule 613 | interface_section, ifcontent_section, port_section, property_section, propertyval_section, 614 | integerval_section, stringval_section, rename_section, section_name_or_rename, owner_section; 615 | 616 | rule 617 | any_string, string_val, alnum_name, string_without_right_paran, 618 | only_string ; 619 | 620 | rule SPACE, LEFT_BRACE, RIGHT_BRACE, LEFT_PARAN, RIGHT_PARAN; 621 | rule const& start() const { return top; } 622 | }; 623 | }; 624 | 625 | bool 626 | EDIFReader::Read(string fileName) 627 | { 628 | edif_grammar g; 629 | ifstream in(fileName.c_str()); 630 | if (!in) 631 | return false; 632 | in.unsetf(ios::skipws); //Switch off white space skipping on the stream 633 | 634 | CharList vec; 635 | std::copy(istream_iterator(in), istream_iterator(), std::back_inserter(vec)); 636 | 637 | ConstCharIter start = vec.begin(); 638 | ConstCharIter end = vec.end(); 639 | 640 | skip_grammar skip; 641 | string to_parse(start, end); 642 | //std::cout << "String to parse:" << std::endl << to_parse << std::endl; 643 | 644 | parse_info::const_iterator> result = parse(start, end, g, skip); 645 | 646 | std::cout << std::endl << "[" << result.full << "]" << std::endl; 647 | 648 | if (result.full) { 649 | std::cout << "Parsing Done...." << std::endl; 650 | return true; 651 | } else { 652 | std::cout << "Parsing Error:"; 653 | //for (int i = 0; i < 50; i++) 654 | while (1) 655 | { 656 | if (result.stop == end) { 657 | break; 658 | } 659 | std::cout << *result.stop++; 660 | } 661 | //std::cout << endl; 662 | return false; 663 | } 664 | } 665 | -------------------------------------------------------------------------------- /EDIFReader.hpp: -------------------------------------------------------------------------------- 1 | /**********************************************************************/ 2 | /* Author: Sumanish */ 3 | /* Modified By: Sumanish */ 4 | /* */ 5 | /* This source code can be downloaded, use, modify, distribute */ 6 | /* freely with this headed intact. Please don't delete this header. */ 7 | /**********************************************************************/ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | #include "boost/lambda/bind.hpp" 17 | 18 | 19 | using namespace boost::spirit; 20 | using namespace std; 21 | 22 | typedef std::vector CharList; 23 | typedef std::vector::const_iterator ConstCharIter; 24 | typedef std::vector::iterator CharIter; 25 | 26 | class EDIFReader { 27 | 28 | public: 29 | /// default constructor 30 | EDIFReader() { } 31 | bool Read(string filename); 32 | 33 | private: 34 | EDIFReader(const EDIFReader&); 35 | EDIFReader& operator=(const EDIFReader&); 36 | }; 37 | 38 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ######################################################################## 2 | ## Author: Sumanish ## 3 | ## Modified By: Sumanish ## 4 | ## ## 5 | ## This source code can be downloaded, use, modify, distribute ## 6 | ## freely with this headed intact. Please don't delete this header. ## 7 | ######################################################################## 8 | 9 | CC=g++ 10 | IPATHS=-I. -I/home/sumanish/Boost_1.68/boost_1_68_0 11 | CFLAGS=-g -w 12 | LPATHS=-L/home/sumanish/Boost_1.68/boost_1_68_0/stage/lib 13 | LFLAGS= 14 | DEPS = EDIFReader.hpp \ 15 | EDIFParserFunctors.hpp 16 | OBJS = EDIFReader.o \ 17 | main.o 18 | 19 | %.o: %.cpp $(DEPS) 20 | $(CC) -c -o $@ $< $(CFLAGS) $(IPATHS) 21 | 22 | Parse: $(OBJS) 23 | $(CC) -o $@ $^ $(CFLAGS) $(LPATHS) $(LFLAGS) 24 | 25 | clean: 26 | rm -f *.o *.log Parse 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ######################################################################## 2 | ## Author: Sumanish ## 3 | ## Modified By: Sumanish ## 4 | ## ## 5 | ## This source code can be downloaded, use, modify, distribute ## 6 | ## freely with this header intact. Please don't delete this header. ## 7 | ######################################################################## 8 | 9 | EDIF Parser 10 | A simple EDIF file parser using Boost. It just parses and prints. 11 | 12 | Development using, 13 | Fedora 28 14 | Boost_1.68 15 | GCC version 8.2.0 (GCC) 16 | 17 | Please note: It's under development. 99% possibility is that it will not work 18 | for most of the cases. 19 | -------------------------------------------------------------------------------- /example2.edif: -------------------------------------------------------------------------------- 1 | (edif (rename and "AND") 2 | (edifVersion 2 0 0) 3 | (edifLevel 0) 4 | (keywordMap (keywordLevel 0)) 5 | (library VIRTEX (edifLevel 0) (technology (numberDefinition)) 6 | (cell LUT2 (cellType GENERIC) 7 | (view PRIM (viewType NETLIST) 8 | (interface 9 | (port I0 (direction INPUT)) 10 | (port I1 (direction INPUT)) 11 | (port O (direction OUTPUT)) 12 | ) 13 | ) 14 | ) 15 | ) 16 | (library work (edifLevel 0) (technology (numberDefinition)) 17 | (cell (rename and "AND") (cellType GENERIC) 18 | (view verilog 19 | (viewType NETLIST) 20 | (interface 21 | (port i0 22 | (direction INPUT) 23 | ) 24 | (port i1 25 | (direction INPUT) 26 | ) 27 | (port o 28 | (direction OUTPUT) 29 | ) 30 | ) 31 | (contents 32 | (instance icfcd208495d565ef66e7dff9f98764da 33 | (viewRef PRIM (cellRef LUT2 (libraryRef VIRTEX))) 34 | (property INIT (string )) 35 | ) 36 | (net ic4ca4238a0b923820dcc509a6f75849b 37 | (joined 38 | (portRef i0) 39 | (portRef I0 (instanceRef icfcd208495d565ef66e7dff9f98764da)) 40 | ) 41 | ) 42 | (net ic81e728d9d4c2f636f067f89cc14862c 43 | (joined 44 | (portRef i1) 45 | (portRef I1 (instanceRef icfcd208495d565ef66e7dff9f98764da)) 46 | ) 47 | ) 48 | (net ieccbc87e4b5ce2fe28308fd9f2a7baf3 49 | (joined 50 | (portRef o) 51 | (portRef O (instanceRef icfcd208495d565ef66e7dff9f98764da)) 52 | ) 53 | ) 54 | ) 55 | ) 56 | ) 57 | ) 58 | (design (rename and "AND") (cellRef and (libraryRef work)) (property PART (string "xc5vlx30ff324-1") (owner "Xilinx"))) 59 | ) 60 | -------------------------------------------------------------------------------- /fibex_example.edif: -------------------------------------------------------------------------------- 1 | (edif fibex (edifVersion 2 0 0) 2 | (edifLevel 0) 3 | (keywordMap (keywordLevel 0)) 4 | (status 5 | (written 6 | (timeStamp 1995 11 22 23 2 53) 7 | (program "EDIFWRITER" (version "v8.4_2.1")) 8 | ) 9 | ) 10 | (library FIBEX 11 | (edifLevel 0) 12 | (technology (numberDefinition (scale 1 (e 1 -6) (unit distance)))) 13 | (cell dff_4 (cellType generic) 14 | (view view1 (viewType netlist) 15 | (interface 16 | (port aset (direction INPUT)) 17 | (port clock (direction INPUT)) 18 | (port data0 (direction INPUT)) 19 | (port data1 (direction INPUT)) 20 | (port data2 (direction INPUT)) 21 | (port data3 (direction INPUT)) 22 | (port q0 (direction OUTPUT)) 23 | (port q1 (direction OUTPUT)) 24 | (port q2 (direction OUTPUT)) 25 | (port q3 (direction OUTPUT)) 26 | (property LPM_Avalue (integer 1)) 27 | (property LPM_TYPE (string "LPM_FF")) 28 | (property LPM_FFTYPE (string "DFF")) 29 | (property LPM_Width (integer 4)) 30 | ) 31 | ) 32 | ) 33 | (cell addsub_4 (cellType generic) 34 | (view view1 (viewType netlist) 35 | (interface 36 | (port dataA0 (direction INPUT)) 37 | (port dataA1 (direction INPUT)) 38 | (port dataA2 (direction INPUT)) 39 | (port dataA3 (direction INPUT)) 40 | (port dataB0 (direction INPUT)) 41 | (port dataB1 (direction INPUT)) 42 | (port dataB2 (direction INPUT)) 43 | (port dataB3 (direction INPUT)) 44 | (port result0 (direction OUTPUT)) 45 | (port result1 (direction OUTPUT)) 46 | (port result2 (direction OUTPUT)) 47 | (port result3 (direction OUTPUT)) 48 | (property LPM_TYPE (string "LPM_ADD_SUB")) 49 | (property LPM_Width (integer 4)) 50 | ) 51 | ) 52 | ) 53 | (cell FIBEX (cellType generic) 54 | (view schematic (viewType netlist) 55 | (interface 56 | (port CLEAR (direction INPUT)) 57 | (port CLOCK (direction INPUT)) 58 | (port (rename RESULT_91_0_93_ "RESULT[0]") (direction INOUT)) 59 | (port (rename RESULT_91_1_93_ "RESULT[1]") (direction INOUT)) 60 | (port (rename RESULT_91_2_93_ "RESULT[2]") (direction INOUT)) 61 | (port (rename RESULT_91_3_93_ "RESULT[3]") (direction INOUT)) 62 | ) 63 | (contents 64 | (instance (rename I_36_1 "I$1") 65 | (viewRef view1 (cellRef dff_4)) 66 | ) 67 | (instance (rename I_36_3 "I$3") 68 | (viewRef view1 (cellRef addsub_4)) 69 | ) 70 | (instance (rename I_36_5 "I$5") 71 | (viewRef view1 (cellRef dff_4)) 72 | ) 73 | (net CLEAR 74 | (joined 75 | (portRef CLEAR) 76 | (portRef aset (instanceRef I_36_1)) 77 | (portRef aset (instanceRef I_36_5)) 78 | ) 79 | ) 80 | (net CLOCK 81 | (joined 82 | (portRef CLOCK) 83 | (portRef clock (instanceRef I_36_1)) 84 | (portRef clock (instanceRef I_36_5)) 85 | ) 86 | ) 87 | (net (rename LAST_91_0_93_ "LAST[0]") 88 | (joined 89 | (portRef data0 (instanceRef I_36_5)) 90 | (portRef dataB0 (instanceRef I_36_3)) 91 | (portRef q0 (instanceRef I_36_1)) 92 | ) 93 | ) 94 | (net (rename LAST_91_1_93_ "LAST[1]") 95 | (joined 96 | (portRef data1 (instanceRef I_36_5)) 97 | (portRef dataB1 (instanceRef I_36_3)) 98 | (portRef q1 (instanceRef I_36_1)) 99 | ) 100 | ) 101 | (net (rename LAST_91_2_93_ "LAST[2]") 102 | (joined 103 | (portRef data2 (instanceRef I_36_5)) 104 | (portRef dataB2 (instanceRef I_36_3)) 105 | (portRef q2 (instanceRef I_36_1)) 106 | ) 107 | ) 108 | (net (rename LAST_91_3_93_ "LAST[3]") 109 | (joined 110 | (portRef data3 (instanceRef I_36_5)) 111 | (portRef dataB3 (instanceRef I_36_3)) 112 | (portRef q3 (instanceRef I_36_1)) 113 | ) 114 | ) 115 | (net (rename PRESENT_91_0_93_ "PRESENT[0]") 116 | (joined 117 | (portRef dataA0 (instanceRef I_36_3)) 118 | (portRef q0 (instanceRef I_36_5)) 119 | ) 120 | ) 121 | (net (rename PRESENT_91_1_93_ "PRESENT[1]") 122 | (joined 123 | (portRef dataA1 (instanceRef I_36_3)) 124 | (portRef q1 (instanceRef I_36_5)) 125 | ) 126 | ) 127 | (net (rename PRESENT_91_2_93_ "PRESENT[2]") 128 | (joined 129 | (portRef dataA2 (instanceRef I_36_3)) 130 | (portRef q2 (instanceRef I_36_5)) 131 | ) 132 | ) 133 | (net (rename PRESENT_91_3_93_ "PRESENT[3]") 134 | (joined 135 | (portRef dataA3 (instanceRef I_36_3)) 136 | (portRef q3 (instanceRef I_36_5)) 137 | ) 138 | ) 139 | (net (rename RESULT_91_0_93_ "RESULT[0]") 140 | (joined 141 | (portRef RESULT_91_0_93_) 142 | (portRef data0 (instanceRef I_36_1)) 143 | (portRef result0 (instanceRef I_36_3)) 144 | ) 145 | ) 146 | (net (rename RESULT_91_1_93_ "RESULT[1]") 147 | (joined 148 | (portRef RESULT_91_1_93_) 149 | (portRef data1 (instanceRef I_36_1)) 150 | (portRef result1 (instanceRef I_36_3)) 151 | ) 152 | ) 153 | (net (rename RESULT_91_2_93_ "RESULT[2]") 154 | (joined 155 | (portRef RESULT_91_2_93_) 156 | (portRef data2 (instanceRef I_36_1)) 157 | (portRef result2 (instanceRef I_36_3)) 158 | ) 159 | ) 160 | (net (rename RESULT_91_3_93_ "RESULT[3]") 161 | (joined 162 | (portRef RESULT_91_3_93_) 163 | (portRef data3 (instanceRef I_36_1)) 164 | (portRef result3 (instanceRef I_36_3)) 165 | ) 166 | ) 167 | ) 168 | ) 169 | ) 170 | ) 171 | (design FIBEX (cellRef FIBEX (libraryRef FIBEX))) 172 | ) 173 | -------------------------------------------------------------------------------- /full_adder_nl.edif: -------------------------------------------------------------------------------- 1 | (edif moxon_edif (edifVersion 2 0 0) (edifLevel 0) 2 | (keywordMap (keywordLevel 0)) 3 | 4 | (status 5 | (written (timeStamp 2001 11 14 13 3 27) 6 | (program "vim" (Version "6.0")) 7 | (dataOrigin "moxon design") (author "tom moxon") 8 | ) 9 | ) 10 | 11 | (external generic_gates (edifLevel 0) (technology (numberDefinition)) 12 | 13 | (cell an02d1 (cellType GENERIC) 14 | (view Netlist_representation (viewType NETLIST) 15 | (interface 16 | (port A1 (direction INPUT)) 17 | (port A2 (direction INPUT)) 18 | (port Z (direction OUTPUT)) 19 | ) 20 | ) 21 | ) 22 | 23 | (cell xo02d1 (cellType GENERIC) 24 | (view Netlist_representation (viewType NETLIST) 25 | (interface 26 | (port A1 (direction INPUT)) 27 | (port A2 (direction INPUT)) 28 | (port Z (direction OUTPUT)) 29 | ) 30 | ) 31 | ) 32 | 33 | (cell or03d1 (cellType GENERIC) 34 | (view Netlist_representation (viewType NETLIST) 35 | (interface 36 | (port A1 (direction INPUT)) 37 | (port A2 (direction INPUT)) 38 | (port A3 (direction INPUT)) 39 | (port Z (direction OUTPUT)) 40 | ) 41 | ) 42 | ) 43 | 44 | ) 45 | 46 | (library DESIGNS (edifLevel 0) (technology (numberDefinition)) 47 | (cell full_adder (cellType GENERIC) 48 | (view Netlist_representation (viewType NETLIST) 49 | (interface 50 | (port A (direction INPUT)) 51 | (port B (direction INPUT)) 52 | (port CI (direction INPUT)) 53 | (port S (direction OUTPUT)) 54 | (port CO (direction OUTPUT)) 55 | ) 56 | 57 | (contents 58 | 59 | (instance U1 60 | (viewRef Netlist_representation 61 | (cellRef xo02d1 (libraryRef generic_gates)) 62 | ) 63 | ) 64 | (instance U2 65 | (viewRef Netlist_representation 66 | (cellRef xo02d1 (libraryRef generic_gates)) 67 | ) 68 | ) 69 | (instance U3 70 | (viewRef Netlist_representation 71 | (cellRef an02d1 (libraryRef generic_gates)) 72 | ) 73 | ) 74 | (instance U4 75 | (viewRef Netlist_representation 76 | (cellRef an02d1 (libraryRef generic_gates)) 77 | ) 78 | ) 79 | (instance U5 80 | (viewRef Netlist_representation 81 | (cellRef an02d1 (libraryRef generic_gates)) 82 | ) 83 | ) 84 | (instance U6 85 | (viewRef Netlist_representation 86 | (cellRef or03d1 (libraryRef generic_gates)) 87 | ) 88 | ) 89 | 90 | (net A 91 | (joined 92 | (portRef A) 93 | (portRef A1 (instanceRef U1)) 94 | (portRef A1 (instanceRef U3)) 95 | (portRef A1 (instanceRef U4)) 96 | ) 97 | ) 98 | 99 | (net B 100 | (joined 101 | (portRef B) 102 | (portRef A2 (instanceRef U1)) 103 | (portRef A2 (instanceRef U3)) 104 | (portRef A1 (instanceRef U5)) 105 | ) 106 | ) 107 | 108 | (net CI 109 | (joined 110 | (portRef CI) 111 | (portRef A2 (instanceRef U2)) 112 | (portRef A2 (instanceRef U4)) 113 | (portRef A2 (instanceRef U5)) 114 | ) 115 | ) 116 | 117 | (net NET1 118 | (joined 119 | (portRef Z (instanceRef U1)) 120 | (portRef A1 (instanceRef U2)) 121 | ) 122 | ) 123 | 124 | (net NET2 125 | (joined 126 | (portRef Z (instanceRef U3)) 127 | (portRef A1 (instanceRef U6)) 128 | ) 129 | ) 130 | 131 | (net NET3 132 | (joined 133 | (portRef Z (instanceRef U4)) 134 | (portRef A2 (instanceRef U6)) 135 | ) 136 | ) 137 | 138 | (net NET4 139 | (joined 140 | (portRef Z (instanceRef U5)) 141 | (portRef A3 (instanceRef U6)) 142 | ) 143 | ) 144 | 145 | (net S 146 | (joined 147 | (portRef S) 148 | (portRef Z (instanceRef U2))) 149 | ) 150 | 151 | (net CO 152 | (joined 153 | (portRef CO) 154 | (portRef Z (instanceRef U6))) 155 | ) 156 | 157 | ) 158 | 159 | ) 160 | ) 161 | 162 | ) 163 | (design moxon_edif (cellRef full_adder (libraryRef DESIGNS))) 164 | ) 165 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | /**********************************************************************/ 2 | /* Author: Sumanish */ 3 | /* Modified By: Sumanish */ 4 | /* */ 5 | /* This source code can be downloaded, use, modify, distribute */ 6 | /* freely with this headed intact. Please don't delete this header. */ 7 | /**********************************************************************/ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "EDIFReader.hpp" 14 | 15 | using namespace std; 16 | 17 | 18 | int main(int argc, char* argv[]) { 19 | 20 | if(argc < 2){ 21 | cout << "Usage:./" << argv[0] << "" << endl; 22 | exit(1); 23 | } 24 | 25 | string file(argv[1]); 26 | EDIFReader reader; 27 | reader.Read(file); 28 | return 0; 29 | } 30 | --------------------------------------------------------------------------------