Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/builtins/SLPrintlnBuiltin.java @ 14799:01afd501f127
Updated getStartBlock() in AbstractControlFlowGraph.
author | Josef Eisl <josef.eisl@jku.at> |
---|---|
date | Thu, 13 Mar 2014 17:18:48 +0100 |
parents | afd6fa5e8229 |
children | abe7128ca473 |
rev | line source |
---|---|
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * accompanied this code). |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * questions. |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 */ |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.sl.builtins; |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 |
13882
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
25 import java.io.*; |
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
26 |
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
27 import com.oracle.truffle.api.CompilerDirectives.SlowPath; |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
28 import com.oracle.truffle.api.dsl.*; |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
29 import com.oracle.truffle.api.nodes.*; |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
30 import com.oracle.truffle.sl.runtime.*; |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
31 |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
32 /** |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
33 * Builtin function to write a value to the {@link SLContext#getOutput() standard output}. The |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
34 * different specialization leverage the typed {@code println} methods available in Java, i.e., |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
35 * primitive values are printed without converting them to a {@link String} first. |
13882
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
36 * <p> |
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
37 * Printing involves a lot of Java code, so we need to tell the optimizing system that it should not |
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
38 * unconditionally inline everything reachable from the println() method. This is done via the |
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
39 * {@link SlowPath} annotations. |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
40 */ |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
41 @NodeInfo(shortName = "println") |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
42 public abstract class SLPrintlnBuiltin extends SLBuiltinNode { |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
43 |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
44 @Specialization |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
45 public long println(long value) { |
13882
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
46 doPrint(getContext().getOutput(), value); |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
47 return value; |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
48 } |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
49 |
13882
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
50 @SlowPath |
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
51 private static void doPrint(PrintStream out, long value) { |
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
52 out.println(value); |
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
53 } |
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
54 |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
55 @Specialization |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
56 public boolean println(boolean value) { |
13882
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
57 doPrint(getContext().getOutput(), value); |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
58 return value; |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
59 } |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
60 |
13882
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
61 @SlowPath |
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
62 private static void doPrint(PrintStream out, boolean value) { |
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
63 out.println(value); |
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
64 } |
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
65 |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
66 @Specialization |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
67 public String println(String value) { |
13882
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
68 doPrint(getContext().getOutput(), value); |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
69 return value; |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
70 } |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
71 |
13882
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
72 @SlowPath |
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
73 private static void doPrint(PrintStream out, String value) { |
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
74 out.println(value); |
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
75 } |
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
76 |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
77 @Specialization |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
78 public Object println(Object value) { |
13882
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
79 doPrint(getContext().getOutput(), value); |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
80 return value; |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
81 } |
13882
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
82 |
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
83 @SlowPath |
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
84 private static void doPrint(PrintStream out, Object value) { |
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
85 out.println(value); |
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
86 } |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
87 } |