-
Notifications
You must be signed in to change notification settings - Fork 7
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
test: Port integration_tests/arrays_31.f90
, arrays_34.f90
and arrays_35.f90
from LFortran and improve LC to compile it
#112
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <iostream> | ||
#include <cmath> | ||
#include <xtensor/xtensor.hpp> | ||
#include <xtensor/xfixed.hpp> | ||
#include "xtensor/xio.hpp" | ||
|
||
// LFortran: ./integration_tests/arrays_31.f90 | ||
|
||
int main() { | ||
xt::xtensor<int, 1> x = xt::empty<int>({5}); | ||
|
||
int pqr = x.size(); | ||
|
||
std::cout << pqr << std::endl; | ||
if (pqr != 5) { | ||
exit(2); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include <iostream> | ||
#include <cmath> | ||
#include <xtensor/xtensor.hpp> | ||
#include <xtensor/xfixed.hpp> | ||
#include "xtensor/xio.hpp" | ||
|
||
// LFortran: ./integration_tests/arrays_34.f90 | ||
|
||
|
||
void sub(xt::xtensor<int, 1>& x, int z) { | ||
switch (z) { | ||
case 1: | ||
x.resize({1}); // Resize x to have size 1 | ||
x(0) = 1; | ||
break; | ||
default: | ||
std::cout << "z = " << z << std::endl; | ||
std::cout << "z not supported." << std::endl; | ||
} | ||
} | ||
|
||
int main() { | ||
xt::xtensor<int, 1> x; | ||
|
||
sub(x, 1); | ||
std::cout << x << std::endl; | ||
if (x(0) != 1) { | ||
exit(2); | ||
} | ||
|
||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <iostream> | ||
#include <cmath> | ||
#include <xtensor/xtensor.hpp> | ||
#include <xtensor/xfixed.hpp> | ||
#include "xtensor/xio.hpp" | ||
|
||
// LFortran: ./integration_tests/arrays_35.f90 | ||
|
||
int main() { | ||
xt::xtensor<float, 1> x = xt::empty<float>({2}); | ||
x = { 9.0, 2.1 }; | ||
|
||
std::cout << x << std::endl; | ||
if (std::abs(x(0) - 9.0) > 1e-7) exit(2); | ||
if (std::abs(x(1) - 2.1) > 1e-7) exit(2); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,6 +146,14 @@ namespace LCompilers::CastingUtil { | |
} else { | ||
dest = ASRUtils::extract_type(dest); | ||
} | ||
if (ASR::is_a<ASR::ArrayConstant_t>(*expr)) { | ||
ASR::ArrayConstant_t* arr = ASR::down_cast<ASR::ArrayConstant_t>(expr); | ||
for (size_t i = 0; i < arr->n_args; i++) { | ||
arr->m_args[i] = ASRUtils::expr_value(ASRUtils::EXPR(ASRUtils::make_Cast_t_value(al, loc, arr->m_args[i], | ||
cast_kind, ASRUtils::expr_type(arr->m_args[i])))); | ||
Comment on lines
+152
to
+153
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems we are casting each array element to the type of that same array element. So, why is a casting being needed? |
||
} | ||
return ASRUtils::EXPR((ASR::asr_t*) arr); | ||
} | ||
return ASRUtils::EXPR(ASRUtils::make_Cast_t_value(al, loc, expr, cast_kind, dest)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"basename": "asr-array_28-e2b02d8", | ||
"cmd": "lc --show-asr --no-color {infile} -o {outfile}", | ||
"infile": "tests/../integration_tests/array_28.cpp", | ||
"infile_hash": "d2a5fada0de4142e17c05431214c0b594476f069036ddddbbfeaa334", | ||
"outfile": null, | ||
"outfile_hash": null, | ||
"stdout": "asr-array_28-e2b02d8.stdout", | ||
"stdout_hash": "797d6000c250772de2e9d7017adb9194c0bd9a6694b04d4ff6b472d6", | ||
"stderr": null, | ||
"stderr_hash": null, | ||
"returncode": 0 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,254 @@ | ||
(TranslationUnit | ||
(SymbolTable | ||
1 | ||
{ | ||
main: | ||
(Function | ||
(SymbolTable | ||
2 | ||
{ | ||
__return_var: | ||
(Variable | ||
2 | ||
__return_var | ||
[] | ||
ReturnVar | ||
() | ||
() | ||
Default | ||
(Integer 4) | ||
() | ||
Source | ||
Public | ||
Required | ||
.false. | ||
), | ||
x: | ||
(Variable | ||
2 | ||
x | ||
[] | ||
Local | ||
() | ||
() | ||
Default | ||
(Allocatable | ||
(Array | ||
(Real 8) | ||
[(() | ||
())] | ||
DescriptorArray | ||
) | ||
) | ||
() | ||
Source | ||
Public | ||
Required | ||
.false. | ||
) | ||
}) | ||
main | ||
(FunctionType | ||
[] | ||
(Integer 4) | ||
Source | ||
Implementation | ||
() | ||
.false. | ||
.false. | ||
.false. | ||
.false. | ||
.false. | ||
[] | ||
.false. | ||
) | ||
[] | ||
[] | ||
[(Allocate | ||
[((Var 2 x) | ||
[((IntegerConstant 0 (Integer 4)) | ||
(IntegerConstant 2 (Integer 4)))] | ||
() | ||
())] | ||
() | ||
() | ||
() | ||
) | ||
(Allocate | ||
[((Var 2 x) | ||
[((IntegerConstant 0 (Integer 4)) | ||
(IntegerConstant 2 (Integer 4)))] | ||
() | ||
())] | ||
() | ||
() | ||
() | ||
) | ||
(= | ||
(Var 2 x) | ||
(ArrayConstant | ||
[(RealConstant | ||
9.000000 | ||
(Const | ||
(Real 8) | ||
) | ||
) | ||
(RealConstant | ||
2.100000 | ||
(Const | ||
(Real 8) | ||
) | ||
)] | ||
(Array | ||
(Const | ||
(Real 8) | ||
) | ||
[((IntegerConstant 0 (Integer 4)) | ||
(IntegerConstant 2 (Integer 4)))] | ||
FixedSizeArray | ||
) | ||
RowMajor | ||
) | ||
() | ||
) | ||
[(Var 2 x)] | ||
(StringConstant | ||
"" | ||
(Character 1 1 ()) | ||
) | ||
(StringConstant | ||
"" | ||
(Character 1 1 ()) | ||
) | ||
) | ||
(If | ||
(RealCompare | ||
(IntrinsicScalarFunction | ||
Abs | ||
[(RealBinOp | ||
(Cast | ||
(ArrayItem | ||
(Var 2 x) | ||
[(() | ||
(IntegerConstant 0 (Integer 4)) | ||
())] | ||
(Real 8) | ||
RowMajor | ||
() | ||
) | ||
RealToReal | ||
(Real 8) | ||
() | ||
) | ||
Sub | ||
(RealConstant | ||
9.000000 | ||
(Real 8) | ||
) | ||
(Real 8) | ||
() | ||
)] | ||
0 | ||
(Real 8) | ||
() | ||
) | ||
Gt | ||
(RealConstant | ||
0.000000 | ||
(Real 8) | ||
) | ||
(Logical 4) | ||
() | ||
) | ||
[] | ||
[] | ||
) | ||
(If | ||
(RealCompare | ||
(IntrinsicScalarFunction | ||
Abs | ||
[(RealBinOp | ||
(Cast | ||
(ArrayItem | ||
(Var 2 x) | ||
[(() | ||
(IntegerConstant 1 (Integer 4)) | ||
())] | ||
(Real 8) | ||
RowMajor | ||
() | ||
) | ||
RealToReal | ||
(Real 8) | ||
() | ||
) | ||
Sub | ||
(RealConstant | ||
2.100000 | ||
(Real 8) | ||
) | ||
(Real 8) | ||
() | ||
)] | ||
0 | ||
(Real 8) | ||
() | ||
) | ||
Gt | ||
(RealConstant | ||
0.000000 | ||
(Real 8) | ||
) | ||
(Logical 4) | ||
() | ||
) | ||
[] | ||
[] | ||
)] | ||
(Var 2 __return_var) | ||
Public | ||
.false. | ||
.false. | ||
() | ||
), | ||
main_program: | ||
(Program | ||
(SymbolTable | ||
3 | ||
{ | ||
exit_code: | ||
(Variable | ||
3 | ||
exit_code | ||
[] | ||
Local | ||
() | ||
() | ||
Default | ||
(Integer 4) | ||
() | ||
Source | ||
Public | ||
Required | ||
.false. | ||
) | ||
}) | ||
main_program | ||
[main] | ||
[(= | ||
(Var 3 exit_code) | ||
(FunctionCall | ||
1 main | ||
1 main | ||
[] | ||
(Integer 4) | ||
() | ||
() | ||
) | ||
() | ||
)] | ||
) | ||
}) | ||
[] | ||
) |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -33,3 +33,7 @@ asr = true | |||||||||||||||||||
[[test]] | ||||||||||||||||||||
filename = "../integration_tests/array_04.cpp" | ||||||||||||||||||||
asr = true | ||||||||||||||||||||
|
||||||||||||||||||||
[[test]] | ||||||||||||||||||||
filename = "../integration_tests/array_28.cpp" | ||||||||||||||||||||
asr = true | ||||||||||||||||||||
Comment on lines
+36
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reference testing should be as limited as possible. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think casting should be done only on the basis of
type
. Using expression to decide casting operation seems more like a hard-coded approach.