1 /*
   2  * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.graalvm.compiler.core.common.alloc;
  24 
  25 import java.util.ArrayList;
  26 import java.util.Arrays;
  27 import java.util.Collection;
  28 
  29 import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
  30 
  31 /**
  32  * Represents a list of sequentially executed {@code AbstractBlockBase blocks}.
  33  */
  34 public class Trace {
  35     private final AbstractBlockBase<?>[] blocks;
  36     private final ArrayList<Trace> successors;
  37     private int id = -1;
  38 
  39     public Trace(Collection<AbstractBlockBase<?>> blocks) {
  40         this(blocks.toArray(new AbstractBlockBase<?>[0]));
  41     }
  42 
  43     public Trace(AbstractBlockBase<?>[] blocks) {
  44         this.blocks = blocks;
  45         this.successors = new ArrayList<>();
  46     }
  47 
  48     public AbstractBlockBase<?>[] getBlocks() {
  49         return blocks;
  50     }
  51 
  52     public ArrayList<Trace> getSuccessors() {
  53         return successors;
  54     }
  55 
  56     public int size() {
  57         return getBlocks().length;
  58     }
  59 
  60     @Override
  61     public String toString() {
  62         return "Trace" + Arrays.toString(blocks);
  63     }
  64 
  65     public int getId() {
  66         assert id != -1 : "id not initialized!";
  67         return id;
  68     }
  69 
  70     void setId(int id) {
  71         this.id = id;
  72     }
  73 }