Skip to content

Commit

Permalink
Using a Visitor based on Java PrettyPrinting.
Browse files Browse the repository at this point in the history
  • Loading branch information
alcides committed Mar 17, 2011
1 parent dbbcf66 commit 05092bd
Show file tree
Hide file tree
Showing 11 changed files with 1,074 additions and 116 deletions.
2 changes: 1 addition & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
<classpathentry kind="lib" path="lib/AeminiumGPU.jar"/>
<classpathentry kind="lib" path="lib/javacl-1.0-beta-6-shaded.jar"/>
<classpathentry kind="lib" path="lib/javacl-demos-1.0-beta-6-shaded.jar"/>
<classpathentry kind="lib" path="compiler-lib/spoon-core-1.4-jar-with-dependencies.jar"/>
<classpathentry kind="lib" path="compiler-lib/spoon-core-1.4-jar-with-dependencies.jar" sourcepath="/Users/alcides/Code/Support/spoon-core-1.4-sources.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
bin
spooned
spooned
compiler
2 changes: 1 addition & 1 deletion .project
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>SpoonCompilerTest</name>
<name>AeminiumGPUCompiler</name>
<comment></comment>
<projects>
</projects>
Expand Down
6 changes: 3 additions & 3 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
<!-- define spoon task -->
<taskdef name="spoon" classname="spoon.SpoonTask" classpathref="compiler.classpath"/>

<spoon classpathref="compiler.classpath" verbose= "true">
<spoon classpathref="compiler.classpath" verbose="true">
<sourceSet dir="${src.dir}" />
<templateset dir="${compiler.src.dir}" includes="template/" />
<processor type="processing.MapLambdaProcessor" />
<templateset dir="${compiler.src.dir}/aeminium/gpu/compiler/template" />
<processor type="aeminium.gpu.compiler.processing.MapLambdaProcessor" />
</spoon>
</target>

Expand Down
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 ::");
}
}

}
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--;
}

}
Loading

0 comments on commit 05092bd

Please sign in to comment.