Skip to content

Lightweight tool for slicing

Notifications You must be signed in to change notification settings

srcML/srcSlice

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:

# Install srcML Develop if not installed on your local machine, after running 'make' when building srcML run 'make install' to ensure cmake can find the srcML package when building srcSlice git clone --recursive -b develop https://github.com/srcML/srcML.git

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 -i shell_sort.cpp.xml -o results.json 

Options

Display the srcslice help page

./srcslice --help 

Output debugging info to stdout

./srcslice -i shell_sort.cpp.xml --verbose 

Set the input srcML output file to read in

./srcslice -i shell_sort.cpp.xml 

Write the output to file. By default, it writes to standard output

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

Examples

Generate slices and write output to standard output

./srcslice -i shell_sort.cpp.xml 

Generate slices and write output to slices.json

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

srcSlice Output

AttributeDescription
FileFile path of the source code the slice variable originates from
LanguageLanguage of the source code file
NamespaceList of namespaces the slice variable is contained in
ClassName of the class containing the slice variable
FunctionName of the function containing the slice variable
TypeData type of the slice variable
NameVariable 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
UseA set of positions where the slice variable is used
DefinitionA set of positions where the slice variable is defined or redefined

About

Lightweight tool for slicing

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 9