Create the shell of a proper type system.

Rather then just relying on comparing type names all throughout
elaboration, create type description data structures and use them
during elaboration to handle proper types.
This commit is contained in:
Stephen Williams 2011-02-06 20:55:31 -08:00
parent 92f6f1058a
commit bc5fe9676e
5 changed files with 158 additions and 15 deletions

View File

@ -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

View File

@ -20,6 +20,7 @@
# include "entity.h"
# include "compiler.h"
# include "architec.h"
# include "vtype.h"
# include <iostream>
# include <fstream>
# include <iomanip>
@ -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<const VTypePrimitive*>(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: "

View File

@ -40,6 +40,7 @@ const char NOTICE[] =
# include "compiler.h"
# include "parse_api.h"
# include "vtype.h"
# include <cstdio>
# include <cstdlib>
# include <cstring>
@ -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) {

51
vhdlpp/vtype.cc Normal file
View File

@ -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<perm_string, const VType*> 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()
{
}

79
vhdlpp/vtype.h Normal file
View File

@ -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 <map>
# 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<perm_string, const VType*> 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