W elcome to
Fintronic USA

redball.gif (326 bytes)About Fintronic USA

redball.gif (326 bytes)Main announcements

redball.gif (326 bytes)What's new at Fintronic

redball.gif (326 bytes)What our customers are saying...

redball.gif (326 bytes)Support for SystemC

redball.gif (326 bytes)Support for Verilog 2001

redball.gif (326 bytes)Third party tools integrated with FinSim(Specman, Denali, Debussy, Undertow, Vera, VirSim, HDL Score, Comet, Meteor, NelSim, Pivot, DeskPOD, @Designer 2.1)

home.htmlProductsSupportEvaluateContact

Example of Translation of Verilog/FinSimMath into SystemC


This example runs on FinSim version 10_08_24 or higher. It shows how one can translate Verilog/FinSimMath models into SystemC models.

In order to inspect the results of the translation and to run this example one can execute the following commands:

finvc +gen_sysc t3.v
more fin_sysc.h
more fin_sysc.cpp
make
v2sc.x

The original design consists of t3.v.

By invoking finvc +gen_sysc t3.v one obtains fin_sysc.h and fin_sysc.cpp.

If one has the files Makefile, Makefile.rules, and Makefile.config, one can obtain an executable named v2sc.x.

However, note that all display statements are omitted in the translation, as the translation is meant to become just input for a synthesis tool. In case one needs to also simulate the result of the translation one must instrument the file fin_sysc.cpp with display statements using either printf() or cout.

The file t3.v is listed below:

module t3;
`define SIM 1   
parameter integer SIZE = 16;
localparam integer SIZE2 =  8;
real a [0:SIZE-1], b [0:SIZE-1];
reg [0:63] j, i, is, ij;
real e, s;

`ifdef SIM
task L1;
  begin
    for (j = 0; j < SIZE; j++)
      begin
        a[j] = j;
        b[j] = j+1;
      end    
  end
endtask
`endif

task T1;
  begin
    s = 1.0;
    for (i = 0; i < 2; i++)
      begin
         for (j = 0; j < SIZE2; j++)
           begin
             is = i*SIZE2;
             ij = is+j;
             e = a[ij]*b[ij];
             s = s + e;
`ifdef SIM
    $display("s=%e\n", s);
`endif
           end
      end

`ifdef SIM
    $display("s=%e\n", s);
`endif
  end
endtask

initial begin
`ifdef SIM
  L1;
