public XILSFunction Run() { int count = 0; foreach (var stype in _inFunc.SlotTypes) { _interLocals.Add(new Variable(stype) { Name = _inFunc.Name + (count++) }); } foreach (var xil3i in _inFunc.Instructions) { Process(xil3i); } foreach (var label in _labels) { label.InstructionIndex = _instRemap[label.InstructionIndex]; } var locals = _inFunc.Locals.Concat(_interLocals).ToArray(); var result = new XILSFunction( _inFunc.Name, _inFunc.Arguments, locals, _outInstrs.ToArray()); return(result); }
/// <summary> /// Compiles given SysDOM function to XIL-S code /// </summary> /// <param name="func">SysDOM function</param> /// <param name="iset">instruction set</param> /// <returns>compiled XIL-S function</returns> public static XILSFunction Compile(this Function func, IInstructionSet <XILInstr> iset) { var input = func; Variable[] inlinedLocals; input = input.ConvertFieldsToLocals(out inlinedLocals); var comp = new Compiler(iset, input); comp.Run(); var instrs = comp.Result; var cfg = CreateCFG(instrs); var reachInstrs = TrimUnreachable(cfg); var optInstrs = OptimizeLocals(cfg); var inArgds = input.InputVariables.Select( (v, i) => new ArgumentDescriptor(v, ArgumentDescriptor.EArgDirection.In, EVariability.ExternVariable, i)); int inCount = inArgds.Count(); var outArgds = input.InputVariables.Select( (v, i) => new ArgumentDescriptor(v, ArgumentDescriptor.EArgDirection.Out, EVariability.ExternVariable, i + inCount)); var argds = inArgds.Union(outArgds).ToArray(); var locals = optInstrs.RenumerateLocalVariables(); var result = new XILSFunction(func.Name, argds, locals.ToArray(), optInstrs.ToArray()); result.SanityCheck(); return(result); }
/// <summary> /// Converts XIL-S function to XIL-3 function /// </summary> /// <param name="xils">XIL-S function to convert</param> /// <returns>resulting XIL-3 function</returns> public static XIL3Function ToXIL3(this XILSFunction xils) { return(StkTo3ACImpl.ToXIL3(xils)); }
private StkTo3ACImpl(XILSFunction func) { _func = func; }
public static XIL3Function ToXIL3(XILSFunction xils) { StkTo3ACImpl conv = new StkTo3ACImpl(xils); return(conv.Run()); }