blob: dad4cd6b06d0e85c5d312b744c1a4cb9e486b0ee [file] [log] [blame]
// Copyright (c) 2021, the R8 project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
package com.android.tools.r8.ir.desugar.desugaredlibrary;
import com.android.tools.r8.graph.AppView;
import com.android.tools.r8.graph.DexClassAndMethod;
import com.android.tools.r8.ir.desugar.CfL8ClassSynthesizer;
import com.android.tools.r8.ir.desugar.CfL8ClassSynthesizerEventConsumer;
import com.android.tools.r8.utils.collections.DexClassAndMethodSet;
public class DesugaredLibraryRetargeterL8Synthesizer implements CfL8ClassSynthesizer {
private final AppView<?> appView;
private final DesugaredLibraryRetargeterSyntheticHelper syntheticHelper;
private final DexClassAndMethodSet emulatedDispatchMethods;
public static DesugaredLibraryRetargeterL8Synthesizer create(
AppView<?> appView, RetargetingInfo retargetingInfo) {
assert appView.options().isDesugaredLibraryCompilation();
if (retargetingInfo == null || retargetingInfo.getEmulatedDispatchMethods().isEmpty()) {
assert appView.options().desugaredLibraryConfiguration.getRetargetCoreLibMember().isEmpty();
return null;
}
return new DesugaredLibraryRetargeterL8Synthesizer(appView, retargetingInfo);
}
public DesugaredLibraryRetargeterL8Synthesizer(
AppView<?> appView, RetargetingInfo retargetingInfo) {
this.appView = appView;
this.syntheticHelper = new DesugaredLibraryRetargeterSyntheticHelper(appView);
emulatedDispatchMethods = retargetingInfo.getEmulatedDispatchMethods();
}
@Override
public void synthesizeClasses(CfL8ClassSynthesizerEventConsumer eventConsumer) {
assert !emulatedDispatchMethods.isEmpty();
for (DexClassAndMethod emulatedDispatchMethod : emulatedDispatchMethods) {
syntheticHelper.ensureProgramEmulatedHolderDispatchMethod(
emulatedDispatchMethod, eventConsumer);
}
}
}