[llvm-dev] building a custom plugin

Osanne Gbayere via llvm-dev llvm-dev at lists.llvm.org
Fri Aug 9 05:23:08 PDT 2019


Hey LLVM Devs,

  I am trying to see if I can use clang plugins to edit
the AST and change the executable output. Any pointers on
whether I'm doing this correctly?

running my plugin:
clang -Xclang -load -Xclang C:\Users\User\llvm-project\build\Release\bin\MyPlugin.dll -Xclang -add-plugin -Xclang my-plugin test.c -o test.exe

how i'm editing the AST (in my Visitor class):
varDecl->setInit(stringLiteral)


Note: The test.exe generated in the above process does not appear to be affected by any changes made to the AST by the plugin

Cheers,

Osanne


________________________________
From: Michael Kruse <llvmdev at meinersbur.de>
Sent: 08 August 2019 17:19
To: Osanne Gbayere <osanne_lukengo at hotmail.com>
Cc: Michael Kruse <llvmdev at meinersbur.de>
Subject: Re: [llvm-dev] building a custom plugin

Good to hear that it works for you. However, I don't know anything about modifying the AST from an plugin.

When discussing on the mailing list, please _always_ reply (or reply-all) to the mailing list to keep the discussion public. One reason being that you can get answers from other people as well, the other that contributors volunteer for the community.

Michael



Am Do., 8. Aug. 2019 um 05:27 Uhr schrieb Osanne Gbayere <osanne_lukengo at hotmail.com<mailto:osanne_lukengo at hotmail.com>>:
Hey Michael,

  Thank you very much for your help. It's much appreciated!

  Got my plugin working, trying to see now if I can use it to edit
the AST and change the executable output. Any pointers on
whether I'm doing this correctly?

running my plugin:
clang -Xclang -load -Xclang C:\Users\User\llvm-project\build\Release\bin\MyPlugin.dll -Xclang -add-plugin -Xclang my-plugin test.c -o test.exe

how i'm editing the AST (in my Visitor class):
varDecl->setInit(stringLiteral)

Cheers,

Osanne

________________________________
From: Michael Kruse <llvmdev at meinersbur.de<mailto:llvmdev at meinersbur.de>>
Sent: Tuesday, August 6, 2019 4:58:02 PM
To: Osanne Gbayere <osanne_lukengo at hotmail.com<mailto:osanne_lukengo at hotmail.com>>
Cc: Michael Kruse <llvmdev at meinersbur.de<mailto:llvmdev at meinersbur.de>>
Subject: Re: [llvm-dev] building a custom plugin

add_llvm_library is a function defined in cmake/modules/AddLLVM.cmake. In order to use it, you must include(AddLLVM) in your CMakeLists.txt. This has already been done if, like PrintFunctionNames, the CMakeLists.txt is invoked from within LLVM's cmake configuration run. If you want to have your plugin to compile independently of LLVM (using an LLVM found on your system), Your CMakeLists.txt has to to search for the LLVM installation via CMake's find_package(LLVM ...). See [1]

To get things started, I suggest you copy the PrintFunctionNames to e.g. PrintFunctionNames2 as a sibling folder and add add_subdirectory(PrintFunctionNames2) in the parent dir's CMakeLists.txt

Michael


[1] https://www.llvm.org/docs/CMake.html#embedding-llvm-in-your-project



Am Di., 6. Aug. 2019 um 03:41 Uhr schrieb Osanne Gbayere <osanne_lukengo at hotmail.com<mailto:osanne_lukengo at hotmail.com>>:
Hi Michael,

  Thanks for this! I've attempted to run CMake to build PrintFunctionNames with success, however with my
custom plugin and also when I try to build PrintFunctionNames individually, I get the following error:

CMake Error at CMakeLists.txt:1 (add_llvm_library):
  Unknown CMake command "add_llvm_library".

I haven't found much in the way of solving this issue. Are there any libraries I need to add to my CMake
environment?

Cheers,

Osanne
________________________________
From: Michael Kruse <llvmdev at meinersbur.de<mailto:llvmdev at meinersbur.de>>
Sent: Friday, August 2, 2019 8:46:59 PM
To: Osanne Gbayere <osanne_lukengo at hotmail.com<mailto:osanne_lukengo at hotmail.com>>
Cc: llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org> <llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>>
Subject: Re: [llvm-dev] building a custom plugin

The code for building the PrintFunctionNames plugin is available here:

https://github.com/llvm/llvm-project/blob/master/clang/examples/PrintFunctionNames/CMakeLists.txt

Michael

[X]<http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=oa-4885-a>  Virus-free. www.avg.com<http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=oa-4885-a>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190809/c5a4d1e5/attachment.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Source1.cpp
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190809/c5a4d1e5/attachment.ksh>


More information about the llvm-dev mailing list