Skip to content

Commit

Permalink
libclang-c binding added
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane committed Nov 17, 2023
1 parent 3bf7d3f commit 35d3570
Show file tree
Hide file tree
Showing 16 changed files with 1,711 additions and 213 deletions.
2 changes: 1 addition & 1 deletion src/bitwriter.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const LLVMtype = @import("types.zig");

pub extern fn LLVMWriteBitcodeToFile(M: LLVMtype.LLVMModuleRef, Path: [*c]const u8) c_int;
pub extern fn LLVMWriteBitcodeToFile(M: LLVMtype.LLVMModuleRef, Path: [*:0]const u8) c_int;
pub extern fn LLVMWriteBitcodeToFD(M: LLVMtype.LLVMModuleRef, FD: c_int, ShouldClose: c_int, Unbuffered: c_int) c_int;
pub extern fn LLVMWriteBitcodeToFileHandle(M: LLVMtype.LLVMModuleRef, Handle: c_int) c_int;
pub extern fn LLVMWriteBitcodeToMemoryBuffer(M: LLVMtype.LLVMModuleRef) LLVMtype.LLVMMemoryBufferRef;
8 changes: 4 additions & 4 deletions src/blake3.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ pub const llvm_blake3_hasher = extern struct {
cv_stack_len: u8,
cv_stack: [1760]u8,
};
pub extern fn llvm_blake3_version() [*c]const u8;
pub extern fn llvm_blake3_version() [*:0]const u8;
pub extern fn llvm_blake3_hasher_init(self: [*c]llvm_blake3_hasher) void;
pub extern fn llvm_blake3_hasher_init_keyed(self: [*c]llvm_blake3_hasher, key: [*c]const u8) void;
pub extern fn llvm_blake3_hasher_init_derive_key(self: [*c]llvm_blake3_hasher, context: [*c]const u8) void;
pub extern fn llvm_blake3_hasher_init_keyed(self: [*c]llvm_blake3_hasher, key: [*:0]const u8) void;
pub extern fn llvm_blake3_hasher_init_derive_key(self: [*c]llvm_blake3_hasher, context: [*:0]const u8) void;
pub extern fn llvm_blake3_hasher_init_derive_key_raw(self: [*c]llvm_blake3_hasher, context: ?*const anyopaque, context_len: usize) void;
pub extern fn llvm_blake3_hasher_update(self: [*c]llvm_blake3_hasher, input: ?*const anyopaque, input_len: usize) void;
pub extern fn llvm_blake3_hasher_finalize(self: [*c]const llvm_blake3_hasher, out: [*c]u8, out_len: usize) void;
pub extern fn llvm_blake3_hasher_finalize(self: [*c]const llvm_blake3_hasher, out: [*:0]u8, out_len: usize) void;
pub extern fn llvm_blake3_hasher_finalize_seek(self: [*c]const llvm_blake3_hasher, seek: u64, out: [*c]u8, out_len: usize) void;
pub extern fn llvm_blake3_hasher_reset(self: [*c]llvm_blake3_hasher) void;
19 changes: 19 additions & 0 deletions src/clang/BuildSystem.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const CXString = @import("CXString.zig");
const CXErrorCode = @import("CXErrorCode.zig");

pub extern fn clang_getBuildSessionTimestamp() c_ulonglong;
pub const CXVirtualFileOverlayImpl = opaque {};
pub const CXVirtualFileOverlay = ?*CXVirtualFileOverlayImpl;
pub extern fn clang_VirtualFileOverlay_create(options: c_uint) CXVirtualFileOverlay;
pub extern fn clang_VirtualFileOverlay_addFileMapping(CXVirtualFileOverlay, virtualPath: [*:0]const u8, realPath: [*:0]const u8) CXErrorCode.CXErrorCode;
pub extern fn clang_VirtualFileOverlay_setCaseSensitivity(CXVirtualFileOverlay, caseSensitive: c_int) CXErrorCode.CXErrorCode;
pub extern fn clang_VirtualFileOverlay_writeToBuffer(CXVirtualFileOverlay, options: c_uint, out_buffer_ptr: [*c][*c]u8, out_buffer_size: [*c]c_uint) CXErrorCode.CXErrorCode;
pub extern fn clang_free(buffer: ?*anyopaque) void;
pub extern fn clang_VirtualFileOverlay_dispose(CXVirtualFileOverlay) void;
pub const CXModuleMapDescriptorImpl = opaque {};
pub const CXModuleMapDescriptor = ?*CXModuleMapDescriptorImpl;
pub extern fn clang_ModuleMapDescriptor_create(options: c_uint) CXModuleMapDescriptor;
pub extern fn clang_ModuleMapDescriptor_setFrameworkModuleName(CXModuleMapDescriptor, name: [*:0]const u8) CXErrorCode.CXErrorCode;
pub extern fn clang_ModuleMapDescriptor_setUmbrellaHeader(CXModuleMapDescriptor, name: [*:0]const u8) CXErrorCode.CXErrorCode;
pub extern fn clang_ModuleMapDescriptor_writeToBuffer(CXModuleMapDescriptor, options: c_uint, out_buffer_ptr: [*c][*c]u8, out_buffer_size: [*c]c_uint) CXErrorCode.CXErrorCode;
pub extern fn clang_ModuleMapDescriptor_dispose(CXModuleMapDescriptor) void;
23 changes: 23 additions & 0 deletions src/clang/CXCompilationDatabase.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const CXString = @import("CXString.zig");
const std = @import("std");

