private IEnumerable<CodeName> ExtractNames(CodeFrame codeFrame) { if (codeFrame.Symbols == null) yield break; var dr = new DebugReader(codeFrame.Symbols); if (dr.EnumerateVarSyms().Count() > 0) { foreach (var v in dr.FindVarSyms(Int32.MaxValue, dr.GetScopeSymByIndex(0))) { var flags = (ElaVariableFlags)v.Flags; if (!v.Name.StartsWith("$")) { var ln = dr.FindLineSym(v.Offset); yield return new CodeName(v.Name, (Int32)flags, ln.Line, ln.Column); } } } else { foreach (var v in codeFrame.GlobalScope.EnumerateNames()) { var sv = codeFrame.GlobalScope.GetVariable(v); if (!sv.VariableFlags.Set(ElaVariableFlags.Private) && !v.StartsWith("$")) yield return new CodeName(v, (Int32)sv.VariableFlags, 0, 0); } } }
//A generic method used to loop a prefixed var in a module. private ScopeVar FindByPrefix(string prefix, string var, out CodeFrame fr) { var sv = GetVariable(prefix, CurrentScope, GetFlags.NoError, 0, 0); var mod = default(ModuleReference); fr = null; //Looks like a target object is not a module if ((sv.Flags & ElaVariableFlags.Module) != ElaVariableFlags.Module || !frame.References.TryGetValue(prefix, out mod)) return ScopeVar.Empty; var fieldSv = default(ScopeVar); //We have such a reference but looks like it couldn't be obtained //We don't need to handle this situation here, it is already reported by a linker fr = refs[mod.LogicalHandle]; if (fr == null) return ScopeVar.Empty; //No such name, now captured statically if (!refs[mod.LogicalHandle].GlobalScope.Locals.TryGetValue(var, out fieldSv) && !options.IgnoreUndefined) return ScopeVar.Empty; //Name is private, now captured statically if ((fieldSv.VariableFlags & ElaVariableFlags.Private) == ElaVariableFlags.Private) return ScopeVar.Empty; return new ScopeVar(fieldSv.Flags|ElaVariableFlags.External, mod.LogicalHandle | fieldSv.Address << 8, fieldSv.Data); }
internal void RefreshRootModule(CodeFrame frame) { if (frame != null) { modules[0] = frame; } }
public CompilerResult Compile(ElaProgram prog, CompilerOptions options, ExportVars builtins, CodeFrame frame, Scope globalScope) { Options = options; var helper = new Builder(frame, this, builtins, globalScope); try { helper.CompileUnit(prog); } catch (TerminationException) { //Nothing should be done here. This was thrown to stop compilation. } #if !DEBUG catch (Exception ex) { if (ex is ElaCompilerException) throw; throw new ElaCompilerException(Strings.GetMessage("Ice", ex.Message), ex); } #endif frame.Symbols = frame.Symbols == null ? helper.Symbols : helper.Symbols != null ? frame.Symbols.Merge(helper.Symbols) : frame.Symbols; frame.GlobalScope = globalScope; return new CompilerResult(frame, helper.Success, helper.Errors.ToArray()); }
private IEnumerable <CodeName> ExtractNames(CodeFrame codeFrame) { if (codeFrame.Symbols == null) { yield break; } var dr = new DebugReader(codeFrame.Symbols); if (dr.EnumerateVarSyms().Count() > 0) { foreach (var v in dr.FindVarSyms(Int32.MaxValue, dr.GetScopeSymByIndex(0))) { var flags = (ElaVariableFlags)v.Flags; if (!v.Name.StartsWith("$")) { var ln = dr.FindLineSym(v.Offset); yield return(new CodeName(v.Name, (Int32)flags, ln.Line, ln.Column)); } } } else { foreach (var v in codeFrame.GlobalScope.EnumerateNames()) { var sv = codeFrame.GlobalScope.GetVariable(v); if (!sv.VariableFlags.Set(ElaVariableFlags.Private) && !v.StartsWith("$")) { yield return(new CodeName(v, (Int32)sv.VariableFlags, 0, 0)); } } } }
public string Generate(CodeFrame frame) { var gen = new EilGenerator(frame); gen.OmitOffsets = !PrintOffsets; gen.IgnoreDebugInfo = IgnoreDebugInfo; return gen.Generate(); }
public string Generate(CodeFrame frame) { var gen = new EilGenerator(frame); gen.OmitOffsets = !PrintOffsets; gen.IgnoreDebugInfo = IgnoreDebugInfo; return(gen.Generate()); }
/// <summary> /// Adds templated code to the method using the string.Format() /// mechanism /// </summary> /// <param name="code"></param> /// <param name="values"></param> /// <returns></returns> public ICodeFrame CodeAsync(string code, params object[] values) { var frame = new CodeFrame(true, code, values); Add(frame); return(frame); }
internal ModuleReference(CodeFrame parent, string moduleName, string dllName, string[] path, int line, int column, bool requireQualified, int logicalHandle) { ModuleName = moduleName; DllName = dllName; Path = path ?? new string[0]; Line = line; Column = column; RequireQuailified = requireQualified; LogicalHandle = logicalHandle; Parent = parent; }
internal CompiledUnit(Document doc, CodeFrame codeFrame) { CodeFrame = codeFrame; Document = doc; if (codeFrame != null) { Globals = ExtractNames(codeFrame).ToList(); Classes = codeFrame.Classes.Select(kv => new TypeClass(kv.Key, kv.Value, GetLocation("$$$" + kv.Key))).ToList(); Instances = codeFrame.Instances.Select(i => new TypeClassInstance(i.Class, i.Type, new Location(i.Line, i.Column))); Types = codeFrame.Types.Select(s => new UserType(s, GetLocation("$$" + s))); References = codeFrame.References.Where(r => !r.Key.StartsWith("$__")).Select(r => new Reference(this, r.Value)).ToList(); } }
internal int AddModule(string name, CodeFrame module, bool qual, int logicHandle) { var hdl = 0; if (!moduleMap.TryGetValue(name, out hdl)) { moduleMap.Add(name, hdl = modules.Count); modules.Add(module); quals.Add(qual); } else { modules[hdl] = module; quals[hdl] = qual; } return(hdl); }
private Dictionary<String, Int32> stringLookup; //String table #endregion Fields #region Constructors //globalScope is not empty (e.g. new Scope()) only if we are resuming in interactive mode internal Builder(CodeFrame frame, ElaCompiler comp, ExportVars exportVars, Scope globalScope) { this.frame = frame; this.options = comp.Options; this.exports = exportVars; this.comp = comp; this.cw = new CodeWriter(frame.Ops, frame.OpData); this.globalScope = globalScope; CurrentScope = globalScope; debug = options.GenerateDebugInfo; opt = options.Optimize; stringLookup = new Dictionary<String,Int32>(); cleans.Push(true); ResumeIndexer(); Success = true; }
public CallStack BuildCallStack(int currentOffset, CodeFrame errModule, ModuleFileInfo moduleFile, Stack <StackPoint> callChain) { var syms = new DebugReader(errModule.Symbols); var frames = new List <CallFrame>(); var lp = syms.FindLineSym(currentOffset - 1); var retval = new CallStack( moduleFile, lp != null ? lp.Line : 0, lp != null ? lp.Column : 0, frames ); if (callChain == null || callChain.Count == 0) { return(retval); } var mem = default(StackPoint); var first = true; var offset = 0; do { mem = callChain.Pop(); var mod = Assembly.GetModuleName(mem.ModuleHandle); syms = new DebugReader(Assembly.GetModule(mem.ModuleHandle).Symbols); offset = first ? currentOffset - 1 : mem.BreakAddress - 1; var glob = callChain.Count == 0 || offset < 0; var funSym = !glob?syms.FindFunSym(offset) : null; var line = syms != null && offset > 0 ? syms.FindLineSym(offset) : null; frames.Add(new CallFrame(glob, mod, funSym != null ? funSym.Name != null ? funSym.Name : String.Format(FUNC_PARS, funSym.Parameters) : glob ? null : FUNC, offset, line)); first = false; }while (callChain.Count > 0 && offset > 0); return(retval); }
public CallStack BuildCallStack(int currentOffset, CodeFrame errModule, FileInfo moduleFile, Stack<StackPoint> callChain) { var syms = new DebugReader(errModule.Symbols); var frames = new List<CallFrame>(); var lp = syms.FindLineSym(currentOffset - 1); var retval = new CallStack( moduleFile, lp != null ? lp.Line : 0, lp != null ? lp.Column : 0, frames ); if (callChain == null || callChain.Count == 0) return retval; var mem = default(StackPoint); var first = true; var offset = 0; do { mem = callChain.Pop(); var mod = Assembly.GetModuleName(mem.ModuleHandle); syms = new DebugReader(Assembly.GetModule(mem.ModuleHandle).Symbols); offset = first ? currentOffset - 1 : mem.BreakAddress - 1; var glob = callChain.Count == 0 || offset < 0; var funSym = !glob ? syms.FindFunSym(offset) : null; var line = syms != null && offset > 0 ? syms.FindLineSym(offset) : null; frames.Add(new CallFrame(glob, mod, funSym != null ? funSym.Name != null ? funSym.Name : String.Format(FUNC_PARS, funSym.Parameters) : glob ? null : FUNC, offset, line)); first = false; } while (callChain.Count > 0 && offset > 0); return retval; }
private void Write(CodeFrame frame, BinaryWriter bw) { bw.Write(Version); var v = new Version(Const.Version); bw.Write(v.Major); bw.Write(v.Minor); bw.Write(v.Build); bw.Write(v.Revision); var d = DateTime.Now.ToUniversalTime().Ticks; bw.Write(d); bw.Write(frame.References.Count); foreach (var kv in frame.References) { bw.Write(kv.Key); bw.Write(kv.Value.ModuleName); bw.Write(kv.Value.DllName ?? String.Empty); bw.Write(kv.Value.RequireQuailified); bw.Write(kv.Value.Path.Length); foreach (var p in kv.Value.Path) bw.Write(p); bw.Write(kv.Value.LogicalHandle); } bw.Write(frame.GlobalScope.Locals.Count); foreach (var kv in frame.GlobalScope.Locals) { bw.Write(kv.Key); bw.Write((Int32)kv.Value.Flags); bw.Write(kv.Value.Address); bw.Write(kv.Value.Data); } bw.Write(frame.LateBounds.Count); foreach (var u in frame.LateBounds) { bw.Write(u.Name); bw.Write(u.Address); bw.Write(u.Data); bw.Write(u.Flags); bw.Write(u.Line); bw.Write(u.Column); } bw.Write(frame.Layouts.Count); for (var i = 0; i < frame.Layouts.Count; i++) { var l = frame.Layouts[i]; bw.Write(l.Size); bw.Write(l.StackSize); bw.Write(l.Address); } bw.Write(frame.Strings.Count); for (var i = 0; i < frame.Strings.Count; i++) bw.Write(frame.Strings[i]); var ops = frame.Ops; bw.Write(ops.Count); for (var i = 0; i < ops.Count; i++) { var op = ops[i]; bw.Write((Byte)op); if (OpSizeHelper.OpSize[(Int32)op] > 1) bw.Write(frame.OpData[i]); } var types = frame.InternalTypes; bw.Write(types.Count); foreach (var kv in types) { bw.Write(kv.Key); if (kv.Value <= SysConst.MAX_TYP) bw.Write(kv.Value); else bw.Write(-1); } var classes = frame.InternalClasses; bw.Write(classes.Count); foreach (var kv in classes) { bw.Write(kv.Key); bw.Write(kv.Value.Members.Length); for (var i = 0; i < kv.Value.Members.Length; i++) { var m = kv.Value.Members[i]; bw.Write(m.Components); bw.Write(m.Mask); bw.Write(m.Name); } } var inst = frame.InternalInstances; bw.Write(inst.Count); for (var i = 0; i < inst.Count; i++) { var it = inst[i]; bw.Write(it.Type); bw.Write(it.Class); bw.Write(it.TypeModuleId); bw.Write(it.ClassModuleId); bw.Write(it.Line); bw.Write(it.Column); } var ctors = frame.InternalConstructors; bw.Write(ctors.Count); foreach (var ct in frame.InternalConstructors) { bw.Write(ct.Name); bw.Write(ct.TypeName); bw.Write(ct.TypeModuleId); if (ct.Parameters != null) { bw.Write(ct.Parameters.Count); for (var j = 0; j < ct.Parameters.Count; j++) bw.Write(ct.Parameters[j]); } else bw.Write(0); } var di = frame.Symbols != null; bw.Write(di); //Contains debug info if (di) { var sym = frame.Symbols; bw.Write(sym.Lines.Count); for (var i = 0; i < sym.Lines.Count; i++) { var ln = sym.Lines[i]; bw.Write(ln.Offset); bw.Write(ln.Line); bw.Write(ln.Column); } bw.Write(sym.Functions.Count); for (var i = 0; i < sym.Functions.Count; i++) { var fn = sym.Functions[i]; bw.Write(fn.Name ?? String.Empty); bw.Write(fn.StartOffset); bw.Write(fn.Parameters); bw.Write(fn.Handle); bw.Write(fn.EndOffset); } } }
public void Write(CodeFrame frame) { using (var bw = new BinaryWriter(File.OpenWrite())) Write(frame, bw); }
internal CompilerResult(CodeFrame frame, bool success, IEnumerable<ElaMessage> messages) : base(success, messages) { CodeFrame = frame; }
internal ModuleReference(CodeFrame parent, string moduleName) : this(parent, moduleName, null, null, 0, 0, false, 0) { }
//This function tries to autogenerate an instance (similar to derived in Haskell). //It can fully or partially generate it. A default instance (instance without a type) is //used for such purpose. private List<String> TryGenerateMembers(List<String> members, CodeFrame mod, ElaClassInstance inst) { if (members.Count == 0) return members; var newMem = new List<String>(members); for (var i = 0; i < newMem.Count; i++) { var m = newMem[i]; var btVar = ObtainClassFunction(inst.TypeClassPrefix, inst.TypeClassName, m, inst.Line, inst.Column); //This is less likely but we better check this anyway if (btVar.IsEmpty()) AddError(ElaCompilerError.MemberInvalid, inst, m, inst.TypeClassName); var defVar = GetGlobalVariable("$default$" + m, GetFlags.NoError, inst.Line, inst.Column); //We dont' need to generate errors here, errors will be captured later. if (!defVar.IsEmpty()) { var builtin = (btVar.Flags & ElaVariableFlags.Builtin) == ElaVariableFlags.Builtin; //Check if this member is implemented directly by compiler if (!TryAutogenerate(defVar, inst)) PushVar(defVar); if (!builtin) PushVar(btVar); else cw.Emit(Op.PushI4, (Int32)btVar.Data); EmitSpecName(inst.TypePrefix, "$$" + inst.TypeName, inst, ElaCompilerError.UndefinedType); cw.Emit(Op.Addmbr); members.Remove(m); } } return members; }
internal int AddModule(ModuleFileInfo fi, CodeFrame module, bool qual, int logicHandle) { var name = ObtainModuleName(fi); return(AddModule(name, module, qual, logicHandle)); }
internal void RefreshRootModule(CodeFrame frame) { if (frame != null) modules[0] = frame; }
internal int AddModule(FileInfo fi, CodeFrame module, bool qual, int logicHandle) { var name = ObtainModuleName(fi); return AddModule(name, module, qual, logicHandle); }
public CompilerResult Compile(ElaProgram prog, CompilerOptions options, ExportVars builtins) { var frame = new CodeFrame(); return Compile(prog, options, builtins, frame, new Scope(false, null)); }
public EilGenerator(CodeFrame frame) { this.frame = frame; }
public CodeAssembly(CodeFrame frame) : this() { moduleMap.Add(MAIN_NAME, modules.Count); modules.Add(frame); }
//This method returns type class data including: type class metadata (ClassData), module local ID //(modId) and compiled module where class is defined. private int ObtainTypeClass(ElaClassInstance s, out ClassData mbr, out int modId, out CodeFrame mod) { mbr = null; modId = -1; mod = null; //If a type class prefix is not set we need to obtain a type class ID using a special '$$$*' variable //that is initialized during type class compilation if (s.TypeClassPrefix == null) { //We first check if a class definition is non-local if (!frame.InternalClasses.TryGetValue(s.TypeClassName, out mbr)) { var sv = GetVariable("$$$" + s.TypeClassName, CurrentScope, GetFlags.NoError, s.Line, s.Column); if (sv.IsEmpty() && !options.IgnoreUndefined) { AddError(ElaCompilerError.UnknownClass, s, s.TypeClassName); return -1; } //The trick is - here sv can be only an external name (we do check prior to this //if a class is not local). If it is an external name that first byte contains a //local index of a referenced module - that is exactly what we need here to obtain //a compiled module frame (from refs array). modId = sv.Address & Byte.MaxValue; if (modId < refs.Count && modId >= 0) mod = refs[modId]; return sv.Data; } else { var sv = GetVariable("$$$" + s.TypeClassName, CurrentScope, GetFlags.NoError, s.Line, s.Column); return sv.Data; } } else { //Type class prefix is set. The prefix itself should be local name (a module alias) var sv = GetVariable(s.TypeClassPrefix, s.Line, s.Column); if (sv.IsEmpty()) return -1; //A name was found but this is not a module alias if ((sv.Flags & ElaVariableFlags.Module) != ElaVariableFlags.Module) { AddError(ElaCompilerError.InvalidQualident, s, s.TypeClassPrefix); return -1; } //In this case we can look for a reference based on its alias (alias should be unique within //the current module). modId = frame.References[s.TypeClassPrefix].LogicalHandle; if (modId < refs.Count && modId >= 0) mod = refs[modId]; //Now we need to obtain 'data' of a type class variable - it might a type class //typeId if this type class is built-in. ScopeVar sv2; if (mod != null && mod.GlobalScope.Locals.TryGetValue("$$$" + s.TypeClassName, out sv2)) return sv.Data; else return -1; } }
internal int AddModule(string name, CodeFrame module, bool qual, int logicHandle) { var hdl = 0; if (!moduleMap.TryGetValue(name, out hdl)) { moduleMap.Add(name, hdl = modules.Count); modules.Add(module); quals.Add(qual); } else { modules[hdl] = module; quals[hdl] = qual; } return hdl; }
public void Write(CodeFrame frame) { using (var bw = new BinaryWriter(new FileInfo(File.FullName).OpenWrite())) Write(frame, bw); }
public void AddModule(CodeFrame frame) { this.frame = frame; }
public void Run() { _logger.Log("Begin"); var context = TstEngineContextHelper.CreateAndInitContext().EngineContext; var applicationInheritanceItem = new InheritanceItem() { IsSystemDefined = true }; applicationInheritanceItem.SubName = NameHelper.CreateName("PeaseKeeper"); applicationInheritanceItem.SuperName = context.CommonNamesStorage.AppName; applicationInheritanceItem.Rank = new LogicalValue(1.0F); context.Storage.GlobalStorage.InheritanceStorage.SetInheritance(applicationInheritanceItem); var compiledFunctionBody = new CompiledFunctionBody(); var strVal = new StringValue("The beatles!"); var command = new ScriptCommand(); command.OperationCode = OperationCode.PushVal; command.Value = strVal; _logger.Log($"command = {command}"); compiledFunctionBody.Commands[0] = command; var identifier = NameHelper.CreateName("@>log"); command = new ScriptCommand(); command.OperationCode = OperationCode.PushVal; command.Value = identifier; command.Position = 1; _logger.Log($"command = {command}"); compiledFunctionBody.Commands[1] = command; command = new ScriptCommand(); command.OperationCode = OperationCode.CallBinOp; command.KindOfOperator = KindOfOperator.LeftRightStream; command.Position = 2; _logger.Log($"command = {command}"); compiledFunctionBody.Commands[2] = command; command = new ScriptCommand(); command.OperationCode = OperationCode.Return; command.Position = 3; _logger.Log($"command = {command}"); compiledFunctionBody.Commands[3] = command; _logger.Log($"compiledFunctionBody = {compiledFunctionBody}"); _logger.Log($"compiledFunctionBody = {compiledFunctionBody.ToDbgString()}"); var codeFrame = new CodeFrame(); codeFrame.CompiledFunctionBody = compiledFunctionBody; codeFrame.LocalContext = new LocalCodeExecutionContext(); codeFrame.LocalContext.Storage = context.Storage.GlobalStorage; codeFrame.LocalContext.Holder = NameHelper.CreateName("PixKeeper"); //codeFrame.LocalContext.Holder = new Name(); _logger.Log($"codeFrame = {codeFrame}"); _logger.Log($"codeFrame = {codeFrame.ToDbgString()}"); var threadExecutor = new SyncThreadExecutor(context); threadExecutor.SetCodeFrame(codeFrame); threadExecutor.Start(); _logger.Log("End"); }
private CodeFrame Read(BinaryReader bw) { var frame = new CodeFrame(); frame.GlobalScope = new Scope(false, null); var v = bw.ReadInt32(); if (v != Version) { throw new ElaLinkerException(Strings.GetMessage("InvalidObjectFile", Version), null); } bw.ReadInt32(); //Version: Major bw.ReadInt32(); //Version: Minor bw.ReadInt32(); //Version: Build bw.ReadInt32(); //Version: Revision bw.ReadInt64(); //Version: Date stamp var c = bw.ReadInt32(); for (var i = 0; i < c; i++) { var alias = bw.ReadString(); var modName = bw.ReadString(); var dllName = bw.ReadString(); dllName = dllName.Length == 0 ? null : dllName; var qual = bw.ReadBoolean(); var pl = bw.ReadInt32(); var list = new string[pl]; for (var j = 0; j < pl; j++) { list[j] = bw.ReadString(); } var lh = bw.ReadInt32(); frame.AddReference(alias, new ModuleReference(frame, modName, dllName, list, 0, 0, qual, lh)); } c = bw.ReadInt32(); for (var i = 0; i < c; i++) { frame.GlobalScope.Locals.Add(bw.ReadString(), new ScopeVar((ElaVariableFlags)bw.ReadInt32(), bw.ReadInt32(), bw.ReadInt32())); } c = bw.ReadInt32(); for (var i = 0; i < c; i++) { frame.LateBounds.Add(new LateBoundSymbol( bw.ReadString(), bw.ReadInt32(), bw.ReadInt32(), bw.ReadInt32(), bw.ReadInt32(), bw.ReadInt32())); } c = bw.ReadInt32(); for (var i = 0; i < c; i++) { var l = new MemoryLayout(bw.ReadInt32(), bw.ReadInt32(), bw.ReadInt32()); frame.Layouts.Add(l); } c = bw.ReadInt32(); for (var i = 0; i < c; i++) { frame.Strings.Add(bw.ReadString()); } c = bw.ReadInt32(); for (var i = 0; i < c; i++) { var opCode = (Op)bw.ReadByte(); frame.Ops.Add(opCode); frame.OpData.Add(OpSizeHelper.OpSize[(Int32)opCode] > 1 ? bw.ReadInt32() : 0); } c = bw.ReadInt32(); for (var i = 0; i < c; i++) { frame.InternalTypes.Add(bw.ReadString(), bw.ReadInt32()); } c = bw.ReadInt32(); for (var i = 0; i < c; i++) { var k = bw.ReadString(); var cc = bw.ReadInt32(); var mbr = new ElaClassMember[cc]; for (var j = 0; j < cc; j++) { var m = new ElaClassMember(); m.Components = bw.ReadInt32(); m.Mask = bw.ReadInt32(); m.Name = bw.ReadString(); mbr[j] = m; } frame.InternalClasses.Add(k, new ClassData(mbr)); } c = bw.ReadInt32(); for (var i = 0; i < c; i++) { frame.InternalInstances.Add(new InstanceData( bw.ReadString(), bw.ReadString(), bw.ReadInt32(), bw.ReadInt32(), bw.ReadInt32(), bw.ReadInt32())); } c = bw.ReadInt32(); for (var i = 0; i < c; i++) { var ct = new ConstructorData { Code = -1, Name = bw.ReadString(), TypeName = bw.ReadString(), TypeModuleId = bw.ReadInt32() }; var cc = bw.ReadInt32(); if (cc > 0) { ct.Parameters = new List <String>(); for (var j = 0; j < cc; j++) { ct.Parameters.Add(bw.ReadString()); } } frame.InternalConstructors.Add(ct); } var di = bw.ReadBoolean(); if (di) { var sym = new DebugInfo(); c = bw.ReadInt32(); for (var i = 0; i < c; i++) { var ln = new LineSym(bw.ReadInt32(), bw.ReadInt32(), bw.ReadInt32()); sym.Lines.Add(ln); } c = bw.ReadInt32(); for (var i = 0; i < c; i++) { var fn = new FunSym(bw.ReadString(), bw.ReadInt32(), bw.ReadInt32()); fn.Handle = bw.ReadInt32(); fn.EndOffset = bw.ReadInt32(); sym.Functions.Add(fn); } frame.Symbols = sym; } return(frame); }
private void Write(CodeFrame frame, BinaryWriter bw) { bw.Write(Version); var v = new Version(Const.Version); bw.Write(v.Major); bw.Write(v.Minor); bw.Write(v.Build); bw.Write(v.Revision); var d = DateTime.Now.ToUniversalTime().Ticks; bw.Write(d); bw.Write(frame.References.Count); foreach (var kv in frame.References) { bw.Write(kv.Key); bw.Write(kv.Value.ModuleName); bw.Write(kv.Value.DllName ?? String.Empty); bw.Write(kv.Value.RequireQuailified); bw.Write(kv.Value.Path.Length); foreach (var p in kv.Value.Path) { bw.Write(p); } bw.Write(kv.Value.LogicalHandle); } bw.Write(frame.GlobalScope.Locals.Count); foreach (var kv in frame.GlobalScope.Locals) { bw.Write(kv.Key); bw.Write((Int32)kv.Value.Flags); bw.Write(kv.Value.Address); bw.Write(kv.Value.Data); } bw.Write(frame.LateBounds.Count); foreach (var u in frame.LateBounds) { bw.Write(u.Name); bw.Write(u.Address); bw.Write(u.Data); bw.Write(u.Flags); bw.Write(u.Line); bw.Write(u.Column); } bw.Write(frame.Layouts.Count); for (var i = 0; i < frame.Layouts.Count; i++) { var l = frame.Layouts[i]; bw.Write(l.Size); bw.Write(l.StackSize); bw.Write(l.Address); } bw.Write(frame.Strings.Count); for (var i = 0; i < frame.Strings.Count; i++) { bw.Write(frame.Strings[i]); } var ops = frame.Ops; bw.Write(ops.Count); for (var i = 0; i < ops.Count; i++) { var op = ops[i]; bw.Write((Byte)op); if (OpSizeHelper.OpSize[(Int32)op] > 1) { bw.Write(frame.OpData[i]); } } var types = frame.InternalTypes; bw.Write(types.Count); foreach (var kv in types) { bw.Write(kv.Key); if (kv.Value <= SysConst.MAX_TYP) { bw.Write(kv.Value); } else { bw.Write(-1); } } var classes = frame.InternalClasses; bw.Write(classes.Count); foreach (var kv in classes) { bw.Write(kv.Key); bw.Write(kv.Value.Members.Length); for (var i = 0; i < kv.Value.Members.Length; i++) { var m = kv.Value.Members[i]; bw.Write(m.Components); bw.Write(m.Mask); bw.Write(m.Name); } } var inst = frame.InternalInstances; bw.Write(inst.Count); for (var i = 0; i < inst.Count; i++) { var it = inst[i]; bw.Write(it.Type); bw.Write(it.Class); bw.Write(it.TypeModuleId); bw.Write(it.ClassModuleId); bw.Write(it.Line); bw.Write(it.Column); } var ctors = frame.InternalConstructors; bw.Write(ctors.Count); foreach (var ct in frame.InternalConstructors) { bw.Write(ct.Name); bw.Write(ct.TypeName); bw.Write(ct.TypeModuleId); if (ct.Parameters != null) { bw.Write(ct.Parameters.Count); for (var j = 0; j < ct.Parameters.Count; j++) { bw.Write(ct.Parameters[j]); } } else { bw.Write(0); } } var di = frame.Symbols != null; bw.Write(di); //Contains debug info if (di) { var sym = frame.Symbols; bw.Write(sym.Lines.Count); for (var i = 0; i < sym.Lines.Count; i++) { var ln = sym.Lines[i]; bw.Write(ln.Offset); bw.Write(ln.Line); bw.Write(ln.Column); } bw.Write(sym.Functions.Count); for (var i = 0; i < sym.Functions.Count; i++) { var fn = sym.Functions[i]; bw.Write(fn.Name ?? String.Empty); bw.Write(fn.StartOffset); bw.Write(fn.Parameters); bw.Write(fn.Handle); bw.Write(fn.EndOffset); } } }