0

I want to insert integer variable into all classes using LLVM PASS or Clang.

How to do this ?

For example..

class foo {
     int a;
}

I want to insert new value as below.

class foo {
     int a;
     unsigned int b; // I want to insert this.
}

How can I do this using LLVM PASS or Clang ? - I much prefer LLVM PASS.

Thank you very much :)

Zzingco
  • 41
  • 5

1 Answers1

0

My recommendation would be to use Clang for this, as LLVM operates on bitcode (IR) and the operation you want is very much C++ related, so why not exploit Clang's knowledge about the AST?

With LibTooling you can write stand-alone tool to do exactly what you want. More specifically, use an AST Matcher to find all C++ class declarations (cxxRecordDecl). You can then insert a new FieldDecl in your callback.

More info: LibTooling and LibASTMatchers Tutorial

Jonas
  • 1,021
  • 11
  • 17