// Copyright (c) StellaOps. All rights reserved.
// Licensed under AGPL-3.0-or-later. See LICENSE in the project root.
// Sprint: SPRINT_20260112_004_BINIDX_b2r2_lowuir_perf_cache (BINIDX-LIFTER-02)
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using StellaOps.BinaryIndex.Semantic;
namespace StellaOps.BinaryIndex.Disassembly.B2R2;
///
/// Extension methods for registering the B2R2 disassembly plugin.
///
public static class B2R2ServiceCollectionExtensions
{
///
/// Adds the B2R2 disassembly plugin to the service collection.
/// Provides multi-architecture disassembly (x86, x64, ARM32, ARM64, MIPS, RISC-V, etc.).
///
/// The service collection.
/// The service collection for chaining.
public static IServiceCollection AddB2R2DisassemblyPlugin(this IServiceCollection services)
{
ArgumentNullException.ThrowIfNull(services);
services.TryAddEnumerable(ServiceDescriptor.Singleton());
return services;
}
///
/// Adds the B2R2 lifter pool to the service collection.
/// Provides pooled lifters with warm preload for improved performance.
///
/// The service collection.
/// Configuration for binding pool options.
/// The service collection for chaining.
public static IServiceCollection AddB2R2LifterPool(
this IServiceCollection services,
IConfiguration? configuration = null)
{
ArgumentNullException.ThrowIfNull(services);
if (configuration != null)
{
services.Configure(
configuration.GetSection(B2R2LifterPoolOptions.SectionName));
}
else
{
services.Configure(_ => { });
}
services.TryAddSingleton();
return services;
}
///
/// Adds the B2R2 LowUIR lifting service to the service collection.
/// Provides IR lifting with B2R2 LowUIR semantics.
///
/// The service collection.
/// The service collection for chaining.
public static IServiceCollection AddB2R2LowUirLiftingService(this IServiceCollection services)
{
ArgumentNullException.ThrowIfNull(services);
services.TryAddSingleton();
return services;
}
///
/// Adds all B2R2 services to the service collection.
///
/// The service collection.
/// Configuration for binding options.
/// The service collection for chaining.
public static IServiceCollection AddB2R2Services(
this IServiceCollection services,
IConfiguration? configuration = null)
{
ArgumentNullException.ThrowIfNull(services);
services.AddB2R2DisassemblyPlugin();
services.AddB2R2LifterPool(configuration);
services.AddB2R2LowUirLiftingService();
return services;
}
}