Commit Graph

2631 Commits

Author SHA1 Message Date
R. Timothy Edwards 60061ea33f Missed one additional place where an "#ifdef MAGIC_NO_TK" block
was needed, in the last commit.  This fix should make the CI run
clean again.
2026-06-25 09:23:09 -04:00
R. Timothy Edwards e7b8e89d2f Added a few lines to ResMerge.c which avoid a crash condition when
a resistor subnet has been linked to itself (or something like that).
Otherwise it leads to a double-free and a crash.  This commit does
not address why the subnet was linked to itself, and the crash was
preceded by another internal diagnostic message "Missing rptr at ..."
which has been noted before but still needs to be tracked down and
fixed.  It is likely that a bad output netlist was created, but at
least magic doesn't segfault.
2026-06-24 13:51:40 -04:00
R. Timothy Edwards b266ec6272 Implemented the resistor "pi" model, which evenly splits the
capacitance of a resistor device between the two terminals.  If
the resistor device model contains the capacitance, then the
resistor type should not be included in types that generate
parasitics.  If not, then the "pi" model is used.  The "tee" model
is still available using "ext2spice resistor tee on".  What this
update does is to default to the "pi" model instead of ignoring
the capacitance of the resistor type (e.g., "rm1"), and because
the capacitance of that node is removed after distributing it
between the two terminals, it will no longer produce a "floating"
node in the netlist output.
2026-06-24 10:34:23 -04:00
R. Timothy Edwards 338b3899bf I broke the CI again for the "wasm" build by adding a Tk routine
to the code (Tk_RestrictEvents()) without an "#ifndef MAGIC_NO_TK"
around it.  This commit fixes that error.
2026-06-24 09:20:06 -04:00
R. Timothy Edwards 3b272cc8d2 Corrected two "extresist" issues: (1) Prevent a segfault when
reading a resistor device which uses the syntax where the resistor
is given a value directly and not as a parameter;  (2) allow the
use of "extresist minres 0" (allow resistors in the output no
matter how small).  Thanks to Torleif Skaar for finding the issue
with the resistor syntax.
2026-06-23 19:41:53 -04:00
R. Timothy Edwards 06f0ce4259 One correction to the previous commit to avoid running
Tk_RestrictEvents() when in batch mode (no graphics, therefore no
Tk);  otherwise, this causes magic to segfault.
2026-06-23 10:53:47 -04:00
R. Timothy Edwards d8046fba2d Corrected the other issue with timers in magic, which is that the
"progress report" of percent completion on certain long-running
processes (namely extraction, DEF reads, and GDS/CIF writes) was
allowing Tcl/Tk events to be processed so that the display would
be repainted and the console window updated to show the progress
instead of hanging.  But that was allowing any key macros or
commands to be entered and executed, potentially corrupting the
database while the process was running.  I have used
Tk_RestrictEvents() to prevent key and button events from being
processed until afterward.  This preserves the display updates
(which do not alter the database) while preventing commands from
being run during one of these long-running processes.  Also:
Previously, whenever a long-running process printed the status,
it would not update at the end, leaving output like "52% complete"
being the last output, leaving the impression that the process
never finished.  Changed the code so that if any partial progress
is printed, then it will always finish up with the output "100%
complete" so that it is clear to the user that everything went
according to plan.
2026-06-23 10:08:31 -04:00
R. Timothy Edwards 5cf1a46061 Corrected two errors with the crash backup mechanism, one minor, one
very major.  The filename created had two slashes in the string
("/tmp//MAG...") because the temporary directory already has a slash
in the string.  This makes no practical difference but looks odd when
printed to the terminal.  The major error is that the Tcl script
that re-establishes the timer after a backup had a typo that caused
the timer never to be reset, resulting in crash backup files that are
created and written once but never again.  This egregious error has
now finally been fixed.
2026-06-22 21:52:06 -04:00
R. Timothy Edwards f4b210a9c0 Made a correction to the last commit, which is that when searching
a shielded substrate area for devices with terminals connecting to
substrate, search the entire cell hierarchy down to the bottom in
that area, not just the immediate child cell.  Also:  Reduced the
number of types being searched to ignore types in non-substrate
areas like nwell, although it should not make a practical difference
because those areas should not be searched.
2026-06-22 20:03:30 -04:00
R. Timothy Edwards 381714e2d5 Modified behavior with regard to substrate shield types being inside
a subcell:  A further check is done to see if there are any devices
that interact with the substrate in the shielded area in the same
subcell.  If not, then this is a trivial case where a different
substrate area exists but does not impact the subcell and should be
ignored.  This change prevents some extraction errors where a substrate
area can get isolated because there was an unrelated substrate area
nearby.  Also:  Corrected parsing of "dsubckt" types when reading .ext
files;  this applies to any device where the optional substrate is
omitted.  There are apparently two conflicting methods when a device
doesn't have a substrate:  (1) Output "None" for the substrate, or
(2) don't output anything.  The 2nd method can be detected by counting
the number of arguments on the line in the .ext file.  The extflat/
EFread.c code handles both methods.  ResReadExtFile() now does too,
but probably code should be changed to just use method (1) always.
Also:  Prevented the "tile not visited" error message in "extresist"
from printing duplicate messages for every device associated with the
same tile.  The message can appear when a labeled net has unconnected
regions, and "extract do unique" is not used.
2026-06-13 16:08:05 -04:00
R. Timothy Edwards d44aeaa1d1 Incremented the version to go along with, and to test, the merge
of pull request #527 from Enno, which allows the AppImage workflow
to trigger on a version update when the version number doesn't
start with a "v", as is the case for the repositories on
opencircuitdesign.com.
2026-06-10 08:54:50 -04:00
Enno Schnackenberg a7f2a38d32 Accept release tags without v prefix in the WASM npm publish gate.
The AppImage release workflows trigger on any tag (the project tags
releases as e.g. 8.3.662, without a v prefix), but the npm publish
gate in main-wasm.yml required a v-prefixed tag, so a normal release
tag built the AppImages but never published the npm package to GitHub
Packages.  The gate now accepts both forms, so a single tag releases
everything.
2026-06-10 11:40:15 +02:00
R. Timothy Edwards a38fa29dac Added a check for exts_globSubstratePlane == -1 in ExtBasic.c,
because this is the default value used if no substrate types are
declared in the tech file;  and if so, this would cause an out-
of-bounds check.  See Issue #523 on github from Darryl Miles.
2026-06-09 17:41:28 -04:00
R. Timothy Edwards 295ec7e492 Corrected the hash tables recently added to the code in resis/,
which used "HT_CLIENTKEYS" when they were intended to use
"HT_WORDKEYS".  See github issue #525 raised by Darryl Miles.
2026-06-09 17:37:51 -04:00
R. Timothy Edwards f650248764 Revised the code of PR #487 (previous merge) to follow the
formatting used for other subroutines.
2026-06-09 16:17:57 -04:00
Gon Solo 8466279b6c Fix K%R in DBbound.c. 2026-06-09 16:16:21 -04:00
R. Timothy Edwards 7296aca107 Updated the version to go along with the merge of pull request #519
from Enno Schnackenberg (adding Tcl support for WASM builds).
2026-06-09 16:09:14 -04:00
Enno Schnackenberg 50320a055a npm: surface readable diagnostics on WASM test failures
The example/suite runners discarded e.stack via console.error(e.message ?? e),
hiding the wasm-function offsets that emsymbolizer needs to map an abort back
to C source. A failing test only printed a terse message like "memory access
out of bounds" with no trace.

