Skip to content
Snippets Groups Projects
Commit e84d7e80 authored by Etienne Kneuss's avatar Etienne Kneuss
Browse files

Add possibility to compile literal generic values

parent 798ee66e
No related branches found
No related tags found
No related merge requests found
...@@ -72,6 +72,7 @@ trait CodeGeneration { ...@@ -72,6 +72,7 @@ trait CodeGeneration {
private[codegen] val ImpossibleEvaluationClass = "leon/codegen/runtime/LeonCodeGenEvaluationException" private[codegen] val ImpossibleEvaluationClass = "leon/codegen/runtime/LeonCodeGenEvaluationException"
private[codegen] val HashingClass = "leon/codegen/runtime/LeonCodeGenRuntimeHashing" private[codegen] val HashingClass = "leon/codegen/runtime/LeonCodeGenRuntimeHashing"
private[codegen] val ChooseEntryPointClass = "leon/codegen/runtime/ChooseEntryPoint" private[codegen] val ChooseEntryPointClass = "leon/codegen/runtime/ChooseEntryPoint"
private[codegen] val GenericValuesClass = "leon/codegen/runtime/GenericValues"
private[codegen] val MonitorClass = "leon/codegen/runtime/LeonCodeGenRuntimeMonitor" private[codegen] val MonitorClass = "leon/codegen/runtime/LeonCodeGenRuntimeMonitor"
def idToSafeJVMName(id: Identifier) = id.uniqueName.replaceAll("\\.", "\\$") def idToSafeJVMName(id: Identifier) = id.uniqueName.replaceAll("\\.", "\\$")
...@@ -695,6 +696,11 @@ trait CodeGeneration { ...@@ -695,6 +696,11 @@ trait CodeGeneration {
ch << InvokeStatic(ChooseEntryPointClass, "invoke", "(I[Ljava/lang/Object;)Ljava/lang/Object;") ch << InvokeStatic(ChooseEntryPointClass, "invoke", "(I[Ljava/lang/Object;)Ljava/lang/Object;")
mkUnbox(choose.getType, ch) mkUnbox(choose.getType, ch)
case gv @ GenericValue(tp, int) =>
val id = runtime.GenericValues.register(gv);
ch << Ldc(id)
ch << InvokeStatic(GenericValuesClass, "get", "(I)Ljava/lang/Object;")
case This(ct) => case This(ct) =>
ch << ALoad(0) // FIXME what if doInstrument etc ch << ALoad(0) // FIXME what if doInstrument etc
......
/* Copyright 2009-2014 EPFL, Lausanne */
package leon
package codegen.runtime
import utils._
import purescala.Common._
import purescala.Definitions._
import purescala.Trees.{Tuple => LeonTuple, _}
import purescala.TreeOps.valuateWithModel
import purescala.TypeTrees._
import scala.collection.immutable.{Map => ScalaMap}
import synthesis._
object GenericValues {
private[this] var counter = 0;
private[this] var gvToI = ScalaMap[GenericValue, Int]()
private[this] var iTogv = ScalaMap[Int, GenericValue]()
def register(gv: GenericValue): Int = {
if (gvToI contains gv) {
gvToI(gv)
} else {
counter += 1;
gvToI += gv -> counter
iTogv += counter -> gv
counter
}
}
def get(i: Int): java.lang.Object = {
iTogv(i)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment