Skip to content

Commit

Permalink
fix L strings
Browse files Browse the repository at this point in the history
  • Loading branch information
John Hankinson committed Mar 19, 2017
1 parent af6269e commit 7149fd3
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 8 deletions.
3 changes: 3 additions & 0 deletions H/globals.h
Expand Up @@ -885,6 +885,9 @@ extern char *MOVE_DOUBLE;
extern char *MOVE_SIMD_DWORD;
extern char *MOVE_SIMD_QWORD;

/* track total auto-generated literal string count */
extern uint_32 literalCnt;

extern struct global_options Options;
extern struct module_info ModuleInfo;
extern unsigned int Parse_Pass; /* assembly pass */
Expand Down
1 change: 1 addition & 0 deletions H/hll.h
Expand Up @@ -14,4 +14,5 @@ extern void HllFini( void );
#endif
extern void HllCheckOpen( void );

extern uint_32 GetHllLabel(void);
#endif
2 changes: 1 addition & 1 deletion hll.c
Expand Up @@ -174,7 +174,7 @@ static unsigned cntCond; /* # of allocated 'condlines'-buffer in .WHILE-blocks
static unsigned cntCondBytes; /* total size of allocated 'condlines'-buffers */
#endif

static uint_32 GetHllLabel(void)
uint_32 GetHllLabel(void)
/********************************/
{
return (++ModuleInfo.hll_label);
Expand Down
158 changes: 151 additions & 7 deletions invoke.c
Expand Up @@ -22,12 +22,19 @@
#include "segment.h"
#include "listing.h"
#include "myassert.h"
#include "label.h"
#include "hll.h"

#if DLLIMPORT
#include "mangle.h"
#include "extern.h"
#endif
#include "proc.h"

uint_32 literalCnt = 0;

extern bool write_to_file;

extern int_64 maxintvalues[];
extern int_64 minintvalues[];
extern enum special_token stackreg[];
Expand Down Expand Up @@ -1329,8 +1336,19 @@ static int PushInvokeParam( int i, struct asm_tok tokenarray[], struct dsym *pro
char stringparam[32][MAX_LINE_LEN];
bool isString[32];
int reg = 0;

DebugMsg1(("PushInvokeParam(%s, param=%s:%u, i=%u ) enter\n", proc->sym.name, curr ? curr->sym.name : "NULL", reqParam, i ));

struct asym *lbl;
struct dsym *curseg;
struct dsym *prev;
struct dsym *currs;
size_t slen;
uint_32 pos;
char *pSrc;
char *pDest;
char *labelstr = "__literal";
char buf[32];

DebugMsg1(("PushInvokeParam(%s, param=%s:%u, i=%u ) enter\n", proc->sym.name, curr ? curr->sym.name : "NULL", reqParam, i ));
//__debugbreak();
for ( currParm = 0; currParm <= reqParam; ) {
isString[i] = FALSE;
Expand All @@ -1343,15 +1361,141 @@ static int PushInvokeParam( int i, struct asm_tok tokenarray[], struct dsym *pro
}
else if (ParamIsString(tokenarray[i].string_ptr))
{
// invoke parameter is a raw ascii string, substitute in the _C builtin macro.
sprintf(stringparam[i], "%s%s%s", "@CSTR(", tokenarray[i].string_ptr, ")");

// Preserve current Segment.
curseg = ModuleInfo.currseg;
// Find Data Segment.
prev = NULL;
currs = NULL;
for (currs = SymTables[TAB_SEG].head; currs && currs->next; prev = currs, currs = currs->next)
{
if (strcmp(currs->sym.name, "_DATA") == 0)
break;
}
// Set CurrSeg
CurrSeg = currs;
// Transfer raw String Data.
slen = strlen(tokenarray[i].string_ptr);
pos = currs->e.seginfo->current_loc;
pSrc = tokenarray[i].string_ptr;
pDest = (char*)currs->e.seginfo->CodeBuffer;

sprintf(buf, "%s%d", labelstr, literalCnt);

if (pDest != 0 && write_to_file == TRUE)
{
literalCnt++;
pDest += pos;

lbl = SymLookup(buf);
lbl->value = pos;
lbl->offset = pos;
lbl->isdefined = TRUE;
lbl->mem_type = MT_BYTE;
lbl->state = SYM_INTERNAL;
lbl->segment = currs;
lbl->first_size = 2;
lbl->Ofssize = 2;
lbl->isfunc = 1;
lbl->total_length = 1;
lbl->total_size = 1;
lbl->max_offset = 1;
lbl->debuginfo = 1;
lbl->sfunc_ptr = 1;
lbl->langtype = LANG_FASTCALL;
lbl->cvtyperef = 1;

for (j = 0; j < slen; j++)
{
*pDest++ = *pSrc++;
}
*pDest++ = 0;

}

currs->e.seginfo->current_loc += (slen + 1);
currs->e.seginfo->bytes_written += (slen + 1);
currs->e.seginfo->written = TRUE;
if (currs->e.seginfo->current_loc > currs->sym.max_offset)
currs->sym.max_offset = currs->e.seginfo->current_loc;

/* invoke parameter is a raw ascii string,
substitute in the our new label pointing to this raw string in .data segment. */
sprintf( stringparam[i], "%s", buf );
isString[i] = TRUE;

// Restore current Sement.
CurrSeg = curseg;
}
else if (strcmp(tokenarray[i].string_ptr,"L") == 0 && ParamIsString(tokenarray[i + 1].string_ptr))
{
// invoke parameter is a raw ascii string prefixed with L, substitute in the _W builtin macro.
sprintf(stringparam[i], "%s%s%s", "@WSTR(", tokenarray[i + 1].string_ptr, ")");
isString[i] = TRUE;

// Preserve current Segment.
curseg = ModuleInfo.currseg;
// Find Data Segment.
prev = NULL;
currs = NULL;
for (currs = SymTables[TAB_SEG].head; currs && currs->next; prev = currs, currs = currs->next)
{
if (strcmp(currs->sym.name, "_DATA") == 0)
break;
}
// Set CurrSeg
CurrSeg = currs;
// Transfer raw String Data.
slen = strlen(tokenarray[i+1].string_ptr);
pos = currs->e.seginfo->current_loc;
pSrc = tokenarray[i+1].string_ptr;
pDest = (char*)currs->e.seginfo->CodeBuffer;

sprintf(buf, "%s%d", labelstr, literalCnt);

if (pDest != 0 && write_to_file == TRUE)
{
literalCnt++;
pDest += pos;

lbl = SymLookup(buf);
lbl->value = pos;
lbl->offset = pos;
lbl->isdefined = TRUE;
lbl->mem_type = MT_BYTE;
lbl->state = SYM_INTERNAL;
lbl->segment = currs;
lbl->first_size = 2;
lbl->Ofssize = 2;
lbl->isfunc = 1;
lbl->total_length = 1;
lbl->total_size = 1;
lbl->max_offset = 1;
lbl->debuginfo = 1;
lbl->sfunc_ptr = 1;
lbl->langtype = LANG_FASTCALL;
lbl->cvtyperef = 1;

for (j = 0; j < slen; j++)
{
*pDest++ = *pSrc++;
*pDest++ = 0;
}
*pDest++ = 0;
*pDest++ = 0;

}

currs->e.seginfo->current_loc += (slen * 2 + 2);
currs->e.seginfo->bytes_written += (slen * 2 + 2);
currs->e.seginfo->written = TRUE;
if (currs->e.seginfo->current_loc > currs->sym.max_offset)
currs->sym.max_offset = currs->e.seginfo->current_loc;

/* invoke parameter is a raw ascii string,
substitute in the our new label pointing to this raw string in .data segment. */
sprintf(stringparam[i], "%s", buf);
isString[i] = TRUE;

// Restore current Sement.
CurrSeg = curseg;

for (j = i; j < Token_Count-1; j++)
{
Expand Down

0 comments on commit 7149fd3

Please sign in to comment.