Skip to content

Commit 314a178

Browse files
committed
[Heavy] Fix add-argument; Remove func return values from IR
1 parent b6135e5 commit 314a178

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
lines changed

heavy/lib/Mlir.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ void add_argument(Context& C, ValueRefs Args) {
356356
heavy::SourceLocation Loc= Args[2].getSourceLocation();
357357
if (!Block)
358358
return C.RaiseError("expecting mlir.block: {}", Args[0]);
359-
if (Type)
360-
return C.RaiseError("expecting mlir.block: {}", Args[1]);
359+
if (!Type)
360+
return C.RaiseError("expecting mlir.type: {}", Args[1]);
361361

362362
mlir::OpBuilder* Builder = getCurrentBuilder(C);
363363
if (!Builder)

heavy/lib/OpGen.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -448,12 +448,12 @@ mlir::FunctionType OpGen::createFunctionType(unsigned Arity,
448448
mlir::Type ClosureT = Builder.getType<HeavyContextTy>();
449449
mlir::Type ValueT = Builder.getType<HeavyValueTy>();
450450

451-
llvm::SmallVector<mlir::Type, 16> Types{};
451+
llvm::SmallVector<mlir::Type, 16> ArgTypes{};
452452
// push the closure type
453-
Types.push_back(ClosureT);
453+
ArgTypes.push_back(ClosureT);
454454
if (Arity > 0) {
455455
for (unsigned i = 0; i < Arity - 1; i++) {
456-
Types.push_back(ValueT);
456+
ArgTypes.push_back(ValueT);
457457
}
458458

459459
mlir::Type LastParamT;
@@ -468,10 +468,10 @@ mlir::FunctionType OpGen::createFunctionType(unsigned Arity,
468468
LastParamT = Builder.getType<HeavyValueRefsTy>();
469469
break;
470470
}
471-
Types.push_back(LastParamT);
471+
ArgTypes.push_back(LastParamT);
472472
}
473473

474-
return Builder.getFunctionType(Types, ValueT);
474+
return Builder.getFunctionType(ArgTypes, /*ResultTypes*/{});
475475
}
476476

477477
heavy::FuncOp OpGen::createFunction(SourceLocation Loc,

heavy/test/Evaluate/create-op.scm

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
(import (heavy builtins))
33
(import (heavy mlir))
44

5+
(load-dialect "func")
6+
(load-dialect "heavy")
7+
8+
(define !heavy.context (type "!heavy.context"))
59
(define !heavy.value (type "!heavy.value"))
610

711
; CHECK: #op{%0 = "heavy.literal"() {info = #heavy<"\22foo\22">} : () -> !heavy.value
@@ -89,3 +93,37 @@
8993
(write command)
9094
(newline)
9195

96+
;; FIXME Why is it not pretty printing the func.func?
97+
; COM-CHECK: #op{func.func @my_func(%arg0: !heavy.context, %arg1: !heavy.value) {
98+
99+
; CHECK: #op{"func.func"() <{
100+
; CHECK-NEXT: ^bb0(%arg0: !heavy.context, %arg1: !heavy.value)
101+
(define my-func
102+
(create-op "func.func"
103+
(loc: 0)
104+
(operands:)
105+
(attributes:
106+
("sym_name" (string-attr "my_func"))
107+
("function_type"
108+
(type-attr (%function-type
109+
#(!heavy.context !heavy.value)
110+
#()))))
111+
(result-types:)
112+
(region: "body" ((ctx : !heavy.context) (arg1 : !heavy.value))
113+
(define callee
114+
(create-op "heavy.load_global"
115+
(loc: 0)
116+
(operands:)
117+
(attributes:
118+
("name" (flat-symbolref-attr "_HEAVYL5SheavyL4SbaseV5Swrite")))
119+
(result-types: !heavy.value)
120+
))
121+
(create-op "heavy.apply"
122+
(loc: 0)
123+
(operands: ctx arg1)
124+
(attributes:)
125+
(result-types:))
126+
)))
127+
(write my-func)
128+
(newline)
129+

0 commit comments

Comments
 (0)