- Add reportError() to helpers.js/helpers-tcl.js; print the full stack
  (falling back to the message).
- Wrap command execution in runScript() to name the command that aborted
  before the error propagates.
- Use reportError() in all standalone runners and in all.js/all-tcl.js
  (full stack to stderr, one-line PASS/FAIL summary kept; tests still run
  independently).
- build.sh: run the --test step in a subshell so its cd does not leak into
  the --pack step.
2026-06-09 16:07:53 -04:00
Enno Schnackenberg d37793e7d0 update build.sh and readme.md 2026-06-09 16:07:53 -04:00
Intubun 4669fa9a9f Changed versioning scheme for npm package and update Readme.md 2026-06-09 16:07:53 -04:00
Intubun 4fe8f12595 update npm versioning, build.sh and delete tcl.ref and fix to latest stable 2026-06-09 16:07:53 -04:00
Intubun bc340fba16 build-tcl-wasm.sh: guard against missing tclConfig.sh after emconfigure 2026-06-09 16:07:53 -04:00
Intubun c4923d44a2 fix: sscanf length bound in TclmagicRegisterCommands; show output-tcl in CI
Add explicit length limit to sscanf in TclmagicRegisterCommands: %92s
instead of %s prevents a potential stack overwrite if a command name
were ever longer than the buffer. Matches the available space (keyword[100]
minus the 7-byte "magic::" prefix minus null).

