nx_codegen
coder · scripts/coder/nx_codegen.m
NX_CODEGEN Shared body for MATLAB Coder-compatible codegen (scripts/coder)
codegen FCN [FCN2 ...] [-o NAME] [-d OUTDIR] [-args {EX1, EX2, ...}]
[-config CFG] [-report] [-launchreport] [-silent] ...
codegen (FUNC_HANDLE, '-args', {EX1, EX2, ...}, '-o', NAME)
FUNC may be a function name or function handle. -args accepts a real
cell of sample inputs or the brace-token command form. Always emits
NAME.c / NAME.h stubs. For fixed-size numeric leaves (nexus#1587) also
tries __nexus_codegen_emit_mex__. On AOT success the .m forwarder is
removed; otherwise NAME.m (default FCN_mex.m) forwards to FCN.
Nexus has no C code generator for full AOT yet.
- FCN must be found by which; otherwise the error 'emlc:compilationError'
is raised, as the MATLAB Coder does for a function it cannot compile.
- -o NAME names the output (a path, or a name placed in -d OUTDIR or the
current folder; a .mex/.mexa64/.mexw64/.mexmaca64 suffix is dropped).
- -args takes the example inputs. Tokens are not evaluated; known forms
(zeros/ones/eye, literals, coder.typeof, coder.newtype, coder.const /
coder.Constant) are parsed into class, size, complex, and constant
metadata and written as a JSON sidecar NAME.args.json beside the
forwarder for the later AOT step (nexus#1586). Unsupported tokens are
recorded as ClassName '__unsupported__', never guessed. The forwarder
itself does no type or size check.
- -config, -report, -launchreport, -silent, -v, -c, -g, -I, -O, -globals,
-s, -nargout, -lang and the other Coder options are accepted and ignored.
- Calling the generated function with no input while FCN needs inputs
raises 'EMLRT:runTime:WrongNumberOfInputs', as a real MEX file does
(matlabfcn2mex relies on it to probe an existing MEX file).
- An existing file NAME.m that was not written by codegen is never
overwritten (error).
See also coder.newtype, coder.typeof, coder.extrinsic.
A compiled backend is specified in AI_Docs/codegen/REAL_CODEGEN_1260.md
(nexus#1260). This file stays the interpreted forwarder until that work lands.