-
Notifications
You must be signed in to change notification settings - Fork 634
/
Core.cs
806 lines (646 loc) · 29.8 KB
/
Core.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using ProtoCore.AssociativeGraph;
using ProtoCore.AST.AssociativeAST;
using ProtoCore.DSASM;
using ProtoCore.Lang;
using ProtoCore.Utils;
using ProtoFFI;
namespace ProtoCore
{
public enum ExecutionMode
{
Parallel,
Serial
}
/// <summary>
/// Represents a single replication guide entity that is associated with an argument to a function
///
/// Given:
/// a = f(i<1>, j<2L>)
///
/// <1> and <2L> are each represented by a ReplicationGuide instance
///
/// </summary>
public class ReplicationGuide
{
public ReplicationGuide(int guide, bool longest)
{
GuideNumber = guide;
IsLongest = longest;
}
public int GuideNumber { get; private set; }
public bool IsLongest {get; private set;}
}
public class AtLevel
{
public AtLevel(int level, bool isDominant)
{
Level = level;
IsDominant = isDominant;
}
public int Level { get; private set; }
public bool IsDominant { get; private set; }
}
public class Options
{
public Options()
{
// Execute using new graphnode dependency
// When executing direct dependency set the following:
// DirectDependencyExecution = true
// LHSGraphNodeUpdate = false
DirectDependencyExecution = true;
ApplyUpdate = false;
DumpByteCode = false;
Verbose = false;
DumpIL = false;
GenerateSSA = true;
ExecuteSSA = true;
GCTempVarsOnDebug = true;
DumpFunctionResolverLogic = false;
BuildOptErrorAsWarning = false;
ExecutionMode = ExecutionMode.Serial;
IDEDebugMode = false;
WatchTestMode = false;
IncludeDirectories = new List<string>();
RootModulePathName = Path.GetFullPath(@".");
staticCycleCheck = true;
dynamicCycleCheck = true;
EmitBreakpoints = true;
AssociativeToImperativePropagation = true;
SuppressFunctionResolutionWarning = true;
IsDeltaExecution = false;
IsDeltaCompile = false;
}
public bool DirectDependencyExecution { get; set; }
public bool ApplyUpdate { get; set; }
public bool DumpByteCode { get; set; }
public bool DumpIL { get; private set; }
public bool GenerateSSA { get; set; }
public bool ExecuteSSA { get; set; }
public bool GCTempVarsOnDebug { get; set; }
public bool Verbose { get; set; }
public bool SuppressBuildOutput { get; set; }
public bool BuildOptErrorAsWarning { get; set; }
public bool IDEDebugMode { get; set; } //set to true if two way mapping b/w DesignScript and JIL code is needed
public bool WatchTestMode { get; set; } // set to true when running automation tests for expression interpreter
public ExecutionMode ExecutionMode { get; set; }
public string FormatToPrintFloatingPoints { get; set; }
public bool staticCycleCheck { get; set; }
public bool dynamicCycleCheck { get; set; }
public bool DumpFunctionResolverLogic { get; set; }
public bool EmitBreakpoints { get; set; }
public bool SuppressFunctionResolutionWarning { get; set; }
public bool AssociativeToImperativePropagation { get; set; }
public bool IsDeltaExecution { get; set; }
public InterpreterMode RunMode { get; set; }
/// <summary>
/// TODO: Aparajit: This flag is true for Delta AST compilation
/// This will be removed once we make this the default and deprecate "deltaCompileStartPC"
/// which requires recompiling the entire source code for every delta execution
/// </summary>
public bool IsDeltaCompile { get; set; }
// This is being moved to Core.Options as this needs to be overridden for the Watch test framework runner
public int kDynamicCycleThreshold = 2000;
public List<string> IncludeDirectories { get; set; }
public string RootModulePathName { get; set; }
}
public struct InlineConditional
{
public bool isInlineConditional;
public int endPc;
public int startPc;
public int instructionStream;
public List<Instruction> ActiveBreakPoints;
}
public enum ParseMode
{
Normal,
AllowNonAssignment,
None
}
public class Core
{
public Dictionary<Guid, int> CallsiteGuidMap { get; set; }
public IDictionary<string, object> Configurations { get; set; }
public List<System.Type> DllTypesToLoad { get; private set; }
public void AddDLLExtensionAppType(System.Type type)
{
Validity.Assert(DllTypesToLoad != null);
DllTypesToLoad.Add(type);
}
/// <summary>
/// Properties in under COMPILER_GENERATED_TO_RUNTIME_DATA, are generated at compile time, and passed to RuntimeData/Exe
/// Only Core can initialize these
/// </summary>
#region COMPILER_GENERATED_TO_RUNTIME_DATA
public FunctionTable FunctionTable { get; private set; }
#endregion
// This flag is set true when we call GraphUtilities.PreloadAssembly to load libraries in Graph UI
public bool IsParsingPreloadedAssembly { get; set; }
// THe ImportModuleHandler owned by the temporary core used in Graph UI precompilation
// needed to detect if the same assembly is not being imported more than once
public ImportModuleHandler ImportHandler { get; set; }
// This is set to true when the temporary core is used for precompilation of CBN's in GraphUI
public bool IsParsingCodeBlockNode { get; set; }
// This is the AST node list of default imported libraries needed for Graph Compiler
public CodeBlockNode ImportNodes { get; set; }
public enum ErrorType
{
OK,
Error,
Warning
}
public struct ErrorEntry
{
public ErrorType Type;
public string FileName;
public string Message;
public BuildData.WarningID BuildId;
public Runtime.WarningID RuntimeId;
public int Line;
public int Col;
}
public Dictionary<ulong, ulong> CodeToLocation = new Dictionary<ulong, ulong>();
public Dictionary<ulong, ErrorEntry> LocationErrorMap = new Dictionary<ulong, ErrorEntry>();
public Dictionary<Language, Compiler> Compilers { get; private set; }
public int GlobOffset { get; set; }
public int GlobHeapOffset { get; set; }
public int BaseOffset { get; set; }
public int GraphNodeUID { get; set; }
public Heap Heap { get; private set; }
//public RuntimeMemory Rmem { get; set; }
public int ClassIndex { get; set; } // Holds the current class scope
public int CodeBlockIndex { get; set; }
public int RuntimeTableIndex { get; set; }
public List<CodeBlock> CodeBlockList { get; set; }
// The Complete Code Block list contains all the code blocks
// unlike the codeblocklist which only stores the outer most code blocks
public List<CodeBlock> CompleteCodeBlockList { get; set; }
/// <summary>
/// ForLoopBlockIndex tracks the current number of new for loop blocks created at compile time for every new compile phase
/// It is reset for delta compilation
/// </summary>
public int ForLoopBlockIndex { get; set; }
public Executable DSExecutable { get; set; }
public Options Options { get; private set; }
public BuildStatus BuildStatus { get; private set; }
public TypeSystem TypeSystem { get; set; }
public InternalAttributes internalAttributes { get; set; }
// The global class table and function tables
public ClassTable ClassTable { get; set; }
public ProcedureTable ProcTable { get; set; }
public ProcedureNode ProcNode { get; set; }
// The function pointer table
public FunctionPointerTable FunctionPointerTable { get; set; }
//The dynamic string table and function table
public DynamicVariableTable DynamicVariableTable { get; set; }
public DynamicFunctionTable DynamicFunctionTable { get; set; }
//Manages injected context data.
internal ContextDataManager ContextDataManager { get; set; }
public ParseMode ParsingMode { get; set; }
public bool ParseDeprecatedListSyntax = false;
/// <summary>
///
/// </summary>
/// <param name="data"></param>
public void AddContextData(Dictionary<string, Object> data)
{
if (data == null)
return;
ContextDataManager.GetInstance(this).AddData(data);
}
// if CompileToLib is true, this is used to output the asm instruction to the dsASM file
// if CompilerToLib is false, this will be set to Console.Out
public TextWriter AsmOutput;
public int AsmOutputIdents;
public string CurrentDSFileName { get; set; }
// this field is used to store the inferedtype information when the code gen cross one langeage to another
// otherwize the inferedtype information will be lost
public Type InferedType;
/// <summary>
/// Debugger properties generated at compile time.
/// This is copied to the RuntimeCore after compilation
/// </summary>
public DebugProperties DebuggerProperties;
public bool builtInsLoaded { get; set; }
public List<string> LoadedDLLs = new List<string>();
public int deltaCompileStartPC { get; set; }
// A list of graphnodes that contain a function call
public List<GraphNode> GraphNodeCallList { get; set; }
// A stack of graphnodes that are generated on the body of an inline conditional
public Stack<List<GraphNode>> InlineConditionalBodyGraphNodes { get; set; }
public int newEntryPoint { get; private set; }
public void SetNewEntryPoint(int pc)
{
newEntryPoint = pc;
}
/// <summary>
/// Sets the function to an inactive state where it can no longer be used by the front-end and backend
/// </summary>
/// <param name="functionDef"></param>
public void SetFunctionInactive(FunctionDefinitionNode functionDef)
{
// DS language only supports function definition on the global and first language block scope
// TODO Jun: Determine if it is still required to combine function tables in the codeblocks and callsite
// Update the functiond definition in the codeblocks
int hash = CoreUtils.GetFunctionHash(functionDef);
ProcedureNode procNode = null;
foreach (CodeBlock block in CodeBlockList)
{
// Update the current function definition in the current block
procNode = block.procedureTable.Procedures.FirstOrDefault(p => p.HashID == hash);
int index = procNode == null ? Constants.kInvalidIndex: procNode.ID;
if (Constants.kInvalidIndex == index)
continue;
procNode.IsActive = false;
// Remove staled graph nodes
var graph = block.instrStream.dependencyGraph;
graph.GraphList.RemoveAll(g => g.classIndex == ClassIndex &&
g.procIndex == index);
graph.RemoveNodesFromScope(Constants.kGlobalScope, index);
// Make a copy of all symbols defined in this function
var localSymbols = block.symbolTable.symbolList.Values
.Where(n =>
n.classScope == Constants.kGlobalScope
&& n.functionIndex == index)
.ToList();
foreach (var symbol in localSymbols)
{
block.symbolTable.UndefineSymbol(symbol);
}
break;
}
if (null != procNode)
{
// Remove codeblock defined in procNode from CodeBlockList and CompleteCodeBlockList
foreach (int cbID in procNode.ChildCodeBlocks)
{
CompleteCodeBlockList.RemoveAll(x => x.codeBlockId == cbID);
foreach (CodeBlock cb in CodeBlockList)
{
cb.children.RemoveAll(x => x.codeBlockId == cbID);
}
}
}
// Update the function definition in global function tables
foreach (KeyValuePair<int, Dictionary<string, FunctionGroup>> functionGroupList in DSExecutable.FunctionTable.GlobalFuncTable)
{
foreach (KeyValuePair<string, FunctionGroup> functionGroup in functionGroupList.Value)
{
functionGroup.Value.FunctionEndPoints.RemoveAll(func => func.procedureNode.HashID == hash);
}
}
}
/// <summary>
/// Reset the VM state for delta execution.
/// </summary>
public void ResetForDeltaExecution()
{
Options.ApplyUpdate = false;
Options.RunMode = InterpreterMode.Normal;
// The main codeblock never goes out of scope
// Resetting CodeBlockIndex means getting the number of main codeblocks that dont go out of scope.
// As of the current requirements, there is only 1 main scope, the rest are nested within.
CodeBlockIndex = CodeBlockList.Count;
RuntimeTableIndex = CodeBlockIndex;
ForLoopBlockIndex = Constants.kInvalidIndex;
// Jun this is where the temp solutions starts for implementing language blocks in delta execution
for (int n = 1; n < CodeBlockList.Count; ++n)
{
CodeBlockList[n].instrStream.instrList.Clear();
}
// Remove inactive graphnodes in the list
GraphNodeCallList.RemoveAll(g => !g.isActive);
ExprInterpreterExe = null;
}
public void ResetForPrecompilation()
{
GraphNodeUID = 0;
CodeBlockIndex = 0;
RuntimeTableIndex = 0;
//Initialize the dynamic string table and dynamic function table
DynamicVariableTable = new DynamicVariableTable();
DynamicFunctionTable = new DynamicFunctionTable();
BuildStatus = new BuildStatus(this);
ExpressionUID = 0;
ForLoopBlockIndex = Constants.kInvalidIndex;
}
private void ResetAll(Options options)
{
Heap = new Heap();
//Rmem = new RuntimeMemory(Heap);
Configurations = new Dictionary<string, object>();
DllTypesToLoad = new List<System.Type>();
Options = options;
Compilers = new Dictionary<Language, Compiler>();
ClassIndex = Constants.kInvalidIndex;
FunctionTable = new FunctionTable();
watchFunctionScope = Constants.kInvalidIndex;
watchSymbolList = new List<SymbolNode>();
watchBaseOffset = 0;
GlobOffset = 0;
GlobHeapOffset = 0;
BaseOffset = 0;
GraphNodeUID = 0;
CodeBlockIndex = 0;
RuntimeTableIndex = 0;
CodeBlockList = new List<CodeBlock>();
CompleteCodeBlockList = new List<CodeBlock>();
CallsiteGuidMap = new Dictionary<Guid, int>();
AssocNode = null;
// TODO Jun/Luke type system refactoring
// Initialize the globalClass table and type system
ClassTable = new ClassTable();
TypeSystem = new TypeSystem();
TypeSystem.SetClassTable(ClassTable);
ProcNode = null;
ProcTable = new ProcedureTable(Constants.kGlobalScope);
// Initialize internal attributes
internalAttributes = new InternalAttributes(ClassTable);
//Initialize the function pointer table
FunctionPointerTable = new FunctionPointerTable();
//Initialize the dynamic string table and dynamic function table
DynamicVariableTable = new DynamicVariableTable();
DynamicFunctionTable = new DynamicFunctionTable();
watchStartPC = Constants.kInvalidIndex;
deltaCompileStartPC = Constants.kInvalidIndex;
BuildStatus = new BuildStatus(this, null, Options.BuildOptErrorAsWarning);
SSAExpressionUID = 0;
SSASubscript = 0;
SSASubscript_GUID = Guid.NewGuid();
SSAExprUID = 0;
ExpressionUID = 0;
ExprInterpreterExe = null;
Options.RunMode = InterpreterMode.Normal;
assocCodegen = null;
// Default execution log is Console.Out.
ExecutionLog = Console.Out;
DebuggerProperties = new DebugProperties();
ParsingMode = ParseMode.Normal;
IsParsingPreloadedAssembly = false;
IsParsingCodeBlockNode = false;
ImportHandler = null;
deltaCompileStartPC = 0;
builtInsLoaded = false;
ForLoopBlockIndex = Constants.kInvalidIndex;
GraphNodeCallList = new List<GraphNode>();
InlineConditionalBodyGraphNodes = new Stack<List<GraphNode>>();
newEntryPoint = Constants.kInvalidIndex;
}
// The unique subscript for SSA temporaries
// TODO Jun: Organize these variables in core into proper enums/classes/struct
public int SSASubscript { get; set; }
public Guid SSASubscript_GUID { get; set; }
public int SSAExprUID { get; set; }
public int SSAExpressionUID { get; set; }
/// <summary>
/// ExpressionUID is used as the unique id to identify an expression
/// It is incremented by 1 after mapping its current value to an expression
/// </summary>
public int ExpressionUID { get; set; }
private int tempVarId = 0;
private int tempLanguageId = 0;
// TODO Jun: Cleansify me - i dont need to be here
public AssociativeNode AssocNode { get; set; }
public int watchStartPC { get; set; }
//
// TODO Jun: This is the expression interpreters executable.
// It must be moved to its own core, whre each core is an instance of a compiler+interpreter
//
public Executable ExprInterpreterExe { get; set; }
public int watchFunctionScope { get; set; }
public int watchBaseOffset { get; set; }
public List<SymbolNode> watchSymbolList { get; set; }
public CodeGen assocCodegen { get; set; }
public TextWriter ExecutionLog { get; set; }
public Core(Options options)
{
ResetAll(options);
}
public SymbolNode GetFirstVisibleSymbol(string name, int classscope, int function, CodeBlock codeblock)
{
Validity.Assert(null != codeblock);
int symbolIndex = Constants.kInvalidIndex;
// For variables defined nested language block, their function index
// is always Constants.kGlobalScope
CodeBlock searchBlock = codeblock;
while (searchBlock != null)
{
// For imported node, it is possbile that the block is not the
// topmost block.
//
// For expression interpreter, as the code has been compiled, the
// outmost block wouldn't be function block (CodeBlockType.Function).
// CodeBlockType.Function is a temporary block type which is set when
// the compile is generating code for function defintion node and will
// be set back to Associative.
var isSearchBoundry = searchBlock.blockType == CodeBlockType.Function ||
(Options.RunMode == InterpreterMode.Expression && searchBlock.parent == null);
if (isSearchBoundry)
{
break;
}
symbolIndex = searchBlock.symbolTable.IndexOf(name, classscope, Constants.kGlobalScope);
if (symbolIndex == Constants.kInvalidIndex)
{
searchBlock = searchBlock.parent;
}
else
{
return searchBlock.symbolTable.symbolList[symbolIndex];
}
}
// Search variable might be defined in function.
// If we are not in class defintion, then just stop here, otherwise
// we should search global block's symbol table.
if (searchBlock != null &&
(searchBlock.blockType == CodeBlockType.Function || (Options.RunMode == InterpreterMode.Expression && searchBlock.parent == null)) &&
classscope == Constants.kGlobalScope)
{
symbolIndex = searchBlock.symbolTable.IndexOf(name, classscope, function);
}
return symbolIndex == Constants.kInvalidIndex ? null : searchBlock.symbolTable.symbolList[symbolIndex];
}
public bool IsFunctionCodeBlock(CodeBlock cblock)
{
// Determine if the immediate block is a function block
// Construct blocks are ignored
Validity.Assert(null != cblock);
while (null != cblock)
{
if (CodeBlockType.Function == cblock.blockType)
{
return true;
}
else if (CodeBlockType.Language == cblock.blockType)
{
return false;
}
cblock = cblock.parent;
}
return false;
}
private void BfsBuildSequenceTable(CodeBlock codeBlock, SymbolTable[] runtimeSymbols)
{
if (CodeBlockType.Language == codeBlock.blockType
|| CodeBlockType.Function == codeBlock.blockType
|| CodeBlockType.Construct == codeBlock.blockType)
{
Validity.Assert(codeBlock.symbolTable.RuntimeIndex < RuntimeTableIndex);
runtimeSymbols[codeBlock.symbolTable.RuntimeIndex] = codeBlock.symbolTable;
}
foreach (CodeBlock child in codeBlock.children)
{
BfsBuildSequenceTable(child, runtimeSymbols);
}
}
private void BfsBuildProcedureTable(CodeBlock codeBlock, ProcedureTable[] procTable)
{
if (CodeBlockType.Language == codeBlock.blockType || CodeBlockType.Function == codeBlock.blockType)
{
Validity.Assert(codeBlock.procedureTable.RuntimeIndex < RuntimeTableIndex);
procTable[codeBlock.procedureTable.RuntimeIndex] = codeBlock.procedureTable;
}
foreach (CodeBlock child in codeBlock.children)
{
BfsBuildProcedureTable(child, procTable);
}
}
private void BfsBuildInstructionStreams(CodeBlock codeBlock, InstructionStream[] istreamList)
{
if (null != codeBlock)
{
if (CodeBlockType.Language == codeBlock.blockType || CodeBlockType.Function == codeBlock.blockType)
{
Validity.Assert(codeBlock.codeBlockId < RuntimeTableIndex);
istreamList[codeBlock.codeBlockId] = codeBlock.instrStream;
}
foreach (CodeBlock child in codeBlock.children)
{
BfsBuildInstructionStreams(child, istreamList);
}
}
}
public void GenerateExprExe()
{
// TODO Jun: Determine if we really need another executable for the expression interpreter
Validity.Assert(null == ExprInterpreterExe);
ExprInterpreterExe = new Executable();
ExprInterpreterExe.FunctionTable = FunctionTable;
ExprInterpreterExe.DynamicVarTable = DynamicVariableTable;
ExprInterpreterExe.FuncPointerTable = FunctionPointerTable;
ExprInterpreterExe.DynamicFuncTable = DynamicFunctionTable;
ExprInterpreterExe.ContextDataMngr = ContextDataManager;
ExprInterpreterExe.Configurations = Configurations;
ExprInterpreterExe.CodeToLocation = CodeToLocation;
ExprInterpreterExe.CurrentDSFileName = CurrentDSFileName;
// Copy all tables
ExprInterpreterExe.classTable = DSExecutable.classTable;
ExprInterpreterExe.procedureTable = DSExecutable.procedureTable;
ExprInterpreterExe.runtimeSymbols = DSExecutable.runtimeSymbols;
ExprInterpreterExe.TypeSystem = TypeSystem;
// Copy all instruction streams
// TODO Jun: What method to copy all? Use that
ExprInterpreterExe.instrStreamList = new InstructionStream[DSExecutable.instrStreamList.Length];
for (int i = 0; i < DSExecutable.instrStreamList.Length; ++i)
{
if (null != DSExecutable.instrStreamList[i])
{
ExprInterpreterExe.instrStreamList[i] = new InstructionStream(DSExecutable.instrStreamList[i].language, this);
//ExprInterpreterExe.instrStreamList[i] = new InstructionStream(DSExecutable.instrStreamList[i].language, DSExecutable.instrStreamList[i].dependencyGraph, this);
for (int j = 0; j < DSExecutable.instrStreamList[i].instrList.Count; ++j)
{
ExprInterpreterExe.instrStreamList[i].instrList.Add(DSExecutable.instrStreamList[i].instrList[j]);
}
}
}
}
public void GenerateExprExeInstructions(int blockScope)
{
// Append the expression instruction at the end of the current block
for (int n = 0; n < ExprInterpreterExe.iStreamCanvas.instrList.Count; ++n)
{
ExprInterpreterExe.instrStreamList[blockScope].instrList.Add(ExprInterpreterExe.iStreamCanvas.instrList[n]);
}
}
public void GenerateExecutable()
{
Validity.Assert(CodeBlockList.Count >= 0);
DSExecutable = new Executable();
// Create the code block list data
DSExecutable.CodeBlocks = new List<CodeBlock>();
DSExecutable.CodeBlocks.AddRange(CodeBlockList);
DSExecutable.CompleteCodeBlocks = new List<CodeBlock>();
DSExecutable.CompleteCodeBlocks.AddRange(CompleteCodeBlockList);
// Retrieve the class table directly since it is a global table
DSExecutable.classTable = ClassTable;
// The TypeSystem is a record of all primitive and compiler generated types
DSExecutable.TypeSystem = TypeSystem;
RuntimeTableIndex = CompleteCodeBlockList.Count;
// Build the runtime symbols
DSExecutable.runtimeSymbols = new SymbolTable[RuntimeTableIndex];
for (int n = 0; n < CodeBlockList.Count; ++n)
{
BfsBuildSequenceTable(CodeBlockList[n], DSExecutable.runtimeSymbols);
}
// Build the runtime procedure table
DSExecutable.procedureTable = new ProcedureTable[RuntimeTableIndex];
for (int n = 0; n < CodeBlockList.Count; ++n)
{
BfsBuildProcedureTable(CodeBlockList[n], DSExecutable.procedureTable);
}
// Build the executable instruction streams
DSExecutable.instrStreamList = new InstructionStream[RuntimeTableIndex];
for (int n = 0; n < CodeBlockList.Count; ++n)
{
BfsBuildInstructionStreams(CodeBlockList[n], DSExecutable.instrStreamList);
}
GenerateExprExe();
DSExecutable.FunctionTable = FunctionTable;
DSExecutable.DynamicVarTable = DynamicVariableTable;
DSExecutable.DynamicFuncTable = DynamicFunctionTable;
DSExecutable.FuncPointerTable = FunctionPointerTable;
DSExecutable.ContextDataMngr = ContextDataManager;
DSExecutable.Configurations = Configurations;
DSExecutable.CodeToLocation = CodeToLocation;
DSExecutable.CurrentDSFileName = CurrentDSFileName;
}
public string GenerateTempVar()
{
tempVarId++;
return Constants.kTempVar + tempVarId.ToString();
}
public string GenerateTempPropertyVar()
{
tempVarId++;
return Constants.kTempPropertyVar + tempVarId.ToString();
}
public string GenerateTempLangageVar()
{
tempLanguageId++;
return Constants.kTempLangBlock + tempLanguageId.ToString();
}
public bool IsTempVar(String varName)
{
if (String.IsNullOrEmpty(varName))
{
return false;
}
return varName[0] == '%';
}
public GraphNode ExecutingGraphnode { get; set; }
public void ResetSSASubscript(Guid guid, int subscript)
{
SSASubscript_GUID = guid;
SSASubscript = subscript;
}
public void Cleanup()
{
CLRModuleType.ClearTypes();
}
}
}