Mercurial > hg-old > index.cgi
diff lwasm/lwasm.c @ 347:1649bc7bda5a
Some data oriented pseudo ops added
author | lost@starbug |
---|---|
date | Sat, 27 Mar 2010 20:16:24 -0600 |
parents | a82c55070624 |
children | 11a95c6414b4 |
line wrap: on
line diff
--- a/lwasm/lwasm.c Sat Mar 27 19:04:03 2010 -0600 +++ b/lwasm/lwasm.c Sat Mar 27 20:16:24 2010 -0600 @@ -431,3 +431,76 @@ return e; } + +void lwasm_save_expr(line_t *cl, int id, lw_expr_t expr) +{ + struct line_expr_s *e; + + for (e = cl -> exprs; e; e = e -> next) + { + if (e -> id == id) + { + lw_expr_destroy(e -> expr); + e -> expr = expr; + return; + } + } + + e = lw_alloc(sizeof(struct line_expr_s)); + e -> expr = expr; + e -> id = id; + e -> next = cl -> exprs; + cl -> exprs = e; +} + +lw_expr_t lwasm_fetch_expr(line_t *cl, int id) +{ + struct line_expr_s *e; + + for (e = cl -> exprs; e; e = e -> next) + { + if (e -> id == id) + { + return e -> expr; + } + } + return NULL; +} + +void skip_operand(char **p) +{ + for (; **p && !isspace(**p); (*p)++) + /* do nothing */ ; +} + +int lwasm_emitexpr(line_t *l, lw_expr_t expr, int size) +{ + int v; + + if (lw_expr_istype(expr, lw_expr_type_int)) + { + v = lw_expr_intval(expr); + } + else + { + lwasm_register_error(l -> as, l, "Expression not fully resolved"); + return -1; + } + + switch (size) + { + case 4: + lwasm_emit(l, v >> 24); + lwasm_emit(l, v >> 16); + /* fallthrough intended */ + + case 2: + lwasm_emit(l, v >> 8); + /* fallthrough intended */ + + case 1: + lwasm_emit(l, v); + } + + return 0; +}