Skip to content

aleden/carbon-copy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Description

Transitively extract source code from a codebase written in C into a single (continuous) standalone file. paper

Usage

There are two steps. The first step is to "collect" information about the given codebase. This is accomplished through a clang plugin.

CFLAGS += -Xclang -load -Xclang /path/to/libcarbon-collect.so \
          -Xclang -add-plugin -Xclang carbon-collect \
          -Xclang -plugin-arg-carbon-collect -Xclang /path/to/source \
          -Xclang -plugin-arg-carbon-collect -Xclang /path/to/build

After compiling, the build directory should contain a directory named .carbon. That is the (serialized) result of the collect step. The second step is to make use of it with carbon-extract

# extract the top-level element at line number 123 (could be a function, or struct, or typedef, etc.)
carbon-extract relative/path/to/source/file.c:123l

Note that the resulting view of the codebase is specific to the build (chosen configuration, the host machine's architecture, etc), as it occurs during compilation (after the preprocessing step, although the output is not preprocessed). Having this "dynamic" view of the codebase is what makes the extraction step straightforward (and correct).

Building

Install recent (>=11) clang. If your distro has a package for it, it is recommended to use that.

cd carbon-copy/
mkdir build && cd build/
cmake -G Ninja -D CMAKE_BUILD_TYPE=RelWithDebInfo ..
ninja

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published