-
-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to latticg maven, and add code generator
- Loading branch information
1 parent
406f308
commit f20575f
Showing
5 changed files
with
75 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
46 changes: 46 additions & 0 deletions
46
src/codeGen/java/net/earthcomputer/clientcommands/codegen/CodeGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package net.earthcomputer.clientcommands.codegen; | ||
|
||
import com.seedfinding.latticg.generator.ClassGenerator; | ||
import com.seedfinding.latticg.reversal.Program; | ||
import com.seedfinding.latticg.reversal.ProgramBuilder; | ||
import com.seedfinding.latticg.reversal.calltype.java.JavaCalls; | ||
import com.seedfinding.latticg.util.LCG; | ||
import net.earthcomputer.clientcommands.features.CCrackRng; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
public class CodeGenerator { | ||
public static void main(String[] args) throws IOException { | ||
if (args.length != 1) { | ||
System.err.println("clientcommands-codegen <destinationDir>"); | ||
return; | ||
} | ||
|
||
Path destDir = Path.of(args[0]); | ||
genLattiCG(destDir); | ||
} | ||
|
||
private static void genLattiCG(Path destDir) throws IOException { | ||
ProgramBuilder program = Program.builder(LCG.JAVA); | ||
program.skip(-CCrackRng.NUM_THROWS * 4); | ||
for (int i = 0; i < CCrackRng.NUM_THROWS; i++) { | ||
program.skip(1); | ||
program.add(JavaCalls.nextFloat().ranged(CCrackRng.MAX_ERROR * 2)); | ||
program.skip(2); | ||
} | ||
|
||
writeLattiCGClass(program.build(), "net.earthcomputer.clientcommands.features.CCrackRngGen", destDir); | ||
} | ||
|
||
private static void writeLattiCGClass(Program program, String fqName, Path destDir) throws IOException { | ||
int dotIndex = fqName.lastIndexOf('.'); | ||
assert dotIndex >= 0; | ||
String packageName = fqName.substring(0, dotIndex); | ||
String className = fqName.substring(dotIndex + 1); | ||
|
||
String generatedClass = new ClassGenerator(packageName, className, program).generate(); | ||
Files.writeString(destDir.resolve(fqName.replace('.', '/') + ".java"), generatedClass); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters