Skip to content

Commit

Permalink
Implement exception handler table generation
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Dec 22, 2010
1 parent ab0a22e commit 5484ab8
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions lib/CLRBackend.cs
Expand Up @@ -607,6 +607,8 @@ class CgContext {
public LocalBuilder ospill;
public List<int> lineStack = new List<int>();
public List<int> lineBuffer = new List<int>();
public List<int> ehspanBuffer = new List<int>();
public List<string> ehlabelBuffer = new List<string>();

public void make_ospill() {
if (ospill == null)
Expand Down Expand Up @@ -1212,7 +1214,18 @@ class ClrEhSpan : ClrOp {
this.kls = kls; this.tag = tag; this.ls = ls; this.le = le;
this.lg = lg; this.lid = lid;
}
public override void CodeGen(CgContext cx) { }
public override void CodeGen(CgContext cx) {
int lidn = -1;
if (tag != "") {
lidn = cx.ehlabelBuffer.Count;
cx.ehlabelBuffer.Add(tag);
}
cx.ehspanBuffer.Add(cx.named_cases[ls]);
cx.ehspanBuffer.Add(cx.named_cases[le]);
cx.ehspanBuffer.Add(kls);
cx.ehspanBuffer.Add(cx.named_cases[lg]);
cx.ehspanBuffer.Add(lidn);
}
}

class ClrPushLine : ClrOp {
Expand Down Expand Up @@ -1657,31 +1670,34 @@ class ClrNewArray : ClrOp {
class ClrNewIntArray : ClrOp {
readonly int[] vec;
public ClrNewIntArray(int[] vec) {
if (vec.Length >= 0xfc000)
throw new ArgumentException();
Returns = typeof(int[]);
this.vec = vec;
Constant = true;
}
public override ClrOp Sink() { return ClrNoop.Instance; }
[ThreadStatic] private static int next_array;
public override void CodeGen(CgContext cx) {
byte[] buf = new byte[vec.Length * 4];
int r = 0;
for (int i = 0; i < vec.Length; i++) {
uint d = (uint) vec[i];
buf[r++] = (byte)((d >> 0) & 0xFF);
buf[r++] = (byte)((d >> 8) & 0xFF);
buf[r++] = (byte)((d >> 16) & 0xFF);
buf[r++] = (byte)((d >> 24) & 0xFF);
}
FieldBuilder fb = cx.tb.DefineInitializedData("A" + (next_array++),
buf, 0);

cx.EmitInt(vec.Length);
// the mono JIT checks for this exact sequence
cx.il.Emit(OpCodes.Newarr, Tokens.Int32);
cx.il.Emit(OpCodes.Dup);
cx.il.Emit(OpCodes.Ldtoken, fb);
cx.il.Emit(OpCodes.Call, typeof(System.Runtime.CompilerServices.RuntimeHelpers).GetMethod("InitializeArray"));
if (vec.Length != 0) {
byte[] buf = new byte[vec.Length * 4];
int r = 0;
for (int i = 0; i < vec.Length; i++) {
uint d = (uint) vec[i];
buf[r++] = (byte)((d >> 0) & 0xFF);
buf[r++] = (byte)((d >> 8) & 0xFF);
buf[r++] = (byte)((d >> 16) & 0xFF);
buf[r++] = (byte)((d >> 24) & 0xFF);
}
FieldBuilder fb = cx.tb.DefineInitializedData(
"A" + (next_array++), buf, 0);
cx.il.Emit(OpCodes.Dup);
cx.il.Emit(OpCodes.Ldtoken, fb);
cx.il.Emit(OpCodes.Call, typeof(System.Runtime.CompilerServices.RuntimeHelpers).GetMethod("InitializeArray"));
}
}
}

Expand Down Expand Up @@ -2712,8 +2728,8 @@ class NamProcessor {
CpsOp.GetSField(((StaticSub)sub.outer.Resolve()).subinfo) :
CpsOp.Null(Tokens.SubInfo);
args[4] = CpsOp.Null(Tokens.LAD); /* TODO LTM */
args[5] = CpsOp.NewIntArray( new int[] { 1 } ); /* TODO ehspan */
args[6] = CpsOp.StringArray( new string[] { } );
args[5] = CpsOp.NewIntArray( cpb.cx.ehspanBuffer.ToArray() );
args[6] = CpsOp.StringArray( cpb.cx.ehlabelBuffer.ToArray() );
args[7] = CpsOp.IntLiteral( 0 );
List<string> dylexn = new List<string>();
List<int> dylexi = new List<int>();
Expand Down

0 comments on commit 5484ab8

Please sign in to comment.