mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-08 15:34:09 +00:00
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:
parent
621ae87058
commit
fc2b633532
@ -21,7 +21,9 @@ enum {
|
||||
/* The following actions need a buffer position. */
|
||||
DASM_ALIGN, DASM_REL_LG, DASM_LABEL_LG,
|
||||
/* 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
|
||||
};
|
||||
|
||||
@ -53,12 +55,12 @@ typedef const unsigned short *dasm_ActList;
|
||||
|
||||
/* Per-section structure. */
|
||||
typedef struct dasm_Section {
|
||||
int *rbuf; /* Biased buffer pointer (negative section bias). */
|
||||
int *buf; /* True buffer pointer. */
|
||||
size_t bsize; /* Buffer size in bytes. */
|
||||
int pos; /* Biased buffer position. */
|
||||
int epos; /* End of biased buffer position - max single put. */
|
||||
int ofs; /* Byte offset into section. */
|
||||
int *rbuf; /* Biased buffer pointer (negative section bias). */
|
||||
int *buf; /* True buffer pointer. */
|
||||
size_t bsize; /* Buffer size in bytes. */
|
||||
int pos; /* Biased buffer position. */
|
||||
int epos; /* End of biased buffer position - max single put. */
|
||||
int ofs; /* Byte offset into section. */
|
||||
} dasm_Section;
|
||||
|
||||
/* Core structure holding the DynASM encoding state. */
|
||||
@ -98,10 +100,10 @@ void dasm_init(Dst_DECL, int maxsection)
|
||||
D->globals = NULL;
|
||||
D->maxsection = maxsection;
|
||||
for (i = 0; i < maxsection; i++) {
|
||||
D->sections[i].buf = NULL; /* Need this for pass3. */
|
||||
D->sections[i].buf = NULL; /* Need this for pass3. */
|
||||
D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i);
|
||||
D->sections[i].bsize = 0;
|
||||
D->sections[i].epos = 0; /* Wrong, but is recalculated after resize. */
|
||||
D->sections[i].epos = 0; /* Wrong, but is recalculated after resize. */
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,8 +115,10 @@ void dasm_free(Dst_DECL)
|
||||
for (i = 0; i < D->maxsection; i++)
|
||||
if (D->sections[i].buf)
|
||||
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->lglabels) DASM_M_FREE(Dst, D->lglabels, D->lgsize);
|
||||
if (D->pclabels)
|
||||
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);
|
||||
}
|
||||
|
||||
@ -122,8 +126,8 @@ void dasm_free(Dst_DECL)
|
||||
void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl)
|
||||
{
|
||||
dasm_State *D = Dst_REF;
|
||||
D->globals = gl - 10; /* Negative bias to compensate for locals. */
|
||||
DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int));
|
||||
D->globals = gl - 10; /* Negative bias to compensate for locals. */
|
||||
DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10 + maxgl) * sizeof(int));
|
||||
}
|
||||
|
||||
/* 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;
|
||||
size_t osz = D->pcsize;
|
||||
DASM_M_GROW(Dst, int, D->pclabels, D->pcsize, maxpc*sizeof(int));
|
||||
memset((void *)(((unsigned char *)D->pclabels)+osz), 0, D->pcsize-osz);
|
||||
DASM_M_GROW(Dst, int, D->pclabels, D->pcsize, maxpc * sizeof(int));
|
||||
memset((void *)(((unsigned char *)D->pclabels) + osz), 0, D->pcsize - osz);
|
||||
}
|
||||
|
||||
/* Setup encoder. */
|
||||
@ -140,11 +144,12 @@ void dasm_setup(Dst_DECL, const void *actionlist)
|
||||
{
|
||||
dasm_State *D = Dst_REF;
|
||||
int i;
|
||||
D->actionlist = (dasm_ActList)actionlist;
|
||||
D->actionlist = (dasm_ActList) actionlist;
|
||||
D->status = DASM_S_OK;
|
||||
D->section = &D->sections[0];
|
||||
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++) {
|
||||
D->sections[i].pos = DASM_SEC2POS(i);
|
||||
D->sections[i].ofs = 0;
|
||||
@ -176,9 +181,10 @@ void dasm_put(Dst_DECL, int start, ...)
|
||||
|
||||
if (pos >= sec->epos) {
|
||||
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->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;
|
||||
@ -193,60 +199,84 @@ void dasm_put(Dst_DECL, int start, ...)
|
||||
} else {
|
||||
int *pl, n = action >= DASM_REL_PC ? va_arg(ap, int) : 0;
|
||||
switch (action) {
|
||||
case DASM_STOP: goto stop;
|
||||
case DASM_STOP:
|
||||
goto stop;
|
||||
case DASM_SECTION:
|
||||
n = (ins & 255); CK(n < D->maxsection, RANGE_SEC);
|
||||
D->section = &D->sections[n]; goto stop;
|
||||
case DASM_ESC: p++; ofs += 4; break;
|
||||
case DASM_REL_EXT: break;
|
||||
case DASM_ALIGN: ofs += (ins & 255); b[pos++] = ofs; break;
|
||||
n = (ins & 255);
|
||||
CK(n < D->maxsection, RANGE_SEC);
|
||||
D->section = &D->sections[n];
|
||||
goto stop;
|
||||
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:
|
||||
n = (ins & 2047) - 10; pl = D->lglabels + n;
|
||||
n = (ins & 2047) - 10;
|
||||
pl = D->lglabels + n;
|
||||
/* Bkwd rel or global. */
|
||||
if (n >= 0) { CK(n>=10||*pl<0, RANGE_LG); CKPL(lg, LG); goto putrel; }
|
||||
pl += 10; n = *pl;
|
||||
if (n < 0) n = 0; /* Start new chain for fwd rel if label exists. */
|
||||
if (n >= 0) {
|
||||
CK(n >= 10 || *pl < 0, RANGE_LG);
|
||||
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;
|
||||
case DASM_REL_PC:
|
||||
pl = D->pclabels + n; CKPL(pc, PC);
|
||||
pl = D->pclabels + n;
|
||||
CKPL(pc, PC);
|
||||
putrel:
|
||||
n = *pl;
|
||||
if (n < 0) { /* Label exists. Get label pos and store it. */
|
||||
if (n < 0) { /* Label exists. Get label pos and store it. */
|
||||
b[pos] = -n;
|
||||
} else {
|
||||
linkrel:
|
||||
b[pos] = n; /* Else link to rel chain, anchored at label. */
|
||||
linkrel:
|
||||
b[pos] = n; /* Else link to rel chain, anchored at label. */
|
||||
*pl = pos;
|
||||
}
|
||||
pos++;
|
||||
break;
|
||||
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:
|
||||
pl = D->pclabels + n; CKPL(pc, PC);
|
||||
pl = D->pclabels + n;
|
||||
CKPL(pc, PC);
|
||||
putlabel:
|
||||
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;
|
||||
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;
|
||||
}
|
||||
*pl = -pos; /* Label exists now. */
|
||||
b[pos++] = ofs; /* Store pass1 offset estimate. */
|
||||
*pl = -pos; /* Label exists now. */
|
||||
b[pos++] = ofs; /* Store pass1 offset estimate. */
|
||||
break;
|
||||
case DASM_IMM16:
|
||||
ofs += 2;
|
||||
fprintf(stderr, "DASM_IMM16 not implemented\n");
|
||||
break;
|
||||
ofs += 2;
|
||||
fprintf(stderr, "DASM_IMM16 not implemented\n");
|
||||
break;
|
||||
case DASM_IMM32:
|
||||
ofs += 4;
|
||||
CK((n>>32) == 0, RANGE_I);
|
||||
b[pos++]=n;
|
||||
ofs += 4;
|
||||
CK((n >> 32) == 0, RANGE_I);
|
||||
b[pos++] = n;
|
||||
break;
|
||||
case DASM_DISP20:
|
||||
CK(-(1<<19) <= n && n < (1<<19), RANGE_I);
|
||||
b[pos++] = n;
|
||||
break;
|
||||
CK(-(1 << 19) <= n && n < (1 << 19), RANGE_I);
|
||||
b[pos++] = n;
|
||||
break;
|
||||
case DASM_DISP12:
|
||||
CK((n>>12) == 0, RANGE_I);
|
||||
b[pos++] = n;
|
||||
CK((n >> 12) == 0, RANGE_I);
|
||||
b[pos++] = n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -256,10 +286,11 @@ stop:
|
||||
sec->pos = pos;
|
||||
sec->ofs = ofs;
|
||||
}
|
||||
|
||||
#undef CK
|
||||
|
||||
/* 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;
|
||||
int secnum;
|
||||
@ -267,20 +298,26 @@ int dasm_link(Dst_DECL, size_t *szp)
|
||||
|
||||
#ifdef DASM_CHECKS
|
||||
*szp = 0;
|
||||
if (D->status != DASM_S_OK) return D->status;
|
||||
if (D->status != DASM_S_OK)
|
||||
return D->status;
|
||||
{
|
||||
int pc;
|
||||
for (pc = 0; pc*sizeof(int) < D->pcsize; pc++)
|
||||
if (D->pclabels[pc] > 0) return DASM_S_UNDEF_PC|pc;
|
||||
for (pc = 0; pc * sizeof(int) < D->pcsize; pc++)
|
||||
if (D->pclabels[pc] > 0)
|
||||
return DASM_S_UNDEF_PC | pc;
|
||||
}
|
||||
#endif
|
||||
|
||||
{ /* Handle globals not defined in this translation unit. */
|
||||
{ /* Handle globals not defined in this translation unit. */
|
||||
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];
|
||||
/* 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,26 +334,39 @@ int dasm_link(Dst_DECL, size_t *szp)
|
||||
unsigned short ins = *p++;
|
||||
unsigned short action = ins;
|
||||
switch (action) {
|
||||
case DASM_STOP: case DASM_SECTION: goto stop;
|
||||
case DASM_ESC: p++; 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_IMM32:
|
||||
case DASM_DISP20:
|
||||
case DASM_DISP12:
|
||||
pos++;
|
||||
case DASM_STOP:
|
||||
case DASM_SECTION:
|
||||
goto stop;
|
||||
case DASM_ESC:
|
||||
p++;
|
||||
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_IMM32:
|
||||
case DASM_DISP20:
|
||||
case DASM_DISP12:
|
||||
pos++;
|
||||
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. */
|
||||
}
|
||||
|
||||
D->codesize = ofs; /* Total size of all code sections */
|
||||
D->codesize = ofs; /* Total size of all code sections */
|
||||
*szp = ofs;
|
||||
return DASM_S_OK;
|
||||
}
|
||||
@ -349,13 +399,19 @@ int dasm_encode(Dst_DECL, void *buffer)
|
||||
unsigned short action = ins;
|
||||
int n = (action >= DASM_ALIGN && action < DASM__MAX) ? *b++ : 0;
|
||||
switch (action) {
|
||||
case DASM_STOP: case DASM_SECTION: goto stop;
|
||||
case DASM_ESC: *cp++ = *p++; break;
|
||||
case DASM_STOP:
|
||||
case DASM_SECTION:
|
||||
goto stop;
|
||||
case DASM_ESC:
|
||||
*cp++ = *p++;
|
||||
break;
|
||||
case DASM_REL_EXT:
|
||||
n = DASM_EXTERN(Dst, (unsigned char *)cp, (ins & 2047), 1) - 4;
|
||||
goto patchrel;
|
||||
case DASM_ALIGN:
|
||||
ins &= 255; while ((((char *)cp - base) & ins)) *cp++ = 0x0707;
|
||||
ins &= 255;
|
||||
while ((((char *)cp - base) & ins))
|
||||
*cp++ = 0x0707;
|
||||
break;
|
||||
case DASM_REL_LG:
|
||||
CK(n >= 0, UNDEF_LG);
|
||||
@ -364,51 +420,59 @@ int dasm_encode(Dst_DECL, void *buffer)
|
||||
n = *DASM_POS2PTR(D, n) - (int)((char *)cp - base);
|
||||
patchrel:
|
||||
CK((n & 3) == 0 &&
|
||||
(((n+4) + ((ins & 2048) ? 0x00008000 : 0x02000000)) >>
|
||||
((ins & 2048) ? 16 : 26)) == 0, RANGE_REL);
|
||||
cp[-1] |= ((n+4) & ((ins & 2048) ? 0x0000fffc: 0x03fffffc));
|
||||
(((n + 4) + ((ins & 2048) ? 0x00008000 : 0x02000000)) >>
|
||||
((ins & 2048) ? 16 : 26)) == 0, RANGE_REL);
|
||||
cp[-1] |= ((n + 4) & ((ins & 2048) ? 0x0000fffc : 0x03fffffc));
|
||||
break;
|
||||
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;
|
||||
case DASM_IMM16:
|
||||
fprintf(stderr, "DASM_IMM16 not implemented\n");
|
||||
break;
|
||||
case DASM_IMM32:
|
||||
case DASM_LABEL_PC:
|
||||
break;
|
||||
case DASM_IMM16:
|
||||
fprintf(stderr, "DASM_IMM16 not implemented\n");
|
||||
break;
|
||||
case DASM_IMM32:
|
||||
*cp++ = n >> 16;
|
||||
*cp++ = n;
|
||||
break;
|
||||
case DASM_DISP20:
|
||||
cp[-2] |= n&0xfff;
|
||||
cp[-1] |= (n>>4)&0xff00;
|
||||
break;
|
||||
case DASM_DISP12:
|
||||
cp[-1] |= n&0xfff;
|
||||
*cp++ = n;
|
||||
break;
|
||||
case DASM_DISP20:
|
||||
cp[-2] |= n & 0xfff;
|
||||
cp[-1] |= (n >> 4) & 0xff00;
|
||||
break;
|
||||
case DASM_DISP12:
|
||||
cp[-1] |= n & 0xfff;
|
||||
break;
|
||||
default:
|
||||
*cp++ = ins;
|
||||
break;
|
||||
default: *cp++ = ins; break;
|
||||
}
|
||||
}
|
||||
stop: (void)0;
|
||||
stop:(void)0;
|
||||
}
|
||||
}
|
||||
|
||||
if (base + D->codesize != (char *)cp) /* Check for phase errors. */
|
||||
if (base + D->codesize != (char *)cp) /* Check for phase errors. */
|
||||
return DASM_S_PHASE;
|
||||
return DASM_S_OK;
|
||||
}
|
||||
|
||||
#undef CK
|
||||
|
||||
/* Get PC label offset. */
|
||||
int dasm_getpclabel(Dst_DECL, unsigned int pc)
|
||||
{
|
||||
dasm_State *D = Dst_REF;
|
||||
if (pc*sizeof(int) < D->pcsize) {
|
||||
if (pc * sizeof(int) < D->pcsize) {
|
||||
int pos = D->pclabels[pc];
|
||||
if (pos < 0) return *DASM_POS2PTR(D, -pos);
|
||||
if (pos > 0) return -1; /* Undefined. */
|
||||
if (pos < 0)
|
||||
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. */
|
||||
}
|
||||
|
||||
#ifdef DASM_CHECKS
|
||||
@ -419,13 +483,16 @@ int dasm_checkstep(Dst_DECL, int secmatch)
|
||||
if (D->status == DASM_S_OK) {
|
||||
int 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;
|
||||
}
|
||||
}
|
||||
if (D->status == DASM_S_OK && secmatch >= 0 &&
|
||||
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;
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user