about summary refs log tree commit diff stats
path: root/subx/036global_variables.cc
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-12-25 23:00:55 -0800
committerKartik Agaram <vc@akkartik.com>2018-12-25 23:01:26 -0800
commitfb7cd3f16cf3a96e0df8bc8b873602fd4bc05e3a (patch)
treeee56010299ec14a66d6100865d36216438c17ad7 /subx/036global_variables.cc
parent17b8233f44d42b06420df2f7a51a87cc22a7adbc (diff)
downloadmu-fb7cd3f16cf3a96e0df8bc8b873602fd4bc05e3a.tar.gz
4874
Diffstat (limited to 'subx/036global_variables.cc')
-rw-r--r--subx/036global_variables.cc14
1 files changed, 14 insertions, 0 deletions
diff --git a/subx/036global_variables.cc b/subx/036global_variables.cc
index afeb7427..5c707bd3 100644
--- a/subx/036global_variables.cc
+++ b/subx/036global_variables.cc
@@ -49,6 +49,10 @@ void compute_addresses_for_global_variables(const segment& s, map<string, uint32
           raise << "'" << to_string(inst) << "': global variable names can only be the first word in a line.\n" << end();
         if (Map_file.is_open())
           Map_file << "0x" << HEXWORD << current_address << ' ' << variable << '\n';
+        if (contains_key(address, variable)) {
+          raise << "duplicate global '" << variable << "'\n" << end();
+          return;
+        }
         put(address, variable, current_address);
         trace(99, "transform") << "global variable '" << variable << "' is at address 0x" << HEXWORD << current_address << end();
         // no modifying current_address; global variable definitions won't be in the final binary
@@ -188,6 +192,16 @@ y:
 +load: 0x0a000003 -> 0a
 $error: 0
 
+:(scenario duplicate_global_variable)
+% Hide_errors = true;
+== 0x1
+40/increment-EAX
+== 0x0a000000
+x:
+x:
+  00
++error: duplicate global 'x'
+
 :(scenario disp32_data_with_modrm)
 == code
 8b/copy 0/mod/indirect 5/rm32/.disp32 2/r32/EDX x/disp32