Commit Graph

2611 Commits

Author SHA1 Message Date
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
R. Timothy Edwards 03610f6d40 Additional tweaks to the handling of the three new options for
determining what does and doesn't get into the R-C extraction
output.  Added option "debug" and moved all excess diagnostic
information to be gated by this flag.  Corrected an issue in
the standard extraction in which the substrate is always output
with zero lumped resistance, preventing it from being checked
by "extresist" for inclusion or exclusion in the .res.ext output.
Reinstated the computation of minimum resistance transistor but
excluded other devices.  Added more sane handling of exceptional
conditions like loops.  The result is a more consistent check of
nets in the design.  However, I still need to recheck the
"rg_maxres" calculation because it appears to be too low.
2026-06-01 17:21:02 -04:00
R. Timothy Edwards c22031724a Some further refinements to the last commit, and other additions:
(1) An incorrect use of ExtResetTiles() was found in "extresist"
    which impacts performance, especially for small nets.
(2) Corrected units for resistance tolerance in extresist, and
    handled output printing in fs when delay values get below ps
    size.
(3) Added command option "extract do unique notopports" to be the
    extraction option equivalent of the standalone command
    "extract unique notopports".
(4) Changed the "extresist" default for "mindelay" to 1ps from 0,
    in response to the observation that lumped resistance from
    "extract" can be an extreme overestimate, and the extracted
    time delay from "extesist" calculations should be used as a
    better determination of whether a net should be output as a
    resistor network or not.
(5) Added documentation for both "extract do unique notopports"
    and the change to the "extresist" default values.
2026-05-29 17:16:37 -04:00
R. Timothy Edwards 349ffd091f Corrected an error when merging nodes during "ext2spice". The code
was checking for device terminals that were pointing to the
deallocated node and updating them.  However, it failed to check
for whether or not the substrate terminal was pointing to the
deallocated node, potentially causing a crash condition.  That has
now been fixed.
2026-05-29 14:06:50 -04:00
R. Timothy Edwards 4393d9310a More work on the "extresist" code, this time to revise the way
that "extresist" selects or rejects networks for resistance
extraction.  The "tolerance" value, which nobody (including
myself) seems to understand, is now deprecated, replaced by
a handful of more meaningful options:  "threshold" to set a
lumped resistance estimate threshold to determined whether or
not to extract a network;  "minres" to specify when to prune
small resistors from the resulting tree network, and "mindelay"
to gate the selection and output on the estimated signal
propagation delay.  With these settings, I am much better able
to control the size and complexity of the resulting output.
2026-05-29 11:47:01 -04:00
R. Timothy Edwards 1bcad6a25c Significant overhaul of the extresist code. The purpose of this
overhaul was to introduce the concept of a "connection point"
between two cells to the ".ext" file format so that it becomes
possible to do proper hierarchical R-C extraction.  Previously
this information was not kept in the .ext file, making it
impossible for "extresist" to know what sub-net of a net connects
up or down the hierarchy.  However, additional changes were made
to the extresist code (in the resis/ directory) to add the
handling of connections up and down the hierarchy, and to make
the code a lot clearer and fix ambiguous variable and subroutine
names.
2026-05-28 13:12:13 -04:00
R. Timothy Edwards d9e6c78adb Corrected an issue that was caused by early work on extresist:
The original version of extresist only worked with 4-terminal FET
devices, and handling of devices with fewer terminals was ignored,
and never properly dealt with.  This commit fixes the issues with
devices such as diodes that have fewer terminals.
2026-05-27 10:52:44 -04:00
R. Timothy Edwards d8580be739 Corrected a problem caused by fixing the "select visible" command
with respect to visible/invisible labels and cells.  The change
inadvertently made the "select area" command option stop selecting
labels on the same type as the layers being selected.  This has
been fixed.
2026-05-26 17:01:45 -04:00
R. Timothy Edwards 1a16502a69 Fixed a potential string overrun crash condition when doing
"getnode", as there is no limit on the length of a hierarchical
node name, and no check on the string length when copying back into
a fixed-length character array.
2026-05-25 14:39:12 -04:00
R. Timothy Edwards 5ecf10c022 Updated the version to go along with the merge of pull request #521
from Sylvain Munaut, which fixes an issue with the "property" command
when using the recently-added plane properties.
2026-05-25 12:07:33 -04:00
Sylvain Munaut e366cf6a4c commands: Fix parsing of plane properties in case of single string
The previous code would iterate over `proplen` chunks of strings
but would not initialize `proplen` for plane properties.

