-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
rgbds.patch
55 lines (53 loc) · 1.64 KB
/
rgbds.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
--- a/src/asm/parser.y
+++ b/src/asm/parser.y
@@ -429,7 +429,9 @@ else:
plain_directive:
label
- | label 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
--- a/src/asm/symbol.cpp
+++ b/src/asm/symbol.cpp
@@ -597,3 +597,24 @@ 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());
+
+ sym = &createSymbol(name);
+ sym->type = SYM_LABEL;
+ sym->data = (int32_t)sect_GetSymbolOffset();
+ sym->isExported = true;
+ sym->section = sect_GetSymbolSection();
+
+ updateSymbolFilename(*sym);
+ return sym;
+}