Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
kekyo committed Apr 29, 2024
1 parent 4580b15 commit 26dadb1
Show file tree
Hide file tree
Showing 8 changed files with 326 additions and 284 deletions.
2 changes: 1 addition & 1 deletion chibild/chibild.core/CilLinker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ injectToAssemblyPath is { } injectPath ?

var codeGenerator = new CodeGenerator(
this.logger,
targetModule,
produceDebuggingInformation);

if (!codeGenerator.ConsumeInputs(
Expand All @@ -364,7 +365,6 @@ injectToAssemblyPath is { } injectPath ?

if (!codeGenerator.Emit(
loadedFragments,
targetModule,
applyOptimization,
targetFramework,
disableJITOptimization,
Expand Down
33 changes: 21 additions & 12 deletions chibild/chibild.core/Generating/CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using chibicc.toolchain.Parsing;

namespace chibild.Generating;

Expand All @@ -27,6 +28,7 @@ internal sealed partial class CodeGenerator
// during which time multithreading speedup is achieved.

private readonly ILogger logger;
private readonly ModuleDefinition targetModule;
private readonly bool produceDebuggingInformation;

private readonly Queue<Action<ModuleDefinition>> delayLookingUpEntries1 = new();
Expand All @@ -38,9 +40,11 @@ internal sealed partial class CodeGenerator

public CodeGenerator(
ILogger logger,
ModuleDefinition targetModule,
bool produceDebuggingInformation)
{
this.logger = logger;
this.targetModule = targetModule;
this.produceDebuggingInformation = produceDebuggingInformation;
}

Expand All @@ -67,73 +71,78 @@ private void ConsumeFragment(
{
currentFragment.ClearDeclarations();

var context = new LookupContext(
this.targetModule,
currentFragment,
inputFragments);

#if DEBUG
foreach (var variable in currentFragment.GlobalVariables)
{
this.ConsumeGlobalVariable(currentFragment, inputFragments, variable);
this.ConsumeGlobalVariable(context, variable);
}
foreach (var constant in currentFragment.GlobalConstants)
{
this.ConsumeGlobalConstant(currentFragment, inputFragments, constant);
this.ConsumeGlobalConstant(context, constant);
}
foreach (var function in currentFragment.Functions)
{
this.ConsumeFunction(currentFragment, inputFragments, function);
this.ConsumeFunction(context, function);
}
foreach (var initializer in currentFragment.Initializers)
{
this.ConsumeInitializer(currentFragment, inputFragments, initializer);
this.ConsumeInitializer(context, initializer);
}
foreach (var enumeration in currentFragment.Enumerations)
{
this.ConsumeEnumeration(currentFragment, inputFragments, enumeration);
this.ConsumeEnumeration(context, enumeration);
}
foreach (var structure in currentFragment.Structures)
{
this.ConsumeStructure(currentFragment, inputFragments, structure);
this.ConsumeStructure(context, structure);
}
#else
Parallel.Invoke(
() =>
{
foreach (var variable in currentFragment.GlobalVariables)
{
this.ConsumeGlobalVariable(currentFragment, inputFragments, variable);
this.ConsumeGlobalVariable(context, variable);
}
},
() =>
{
foreach (var constant in currentFragment.GlobalConstants)
{
this.ConsumeGlobalConstant(currentFragment, inputFragments, constant);
this.ConsumeGlobalConstant(context, constant);
}
},
() =>
{
foreach (var function in currentFragment.Functions)
{
this.ConsumeFunction(currentFragment, inputFragments, function);
this.ConsumeFunction(context, function);
}
},
() =>
{
foreach (var initializer in currentFragment.Initializers)
{
this.ConsumeInitializer(currentFragment, inputFragments, initializer);
this.ConsumeInitializer(context, initializer);
}
},
() =>
{
foreach (var enumeration in currentFragment.Enumerations)
{
this.ConsumeEnumeration(currentFragment, inputFragments, enumeration);
this.ConsumeEnumeration(context, enumeration);
}
},
() =>
{
foreach (var structure in currentFragment.Structures)
{
this.ConsumeStructure(currentFragment, inputFragments, structure);
this.ConsumeStructure(context, structure);
}
});
#endif
Expand Down
Loading

0 comments on commit 26dadb1

Please sign in to comment.