source: src/CodeGen/LinkOnce.cc @ 8f2f185

ADTast-experimentalenumpthread-emulationqualifiedEnum
Last change on this file since 8f2f185 was aff7e86, checked in by Andrew Beach <ajbeach@…>, 4 years ago

Added a new attribute 'cfa_linkonce'.

  • Property mode set to 100644
File size: 1.9 KB
RevLine 
[aff7e86]1//
2// Cforall Version 1.0.0 Copyright (C) 2021 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// LinkOnce.cc -- Translate the cfa_linkonce attribute.
8//
9// Author           : Andrew Beach
10// Created On       : Thur May 13 10:10:00 2021
11// Last Modified By : Andrew Beach
12// Last Modified On : Thur May 13 14:39:00 2021
13// Update Count     : 0
14//
15
16#include "LinkOnce.h"
17
18#include <algorithm>
19
20#include "Common/PassVisitor.h"       // for PassVisitor, WithShortCircuiting
21
22namespace CodeGen {
23
24static bool is_cfa_linkonce( Attribute const * attr ) {
25        return std::string("cfa_linkonce") == attr->name;
26}
27
28static bool is_section_attribute( Attribute const * attr ) {
29        return std::string("section") == attr->name;
30}
31
32class LinkOnceVisitorCore : public WithShortCircuiting {
33public:
34        void previsit( Declaration * ) {
35                visit_children = false;
36        }
37
38        void previsit( DeclarationWithType * decl ) {
39                std::list< Attribute * > & attributes = decl->attributes;
40                // See if we can find the element:
41                auto found = std::find_if(attributes.begin(), attributes.end(), is_cfa_linkonce );
42                if ( attributes.end() != found ) {
43                        // Remove any other sections:
44                        attributes.remove_if( is_section_attribute );
45                        // Iterator to the cfa_linkonce attribute should still be valid.
46                        Attribute * attribute = *found;
47                        assert( attribute->parameters.empty() );
48                        assert( !decl->mangleName.empty() );
49                        // Overwrite the attribute in place.
50                        const std::string section_name = ".gnu.linkonce." + decl->mangleName;
51                        attribute->name = "section";
52                        attribute->parameters.push_back(
53                                new ConstantExpr( Constant::from_string( section_name ) )
54                        );
55                }
56                visit_children = false;
57        }
58};
59
60void translateLinkOnce( std::list< Declaration *> & translationUnit ) {
61        PassVisitor<LinkOnceVisitorCore> translator;
62        acceptAll( translationUnit, translator );
63}
64
65}
Note: See TracBrowser for help on using the repository browser.