[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NewInokeExpr and CmpXXX instructions in Jimple



On Sun, 16 Nov 2003, Venkatesh Prasad Ranganath wrote:

> Does NewInvokeExpr have any use in Jimple?  I am guessing not.  Am I
> right?  I am guessing that it is more relevant in Grimp.

NewInvokeExpr should only occur in Grimp, not Jimple.

> Also, there are CmpExpr, CmplExpr, and CmpgExpr expressions in Jimple
> along with 6 relational operator expressions.  I am guessing these
> latter 6 represent the if_icmp and/or if JVM instructions.

Correct: LeExpr, LtExpr, GeExpr, GtExpr, EqExpr, and NeExpr are to be used
exclusively inside an IfStmt.  These expressions don't have a translation
to Baf, unless they occur inside an IfStmt.  They return true or false.

> If so, I wonder to what is the mapping from CmpXXXX expressions to the
> JVM instructions?  Do they map to if_acmp, dcmp, and fcmp?

CmpExpr compares its two arguments (x,y) and returns 0 if they are, -1 if
x < y, +1 if x > y.  The Cmpl and Cmpg expressions act the same way, but
differ in their treatment of NaN.  These expressions translate directly to
the Cmp JVM instruction of the appropriate type (e.g.  fcmp{l,g} on
floats, cmp{l,g} on doubles, etc).  They are real expressions and can
occur anywhere, since they have a translation to Baf.

Note that the concrete JCmp*Expr is an AbstractIntBinopExpr, because its
return type is Int.

> However, as Jimple is typed, can't these also be represented by
> overloading a few of the former expressions?  I am trying to understand
> the intuition/reason behind CmpXXXX expressions in order to know how
> these influence any translation from Jimple to another representation.

I'm not sure why you mention typing.  The type system doesn't seem
relevant here, except to be confusing.

It seems to me that CmpExpr returns a lot more information than LtExpr;
there is no straightforward mapping of CmpExpr in terms of LtExpr, etc.
If you wanted to express LtExpr in terms of CmpExpr, then you need to
write (x < y) as (x cmp y) == -1.

pat