Skip to content
Snippets Groups Projects
Commit 1c8605ab authored by Ali Sinan Köksal's avatar Ali Sinan Köksal
Browse files

Working version of generation of conversion method

parent 6baa0c66
Branches
Tags
No related merge requests found
......@@ -29,6 +29,15 @@ class CPComponent(val global: Global, val pluginInstance: CPPlugin)
fresh = unit.fresh
println("Starting CP phase")
def plop(tr: Tree) = tr match {
case a: Apply =>
println(a)
println(a.fun.getClass)
case _ =>
}
// new ForeachTreeTraverser(plop).traverse(unit.body)
val prog: purescala.Definitions.Program = extractCode(unit)
val filename = writeProgram(prog)
println("Program extracted and written into: " + filename)
......
......@@ -24,8 +24,8 @@ trait CallTransformation
unit.body = new CallTransformer(unit, prog, programFilename).transform(unit.body)
class CallTransformer(unit: CompilationUnit, prog: Program, programFilename: String) extends TypingTransformer(unit) {
val codeGen = new CodeGenerator(unit, currentOwner)
val (exprToScalaSym, exprToScalaCode) = codeGen.exprToScala
var exprToScalaSym : Symbol = null
var exprToScalaCode : Tree = null
override def transform(tree: Tree) : Tree = {
tree match {
......@@ -38,6 +38,7 @@ trait CallTransformation
println("Here is the extracted FunDef:")
println(fd)
val codeGen = new CodeGenerator(unit, currentOwner)
fd.body match {
case None => println("Could not extract choose predicate: " + funBody); super.transform(tree)
......@@ -47,7 +48,8 @@ trait CallTransformation
val (exprGet, exprSym) = codeGen.getExpr(exprFilename)
val solverInvocation = codeGen.invokeSolver(progSym, exprSym)
val exprToScalaInvocation = codeGen.invokeExprToScala(exprToScalaSym)
val code = BLOCK(programGet, exprGet, solverInvocation) //, exprToScalaInvocation)
// val code = BLOCK(programGet, exprGet, solverInvocation)
val code = BLOCK(programGet, exprGet, solverInvocation, exprToScalaInvocation)
typer.typed(atOwner(currentOwner) {
code
......@@ -58,6 +60,10 @@ trait CallTransformation
case cd @ ClassDef(mods, name, tparams, impl) if (cd.symbol.isModuleClass && tparams.isEmpty && !cd.symbol.isSynthetic) => {
println("I'm inside the object " + name.toString + " !")
val codeGen = new CodeGenerator(unit, currentOwner)
val (e2sSym, e2sCode) = codeGen.exprToScala(cd.symbol)
exprToScalaSym = e2sSym
exprToScalaCode = e2sCode
atOwner(tree.symbol) {
treeCopy.ClassDef(tree, transformModifiers(mods), name,
transformTypeDefs(tparams), impl match {
......
......@@ -23,6 +23,7 @@ trait CodeGeneration {
private lazy val treesModule = definitions.getModule("purescala.Trees")
private lazy val exprClass = definitions.getClass("purescala.Trees.Expr")
private lazy val intLiteralClass = definitions.getClass("purescala.Trees.IntLiteral")
private lazy val intLiteralModule = definitions.getModule("purescala.Trees.IntLiteral")
private lazy val fairZ3SolverClass = definitions.getClass("purescala.FairZ3Solver")
private lazy val restartAndDecideWithModel = definitions.getMember(fairZ3SolverClass, "restartAndDecideWithModel")
......@@ -53,17 +54,19 @@ trait CodeGeneration {
BLOCK(solverDeclaration, setProgram, invocation, LIT(0))
}
def exprToScala : (Symbol, Tree) = {
val scrutSym = owner.newValue(NoPosition, unit.fresh.newName(NoPosition, "scrut")).setInfo(exprClass.tpe)
val intSym = owner.newValue(NoPosition, unit.fresh.newName(NoPosition, "value")).setInfo(definitions.IntClass.tpe)
def exprToScala(owner : Symbol) : (Symbol, Tree) = {
val methodSym = owner.newMethod(NoPosition, unit.fresh.newName(NoPosition, "exprToScala"))
methodSym.setInfo(MethodType(methodSym.newSyntheticValueParams(List(definitions.AnyClass.tpe)), definitions.AnyClass.tpe))
owner.info.decls.enter(methodSym)
val matchExpr = ID(scrutSym) MATCH (
CASE(ID(intLiteralClass) APPLY (intSym BIND WILD())) ==> ID(intSym) ,
DEFAULT ==> THROW(exceptionClass, LIT("Cannot convert FunCheck expression to Scala term"))
val intSym = methodSym.newValue(NoPosition, unit.fresh.newName(NoPosition, "value")).setInfo(definitions.IntClass.tpe)
val matchExpr = (methodSym ARG 0) MATCH (
CASE((intLiteralModule) APPLY (intSym BIND WILD())) ==> ID(intSym) ,
DEFAULT ==> THROW(exceptionClass, LIT("Cannot convert FunCheck expression to Scala term"))
)
val methodSym = owner.newMethod(NoPosition, unit.fresh.newName(NoPosition, "exprToScala")).setInfo(MethodType(Nil, definitions.IntClass.tpe))
// (methodSym, DEF(methodSym) === matchExpr)
(methodSym, DEF(methodSym) === LIT(0))
(methodSym, DEF(methodSym) === matchExpr)
}
def invokeExprToScala(methodSym : Symbol) : Tree = {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment