| [dd3263c] | 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 | //
 | 
|---|
| [400b8be] | 7 | // LabelGeneratorNew.cpp --
 | 
|---|
| [dd3263c] | 8 | //
 | 
|---|
 | 9 | // Author           : Peter A. Buhr
 | 
|---|
 | 10 | // Created On       : Mon May 18 07:44:20 2015
 | 
|---|
| [400b8be] | 11 | // Last Modified By : Andrew Beach
 | 
|---|
 | 12 | // Last Modified On : Mon Mar 28 10:03:00 2022
 | 
|---|
 | 13 | // Update Count     : 73
 | 
|---|
| [dd3263c] | 14 | //
 | 
|---|
 | 15 | 
 | 
|---|
 | 16 | #include "LabelGeneratorNew.hpp"
 | 
|---|
 | 17 | 
 | 
|---|
 | 18 | #include "AST/Attribute.hpp"
 | 
|---|
 | 19 | #include "AST/Label.hpp"
 | 
|---|
 | 20 | #include "AST/Stmt.hpp"
 | 
|---|
| [0bd46fd] | 21 | 
 | 
|---|
 | 22 | using namespace std;
 | 
|---|
| [dd3263c] | 23 | using namespace ast;
 | 
|---|
 | 24 | 
 | 
|---|
 | 25 | namespace ControlStruct {
 | 
|---|
 | 26 | 
 | 
|---|
| [400b8be] | 27 | enum { size = 128 };
 | 
|---|
| [dd3263c] | 28 | 
 | 
|---|
| [400b8be] | 29 | static int newLabelPre( char buf[size], const string & suffix ) {
 | 
|---|
 | 30 |         static int current = 0;
 | 
|---|
| [dd3263c] | 31 | 
 | 
|---|
 | 32 |         int len = snprintf( buf, size, "__L%d__%s", current++, suffix.c_str() );
 | 
|---|
| [fde0a58] | 33 |         assertf( len < size, "CFA Internal error: buffer overflow creating label" );
 | 
|---|
| [400b8be] | 34 |         return len;
 | 
|---|
 | 35 | }
 | 
|---|
 | 36 | 
 | 
|---|
 | 37 | static Label newLabelPost( char buf[size], const CodeLocation & location ) {
 | 
|---|
 | 38 |         Label ret_label( location, buf );
 | 
|---|
 | 39 |         ret_label.attributes.push_back( new Attribute( "unused" ) );
 | 
|---|
 | 40 |         return ret_label;
 | 
|---|
 | 41 | }
 | 
|---|
 | 42 | 
 | 
|---|
 | 43 | Label newLabel( const string & suffix, const Stmt * stmt ) {
 | 
|---|
 | 44 |         // Buffer for string manipulation.
 | 
|---|
 | 45 |         char buf[size];
 | 
|---|
 | 46 | 
 | 
|---|
 | 47 |         assertf( stmt, "CFA internal error: parameter statement cannot be null pointer" );
 | 
|---|
 | 48 |         int len = newLabelPre( buf, suffix );
 | 
|---|
| [dd3263c] | 49 | 
 | 
|---|
 | 50 |         // What does this do?
 | 
|---|
 | 51 |         if ( ! stmt->labels.empty() ) {
 | 
|---|
 | 52 |                 len = snprintf( buf + len, size - len, "_%s__", stmt->labels.front().name.c_str() );
 | 
|---|
| [fde0a58] | 53 |                 assertf( len < size - len, "CFA Internal error: buffer overflow creating label" );
 | 
|---|
| [dd3263c] | 54 |         } // if
 | 
|---|
 | 55 | 
 | 
|---|
| [400b8be] | 56 |         return newLabelPost( buf, stmt->location );
 | 
|---|
 | 57 | }
 | 
|---|
 | 58 | 
 | 
|---|
 | 59 | Label newLabel( const string & suffix, const CodeLocation & location ) {
 | 
|---|
 | 60 |         // Buffer for string manipulation.
 | 
|---|
 | 61 |         char buf[size];
 | 
|---|
 | 62 | 
 | 
|---|
 | 63 |         newLabelPre( buf, suffix );
 | 
|---|
 | 64 |         return newLabelPost( buf, location );
 | 
|---|
| [dd3263c] | 65 | }
 | 
|---|
 | 66 | 
 | 
|---|
 | 67 | } // namespace ControlStruct
 | 
|---|
 | 68 | 
 | 
|---|
 | 69 | // Local Variables: //
 | 
|---|
 | 70 | // mode: c++ //
 | 
|---|
 | 71 | // End: //
 | 
|---|