pub const CXCompilationDatabase = ?*anyopaque;
pub const CXCompileCommands = ?*anyopaque;
pub const CXCompileCommand = ?*anyopaque;
pub const CXCompilationDatabase_NoError: c_int = 0;
pub const CXCompilationDatabase_CanNotLoadDatabase: c_int = 1;
pub const CXCompilationDatabase_Error = c_uint;
pub extern fn clang_CompilationDatabase_fromDirectory(BuildDir: [*:0]const u8, ErrorCode: [*c]CXCompilationDatabase_Error) CXCompilationDatabase;
pub extern fn clang_CompilationDatabase_dispose(CXCompilationDatabase) void;
pub extern fn clang_CompilationDatabase_getCompileCommands(CXCompilationDatabase, CompleteFileName: [*:0]const u8) CXCompileCommands;
pub extern fn clang_CompilationDatabase_getAllCompileCommands(CXCompilationDatabase) CXCompileCommands;
pub extern fn clang_CompileCommands_dispose(CXCompileCommands) void;
pub extern fn clang_CompileCommands_getSize(CXCompileCommands) c_uint;
pub extern fn clang_CompileCommands_getCommand(CXCompileCommands, I: c_uint) CXCompileCommand;
pub extern fn clang_CompileCommand_getDirectory(CXCompileCommand) CXString.CXString;
pub extern fn clang_CompileCommand_getFilename(CXCompileCommand) CXString.CXString;
pub extern fn clang_CompileCommand_getNumArgs(CXCompileCommand) c_uint;
pub extern fn clang_CompileCommand_getArg(CXCompileCommand, I: c_uint) CXString.CXString;
pub extern fn clang_CompileCommand_getNumMappedSources(CXCompileCommand) c_uint;
pub extern fn clang_CompileCommand_getMappedSourcePath(CXCompileCommand, I: c_uint) CXString.CXString;
pub extern fn clang_CompileCommand_getMappedSourceContent(CXCompileCommand, I: c_uint) CXString.CXString;
43 changes: 43 additions & 0 deletions src/clang/CXDiagnostic.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const std = @import("std");
const CXString = @import("CXString.zig");
const CXSourceLocation = @import("CXSourceLocation.zig");

