Skip to content

Commit

Permalink
Changed to use ArchiveReader on the linker.
Browse files Browse the repository at this point in the history
  • Loading branch information
kekyo committed Jan 5, 2025
1 parent 71e4377 commit 31d2273
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
17 changes: 11 additions & 6 deletions chibild/chibild.core/Generating/ArchivedObjectInputFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ private enum RequiredStates
Loaded,
}

private readonly ArchiveReader archiveReader;
private readonly string archivedObjectName;

private readonly Dictionary<string, Symbol> typeSymbols;
Expand All @@ -58,12 +59,14 @@ private enum RequiredStates
private ArchivedObjectInputFragment(
string baseInputPath,
string relativePath,
ArchiveReader archiveReader,
string archivedObjectName,
Dictionary<string, Symbol> typeSymbols,
Dictionary<string, Symbol> variableSymbols,
Dictionary<string, Symbol> functionSymbols) :
base(baseInputPath, relativePath)
{
this.archiveReader = archiveReader;
this.archivedObjectName = archivedObjectName;
this.ObjectName = Path.GetFileNameWithoutExtension(this.archivedObjectName);
this.ObjectPath = $"{this.archivedObjectName}@{base.ObjectPath}";
Expand Down Expand Up @@ -181,19 +184,18 @@ public LoadObjectResults LoadObjectIfRequired(
{
logger.Information($"Loading: {this.ObjectPath}");

if (!ArchiverUtilities.TryOpenArchivedObject(
Path.Combine(this.BaseInputPath, this.RelativePath),
if (!this.archiveReader.TryOpenObjectStream(
this.archivedObjectName,
true,
out var stream))
out var objectStream))
{
logger.Error(
$"Unable find an object on archive: ObjectName={this.archivedObjectName}, ArchiveFile={this.RelativePath}");
return LoadObjectResults.CaughtError;
}

using var _s = stream;
var tr = StreamUtilities.CreateTextReader(stream);
using var _ = objectStream;
var tr = StreamUtilities.CreateTextReader(objectStream);

var parser = new CilParser(logger);
var declarations = parser.Parse(
Expand Down Expand Up @@ -238,8 +240,10 @@ public static ArchivedObjectInputFragment[] Load(
{
logger.Information($"Loading symbol table: {relativePath}");

var symbolLists = ArchiverUtilities.EnumerateSymbolListFromArchive(
var archiveReader = new ArchiveReader(
Path.Combine(baseInputPath, relativePath));

var symbolLists = archiveReader.EnumerateSymbolListFromArchive();

return symbolLists.Select(symbolList =>
{
Expand Down Expand Up @@ -271,6 +275,7 @@ public static ArchivedObjectInputFragment[] Load(
return new ArchivedObjectInputFragment(
baseInputPath,
relativePath,
archiveReader,
symbolList.ObjectName,
symbols.TryGetValue("type", out var types) ? types : empty,
symbols.TryGetValue("variable", out var variableNames) ? variableNames : empty,
Expand Down
17 changes: 1 addition & 16 deletions toolchain.common/Archiving/ArchiverUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,8 @@ public static IObjectItemDescriptor[] LoadArchivedObjectItemDescriptors(
////////////////////////////////////////////////////////////////////

public static IEnumerable<SymbolList> EnumerateSymbolListFromArchive(
string archiveFilePath)
this ArchiveReader archiveReader)
{
var archiveReader = new ArchiveReader(
archiveFilePath, [ SymbolTableFileName ]);

if (archiveReader.TryOpenObjectStream(
SymbolTableFileName, true, out var symbolTableStream))
{
Expand Down Expand Up @@ -383,16 +380,4 @@ tokens[2] is (TokenTypes.Identity, var name):
}
}
}

public static bool TryOpenArchivedObject(
string archiveFilePath,
string objectName,
bool decodedBody,
out Stream stream)
{
var archiveReader = new ArchiveReader(
archiveFilePath, [ objectName ]);
return archiveReader.TryOpenObjectStream(
objectName, decodedBody, out stream);
}
}

0 comments on commit 31d2273

Please sign in to comment.