Hey Thanks for your reply Charles. The .mem file contains the entire
contents of the c file? I was going through the code and it seems like the
heap is created from a typed array in an initializeMemoryBlock. Am I
correct in my thinking?
On Friday, April 27, 2018 at 5:05:32 PM UTC-7, Charles Vaughn wrote:
>
> Look for a .mem file in chrome network tools or look for a long array in
> the javascript file that initializes the memory. Offset 434 contains the
> string "%s\0", Offset 384 contains "Hello World!\n....."
>
> On Friday, April 27, 2018 at 11:13:15 AM UTC-7, Vivek Pradhan wrote:
>>
>> Hey guys!
>>
>> I am trying to educate myself on emscripten and I definitely feel that
>> the idea of transpiling to JS is amazing! I was trying the basic
>> `hello_world.c` program. The c code was:
>>
>> #include <stdio.h>
>>
>> int main() {
>>
>> // declare and initialize string
>> char str[50] = "Hello World!\n";
>>
>> // print string
>> printf("%s",str);
>> return 0;
>> }
>>
>> The compiled `a.out.js` has the main function which looks like:
>>
>> function _main() {
>> var $0 = 0, $1 = 0, $vararg_buffer = 0, dest = 0, label = 0, sp = 0, src
>> = 0, stop = 0;
>> sp = STACKTOP;
>> STACKTOP = STACKTOP + 64|0; if ((STACKTOP|0) >= (STACK_MAX|0))
>> abortStackOverflow(64|0);
>> $vararg_buffer = sp;
>> $1 = sp + 8|0;
>> $0 = 0;
>> dest=$1; src=384; stop=dest+50|0; do { HEAP8[dest>>0]=HEAP8[src>>0]|0;
>> dest=dest+1|0; src=src+1|0; } while ((dest|0) < (stop|0));
>> HEAP32[$vararg_buffer>>2] = $1;
>> (_printf(434,$vararg_buffer)|0);
>> STACKTOP = sp;return 0;
>> }
>>
>> I am assuming that the first argument to _printf contains the string
>> representation somehow, may be as an offset into the HEAP8. I have however,
>> not been able to figure out where exactly in JS code is the HEAP8 populated
>> with characters from the string "Hello World!\n". There has to be a place
>> where memory is allocated and corresponding character values are saved at
>> those memory locations right? Tried going through the `run` function to see
>> if it happens in `preMain` function but I have no clue at this point.
>>
>> It will be a great help if someone can point at what point are variables
>> initialized in the JS file (especially strings because numbers are
>> initialized directly in _main I gathered) so that I can study that and
>> move forward from there.
>>
>> I really appreciate the support!
>>
>> Thanks
>>
>
--
You received this message because you are subscribed to the Google Groups
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.