[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 |
---|
| 12 | // Last Modified On : Mon Nov 1 12:21:00 2021 |
---|
| 13 | // Update Count : 16 |
---|
[51587aa] | 14 | // |
---|
[a08ba92] | 15 | |
---|
[21f0aa8] | 16 | #include <iostream> // for operator<<, basic_ostream |
---|
| 17 | #include <sstream> // for ostringstream |
---|
[d180746] | 18 | #include <list> // for list |
---|
[51b7345] | 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 |
---|
[51b7345] | 28 | |
---|
| 29 | namespace ControlStruct { |
---|
[35a2d47] | 30 | LabelGenerator * LabelGenerator::labelGenerator = 0; |
---|
[51b7345] | 31 | |
---|
[35a2d47] | 32 | LabelGenerator * LabelGenerator::getGenerator() { |
---|
[a08ba92] | 33 | if ( LabelGenerator::labelGenerator == 0 ) |
---|
| 34 | LabelGenerator::labelGenerator = new LabelGenerator(); |
---|
| 35 | return labelGenerator; |
---|
| 36 | } |
---|
[51b7345] | 37 | |
---|
[af68f0a] | 38 | Label LabelGenerator::newLabel( std::string suffix, Statement * stmt ) { |
---|
[5f2f2d7] | 39 | std::ostringstream os; |
---|
[27de955] | 40 | os << "__L" << current++ << "__" << suffix; |
---|
[af68f0a] | 41 | if ( stmt && ! stmt->get_labels().empty() ) { |
---|
| 42 | os << "_" << stmt->get_labels().front() << "__"; |
---|
[35a2d47] | 43 | } // if |
---|
[5f2f2d7] | 44 | std::string ret = os.str(); |
---|
[888cbe4] | 45 | Label l( ret ); |
---|
| 46 | l.get_attributes().push_back( new Attribute("unused") ); |
---|
| 47 | return l; |
---|
[a08ba92] | 48 | } |
---|
[b8ab91a] | 49 | |
---|
| 50 | LabelGenerator_new * LabelGenerator_new::labelGenerator = nullptr; |
---|
| 51 | |
---|
| 52 | LabelGenerator_new * LabelGenerator_new::getGenerator() { |
---|
| 53 | if ( nullptr == labelGenerator ) { |
---|
| 54 | labelGenerator = new LabelGenerator_new(); |
---|
| 55 | } |
---|
| 56 | return labelGenerator; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | ast::Label LabelGenerator_new::newLabel( |
---|
| 60 | const std::string & suffix, const ast::Stmt * stmt ) { |
---|
| 61 | assert( stmt ); |
---|
| 62 | |
---|
| 63 | std::ostringstream os; |
---|
| 64 | os << "__L" << current++ << "__" << suffix; |
---|
| 65 | if ( stmt && !stmt->labels.empty() ) { |
---|
| 66 | os << "_" << stmt->labels.front() << "__"; |
---|
| 67 | } |
---|
| 68 | ast::Label ret_label( stmt->location, os.str() ); |
---|
| 69 | ret_label.attributes.push_back( new ast::Attribute( "unused" ) ); |
---|
| 70 | return ret_label; |
---|
| 71 | } |
---|
| 72 | |
---|
[51b7345] | 73 | } // namespace ControlStruct |
---|
[a08ba92] | 74 | |
---|
[51587aa] | 75 | // Local Variables: // |
---|
| 76 | // tab-width: 4 // |
---|
| 77 | // mode: c++ // |
---|
| 78 | // compile-command: "make install" // |
---|
| 79 | // End: // |
---|