You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MOCKA permits the unrestricted use of lowline ("_") characters in Modula-2 identifiers. An identifier may start or end with one or more lowlines and multiple consecutive lowlines may occur anywhere within an identifier.
MOCKA internally encodes identifiers using a technique known as name mangling to derive labels in the assembly output. The default method to generate a label is to use the module identifier followed by a lowline ("_") followed by the unqualified identifier.
Example 1
DEFINITION MODULEFoobar;PROCEDUREBaz;ENDFoobar.
will generate a global label in the assembly output
.globl Foobar_Baz
For nested procedures, the label is derived by using the label of the parent procedure, appending a lowline ("_") and the procedure identifier.
Example 2
IMPLEMENTATION MODULEFoobar;PROCEDUREBaz;(* global *)PROCEDUREBam;(* local *)...ENDBam;...ENDBaz;...ENDFoobar.
will generate a global label in the assembly output
.globl Foobar_Baz_Bam
MOCKA limits the length of such a label to a maximum of 80 characters. If the name mangling of a label exceeds this length, an alternative method is used whereby the label is derived from the module identifier, followed by a lowline ("_") and the procedure identifier, followed by a lowline and the ordinal number of the procedure.
will generate a global label in the assembly output
.globl Foobar_Boo_4
Problem
However, since MOCKA permits user defined identifiers to include lowline characters, a name collision could occur between the label of a user defined global procedure and the label of an overlong nested procedure.
Example 4
DEFINITION MODULEFoobar;PROCEDUREBoo_4;ENDFoobar;
will generate a global label in the assembly output
.globl Foobar_Boo_4
The label of nested procedure Boo of example 3 would then cause a collision with the label of global procedure Boo in example 4.
Possible Solutions
There are two possible ways to prevent such name collisions:
(1) prohibit the use of lowlines in Modula-2 identifiers
(2) change the name mangling method for nested procedure labels
Prohibiting the use of lowlines in MOCKA Modula-2 identifiers may not be desirable considering backwards compatibility of existing source code written for MOCKA and the need to interface with C APIs which often have identifiers with lowlines.
The gas assembler used by MOCKA to translate generated assembly output also permits the use of the period (".") in labels. Since the period is not permitted within Modula-2 identifiers, no name collision with user defined names can occur if the name mangling method to derive overlong labels used a period instead of a lowline to append the ordinal number of the procedure.
Background
MOCKA permits the unrestricted use of lowline ("_") characters in Modula-2 identifiers. An identifier may start or end with one or more lowlines and multiple consecutive lowlines may occur anywhere within an identifier.
MOCKA internally encodes identifiers using a technique known as name mangling to derive labels in the assembly output. The default method to generate a label is to use the module identifier followed by a lowline ("_") followed by the unqualified identifier.
Example 1
will generate a global label in the assembly output
For nested procedures, the label is derived by using the label of the parent procedure, appending a lowline ("_") and the procedure identifier.
Example 2
will generate a global label in the assembly output
MOCKA limits the length of such a label to a maximum of 80 characters. If the name mangling of a label exceeds this length, an alternative method is used whereby the label is derived from the module identifier, followed by a lowline ("_") and the procedure identifier, followed by a lowline and the ordinal number of the procedure.
Example 3
will generate a global label in the assembly output
Problem
However, since MOCKA permits user defined identifiers to include lowline characters, a name collision could occur between the label of a user defined global procedure and the label of an overlong nested procedure.
Example 4
will generate a global label in the assembly output
The label of nested procedure
Boo
of example 3 would then cause a collision with the label of global procedureBoo
in example 4.Possible Solutions
There are two possible ways to prevent such name collisions:
(1) prohibit the use of lowlines in Modula-2 identifiers
(2) change the name mangling method for nested procedure labels
Prohibiting the use of lowlines in MOCKA Modula-2 identifiers may not be desirable considering backwards compatibility of existing source code written for MOCKA and the need to interface with C APIs which often have identifiers with lowlines.
The
gas
assembler used by MOCKA to translate generated assembly output also permits the use of the period (".") in labels. Since the period is not permitted within Modula-2 identifiers, no name collision with user defined names can occur if the name mangling method to derive overlong labels used a period instead of a lowline to append the ordinal number of the procedure.Example 5
would then generate the label
for nested procedure
Boo
in the assembly output instead.The text was updated successfully, but these errors were encountered: