Commit Graph

195 Commits

Author SHA1 Message Date
R. Timothy Edwards bb131f14d0 One additional modification to output the message about duplicate
cells as a "note" if "gds noduplicates" has been set, and a
"warning" otherwise.  This makes error handling of magic's
output a bit easier.
2025-10-01 15:38:41 -04:00
R. Timothy Edwards 78f7d22796 A number of changes:
1) Corrected spurious error messages about cells already existing
   in GDS when using "flatten" or "flatglob".
2) Fixed handling of resistance as a subcircuit parameter
3) Added area and perimeter resistance for a device;  this is done
   through the "devresist" statement in the tech file, which is an
   extension of the original "fetresist" statement.  Where "fetresist"
   only supported type "linear", "devresist" supports types "area"
   and "perimeter".
4) Support for CDL syntax, including generating subcircuit-like
   parameters for components starting with SPICE-standard prefixes
   like M, R, C, etc., adding "/" between pins and subcircuit name,
   and saving the file as ".cdl" instead of ".spice".
5) Estimated L and W for devices whose geometry is complex and do not
   reduce to a simple rectangle.  L and W are estimated as the square
   root of the area.
6) Changed the method of extracting L and W for diodes to use the same
   method as capacitors.  Note that diodes are not usually specified
   by L and W, but if they are, this will produce the right result.
7) Corrected the reported filename and line number when printing error
   messages related to errors inside a technology file, when the
   technology file uses "include" to combine multiple files.
2025-10-01 15:17:49 -04:00
R. Timothy Edwards b1c7b52ed2 Modified "gds flatglob" to have the value "*_CDNS_*" by default,
since this is a common artifact of foundry cells and almost
always incompatible with magic.  Modified the "port" command to
allow "port make <index>" on a label where other labels of the
same text already have the same index.  Removed deprecated
documentation and added some missing documentation, such as an
explanation of the "ext2spice subcircuit auto" option.
2025-09-26 09:18:43 -04:00
Darryl L. Miles d55a2b74ac header file #ifndef guard namespace consistency (global change)
This add an effective namespace prefix to the guard ifndef
2025-07-29 10:50:32 -04:00
Darryl L. Miles f88c7a86cb utils/magic_zlib.h: limit #include <zlib.h> to files that need it
Remove limited use HAVE_ZLIB wrapper API into separate header as
utils.h is used in many places and most source files don't need
to drag in the header file from this external dependency.

Copyright date(s) taken from original source file / git blame.
2025-07-29 10:50:32 -04:00
Darryl L. Miles 3fd0798312 CalmaRdpt.c: -Wall -O3 savedef used uninitialized
GCC11 -Wall -Wpedantic -O3
2025-07-27 12:43:59 -04:00
Darryl L. Miles 5d8cfdc760 CalmaRdpt.c: -Wall -O3 snprintf("polygon%5d")
Finds this a problem still.

GCC11 -Wall -Wpedantic -O3
2025-07-27 12:43:59 -04:00
Darryl L. Miles 046401cbd8 Use HAVE_SYS_TIME_H and TIME_WITH_SYS_TIME from autoconf where possible 2025-07-27 12:43:04 -04:00
Darryl L. Miles 66e72c748a CIFParsePath() prototype change to simply return of created data
Previously this was returning two values, a 'bool' and a data
structure that is created.  Now it simply returns the data
structure which makes it easier to reason about who takes
ownership of the memory and when, also that no address-of can
be supplied that has any side-effect that interacts with how
the method works / the returned result.

-extern bool CIFParsePath(CIFPath **pathheadpp, int iscale);
+extern CIFPath *CIFParsePath(int iscale);

Previous related comments:

Easier to reason about, there can be no interaction from *pathheadpp
and the various functions called, which maybe the first concern to
the next reader as visibility of new data is limited to that of a
local variable of the function.
2025-06-26 16:09:43 +01:00
Darryl L. Miles 16efabe9ee calma: TiPlaneRect const ripple 2025-04-09 15:07:28 -04:00
Darryl L. Miles 606f37cc80 Ti[GS]etClient() usage enforcement
All naked access to `ti_client` now uses the function-like-macro
to encapsulate this action.  This macro existed before this just
makes all sites utilize it.

