Example 0 - [Java] [Ideal] [Graph]
The goal here is to illustrate the nodes that appear on the most basic Java method.
                        
public void method0()
{
}
                        
                        
These four kinds of nodes are always present in any C2 IR graph. Note that the Start method has an additional "Parameter" which is the "this" pointer of the method.
                        
 0  Root    ===  0  21          [[ 0  1  3  	     ]] inner   Type:bottom
 3  Start   ===  3  0           [[ 3  5  6  7  8  9  ]] #{0:control, 1:abIO, 2:memory, 3:rawptr:BotPTR, 4:return_address,
                                                            5:IRStudy:NotNull *}
                                                        Type:{0:control, 1:abIO, 2:memory, 3:rawptr:BotPTR, 4:return_address,
                                                            5:IRStudy:NotNull *}
 5  Parm    ===  3              [[ 21                ]] Control  Type:control
 6  Parm    ===  3              [[ 21                ]] I_O  Type:abIO
 7  Parm    ===  3              [[ 21                ]] Memory  Memory: @BotPTR *+bot, idx=Bot;
 8  Parm    ===  3              [[ 21                ]] FramePtr  Type:rawptr:BotPTR
 9  Parm    ===  3              [[ 21                ]] ReturnAdr  Type:return_address
21  Return  ===  5  6  7  8  9  [[ 0                 ]] Type:bottom
                        
                        
 cesar 
Example 1 - [Java] [Ideal] [Graph]
This example is pretty much the same as the previous one, however, this method is static.
                        
public static void method1()
{
}
                        
                        
Example 2 - [Java] [Ideal] [Graph]
The goal of this example is to illustrate once more a method with parameters and that the "return" node will reference it.
                        
public int method2(int x)
{
    return x;
}
                        
                        
Example 3 - [Java] [Ideal] [Graph]
                            
public int method3(int a, int b, int c, int d, int e)
{
    return a + b + c + d + e;
}
                            
                        
Example 4 - [Java] [Ideal] [Graph]
                            
public long method4(long x, long y) {
    if (x > y) {
        return x;
    }
    else {
        return y;
    }
}
                            
                        
Example 5 - [Java] [Ideal] [Graph]
                            
public int method5(int x, int y, int z) {
    if (x > y) {
        return x*y;
    }
    else {
        return y*z;
    }
}
                            
                        
Example 6 - [Java] [Ideal] [Graph]
                            
public int method6(int x, int y, int z) {
    if (x > y) {
        if (x > z) {
            return x;
        }
        else {
            return z;
        }
    }

    return z;
}
                            
                        
Example 7 - [Java] [Ideal] [Graph]
                            
public int method7(int x, int y) {
    for (int i=0; i<1000; i++) {
        x += y;
    }
    return x;
}
                            
                        
Example 8 - [Java] [Ideal] [Graph]
                            
public int method8(String x, String y) {
    return Integer.valueOf(x) + Integer.valueOf(y);
}
                            
                        
Example 9 - [Java] [Ideal] [Graph]
                            
public int method9(IRStudy p) {
    return p.x;
}
                            
                        
Example 10 - [Java] [Ideal] [Graph]
                            
public int method10(Animal p) {
    if (p != null) {
        return p.age;
    }
    else {
        return 0;
    }
}
                            
                        
Example 11 - [Java] [Ideal] [Graph]
                            
public String method11(Animal p) {
    if (p != null) {
        return p.name;
    }
    else {
        return 0;
    }
}
                            
                        
Example 12 - [Java] [Ideal] [Graph]
This is the same code as the previous example, however the method was invoked with an instance of a subclass of Animal instead of an Animal object.
                            
public String method12(Animal p) {
    if (p != null) {
        return p.name;
    }
    else {
        return null;
    }
}
                            
                        
Example 13 - [Java] [Ideal] [Graph]
Similar to the previous 4 examples, however this time the method is accessing a field of the subclass. Note that the ConL used by AddP changed to 20.
                            
public String method13(Dog d) {
    return d.breed;
}
                            
                        
Example 14 - [Java] [Ideal] [Graph]
description
                            
public static MyPair method17() {
    MyPair m = new MyPair(0, 0);
    return m;
}
                            
                        
Example 15 - [Java] [Ideal] [Graph]
This example is to illustrate what happens when the same variable, in this case "a", is assigned in different control-flow paths.
                            
public static MyPair method18(boolean cond) {
    MyPair a = null;

    if (cond)
        a = new MyPair(0, 0);
    else
        a = new MyPair(1, 1);

    return a;
}