Tommy, so what u mean is there is no way I can detect field read and write in 
this case?

But how come Jb said "So if you want to detect where PI is used, you have to 
check for the `ldc.r8 Math.PI` pattern."? My previous post was trying to say 
that I can't find this.



From: Tommy Carlier 
Sent: Sunday, January 10, 2010 8:21 PM
To: [email protected] 
Subject: Re: [mono-cecil] Field read and write


Because Math.PI is a constant, the compiler will just copy its value to the 
location of where it's used. So, if your code says "double pi = Math.PI;", the 
compiler will translate it to "double pi = 3.1415926...;". That's why there are 
no references to Math.PI.


2010/1/10 Wee Li Yen <[email protected]>

  Sorry to bother you on this issue again.

  I print out all the instructions from VisitInstruction (BaseCodeVisitor) in 
this way:

            OpCode opCode = instr.OpCode;
            object operand = instr.Operand;
            Console.Write("###" + opCode + " " + ((operand != null)? 
operand.ToString() : "") + "###");
            Console.WriteLine();

  But I don't see ldc.r8 Math.PI...

  Do you know why? Thanks...




  --------------------------------------------------
  From: "Jb Evain" <[email protected]>
  Sent: Friday, January 08, 2010 5:58 PM
  To: <[email protected]>
  Subject: Re: [mono-cecil] Field read and write


    2010/1/8 Li Yen Wee <[email protected]>:

      But how has it got to do with me not being able to detect the field 
PIValue
      as written and Math.PI as read?


    Again, if you had bothered to investigate a little bit you would know.
    PI is defined as a constant, so the compiler will inline its value
    everywhere it's used

    var pi = Math.PI is compiled as:

    ldc.r8 3.1415926535897931
    stloc pi

    So if you want to detect where PI is used, you have to check for the
    `ldc.r8 Math.PI` pattern.

    -- 
    Jb Evain  <[email protected]>






    -- 
    --
    mono-cecil 



  --
  --
  mono-cecil





--------------------------------------------------------------------------------


-- 
--
mono-cecil
-- 
--
mono-cecil

Reply via email to