Implement [[ fragment literals ]] (#1614)

This feature is referred to as "code/data literals" in ASMotor,
and simply as "literals" in some older assemblers like MIDAS
for the PDP-10. RGBASM already had the "section fragments"
feature for keeping disparate contents together when linked,
so these worked naturally as "fragment literals".
This commit is contained in:
Rangi
2025-07-09 12:13:01 -04:00
committed by GitHub
parent 5e43ece578
commit 41ab5dff5a
19 changed files with 343 additions and 13 deletions

View File

@@ -113,11 +113,13 @@
%token YYEOF 0 "end of file"
%token NEWLINE "end of line"
%token EOB "end of buffer"
%token EOL "end of fragment literal"
// General punctuation
%token COMMA ","
%token COLON ":" DOUBLE_COLON "::"
%token LBRACK "[" RBRACK "]"
%token LBRACKS "[[" RBRACKS "]]"
%token LPAREN "(" RPAREN ")"
// Arithmetic operators
@@ -381,6 +383,8 @@
// `scoped_sym_no_anon` exists because anonymous labels usually count as "scoped symbols", but some
// contexts treat anonymous labels and other labels/symbols differently, e.g. `purge` or `export`.
%type <std::string> scoped_sym_no_anon
%type <std::string> fragment_literal
%type <std::string> fragment_literal_name
// SM83 instruction parameters
%type <int32_t> reg_r
@@ -455,7 +459,7 @@ line:
| line_directive // Directives that manage newlines themselves
;
endofline: NEWLINE | EOB;
endofline: NEWLINE | EOB | EOL;
// For "logistical" reasons, these directives must manage newlines themselves.
// This is because we need to switch the lexer's mode *after* the newline has been read,
@@ -1308,6 +1312,12 @@ constlist_16bit_entry:
}
);
}
| fragment_literal {
Expression expr;
expr.makeSymbol($1);
expr.checkNBit(16);
sect_RelWord(expr, 0);
}
;
constlist_32bit:
@@ -1358,6 +1368,23 @@ reloc_16bit:
$$ = std::move($1);
$$.checkNBit(16);
}
| fragment_literal {
$$.makeSymbol($1);
}
;
fragment_literal:
LBRACKS fragment_literal_name asm_file RBRACKS {
sect_PopSection();
$$ = std::move($2);
}
;
fragment_literal_name:
%empty {
$$ = sect_PushSectionFragmentLiteral();
sym_AddLabel($$);
}
;
relocexpr: