# HG changeset patch # User twisti # Date 1398906489 36000 # Node ID 0e0c24424d142ee9c1ccb288498b643d3c2e3a44 # Parent 100306ae985b25cf78c8d83819b536d1de180940 added com.oracle.graal.api.code.RegisterSaveLayout.registerToSlot(Register) diff -r 100306ae985b -r 0e0c24424d14 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/RegisterSaveLayout.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/RegisterSaveLayout.java Wed Apr 30 12:27:27 2014 -0700 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/RegisterSaveLayout.java Wed Apr 30 15:08:09 2014 -1000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -33,16 +33,16 @@ /** * Keys. */ - private Register[] registers; + private final Register[] registers; /** * Slot indexes relative to stack pointer. */ - private int[] slots; + private final int[] slots; /** * Creates a map from registers to frame slots. - * + * * @param registers the keys in the map * @param slots frame slot index for each register in {@code registers} */ @@ -55,6 +55,21 @@ } /** + * Gets the frame slot index for a given register. + * + * @param register register to get the frame slot index for + * @return frame slot index + */ + public int registerToSlot(Register register) { + for (int i = 0; i < registers.length; i++) { + if (register.equals(registers[i])) { + return slots[i]; + } + } + throw new IllegalArgumentException(register + " not saved by this layout: " + this); + } + + /** * Gets this layout information as a {@link Map} from registers to slots. */ public Map registersToSlots(boolean sorted) {