summaryrefslogtreecommitdiff
path: root/src/main/java/com/seaofnodes/simple/node/CastNode.java
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2026-08-10 11:11:18 -0700
committerCliff Click <cliffc@acm.org>2026-10-08 16:52:27 -0700
commitd32f97238c903765dec4e9a9f3cbfa5fd12cded6 (patch)
treea5ac731801ef7066bab6359c4e85c2bdd20082a6 /src/main/java/com/seaofnodes/simple/node/CastNode.java
parentb5ebb2032aa04cf4506d533127d373d4cf5a25c6 (diff)
downloadSimple-linear.tar.gz
Simple-linear.zip
Chapter 25: Modules, Separate Compilation, and SSA Constructionlinear
Co-authored-by: Hsiang-Ying Fu <66062782+fuhsnn@users.noreply.github.com> Co-authored-by: fuhsnn <66062782+fuhsnn@users.noreply.github.com> Co-authored-by: Symious <14933944+symious@users.noreply.github.com> Co-authored-by: Jun Kawasaki <jun784@gmail.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'src/main/java/com/seaofnodes/simple/node/CastNode.java')
-rw-r--r--src/main/java/com/seaofnodes/simple/node/CastNode.java71
1 files changed, 0 insertions, 71 deletions
diff --git a/src/main/java/com/seaofnodes/simple/node/CastNode.java b/src/main/java/com/seaofnodes/simple/node/CastNode.java
deleted file mode 100644
index 4e93f3e6..00000000
--- a/src/main/java/com/seaofnodes/simple/node/CastNode.java
+++ /dev/null
@@ -1,71 +0,0 @@
-package com.seaofnodes.simple.node;
-
-import com.seaofnodes.print.ExprPrinter;
-
-import com.seaofnodes.simple.Parser;
-import com.seaofnodes.simple.type.Type;
-import com.seaofnodes.simple.type.TypeInteger;
-import com.seaofnodes.simple.type.TypeMemPtr;
-import com.seaofnodes.simple.util.Utils;
-
-// Upcast (join) the input to a t. Used after guard test to lift an input.
-// Can also be used to make a type-assertion if ctrl is null.
-public class CastNode extends Node {
- public Type _t;
- public CastNode(Type t, Node ctrl, Node in) {
- super(ctrl, in);
- _t = t;
- setType(compute());
- }
-
- public CastNode(CastNode c) {
- super(c.in(0), c.in(1)); // Call parent constructor
- this._t = c._t; // Copy the Type field
- setType(compute()); // Ensure type is recomputed
- }
-
- @Override public String label() { return "("+_t.str()+")"; }
-
-
- @Override public boolean isConst() { return true; }
-
- @Override protected ExprPrinter<Node> _print1(ExprPrinter<Node> p) {
- return p.p(label()).n(in(1));
- }
-
- @Override
- public Type compute() {
- // Cast array to int
- Type t1 = in(1)._type;
- if( _t == TypeInteger.BOT && t1 instanceof TypeMemPtr tmp && tmp._obj.isAry() )
- return _t;
- // Freeze if the join is high but both inputs are low
- Type tj = t1.join(_t);
- if( tj.isHigh() && !t1.isHigh() )
- return _type==null ? _t : _type;
-
- return tj;
- }
-
- @Override
- public Node idealize() {
- return in(1)._type.isa(_t) && in(1)._type.accessISA(_t) ? in(1) : null;
- }
-
- @Override
- public boolean eq(Node n) {
- CastNode cast = (CastNode)n; // Contract
- return _t==cast._t;
- }
-
- @Override
- int hash() { return _t.hashCode(); }
-
- @Override
- public Parser.ParseException err() {
- // Has a condition to test, so OK
- if( in(0) != null ) return null;
- // No condition to test, so this must optimize away
- return Parser.error( "Type " + in(1)._type.str() + " is not of declared type " + _t.str(), null );
- }
-}