Extend the CI output-display step to also iterate over output-tcl/ so
that TCL-variant test regressions are visible in the job log without
downloading artifacts.
2026-06-09 16:07:53 -04:00
Intubun 1ca85fa372 fix: three correctness fixes before PR
tclmagic.c: remove stray /*-----*/ line left over from a previous edit
that left a duplicate comment opener before TclmagicRegisterCommands.

magicWasm.c: move TxSetPoint inside the #else (non-TCL) branch of
magic_wasm_source_file and restore its explanation comment. TxSetPoint
routes TxDispatch commands to the layout window; it is irrelevant and
misleading in the Tcl_EvalFile path.

magic/Makefile: guard the TCL linker flags in the magic.js link rule
with ifneq (${TCL_LIB_DIR},). When building the non-TCL WASM variant
TCL_LIB_DIR is empty, so the unconditional -L${TCL_LIB_DIR} -ltclstub
expanded to a bare -L flag and a missing library, breaking the notcl
build.
2026-06-09 16:07:53 -04:00
Intubun 6efb44db0a fix: remove remaining intubun/tcl references and dead workflow comment
Replace the last three intubun/tcl mentions with tcltk/tcl in
npm/tcl.js, toolchains/emscripten/build-tcl-wasm.sh, and npm/tcl.ref.
Also remove the stale comment in tcl.ref that referenced a non-existent
update-tcl GitHub Actions workflow.
2026-06-09 16:07:53 -04:00
Intubun db36e896e6 refactor(tcl-examples): rename TCL scripts, drop dead pcell.tcl, fix comments and naming
Rename *-magic.tcl scripts to *-tcl.tcl to match the -tcl.js test naming
convention. Delete the old bare-command pcell.tcl (used cellname create,
no magic:: prefix) and promote pcell-magic.tcl to pcell.tcl.

Fix misleading comment in magicWasm.c: Tclmagic_Init only bootstraps the
interpreter; magic:: commands are registered separately by
TclmagicRegisterCommands after magicMainInit. Align comment block
dashes in TclmagicRegisterCommands to match tclmagic.c style (62 dashes).

Replace intubun/tcl references in build scripts and CI with tcltk/tcl to
match the actual pinned repo in npm/tcl.ref. Also run both test suites
when build.sh is invoked with --test.
2026-06-09 16:07:53 -04:00
Intubun ed576b23c8 fix(pcell): use magic::load to switch cell context before painting 2026-06-09 16:07:53 -04:00
Intubun 7c71d0f3e5 test(tcl): add TCL variant test suite including PCell generation
All non-TCL tests (extract, gds, drc, cif) now also run against the TCL
variant using magic::-prefixed Tcl scripts. A new PCell test generates
two parameterized rectangle cells and verifies their GDS output.

