Changeset 48ee593


Ignore:
Timestamp:
Jun 29, 2023, 9:59:17 PM (10 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
599dc6a
Parents:
795500c3 (diff), 260dad7 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/AST
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/AST/LinkageSpec.cpp

    r795500c3 r48ee593  
    2727namespace Linkage {
    2828
    29         Spec update( CodeLocation loc, Spec spec, const std::string * cmd ) {
    30                 assert( cmd );
    31                 std::unique_ptr<const std::string> guard( cmd ); // allocated by lexer
    32                 if ( *cmd == "\"Cforall\"" ) {
    33                         spec.is_mangled = true;
    34                         return spec;
    35                 } else if ( *cmd == "\"C\"" ) {
    36                         spec.is_mangled = false;
    37                         return spec;
    38                 } else {
    39                         SemanticError( loc, "Invalid linkage specifier " + *cmd );
    40                 }
     29Spec update( CodeLocation loc, Spec spec, const std::string * cmd ) {
     30        assert( cmd );
     31        std::unique_ptr<const std::string> guard( cmd ); // allocated by lexer
     32        if ( *cmd == "\"Cforall\"" ) {
     33                spec.is_mangled = true;
     34                return spec;
     35        } else if ( *cmd == "\"C\"" ) {
     36                spec.is_mangled = false;
     37                return spec;
     38        } else {
     39                SemanticError( loc, "Invalid linkage specifier " + *cmd );
    4140        }
     41}
    4242
    43 
    44         std::string name( Spec spec ) {
    45                 switch ( spec.val ) {
    46                 case Intrinsic.val:  return "intrinsic";
    47                 case C.val:          return "C";
    48                 case Cforall.val:    return "Cforall";
    49                 case AutoGen.val:    return "autogenerated cfa";
    50                 case Compiler.val:   return "compiler built-in";
    51                 case BuiltinCFA.val: return "cfa built-in";
    52                 case BuiltinC.val:   return "c built-in";
    53                 default:         return "<unnamed linkage spec>";
    54                 }
     43std::string name( Spec spec ) {
     44        switch ( spec.val ) {
     45        case Intrinsic.val:  return "intrinsic";
     46        case C.val:          return "C";
     47        case Cforall.val:    return "Cforall";
     48        case AutoGen.val:    return "autogenerated cfa";
     49        case Compiler.val:   return "compiler built-in";
     50        case BuiltinCFA.val: return "cfa built-in";
     51        case BuiltinC.val:   return "c built-in";
     52        default:             return "<unnamed linkage spec>";
    5553        }
     54}
    5655
    5756}
  • src/AST/LinkageSpec.hpp

    r795500c3 r48ee593  
    2525namespace Linkage {
    2626
    27         /// Bitflags for linkage specifiers
    28         enum {
    29                 Mangle       = 1 << 0,
    30                 Generate     = 1 << 1,
    31                 Overrideable = 1 << 2,
    32                 Builtin      = 1 << 3,
    33                 GccBuiltin   = 1 << 4
     27/// Bitflags for linkage specifiers
     28enum {
     29        Mangle       = 1 << 0,
     30        Generate     = 1 << 1,
     31        Overrideable = 1 << 2,
     32        Builtin      = 1 << 3,
     33        GccBuiltin   = 1 << 4
     34};
     35
     36/// Bitflag type for storage classes
     37struct spec_flags {
     38        union {
     39                unsigned int val;
     40                struct {
     41                        bool is_mangled      : 1;
     42                        bool is_generatable  : 1;
     43                        bool is_overrideable : 1;
     44                        bool is_builtin      : 1;
     45                        bool is_gcc_builtin  : 1;
     46                };
    3447        };
    3548
    36         /// Bitflag type for storage classes
    37         struct spec_flags {
    38                 union {
    39                         unsigned int val;
    40                         struct {
    41                                 bool is_mangled      : 1;
    42                                 bool is_generatable  : 1;
    43                                 bool is_overrideable : 1;
    44                                 bool is_builtin      : 1;
    45                                 bool is_gcc_builtin  : 1;
    46                         };
    47                 };
     49        constexpr spec_flags( unsigned int val ) : val(val) {}
     50};
    4851
    49                 constexpr spec_flags( unsigned int val ) : val(val) {}
    50         };
     52using Spec = bitfield<spec_flags>;
    5153
    52         using Spec = bitfield<spec_flags>;
     54/// If `cmd` = "C" returns `spec` with `is_mangled = false`.
     55/// If `cmd` = "Cforall" returns `spec` with `is_mangled = true`.
     56Spec update( CodeLocation loc, Spec spec, const std::string * cmd );
    5357
    54         /// If `cmd` = "C" returns `spec` with `is_mangled = false`.
    55         /// If `cmd` = "Cforall" returns `spec` with `is_mangled = true`.
    56         Spec update( CodeLocation loc, Spec spec, const std::string * cmd );
     58/// A human-readable name for this spec
     59std::string name( Spec spec );
    5760
    58         /// A human-readable name for this spec
    59         std::string name( Spec spec );
     61// Pre-defined flag combinations
    6062
    61         // Pre-defined flag combinations
     63/// C built-in defined in prelude
     64constexpr Spec Intrinsic  = { Mangle | Generate | Overrideable | Builtin };
     65/// Ordinary Cforall
     66constexpr Spec Cforall    = { Mangle | Generate };
     67/// C code: not overloadable, not mangled
     68constexpr Spec C          = { Generate };
     69/// Built by translator (e.g. struct assignment)
     70constexpr Spec AutoGen    = { Mangle | Generate | Overrideable };
     71/// GCC internal
     72constexpr Spec Compiler   = { Mangle | Builtin | GccBuiltin };
     73/// Mangled builtins
     74constexpr Spec BuiltinCFA = { Mangle | Generate | Builtin };
     75/// Non-mangled builtins
     76constexpr Spec BuiltinC   = { Generate | Builtin };
    6277
    63         /// C built-in defined in prelude
    64         constexpr Spec Intrinsic  = { Mangle | Generate | Overrideable | Builtin };
    65         /// Ordinary Cforall
    66         constexpr Spec Cforall    = { Mangle | Generate };
    67         /// C code: not overloadable, not mangled
    68         constexpr Spec C          = { Generate };
    69         /// Built by translator (e.g. struct assignment)
    70         constexpr Spec AutoGen    = { Mangle | Generate | Overrideable };
    71         /// GCC internal
    72         constexpr Spec Compiler   = { Mangle | Builtin | GccBuiltin };
    73         /// Mangled builtins
    74         constexpr Spec BuiltinCFA = { Mangle | Generate | Builtin };
    75         /// Non-mangled builtins
    76         constexpr Spec BuiltinC   = { Generate | Builtin };
    7778}
    7879
Note: See TracChangeset for help on using the changeset viewer.