[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / mlir / examples / standalone / test / CAPI / standalone-capi-test.c
blob54f3ca7f7ff14e0395685ce1b464dd5a07a9ba90
1 //===- standalone-cap-demo.c - Simple demo of C-API -----------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM
4 // Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
10 // RUN: standalone-capi-test 2>&1 | FileCheck %s
12 #include <stdio.h>
14 #include "Standalone-c/Dialects.h"
15 #include "mlir-c/IR.h"
16 #include "mlir-c/RegisterEverything.h"
18 static void registerAllUpstreamDialects(MlirContext ctx) {
19 MlirDialectRegistry registry = mlirDialectRegistryCreate();
20 mlirRegisterAllDialects(registry);
21 mlirContextAppendDialectRegistry(ctx, registry);
22 mlirDialectRegistryDestroy(registry);
25 int main(int argc, char **argv) {
26 MlirContext ctx = mlirContextCreate();
27 // TODO: Create the dialect handles for the builtin dialects and avoid this.
28 // This adds dozens of MB of binary size over just the standalone dialect.
29 registerAllUpstreamDialects(ctx);
30 mlirDialectHandleRegisterDialect(mlirGetDialectHandle__standalone__(), ctx);
32 MlirModule module = mlirModuleCreateParse(
33 ctx, mlirStringRefCreateFromCString("%0 = arith.constant 2 : i32\n"
34 "%1 = standalone.foo %0 : i32\n"));
35 if (mlirModuleIsNull(module)) {
36 printf("ERROR: Could not parse.\n");
37 mlirContextDestroy(ctx);
38 return 1;
40 MlirOperation op = mlirModuleGetOperation(module);
42 // CHECK: %[[C:.*]] = arith.constant 2 : i32
43 // CHECK: standalone.foo %[[C]] : i32
44 mlirOperationDump(op);
46 mlirModuleDestroy(module);
47 mlirContextDestroy(ctx);
48 return 0;