日曜技術者のメモ

趣味でやった事のメモ書きです。

clangでSystemC2.2をビルドしてみた

clangでSystemC2.2がビルドできたのでメモ
ただしこの方法はclangのバージョン3.3のみに有効

clangインストール

インストールは以下ページを参考にしました。

CentOS5にLLVMとclangをインストールする | CentOS・Red Hat Linux実践テクニック - サンプルコードによるPerl入門 〜 伝統と信頼のPerlを学ぼう 〜

automake-1.6.3 インストール

Fedora Coreに入っているautomakeは1.12は新しすぎて
SystemC2.2では使えないので1.6.3をインストール

wget http://ftp.gnu.org/gnu/automake/automake-1.6.3.tar.gz 
tar zxvf automake-1.6.3.tar.gz
cd automake-1.6.3
./configure
make 
sudo make install

SystemC2.2修正

そのままではビルドできないのでコードに手をいれる。
修正は以下を参照

configure

@@ -3445,7 +3445,7 @@
         ;;
     x86_64*linux*)
         case "$CXX_COMP" in
-            c++ | g++)
+            c++ | g++ | clang++)
                 EXTRA_CXXFLAGS="-Wall"
                 DEBUG_CXXFLAGS="-g"
                 OPT_CXXFLAGS="-O3"

src/sysc/datatypes/bit/sc_bit_proxies.h

@@ -713,7 +713,7 @@
 
 protected:
 
-    mutable X& m_obj;
+    X&         m_obj;
     int        m_hi;
     int        m_lo;
     int        m_len;
@@ -1190,10 +1190,10 @@
 
 protected:
 
-    mutable X&   m_left;
-    mutable Y&   m_right;
+    X&           m_left;
+    Y&           m_right;
     mutable int  m_delete;
-    mutable int& m_refs;
+    int&         m_refs;
 
 private:

src/sysc/datatypes/fx/scfx_rep.h

@@ -74,6 +74,7 @@
 void multiply( scfx_rep&, const scfx_rep&, const scfx_rep&, int );
 scfx_rep*  neg_scfx_rep( const scfx_rep& );
 scfx_rep* mult_scfx_rep( const scfx_rep&, const scfx_rep&, int );
+scfx_rep* mult_scfx_rep( const scfx_rep& );
 scfx_rep*  div_scfx_rep( const scfx_rep&, const scfx_rep&, int );
 scfx_rep*  add_scfx_rep( const scfx_rep&, const scfx_rep&, int );
 scfx_rep*  sub_scfx_rep( const scfx_rep&, const scfx_rep&, int );
@@ -374,6 +375,15 @@
 
 inline
 scfx_rep*
+mult_scfx_rep( const scfx_rep& a, const scfx_rep& b)
+{
+    scfx_rep& c = *new scfx_rep;
+    sc_dt::multiply( c, a, b, SC_DEFAULT_MAX_WL_ );
+    return &c;
+}
+
+inline
+scfx_rep*
 lsh_scfx_rep( const scfx_rep& a, int b )
 {
     scfx_rep& c = *new scfx_rep( a );

src/sysc/utils/sc_utils_ids.cpp

@@ -59,6 +59,8 @@
 //
 
 #include "sysc/utils/sc_report.h"
+#include <cstdlib>
+#include <cstring>
 
 
 namespace sc_core {

SystemC2.2ビルド&インストール

手順は普通のやり方。
ただし、環境変数コンパイラをclangにする。

mkdir build
cd build
env CC=clang CXX=clang++ ../configure --prefix=/home/ginnyu-tei/lib/SystemC-2.2_Clang
make 
sudo make install
make check

参考にしたサイト

LSI設計雑記帳 [SystemC] clangでインストール

clang - Installing SystemC 2.2.0, compilation with GCC 4.6 and package for Fedora - Stack Overflow