]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/SCLContextPreparationStep.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / internal / codegen / utils / SCLContextPreparationStep.java
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/SCLContextPreparationStep.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/SCLContextPreparationStep.java
new file mode 100644 (file)
index 0000000..bf2143c
--- /dev/null
@@ -0,0 +1,22 @@
+package org.simantics.scl.compiler.internal.codegen.utils;
+
+import org.simantics.scl.compiler.internal.codegen.utils.LocalVariable;
+import org.cojen.classfile.TypeDesc;
+import org.simantics.scl.runtime.SCLContext;
+
+public enum SCLContextPreparationStep implements PreparationStep<LocalVariable> {
+    INSTANCE;
+    
+    public final static TypeDesc SCL_CONTEXT = TypeDesc.forClass(SCLContext.class);
+    
+    public static LocalVariable getCurrent(MethodBuilder mb) {
+        LocalVariable var = mb.getPreparation(INSTANCE);
+        if(var == null) {
+            var = mb.createLocalVariable("sclContext", SCL_CONTEXT);
+            mb.invokeStatic(SCL_CONTEXT, "getCurrent", SCL_CONTEXT, Constants.EMPTY_TYPEDESC_ARRAY);
+            mb.storeLocal(var);
+            mb.addPreparation(INSTANCE, var);
+        }
+        return var;
+    }
+}