diff --git a/vhdlpp/Makefile.in b/vhdlpp/Makefile.in index 2f643433e..12b37f7a9 100644 --- a/vhdlpp/Makefile.in +++ b/vhdlpp/Makefile.in @@ -59,8 +59,8 @@ LIBS = @LIBS@ @EXTRALIBS@ M = StringHeap.o LineInfo.o -O = main.o architec.o compiler.o entity.o entity_elaborate.o \ - expression.o lexor.o lexor_keyword.o parse.o vhdlreal.o vhdlint.o debug.o \ +O = main.o architec.o compiler.o entity.o entity_elaborate.o \ + expression.o vtype.o lexor.o lexor_keyword.o parse.o parse_misc.o vhdlreal.o vhdlint.o debug.o \ architec_emit.o entity_emit.o expression_emit.o \ $M diff --git a/vhdlpp/entity_elaborate.cc b/vhdlpp/entity_elaborate.cc index 9ad06ed11..e8edc2a81 100644 --- a/vhdlpp/entity_elaborate.cc +++ b/vhdlpp/entity_elaborate.cc @@ -20,6 +20,7 @@ # include "entity.h" # include "compiler.h" # include "architec.h" +# include "vtype.h" # include # include # include @@ -91,20 +92,29 @@ int Entity::elaborate_ports_(void) cur_decl.msb = 0; cur_decl.lsb = 0; - if (strcasecmp(cur_port->type_name, "std_logic") == 0) { - cur_decl.type = VLOGIC; + const VType*type = global_types[cur_port->type_name]; + if (type == 0) { + cerr << get_fileline() << ": error: " + << "No such type mark " << cur_port->type_name + << "." << endl; + continue; + } - } else if (strcasecmp(cur_port->type_name, "bit") == 0) { - cur_decl.type = VBOOL; - - } else if (strcasecmp(cur_port->type_name, "boolean") == 0) { - cur_decl.type = VBOOL; - - } else if (strcasecmp(cur_port->type_name, "integer") == 0) { - cur_decl.type = VBOOL; - cur_decl.signed_flag = true; - cur_decl.msb = 31; - cur_decl.lsb = 0; + if (const VTypePrimitive*use_type = dynamic_cast(type)) { + switch (use_type->type()) { + case VTypePrimitive::BOOLEAN: + case VTypePrimitive::BIT: + cur_decl.type = VBOOL; + break; + case VTypePrimitive::STDLOGIC: + cur_decl.type = VLOGIC; + break; + case VTypePrimitive::INTEGER: + cur_decl.type = VBOOL; + cur_decl.msb = 31; + cur_decl.lsb = 0; + break; + } } else { cerr << get_fileline() << ": error: " diff --git a/vhdlpp/main.cc b/vhdlpp/main.cc index dc7f12b82..7b3cad2e0 100644 --- a/vhdlpp/main.cc +++ b/vhdlpp/main.cc @@ -40,6 +40,7 @@ const char NOTICE[] = # include "compiler.h" # include "parse_api.h" +# include "vtype.h" # include # include # include @@ -115,6 +116,8 @@ int main(int argc, char*argv[]) if (dump_design_entities_path) dump_design_entities(dump_design_entities_path); + preload_global_types(); + int errors = 0; errors = elaborate_entities(); if (errors > 0) { diff --git a/vhdlpp/vtype.cc b/vhdlpp/vtype.cc new file mode 100644 index 000000000..4b36a5fb6 --- /dev/null +++ b/vhdlpp/vtype.cc @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2011 Stephen Williams (steve@icarus.com) + * + * This source code is free software; you can redistribute it + * and/or modify it in source code form 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +# include "vtype.h" + +using namespace std; + +std::map global_types; + +const VTypePrimitive primitive_BOOLEAN (VTypePrimitive::BOOLEAN); +const VTypePrimitive primitive_BIT (VTypePrimitive::BIT);; +const VTypePrimitive primitive_INTEGER (VTypePrimitive::INTEGER);; +const VTypePrimitive primitive_STDLOGIC(VTypePrimitive::STDLOGIC);; + +void preload_global_types(void) +{ + global_types[perm_string::literal("boolean")] = &primitive_BOOLEAN; + global_types[perm_string::literal("bit")] = &primitive_BIT; + global_types[perm_string::literal("integer")] = &primitive_INTEGER; + global_types[perm_string::literal("std_logic")] = &primitive_STDLOGIC; +} + + +VType::~VType() +{ +} + +VTypePrimitive::VTypePrimitive(VTypePrimitive::type_t tt) +: type_(tt) +{ +} + +VTypePrimitive::~VTypePrimitive() +{ +} diff --git a/vhdlpp/vtype.h b/vhdlpp/vtype.h new file mode 100644 index 000000000..8b3239999 --- /dev/null +++ b/vhdlpp/vtype.h @@ -0,0 +1,79 @@ +#ifndef __vtype_H +#define __vtype_H +/* + * Copyright (c) 2011 Stephen Williams (steve@icarus.com) + * + * This source code is free software; you can redistribute it + * and/or modify it in source code form 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +# include +# include "StringHeap.h" + +class VType { + + public: + VType() { } + virtual ~VType() =0; +}; + +/* + * The global_types variable maps type names to a type + * definition. This is after the "use" statements bring in the types + * in included packages. + */ +extern std::map global_types; + +extern void preload_global_types(void); + +/* + * This class represents the primative types that are available to the + * type subsystem. + */ +class VTypePrimitive : public VType { + + public: + enum type_t { BOOLEAN, BIT, INTEGER, STDLOGIC }; + + public: + VTypePrimitive(type_t); + ~VTypePrimitive(); + + type_t type() const { return type_; } + + private: + type_t type_; +}; + +extern const VTypePrimitive primitive_BOOLEAN; +extern const VTypePrimitive primitive_BIT; +extern const VTypePrimitive primitive_INTEGER; +extern const VTypePrimitive primitive_STDLOGIC; + +class VTypeArray : public VType { + + public: + VTypeArray(size_t dimensions, VType*etype); + ~VTypeArray(); + + size_t dimensions() const; + VType* element_type() const; + + private: + size_t dimensions_; + VType*etype_; +}; + +#endif