pub const CXDiagnostic_Ignored: c_int = 0;
pub const CXDiagnostic_Note: c_int = 1;
pub const CXDiagnostic_Warning: c_int = 2;
pub const CXDiagnostic_Error: c_int = 3;
pub const CXDiagnostic_Fatal: c_int = 4;
pub const CXDiagnosticSeverity = c_uint;
pub const CXDiagnostic = ?*anyopaque;
pub const CXDiagnosticSet = ?*anyopaque;
pub extern fn clang_getNumDiagnosticsInSet(Diags: CXDiagnosticSet) c_uint;
pub extern fn clang_getDiagnosticInSet(Diags: CXDiagnosticSet, Index: c_uint) CXDiagnostic;
pub const CXLoadDiag_None: c_int = 0;
pub const CXLoadDiag_Unknown: c_int = 1;
pub const CXLoadDiag_CannotLoad: c_int = 2;
pub const CXLoadDiag_InvalidFile: c_int = 3;
pub const CXLoadDiag_Error = c_uint;
pub extern fn clang_loadDiagnostics(file: [*:0]const u8, @"error": [*c]CXLoadDiag_Error, errorString: [*c]CXString.CXString) CXDiagnosticSet;
pub extern fn clang_disposeDiagnosticSet(Diags: CXDiagnosticSet) void;
pub extern fn clang_getChildDiagnostics(D: CXDiagnostic) CXDiagnosticSet;
pub extern fn clang_disposeDiagnostic(Diagnostic: CXDiagnostic) void;
pub const CXDiagnostic_DisplaySourceLocation: c_int = 1;
pub const CXDiagnostic_DisplayColumn: c_int = 2;
pub const CXDiagnostic_DisplaySourceRanges: c_int = 4;
pub const CXDiagnostic_DisplayOption: c_int = 8;
pub const CXDiagnostic_DisplayCategoryId: c_int = 16;
pub const CXDiagnostic_DisplayCategoryName: c_int = 32;
pub const CXDiagnosticDisplayOptions = c_uint;
pub extern fn clang_formatDiagnostic(Diagnostic: CXDiagnostic, Options: c_uint) CXString.CXString;
pub extern fn clang_defaultDiagnosticDisplayOptions() c_uint;
pub extern fn clang_getDiagnosticSeverity(CXDiagnostic) CXDiagnosticSeverity;
pub extern fn clang_getDiagnosticLocation(CXDiagnostic) CXSourceLocation.CXSourceLocation;
pub extern fn clang_getDiagnosticSpelling(CXDiagnostic) CXString.CXString;
pub extern fn clang_getDiagnosticOption(Diag: CXDiagnostic, Disable: [*c]CXString.CXString) CXString.CXString;
pub extern fn clang_getDiagnosticCategory(CXDiagnostic) c_uint;
pub extern fn clang_getDiagnosticCategoryName(Category: c_uint) CXString.CXString;
pub extern fn clang_getDiagnosticCategoryText(CXDiagnostic) CXString.CXString;
pub extern fn clang_getDiagnosticNumRanges(CXDiagnostic) c_uint;
pub extern fn clang_getDiagnosticRange(Diagnostic: CXDiagnostic, Range: c_uint) CXSourceLocation.CXSourceRange;
pub extern fn clang_getDiagnosticNumFixIts(Diagnostic: CXDiagnostic) c_uint;
pub extern fn clang_getDiagnosticFixIt(Diagnostic: CXDiagnostic, FixIt: c_uint, ReplacementRange: [*c]CXSourceLocation.CXSourceRange) CXString.CXString;
7 changes: 7 additions & 0 deletions src/clang/CXErrorCode.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub const CXErrorCode = enum(c_uint) {
CXError_Success = 0,
CXError_Failure = 1,
CXError_Crashed = 2,
CXError_InvalidArguments = 3,
CXError_ASTReadError = 4,
};
12 changes: 12 additions & 0 deletions src/clang/CXFile.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const CXString = @import("CXString.zig");
const std = @import("std");

pub const CXFile = ?*anyopaque;
pub extern fn clang_getFileName(SFile: CXFile) CXString.CXString;
pub extern fn clang_getFileTime(SFile: CXFile) std.os.linux.time_t;
pub const CXFileUniqueID = extern struct {
data: [3]c_ulonglong = std.mem.zeroes([3]c_ulonglong),
};
pub extern fn clang_getFileUniqueID(file: CXFile, outID: [*c]CXFileUniqueID) c_int;
pub extern fn clang_File_isEqual(file1: CXFile, file2: CXFile) c_int;
pub extern fn clang_File_tryGetRealPathName(file: CXFile) CXString.CXString;
33 changes: 33 additions & 0 deletions src/clang/CXSourceLocation.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const CXString = @import("CXString.zig");
const CXFile = @import("CXFile.zig");
const std = @import("std");

