Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
kekyo committed Jun 3, 2024
1 parent b7ca41e commit b76978e
Show file tree
Hide file tree
Showing 9 changed files with 556 additions and 280 deletions.
5 changes: 4 additions & 1 deletion chibild/chibild.core.Tests/LinkerTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ public static string RunCore(
{
try
{
logtw.Flush();
if (logfs.CanWrite)
{
logtw.Flush();
}
}
catch
{
Expand Down
3 changes: 2 additions & 1 deletion chibild/chibild.core/CilLinker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ injectToAssemblyPath is { } injectPath ?
// Will be injected exist (loaded) assembly.
if (injectToAssemblyPath != null)
{
primaryAssembly = ((AssemblyInputFragment)loadedFragments[0]).Assembly;
primaryAssembly = ((AssemblyInputFragment)loadedFragments[0]).
GetAssembly();
}
// Will be created a new assembly.
else
Expand Down
62 changes: 11 additions & 51 deletions chibild/chibild.core/Generating/ArchivedObjectInputFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,16 @@ private enum RequiredStates
private ArchivedObjectInputFragment(
string baseInputPath,
string relativePath,
string archivedObjectName,
Dictionary<string, Symbol> typeSymbols,
Dictionary<string, Symbol> variableSymbols,
Dictionary<string, Symbol> functionSymbols) :
AggregatedSymbols extraction) :
base(baseInputPath, relativePath)
{
this.archivedObjectName = archivedObjectName;
this.archivedObjectName = extraction.ObjectName;
this.ObjectName = Path.GetFileNameWithoutExtension(this.archivedObjectName);
this.ObjectPath = $"{this.archivedObjectName}@{base.ObjectPath}";

this.typeSymbols = typeSymbols;
this.variableSymbols = variableSymbols;
this.functionSymbols = functionSymbols;
this.typeSymbols = extraction.TypeSymbols;
this.variableSymbols = extraction.VariableSymbols;
this.functionSymbols = extraction.FunctionSymbols;
}

public override string ObjectName { get; }
Expand Down Expand Up @@ -162,14 +159,7 @@ public override bool ContainsFunctionAndSchedule(

//////////////////////////////////////////////////////////////

public enum LoadObjectResults
{
Ignored,
Loaded,
CaughtError,
}

public LoadObjectResults LoadObjectIfRequired(
public override LoadObjectResults LoadObjectIfRequired(
ILogger logger,
bool isLocationOriginSource)
{
Expand Down Expand Up @@ -239,42 +229,12 @@ public static ArchivedObjectInputFragment[] Load(

var symbolLists = ArchiverUtilities.EnumerateSymbolTable(
Path.Combine(baseInputPath, relativePath));

return symbolLists.Select(symbolList =>
{
var symbols = symbolList.Symbols.
GroupBy(symbol =>
{
switch (symbol.Directive)
{
case "enumeration": return "type";
case "structure": return "type";
case "global": return "variable";
case "constant": return "variable";
case "function": return "function";
default:
logger.Warning($"Ignored invalid symbol table entry: {symbol.Directive}");
return "unknown";
}
}).
ToDictionary(
g => g.Key,
g => g.
// Takes largest member count.
OrderByDescending(symbol => symbol.MemberCount ?? 0).
DistinctBy(symbol => symbol.Name).
ToDictionary(symbol => symbol.Name));
var empty = new Dictionary<string, Symbol>();
return new ArchivedObjectInputFragment(

return SymbolAggregator.AggregateSymbolsFromSymbolTable(logger, symbolLists).
Select(extraction => new ArchivedObjectInputFragment(
baseInputPath,
relativePath,
symbolList.ObjectName,
symbols.TryGetValue("type", out var types) ? types : empty,
symbols.TryGetValue("variable", out var variableNames) ? variableNames : empty,
symbols.TryGetValue("function", out var functionNames) ? functionNames : empty);
}).
ToArray();
extraction)).
ToArray();
}
}
Loading

0 comments on commit b76978e

Please sign in to comment.