changeset 7898:1aca91e4333d

fix Word.readByte/writeByte/readShort/writeShort/readChar/writeChar
author Lukas Stadler <lukas.stadler@jku.at>
date Wed, 27 Feb 2013 17:50:11 +0100
parents a58851061377
children 21ccfe2e180b
files graal/com.oracle.graal.word/src/com/oracle/graal/word/phases/WordTypeRewriterPhase.java
diffstat 1 files changed, 16 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.word/src/com/oracle/graal/word/phases/WordTypeRewriterPhase.java	Wed Feb 27 15:59:16 2013 +0100
+++ b/graal/com.oracle.graal.word/src/com/oracle/graal/word/phases/WordTypeRewriterPhase.java	Wed Feb 27 17:50:11 2013 +0100
@@ -139,12 +139,14 @@
 
                     case READ:
                         assert arguments.size() == 3;
-                        replace(invoke, readOp(graph, arguments.get(0), arguments.get(1), invoke, arguments.get(2).asConstant().asObject()));
+                        Kind readKind = asKind(callTargetNode.returnType());
+                        replace(invoke, readOp(graph, arguments.get(0), arguments.get(1), invoke, readKind, arguments.get(2).asConstant().asObject()));
                         break;
 
                     case WRITE:
                         assert arguments.size() == 4;
-                        replace(invoke, writeOp(graph, arguments.get(0), arguments.get(1), arguments.get(2), invoke, arguments.get(3).asConstant().asObject()));
+                        Kind writeKind = asKind(targetMethod.getSignature().getParameterType(1, targetMethod.getDeclaringClass()));
+                        replace(invoke, writeOp(graph, arguments.get(0), arguments.get(1), arguments.get(2), invoke, writeKind, arguments.get(3).asConstant().asObject()));
                         break;
 
                     case ZERO:
@@ -254,8 +256,8 @@
         return op;
     }
 
-    private static ValueNode readOp(StructuredGraph graph, ValueNode base, ValueNode offset, Invoke invoke, Object locationIdentity) {
-        IndexedLocationNode location = IndexedLocationNode.create(locationIdentity, invoke.node().kind(), 0, offset, graph, 1);
+    private static ValueNode readOp(StructuredGraph graph, ValueNode base, ValueNode offset, Invoke invoke, Kind readKind, Object locationIdentity) {
+        IndexedLocationNode location = IndexedLocationNode.create(locationIdentity, readKind, 0, offset, graph, 1);
         ReadNode read = graph.add(new ReadNode(base, location, invoke.node().stamp()));
         graph.addBeforeFixed(invoke.node(), read);
         // The read must not float outside its block otherwise it may float above an explicit zero
@@ -264,8 +266,8 @@
         return read;
     }
 
-    private static ValueNode writeOp(StructuredGraph graph, ValueNode base, ValueNode offset, ValueNode value, Invoke invoke, Object locationIdentity) {
-        IndexedLocationNode location = IndexedLocationNode.create(locationIdentity, value.kind(), 0, offset, graph, 1);
+    private static ValueNode writeOp(StructuredGraph graph, ValueNode base, ValueNode offset, ValueNode value, Invoke invoke, Kind writeKind, Object locationIdentity) {
+        IndexedLocationNode location = IndexedLocationNode.create(locationIdentity, writeKind, 0, offset, graph, 1);
         WriteNode write = graph.add(new WriteNode(base, value, location));
         graph.addBeforeFixed(invoke.node(), write);
         return write;
@@ -319,6 +321,14 @@
         return false;
     }
 
+    public Kind asKind(JavaType type) {
+        if (type instanceof ResolvedJavaType) {
+            return isWord((ResolvedJavaType) type) ? wordKind : type.getKind();
+        } else {
+            return Kind.Object;
+        }
+    }
+
     private void changeToWord(ValueNode valueNode) {
         if (valueNode.isConstant() && valueNode.asConstant().getKind() == Kind.Object) {
             WordBase value = (WordBase) valueNode.asConstant().asObject();