pub const CXSourceLocation = extern struct {
ptr_data: [2]?*const anyopaque = std.mem.zeroes([2]?*const anyopaque),
int_data: c_uint = std.mem.zeroes(c_uint),
};
pub const CXSourceRange = extern struct {
ptr_data: [2]?*const anyopaque = std.mem.zeroes([2]?*const anyopaque),
begin_int_data: c_uint = std.mem.zeroes(c_uint),
end_int_data: c_uint = std.mem.zeroes(c_uint),
};
pub extern fn clang_getNullLocation() CXSourceLocation;
pub extern fn clang_equalLocations(loc1: CXSourceLocation, loc2: CXSourceLocation) c_uint;
pub extern fn clang_Location_isInSystemHeader(location: CXSourceLocation) c_int;
pub extern fn clang_Location_isFromMainFile(location: CXSourceLocation) c_int;
pub extern fn clang_getNullRange() CXSourceRange;
pub extern fn clang_getRange(begin: CXSourceLocation, end: CXSourceLocation) CXSourceRange;
pub extern fn clang_equalRanges(range1: CXSourceRange, range2: CXSourceRange) c_uint;
pub extern fn clang_Range_isNull(range: CXSourceRange) c_int;
pub extern fn clang_getExpansionLocation(location: CXSourceLocation, file: [*c]CXFile.CXFile, line: [*c]c_uint, column: [*c]c_uint, offset: [*c]c_uint) void;
pub extern fn clang_getPresumedLocation(location: CXSourceLocation, filename: [*c]CXString.CXString, line: [*c]c_uint, column: [*c]c_uint) void;
pub extern fn clang_getInstantiationLocation(location: CXSourceLocation, file: [*c]CXFile.CXFile, line: [*c]c_uint, column: [*c]c_uint, offset: [*c]c_uint) void;
pub extern fn clang_getSpellingLocation(location: CXSourceLocation, file: [*c]CXFile.CXFile, line: [*c]c_uint, column: [*c]c_uint, offset: [*c]c_uint) void;
pub extern fn clang_getFileLocation(location: CXSourceLocation, file: [*c]CXFile.CXFile, line: [*c]c_uint, column: [*c]c_uint, offset: [*c]c_uint) void;
pub extern fn clang_getRangeStart(range: CXSourceRange) CXSourceLocation;
pub extern fn clang_getRangeEnd(range: CXSourceRange) CXSourceLocation;
pub const CXSourceRangeList = extern struct {
count: c_uint = std.mem.zeroes(c_uint),
ranges: [*c]CXSourceRange = std.mem.zeroes([*c]CXSourceRange),
};
pub extern fn clang_disposeSourceRangeList(ranges: [*c]CXSourceRangeList) void;
12 changes: 12 additions & 0 deletions src/clang/CXString.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const std = @import("std");
pub const CXString = extern struct {
data: ?*const anyopaque = std.mem.zeroes(?*const anyopaque),
private_flags: c_uint = std.mem.zeroes(c_uint),
};
pub const CXStringSet = extern struct {
Strings: [*c]CXString = std.mem.zeroes([*c]CXString),
Count: c_uint = std.mem.zeroes(c_uint),
};
pub extern fn clang_getCString(string: CXString) [*:0]const u8;
pub extern fn clang_disposeString(string: CXString) void;
pub extern fn clang_disposeStringSet(set: [*c]CXStringSet) void;
76 changes: 76 additions & 0 deletions src/clang/Documentation.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const CXString = @import("CXString.zig");
const CXErrorCode = @import("CXErrorCode.zig");
const CXSourceLocation = @import("CXSourceLocation.zig");
const CXFile = @import("CXFile.zig");
const CXDiagnostic = @import("CXDiagnostic.zig");
const Index = @import("Index.zig");
const std = @import("std");

