Allow :: to join instructions *and* data declarations (#1785)

This commit is contained in:
Rangi
2025-08-11 08:04:42 -04:00
committed by GitHub
parent 2130a5ba1f
commit 978e832914
4 changed files with 66 additions and 62 deletions

View File

@@ -43,7 +43,9 @@ Labels tie a name to a specific location within a section (see
below).
.Pp
Instructions are assembled into Game Boy opcodes.
Multiple instructions on one line can be separated by double colons
Multiple instructions on one line, as well as data directives (see
.Sx Defining constant data in ROM
below), can be separated by double colons
.Ql :: .
.Pp
The available instructions are documented in

View File

@@ -480,7 +480,7 @@ else:
plain_directive:
label
| label cpu_commands
| label data
| label macro
| label directive
;
@@ -562,10 +562,6 @@ directive:
| println
| export
| export_def
| db
| dw
| dl
| ds
| section
| rsreset
| rsset
@@ -889,56 +885,6 @@ endu:
}
;
ds:
POP_DS uconst {
sect_Skip($2, true);
}
| POP_DS uconst COMMA ds_args trailing_comma {
sect_RelBytes($2, $4);
}
| POP_DS POP_ALIGN LBRACK align_spec RBRACK trailing_comma {
uint32_t n = sect_GetAlignBytes($4.alignment, $4.alignOfs);
sect_Skip(n, true);
sect_AlignPC($4.alignment, $4.alignOfs);
}
| POP_DS POP_ALIGN LBRACK align_spec RBRACK COMMA ds_args trailing_comma {
uint32_t n = sect_GetAlignBytes($4.alignment, $4.alignOfs);
sect_RelBytes(n, $7);
sect_AlignPC($4.alignment, $4.alignOfs);
}
;
ds_args:
reloc_8bit {
$$.push_back(std::move($1));
}
| ds_args COMMA reloc_8bit {
$$ = std::move($1);
$$.push_back(std::move($3));
}
;
db:
POP_DB {
sect_Skip(1, false);
}
| POP_DB constlist_8bit trailing_comma
;
dw:
POP_DW {
sect_Skip(2, false);
}
| POP_DW constlist_16bit trailing_comma
;
dl:
POP_DL {
sect_Skip(4, false);
}
| POP_DL constlist_32bit trailing_comma
;
def_equ:
def_id POP_EQU iconst {
$$ = std::move($1);
@@ -1775,15 +1721,19 @@ sect_attrs:
}
;
// CPU commands.
// CPU instructions and data declarations
cpu_commands:
cpu_command
| cpu_command DOUBLE_COLON cpu_commands
data:
datum
| datum DOUBLE_COLON data
;
cpu_command:
sm83_adc
datum:
db
| dw
| dl
| ds
| sm83_adc
| sm83_add
| sm83_and
| sm83_bit
@@ -1831,6 +1781,56 @@ cpu_command:
| sm83_xor
;
ds:
POP_DS uconst {
sect_Skip($2, true);
}
| POP_DS uconst COMMA ds_args trailing_comma {
sect_RelBytes($2, $4);
}
| POP_DS POP_ALIGN LBRACK align_spec RBRACK trailing_comma {
uint32_t n = sect_GetAlignBytes($4.alignment, $4.alignOfs);
sect_Skip(n, true);
sect_AlignPC($4.alignment, $4.alignOfs);
}
| POP_DS POP_ALIGN LBRACK align_spec RBRACK COMMA ds_args trailing_comma {
uint32_t n = sect_GetAlignBytes($4.alignment, $4.alignOfs);
sect_RelBytes(n, $7);
sect_AlignPC($4.alignment, $4.alignOfs);
}
;
ds_args:
reloc_8bit {
$$.push_back(std::move($1));
}
| ds_args COMMA reloc_8bit {
$$ = std::move($1);
$$.push_back(std::move($3));
}
;
db:
POP_DB {
sect_Skip(1, false);
}
| POP_DB constlist_8bit trailing_comma
;
dw:
POP_DW {
sect_Skip(2, false);
}
| POP_DW constlist_16bit trailing_comma
;
dl:
POP_DL {
sect_Skip(4, false);
}
| POP_DL constlist_32bit trailing_comma
;
sm83_adc:
SM83_ADC op_a_n {
sect_ConstByte(0xCE);

View File

@@ -9,3 +9,5 @@ Label: nop :: call z, .local :: ld b, a
Label2::jr Label2::ret
.local2::call nz, .local2::ret
Label3:: db 1, 2 :: dw 3, 4 :: dl 5, 6 :: ds 7, 8 :: ret