Skip to content

Commit dd64724

Browse files
committed
Add TLCExt!Trace and TLCExt!TraceFrom (CommunityModules) for simulation
mode. [Feature][TLC]
1 parent 4e5f35f commit dd64724

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

modules/tlc2/overrides/TLCExt.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import tlc2.tool.ConcurrentTLCTrace;
4141
import tlc2.tool.EvalException;
4242
import tlc2.tool.ModelChecker;
43+
import tlc2.tool.SimulationWorker;
4344
import tlc2.tool.StateVec;
4445
import tlc2.tool.TLCState;
4546
import tlc2.tool.TLCStateInfo;
@@ -140,8 +141,6 @@ public synchronized static Value pickSuccessor(final Tool tool, final ExprOrOpAr
140141
@Evaluation(definition = "Trace", module = "TLCExt", minLevel = 1, warn = false)
141142
public synchronized static Value getTrace(final Tool tool, final ExprOrOpArgNode[] args, final Context c,
142143
final TLCState s0, final TLCState s1, final int control, final CostModel cm) throws IOException {
143-
final ModelChecker mc = (ModelChecker) TLCGlobals.mainChecker;
144-
final ConcurrentTLCTrace traceFile = mc.trace;
145144

146145
if (!s0.allAssigned()) {
147146
/*
@@ -163,16 +162,23 @@ public synchronized static Value getTrace(final Tool tool, final ExprOrOpArgNode
163162
if (s0.isInitial()) {
164163
return new TupleValue(new Value[] { new RecordValue(s0) });
165164
}
165+
166+
if (TLCGlobals.simulator != null) {
167+
// TODO Somehow load only this implementation in simulation mode => module
168+
// overrides for a specific tool mode.
169+
final SimulationWorker w = (SimulationWorker) Thread.currentThread();
170+
return new TupleValue(w.getTrace().toRecords(s0));
171+
}
172+
final ModelChecker mc = (ModelChecker) TLCGlobals.mainChecker;
173+
final ConcurrentTLCTrace traceFile = mc.trace;
166174

167175
return getTrace0(s0, traceFile.getTrace(s0));
168176
}
169177

170178
@Evaluation(definition = "TraceFrom", module = "TLCExt", minLevel = 1, warn = false)
171179
public synchronized static Value getTraceFrom(final Tool tool, final ExprOrOpArgNode[] args, final Context c,
172180
final TLCState s0, final TLCState s1, final int control, final CostModel cm) throws IOException {
173-
final ModelChecker mc = (ModelChecker) TLCGlobals.mainChecker;
174-
final ConcurrentTLCTrace traceFile = mc.trace;
175-
181+
176182
final Value v = tool.eval(args[0], c, s0, s1, control, cm);
177183
if (!(v instanceof RecordValue)) {
178184
Assert.fail(EC.GENERAL, "In evaluating TLCExt!TraceFrom, a non-record expression (" + v.getKindString()
@@ -185,6 +191,13 @@ public synchronized static Value getTraceFrom(final Tool tool, final ExprOrOpArg
185191
if (s0.isInitial() || from.equals(s0)) {
186192
return new TupleValue(new RecordValue(s0));
187193
}
194+
195+
if (TLCGlobals.simulator != null) {
196+
final SimulationWorker w = (SimulationWorker) Thread.currentThread();
197+
return new TupleValue(w.getTrace().toRecords(from, s0));
198+
}
199+
final ModelChecker mc = (ModelChecker) TLCGlobals.mainChecker;
200+
final ConcurrentTLCTrace traceFile = mc.trace;
188201
return getTrace0(s0, traceFile.getTrace(from, s0));
189202
}
190203

0 commit comments

Comments
 (0)