aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2013-05-23 12:56:23 +0200
committerClifford Wolf <clifford@clifford.at>2013-05-23 12:56:23 +0200
commitcbe423a1fe67a9f7154d56d968fb059a4f92f2ad (patch)
tree8bba6075296ef906732177f9b0a3927d0138f870
parent375f83c5ecde82226c33fbfb89463e92548ecf63 (diff)
downloadyosys-cbe423a1fe67a9f7154d56d968fb059a4f92f2ad.tar.gz
yosys-cbe423a1fe67a9f7154d56d968fb059a4f92f2ad.tar.bz2
yosys-cbe423a1fe67a9f7154d56d968fb059a4f92f2ad.zip
Only initialize TCL interpreter when needed
-rw-r--r--kernel/driver.cc80
-rw-r--r--kernel/register.cc5
-rw-r--r--kernel/register.h4
3 files changed, 50 insertions, 39 deletions
diff --git a/kernel/driver.cc b/kernel/driver.cc
index 3de16e724..b43df868d 100644
--- a/kernel/driver.cc
+++ b/kernel/driver.cc
@@ -269,30 +269,8 @@ struct ScriptPass : public Pass {
} ScriptPass;
#ifdef YOSYS_ENABLE_TCL
-struct TclPass : public Pass {
- TclPass() : Pass("tcl", "execute a TCL script file") { }
- virtual void help() {
- log("\n");
- log(" tcl <filename>\n");
- log("\n");
- log("This command executes the tcl commands in the specified file.\n");
- log("Use 'yosys cmd' to run the yosys command 'cmd' from tcl.\n");
- log("\n");
- log("The tcl command 'yosys -import' can be used to import all yosys\n");
- log("commands directly as tcl commands to the tcl shell. The yosys\n");
- log("command 'proc' is wrapped using the tcl command 'procs' in order\n");
- log("to avoid a name collision with the tcl builting command 'proc'.\n");
- log("\n");
- }
- virtual void execute(std::vector<std::string> args, RTLIL::Design *design) {
- if (args.size() < 2)
- log_cmd_error("Missing script file.\n");
- if (args.size() > 2)
- extra_args(args, 1, design, false);
- if (Tcl_EvalFile(yosys_tcl, args[1].c_str()) != TCL_OK)
- log_cmd_error("TCL interpreter returned an error: %s\n", Tcl_GetStringResult(yosys_tcl));
- }
-} TclPass;
+static Tcl_Interp *yosys_tcl_interp = NULL;
+static RTLIL::Design *yosys_tcl_design = NULL;
static int tcl_yosys_cmd(ClientData, Tcl_Interp *interp, int argc, const char *argv[])
{
@@ -324,6 +302,45 @@ static int tcl_yosys_cmd(ClientData, Tcl_Interp *interp, int argc, const char *a
Pass::call(yosys_tcl_design, args);
return TCL_OK;
}
+
+extern Tcl_Interp *yosys_get_tcl_interp()
+{
+ if (yosys_tcl_interp == NULL) {
+ yosys_tcl_interp = Tcl_CreateInterp();
+ Tcl_CreateCommand(yosys_tcl_interp, "yosys", tcl_yosys_cmd, NULL, NULL);
+ }
+ return yosys_tcl_interp;
+}
+
+extern RTLIL::Design *yosys_get_tcl_design()
+{
+ return yosys_tcl_design;
+}
+
+struct TclPass : public Pass {
+ TclPass() : Pass("tcl", "execute a TCL script file") { }
+ virtual void help() {
+ log("\n");
+ log(" tcl <filename>\n");
+ log("\n");
+ log("This command executes the tcl commands in the specified file.\n");
+ log("Use 'yosys cmd' to run the yosys command 'cmd' from tcl.\n");
+ log("\n");
+ log("The tcl command 'yosys -import' can be used to import all yosys\n");
+ log("commands directly as tcl commands to the tcl shell. The yosys\n");
+ log("command 'proc' is wrapped using the tcl command 'procs' in order\n");
+ log("to avoid a name collision with the tcl builting command 'proc'.\n");
+ log("\n");
+ }
+ virtual void execute(std::vector<std::string> args, RTLIL::Design *design) {
+ if (args.size() < 2)
+ log_cmd_error("Missing script file.\n");
+ if (args.size() > 2)
+ extra_args(args, 1, design, false);
+ if (Tcl_EvalFile(yosys_get_tcl_interp(), args[1].c_str()) != TCL_OK)
+ log_cmd_error("TCL interpreter returned an error: %s\n", Tcl_GetStringResult(yosys_get_tcl_interp()));
+ }
+} TclPass;
#endif
int main(int argc, char **argv)
@@ -337,11 +354,6 @@ int main(int argc, char **argv)
bool scriptfile_tcl = false;
bool got_output_filename = false;
-#ifdef YOSYS_ENABLE_TCL
- yosys_tcl = Tcl_CreateInterp();
- Tcl_CreateCommand(yosys_tcl, "yosys", tcl_yosys_cmd, NULL, NULL);
-#endif
-
int opt;
while ((opt = getopt(argc, argv, "Sm:f:b:o:p:l:qts:c:")) != -1)
{
@@ -497,8 +509,8 @@ int main(int argc, char **argv)
if (!scriptfile.empty()) {
if (scriptfile_tcl) {
#ifdef YOSYS_ENABLE_TCL
- if (Tcl_EvalFile(yosys_tcl, scriptfile.c_str()) != TCL_OK)
- log_error("TCL interpreter returned an error: %s\n", Tcl_GetStringResult(yosys_tcl));
+ if (Tcl_EvalFile(yosys_get_tcl_interp(), scriptfile.c_str()) != TCL_OK)
+ log_error("TCL interpreter returned an error: %s\n", Tcl_GetStringResult(yosys_get_tcl_interp()));
#else
log_error("Can't exectue TCL script: this version of yosys is not built with TCL support enabled.\n");
#endif
@@ -533,7 +545,11 @@ int main(int argc, char **argv)
dlclose(mod);
#ifdef YOSYS_ENABLE_TCL
- Tcl_DeleteInterp(yosys_tcl);
+ if (yosys_tcl_interp != NULL) {
+ Tcl_DeleteInterp(yosys_tcl_interp);
+ Tcl_Finalize();
+ yosys_tcl_interp = NULL;
+ }
#endif
return 0;
diff --git a/kernel/register.cc b/kernel/register.cc
index f4e973889..dae47f976 100644
--- a/kernel/register.cc
+++ b/kernel/register.cc
@@ -27,11 +27,6 @@
using namespace REGISTER_INTERN;
#define MAX_REG_COUNT 1000
-#ifdef YOSYS_ENABLE_TCL
-Tcl_Interp *yosys_tcl = NULL;
-RTLIL::Design *yosys_tcl_design = NULL;
-#endif
-
namespace REGISTER_INTERN
{
int raw_register_count = 0;
diff --git a/kernel/register.h b/kernel/register.h
index 2f664e7c1..5bd8216c7 100644
--- a/kernel/register.h
+++ b/kernel/register.h
@@ -28,8 +28,8 @@
#ifdef YOSYS_ENABLE_TCL
#include <tcl.h>
-extern Tcl_Interp *yosys_tcl;
-extern RTLIL::Design *yosys_tcl_design;
+extern Tcl_Interp *yosys_get_tcl_interp();
+extern RTLIL::Design *yosys_get_tcl_design();
#endif
struct Pass
#n374'>374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673