mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-28 08:02:08 +00:00
Add call site location getter to C API
Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D93334
This commit is contained in:
parent
23d183f190
commit
4a327bd252
@ -147,6 +147,10 @@ MLIR_CAPI_EXPORTED MlirStringRef mlirDialectGetNamespace(MlirDialect dialect);
|
||||
MLIR_CAPI_EXPORTED MlirLocation mlirLocationFileLineColGet(
|
||||
MlirContext context, MlirStringRef filename, unsigned line, unsigned col);
|
||||
|
||||
/// Creates a call site location with a callee and a caller.
|
||||
MLIR_CAPI_EXPORTED MlirLocation mlirLocationCallSiteGet(MlirLocation callee,
|
||||
MlirLocation caller);
|
||||
|
||||
/// Creates a location with unknown position owned by the given context.
|
||||
MLIR_CAPI_EXPORTED MlirLocation mlirLocationUnknownGet(MlirContext context);
|
||||
|
||||
|
@ -116,6 +116,10 @@ MlirLocation mlirLocationFileLineColGet(MlirContext context,
|
||||
FileLineColLoc::get(unwrap(filename), line, col, unwrap(context)));
|
||||
}
|
||||
|
||||
MlirLocation mlirLocationCallSiteGet(MlirLocation callee, MlirLocation caller) {
|
||||
return wrap(CallSiteLoc::get(unwrap(callee), unwrap(caller)));
|
||||
}
|
||||
|
||||
MlirLocation mlirLocationUnknownGet(MlirContext context) {
|
||||
return wrap(UnknownLoc::get(unwrap(context)));
|
||||
}
|
||||
|
@ -1295,7 +1295,7 @@ MlirLogicalResult errorHandler(MlirDiagnostic diagnostic, void *userData) {
|
||||
MlirLocation loc = mlirDiagnosticGetLocation(diagnostic);
|
||||
mlirLocationPrint(loc, printToStderr, NULL);
|
||||
assert(mlirDiagnosticGetNumNotes(diagnostic) == 0);
|
||||
fprintf(stderr, ">> end of diagnostic (userData: %ld)\n", (long)userData);
|
||||
fprintf(stderr, "\n>> end of diagnostic (userData: %ld)\n", (long)userData);
|
||||
return mlirLogicalResultSuccess();
|
||||
}
|
||||
|
||||
@ -1308,16 +1308,32 @@ void testDiagnostics() {
|
||||
MlirContext ctx = mlirContextCreate();
|
||||
MlirDiagnosticHandlerID id = mlirContextAttachDiagnosticHandler(
|
||||
ctx, errorHandler, (void *)42, deleteUserData);
|
||||
MlirLocation loc = mlirLocationUnknownGet(ctx);
|
||||
fprintf(stderr, "@test_diagnostics\n");
|
||||
mlirEmitError(loc, "test diagnostics");
|
||||
MlirLocation unknownLoc = mlirLocationUnknownGet(ctx);
|
||||
mlirEmitError(unknownLoc, "test diagnostics");
|
||||
MlirLocation fileLineColLoc = mlirLocationFileLineColGet(
|
||||
ctx, mlirStringRefCreateFromCString("file.c"), 1, 2);
|
||||
mlirEmitError(fileLineColLoc, "test diagnostics");
|
||||
MlirLocation callSiteLoc = mlirLocationCallSiteGet(
|
||||
mlirLocationFileLineColGet(
|
||||
ctx, mlirStringRefCreateFromCString("other-file.c"), 2, 3),
|
||||
fileLineColLoc);
|
||||
mlirEmitError(callSiteLoc, "test diagnostics");
|
||||
mlirContextDetachDiagnosticHandler(ctx, id);
|
||||
mlirEmitError(loc, "more test diagnostics");
|
||||
mlirEmitError(unknownLoc, "more test diagnostics");
|
||||
// CHECK-LABEL: @test_diagnostics
|
||||
// CHECK: processing diagnostic (userData: 42) <<
|
||||
// CHECK: test diagnostics
|
||||
// CHECK: loc(unknown)
|
||||
// CHECK: >> end of diagnostic (userData: 42)
|
||||
// CHECK: processing diagnostic (userData: 42) <<
|
||||
// CHECK: test diagnostics
|
||||
// CHECK: loc("file.c":1:2)
|
||||
// CHECK: >> end of diagnostic (userData: 42)
|
||||
// CHECK: processing diagnostic (userData: 42) <<
|
||||
// CHECK: test diagnostics
|
||||
// CHECK: loc(callsite("other-file.c":2:3 at "file.c":1:2))
|
||||
// CHECK: >> end of diagnostic (userData: 42)
|
||||
// CHECK: deleting user data (userData: 42)
|
||||
// CHECK-NOT: processing diagnostic
|
||||
// CHECK: more test diagnostics
|
||||
|
Loading…
Reference in New Issue
Block a user