polyglot-compiler / JLang

JLang: Ahead-of-time compilation of Java programs to LLVM
http://polyglot-compiler.github.io/JLang/
Other
284 stars 29 forks source link

The question about hiding the original variable names in java IR file #75

Closed mengyuan-Sharon closed 3 years ago

mengyuan-Sharon commented 3 years ago

Dear Author of Jlang, Thank you for creating convenient and quick tools Jlang which is very helpful to me. I found an interesting problem that when I converted CPP code into IR, by using llvm and clang, all variable names were hidden into 1%, 2%, 3%, etc,such as the cpp code shown below, However, when using Jlang to convert Java code to IR, all variable names are still in the *. Ll IR file. Is there a convenient way to hide the file names in Java LL, just like CPP to IR.

cpp to IR cpp code: int whileTest() { int a = 10,i = 20; while (i < 10) { i=i+1; a=a2; } return 0; } Part of IR generated by llvm: define void @whileTest() { entry: %"1" = alloca i32 %"2" = alloca i32 %"3" = alloca i32 store i32 0, i32 %"1" store i32 10, i32 %"2" store i32 20, i32 %"3" br label %label1 br label %label1

java code: public class AddTwoNumbers { public static void main(String[] args) { int num1 = 5, num2 = 15, sum, t; t = num1 + num2; sum = t+t System.out.println("Sum of these numbers: "+sum); } }

name "num1, num2 " still in IR Part of IR generated by llvm image

Looking forward to your reply, Thank you very much.

dz333 commented 3 years ago

For this, you can use the LLVM infrastructure and apply it directly to the *.ll files produced by JLang. You can write your own LLVM pass that renames all of the variables, using whatever naming scheme you would like.

Since this can easily be accomplished with post-processing, we don't plan on adding this kind of functionality directly to JLang.

mengyuan-Sharon commented 3 years ago

Thanks for the apply! you have solved the problem that I have been confused about for a long time,Thank you very much!