Code Monkey home page Code Monkey logo

Comments (10)

ckirsch avatar ckirsch commented on June 9, 2024

@Son-Typ Could you please have a look and see if you can fix this? Thanks!

from selfie.

Son-Typ avatar Son-Typ commented on June 9, 2024

A small test case would be useful. Is the number_of_written_characters wrong? I tried compiling using ./selfie -c selfie.c -o selfie.m and ./selfie -l selfie.m -m 42 -c selfie.c -o selfie2.m and those are my results:

For main:

  • bootlevel 0: 185520 bytes generated with 42906 instructions and 13896 bytes of data
  • bootlevel 1: 282792 bytes generated with 42906 instructions and 13896 bytes of data

For printf:

  • bootlevel 0: 184936 bytes generated with 42580 instructions and 14616 bytes of data
  • bootlevel 1: 184936 bytes generated with 42580 instructions and 14616 bytes of data

The printf branch generates the same number of bytes for both bootlevels which I would expect to make more sense.

What are the expected results?

from selfie.

ckirsch avatar ckirsch commented on June 9, 2024

@Son-Typ I can't reproduce the issue you are seeing for main. I am on commit 0de776c.

What I actually meant is the character count, not the byte count. But we may have to check both.

Try: ./selfie -c selfie.c -S selfie.s

Should show more than a million characters in the assembly file but does not on the printf branch. I am on commit 0cbbb30.

from selfie.

Son-Typ avatar Son-Typ commented on June 9, 2024

I was on the same commits while conducting both tests.
Regarding the problem: The reason is actually quite simple. At bootlevel 0 we use the bootstrapping compiler's dprintf to write into the file, while we use our own dprintf at the other bootlevels. Clang's/GCC's dprintf does not count the number of written characters in number_of_written_characters while the printf implementation in main and our dprintf implementation do count. We probably want to count the written characters inside direct_output as dprintf returns the number of written characters. In this case we would have to stop counting inside put_character, which is a nasty side effect to begin with.
I tried ./selfie -l selfie.m -c selfie.c -S selfie.s, i.e., disassembling at bootlevel 1, which resulted in the expected "selfie.m: 1901357 characters of assembly [...]".

from selfie.

MartinGroesbacher avatar MartinGroesbacher commented on June 9, 2024

We will work on it asap but since its family holidays it might take a little while. Will post here when we're done

from selfie.

ckirsch avatar ckirsch commented on June 9, 2024

Sure, that's fine. Thanks a lot for looking into this. I hope there is a clean solution.

from selfie.

MartinGroesbacher avatar MartinGroesbacher commented on June 9, 2024

We have suggested a solution to the problem (PR created already). It should be mentioned that this solution (counting using the return value of dprintf) is not thread-safe, however in order to make it thread-safe, due to the limitations of C* we would have to use local variables in every method that calls put_character and return those and continue to count. This would be tedious to implement as some of these methods already have return values that are used in other parts of the code (for example print format returning the index of the format string). Therefore this is our best suggestion.

from selfie.

ckirsch avatar ckirsch commented on June 9, 2024

@MartinGroesbacher I am actually not sure why you guys are concerned about thread safety. Are you worried about the concurrency assignments in the SE class?

from selfie.

MartinGroesbacher avatar MartinGroesbacher commented on June 9, 2024

We just wanted to point this out in case you eventually may want to use printf in a future concurrent project that uses selfie as a library. If this is ever the case, then one would have to adapt the implementation.

from selfie.

ckirsch avatar ckirsch commented on June 9, 2024

Got it! Thanks.

from selfie.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.