Technically for plane properties you don't need to "pre-count"
the string chunks but given how the code is currently written
it's easier to do the counting in all cases.

Also makes sure proprec is init to NULL so that if argument is
empty, property is set to NULL and not random value on the stack.

Fixes #520

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2026-05-25 12:49:52 +02:00
R. Timothy Edwards 7ecebb5dd6 Corrected a stupid omission to set the plane hint during a search
in "extresist", which when missing causes the plane to be searched
repeatedly from the same point instead of from the last place searched.
Can knock down the "extresist" time by up to 50%.
2026-05-24 22:01:29 -04:00
R. Timothy Edwards 099d513011 Corrected the "Pick" button action in the "Library Manager" window;
this had two issues:  (1) "getcell" was not being called with
"child 0 0", leading to child cells that are not placed where
expected in relation to a grid snap setting;  and (2) "cursor"
was assuming internal units and needed that to be explicitly
stated using "cursor internal".
2026-05-24 16:23:18 -04:00
R. Timothy Edwards e45399d347 Yet another optimization on "extresist", to remove the calls to
DBPaint() and DBErase(), which are meant as high-level calls from
the "paint" and "erase" commands and are not appropriate for low-
level tasks like erasing all contacts out of a database.  This
cut maybe 40 to 50% time off of the resistance extraction.
2026-05-22 12:02:03 -04:00
R. Timothy Edwards 7a3717b02a Another performance optimization to "extresist", this one to
avoid re-parsing a linked list from the current breakpoint
to the end to find all entries pointing to the same node.
Instead, the change to be made is saved in a hash table and
applied at the following link, so only one pass through the
linked list is required.
2026-05-21 19:55:50 -04:00
R. Timothy Edwards a062fdcfe0 Continued optimizing poorly written routines in "extresist".
Changed the "ResDissolveContacts()" routine to avoid running both
redundant and useless code.  Changed the breakpoint sorting
routine from a bubble sort to a merge sort for linked lists
longer than 16, as merge sort is more efficient for long lists.
2026-05-20 19:02:22 -04:00
Ahmed Nematallah 29447a35cd Delete duplicate magicps.pro file
This file exists in the magic directory, and is the one the build system uses, this file is a duplicate that has one different line "/ms { rectfill } bind def", and is not used anywhere

Keeping two duplicate files causes issues like them being out of sync, therefore it would be great if it was deleted
2026-05-19 12:22:37 -04:00
Ahmed Nematallah 1dcd09e20c Update the postscript file to be able to support much more stipples
The postscript template had a hardcoded stipple length of 29, any more stipples would cause problems with a postscript parser. This was particularly a problem since the default mos.24bit.dstyle has 36 stipples already.

It also used a base-30 encoding.

I have updated the template to fix both issues, it now uses base-10 encoding, and can support up to 255 stipples (which is the maximum length allowed by the current approach of using fonts)

I was also wondering if it made more sense to encode this file directly into the C program as a literal, as half of it already is in the C program. (some "begin"s have an "end" in strings directly embedded in magic, so this file basically serves as a large string that has to be loaded each time from disk, while other parts of the string are stored normally in memory)
2026-05-19 12:22:37 -04:00
R. Timothy Edwards 9626b5e8c9 Changed two sprintf() to snprint() on recommendation from an AI. 2026-05-19 12:21:54 -04:00
R. Timothy Edwards 256955f48e Created alternative algorithms for routines ResParallelCheck() and
ResTriangleCheck().  By using hash tables, I reduced
ResParallelCheck() from O(N^2) to O(N), and I reduced
ResTriangleCheck() from O(N^3) to O(N^2);  however, it is a bit
better than that because previously there was an N^2 loop over
items in the same list, so if one list happened to be very long,
then N^2 would be huge; whereas now the N^2 is the length of two
lists multiplied together, where both lists would have to be very
long to have the same performance impact.  It appears that long
resistor lists are pathological and rare.  For an example
pathological case, the extresist runtime has been reduced from
hours to seconds.
2026-05-15 21:38:32 -04:00
R. Timothy Edwards b983e33be7 Corrected an error with the recently-added "exception" DRC rule.
The logical expression for determining an excepted area was wrong
for one direction, resulting in false positive DRC violations.
2026-05-15 11:04:23 -04:00