1/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.dexgen.rop.code;
18
19/**
20 * Interface for "advice" passed from the late stage of translation back
21 * to the early stage. This allows for the final target architecture to
22 * exert its influence early in the translation process without having
23 * the early stage code be explicitly tied to the target.
24 */
25public interface TranslationAdvice {
26    /**
27     * Returns an indication of whether the target can directly represent an
28     * instruction with the given opcode operating on the given arguments,
29     * where the last source argument is used as a constant. (That is, the
30     * last argument must have a type which indicates it is a known constant.)
31     * The instruction associated must have exactly two sources.
32     *
33     * @param opcode {@code non-null;} the opcode
34     * @param sourceA {@code non-null;} the first source
35     * @param sourceB {@code non-null;} the second source
36     * @return {@code true} iff the target can represent the operation
37     * using a constant for the last argument
38     */
39    public boolean hasConstantOperation(Rop opcode,
40            RegisterSpec sourceA, RegisterSpec sourceB);
41
42    /**
43     * Returns true if the translation target requires the sources of the
44     * specified opcode to be in order and contiguous (eg, for an invoke-range)
45     *
46     * @param opcode {@code non-null;} opcode
47     * @param sources {@code non-null;} source list
48     * @return {@code true} iff the target requires the sources to be
49     * in order and contiguous.
50     */
51    public boolean requiresSourcesInOrder(Rop opcode, RegisterSpecList sources);
52
53    /**
54     * Gets the maximum register width that can be represented optimally.
55     * For example, Dex bytecode does not have instruction forms that take
56     * register numbers larger than 15 for all instructions so
57     * DexTranslationAdvice returns 15 here.
58     *
59     * @return register count noted above
60     */
61    public int getMaxOptimalRegisterCount();
62}
63