Auto-format dasm_s390x.h.

I did this mostly to get rid of the annoying tabs/spaces mix in this
file. It has the side effect of forcing newlines before statements
which I think is a better style (and not particularly inconsistent
with the original which used both styles). Other than that I've tried
to match the original style as closely as possible.

Generated with this command:

indent -i2 -brs -cli0 -br -ce -npcs -nbc -di1 -npsl -ncs dasm_s390x.h
This commit is contained in:
Michael Munday 2016-12-02 13:41:45 -05:00
parent 621ae87058
commit fc2b633532

View File

@ -21,7 +21,9 @@ enum {
/* The following actions need a buffer position. */ /* The following actions need a buffer position. */
DASM_ALIGN, DASM_REL_LG, DASM_LABEL_LG, DASM_ALIGN, DASM_REL_LG, DASM_LABEL_LG,
/* The following actions also have an argument. */ /* The following actions also have an argument. */
DASM_REL_PC, DASM_LABEL_PC, DASM_DISP12, DASM_DISP20, DASM_IMM16, DASM_IMM32, DASM_REL_PC, DASM_LABEL_PC,
DASM_DISP12, DASM_DISP20,
DASM_IMM16, DASM_IMM32,
DASM__MAX DASM__MAX
}; };
@ -113,8 +115,10 @@ void dasm_free(Dst_DECL)
for (i = 0; i < D->maxsection; i++) for (i = 0; i < D->maxsection; i++)
if (D->sections[i].buf) if (D->sections[i].buf)
DASM_M_FREE(Dst, D->sections[i].buf, D->sections[i].bsize); DASM_M_FREE(Dst, D->sections[i].buf, D->sections[i].bsize);
if (D->pclabels) DASM_M_FREE(Dst, D->pclabels, D->pcsize); if (D->pclabels)
if (D->lglabels) DASM_M_FREE(Dst, D->lglabels, D->lgsize); DASM_M_FREE(Dst, D->pclabels, D->pcsize);
if (D->lglabels)
DASM_M_FREE(Dst, D->lglabels, D->lgsize);
DASM_M_FREE(Dst, D, D->psize); DASM_M_FREE(Dst, D, D->psize);
} }
@ -123,7 +127,7 @@ void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl)
{ {
dasm_State *D = Dst_REF; dasm_State *D = Dst_REF;
D->globals = gl - 10; /* Negative bias to compensate for locals. */ D->globals = gl - 10; /* Negative bias to compensate for locals. */
DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int)); DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10 + maxgl) * sizeof(int));
} }
/* Grow PC label array. Can be called after dasm_setup(), too. */ /* Grow PC label array. Can be called after dasm_setup(), too. */
@ -131,8 +135,8 @@ void dasm_growpc(Dst_DECL, unsigned int maxpc)
{ {
dasm_State *D = Dst_REF; dasm_State *D = Dst_REF;
size_t osz = D->pcsize; size_t osz = D->pcsize;
DASM_M_GROW(Dst, int, D->pclabels, D->pcsize, maxpc*sizeof(int)); DASM_M_GROW(Dst, int, D->pclabels, D->pcsize, maxpc * sizeof(int));
memset((void *)(((unsigned char *)D->pclabels)+osz), 0, D->pcsize-osz); memset((void *)(((unsigned char *)D->pclabels) + osz), 0, D->pcsize - osz);
} }
/* Setup encoder. */ /* Setup encoder. */
@ -140,11 +144,12 @@ void dasm_setup(Dst_DECL, const void *actionlist)
{ {
dasm_State *D = Dst_REF; dasm_State *D = Dst_REF;
int i; int i;
D->actionlist = (dasm_ActList)actionlist; D->actionlist = (dasm_ActList) actionlist;
D->status = DASM_S_OK; D->status = DASM_S_OK;
D->section = &D->sections[0]; D->section = &D->sections[0];
memset((void *)D->lglabels, 0, D->lgsize); memset((void *)D->lglabels, 0, D->lgsize);
if (D->pclabels) memset((void *)D->pclabels, 0, D->pcsize); if (D->pclabels)
memset((void *)D->pclabels, 0, D->pcsize);
for (i = 0; i < D->maxsection; i++) { for (i = 0; i < D->maxsection; i++) {
D->sections[i].pos = DASM_SEC2POS(i); D->sections[i].pos = DASM_SEC2POS(i);
D->sections[i].ofs = 0; D->sections[i].ofs = 0;
@ -176,9 +181,10 @@ void dasm_put(Dst_DECL, int start, ...)
if (pos >= sec->epos) { if (pos >= sec->epos) {
DASM_M_GROW(Dst, int, sec->buf, sec->bsize, DASM_M_GROW(Dst, int, sec->buf, sec->bsize,
sec->bsize + 2*DASM_MAXSECPOS*sizeof(int)); sec->bsize + 2 * DASM_MAXSECPOS * sizeof(int));
sec->rbuf = sec->buf - DASM_POS2BIAS(pos); sec->rbuf = sec->buf - DASM_POS2BIAS(pos);
sec->epos = (int)sec->bsize/sizeof(int) - DASM_MAXSECPOS+DASM_POS2BIAS(pos); sec->epos =
(int)sec->bsize / sizeof(int) - DASM_MAXSECPOS + DASM_POS2BIAS(pos);
} }
b = sec->rbuf; b = sec->rbuf;
@ -193,22 +199,40 @@ void dasm_put(Dst_DECL, int start, ...)
} else { } else {
int *pl, n = action >= DASM_REL_PC ? va_arg(ap, int) : 0; int *pl, n = action >= DASM_REL_PC ? va_arg(ap, int) : 0;
switch (action) { switch (action) {
case DASM_STOP: goto stop; case DASM_STOP:
goto stop;
case DASM_SECTION: case DASM_SECTION:
n = (ins & 255); CK(n < D->maxsection, RANGE_SEC); n = (ins & 255);
D->section = &D->sections[n]; goto stop; CK(n < D->maxsection, RANGE_SEC);
case DASM_ESC: p++; ofs += 4; break; D->section = &D->sections[n];
case DASM_REL_EXT: break; goto stop;
case DASM_ALIGN: ofs += (ins & 255); b[pos++] = ofs; break; case DASM_ESC:
p++;
ofs += 4;
break;
case DASM_REL_EXT:
break;
case DASM_ALIGN:
ofs += (ins & 255);
b[pos++] = ofs;
break;
case DASM_REL_LG: case DASM_REL_LG:
n = (ins & 2047) - 10; pl = D->lglabels + n; n = (ins & 2047) - 10;
pl = D->lglabels + n;
/* Bkwd rel or global. */ /* Bkwd rel or global. */
if (n >= 0) { CK(n>=10||*pl<0, RANGE_LG); CKPL(lg, LG); goto putrel; } if (n >= 0) {
pl += 10; n = *pl; CK(n >= 10 || *pl < 0, RANGE_LG);
if (n < 0) n = 0; /* Start new chain for fwd rel if label exists. */ CKPL(lg, LG);
goto putrel;
}
pl += 10;
n = *pl;
if (n < 0)
n = 0; /* Start new chain for fwd rel if label exists. */
goto linkrel; goto linkrel;
case DASM_REL_PC: case DASM_REL_PC:
pl = D->pclabels + n; CKPL(pc, PC); pl = D->pclabels + n;
CKPL(pc, PC);
putrel: putrel:
n = *pl; n = *pl;
if (n < 0) { /* Label exists. Get label pos and store it. */ if (n < 0) { /* Label exists. Get label pos and store it. */
@ -221,12 +245,18 @@ void dasm_put(Dst_DECL, int start, ...)
pos++; pos++;
break; break;
case DASM_LABEL_LG: case DASM_LABEL_LG:
pl = D->lglabels + (ins & 2047) - 10; CKPL(lg, LG); goto putlabel; pl = D->lglabels + (ins & 2047) - 10;
CKPL(lg, LG);
goto putlabel;
case DASM_LABEL_PC: case DASM_LABEL_PC:
pl = D->pclabels + n; CKPL(pc, PC); pl = D->pclabels + n;
CKPL(pc, PC);
putlabel: putlabel:
n = *pl; /* n > 0: Collapse rel chain and replace with label pos. */ n = *pl; /* n > 0: Collapse rel chain and replace with label pos. */
while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = pos; while (n > 0) {
int *pb = DASM_POS2PTR(D, n);
n = *pb;
*pb = pos;
} }
*pl = -pos; /* Label exists now. */ *pl = -pos; /* Label exists now. */
b[pos++] = ofs; /* Store pass1 offset estimate. */ b[pos++] = ofs; /* Store pass1 offset estimate. */
@ -237,15 +267,15 @@ void dasm_put(Dst_DECL, int start, ...)
break; break;
case DASM_IMM32: case DASM_IMM32:
ofs += 4; ofs += 4;
CK((n>>32) == 0, RANGE_I); CK((n >> 32) == 0, RANGE_I);
b[pos++]=n; b[pos++] = n;
break; break;
case DASM_DISP20: case DASM_DISP20:
CK(-(1<<19) <= n && n < (1<<19), RANGE_I); CK(-(1 << 19) <= n && n < (1 << 19), RANGE_I);
b[pos++] = n; b[pos++] = n;
break; break;
case DASM_DISP12: case DASM_DISP12:
CK((n>>12) == 0, RANGE_I); CK((n >> 12) == 0, RANGE_I);
b[pos++] = n; b[pos++] = n;
break; break;
} }
@ -256,10 +286,11 @@ stop:
sec->pos = pos; sec->pos = pos;
sec->ofs = ofs; sec->ofs = ofs;
} }
#undef CK #undef CK
/* Pass 2: Link sections, shrink aligns, fix label offsets. */ /* Pass 2: Link sections, shrink aligns, fix label offsets. */
int dasm_link(Dst_DECL, size_t *szp) int dasm_link(Dst_DECL, size_t * szp)
{ {
dasm_State *D = Dst_REF; dasm_State *D = Dst_REF;
int secnum; int secnum;
@ -267,20 +298,26 @@ int dasm_link(Dst_DECL, size_t *szp)
#ifdef DASM_CHECKS #ifdef DASM_CHECKS
*szp = 0; *szp = 0;
if (D->status != DASM_S_OK) return D->status; if (D->status != DASM_S_OK)
return D->status;
{ {
int pc; int pc;
for (pc = 0; pc*sizeof(int) < D->pcsize; pc++) for (pc = 0; pc * sizeof(int) < D->pcsize; pc++)
if (D->pclabels[pc] > 0) return DASM_S_UNDEF_PC|pc; if (D->pclabels[pc] > 0)
return DASM_S_UNDEF_PC | pc;
} }
#endif #endif
{ /* Handle globals not defined in this translation unit. */ { /* Handle globals not defined in this translation unit. */
int idx; int idx;
for (idx = 20; idx*sizeof(int) < D->lgsize; idx++) { for (idx = 20; idx * sizeof(int) < D->lgsize; idx++) {
int n = D->lglabels[idx]; int n = D->lglabels[idx];
/* Undefined label: Collapse rel chain and replace with marker (< 0). */ /* Undefined label: Collapse rel chain and replace with marker (< 0). */
while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = -idx; } while (n > 0) {
int *pb = DASM_POS2PTR(D, n);
n = *pb;
*pb = -idx;
}
} }
} }
@ -297,12 +334,25 @@ int dasm_link(Dst_DECL, size_t *szp)
unsigned short ins = *p++; unsigned short ins = *p++;
unsigned short action = ins; unsigned short action = ins;
switch (action) { switch (action) {
case DASM_STOP: case DASM_SECTION: goto stop; case DASM_STOP:
case DASM_ESC: p++; break; case DASM_SECTION:
case DASM_REL_EXT: break; goto stop;
case DASM_ALIGN: ofs -= (b[pos++] + ofs) & (ins & 255); break; case DASM_ESC:
case DASM_REL_LG: case DASM_REL_PC: pos++; break; p++;
case DASM_LABEL_LG: case DASM_LABEL_PC: b[pos++] += ofs; break; break;
case DASM_REL_EXT:
break;
case DASM_ALIGN:
ofs -= (b[pos++] + ofs) & (ins & 255);
break;
case DASM_REL_LG:
case DASM_REL_PC:
pos++;
break;
case DASM_LABEL_LG:
case DASM_LABEL_PC:
b[pos++] += ofs;
break;
case DASM_IMM16: case DASM_IMM16:
case DASM_IMM32: case DASM_IMM32:
case DASM_DISP20: case DASM_DISP20:
@ -311,7 +361,7 @@ int dasm_link(Dst_DECL, size_t *szp)
break; break;
} }
} }
stop: (void)0; stop:(void)0;
} }
ofs += sec->ofs; /* Next section starts right after current section. */ ofs += sec->ofs; /* Next section starts right after current section. */
} }
@ -349,13 +399,19 @@ int dasm_encode(Dst_DECL, void *buffer)
unsigned short action = ins; unsigned short action = ins;
int n = (action >= DASM_ALIGN && action < DASM__MAX) ? *b++ : 0; int n = (action >= DASM_ALIGN && action < DASM__MAX) ? *b++ : 0;
switch (action) { switch (action) {
case DASM_STOP: case DASM_SECTION: goto stop; case DASM_STOP:
case DASM_ESC: *cp++ = *p++; break; case DASM_SECTION:
goto stop;
case DASM_ESC:
*cp++ = *p++;
break;
case DASM_REL_EXT: case DASM_REL_EXT:
n = DASM_EXTERN(Dst, (unsigned char *)cp, (ins & 2047), 1) - 4; n = DASM_EXTERN(Dst, (unsigned char *)cp, (ins & 2047), 1) - 4;
goto patchrel; goto patchrel;
case DASM_ALIGN: case DASM_ALIGN:
ins &= 255; while ((((char *)cp - base) & ins)) *cp++ = 0x0707; ins &= 255;
while ((((char *)cp - base) & ins))
*cp++ = 0x0707;
break; break;
case DASM_REL_LG: case DASM_REL_LG:
CK(n >= 0, UNDEF_LG); CK(n >= 0, UNDEF_LG);
@ -364,14 +420,17 @@ int dasm_encode(Dst_DECL, void *buffer)
n = *DASM_POS2PTR(D, n) - (int)((char *)cp - base); n = *DASM_POS2PTR(D, n) - (int)((char *)cp - base);
patchrel: patchrel:
CK((n & 3) == 0 && CK((n & 3) == 0 &&
(((n+4) + ((ins & 2048) ? 0x00008000 : 0x02000000)) >> (((n + 4) + ((ins & 2048) ? 0x00008000 : 0x02000000)) >>
((ins & 2048) ? 16 : 26)) == 0, RANGE_REL); ((ins & 2048) ? 16 : 26)) == 0, RANGE_REL);
cp[-1] |= ((n+4) & ((ins & 2048) ? 0x0000fffc: 0x03fffffc)); cp[-1] |= ((n + 4) & ((ins & 2048) ? 0x0000fffc : 0x03fffffc));
break; break;
case DASM_LABEL_LG: case DASM_LABEL_LG:
ins &= 2047; if (ins >= 20) D->globals[ins-10] = (void *)(base + n); ins &= 2047;
if (ins >= 20)
D->globals[ins - 10] = (void *)(base + n);
break;
case DASM_LABEL_PC:
break; break;
case DASM_LABEL_PC: break;
case DASM_IMM16: case DASM_IMM16:
fprintf(stderr, "DASM_IMM16 not implemented\n"); fprintf(stderr, "DASM_IMM16 not implemented\n");
break; break;
@ -380,16 +439,18 @@ int dasm_encode(Dst_DECL, void *buffer)
*cp++ = n; *cp++ = n;
break; break;
case DASM_DISP20: case DASM_DISP20:
cp[-2] |= n&0xfff; cp[-2] |= n & 0xfff;
cp[-1] |= (n>>4)&0xff00; cp[-1] |= (n >> 4) & 0xff00;
break; break;
case DASM_DISP12: case DASM_DISP12:
cp[-1] |= n&0xfff; cp[-1] |= n & 0xfff;
break;
default:
*cp++ = ins;
break; break;
default: *cp++ = ins; break;
} }
} }
stop: (void)0; stop:(void)0;
} }
} }
@ -397,16 +458,19 @@ int dasm_encode(Dst_DECL, void *buffer)
return DASM_S_PHASE; return DASM_S_PHASE;
return DASM_S_OK; return DASM_S_OK;
} }
#undef CK #undef CK
/* Get PC label offset. */ /* Get PC label offset. */
int dasm_getpclabel(Dst_DECL, unsigned int pc) int dasm_getpclabel(Dst_DECL, unsigned int pc)
{ {
dasm_State *D = Dst_REF; dasm_State *D = Dst_REF;
if (pc*sizeof(int) < D->pcsize) { if (pc * sizeof(int) < D->pcsize) {
int pos = D->pclabels[pc]; int pos = D->pclabels[pc];
if (pos < 0) return *DASM_POS2PTR(D, -pos); if (pos < 0)
if (pos > 0) return -1; /* Undefined. */ return *DASM_POS2PTR(D, -pos);
if (pos > 0)
return -1; /* Undefined. */
} }
return -2; /* Unused or out of range. */ return -2; /* Unused or out of range. */
} }
@ -419,13 +483,16 @@ int dasm_checkstep(Dst_DECL, int secmatch)
if (D->status == DASM_S_OK) { if (D->status == DASM_S_OK) {
int i; int i;
for (i = 1; i <= 9; i++) { for (i = 1; i <= 9; i++) {
if (D->lglabels[i] > 0) { D->status = DASM_S_UNDEF_LG|i; break; } if (D->lglabels[i] > 0) {
D->status = DASM_S_UNDEF_LG | i;
break;
}
D->lglabels[i] = 0; D->lglabels[i] = 0;
} }
} }
if (D->status == DASM_S_OK && secmatch >= 0 && if (D->status == DASM_S_OK && secmatch >= 0 &&
D->section != &D->sections[secmatch]) D->section != &D->sections[secmatch])
D->status = DASM_S_MATCH_SEC|(D->section-D->sections); D->status = DASM_S_MATCH_SEC | (D->section - D->sections);
return D->status; return D->status;
} }
#endif #endif