`endif
  T1;
end
endmodule


The file fin_sysc.h is listed below:

#include "$FINTRONIC/include/sysc/datatypes/fx/scfx_ieee.h"
SC_MODULE( t3 ) {
   #define  SIZE  16
   #define  SIZE2  8
   sc_int<64>  a [16] , b [16];
   sc_int<64> j, i, is, ij;
   sc_int<64>  e , s;

   void L1();

   void T1();

   void initial0();
   SC_CTOR( t3 ) {
   SC_THREAD(initial0);
   } };


The file fin_sysc.cpp is listed below:

#include 
#include 
#include 


void t3::L1()
{
for (j = 0; (j < SIZE); j = (j + 1))
   {
      a [j] = j;
      b [j] = (j + 1);
   }
}
void t3::T1()
{
s = 1.0;
for (i = 0; (i < 2); i = (i + 1))
   {
      for (j = 0; (j < SIZE2); j = (j + 1))
         {
            is = (i * SIZE2);
            ij = (is + j);
            e = (a [ij] * b [ij]);
            s = (s + e);
            ;
         }
   }
;
}
void t3:: initial0()
{
   L1();
   T1();
}

int sc_main (int, char *[])
{
t3 t31("t3");
sc_start();
return 0;
}


The file Makefile is listed below:

include Makefile.config

PROJECT := v2sc
SRCS    := $(wildcard *.cpp)
OBJS    := $(SRCS:.cpp=.o)

include Makefile.rules


The file Makefile.rules is listed below:

## ***************************************************************************
##
##  The following code is derived, directly or indirectly, from the SystemC
##  source code Copyright (c) 1996-2014 by all Contributors.
##  All Rights reserved.
##
##  The contents of this file are subject to the restrictions and limitations
##  set forth in the SystemC Open Source License (the "License");
##  You may not use this file except in compliance with such restrictions and
##  limitations. You may obtain instructions on how to receive a copy of the
##  License at http://www.accellera.org/. Software distributed by Contributors
##  under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
##  ANY KIND, either express or implied. See the License for the specific
##  language governing rights and limitations under the License.
##
## ***************************************************************************
##
##  Makefile.rules -- simple generic SystemC example build rules
##
##  Include this file from your own Makefile to obtain a simple build
##  environment.  You need to set at least the variables
##    PROJECT - name of the application
##    OBJS    - list of required object files
##  to make things work.
##
##  The environment is assumed to be set up from Makefile.config file and
##  the main example Makefile.
##
##  Original Author: Philipp A. Hartmann, OFFIS
##
## ***************************************************************************
##
##  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
##  changes you are making here.
##
##      Name, Affiliation, Date:
##  Description of Modification:
##
## ***************************************************************************
## complete config, if not set from Makefile.config

## Variable that points to SystemC installation path
## needs to be set, fallback to SYSTEMC otherwise
SYSTEMC_HOME?=$(SYSTEMC)

## Select the TARGET_ARCH needs to be set
TARGET_ARCH      ?= linux64

## default values for additional setup variables
ifneq (,$(strip $(TARGET_ARCH)))
ARCH_SUFFIX      ?= -$(TARGET_ARCH)
endif
LDFLAG_RPATH     ?= -Wl,-rpath=

SYSTEMC_INC_DIR  ?= $(FINTRONIC)/include
SYSTEMC_LIB_DIR  ?= $(SYSTEMC_HOME)/lib$(ARCH_SUFFIX)

SYSTEMC_DEFINES  ?=
SYSTEMC_CXXFLAGS ?= $(FLAGS_COMMON) $(FLAGS_STRICT) $(FLAGS_WERROR)
SYSTEMC_LDFLAGS  ?= -L $(SYSTEMC_LIB_DIR) \
                    $(LDFLAG_RPATH)$(SYSTEMC_LIB_DIR)
SYSTEMC_LIBS     ?= -lsystemc -lm

## Add 'PTHREADS=1' to command line for a pthreads build
## (should not be needed in most cases)
ifdef PTHREADS
SYSTEMC_CXXFLAGS += -pthread
SYSTEMC_LIBS     += -lpthread
endif

## ***************************************************************************
## example defaults
## - basic configuration should be set from Makefile.config

FILTER ?= cat

INCDIR   += -I. -I.. -I$(SYSTEMC_INC_DIR)
LIBDIR   += -L. -L..

CXXFLAGS  += $(CFLAGS) $(SYSTEMC_CXXFLAGS) $(INCDIR) $(SYSTEMC_DEFINES)
LDFLAGS   += $(CFLAGS) $(SYSTEMC_CXXFLAGS) $(LIBDIR) $(SYSTEMC_LDFLAGS)
LIBS      += $(SYSTEMC_LIBS) $(EXTRA_LIBS)

# "real" Makefile needs to set PROJECT
ifeq (,$(strip $(PROJECT)))
$(error PROJECT not set. Cannot build.)
endif

# basic check for SystemC directory
ifeq (,$(wildcard $(SYSTEMC_HOME)/.))
$(error SYSTEMC_HOME [$(SYSTEMC_HOME)] is not present. \
        Please update Makefile.config)
endif
ifeq (,$(wildcard $(SYSTEMC_INC_DIR)/systemc.h))
$(error systemc.h [$(SYSTEMC_INC_DIR)] not found. \
        Please update Makefile.config)
endif
ifeq (,$(wildcard $(SYSTEMC_LIB_DIR)/libsystemc*))
$(error SystemC library [$(SYSTEMC_LIB_DIR)] not found. \
        Please update Makefile.config)
endif

# use g++ by default, unless user specifies CXX explicitly
ifeq (default,$(origin CXX))
CXX=g++
endif
# use CXX by default, unless user specifies CC explicitly
ifeq (default,$(origin CC))
CC=$(CXX)
endif

## ***************************************************************************
## build rules

.SUFFIXES: .cc .cpp .o .x

GOLDEN?=golden.log
EXEEXT?=.x
EXE   := $(PROJECT)$(EXEEXT)

all: announce $(EXE)

announce:
	@if test x1 = x$(FLAG_BATCH) ; then \
		echo; echo "*** $(PROJECT):"; echo; \
	fi

check: announce all
	@if test -f "$(INPUT)" ; then INPUT="< $(INPUT)" ; fi ; \
		eval "$(VALGRIND) ./$(EXE) $(ARGS) $${INPUT} > run.log"
	@cat run.log | grep -v "stopped by user" | \
		$(FILTER) | awk '{if($$0!="") print $$0}' > run_trimmed.log
	@if test -f "$(GOLDEN)" ; then \
	  cat "$(GOLDEN)" | grep -v "stopped by user" | \
		awk '{if($$0!="") print $$0}' > ./expected_trimmed.log ; \
	  diff ./run_trimmed.log ./expected_trimmed.log > diff.log 2>&1 ; \
	  if [ -s diff.log ]; then \
	    echo "***ERROR:"; cat diff.log; \
	  else echo "OK"; fi \
	fi


run: announce all
	@if test -f "$(INPUT)" ; then INPUT="< $(INPUT)" ; fi ; \
		eval "./$(EXE) $(ARGS) $${INPUT}"

$(EXE): $(OBJS) $(SYSTEMC_LIB_DIR)/libsystemc.a
	$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) 2>&1 | c++filt
	@test -x $@

.cpp.o:
	$(CC) $(CXXFLAGS) -c $< -o $@

.cc.o:
	$(CC) $(CXXFLAGS) -c $< -o $@

clean:: announce
	rm -f $(OBJS) $(EXE) core $(EXTRA_CLEAN) \
		run.log run_trimmed.log expected_trimmed.log diff.log

ultraclean: announce clean
	rm -f Makefile.deps *~

Makefile.deps:
#	$(CC) $(CXXFLAGS) -M $(SRCS) >> Makefile.deps

#include Makefile.deps


The file Makefile.config is listed below:

## ***************************************************************************
##
##  The following code is derived, directly or indirectly, from the SystemC
##  source code Copyright (c) 1996-2014 by all Contributors.
##  All Rights reserved.
##
##  The contents of this file are subject to the restrictions and limitations
##  set forth in the SystemC Open Source License (the "License");
##  You may not use this file except in compliance with such restrictions and
##  limitations. You may obtain instructions on how to receive a copy of the
##  License at http://www.accellera.org/. Software distributed by Contributors
##  under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
##  ANY KIND, either express or implied. See the License for the specific
##  language governing rights and limitations under the License.
##
## ***************************************************************************
##
##  Makefile.config --
##
##  Original Author: Philipp A. Hartmann, OFFIS
##
## ***************************************************************************
##
##  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
##  changes you are making here.
##
##      Name, Affiliation, Date:
##  Description of Modification:
##
## ***************************************************************************

## guess config from environment

## Variable that points to SystemC installation path
SYSTEMC_HOME?=/home/alec/wsystem/SystemC/systemc-2.3.1

## Select the target architecture
#TARGET_ARCH = linux

## Select the architecture suffix, if necessary
#ARCH_SUFFIX = -$(TARGET_ARCH)

## How to instruct the dynamic linker to locate the SystemC library
#LDFLAG_RPATH = -Wl,-rpath=

# default compiler flags
FLAGS_COMMON = -g -Wall
FLAGS_STRICT = -pedantic -Wno-long-long
FLAGS_WERROR = -Werror

# combined flags
#SYSTEMC_CXXFLAGS = $(FLAGS_COMMON) $(FLAGS_STRICT) $(FLAGS_WERROR)

# Additional preprocessor symbols
#SYSTEMC_DEFINES =

# Explicit location of the SystemC headers
#SYSTEMC_INC_DIR = $(SYSTEMC_HOME)/include

# Explicit location if the SystenC library
#SYSTEMC_LIB_DIR = $(SYSTEMC_HOME)/lib$(ARCH_SUFFIX)

# Run with valgrind
#VALGRIND=valgrind --log-file-exactly=valgrind.log



Copyright 1999-2011, Fintronic USA, Inc.   All rights reserved.