diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8fd7eef --- /dev/null +++ b/Makefile @@ -0,0 +1,62 @@ +# Makefile for tlin + +# Go parameters +GOCMD=go +GOBUILD=$(GOCMD) build +GOTEST=$(GOCMD) test +GOCLEAN=$(GOCMD) clean +GOGET=$(GOCMD) get +BINARY_NAME=tlin +BINARY_UNIX=$(BINARY_NAME)_unix +BINARY_WINDOWS=$(BINARY_NAME).exe +BINARY_MAC=$(BINARY_NAME)_mac + +# Main package path +MAIN_PACKAGE=./cmd/tlin + +# Build the project +all: test build + +build: + $(GOBUILD) -o $(BINARY_NAME) -v $(MAIN_PACKAGE) + +# Cross compilation +build-linux: + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -o $(BINARY_UNIX) -v $(MAIN_PACKAGE) + +build-windows: + CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(GOBUILD) -o $(BINARY_WINDOWS) -v $(MAIN_PACKAGE) + +build-mac: + CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GOBUILD) -o $(BINARY_MAC) -v $(MAIN_PACKAGE) + +test: + $(GOTEST) -v ./... + +clean: + $(GOCLEAN) + rm -f $(BINARY_NAME) + rm -f $(BINARY_UNIX) + rm -f $(BINARY_WINDOWS) + rm -f $(BINARY_MAC) + +run: + $(GOBUILD) -o $(BINARY_NAME) -v $(MAIN_PACKAGE) + ./$(BINARY_NAME) + +# Cross compilation +build-all: build-linux build-windows build-mac + +# Dependencies +deps: + $(GOGET) -v ./... + +# Install golangci-lint +install-linter: + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin + +# Run golangci-lint +lint: + golangci-lint run + +.PHONY: all build test clean run deps build-linux build-windows build-mac build-all install-linter lint diff --git a/README.md b/README.md index a5fc408..01aea3b 100644 --- a/README.md +++ b/README.md @@ -159,6 +159,34 @@ The output will show: Use this feature to identify complex parts of your codebase that might benefit from refactoring. +## Control Flow Graph (CFG) [Experimental] + +tlin supports generating control flow graphs (CFG) for functions, A CFG is a representation of all paths that might be traversed through a program during its execution. + +### What is CFG? + +A Control Flow Graph (CFG) is a graphical representation of the flow of control in a program. It shows: + +- All possible execution paths in a function +- Basic blocks of code (sequences of instructions with no branches except at the end) +- Branching points (if statements, loops, etc.) +- Function entry and exit points + +### How to Generate CFG? + +To generate a CFG for a specific function, use the follow command: + +```bash +tlin -cfg -func +``` + +Where: + +- `` is the name of the function you want to analyze +- `` is the path to the file or directory containing the function + +When you run this command, it outputs a string in DOT format. However, exporting to a file after rendering is not yet supported. + ## Contributing We welcome all forms of contributions, including bug reports, feature requests, and pull requests. Please feel free to open an issue or submit a pull request.