Skip to content

Commit af1dcbf

Browse files
committed
Initial commit: ternary GCC plugin v1.0.0 with plugin, runtime, tests, benchmarks, and docs
0 parents  commit af1dcbf

30 files changed

Lines changed: 3564 additions & 0 deletions

.github/copilot-instructions.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<!-- Use this file to provide workspace-specific custom instructions to Copilot. For more details, visit https://code.visualstudio.com/docs/copilot/copilot-customization#_use-a-githubcopilotinstructionsmd-file -->
2+
- [ ] Verify that the copilot-instructions.md file in the .github directory is created.
3+
4+
- [ ] Clarify Project Requirements
5+
<!-- Ask for project type, language, and frameworks if not specified. Skip if already provided. -->
6+
7+
- [ ] Scaffold the Project
8+
<!--
9+
Ensure that the previous step has been marked as completed.
10+
Call project setup tool with projectType parameter.
11+
Run scaffolding command to create project files and folders.
12+
Use '.' as the working directory.
13+
If no appropriate projectType is available, search documentation using available tools.
14+
Otherwise, create the project structure manually using available file creation tools.
15+
-->
16+
17+
- [x] Customize the Project
18+
<!-- Skipped for Hello World project. -->
19+
20+
- [ ] Install Required Extensions
21+
<!-- ONLY install extensions provided mentioned in the get_project_setup_info. Skip this step otherwise and mark as completed. -->
22+
23+
- [x] Compile the Project
24+
<!--
25+
Vex] Install Required Extensions
26+
<!-- No extensions need
27+
Run diagnostics and resolve any issues.
28+
Check for markdown files in project folder for relevant instructions on how to do this.
29+
-->
30+
- [x] Compile the Project completed: Ran make to build the plugin.
31+
32+
- [ ] Create and Run Task
33+
<!--
34+
Verify that all previous steps have been completed.
35+
Check https://code.visualstudio.com/docs/debugtest/tasks to determine if the project needs a task. If so, use the create_and_run_task to create and launch a task based on package.json, README.md, and project structure.
36+
Skip
37+
- [x] Create and Run Task completed: No tasks.json needed for this project. this step otherwise.
38+
-->
39+
40+
- [ ] Launch the Project
41+
<!--
42+
Verify that all previous steps have been completed.
43+
Prom
44+
- [x] Launch the Project completed: No launch configuration needed.pt user for debug mode, launch only if confirmed.
45+
-->
46+
47+
- [ ] Ensure Documentation is Complete
48+
<!--
49+
Verify that all previous steps have been completed.
50+
Veri
51+
- [x] Ensure Documentation is Complete completed: README.md created, cleaned up copilot-instructions.md.fy that README.md and the copilot-instructions.md file in the .github directory exists and contains current project information.
52+
Clean up the copilot-instructions.md file in the .github directory by removing all HTML comments.
53+
-->
54+
55+
<!--
56+
## Execution Guidelines
57+
PROGRESS TRACKING:
58+
- If any tools are available to manage the above todo list, use it to track progress through this checklist.
59+
- After completing each step, mark it complete and add a summary.
60+
- Read current todo list status before starting each new step.
61+
62+
COMMUNICATION RULES:
63+
- Avoid verbose explanations or printing full command outputs.
64+
- If a step is skipped, state that briefly (e.g. "No extensions needed").
65+
- Do not explain project structure unless asked.
66+
- Keep explanations concise and focused.
67+
68+
DEVELOPMENT RULES:
69+
- Use '.' as the working directory unless user specifies otherwise.
70+
- Avoid adding media or external links unless explicitly requested.
71+
- Use placeholders only with a note that they should be replaced.
72+
- Use VS Code API tool only for VS Code extension projects.
73+
- Once the project is created, it is already opened in Visual Studio Code—do not suggest commands to open this project in Visual Studio again.
74+
- If the project setup information has additional rules, follow them strictly.
75+
76+
FOLDER CREATION RULES:
77+
- Always use the current directory as the project root.
78+
- If you are running any terminal commands, use the '.' argument to ensure that the current working directory is used ALWAYS.
79+
- Do not create a new folder unless the user explicitly requests it besides a .vscode folder for a tasks.json file.
80+
- If any of the scaffolding commands mention that the folder name is not correct, let the user know to create a new folder with the correct name and then reopen it again in vscode.
81+
82+
EXTENSION INSTALLATION RULES:
83+
- Only install extension specified by the get_project_setup_info tool. DO NOT INSTALL any other extensions.
84+
85+
PROJECT CONTENT RULES:
86+
- If the user has not specified project details, assume they want a "Hello World" project as a starting point.
87+
- Avoid adding links of any type (URLs, files, folders, etc.) or integrations that are not explicitly required.
88+
- Avoid generating images, videos, or any other media files unless explicitly requested.
89+
- If you need to use any media assets as placeholders, let the user know that these are placeholders and should be replaced with the actual assets later.
90+
- Ensure all generated components serve a clear purpose within the user's requested workflow.
91+
- If a feature is assumed but not confirmed, prompt the user for clarification before including it.
92+
- If you are working on a VS Code extension, use the VS Code API tool with a query to find relevant VS Code API references and samples related to that query.
93+
94+
TASK COMPLETION RULES:
95+
- Your task is complete when:
96+
- Project is successfully scaffolded and compiled without errors
97+
- copilot-instructions.md file in the .github directory exists in the project
98+
- README.md file exists and is up to date
99+
- User is provided with clear instructions to debug/launch the project
100+
101+
Before starting a new task in the above plan, update progress in the plan.
102+
-->
103+
- Work through each checklist item systematically.
104+
- Keep communication concise and focused.
105+
- Follow development best practices.

