@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,11 +1,12 @@
|
|
|
1
|
-
import type { CoreExpression, CorePath } from "@tsplc/compiler/ir";
|
|
2
|
-
import {
|
|
1
|
+
import type { CoreExpression, CorePath, CoreTables } from "@tsplc/compiler/ir";
|
|
2
|
+
import { required } from "./required";
|
|
3
|
+
import type { CodesysSymbols } from "./symbols";
|
|
3
4
|
|
|
4
|
-
/** The storage a routine's ST can name
|
|
5
|
+
/** The storage a routine's ST can name (module storage, IO and its own variables), and each variable's declaration. */
|
|
5
6
|
export interface StorageScope {
|
|
6
7
|
symbols: CodesysSymbols;
|
|
7
8
|
names: ReadonlyMap<string, string>;
|
|
8
|
-
|
|
9
|
+
variableOf: CoreTables["variableOf"];
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
export const storageName = ({ names }: StorageScope, id: string): string => {
|
|
@@ -16,53 +17,60 @@ export const storageName = ({ names }: StorageScope, id: string): string => {
|
|
|
16
17
|
return value;
|
|
17
18
|
};
|
|
18
19
|
|
|
19
|
-
// Block output records are a source abstraction; target FB fields are direct.
|
|
20
20
|
export const placeText = (
|
|
21
21
|
scope: StorageScope,
|
|
22
22
|
id: string,
|
|
23
23
|
path: CorePath = [],
|
|
24
24
|
): string => {
|
|
25
25
|
const { typeMap, blocks, blockFields, targetTypes } = scope.symbols;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
const place = (
|
|
27
|
+
text: string,
|
|
28
|
+
typeId: string,
|
|
29
|
+
[segment, ...rest]: CorePath,
|
|
30
|
+
): string => {
|
|
31
|
+
if (!segment) {
|
|
32
|
+
return text;
|
|
33
|
+
}
|
|
30
34
|
const type = required(typeMap.get(typeId));
|
|
35
|
+
// Block output records are a source abstraction; target FB fields are direct.
|
|
31
36
|
if (
|
|
32
37
|
segment.kind === "field" &&
|
|
33
38
|
type.kind === "block" &&
|
|
34
39
|
segment.name === "out"
|
|
35
40
|
) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (segment.kind === "field" && outputBlock) {
|
|
41
|
+
const [field, ...after] = rest;
|
|
42
|
+
if (!field) {
|
|
43
|
+
return text;
|
|
44
|
+
}
|
|
41
45
|
const output = required(
|
|
42
|
-
required(blocks.get(
|
|
43
|
-
(
|
|
46
|
+
required(blocks.get(type.block)).outputs.find(
|
|
47
|
+
(item) => field.kind === "field" && item.name === field.name,
|
|
44
48
|
),
|
|
45
49
|
);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
return place(
|
|
51
|
+
`${text}.${required(required(blockFields.get(type.block)).get(output.id))}`,
|
|
52
|
+
output.type,
|
|
53
|
+
after,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
if (segment.kind === "field" && type.kind === "record") {
|
|
57
|
+
return place(
|
|
58
|
+
`${text}.${targetTypes.field(typeId, segment.name)}`,
|
|
59
|
+
required(type.fields.find((field) => field.name === segment.name)).type,
|
|
60
|
+
rest,
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
if (segment.kind === "index" && type.kind === "array") {
|
|
55
64
|
// A strict enum converts explicitly to its DINT base, as HTTP JSON encoding does.
|
|
56
|
-
|
|
65
|
+
const index =
|
|
57
66
|
typeMap.get(segment.value.type)?.kind === "enum"
|
|
58
|
-
? `
|
|
59
|
-
:
|
|
60
|
-
|
|
61
|
-
} else {
|
|
62
|
-
throw new Error("Invalid verified place");
|
|
67
|
+
? `TO_DINT(${expressionText(scope, segment.value)})`
|
|
68
|
+
: expressionText(scope, segment.value);
|
|
69
|
+
return place(`${text}[${index}]`, type.element, rest);
|
|
63
70
|
}
|
|
64
|
-
|
|
65
|
-
|
|
71
|
+
throw new Error("Invalid verified place");
|
|
72
|
+
};
|
|
73
|
+
return place(storageName(scope, id), scope.variableOf(id).type, path);
|
|
66
74
|
};
|
|
67
75
|
|
|
68
76
|
export const expressionText = (
|
|
@@ -2,9 +2,11 @@ import {
|
|
|
2
2
|
defaultValue,
|
|
3
3
|
type GeneratedObject,
|
|
4
4
|
instancedBlock,
|
|
5
|
+
isLogicalIo,
|
|
6
|
+
type SourceSpan,
|
|
5
7
|
type Variable,
|
|
6
8
|
} from "@tsplc/compiler/ir";
|
|
7
|
-
import
|
|
9
|
+
import { isOutputAddress } from "@tsplc/typegen/hardware";
|
|
8
10
|
import {
|
|
9
11
|
isStoragePath,
|
|
10
12
|
resolveStoragePath,
|
|
@@ -12,11 +14,15 @@ import {
|
|
|
12
14
|
} from "./io-paths";
|
|
13
15
|
import { Names } from "./names";
|
|
14
16
|
import type { CodesysPlan } from "./plan";
|
|
17
|
+
import { required } from "./required";
|
|
18
|
+
import type { ObjectMapping } from "./st-files";
|
|
15
19
|
import type { GlobalStorage } from "./storage";
|
|
16
|
-
import {
|
|
20
|
+
import type { EmissionContext, GlobalSymbols } from "./symbols";
|
|
17
21
|
|
|
18
22
|
const globalSections = {
|
|
19
23
|
constants: "VAR_GLOBAL CONSTANT",
|
|
24
|
+
// The build makes a list with this section CODESYS's one persistent variable list.
|
|
25
|
+
persistent: "VAR_GLOBAL PERSISTENT RETAIN",
|
|
20
26
|
retained: "VAR_GLOBAL RETAIN",
|
|
21
27
|
state: "VAR_GLOBAL",
|
|
22
28
|
} as const satisfies Record<GlobalStorage, string>;
|
|
@@ -39,7 +45,7 @@ export interface IoMapping {
|
|
|
39
45
|
}
|
|
40
46
|
|
|
41
47
|
const globalInitializer = (
|
|
42
|
-
{ typeMap, targetTypes }:
|
|
48
|
+
{ typeMap, targetTypes }: GlobalSymbols,
|
|
43
49
|
storage: GlobalStorage,
|
|
44
50
|
item: Variable,
|
|
45
51
|
): string => {
|
|
@@ -54,118 +60,126 @@ const globalInitializer = (
|
|
|
54
60
|
: targetTypes.declarationInitializer(value, item.type);
|
|
55
61
|
};
|
|
56
62
|
|
|
57
|
-
/**
|
|
58
|
-
|
|
59
|
-
* published variable is writable by clients. Unpublished variables have no access.
|
|
60
|
-
*/
|
|
61
|
-
export const publishedAccess = (
|
|
63
|
+
/** Whether the build target publishes a variable, which clients may then read and write. */
|
|
64
|
+
export const isPublished = (
|
|
62
65
|
plan: CodesysPlan,
|
|
63
|
-
): ((variable: Variable) =>
|
|
66
|
+
): ((variable: Variable) => boolean) => {
|
|
64
67
|
const published = new Set(plan.publication[plan.options.buildTarget]);
|
|
65
|
-
return (variable) =>
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
return (variable) => published.has(variable.id);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/** A list's declaration lines and the source each declares, in the order it writes them. */
|
|
72
|
+
const listLines = (object: string, header: readonly string[]) => {
|
|
73
|
+
const lines = [...header];
|
|
74
|
+
const mappings: ObjectMapping[] = [];
|
|
75
|
+
return {
|
|
76
|
+
lines,
|
|
77
|
+
mappings,
|
|
78
|
+
/** Appends a line; one that declares `span` maps back to it. */
|
|
79
|
+
write: (line: string, span?: SourceSpan) => {
|
|
80
|
+
lines.push(line);
|
|
81
|
+
if (span) {
|
|
82
|
+
mappings.push({
|
|
83
|
+
object,
|
|
84
|
+
file: "declaration",
|
|
85
|
+
line: lines.length,
|
|
86
|
+
span,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
},
|
|
70
90
|
};
|
|
71
91
|
};
|
|
72
92
|
|
|
73
|
-
/** The global lists of module storage
|
|
93
|
+
/** The global lists of module storage, and the global symbol of each variable they declare. */
|
|
74
94
|
export function emitGlobalLists(
|
|
75
95
|
plan: CodesysPlan,
|
|
76
|
-
symbols:
|
|
77
|
-
): {
|
|
78
|
-
|
|
96
|
+
symbols: GlobalSymbols,
|
|
97
|
+
): {
|
|
98
|
+
objects: GeneratedObject[];
|
|
99
|
+
mappings: ObjectMapping[];
|
|
100
|
+
references: Map<string, string>;
|
|
101
|
+
} {
|
|
102
|
+
const { globals, targetTypes } = symbols;
|
|
79
103
|
const objects: GeneratedObject[] = [];
|
|
80
|
-
const mappings:
|
|
81
|
-
const
|
|
104
|
+
const mappings: ObjectMapping[] = [];
|
|
105
|
+
const references = new Map<string, string>();
|
|
106
|
+
const published = isPublished(plan);
|
|
82
107
|
for (const group of globals) {
|
|
83
108
|
const { name, fields } = group;
|
|
84
|
-
const publish = group.variables.some(
|
|
85
|
-
const
|
|
109
|
+
const publish = group.variables.some(published);
|
|
110
|
+
const list = listLines(group.id, [
|
|
86
111
|
...(publish ? ["{attribute 'linkalways'}"] : []),
|
|
87
112
|
"{attribute 'qualified_only'}",
|
|
88
|
-
];
|
|
113
|
+
]);
|
|
89
114
|
for (const section of group.sections) {
|
|
90
|
-
|
|
115
|
+
list.write(globalSections[section.storage]);
|
|
91
116
|
for (const item of section.variables) {
|
|
92
117
|
const field = required(fields.get(item.id));
|
|
93
118
|
references.set(item.id, `${name}.${field}`);
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
lines.push(` {attribute 'symbol' := '${symbol}'}`);
|
|
119
|
+
if (published(item)) {
|
|
120
|
+
list.write(" {attribute 'symbol' := 'readwrite'}");
|
|
97
121
|
}
|
|
98
|
-
mappings.push({
|
|
99
|
-
path: `${name}.st`,
|
|
100
|
-
line: lines.length + 1,
|
|
101
|
-
span: item.span,
|
|
102
|
-
});
|
|
103
122
|
const initial = globalInitializer(symbols, section.storage, item);
|
|
104
|
-
|
|
123
|
+
list.write(
|
|
124
|
+
` ${field} : ${targetTypes.name(item.type)}${initial};`,
|
|
125
|
+
item.span,
|
|
126
|
+
);
|
|
105
127
|
}
|
|
106
|
-
|
|
128
|
+
list.write("END_VAR");
|
|
107
129
|
}
|
|
108
130
|
objects.push({
|
|
109
131
|
id: group.id,
|
|
110
132
|
kind: "globalList",
|
|
111
133
|
name,
|
|
112
|
-
declaration: `${lines.join("\n")}\n`,
|
|
134
|
+
declaration: `${list.lines.join("\n")}\n`,
|
|
113
135
|
});
|
|
136
|
+
mappings.push(...list.mappings);
|
|
114
137
|
}
|
|
115
|
-
return { objects, mappings };
|
|
138
|
+
return { objects, mappings, references };
|
|
116
139
|
}
|
|
117
140
|
|
|
118
|
-
/**
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
*/
|
|
141
|
+
/** The id of the I/O list, which no source module places. */
|
|
142
|
+
export const ioListId = "io";
|
|
143
|
+
|
|
144
|
+
/** `GVL_IO`: logical IO and the AT wires of `io` bindings, and logical IO's global symbols. */
|
|
122
145
|
export function emitIoList(
|
|
123
146
|
plan: CodesysPlan,
|
|
124
|
-
symbols:
|
|
147
|
+
symbols: GlobalSymbols,
|
|
148
|
+
references: ReadonlyMap<string, string>,
|
|
125
149
|
): {
|
|
126
150
|
objects: GeneratedObject[];
|
|
127
|
-
mappings:
|
|
151
|
+
mappings: ObjectMapping[];
|
|
128
152
|
channels: IoChannel[];
|
|
129
153
|
ioMappings: IoMapping[];
|
|
154
|
+
references: Map<string, string>;
|
|
130
155
|
} {
|
|
131
156
|
const { core, options } = plan;
|
|
132
|
-
const { names,
|
|
133
|
-
const objects: GeneratedObject[] = [];
|
|
134
|
-
const mappings: SourceMapping[] = [];
|
|
157
|
+
const { names, targetTypes, typeMap } = symbols;
|
|
135
158
|
const channels: IoChannel[] = [];
|
|
136
159
|
const ioMappings: IoMapping[] = [];
|
|
160
|
+
const ioReferences = new Map<string, string>();
|
|
137
161
|
const ioName = names.allocate("GVL_IO");
|
|
138
|
-
const ioFields = new Names();
|
|
139
|
-
|
|
140
|
-
ioFields.reserve(name);
|
|
141
|
-
}
|
|
142
|
-
const ioLines = [
|
|
162
|
+
const ioFields = new Names(symbols.blockNames.values());
|
|
163
|
+
const header = [
|
|
143
164
|
"{attribute 'linkalways'}",
|
|
144
165
|
"{attribute 'qualified_only'}",
|
|
145
166
|
"VAR_GLOBAL",
|
|
146
167
|
];
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
)) {
|
|
168
|
+
const list = listLines(ioListId, header);
|
|
169
|
+
for (const item of core.variables.filter(isLogicalIo)) {
|
|
150
170
|
const field = ioFields.allocate(item.name);
|
|
151
171
|
const initial = item.initial ?? defaultValue(item.type, typeMap);
|
|
152
172
|
const binding = required(options.io[item.name]);
|
|
153
|
-
|
|
173
|
+
const declaration = ` ${field} : ${targetTypes.name(item.type)} := ${targetTypes.literal(initial, item.type)};`;
|
|
174
|
+
ioReferences.set(item.id, `${ioName}.${field}`);
|
|
154
175
|
if (binding.mapped) {
|
|
155
176
|
ioMappings.push({
|
|
156
177
|
key: item.name,
|
|
157
178
|
address: binding.address,
|
|
158
179
|
variable: `${ioName}.${field}`,
|
|
159
180
|
});
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
line: ioLines.length + 2,
|
|
163
|
-
span: item.span,
|
|
164
|
-
});
|
|
165
|
-
ioLines.push(
|
|
166
|
-
" {attribute 'symbol' := 'read'}",
|
|
167
|
-
` ${field} : ${targetTypes.name(item.type)} := ${targetTypes.literal(initial, item.type)};`,
|
|
168
|
-
);
|
|
181
|
+
list.write(" {attribute 'symbol' := 'read'}");
|
|
182
|
+
list.write(declaration, item.span);
|
|
169
183
|
continue;
|
|
170
184
|
}
|
|
171
185
|
const wire = ioFields.allocate(`${item.name}_physical`);
|
|
@@ -177,21 +191,18 @@ export function emitIoList(
|
|
|
177
191
|
wire: `${ioName}.${wire}`,
|
|
178
192
|
inverted: binding.inverted,
|
|
179
193
|
});
|
|
180
|
-
|
|
181
|
-
{ path: `${ioName}.st`, line: ioLines.length + 1, span: item.span },
|
|
182
|
-
{ path: `${ioName}.st`, line: ioLines.length + 3, span: item.span },
|
|
183
|
-
);
|
|
184
|
-
ioLines.push(
|
|
194
|
+
list.write(
|
|
185
195
|
` ${wire} AT ${binding.address} : ${targetTypes.name(item.type)};`,
|
|
186
|
-
|
|
187
|
-
// private; external writes cannot alter the controller's IO snapshot.
|
|
188
|
-
" {attribute 'symbol' := 'read'}",
|
|
189
|
-
` ${field} : ${targetTypes.name(item.type)} := ${targetTypes.literal(initial, item.type)};`,
|
|
196
|
+
item.span,
|
|
190
197
|
);
|
|
198
|
+
// Publish the scan's logical value for monitoring. Physical wires stay
|
|
199
|
+
// private; external writes cannot alter the controller's IO snapshot.
|
|
200
|
+
list.write(" {attribute 'symbol' := 'read'}");
|
|
201
|
+
list.write(declaration, item.span);
|
|
191
202
|
}
|
|
192
203
|
for (const { key, root, segments, type } of plan.storageBindings) {
|
|
193
204
|
const { address, mapped, inverted } = required(options.io[key]);
|
|
194
|
-
const target = bindingTarget(symbols, { root, segments });
|
|
205
|
+
const target = bindingTarget(symbols, references, { root, segments });
|
|
195
206
|
if (mapped) {
|
|
196
207
|
ioMappings.push({ key, address, variable: target });
|
|
197
208
|
continue;
|
|
@@ -200,53 +211,59 @@ export function emitIoList(
|
|
|
200
211
|
`${key.replace(/\W+/g, "_").replace(/_+$/, "")}_physical`,
|
|
201
212
|
);
|
|
202
213
|
// The wire takes the target's own type, so equal-width EDS types need no conversion.
|
|
203
|
-
|
|
214
|
+
list.write(` ${wire} AT ${address} : ${targetTypes.name(type.id)};`);
|
|
204
215
|
channels.push({
|
|
205
216
|
key,
|
|
206
217
|
root: root.id,
|
|
207
|
-
input: address
|
|
218
|
+
input: !isOutputAddress(address),
|
|
208
219
|
target,
|
|
209
220
|
wire: `${ioName}.${wire}`,
|
|
210
221
|
inverted,
|
|
211
222
|
});
|
|
212
223
|
}
|
|
213
|
-
ioLines.push("END_VAR");
|
|
214
224
|
// Mapped storage bindings need no IO list; mapped logical IO is declared here.
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
225
|
+
const declares = list.lines.length > header.length;
|
|
226
|
+
list.write("END_VAR");
|
|
227
|
+
return {
|
|
228
|
+
objects: declares
|
|
229
|
+
? [
|
|
230
|
+
{
|
|
231
|
+
id: ioListId,
|
|
232
|
+
kind: "globalList",
|
|
233
|
+
name: ioName,
|
|
234
|
+
declaration: `${list.lines.join("\n")}\n`,
|
|
235
|
+
},
|
|
236
|
+
]
|
|
237
|
+
: [],
|
|
238
|
+
mappings: list.mappings,
|
|
239
|
+
channels,
|
|
240
|
+
ioMappings,
|
|
241
|
+
references: ioReferences,
|
|
242
|
+
};
|
|
224
243
|
}
|
|
225
244
|
|
|
226
245
|
/** The target symbol of an `io` storage path. */
|
|
227
246
|
function bindingTarget(
|
|
228
|
-
|
|
247
|
+
{ targetTypes }: GlobalSymbols,
|
|
248
|
+
references: ReadonlyMap<string, string>,
|
|
229
249
|
{ root, segments }: Pick<StorageBinding, "root" | "segments">,
|
|
230
250
|
): string {
|
|
231
251
|
return segments.reduce(
|
|
232
252
|
(path, segment) =>
|
|
233
253
|
segment.kind === "field"
|
|
234
|
-
? `${path}.${
|
|
254
|
+
? `${path}.${targetTypes.field(segment.record, segment.name)}`
|
|
235
255
|
: `${path}[${segment.value}]`,
|
|
236
|
-
required(
|
|
256
|
+
required(references.get(root.id)),
|
|
237
257
|
);
|
|
238
258
|
}
|
|
239
259
|
|
|
240
260
|
/** The target symbol and type that hold an `io` key's value, when this program has it. */
|
|
241
261
|
export function ioTarget(
|
|
242
|
-
{ core }:
|
|
243
|
-
symbols: CodesysSymbols,
|
|
262
|
+
{ plan: { core }, symbols }: EmissionContext,
|
|
244
263
|
key: string,
|
|
245
264
|
): { target: string; type: string } | undefined {
|
|
246
265
|
const logical = core.variables.find(
|
|
247
|
-
(variable) =>
|
|
248
|
-
(variable.storage === "input" || variable.storage === "output") &&
|
|
249
|
-
variable.name === key,
|
|
266
|
+
(variable) => isLogicalIo(variable) && variable.name === key,
|
|
250
267
|
);
|
|
251
268
|
if (logical) {
|
|
252
269
|
return {
|
|
@@ -260,5 +277,8 @@ export function ioTarget(
|
|
|
260
277
|
const resolved = resolveStoragePath(core, key);
|
|
261
278
|
return "error" in resolved
|
|
262
279
|
? undefined
|
|
263
|
-
: {
|
|
280
|
+
: {
|
|
281
|
+
target: bindingTarget(symbols, symbols.references, resolved),
|
|
282
|
+
type: resolved.type.id,
|
|
283
|
+
};
|
|
264
284
|
}
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
coreTables,
|
|
3
|
+
pascalCase,
|
|
4
|
+
standardBlocks,
|
|
5
|
+
type VerifiedCoreModule,
|
|
6
|
+
} from "@tsplc/compiler/ir";
|
|
7
|
+
import { Names } from "./names";
|
|
3
8
|
import { storageLayout } from "./storage";
|
|
4
9
|
import { CodesysTypes } from "./types";
|
|
5
10
|
|
|
6
11
|
export const planGlobalNames = (
|
|
7
12
|
core: VerifiedCoreModule,
|
|
8
|
-
programNames:
|
|
13
|
+
programNames: ReadonlyMap<string, string>,
|
|
9
14
|
) => {
|
|
10
|
-
const names = new Names();
|
|
11
|
-
|
|
12
|
-
names.reserve(name);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const typeMap = new Map(core.types.map((type) => [type.id, type]));
|
|
15
|
+
const names = new Names(programNames.values());
|
|
16
|
+
const typeMap = coreTables(core).types;
|
|
16
17
|
const blockNames = new Map(
|
|
17
18
|
core.blocks.map((block) => [
|
|
18
19
|
block.id,
|
|
@@ -28,7 +29,7 @@ export const planGlobalNames = (
|
|
|
28
29
|
|
|
29
30
|
const { globalLists, retainedVariables } = storageLayout(core);
|
|
30
31
|
const hasExports = (group: (typeof globalLists)[number]) =>
|
|
31
|
-
group.variables.some((variable) => variable.exported
|
|
32
|
+
group.variables.some((variable) => variable.exported);
|
|
32
33
|
const globals = globalLists.map((group) => {
|
|
33
34
|
const splitByStorage = globalLists.some(
|
|
34
35
|
(other) =>
|
|
@@ -44,10 +45,7 @@ export const planGlobalNames = (
|
|
|
44
45
|
),
|
|
45
46
|
)
|
|
46
47
|
: names.allocateObject("GVL", `${group.module}_${group.kind}`);
|
|
47
|
-
const fields = new Names();
|
|
48
|
-
for (const name of blockNames.values()) {
|
|
49
|
-
fields.reserve(name);
|
|
50
|
-
}
|
|
48
|
+
const fields = new Names(blockNames.values());
|
|
51
49
|
return {
|
|
52
50
|
...group,
|
|
53
51
|
name,
|