Softart, The raster software Renderer, is half done, and now the main work is concentrated on the compiler (that is, SASL ). Recently, due to the shortage of graduation replies, there are only a few questions about idle research and implementation, such as name mangling.
For C ++ systems, name mangling is mainly used for functions with the same name, and reloads variables of the same name type and with the same name. The compiler can differentiate different signatures of functions with the same name during compilation. Name mangling is often used in the following scenarios: functions with different signatures (function overloading); variables and function references in different compilation units; dynamic link libraries or other forms of function and variable export.
Although SASL does not intend to support complicated behaviors such as member functions at present, it does not even consider function overloading. As a basic element of modern language compilation, SASL still provides a complete name mangling mechanism in the semantic analysis stage, laying the foundation for future compiler feature expansion.
By referring to the existing mangling version on the Internet, this article designs and implements the mangling Syntax of SASL Based on the mangling method of msvc:
The specific syntax is as follows:
Mangled_name = 'M' basic_name '@ 'return_value_type parameter_type_list' @ 'Z'
Basic_name = string '@'
Return_value_type = value_type
Parameter_type_list = (value_type )*
Value_type = qualifier_code type_code
Qualifier_code = "un" | "cn" | "Nn" | "UC"
Type_code = buildin_typecode | struct_class_typecode | array_type_code
Buildin_typecode = dimension_code basic_type
Dimension_code = scalar | vector | Matrix
Scalar = 'B'
Vector = 'V' (1 | 2 | 3 | 4)
Matrix = 'M' (1 | 2 | 3 | 4) {2}
Basic_type =
'S1' | 'u1' | 's2' | 'u2 '| 's1' | 'u4' | 'ss' | 'u8' | 'F' | 'D' | 'V' | 'B'
Struct_class_typecode ='s 'string '@@'
Array_class_typecode = 'A' type_code size '@@'
Compared with mainstream languages (C ++), this mangling currently does not support qualifier (class member, namespace qualifiers ). In the future, add qualifier as appropriate.
Here is an example of mangling:
Double Foo () ;=> mfoo nnbd @ Z