Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
.git/
venv/
tmp/

build/
**/build/
**/build-*/
**/build*/

**/subprojects/.wraplock
**/subprojects/packagecache/
**/subprojects/approvaltests/

**/*.received.*

Dockerfile
85 changes: 85 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: build and test

on: [pull_request]

jobs:
test-compiler:
name: Test Compiler
runs-on: ubuntu-24.04

steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y bison flex libfl-dev g++-13 python3-venv
g++-13 --version
python3 -m venv venv
. venv/bin/activate
python -m pip install --upgrade pip
python -m pip install 'meson>=1.10.1' 'ninja>=1.11' 'reoxide==0.7.2'

- name: Test compiler
working-directory: src/compiler
run: |
. ../../venv/bin/activate
export XDG_CONFIG_HOME="${RUNNER_TEMP}/config"
mkdir -p "${XDG_CONFIG_HOME}/reoxide"
touch "${XDG_CONFIG_HOME}/reoxide/reoxide.toml"
CXX=g++-13 meson setup build --buildtype release -Dtests=true
meson compile -j 1 -C build
meson test -C build --print-errorlogs

build-plugin:
name: Build Plugin
runs-on: ubuntu-24.04

steps:
- uses: actions/checkout@v4

- name: Build plugin
run: docker build -o tmp/out .

test-plugin:
name: Test Plugin
runs-on: ubuntu-24.04

steps:
- uses: actions/checkout@v4

- name: Install host dependencies
run: |
sudo apt-get update
sudo apt-get install -y bison flex libfl-dev g++-13 python3-venv
python3 -m venv venv
. venv/bin/activate
python -m pip install --upgrade pip
python -m pip install 'meson>=1.10.1' 'ninja>=1.11' 'reoxide==0.7.2'

- name: Build compiler for rule fixtures
working-directory: src/compiler
run: |
. ../../venv/bin/activate
export XDG_CONFIG_HOME="${RUNNER_TEMP}/config"
mkdir -p "${XDG_CONFIG_HOME}/reoxide"
touch "${XDG_CONFIG_HOME}/reoxide/reoxide.toml"
CXX=g++-13 meson setup build --buildtype release -Dtests=false
meson compile -j 1 -C build

- name: Build plugin test base image
run: |
docker build \
-f src/plugin/tests/docker/base.Dockerfile \
-t pcode-weaver-plugin-test-base:ghidra-12.0_reoxide-0.7.2 \
.

- name: Build plugin test image
run: docker build --target plugin-test -t pcode-weaver-plugin-test .

- name: Test plugin
working-directory: src/plugin/tests
run: |
. ../../../venv/bin/activate
meson setup build --buildtype release
meson test -C build --print-errorlogs
41 changes: 0 additions & 41 deletions .github/workflows/build.yml

This file was deleted.

11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,13 @@ src/publisher/parse/parser.cc
src/publisher/parse/location.hh
.codex
tmp
AGENTS.md
AGENTS.md
src/compiler/subprojects/.wraplock
src/compiler/subprojects/approvaltests/
src/compiler/subprojects/packagecache/
src/compiler/tests/**/*.received.*

src/plugin/tests/subprojects/.wraplock
src/plugin/tests/subprojects/approvaltests/
src/plugin/tests/subprojects/packagecache/
src/plugin/tests/fixtures/**/*.received.*
23 changes: 20 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM quay.io/pypa/manylinux2014 AS build
ARG PLUGIN_TEST_BASE_IMAGE=pcode-weaver-plugin-test-base:ghidra-12.0_reoxide-0.7.2

FROM quay.io/pypa/manylinux2014 AS plugin-build

ARG REOXIDE_VERSION=0.7.2
ENV VIRTUAL_ENV=/venv
Expand All @@ -17,12 +19,27 @@ RUN --mount=type=cache,target=/root/.cache/pip \
touch /root/.config/reoxide/reoxide.toml

WORKDIR /plugin
COPY . .
COPY src/inc/ ./src/inc/
COPY src/plugin/meson.build ./src/plugin/meson.build
COPY src/plugin/main/ ./src/plugin/main/

RUN set -ex;\
meson setup build ./src/plugin/ --buildtype release;\
meson install -C build

FROM ${PLUGIN_TEST_BASE_IMAGE} AS plugin-test