pub const CXComment = extern struct {
ASTNode: ?*const anyopaque = std.mem.zeroes(?*const anyopaque),
TranslationUnit: Index.CXTranslationUnit = std.mem.zeroes(Index.CXTranslationUnit),
};
pub extern fn clang_Cursor_getParsedComment(C: Index.CXCursor) CXComment;
pub const CXComment_Null: c_int = 0;
pub const CXComment_Text: c_int = 1;
pub const CXComment_InlineCommand: c_int = 2;
pub const CXComment_HTMLStartTag: c_int = 3;
pub const CXComment_HTMLEndTag: c_int = 4;
pub const CXComment_Paragraph: c_int = 5;
pub const CXComment_BlockCommand: c_int = 6;
pub const CXComment_ParamCommand: c_int = 7;
pub const CXComment_TParamCommand: c_int = 8;
pub const CXComment_VerbatimBlockCommand: c_int = 9;
pub const CXComment_VerbatimBlockLine: c_int = 10;
pub const CXComment_VerbatimLine: c_int = 11;
pub const CXComment_FullComment: c_int = 12;
pub const CXCommentKind = c_uint;
pub const CXCommentInlineCommandRenderKind_Normal: c_int = 0;
pub const CXCommentInlineCommandRenderKind_Bold: c_int = 1;
pub const CXCommentInlineCommandRenderKind_Monospaced: c_int = 2;
pub const CXCommentInlineCommandRenderKind_Emphasized: c_int = 3;
pub const CXCommentInlineCommandRenderKind_Anchor: c_int = 4;
pub const CXCommentInlineCommandRenderKind = c_uint;
pub const CXCommentParamPassDirection_In: c_int = 0;
pub const CXCommentParamPassDirection_Out: c_int = 1;
pub const CXCommentParamPassDirection_InOut: c_int = 2;
pub const CXCommentParamPassDirection = c_uint;
pub extern fn clang_Comment_getKind(Comment: CXComment) CXCommentKind;
pub extern fn clang_Comment_getNumChildren(Comment: CXComment) c_uint;
pub extern fn clang_Comment_getChild(Comment: CXComment, ChildIdx: c_uint) CXComment;
pub extern fn clang_Comment_isWhitespace(Comment: CXComment) c_uint;
pub extern fn clang_InlineContentComment_hasTrailingNewline(Comment: CXComment) c_uint;
pub extern fn clang_TextComment_getText(Comment: CXComment) CXString.CXString;
pub extern fn clang_InlineCommandComment_getCommandName(Comment: CXComment) CXString.CXString;
pub extern fn clang_InlineCommandComment_getRenderKind(Comment: CXComment) CXCommentInlineCommandRenderKind;
pub extern fn clang_InlineCommandComment_getNumArgs(Comment: CXComment) c_uint;
pub extern fn clang_InlineCommandComment_getArgText(Comment: CXComment, ArgIdx: c_uint) CXString.CXString;
pub extern fn clang_HTMLTagComment_getTagName(Comment: CXComment) CXString.CXString;
pub extern fn clang_HTMLStartTagComment_isSelfClosing(Comment: CXComment) c_uint;
pub extern fn clang_HTMLStartTag_getNumAttrs(Comment: CXComment) c_uint;
pub extern fn clang_HTMLStartTag_getAttrName(Comment: CXComment, AttrIdx: c_uint) CXString.CXString;
pub extern fn clang_HTMLStartTag_getAttrValue(Comment: CXComment, AttrIdx: c_uint) CXString.CXString;
pub extern fn clang_BlockCommandComment_getCommandName(Comment: CXComment) CXString.CXString;
pub extern fn clang_BlockCommandComment_getNumArgs(Comment: CXComment) c_uint;
pub extern fn clang_BlockCommandComment_getArgText(Comment: CXComment, ArgIdx: c_uint) CXString.CXString;
pub extern fn clang_BlockCommandComment_getParagraph(Comment: CXComment) CXComment;
pub extern fn clang_ParamCommandComment_getParamName(Comment: CXComment) CXString.CXString;
pub extern fn clang_ParamCommandComment_isParamIndexValid(Comment: CXComment) c_uint;
pub extern fn clang_ParamCommandComment_getParamIndex(Comment: CXComment) c_uint;
pub extern fn clang_ParamCommandComment_isDirectionExplicit(Comment: CXComment) c_uint;
pub extern fn clang_ParamCommandComment_getDirection(Comment: CXComment) CXCommentParamPassDirection;
pub extern fn clang_TParamCommandComment_getParamName(Comment: CXComment) CXString.CXString;
pub extern fn clang_TParamCommandComment_isParamPositionValid(Comment: CXComment) c_uint;
pub extern fn clang_TParamCommandComment_getDepth(Comment: CXComment) c_uint;
pub extern fn clang_TParamCommandComment_getIndex(Comment: CXComment, Depth: c_uint) c_uint;
pub extern fn clang_VerbatimBlockLineComment_getText(Comment: CXComment) CXString.CXString;
pub extern fn clang_VerbatimLineComment_getText(Comment: CXComment) CXString.CXString;
pub extern fn clang_HTMLTagComment_getAsString(Comment: CXComment) CXString.CXString;
pub extern fn clang_FullComment_getAsHTML(Comment: CXComment) CXString.CXString;
pub extern fn clang_FullComment_getAsXML(Comment: CXComment) CXString.CXString;
pub const CXAPISetImpl = opaque {};
pub const CXAPISet = ?*CXAPISetImpl;
pub extern fn clang_createAPISet(tu: Index.CXTranslationUnit, out_api: [*c]CXAPISet) CXErrorCode;
pub extern fn clang_disposeAPISet(api: CXAPISet) void;
pub extern fn clang_getSymbolGraphForUSR(usr: [*:0]const u8, api: CXAPISet) CXString.CXString;
pub extern fn clang_getSymbolGraphForCursor(cursor: Index.CXCursor) CXString.CXString;
2 changes: 2 additions & 0 deletions src/clang/FatalErrorHandler.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub extern fn clang_install_aborting_llvm_fatal_error_handler() void;
pub extern fn clang_uninstall_llvm_fatal_error_handler() void;
Loading

0 comments on commit 35d3570

Please sign in to comment.