Skip to content

Commit f3602c0

Browse files
committed
WIP #117 Add proto file and cmake integration
1 parent 0e5ac3e commit f3602c0

File tree

2 files changed

+178
-1
lines changed

2 files changed

+178
-1
lines changed

bindgen/CMakeLists.txt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,19 @@ project(scala-native-bindgen)
33

44
option(STATIC_LINKING "Statically link the executable" OFF)
55

6+
if (STATIC_LINKING)
7+
set(Protobuf_USE_STATIC_LIBS ON)
8+
endif()
9+
10+
find_package(Protobuf REQUIRED)
11+
message(STATUS "Found protobuf ${Protobuf_VERSION}")
12+
13+
message(STATUS "Using protobuf include dirs: ${Protobuf_INCLUDE_DIRS}")
14+
include_directories(SYSTEM ${Protobuf_INCLUDE_DIRS})
15+
616
# Locate LLVMConfig.cmake
717
find_package(LLVM REQUIRED CONFIG)
818
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
9-
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
1019

1120
message(STATUS "Using LLVM include dirs: ${LLVM_INCLUDE_DIRS}")
1221
include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})
@@ -19,6 +28,9 @@ link_directories(${LLVM_LIBRARY_DIRS})
1928

2029
add_compile_options(-fexceptions -std=c++11 -Wall -Wconversion -Werror)
2130

31+
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS "${CMAKE_CURRENT_SOURCE_DIR}/../proto/ir.proto")
32+
include_directories(SYSTEM ${CMAKE_CURRENT_BINARY_DIR})
33+
2234
add_executable(bindgen
2335
Main.cpp
2436
visitor/ScalaFrontendAction.h
@@ -74,6 +86,8 @@ add_executable(bindgen
7486
ir/Location.cpp
7587
ir/LocationManager.h
7688
ir/LocationManager.cpp
89+
${PROTO_SRCS}
90+
${PROTO_HDRS}
7791
)
7892

7993
if (STATIC_LINKING)
@@ -113,4 +127,5 @@ target_link_libraries(bindgen
113127
clangLex
114128
clangBasic
115129
${LLVM_LIBS}
130+
${Protobuf_LIBRARIES}
116131
)

proto/ir.proto

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
syntax = "proto3";
2+
3+
package org.scalanative.bindgen;
4+
5+
option optimize_for = LITE_RUNTIME;
6+
7+
message IR {
8+
repeated EnumType enums = 1;
9+
repeated StructType structs = 2;
10+
repeated UnionType unions = 3;
11+
repeated TypedefType typedefs = 4;
12+
repeated Decl.FunctionDecl functions = 5;
13+
repeated Decl.VariableDecl variables = 6;
14+
//std::vector<std::shared_ptr<LiteralDefine>> literalDefines;
15+
//std::vector<std::shared_ptr<PossibleVarDefine>> possibleVarDefines;
16+
//std::vector<std::shared_ptr<VarDefine>> varDefines;
17+
}
18+
19+
message Range {
20+
int32 start_line = 1;
21+
int32 start_character = 2;
22+
int32 end_line = 3;
23+
int32 end_character = 4;
24+
}
25+
26+
message Location {
27+
string uri = 1;
28+
Range range = 2;
29+
}
30+
31+
message Type {
32+
/*
33+
enum Kind {
34+
UNKNOWN = 0;
35+
PRIMITIVE = 1;
36+
ENUM = 2;
37+
POINTER = 3;
38+
ARRAY = 4;
39+
FUNCTION_POINTER = 5;
40+
UNION = 6;
41+
STRUCT = 7;
42+
TYPEDEF = 8;
43+
}
44+
*/
45+
46+
//Kind kind = 1; // FIXME: remove?
47+
Location location = 2;
48+
49+
oneof kind {
50+
PrimitiveType primitiveType = 3;
51+
EnumType enumType = 4;
52+
PointerType pointerType = 5;
53+
ArrayType arrayType = 6;
54+
FunctionPointerType functionPointerType = 7;
55+
UnionType unionType = 8;
56+
StructType structType = 9;
57+
TypedefType typedefType = 10;
58+
}
59+
}
60+
61+
message PrimitiveType {
62+
enum Modifier {
63+
NONE = 0;
64+
CONST = 0x1;
65+
}
66+
67+
string type = 1;
68+
uint64 modifiers = 2;
69+
}
70+
71+
message EnumType {
72+
message Enumerator {
73+
string name = 1;
74+
// Have both int64 and uint64?
75+
int64 value = 2;
76+
}
77+
78+
string name = 1;
79+
repeated Enumerator enumerators = 2;
80+
}
81+
82+
message PointerType {
83+
Type type = 1;
84+
}
85+
86+
message ArrayType {
87+
Type type = 1;
88+
uint64 size = 2;
89+
}
90+
91+
message FunctionPointerType {
92+
// FIXME: Include parameter name in doc string?
93+
Type returnType = 1;
94+
repeated Type parameterTypes = 2;
95+
bool isVariadic = 3;
96+
}
97+
98+
message Field {
99+
string name = 1;
100+
Type type = 2;
101+
}
102+
103+
message UnionType {
104+
string name = 1;
105+
repeated Field fields = 2;
106+
uint64 size = 3;
107+
}
108+
109+
message StructType {
110+
// FIXME: packed attr
111+
string name = 1;
112+
repeated Field fields = 2;
113+
uint64 size = 3;
114+
}
115+
116+
message TypedefType {
117+
string name = 1;
118+
Type type = 2;
119+
}
120+
121+
message Decl {
122+
/*
123+
enum Kind {
124+
UNKNOWN = 0;
125+
FUNCTION = 1;
126+
VARIABLE = 2;
127+
VARIABLE_DEFINE = 3;
128+
LITERAL_DEFINE = 4;
129+
}
130+
*/
131+
132+
//Kind kind = 1;
133+
Location location = 2;
134+
135+
oneof kind {
136+
FunctionDecl functionDecl = 11;
137+
VariableDecl variableDecl = 12;
138+
}
139+
140+
message FunctionDecl {
141+
message Parameter {
142+
string name = 1;
143+
Type type = 2;
144+
}
145+
146+
string name = 1;
147+
Type returnType = 2;
148+
repeated Parameter parameters = 3;
149+
bool isVariadic = 4;
150+
}
151+
152+
message VariableDecl {
153+
enum Modifier {
154+
NONE = 0;
155+
VOLATILE = 1;
156+
}
157+
158+
string name = 1;
159+
Type type = 2;
160+
repeated Modifier modifiers = 3;
161+
}
162+
}

0 commit comments

Comments
 (0)