aboutsummaryrefslogtreecommitdiff
path: root/lib/xixanta/src/object.rs
Commit message (Collapse)AuthorAgeFilesLines
* Ignore GLOBAL_CONTEXT on force_context_switch()Miquel Sabaté Solà2026-03-091-0/+6
| | | | Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
* asan: ignore names from macro argumentsMiquel Sabaté Solà2026-03-091-1/+2
| | | | | | | These are usually capitalized, and thus they are not going to be following the usual zp_/m_/wr_ pattern. Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
* Define the global scope to a more obscure nameMiquel Sabaté Solà2026-02-251-1/+1
| | | | | | | | | | | | | | | By how we define scopes, we needed an internal name for the global scope. All the way back to my first commit 587dd5bb8036 ("Initial commit"), I simply picked "Global". That is troublesome, as it can easily be typed by a human. If a programmer writes a scope with "global" definitions via this scope, this can be messed up with nasm's internal Global scope. Change that to a more obscure name for this internal global scope. If a programmer is so dead from the inside that wants to have a scope named like that, so be it. Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
* Warn on pointless (un)conditional branchingMiquel Sabaté Solà2026-02-021-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | Sometimes performing some 'jmp'/'jsr' can be quite pointless, and the programmer might not be fully aware of this because of the layout of the code. Imagine: .proc foo ;; code jmp bar .endproc ;; Documentation, comments, extra space, etc. .proc bar ;; whatever .endproc The 'jmp' in the code above tries to perform a call stack optimization, but it's actually not needed because the next instruction after 'jmp' is the one inside of 'bar', but that's obfuscated because of the layout. In these sort of cases (and also for 'jsr' and branches) warn the programmer about it so it can remove that instruction. Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
* Allow asan:reserve to receive an usizeMiquel Sabaté Solà2025-12-141-1/+1
| | | | | | | This allows for reserving memory regions which go outside of the page boundary. Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
* Add a warning for each unused variableMiquel Sabaté Solà2025-09-021-10/+22
| | | | Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* assembler: Add support for asan:reserve,ignoreMiquel Sabaté Solà2025-09-021-1/+10
| | | | | | | | This is the initial support for both directives for the address sanitizer. Note that asan:weak has been moved into asan:ignore, which is not exactly the same but for now it should suffice. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Provide a node to the Object structMiquel Sabaté Solà2025-08-181-0/+16
| | | | | | | | | This allows the `evaluate_variable` to pull from it in the crunching stage so to evaluate the original node in cases like macro expansion, where the connection between the macro argument and the original caller might have been lost. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Apply suggested style fixes from clippyMiquel Sabaté Solà2025-08-171-4/+4
| | | | Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Properly fill the context stack when forcing itMiquel Sabaté Solà2025-01-101-14/+19
| | | | | | | | | | | | | When calling `force_context_switch` the stack was mindlessly pushing the given name without taking into consideration how scopes are to be laid out. This made some variables/addresses that were previously preserved no longer reachable when crunching pending nodes. This patch also makes `force_context_switch` reset the stack before doing anything at all, which means that `force_context_pop` was no longer relevant. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Improve error message on unknown variable/scopeMiquel Sabaté Solà2025-01-091-1/+1
| | | | Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Implement the .include statementMiquel Sabaté Solà2025-01-091-67/+24
| | | | | | | | | | | | | | This needed some heavy lifting when it comes to how files were located. This means that statements like .include/.incbin now take into consideration a new list made out of SourceInfo, which holds enough information to translate from which file a node comes from. This has also been added into errors, so they are more informative on what went wrong. In order to tests this, besides all the regular unit tests, a new e2e test has been added. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Add the .repeat control statementMiquel Sabaté Solà2025-01-071-3/+10
| | | | | | | | | | | | | | | | | | | | | | | | This is a control statement which acts similarly as .proc/.macro/.scope, in which an inner block is allocated for it. Hence, all the previous work from 1f8a6becc7cd ("parser: Implement block bodies") and ec8b709fa24c ("Implement block bodies inside of the assembler") make this one out possible, as .repeat statements don't have an identifier that can be used for hashing. From the parser perspective this introduction raises two new things. First of all this control statement also needed a differentiation between the amount of required arguments, and the allowed ones, since there is a second optional argument to it. And second, even the identifier is not given, we have to generate one so to add a context for it. This was at first not needed, but introducing .repeat-only variables means that we have to have inner contexts which need to be named somehow so we can retrieve the context later when picking up the value for them again. This last thing brought the need for a new dependency: rand. This is used to generate a random string to identify the .repeat block. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Store a reference for macros instead of an indexMiquel Sabaté Solà2025-01-071-1/+1
| | | | | | | | | | | | | | | | | It is not safe to store a node index for macros since the list of nodes that is passed down during assembly might change depending on whether an inner block is being evaluated. Hence, the previous implementation would break on a simple macro call inside of a .proc. This also raised some concerns on the design around the API, since the lifetime of references for internal assembler data needed an explicit lifetime now, and as a side-effect functions like `assemble` had to be moved out of the inner impl Assembler. This is in retrospect also a better design choice. Fixes: ec8b709fa24c ("Implement block bodies inside of the assembler"). Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Implement block bodies inside of the assemblerMiquel Sabaté Solà2025-01-051-14/+10
| | | | | | | | | | | Following 1f8a6becc7cd ("parser: Implement block bodies"), the support for the new way of managing block bodies have also been added into the assembler. There are still some things to iron out, but they will be fixed in later commits. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Find variable values on parent scopesMiquel Sabaté Solà2024-12-201-12/+65
| | | | | | | If a given variable cannot be found on the current scope, attempt to go up the context hierarchy to find it. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* assembler: Implement and add tests for operatorsMiquel Sabaté Solà2024-12-191-0/+35
| | | | Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Add support for jumping into .proc'sMiquel Sabaté Solà2024-12-181-1/+1
| | | | | | | | Up until now defining a proc only involved pushing/popping the context. Here we also allow it to create a label so it can be referenced by instructions like jsr. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Remove unneeded Ok callMiquel Sabaté Solà2024-12-181-1/+1
| | | | | | Fixes: 03dae41b2ec2 ("Prevent addresses which are out of bounds") Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Prevent addresses which are out of boundsMiquel Sabaté Solà2024-12-181-7/+29
| | | | | | | | | | In some bad scenarios addresses might be pointing out of bounds (e.g. a reference further than 0xFFFF). This has to be avoided and through fuzzy testing we even got Rust panics for out of bounds u16 arithmetic. Hence, just go through usize for the actual computation and check with u16::MAX. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Fix the mapping of addresses on labelsMiquel Sabaté Solà2024-12-161-0/+418
There was a big missunderstanding on how things were to be laid out in the end file, and so it was needed to create a proper understanding on what's a Mapping and what's a Segment. These turned out to be fundamental concepts that I failed to grok up until this commit. Hence, this commit re-arranges completely how variables and labels are stored in the Context, and how these objects can then be translated into bundles that can be spit out to the caller. This commit, besides introducing the new Mapping struct, also introduced a more general Object, which abstracts things from the Bundle struct, and allows us to pass certain metadata about the bundle at hand. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>