Showing the changes to java (8 of 8 files). Show all
Unified · Split
| @@ -216,6 +216,17 @@ instconv(in: ref Inst): string · 215 unmodified lines | |||
| 216 | return s; | 216 | return s; |
| 217 | } | 217 | } |
| 218 | 218 | ||
| 219 | asmhandlers() | ||
| 220 | { | ||
| 221 | nex := len class.handlers; | ||
| 222 | bout.puts("\texceptions " + string nex + "\n"); | ||
| 223 | for (i := 0; i < len class.handlers; i++) { | ||
| 224 | h := class.handlers[i]; | ||
| 225 | bout.puts(sprint("\texception\t%d, %d, 0, -1, 0, 0\n", h.start_pc, h.end_pc)); | ||
| 226 | bout.puts(sprint("\texctab\t*, %d\n", h.handler_pc)); | ||
| 227 | } | ||
| 228 | } | ||
| 229 | |||
| 219 | ehtable(c: ref Code) | 230 | ehtable(c: ref Code) |
| 220 | { | 231 | { |
| 221 | i: int; | 232 | i: int; |
| @@ -266,10 +266,38 @@ disinst() · 265 unmodified lines | |||
| 266 | ibuf = nil; | 266 | ibuf = nil; |
| 267 | } | 267 | } |
| 268 | 268 | ||
| 269 | disstr(s: string) | ||
| 270 | { | ||
| 271 | a := array of byte s; | ||
| 272 | for (i := 0; i < len a; i++) | ||
| 273 | bout.putb(a[i]); | ||
| 274 | discon(0); | ||
| 275 | } | ||
| 276 | |||
| 277 | dishandlers() | ||
| 278 | { | ||
| 279 | discon(len class.handlers); | ||
| 280 | for (i := 0; i < len class.handlers; i++) { | ||
| 281 | h := class.handlers[i]; | ||
| 282 | # FIXME: exception object offset | ||
| 283 | discon(42); | ||
| 284 | discon(h.start_pc); | ||
| 285 | discon(h.end_pc); | ||
| 286 | discon(-1); # type to destroy, nil | ||
| 287 | discon(1); # number of exception handlers | ||
| 288 | disstr("*"); | ||
| 289 | discon(h.handler_pc); | ||
| 290 | discon(0); | ||
| 291 | } | ||
| 292 | # Don't know what is it, but zero-byte is | ||
| 293 | # expected after handler section | ||
| 294 | discon(0); | ||
| 295 | } | ||
| 296 | |||
| 269 | disout() | 297 | disout() |
| 270 | { | 298 | { |
| 271 | discon(XMAGIC); | 299 | discon(XMAGIC); |
| 272 | discon(DONTCOMPILE); # runtime "hints" | 300 | discon(DONTCOMPILE | HASEXCEPT); # dis flags |
| 273 | disstackext(); # minimum stack extent size | 301 | disstackext(); # minimum stack extent size |
| 274 | disninst(); | 302 | disninst(); |
| 275 | disnvar(); | 303 | disnvar(); |
| @@ -281,4 +309,5 @@ disout() · 5 unmodified lines | |||
| 281 | disvar(); | 309 | disvar(); |
| 282 | dismod(); | 310 | dismod(); |
| 283 | dislinks(); | 311 | dislinks(); |
| 312 | dishandlers(); | ||
| 284 | } | 313 | } |
| @@ -202,6 +202,7 @@ Class: adt { # ClassFile · 201 unmodified lines | |||
| 202 | methods_count: int; | 202 | methods_count: int; |
| 203 | methods: array of ref Method; | 203 | methods: array of ref Method; |
| 204 | source_file: int; | 204 | source_file: int; |
| 205 | handlers: array of ref Handler; | ||
| 205 | }; | 206 | }; |
| 206 | 207 | ||
| 207 | Addr: adt { # Dis operand | 208 | Addr: adt { # Dis operand |
| @@ -308,7 +308,7 @@ byte2Class(text: array of byte) · 307 unmodified lines | |||
| 308 | mp: ref Method; | 308 | mp: ref Method; |
| 309 | 309 | ||
| 310 | uSet(text); | 310 | uSet(text); |
| 311 | class = ref Class(0, 0, 0, nil, nil, 0, 0, 0, 0, nil, 0, nil, 0, nil, 0); | 311 | class = ref Class(0, 0, 0, nil, nil, 0, 0, 0, 0, nil, 0, nil, 0, nil, 0, nil); |
| 312 | 312 | ||
| 313 | if(u4() != int 16rCAFEBABE) | 313 | if(u4() != int 16rCAFEBABE) |
| 314 | verifyerrormess("magic"); | 314 | verifyerrormess("magic"); |
| @@ -51,6 +51,7 @@ translate(in: string, out: string) · 50 unmodified lines | |||
| 51 | asmvar(); | 51 | asmvar(); |
| 52 | asmmod(); | 52 | asmmod(); |
| 53 | asmlinks(); | 53 | asmlinks(); |
| 54 | asmhandlers(); | ||
| 54 | } else | 55 | } else |
| 55 | disout(); # generate .dis file | 56 | disout(); # generate .dis file |
| 56 | 57 | ||
| @@ -47,7 +47,7 @@ Hentry: adt { · 46 unmodified lines | |||
| 47 | }; | 47 | }; |
| 48 | 48 | ||
| 49 | htable := array [Hashsize] of ref Hentry; | 49 | htable := array [Hashsize] of ref Hentry; |
| 50 | mpoff: int; | 50 | mpoff := IBY2WD; # skip first cell, as it's reserved for nil ptr |
| 51 | 51 | ||
| 52 | mplist: ref Datum; | 52 | mplist: ref Datum; |
| 53 | mptail: ref Datum; | 53 | mptail: ref Datum; |
| @@ -405,7 +405,9 @@ reset() · 404 unmodified lines | |||
| 405 | # mdata.b | 405 | # mdata.b |
| 406 | for(i = 0; i < Hashsize; i++) | 406 | for(i = 0; i < Hashsize; i++) |
| 407 | htable[i] = nil; | 407 | htable[i] = nil; |
| 408 | mpoff = 0; | 408 | # mpoff should not be zero, |
| 409 | # as zero is reserved for nil ptr | ||
| 410 | mpoff = IBY2WD; | ||
| 409 | mplist = nil; | 411 | mplist = nil; |
| 410 | mptail = nil; | 412 | mptail = nil; |
| 411 | llist = nil; | 413 | llist = nil; |
| @@ -1382,7 +1382,7 @@ xjavastore(op: int) · 1381 unmodified lines | |||
| 1382 | i: ref Inst; | 1382 | i: ref Inst; |
| 1383 | 1383 | ||
| 1384 | if(op == IMOVP && J.bb.js == J && int (J.bb.flags & BB_FINALLY)) | 1384 | if(op == IMOVP && J.bb.js == J && int (J.bb.flags & BB_FINALLY)) |
| 1385 | ; # astore instruction at the start of a finally block | 1385 | print("[The voice of Translator] removed some MOV at %d\n", op); # astore instruction at the start of a finally block |
| 1386 | else if(J.dst.mode != Anone) { # marked for explicit mov | 1386 | else if(J.dst.mode != Anone) { # marked for explicit mov |
| 1387 | i = newi(op); | 1387 | i = newi(op); |
| 1388 | *i.s = *code.j[J.src[0]].dst; | 1388 | *i.s = *code.j[J.src[0]].dst; |
| @@ -2072,6 +2072,20 @@ ehinst: ref EHInst; · 683 unmodified lines | |||
| 2072 | trylist: ref Try; | 2072 | trylist: ref Try; |
| 2073 | distrylist: ref Try; | 2073 | distrylist: ref Try; |
| 2074 | 2074 | ||
| 2075 | # | ||
| 2076 | # Dis pc by jinst index | ||
| 2077 | # | ||
| 2078 | |||
| 2079 | instpc(jix: int): int | ||
| 2080 | { | ||
| 2081 | j := code.j[jix]; | ||
| 2082 | while(j.dis == nil) { | ||
| 2083 | jix += j.size; | ||
| 2084 | j = code.j[jix]; | ||
| 2085 | } | ||
| 2086 | return j.dis.pc; | ||
| 2087 | } | ||
| 2088 | |||
| 2075 | # | 2089 | # |
| 2076 | # Save an EH branch instruction for later patching. | 2090 | # Save an EH branch instruction for later patching. |
| 2077 | # | 2091 | # |
| @@ -2814,9 +2828,16 @@ java2dis() · 736 unmodified lines | |||
| 2814 | jix += J.size; | 2828 | jix += J.size; |
| 2815 | } | 2829 | } |
| 2816 | # handle exception handlers | 2830 | # handle exception handlers |
| 2817 | for(t := trylist; t != nil; t = t.next) { | 2831 | hbase := len class.handlers; |
| 2818 | # just convert pc's and append the entries to global distrylist | 2832 | newhandlers := array [len class.handlers + code.nex] of ref Handler; |
| 2819 | 2833 | newhandlers[:] = class.handlers[:]; | |
| 2834 | class.handlers = newhandlers; | ||
| 2835 | for(i := 0; i < code.nex; i++) { | ||
| 2836 | h := code.ex[i]; | ||
| 2837 | # by this time all the needed code is already translated, so we can | ||
| 2838 | # just convert pc's and append the entries to global handlers section | ||
| 2839 | class.handlers[hbase++] = ref Handler(instpc(h.start_pc), instpc(h.end_pc), | ||
| 2840 | instpc(h.handler_pc), 0); | ||
| 2820 | } | 2841 | } |
| 2821 | J = nil; | 2842 | J = nil; |
| 2822 | } | 2843 | } |