comparison lwasm/pseudo.c @ 519:724bcc4508bc

Add SETSTR/INCLUDESTR for some basic code building It seemed useful to have the ability to build up a variable containing arbitrary text and then to be able to include that in the assembly process like an include file. So add, undocumented for now, the following: SETTSTR varname="string" INCLUDESTSR "string" "string" must be enclosed in double quotes and may contain most of the usual escape sequences (\t, \r, etc.) as well as %(varname) to interpolate a variable value. To use it to create assembleable source code, you need to make sure it creates lines (ended by either \r or \n) with appropriate whitespace in appropriate places.
author William Astle <lost@l-w.ca>
date Sun, 19 Dec 2021 17:01:42 -0700
parents c33b4abff860
children 56c32bc798f8
comparison
equal deleted inserted replaced
518:b530ff19f7c0 519:724bcc4508bc
1581 l -> hideline = 1; 1581 l -> hideline = 1;
1582 l -> len = 0; 1582 l -> len = 0;
1583 lw_free(fn); 1583 lw_free(fn);
1584 } 1584 }
1585 1585
1586 PARSEFUNC(pseudo_parse_includestr)
1587 {
1588 char *str;
1589 char buf[110];
1590
1591 l -> len = 0;
1592
1593 if (!**p)
1594 {
1595 // no operand - include nothing
1596 return;
1597 }
1598
1599 str = lwasm_parse_general_string(l, p);
1600 if (!str)
1601 {
1602 // string parsing failed
1603 return;
1604 }
1605 if (*str == '\0')
1606 {
1607 // empty string; don't do anything
1608 lw_free(str);
1609 return;
1610 }
1611
1612 /* add a book-keeping entry for line numbers */
1613 snprintf(buf, 100, "\001\001SETLINENO %d\n", l -> lineno + 1);
1614 input_openstring(as, "INTERNAL", buf);
1615
1616 /* add the constructed string to the input */
1617 input_openstring(as, "INCLUDESTR", str);
1618 lw_free(str);
1619 }
1620
1586 PARSEFUNC(pseudo_parse_align) 1621 PARSEFUNC(pseudo_parse_align)
1587 { 1622 {
1588 lw_expr_t e; 1623 lw_expr_t e;
1589 if (!**p) 1624 if (!**p)
1590 { 1625 {