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 | 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 | 230 | ehtable(c: ref Code) |
| 220 | 231 | { |
| 221 | 232 | i: int; |
| @@ -266,10 +266,38 @@ disinst() · 265 unmodified lines | ||
| 266 | 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 | 297 | disout() |
| 270 | 298 | { |
| 271 | 299 | discon(XMAGIC); |
| 272 | − discon(DONTCOMPILE); # runtime "hints" | |
| 300 | + discon(DONTCOMPILE | HASEXCEPT); # dis flags | |
| 273 | 301 | disstackext(); # minimum stack extent size |
| 274 | 302 | disninst(); |
| 275 | 303 | disnvar(); |
| @@ -281,4 +309,5 @@ disout() · 5 unmodified lines | ||
| 281 | 309 | disvar(); |
| 282 | 310 | dismod(); |
| 283 | 311 | dislinks(); |
| 312 | + dishandlers(); | |
| 284 | 313 | } |
| @@ -202,6 +202,7 @@ Class: adt { # ClassFile · 201 unmodified lines | ||
| 202 | 202 | methods_count: int; |
| 203 | 203 | methods: array of ref Method; |
| 204 | 204 | source_file: int; |
| 205 | + handlers: array of ref Handler; | |
| 205 | 206 | }; |
| 206 | 207 | |
| 207 | 208 | Addr: adt { # Dis operand |
| @@ -308,7 +308,7 @@ byte2Class(text: array of byte) · 307 unmodified lines | ||
| 308 | 308 | mp: ref Method; |
| 309 | 309 | |
| 310 | 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 | 313 | if(u4() != int 16rCAFEBABE) |
| 314 | 314 | verifyerrormess("magic"); |
| @@ -51,6 +51,7 @@ translate(in: string, out: string) · 50 unmodified lines | ||
| 51 | 51 | asmvar(); |
| 52 | 52 | asmmod(); |
| 53 | 53 | asmlinks(); |
| 54 | + asmhandlers(); | |
| 54 | 55 | } else |
| 55 | 56 | disout(); # generate .dis file |
| 56 | 57 | |
| @@ -47,7 +47,7 @@ Hentry: adt { · 46 unmodified lines | ||
| 47 | 47 | }; |
| 48 | 48 | |
| 49 | 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 | 52 | mplist: ref Datum; |
| 53 | 53 | mptail: ref Datum; |
| @@ -405,7 +405,9 @@ reset() · 404 unmodified lines | ||
| 405 | 405 | # mdata.b |
| 406 | 406 | for(i = 0; i < Hashsize; i++) |
| 407 | 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 | 411 | mplist = nil; |
| 410 | 412 | mptail = nil; |
| 411 | 413 | llist = nil; |
| @@ -1382,7 +1382,7 @@ xjavastore(op: int) · 1381 unmodified lines | ||
| 1382 | 1382 | i: ref Inst; |
| 1383 | 1383 | |
| 1384 | 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 | 1386 | else if(J.dst.mode != Anone) { # marked for explicit mov |
| 1387 | 1387 | i = newi(op); |
| 1388 | 1388 | *i.s = *code.j[J.src[0]].dst; |
| @@ -2072,6 +2072,20 @@ ehinst: ref EHInst; · 683 unmodified lines | ||
| 2072 | 2072 | trylist: ref Try; |
| 2073 | 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 | 2090 | # Save an EH branch instruction for later patching. |
| 2077 | 2091 | # |
| @@ -2814,9 +2828,16 @@ java2dis() · 736 unmodified lines | ||
| 2814 | 2828 | jix += J.size; |
| 2815 | 2829 | } |
| 2816 | 2830 | # handle exception handlers |
| 2817 | − for(t := trylist; t != nil; t = t.next) { | |
| 2818 | − # just convert pc's and append the entries to global distrylist | |
| 2819 | − | |
| 2831 | + hbase := len class.handlers; | |
| 2832 | + newhandlers := array [len class.handlers + code.nex] of ref Handler; | |
| 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 | 2842 | J = nil; |
| 2822 | 2843 | } |