summaryrefslogtreecommitdiff
path: root/src/main/java/com/seaofnodes/simple/node/PtrToIntNode.java
blob: d3d380605a4fc96539147d29aec84c6f9de4041b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package com.seaofnodes.simple.node;


import com.seaofnodes.simple.Parser;
import com.seaofnodes.simple.type.Type;
import com.seaofnodes.simple.type.TypeInteger;
import com.seaofnodes.simple.type.TypeMemPtr;


/**
 * Reinterpret a non-null managed pointer as its raw integer address.
 *
 * This node changes representation families but emits no code.  No
 * control-dependent proof can turn a pointer into an integer; array-to-C-pointer
 * conversion adds the array body offset separately.
 */
public class PtrToIntNode extends Node {
    public PtrToIntNode(Node ptr) { super(null,ptr); }
    public PtrToIntNode(PtrToIntNode ptr) { super(ptr); }

    @Override public Tag serialTag() { return Tag.PtrToInt; }
    @Override protected String format() { return "(i64*)%1"; }

    @Override public Type compute() {
        return in(1)._type.isHigh() ? TypeInteger.TOP : TypeInteger.BOT;
    }

    @Override public Node idealize() { return null; }

    @Override public Parser.ParseException err() {
        Type t = in(1)._type;
        if( t instanceof TypeMemPtr ptr )
            return ptr.notNull() ? null : Parser.error("Cannot convert a nullable pointer to an integer",null);
        return Parser.error("Cannot convert "+t.str()+" to an integer pointer",null);
    }
}