Skip to content

Commit c2c3b10

Browse files
committed
some attempts at improving inline assembly in mini-dat blocks
1 parent 64a5b17 commit c2c3b10

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

backends/asm/inlineasm.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -868,8 +868,7 @@ static int copyLocal(Symbol *sym, void *arg)
868868
size = TypeSize((AST *)sym->v.ptr);
869869
break;
870870
default:
871-
size = LONG_SIZE;
872-
break;
871+
return 1;
873872
}
874873

875874
hubtmp = CompileSymbolForFunc(irl, sym, curfunc, linesrc);
@@ -895,9 +894,11 @@ CompileMiniDatBlock(IRList *irl, AST *origtop, unsigned asmFlags)
895894
IR *ir, *fitir;
896895
Operand *enddst, *startdst;
897896
Flexbuf *fb = (Flexbuf *)malloc(sizeof(Flexbuf));
897+
Flexbuf *relocs = (Flexbuf *)malloc(sizeof(Flexbuf));
898898
struct CopyLocalData copyInfo;
899899

900900
flexbuf_init(fb, 1024);
901+
flexbuf_init(relocs, 1024);
901902

902903
startdst = NewHubLabel();
903904
enddst = NewHubLabel();
@@ -915,7 +916,7 @@ CompileMiniDatBlock(IRList *irl, AST *origtop, unsigned asmFlags)
915916
/* compile the inline assembly as a DAT block */
916917
curfunc->localsUsedInAsm = 0;
917918
AssignAddresses(&curfunc->localsyms, top, 0);
918-
PrintDataBlock(fb, top, NULL, NULL);
919+
PrintDataBlock(fb, top, NULL, relocs);
919920

920921
/* copy the locals used in the inline assembly */
921922
copyInfo.irl = irl;
@@ -931,7 +932,7 @@ CompileMiniDatBlock(IRList *irl, AST *origtop, unsigned asmFlags)
931932
org0->dst = NewImmediate(0);
932933
AppendIR(irl, org0);
933934
}
934-
Operand *op = NewOperand(IMM_BINARY, (const char *)fb, 0);
935+
Operand *op = NewOperand(IMM_BINARY, (const char *)fb, (intptr_t)relocs);
935936
ir = EmitOp2(irl, OPC_BINARY_BLOB, NULL, op);
936937
ir->src2 = (Operand *)current;
937938

backends/nucode/outnu.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// Bytecode (nucode) compiler for spin2cpp
33
//
4-
// Copyright 2021-2024 Total Spectrum Software Inc.
4+
// Copyright 2021-2025 Total Spectrum Software Inc.
55
// see the file COPYING for conditions of redistribution
66
//
77
#include "outnu.h"
@@ -1673,6 +1673,7 @@ NuCompileExpression(NuIrList *irl, AST *node) {
16731673
if (!fdata->dataLabel) {
16741674
fdata->dataLabel = NuCreateLabel();
16751675
flexbuf_init(&fdata->dataBuf, 256);
1676+
flexbuf_init(&fdata->dataBufRelocs, 256);
16761677
}
16771678
tmpLabel = NuIrOffsetLabel(fdata->dataLabel, flexbuf_curlen(&fdata->dataBuf));
16781679
StringBuildBuffer(&fdata->dataBuf, node->left, node->d.ival);
@@ -1924,7 +1925,7 @@ static void NuCompileInlineAsm(NuIrList *irl, AST *ast) {
19241925
startPos = flexbuf_curlen(&fdata->dataBuf);
19251926
startLabel = NuIrOffsetLabel(fdata->dataLabel, startPos);
19261927
AssignAddresses(&curfunc->localsyms, list, 0);
1927-
PrintDataBlock(&fdata->dataBuf,list,NULL,NULL);
1928+
PrintDataBlock(&fdata->dataBuf,list,NULL,&fdata->dataBufRelocs);
19281929
// append a RET instruction
19291930
// which is $FD64002D
19301931
flexbuf_addchar(&fdata->dataBuf, 0x2d);
@@ -2469,7 +2470,7 @@ static int NuCompileObject(void *vptr, Module *P) {
24692470
NuOutputIrList(fb, &FunData(pf)->irl);
24702471
if (FunData(pf)->dataLabel) {
24712472
NuOutputLabelNL(fb, FunData(pf)->dataLabel);
2472-
OutputDataBlob(fb, &FunData(pf)->dataBuf, NULL, NULL);
2473+
OutputDataBlob(fb, &FunData(pf)->dataBuf, &FunData(pf)->dataBufRelocs, NULL);
24732474
}
24742475
}
24752476
return 1;

backends/nucode/outnu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ typedef struct {
2020
NuIrLabel *entryLabel;
2121
NuIrLabel *dataLabel;
2222
Flexbuf dataBuf; // inline data for the function
23+
Flexbuf dataBufRelocs; // relocations for same
2324
FunctionList *funcdups; // functions that are aliases to this one
2425
bool isRemoved; // flag, if set function is a duplicate of something else
2526
unsigned char hash[SHA256_BLOCK_SIZE];

0 commit comments

Comments
 (0)