Created
July 8, 2020 23:27
-
-
Save t81lal/bab635b1a0751669d32459359585205f to your computer and use it in GitHub Desktop.
First prototype of Spade mainline pipeline
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
static class TestModule extends AbstractModule { | |
private final GenerationCtx ctx; | |
public TestModule(GenerationCtx ctx) { | |
this.ctx = ctx; | |
} | |
@Override | |
protected void configure() { | |
bind(GenerationCtx.class).toInstance(ctx); | |
install(new FactoryModuleBuilder().build(AsmGenerator.AsmGeneratorFactory.class)); | |
MapBinder<Class<? extends GenerationCtx>, GeneratorFactory<?>> mapBinder = MapBinder.newMapBinder(binder(), | |
new TypeLiteral<Class<? extends GenerationCtx>>() {}, | |
new TypeLiteral<GeneratorFactory<?>>() {}); | |
mapBinder.addBinding(AsmGenerationCtx.class).to(AsmGenerator.AsmGeneratorFactory.class); | |
} | |
} | |
static class MakeGeneratorStep implements PipelineStep<GenerationCtx, Generator> { | |
private final AbstractGeneratorFactory abstractFactory; | |
@Inject | |
public MakeGeneratorStep(AbstractGeneratorFactory abstractFactory) { | |
this.abstractFactory = abstractFactory; | |
} | |
@Override | |
public Generator apply(GenerationCtx ctx) { | |
GeneratorFactory<GenerationCtx> generatorFactory = abstractFactory.create(ctx); | |
Generator generator = generatorFactory.create(ctx); | |
return generator; | |
} | |
} | |
static class ExecuteGeneratorStep implements PipelineStep<Generator, ControlFlowGraph> { | |
@Override | |
public ControlFlowGraph apply(Generator t) { | |
return t.run(); | |
} | |
} | |
static class EnterSSAStep implements PipelineStep<Object, ControlFlowGraph> { | |
private final GenerationCtx context; | |
private final SSAGenerator generator; | |
@Inject | |
public EnterSSAStep(GenerationCtx context, SSAGenerator generator) { | |
this.context = context; | |
this.generator = generator; | |
} | |
@Override | |
public ControlFlowGraph apply(Object any) { | |
generator.doTransform(); | |
return context.getGraph(); | |
} | |
} | |
public static void main(String[] args) throws IOException, ExecutionException { | |
Function<GenerationCtx, PipelineExecutionContext<GenerationCtx>> contextCreator = s -> { | |
Injector injector = Guice.createInjector(new TestModule(s)); | |
return new GuicedPipelineExecutionContext<>(s, injector); | |
}; | |
var pipeline = Pipeline.<GenerationCtx>from().then(MakeGeneratorStep.class).then(ExecuteGeneratorStep.class) | |
.dropThen(EnterSSAStep.class).build(contextCreator); | |
var typeManager = new MockTypeManager(); | |
var target = getContext(SSAPassTest.class, "test2"); | |
var ctx = new AsmGenerationCtx(typeManager, target.getA(), target.getB()); | |
ControlFlowGraph ssaCfg = pipeline.execute(ctx); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment