flat assembler
Message board for the users of flat assembler.
Index
> Windows > fasm compiler programming tutorial? Goto page 1, 2 Next |
Author |
|
kerr 25 Sep 2017, 14:36
hello friends
you have fasm compiler programming turorial? or you have studied its source code? _________________ I hope we will be good friends. |
|||
25 Sep 2017, 14:36 |
|
_shura 26 Sep 2017, 13:25
Is this question about how fasm/fasmg itself works or do you want to create windows-programmes with fasm/fasmg?
|
|||
26 Sep 2017, 13:25 |
|
_shura 05 Oct 2017, 14:33
then better move the topic to ›compiler internals‹. Anyway, the core file is assembler.inc, best way is to start there, but I must confess, it is complicated, because Tomasz does not comment a lot.
Last edited by _shura on 05 Oct 2017, 16:15; edited 1 time in total |
|||
05 Oct 2017, 14:33 |
|
Tomasz Grysztar 05 Oct 2017, 15:44
There is a guide to fasm's internals, it also had some tiny updates later but I never finished it.
|
|||
05 Oct 2017, 15:44 |
|
kerr 05 Oct 2017, 15:45
_shura wrote: then better move the topic to ›compiler internals‹. Anyway, the core file is assembly.inc, best way is to start there, but I must confess, it is complicated, because Tomasz does not comment a lot. yes i want to analyze it . but it is too difficult. _________________ I hope we will be good friends. |
|||
05 Oct 2017, 15:45 |
|
kerr 05 Oct 2017, 16:01
Tomasz Grysztar wrote: There is a guide to fasm's internals, it also had some tiny updates later but I never finished it. thank you。 are you studying this compiler? _________________ I hope we will be good friends. |
|||
05 Oct 2017, 16:01 |
|
_shura 05 Oct 2017, 16:04
So there is no current overview about fasm itself and none for fasmg?
PS: Tomasz is the author of this compiler. he wrote it. |
|||
05 Oct 2017, 16:04 |
|
Tomasz Grysztar 05 Oct 2017, 16:27
_shura wrote: So there is no current overview about fasm itself and none for fasmg? As for the fasmg, all my design notes were digital since the beginning and you can find them in the Fossil repository. They focus more on the design of the language (note that they mostly predate an actual implementation) and have only little information on the internal data structures, but the fasmg sources themselves are more self-descriptive compared to fasm 1. At least fasmg sources use named structure fields and flags (in fasm 1 all of them were hard-coded numbers that I was looking up on my paper notes every time I worked with fasm's source). |
|||
05 Oct 2017, 16:27 |
|
_shura 05 Oct 2017, 16:33
Yeah, the good old magic numbers of fasm Anyway, it would be more helpful, if I know, what piece of code does what. E.g. where I have to start, if i want to add a feature to source-processing. I am currently program a compiler with fasmg-macros and I had the idea to replace the token-based system of fasmg with some kind of bytecode, that may speed up the compilation by fasmg.
|
|||
05 Oct 2017, 16:33 |
|
kerr 05 Oct 2017, 16:40
Tomasz Grysztar wrote:
hello about fasm author What order is the step of the FASM compiler source code? _________________ I hope we will be good friends. |
|||
05 Oct 2017, 16:40 |
|
Tomasz Grysztar 05 Oct 2017, 16:52
_shura wrote: Yeah, the good old magic numbers of fasm Anyway, it would be more helpful, if I know, what piece of code does what. E.g. where I have to start, if i want to add a feature to source-processing. I am currently program a compiler with fasmg-macros and I had the idea to replace the token-based system of fasmg with some kind of bytecode, that may speed up the compilation by fasmg. |
|||
05 Oct 2017, 16:52 |
|
_shura 05 Oct 2017, 17:06
depends on the design of the bytecode. But you said, that long macros are slow, because the assembler has to process e.g. the code in an if-statement, even if this path is not used in an specific macro-call. But with bytecode, you just can put the content of it in another memory and it does not get touched, if the statement is false:
Code: macro foo bar if ( bar = 0 ) ;some long code else if ( bar = 1 ) ;also long code else ;even longer code end if ;always do this end macro can be transformed to some bytecode like this: Code: _0: ;some long code done _1: ;also long code done _2: ;even longer code done _3: push 0 ;argument 0 pushArgument push 1 compare push _1 push _2 branch done _macro_foo: push 0 ;argument 0 pushArgument push 0 compare push _0 push _3 branch ;always do this done at least it may speed up huge macros |
|||
05 Oct 2017, 17:06 |
|
Tomasz Grysztar 05 Oct 2017, 17:10
_shura wrote: depends on the design of the bytecode. But you said, that long macros are slow, because the assembler has to process e.g. the code in an if-statement, even if this path is not used in an specific macro-call. But with bytecode, you just can put the content of it in another memory and it does not get touched, if the statement is false: What you proposed sounds very much like that "middle ground" assembler I mentioned earlier. At the time I finished the core features of fasmg I believed it would be possible to design and implement one, but it would be nowhere near as flexible as fasmg is. |
|||
05 Oct 2017, 17:10 |
|
Tomasz Grysztar 05 Oct 2017, 17:29
BTW, the optimization that you proposed is possible to do simply at the level of macro definition in fasmg. If you rewrite the macro this way:
Code: macro foo bar if ( bar = 0 ) _1 else if ( bar = 1 ) _2 else _3 end if |
|||
05 Oct 2017, 17:29 |
|
_shura 05 Oct 2017, 17:32
Well, thats true of course, did not think about that.
But what about allowing some kind of preprocessed files with limited capabilities. The changes, that must be done in assembl_pass are obvious, I just have to add a check for a magic-number at the beginning of the includes source-file, but where can I add macros and strucs to the current/root namespace? this does not need access to other symbols than macros/strucs, because setting internal variables/flags of the included file can simply be done with macro-calls. So in the end, there are 3 different types of macros: internal macros like ›display‹ (fast), custom macros (slow) and preprocessed macros, that do not have the full capabilities, but are good enough for most purposes, like encoding x86-instructions. The addition of an ›format preprocessed‹ to create such files should be trivial. Last edited by _shura on 05 Oct 2017, 17:37; edited 1 time in total |
|||
05 Oct 2017, 17:32 |
|
Tomasz Grysztar 05 Oct 2017, 17:36
_shura wrote: But what about allowing some kind of preprocessed files with limited capabilities. The changes, that must be done in assembl_pass are obvious, I just have to add a check for a magic-number at the beginning of the includes source-file, but where can I add macros and strucs to the current/root namespace? this does not need access to other symbols than macros/strucs, because setting internal variables/flags of the included file can simply be done with macro-calls. So in the end, there are 3 different types of macros: internal macros like ›display‹ (fast), custom macros (slow) and preprocessed macros, that do not have the full capabilities, but are good enough for most purposes, like encoding x86-instructions. |
|||
05 Oct 2017, 17:36 |
|
_shura 05 Oct 2017, 17:41
Well, you just could explain more about the internals of fasmg, so I can try a first attempt.
|
|||
05 Oct 2017, 17:41 |
|
Tomasz Grysztar 05 Oct 2017, 19:38
_shura wrote: Well, you just could explain more about the internals of fasmg, so I can try a first attempt. As for pre-compiling macro contents, the easiest first try would be to replace initial symbol in macro line with "." enclosed within a context linking directly to the symbol that the name meant at the time when macro was defined. The same trick is currently used by IRPV to create a symbolic value representing a link to a hidden proxy symbol. This would require relatively small additions to current code but could nonetheless give some improvement in speed, though probably not that much. The token that switches name recognition context is described in the design notes (I gave a link to it earlier). I later changed it so that it simply contains RecognitionContext structure after the initial byte 40h. The "current_label" field can be used to point to a pre-identified symbol and then "." token is going to point to this symbol directly, with no name lookup involved. You could try to change most of the symbols inside macro to such links, but you'd have to be careful to not touch parameters. Recently I was working on something very different in the fasmg internals - I made a branch in the repository called "lowmem" as it has a much smaller memory footprint when using macros that do not have local parameters (like my x86 macros). The memory requirements for self-hosting became 12 MB instead of 70 MB, but unfortunately this new variant is slightly slower. I managed to bring its performance to be almost on par with the trunk, but there is still a small difference. Nonetheless I invite anyone willing to try it on other machines to check it out. It may remain more of a curiosity though, just a special variant for self-hosting on my DOS machine with little RAM. |
|||
05 Oct 2017, 19:38 |
|
Tomasz Grysztar 05 Oct 2017, 20:41
I have an even simpler idea for the first approach to the symbol linking I mentioned above. We could tweak the ESC directive and create a variant that would identify all symbols and replace them with links and then append such line to the macro. This would be completely self-contained (would require no modifications to other parts of fasmg, just a new directive handler analogous to the "escape_directive" one). Then we could insert this directive at the start of lines in macros we would like to have "pre-compiled" and see what kind of a boost this provides.
|
|||
05 Oct 2017, 20:41 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.