magic/router/tclroute.c

96 lines
2.9 KiB
C
Raw Normal View History

/*--------------------------------------------------------------*/
/* tclroute.c */
/* */
/* Allows the "router" feature to be loaded as a module */
/* under the Tcl/Tk version of magic. Loading is */
/* automatic upon invoking one of the router commands. */
/*--------------------------------------------------------------*/
#ifdef ROUTE_AUTO
#include <stdio.h>
#include <string.h>
#include "tcltk/tclmagic.h"
#include "utils/magic.h"
#include "utils/geometry.h"
#include "tiles/tile.h"
#include "utils/hash.h"
#include "utils/heap.h"
#include "utils/list.h"
#include "database/database.h"
#include "windows/windows.h"
#include "commands/commands.h"
#include "utils/tech.h"
#include "dbwind/dbwind.h"
#include "router/router.h"
#include "gcr/gcr.h"
#include "grouter/grouter.h"
#include "mzrouter/mzrouter.h"
/* External routines */
extern void CmdRoute(), CmdIRoute(), CmdGaRoute();
extern void CmdChannel(), CmdSeeFlags();
extern void CmdGARouterTest(), CmdGRouterTest();
extern void CmdIRouterTest(), CmdMZRouterTest();
/*
* ----------------------------------------------------------------------------
*
* Tcl package initialization function
*
* ----------------------------------------------------------------------------
*/
int
Tclroute_Init(interp)
Tcl_Interp *interp;
{
SectionID invsec;
/* Sanity checks! */
if (interp == NULL) return TCL_ERROR;
build: isolate build-info defines into utils/buildinfo.c (ccache-friendly) MAGIC_VERSION / MAGIC_REVISION / MAGIC_COMMIT / MAGIC_BUILDDATE were on the global DFLAGS, so every object's compile command line carried them. Because the command line is part of ccache/sccache's hash key and MAGIC_BUILDDATE changes every second, that meant a cache miss on every unit on every build; it also smeared the baked-in date/commit across "whenever each file last recompiled". Move the four values into a single translation unit: * utils/magic_buildinfo.h -- extern MagicVersion/MagicRevision/MagicCommit/ MagicCompileTime (MagicCommit is new; the other three moved here from utils/magic.h, which now includes this header). * utils/buildinfo.c -- the ONLY unit compiled with the version defines (target-specific `buildinfo.o: DFLAGS += ${DFLAGS_MAGICVERSION}` in utils/Makefile.in); it defines the four globals. ${DFLAGS_MAGICVERSION} is removed from the global DFLAGS/DFLAGS_NOSTUB. Consumers updated to read the runtime symbol instead of the compile-time macro: * magicTop.c / tclmagic.c no longer define the globals (the MAGIC_WRAPPER duplicate-symbol guard is gone -- buildinfo.o owns them for every variant, including WASM, which links both mains). * Tcl_PkgProvide/PkgRequire in router/ext2spice/lef/ext2sim/plot/tclmagic now pass MagicVersion. * extflat: EFVersion (a static-initialized copy of MAGIC_VERSION) is dropped; EFread.c compares the .ext version against MagicVersion directly -- the same value ExtCell.c already *writes* into .ext files, so read and write are now consistent. Verified: only buildinfo.o carries -DMAGIC_* (hash/DBio/windCmdSZ carry none); Tcl (375 files) and --without-tcl builds rc=0, version/commit/date embedded in tclmagic.so, magicTop.o no longer defines MagicVersion; in-tree source clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-23 15:55:20 +02:00
if (Tcl_PkgRequire(interp, "Tclmagic", MagicVersion, 0) == NULL)
return TCL_ERROR;
2024-10-21 10:19:15 +02:00
if (Tcl_InitStubs(interp, Tclmagic_InitStubsVersion, 0) == NULL) return TCL_ERROR;
TxPrintf("Auto-loading ROUTE module\n");
TxFlushOut();
/* Replace the auto-load function with the ones defined in */
/* this package in the command functions list. */
WindReplaceCommand(DBWclientID, "route", CmdRoute);
WindReplaceCommand(DBWclientID, "garoute", CmdRoute);
WindReplaceCommand(DBWclientID, "iroute", CmdIRoute);
WindReplaceCommand(DBWclientID, "channels", CmdChannel);
WindReplaceCommand(DBWclientID, "*garoute", CmdGARouterTest);
WindReplaceCommand(DBWclientID, "*groute", CmdGRouterTest);
WindReplaceCommand(DBWclientID, "*iroute", CmdIRouterTest);
WindReplaceCommand(DBWclientID, "*mzroute", CmdMZRouterTest);
WindReplaceCommand(DBWclientID, "*seeflags", CmdSeeFlags);
/* Now we need to do TechAddClient and reload the tech file */
TechAddClient("mzrouter", MZTechInit, MZTechLine, MZTechFinal,
(SectionID) 0, (SectionID *) 0, FALSE);
TechAddClient("router", RtrTechInit, RtrTechLine, RtrTechFinal,
(SectionID) 0, (SectionID *) 0, FALSE);
/* Initialization functions */
NMinit();
MZInit();
IRInit();
invsec = TechSectionGetMask("drc", NULL);
invsec &= TechSectionGetMask("mzrouter", NULL);
invsec &= TechSectionGetMask("router", NULL);
if (!TechLoad(NULL, invsec)) return TCL_ERROR;
build: isolate build-info defines into utils/buildinfo.c (ccache-friendly) MAGIC_VERSION / MAGIC_REVISION / MAGIC_COMMIT / MAGIC_BUILDDATE were on the global DFLAGS, so every object's compile command line carried them. Because the command line is part of ccache/sccache's hash key and MAGIC_BUILDDATE changes every second, that meant a cache miss on every unit on every build; it also smeared the baked-in date/commit across "whenever each file last recompiled". Move the four values into a single translation unit: * utils/magic_buildinfo.h -- extern MagicVersion/MagicRevision/MagicCommit/ MagicCompileTime (MagicCommit is new; the other three moved here from utils/magic.h, which now includes this header). * utils/buildinfo.c -- the ONLY unit compiled with the version defines (target-specific `buildinfo.o: DFLAGS += ${DFLAGS_MAGICVERSION}` in utils/Makefile.in); it defines the four globals. ${DFLAGS_MAGICVERSION} is removed from the global DFLAGS/DFLAGS_NOSTUB. Consumers updated to read the runtime symbol instead of the compile-time macro: * magicTop.c / tclmagic.c no longer define the globals (the MAGIC_WRAPPER duplicate-symbol guard is gone -- buildinfo.o owns them for every variant, including WASM, which links both mains). * Tcl_PkgProvide/PkgRequire in router/ext2spice/lef/ext2sim/plot/tclmagic now pass MagicVersion. * extflat: EFVersion (a static-initialized copy of MAGIC_VERSION) is dropped; EFread.c compares the .ext version against MagicVersion directly -- the same value ExtCell.c already *writes* into .ext files, so read and write are now consistent. Verified: only buildinfo.o carries -DMAGIC_* (hash/DBio/windCmdSZ carry none); Tcl (375 files) and --without-tcl builds rc=0, version/commit/date embedded in tclmagic.so, magicTop.o no longer defines MagicVersion; in-tree source clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-23 15:55:20 +02:00
Tcl_PkgProvide(interp, "Route", MagicVersion);
return TCL_OK;
}
#endif /* ROUTE_AUTO */