-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
41 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,60 @@ | ||
diff --git a/include/asm/symbol.hpp b/include/asm/symbol.hpp | ||
index 409e2ba5..58b78ba0 100644 | ||
--- a/include/asm/symbol.hpp | ||
+++ b/include/asm/symbol.hpp | ||
@@ -100,4 +100,6 @@ void sym_Init(time_t now); | ||
std::optional<std::string> const &sym_GetCurrentSymbolScope(); | ||
void sym_SetCurrentSymbolScope(std::optional<std::string> const &newScope); | ||
|
||
+Symbol *sym_AddSecret(); | ||
+ | ||
#endif // RGBDS_ASM_SYMBOL_HPP | ||
diff --git a/src/asm/parser.y b/src/asm/parser.y | ||
index 55044bfc..94ec183d 100644 | ||
index 437c6afa..61be7ae4 100644 | ||
--- a/src/asm/parser.y | ||
+++ b/src/asm/parser.y | ||
@@ -429,7 +429,9 @@ else: | ||
@@ -86,7 +86,7 @@ | ||
static void compoundAssignment(std::string const &symName, RPNCommand op, int32_t constValue); | ||
static void failAssert(AssertionType type); | ||
static void failAssertMsg(AssertionType type, std::string const &message); | ||
- | ||
+ Symbol *sym_AddSecret(); | ||
// The CPU encodes instructions in a logical way, so most instructions actually follow patterns. | ||
// These enums thus help with bit twiddling to compute opcodes. | ||
enum { REG_B, REG_C, REG_D, REG_E, REG_H, REG_L, REG_HL_IND, REG_A }; | ||
@@ -503,7 +503,7 @@ else: | ||
|
||
plain_directive: | ||
label | ||
- | label cpu_commands | ||
+ | label { | ||
+ sym_AddSecret(); | ||
+ } cpu_commands | ||
+ | label { sym_AddSecret(); } cpu_commands | ||
| label macro | ||
| label directive | ||
; | ||
diff --git a/src/asm/symbol.cpp b/src/asm/symbol.cpp | ||
index 8d803a39..be108ae8 100644 | ||
index 1ae86aba..3ed2dcd4 100644 | ||
--- a/src/asm/symbol.cpp | ||
+++ b/src/asm/symbol.cpp | ||
@@ -597,3 +597,24 @@ void sym_Init(time_t now) { | ||
@@ -669,3 +669,33 @@ void sym_Init(time_t now) { | ||
sym_AddEqu("__UTC_MINUTE__"s, time_utc->tm_min)->isBuiltin = true; | ||
sym_AddEqu("__UTC_SECOND__"s, time_utc->tm_sec)->isBuiltin = true; | ||
} | ||
+ | ||
+static uint32_t secret_counter = 0; | ||
+Symbol *sym_AddSecret() { | ||
+ Symbol *sym; | ||
+ char name[256]; | ||
+ secret_counter += 1; | ||
+ std::shared_ptr<FileStackNode> fstk = fstk_GetFileStack(); | ||
+ while(fstk->type == NODE_REPT) { | ||
+ fstk = fstk->parent; | ||
+ } | ||
+ sprintf(name, "__SEC_%x_%x_%s", secret_counter, lexer_GetLineNo(), fstk->name().c_str()); | ||
+ static uint64_t secretCounter = 1; | ||
+ | ||
+ std::shared_ptr<FileStackNode> fstk = fstk_GetFileStack(); | ||
+ while (fstk->type == NODE_REPT) { | ||
+ fstk = fstk->parent; | ||
+ } | ||
+ | ||
+ char valueBuf[64]; | ||
+ snprintf( | ||
+ valueBuf, | ||
+ sizeof(valueBuf), | ||
+ "__SEC_%" PRIx64 "_%" PRIx32 "_", | ||
+ secretCounter++, | ||
+ lexer_GetLineNo() | ||
+ ); | ||
+ | ||
+ std::string name = valueBuf; | ||
+ name += fstk->name(); | ||
+ | ||
+ sym = &createSymbol(name); | ||
+ sym->type = SYM_LABEL; | ||
+ sym->data = (int32_t)sect_GetSymbolOffset(); | ||
+ sym->isExported = true; | ||
+ sym->section = sect_GetSymbolSection(); | ||
+ Symbol *sym = &createSymbol(name); | ||
+ sym->type = SYM_LABEL; | ||
+ sym->data = static_cast<int32_t>(sect_GetSymbolOffset()); | ||
+ sym->isExported = true; | ||
+ sym->section = sect_GetSymbolSection(); | ||
+ | ||
+ updateSymbolFilename(*sym); | ||
+ return sym; | ||
+ updateSymbolFilename(*sym); | ||
+ return sym; | ||
+} |