2 * Copyright (C) 2007 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.dx.dex.code;
19 import com.android.dx.rop.code.RegisterSpec;
20 import com.android.dx.rop.code.RegisterSpecList;
21 import com.android.dx.rop.code.SourcePosition;
24 * Pseudo-instruction which is used to introduce a new local variable. That
25 * is, an instance of this class in an instruction stream indicates that
26 * starting with the subsequent instruction, the indicated variable
29 public final class LocalStart extends ZeroSizeInsn {
31 * {@code non-null;} register spec representing the local variable introduced
34 private final RegisterSpec local;
37 * Returns the local variable listing string for a single register spec.
39 * @param spec {@code non-null;} the spec to convert
40 * @return {@code non-null;} the string form
42 public static String localString(RegisterSpec spec) {
43 return spec.regString() + ' ' + spec.getLocalItem().toString() + ": " +
44 spec.getTypeBearer().toHuman();
48 * Constructs an instance. The output address of this instance is initially
49 * unknown ({@code -1}).
51 * @param position {@code non-null;} source position
52 * @param local {@code non-null;} register spec representing the local
53 * variable introduced by this instance
55 public LocalStart(SourcePosition position, RegisterSpec local) {
59 throw new NullPointerException("local == null");
67 public DalvInsn withRegisterOffset(int delta) {
68 return new LocalStart(getPosition(), local.withOffset(delta));
73 public DalvInsn withRegisters(RegisterSpecList registers) {
74 return new LocalStart(getPosition(), local);
78 * Gets the register spec representing the local variable introduced
81 * @return {@code non-null;} the register spec
83 public RegisterSpec getLocal() {
89 protected String argString() {
90 return local.toString();
95 protected String listingString0(boolean noteIndices) {
96 return "local-start " + localString(local);