brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 62add13 Raw
41 lines · c
1//===- standalone-cap-demo.c - Simple demo of C-API -----------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM4// Exceptions.5// See https://llvm.org/LICENSE.txt for license information.6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7//8//===----------------------------------------------------------------------===//9 10// RUN: standalone-capi-test 2>&1 | FileCheck %s11 12#include <stdio.h>13 14#include "Standalone-c/Dialects.h"15#include "mlir-c/Dialect/Arith.h"16#include "mlir-c/IR.h"17 18int main(int argc, char **argv) {19  MlirContext ctx = mlirContextCreate();20  mlirDialectHandleRegisterDialect(mlirGetDialectHandle__arith__(), ctx);21  mlirDialectHandleRegisterDialect(mlirGetDialectHandle__standalone__(), ctx);22 23  MlirModule module = mlirModuleCreateParse(24      ctx, mlirStringRefCreateFromCString("%0 = arith.constant 2 : i32\n"25                                          "%1 = standalone.foo %0 : i32\n"));26  if (mlirModuleIsNull(module)) {27    printf("ERROR: Could not parse.\n");28    mlirContextDestroy(ctx);29    return 1;30  }31  MlirOperation op = mlirModuleGetOperation(module);32 33  // CHECK: %[[C:.*]] = arith.constant 2 : i3234  // CHECK: standalone.foo %[[C]] : i3235  mlirOperationDump(op);36 37  mlirModuleDestroy(module);38  mlirContextDestroy(ctx);39  return 0;40}41