@tsplc/compiler 0.5.13 → 0.5.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -8
- package/dist/cli.js +794 -621
- package/dist/cli.js.map +19 -16
- package/dist/clock.js +5 -2
- package/dist/clock.js.map +5 -4
- package/dist/codesys.js +4162 -4157
- package/dist/codesys.js.map +43 -29
- package/dist/index.js +7852 -6549
- package/dist/index.js.map +53 -50
- package/dist/ir.js +2482 -2277
- package/dist/ir.js.map +28 -25
- package/dist/retain.js +3 -1
- package/dist/retain.js.map +3 -3
- package/dist/signals.js +115 -0
- package/dist/signals.js.map +10 -0
- package/dist/telemetry.js +25 -20
- package/dist/telemetry.js.map +6 -6
- package/package.json +19 -39
- package/src/codesys/config.ts +3 -3
- package/src/codesys/debug.ts +92 -108
- package/src/codesys/emit.ts +100 -88
- package/src/codesys/endpoints.ts +111 -0
- package/src/codesys/engineering.ts +30 -54
- package/src/codesys/explain/expressions.ts +445 -0
- package/src/codesys/explain/flags.ts +134 -0
- package/src/codesys/explain/parameters.ts +53 -0
- package/src/codesys/explain/rows.ts +182 -0
- package/src/codesys/explain/tables.ts +79 -0
- package/src/codesys/explain/tasks.ts +68 -0
- package/src/codesys/explain/writes.ts +497 -0
- package/src/codesys/explain.ts +85 -1401
- package/src/codesys/expressions.ts +41 -33
- package/src/codesys/global-lists.ts +114 -94
- package/src/codesys/global-names.ts +12 -14
- package/src/codesys/http.ts +428 -388
- package/src/codesys/instrumentation.ts +142 -148
- package/src/codesys/io-paths.ts +31 -23
- package/src/codesys/loops.ts +101 -0
- package/src/codesys/manifest.ts +269 -269
- package/src/codesys/names.ts +10 -33
- package/src/codesys/numeric.ts +89 -42
- package/src/codesys/plan.ts +202 -190
- package/src/codesys/programs.ts +23 -16
- package/src/codesys/publication.ts +13 -86
- package/src/codesys/required.ts +8 -0
- package/src/codesys/routines.ts +103 -489
- package/src/codesys/scheduling.ts +96 -0
- package/src/codesys/service-channels.ts +23 -0
- package/src/codesys/sources.ts +34 -28
- package/src/codesys/st-files.ts +112 -105
- package/src/codesys/statements.ts +409 -0
- package/src/codesys/storage.ts +41 -23
- package/src/codesys/symbols.ts +130 -119
- package/src/codesys/task-access.ts +65 -221
- package/src/codesys/telemetry-settings.ts +19 -0
- package/src/codesys/telemetry.ts +185 -148
- package/src/codesys/types.ts +69 -109
- package/src/codesys/vendor.ts +13 -50
- package/src/frontend/analyzer.ts +66 -111
- package/src/frontend/async.ts +316 -128
- package/src/frontend/blocks.ts +178 -154
- package/src/frontend/configuration.ts +49 -153
- package/src/frontend/const-functions.ts +50 -40
- package/src/frontend/control-flow.ts +164 -129
- package/src/frontend/cooperative.ts +17 -9
- package/src/frontend/coroutines.ts +539 -441
- package/src/frontend/dialect-names.ts +104 -0
- package/src/frontend/elaborate/array-searches.ts +77 -69
- package/src/frontend/elaborate/assignments.ts +68 -77
- package/src/frontend/elaborate/calls.ts +878 -512
- package/src/frontend/elaborate/capture-protocol.ts +118 -21
- package/src/frontend/elaborate/capture.ts +196 -109
- package/src/frontend/elaborate/declarations.ts +124 -0
- package/src/frontend/elaborate/dialect.ts +119 -46
- package/src/frontend/elaborate/expressions.ts +763 -442
- package/src/frontend/elaborate/filtered-arrays.ts +127 -91
- package/src/frontend/elaborate/frame.ts +50 -2
- package/src/frontend/elaborate/generics.ts +20 -34
- package/src/frontend/elaborate/graph.ts +13 -87
- package/src/frontend/elaborate/imports.ts +0 -5
- package/src/frontend/elaborate/index.ts +416 -169
- package/src/frontend/elaborate/initializers.ts +64 -42
- package/src/frontend/elaborate/iterators.ts +228 -364
- package/src/frontend/elaborate/layouts.ts +477 -116
- package/src/frontend/elaborate/model.ts +113 -55
- package/src/frontend/elaborate/references.ts +116 -138
- package/src/frontend/elaborate/retention.ts +137 -59
- package/src/frontend/elaborate/specialize.ts +617 -308
- package/src/frontend/elaborate/statements.ts +436 -247
- package/src/frontend/elaborate/storage.ts +280 -213
- package/src/frontend/elaborate/time-constructors.ts +34 -0
- package/src/frontend/elaborate/values.ts +77 -7
- package/src/frontend/elaborate/writes.ts +98 -84
- package/src/frontend/expressions.ts +149 -151
- package/src/frontend/generated-names.ts +3 -3
- package/src/frontend/intrinsics.ts +31 -17
- package/src/frontend/lowering-key.ts +23 -0
- package/src/frontend/module-graph.ts +105 -43
- package/src/frontend/positions.ts +43 -35
- package/src/frontend/promise-chains.ts +226 -266
- package/src/frontend/promises.ts +88 -67
- package/src/frontend/routines.ts +122 -65
- package/src/frontend/sdk.ts +104 -5
- package/src/frontend/services.ts +149 -102
- package/src/frontend/statements.ts +60 -64
- package/src/frontend/tasks.ts +151 -96
- package/src/frontend/telemetry.ts +1 -1
- package/src/frontend/types.ts +366 -181
- package/src/frontend/typescript.ts +239 -112
- package/src/index.ts +2 -1
- package/src/ir/aggregates.ts +90 -75
- package/src/ir/allocation.ts +29 -18
- package/src/ir/conditions.ts +38 -78
- package/src/ir/core-model.ts +128 -11
- package/src/ir/declarations.ts +18 -32
- package/src/ir/diagnostics.ts +25 -18
- package/src/ir/domains.ts +26 -23
- package/src/ir/fold.ts +55 -50
- package/src/ir/identity.ts +10 -0
- package/src/ir/index.ts +31 -7
- package/src/ir/job-errors.ts +30 -8
- package/src/ir/layouts.ts +63 -34
- package/src/ir/link.ts +11 -46
- package/src/ir/model.ts +25 -6
- package/src/ir/normalize.ts +3 -28
- package/src/ir/numeric.ts +45 -18
- package/src/ir/operands.ts +102 -0
- package/src/ir/ranges.ts +242 -67
- package/src/ir/routine.ts +126 -183
- package/src/ir/scalars.ts +29 -25
- package/src/ir/share.ts +323 -343
- package/src/ir/short-circuit.ts +140 -0
- package/src/ir/tables.ts +111 -0
- package/src/ir/temporaries.ts +15 -113
- package/src/ir/types.ts +32 -8
- package/src/project/artifacts.ts +143 -71
- package/src/project/cli.ts +104 -87
- package/src/project/debugger.ts +48 -34
- package/src/project/deployments.ts +12 -68
- package/src/project/flags.ts +14 -0
- package/src/project/plant.ts +293 -225
- package/src/project/project-commands.ts +254 -192
- package/src/project/project.ts +184 -141
- package/src/project/release.ts +22 -28
- package/src/project/server.ts +22 -26
- package/src/project/terminal.ts +13 -2
- package/src/runtime/async.ts +17 -13
- package/src/runtime/launch.ts +5 -2
- package/src/runtime/main.ts +8 -3
- package/src/runtime/missing-file.ts +3 -0
- package/src/runtime/process.ts +24 -19
- package/src/runtime/program.ts +20 -53
- package/src/runtime/retain.ts +18 -10
- package/src/runtime/runtime.ts +47 -60
- package/src/runtime/settings.ts +27 -0
- package/src/runtime/storage.ts +49 -74
- package/src/runtime/symbols.ts +19 -75
- package/src/runtime/telemetry.ts +37 -14
- package/src/runtime/transport.ts +26 -30
- package/stdlib/clock.ts +4 -2
- package/stdlib/plc-time.ts +2 -0
- package/stdlib/retain.ts +2 -0
- package/stdlib/signals.ts +142 -0
- package/stdlib/telemetry.ts +5 -12
- package/types/dialect.d.ts +49 -0
- package/types/globals.d.ts +2 -42
- package/types/index.d.ts +3 -1
- package/types/retain.d.ts +8 -2
- package/types/telemetry.d.ts +3 -0
- package/dist/bun-runtime.js +0 -1472
- package/dist/bun-runtime.js.map +0 -26
- package/dist/elaborate-capture.js +0 -304
- package/dist/elaborate-capture.js.map +0 -11
- package/dist/math.js +0 -24
- package/dist/math.js.map +0 -10
- package/dist/project.js +0 -626
- package/dist/project.js.map +0 -12
- package/dist/server-check.js +0 -59
- package/dist/server-check.js.map +0 -11
- package/src/frontend/exposure.ts +0 -181
- package/src/project/index.ts +0 -6
- package/src/runtime/.runtime-65O4JH/server/router.ts +0 -17
- package/src/runtime/.runtime-65O4JH/src/cell.ts +0 -45
- package/src/runtime/.runtime-65O4JH/src/controller.ts +0 -58
- package/src/runtime/.runtime-65O4JH/src/lane.ts +0 -6
- package/src/runtime/.runtime-65O4JH/src/main.ts +0 -11
- package/src/runtime/.runtime-65O4JH/src/services.ts +0 -8
- package/src/runtime/.runtime-65O4JH/tsconfig.json +0 -13
- package/src/runtime/.runtime-65O4JH/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-Brw2kO/server/router.ts +0 -17
- package/src/runtime/.runtime-Brw2kO/src/cell.ts +0 -45
- package/src/runtime/.runtime-Brw2kO/src/controller.ts +0 -58
- package/src/runtime/.runtime-Brw2kO/src/lane.ts +0 -6
- package/src/runtime/.runtime-Brw2kO/src/main.ts +0 -11
- package/src/runtime/.runtime-Brw2kO/src/services.ts +0 -8
- package/src/runtime/.runtime-Brw2kO/tsconfig.json +0 -13
- package/src/runtime/.runtime-Brw2kO/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-NHfu1D/server/router.ts +0 -17
- package/src/runtime/.runtime-NHfu1D/src/cell.ts +0 -45
- package/src/runtime/.runtime-NHfu1D/src/controller.ts +0 -58
- package/src/runtime/.runtime-NHfu1D/src/lane.ts +0 -6
- package/src/runtime/.runtime-NHfu1D/src/main.ts +0 -11
- package/src/runtime/.runtime-NHfu1D/src/services.ts +0 -8
- package/src/runtime/.runtime-NHfu1D/tsconfig.json +0 -13
- package/src/runtime/.runtime-NHfu1D/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-VaUSOu/server/router.ts +0 -17
- package/src/runtime/.runtime-VaUSOu/src/cell.ts +0 -45
- package/src/runtime/.runtime-VaUSOu/src/controller.ts +0 -58
- package/src/runtime/.runtime-VaUSOu/src/lane.ts +0 -6
- package/src/runtime/.runtime-VaUSOu/src/main.ts +0 -11
- package/src/runtime/.runtime-VaUSOu/src/services.ts +0 -8
- package/src/runtime/.runtime-VaUSOu/tsconfig.json +0 -13
- package/src/runtime/.runtime-VaUSOu/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-WbtNvR/server/router.ts +0 -17
- package/src/runtime/.runtime-WbtNvR/src/cell.ts +0 -45
- package/src/runtime/.runtime-WbtNvR/src/controller.ts +0 -58
- package/src/runtime/.runtime-WbtNvR/src/lane.ts +0 -6
- package/src/runtime/.runtime-WbtNvR/src/main.ts +0 -11
- package/src/runtime/.runtime-WbtNvR/src/services.ts +0 -8
- package/src/runtime/.runtime-WbtNvR/tsconfig.json +0 -13
- package/src/runtime/.runtime-WbtNvR/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-opcua-GMPUt8/server/router.ts +0 -17
- package/src/runtime/.runtime-opcua-GMPUt8/src/cell.ts +0 -45
- package/src/runtime/.runtime-opcua-GMPUt8/src/controller.ts +0 -58
- package/src/runtime/.runtime-opcua-GMPUt8/src/lane.ts +0 -6
- package/src/runtime/.runtime-opcua-GMPUt8/src/main.ts +0 -11
- package/src/runtime/.runtime-opcua-GMPUt8/src/services.ts +0 -8
- package/src/runtime/.runtime-opcua-GMPUt8/tsconfig.json +0 -13
- package/src/runtime/.runtime-opcua-GMPUt8/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-opcua-UwafxO/server/router.ts +0 -17
- package/src/runtime/.runtime-opcua-UwafxO/src/cell.ts +0 -45
- package/src/runtime/.runtime-opcua-UwafxO/src/controller.ts +0 -58
- package/src/runtime/.runtime-opcua-UwafxO/src/lane.ts +0 -6
- package/src/runtime/.runtime-opcua-UwafxO/src/main.ts +0 -11
- package/src/runtime/.runtime-opcua-UwafxO/src/services.ts +0 -8
- package/src/runtime/.runtime-opcua-UwafxO/tsconfig.json +0 -13
- package/src/runtime/.runtime-opcua-UwafxO/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-opcua-ecaSee/server/router.ts +0 -17
- package/src/runtime/.runtime-opcua-ecaSee/src/cell.ts +0 -45
- package/src/runtime/.runtime-opcua-ecaSee/src/controller.ts +0 -58
- package/src/runtime/.runtime-opcua-ecaSee/src/lane.ts +0 -6
- package/src/runtime/.runtime-opcua-ecaSee/src/main.ts +0 -11
- package/src/runtime/.runtime-opcua-ecaSee/src/services.ts +0 -8
- package/src/runtime/.runtime-opcua-ecaSee/tsconfig.json +0 -13
- package/src/runtime/.runtime-opcua-ecaSee/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-opcua-y91UCm/server/router.ts +0 -17
- package/src/runtime/.runtime-opcua-y91UCm/src/cell.ts +0 -45
- package/src/runtime/.runtime-opcua-y91UCm/src/controller.ts +0 -58
- package/src/runtime/.runtime-opcua-y91UCm/src/lane.ts +0 -6
- package/src/runtime/.runtime-opcua-y91UCm/src/main.ts +0 -11
- package/src/runtime/.runtime-opcua-y91UCm/src/services.ts +0 -8
- package/src/runtime/.runtime-opcua-y91UCm/tsconfig.json +0 -13
- package/src/runtime/.runtime-opcua-y91UCm/tsplc.config.ts +0 -31
- package/src/runtime/.runtime-ybIxYh/server/router.ts +0 -17
- package/src/runtime/.runtime-ybIxYh/src/cell.ts +0 -45
- package/src/runtime/.runtime-ybIxYh/src/controller.ts +0 -58
- package/src/runtime/.runtime-ybIxYh/src/lane.ts +0 -6
- package/src/runtime/.runtime-ybIxYh/src/main.ts +0 -11
- package/src/runtime/.runtime-ybIxYh/src/services.ts +0 -8
- package/src/runtime/.runtime-ybIxYh/tsconfig.json +0 -13
- package/src/runtime/.runtime-ybIxYh/tsplc.config.ts +0 -31
- package/stdlib/math.ts +0 -23
- package/types/plc.d.ts +0 -4
|
@@ -1,22 +1,31 @@
|
|
|
1
|
-
// biome-ignore-all lint/style/noNonNullAssertion: Retain existing non-null assertions during the tooling migration; changing their contracts requires a separate review.
|
|
2
1
|
import { createHash } from "node:crypto";
|
|
3
|
-
import
|
|
4
|
-
CoreExpression,
|
|
5
|
-
CoreFunctionBlock,
|
|
6
|
-
CoreStatement,
|
|
7
|
-
GeneratedObject,
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
import {
|
|
3
|
+
type CoreExpression,
|
|
4
|
+
type CoreFunctionBlock,
|
|
5
|
+
type CoreStatement,
|
|
6
|
+
type GeneratedObject,
|
|
7
|
+
jobError,
|
|
8
|
+
type SourceSpan,
|
|
9
|
+
type VerifiedCoreModule,
|
|
10
10
|
} from "@tsplc/compiler/ir";
|
|
11
11
|
import type { ResolvedDebugConfig } from "@tsplc/config";
|
|
12
|
-
import
|
|
13
|
-
|
|
12
|
+
import {
|
|
13
|
+
type DebugManifest,
|
|
14
|
+
type jobStateFields,
|
|
15
|
+
scanClockType,
|
|
16
|
+
writerSlotType,
|
|
17
|
+
} from "@tsplc/debug/manifest";
|
|
18
|
+
import { createPaths, TooManyMatches } from "@tsplc/debug/paths";
|
|
14
19
|
import { elementaryType, integerRange } from "@tsplc/iec";
|
|
20
|
+
import { buildIdLength } from "@tsplc/server/telemetry";
|
|
21
|
+
import type { ServiceChannel } from "@tsplc/server/wire";
|
|
22
|
+
import { isOutputAddress } from "@tsplc/typegen/hardware";
|
|
15
23
|
import {
|
|
16
24
|
DebugAnalysis,
|
|
17
|
-
|
|
25
|
+
instanceText,
|
|
18
26
|
type Operand,
|
|
19
|
-
|
|
27
|
+
type Output,
|
|
28
|
+
typescriptPath,
|
|
20
29
|
} from "./debug";
|
|
21
30
|
import {
|
|
22
31
|
expressionText,
|
|
@@ -24,17 +33,23 @@ import {
|
|
|
24
33
|
type StorageScope,
|
|
25
34
|
storageName,
|
|
26
35
|
} from "./expressions";
|
|
27
|
-
import {
|
|
36
|
+
import { rpcSlots, unsignedWidening } from "./http";
|
|
28
37
|
import {
|
|
29
38
|
isStoragePath,
|
|
30
39
|
resolveStoragePath,
|
|
31
40
|
type StorageBinding,
|
|
32
41
|
} from "./io-paths";
|
|
33
|
-
import { ioAddress } from "./manifest";
|
|
42
|
+
import { dataDebugType, ioAddress } from "./manifest";
|
|
34
43
|
import { Names } from "./names";
|
|
35
|
-
import type { CodesysPlan } from "./plan";
|
|
36
|
-
import {
|
|
37
|
-
import {
|
|
44
|
+
import type { CodesysPlan, Report } from "./plan";
|
|
45
|
+
import { required } from "./required";
|
|
46
|
+
import type { EmissionContext, GlobalSymbols } from "./symbols";
|
|
47
|
+
import {
|
|
48
|
+
fillBuildId,
|
|
49
|
+
type TelemetryTransport,
|
|
50
|
+
telemetryClient,
|
|
51
|
+
telemetryObjects,
|
|
52
|
+
} from "./telemetry";
|
|
38
53
|
import { stStringLiteral } from "./types";
|
|
39
54
|
|
|
40
55
|
/**
|
|
@@ -43,53 +58,26 @@ import { stStringLiteral } from "./types";
|
|
|
43
58
|
*/
|
|
44
59
|
export const maxWriterPaths = 256;
|
|
45
60
|
|
|
46
|
-
/** Module storage as the debugger's paths name it, for expanding `debug.writers.paths`. */
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
io: [],
|
|
56
|
-
constants: [],
|
|
57
|
-
types: Object.fromEntries(
|
|
58
|
-
core.types.flatMap((type): [string, DebugType][] => {
|
|
59
|
-
switch (type.kind) {
|
|
60
|
-
case "record":
|
|
61
|
-
return [
|
|
62
|
-
[
|
|
63
|
-
type.id,
|
|
64
|
-
{
|
|
65
|
-
kind: "record",
|
|
66
|
-
name: type.id,
|
|
67
|
-
fields: type.fields.map((field) => ({
|
|
68
|
-
name: field.name,
|
|
69
|
-
target: field.name,
|
|
70
|
-
type: field.type,
|
|
71
|
-
})),
|
|
72
|
-
},
|
|
73
|
-
],
|
|
74
|
-
];
|
|
75
|
-
case "array":
|
|
76
|
-
return [
|
|
77
|
-
[
|
|
78
|
-
type.id,
|
|
79
|
-
{
|
|
80
|
-
kind: "array",
|
|
81
|
-
element: type.element,
|
|
82
|
-
length: type.length,
|
|
83
|
-
lower: type.lowerBound,
|
|
84
|
-
},
|
|
85
|
-
],
|
|
86
|
-
];
|
|
87
|
-
default:
|
|
88
|
-
return [];
|
|
89
|
-
}
|
|
61
|
+
/** Module storage as the debugger's paths name it, for expanding `debug.writers.paths`. Blocks are leaves: their fields aren't module storage. */
|
|
62
|
+
const storagePaths = (core: VerifiedCoreModule) =>
|
|
63
|
+
createPaths({
|
|
64
|
+
roots: core.variables.flatMap((variable) => {
|
|
65
|
+
const path =
|
|
66
|
+
variable.storage === "module" ? typescriptPath(variable) : undefined;
|
|
67
|
+
return path
|
|
68
|
+
? [{ path, target: "", type: variable.type, readable: true }]
|
|
69
|
+
: [];
|
|
90
70
|
}),
|
|
91
|
-
|
|
92
|
-
|
|
71
|
+
io: [],
|
|
72
|
+
constants: [],
|
|
73
|
+
types: Object.fromEntries(
|
|
74
|
+
core.types.flatMap((type) =>
|
|
75
|
+
type.kind === "block"
|
|
76
|
+
? []
|
|
77
|
+
: [[type.id, dataDebugType(type, (_, field) => field)]],
|
|
78
|
+
),
|
|
79
|
+
),
|
|
80
|
+
});
|
|
93
81
|
|
|
94
82
|
/**
|
|
95
83
|
* The module storage paths `debug.writers.paths` matches. A pattern that names a block's field or
|
|
@@ -98,7 +86,7 @@ const storageShape = (core: VerifiedCoreModule): PathManifest => ({
|
|
|
98
86
|
export function writerPaths(
|
|
99
87
|
core: VerifiedCoreModule,
|
|
100
88
|
settings: ResolvedDebugConfig | undefined,
|
|
101
|
-
report:
|
|
89
|
+
report: Report,
|
|
102
90
|
): StorageBinding[] {
|
|
103
91
|
const writers = settings?.writers;
|
|
104
92
|
if (typeof writers !== "object") {
|
|
@@ -106,12 +94,9 @@ export function writerPaths(
|
|
|
106
94
|
}
|
|
107
95
|
const expanded = (() => {
|
|
108
96
|
try {
|
|
109
|
-
return
|
|
110
|
-
writers.paths,
|
|
111
|
-
maxWriterPaths,
|
|
112
|
-
);
|
|
97
|
+
return storagePaths(core).expand(writers.paths, maxWriterPaths);
|
|
113
98
|
} catch (error) {
|
|
114
|
-
if (error instanceof
|
|
99
|
+
if (error instanceof TooManyMatches) {
|
|
115
100
|
report(`debug.writers.paths match more than ${maxWriterPaths} values.`);
|
|
116
101
|
return [];
|
|
117
102
|
}
|
|
@@ -130,27 +115,28 @@ export function writerPaths(
|
|
|
130
115
|
|
|
131
116
|
/**
|
|
132
117
|
* The debugger's and telemetry's names in the program: `GVL_TsplcDebug` and its fields, each
|
|
133
|
-
* task's ring, and the instrumentation fields of each block.
|
|
118
|
+
* task's ring, and the instrumentation fields of each block, by block id.
|
|
134
119
|
*/
|
|
135
|
-
export type Instrumentation = ReturnType<typeof planInstrumentation
|
|
120
|
+
export type Instrumentation = ReturnType<typeof planInstrumentation> & {
|
|
121
|
+
fields: ReadonlyMap<string, BlockInstrumentation>;
|
|
122
|
+
};
|
|
136
123
|
|
|
137
|
-
export function planInstrumentation(
|
|
138
|
-
plan: CodesysPlan,
|
|
139
|
-
symbols: CodesysSymbols,
|
|
140
|
-
) {
|
|
124
|
+
export function planInstrumentation(plan: CodesysPlan, symbols: GlobalSymbols) {
|
|
141
125
|
const { core, options } = plan;
|
|
142
126
|
const settings = plan.project.debug;
|
|
143
127
|
// A simulation build binds no fieldbus I/O, but its outputs are still the configured ones.
|
|
144
128
|
const hardware = plan.project.hardware;
|
|
145
|
-
const outputs = [
|
|
129
|
+
const outputs: Output[] = [
|
|
146
130
|
...core.variables
|
|
147
131
|
.filter((variable) => variable.storage === "output")
|
|
148
132
|
.map((root) => ({ key: root.name, root, segments: [] })),
|
|
149
133
|
...(hardware
|
|
150
134
|
? Object.entries(hardware.config.io).flatMap(([key, binding]) => {
|
|
135
|
+
const address = ioAddress(hardware, binding);
|
|
151
136
|
if (
|
|
152
137
|
!isStoragePath(key) ||
|
|
153
|
-
|
|
138
|
+
address === undefined ||
|
|
139
|
+
!isOutputAddress(address)
|
|
154
140
|
) {
|
|
155
141
|
return [];
|
|
156
142
|
}
|
|
@@ -158,21 +144,19 @@ export function planInstrumentation(
|
|
|
158
144
|
return "error" in resolved ? [] : [resolved];
|
|
159
145
|
})
|
|
160
146
|
: plan.storageBindings.filter(({ key }) =>
|
|
161
|
-
required(options.io[key]).address
|
|
162
|
-
)
|
|
163
|
-
).map(({ key, root, segments }) => ({ key, root, segments })),
|
|
147
|
+
isOutputAddress(required(options.io[key]).address),
|
|
148
|
+
)),
|
|
164
149
|
];
|
|
165
|
-
for (const
|
|
166
|
-
if (!outputs.some((output) => output.key === key)) {
|
|
167
|
-
outputs.push(
|
|
150
|
+
for (const binding of plan.writerPaths) {
|
|
151
|
+
if (!outputs.some((output) => output.key === binding.key)) {
|
|
152
|
+
outputs.push(binding);
|
|
168
153
|
}
|
|
169
154
|
}
|
|
170
155
|
const analysis = new DebugAnalysis(core, plan.deployment, settings, outputs);
|
|
171
|
-
/** `GVL_TsplcDebug`, and the names of its fields. */
|
|
172
156
|
const global = symbols.names.allocateObject("GVL", "TsplcDebug");
|
|
173
157
|
const names = new Names();
|
|
174
|
-
names.allocate("buildId");
|
|
175
158
|
const slots = {
|
|
159
|
+
buildId: names.allocate("buildId"),
|
|
176
160
|
decisions: names.allocate("decisions"),
|
|
177
161
|
writers: names.allocate("writers"),
|
|
178
162
|
};
|
|
@@ -198,25 +182,36 @@ export function planInstrumentation(
|
|
|
198
182
|
record: symbols.names.allocateObject("ST", "TsplcRecord"),
|
|
199
183
|
client: symbols.names.allocateObject(
|
|
200
184
|
"FB",
|
|
201
|
-
|
|
185
|
+
telemetry?.endpoint.transport === "opcua"
|
|
202
186
|
? "TsplcTelemetryOpcUa"
|
|
203
187
|
: "TsplcTelemetryHttp",
|
|
204
188
|
),
|
|
205
189
|
}
|
|
206
190
|
: undefined;
|
|
207
|
-
/**
|
|
208
|
-
|
|
191
|
+
/**
|
|
192
|
+
* Job instances in manifest order, each with its id and instance text, and the job id each
|
|
193
|
+
* single-instance declaration passes to its service calls.
|
|
194
|
+
*/
|
|
195
|
+
const jobs = core.blocks
|
|
209
196
|
.filter((block) => block.job)
|
|
210
197
|
.flatMap((block) =>
|
|
211
|
-
analysis.instances.get(block.id)
|
|
212
|
-
|
|
198
|
+
required(analysis.instances.get(block.id)).map((path) => ({
|
|
199
|
+
block,
|
|
200
|
+
path,
|
|
201
|
+
})),
|
|
202
|
+
)
|
|
203
|
+
.map((job, index) => ({
|
|
204
|
+
...job,
|
|
205
|
+
id: index + 1,
|
|
206
|
+
instance: instanceText(job.path),
|
|
207
|
+
}));
|
|
213
208
|
const jobIds = new Map<string, number>();
|
|
214
|
-
|
|
215
|
-
const declared = path.at(-1)
|
|
209
|
+
for (const { path, id } of jobs) {
|
|
210
|
+
const declared = required(path.at(-1)).variable;
|
|
216
211
|
if (analysis.owningPath(declared) === path) {
|
|
217
|
-
jobIds.set(declared.id,
|
|
212
|
+
jobIds.set(declared.id, id);
|
|
218
213
|
}
|
|
219
|
-
}
|
|
214
|
+
}
|
|
220
215
|
/** Raw bytes over each assembly, in `GVL_TsplcDebug`, by device. */
|
|
221
216
|
const devices = new Map<
|
|
222
217
|
string,
|
|
@@ -250,12 +245,7 @@ export function planInstrumentation(
|
|
|
250
245
|
? plan.deployment.tasks.flatMap((task) =>
|
|
251
246
|
rings.has(task.name)
|
|
252
247
|
? []
|
|
253
|
-
: [
|
|
254
|
-
[
|
|
255
|
-
task.name,
|
|
256
|
-
`${global}.${names.allocate(`scanClock_${task.name}`)}`,
|
|
257
|
-
],
|
|
258
|
-
],
|
|
248
|
+
: [[task.name, names.allocate(`scanClock_${task.name}`)]],
|
|
259
249
|
)
|
|
260
250
|
: [],
|
|
261
251
|
);
|
|
@@ -264,18 +254,17 @@ export function planInstrumentation(
|
|
|
264
254
|
global,
|
|
265
255
|
slots,
|
|
266
256
|
rings,
|
|
267
|
-
/** Each task's clock in `GVL_TsplcDebug`, by task, when it has no ring that reads the clock. */
|
|
257
|
+
/** Each task's clock field in `GVL_TsplcDebug`, by task, when it has no ring that reads the clock. */
|
|
268
258
|
scanClocks,
|
|
269
259
|
telemetryNames,
|
|
270
260
|
jobs,
|
|
271
261
|
jobIds,
|
|
272
262
|
devices,
|
|
273
|
-
fields: new Map<string, BlockInstrumentation>(),
|
|
274
263
|
};
|
|
275
264
|
}
|
|
276
265
|
|
|
277
266
|
/** Instrumentation fields of a block: its job state and the requesting job's id. */
|
|
278
|
-
interface BlockInstrumentation {
|
|
267
|
+
export interface BlockInstrumentation {
|
|
279
268
|
busy?: string;
|
|
280
269
|
/** The method that records the job starting and finishing, allocated with `busy`. */
|
|
281
270
|
track?: string;
|
|
@@ -285,47 +274,54 @@ interface BlockInstrumentation {
|
|
|
285
274
|
sequence?: string;
|
|
286
275
|
}
|
|
287
276
|
|
|
288
|
-
/** Stands for the build id in the sender until the id, a hash over everything else, is known. */
|
|
289
|
-
const buildPlaceholder = "<build>";
|
|
290
|
-
|
|
291
277
|
/** The telemetry sender and its client; over OPC UA also the client's slots and their channels. */
|
|
292
278
|
export function emitTelemetry(
|
|
293
279
|
plan: CodesysPlan,
|
|
294
|
-
symbols:
|
|
280
|
+
symbols: GlobalSymbols,
|
|
295
281
|
instrumentation: Instrumentation,
|
|
296
282
|
networkName: string | undefined,
|
|
297
|
-
): { objects: GeneratedObject[]; rpcChannels:
|
|
283
|
+
): { objects: GeneratedObject[]; rpcChannels: ServiceChannel[] } {
|
|
298
284
|
const { telemetry } = plan;
|
|
299
285
|
const names = instrumentation.telemetryNames;
|
|
300
286
|
if (!telemetry || !names) {
|
|
301
287
|
return { objects: [], rpcChannels: [] };
|
|
302
288
|
}
|
|
303
|
-
const endpoint =
|
|
304
|
-
const
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
289
|
+
const { endpoint } = telemetry;
|
|
290
|
+
const objects = (transport: TelemetryTransport) =>
|
|
291
|
+
telemetryObjects({
|
|
292
|
+
plan: telemetry,
|
|
293
|
+
names,
|
|
294
|
+
target: symbols.targetTypes,
|
|
295
|
+
transport,
|
|
296
|
+
types: symbols.typeMap,
|
|
297
|
+
});
|
|
298
|
+
if (endpoint.transport === "opcua") {
|
|
299
|
+
const slots = rpcSlots(
|
|
300
|
+
symbols,
|
|
301
|
+
telemetryClient,
|
|
302
|
+
names.client,
|
|
303
|
+
endpoint.path,
|
|
304
|
+
);
|
|
305
|
+
return {
|
|
306
|
+
objects: [
|
|
307
|
+
slots.list,
|
|
308
|
+
...objects({
|
|
314
309
|
kind: "opcua",
|
|
315
310
|
timeoutMs: endpoint.timeoutMs,
|
|
316
311
|
rpcGlobal: slots.list.name,
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
312
|
+
}),
|
|
313
|
+
],
|
|
314
|
+
rpcChannels: slots.channels,
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
return {
|
|
318
|
+
objects: objects({
|
|
319
|
+
kind: "http",
|
|
320
|
+
endpoint,
|
|
321
|
+
network: `${required(networkName)}.network`,
|
|
322
|
+
}),
|
|
323
|
+
rpcChannels: [],
|
|
324
|
+
};
|
|
329
325
|
}
|
|
330
326
|
|
|
331
327
|
/**
|
|
@@ -345,19 +341,15 @@ export function emitDebugGlobal(
|
|
|
345
341
|
);
|
|
346
342
|
}
|
|
347
343
|
hash.update(JSON.stringify(manifest));
|
|
348
|
-
const id = hash.digest("hex").slice(0,
|
|
344
|
+
const id = hash.digest("hex").slice(0, buildIdLength);
|
|
349
345
|
|
|
350
|
-
|
|
351
|
-
const send = objects.find(
|
|
352
|
-
(object) => object.id === "tsplc:telemetryWriter:Send",
|
|
353
|
-
);
|
|
354
|
-
if (send?.implementation !== undefined) {
|
|
355
|
-
send.implementation = send.implementation.replace(buildPlaceholder, id);
|
|
356
|
-
}
|
|
346
|
+
fillBuildId(objects, id);
|
|
357
347
|
|
|
358
|
-
const fields = [
|
|
359
|
-
|
|
360
|
-
|
|
348
|
+
const fields = [
|
|
349
|
+
`${instrumentation.slots.buildId} : STRING(${buildIdLength}) := '${id}'`,
|
|
350
|
+
];
|
|
351
|
+
for (const field of instrumentation.scanClocks.values()) {
|
|
352
|
+
fields.push(`${field} : ${scanClockType}`);
|
|
361
353
|
}
|
|
362
354
|
for (const [task, field] of instrumentation.rings) {
|
|
363
355
|
fields.push(
|
|
@@ -373,7 +365,7 @@ export function emitDebugGlobal(
|
|
|
373
365
|
}
|
|
374
366
|
if (settings.writers && instrumentation.analysis.outputs.length) {
|
|
375
367
|
fields.push(
|
|
376
|
-
`${instrumentation.slots.writers} : ARRAY[0..${instrumentation.analysis.outputs.length - 1}] OF
|
|
368
|
+
`${instrumentation.slots.writers} : ARRAY[0..${instrumentation.analysis.outputs.length - 1}] OF ${writerSlotType}`,
|
|
377
369
|
);
|
|
378
370
|
}
|
|
379
371
|
for (const raw of [...instrumentation.devices.values()].flatMap((device) =>
|
|
@@ -433,7 +425,7 @@ const traceOperand = (storage: StorageScope, value: CoreExpression): string => {
|
|
|
433
425
|
if (signed) {
|
|
434
426
|
return `TO_DINT(LIMIT(LINT#${dintMinimum}, ${text}, LINT#${dintMaximum}))`;
|
|
435
427
|
}
|
|
436
|
-
const wide = type.bits
|
|
428
|
+
const wide = unsignedWidening(type.bits);
|
|
437
429
|
return `TO_DINT(MIN(TO_${wide}(${text}), ${wide}#${dintMaximum}))`;
|
|
438
430
|
};
|
|
439
431
|
|
|
@@ -442,7 +434,7 @@ const traceCall = (
|
|
|
442
434
|
{ context, storage, task }: RoutineProbes,
|
|
443
435
|
site: number,
|
|
444
436
|
value: string,
|
|
445
|
-
operands: readonly Operand[]
|
|
437
|
+
operands: readonly Operand[],
|
|
446
438
|
): string => {
|
|
447
439
|
const captured = Array.from(
|
|
448
440
|
{ length: required(context.plan.telemetry?.traceOperands) },
|
|
@@ -503,7 +495,7 @@ export function writeProbes(
|
|
|
503
495
|
export const jobField = (
|
|
504
496
|
storage: StorageScope,
|
|
505
497
|
job: CoreFunctionBlock,
|
|
506
|
-
name:
|
|
498
|
+
name: keyof typeof jobStateFields,
|
|
507
499
|
) =>
|
|
508
500
|
storageName(
|
|
509
501
|
storage,
|
|
@@ -541,6 +533,7 @@ export function jobTracking(
|
|
|
541
533
|
probes,
|
|
542
534
|
sites.start,
|
|
543
535
|
`TO_DINT(${jobField(probes.storage, job, "step")})`,
|
|
536
|
+
[],
|
|
544
537
|
),
|
|
545
538
|
1,
|
|
546
539
|
);
|
|
@@ -552,13 +545,14 @@ export function jobTracking(
|
|
|
552
545
|
line(`IF NOT ${busy} THEN`, 0);
|
|
553
546
|
if (sites) {
|
|
554
547
|
line(`IF ${error} <> 0 THEN`, 1);
|
|
555
|
-
line(traceCall(probes, sites.completion, `-TO_DINT(${error})
|
|
548
|
+
line(traceCall(probes, sites.completion, `-TO_DINT(${error})`, []), 2);
|
|
556
549
|
line("ELSE", 1);
|
|
557
550
|
line(
|
|
558
551
|
traceCall(
|
|
559
552
|
probes,
|
|
560
553
|
sites.completion,
|
|
561
554
|
`TO_DINT(${required(fields.step)})`,
|
|
555
|
+
[],
|
|
562
556
|
),
|
|
563
557
|
2,
|
|
564
558
|
);
|
|
@@ -566,7 +560,7 @@ export function jobTracking(
|
|
|
566
560
|
}
|
|
567
561
|
// Cancellation is asked for, so it isn't a failure.
|
|
568
562
|
if (failure) {
|
|
569
|
-
line(`IF ${error} <> 0 AND ${error} <>
|
|
563
|
+
line(`IF ${error} <> 0 AND ${error} <> ${jobError.cancelled} THEN`, 1);
|
|
570
564
|
line(
|
|
571
565
|
`${ringTarget(instrumentation, failure.task)}.Failure${failure.id}(code := ${error}, step := ${required(fields.step)}${failure.instance === null ? "" : `, instance := ${stStringLiteral(failure.instance)}`});`,
|
|
572
566
|
2,
|
package/src/codesys/io-paths.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
coreTables,
|
|
3
|
+
isLogicalIo,
|
|
4
|
+
type PlcType,
|
|
5
|
+
type Variable,
|
|
6
|
+
type VerifiedCoreModule,
|
|
7
|
+
} from "@tsplc/compiler/ir";
|
|
8
|
+
import { arrayTypeText } from "@tsplc/iec";
|
|
3
9
|
import { type IoTarget, ioLayout } from "@tsplc/typegen/hardware";
|
|
4
|
-
import { moduleName } from "./storage";
|
|
10
|
+
import { moduleName, storagePath } from "./storage";
|
|
5
11
|
|
|
6
12
|
type StorageSegment =
|
|
7
13
|
| { kind: "field"; record: string; name: string }
|
|
@@ -32,7 +38,7 @@ export function resolveStoragePath(
|
|
|
32
38
|
error: `${key}: expected Module.variable followed by .field or [index].`,
|
|
33
39
|
};
|
|
34
40
|
}
|
|
35
|
-
const [, module, name, rest] = match;
|
|
41
|
+
const [, module, name, rest = ""] = match;
|
|
36
42
|
const roots = core.variables.filter(
|
|
37
43
|
(item) =>
|
|
38
44
|
item.storage === "module" &&
|
|
@@ -47,10 +53,10 @@ export function resolveStoragePath(
|
|
|
47
53
|
: `${key}: no mutable module variable ${module}.${name}.`,
|
|
48
54
|
};
|
|
49
55
|
}
|
|
50
|
-
const
|
|
51
|
-
let type =
|
|
56
|
+
const { typeOf } = coreTables(core);
|
|
57
|
+
let type = typeOf(root.type);
|
|
52
58
|
const segments: StorageSegment[] = [];
|
|
53
|
-
for (const [, field, index] of rest
|
|
59
|
+
for (const [, field, index] of rest.matchAll(
|
|
54
60
|
/\.([A-Za-z_$][\w$]*)|\[(-?\d+)\]/g,
|
|
55
61
|
)) {
|
|
56
62
|
if (field !== undefined) {
|
|
@@ -62,7 +68,7 @@ export function resolveStoragePath(
|
|
|
62
68
|
return { error: `${key}: no field ${field}.` };
|
|
63
69
|
}
|
|
64
70
|
segments.push({ kind: "field", record: type.id, name: field });
|
|
65
|
-
type =
|
|
71
|
+
type = typeOf(member.type);
|
|
66
72
|
} else {
|
|
67
73
|
const value = Number(index);
|
|
68
74
|
if (type.kind !== "array") {
|
|
@@ -74,7 +80,7 @@ export function resolveStoragePath(
|
|
|
74
80
|
};
|
|
75
81
|
}
|
|
76
82
|
segments.push({ kind: "index", value });
|
|
77
|
-
type =
|
|
83
|
+
type = typeOf(type.element);
|
|
78
84
|
}
|
|
79
85
|
}
|
|
80
86
|
return { key, root, segments, type };
|
|
@@ -98,19 +104,24 @@ export function iecSpelling(
|
|
|
98
104
|
if (type.kind !== "array") {
|
|
99
105
|
return undefined;
|
|
100
106
|
}
|
|
101
|
-
const element =
|
|
102
|
-
const
|
|
103
|
-
return
|
|
104
|
-
?
|
|
107
|
+
const element = types.get(type.element);
|
|
108
|
+
const spelling = element && iecSpelling(element, types);
|
|
109
|
+
return spelling && element.kind !== "array"
|
|
110
|
+
? arrayTypeText({
|
|
111
|
+
lower: type.lowerBound,
|
|
112
|
+
upper: type.lowerBound + type.length - 1,
|
|
113
|
+
element: spelling,
|
|
114
|
+
})
|
|
105
115
|
: undefined;
|
|
106
116
|
}
|
|
107
117
|
|
|
108
118
|
/** Every key an `io` mapping may use: logical IO names and paths into mutable module storage. */
|
|
109
119
|
export function ioTargets(core: VerifiedCoreModule): IoTarget[] {
|
|
110
|
-
const types =
|
|
120
|
+
const { types, typeOf } = coreTables(core);
|
|
111
121
|
const targets: IoTarget[] = [];
|
|
112
122
|
const add = (key: string, type: PlcType) => {
|
|
113
|
-
const
|
|
123
|
+
const spelling = iecSpelling(type, types);
|
|
124
|
+
const layout = spelling && ioLayout(spelling);
|
|
114
125
|
if (layout) {
|
|
115
126
|
targets.push({ key, layout });
|
|
116
127
|
}
|
|
@@ -119,22 +130,19 @@ export function ioTargets(core: VerifiedCoreModule): IoTarget[] {
|
|
|
119
130
|
add(key, type);
|
|
120
131
|
if (type.kind === "record") {
|
|
121
132
|
for (const field of type.fields) {
|
|
122
|
-
visit(`${key}.${field.name}`,
|
|
133
|
+
visit(`${key}.${field.name}`, typeOf(field.type));
|
|
123
134
|
}
|
|
124
135
|
}
|
|
125
136
|
// Typegen writes keys as template literal types, so any index matches here.
|
|
126
137
|
if (type.kind === "array") {
|
|
127
|
-
visit(`${key}[\${number}]`,
|
|
138
|
+
visit(`${key}[\${number}]`, typeOf(type.element));
|
|
128
139
|
}
|
|
129
140
|
};
|
|
130
141
|
for (const variable of core.variables) {
|
|
131
|
-
if (variable
|
|
132
|
-
add(variable.name,
|
|
142
|
+
if (isLogicalIo(variable)) {
|
|
143
|
+
add(variable.name, typeOf(variable.type));
|
|
133
144
|
} else if (variable.storage === "module") {
|
|
134
|
-
visit(
|
|
135
|
-
`${moduleName(variable)}.${variable.name}`,
|
|
136
|
-
types.get(variable.type)!,
|
|
137
|
-
);
|
|
145
|
+
visit(storagePath(variable), typeOf(variable.type));
|
|
138
146
|
}
|
|
139
147
|
}
|
|
140
148
|
return targets;
|