Browse code

Add support for internal function calls to bytecode loader.

Török Edvin authored on 2009/06/29 23:57:02
Showing 2 changed files
... ...
@@ -388,6 +388,20 @@ static int parseBB(struct cli_bc *bc, unsigned func, unsigned bb, unsigned char
388 388
 		inst.u.branch.br_true = readBBID(bcfunc, buffer, &offset, len, &ok);
389 389
 		inst.u.branch.br_false = readBBID(bcfunc, buffer, &offset, len, &ok);
390 390
 		break;
391
+	    case OP_CALL_DIRECT:
392
+		numOp = readFixedNumber(buffer, &offset, len, &ok, 1)+1;
393
+		if (ok) {
394
+		    inst.u.ops.numOps = numOp;
395
+		    inst.u.ops.ops = cli_calloc(numOp, sizeof(*inst.u.ops.ops));
396
+		    if (!inst.u.ops.ops) {
397
+			cli_errmsg("Out of memory allocating operands\n");
398
+			return CL_EMALFDB;
399
+		    }
400
+		    for (i=0;i<numOp;i++) {
401
+			inst.u.ops.ops[i] = readOperand(buffer, &offset, len, &ok);
402
+		    }
403
+		}
404
+		break;
391 405
 	    default:
392 406
 		numOp = operand_counts[inst.opcode];
393 407
 		switch (numOp) {
... ...
@@ -404,15 +418,8 @@ static int parseBB(struct cli_bc *bc, unsigned func, unsigned bb, unsigned char
404 404
 			inst.u.three[2] = readOperand(buffer, &offset, len, &ok);
405 405
 			break;
406 406
 		    default:
407
-			inst.u.ops.numOps = numOp;
408
-			inst.u.ops.ops = cli_calloc(numOp, sizeof(*inst.u.ops.ops));
409
-			if (!inst.u.ops.ops) {
410
-			    cli_errmsg("Out of memory allocating operands\n");
411
-			    return CL_EMALFDB;
412
-			}
413
-			for (i=0;i<numOp;i++) {
414
-			    inst.u.ops.ops[i] = readOperand(buffer, &offset, len, &ok);
415
-			}
407
+			cli_errmsg("Opcode with too many operands: %u?\n", numOp);
408
+			ok = 0;
416 409
 			break;
417 410
 		}
418 411
 	}
... ...
@@ -65,6 +65,7 @@ enum bc_opcode {
65 65
   OP_ICMP_SLE,
66 66
   OP_ICMP_SLT,
67 67
   OP_SELECT,
68
+  OP_CALL_DIRECT,
68 69
   OP_INVALID /* last */
69 70
 };
70 71
 
... ...
@@ -79,6 +80,8 @@ static const unsigned char operand_counts[] = {
79 79
   /* ICMP */
80 80
   2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
81 81
   /* SELECT */
82
-  3
82
+  3,
83
+  /* CALLs have variable number of operands */
84
+  0
83 85
 };
84 86
 #endif