| 1 | //
 | 
|---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
 | 
|---|
| 3 | //
 | 
|---|
| 4 | // The contents of this file are covered under the licence agreement in the
 | 
|---|
| 5 | // file "LICENCE" distributed with Cforall.
 | 
|---|
| 6 | //
 | 
|---|
| 7 | // LinkageSpec.cc --
 | 
|---|
| 8 | //
 | 
|---|
| 9 | // Author           : Rodolfo G. Esteves
 | 
|---|
| 10 | // Created On       : Sat May 16 13:22:09 2015
 | 
|---|
| 11 | // Last Modified By : Peter A. Buhr
 | 
|---|
| 12 | // Last Modified On : Sun Oct  2 23:16:21 2016
 | 
|---|
| 13 | // Update Count     : 23
 | 
|---|
| 14 | //
 | 
|---|
| 15 | 
 | 
|---|
| 16 | #include <memory>
 | 
|---|
| 17 | #include <string>
 | 
|---|
| 18 | #include <cassert>
 | 
|---|
| 19 | using namespace std;
 | 
|---|
| 20 | 
 | 
|---|
| 21 | #include "LinkageSpec.h"
 | 
|---|
| 22 | #include "Common/SemanticError.h"
 | 
|---|
| 23 | 
 | 
|---|
| 24 | LinkageSpec::Spec LinkageSpec::linkageCheck( const string * spec ) {
 | 
|---|
| 25 |         unique_ptr<const string> guard( spec ); // allocated by lexer
 | 
|---|
| 26 |         if ( *spec == "\"Cforall\"" ) {
 | 
|---|
| 27 |                 return Cforall;
 | 
|---|
| 28 |         } else if ( *spec == "\"C\"" ) {
 | 
|---|
| 29 |                 return C;
 | 
|---|
| 30 |         } else {
 | 
|---|
| 31 |                 throw SemanticError( "Invalid linkage specifier " + *spec );
 | 
|---|
| 32 |         } // if
 | 
|---|
| 33 | }
 | 
|---|
| 34 | 
 | 
|---|
| 35 | string LinkageSpec::linkageName( LinkageSpec::Spec linkage ) {
 | 
|---|
| 36 |         assert( 0 <= linkage && linkage < LinkageSpec::NoOfSpecs );
 | 
|---|
| 37 |         static const char *linkageKinds[LinkageSpec::NoOfSpecs] = {
 | 
|---|
| 38 |                 "intrinsic", "Cforall", "C", "automatically generated", "compiler built-in",
 | 
|---|
| 39 |         };
 | 
|---|
| 40 |         return linkageKinds[linkage];
 | 
|---|
| 41 | }
 | 
|---|
| 42 | 
 | 
|---|
| 43 | bool LinkageSpec::isDecoratable( Spec spec ) {
 | 
|---|
| 44 |         assert( 0 <= spec && spec < LinkageSpec::NoOfSpecs );
 | 
|---|
| 45 |         static bool decoratable[LinkageSpec::NoOfSpecs] = {
 | 
|---|
| 46 |                 //      Intrinsic,      Cforall,        C,              AutoGen,        Compiler
 | 
|---|
| 47 |                         true,           true,           false,  true,           false,
 | 
|---|
| 48 |         };
 | 
|---|
| 49 |         return decoratable[spec];
 | 
|---|
| 50 | }
 | 
|---|
| 51 | 
 | 
|---|
| 52 | bool LinkageSpec::isGeneratable( Spec spec ) {
 | 
|---|
| 53 |         assert( 0 <= spec && spec < LinkageSpec::NoOfSpecs );
 | 
|---|
| 54 |         static bool generatable[LinkageSpec::NoOfSpecs] = {
 | 
|---|
| 55 |                 //      Intrinsic,      Cforall,        C,              AutoGen,        Compiler
 | 
|---|
| 56 |                         true,           true,           true,   true,           false,
 | 
|---|
| 57 |         };
 | 
|---|
| 58 |         return generatable[spec];
 | 
|---|
| 59 | }
 | 
|---|
| 60 | 
 | 
|---|
| 61 | bool LinkageSpec::isOverridable( Spec spec ) {
 | 
|---|
| 62 |         assert( spec >= 0 && spec < LinkageSpec::NoOfSpecs );
 | 
|---|
| 63 |         static bool overridable[LinkageSpec::NoOfSpecs] = {
 | 
|---|
| 64 |                 //      Intrinsic,      Cforall,        C,              AutoGen,        Compiler
 | 
|---|
| 65 |                         true,           false,          false,  true,           false,
 | 
|---|
| 66 |         };
 | 
|---|
| 67 |         return overridable[spec];
 | 
|---|
| 68 | }
 | 
|---|
| 69 | 
 | 
|---|
| 70 | bool LinkageSpec::isBuiltin( Spec spec ) {
 | 
|---|
| 71 |         assert( spec >= 0 && spec < LinkageSpec::NoOfSpecs );
 | 
|---|
| 72 |         static bool builtin[LinkageSpec::NoOfSpecs] = {
 | 
|---|
| 73 |                 //      Intrinsic,      Cforall,        C,              AutoGen,        Compiler
 | 
|---|
| 74 |                         true,           false,          false,  false,          true,
 | 
|---|
| 75 |         };
 | 
|---|
| 76 |         return builtin[spec];
 | 
|---|
| 77 | }
 | 
|---|
| 78 | 
 | 
|---|
| 79 | // Local Variables: //
 | 
|---|
| 80 | // tab-width: 4 //
 | 
|---|
| 81 | // mode: c++ //
 | 
|---|
| 82 | // compile-command: "make install" //
 | 
|---|
| 83 | // End: //
 | 
|---|