19 auto *op =
unwrap(MlirOperation{obj->internalRep.otherValuePtr});
20 llvm::raw_string_ostream stream(str);
22 obj->length = str.length();
23 obj->bytes = Tcl_Alloc(obj->length);
24 memcpy(obj->bytes, str.c_str(), obj->length);
25 obj->bytes[obj->length] =
'\0';
44 int objc, Tcl_Obj *
const objv[]) {
46 Tcl_WrongNumArgs(interp, objc, objv,
"usage: circt load [MLIR|FIR] [file]");
50 std::string errorMessage;
51 auto input = mlir::openInputFile(llvm::StringRef(Tcl_GetString(objv[2])),
57 llvm::SourceMgr sourceMgr;
58 sourceMgr.AddNewSourceBuffer(std::move(input), llvm::SMLoc());
59 mlir::SourceMgrDiagnosticHandler sourceMgrHandler(sourceMgr, context);
62 if (!strcmp(Tcl_GetString(objv[1]),
"MLIR"))
63 module = wrap(mlir::parseSourceFile<mlir::ModuleOp>(sourceMgr, context)
66 else if (!strcmp(Tcl_GetString(objv[1]),
"FIR"))
68 return returnErrorStr(interp,
"loading FIR files is unimplemented :(");
72 if (mlirOperationIsNull(module))
77 auto *obj = Tcl_NewObj();
78 obj->typePtr = Tcl_GetObjType(
"MlirOperation");
79 obj->internalRep.otherValuePtr = (
void *)m;
82 Tcl_SetObjResult(interp, obj);
88 Tcl_Obj *
const objv[]) {
90 Tcl_WrongNumArgs(interp, objc, objv,
"usage: circt load");
94 auto *context = (mlir::MLIRContext *)cdata;
96 if (!strcmp(
"load", Tcl_GetString(objv[1])))
107 if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL)
111 Tcl_ObjType *operationType =
new Tcl_ObjType;
112 operationType->name =
"MlirOperation";
117 Tcl_RegisterObjType(operationType);
120 if (Tcl_PkgProvide(interp,
"Circt",
"1.0") == TCL_ERROR)
124 auto *context =
new mlir::MLIRContext;
125 context->loadDialect<circt::hw::HWDialect, circt::comb::CombDialect,
126 circt::sv::SVDialect>();