Mercurial > hg > index.cgi
comparison lwasm/lwasm.c @ 399:6153cb49403c
Initial commit of pragma newsource
pragma newsource enables a source code variant as follows:
1. no line numbers
2. no implied comments at the end of lines
3. all comments must be introduced by a comment character
4. spaces are allowed in operands
(4) is not quite complete. This commit handles "operandless" instructions
(anything where the parser calls skip_operand()) and expression parsing.
author | William Astle <lost@l-w.ca> |
---|---|
date | Tue, 13 Oct 2015 23:38:02 -0600 |
parents | f813a56178c0 |
children | f8e56377a32a |
comparison
equal
deleted
inserted
replaced
398:4cf907aa634c | 399:6153cb49403c |
---|---|
29 #include <lw_string.h> | 29 #include <lw_string.h> |
30 #include <lw_error.h> | 30 #include <lw_error.h> |
31 | 31 |
32 #include "lwasm.h" | 32 #include "lwasm.h" |
33 #include "instab.h" | 33 #include "instab.h" |
34 | |
35 void lwasm_skip_to_next_token(line_t *cl, char **p) | |
36 { | |
37 if (CURPRAGMA(cl, PRAGMA_NEWSOURCE)) | |
38 { | |
39 for (; **p && isspace(**p); (*p)++) | |
40 /* do nothing */ ; | |
41 } | |
42 } | |
34 | 43 |
35 int lwasm_expr_exportable(asmstate_t *as, lw_expr_t expr) | 44 int lwasm_expr_exportable(asmstate_t *as, lw_expr_t expr) |
36 { | 45 { |
37 return 0; | 46 return 0; |
38 } | 47 } |
867 lw_expr_t e; | 876 lw_expr_t e; |
868 | 877 |
869 if (as->exprwidth != 16) | 878 if (as->exprwidth != 16) |
870 { | 879 { |
871 lw_expr_setwidth(as->exprwidth); | 880 lw_expr_setwidth(as->exprwidth); |
872 e = lw_expr_parse(p, as); | 881 if (CURPRAGMA(as -> cl, PRAGMA_NEWSOURCE)) |
882 e = lw_expr_parse(p, as); | |
883 else | |
884 e = lw_expr_parse_compact(p, as); | |
873 lw_expr_setwidth(0); | 885 lw_expr_setwidth(0); |
874 } | 886 } |
875 else | 887 else |
876 { | 888 { |
877 e = lw_expr_parse(p, as); | 889 if (CURPRAGMA(as -> cl, PRAGMA_NEWSOURCE)) |
878 } | 890 e = lw_expr_parse(p, as); |
891 else | |
892 e = lw_expr_parse_compact(p, as); | |
893 } | |
894 lwasm_skip_to_next_token(as -> cl, p); | |
879 return e; | 895 return e; |
880 } | 896 } |
881 | 897 |
882 int lwasm_reduce_expr(asmstate_t *as, lw_expr_t expr) | 898 int lwasm_reduce_expr(asmstate_t *as, lw_expr_t expr) |
883 { | 899 { |
919 } | 935 } |
920 } | 936 } |
921 return NULL; | 937 return NULL; |
922 } | 938 } |
923 | 939 |
924 void skip_operand(char **p) | 940 void skip_operand_real(line_t *cl, char **p) |
925 { | 941 { |
942 if (CURPRAGMA(cl, PRAGMA_NEWSOURCE)) | |
943 return; | |
926 for (; **p && !isspace(**p); (*p)++) | 944 for (; **p && !isspace(**p); (*p)++) |
927 /* do nothing */ ; | 945 /* do nothing */ ; |
928 } | 946 } |
929 | 947 |
930 int lwasm_emitexpr(line_t *l, lw_expr_t expr, int size) | 948 int lwasm_emitexpr(line_t *l, lw_expr_t expr, int size) |