Comments (2)
hello,
i'm reading MIR.md and found this paragraph:
* MIR functions can have more one result but possible number of results and combination of their types are machine-defined. For example, for x86-64 the function can have upto six results and return two integer values, two float or double values, and two long double values in any combination
this decision seems to make mir programs dependent on ARCH it runs on.
i'm wondering whether it would be preferable to modify API such that any number of args can be returned.
the target-specific codegen could then decide how these are returned (optimally the same way C does it when returning a struct).
so a scripting language can freely use MIR without being restricted in this aspect.of course i may be missing some important aspects you already considered.
No, you nailed it. I thought about this too because I stated several times that MIR is machine-independent languages. So I am going to implement returning any combinations of values. My plan is to pass other values through the stack. Although there will be still machine-dependence on which values are returned through regs or memory. But if only MIR is used, it should work on any target.
Another thing I mentioned that MIR supports only binary compliment arithmetic. So it will not work on machines w/o it. Fortunately, there are very few such machines. And as I know coming C2x standard will require this too.
interestingly, c2mir compiles the following snippet
struct foo { long long l1, l2, l3, l4; }; struct foo bar(int a1, int a2, int a3) { return (struct foo) {.l1 = a1, .l2 = a2, .l3 = a3, .l4 = a3+a2}; }but using m2c[0] on mir code generated by -S causes assert failure.
Thank you I'll investigate this on this week.
[0]:
diff --git a/mir2c/mir2c.c b/mir2c/mir2c.c index bf9d92f..20454cd 100644 --- a/mir2c/mir2c.c +++ b/mir2c/mir2c.c @@ -462,7 +462,7 @@ void MIR_module2c (MIR_context_t ctx, FILE *f, MIR_module_t m) { } /* ------------------------- Small test example ------------------------- */ -#ifdef TEST_MIR2C +#if defined(TEST_MIR2C) #include "mir-tests/scan-sieve.h" #include "mir-tests/scan-hi.h" @@ -478,4 +478,27 @@ int main (int argc, const char *argv[]) { MIR_finish (ctx); return 0; } + +#elif defined(M2C) + +int main (int argc, const char *argv[]) { + MIR_module_t m; + MIR_context_t ctx = MIR_init (); + + FILE *f = fopen(argv[1], "r"); + fseeko(f, 0, SEEK_END); + off_t l = ftello(f); + fseeko(f, 0, SEEK_SET); + char *buf = malloc(l+1); + assert(fread(buf, 1, l, f) == l); + fclose(f); + buf[l] = 0; + MIR_scan_string (ctx, buf); + m = DLIST_TAIL (MIR_module_t, *MIR_get_module_list (ctx)); + MIR_module2c (ctx, stdout, m); + MIR_finish (ctx); + return 0; +} + + #endif
from mir.
Thank you I'll investigate this on this week.
MIR2C was not updated when I reworked return-stmt. An early version of MIR_RET
always required one return value. I fixed that. But MIR2C will report an error if there is more one return value.
from mir.
Related Issues (20)
- Segfault in `target_get_blk_type` HOT 1
- Segfault in `classify_node` HOT 1
- Segfault in `get_enum_basic_type` HOT 1
- Segfault in `get_enum_basic_type` HOT 1
- heap-buffer-overflow in `def_symbol` HOT 1
- heap-buffer-overflow in `VARR_token_tpush` and `VARR_token_tpop` HOT 3
- Assertion failed: (0), function out_op, file mir2c.c, line 65 HOT 8
- Supplying custom allocation/deallocation routines HOT 2
- Building with zig and failing at runtime on `mir_hash_1`
- Support for system calls? HOT 11
- Issue 361 test case failed HOT 2
- Shebang support for Mir files? HOT 13
- Awk has a syntax error in the benchmarks HOT 16
- Allow MIR text to be mixed in with C API
- Bug in mir-gen-x86_64.c on bbv branch HOT 3
- Add Apple Silicon CI support HOT 2
- Assertion error in 'process_aggregate_arg' for anonymous struct/union HOT 2
- Assertion error in 'get_uptodate_def_insn' relating to division by `sizeof(char)` HOT 3
- Please implement _Thread_local HOT 1
- CMake build broken with 9b7aa03 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mir.