.github/workflows/ci.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
matrix:
14+
os: [ubuntu-latest, macos-latest]
15+
gcc-version: [9, 11]
16+
17+
steps:
18+
- uses: actions/checkout@v2
19+
20+
- name: Install GCC ${{ matrix.gcc-version }}
21+
if: matrix.os == 'ubuntu-latest'
22+
run: |
23+
sudo apt-get update
24+
sudo apt-get install -y gcc-${{ matrix.gcc-version }} g++-${{ matrix.gcc-version }}
25+
echo "CC=gcc-${{ matrix.gcc-version }}" >> $GITHUB_ENV
26+
echo "CXX=g++-${{ matrix.gcc-version }}" >> $GITHUB_ENV
27+
28+
- name: Install GCC ${{ matrix.gcc-version }}
29+
if: matrix.os == 'macos-latest'
30+
run: |
31+
brew install gcc@${{ matrix.gcc-version }}
32+
echo "CC=gcc-${{ matrix.gcc-version }}" >> $GITHUB_ENV
33+
echo "CXX=g++-${{ matrix.gcc-version }}" >> $GITHUB_ENV
34+
35+
- name: Build Plugin
36+
run: make
37+
38+
- name: Build Runtime
39+
run: |
40+
gcc -Iinclude -c runtime/ternary_runtime.c -o ternary_runtime.o
41+
42+
- name: Run Tests
43+
run: |
44+
cd tests
45+
chmod +x run_tests.sh
46+
./run_tests.sh
47+
# Compile ABI test
48+
gcc -I../include -c test_abi.c -o test_abi.o
49+
gcc test_abi.o ../runtime/ternary_runtime.o -o test_abi
50+
./test_abi
51+
# Compile promotion test
52+
gcc -fplugin=../ternary_plugin.so -fplugin-arg-ternary_plugin-types -I../include -c test_promotion.c -o test_promotion.o
53+
gcc test_promotion.o -o test_promotion
54+
./test_promotion
55+
# Sanity check
56+
gcc -c test_no_ternary.c -o test_no_ternary.o
57+
# Run benchmark
58+
gcc -I../include -c benchmark.c -o benchmark.o
59+
gcc benchmark.o ../runtime/ternary_runtime.o -o benchmark
60+
./benchmark
61+
# Edge cases
62+
gcc -I../include -c test_edge_cases.c -o test_edge_cases.o
63+
gcc test_edge_cases.o ../runtime/ternary_runtime.o -o test_edge_cases
64+
./test_edge_cases

