From 94ed9f1a45e98506690f6033b0c87c4c764c95e1 Mon Sep 17 00:00:00 2001 From: Christophe Alexandre Date: Thu, 3 Oct 2002 16:56:42 +0000 Subject: [PATCH] importing a2sdf .... --- alliance/src/a2sdf/Makefile.am | 3 + alliance/src/a2sdf/configure.in | 35 ++++++++ alliance/src/a2sdf/popt.m4 | 56 ++++++++++++ alliance/src/a2sdf/src/A2Sdf.cpp | 123 ++++++++++++++++++++++++++ alliance/src/a2sdf/src/A2Sdf.h | 25 ++++++ alliance/src/a2sdf/src/IOPath.cpp | 58 ++++++++++++ alliance/src/a2sdf/src/IOPath.h | 47 ++++++++++ alliance/src/a2sdf/src/Makefile.am | 16 ++++ alliance/src/a2sdf/src/TimingCell.cpp | 42 +++++++++ alliance/src/a2sdf/src/TimingCell.h | 37 ++++++++ alliance/src/a2sdf/src/a2sdf.cpp | 100 +++++++++++++++++++++ 11 files changed, 542 insertions(+) create mode 100644 alliance/src/a2sdf/Makefile.am create mode 100644 alliance/src/a2sdf/configure.in create mode 100644 alliance/src/a2sdf/popt.m4 create mode 100644 alliance/src/a2sdf/src/A2Sdf.cpp create mode 100644 alliance/src/a2sdf/src/A2Sdf.h create mode 100644 alliance/src/a2sdf/src/IOPath.cpp create mode 100644 alliance/src/a2sdf/src/IOPath.h create mode 100644 alliance/src/a2sdf/src/Makefile.am create mode 100644 alliance/src/a2sdf/src/TimingCell.cpp create mode 100644 alliance/src/a2sdf/src/TimingCell.h create mode 100644 alliance/src/a2sdf/src/a2sdf.cpp diff --git a/alliance/src/a2sdf/Makefile.am b/alliance/src/a2sdf/Makefile.am new file mode 100644 index 00000000..9dd5545d --- /dev/null +++ b/alliance/src/a2sdf/Makefile.am @@ -0,0 +1,3 @@ +## Process this file with automake to produce Makefile.in + +SUBDIRS = src diff --git a/alliance/src/a2sdf/configure.in b/alliance/src/a2sdf/configure.in new file mode 100644 index 00000000..db61f7cc --- /dev/null +++ b/alliance/src/a2sdf/configure.in @@ -0,0 +1,35 @@ +dnl Process this file with autoconf to produce a configure script. +AC_INIT(src/IOPath.cpp) + +A2SDF_MAJOR_VERSION=0 +A2SDF_MINOR_VERSION=9b +A2SDF_VERSION=$A2SDF_MAJOR_VERSION.$A2SDF_MINOR_VERSION + +AC_SUBST(A2SDF_MAJOR_VERSION) +AC_SUBST(A2SDF_MINOR_VERSION) +AC_SUBST(A2SDF_VERSION) + +# For automake. +VERSION=$A2SDF_VERSION +PACKAGE=emmaus + +dnl Initialize automake stuff +AM_INIT_AUTOMAKE($PACKAGE, $VERSION) + +dnl Checks for programs. +AC_PROG_CXX +AC_PROG_RANLIB +AC_PROG_MAKE_SET + +dnl Checks for libraries. + +dnl Checks for typedefs, structures, and compiler characteristics. +AC_C_CONST + +AM_PATH_POPT +AM_ALLIANCE + +AC_OUTPUT([ +Makefile +src/Makefile +]) diff --git a/alliance/src/a2sdf/popt.m4 b/alliance/src/a2sdf/popt.m4 new file mode 100644 index 00000000..aed4cce6 --- /dev/null +++ b/alliance/src/a2sdf/popt.m4 @@ -0,0 +1,56 @@ +dnl AM_PATH_POPT([ACTION-IF-FOUND]) +dnl Test for GTK, and define GTK_CFLAGS and GTK_LIBS +AC_DEFUN(AM_PATH_POPT,[ + AC_ARG_WITH(popt-prefix, + [ --with-popt-prefix=PFX Prefix where popt is installed (optional)], + popt_prefix="$withval", popt_prefix="") + + if test x$popt_prefix != x ; then + POPT_CFLAGS="-I$popt_prefix/include" + POPT_LIBS="-L$popt_prefix/lib -lpopt" + else + POPT_CFLAGS="" + POPT_LIBS="-lpopt" + fi + + AC_MSG_CHECKING(for popt library) + + ac_save_CFLAGS="$CFLAGS" + ac_save_LIBS="$LIBS" + CFLAGS="$CFLAGS $POPT_CFLAGS" + LIBS="$POPT_LIBS $LIBS" + + AC_TRY_RUN([ +#include + +int main(int argc, const char** argv) +{ + struct poptOption options[] = { + POPT_AUTOHELP + { NULL, 0, 0, NULL, 0 } + }; + + poptContext context = poptGetContext("popt-test", argc, argv, options, 0); + poptGetNextOpt(context); + + return 0; +} +],, no_popt=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"]) + CFLAGS="$ac_save_CFLAGS" + LIBS="$ac_save_LIBS" + + if test "x$no_popt" = x ; then + AC_MSG_RESULT(yes) + ifelse([$1], , :, [$1]) + else + AC_MSG_RESULT(no) + AC_MSG_ERROR([This version of $PACKAGE requires libpopt: + ftp://ftp.redhat.com/pub/redhat/code/popt]) + POPT_CFLAGS="" + POPT_LIBS="" +dnl ifelse([$2], , :, [$2]) + fi + + AC_SUBST(POPT_CFLAGS) + AC_SUBST(POPT_LIBS) +]) diff --git a/alliance/src/a2sdf/src/A2Sdf.cpp b/alliance/src/a2sdf/src/A2Sdf.cpp new file mode 100644 index 00000000..c02a2e0f --- /dev/null +++ b/alliance/src/a2sdf/src/A2Sdf.cpp @@ -0,0 +1,123 @@ +#include "A2Sdf.h" + +#include +#include +#include +#include +#include +#include + +/*for inputs to output: Tphl_i_t */ +#define Tphl "tphl" +#define Tpll "tpll" +#define Tplh "tplh" +#define Tphh "tphh" + +/*for flip-flop*/ +#define Tsr "tsr" /* tsr_i_ck */ +#define Tsf "tsf" /* tsf_i_ck */ +#define Thr "thr" /* thr_i_ck */ +#define Thf "thf" /* thf_i_ck */ +#define Tar "tar" /* tar_ck_q */ +#define Taf "taf" /* taf_ck_q */ + + +A2Sdf::~A2Sdf() +{ + for (TimingCells::iterator it = _timingCells.begin(); + it != _timingCells.end(); + it++) + { + delete *it; + } + +} + +void +A2Sdf::CreateTimingCell(const char* name) +{ + char* Thl, *Tll, *Tlh, *Thh, *tar, *taf; + TimingCell* timingCell = new TimingCell(name); + _timingCells.push_back(timingCell); + + befig_list* befig = vhdlloadbefig(NULL,const_cast(name),0/*don't dump message*/); + assert(befig); + list outs; + for (const bepor_list* bepor=befig->BEPOR; bepor; bepor=bepor->NEXT) + { + if (isvdd(bepor->NAME) || isvss(bepor->NAME)) continue; + if (bepor->DIRECTION == OUT || bepor->DIRECTION == INOUT) + { + outs.push_back(bepor->NAME); + } + } + + if (outs.size() > 1) + { + cerr << name << endl; + return; + } + + for (list::const_iterator lit = outs.begin(); + lit != outs.end(); + lit++) + { + const char* output = *lit; + for (const bepor_list* bepor=befig->BEPOR; bepor; bepor=bepor->NEXT) + { + char* newCon = bepor->NAME; + if (newCon == output) continue; + if (isvdd(newCon) || isvss(newCon)) continue; + if (bepor->DIRECTION == IN || bepor->DIRECTION == INOUT) + { + char memo=SEPAR; + SEPAR='_'; + Thl=concatname(Tphl,newCon); + Tll=concatname(Tpll,newCon); + Thh=concatname(Tphh,newCon); + Tlh=concatname(Tplh,newCon); + tar=concatname(Tar,newCon); + taf=concatname(Taf,newCon); + Thl=concatname(Thl,output); + Tll=concatname(Tll,output); + Thh=concatname(Thh,output); + Tlh=concatname(Tlh,output); + tar=concatname(tar,output); + taf=concatname(taf,output); + SEPAR=memo; + + for (const begen_list* begen=befig->BEGEN; begen; begen=begen->NEXT) + { + if (begen->NAME==Tlh || begen->NAME==Thh) + { + IOPath* ioPath = timingCell->AddIOPath(newCon, output); + ioPath->CreateRisingPath(*(int*)begen->VALUE); + } + if (begen->NAME==Thl || begen->NAME==Tll) + { + IOPath* ioPath = timingCell->AddIOPath(newCon, output); + ioPath->CreateFallingPath(*(int*)begen->VALUE); + } + } + } + } + } +} + +void +A2Sdf::Dump() const +{ + ofstream out(_fileName); + out << "(DELAYFILE" << endl + << " (SDFVERSION \"3.0\")" << endl + << " (VENDOR \"ASIM/LIP6\")" << endl + << " (VERSION \"1.0b\")" << endl + << " (TIMESCALE 1 ps)" << endl; + for (TimingCells::const_iterator it = _timingCells.begin(); + it != _timingCells.end(); + it++) + { + (*it)->Dump(out); + } + out << ")" << endl; +} diff --git a/alliance/src/a2sdf/src/A2Sdf.h b/alliance/src/a2sdf/src/A2Sdf.h new file mode 100644 index 00000000..b15c11e6 --- /dev/null +++ b/alliance/src/a2sdf/src/A2Sdf.h @@ -0,0 +1,25 @@ +#ifndef __A2SDF_H +#define __A2SDF_H + +#include +#include "TimingCell.h" +using namespace std; + +class A2Sdf +{ + public: + typedef list TimingCells; + private: + const char* _fileName; + TimingCells _timingCells; + public: + A2Sdf(const char* filename): + _fileName(filename), _timingCells() + {} + + ~A2Sdf(); + void CreateTimingCell(const char* name); + void Dump() const; +}; + +#endif /* __A2SDF_H */ diff --git a/alliance/src/a2sdf/src/IOPath.cpp b/alliance/src/a2sdf/src/IOPath.cpp new file mode 100644 index 00000000..76cd9b97 --- /dev/null +++ b/alliance/src/a2sdf/src/IOPath.cpp @@ -0,0 +1,58 @@ +#include "IOPath.h" + +IOPath::~IOPath() +{ + if (_risingPath) + delete _risingPath; + if (_fallingPath) + delete _fallingPath; +} + +void +IOPath::CreateRisingPath(const int value) +{ + if (!_risingPath) + _risingPath = new TimePath(value); + else + _risingPath->PutValue(value); +} + +void +IOPath::CreateFallingPath(const int value) +{ + if (!_fallingPath) + _fallingPath = new TimePath(value); + else + _fallingPath->PutValue(value); +} + +ofstream& +IOPath::Dump(ofstream& out) const +{ + out << " (IOPATH " + << _input + << " " + << _output + << " "; + if (_risingPath) + { + out << "(" << _risingPath->GetWorstValue() + << "::" + << _risingPath->GetBestValue() + << ") "; + } + else + out << "() "; + if (_fallingPath) + { + out << "(" << _fallingPath->GetWorstValue() + << "::" + << _fallingPath->GetBestValue() + << ") "; + } + else + out << "() "; + + out << ")" << endl; + return out; +} diff --git a/alliance/src/a2sdf/src/IOPath.h b/alliance/src/a2sdf/src/IOPath.h new file mode 100644 index 00000000..f91de327 --- /dev/null +++ b/alliance/src/a2sdf/src/IOPath.h @@ -0,0 +1,47 @@ +#ifndef __IO_PATH_H +#define __IO_PATH_H + +#include +using namespace std; + +class TimePath +{ + friend class IOPath; + private: + int _worstValue; + int _bestValue; + TimePath(const int value): + _worstValue(value), _bestValue(value) + {} + void PutValue(const int value) + { + if (value < _worstValue) + _worstValue = value; + else + if (value > _bestValue) + _bestValue = value; + } + int GetWorstValue() const { return _worstValue; } + int GetBestValue() const { return _bestValue; } +}; + +class IOPath +{ + private: + const char* _input; + const char* _output; + TimePath* _risingPath; + TimePath* _fallingPath; + public: + IOPath(const char* input, const char* output): + _input(input), _output(output), + _risingPath(NULL), _fallingPath(NULL) + {} + ~IOPath(); + void CreateRisingPath(const int value); + void CreateFallingPath(const int value); + ofstream& Dump(ofstream& out) const; + +}; + +#endif /* __IO_PATH_H */ diff --git a/alliance/src/a2sdf/src/Makefile.am b/alliance/src/a2sdf/src/Makefile.am new file mode 100644 index 00000000..ac8c9609 --- /dev/null +++ b/alliance/src/a2sdf/src/Makefile.am @@ -0,0 +1,16 @@ +## Process this file with automake to produce Makefile.in + +AM_CXXFLAGS = @ALLIANCE_CFLAGS@ @POPT_CFLAGS@ + +bin_PROGRAMS = a2sdf + +a2sdf_SOURCES = IOPath.cpp IOPath.h \ + TimingCell.cpp TimingCell.h \ + A2Sdf.cpp A2Sdf.h \ + a2sdf.cpp + +a2sdf_LDADD = @ALLIANCE_LIBS@ @POPT_LIBS@ \ + -lAbv -lAbe -lAbt -lMlu \ + -lMcl -lMal -lMsl -lMhl \ + -lMel -lMvl -lMgl -lRcn \ + -lMlo -lBdd -lAbl -lAut -lMut diff --git a/alliance/src/a2sdf/src/TimingCell.cpp b/alliance/src/a2sdf/src/TimingCell.cpp new file mode 100644 index 00000000..814af972 --- /dev/null +++ b/alliance/src/a2sdf/src/TimingCell.cpp @@ -0,0 +1,42 @@ +#include "TimingCell.h" + +TimingCell::~TimingCell() +{ + for (IOPaths::iterator it = _ioPaths.begin(); + it != _ioPaths.end(); + it++) + delete it->second; +} + +IOPath* +TimingCell::AddIOPath(const char* input, const char* output) +{ + IOPathKey key(input, output); + IOPath* ioPath = _ioPaths[key]; + if (ioPath) + return ioPath; + ioPath = new IOPath(input, output); + _ioPaths[key] = ioPath; + return ioPath; +} + +ofstream& +TimingCell::Dump(ofstream& out) +{ + if (_ioPaths.empty()) + return out; + out << " (CELL" << endl + << " (CELLTYPE \"" << _cellName << "\")" << endl + << " (DELAY" << endl + << " (ABSOLUTE" << endl; + for (IOPaths::iterator it = _ioPaths.begin(); + it != _ioPaths.end(); + it++) + { + it->second->Dump(out); + } + out << " )" << endl + << " )" << endl + << " )" << endl; + return out; +} diff --git a/alliance/src/a2sdf/src/TimingCell.h b/alliance/src/a2sdf/src/TimingCell.h new file mode 100644 index 00000000..87f42e37 --- /dev/null +++ b/alliance/src/a2sdf/src/TimingCell.h @@ -0,0 +1,37 @@ +#ifndef __TIMING_CELL_H +#define __TIMING_CELL_H + +#include +#include +#include +#include "IOPath.h" +using namespace std; + +struct CompIoPaths +{ + bool operator()(const pair p1, + const pair p2) const + { + return (((int)(p1.first) < (int)(p2.first)) + || ((int)(p1.second) < (int)(p2.second))); + } +}; + +class TimingCell +{ + public: + typedef pair IOPathKey; + typedef map IOPaths; + private: + string _cellName; + IOPaths _ioPaths; + public: + TimingCell(const char* name): + _cellName(name), _ioPaths() + {} + ~TimingCell(); + IOPath* AddIOPath(const char* input, const char* output); + ofstream& Dump(ofstream& out); +}; + +#endif /* __TIMING_CELL_H */ diff --git a/alliance/src/a2sdf/src/a2sdf.cpp b/alliance/src/a2sdf/src/a2sdf.cpp new file mode 100644 index 00000000..62580a1d --- /dev/null +++ b/alliance/src/a2sdf/src/a2sdf.cpp @@ -0,0 +1,100 @@ +#include +#include +#include +#include "mut.h" +#include "A2Sdf.h" +using namespace std; + +#define EXTENSION ".vbe" + +static void version(void) +{ + cout << "a2sdf(" PACKAGE ") " VERSION << endl; + cout << "The " PACKAGE " package comes with NO WARRANTY" << endl; +} + +int +main(int argc, char** argv) +{ + int showUsage = 0; + int showVersion = 0; + const char* cellsDir = NULL; + const char* sdfFileName = NULL; + poptOption options[] = { + { "help", 'h', POPT_ARG_NONE, &showUsage, 0, "print this message", 0}, + { "version", 'v', POPT_ARG_NONE, &showVersion, 0, "print the version information", 0}, + { 0, 0, 0, 0, 0, 0, 0 } + }; + + poptContext context = poptGetContext("a2sdf", argc, (const char**)argv, options, 0); + poptSetOtherOptionHelp(context, " "); + + if (int rc = poptGetNextOpt(context) < -1) + { + cerr << "simann: bad argument " << poptBadOption(context, POPT_BADOPTION_NOALIAS) << ": " << poptStrerror(rc) << endl; + cerr << "Try `" << argv[0] << " --help' for more information" << endl; + return 1; + } + + if (showVersion) + { + version(); + return 0; + } + + if (showUsage) + { + version(); + cout << endl; + poptPrintHelp(context, stdout, 0); + return 0; + } + + if ((cellsDir = poptGetArg(context)) == 0 || poptPeekArg(context) == 0) + { + poptPrintUsage(context, stderr, 0); + return 1; + } + + if ((sdfFileName = poptGetArg(context)) == 0 || poptPeekArg(context) != 0) + { + poptPrintUsage(context, stderr, 0); + return 1; + } + + poptFreeContext(context); + + alliancebanner ("A2Sdf", VERSION, "Alliance to SDF format translator", "2002", ALLIANCE_VERSION); + + + DIR* dir = opendir (cellsDir); + if (!dir) + { + cerr << "No directory " << cellsDir << endl; + return 1; + } + + A2Sdf a2sdf(sdfFileName); + + int extensionlength = strlen(EXTENSION); + + struct dirent* entry = NULL; + + while ((entry = readdir (dir)) != NULL) + { + char* filename = entry->d_name; + int filenamelength = strlen (filename); + + if (filenamelength <= extensionlength) continue; + /* is extension of filename accepted */ + if (strncmp (filename + filenamelength - extensionlength, + EXTENSION, extensionlength)) continue; + string cellName(filename); + cellName.erase( cellName.find(EXTENSION)); + a2sdf.CreateTimingCell(cellName.c_str()); + } + + a2sdf.Dump(); + + return 0; +}