internal static Function CompileFunctionForBytecodeInterpreter(DfirRoot dfirRoot, CompileCancellationToken cancellationToken) { ExecutionOrderSortingVisitor.SortDiagrams(dfirRoot); var variableAllocations = VariableReference.CreateDictionaryWithUniqueVariableKeys <ValueSource>(); var allocator = new BytecodeInterpreterAllocator(variableAllocations); allocator.Execute(dfirRoot, cancellationToken); IEnumerable <LocalAllocationValueSource> localAllocations = variableAllocations.Values.OfType <LocalAllocationValueSource>(); int[] localSizes = new int[localAllocations.Count()]; foreach (var allocation in localAllocations) { localSizes[allocation.Index] = allocation.Size; } var functionBuilder = new FunctionBuilder() { Name = dfirRoot.SpecAndQName.EditorName, LocalSizes = localSizes }; new FunctionCompiler(functionBuilder, variableAllocations).Execute(dfirRoot, cancellationToken); return(functionBuilder.CreateFunction()); }
internal static Module CompileFunctionForLLVM(DfirRoot dfirRoot, CompileCancellationToken cancellationToken, string compiledFunctionName = "") { ExecutionOrderSortingVisitor.SortDiagrams(dfirRoot); Dictionary <VariableReference, LLVM.ValueSource> valueSources = VariableReference.CreateDictionaryWithUniqueVariableKeys <LLVM.ValueSource>(); LLVM.Allocator allocator = new LLVM.Allocator(valueSources); allocator.Execute(dfirRoot, cancellationToken); Module module = new Module("module"); compiledFunctionName = string.IsNullOrEmpty(compiledFunctionName) ? dfirRoot.SpecAndQName.RuntimeName : compiledFunctionName; LLVM.FunctionCompiler functionCompiler = new LLVM.FunctionCompiler(module, compiledFunctionName, valueSources); functionCompiler.Execute(dfirRoot, cancellationToken); return(module); }