| 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 | // LabelGenerator.cc --
|
|---|
| 8 | //
|
|---|
| 9 | // Author : Rodolfo G. Esteves
|
|---|
| 10 | // Created On : Mon May 18 07:44:20 2015
|
|---|
| 11 | // Last Modified By : Andrew Beach
|
|---|
| 12 | // Last Modified On : Mon Nov 1 12:21:00 2021
|
|---|
| 13 | // Update Count : 16
|
|---|
| 14 | //
|
|---|
| 15 |
|
|---|
| 16 | #include <iostream> // for operator<<, basic_ostream
|
|---|
| 17 | #include <sstream> // for ostringstream
|
|---|
| 18 | #include <list> // for list
|
|---|
| 19 |
|
|---|
| 20 | #include "LabelGenerator.h"
|
|---|
| 21 |
|
|---|
| 22 | #include "AST/Attribute.hpp"
|
|---|
| 23 | #include "AST/Label.hpp"
|
|---|
| 24 | #include "AST/Stmt.hpp"
|
|---|
| 25 | #include "SynTree/Attribute.h" // for Attribute
|
|---|
| 26 | #include "SynTree/Label.h" // for Label, operator<<
|
|---|
| 27 | #include "SynTree/Statement.h" // for Statement
|
|---|
| 28 |
|
|---|
| 29 | namespace ControlStruct {
|
|---|
| 30 | LabelGenerator * LabelGenerator::labelGenerator = 0;
|
|---|
| 31 |
|
|---|
| 32 | LabelGenerator * LabelGenerator::getGenerator() {
|
|---|
| 33 | if ( LabelGenerator::labelGenerator == 0 )
|
|---|
| 34 | LabelGenerator::labelGenerator = new LabelGenerator();
|
|---|
| 35 | return labelGenerator;
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | Label LabelGenerator::newLabel( std::string suffix, Statement * stmt ) {
|
|---|
| 39 | std::ostringstream os;
|
|---|
| 40 | os << "__L" << current++ << "__" << suffix;
|
|---|
| 41 | if ( stmt && ! stmt->get_labels().empty() ) {
|
|---|
| 42 | os << "_" << stmt->get_labels().front() << "__";
|
|---|
| 43 | } // if
|
|---|
| 44 | std::string ret = os.str();
|
|---|
| 45 | Label l( ret );
|
|---|
| 46 | l.get_attributes().push_back( new Attribute("unused") );
|
|---|
| 47 | return l;
|
|---|
| 48 | }
|
|---|
| 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 |
|
|---|
| 73 | } // namespace ControlStruct
|
|---|
| 74 |
|
|---|
| 75 | // Local Variables: //
|
|---|
| 76 | // tab-width: 4 //
|
|---|
| 77 | // mode: c++ //
|
|---|
| 78 | // compile-command: "make install" //
|
|---|
| 79 | // End: //
|
|---|