The CI workflow runs npm run test:tcl after the TCL build and saves the
generated output files as an artifact.
2026-06-09 16:07:53 -04:00
Intubun 5801acce62 fix(tcl-wasm): register magic:: Tcl commands after C initialization completes
magic_wasm_init() called Tclmagic_Init() and magicMainInit() but never
ran the command-registration loop in _magic_initialize(), so magic::tech,
magic::load, magic::gds and all other Magic commands were missing from
the Tcl interpreter.

Add TclmagicRegisterCommands() in tclmagic.c containing the
WindNextClient/WindGetCommandTable loop and call it from magic_wasm_init()
after magicMainInit() succeeds.

Also change magic_wasm_source_file() to use Tcl_EvalFile in MAGIC_WRAPPER
mode so scripts with magic:: commands are evaluated through the Tcl
interpreter instead of the plain text dispatcher.
2026-06-09 16:07:53 -04:00
Intubun 4dd0cfd472 docs(npm): add GitHub Packages install instructions and TCL variant documentation 2026-06-09 16:07:53 -04:00
Intubun d873cd7f2b wasm: increase initial memory to 64 MB and stack to 10 MB for larger designs 2026-06-09 16:07:53 -04:00
Intubun 2f2faf68eb Update tcl.ref 2026-06-09 16:07:53 -04:00
Intubun ab2515fd8f Update main-wasm.yml 2026-06-09 16:07:53 -04:00
Enno Schnackenberg e45db485d8 Add TCL-embedded WASM build variant alongside the existing non-TCL build
Bump VERSION to 8.3.645.

magic.wasm can now be built as two variants packaged in the same npm
release: notcl/ (legacy, magic's own parser) and tcl/ (intubun/tcl 9.x
statically linked, commands evaluated by Tcl_EvalEx). The TCL fork is
pinned via npm/tcl.ref and cloned/built by magic itself — the tcl/
checkout is treated as read-only and built out-of-source into
magic/build-tcl-wasm/.

Configure layer:
- New usingTk variable decoupled from usingTcl in scripts/configure.in
  + scripts/configure, so --with-tcl --without-tk is finally a valid
  combination. Native Linux Tcl+Tk builds keep their previous behaviour
  (both flags default to enabled).
- When usingTk is empty, configure passes -DMAGIC_NO_TK so the small
  number of remaining Tk callsites in tcltk/tclmagic.{h,c} compile out,
  and TKCOMMON_SRCS / USE_TK_STUBS are omitted from the link.

WASM build orchestration:
- toolchains/emscripten/build-tcl-wasm.sh builds libtcl9.x.a + libtclstub.a
  + tclConfig.sh out-of-source from a pristine intubun/tcl checkout.
- npm/build.sh grew a --variant=<tcl|notcl|both> flag and writes its
  outputs into npm/tcl/ and npm/notcl/. It also clones intubun/tcl with
  autocrlf=false at the SHA pinned by npm/tcl.ref.
- magic/Makefile (WASM block only): magicWasm.o is now compiled with
  DFLAGS_NOSTUB so Tcl_CreateInterp resolves to libtcl9.x directly
  before tclStubsPtr is set. magic.js link pulls in LIB_SPECS_NOSTUB
  and -ltclstub. After rules.mak include, magic: is a phony alias for
  magic.js so the generic ${MODULE} recipe doesn't fight it.
- toolchains/emscripten/defs.mak: add -sUSE_ZLIB=1 (libtcl9 references
  zlib), replace -sSTACK_SIZE=N with -Wl,-z,stack-size=N (emcc >=5
  rejects the setting form).
- magic/magicWasm.c bootstraps the embedded interp under MAGIC_WRAPPER
  (Tcl_CreateInterp -> Tcl_Init -> Tclmagic_Init) and routes
  run_command through Tcl_EvalEx.
