@sccharts-lab/engine 0.0.0-stage → 0.1.0
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/LICENSE +277 -0
- package/README.md +125 -2
- package/dist/codegen/expr.d.ts +36 -0
- package/dist/codegen/expr.js +252 -0
- package/dist/codegen/expr.js.map +1 -0
- package/dist/codegen/index.d.ts +4 -0
- package/dist/codegen/index.js +238 -0
- package/dist/codegen/index.js.map +1 -0
- package/dist/codegen/layout.d.ts +57 -0
- package/dist/codegen/layout.js +306 -0
- package/dist/codegen/layout.js.map +1 -0
- package/dist/codegen/logic.d.ts +31 -0
- package/dist/codegen/logic.js +258 -0
- package/dist/codegen/logic.js.map +1 -0
- package/dist/codegen/methods.d.ts +17 -0
- package/dist/codegen/methods.js +242 -0
- package/dist/codegen/methods.js.map +1 -0
- package/dist/codegen/reset.d.ts +6 -0
- package/dist/codegen/reset.js +110 -0
- package/dist/codegen/reset.js.map +1 -0
- package/dist/codegen/types.d.ts +81 -0
- package/dist/codegen/types.js +3 -0
- package/dist/codegen/types.js.map +1 -0
- package/dist/format.d.ts +136 -0
- package/dist/format.js +872 -0
- package/dist/format.js.map +1 -0
- package/dist/index.d.ts +120 -0
- package/dist/index.js +507 -0
- package/dist/index.js.map +1 -0
- package/dist/internal.d.ts +1 -0
- package/dist/internal.js +4 -0
- package/dist/internal.js.map +1 -0
- package/dist/parser/ids.d.ts +4 -0
- package/dist/parser/ids.js +172 -0
- package/dist/parser/ids.js.map +1 -0
- package/dist/parser/imports.d.ts +2 -0
- package/dist/parser/imports.js +28 -0
- package/dist/parser/imports.js.map +1 -0
- package/dist/parser/interface.d.ts +10 -0
- package/dist/parser/interface.js +93 -0
- package/dist/parser/interface.js.map +1 -0
- package/dist/parser/kielerWording.d.ts +2 -0
- package/dist/parser/kielerWording.js +196 -0
- package/dist/parser/kielerWording.js.map +1 -0
- package/dist/parser/lexer.d.ts +25 -0
- package/dist/parser/lexer.js +334 -0
- package/dist/parser/lexer.js.map +1 -0
- package/dist/parser/parser.d.ts +29 -0
- package/dist/parser/parser.js +3249 -0
- package/dist/parser/parser.js.map +1 -0
- package/dist/parser/resolve.d.ts +46 -0
- package/dist/parser/resolve.js +919 -0
- package/dist/parser/resolve.js.map +1 -0
- package/dist/parser/source.d.ts +15 -0
- package/dist/parser/source.js +42 -0
- package/dist/parser/source.js.map +1 -0
- package/dist/parser/validate.d.ts +5 -0
- package/dist/parser/validate.js +1430 -0
- package/dist/parser/validate.js.map +1 -0
- package/dist/sim/abortRegions.d.ts +9 -0
- package/dist/sim/abortRegions.js +192 -0
- package/dist/sim/abortRegions.js.map +1 -0
- package/dist/sim/analysis.d.ts +113 -0
- package/dist/sim/analysis.js +1104 -0
- package/dist/sim/analysis.js.map +1 -0
- package/dist/sim/codegen.d.ts +30 -0
- package/dist/sim/codegen.js +730 -0
- package/dist/sim/codegen.js.map +1 -0
- package/dist/sim/compile.d.ts +43 -0
- package/dist/sim/compile.js +1062 -0
- package/dist/sim/compile.js.map +1 -0
- package/dist/sim/deps.d.ts +73 -0
- package/dist/sim/deps.js +481 -0
- package/dist/sim/deps.js.map +1 -0
- package/dist/sim/describe.d.ts +22 -0
- package/dist/sim/describe.js +272 -0
- package/dist/sim/describe.js.map +1 -0
- package/dist/sim/describePreemption.d.ts +22 -0
- package/dist/sim/describePreemption.js +90 -0
- package/dist/sim/describePreemption.js.map +1 -0
- package/dist/sim/describeStructure.d.ts +75 -0
- package/dist/sim/describeStructure.js +293 -0
- package/dist/sim/describeStructure.js.map +1 -0
- package/dist/sim/eval.d.ts +99 -0
- package/dist/sim/eval.js +644 -0
- package/dist/sim/eval.js.map +1 -0
- package/dist/sim/exec.d.ts +212 -0
- package/dist/sim/exec.js +874 -0
- package/dist/sim/exec.js.map +1 -0
- package/dist/sim/fold.d.ts +2 -0
- package/dist/sim/fold.js +40 -0
- package/dist/sim/fold.js.map +1 -0
- package/dist/sim/goblock.d.ts +16 -0
- package/dist/sim/goblock.js +171 -0
- package/dist/sim/goblock.js.map +1 -0
- package/dist/sim/guardIndices.d.ts +13 -0
- package/dist/sim/guardIndices.js +137 -0
- package/dist/sim/guardIndices.js.map +1 -0
- package/dist/sim/index.d.ts +43 -0
- package/dist/sim/index.js +138 -0
- package/dist/sim/index.js.map +1 -0
- package/dist/sim/lower.d.ts +33 -0
- package/dist/sim/lower.js +716 -0
- package/dist/sim/lower.js.map +1 -0
- package/dist/sim/memory.d.ts +47 -0
- package/dist/sim/memory.js +328 -0
- package/dist/sim/memory.js.map +1 -0
- package/dist/sim/model.d.ts +487 -0
- package/dist/sim/model.js +772 -0
- package/dist/sim/model.js.map +1 -0
- package/dist/sim/passes/abort.d.ts +2 -0
- package/dist/sim/passes/abort.js +269 -0
- package/dist/sim/passes/abort.js.map +1 -0
- package/dist/sim/passes/abortRegion.d.ts +10 -0
- package/dist/sim/passes/abortRegion.js +62 -0
- package/dist/sim/passes/abortRegion.js.map +1 -0
- package/dist/sim/passes/arrayAssignment.d.ts +2 -0
- package/dist/sim/passes/arrayAssignment.js +147 -0
- package/dist/sim/passes/arrayAssignment.js.map +1 -0
- package/dist/sim/passes/codeEffects.d.ts +2 -0
- package/dist/sim/passes/codeEffects.js +14 -0
- package/dist/sim/passes/codeEffects.js.map +1 -0
- package/dist/sim/passes/complexFinalState.d.ts +4 -0
- package/dist/sim/passes/complexFinalState.js +77 -0
- package/dist/sim/passes/complexFinalState.js.map +1 -0
- package/dist/sim/passes/connector.d.ts +2 -0
- package/dist/sim/passes/connector.js +18 -0
- package/dist/sim/passes/connector.js.map +1 -0
- package/dist/sim/passes/contained.d.ts +37 -0
- package/dist/sim/passes/contained.js +198 -0
- package/dist/sim/passes/contained.js.map +1 -0
- package/dist/sim/passes/context.d.ts +39 -0
- package/dist/sim/passes/context.js +3 -0
- package/dist/sim/passes/context.js.map +1 -0
- package/dist/sim/passes/countDelay.d.ts +2 -0
- package/dist/sim/passes/countDelay.js +51 -0
- package/dist/sim/passes/countDelay.js.map +1 -0
- package/dist/sim/passes/dataflow.d.ts +11 -0
- package/dist/sim/passes/dataflow.js +319 -0
- package/dist/sim/passes/dataflow.js.map +1 -0
- package/dist/sim/passes/deferred.d.ts +2 -0
- package/dist/sim/passes/deferred.js +345 -0
- package/dist/sim/passes/deferred.js.map +1 -0
- package/dist/sim/passes/detect.d.ts +10 -0
- package/dist/sim/passes/detect.js +33 -0
- package/dist/sim/passes/detect.js.map +1 -0
- package/dist/sim/passes/during.d.ts +2 -0
- package/dist/sim/passes/during.js +67 -0
- package/dist/sim/passes/during.js.map +1 -0
- package/dist/sim/passes/entry.d.ts +5 -0
- package/dist/sim/passes/entry.js +93 -0
- package/dist/sim/passes/entry.js.map +1 -0
- package/dist/sim/passes/enum.d.ts +2 -0
- package/dist/sim/passes/enum.js +22 -0
- package/dist/sim/passes/enum.js.map +1 -0
- package/dist/sim/passes/exit.d.ts +4 -0
- package/dist/sim/passes/exit.js +120 -0
- package/dist/sim/passes/exit.js.map +1 -0
- package/dist/sim/passes/finalRegion.d.ts +2 -0
- package/dist/sim/passes/finalRegion.js +21 -0
- package/dist/sim/passes/finalRegion.js.map +1 -0
- package/dist/sim/passes/followedBy.d.ts +2 -0
- package/dist/sim/passes/followedBy.js +78 -0
- package/dist/sim/passes/followedBy.js.map +1 -0
- package/dist/sim/passes/forRegion.d.ts +9 -0
- package/dist/sim/passes/forRegion.js +230 -0
- package/dist/sim/passes/forRegion.js.map +1 -0
- package/dist/sim/passes/history.d.ts +12 -0
- package/dist/sim/passes/history.js +115 -0
- package/dist/sim/passes/history.js.map +1 -0
- package/dist/sim/passes/hostCode.d.ts +2 -0
- package/dist/sim/passes/hostCode.js +152 -0
- package/dist/sim/passes/hostCode.js.map +1 -0
- package/dist/sim/passes/index.d.ts +4 -0
- package/dist/sim/passes/index.js +84 -0
- package/dist/sim/passes/index.js.map +1 -0
- package/dist/sim/passes/inheritance.d.ts +8 -0
- package/dist/sim/passes/inheritance.js +233 -0
- package/dist/sim/passes/inheritance.js.map +1 -0
- package/dist/sim/passes/initOperator.d.ts +2 -0
- package/dist/sim/passes/initOperator.js +68 -0
- package/dist/sim/passes/initOperator.js.map +1 -0
- package/dist/sim/passes/initialization.d.ts +2 -0
- package/dist/sim/passes/initialization.js +69 -0
- package/dist/sim/passes/initialization.js.map +1 -0
- package/dist/sim/passes/ode.d.ts +2 -0
- package/dist/sim/passes/ode.js +14 -0
- package/dist/sim/passes/ode.js.map +1 -0
- package/dist/sim/passes/period.d.ts +2 -0
- package/dist/sim/passes/period.js +106 -0
- package/dist/sim/passes/period.js.map +1 -0
- package/dist/sim/passes/prTransitions.d.ts +2 -0
- package/dist/sim/passes/prTransitions.js +12 -0
- package/dist/sim/passes/prTransitions.js.map +1 -0
- package/dist/sim/passes/pre.d.ts +4 -0
- package/dist/sim/passes/pre.js +326 -0
- package/dist/sim/passes/pre.js.map +1 -0
- package/dist/sim/passes/quirks.d.ts +2 -0
- package/dist/sim/passes/quirks.js +169 -0
- package/dist/sim/passes/quirks.js.map +1 -0
- package/dist/sim/passes/reference.d.ts +60 -0
- package/dist/sim/passes/reference.js +386 -0
- package/dist/sim/passes/reference.js.map +1 -0
- package/dist/sim/passes/regionActions.d.ts +2 -0
- package/dist/sim/passes/regionActions.js +56 -0
- package/dist/sim/passes/regionActions.js.map +1 -0
- package/dist/sim/passes/sequentialFollowedBy.d.ts +2 -0
- package/dist/sim/passes/sequentialFollowedBy.js +72 -0
- package/dist/sim/passes/sequentialFollowedBy.js.map +1 -0
- package/dist/sim/passes/signal.d.ts +2 -0
- package/dist/sim/passes/signal.js +230 -0
- package/dist/sim/passes/signal.js.map +1 -0
- package/dist/sim/passes/static.d.ts +5 -0
- package/dist/sim/passes/static.js +67 -0
- package/dist/sim/passes/static.js.map +1 -0
- package/dist/sim/passes/suspend.d.ts +10 -0
- package/dist/sim/passes/suspend.js +71 -0
- package/dist/sim/passes/suspend.js.map +1 -0
- package/dist/sim/passes/termination.d.ts +9 -0
- package/dist/sim/passes/termination.js +69 -0
- package/dist/sim/passes/termination.js.map +1 -0
- package/dist/sim/passes/timedAutomata.d.ts +10 -0
- package/dist/sim/passes/timedAutomata.js +437 -0
- package/dist/sim/passes/timedAutomata.js.map +1 -0
- package/dist/sim/passes/unpackClasses.d.ts +2 -0
- package/dist/sim/passes/unpackClasses.js +54 -0
- package/dist/sim/passes/unpackClasses.js.map +1 -0
- package/dist/sim/passes/userSchedule.d.ts +2 -0
- package/dist/sim/passes/userSchedule.js +43 -0
- package/dist/sim/passes/userSchedule.js.map +1 -0
- package/dist/sim/passes/weakSuspend.d.ts +2 -0
- package/dist/sim/passes/weakSuspend.js +145 -0
- package/dist/sim/passes/weakSuspend.js.map +1 -0
- package/dist/sim/preemptionLog.d.ts +41 -0
- package/dist/sim/preemptionLog.js +133 -0
- package/dist/sim/preemptionLog.js.map +1 -0
- package/dist/sim/random.d.ts +12 -0
- package/dist/sim/random.js +40 -0
- package/dist/sim/random.js.map +1 -0
- package/dist/sim/reasons.d.ts +29 -0
- package/dist/sim/reasons.js +168 -0
- package/dist/sim/reasons.js.map +1 -0
- package/dist/sim/scg.d.ts +124 -0
- package/dist/sim/scg.js +723 -0
- package/dist/sim/scg.js.map +1 -0
- package/dist/sim/sfr.d.ts +4 -0
- package/dist/sim/sfr.js +264 -0
- package/dist/sim/sfr.js.map +1 -0
- package/dist/sim/stringConditions.d.ts +3 -0
- package/dist/sim/stringConditions.js +42 -0
- package/dist/sim/stringConditions.js.map +1 -0
- package/dist/sim/structure/copy.d.ts +4 -0
- package/dist/sim/structure/copy.js +140 -0
- package/dist/sim/structure/copy.js.map +1 -0
- package/dist/sim/structure/delays.d.ts +30 -0
- package/dist/sim/structure/delays.js +127 -0
- package/dist/sim/structure/delays.js.map +1 -0
- package/dist/sim/structure/instance.d.ts +15 -0
- package/dist/sim/structure/instance.js +69 -0
- package/dist/sim/structure/instance.js.map +1 -0
- package/dist/sim/structure/methods.d.ts +19 -0
- package/dist/sim/structure/methods.js +550 -0
- package/dist/sim/structure/methods.js.map +1 -0
- package/dist/sim/structure/rewrite.d.ts +20 -0
- package/dist/sim/structure/rewrite.js +113 -0
- package/dist/sim/structure/rewrite.js.map +1 -0
- package/dist/sim/structure/track.d.ts +22 -0
- package/dist/sim/structure/track.js +123 -0
- package/dist/sim/structure/track.js.map +1 -0
- package/dist/sim/tracker.d.ts +77 -0
- package/dist/sim/tracker.js +265 -0
- package/dist/sim/tracker.js.map +1 -0
- package/dist/sim/values.d.ts +31 -0
- package/dist/sim/values.js +103 -0
- package/dist/sim/values.js.map +1 -0
- package/dist/types.d.ts +670 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/package.json +58 -3
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { CompiledChart } from "../sim/compile.js";
|
|
2
|
+
import { type CEffect, type CExpr, type CStmt, type CVar } from "../sim/model.js";
|
|
3
|
+
import type { CVariable } from "./types.js";
|
|
4
|
+
export interface Slot {
|
|
5
|
+
v: CVar;
|
|
6
|
+
/** The member of the struct (`count`, `_Chart_local_x`, `home.count`). */
|
|
7
|
+
member: string;
|
|
8
|
+
}
|
|
9
|
+
/** The C type of a variable (one element). */
|
|
10
|
+
export declare function ctypeOf(v: CVar): string;
|
|
11
|
+
export declare function simpleType(v: CVar): CVariable['type'];
|
|
12
|
+
export declare const dimsOf: (v: CVar) => number[];
|
|
13
|
+
export declare class Layout {
|
|
14
|
+
readonly compiled: CompiledChart;
|
|
15
|
+
readonly chartName: string;
|
|
16
|
+
readonly slots: Map<CVar, Slot>;
|
|
17
|
+
/** Struct members in order: the declaration lines (without indentation). */
|
|
18
|
+
readonly lines: string[];
|
|
19
|
+
/** `typedef struct { ... } <name>;` of the chart's classes and structs, before TickData. */
|
|
20
|
+
readonly typedefs: string[];
|
|
21
|
+
readonly variables: CVariable[];
|
|
22
|
+
/** Instances of classes, structs and charts used as classes (KIELER's data pool reports each as an object). */
|
|
23
|
+
readonly instances: {
|
|
24
|
+
name: string;
|
|
25
|
+
member: string;
|
|
26
|
+
ctype: string;
|
|
27
|
+
pool?: string;
|
|
28
|
+
}[];
|
|
29
|
+
private readonly used;
|
|
30
|
+
private readonly maxSuffix;
|
|
31
|
+
/**
|
|
32
|
+
* `declarationOf`: the source declaration of a variable, so that instances declared together share a line
|
|
33
|
+
* (`Counter home, away;`).
|
|
34
|
+
*/
|
|
35
|
+
constructor(compiled: CompiledChart, chartName: string, takenCount: number | undefined, extra: CVar[], declarationOf?: (v: CVar) => object | undefined);
|
|
36
|
+
/** An instance of a chart used as a class: `<Chart>_<Referenced>1 c;` (KIELER's naming) with the chart's fields. */
|
|
37
|
+
private chartInstance;
|
|
38
|
+
/** Reserves a member name (KIELER's UniqueNameCache: `x`, then `x1`, `x2`, ...). */
|
|
39
|
+
unique(base: string): string;
|
|
40
|
+
/** The C lvalue of a variable (`d->x`), or undefined for one the struct does not have. */
|
|
41
|
+
member(v: CVar): string | undefined;
|
|
42
|
+
private plain;
|
|
43
|
+
/** The members of a class or struct instance: `<instance>.<member>`. */
|
|
44
|
+
private instance;
|
|
45
|
+
/** The typedef of an instance's class (`<Chart>_<Class>`), declared once per class. */
|
|
46
|
+
private classType;
|
|
47
|
+
}
|
|
48
|
+
/** Every variable the code refers to (to give the frames of inlined methods a place in the struct). */
|
|
49
|
+
export declare function referencedVars(nodes: {
|
|
50
|
+
effect?: CEffect;
|
|
51
|
+
expr?: CExpr;
|
|
52
|
+
}[], bodies: CStmt[][]): CVar[];
|
|
53
|
+
/** Every variable the code reads (an assignment's target only through its indices, or with a compound operator). */
|
|
54
|
+
export declare function readVars(nodes: {
|
|
55
|
+
effect?: CEffect;
|
|
56
|
+
expr?: CExpr;
|
|
57
|
+
}[], bodies: CStmt[][]): Set<CVar>;
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
// The TickData struct: which C member holds which variable, in KIELER's order (CCodeGeneratorStructModule).
|
|
2
|
+
//
|
|
3
|
+
// KIELER keeps every variable of the chart in one struct: the chart's own top-level declarations in the order written
|
|
4
|
+
// (its Signal processor declares signals anew at the end, after the simulation's `_taken_transitions`), then what the
|
|
5
|
+
// transformations generate, then the locals of inner states, which its Valued Object Rise moves to the top as
|
|
6
|
+
// `_<Chart>_local_<name>` (made unique with a number), then the netlist's guards. sim/memory.ts relies on the same
|
|
7
|
+
// order for indices outside an array, so the C code reads and writes the same neighbours as the simulator.
|
|
8
|
+
import { allScopes, walkExpr } from "../sim/model.js";
|
|
9
|
+
/** C's keywords (KIELER rejects charts using them: sim/codegen.ts). A member `d` is fine: `d->d`. */
|
|
10
|
+
const RESERVED = new Set(['auto', 'break', 'case', 'char', 'const', 'continue', 'default', 'do', 'double', 'else', 'enum',
|
|
11
|
+
'extern', 'float', 'for', 'goto', 'if', 'int', 'long', 'register', 'return', 'short', 'signed', 'sizeof', 'static',
|
|
12
|
+
'struct', 'switch', 'typedef', 'union', 'unsigned', 'void', 'volatile', 'while', 'inline', 'restrict', 'bool']);
|
|
13
|
+
/** The C type of a variable (one element). */
|
|
14
|
+
export function ctypeOf(v) {
|
|
15
|
+
switch (v.type) {
|
|
16
|
+
case 'bool':
|
|
17
|
+
case 'pure': return 'char';
|
|
18
|
+
case 'int': return 'int';
|
|
19
|
+
case 'float':
|
|
20
|
+
case 'clock':
|
|
21
|
+
case 'clock-time': return 'double';
|
|
22
|
+
case 'string': return 'char*';
|
|
23
|
+
default: return v.hostType || 'int';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export function simpleType(v) {
|
|
27
|
+
switch (v.type) {
|
|
28
|
+
case 'bool':
|
|
29
|
+
case 'pure': return 'bool';
|
|
30
|
+
case 'int': return 'int';
|
|
31
|
+
case 'float':
|
|
32
|
+
case 'clock':
|
|
33
|
+
case 'clock-time': return 'float';
|
|
34
|
+
case 'string': return 'string';
|
|
35
|
+
default: return v.hostType ? 'host' : 'int';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export const dimsOf = (v) => v.dims.map(d => (d.k === 'lit' && typeof d.v === 'number' ? d.v : 0));
|
|
39
|
+
/** A C identifier made of the name (generated names are KIELER's already; this only guards against odd ones). */
|
|
40
|
+
function identifier(name) {
|
|
41
|
+
const s = name.replace(/[^A-Za-z0-9_]/g, '_');
|
|
42
|
+
return /^[0-9]/.test(s) ? `_${s}` : s;
|
|
43
|
+
}
|
|
44
|
+
export class Layout {
|
|
45
|
+
compiled;
|
|
46
|
+
chartName;
|
|
47
|
+
slots = new Map();
|
|
48
|
+
/** Struct members in order: the declaration lines (without indentation). */
|
|
49
|
+
lines = [];
|
|
50
|
+
/** `typedef struct { ... } <name>;` of the chart's classes and structs, before TickData. */
|
|
51
|
+
typedefs = [];
|
|
52
|
+
variables = [];
|
|
53
|
+
/** Instances of classes, structs and charts used as classes (KIELER's data pool reports each as an object). */
|
|
54
|
+
instances = [];
|
|
55
|
+
used = new Set();
|
|
56
|
+
maxSuffix = new Map();
|
|
57
|
+
/**
|
|
58
|
+
* `declarationOf`: the source declaration of a variable, so that instances declared together share a line
|
|
59
|
+
* (`Counter home, away;`).
|
|
60
|
+
*/
|
|
61
|
+
constructor(compiled, chartName, takenCount, extra, declarationOf = () => undefined) {
|
|
62
|
+
this.compiled = compiled;
|
|
63
|
+
this.chartName = chartName;
|
|
64
|
+
const core = compiled.core;
|
|
65
|
+
const rootDecls = core.decls;
|
|
66
|
+
// The leading source declarations (not signals): `_taken_transitions` comes right after them (memory.ts).
|
|
67
|
+
let taken = takenCount !== undefined;
|
|
68
|
+
const placeTaken = () => {
|
|
69
|
+
if (!taken)
|
|
70
|
+
return;
|
|
71
|
+
taken = false;
|
|
72
|
+
this.lines.push(`int _taken_transitions[${Math.max(1, takenCount)}];`);
|
|
73
|
+
this.used.add('_taken_transitions');
|
|
74
|
+
};
|
|
75
|
+
const classes = new Map();
|
|
76
|
+
// Charts used as classes and `ref C g(...)` instances (passes/reference.ts): their fields are variables whose
|
|
77
|
+
// instance is no declaration any more; one without fields is known by name only.
|
|
78
|
+
const rootSet = new Set(rootDecls);
|
|
79
|
+
const empty = new Set(core.ext.emptyInstances ?? []);
|
|
80
|
+
const chartInstanceOf = (v) => {
|
|
81
|
+
if (v.member && !rootSet.has(v.member.of))
|
|
82
|
+
return v.member.of.name;
|
|
83
|
+
const at = v.decl?.indexOf('$') ?? -1;
|
|
84
|
+
const slash = v.decl?.indexOf('/', at) ?? -1;
|
|
85
|
+
const inst = at >= 0 && slash > at ? v.decl.slice(at + 1, slash) : undefined;
|
|
86
|
+
return inst !== undefined && empty.has(inst) ? inst : undefined;
|
|
87
|
+
};
|
|
88
|
+
const placed = new Set();
|
|
89
|
+
for (let i = 0; i < rootDecls.length; i++) {
|
|
90
|
+
const v = rootDecls[i];
|
|
91
|
+
const inst = chartInstanceOf(v);
|
|
92
|
+
if (inst !== undefined) {
|
|
93
|
+
if (!placed.has(inst)) {
|
|
94
|
+
placed.add(inst);
|
|
95
|
+
this.chartInstance(inst, rootDecls, classes);
|
|
96
|
+
}
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (v.const || v.extern || v.declKind === 'method' || v.declKind === 'enum' || v.member)
|
|
100
|
+
continue;
|
|
101
|
+
if (v.generated || v.role === 'presence' || v.role === 'value' || v.role === 'curval')
|
|
102
|
+
placeTaken();
|
|
103
|
+
if (v.declKind === 'class' || v.declKind === 'struct') {
|
|
104
|
+
if (this.slots.has(v))
|
|
105
|
+
continue;
|
|
106
|
+
// Instances of one declaration share a line, as KIELER declares them (`Counter home, away;`).
|
|
107
|
+
const type = this.classType(v, rootDecls, classes);
|
|
108
|
+
const decl = declarationOf(v);
|
|
109
|
+
const group = [v, ...(decl ? rootDecls.slice(i + 1).filter(w => w.declKind === v.declKind && declarationOf(w) === decl) : [])];
|
|
110
|
+
const names = group.map(w => {
|
|
111
|
+
const n = this.unique(identifier(w.name));
|
|
112
|
+
this.instance(w, n, rootDecls);
|
|
113
|
+
this.instances.push({ name: w.name, member: n, ctype: type });
|
|
114
|
+
return n;
|
|
115
|
+
});
|
|
116
|
+
this.lines.push(`${type} ${names.join(', ')};`);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (v.declKind)
|
|
120
|
+
continue;
|
|
121
|
+
this.plain(v, this.unique(identifier(v.name)), true);
|
|
122
|
+
}
|
|
123
|
+
placeTaken();
|
|
124
|
+
// Inner states' and regions' locals (KIELER's Valued Object Rise), then what only the code refers to (the frames
|
|
125
|
+
// of inlined methods).
|
|
126
|
+
for (const scope of allScopes(core).slice(1)) {
|
|
127
|
+
for (const v of scope.decls) {
|
|
128
|
+
if (this.slots.has(v) || v.const || v.extern || v.declKind === 'method' || v.declKind === 'enum')
|
|
129
|
+
continue;
|
|
130
|
+
if (v.member)
|
|
131
|
+
continue;
|
|
132
|
+
const name = this.unique(`_${chartName}_local_${identifier(v.name)}`);
|
|
133
|
+
if (v.declKind === 'class' || v.declKind === 'struct') {
|
|
134
|
+
const type = this.classType(v, scope.decls, classes);
|
|
135
|
+
this.instance(v, name, scope.decls);
|
|
136
|
+
this.lines.push(`${type} ${name};`);
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (v.declKind)
|
|
140
|
+
continue;
|
|
141
|
+
this.plain(v, name, false);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
for (const inst of empty)
|
|
145
|
+
if (!placed.has(inst))
|
|
146
|
+
this.chartInstance(inst, rootDecls, classes);
|
|
147
|
+
for (const v of extra)
|
|
148
|
+
if (!this.slots.has(v) && !v.declKind)
|
|
149
|
+
this.plain(v, this.unique(identifier(v.name)), false);
|
|
150
|
+
}
|
|
151
|
+
/** An instance of a chart used as a class: `<Chart>_<Referenced>1 c;` (KIELER's naming) with the chart's fields. */
|
|
152
|
+
chartInstance(inst, decls, classes) {
|
|
153
|
+
const members = decls.filter(m => m.member?.of.name === inst && !m.declKind);
|
|
154
|
+
// Ids inside the instance are `<Chart>$<instance>/<Referenced chart>[/<Base>]$<name>`.
|
|
155
|
+
const id = decls.map(m => m.decl ?? '').find(d => d.includes(`$${inst}/`)) ?? '';
|
|
156
|
+
const rest = id.slice(id.indexOf(`$${inst}/`) + inst.length + 2);
|
|
157
|
+
const chart = rest ? rest.split(/[/$]/)[0] : inst;
|
|
158
|
+
const fields = members.map(m => `${ctypeOf(m)} ${identifier(m.member.name)}${dimsOf(m).map(n => `[${n}]`).join('')};`);
|
|
159
|
+
const key = `chart ${chart}|${fields.join(' ')}`;
|
|
160
|
+
let type = classes.get(key);
|
|
161
|
+
if (!type) {
|
|
162
|
+
type = this.unique(`${this.chartName}_${identifier(chart)}1`);
|
|
163
|
+
classes.set(key, type);
|
|
164
|
+
this.typedefs.push(`typedef struct {\n${fields.map(f => ` ${f}\n`).join('')}} ${type};\n`);
|
|
165
|
+
}
|
|
166
|
+
const name = this.unique(identifier(inst));
|
|
167
|
+
this.lines.push(`${type} ${name};`);
|
|
168
|
+
this.instances.push({ name: inst, member: name, ctype: type, pool: inst });
|
|
169
|
+
for (const m of members) {
|
|
170
|
+
const member = `${name}.${identifier(m.member.name)}`;
|
|
171
|
+
this.slots.set(m, { v: m, member });
|
|
172
|
+
if (m.tags.has('#const-member'))
|
|
173
|
+
continue;
|
|
174
|
+
this.variables.push({
|
|
175
|
+
name: `${inst}.${m.member.name}`, member, ctype: ctypeOf(m), type: simpleType(m), dims: dimsOf(m),
|
|
176
|
+
input: false, output: false, pool: m.member.name, poolObject: inst,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/** Reserves a member name (KIELER's UniqueNameCache: `x`, then `x1`, `x2`, ...). */
|
|
181
|
+
unique(base) {
|
|
182
|
+
let name = RESERVED.has(base) ? `${base}_` : base;
|
|
183
|
+
if (this.used.has(name)) {
|
|
184
|
+
let n = this.maxSuffix.get(name) ?? 0;
|
|
185
|
+
do
|
|
186
|
+
n++;
|
|
187
|
+
while (this.used.has(name + n));
|
|
188
|
+
this.maxSuffix.set(name, n);
|
|
189
|
+
name = name + n;
|
|
190
|
+
}
|
|
191
|
+
this.used.add(name);
|
|
192
|
+
return name;
|
|
193
|
+
}
|
|
194
|
+
/** The C lvalue of a variable (`d->x`), or undefined for one the struct does not have. */
|
|
195
|
+
member(v) {
|
|
196
|
+
return this.slots.get(v)?.member;
|
|
197
|
+
}
|
|
198
|
+
plain(v, name, root) {
|
|
199
|
+
const dims = dimsOf(v);
|
|
200
|
+
this.slots.set(v, { v, member: name });
|
|
201
|
+
this.lines.push(`${ctypeOf(v)} ${name}${dims.map(n => `[${n}]`).join('')};`);
|
|
202
|
+
// KIELER's data pool: the chart's top-level variables, without its helpers (names starting with `_`).
|
|
203
|
+
const pool = root && !v.name.startsWith('_') ? v.name : undefined;
|
|
204
|
+
if (!pool && (v.generated || !v.decl))
|
|
205
|
+
return;
|
|
206
|
+
this.variables.push({
|
|
207
|
+
name: root ? v.name : v.display ?? v.name, member: name, ctype: ctypeOf(v), type: simpleType(v), dims,
|
|
208
|
+
input: v.input, output: v.output, pool,
|
|
209
|
+
signal: v.role === 'presence' || v.role === 'value' || v.role === 'curval' ? v.role : undefined,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
/** The members of a class or struct instance: `<instance>.<member>`. */
|
|
213
|
+
instance(v, name, decls) {
|
|
214
|
+
this.slots.set(v, { v, member: name });
|
|
215
|
+
for (const m of decls) {
|
|
216
|
+
if (m.member?.of !== v || m.declKind)
|
|
217
|
+
continue;
|
|
218
|
+
const member = `${name}.${identifier(m.member.name)}`;
|
|
219
|
+
this.slots.set(m, { v: m, member });
|
|
220
|
+
if (m.tags.has('#const-member'))
|
|
221
|
+
continue;
|
|
222
|
+
this.variables.push({
|
|
223
|
+
name: `${v.name}.${m.member.name}`, member, ctype: ctypeOf(m), type: simpleType(m), dims: dimsOf(m),
|
|
224
|
+
input: false, output: false, pool: name === v.name ? m.member.name : undefined, poolObject: name === v.name ? v.name : undefined,
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
/** The typedef of an instance's class (`<Chart>_<Class>`), declared once per class. */
|
|
229
|
+
classType(v, decls, classes) {
|
|
230
|
+
if (v.tags.has('#host') && v.hostType)
|
|
231
|
+
return v.hostType;
|
|
232
|
+
const members = decls.filter(m => m.member?.of === v && !m.declKind);
|
|
233
|
+
// The class's name: the member declarations' ids are `<Chart>$<Class>.<member>`.
|
|
234
|
+
const id = members[0]?.decl ?? v.decl ?? v.name;
|
|
235
|
+
const cls = /\$([^.$]+)\.[^.]*$/.exec(id)?.[1] ?? v.name;
|
|
236
|
+
const key = `${cls}|${members.map(m => `${ctypeOf(m)} ${m.member.name}${dimsOf(m).map(n => `[${n}]`).join('')}`).join(';')}`;
|
|
237
|
+
let type = classes.get(key);
|
|
238
|
+
if (!type) {
|
|
239
|
+
type = this.unique(`${this.chartName}_${identifier(cls)}`);
|
|
240
|
+
classes.set(key, type);
|
|
241
|
+
const body = members.map(m => ` ${ctypeOf(m)} ${identifier(m.member.name)}${dimsOf(m).map(n => `[${n}]`).join('')};`);
|
|
242
|
+
this.typedefs.push(`typedef struct {\n${body.map(b => `${b}\n`).join('')}} ${type};\n`);
|
|
243
|
+
}
|
|
244
|
+
return type;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
/** Every variable the code refers to (to give the frames of inlined methods a place in the struct). */
|
|
248
|
+
export function referencedVars(nodes, bodies) {
|
|
249
|
+
return [...accessed(nodes, bodies, true)];
|
|
250
|
+
}
|
|
251
|
+
/** Every variable the code reads (an assignment's target only through its indices, or with a compound operator). */
|
|
252
|
+
export function readVars(nodes, bodies) {
|
|
253
|
+
return accessed(nodes, bodies, false);
|
|
254
|
+
}
|
|
255
|
+
function accessed(nodes, bodies, targets) {
|
|
256
|
+
const out = new Set();
|
|
257
|
+
const visit = (e) => { if (e.k === 'ref')
|
|
258
|
+
out.add(e.v); };
|
|
259
|
+
const effect = (f) => {
|
|
260
|
+
if (f.k === 'assign') {
|
|
261
|
+
if (targets || f.op !== '=')
|
|
262
|
+
walkExpr(f.ref, visit);
|
|
263
|
+
else
|
|
264
|
+
f.ref.idx.forEach(i => walkExpr(i, visit));
|
|
265
|
+
walkExpr(f.expr, visit);
|
|
266
|
+
}
|
|
267
|
+
else if (f.k === 'print')
|
|
268
|
+
f.args.forEach(a => walkExpr(a, visit));
|
|
269
|
+
else if (f.k === 'call')
|
|
270
|
+
walkExpr(f.call, visit);
|
|
271
|
+
};
|
|
272
|
+
for (const n of nodes) {
|
|
273
|
+
if (n.effect)
|
|
274
|
+
effect(n.effect);
|
|
275
|
+
walkExpr(n.expr, visit);
|
|
276
|
+
}
|
|
277
|
+
const stmts = (list) => {
|
|
278
|
+
for (const s of list) {
|
|
279
|
+
if (s.k === 'do')
|
|
280
|
+
effect(s.f);
|
|
281
|
+
else if (s.k === 'if') {
|
|
282
|
+
walkExpr(s.cond, visit);
|
|
283
|
+
stmts(s.then);
|
|
284
|
+
if (s.else)
|
|
285
|
+
stmts(s.else);
|
|
286
|
+
}
|
|
287
|
+
else if (s.k === 'while') {
|
|
288
|
+
walkExpr(s.cond, visit);
|
|
289
|
+
stmts(s.body);
|
|
290
|
+
}
|
|
291
|
+
else if (s.k === 'for') {
|
|
292
|
+
stmts(s.init);
|
|
293
|
+
walkExpr(s.cond, visit);
|
|
294
|
+
stmts(s.update);
|
|
295
|
+
stmts(s.body);
|
|
296
|
+
}
|
|
297
|
+
else if (s.k === 'return')
|
|
298
|
+
walkExpr(s.expr, visit);
|
|
299
|
+
else if (s.k === 'expr')
|
|
300
|
+
walkExpr(s.e, visit);
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
bodies.forEach(stmts);
|
|
304
|
+
return out;
|
|
305
|
+
}
|
|
306
|
+
//# sourceMappingURL=layout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layout.js","sourceRoot":"","sources":["../../src/codegen/layout.ts"],"names":[],"mappings":"AAAA,4GAA4G;AAC5G,EAAE;AACF,sHAAsH;AACtH,sHAAsH;AACtH,8GAA8G;AAC9G,mHAAmH;AACnH,2GAA2G;AAG3G,OAAO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AAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;gBAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;gBAAC,IAAI,CAAC,CAAC,IAAI;oBAAE,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;YAAC,CAAC;iBACvF,IAAI,CAAC,CAAC,CAAC,KAAK,OAAO,EAAE,CAAC;gBAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;gBAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;YAAC,CAAC;iBAC/D,IAAI,CAAC,CAAC,CAAC,KAAK,KAAK,EAAE,CAAC;gBAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;gBAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;gBAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;gBAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;YAAC,CAAC;iBAC7F,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ;gBAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;iBAC7C,IAAI,CAAC,CAAC,CAAC,KAAK,MAAM;gBAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAA;QACjD,CAAC;IACL,CAAC,CAAA;IACD,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IACrB,OAAO,GAAG,CAAA;AACd,CAAC","sourcesContent":["// The TickData struct: which C member holds which variable, in KIELER's order (CCodeGeneratorStructModule).\n//\n// KIELER keeps every variable of the chart in one struct: the chart's own top-level declarations in the order written\n// (its Signal processor declares signals anew at the end, after the simulation's `_taken_transitions`), then what the\n// transformations generate, then the locals of inner states, which its Valued Object Rise moves to the top as\n// `_<Chart>_local_<name>` (made unique with a number), then the netlist's guards. sim/memory.ts relies on the same\n// order for indices outside an array, so the C code reads and writes the same neighbours as the simulator.\n\nimport type { CompiledChart } from '../sim/compile'\nimport { allScopes, walkExpr, type CEffect, type CExpr, type CStmt, type CVar } from '../sim/model'\nimport type { CVariable } from './types'\n\nexport interface Slot {\n v: CVar\n /** The member of the struct (`count`, `_Chart_local_x`, `home.count`). */\n member: string\n}\n\n/** C's keywords (KIELER rejects charts using them: sim/codegen.ts). A member `d` is fine: `d->d`. */\nconst RESERVED = new Set(['auto', 'break', 'case', 'char', 'const', 'continue', 'default', 'do', 'double', 'else', 'enum',\n 'extern', 'float', 'for', 'goto', 'if', 'int', 'long', 'register', 'return', 'short', 'signed', 'sizeof', 'static',\n 'struct', 'switch', 'typedef', 'union', 'unsigned', 'void', 'volatile', 'while', 'inline', 'restrict', 'bool'])\n\n/** The C type of a variable (one element). */\nexport function ctypeOf(v: CVar): string {\n switch (v.type) {\n case 'bool': case 'pure': return 'char'\n case 'int': return 'int'\n case 'float': case 'clock': case 'clock-time': return 'double'\n case 'string': return 'char*'\n default: return v.hostType || 'int'\n }\n}\n\nexport function simpleType(v: CVar): CVariable['type'] {\n switch (v.type) {\n case 'bool': case 'pure': return 'bool'\n case 'int': return 'int'\n case 'float': case 'clock': case 'clock-time': return 'float'\n case 'string': return 'string'\n default: return v.hostType ? 'host' : 'int'\n }\n}\n\nexport const dimsOf = (v: CVar): number[] => v.dims.map(d => (d.k === 'lit' && typeof d.v === 'number' ? d.v : 0))\n\n/** A C identifier made of the name (generated names are KIELER's already; this only guards against odd ones). */\nfunction identifier(name: string): string {\n const s = name.replace(/[^A-Za-z0-9_]/g, '_')\n return /^[0-9]/.test(s) ? `_${s}` : s\n}\n\nexport class Layout {\n readonly slots = new Map<CVar, Slot>()\n /** Struct members in order: the declaration lines (without indentation). */\n readonly lines: string[] = []\n /** `typedef struct { ... } <name>;` of the chart's classes and structs, before TickData. */\n readonly typedefs: string[] = []\n readonly variables: CVariable[] = []\n /** Instances of classes, structs and charts used as classes (KIELER's data pool reports each as an object). */\n readonly instances: { name: string; member: string; ctype: string; pool?: string }[] = []\n private readonly used = new Set<string>()\n private readonly maxSuffix = new Map<string, number>()\n\n /**\n * `declarationOf`: the source declaration of a variable, so that instances declared together share a line\n * (`Counter home, away;`).\n */\n constructor(readonly compiled: CompiledChart, readonly chartName: string, takenCount: number | undefined, extra: CVar[], declarationOf: (v: CVar) => object | undefined = () => undefined) {\n const core = compiled.core\n const rootDecls = core.decls\n // The leading source declarations (not signals): `_taken_transitions` comes right after them (memory.ts).\n let taken = takenCount !== undefined\n const placeTaken = () => {\n if (!taken) return\n taken = false\n this.lines.push(`int _taken_transitions[${Math.max(1, takenCount!)}];`)\n this.used.add('_taken_transitions')\n }\n const classes = new Map<string, string>()\n // Charts used as classes and `ref C g(...)` instances (passes/reference.ts): their fields are variables whose\n // instance is no declaration any more; one without fields is known by name only.\n const rootSet = new Set(rootDecls)\n const empty = new Set((core.ext.emptyInstances as string[] | undefined) ?? [])\n const chartInstanceOf = (v: CVar): string | undefined => {\n if (v.member && !rootSet.has(v.member.of)) return v.member.of.name\n const at = v.decl?.indexOf('$') ?? -1\n const slash = v.decl?.indexOf('/', at) ?? -1\n const inst = at >= 0 && slash > at ? v.decl!.slice(at + 1, slash) : undefined\n return inst !== undefined && empty.has(inst) ? inst : undefined\n }\n const placed = new Set<string>()\n for (let i = 0; i < rootDecls.length; i++) {\n const v = rootDecls[i]\n const inst = chartInstanceOf(v)\n if (inst !== undefined) {\n if (!placed.has(inst)) {\n placed.add(inst)\n this.chartInstance(inst, rootDecls, classes)\n }\n continue\n }\n if (v.const || v.extern || v.declKind === 'method' || v.declKind === 'enum' || v.member) continue\n if (v.generated || v.role === 'presence' || v.role === 'value' || v.role === 'curval') placeTaken()\n if (v.declKind === 'class' || v.declKind === 'struct') {\n if (this.slots.has(v)) continue\n // Instances of one declaration share a line, as KIELER declares them (`Counter home, away;`).\n const type = this.classType(v, rootDecls, classes)\n const decl = declarationOf(v)\n const group = [v, ...(decl ? rootDecls.slice(i + 1).filter(w => w.declKind === v.declKind && declarationOf(w) === decl) : [])]\n const names = group.map(w => {\n const n = this.unique(identifier(w.name))\n this.instance(w, n, rootDecls)\n this.instances.push({ name: w.name, member: n, ctype: type })\n return n\n })\n this.lines.push(`${type} ${names.join(', ')};`)\n continue\n }\n if (v.declKind) continue\n this.plain(v, this.unique(identifier(v.name)), true)\n }\n placeTaken()\n // Inner states' and regions' locals (KIELER's Valued Object Rise), then what only the code refers to (the frames\n // of inlined methods).\n for (const scope of allScopes(core).slice(1)) {\n for (const v of scope.decls) {\n if (this.slots.has(v) || v.const || v.extern || v.declKind === 'method' || v.declKind === 'enum') continue\n if (v.member) continue\n const name = this.unique(`_${chartName}_local_${identifier(v.name)}`)\n if (v.declKind === 'class' || v.declKind === 'struct') {\n const type = this.classType(v, scope.decls, classes)\n this.instance(v, name, scope.decls)\n this.lines.push(`${type} ${name};`)\n continue\n }\n if (v.declKind) continue\n this.plain(v, name, false)\n }\n }\n for (const inst of empty) if (!placed.has(inst)) this.chartInstance(inst, rootDecls, classes)\n for (const v of extra) if (!this.slots.has(v) && !v.declKind) this.plain(v, this.unique(identifier(v.name)), false)\n }\n\n /** An instance of a chart used as a class: `<Chart>_<Referenced>1 c;` (KIELER's naming) with the chart's fields. */\n private chartInstance(inst: string, decls: CVar[], classes: Map<string, string>) {\n const members = decls.filter(m => m.member?.of.name === inst && !m.declKind)\n // Ids inside the instance are `<Chart>$<instance>/<Referenced chart>[/<Base>]$<name>`.\n const id = decls.map(m => m.decl ?? '').find(d => d.includes(`$${inst}/`)) ?? ''\n const rest = id.slice(id.indexOf(`$${inst}/`) + inst.length + 2)\n const chart = rest ? rest.split(/[/$]/)[0] : inst\n const fields = members.map(m => `${ctypeOf(m)} ${identifier(m.member!.name)}${dimsOf(m).map(n => `[${n}]`).join('')};`)\n const key = `chart ${chart}|${fields.join(' ')}`\n let type = classes.get(key)\n if (!type) {\n type = this.unique(`${this.chartName}_${identifier(chart)}1`)\n classes.set(key, type)\n this.typedefs.push(`typedef struct {\\n${fields.map(f => ` ${f}\\n`).join('')}} ${type};\\n`)\n }\n const name = this.unique(identifier(inst))\n this.lines.push(`${type} ${name};`)\n this.instances.push({ name: inst, member: name, ctype: type, pool: inst })\n for (const m of members) {\n const member = `${name}.${identifier(m.member!.name)}`\n this.slots.set(m, { v: m, member })\n if (m.tags.has('#const-member')) continue\n this.variables.push({\n name: `${inst}.${m.member!.name}`, member, ctype: ctypeOf(m), type: simpleType(m), dims: dimsOf(m),\n input: false, output: false, pool: m.member!.name, poolObject: inst,\n })\n }\n }\n\n /** Reserves a member name (KIELER's UniqueNameCache: `x`, then `x1`, `x2`, ...). */\n unique(base: string): string {\n let name = RESERVED.has(base) ? `${base}_` : base\n if (this.used.has(name)) {\n let n = this.maxSuffix.get(name) ?? 0\n do n++\n while (this.used.has(name + n))\n this.maxSuffix.set(name, n)\n name = name + n\n }\n this.used.add(name)\n return name\n }\n\n /** The C lvalue of a variable (`d->x`), or undefined for one the struct does not have. */\n member(v: CVar): string | undefined {\n return this.slots.get(v)?.member\n }\n\n private plain(v: CVar, name: string, root: boolean) {\n const dims = dimsOf(v)\n this.slots.set(v, { v, member: name })\n this.lines.push(`${ctypeOf(v)} ${name}${dims.map(n => `[${n}]`).join('')};`)\n // KIELER's data pool: the chart's top-level variables, without its helpers (names starting with `_`).\n const pool = root && !v.name.startsWith('_') ? v.name : undefined\n if (!pool && (v.generated || !v.decl)) return\n this.variables.push({\n name: root ? v.name : v.display ?? v.name, member: name, ctype: ctypeOf(v), type: simpleType(v), dims,\n input: v.input, output: v.output, pool,\n signal: v.role === 'presence' || v.role === 'value' || v.role === 'curval' ? v.role : undefined,\n })\n }\n\n /** The members of a class or struct instance: `<instance>.<member>`. */\n private instance(v: CVar, name: string, decls: CVar[]) {\n this.slots.set(v, { v, member: name })\n for (const m of decls) {\n if (m.member?.of !== v || m.declKind) continue\n const member = `${name}.${identifier(m.member.name)}`\n this.slots.set(m, { v: m, member })\n if (m.tags.has('#const-member')) continue\n this.variables.push({\n name: `${v.name}.${m.member.name}`, member, ctype: ctypeOf(m), type: simpleType(m), dims: dimsOf(m),\n input: false, output: false, pool: name === v.name ? m.member.name : undefined, poolObject: name === v.name ? v.name : undefined,\n })\n }\n }\n\n /** The typedef of an instance's class (`<Chart>_<Class>`), declared once per class. */\n private classType(v: CVar, decls: CVar[], classes: Map<string, string>): string {\n if (v.tags.has('#host') && v.hostType) return v.hostType\n const members = decls.filter(m => m.member?.of === v && !m.declKind)\n // The class's name: the member declarations' ids are `<Chart>$<Class>.<member>`.\n const id = members[0]?.decl ?? v.decl ?? v.name\n const cls = /\\$([^.$]+)\\.[^.]*$/.exec(id)?.[1] ?? v.name\n const key = `${cls}|${members.map(m => `${ctypeOf(m)} ${m.member!.name}${dimsOf(m).map(n => `[${n}]`).join('')}`).join(';')}`\n let type = classes.get(key)\n if (!type) {\n type = this.unique(`${this.chartName}_${identifier(cls)}`)\n classes.set(key, type)\n const body = members.map(m => ` ${ctypeOf(m)} ${identifier(m.member!.name)}${dimsOf(m).map(n => `[${n}]`).join('')};`)\n this.typedefs.push(`typedef struct {\\n${body.map(b => `${b}\\n`).join('')}} ${type};\\n`)\n }\n return type\n }\n}\n\n/** Every variable the code refers to (to give the frames of inlined methods a place in the struct). */\nexport function referencedVars(nodes: { effect?: CEffect; expr?: CExpr }[], bodies: CStmt[][]): CVar[] {\n return [...accessed(nodes, bodies, true)]\n}\n\n/** Every variable the code reads (an assignment's target only through its indices, or with a compound operator). */\nexport function readVars(nodes: { effect?: CEffect; expr?: CExpr }[], bodies: CStmt[][]): Set<CVar> {\n return accessed(nodes, bodies, false)\n}\n\nfunction accessed(nodes: { effect?: CEffect; expr?: CExpr }[], bodies: CStmt[][], targets: boolean): Set<CVar> {\n const out = new Set<CVar>()\n const visit = (e: CExpr) => { if (e.k === 'ref') out.add(e.v) }\n const effect = (f: CEffect) => {\n if (f.k === 'assign') {\n if (targets || f.op !== '=') walkExpr(f.ref, visit)\n else f.ref.idx.forEach(i => walkExpr(i, visit))\n walkExpr(f.expr, visit)\n }\n else if (f.k === 'print') f.args.forEach(a => walkExpr(a, visit))\n else if (f.k === 'call') walkExpr(f.call, visit)\n }\n for (const n of nodes) {\n if (n.effect) effect(n.effect)\n walkExpr(n.expr, visit)\n }\n const stmts = (list: CStmt[]) => {\n for (const s of list) {\n if (s.k === 'do') effect(s.f)\n else if (s.k === 'if') { walkExpr(s.cond, visit); stmts(s.then); if (s.else) stmts(s.else) }\n else if (s.k === 'while') { walkExpr(s.cond, visit); stmts(s.body) }\n else if (s.k === 'for') { stmts(s.init); walkExpr(s.cond, visit); stmts(s.update); stmts(s.body) }\n else if (s.k === 'return') walkExpr(s.expr, visit)\n else if (s.k === 'expr') walkExpr(s.e, visit)\n }\n }\n bodies.forEach(stmts)\n return out\n}\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ExecutableChart } from "../sim/exec.js";
|
|
2
|
+
import type { SNode } from "../sim/scg.js";
|
|
3
|
+
import { type ExprEnv } from "./expr.js";
|
|
4
|
+
/** What the netlist needs to know besides the schedule. */
|
|
5
|
+
export interface LogicInput {
|
|
6
|
+
exe: ExecutableChart;
|
|
7
|
+
env: ExprEnv;
|
|
8
|
+
/** The struct member of a guard name (unique among the chart's variables). */
|
|
9
|
+
name(base: string): string;
|
|
10
|
+
/** Nodes whose effect has no code in logic(): it runs in reset() (KIELER's GO-init, reset.ts), or it initialises a
|
|
11
|
+
* constant (KIELER's Const processor removes them). */
|
|
12
|
+
skip: Set<number>;
|
|
13
|
+
takenTransitions: boolean;
|
|
14
|
+
/** A comment for the node's source transition or action (undefined: none). */
|
|
15
|
+
comment?(n: SNode): string | undefined;
|
|
16
|
+
}
|
|
17
|
+
export interface LogicOutput {
|
|
18
|
+
/** The body of logic(), one statement per line, indented by two spaces per level. */
|
|
19
|
+
lines: string[];
|
|
20
|
+
/** Guard members in KIELER's order: `_g`, then `_GO`, `_cg`, `_TERM`, `_pg`. */
|
|
21
|
+
guards: string[];
|
|
22
|
+
conditions: string[];
|
|
23
|
+
/** Every pause's register and the guard tick() saves into it (none: the pause is never reached). */
|
|
24
|
+
registers: {
|
|
25
|
+
register: string;
|
|
26
|
+
guard?: string;
|
|
27
|
+
}[];
|
|
28
|
+
/** Guards that keep their value from tick to tick (conditions with a conditional without else). */
|
|
29
|
+
persistent: string[];
|
|
30
|
+
}
|
|
31
|
+
export declare function generateLogic(input: LogicInput): LogicOutput;
|