[51587aa] | 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 | //
|
---|
[0f8e4ac] | 7 | // LabelGenerator.cc --
|
---|
[51587aa] | 8 | //
|
---|
[843054c2] | 9 | // Author : Rodolfo G. Esteves
|
---|
[51587aa] | 10 | // Created On : Mon May 18 07:44:20 2015
|
---|
[b8ab91a] | 11 | // Last Modified By : Andrew Beach
|
---|
[de31a1d] | 12 | // Last Modified On : Mon Nov 8 10:18:00 2021
|
---|
| 13 | // Update Count : 17
|
---|
[51587aa] | 14 | //
|
---|
[a08ba92] | 15 |
|
---|
[21f0aa8] | 16 | #include <iostream> // for operator<<, basic_ostream
|
---|
| 17 | #include <sstream> // for ostringstream
|
---|
[d180746] | 18 | #include <list> // for list
|
---|
[51b73452] | 19 |
|
---|
| 20 | #include "LabelGenerator.h"
|
---|
[b8ab91a] | 21 |
|
---|
| 22 | #include "AST/Attribute.hpp"
|
---|
| 23 | #include "AST/Label.hpp"
|
---|
| 24 | #include "AST/Stmt.hpp"
|
---|
[d180746] | 25 | #include "SynTree/Attribute.h" // for Attribute
|
---|
| 26 | #include "SynTree/Label.h" // for Label, operator<<
|
---|
| 27 | #include "SynTree/Statement.h" // for Statement
|
---|
[51b73452] | 28 |
|
---|
| 29 | namespace ControlStruct {
|
---|
[de31a1d] | 30 |
|
---|
| 31 | int LabelGenerator::current = 0;
|
---|
| 32 | LabelGenerator * LabelGenerator::labelGenerator = nullptr;
|
---|
[51b73452] | 33 |
|
---|
[35a2d47] | 34 | LabelGenerator * LabelGenerator::getGenerator() {
|
---|
[a08ba92] | 35 | if ( LabelGenerator::labelGenerator == 0 )
|
---|
| 36 | LabelGenerator::labelGenerator = new LabelGenerator();
|
---|
| 37 | return labelGenerator;
|
---|
| 38 | }
|
---|
[51b73452] | 39 |
|
---|
[af68f0a] | 40 | Label LabelGenerator::newLabel( std::string suffix, Statement * stmt ) {
|
---|
[5f2f2d7] | 41 | std::ostringstream os;
|
---|
[27de955] | 42 | os << "__L" << current++ << "__" << suffix;
|
---|
[af68f0a] | 43 | if ( stmt && ! stmt->get_labels().empty() ) {
|
---|
| 44 | os << "_" << stmt->get_labels().front() << "__";
|
---|
[35a2d47] | 45 | } // if
|
---|
[5f2f2d7] | 46 | std::string ret = os.str();
|
---|
[888cbe4] | 47 | Label l( ret );
|
---|
| 48 | l.get_attributes().push_back( new Attribute("unused") );
|
---|
| 49 | return l;
|
---|
[a08ba92] | 50 | }
|
---|
[b8ab91a] | 51 |
|
---|
[de31a1d] | 52 | ast::Label LabelGenerator::newLabel(
|
---|
[b8ab91a] | 53 | const std::string & suffix, const ast::Stmt * stmt ) {
|
---|
| 54 | assert( stmt );
|
---|
| 55 |
|
---|
| 56 | std::ostringstream os;
|
---|
| 57 | os << "__L" << current++ << "__" << suffix;
|
---|
| 58 | if ( stmt && !stmt->labels.empty() ) {
|
---|
| 59 | os << "_" << stmt->labels.front() << "__";
|
---|
| 60 | }
|
---|
| 61 | ast::Label ret_label( stmt->location, os.str() );
|
---|
| 62 | ret_label.attributes.push_back( new ast::Attribute( "unused" ) );
|
---|
| 63 | return ret_label;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
[51b73452] | 66 | } // namespace ControlStruct
|
---|
[a08ba92] | 67 |
|
---|
[51587aa] | 68 | // Local Variables: //
|
---|
| 69 | // tab-width: 4 //
|
---|
| 70 | // mode: c++ //
|
---|
| 71 | // compile-command: "make install" //
|
---|
| 72 | // End: //
|
---|