
16 changed files with 0 additions and 1199 deletions
@ -1,10 +0,0 @@ |
|||||
.PHONY: all clean |
|
||||
|
|
||||
all: |
|
||||
$(MAKE) -C synth_shed |
|
||||
$(MAKE) -C test_data |
|
||||
|
|
||||
clean: |
|
||||
$(MAKE) -C synth_shed clean |
|
||||
$(MAKE) -C test_data clean |
|
||||
|
|
@ -1,55 +0,0 @@ |
|||||
TARGET_EXE=synth_shed |
|
||||
TARGET_MODULE=synth_shed.so |
|
||||
|
|
||||
|
|
||||
PREFIX=/Users/heck/local-default |
|
||||
# C
|
|
||||
CFLAGS+=-std=c99 -g |
|
||||
# C++
|
|
||||
CXX=clang |
|
||||
CXXFLAGS+=-std=c++11 -g |
|
||||
|
|
||||
# Sources
|
|
||||
SRCS_C+=$(wildcard *.c) |
|
||||
SRCS_CXX+=$(wildcard *.cc) |
|
||||
|
|
||||
# deps
|
|
||||
INCLUDES+=-I/opt/local/Library/Frameworks/Python.framework/Versions/3.8/include/python3.8 |
|
||||
INCLUDES+=-I$(PREFIX)/include |
|
||||
|
|
||||
#Link
|
|
||||
C_LDFLAGS+= |
|
||||
CXX_LDFLAGS+=-undefined dynamic_lookup |
|
||||
|
|
||||
CXXFLAGS+=$(INCLUDES) |
|
||||
|
|
||||
OBJS_C+=$(SRCS_C:.c=.o) |
|
||||
OBJS_CXX+=$(SRCS_CXX:.cc=.o) |
|
||||
OBJS = $(OBJS_C) $(OBJS_CXX) |
|
||||
|
|
||||
|
|
||||
$(info -----BUILD INFO----) |
|
||||
$(info SRCS_C $(SRCS_C)) |
|
||||
$(info SRCS_CXX $(SRCS_CXX)) |
|
||||
$(info OBJS_C $(OBJS_C)) |
|
||||
$(info OBJS_CXX $(OBJS_CXX)) |
|
||||
$(info OBJS $(OBJS)) |
|
||||
|
|
||||
.PHONY: all exe module clean |
|
||||
|
|
||||
all: exe module |
|
||||
|
|
||||
exe: $(TARGET_EXE) |
|
||||
|
|
||||
module: $(TARGET_MODULE) |
|
||||
|
|
||||
$(TARGET_EXE) : $(OBJS_C) |
|
||||
$(CC) $(C_LDFLAGS) -o $@ $^ |
|
||||
|
|
||||
$(TARGET_MODULE) : $(OBJS) |
|
||||
$(CXX) $(CXX_LDFLAGS) -o $@ $^ |
|
||||
|
|
||||
clean: |
|
||||
rm -f $(TARGET_EXE) |
|
||||
rm -f $(TARGET_MODULE) |
|
||||
rm -f $(OBJS) |
|
@ -1,16 +0,0 @@ |
|||||
#include "synth_shed.h" |
|
||||
#include <stdio.h> |
|
||||
|
|
||||
|
|
||||
|
|
||||
int main() { |
|
||||
init_synth_shed(); |
|
||||
|
|
||||
synth_t* my_synth = synth_create("UltraBoog"); |
|
||||
printf("%s", play_synth(my_synth)); |
|
||||
|
|
||||
synth_set_osc_count(my_synth, 33); |
|
||||
printf("%s", play_synth(my_synth)); |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
@ -1,14 +0,0 @@ |
|||||
#include <string> |
|
||||
#include <iostream> |
|
||||
#include <pybind11/pybind11.h> |
|
||||
#include <pybind11/detail/common.h> |
|
||||
#include "synth_shed.h" |
|
||||
|
|
||||
using namespace std; |
|
||||
|
|
||||
PYBIND11_MODULE(synth_shed, m) { |
|
||||
#include "../../examples/synth_shed/py_module.cc" |
|
||||
|
|
||||
|
|
||||
} |
|
||||
|
|
@ -1,86 +0,0 @@ |
|||||
#include "synth_shed.h" |
|
||||
#include <stdio.h> |
|
||||
#include <stdlib.h> |
|
||||
#include <assert.h> |
|
||||
#include <string.h> |
|
||||
|
|
||||
void init_synth_shed() { |
|
||||
printf("init_synth_shed() - called\n"); |
|
||||
} |
|
||||
|
|
||||
synth_t* synth_create(const char* name) { |
|
||||
synth_t* new = (synth_t*) malloc(sizeof(synth_t)); |
|
||||
assert(new); |
|
||||
if (new != NULL) { |
|
||||
new->model_name = name; |
|
||||
new->osc_count = 1; |
|
||||
new->technolgy = ANALOG; |
|
||||
new->filter.technology = ANALOG; |
|
||||
new->filter.type = LPF; |
|
||||
} |
|
||||
return new; |
|
||||
} |
|
||||
|
|
||||
SYNTH_STATUS synth_set_osc_count(synth_t* synth, int osc_count) { |
|
||||
assert(synth); |
|
||||
SYNTH_STATUS status = 0; |
|
||||
if (osc_count < 0) { |
|
||||
status = 1; |
|
||||
} else { |
|
||||
synth->osc_count = osc_count; |
|
||||
} |
|
||||
return status; |
|
||||
} |
|
||||
|
|
||||
|
|
||||
//SYNTH_STATUS synth_set_filter(synth_t* synth,
|
|
||||
// filter_t* filt);
|
|
||||
//
|
|
||||
//SYNTH_STATUS synth_set_tech(synth_t* synth,
|
|
||||
// tech_t tech);
|
|
||||
|
|
||||
const char* tech_to_string(const tech_t* const tech) { |
|
||||
assert(tech); |
|
||||
const char* ret = "unknown tech"; |
|
||||
if (*tech == ANALOG) { |
|
||||
return "ANALOG"; |
|
||||
} |
|
||||
if (*tech == DIGITAL) { |
|
||||
return "DIGITAL"; |
|
||||
} |
|
||||
return ret; |
|
||||
} |
|
||||
|
|
||||
|
|
||||
const char* filtertype_to_string(const filtertype_t* const filt) { |
|
||||
assert(filt); |
|
||||
const char* ret = "unknown filtertype"; |
|
||||
if (*filt == LPF) { |
|
||||
ret = "LPF"; |
|
||||
} |
|
||||
if (*filt == HPF) { |
|
||||
ret = "HPF"; |
|
||||
} |
|
||||
if (*filt == BPF) { |
|
||||
ret = "BPF"; |
|
||||
} |
|
||||
return ret; |
|
||||
} |
|
||||
|
|
||||
|
|
||||
const char* play_synth(synth_t* synth) { |
|
||||
assert(synth); |
|
||||
char ret[9999]; |
|
||||
const char* greet = "Playing synth:"; |
|
||||
const char* model = synth->model_name; |
|
||||
|
|
||||
char osc[4]; |
|
||||
sprintf(osc, "%i", synth->osc_count); |
|
||||
|
|
||||
const char* tech = tech_to_string(&synth->technolgy); |
|
||||
const char* filt_tech = tech_to_string(&synth->filter.technology); |
|
||||
const char* filt_type = filtertype_to_string(&synth->filter.type); |
|
||||
|
|
||||
sprintf(ret, "%s\nnamed: %s\nosc: %s\ntech:%s\nfilt:%s / %s\n\n", greet, model, osc, tech, filt_tech, filt_type); |
|
||||
return strdup(ret); |
|
||||
} |
|
@ -1,65 +0,0 @@ |
|||||
#ifndef SYNTH_SHED_H |
|
||||
#define SYNTH_SHED_H |
|
||||
|
|
||||
#ifdef __cplusplus |
|
||||
extern "C" { |
|
||||
#endif |
|
||||
|
|
||||
|
|
||||
// Types (as forward declarations)
|
|
||||
// != 0 means ERR
|
|
||||
typedef int SYNTH_STATUS; |
|
||||
typedef struct _synth synth_t; |
|
||||
typedef synth_t synth; |
|
||||
|
|
||||
// Enums
|
|
||||
typedef enum _filtertype { |
|
||||
HPF, |
|
||||
LPF, |
|
||||
BPF |
|
||||
} filtertype_t; |
|
||||
|
|
||||
typedef enum _tech { |
|
||||
ANALOG, |
|
||||
DIGITAL |
|
||||
} tech_t; |
|
||||
|
|
||||
// Structs
|
|
||||
typedef struct _filter { |
|
||||
tech_t technology; |
|
||||
filtertype_t type; |
|
||||
} filter_t; |
|
||||
|
|
||||
struct _synth { |
|
||||
const char* model_name; |
|
||||
int osc_count; |
|
||||
tech_t technolgy; |
|
||||
filter_t filter; |
|
||||
}; |
|
||||
|
|
||||
|
|
||||
// Functions
|
|
||||
void init_synth_shed(); |
|
||||
|
|
||||
synth_t* synth_create(const char* name); |
|
||||
|
|
||||
SYNTH_STATUS synth_set_osc_count(synth_t* synth, int osc_count); |
|
||||
|
|
||||
//SYNTH_STATUS synth_set_filter(synth_t* synth,
|
|
||||
// filter_t* filt);
|
|
||||
//
|
|
||||
//SYNTH_STATUS synth_set_tech(synth_t* synth,
|
|
||||
// tech_t tech);
|
|
||||
|
|
||||
const char* tech_to_string(const tech_t* tech); |
|
||||
|
|
||||
const char* filtertype_to_string(const filtertype_t* filt); |
|
||||
|
|
||||
|
|
||||
const char* play_synth(synth_t* synth); |
|
||||
|
|
||||
#ifdef __cplusplus |
|
||||
} // extern "C"
|
|
||||
#endif |
|
||||
|
|
||||
#endif //SYNTH_SHED_H
|
|
@ -1,25 +0,0 @@ |
|||||
TARGET=test_lib |
|
||||
|
|
||||
SRCS+=$(wildcard *.c) |
|
||||
CFLAGS+=-std=c99 -g |
|
||||
INCLUDES+= |
|
||||
LIB_DIRS+= |
|
||||
LIBS+= |
|
||||
LDFLAGS+= |
|
||||
|
|
||||
|
|
||||
CXXFLAGS+=$(INCLUDES) |
|
||||
LDFLAGS+=$(LIB_DIRS+) |
|
||||
LDFLAGS+=$(LIBS) |
|
||||
OBJS+=$(SRCS:.c=.o) |
|
||||
|
|
||||
.PHONY: all, clean |
|
||||
|
|
||||
all: $(TARGET) |
|
||||
|
|
||||
$(TARGET) : $(OBJS) |
|
||||
$(CC) $(LDFLAGS) -o $@ $^ |
|
||||
|
|
||||
clean: |
|
||||
rm -f $(TARGET) |
|
||||
rm -f $(OBJS) |
|
@ -1,42 +0,0 @@ |
|||||
#ifndef ENUMS_H |
|
||||
#define ENUMS_H |
|
||||
|
|
||||
// Enums
|
|
||||
// =====
|
|
||||
// Enums only have the item qualifier I and A,
|
|
||||
// so their combinations are simple.
|
|
||||
//
|
|
||||
// Covered combinations
|
|
||||
// ====================
|
|
||||
// _IE = incomplete enum without an alias
|
|
||||
// IE = incomplete enum
|
|
||||
// AIE = alias of an incomplete enum
|
|
||||
// _E = enum without an alias
|
|
||||
// E = enum
|
|
||||
// AE = alias of an enum
|
|
||||
|
|
||||
|
|
||||
// _IE = incomplete enum without anb alias
|
|
||||
enum _IE; |
|
||||
|
|
||||
// IE = incomplete enum
|
|
||||
// AIE = alias of an incomplete enum
|
|
||||
typedef enum IE AIE; |
|
||||
|
|
||||
// _E = enum without an alias
|
|
||||
enum _E { |
|
||||
_E1, |
|
||||
_E2, |
|
||||
_E3 |
|
||||
}; |
|
||||
|
|
||||
// E = enum
|
|
||||
// AE = alias of an enum
|
|
||||
typedef enum E { |
|
||||
E1, |
|
||||
E3, |
|
||||
E2, |
|
||||
} AE; |
|
||||
|
|
||||
|
|
||||
#endif //ENUMS_H
|
|
@ -1,39 +0,0 @@ |
|||||
#ifndef FUNCTIONS_H |
|
||||
#define FUNCTIONS_H |
|
||||
|
|
||||
#include "typedefs.h" |
|
||||
#include "enums.h" |
|
||||
#include "structs.h" |
|
||||
#include "vars.h" |
|
||||
|
|
||||
|
|
||||
void func_void_void(); |
|
||||
|
|
||||
int func_int_void(); |
|
||||
|
|
||||
void func_void_int(int); |
|
||||
|
|
||||
int func_int_int(int); |
|
||||
|
|
||||
// struct
|
|
||||
struct _PS func__PS_V(); |
|
||||
|
|
||||
// enum
|
|
||||
enum _E func__E_V(); |
|
||||
|
|
||||
// typedef
|
|
||||
T_P func_TP_V(); |
|
||||
void func_V_TP(T_P); |
|
||||
T_P func_TP_TP(T_P); |
|
||||
|
|
||||
APS func_APS_V(); |
|
||||
void func_V_APS(APS); |
|
||||
APS func_APS_APS(APS); |
|
||||
|
|
||||
TPS func_TPS_V(); |
|
||||
void func_V_TPS(TPS); |
|
||||
TPS func_TPS_TPS(TPS); |
|
||||
|
|
||||
|
|
||||
|
|
||||
#endif //FUNCTIONS_H
|
|
@ -1,13 +0,0 @@ |
|||||
#include "test_lib.h" |
|
||||
#include <stdio.h> |
|
||||
|
|
||||
|
|
||||
int main() { |
|
||||
printf("test_lib starting...\n"); |
|
||||
|
|
||||
|
|
||||
TT_HHS a; |
|
||||
|
|
||||
TT_CCS b; |
|
||||
// printf("%i, %i\n", a.x, a.y);
|
|
||||
} |
|
@ -1,183 +0,0 @@ |
|||||
#ifndef STRUCTS_H |
|
||||
#define STRUCTS_H |
|
||||
|
|
||||
// Structs
|
|
||||
// =======
|
|
||||
// For structs, a combination is needed to define the type of struct
|
|
||||
// IS = Struct (Empty or incomplete, neither primitive nor complex)
|
|
||||
// PS = Primitive struct (struct containing only primitive types)
|
|
||||
// CS = Complex struct (struct containing other structs and primitive)
|
|
||||
// NPS = Nested primitive struct
|
|
||||
|
|
||||
|
|
||||
// Covered combinations
|
|
||||
// ====================
|
|
||||
// _IS = incomplete struct without a typedef (forward decl)
|
|
||||
// IS = incomplete struct
|
|
||||
// AIS = alias of an incomplete struct
|
|
||||
|
|
||||
// (aliased) struct [ primitive | complex ]
|
|
||||
// ----------------------------------------
|
|
||||
// _PS = primitive struct without a an alias
|
|
||||
// PS = primitive struct
|
|
||||
// APS = Alias of primitive struct
|
|
||||
// _CS = complex struct without a an alias
|
|
||||
// CS = complex struct
|
|
||||
// ACS = alias of a complex struct
|
|
||||
// _CCS = complex complex struct without an alias
|
|
||||
// CCS = complex complex struct
|
|
||||
// ACCS = alias of a complex complex struct
|
|
||||
//
|
|
||||
// Nested structs
|
|
||||
// --------------
|
|
||||
// there is always a hosting struct and a nesting struct
|
|
||||
// in case of double nesting it can be both
|
|
||||
//
|
|
||||
// simply nested struct [ primitive | complex ]
|
|
||||
// --------------------------------------------
|
|
||||
// (aliased) hosting struct (complex always)
|
|
||||
// _HS = hosting struct without an alias
|
|
||||
// HS = hosting struct
|
|
||||
// AHS = alias of a hosting struct
|
|
||||
// _NPS = nested primitive struct without an alias
|
|
||||
// _NCS = nested complex struct without an alias
|
|
||||
//
|
|
||||
// doubly nested struct (complex always)
|
|
||||
// -------------------------------------
|
|
||||
// _HHS = hosting hosting struct without an alias
|
|
||||
// HHS = hosting hosting struct
|
|
||||
// AHHS = alias of a hosting hosting struct
|
|
||||
// _NHS = nested hosting struct
|
|
||||
// _NNPS = nested nested struct
|
|
||||
// _NNCS = nested nested complex struct
|
|
||||
//
|
|
||||
// enums in structs
|
|
||||
// _NEHS = nested enum in hosting struct
|
|
||||
// _NENHS = nested enum in nested hosting struct
|
|
||||
|
|
||||
|
|
||||
// _IS = incomplete struct without a typedef (forward decl)
|
|
||||
struct _IS; |
|
||||
|
|
||||
// IS = incomplete struct
|
|
||||
// AIS = alias of an incomplete struct
|
|
||||
typedef struct IS AIS; |
|
||||
|
|
||||
//
|
|
||||
// (aliased) struct [ primitive | complex ]
|
|
||||
// ----------------------------------------
|
|
||||
// _PS = primitive struct without a an alias
|
|
||||
|
|
||||
struct _PS { |
|
||||
int x, y; |
|
||||
}; |
|
||||
|
|
||||
// PS = primitive struct
|
|
||||
// APS = Alias of primitive struct
|
|
||||
typedef struct PS { |
|
||||
int x, y; |
|
||||
} APS; |
|
||||
|
|
||||
// _CS = complex struct without a an alias
|
|
||||
struct _CS { |
|
||||
struct _PS x; |
|
||||
APS y; |
|
||||
}; |
|
||||
|
|
||||
// CS = complex struct
|
|
||||
// ACS = alias of a complex struct
|
|
||||
typedef struct CS { |
|
||||
APS y; |
|
||||
struct _PS x; |
|
||||
} ACS; |
|
||||
|
|
||||
// _CCS = complex complex struct without an alias
|
|
||||
struct _CCS { |
|
||||
ACS x; |
|
||||
}; |
|
||||
|
|
||||
// CCS = complex complex struct
|
|
||||
// ACCS = alias of a complex complex struct
|
|
||||
typedef struct CCS { |
|
||||
ACS x; |
|
||||
} ACCS; |
|
||||
|
|
||||
// Nested structs
|
|
||||
// --------------
|
|
||||
// there is always a hosting struct and a nesting struct
|
|
||||
// in case of double nesting it can be both
|
|
||||
//
|
|
||||
// simply nested struct [ primitive | complex ]
|
|
||||
// --------------------------------------------
|
|
||||
|
|
||||
// _HS = hosting struct without an alias
|
|
||||
// _NCS = nested complex struct without an alias
|
|
||||
struct _HS { |
|
||||
int x, y; |
|
||||
struct _NCS { |
|
||||
ACS x; |
|
||||
} _ncs; |
|
||||
}; |
|
||||
|
|
||||
// (aliased) hosting struct (complex always)
|
|
||||
// HS = hosting struct
|
|
||||
// AHS = alias of a hosting struct
|
|
||||
// _NPS = nested primitive struct (never has alias)
|
|
||||
typedef struct HS { |
|
||||
struct _NPS { |
|
||||
int x, y; |
|
||||
} _nps; |
|
||||
int x, y; |
|
||||
} AHS; |
|
||||
|
|
||||
|
|
||||
// doubly nested struct (complex always)
|
|
||||
// -------------------------------------
|
|
||||
// (And enums in struct)
|
|
||||
//
|
|
||||
// _HHS = hosting hosting struct without an alias
|
|
||||
// _NHS = nested hosting struct
|
|
||||
// _NNPS = nested nested primitve struct
|
|
||||
struct _HHS { |
|
||||
int x, y; |
|
||||
struct _NHS { |
|
||||
int x, y; |
|
||||
struct _NNPS { |
|
||||
int x,y; |
|
||||
} _nnps; |
|
||||
} _nhs; |
|
||||
}; |
|
||||
|
|
||||
// HHS = hosting hosting struct
|
|
||||
// AHHS = alias of a hosting hosting struct
|
|
||||
// _NNCS = nested nested complex struct
|
|
||||
// _NENHS = nested enum in nested hosting struct
|
|
||||
typedef struct HHS { |
|
||||
int x, y; |
|
||||
struct _NHS1 { |
|
||||
int x, y; |
|
||||
struct _NNCS { |
|
||||
struct _CS a; |
|
||||
} _nncs; |
|
||||
enum _NENHS { |
|
||||
_NENHS1, |
|
||||
_NENHS2, |
|
||||
_NENHS3 |
|
||||
} _nenhs; |
|
||||
} _nhs1; |
|
||||
} AHHS; |
|
||||
|
|
||||
|
|
||||
// _NEHS = nested enum in hosting struct
|
|
||||
struct _HS1 { |
|
||||
int x, y; |
|
||||
enum _NEHS { |
|
||||
_NEHS1, |
|
||||
_NEHS2, |
|
||||
_NEHS3 |
|
||||
} _nehs; |
|
||||
}; |
|
||||
|
|
||||
|
|
||||
#endif //STRUCTS_H
|
|
||||
|
|
@ -1,9 +0,0 @@ |
|||||
#include "test_lib.h" |
|
||||
|
|
||||
struct _PS func__PS_V() { |
|
||||
return var__PS; |
|
||||
} |
|
||||
|
|
||||
TT_NNPS func_TT_NNPS_V() { |
|
||||
return var_TT_NNPS; |
|
||||
} |
|
@ -1,110 +0,0 @@ |
|||||
#ifndef MAIN_INCLUDE_H |
|
||||
#define MAIN_INCLUDE_H |
|
||||
|
|
||||
#include "typedefs.h" |
|
||||
#include "enums.h" |
|
||||
#include "structs.h" |
|
||||
#include "functions.h" |
|
||||
#include "vars.h" |
|
||||
|
|
||||
// Gen-CID
|
|
||||
// =======
|
|
||||
// Gen-CID generates a C Interface Defintion file (json) given the inputs:
|
|
||||
// * headerfile
|
|
||||
// * list of function names needed
|
|
||||
// * list of var names needed
|
|
||||
// The generator searches each function/var in the headerfile (recursively) and collects all the
|
|
||||
// types needed (var type, return type, parm types).
|
|
||||
// As structs can contain further types, these dependent types need to be collected
|
|
||||
// recursively.
|
|
||||
// Finally, all the collected types will be resolved to their final underlying type.
|
|
||||
// If a type is primitive, nothing needs to be done, cause its already defined.
|
|
||||
// But types of typekind struct or enum need to be defined.
|
|
||||
// Their definition will be searched for in the headerfile and included in the interface definition
|
|
||||
// The CID file contains all the information needed to represent:
|
|
||||
// * functions
|
|
||||
// * vars
|
|
||||
// * structs
|
|
||||
// * enums
|
|
||||
// Well enough so they can be expressed in pyBind11
|
|
||||
// use "pyBind11-CID" to generate the pyBind11 code out of the CID file.
|
|
||||
//
|
|
||||
// Gen-CID test library
|
|
||||
// --------------------
|
|
||||
// This here is the test main test library for Gen-CID.
|
|
||||
// The C language is broken down into its components and common pattern.
|
|
||||
// It is a humble attempt to cover all possible combinations that can be created in the
|
|
||||
// C language. (like, struct containing` primitive, struct containing struct, typedef chains,
|
|
||||
// etc..).
|
|
||||
// Please note, that pointer types have not been addressed yet (at all)
|
|
||||
//
|
|
||||
// The intended use of this test lib is: If you encounter a scenario using Gen-CID that poses problem
|
|
||||
// it is most likely that the scenario can be reproduced using this test lib pretty easily.
|
|
||||
// lets say you Gen-CID a function with sig:
|
|
||||
// TT_E(*)(ACCS), where:
|
|
||||
// TT_E = typedef of typedef of an enum without an alias.
|
|
||||
// ACCS = Alias to a complex struct containing another complex struct
|
|
||||
// these types exist already along with a systematic permutation of possible types that amount
|
|
||||
// to over 100 of types.
|
|
||||
// just write your func/var using these types and debug the generation.
|
|
||||
|
|
||||
|
|
||||
// The CID format deals with items. Everything is an item.
|
|
||||
// There are qualifiers that can be used and combined to define an item. (list below)
|
|
||||
// e.g PS = primitive struct that possibly has a typedef
|
|
||||
//
|
|
||||
// Of all the possible combinations, not all are valid (C lang). Its a futile attempt
|
|
||||
// trying to cover all the valid ones. But an effort has been made to cover the most
|
|
||||
// of the valid combinations.
|
|
||||
// Combination of structs, enums and typedefs are systematically explored in the files:
|
|
||||
// * structs.h
|
|
||||
// * enums.h
|
|
||||
// * typedefs.h
|
|
||||
//
|
|
||||
// For all the types defined the file:
|
|
||||
// * vars.h
|
|
||||
// contains an instance of each.
|
|
||||
//
|
|
||||
// for all the possible function signature, well with a 100 types,
|
|
||||
// we can create 10000 different sigantures using 1 ret and 1 arg.
|
|
||||
// Therefore, no functions have been defined.
|
|
||||
// define them when you are interested in the combination, and Gen-CID the defintion.
|
|
||||
|
|
||||
|
|
||||
// Item Qualitfier
|
|
||||
// ===============
|
|
||||
// V = Void already defined
|
|
||||
// P = Primitive Type already defined
|
|
||||
// S = Struct -> struct.h
|
|
||||
// E = Enum -> enums.h
|
|
||||
// A = Alias -> structs.h/enums.h
|
|
||||
// N = Nested (Structs only, cant be aliased) -> structs.h
|
|
||||
// H = Hosting (Structs only -> structs.h
|
|
||||
// containing the nested struct, cant be primitive)
|
|
||||
// T = typedef -> typedefs.h
|
|
||||
// I = Incomplete / (forward decl) -> struct.h/enums.h
|
|
||||
//
|
|
||||
// func_ = function -> functions.h
|
|
||||
// var_ = variable -> vars.h
|
|
||||
//
|
|
||||
// prefixed underline (e.g _E) means no typedef/alias exists for this item (enum in this case)
|
|
||||
//
|
|
||||
// Alias vs. Typedef
|
|
||||
// -----------------
|
|
||||
// aliased means direct typedef directly, like
|
|
||||
// structs and enums only
|
|
||||
/*
|
|
||||
* typedef struct _X { |
|
||||
int x; |
|
||||
* } X; |
|
||||
* |
|
||||
*/ |
|
||||
|
|
||||
// Typedef means, not typdeffed directly, but anywhere, like
|
|
||||
/*
|
|
||||
* typedef _X X; |
|
||||
* |
|
||||
*/ |
|
||||
|
|
||||
|
|
||||
#endif //MAIN_INCLUDE_H
|
|
@ -1,133 +0,0 @@ |
|||||
#ifndef TYPEDEFS_H |
|
||||
#define TYPEDEFS_H |
|
||||
|
|
||||
#include "structs.h" |
|
||||
#include "enums.h" |
|
||||
|
|
||||
// Typedefs
|
|
||||
// ========
|
|
||||
// Typedefs are simply applied to all defined enums and structs, and the
|
|
||||
// their respecitve "alias".
|
|
||||
// Then a typedef os applied to every typedef (TT*)
|
|
||||
|
|
||||
typedef void T_V; |
|
||||
typedef int T_P; |
|
||||
|
|
||||
// typedef struct
|
|
||||
// --------------
|
|
||||
// T_IS = typedef of an incomplete struct without a typedef (forward decl)
|
|
||||
typedef struct _IS T_IS; |
|
||||
// TIS = typedef of an incomplete struct
|
|
||||
typedef struct IS TIS; |
|
||||
// TAIS = typedef of an alias of an incomplete struct
|
|
||||
typedef AIS TAIS; |
|
||||
// T_PS = typedef of a primitive struct without a an alias
|
|
||||
typedef struct _PS T_PS; |
|
||||
// TPS = typedef of a primitive struct
|
|
||||
typedef struct PS TPS; |
|
||||
// TAPS = typedef of an Alias of primitive struct
|
|
||||
typedef APS TAPS; |
|
||||
// _CS = complex struct without a an alias
|
|
||||
typedef struct _CS T_CS; |
|
||||
// CS = complex struct
|
|
||||
typedef struct CS TCS; |
|
||||
// ACS = alias of a complex struct
|
|
||||
typedef ACS TACS; |
|
||||
// _CCS = complex complex struct without an alias
|
|
||||
typedef struct _CCS T_CCS; |
|
||||
// CCS = complex complex struct
|
|
||||
typedef struct CCS TCCS; |
|
||||
// ACCS = alias of a complex complex struct
|
|
||||
typedef ACCS TACCS; |
|
||||
|
|
||||
// _HS = hosting struct without an alias
|
|
||||
typedef struct _HS T_HS; |
|
||||
// _NCS = nested primitive struct without an alias
|
|
||||
typedef struct _NCS T_NCS; |
|
||||
// HS = hosting struct
|
|
||||
typedef struct HS THS; |
|
||||
// _NPS = nested primitive struct (never has alias)
|
|
||||
typedef struct _NPS T_NPS; |
|
||||
// AHS = alias of a hosting struct
|
|
||||
typedef AHS TAHS; |
|
||||
|
|
||||
|
|
||||
// _HHS = hosting hosting struct without an alias
|
|
||||
typedef struct _HHS T_HHS; |
|
||||
// _NHS = nested hosting struct
|
|
||||
typedef struct _NHS T_NHS; |
|
||||
// _NNPS = nested nested primitve struct
|
|
||||
typedef struct _NNPS T_NNPS; |
|
||||
|
|
||||
// HHS = hosting hosting struct
|
|
||||
typedef struct HHS THHS; |
|
||||
// AHHS = alias of a hosting hosting struct
|
|
||||
typedef AHHS TAHHS; |
|
||||
// _NNCS = nested nested complex struct
|
|
||||
typedef struct _NNCS T_NNCS; |
|
||||
// _NENHS = nested enum in nested hosting struct
|
|
||||
typedef enum _NENHS T_NENHS; |
|
||||
// _NHS1 = nested hosting struct
|
|
||||
typedef struct _NHS1 T_NHS1; |
|
||||
|
|
||||
|
|
||||
// _NEHS = nested enum in hosting struct
|
|
||||
typedef struct _HS1 T_HS1; |
|
||||
typedef enum _NEHS T_NEHS; |
|
||||
|
|
||||
|
|
||||
// typedef enum
|
|
||||
// ------------
|
|
||||
// T_IE = typedef of an incomplete enum without an alias
|
|
||||
typedef enum _IE T_IE; |
|
||||
// TIE = typedef of an incomplete enum
|
|
||||
typedef enum IE TIE; |
|
||||
// TAIE = typedef of an alias of an incomplete enum
|
|
||||
typedef AIE TAIE; |
|
||||
// T_E = typedef of an enum without an alias
|
|
||||
typedef enum _E T_E; |
|
||||
// TE = typedef of an enum
|
|
||||
typedef enum E TE; |
|
||||
// TAE = typedef of an alias of an enum
|
|
||||
typedef AE TAE; |
|
||||
|
|
||||
|
|
||||
// TT* = typedef of all typedefs above
|
|
||||
typedef T_V TT_V; |
|
||||
typedef T_P TT_P; |
|
||||
typedef T_IS TT_IS; |
|
||||
typedef TIS TTIS; |
|
||||
typedef TAIS TTAIS; |
|
||||
typedef T_PS TT_PS; |
|
||||
typedef TPS TTPS; |
|
||||
typedef TAPS TTAPS; |
|
||||
typedef T_CS TT_CS; |
|
||||
typedef TCS TTCS; |
|
||||
typedef TACS TTACS; |
|
||||
typedef T_CCS TT_CCS; |
|
||||
typedef TCCS TTCCS; |
|
||||
typedef TACCS TTACCS; |
|
||||
typedef T_HS TT_HS; |
|
||||
typedef T_NCS TT_NCS; |
|
||||
typedef THS TTHS; |
|
||||
typedef T_NPS TT_NPS; |
|
||||
typedef TAHS TTAHS; |
|
||||
typedef T_HHS TT_HHS; |
|
||||
typedef T_NHS TT_NHS; |
|
||||
typedef T_NNPS TT_NNPS; |
|
||||
typedef THHS TTHHS; |
|
||||
typedef TAHHS TTAHHS; |
|
||||
typedef T_NNCS TT_NNCS; |
|
||||
typedef T_NENHS TT_NENHS; |
|
||||
typedef T_NHS1 TT_NHS1; |
|
||||
typedef T_HS1 TT_HS1; |
|
||||
typedef T_NEHS TT_NEHS; |
|
||||
typedef T_IE TT_IE; |
|
||||
typedef TIE TTIE; |
|
||||
typedef TAIE TTAIE; |
|
||||
typedef T_E TT_E; |
|
||||
typedef TE TTE; |
|
||||
typedef TAE TTAE; |
|
||||
|
|
||||
#endif //TYPEDEFS_H
|
|
||||
|
|
@ -1,180 +0,0 @@ |
|||||
#ifndef VARS_H |
|
||||
#define VARS_H |
|
||||
|
|
||||
#include "typedefs.h" |
|
||||
#include "enums.h" |
|
||||
#include "structs.h" |
|
||||
|
|
||||
// Variables
|
|
||||
// =========
|
|
||||
// _V = Void
|
|
||||
//void var__V;
|
|
||||
|
|
||||
// _P
|
|
||||
char var__P; |
|
||||
|
|
||||
// enums
|
|
||||
// =====
|
|
||||
// Incomplete types:
|
|
||||
// enum _IE var__IE;
|
|
||||
// enum IE var_IE;
|
|
||||
// AIE var_AIE;
|
|
||||
|
|
||||
enum _E var__E ; |
|
||||
enum E var_E; |
|
||||
AE var_AE; |
|
||||
|
|
||||
|
|
||||
// structs
|
|
||||
// =======
|
|
||||
|
|
||||
// Incomplete types
|
|
||||
// struct _IS var__IS;
|
|
||||
// struct IS var_IS;
|
|
||||
// AIS var_AIS;
|
|
||||
|
|
||||
// primitive structs
|
|
||||
struct _PS var__PS; |
|
||||
struct PS var_PS; |
|
||||
APS var_APS; |
|
||||
|
|
||||
// complex structs
|
|
||||
struct _CS var__CS; |
|
||||
struct CS var_CS; |
|
||||
ACS var_ACS; |
|
||||
|
|
||||
struct _CCS var__CCS; |
|
||||
struct CCS var_CCS; |
|
||||
ACCS var_ACCS; |
|
||||
|
|
||||
// nested structs / hosting structs
|
|
||||
struct _HS var__HS; |
|
||||
struct _NCS var__NCS; |
|
||||
|
|
||||
struct HS var_HS; |
|
||||
struct _NPS var__NPS; |
|
||||
AHS var_AHS; |
|
||||
|
|
||||
struct _HHS var__HHS; |
|
||||
struct _NHS var__NHS; |
|
||||
struct _NNPS var__NNPS; |
|
||||
|
|
||||
struct HHS var_HHS; |
|
||||
struct _NHS1 var__NHS1; |
|
||||
struct _NNCS var__NNCS; |
|
||||
|
|
||||
//nested enum in hosting struct
|
|
||||
enum _NENHS var__NENHS; |
|
||||
AHHS var_AHHS; |
|
||||
|
|
||||
struct _HS1 var__HS1; |
|
||||
enum _NEHS var__NEHS; |
|
||||
|
|
||||
|
|
||||
// TYPEDEFS
|
|
||||
// ========
|
|
||||
|
|
||||
// Typedefs of primitive
|
|
||||
// ---------------------
|
|
||||
//TV var_TV;
|
|
||||
T_P var_T_P; |
|
||||
|
|
||||
// Typedefs of structs
|
|
||||
// ------------------
|
|
||||
// Incomplete types
|
|
||||
//T_IS var_T_IS;
|
|
||||
//TIS var_TIS;
|
|
||||
//TAIS var_TAIS;
|
|
||||
|
|
||||
// primitive structs
|
|
||||
T_PS var_T_PS; |
|
||||
TPS var_TPS; |
|
||||
TAPS var_TAPS; |
|
||||
|
|
||||
// complex structs
|
|
||||
T_CS var_T_CS; |
|
||||
TCS var_TCS; |
|
||||
TACS var_TACS; |
|
||||
T_CCS var_T_CCS; |
|
||||
TCCS var_TCCS; |
|
||||
TACCS var_TACCS; |
|
||||
|
|
||||
// nested structs / hosting structs
|
|
||||
T_HS var_T_HS; |
|
||||
T_NCS var_T_NCS; |
|
||||
THS var_THS; |
|
||||
T_NPS var_T_NPS; |
|
||||
TAHS var_TAHS; |
|
||||
T_HHS var_T_HHS; |
|
||||
T_NHS var_T_NHS; |
|
||||
T_NNPS var_T_NNPS; |
|
||||
THHS var_THHS; |
|
||||
TAHHS var_TAHHS; |
|
||||
T_NNCS var_T_NNCS; |
|
||||
T_NENHS var_T_NENHS; |
|
||||
T_NHS1 var_T_NHS1; |
|
||||
|
|
||||
//nested enum in hosting struct
|
|
||||
T_HS1 var_T_HS1; |
|
||||
T_NEHS var_T_NEHS; |
|
||||
|
|
||||
// Typedef of enums
|
|
||||
// ----------------
|
|
||||
// Incomplete types
|
|
||||
//T_IE var_TIE;
|
|
||||
//TIE var_TIE;
|
|
||||
//TAIE var_TAIE;
|
|
||||
T_E var_T_E; |
|
||||
TE var_TE; |
|
||||
TAE var_TAE; |
|
||||
|
|
||||
|
|
||||
|
|
||||
// TYPEDEFS OF TYPEDEFS
|
|
||||
// ====================
|
|
||||
|
|
||||
// Typedefs of primitive
|
|
||||
// ---------------------
|
|
||||
TT_P var_TT_P; |
|
||||
|
|
||||
// Typedefs of structs
|
|
||||
// ------------------
|
|
||||
// primitive structs
|
|
||||
TT_PS var_TT_PS; |
|
||||
TTPS var_TTPS; |
|
||||
TTAPS var_TTAPS; |
|
||||
|
|
||||
// complex structs
|
|
||||
TT_CS var_TT_CS; |
|
||||
TTCS var_TTCS; |
|
||||
TTACS var_TTACS; |
|
||||
TT_CCS var_TT_CCS; |
|
||||
TTCCS var_TTCCS; |
|
||||
TTACCS var_TTACCS; |
|
||||
|
|
||||
// nested structs / hosting structs
|
|
||||
TT_HS var_TT_HS; |
|
||||
TT_NCS var_TT_NCS; |
|
||||
TTHS var_TTHS; |
|
||||
TT_NPS var_TT_NPS; |
|
||||
TTAHS var_TTAHS; |
|
||||
TT_HHS var_TT_HHS; |
|
||||
TT_NHS var_TT_NHS; |
|
||||
TT_NNPS var_TT_NNPS; |
|
||||
TTHHS var_TTHHS; |
|
||||
TTAHHS var_TTAHHS; |
|
||||
TT_NNCS var_TT_NNCS; |
|
||||
TT_NENHS var_TT_NENHS; |
|
||||
TT_NHS1 var_TT_NHS1; |
|
||||
|
|
||||
//nested enum in hosting struct
|
|
||||
TT_HS1 var_TT_HS1; |
|
||||
TT_NEHS var_TT_NEHS; |
|
||||
|
|
||||
// Typedef of enums
|
|
||||
// ----------------
|
|
||||
TT_E var_TT_E; |
|
||||
TTE var_TTE; |
|
||||
TTAE var_TTAE; |
|
||||
|
|
||||
#endif // VARS_H
|
|
@ -1,219 +0,0 @@ |
|||||
#!/usr/bin/env python3 |
|
||||
# -*- coding: utf-8 -*- |
|
||||
import pytest |
|
||||
|
|
||||
from gen_cid import utils |
|
||||
import gen_cid |
|
||||
|
|
||||
types_with_alias = [] |
|
||||
types_no_alias = [] |
|
||||
types_no_alias.append({"var": ["_P"], |
|
||||
"type_names": [ |
|
||||
]}) |
|
||||
|
|
||||
types_no_alias.append({"var": ["_E"], |
|
||||
"type_names": [ |
|
||||
"enum _E" |
|
||||
]}) |
|
||||
|
|
||||
types_with_alias.append({"var": ["E"], |
|
||||
"type_names": [ |
|
||||
"enum E" |
|
||||
]}) |
|
||||
|
|
||||
types_no_alias.append({"var": ["_PS"], |
|
||||
"type_names": [ |
|
||||
"struct _PS" |
|
||||
]}) |
|
||||
|
|
||||
types_with_alias.append({"var": ["PS"], |
|
||||
"type_names": [ |
|
||||
"struct PS" |
|
||||
]}) |
|
||||
|
|
||||
types_no_alias.append({"var": ["_CS"], |
|
||||
"type_names": [ |
|
||||
"struct _CS", |
|
||||
"struct PS", |
|
||||
"struct _PS" |
|
||||
]}) |
|
||||
|
|
||||
types_with_alias.append({"var": ["CS"], |
|
||||
"type_names": [ |
|
||||
"struct CS", |
|
||||
"struct _PS", |
|
||||
"struct PS" |
|
||||
]}) |
|
||||
|
|
||||
types_no_alias.append({"var": ["_CCS"], |
|
||||
"type_names": [ |
|
||||
"struct _CCS", |
|
||||
"struct CS", |
|
||||
"struct _PS", |
|
||||
"struct PS" |
|
||||
]}) |
|
||||
|
|
||||
types_with_alias.append({"var": ["CCS"], |
|
||||
"type_names": [ |
|
||||
"struct CCS", |
|
||||
"struct CS", |
|
||||
"struct _PS", |
|
||||
"struct PS" |
|
||||
]}) |
|
||||
|
|
||||
types_no_alias.append({"var": ["_HS"], |
|
||||
"type_names": [ |
|
||||
"struct _HS", |
|
||||
"struct _NCS", |
|
||||
"struct CS", |
|
||||
"struct _PS", |
|
||||
"struct PS" |
|
||||
]}) |
|
||||
|
|
||||
types_with_alias.append({"var": ["HS"], |
|
||||
"type_names": [ |
|
||||
"struct HS", |
|
||||
"struct _NPS" |
|
||||
]}) |
|
||||
|
|
||||
types_no_alias.append({"var": ["_NCS"], |
|
||||
"type_names": [ |
|
||||
"struct _NCS", |
|
||||
"struct CS", |
|
||||
"struct _PS", |
|
||||
"struct PS" |
|
||||
]}) |
|
||||
|
|
||||
types_no_alias.append({"var": ["_NPS"], |
|
||||
"type_names": [ |
|
||||
"struct _NPS" |
|
||||
]}) |
|
||||
|
|
||||
types_no_alias.append({"var": ["_HHS"], |
|
||||
"type_names": [ |
|
||||
"struct _HHS", |
|
||||
"struct _NHS", |
|
||||
"struct _NNPS" |
|
||||
]}) |
|
||||
|
|
||||
types_with_alias.append({"var": ["HHS"], |
|
||||
"type_names": [ |
|
||||
"struct HHS", |
|
||||
"struct _NHS1", |
|
||||
"struct _NNCS", |
|
||||
"struct _CS", |
|
||||
"struct PS", |
|
||||
"struct _PS", |
|
||||
"enum _NENHS" |
|
||||
]}) |
|
||||
|
|
||||
types_no_alias.append({"var": ["_NHS"], |
|
||||
"type_names": [ |
|
||||
"struct _NHS", |
|
||||
"struct _NNPS" |
|
||||
]}) |
|
||||
|
|
||||
types_no_alias.append({"var": ["_NNPS"], |
|
||||
"type_names": [ |
|
||||
"struct _NNPS" |
|
||||
]}) |
|
||||
|
|
||||
types_no_alias.append({"var": ["_NHS1"], |
|
||||
"type_names": [ |
|
||||
"struct _NHS1", |
|
||||
"struct _NNCS", |
|
||||
"struct _CS", |
|
||||
"struct PS", |
|
||||
"struct _PS", |
|
||||
"enum _NENHS" |
|
||||
]}) |
|
||||
|
|
||||
types_no_alias.append({"var": ["_NNCS"], |
|
||||
"type_names": [ |
|
||||
"struct _NNCS", |
|
||||
"struct _CS", |
|
||||
"struct PS", |
|
||||
"struct _PS" |
|
||||
]}) |
|
||||
|
|
||||
types_no_alias.append({"var": ["_NENHS"], |
|
||||
"type_names": [ |
|
||||
"enum _NENHS" |
|
||||
]}) |
|
||||
|
|
||||
types_no_alias.append({"var": ["_HS1"], |
|
||||
"type_names": [ |
|
||||
"struct _HS1", |
|
||||
"enum _NEHS" |
|
||||
]}) |
|
||||
|
|
||||
types_no_alias.append({"var": ["_NEHS"], |
|
||||
"type_names": [ |
|
||||
"enum _NEHS" |
|
||||
]}) |
|
||||
|
|
||||
|
|
||||
def resolve_vars_and_funcs_to_cid(vars, funcs): |
|
||||
header_filename = "src/test_data/test_lib.h" |
|
||||
libclang_path = "/opt/local/libexec/llvm-9.0/lib/libclang.dylib" |
|
||||
cidtools = gen_cid.CIDTools(libclang_path, header_filename, "test_cid") |
|
||||
header = cidtools.extract(vars,funcs) |
|
||||
|
|
||||
return header["cid"] |
|
||||
|
|
||||
|
|
||||
def check_expected_types_resolved(vars, funcs, type_names_expected): |
|
||||
print("RESOLVING: ", vars, funcs) |
|
||||
cid = resolve_vars_and_funcs_to_cid(vars, funcs) |
|
||||
|
|
||||
# Check on unresolved vars |
|
||||
assert len(cid["vars_notfound"]) == 0, "vars not found" |
|
||||
|
|
||||
# Check on unresolved functions |
|
||||
assert len(cid["functions_notfound"]) == 0, "vars not found" |
|
||||
|
|
||||
# Check on unresolved typerefs |
|
||||
assert len(cid["typerefs_notfound"]) == 0, "vars not found" |
|
||||
|
|
||||
type_names = cid["type_names"] |
|
||||
# test for no dup types |
|
||||
for tn in type_names: |
|
||||
assert type_names.count(tn) == 1, "duplicate type" |
|
||||
|
|
||||
type_names.sort() |
|
||||
type_names_expected.sort() |
|
||||
|
|
||||
# test expected types match in no specific order |
|
||||
# print("GOT: ", type_names) |
|
||||
# print("EXPECTED: ", type_names_expected) |
|
||||
assert type_names == type_names_expected |
|
||||
|
|
||||
|
|
||||
@pytest.mark.skip |
|
||||
@pytest.mark.parametrize('vars', [["var_TP"]]) |
|
||||
@pytest.mark.parametrize('funcs', [""]) |
|
||||
def test_manual(vars, funcs): |
|
||||
resolve_vars_and_funcs_to_cid(vars, funcs) |
|
||||
|
|
||||
|
|
||||
# @pytest.mark.skip |
|
||||
@pytest.mark.parametrize('variation', ["var_", "var_A", "var_T", "var_TA", "var_TT", "var_TTA"]) |
|
||||
@pytest.mark.parametrize('data', types_with_alias) |
|
||||
def test_single_var_with_alias(data, variation): |
|
||||
var_list = [] |
|
||||
for var in data["var"]: |
|
||||
var_name = variation + var |
|
||||
var_list.append(var_name) |
|
||||
|
|
||||
check_expected_types_resolved(var_list, [], data["type_names"]) |
|
||||
|
|
||||
|
|
||||
@pytest.mark.parametrize('variation', ["var_", "var_T", "var_TT"]) |
|
||||
@pytest.mark.parametrize('data', types_no_alias) |
|
||||
def test_single_var_no_alias(data, variation): |
|
||||
var_list = [] |
|
||||
for var in data["var"]: |
|
||||
var_name = variation + var |
|
||||
var_list.append(var_name) |
|
||||
|
|
||||
check_expected_types_resolved(var_list, [], data["type_names"]) |
|
Loading…
Reference in new issue