comparison graal/com.oracle.max.cri/src/com/oracle/max/cri/xir/XirSnippet.java @ 4199:aaac4894175c

Renamed cri packages from sun to oracle.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Tue, 03 Jan 2012 16:29:28 +0100
parents graal/com.oracle.max.cri/src/com/sun/cri/xir/XirSnippet.java@bc8527f3071c
children 1aaf3592e516
comparison
equal deleted inserted replaced
4198:8c9c0e1eaab1 4199:aaac4894175c
1 /*
2 * Copyright (c) 2009, 2011, 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 com.oracle.max.cri.xir;
24
25 import java.util.*;
26
27 import com.oracle.max.cri.ci.*;
28 import com.oracle.max.cri.ci.CiTargetMethod.*;
29 import com.oracle.max.cri.xir.CiXirAssembler.*;
30
31 /**
32 * Represents a {@link XirTemplate template of XIR} along with the {@link XirArgument arguments} to be passed to the
33 * template. The runtime generates such snippets for each bytecode being compiled at the request of the compiler, and
34 * the compiler can generate machine code for the XIR snippet.
35 */
36 public class XirSnippet {
37
38 public final XirArgument[] arguments;
39 public final XirTemplate template;
40 public final Map<XirMark, Mark> marks;
41
42 public XirSnippet(XirTemplate template, XirArgument... inputs) {
43 assert template != null;
44 this.template = template;
45 this.arguments = inputs;
46 this.marks = (template.marks != null && template.marks.length > 0) ? new HashMap<XirMark, Mark>() : null;
47 assert assertArgumentsCorrect();
48 }
49
50 private boolean assertArgumentsCorrect() {
51 int argLength = arguments == null ? 0 : arguments.length;
52 int paramLength = template.parameters == null ? 0 : template.parameters.length;
53 assert argLength == paramLength : "expected param count: " + paramLength + ", actual: " + argLength;
54 for (int i = 0; i < arguments.length; i++) {
55 assert assertArgumentCorrect(template.parameters[i], arguments[i]) : "mismatch in parameter " + i + ": " + arguments[i] + " instead of " + template.parameters[i];
56 }
57 return true;
58 }
59
60 private static boolean assertArgumentCorrect(XirParameter param, XirArgument arg) {
61 if (param.kind == CiKind.Illegal || param.kind == CiKind.Void) {
62 if (arg != null) {
63 return false;
64 }
65 } else {
66 if (arg == null) {
67 return false;
68 }
69 if (arg.constant != null) {
70 if (arg.constant != null && arg.constant.kind != param.kind) {
71 return false;
72 }
73 }
74 }
75 return true;
76 }
77
78 @Override
79 public String toString() {
80
81 StringBuffer sb = new StringBuffer();
82
83 sb.append(template.toString());
84 sb.append("(");
85 for (XirArgument a : arguments) {
86 sb.append(" ");
87 sb.append(a);
88 }
89
90 sb.append(" )");
91
92 return sb.toString();
93 }
94 }