Early Python binding for libasm (untested)
This commit is contained in:
parent
d17ca8dfde
commit
0bd5a62bad
4
Makefile
4
Makefile
@ -66,6 +66,10 @@ dist:
|
|||||||
$(PACKAGE)-$(VERSION)/src/format.h \
|
$(PACKAGE)-$(VERSION)/src/format.h \
|
||||||
$(PACKAGE)-$(VERSION)/src/parser.h \
|
$(PACKAGE)-$(VERSION)/src/parser.h \
|
||||||
$(PACKAGE)-$(VERSION)/src/token.h \
|
$(PACKAGE)-$(VERSION)/src/token.h \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/python/project.conf \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/python/Makefile \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/python/libasm.c \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/python/libasm.py \
|
||||||
$(PACKAGE)-$(VERSION)/src/project.conf \
|
$(PACKAGE)-$(VERSION)/src/project.conf \
|
||||||
$(PACKAGE)-$(VERSION)/src/arch/amd64.c \
|
$(PACKAGE)-$(VERSION)/src/arch/amd64.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/arch/arm.c \
|
$(PACKAGE)-$(VERSION)/src/arch/arm.c \
|
||||||
|
@ -5,7 +5,7 @@ cppflags=
|
|||||||
cflags_force=-W `pkg-config --cflags cpp`
|
cflags_force=-W `pkg-config --cflags cpp`
|
||||||
cflags=-Wall -g -O2 -pedantic
|
cflags=-Wall -g -O2 -pedantic
|
||||||
ldflags=-ldl
|
ldflags=-ldl
|
||||||
dist=Makefile,arch.h,code.h,common.h,format.h,parser.h,token.h
|
dist=Makefile,arch.h,code.h,common.h,format.h,parser.h,token.h,python/project.conf,python/Makefile,python/libasm.c,python/libasm.py
|
||||||
|
|
||||||
[libasm]
|
[libasm]
|
||||||
type=library
|
type=library
|
||||||
|
52
src/python/Makefile
Normal file
52
src/python/Makefile
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
MKDIR = mkdir -m 0755 -p
|
||||||
|
INSTALL = install
|
||||||
|
RM = rm -f
|
||||||
|
TARGETS = _libasm.so
|
||||||
|
PREFIX = /usr/local
|
||||||
|
DESTDIR =
|
||||||
|
LIBDIR = $(PREFIX)/lib
|
||||||
|
CC = cc
|
||||||
|
CPPFLAGSF= -I ../../include
|
||||||
|
CPPFLAGS=
|
||||||
|
CFLAGSF = -W `pkg-config --cflags python-2.7 Asm` -fPIC
|
||||||
|
CFLAGS = -Wall -g -O2
|
||||||
|
LDFLAGSF= `pkg-config --libs python-2.7 Asm`
|
||||||
|
LDFLAGS = -L.. -L$(LIBDIR) -Wl,-rpath,$(LIBDIR)
|
||||||
|
AR = ar
|
||||||
|
RANLIB = ranlib
|
||||||
|
CCSHARED= $(CC) -shared
|
||||||
|
RM = rm -f
|
||||||
|
LN = ln -f
|
||||||
|
MKDIR = mkdir -m 0755 -p
|
||||||
|
INSTALL = install
|
||||||
|
|
||||||
|
|
||||||
|
all: $(TARGETS)
|
||||||
|
|
||||||
|
_libasm_OBJS = libasm.o
|
||||||
|
_libasm_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
||||||
|
_libasm_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
||||||
|
|
||||||
|
_libasm.so: $(_libasm_OBJS)
|
||||||
|
$(CCSHARED) -o _libasm.so $(_libasm_OBJS) $(_libasm_LDFLAGS)
|
||||||
|
|
||||||
|
libasm.o: libasm.c
|
||||||
|
$(CC) $(_libasm_CFLAGS) -c libasm.c
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) -- $(_libasm_OBJS)
|
||||||
|
|
||||||
|
distclean: clean
|
||||||
|
$(RM) -- $(TARGETS)
|
||||||
|
|
||||||
|
install: $(TARGETS)
|
||||||
|
$(MKDIR) $(DESTDIR)$(PREFIX)/lib/python2.7/site-packages
|
||||||
|
$(INSTALL) -m 0644 -- _libasm.so $(DESTDIR)$(PREFIX)/lib/python2.7/site-packages/_libasm.so
|
||||||
|
$(MKDIR) $(DESTDIR)$(PREFIX)/lib/python2.7/site-packages
|
||||||
|
$(INSTALL) -m 0644 -- libasm.py $(DESTDIR)$(PREFIX)/lib/python2.7/site-packages/libasm.py
|
||||||
|
|
||||||
|
uninstall:
|
||||||
|
$(RM) -- $(DESTDIR)$(PREFIX)/lib/python2.7/site-packages/_libasm.so
|
||||||
|
$(RM) -- $(DESTDIR)$(PREFIX)/lib/python2.7/site-packages/libasm.py
|
||||||
|
|
||||||
|
.PHONY: all clean distclean install uninstall
|
81
src/python/libasm.c
Normal file
81
src/python/libasm.c
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
/* $Id$ */
|
||||||
|
/* Copyright (c) 2013 Pierre Pronchery <khorben@defora.org> */
|
||||||
|
/* This file is part of DeforaOS Devel asm */
|
||||||
|
/* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3 of the License.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <Python.h>
|
||||||
|
#include "Devel/Asm.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* libasm */
|
||||||
|
/* private */
|
||||||
|
/* constants */
|
||||||
|
static char const _libasm_asm_name[] = "libasm::Asm";
|
||||||
|
|
||||||
|
|
||||||
|
/* prototypes */
|
||||||
|
/* Asm */
|
||||||
|
static PyObject * _libasm_asm_new(PyObject * self, PyObject * args);
|
||||||
|
static void _libasm_asm_delete(PyObject * self);
|
||||||
|
|
||||||
|
|
||||||
|
/* variables */
|
||||||
|
static PyMethodDef _libasm_methods[] =
|
||||||
|
{
|
||||||
|
{ "asm_new", _libasm_asm_new, METH_VARARGS,
|
||||||
|
"Instantiates an Asm object." },
|
||||||
|
{ NULL, NULL, 0, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* public */
|
||||||
|
/* prototypes */
|
||||||
|
PyMODINIT_FUNC init_libasm(void);
|
||||||
|
|
||||||
|
|
||||||
|
/* functions */
|
||||||
|
PyMODINIT_FUNC init_libasm(void)
|
||||||
|
{
|
||||||
|
Py_InitModule("_libasm", _libasm_methods);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* private */
|
||||||
|
/* functions */
|
||||||
|
/* Asm */
|
||||||
|
/* libasm_asm_new */
|
||||||
|
static PyObject * _libasm_asm_new(PyObject * self, PyObject * args)
|
||||||
|
{
|
||||||
|
Asm * a;
|
||||||
|
char const * arch;
|
||||||
|
char const * format;
|
||||||
|
|
||||||
|
if(!PyArg_ParseTuple(args, "ss", &arch, &format))
|
||||||
|
return NULL;
|
||||||
|
if((a = asm_new(arch, format)) == NULL)
|
||||||
|
return NULL;
|
||||||
|
return PyCapsule_New(a, _libasm_asm_name, _libasm_asm_delete);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* libasm_asm_delete */
|
||||||
|
static void _libasm_asm_delete(PyObject * self)
|
||||||
|
{
|
||||||
|
Asm * a;
|
||||||
|
|
||||||
|
if((a = PyCapsule_GetPointer(self, _libasm_asm_name)) == NULL)
|
||||||
|
return;
|
||||||
|
asm_delete(a);
|
||||||
|
}
|
25
src/python/libasm.py
Normal file
25
src/python/libasm.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#!/usr/bin/env python2.7
|
||||||
|
#$Id$
|
||||||
|
#Copyright (c) 2013 Pierre Pronchery <khorben@defora.org>
|
||||||
|
#This file is part of DeforaOS Devel asm
|
||||||
|
#This program is free software: you can redistribute it and/or modify
|
||||||
|
#it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
#the Free Software Foundation, version 3 of the License.
|
||||||
|
#
|
||||||
|
#This program is distributed in the hope that it will be useful,
|
||||||
|
#but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
#GNU Lesser General Public License for more details.
|
||||||
|
#
|
||||||
|
#You should have received a copy of the GNU Lesser General Public License
|
||||||
|
#along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import _libasm
|
||||||
|
|
||||||
|
|
||||||
|
#Asm
|
||||||
|
class Asm:
|
||||||
|
def __init__(self, arch, format):
|
||||||
|
self.asm = _libasm.asm_new(arch, format)
|
15
src/python/project.conf
Normal file
15
src/python/project.conf
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
targets=_libasm
|
||||||
|
cppflags_force=-I ../../include
|
||||||
|
cflags_force=-W `pkg-config --cflags python-2.7 Asm` -fPIC
|
||||||
|
cflags=-Wall -g -O2
|
||||||
|
ldflags_force=`pkg-config --libs python-2.7 Asm`
|
||||||
|
ldflags=-L.. -L$(LIBDIR) -Wl,-rpath,$(LIBDIR)
|
||||||
|
dist=Makefile,libasm.py
|
||||||
|
|
||||||
|
[_libasm]
|
||||||
|
type=plugin
|
||||||
|
sources=libasm.c
|
||||||
|
install=$(PREFIX)/lib/python2.7/site-packages
|
||||||
|
|
||||||
|
[libasm.py]
|
||||||
|
install=$(PREFIX)/lib/python2.7/site-packages
|
Loading…
Reference in New Issue
Block a user