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); } }