-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[no ci] Initial work on ASM visitor-based processor
- Loading branch information
1 parent
c691485
commit 32e03c1
Showing
24 changed files
with
511 additions
and
34 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
4 changes: 2 additions & 2 deletions
4
...sesame/compile/javac/ASMTypeProvider.java → ...ensesame/compile/asm/ASMTypeProvider.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
52 changes: 52 additions & 0 deletions
52
compile/src/asm/java/dev/lukebemish/opensesame/compile/asm/Processor.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,52 @@ | ||
package dev.lukebemish.opensesame.compile.asm; | ||
|
||
import org.objectweb.asm.ClassReader; | ||
import org.objectweb.asm.ClassWriter; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
public class Processor { | ||
public static void main(String[] args) { | ||
if ((~args.length & 1) != 1) { | ||
System.err.println("Usage: java dev.lukebemish.opensesame.compile.asm.Processor <input> <output> <input> <output> ..."); | ||
System.exit(1); | ||
} | ||
for (int i = 0; i < args.length; i += 2) { | ||
var input = Path.of(args[0]); | ||
var output = Path.of(args[1]); | ||
if (Files.isRegularFile(input)) { | ||
try { | ||
processFile(input, output); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} else { | ||
try (var paths = Files.walk(input)) { | ||
paths.filter(Files::isRegularFile).forEach(file -> { | ||
try { | ||
var relative = input.relativize(file); | ||
var out = output.resolve(relative); | ||
Files.createDirectories(out.getParent()); | ||
processFile(file, out); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
}); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public static void processFile(Path file, Path out) throws IOException { | ||
try (var inputStream = Files.newInputStream(file)) { | ||
ClassReader reader = new ClassReader(inputStream); | ||
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); | ||
reader.accept(new VisitingOpenProcessor(writer, VisitingOpenProcessor.ANNOTATIONS), 0); | ||
Files.write(out, writer.toByteArray()); | ||
} | ||
} | ||
} |
Oops, something went wrong.