COPY --from=plugin-build /root/.local/share/reoxide/plugins/*.so /opt/reoxide/data/plugins/
COPY src/plugin/tests/scripts/ /opt/pcode-weaver/scripts/
COPY scripts/install-pcodeweaver-action.sh /opt/pcode-weaver/scripts/install-pcodeweaver-action.sh

RUN set -ex;\
default_reoxide_yaml="$(python3 -c 'from pathlib import Path; import reoxide; print(Path(reoxide.__file__).parent / "data" / "default.yaml")')";\
cp "${default_reoxide_yaml}" /opt/reoxide/data/current.yaml;\
sh /opt/pcode-weaver/scripts/install-pcodeweaver-action.sh /opt/reoxide/data/current.yaml;\
chmod +x /opt/pcode-weaver/scripts/run-case.sh \
/opt/pcode-weaver/scripts/install-pcodeweaver-action.sh

FROM scratch

COPY --from=build /root/.local/share/reoxide/plugins/*.so .
COPY --from=plugin-build /root/.local/share/reoxide/plugins/*.so .
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Pcode Weaver

[![build and test](https://github.com/osogi/pcode-weaver/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/osogi/pcode-weaver/actions/workflows/build-and-test.yml)
[![formatting-check](https://github.com/osogi/pcode-weaver/actions/workflows/formatting-check.yml/badge.svg)](https://github.com/osogi/pcode-weaver/actions/workflows/formatting-check.yml)

Experimental ReOxide(Ghidra) plugin for applying custom p-code rewrite rules
with validation checks.

Expand Down
4 changes: 4 additions & 0 deletions src/compiler/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ subdir('validate')
subdir('rulecompile')

subdir('bin')

if get_option('tests')
subdir('tests')
endif
1 change: 1 addition & 0 deletions src/compiler/meson_options.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
option('tests', type: 'boolean', value: false, description: 'Build compiler unit tests')
2 changes: 1 addition & 1 deletion src/compiler/parse/context.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "parse/op_type_predefined.hh"

// generated headers
#include "parse/parser.hh"
#include "parse/parser.hpp"

struct Context {
Context()
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/parse/driver.hh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "parse/scanner.hh"

// generated headers
#include "parse/parser.hh"
#include "parse/parser.hpp"

#include <filesystem>

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/parse/op_type_predefined.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "parse/op_type_predefined.hh"

// generated headers
#include "parse/parser.hh"
#include "parse/parser.hpp"

#include <cassert>
#include <unordered_map>
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/parse/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
%skeleton "lalr1.cc"
%require "3.8"

%defines "parse/parser.hh"
%defines "parse/parser.hpp"

%define api.parser.class { Parser }
%define api.token.constructor
Expand Down Expand Up @@ -37,7 +37,7 @@

#include "parse/driver.hh"
#include "parse/scanner.hh"
#include "parse/parser.hh"
#include "parse/parser.hpp"

static yy::Parser::symbol_type yylex(yy::Scanner &scanner) {
return scanner.get_next_token();
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/parse/scanner.hh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#pragma once

// generated headers
#include "parse/parser.hh"
#include "parse/parser.hpp"

#undef yyFlexLexer
#include <FlexLexer.h>
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/parse/scanner.ll
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "parse/driver.hh"

#include "parse/scanner.hh"
#include "parse/parser.hh"
#include "parse/parser.hpp"

// Original yyterminate() macro returns int. Since we're using Bison 3 variants
// as tokens, we must redefine it to change type from `int` to `Parser::semantic_type`
Expand Down
9 changes: 9 additions & 0 deletions src/compiler/subprojects/approvaltests.wrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[wrap-git]
url = https://github.com/approvals/ApprovalTests.cpp.git
revision = v.10.13.0
depth = 1
method = meson
patch_directory = approvaltests

[provide]
approvaltests = approvaltests_dep
31 changes: 31 additions & 0 deletions src/compiler/subprojects/packagefiles/approvaltests/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
project(
'approvaltests',
'cpp',
version: '10.13.0',
)

approvaltests_sources = run_command(
'find',
'ApprovalTests',
'-name',
'*.cpp',
check: true,
).stdout().strip().split('\n')

approvaltests_inc = [
include_directories('.'),
include_directories('ApprovalTests'),
]

approvaltests_lib = static_library(
'approvaltests',
approvaltests_sources,
include_directories: approvaltests_inc,
)

approvaltests_dep = declare_dependency(
include_directories: approvaltests_inc,
link_with: approvaltests_lib,
)

meson.override_dependency('approvaltests', approvaltests_dep)
30 changes: 30 additions & 0 deletions src/compiler/tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Compiler Tests

Compiler tests are disabled by default. Golden tests use ApprovalTests.cpp for
approved/received output comparison, and Meson runs one fixture per test.

To build and run the tests:

```sh
cd src/compiler
# Or any other C++23 compiler
CXX=g++-13 meson setup build-tests -Dtests=true
meson compile -j 1 -C build-tests
meson test -C build-tests
```

Golden tests are discovered from these fixture directories when the build
directory is configured:

```text
src/compiler/tests/fixtures/parser/
src/compiler/tests/fixtures/validate/
src/compiler/tests/fixtures/compile/
```

Each `.rule` fixture should have a sibling `.approved.txt` file. If you add or
remove a `.rule` fixture, reconfigure the test build:

```sh
meson setup --reconfigure build-tests
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fixture: fixtures/parser/copy_propagation.rule
parse_status: 0
stderr:
<empty>
ast:
v_orig ->(0) o_copy(COPY, __b_0) -> v_copy ->(0) o_any(ANY, __b_1)
--
v_orig ->>(0) o_any

3 changes: 3 additions & 0 deletions src/compiler/tests/fixtures/parser/copy_propagation.rule
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
v_orig -> (0) o_copy(COPY, _) -> v_copy -> (0) o_any(_, _)
--
v_orig ->> (0) o_any
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fixture: fixtures/parser/empty_examples.rule
parse_status: 0
stderr:
<empty>
ast:
VEMPTY ->(0) OPEMPTY -> VEMPTY
--
VEMPTY ->>(0) op_new

3 changes: 3 additions & 0 deletions src/compiler/tests/fixtures/parser/empty_examples.rule
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
VEMPTY -> (0) OPEMPTY -> VEMPTY
--
VEMPTY ->>(0) op_new
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fixture: fixtures/parser/invalid_arrow_action.rule
parse_status: 1
stderr:
Parser error: fixtures/parser/invalid_arrow_action.rule:3:4: syntax error, unexpected ->, expecting end of file

3 changes: 3 additions & 0 deletions src/compiler/tests/fixtures/parser/invalid_arrow_action.rule
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
v1 -> (0) op(INT_ADD, _)
--
v1 -> (0) op
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fixture: fixtures/parser/invalid_arrow_pattern copy.rule
parse_status: 1
stderr:
Parser error: fixtures/parser/invalid_arrow_pattern copy.rule:1:4: syntax error, unexpected ->>, expecting -- or ;

Loading
Loading