Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass: Passing Array descriptor by value #77

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 12 additions & 4 deletions examples/expr2.f90
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
program expr2
implicit none

integer :: x

x = (2+3)*5
print *, x
integer :: x(2)
print *, mysum(x)

contains
function mysum(x) result(r)
integer, intent(in) :: x(:)
integer :: i
integer :: r
r = 0
do i = 1, size(x)
r = r + x(i)
end do
end function
end program
61 changes: 31 additions & 30 deletions grammar/asdl_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,33 @@ def visitField(self, field):
self.emit( "this->visit_symbol(*a.second);", 3)
self.emit("}", 2)

class WalkUpdaterVisitor(ASTWalkVisitorVisitor):

def visitModule(self, mod):
self.emit("/" + "*"*78 + "/")
self.emit("// Walk Updater Visitor base class")
self.emit("")
self.emit("template <class Derived>")
self.emit("class BaseWalkUpdater : public BaseVisitor<Derived>")
self.emit("{")
self.emit("private:")
self.emit(" Derived& self() { return static_cast<Derived&>(*this); }")
self.emit("public:")
super(ASTWalkVisitorVisitor, self).visitModule(mod)
self.emit("};")

def make_visitor(self, name, fields):
self.emit("void visit_%s(%s_t &x) {" % (name, name), 1)
self.used = False
have_body = False
for field in fields:
self.visitField(field)
if not self.used:
# Note: a better solution would be to change `&x` to `& /* x */`
# above, but we would need to change emit to return a string.
self.emit("if ((bool&)x) { } // Suppress unused warning", 2)
self.emit("}", 1)

class CallReplacerOnExpressionsVisitor(ASDLVisitor):

def visitModule(self, mod):
Expand Down Expand Up @@ -501,33 +528,6 @@ def visitField(self, field):
self.emit( "this->visit_symbol(*a.second);", 3)
self.emit("}", 2)

class StatementsFirstWalkVisitorVisitor(ASTWalkVisitorVisitor, ASDLVisitor):

def visitModule(self, mod):
self.emit("/" + "*"*78 + "/")
self.emit("// Statements First Visitor base class")
self.emit("")
self.emit("template <class Derived>")
self.emit("class StatementsFirstBaseWalkVisitor : public BaseVisitor<Derived>")
self.emit("{")
self.emit("private:")
self.emit(" Derived& self() { return static_cast<Derived&>(*this); }")
self.emit("public:")
super(ASTWalkVisitorVisitor, self).visitModule(mod)
self.emit("};")

def make_visitor(self, name, fields):
self.emit("void visit_%s(const %s_t &x) {" % (name, name), 1)
self.used = False
have_body = False
for field in fields[::-1]:
self.visitField(field)
if not self.used:
# Note: a better solution would be to change `&x` to `& /* x */`
# above, but we would need to change emit to return a string.
self.emit("if ((bool&)x) { } // Suppress unused warning", 2)
self.emit("}", 1)

# This class generates a visitor that prints the tree structure of AST/ASR
class TreeVisitorVisitor(ASDLVisitor):

Expand Down Expand Up @@ -2129,9 +2129,8 @@ def add_masks(fields, node):

visitors = [ASTNodeVisitor0, ASTNodeVisitor1, ASTNodeVisitor,
ASTVisitorVisitor1, ASTVisitorVisitor1b, ASTVisitorVisitor2,
ASTWalkVisitorVisitor, TreeVisitorVisitor, PickleVisitorVisitor,
StatementsFirstWalkVisitorVisitor, SerializationVisitorVisitor,
DeserializationVisitorVisitor]
ASTWalkVisitorVisitor, PickleVisitorVisitor,
SerializationVisitorVisitor, DeserializationVisitorVisitor]


def main(argv):
Expand Down Expand Up @@ -2170,6 +2169,8 @@ def main(argv):

try:
if is_asr:
WalkUpdaterVisitor(fp, data).visit(mod)
fp.write("\n\n")
ExprStmtDuplicatorVisitor(fp, data).visit(mod)
fp.write("\n\n")
ExprBaseReplacerVisitor(fp, data).visit(mod)
Expand Down
7 changes: 4 additions & 3 deletions src/libasr/codegen/asr_to_wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <libasr/exception.h>
#include <libasr/asr_utils.h>

// #include <lfortran/pickle.h>
#include <lfortran/pickle.h>

namespace LFortran {

Expand Down Expand Up @@ -1591,8 +1591,9 @@ Result<Vec<uint8_t>> asr_to_wasm_bytes_stream(ASR::TranslationUnit_t &asr, Alloc
pass_replace_do_loops(al, asr);
pass_propagate_arr_dims(al, asr);

// std::cout << pickle(asr, true /* use colors */, true /* indent */,
// true /* with_intrinsic_modules */) << std::endl;
std::cout << pickle(asr, true /* use colors */, true /* indent */,
true /* with_intrinsic_modules */) << std::endl;
exit(0);
try {
v.visit_asr((ASR::asr_t &)asr);
} catch (const CodeGenError &e) {
Expand Down