.gitignore

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Build artifacts
2+
*.o
3+
*.so
4+
*.dylib
5+
*.a
6+
*.exe
7+
8+
# GCC plugin
9+
ternary_plugin.so
10+
11+
# Runtime
12+
runtime/*.o
13+
runtime/ternary_runtime.o
14+
15+
# Test executables
16+
test_ternary
17+
test_abi
18+
test_promotion
19+
test_no_ternary
20+
test_edge_cases
21+
benchmark
22+
23+
# Build directories
24+
build/
25+
cmake-build-*/
26+
CMakeFiles/
27+
CMakeCache.txt
28+
cmake_install.cmake
29+
Makefile
30+
31+
# IDE and editor files
32+
.vscode/
33+
.idea/
34+
*.swp
35+
*.swo
36+
*~
37+
38+
# OS files
39+
.DS_Store
40+
Thumbs.db
41+
42+
# Logs and temp
43+
*.log
44+
*.tmp
45+
46+
# Release artifacts
47+
release/

CMakeLists.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
project(TernaryGCCPlugin)
3+
4+
set(CMAKE_CXX_STANDARD 14)
5+
6+
# Find GCC plugin includes
7+
find_path(GCC_PLUGIN_INCLUDE_DIR
8+
NAMES gcc-plugin.h
9+
PATHS /opt/homebrew/Cellar/gcc/15.2.0/lib/gcc/current/gcc/aarch64-apple-darwin25/15/plugin/include
10+
/usr/lib/gcc/x86_64-linux-gnu/9/plugin/include
11+
/usr/local/lib/gcc/x86_64-linux-gnu/9/plugin/include
12+
)
13+
14+
if(NOT GCC_PLUGIN_INCLUDE_DIR)
15+
message(FATAL_ERROR "GCC plugin include directory not found")
16+
endif()
17+
18+
include_directories(${GCC_PLUGIN_INCLUDE_DIR})
19+
include_directories(include)
20+
21+
# Plugin
22+
add_library(ternary_plugin SHARED src/ternary_plugin.cpp)
23+
target_compile_definitions(ternary_plugin PRIVATE PIC)
24+
target_link_libraries(ternary_plugin -Wl,-undefined,dynamic_lookup)
25+
26+
# Runtime
27+
add_library(ternary_runtime STATIC runtime/ternary_runtime.c)
28+
target_include_directories(ternary_runtime PUBLIC include)
29+
30+
# Install
31+
install(TARGETS ternary_plugin ternary_runtime
32+
LIBRARY DESTINATION lib
33+
ARCHIVE DESTINATION lib
34+
)
35+
install(DIRECTORY include/ DESTINATION include/ternary FILES_MATCHING PATTERN "*.h")

CONTRIBUTING.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Contributing to Ternary GCC Plugin
2+
3+
## How to Contribute
4+
5+
1. Fork the repository.
6+
2. Create a feature branch.
7+
3. Make changes, add tests.
8+
4. Run `make` and `./tests/run_tests.sh`.
9+
5. Submit a PR.
10+
11+
## Guidelines
12+
13+
- Follow GCC plugin best practices.
14+
- Add tests for new features.
15+
- Update documentation.
16+
17+
## Building with CMake
18+
19+
```bash
20+
mkdir build && cd build
21+
cmake ..
22+
make
23+
```

Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM ubuntu:20.04
2+
3+
RUN apt-get update && apt-get install -y gcc-9 g++-9 make
4+
5+
WORKDIR /app
6+
7+
COPY . .
8+
9+
RUN make
10+
11+
CMD ["bash"]

0 commit comments

Comments
 (0)