Skip to content

Instantly share code, notes, and snippets.

@kripken
Created April 27, 2022 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kripken/0b4e39a9f2943887ff122df5557c252c to your computer and use it in GitHub Desktop.
Save kripken/0b4e39a9f2943887ff122df5557c252c to your computer and use it in GitHub Desktop.
#include "a.h"
void a() {
data = 42;
}
extern int data;
void a();
#include <stdio.h>
#include "a.h"
int data = 0;
struct B {
B() {
printf("B(), data=%d\n", data);
}
~B() {
printf("~B(), data=%d\n", data);
}
};
int main() {
B b;
a();
}
;;
;; relevant output from running
;;
;; ./emcc a.cpp b.cpp -O1 --profiling -fwasm-exceptions -s ENVIRONMENT=shell
;;
(func $a\28\29
(i32.store offset=1680
(i32.const 0)
(i32.const 42)
)
)
(func $__original_main (result i32)
(local $0 i32)
(global.set $__stack_pointer
(local.tee $0
(i32.sub
(global.get $__stack_pointer)
(i32.const 48)
)
)
)
(i32.store offset=32
(local.get $0)
(i32.load offset=1680
(i32.const 0)
)
)
(drop
(call $iprintf
(i32.const 1042)
(i32.add
(local.get $0)
(i32.const 32)
)
)
)
(try $label$3 ;; unnecessary try-catch
(do
(call $a\28\29)
)
(catch_all
(global.set $__stack_pointer
(local.get $0)
)
(i32.store offset=16
(local.get $0)
(i32.load offset=1680
(i32.const 0)
)
)
(drop
(call $iprintf
(i32.const 1041)
(i32.add
(local.get $0)
(i32.const 16)
)
)
)
(rethrow $label$3)
)
)
(i32.store
(local.get $0)
(i32.load offset=1680
(i32.const 0)
)
)
(drop
(call $iprintf
(i32.const 1041)
(local.get $0)
)
)
(global.set $__stack_pointer
(i32.add
(local.get $0)
(i32.const 48)
)
)
(i32.const 0)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment