Monday 15 July 2013

Outputting input's constant char array from llvm pass -


All

I want to know how an ALVVM pass output defined by the input source is a fixed four array. Here is an example that I Want to do

Test Input Source

  char * msg = "Hello, World \ n"; Zero msg_out (four * in) {printf ("msg:% s \ n", in); } Main () {... msg_out (msg); ...}   

llvm pass snippet

  ... const callinst * ci = dyn_cast & lt; CallInst & gt; (Val); Const function * func = ci-> GetCalledFunction (); If (fancy-> getName () == "msg_out") {errs () & lt; & Lt; Ci- & gt; GetOperand (0); } ...   

With the source, the following LL.M. will print the following output.

Output

  i8 * getelementptr inbounds ([8 x i8] * @ 10, i32 0, i32 0)  <  
  • However, if I want to implement it,
    1. Identify the first argument is a continuous character array
    2. If so, then "Hello, the world" N "

      Can anyone print me tell how to apply it?

      Thank you very much for your help! First, the first logic not is a fixed character array; This is an indicator, so getelementptr (GEP). In any case, the proper way to do this is to dereference GEP's pointer, if it is a global, then get its initial information. In your case (and gep actually since A), it should look like this:

        value * op0 = ci-> GetOperand (0); If (Global Vibrant * Global = Darkcast & gt; GlobalWeible> (GP- & amp;; GetOperand (0))) (if (ConstantDataArray * array = dyn_cast & lt; ConstantDataArea (Global-to- & Gt ; GetInitializer ())) Click on {if (array-> isCString ()) Return ARAR-> GetAsCString ();}}}    

  • No comments:

    Post a Comment