File tree 2 files changed +23
-0
lines changed 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,22 @@ namespace LFortran {
11
11
12
12
namespace wasm {
13
13
14
+ /*
15
+
16
+ This X86Visitor uses stack to pass arguments and return values from functions.
17
+ Since in X86, instructions operate on registers (and not on stack),
18
+ for every instruction we pop elements from top of stack and store them into
19
+ registers. After operating on the registers, the result value is then
20
+ pushed back onto the stack.
21
+
22
+ One of the reasons to use stack to pass function arguments is that,
23
+ it allows us to define and call functions with any number of parameters.
24
+ As registers are limited in number, if we use them to pass function arugments,
25
+ the number of arguments we could pass to a function would get limited by
26
+ the number of registers available with the CPU.
27
+
28
+ */
29
+
14
30
class X86Visitor : public WASMDecoder <X86Visitor>,
15
31
public WASM_INSTS_VISITOR::BaseWASMVisitor<X86Visitor> {
16
32
public:
Original file line number Diff line number Diff line change @@ -815,7 +815,14 @@ void emit_elf32_footer(X86Assembler &a);
815
815
816
816
void emit_exit (X86Assembler &a, const std::string &name,
817
817
uint32_t exit_code);
818
+
819
+ // this is similar to emit_exit() but takes the argument (i.e. exit code)
820
+ // from top of stack. To call this exit2, one needs to jump to it
821
+ // instead of call it. (Because calling pushes the instruction address and
822
+ // base pointer value (ebp) of previous function and thus makes the
823
+ // exit code parameter less reachable)
818
824
void emit_exit2 (X86Assembler &a, const std::string &name);
825
+
819
826
void emit_data_string (X86Assembler &a, const std::string &label,
820
827
const std::string &s);
821
828
void emit_print (X86Assembler &a, const std::string &msg_label,
You can’t perform that action at this time.
0 commit comments