private void GenerateTrace(StaticSymbolWindows staticSymbol) { if (!m_globalList.Contains(staticSymbol)) { m_globalList.Add(staticSymbol); m_addressMap.Add(staticSymbol.UniqueName, m_totalSize); m_totalSize += (int)staticSymbol.ByteList.Count; ISet <string> accessNameSet = new HashSet <string>(staticSymbol.AccessMap.Values); foreach (string accessName in accessNameSet) { StaticSymbolWindows accessSymbol; Error.Check(m_globalMap.TryGetValue(accessName, out accessSymbol), accessName, Message.Object_missing_in_linking); Debug.Assert(accessSymbol != null); GenerateTrace(accessSymbol); } ISet <string> callNameSet = new HashSet <string>(staticSymbol.CallMap.Values); foreach (string callName in callNameSet) { StaticSymbolWindows funcSymbol; Error.Check(m_globalMap.TryGetValue(callName, out funcSymbol), callName, Message.Function_missing_in_linking); Error.Check(funcSymbol != null, SimpleName(callName), Message.Missing_external_function); GenerateTrace(funcSymbol); } } }
public void Add(StaticSymbol staticSymbol) { StaticSymbolWindows staticSymbolWindows = (StaticSymbolWindows)staticSymbol; string uniqueName = staticSymbolWindows.UniqueName; if (!m_globalMap.ContainsKey(uniqueName)) { m_globalMap.Add(uniqueName, staticSymbolWindows); } else { Error.Check(uniqueName.EndsWith(Symbol.NumberId), SimpleName(uniqueName), Message.Duplicate_global_name); } }
public static void ReadObjectFile(FileInfo file, Linker linker) { FileInfo objectFile = new FileInfo(file.FullName + ".obj"); try { BinaryReader dataInputStream = new BinaryReader(File.OpenRead(objectFile.FullName)); int linkerSetSize = dataInputStream.ReadInt32(); for (int count = 0; count < linkerSetSize; ++count) { StaticSymbolWindows staticSymbol = new StaticSymbolWindows(); staticSymbol.Read(dataInputStream); linker.Add(staticSymbol); } dataInputStream.Close(); } catch (Exception exception) { Console.Out.WriteLine(exception.StackTrace); Assert.Error(exception.Message); } }
public void Generate(FileInfo targetFile) { Debug.Assert(m_globalMap.ContainsKey(AssemblyCodeGenerator.InitializerName)); StaticSymbolWindows initializerInfo = m_globalMap[AssemblyCodeGenerator.InitializerName]; m_globalList.Add(initializerInfo); m_totalSize += initializerInfo.ByteList.Count; m_addressMap.Add(AssemblyCodeGenerator.InitializerName, 0); StaticSymbolWindows pathNameSymbol = null; if (m_globalMap.ContainsKey(AssemblyCodeGenerator.ArgsName)) { StaticSymbolWindows argsInfo = m_globalMap[AssemblyCodeGenerator.ArgsName]; m_globalList.Add(argsInfo); Console.Out.WriteLine(argsInfo.UniqueName); m_totalSize += argsInfo.ByteList.Count; m_addressMap.Add(AssemblyCodeGenerator.ArgsName, 0); List <byte> byteList = new List <byte>(); IDictionary <int, string> accessMap = new Dictionary <int, string>(); pathNameSymbol = (StaticSymbolWindows) ConstantExpression.Value(AssemblyCodeGenerator.PathName, Type.StringType, @"C:\D\Main.com"); m_globalMap.Add(AssemblyCodeGenerator.PathName, pathNameSymbol); } StaticSymbolWindows mainInfo; Error.Check(m_globalMap.TryGetValue("main", out mainInfo), "non-static main", Message.Function_missing); GenerateTrace(mainInfo); if (pathNameSymbol != null) { Debug.Assert(!m_globalList.Contains(pathNameSymbol)); m_globalList.Add(pathNameSymbol); m_addressMap.Add(pathNameSymbol.UniqueName, m_totalSize); m_totalSize += (int)pathNameSymbol.ByteList.Count; } m_addressMap.Add(StackStart, m_totalSize); foreach (StaticSymbolWindows staticSymbol in m_globalList) { List <byte> byteList = staticSymbol.ByteList; int startAddress = m_addressMap[staticSymbol.UniqueName]; GenerateAccess(staticSymbol.AccessMap, byteList); GenerateCall(startAddress, staticSymbol.CallMap, byteList); GenerateReturn(startAddress, staticSymbol.ReturnSet, byteList); } { Console.Out.WriteLine("Generating \"" + targetFile.FullName + "\"."); targetFile.Delete(); BinaryWriter targetStream = new BinaryWriter(File.OpenWrite(targetFile.FullName)); foreach (StaticSymbolWindows staticSymbol in m_globalList) { foreach (sbyte b in staticSymbol.ByteList) { targetStream.Write(b); } } targetStream.Close(); } }