Added additional INT and PTR variants to remove the programmer
load on thinking about casing and casts polluting the point
of use.  So the use now looks cleaner.

Equivalent prototypes:

 void TiSetClient(Tile*, ClientData)
 void TiSetClientINT(Tile*, intptr_t) /* pointertype */
 void TiSetClientPTR(Tile*, void*)

 ClientData TiGetClient(Tile*)
 intptr_t TiGetClientINT(Tile*) /* pointertype */
 void *TiGetClientPTR(Tile*)
2025-04-09 14:55:58 -04:00
Darryl L. Miles 7508a9e6b7 CodeQL MemoryMayNotBeFreed.ql calma/**
Looks straight forward lost pointer to recently malloced block
2025-02-22 21:35:23 -05:00
Tim Edwards df84a36659 Added code to handle the case where GDS_FILE points to a filename
that has since been compressed and given a ".gz" extension.
Removed code that uses a system call to "gunzip" and "gzip" when
the target file is compressed, since the compression is handled
in the code.
2025-02-12 16:28:43 -05:00
Darryl L. Miles 4887f71ca3 CIFread.h: fix struct cifrstyle.crs_layers type bool -> enum (unsigned char)
The type is actually an enum (assumed to be int by default) but relies
on the magic typedef to (unsigned char) so we make this explicit and
better document what the real type is.

I guess in the past it was really a bool with only 2 states NONE|TEXT.

C29 bool type compatibility
2025-01-07 14:02:07 -05:00
Darryl L. Miles 07f9bbe1fb gcc11 -Wall -Wpedantic cleanup 2025-01-06 16:12:11 +00:00
Darryl L. Miles a616dbc113 calma: use 'const' with 'rcsid' 2025-01-04 11:31:17 -05:00
Darryl L. Miles 4cd1235575 calma: use 'const' with readonly data
This then required a cascade of function APIs to also now receive
const arguments.

This reduces the .data segment use of this module.
2025-01-04 11:31:17 -05:00
Darryl L. Miles 378755e083 CalmaRdpt.c: simplfy use of sprintf()
This replacement pattern is easier to reason about and less error prone.
2025-01-04 11:31:17 -05:00
Darryl L. Miles 0ce8265570 TCL9: ClientData macro assignment and access usage 2025-01-04 11:08:01 -05:00
Darryl Miles bf96348502 printf: vararg functions use 'const' for format string 2025-01-03 09:08:14 +00:00
Darryl Miles 94ec5cf98f printf: use compiler __attribute__((format (printf,fff,aaa))) 2025-01-03 09:08:14 +00:00
Darryl L. Miles 97913ab08c calma/CalmaWrite.c: calmaProcessBoundaryZ() Dereference of null pointer
Theoretical NULL pointer deref.  Seems like false positive as a
BOUNDARY record does not make sense with no points.

This guards against a potential crash from a bad data model.

SonarCloud
Dereference of null pointer
https://sonarcloud.io/project/issues?open=AZJB17hwNGfDNup0Rkub&id=dlmiles_magic
2024-12-26 13:01:24 -05:00
Darryl L. Miles dd6bb9baf4 calma/CalmaWrite.c: calmaProcessBoundary() Dereference of null pointer
Theoretical NULL pointer deref.  Seems like false positive as a
BOUNDARY record does not make sense with no points.

This guards against a potential crash from a bad data model.

SonarCloud
Dereference of null pointer
https://sonarcloud.io/project/issues?open=AZJB17hXNGfDNup0Rktk&id=dlmiles_magic
2024-12-26 13:01:24 -05:00
Darryl L. Miles bfc82e43db MacOS: FREAD rename to magicFREAD due to sys/fcntl.h definition
Example build issue using MacOS 12 (Xcode 14.2 from MacOSX.platform).

In file included from grTk1.c:23:
In file included from ../utils/main.h:26:
In file included from ../windows/windows.h:26:
../utils/magic.h:143:13: warning: 'FREAD' macro redefined [-Wmacro-redefined]
    #define FREAD(a,b,c,d)    gzread(d,a,b*c)
            ^
/Applications/Xcode_14.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/fcntl.h:110:9: note: previous definition is here
 #define FREAD           0x00000001
2024-12-26 12:52:25 -05:00
Darryl L. Miles d79533a255 K&R calma: move internal prototypes and typedef to calmaInt.h
K&R obsolete syntax removal for C23 compatibility series
2024-12-26 12:44:50 -05:00
Darryl L. Miles d92e2b70b6 K&R CalmaWrite.c: move typedef to before forward declaration usage
K&R obsolete syntax removal for C23 compatibility series
2024-12-26 12:44:50 -05:00
Darryl L. Miles 5f55ab825a K&R CalmaWriteZ.c: move typedef to before forward declaration
K&R obsolete syntax removal for C23 compatibility series
2024-12-26 12:44:50 -05:00
Darryl L. Miles 979c810c38 K&R calma: missing HAVE_ZLIB ifdef around function using type gzFile
K&R obsolete syntax removal for C23 compatibility series
2024-12-26 12:44:50 -05:00
Darryl L. Miles 603ce8b887 K&R CalmaRead.c: too many args for calmaLookCell()
K&R obsolete syntax removal for C23 compatibility series
2024-12-26 12:44:50 -05:00
Darryl L. Miles a9ea08a597 K&R calma/*.c: bulk function implementation conversion
K&R obsolete syntax removal for C23 compatibility series
2024-12-26 12:44:50 -05:00
Darryl L. Miles f3ace65a78 K&R calma/*.c: bulk forward reference function prototype conversion
K&R obsolete syntax removal for C23 compatibility series
2024-12-26 12:44:50 -05:00
Darryl L. Miles cd63fa3c14 K&R calma: remove system header time() K&R style prototype
time.h has existed since C89 so is a standard header expected
to always be available.

sys/time.h was an optional header that historically only some
platforms provided.

If there is a conflict on specific platforms it is better to
'#if !defined()' that specific niche platform with the problem
if both headers are included in the same compile unit.  But I
don't think this is a problem in modern times.

So this results in a resolution that removes #ifdef around
time.h and the detection by configure for the availabiltiy
of sys/time.h.

K&R obsolete syntax removal for C23 compatibility series
2024-12-26 12:44:50 -05:00
Darryl L. Miles 3f4eb4120e K&R calma: prototype for non-existent function: calmaMergeBoundaries()
Remove forward declaration prototype to correct error.

K&R obsolete syntax removal for C23 compatibility series
2024-12-26 12:44:50 -05:00
Darryl L. Miles f0b6231017 K&R calma: prototype for non-existent function: calmaWriteMarkFunc()
Remove forward declaration prototype to correct error.

K&R obsolete syntax removal for C23 compatibility series
2024-12-26 12:44:50 -05:00
Darryl L. Miles 1fdd8bc185 K&R calmaInt.h: conversion to ANSI
K&R obsolete syntax removal for C23 compatibility series
2024-12-26 12:44:50 -05:00
Darryl L. Miles 40b317979d K&R calma.h: conversion to ANSI
K&R obsolete syntax removal for C23 compatibility series
2024-12-26 12:44:50 -05:00
Darryl L. Miles 5ee3b180d3 K&R calma: missing prototype: calmaWriteContacts()
Rename existing prototype method name to correct error.

K&R obsolete syntax removal for C23 compatibility series
2024-12-26 12:44:50 -05:00
Darryl L. Miles 95d3e9f85d CalmaRead.c: warning: variable 'libnameptr' is used uninitialized
The local variable 'libnameptr' is used from the 'goto done;' label cleanup
but it may not be initiailzied at the time of the first use of the label.

When evaluating this I also notice the global 'calmaErrorFile' when closed
does not have the handle invalidated.

CalmaRead.c:233:9: warning: variable 'libnameptr' is used uninitialized whenever 'if' condition is true
CalmaRead.c:231:9: warning: variable 'libnameptr' is used uninitialized whenever 'if' condition is true
CalmaRead.c:225:9: warning: variable 'libnameptr' is used uninitialized whenever 'if' condition is true

clang18 -Wall warning cleanup [-Wsometimes-uninitialized]
2024-10-09 21:34:12 -04:00
Darryl L. Miles 60e78f4ab4 CalmaWriteZ.c: warning: variable 'rtype' is used uninitialized
CalmaWriteZ.c:418:5: warning: variable 'rtype' is used uninitialized whenever 'if' condition is true

clang18 -Wall warning cleanup [-Wsometimes-uninitialized]
2024-10-09 21:34:12 -04:00
Darryl L. Miles fca0c2945d CalmaWrite.c: warning: variable 'rtype' is used uninitialized
CalmaWrite.c:442:5: warning: variable 'rtype' is used uninitialized whenever 'if' condition is true

clang18 -Wall warning cleanup [-Wsometimes-uninitialized]
2024-10-09 21:34:12 -04:00
Darryl L. Miles fece689c43 CalmaRdpt.c: warning: variable 'rtype' is used uninitialized
CalmaRdpt.c:525:5: warning: variable 'rtype' is used uninitialized whenever 'if' condition is true
CalmaRdpt.c:792:5: warning: variable 'rtype' is used uninitialized whenever 'if' condition is true

clang18 -Wall warning cleanup [-Wsometimes-uninitialized]
2024-10-09 21:34:12 -04:00
Darryl L. Miles 2b06c8cee5 CalmaRdcl.c: warning: variable 'rtype' is used uninitialized
FEOF condition of PEEKRH causes variable to possibly not get
initialized before use.

CalmaRdcl.c:372:5: warning: variable 'rtype' is used uninitialized whenever 'if' condition is true

clang18 -Wall warning cleanup [-Wsometimes-uninitialized]
2024-10-09 21:34:12 -04:00
Darryl L. Miles 9ca8697659 strings.h: add #include required when strict
Due to use of strcasecmp() or similar C API.

Maybe HAVE_STRINGS_H is needed ?  If so which platforms needs this ?

clang18 default warning cleanup (strict)
2024-10-09 21:22:37 -04:00
Darryl L. Miles 76d8c8c911 35 x warning: suggest parentheses around assignment used as truth value
PlowRules1.c:439:9: warning: suggest parentheses around assignment used as truth value
PlowTech.c:645:17: warning: suggest parentheses around assignment used as truth value
PlowTech.c:652:17: warning: suggest parentheses around assignment used as truth value
PlowTech.c:1019:17: warning: suggest parentheses around assignment used as truth value
ResReadSim.c:270:13: warning: suggest parentheses around assignment used as truth value
ResReadSim.c:871:9: warning: suggest parentheses around assignment used as truth value
ResRex.c:1840:17: warning: suggest parentheses around assignment used as truth value
getrect.c:72:9: warning: suggest parentheses around assignment used as truth value
getrect.c:79:9: warning: suggest parentheses around assignment used as truth value
getrect.c:86:9: warning: suggest parentheses around assignment used as truth value
getrect.c:93:9: warning: suggest parentheses around assignment used as truth value
hash.c:732:16: warning: suggest parentheses around assignment used as truth value
heap.c:328:17: warning: suggest parentheses around assignment used as truth value
heap.c:344:17: warning: suggest parentheses around assignment used as truth value
netlist.c:323:17: warning: suggest parentheses around assignment used as truth value
niceabort.c:121:9: warning: suggest parentheses around assignment used as truth value
path.c:1102:12: warning: suggest parentheses around assignment used as truth value
pathvisit.c:245:13: warning: suggest parentheses around assignment used as truth value
pathvisit.c:295:17: warning: suggest parentheses around assignment used as truth value
tech.c:656:17: warning: suggest parentheses around assignment used as truth value
ext2spice.c:1591:16: warning: suggest parentheses around assignment used as truth value
ext2spice.c:1622:16: warning: suggest parentheses around assignment used as truth value
ext2spice.c:1813:12: warning: suggest parentheses around assignment used as truth value
ext2spice.c:1862:12: warning: suggest parentheses around assignment used as truth value
ext2spice.c:3808:16: warning: suggest parentheses around assignment used as truth value
CalmaRdio.c:437:9: warning: suggest parentheses around assignment used as truth value
CalmaWrite.c:396:9: warning: suggest parentheses around assignment used as truth value
CalmaWrite.c:1772:29: warning: suggest parentheses around assignment used as truth value
CalmaWriteZ.c:372:9: warning: suggest parentheses around assignment used as truth value
CalmaWriteZ.c:1608:29: warning: suggest parentheses around assignment used as truth value
CIFrdtech.c:209:9: warning: suggest parentheses around assignment used as truth value
CIFrdtech.c:214:9: warning: suggest parentheses around assignment used as truth value
CIFrdtech.c:220:9: warning: suggest parentheses around assignment used as truth value
CIFrdtech.c:226:9: warning: suggest parentheses around assignment used as truth value
CIFrdutils.c:1258:12: warning: suggest parentheses around assignment used as truth value

GCC14 -Wall cleanup series [-Wparentheses]
2024-10-09 21:12:55 -04:00
Darryl L. Miles 1ca23ca0a2 fix: Accessing uninitialized variable
Trigger condition maybe that no labels exist in the project, so the
loop never iterates.
2024-10-01 12:43:27 -04:00
Darryl L. Miles 48853b98a3 calma/CalmaRead.c missing initialization
An FEOF exit path exists in READRH() which causes the output
variable(s) to not be assigned a value, then the code makes
a decision (branch) based on uninitialized data.

SonarCloud detection
CalmaRead.c:359:The left operand of '!=' is a garbage value
https://sonarcloud.io/project/issues?open=AZJB17gSNGfDNup0Rkp5&id=dlmiles_magic
2024-10-01 12:36:13 -04:00
Darryl L. Miles 1360f962a1 calma/CalmaRdcl.c: calmaFindCell() Call to function with fewer arguments than declared parameters
The 'predefined' pointer argument to calmaFindCell() is for an optional return value, so must be
NULL when feature is not used.

Copilot Autofix rejected: newdef = calmaFindCell(newname, someSecondArgument);

calma/CalmaRdcl.c
1c822652 (2020-12-04 16:56:51 -0500 1359)     bool *predefined; /* If this cell was in memory before the GDS
1c822652 (2020-12-04 16:56:51 -0500 1360)                        * file was read, then this flag gets set.
1c822652 (2020-12-04 16:56:51 -0500 1361)                        */

