private void RecursiveDiscoverCompilationTree( LinkerTarget root, Dictionary <FileReference, LinkerTarget> targets) { if (root.FileCompilation.FileReferences.Count != 0) { foreach (FileReference reference in root.FileCompilation.FileReferences) { if (targets.ContainsKey(reference)) { continue; } if (File.Exists(reference.File)) { FileCompilation fc = new FileCompilation(reference); LinkerTarget t = new LinkerTarget(fc, fc.Reference.LinkerArguments); targets[reference] = t; RecursiveDiscoverCompilationTree(t, targets); } else { LinkerInfo info = LinkerInfo.Load(reference.File); FileCompilation fc = new FileCompilation(info); LinkerTarget t = new LinkerTarget(fc, new object[0]); targets[reference] = t; } } } }
public static void MakeHeader(string outputFile, string[] linkerFiles) { List <LinkerInfo> infos = new List <LinkerInfo>(); foreach (string path in linkerFiles) { if (!string.IsNullOrEmpty(path)) { infos.Add(LinkerInfo.Load(path)); } } StringBuilder sb = new StringBuilder(); foreach (LinkerInfo linkerInfo in infos) { foreach (KeyValuePair <string, AddressItem> linkerInfoLabel in linkerInfo.Labels) { sb.AppendLine(linkerInfoLabel.Key); } } File.WriteAllText(outputFile, sb.ToString()); }
public IExternalData[] ProcessImport(HlCompilation compilation, string input) { int tagLen = "link".Length + 1; if (input.Length < tagLen) { EventManager <ErrorEvent> .SendEvent(new InvalidLinkImporterArgumentsEvent( input )); return(new IExternalData[0]); } string cmd = input.Remove(0, tagLen); LinkerInfo info = LinkerInfo.Load(cmd); foreach (KeyValuePair <string, AddressItem> label in info.Labels) { if (label.Key.StartsWith("SFUN_")) { string raw = label.Key.Remove(0, "SFUN_".Length); int idx = raw.IndexOf("_"); string name = raw.Substring(0, idx); HlTypeDefinition tdef = compilation.TypeSystem.HasType(compilation.Root, name) ? compilation.TypeSystem.GetType(compilation.Root, name) : compilation.TypeSystem.CreateEmptyType( compilation.Root, name, true, false, false ); tdef.AddMember( new HlExternalFunctionDefinition( compilation.TypeSystem, compilation.Root, raw.Remove(0, idx + 1), label.Key, new List <IHlToken> { new HlTextToken( HlTokenType.OpPublicMod, "public", 0 ), new HlTextToken( HlTokenType.OpStaticMod, "static", 0 ) } ) ); } else if (label.Key.StartsWith("ADFUN_")) { string raw = label.Key.Remove(0, "ADFUN_".Length); int idx = raw.IndexOf("_"); string name = raw.Substring(0, idx); HlTypeDefinition tdef = compilation.TypeSystem.HasType(compilation.Root, name) ? compilation.TypeSystem.GetType(compilation.Root, name) : compilation.TypeSystem.CreateEmptyType( compilation.Root, name, true, false, false ); tdef.AddMember( new HlExternalFunctionDefinition( compilation.TypeSystem, compilation.Root, raw.Remove(0, idx + 1), label.Key, new List <IHlToken> { new HlTextToken( HlTokenType.OpPublicMod, "public", 0 ), new HlTextToken( HlTokenType.OpAbstractMod, "abstract", 0 ), } ) ); } else if (label.Key.StartsWith("DFUN_")) { string raw = label.Key.Remove(0, "DFUN_".Length); int idx = raw.IndexOf("_"); string name = raw.Substring(0, idx); HlTypeDefinition tdef = compilation.TypeSystem.HasType(compilation.Root, name) ? compilation.TypeSystem.GetType(compilation.Root, name) : compilation.TypeSystem.CreateEmptyType( compilation.Root, name, true, false, false ); tdef.AddMember( new HlExternalFunctionDefinition( compilation.TypeSystem, compilation.Root, raw.Remove(0, idx + 1), label.Key, new List <IHlToken> { new HlTextToken( HlTokenType.OpPublicMod, "public", 0 ), } ) ); } else if (label.Key.StartsWith("VDFUN_")) { string raw = label.Key.Remove(0, "VDFUN_".Length); int idx = raw.IndexOf("_"); string name = raw.Substring(0, idx); HlTypeDefinition tdef = compilation.TypeSystem.HasType(compilation.Root, name) ? compilation.TypeSystem.GetType(compilation.Root, name) : compilation.TypeSystem.CreateEmptyType( compilation.Root, name, true, false, false ); tdef.AddMember( new HlExternalFunctionDefinition( compilation.TypeSystem, compilation.Root, raw.Remove(0, idx + 1), label.Key, new List <IHlToken> { new HlTextToken( HlTokenType.OpPublicMod, "public", 0 ), new HlTextToken( HlTokenType.OpVirtualMod, "virtual", 0 ) } ) ); } } return(info.Labels. Select( x => (IExternalData) new LinkedData( x.Key, x.Value, ExternalDataType.Function ) ). Concat( info.DataSectionHeader.Select( x => (IExternalData) new LinkedData( x.Key, x.Value, ExternalDataType.Variable ) ) ). ToArray()); }
public void LoadSymbols(string binary) { LoadSymbols(LinkerInfo.Load(binary)); }