INRIA / spoon

Spoon is a metaprogramming library to analyze and transform Java source code. :spoon: is made with :heart:, :beers: and :sparkles:. It parses source files to build a well-designed AST with powerful analysis and transformation API.
http://spoon.gforge.inria.fr/
Other
1.72k stars 344 forks source link

feature: compile source code transformation to binary code transformation #1834

Open monperrus opened 6 years ago

monperrus commented 6 years ago

For the programmer, it is much easier to write a transformation at the source code level, because she is familiar with the language constructs. However, in many cases, it is better to be able to apply the transformations at the binary level (eg one could apply the transformation on binary code for which we don't have the source code). For doing this, there are different options:

  1. compiling a source code transformation in Spoon to a binary code transformation in ASM/Javassist
  2. applying transformation after decompilation.

The first option is the most fun: write a transformation at the source code level, and then compile the source-level transformation to a binary-level transformation (in our case writing a Spoon transformation and compile it to an ASM/Javassist transformation)

Are you ready to take on the challenge?

monperrus commented 5 years ago

This tool compute diff on bytecode https://github.com/scala/jardiff

May be useful for this task.

Thanks @nharrand

surli commented 5 years ago

I'm a bit puzzled by the usecase: if a user wants to write a transformation at the source code level, then he must know the source code level, so this one must be available? Or do you imagine the case of analyzing the code using a decompiler to write a transfo and then apply it to the jar?

Now I don't know much the field but I'm a bit afraid about the optimization realized by compilers. A naive example would be a for-loop changed as a while: then the user would write a transfo to catch that loop, except that it doesn't exist anymore in the binaries. Do you think this kind of case could occur?

monperrus commented 5 years ago

Or do you imagine the case of analyzing the code using a decompiler to write a transfo and then apply it to the jar? Exactly! @nharrand is making great progress on the decompilation aspect of it.

monperrus commented 4 years ago

Having AST generators #1960 would be super useful here

monperrus commented 4 years ago

@andrewbwogi some related work: MetaWSL and meta-transformations in the fermaT transformation system (2005)