summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar qadeer <unknown>2011-03-02 07:32:12 +0000
committerGravatar qadeer <unknown>2011-03-02 07:32:12 +0000
commit36a32108fa3edfa9385946f4feded3065fb2bf58 (patch)
tree5384ab6ac65857519cfe810c9f2870d4dcef20a1
parentda04d48c9f94af45b5bc1b3964a104c8a8c2f3e6 (diff)
some fixes
1. introduced ProcedureInfo for packaging up relevant information about a Procedure 2. removed the call to the code that generates the static class constructor. this is temporarily broken; have to discuss with mike
-rw-r--r--BCT/BytecodeTranslator/Heap.cs2
-rw-r--r--BCT/BytecodeTranslator/MetadataTraverser.cs15
-rw-r--r--BCT/BytecodeTranslator/Sink.cs31
3 files changed, 30 insertions, 18 deletions
diff --git a/BCT/BytecodeTranslator/Heap.cs b/BCT/BytecodeTranslator/Heap.cs
index e023d300..919ab243 100644
--- a/BCT/BytecodeTranslator/Heap.cs
+++ b/BCT/BytecodeTranslator/Heap.cs
@@ -165,6 +165,8 @@ procedure {:inline 1} Alloc() returns (x: int)
assume $Alloc[x] == false;
$Alloc[x] := true;
}
+
+type ref = int;
";
public override bool MakeHeap(Sink sink, out Heap heap, out Bpl.Program/*?*/ program) {
diff --git a/BCT/BytecodeTranslator/MetadataTraverser.cs b/BCT/BytecodeTranslator/MetadataTraverser.cs
index a01f3a4b..ab797529 100644
--- a/BCT/BytecodeTranslator/MetadataTraverser.cs
+++ b/BCT/BytecodeTranslator/MetadataTraverser.cs
@@ -85,7 +85,7 @@ namespace BytecodeTranslator {
}
var procAndFormalMap = this.sink.FindOrCreateProcedureAndReturnProcAndFormalMap(invokeMethod, invokeMethod.IsStatic);
- var proc = procAndFormalMap.Item1;
+ var proc = procAndFormalMap.Procedure;
var invars = proc.InParams;
var outvars = proc.OutParams;
@@ -171,14 +171,8 @@ namespace BytecodeTranslator {
public override void Visit(ITypeDefinition typeDefinition) {
if (typeDefinition.IsClass) {
- bool savedSawCctor = this.sawCctor;
- this.sawCctor = false;
sink.FindOrCreateType(typeDefinition);
base.Visit(typeDefinition);
- if (!this.sawCctor) {
- CreateStaticConstructor(typeDefinition);
- }
- this.sawCctor = savedSawCctor;
} else if (typeDefinition.IsDelegate) {
sink.AddDelegateType(typeDefinition);
} else if (typeDefinition.IsInterface) {
@@ -193,8 +187,6 @@ namespace BytecodeTranslator {
}
}
- private bool sawCctor = false;
-
private void CreateStaticConstructor(ITypeDefinition typeDefinition) {
var proc = new Bpl.Procedure(Bpl.Token.NoToken,
TypeHelper.GetTypeName(typeDefinition) + ".#cctor",
@@ -263,8 +255,9 @@ namespace BytecodeTranslator {
return;
}
- var proc = procAndFormalMap.Item1;
- var formalMap = procAndFormalMap.Item2;
+ var proc = procAndFormalMap.Procedure;
+ var formalMap = procAndFormalMap.FormalMap;
+ this.sink.RetVariable = procAndFormalMap.ReturnVariable;
try {
diff --git a/BCT/BytecodeTranslator/Sink.cs b/BCT/BytecodeTranslator/Sink.cs
index e7b99376..e08c1b7b 100644
--- a/BCT/BytecodeTranslator/Sink.cs
+++ b/BCT/BytecodeTranslator/Sink.cs
@@ -130,9 +130,9 @@ namespace BytecodeTranslator {
/// <returns></returns>
public Bpl.Variable FindParameterVariable(IParameterDefinition param) {
MethodParameter mp;
- Tuple<Bpl.Procedure, Dictionary<IParameterDefinition, MethodParameter>> procAndFormalMap;
+ ProcedureInfo procAndFormalMap;
this.declaredMethods.TryGetValue(param.ContainingSignature, out procAndFormalMap);
- var formalMap = procAndFormalMap.Item2;
+ var formalMap = procAndFormalMap.FormalMap;
formalMap.TryGetValue(param, out mp);
return mp.outParameterCopy;
}
@@ -175,8 +175,25 @@ namespace BytecodeTranslator {
private Dictionary<IPropertyDefinition, Bpl.Variable> declaredProperties = new Dictionary<IPropertyDefinition, Bpl.Variable>();
+ public struct ProcedureInfo {
+ private Bpl.Procedure proc;
+ private Dictionary<IParameterDefinition, MethodParameter> formalMap;
+ private Bpl.Variable returnVariable;
+
+ public ProcedureInfo(Bpl.Procedure proc, Dictionary<IParameterDefinition, MethodParameter> formalMap, Bpl.Variable returnVariable) {
+ this.proc = proc;
+ this.formalMap = formalMap;
+ this.returnVariable = returnVariable;
+ }
+
+ public Bpl.Procedure Procedure { get { return proc; } }
+ public Dictionary<IParameterDefinition, MethodParameter> FormalMap { get { return formalMap; } }
+ public Bpl.Variable ReturnVariable { get { return returnVariable; } }
+ }
+
public Bpl.Procedure FindOrCreateProcedure(IMethodReference method, bool isStatic) {
- Tuple<Bpl.Procedure, Dictionary<IParameterDefinition, MethodParameter>> procAndFormalMap;
+ ProcedureInfo procAndFormalMap;
+
var key = method; //.InternedKey;
if (!this.declaredMethods.TryGetValue(key, out procAndFormalMap)) {
#region Create in- and out-parameters
@@ -312,12 +329,12 @@ namespace BytecodeTranslator {
this.TranslatedProgram.TopLevelDeclarations.Add(proc);
- procAndFormalMap = Tuple.Create(proc, formalMap);
+ procAndFormalMap = new ProcedureInfo(proc, formalMap, this.RetVariable);
this.declaredMethods.Add(key, procAndFormalMap);
}
- return procAndFormalMap.Item1;
+ return procAndFormalMap.Procedure;
}
- public Tuple<Bpl.Procedure,Dictionary<IParameterDefinition, MethodParameter>> FindOrCreateProcedureAndReturnProcAndFormalMap(IMethodDefinition method, bool isStatic) {
+ public ProcedureInfo FindOrCreateProcedureAndReturnProcAndFormalMap(IMethodDefinition method, bool isStatic) {
this.FindOrCreateProcedure(method, isStatic);
return this.declaredMethods[method];
}
@@ -350,7 +367,7 @@ namespace BytecodeTranslator {
/// The values are pairs: first element is the procedure,
/// second element is the formal map for the procedure
/// </summary>
- private Dictionary<ISignature, Tuple<Bpl.Procedure, Dictionary<IParameterDefinition, MethodParameter>>> declaredMethods = new Dictionary<ISignature, Tuple<Bpl.Procedure, Dictionary<IParameterDefinition, MethodParameter>>>();
+ private Dictionary<ISignature, ProcedureInfo> declaredMethods = new Dictionary<ISignature, ProcedureInfo>();
public void BeginMethod() {
this.localVarMap = new Dictionary<ILocalDefinition, Bpl.LocalVariable>();