-
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.
Using a Visitor based on Java PrettyPrinting.
- Loading branch information
Showing
11 changed files
with
1,074 additions
and
116 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
bin | ||
spooned | ||
spooned | ||
compiler |
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
59 changes: 59 additions & 0 deletions
59
compiler-src/aeminium/gpu/compiler/processing/MapLambdaProcessor.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,59 @@ | ||
package aeminium.gpu.compiler.processing; | ||
|
||
import aeminium.gpu.compiler.processing.visitor.OpenCLCodeGeneratorVisitor; | ||
import aeminium.gpu.compiler.template.MapLambdaTemplate; | ||
import spoon.processing.AbstractProcessor; | ||
import spoon.reflect.code.CtBlock; | ||
import spoon.reflect.declaration.CtClass; | ||
import spoon.reflect.declaration.CtElement; | ||
import spoon.reflect.declaration.CtMethod; | ||
import spoon.reflect.visitor.ModelConsistencyChecker; | ||
import spoon.template.Substitution; | ||
import spoon.template.Template; | ||
|
||
public class MapLambdaProcessor<T> extends AbstractProcessor<CtMethod<T>>{ | ||
|
||
private boolean canSubstitute = false; | ||
private String clCode = null; | ||
|
||
@Override | ||
public void process(CtMethod<T> target) { | ||
if (target.getSimpleName().equals("call")) { | ||
|
||
checkAndReplaceMethodBody(target); | ||
|
||
if (canSubstitute) { | ||
// Check for consistency and correct it. | ||
ModelConsistencyChecker checker = new ModelConsistencyChecker(this.getEnvironment(), true); | ||
checker.enter(target); | ||
} | ||
|
||
} | ||
} | ||
|
||
private void checkAndReplaceMethodBody(CtMethod<T> target) { | ||
CtBlock<T> body = target.getBody(); | ||
checkAndGenerateExpr(body); | ||
|
||
if (canSubstitute) { | ||
|
||
Template t = new MapLambdaTemplate(clCode.toString()); | ||
Substitution.insertAllMethods(target.getParent(CtClass.class), t); | ||
} | ||
} | ||
|
||
private void checkAndGenerateExpr(CtElement expr) { | ||
|
||
OpenCLCodeGeneratorVisitor gen = new OpenCLCodeGeneratorVisitor(getEnvironment()); | ||
expr.accept(gen); | ||
|
||
if (gen.canBeGenerated()) { | ||
canSubstitute = true; | ||
clCode = gen.toString(); | ||
System.out.println(":::: Final Code ::::"); | ||
System.out.println(clCode); | ||
System.out.println(":: End Final Code ::"); | ||
} | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
compiler-src/aeminium/gpu/compiler/processing/utils/CodeGenerationContext.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,42 @@ | ||
package aeminium.gpu.compiler.processing.utils; | ||
|
||
import java.util.Stack; | ||
|
||
import spoon.reflect.code.CtExpression; | ||
import spoon.reflect.declaration.CtSimpleType; | ||
import spoon.reflect.reference.CtTypeReference; | ||
|
||
public class CodeGenerationContext { | ||
|
||
public Stack<CtTypeReference<?>> currentThis = new Stack<CtTypeReference<?>>(); | ||
|
||
public Stack<CtExpression<?>> parenthesedExpression = new Stack<CtExpression<?>>(); | ||
|
||
public CtSimpleType<?> currentTopLevel; | ||
|
||
public int nbTabs = 0; | ||
|
||
public boolean skipArray = false; | ||
public boolean noTypeDecl = false; | ||
|
||
int target = 0; | ||
int jumped = 0; | ||
|
||
public void enterTarget() { | ||
target++; | ||
} | ||
|
||
public void exitTarget() { | ||
if (jumped > 0) { | ||
jumped--; | ||
} else { | ||
target--; | ||
} | ||
} | ||
|
||
public void jumpTarget() { | ||
jumped++; | ||
target--; | ||
} | ||
|
||
} |
Oops, something went wrong.