Commit 703a8d89 authored by Anirudh Kaushik's avatar Anirudh Kaushik

Initial commit

parents
cmake_minimum_required(VERSION 2.6)
project(systemc-clang)
option (USE_SAUTO
"Use suspension-automata library." OFF
)
set (ROOT_CPP
driver-tooling.cpp
# ToolingTest.cpp
# ToolingTutorial.cpp
)
# set (CLANG_SRC_DIR
# $ENV{CLANG_SRC_DIR}
# )
# set (LLVM_SRC_DIR
# $ENV{LLVM_SRC_DIR}
# )
set (LLVM_BUILD_DIR
$ENV{LLVM_BUILD_DIR}
)
set (CMAKE_CXX_FLAGS
"$ENV{LLVM_CXX_FLAGS} $ENV{CMAKE_CXX_FLAGS} -DUSE_SAUTO=off"
)
if (USE_SAUTO)
set (CMAKE_CXX_FLAGS
"-DUSE_SAUTO=on ${CMAKE_CXX_FLAGS}"
)
endif(USE_SAUTO)
set (LLVM_LD_FLAGS
$ENV{LLVM_LD_FLAGS}
)
set (LLVM_LIBS
$ENV{LLVM_LIBS}
)
#set (LLVM_LD_LIBS LLVMCppBackendCodeGen LLVMCppBackendInfo LLVMTarget LLVMCore LLVMMC LLVMObject LLVMSupport)
#LLVMJIT LLVMX86CodeGen LLVMX86AsmParser LLVMX86Disassembler LLVMExecutionEngine LLVMAsmPrinter LLVMSelectionDAG LLVMX86AsmPrinter LLVMX86Info LLVMMCParser LLVMCodeGen LLVMX86Utils LLVMScalarOpts LLVMInstCombine LLVMTransformUtils LLVMipa LLVMAnalysis LLVMTarget LLVMCore LLVMMC LLVMSupport
set (CLANG_LIBS
clangTooling
clangFrontendTool
clangFrontend
clangDriver
clangSerialization
clangCodeGen
clangParse
clangSema
clangStaticAnalyzerFrontend
clangStaticAnalyzerCheckers
clangStaticAnalyzerCore
clangAnalysis
clangARCMigrate
clangRewriteFrontend
clangRewriteCore
clangEdit
clangAST
clangLex
clangBasic
)
set (CMAKE_MODULE_LINKER_FLAGS
$ENV{LLVM_LD_FLAGS}
)
set (TARGET
"systemc-clang"
)
include_directories(
"${LLVM_BUILD_DIR}/include"
src
if (USE_SAUTO)
sauto
endif (USE_SAUTO)
)
link_directories(
${LLVM_BUILD_DIR}/lib
)
add_subdirectory(src)
if (USE_SAUTO)
add_subdirectory(sauto)
endif (USE_SAUTO)
set( SRC_LIB libsystemc-clang)
if (USE_SAUTO)
set( SAUTO_LIB libsauto )
endif (USE_SAUTO)
add_executable(
${TARGET}
${ROOT_CPP} )
target_link_libraries(${TARGET} ${SRC_LIB})
target_link_libraries(${TARGET} ${SAUTO_LIB})
foreach (clang_lib ${CLANG_LIBS})
target_link_libraries( ${TARGET} ${clang_lib} )
endforeach()
foreach (llvm_lib ${LLVM_LIBS})
target_link_libraries( ${TARGET} ${llvm_lib} )
endforeach()
foreach (ld_flag ${LLVM_LD_FLAGS})
target_link_libraries( ${TARGET} ${ld_flag} )
endforeach()
cmake_minimum_required(VERSION 2.6)
project(systemc-clang)
set (ROOT_CPP
driver-tooling.cpp
# ToolingTest.cpp
# ToolingTutorial.cpp
)
# set (CLANG_SRC_DIR
# $ENV{CLANG_SRC_DIR}
# )
# set (LLVM_SRC_DIR
# $ENV{LLVM_SRC_DIR}
# )
set (LLVM_BUILD_DIR
$ENV{LLVM_BUILD_DIR}
)
set (CMAKE_CXX_FLAGS
$ENV{LLVM_CXX_FLAGS}
)
set (LLVM_LD_FLAGS
$ENV{LLVM_LD_FLAGS}
)
set (LLVM_LIBS
$ENV{LLVM_LIBS}
)
#set (LLVM_LD_LIBS LLVMCppBackendCodeGen LLVMCppBackendInfo LLVMTarget LLVMCore LLVMMC LLVMObject LLVMSupport)
#LLVMJIT LLVMX86CodeGen LLVMX86AsmParser LLVMX86Disassembler LLVMExecutionEngine LLVMAsmPrinter LLVMSelectionDAG LLVMX86AsmPrinter LLVMX86Info LLVMMCParser LLVMCodeGen LLVMX86Utils LLVMScalarOpts LLVMInstCombine LLVMTransformUtils LLVMipa LLVMAnalysis LLVMTarget LLVMCore LLVMMC LLVMSupport
set (CLANG_LIBS
clangTooling
clangFrontendTool
clangFrontend
clangDriver
clangSerialization
clangCodeGen
clangParse
clangSema
clangStaticAnalyzerFrontend
clangStaticAnalyzerCheckers
clangStaticAnalyzerCore
clangAnalysis
clangARCMigrate
clangRewriteFrontend
clangRewriteCore
clangEdit
clangAST
clangLex
clangBasic
)
set (CMAKE_MODULE_LINKER_FLAGS
$ENV{LLVM_LD_FLAGS}
)
set (TARGET
"systemc-clang"
)
include_directories(
"${LLVM_BUILD_DIR}/include"
src
)
link_directories(
${LLVM_BUILD_DIR}/lib
)
add_subdirectory(src)
set( SRC_LIB libsystemc-clang)
add_executable(
${TARGET}
${ROOT_CPP} )
target_link_libraries(${TARGET} ${SRC_LIB})
target_link_libraries(${TARGET} ${SAUTO_LIB})
foreach (clang_lib ${CLANG_LIBS})
target_link_libraries( ${TARGET} ${clang_lib} )
endforeach()
foreach (llvm_lib ${LLVM_LIBS})
target_link_libraries( ${TARGET} ${llvm_lib} )
endforeach()
foreach (ld_flag ${LLVM_LD_FLAGS})
target_link_libraries( ${TARGET} ${ld_flag} )
endforeach()
Installation
============
* This version of systemc-clang compiles as a dynamic library. It requires LLVM and clang to be installed. Please follow the directions below
Steps
===========
* Follow the instructions to install clang: [Get Started](http://clang.llvm.org/get_started.html). Notice that you should also install LLVM as it is needed for compilation of the stand-along program. A suggestion is to install LLVM/clang in a location that is accessible by the user.
* Clone systemc-clang repository.
```bash
$ git clone git@github.com:anikau31/systemc-clang.git
```
* Create a build directory for this stand-alone program.
```bash
$ mkdir systemc-clang-build
```
* Enter the cloned repository folder.
```bash
$ cd systemc-clang
```
* Edit the path for the LLVM_BUILD_DIR in paths.sh, and set it to the appropriate path where LLVM/clang was installed.
* Source the paths file (assuming bash shell). This should setup certain environment variables that cmake will use.
```bash
$ source paths.sh
```
* Go to the build directory.
```bash
$ cd ../systemc-clang-build
```
* Create the makefiles using cmake.
```bash
$ cmake ../systemc-clang
```
* If there are no errors, then the compilation of Makefiles was successful. So, you can go ahead and compile the stand-alone program.
```bash
$ make
```
Testing on a small example
==========================
* Copy the compiled binary in the bin folder of LLVM_BUILD_DIR
```bash
$ cp systemc-clang $LLVM_BUILD_DIR/bin
```
* Set the SYSTEMC variable.
```bash
$ export SYSTEMC=<path-to-systemc-install>
```
* Execute it on a simple example. You should see some (debug) information print out on the screen. Hope to make this more meaningful in the future.
```bash
$ $LLVM_BUILD_DIR/bin/systemc-clang ../systemc-clang/tests/module1.hpp -- \
-D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -I/usr/include \
-I$SYSTEMC/include -x c++ -w -c
```
==============================================================================
LLVM Release License
==============================================================================
University of Illinois/NCSA
Open Source License
Copyright (c) 2007-2012 University of Illinois at Urbana-Champaign.
All rights reserved.
Developed by:
LLVM Team
University of Illinois at Urbana-Champaign
http://llvm.org
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal with
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimers.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimers in the
documentation and/or other materials provided with the distribution.
* Neither the names of the LLVM Team, University of Illinois at
Urbana-Champaign, nor the names of its contributors may be used to
endorse or promote products derived from this Software without specific
prior written permission.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
SOFTWARE.
==============================================================================
The LLVM software contains code written by third parties. Such software will
have its own individual LICENSE.TXT file in the directory in which it appears.
This file will describe the copyrights, license, and restrictions which apply
to that code.
The disclaimer of warranty in the University of Illinois Open Source License
applies to all code in the LLVM Distribution, and nothing in any of the
other licenses gives permission to use the names of the LLVM Team or the
University of Illinois to endorse or promote products derived from this
Software.
The following pieces of software have additional or alternate copyrights,
licenses, and/or restrictions:
Program Directory
------- ---------
<none yet>
==============================================================================
systemc-clang Release License
==============================================================================
University of Illinois/NCSA
Open Source License
Copyright (c) 2012 University of Waterloo
All rights reserved.
Developed by:
systemc-clang Team
University of Waterloo
https://github.com/anikau31/systemc-clang
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal with
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimers.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimers in the
documentation and/or other materials provided with the distribution.
* Neither the names of the systemc-clang team, University of Waterloo,
nor the names of its contributors may be used to
endorse or promote products derived from this Software without specific
prior written permission.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
SOFTWARE.
Some useful commands and notes
==================
To speed up the parsing, we use pre-compiled headers.
* Create the PCH for systemc.h,
```bash
$ clang -cc1 $SYSTEMC/include/systemc.h -emit-pch -o systemc.h.pch -x c++ -I$SYSTEMC/include
```
* Dump the CFG using the following command.
```bash
clang++ -cc1 -analyze -analyzer-checker=debug.DumpCFG -x c++ <filename>.cpp
```
* Dump the Graphviz CFG using the following command.
```bash
clang++ -cc1 -analyze -analyzer-checker=debug.ViewCFG -x c++ <filename>.cpp
```
* Compile project for Xcode (Mac specific) using cmake
```bash
$ mkdir build
$ cmake -G "Xcode" <path-to-systemc-clang>/
```
[systemc-clang](http://github.com/anikau31/systemc-clang): SystemC Parser using the Clang Front-end
================================================================================================
[systemc-clang](https://github.com/anikau31/systemc-clang) is a revamp of an earlier [SystemC](http://systemc.org) Parser called [SystemCXML](http://systemcxml.sourceforge.net/). The purpose of this project is to provide researchers and individuals with a parser for SystemC. This SystemC parser uses the [clang](http://clang.llvm.org) front-end.
The public release will only allow parsing and representation of structural information of SystemC models at the RTL. This implementation will provide a reflection data structure that a designer can use to extract this information.
Internally, we are developing methods to represent behavioural information of the SystemC models. In addition, we plan to support TLM 2.0 models as well. Stay tuned for more updates and releases.
As always, please feel free to provide issues, and feature requests.
Requirements
------------
* [llvm](http://llvm.org) (trunk: svn version 179461)
* [clang](http://clang.llvm.org) (trunk: svn version 179461)
* [SystemC](http://systemc.org) version 2.2.0
* Please see [SystemC Installation notes](https://github.com/anikau31/systemc-clang/blob/revamp/doc/systemc-install.mkd)
Installation
------------
Please see the instruction [here](https://github.com/anikau31/systemc-clang/blob/revamp/INSTALL.mkd)
Plugging into systemc-clang
---------------------------
Write a simple [plugin](https://github.com/anikau31/systemc-clang/blob/revamp/doc/plugins.mkd) to access the parsed information.
Contact
-------
* [Anirudh M. Kaushik](https://ece.uwaterloo.ca/~anikau31/uwhtml/team/anirudh-kaushik/)
License
--------
* systemc-clang follows the same licensing as clang. Please look at [LICENSE]( https://github.com/anikau31/systemc-clang/blob/revamp/LICENSE.mkd).
Other Tools
------------
There are several other SystemC parsers that are available. If you try them, and have some feedback for us, please let us know.
* [SystemCXML:](http://systemcxml.sourceforge.net/)
* [Pinapa: A SystemC Front-end](http://greensocs.sourceforge.net/pinapa/)
* [KaSCPar: Karlsruhe SystemC Parser Suite](http://www.fzi.de/index.php/de/component/content/article/238-ispe-sim/4350-sim-tools-kascpar-examples)
Urgent
=======
- There is duplication between SignalInstanceContainer class and a Signal, and SignalContainer. This needs to be fixed to avoid further confusions.
In Progress
============
- Find connection netlist (bindings)
- Provide data structure for querying structural information
Fixed
======
- Find instances of sc_modules.
- Find sc_main function
Older
============
*Supported but refinements necessary*
FindPorts.h
-----------
- DONE: Default types are not handled, but template types are !! huh!
FindEntryFunctions.h
--------------------
- Multiple entry functions in different constructors of the same class.
FindSensitivity.h
--------------------
- We only handle "sensitive << a << b" type calls.
- Have to support .pos(), .neg(), and sensitive_neg/sensitive_pos.
Compiling SystemC 2.2.0 Instructions
----------------------------------------
- On Mac OSX:
-- ../configure --build=i386-pc-linux (must pass the pc-linux build flag)
-- make[3]: Entering directory xxxx/systemc-2.2.0/src/sysc/qt'
as -o qtmds.o qtmds.s -I. -I. -I. -I../../../src
qtmds.s: Assembler messages:
qtmds.s:69: Error: suffix or operands invalid for `push'
qtmds.s:70: Error: suffix or operands invalid for `push
....
The solution is:
1)remove the file xxxx/systemc-2.2.0/src/sysc/qt/qtmds.s
2)go under xxxx/systemc-2.2.0/src/sysc/qt and execute this command:ln -s
md/iX86_64.s qtmds.s to get the "qtmds.s" back but with the correct
version (64 bits), then execute make under the
3)execute make
4) go back to xxxx/systemc-2.2.0 and execute make
Writing a plugin for systemc-clang
==================================
These instructions will help in integrating your code with systemc-clang. This will allow your code to interface with the data structure created by systemc-clang that holds the parsed information.
The steps involved in getting access to the data structure after systemc-clang has parsed the information are as follows.
* Define a class that inherits from `SystemCConsumer`. Let us for our example, declare this class to be ModelDump. Notice a few things here. We are going to inherit from `SystemCConsumer` class, which is responsible for parsing and creating the data structure. The constructor passes a `CompilerInstance` reference to the base class. This is necessary so for the systemc-clang to know parameters to the clang.
```c++
#include "SystemCClang.h"
using namespace clang;
using namespace scpar;
class ModelDump
: public SystemCConsumer {
public:
ModelDump( CompilerInstance& ci)
: SystemCConsumer(ci) {
}
// Virtual methods.
bool postFire() {
Model* model = getSystemCModel();
// Just dump the model traits.
llvm::errs() << "\n Datastructure dump from static analysis\n";
model->dump(llvm::errs());
return true;
}
};
```
* `SystemCConsumer` provides a virtual method `postFire` that can be overridden. The overridden `postFire` method uses `getSystemCModel()` to retrieve a pointer to the data structure that stores the parsed information.
* Invoking `model->dump(llvm::errs());` prints out the information stored in the data structure. Additional methods can be found at [Model.h](https://github.com/anikau31/systemc-clang/blob/revamp/src/Model.h).
* Edit the [driver-tooling.cpp]() file with the following changes.
** Include your class header file.
** Provide a template argument that is the class name of the created class. For our example, we will provide `ModelDump` as the class name.
```c++
#include "PluginAction.h"
using namespace scpar;
// Include your class
#include "ModelDump.h"
int main(int argc, const char **argv)
{
PluginAction<ModelDump> pa(argc, argv);
return 0;
}
```
* Compile systemc-clang. The executable will now execute the method `postFire` after the SystemC file is parsed.
SystemC 2.2.0 Installation Notes
--------------------------------
We have tested this on Mac OSX, and Ubuntu 64bit.
Mutable errors