LARA

Translation of Relations

Consider translation of <,=,⇐,>,>=,=,!= on integers

Operations of type

int => int => {0,1}

But there are no instructions that do this

There are conditional branches for comparison of two stack operands:

for different 'OP'

Compilation scheme

  • assuming translations compute results on top of the stack
[[ e1 COND e2 ]] =
        [[ e1 ]]
        [[ e2 ]]
        if_icmpCOND nTrue
        bipush 0
        goto nAfter
nTrue:  
        bipush 1
nAfter:

Example

static boolean test(int x, int y) {
  return (x < y);
}

Bytecode:

static boolean test(int, int);
  Code:
   0:   iload_0
   1:   iload_1
   2:   if_icmpge       9
   5:   iconst_1
   6:   goto    10
   9:   iconst_0
   10:  ireturn

Note:

  • iconst is a shorter form for bipush
  • the code above uses the dual branch and swaps constants true and false