2008-05-28 18:17:39 +02:00
|
|
|
/*
|
|
|
|
|
* VHDL abstract syntax elements.
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2008 Nick Gasson (nick@nickg.me.uk)
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "vhdl_element.hh"
|
|
|
|
|
|
2008-05-29 17:24:16 +02:00
|
|
|
#include <algorithm>
|
2008-06-02 18:45:58 +02:00
|
|
|
#include <cassert>
|
2008-06-07 17:19:10 +02:00
|
|
|
#include <cstring>
|
2008-06-02 18:45:58 +02:00
|
|
|
#include <typeinfo>
|
|
|
|
|
#include <iostream>
|
2008-06-08 13:48:56 +02:00
|
|
|
#include <sstream>
|
2008-05-29 17:24:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
static const int VHDL_INDENT = 2; // Spaces to indent
|
|
|
|
|
|
2008-06-08 14:27:48 +02:00
|
|
|
int indent(int level)
|
2008-05-29 17:24:16 +02:00
|
|
|
{
|
|
|
|
|
return level + VHDL_INDENT;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-19 22:04:52 +02:00
|
|
|
std::string nl_string(int level)
|
|
|
|
|
{
|
|
|
|
|
std::ostringstream ss;
|
|
|
|
|
newline(ss, level);
|
|
|
|
|
return ss.str();
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-29 17:24:16 +02:00
|
|
|
/*
|
|
|
|
|
* Emit a newline and indent to the correct level.
|
|
|
|
|
*/
|
2008-07-01 11:37:22 +02:00
|
|
|
void newline(std::ostream &of, int level)
|
2008-05-29 17:24:16 +02:00
|
|
|
{
|
|
|
|
|
of << std::endl;
|
|
|
|
|
while (level--)
|
|
|
|
|
of << ' ';
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-01 11:37:22 +02:00
|
|
|
void blank_line(std::ostream &of, int level)
|
2008-05-29 17:24:16 +02:00
|
|
|
{
|
|
|
|
|
of << std::endl;
|
|
|
|
|
newline(of, level);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vhdl_element::set_comment(std::string comment)
|
|
|
|
|
{
|
|
|
|
|
comment_ = comment;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-03 20:46:10 +02:00
|
|
|
/*
|
|
|
|
|
* Draw the comment for any element. The comment is either on
|
|
|
|
|
* a line before the element (end_of_line is false) or at the
|
|
|
|
|
* end of the line containing the element (end_of_line is true).
|
|
|
|
|
*/
|
2008-07-01 11:37:22 +02:00
|
|
|
void vhdl_element::emit_comment(std::ostream &of, int level,
|
2008-06-03 20:46:10 +02:00
|
|
|
bool end_of_line) const
|
2008-05-29 17:24:16 +02:00
|
|
|
{
|
|
|
|
|
if (comment_.size() > 0) {
|
2008-06-03 20:46:10 +02:00
|
|
|
if (end_of_line)
|
|
|
|
|
of << " ";
|
2008-05-29 17:24:16 +02:00
|
|
|
of << "-- " << comment_;
|
2008-06-03 20:46:10 +02:00
|
|
|
if (!end_of_line)
|
|
|
|
|
newline(of, level);
|
2008-05-29 17:24:16 +02:00
|
|
|
}
|
|
|
|
|
}
|
2008-07-01 11:44:20 +02:00
|
|
|
|
|
|
|
|
void vhdl_element::print() const
|
|
|
|
|
{
|
|
|
|
|
emit(std::cout, 0);
|
|
|
|
|
std::cout << std::endl;
|
|
|
|
|
}
|