commit 1c82265244 (tag: mpw-one-a, tag: 8.3.92)
Date:   Fri Dec 4 16:56:51 2020 -0500

CodeQL: https://github.com/dlmiles/magic/security/code-scanning/6
        https://github.com/dlmiles/magic/security/code-scanning/5
2024-10-01 12:36:12 -04:00
Tim Edwards 0ae54b500a Added the ability to track the first CellDef to fail to read and
report it after "Failure to read in entire sub-tree".  This will
not report every failing cell (since it quits reading after the
first failure) but will avoid the existing issue of printing
nothing and leaving the user with no feedback as to which cell
was the problem.
2024-04-29 17:43:37 -04:00
Tim Edwards 21336607e0 Added checks for GDS scalefactor (DBU) both when reading GDS in
"gds readonly true" mode and when writing a GDS file in full-dump
mode.  Reading or writing a file with an incompatible DBU is now
prohibited.  This is not a great solution, as it forces the
original file to be rewritten with a different DBU.  Preferably
there should be code to scale the units during a dump, but that
needs to be coded.
2023-11-21 09:44:16 -05:00
Tim Edwards 610c86a234 When writing a GDS file, there is a statement printed about each
cell being generated.  This statement does not disambiguate the
case where a cell is being ripped verbatim from GDS instead of
being generated from the magic database.  This print statement
has been split into two cases, and where a cell is being ripped
verbatim, the name of the file is indicated.  This provides better
information to the user.
2023-10-24 10:36:57 -04:00