scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 74488c63a586f4c4e2ab6c5b7a3b0fde8afeb021
parent 8beaaef5c3c15d1ca09f114e4ff62057a319571a
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 17 Nov 2017 14:03:39 +0000

[as] Move pack() to tobytes()

Pack is a too good name for other function. This patch
also moves the function out of symbol, and it puts it
in ins.c.

Diffstat:
Mas/as.h | 4+++-
Mas/ins.c | 20+++++++++++++++++++-
Mas/symbol.c | 18------------------
3 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/as/as.h b/as/as.h @@ -105,7 +105,6 @@ struct node { }; /* symbol.c */ -extern char *pack(TUINT v, int n, int inc); extern void isections(void); extern void writeout(char *name); extern void emit(Section *sec, char *bytes, int nbytes); @@ -135,6 +134,9 @@ extern void deltree(Node *np); extern void iarch(void); extern int match(Op *op, Node **args); +/* ins.c */ +extern char *tobytes(TUINT v, int n, int inc); + /* * Definition of global variables */ diff --git a/as/ins.c b/as/ins.c @@ -3,6 +3,24 @@ static char sccsid[] = "@(#) ./as/ins.c"; #include "../inc/scc.h" #include "as.h" +char * +tobytes(TUINT v, int nbytes, int inc) +{ + static char buf[sizeof(TUINT)]; + int idx; + + idx = (inc < 0) ? nbytes-1 : 0; + while (nbytes--) { + buf[idx] = v; + idx += inc; + v >>= 8; + } + + if (v) + error("overflow in immediate value"); + return buf; +} + void noargs(Op *op, Node **args) { @@ -15,7 +33,7 @@ def(Node **args, int siz) Node *np; for ( ; np = *args; ++args) - emit(cursec, pack(np->sym->value, siz, endian), siz); + emit(cursec, tobytes(np->sym->value, siz, endian), siz); } void diff --git a/as/symbol.c b/as/symbol.c @@ -143,24 +143,6 @@ toobig(Node *np, int type) return 0; } -char * -pack(TUINT v, int n, int inc) -{ - static char buf[sizeof(TUINT)]; - int idx; - - idx = (inc < 0) ? n-1 : 0; - while (n--) { - buf[idx] = v; - idx += inc; - v >>= 8; - } - - if (v) - error("overflow in immediate value"); - return buf; -} - static void incpc(int siz) {