mirror of
https://github.com/badvision/lawless-legends.git
synced 2024-12-26 19:29:27 +00:00
Improve structure offset access (especially for function pointers)
This commit is contained in:
parent
e465ae6ced
commit
25dd968f74
@ -542,32 +542,18 @@ void emit_llw(int index)
|
||||
{
|
||||
printf("\t%s\t$66,$%02X\t\t\t; LLW\t[%d]\n", DB, index, index);
|
||||
}
|
||||
void emit_lab(int tag, int type)
|
||||
void emit_lab(int tag, int offset, int type)
|
||||
{
|
||||
int fixup = fixup_new(tag, type, FIXUP_WORD);
|
||||
char *taglbl = tag_string(tag, type);
|
||||
printf("\t%s\t$68\t\t\t; LAB\t%s\n", DB, taglbl);
|
||||
printf("_F%03d%c\t%s\t%s\t\t\n", fixup, LBL, DW, type & EXTERN_TYPE ? "0" : taglbl);
|
||||
}
|
||||
void emit_law(int tag, int type)
|
||||
{
|
||||
int fixup = fixup_new(tag, type, FIXUP_WORD);
|
||||
char *taglbl = tag_string(tag, type);
|
||||
printf("\t%s\t$6A\t\t\t; LAW\t%s\n", DB, taglbl);
|
||||
printf("_F%03d%c\t%s\t%s\t\t\n", fixup, LBL, DW, type & EXTERN_TYPE ? "0" : taglbl);
|
||||
}
|
||||
void emit_lab_ofst(int tag, int offset, int type)
|
||||
{
|
||||
int fixup = fixup_new(tag, type, FIXUP_WORD);
|
||||
char *taglbl = tag_string(tag, type);
|
||||
printf("\t%s\t$68\t\t\t; LAB\t%s\n", DB, taglbl);
|
||||
printf("\t%s\t$68\t\t\t; LAB\t%s+%d\n", DB, taglbl, offset);
|
||||
printf("_F%03d%c\t%s\t%s+%d\t\t\n", fixup, LBL, DW, type & EXTERN_TYPE ? "0" : taglbl, offset);
|
||||
}
|
||||
void emit_law_ofst(int tag, int offset, int type)
|
||||
void emit_law(int tag, int offset, int type)
|
||||
{
|
||||
int fixup = fixup_new(tag, type, FIXUP_WORD);
|
||||
char *taglbl = tag_string(tag, type);
|
||||
printf("\t%s\t$6A\t\t\t; LAW\t%s\n", DB, taglbl);
|
||||
printf("\t%s\t$6A\t\t\t; LAW\t%s+%d\n", DB, taglbl, offset);
|
||||
printf("_F%03d%c\t%s\t%s+%d\t\t\n", fixup, LBL, DW, type & EXTERN_TYPE ? "0" : taglbl, offset);
|
||||
}
|
||||
void emit_sb(void)
|
||||
@ -594,32 +580,18 @@ void emit_dlw(int index)
|
||||
{
|
||||
printf("\t%s\t$6E,$%02X\t\t\t; DLW\t[%d]\n", DB, index, index);
|
||||
}
|
||||
void emit_sab(int tag, int type)
|
||||
void emit_sab(int tag, int offset, int type)
|
||||
{
|
||||
int fixup = fixup_new(tag, type, FIXUP_WORD);
|
||||
char *taglbl = tag_string(tag, type);
|
||||
printf("\t%s\t$78\t\t\t; SAB\t%s\n", DB, taglbl);
|
||||
printf("_F%03d%c\t%s\t%s\t\t\n", fixup, LBL, DW, type & EXTERN_TYPE ? "0" : taglbl);
|
||||
}
|
||||
void emit_saw(int tag, int type)
|
||||
{
|
||||
int fixup = fixup_new(tag, type, FIXUP_WORD);
|
||||
char *taglbl = tag_string(tag, type);
|
||||
printf("\t%s\t$7A\t\t\t; SAW\t%s\n", DB, taglbl);
|
||||
printf("_F%03d%c\t%s\t%s\t\t\n", fixup, LBL, DW, type & EXTERN_TYPE ? "0" : taglbl);
|
||||
}
|
||||
void emit_sab_ofst(int tag, int offset, int type)
|
||||
{
|
||||
int fixup = fixup_new(tag, type, FIXUP_WORD);
|
||||
char *taglbl = tag_string(tag, type);
|
||||
printf("\t%s\t$78\t\t\t; SAB\t%s\n", DB, taglbl);
|
||||
printf("\t%s\t$78\t\t\t; SAB\t%s+%d\n", DB, taglbl, offset);
|
||||
printf("_F%03d%c\t%s\t%s+%d\t\t\n", fixup, LBL, DW, type & EXTERN_TYPE ? "0" : taglbl, offset);
|
||||
}
|
||||
void emit_saw_ofst(int tag, int offset, int type)
|
||||
void emit_saw(int tag, int offset, int type)
|
||||
{
|
||||
int fixup = fixup_new(tag, type, FIXUP_WORD);
|
||||
char *taglbl = tag_string(tag, type);
|
||||
printf("\t%s\t$7A\t\t\t; SAW\t%s\n", DB, taglbl);
|
||||
printf("\t%s\t$7A\t\t\t; SAW\t%s+%d\n", DB, taglbl, offset);
|
||||
printf("_F%03d%c\t%s\t%s+%d\t\t\n", fixup, LBL, DW, type & EXTERN_TYPE ? "0" : taglbl, offset);
|
||||
}
|
||||
void emit_dab(int tag, int type)
|
||||
@ -640,19 +612,12 @@ void emit_localaddr(int index)
|
||||
{
|
||||
printf("\t%s\t$28,$%02X\t\t\t; LLA\t[%d]\n", DB, index, index);
|
||||
}
|
||||
void emit_globaladdr(int tag, int type)
|
||||
void emit_globaladdr(int tag, int offset, int type)
|
||||
{
|
||||
int fixup = fixup_new(tag, type, FIXUP_WORD);
|
||||
char *taglbl = tag_string(tag, type);
|
||||
printf("\t%s\t$26\t\t\t; LA\t%s\n", DB, taglbl);
|
||||
printf("_F%03d%c\t%s\t%s\t\t\n", fixup, LBL, DW, type & EXTERN_TYPE ? "0" : taglbl);
|
||||
}
|
||||
void emit_globaladdrofst(int tag, int ofst, int type)
|
||||
{
|
||||
int fixup = fixup_new(tag, type, FIXUP_WORD);
|
||||
char *taglbl = tag_string(tag, type);
|
||||
printf("\t%s\t$26\t\t\t; LA\t%s+%d\n", DB, taglbl, ofst);
|
||||
printf("_F%03d%c\t%s\t%s+%d\t\t\n", fixup, LBL, DW, type & EXTERN_TYPE ? "" : taglbl, ofst);
|
||||
printf("\t%s\t$26\t\t\t; LA\t%s+%d\n", DB, taglbl, offset);
|
||||
printf("_F%03d%c\t%s\t%s+%d\t\t\n", fixup, LBL, DW, type & EXTERN_TYPE ? "" : taglbl, offset);
|
||||
}
|
||||
void emit_indexbyte(void)
|
||||
{
|
||||
|
@ -20,27 +20,22 @@ void emit_lb(void);
|
||||
void emit_lw(void);
|
||||
void emit_llb(int index);
|
||||
void emit_llw(int index);
|
||||
void emit_lab(int tag, int type);
|
||||
void emit_law(int tag, int type);
|
||||
void emit_lab_ofst(int tag, int offset, int type);
|
||||
void emit_law_ofst(int tag, int offset, int type);
|
||||
void emit_lab(int tag, int offset, int type);
|
||||
void emit_law(int tag, int offset, int type);
|
||||
void emit_sb(void);
|
||||
void emit_sw(void);
|
||||
void emit_slb(int index);
|
||||
void emit_slw(int index);
|
||||
void emit_dlb(int index);
|
||||
void emit_dlw(int index);
|
||||
void emit_sab(int tag, int type);
|
||||
void emit_saw(int tag, int type);
|
||||
void emit_sab_ofst(int tag, int offset, int type);
|
||||
void emit_saw_ofst(int tag, int ofset, int type);
|
||||
void emit_sab(int tag, int offset, int type);
|
||||
void emit_saw(int tag, int ofset, int type);
|
||||
void emit_dab(int tag, int type);
|
||||
void emit_daw(int tag, int type);
|
||||
void emit_call(int tag, int type);
|
||||
void emit_ical(void);
|
||||
void emit_localaddr(int index);
|
||||
void emit_globaladdr(int tag, int type);
|
||||
void emit_globaladdrofst(int tag, int offset, int type);
|
||||
void emit_globaladdr(int tag, int offset, int type);
|
||||
void emit_indexbyte(void);
|
||||
void emit_indexword(void);
|
||||
int emit_unaryop(int op);
|
||||
|
@ -188,6 +188,8 @@ int parse_value(int rvalue)
|
||||
int deref = rvalue;
|
||||
int optos = opsptr;
|
||||
int type = 0, value = 0, emit_value = 0;
|
||||
int elem_size, elem_type;
|
||||
long elem_offset = 0;
|
||||
/*
|
||||
* Parse pre operand operators.
|
||||
*/
|
||||
@ -301,7 +303,7 @@ int parse_value(int rvalue)
|
||||
if (type & LOCAL_TYPE)
|
||||
emit_localaddr(value);
|
||||
else
|
||||
emit_globaladdr(value, type);
|
||||
emit_globaladdr(value, 0, type);
|
||||
}
|
||||
else if (type & CONST_TYPE)
|
||||
{
|
||||
@ -340,9 +342,7 @@ int parse_value(int rvalue)
|
||||
/*
|
||||
* Structure member offset or array of arrays
|
||||
*/
|
||||
int elem_size;
|
||||
int elem_type = (scantoken == DOT_TOKEN) ? BPTR_TYPE : WPTR_TYPE;
|
||||
long elem_offset = 0;
|
||||
elem_type = (scantoken == DOT_TOKEN) ? BPTR_TYPE : WPTR_TYPE;
|
||||
if (parse_constval(&elem_offset, &elem_size))
|
||||
{
|
||||
/*
|
||||
@ -352,23 +352,20 @@ int parse_value(int rvalue)
|
||||
{
|
||||
if (type & VAR_TYPE)
|
||||
{
|
||||
if (type & LOCAL_TYPE)
|
||||
emit_localaddr(value + elem_offset);
|
||||
else
|
||||
emit_globaladdrofst(value, elem_offset, type);
|
||||
elem_type = (type & ~VAR_TYPE) | (elem_type == BPTR_TYPE ? BYTE_TYPE : WORD_TYPE);
|
||||
}
|
||||
else if (type & CONST_TYPE)
|
||||
{
|
||||
value += elem_offset;
|
||||
emit_const(value);
|
||||
elem_offset = 0;
|
||||
emit_value = 1;
|
||||
}
|
||||
else // FUNC_TYPE
|
||||
{
|
||||
emit_globaladdr(value, type);
|
||||
emit_const(elem_offset);
|
||||
emit_op(ADD_TOKEN);
|
||||
emit_globaladdr(value, elem_offset, type);
|
||||
emit_value = 1;
|
||||
}
|
||||
emit_value = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -376,6 +373,7 @@ int parse_value(int rvalue)
|
||||
{
|
||||
emit_const(elem_offset);
|
||||
emit_op(ADD_TOKEN);
|
||||
elem_offset = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -389,9 +387,9 @@ int parse_value(int rvalue)
|
||||
if (type & ADDR_TYPE)
|
||||
{
|
||||
if (type & LOCAL_TYPE)
|
||||
emit_localaddr(value);
|
||||
emit_localaddr(value + elem_offset);
|
||||
else
|
||||
emit_globaladdr(value, type);
|
||||
emit_globaladdr(value, elem_offset, type);
|
||||
}
|
||||
else if (type & CONST_TYPE)
|
||||
{
|
||||
@ -454,9 +452,9 @@ int parse_value(int rvalue)
|
||||
if (type & VAR_TYPE)
|
||||
{
|
||||
if (type & LOCAL_TYPE)
|
||||
emit_llw(value);
|
||||
emit_llw(value + elem_offset);
|
||||
else
|
||||
emit_law(value, type);
|
||||
emit_law(value, elem_offset, type);
|
||||
}
|
||||
else if (type & PTR_TYPE)
|
||||
emit_lw();
|
||||
@ -486,9 +484,9 @@ int parse_value(int rvalue)
|
||||
else if (type & VAR_TYPE)
|
||||
{
|
||||
if (type & LOCAL_TYPE)
|
||||
(type & BYTE_TYPE) ? emit_llb(value) : emit_llw(value);
|
||||
(type & BYTE_TYPE) ? emit_llb(value + elem_offset) : emit_llw(value + elem_offset);
|
||||
else
|
||||
(type & BYTE_TYPE) ? emit_lab(value, type) : emit_law(value, type);
|
||||
(type & BYTE_TYPE) ? emit_lab(value, elem_offset, type) : emit_law(value, elem_offset, type);
|
||||
}
|
||||
else if (type & PTR_TYPE)
|
||||
(type & BPTR_TYPE) ? emit_lb() : emit_lw();
|
||||
@ -496,9 +494,9 @@ int parse_value(int rvalue)
|
||||
else
|
||||
{
|
||||
if (type & LOCAL_TYPE)
|
||||
emit_localaddr(value);
|
||||
emit_localaddr(value + elem_offset);
|
||||
else
|
||||
emit_globaladdr(value, type);
|
||||
emit_globaladdr(value, elem_offset, type);
|
||||
}
|
||||
}
|
||||
while (optos < opsptr)
|
||||
@ -894,10 +892,8 @@ int parse_stmnt(void)
|
||||
}
|
||||
if (type & LOCAL_TYPE)
|
||||
(elem_type & BYTE_TYPE) ? emit_slb(addr + elem_offset) : emit_slw(addr + elem_offset);
|
||||
else if (elem_offset)
|
||||
(elem_type & BYTE_TYPE) ? emit_sab_ofst(addr, elem_offset, type) : emit_saw_ofst(addr, elem_offset, type);
|
||||
else
|
||||
(elem_type & BYTE_TYPE) ? emit_sab(addr, type) : emit_saw(addr, type);
|
||||
else
|
||||
(elem_type & BYTE_TYPE) ? emit_sab(addr, elem_offset, type) : emit_saw(addr, elem_offset, type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -8,15 +8,17 @@ end
|
||||
import testlib
|
||||
predef puti, putnl
|
||||
end
|
||||
const mainentry = 2
|
||||
;
|
||||
; Predeclare any functions called before defined.
|
||||
;
|
||||
predef main
|
||||
predef ascii, main
|
||||
;
|
||||
; Declare all global variables for this module.
|
||||
;
|
||||
byte hello[] = "Hello, world.\n"
|
||||
word defptr = main
|
||||
word defptr = @ascii, @main
|
||||
word struct[] = 1, 10, 100
|
||||
;
|
||||
; Define functions.
|
||||
;
|
||||
@ -48,7 +50,7 @@ end
|
||||
export def indirect
|
||||
word mainptr
|
||||
mainptr = @main
|
||||
return mainptr(10)
|
||||
return defptr:mainentry(struct:2)
|
||||
end
|
||||
|
||||
indirect
|
||||
|
Loading…
Reference in New Issue
Block a user