Mercurial > hg > index.cgi
comparison lwasm/pseudo.c @ 266:35c051bffbff
Make fill and align do something useful in the object target
Now, instead of being ignored, both directives will work on the offset from
the start of the section instance in the current file. In a bss or constant
section, no code will be emitted regardless of the padding byte specified.
Otherwise, code will be emitted as usual.
author | William Astle <lost@l-w.ca> |
---|---|
date | Sat, 09 Mar 2013 11:11:51 -0700 |
parents | 346966cffeef |
children | 4370370f38d1 |
comparison
equal
deleted
inserted
replaced
265:6f4c4d59666f | 266:35c051bffbff |
---|---|
1474 | 1474 |
1475 RESOLVEFUNC(pseudo_resolve_align) | 1475 RESOLVEFUNC(pseudo_resolve_align) |
1476 { | 1476 { |
1477 lw_expr_t e; | 1477 lw_expr_t e; |
1478 int align = 1; | 1478 int align = 1; |
1479 | 1479 lw_expr_t te; |
1480 int a; | |
1481 | |
1480 e = lwasm_fetch_expr(l, 0); | 1482 e = lwasm_fetch_expr(l, 0); |
1481 | 1483 |
1482 if (lw_expr_istype(e, lw_expr_type_int)) | 1484 if (lw_expr_istype(e, lw_expr_type_int)) |
1483 { | 1485 { |
1484 align = lw_expr_intval(e); | 1486 align = lw_expr_intval(e); |
1486 { | 1488 { |
1487 lwasm_register_error(as, l, "Invalid alignment"); | 1489 lwasm_register_error(as, l, "Invalid alignment"); |
1488 return; | 1490 return; |
1489 } | 1491 } |
1490 } | 1492 } |
1491 | 1493 else |
1492 if (lw_expr_istype(l -> addr, lw_expr_type_int)) | 1494 { |
1493 { | 1495 return; |
1494 int a; | 1496 } |
1495 a = lw_expr_intval(l -> addr); | 1497 |
1498 | |
1499 te = lw_expr_copy(l -> addr); | |
1500 as -> exportcheck = 1; | |
1501 lwasm_reduce_expr(as, te); | |
1502 as -> exportcheck = 0; | |
1503 | |
1504 if (lw_expr_istype(te, lw_expr_type_int)) | |
1505 { | |
1506 a = lw_expr_intval(te); | |
1507 } | |
1508 else | |
1509 { | |
1510 a = -1; | |
1511 } | |
1512 lw_expr_destroy(te); | |
1513 | |
1514 if (a >= 0) | |
1515 { | |
1496 if (a % align == 0) | 1516 if (a % align == 0) |
1497 { | 1517 { |
1498 l -> len = 0; | 1518 l -> len = 0; |
1499 return; | 1519 return; |
1500 } | 1520 } |
1506 EMITFUNC(pseudo_emit_align) | 1526 EMITFUNC(pseudo_emit_align) |
1507 { | 1527 { |
1508 lw_expr_t e; | 1528 lw_expr_t e; |
1509 int i; | 1529 int i; |
1510 | 1530 |
1531 if (l -> csect && (l -> csect -> flags & (section_flag_bss | section_flag_constant))) | |
1532 return; | |
1511 e = lwasm_fetch_expr(l, 1); | 1533 e = lwasm_fetch_expr(l, 1); |
1512 for (i = 0; i < l -> len; i++) | 1534 for (i = 0; i < l -> len; i++) |
1513 { | 1535 { |
1514 lwasm_emitexpr(l, e, 1); | 1536 lwasm_emitexpr(l, e, 1); |
1515 } | 1537 } |
1549 } | 1571 } |
1550 } | 1572 } |
1551 | 1573 |
1552 RESOLVEFUNC(pseudo_resolve_fill) | 1574 RESOLVEFUNC(pseudo_resolve_fill) |
1553 { | 1575 { |
1554 lw_expr_t e; | 1576 lw_expr_t e, te; |
1555 int align = 1; | 1577 int align = 1; |
1556 | 1578 |
1557 e = lwasm_fetch_expr(l, 0); | 1579 e = lwasm_fetch_expr(l, 0); |
1558 | 1580 |
1559 if (lw_expr_istype(e, lw_expr_type_int)) | 1581 te = lw_expr_copy(e); |
1560 { | 1582 as -> exportcheck = 1; |
1561 align = lw_expr_intval(e); | 1583 lwasm_reduce_expr(as, te); |
1562 if (align < 1) | 1584 as -> exportcheck = 0; |
1563 { | 1585 |
1586 if (lw_expr_istype(te, lw_expr_type_int)) | |
1587 { | |
1588 align = lw_expr_intval(te); | |
1589 if (align < 0) | |
1590 { | |
1591 lw_expr_destroy(te); | |
1564 lwasm_register_error(as, l, "Invalid fill length"); | 1592 lwasm_register_error(as, l, "Invalid fill length"); |
1565 return; | 1593 return; |
1566 } | 1594 } |
1567 } | 1595 } |
1568 | 1596 else |
1569 if (lw_expr_istype(l -> addr, lw_expr_type_int)) | 1597 { |
1570 { | 1598 lw_expr_destroy(te); |
1571 l -> len = align; | 1599 return; |
1572 return; | 1600 } |
1573 } | 1601 lw_expr_destroy(te); |
1602 | |
1603 l -> len = align; | |
1574 } | 1604 } |
1575 | 1605 |
1576 EMITFUNC(pseudo_emit_fill) | 1606 EMITFUNC(pseudo_emit_fill) |
1577 { | 1607 { |
1578 lw_expr_t e; | 1608 lw_expr_t e; |
1579 int i; | 1609 int i; |
1610 | |
1611 /* don't emit anything in bss */ | |
1612 if (l -> csect && (l -> csect -> flags & (section_flag_bss | section_flag_constant))) | |
1613 return; | |
1580 | 1614 |
1581 e = lwasm_fetch_expr(l, 1); | 1615 e = lwasm_fetch_expr(l, 1); |
1582 for (i = 0; i < l -> len; i++) | 1616 for (i = 0; i < l -> len; i++) |
1583 { | 1617 { |
1584 lwasm_emitexpr(l, e, 1); | 1618 lwasm_emitexpr(l, e, 1); |