Skip to content

srcML/srcSlice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

626 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

srcSlice

Description

srcSlice is a fast, lightweight srcML tool for static slicing. srcSlice reads srcML output files and produces variable slices in JSON, these slices contain details such as where a variable is used and defined, passed into a function as an argument, function of origin, class it is contained in, variables that are data-dependent of it, and potential aliases.

Table of Contents:


Building srcSlice

Prepare dependencies:

This is a srcML tool, if you do not have srcML installed you must install it. You can download an installer here or you can

# After running 'make' when building srcML, run 'make install' to ensure cmake can find the srcML package when building srcSlice
git clone --recursive https://github.com/srcML/srcML.git

This project uses the nlohmann json for handling JSON

# Linux
apt install nlohmann-json3-dev
sudo pacman -S nlohmann-json
# macOS
brew install nlohmann-json

Preparing srcSlice:

# Clone srcSlice repository
git clone --recursive https://github.com/srcML/srcSlice.git

# (This guide assumes the cloned directory and build directory are at the same working directory)
mkdir build
cd build

# Run cmake to create the build files and run make to build the executable
cmake ../srcSlice

# You can run make but it will take longer
make srcslice

Using srcSlice

Input: A srcML file of source code with --position and --hash options. srcML file can be a single unit (one source code file) or an archive (multiple source code files).

srcml shell_sort.cpp -o shell_sort.cpp.xml --position --hash

Output: A JSON file containing the slice information about each variable contained in the input file.

./srcslice shell_sort.cpp.xml -o results.json

srcSlice supports multi-file slicing against a srcML archive:

srcml src/ -o src.xml -r --position --hash
./srcslice src.xml -o results.json

Options

srcSlice (srcML Slicing Tool)
Usage: srcslice [OPTIONS]

Positionals:
  input srcML FILE REQUIRED   Name of the srcML input file [Must be built using the --position and --hash flags]

Options:
  -h,--help                   Print this help message and exit
  -c,--control-edges          Display Control-Edges of the Slice
  -o,--output TEXT            Name of the JSON output file [Stdout is Default]
  -t,--threads INT            Number of concurrent threads
  -v,--verbose                Display Debug Info when Slicing
  -p,--progress               Display Feedback Progress Bars

Examples

Generate slices and write output to standard output

./srcslice shell_sort.cpp.xml

Generate slices and write output to slices.json

./srcslice shell_sort.cpp.xml -o slices.json

srcSlice Output

Attribute Description
File File path of the source code the slice variable originates from
Language Language of the source code file
Namespace List of namespaces the slice variable is contained in
Class Name of the class containing the slice variable
Function Name of the function containing the slice variable
Type Data type of the slice variable
Name Variable name of the slice variable
Dependence A list of variable-position pairs, containing:
  • Name of Variable Data-Dependent of the Slice
  • Position of the Dependence
Aliases A list of potential targets of a pointer or reference
Calls A list of function calls where the slice variable is used as an argument.
This includes:
  • Function Name
  • Argument Index
  • Position of Function Definition
  • Position of Invokation
Use A set of positions where the slice variable is used
Definition A set of positions where the slice variable is defined or redefined

About

Lightweight tool for slicing

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors