[LLVMdev] Passing String to an external function in llvm
David Blaikie
dblaikie at gmail.com
Thu Jul 25 11:16:46 PDT 2013
On Thu, Jul 25, 2013 at 11:07 AM, Abhinash Jain <omnia at mailinator.com> wrote:
> Thanx for the response.
>
> %x = alloca i32, align 4
> %y = alloca i32, align 4
> %a = alloca i32, align 4
> %t = alloca i32, align 4
>
> 1. %10 = load i32* %x, align 4
> 2. %11 = load i32* %y, align 4
> 3. %div = sdiv i32 %10, %11
> 4. %12 = load i32* %a, align 4
> 5. %mul4 = mul nsw i32 %div, %12
>
> 6. store i32 %mul4, i32* %t, align 4
> a. %mul4 = mul nsw i32 %div, %12
> b. %div = sdiv i32 %10, %11
> c. %10 = load i32* %x, align 4
> d. %11 = load i32* %y, align 4
> e. %12 = load i32* %a, align 4
>
> This is a IR of " t = x/y*a "
> The address of the "%x, %y, %a" are "0xbe4ab94, 0xbe4abd4, 0xbe4ac54"
> respectively.
> and the opcode of "*, /" are "12, 15" respectively.
>
> Point (6.a to 6.e) are the result of use-def chain, with the help of which
> I managed to make a string as -
>
> "12_15_0xbe4ab94_0xbe4abd4_0xbe4ac54" (by converting getOpcode() and
> getOperand() to string and than concatenating it)
>
> Now I want to pass this whole string to some other external function, How
> can I do this?
It's still rather unclear what you're attempting to achieve - are you
trying to pass this string to something else within the compiler? If
so, you'd pass a string the same way you'd pass any other string in
C++ (well, in LLVM:
void func(StringRef Str);
...
std::string foo = "12_15_....";
func(foo);
If you're trying to emit this string into the compiled binary &
produce a function call in that program... that's another story, but
again - looking at simple examples of code compiled by Clang should
give you an idea of what instructions you need to emit.
>
> If you want I can show you the full code.
>
>
>
> --
> View this message in context: http://llvm.1065342.n5.nabble.com/Passing-String-to-an-external-function-in-llvm-tp59798p59807.html
> Sent from the LLVM - Dev mailing list archive at Nabble.com.
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
More information about the llvm-dev
mailing list