- magic/magicTop.c: gate MagicVersion/Revision/CompileTime on
  !MAGIC_WRAPPER so they don't collide with the copies in
  tcltk/tclmagic.c when both objects land in the same wasm binary.

npm package:
- Subpath exports: ".", "./tcl", "./notcl". Default import keeps the
  pre-existing non-TCL behaviour for backward compatibility.
- examples/smoke-tcl.mjs exercises the TCL variant.

CI:
- main-wasm.yml clones intubun/tcl at the pinned ref, builds both
  variants via npm/build.sh --variant=both, runs the existing notcl
  test suite and the new TCL smoke test, and publishes only on a
  v<x.y.z>... git tag. Tag name (minus the leading v) becomes the
  npm version.
2026-06-09 16:07:53 -04:00
R. Timothy Edwards 8d61bae1f1 Corrected the "extresist" node merge routine to not merge away the
ResNodeAtOrigin node, but to instead move it to the remaining valid
node.
2026-06-08 19:33:07 -04:00
R. Timothy Edwards 3934b77f64 Modified the GDS path handling so that duplicate points produce
a warning appropriate for duplicate points and not a path
reversal warning.  Modified the output for path reversal or
duplicate point errors so that the coordinate is in GDS units
and not path units (which are multiplied by 2).
2026-06-08 15:58:06 -04:00
R. Timothy Edwards 788c73b867 Added some support for the open PDKs in the technology manager GUI.
This uses environment variable PDK_ROOT to search for available
technologies, and loads them by sourcing the .magicrc file instead
of using "tech load".  However, there are currently some caveats:
(1) The device generators do not immediately appear in the window
menu;  a new window must be created for the extra menu buttons to
be added;  (2) Once a PDK sets up the menus, they cannot be
revised.  Switching to another technology causes the extra menu
items to not appear at all.  Both issues need to be addressed.
2026-06-08 15:10:14 -04:00
R. Timothy Edwards 83569da8b3 I hope this is the last change to the "extresist" code for a while.
Corrected an error that was caused by moving the handling of the
"Short"-type device from "extract" to "ext2spice".  When running
with "ext2spice extresist on", the "Short" device is read twice.
Since it's being treated like an "equiv" statement, it's very
important to do the node merge only for the device as it appears
in the ".res.ext" file, and ignore the entry in ".ext", or the
wrong nodes may get merged.  This appears to be the last major
error lurking in the "extresist" code, as I am now able to run
full R-C extraction on an entire chip, in reasonable time.
2026-06-07 20:30:33 -04:00
R. Timothy Edwards 65f034777e Corrected an issue where a device was given the wrong type due to
ambiguity in the tech file and therefore also in the .ext file.
This is easy to resolve and it was only necessary to change the
type after finding the tile belonging to the device.  There are
pathological cases where this might still go wrong, like defining
a "short" device name for metal resistors on any plane;  then,
if a "short" device overlaps something on another plane, it might
be given the wrong type.  Avoiding all ambiguity would require
adding an extra item to "device" lines in the .ext file output;
the short plane name would be most efficient.
2026-06-07 19:37:52 -04:00
R. Timothy Edwards 3667b348e8 Removed a few orphaned routines that were part of deprecated code
and not being used.  Corrected one other obscure error in which
reading the .ext file picks up the wrong device type because it
is possible to have multiple types map to the same device name.
This is easy to detect and fix in place.
2026-06-07 16:31:23 -04:00
R. Timothy Edwards e2673e4e36 Found what I think is the last major issue in extresist, which is
that the check for the "starting device" was not checking if a
terminal was substrate, and so was treating it as a terminal,
which would cause the extraction starting point to be set on the
wrong plane, along with probably other unwanted behavior.
Ignoring substrate terminals when checking for current drivers
solved the problem.  Also:  Removed some code that had been
reworked but was still sitting in an "#ifdef 0" block.
2026-06-07 12:35:45 -04:00
R. Timothy Edwards 14afb4bd52 The method committed yesterday (last commit) was found to be too
time-consuming (note the commit message "There are still likely much
better ways to do this").  Worked out a method of hashing the location
of terminals on other planes so that they can be looked up from the
address of the tile.  This requires only one pass through the devices
to locate and record the terminals, and no loops through devices when
processing tiles.  Also corrected the positioning of the substrate
terminal to be the center position of the device tile, not the substrate
tile.  This not only better represents the substrate connections, but
it also eliminates the condition in which many thousands of resistors
converge on the same point, which causes stack overflow.  With the
current scheme, stack overflow is unlikely to occur.
2026-06-06 20:04:47 -04:00
R. Timothy Edwards 1db2567841 Another major refactoring of code in extresist. This gets rid of
several more questionable methods and allows extresist to find
devices above nets that are part of substrate planes or terminals
that exist on planes other than the device (like diodes, often).
There are still likely much better ways to do this.
2026-06-05 20:12:09 -04:00
R. Timothy Edwards 0efed5813e Corrected an issue in which permutable FETs were being assumed when
checking device terminals in "extresist", leading to incorrect
assignments for devices with only 3 terminals, or for asymmetric
FETs.  Corrected "select area label" which had stopped working from
a handful of commits back when the "select" command was corrected for
visible/invisible labels and cells.  Corrected the "extresist mindelay"
command option parsing, which was not allowing mindelay to be set to 0.
2026-06-05 15:46:54 -04:00
R. Timothy Edwards 43e4cf9b03 Expanded the use of the "tagged" operator to allow the use of
"tagged <text>" without any additional arguments, to indicate
that the operator should look for text that overlaps the
current layer.  That allows handling the case were a text tag
is sitting over space inside a cell, which otherwise would not
be able to be searched.  Also corrected a likely issue in which
point labels could not be used as tags because they have no
area to search under.
2026-06-04 21:20:03 -04:00
R. Timothy Edwards 7a0e2aa2b9 Additional corrections fix the problem of devices being removed from
the output if they reference a killed node.  This will result in an
invalid netlist, but at least now all devices are represented in the
output, and a warning is issued about the error.  There are still
multiple problems that need to be tracked down and fixed.  Most
problems are stemming from the unusual "Short" device handling.
2026-06-04 17:45:03 -04:00
R. Timothy Edwards a157ec9aa8 Another overhaul of the R-C extraction code. This fixes a known
long-standing problem, in which the resistance extraction attempts
to determine the device type of each device.  Which is stupid,
because the original extraction process has already done this, and
the information is readily available in the .ext file.  This update
allows "extresist" to get all the device information from the .ext
file, so there is no guesswork and no extra time spent trying.
Unfortunately, it does not solve the problem I expected it to solve,
which is the disappearance of _dss and moscap devices from gf180mcu
netlists.  More work to do. . .
2026-06-04 12:50:13 -04:00
R. Timothy Edwards 1a1cee058e Fixed an issue with the connectivity stack which does not change
"lasttop" after a new heap has been allocated and "top" is reset.
This is a minor issue, as even random data at the top of the
newly allocated heap is vanishingly unlikely to make a match,
but valgrind caught it as a use of unallocated memory, and it
should be fixed.
2026-06-03 11:34:41 -04:00
Torleif Skår 799fd5d8f2 fix(ext2spice): use ';' instead of '$' for NGSpice end-of-line comments
'$' is only used by NGSpice, for broader compatibility use ';'.
2026-06-03 11:27:36 -04:00
R. Timothy Edwards 21b8579734 Found the error with rg_maxres, which is that it was being used in
one place as ohms and another as milliohms.  Changed it to be
milliohms always, except when written as output to the lumped
resistance file or as diagnostic output.  The result makes more
sense, but now has the issue that the maximum resistance is always
an over-estimate and may need to account for resistances in
parallel.
2026-06-01 17:33:45 -04:00