flat assembler
Message board for the users of flat assembler.
Index
> Compiler Internals > Feature req: Export constants to file |
Author |
|
AlexP 21 Jun 2008, 15:00
It's an interesting idea, I'm not sure of many practical uses of it though. So your idea is to has certain constants be written to a file at compile time? It could possibly be used for assembling log files... Such as when you assemble any program with FASM, it would (opitionally) drop a file in the same dir that says things like '3 passes, xxx seconds, any bugs...' or whatever is usually outputted to the console.
I think it's a great idea now that I think of those uses, fairly simple to implement the non-macro side of it (stick a little routine in FASM source before assembling?). I do not wish to do this project myself, but it would be a very nice little addition for those who want it. Example command-line?: C:\> FASM.exe Program.asm Program.exe /l LogFile.txt New command option, '/l' is followed by a file to output the buffers to instead of the console. |
|||
21 Jun 2008, 15:00 |
|
TNick 21 Jun 2008, 16:01
Hello, Alex!
The practical use is, for example, that you may build individual pices of a ... well.. let's call it a distribution for OS. Long talk ... Or, when you define a set of constants (a structure) where each element's position and size may depend on size of previously defined elements in structure and on outside elements. I end up defining macros for this purpose. But you may want to export a clean set of constants like: Code: Str1.el1 = 0x1000 Str1.el2 = 0x1235 So, you see, I was thinking about a file that may be latter passes as include to the assembler. However, since I was stuck, I start reading the FASM source code, found the SYMBDUMP here, read that, too (this was the great help), and now I am almost ready to post the way you can modify source code to export those constants. I just want to add support for conditional export. Ready untill now: - inserted "expform" keyword in FASM, to let you tell the format of the export (include file or source file for Labelmaster-Olly) and option to export all labels or just those that are marked. Something like this: Code: ExpForm olly,all,"Filename.someext" ExpForm none ExpForm incl,all ExpForm incl,mark ExpForm olly,mark Still, this is rudimentary, 'couse you can use this just once (infact, only the last one is used). To mark which constant to export, you will have to insert a macro in your source code with onne argument: the label that you want to export. This will be added to a "pattern" string (something like E_X_P_L_B_L____). When is to export the label, if option is on, the pattern is searched in label name. It is only exported if the pattern is found (withoput the pattern, of course). <--I'm not really proud of this, but, until I will have a better understanding of FASM source code, this is all I could came up with... But, as I said, in some hours I will post it all. About your idea: - I guess you know there is a snippet to generate a listing - to store console output in a file.. that isn't that hard, either. There are 3 functions that display something, if I recall correctly. The problem, I think, is with memory that you have to get it in fixed size at program start. So, if the output is longer, you will simply lost it. Nick P.S.: Damn, it was easier to write the code than to explain it... |
|||
21 Jun 2008, 16:01 |
|
AlexP 21 Jun 2008, 16:58
Wow, that's a very nice idea. It could really help with chained projects, but are there any things that could go wrong with it . For example, you compile the main file of ... let's use your example, an OS. One file is compiled (the constants are written to another file), the next file is compiled automatically, and so on... But will the file be guaranteed to be written by the time the next file is pre-processed? You should make a few example files to demonstrate the rigidity of that idea.
It is a very nice idea Nick, and I hope it will work (maybe even get put into a future FASM release if it finds enough supporters). I guess it would work quite nice if you put your routine at the start of the pre-processor or something to ensure it will be there when the next file is grabbed. Good luck! |
|||
21 Jun 2008, 16:58 |
|
TNick 22 Jun 2008, 06:48
Ok. Here it is. This may clarify all.
There are many infos in the file, but here is a general layout: First thing first: in order to build this feature in FASM, you have to INCLUDE this file in FASM.ASM. Second, you have to modify TABLES.INC by inserting: Code: db 7,'expform' dw define_export-preprocessor in preprocessor_directives. Note that entries must be sorted. A call ExportConst must be inserted in fasm.asm, just after the call assembler and before the call formatter Now assemble new fasm for your os, and we're there. USAGE: Your old sources will be assembled without any diffrence. Nothing new will happen unless you insert a ExpForm directive. This may take up to 3 arguments: - first one must be the format that you expect: olly format (olly) will place hex values in file, a tab and label's name; include format (incl) will generate a file that can be interpreted by fasm, having the label, spaces, a = and 0xhex value) - second, you may tell if all labels should be exported (all) or only those that are marked (mark) - to see how to mark them, see below. -third, the file path (optional) and name of output file. It would be a nice thing to enclose this in quotes. You may place this directive anywhere you want. Note that it will follow same rules as "macro" or "struct". Here are some examples of use: Code: ExpForm olly,all ExpForm olly,mark ExpForm olly,all,"L_A_B_E_L_S.inc" ExpForm none ExpForm incl ExpForm incl,mark ExpForm incl,all ExpForm incl,mark,"L_A_B_E_L_S.inc" If an invalid string is placed at one argument's position, a warning will be shown and there will be no output. If multiple ExpForm are found while preprocessing, only the last one will be used to format the output. To mark a symbol for export (so that it will be exported when you use (mark) in second argument for ExpForm), this string Quote: E_X_P_O_R_T__1234567____________ Code: macro ExportConst Constname* { E_X_P_O_R_T__1234567____________ # Constname = Constname } and, then: Code: myVar01 = 10 ... ExportConst myVar01 I will value your input and test results. Let me know if there are any problems with this. Nick
|
|||||||||||
22 Jun 2008, 06:48 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.