ref: 544097136c80b4754ac5905f948b802fdb9e090e
parent: bcfb495c00ea175223148a037ce64f8cc9504c57
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Nov 17 09:03:39 EST 2017
[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.
--- a/as/as.h
+++ b/as/as.h
@@ -105,7 +105,6 @@
};
/* 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);
@@ -134,6 +133,9 @@
/* proc.c */
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
--- a/as/ins.c
+++ b/as/ins.c
@@ -3,6 +3,24 @@
#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 @@
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
--- a/as/symbol.c
+++ b/as/symbol.c
@@ -143,24 +143,6 @@
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)
{