Skip to content

Commit

Permalink
Generalized function call via IL compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
ashalkhakov committed Sep 23, 2015
1 parent 70cf36d commit 50c01a4
Show file tree
Hide file tree
Showing 9 changed files with 3,165 additions and 652 deletions.
46 changes: 21 additions & 25 deletions Dataphor/DAE/Compiling/Compiler.cs
Expand Up @@ -694,8 +694,12 @@ public static PlanNode Compile(Plan plan, Statement statement, DataParams params
if (!plan.Messages.HasErrors)
{
long startSubTicks = TimingUtility.CurrentTicks;
//node = ChunkNode(plan, node);
//node = ChunkNode(plan, node);
if (plan.ShouldEmitIL)
node.StartEmitIL(plan);
node = OptimizeNode(plan, node);
if (plan.ShouldEmitIL)
node.FinishEmitIL(plan);
plan.Statistics.OptimizeTime = new TimeSpan((long)((((double)(TimingUtility.CurrentTicks - startSubTicks)) / TimingUtility.TicksPerSecond) * TimeSpan.TicksPerSecond));
//startSubTicks = TimingUtility.CurrentTicks;
//node = Bind(plan, node);
Expand Down Expand Up @@ -766,11 +770,22 @@ private static PlanNode OptimizeNode(Plan plan, PlanNode planNode)
// Determine access paths
#if USEVISIT
planNode = BindingTraversal(plan, planNode, new DetermineAccessPathVisitor());
#else
#else
BindingTraversal(plan, planNode, new DetermineAccessPathVisitor());
#endif
}
}
#endif

// determine if it should be compiled to IL
try
{
if (plan.ShouldEmitIL)
planNode.EmitIL(plan);
}
catch (Exception exception)
{
plan.Messages.Add(new CompilerException(CompilerException.Codes.NonFatalErrors, CompilerErrorLevel.Warning, exception));
}
}
}
catch (Exception exception)
{
plan.Messages.Add(exception);
Expand All @@ -784,26 +799,7 @@ private static PlanNode OptimizeNode(Plan plan, PlanNode planNode)
// // This method is here for consistency with the Bind phase method, and for future expansion.
// return OptimizeNode(plan, planNode);
//}

//private static PlanNode OptimizeNode(Plan plan, PlanNode planNode)
//{
// try
// {
// if (plan.ShouldEmitIL)
// planNode.EmitIL(plan, false);

// if (!plan.IsEngine)
// {
// planNode = BindingTraversal(plan, planNode, new DetermineAccessPathVisitor());
// }
// }
// catch (Exception exception)
// {
// plan.Messages.Add(exception);
// }

// return planNode;
//}


//private static PlanNode Bind(Plan plan, PlanNode planNode)
//{
Expand Down
27 changes: 26 additions & 1 deletion Dataphor/DAE/Compiling/Plan.cs
Expand Up @@ -868,5 +868,30 @@ public object CreateObject(ClassDefinition classDefinition, object[] actualParam
{
return Catalog.ClassLoader.CreateObject(CatalogDeviceSession, classDefinition, actualParameters);
}
}

#region IL Emission
private System.Reflection.Emit.DynamicMethod _dynamicMethod = null;
public System.Reflection.Emit.ILGenerator ILGenerator
{
get
{
if (_dynamicMethod == null)
_dynamicMethod = new System.Reflection.Emit.DynamicMethod(
"dynmth_" + Guid.NewGuid().ToString().Replace("-", "_"),
System.Reflection.MethodAttributes.Public | System.Reflection.MethodAttributes.Static,
System.Reflection.CallingConventions.Standard,
typeof(object),
new Type[] { typeof(Program) },
typeof(Plan).Module,
false
);
return _dynamicMethod.GetILGenerator();
}
}
public Func<Program,object> CreateDynamicMethod()
{
return (Func<Program, object>)_dynamicMethod.CreateDelegate(typeof(Func<Program, object>));
}
#endregion
}
}

0 comments on commit 50c01a4

Please sign in to comment.