Introduce IR and parser support for ML functions.
Representing function arguments is still TODO.
Supporting instructions other than return is also TODO.
PiperOrigin-RevId: 202570934
diff --git a/lib/IR/AsmPrinter.cpp b/lib/IR/AsmPrinter.cpp
index 08fe838..03871fc 100644
--- a/lib/IR/AsmPrinter.cpp
+++ b/lib/IR/AsmPrinter.cpp
@@ -21,6 +21,7 @@
//===----------------------------------------------------------------------===//
#include "mlir/IR/CFGFunction.h"
+#include "mlir/IR/MLFunction.h"
#include "mlir/IR/Module.h"
#include "mlir/IR/Types.h"
#include "mlir/Support/STLExtras.h"
@@ -151,10 +152,18 @@
print(llvm::errs());
}
+void MLStatement::print(raw_ostream &os) const {
+ //TODO
+}
+
+void MLStatement::dump() const {
+ print(llvm::errs());
+}
void Function::print(raw_ostream &os) const {
switch (getKind()) {
case Kind::ExtFunc: return cast<ExtFunction>(this)->print(os);
case Kind::CFGFunc: return cast<CFGFunction>(this)->print(os);
+ case Kind::MLFunc: return cast<MLFunction>(this)->print(os);
}
}
@@ -167,6 +176,18 @@
state.print();
}
+void MLFunction::print(raw_ostream &os) const {
+ os << "mlfunc ";
+ // FIXME: should print argument names rather than just signature
+ printFunctionSignature(this, os);
+ os << " {\n";
+
+ for (auto *stmt : stmtList)
+ stmt->print(os);
+ os << " return\n";
+ os << "}\n\n";
+}
+
void Module::print(raw_ostream &os) const {
for (auto *fn : functionList)
fn->print(os);