aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2018-09-18 14:41:06 +0100
committerIan C <ianc@noddybox.co.uk>2018-09-18 14:41:06 +0100
commit28bbe2acbd0064769be2f8efc7f64f05ba1e321e (patch)
treeb0241903303b01b4ccba7fa582c9ffc4679842a4
parentb442eb4bbab3820ce6bc0b2551c1c560c2911c43 (diff)
Made it so duplicating a label is an error.
-rw-r--r--doc/casm.html9
-rw-r--r--src/casm.c22
2 files changed, 28 insertions, 3 deletions
diff --git a/doc/casm.html b/doc/casm.html
index 28284f8..31e1d92 100644
--- a/doc/casm.html
+++ b/doc/casm.html
@@ -238,15 +238,18 @@ of a string constant).</li>
<li>Labels must start in column zero (the left hand most column).</li>
<ul>
+ <li>It is an error to redefine a global label that already exists.</li>
+
<li>If the label ends with a colon (:) then the colon is removed.</li>
<li>If the label doesn't start with a period (.) then it is assumed a global
label.</li>
<li>If the label starts with a period (.) then it is assumed to be a local
- label. Local labels are associated with the preceding global label.
- If a global label and related local label have the same name, the local
- label will be used on expansion.</li>
+ label. Local labels are associated with the preceding global label. If
+ a local label has the same name as a global variable the local value will be
+ used on expansion. If a local label already exists with the same name it
+ is an error.</li>
<li>Any label can be followed by an <code>equ</code> directive, in which case
the label is set to that value rather than the current program counter.</li>
diff --git a/src/casm.c b/src/casm.c
index bec864b..f4b06e5 100644
--- a/src/casm.c
+++ b/src/casm.c
@@ -892,6 +892,28 @@ static void RunPass(const char *name, FILE *fp, int depth)
goto error_handling;
}
+ if (IsFirstPass())
+ {
+ const Label *l;
+
+ if ((l = LabelFind(label, type)))
+ {
+ if (l->type == GLOBAL_LABEL)
+ {
+ snprintf(err, sizeof err, "Global %s already defined",
+ label);
+ }
+ else
+ {
+ snprintf(err, sizeof err, "Local %s already defined",
+ label);
+ }
+
+ cmdstat = CMD_FAILED;
+ goto error_handling;
+ }
+ }
+
/* This may well be updated by a command, but easier to set anyway
*/
if (options.address24)