comparison lwasm/pseudo.c @ 186:1824cabf25ce

Various enhancements to lwasm
author lost@l-w.ca
date Thu, 22 Dec 2011 18:04:13 -0700
parents 5965c01b3dec
children fa835b780ffb
comparison
equal deleted inserted replaced
185:cca933d32298 186:1824cabf25ce
1446 { 1446 {
1447 lwasm_emitexpr(l, e, 1); 1447 lwasm_emitexpr(l, e, 1);
1448 } 1448 }
1449 } 1449 }
1450 1450
1451 PARSEFUNC(pseudo_parse_fill)
1452 {
1453 lw_expr_t e, e1;
1454 if (!**p)
1455 {
1456 lwasm_register_error(as, l, "Bad operand");
1457 return;
1458 }
1459
1460 e1 = lwasm_parse_expr(as, p);
1461 if (**p != ',')
1462 {
1463 lwasm_register_error(as, l, "Bad operand");
1464 return;
1465 }
1466 (*p)++;
1467 e = lwasm_parse_expr(as, p);
1468
1469 if (!e)
1470 {
1471 lwasm_register_error(as, l, "Bad operand");
1472 return;
1473 }
1474
1475 lwasm_save_expr(l, 0, e);
1476 lwasm_save_expr(l, 1, e1);
1477
1478 if (!e1)
1479 {
1480 lwasm_register_error(as, l, "Bad padding");
1481 return;
1482 }
1483 }
1484
1485 RESOLVEFUNC(pseudo_resolve_fill)
1486 {
1487 lw_expr_t e;
1488 int align;
1489
1490 e = lwasm_fetch_expr(l, 0);
1491
1492 if (lw_expr_istype(e, lw_expr_type_int))
1493 {
1494 align = lw_expr_intval(e);
1495 if (align < 1)
1496 {
1497 lwasm_register_error(as, l, "Invalid fill length");
1498 return;
1499 }
1500 }
1501
1502 if (lw_expr_istype(l -> addr, lw_expr_type_int))
1503 {
1504 l -> len = align;
1505 return;
1506 }
1507 }
1508
1509 EMITFUNC(pseudo_emit_fill)
1510 {
1511 lw_expr_t e;
1512 int i;
1513
1514 e = lwasm_fetch_expr(l, 1);
1515 for (i = 0; i < l -> len; i++)
1516 {
1517 lwasm_emitexpr(l, e, 1);
1518 }
1519 }
1520
1451 /* string conditional argument parser */ 1521 /* string conditional argument parser */
1452 /* 1522 /*
1453 argument syntax: 1523 argument syntax:
1454 1524
1455 a bare word ended by whitespace, comma, or NUL 1525 a bare word ended by whitespace, comma, or NUL