https://github.com/eswar2001/fieldinspector
https://github.com/eswar2001/fieldinspector
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/eswar2001/fieldinspector
- Owner: eswar2001
- License: mit
- Created: 2024-06-20T04:23:13.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-26T07:02:40.000Z (about 2 years ago)
- Last Synced: 2024-06-26T11:05:28.213Z (about 2 years ago)
- Language: Haskell
- Size: 165 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# FieldInspector Plugin
## Overview
The FieldInspector plugin is a GHC (Glasgow Haskell Compiler) plugin designed to collect and analyze field usage information within Haskell code. This plugin is useful for understanding how fields within data types are used across different modules in a Haskell project.
## Installation
To use the FieldInspector plugin, include it in your GHC configuration. Typically, this involves adding the plugin to your project's `.cabal` file or passing it as a command-line argument when invoking GHC.
## Usage
### Command-Line Options
The plugin accepts the following command-line options:
- A single optional argument specifying the output directory for the generated JSON files. If no argument is provided, the default directory is `/tmp/fieldInspector/`.
### Enabling the Plugin
To enable the plugin, add the following line to your GHC command:
```
-ghc-options "-fplugin=FieldInspector.Plugin"
```
If you want to specify an output directory, use:
```
-ghc-options "-fplugin=FieldInspector.Plugin:"
```
## How It Works
The plugin operates in two main phases:
1. **Core-to-Core Pass**:
- The `buildCfgPass` function is executed during the core-to-core transformation phase of the GHC compilation process.
- This function analyzes the Core bindings (`CoreBind`) in the current module and collects field usage information.
- The collected information is written to a JSON file named `fieldUsage.json` in the specified or default directory.
2. **Type Collection**:
- The `collectTypes` function is executed after the type-checking phase.
- This function collects information about type constructors (`TyCon`) and data constructors (`DataCon`) in the module.
- The collected type information is written to a JSON file named `types.json` in the specified or default directory.
## Output
The plugin generates two JSON files for each module:
### fieldUsage.json:
Contains information about field usage within the module.
### types.json:
Contains information about types and their constructors within the module.
## The exe onsolidates these files into two comprehensive datasets:
### fieldUsage-data.json:
consolidated all modules data
### types-data.json
consolidated all modules data