Skip to content

Commit

Permalink
adding basic example with python to close #1
Browse files Browse the repository at this point in the history
Signed-off-by: vsoch <vsoch@users.noreply.github.com>
  • Loading branch information
vsoch committed May 8, 2022
1 parent 0532ecf commit f0d5320
Show file tree
Hide file tree
Showing 8 changed files with 1,815 additions and 2 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ For more detailed examples, see:

## TODO

- write asp example
- looking into clingo for go
- write python example
- write abi example
- write out actual full spec
114 changes: 114 additions & 0 deletions python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Python Changes

Now that we've seen a simple example using [asp](../asp) it might make sense
to try to extend this example to Python, and reading binary dwarf. We will
use [this repository](https://github.com/buildsi/build-abi-test-mathclient) that has two versions of a
library to build - a math client with the same namespace / class / functions
but parameter type changes.

## Setup

Let's clone the different versions and build them!

```bash
git clone https://github.com/buildsi/build-abi-test-mathclient
cd build-abi-test-mathclient
git fetch
```
Build version 2.0

```bash
make
cp libmath.so ../libmath.v2.so
```

And version 1!

```bash
git checkout 1.0.0
make
cp libmath.so ../libmath.v1.so
```

These libraries will be required for the example, so make sure you have them!

## Usage

First, prepare your environment. You will need to install clingo (or the Python wrapper to it).

```bash
$ python -m venv env
$ source env/bin/activate
$ pip install -r requirements.txt
```

And then run the example!

```bash
$ python example.py
```
```bash
$ python example.py
{
"is_a": [
[
"A"
]
],
"is_b": [
[
"B"
]
],
"is_different": [
[
"A",
"B"
]
],
"removed_node": [
[
"A",
"B",
"function",
"_ZN11MathLibrary10Arithmetic3AddEii"
],
[
"A",
"B",
"type",
"int"
],
[
"A",
"B",
"basetype",
"int"
],
[
"A",
"B",
"size",
"4"
],
[
"A",
"B",
"location",
"framebase-20"
]
],
"added_node": [
[
"A",
"B",
"function",
"_ZN11MathLibrary10Arithmetic3AddEdd"
]
]
}
```

Note that the scripts here can be integrated into a module proper if this
idea makes sense. The current example is very simple, and I'll need to parse more complex
ones (e.g., with more DWARF DIE tag types) to finish it up.

0 comments on commit f0d5320

Please sign in to comment.