| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
|
|
|
|
|
|
|
|
|
|
| |
The handling of labels and proc's both when evaluating the context and
when bundling is almost identical. The only change is that proc's need
to change the context afterwards, but otherwise they need to create a
label just as regular ones.
Merge things as much as possible on both these cases, while also taking
the chance to do some much needed clean up around these areas, and
adding a bit of helpful comments in between.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
| |
Failing to do so would spill over the previous literal mode into the
evaluation of nodes pending to be crunched.
Fixes: a9f50efdef40 ("Fix label references on control statements")
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
| |
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>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
| |
They were named with increasing numbers due to the fact that that's the
default behaviour from cargo fuzz's command. So, just rename them to
proper human-readable names.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
| |
When evaluating binary literals we allowed the shift value to grow as
needed and we checked whether it was a good value after evaluating the
literal. This is bad for performance reasons: if we are expecting an
exact size for a literal (8 digits here), do not even attempt to do
anything at all if the size doesn't match.
Moreover, in some extreme cases this could result into an overflow of
the 'shift' variable, which was promptly catched by Rust's bound
checker.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
| |
Some of the functions are actually private, so don't export them.
Moreover, there was an import cycle which was not needed and was forcing
a public import. Remove that as well.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
|
|
| |
This function originally came from the naive idea I had with how
mappings and segments ought to work. For this reason, the function grew
more ever more complex.
Split this function into more clear responsabilities for each new
function.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
| |
These two enum values were actually never used and they are not relevant
for the assembling process. Let's remove it for simplicity's sake.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
| |
Fixes: 03dae41b2ec2 ("Prevent addresses which are out of bounds")
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
|
| |
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>
|
| |
|
|
|
|
|
|
|
|
| |
This never quite worked and since multiple re-writes of the
assembler/parser it was even commented out. Moreover, this functionality
appears to be more suitable to the new `readrom` binary introduced in
commit 407048d0037c ("Add the readrom binary"). Hence, just remove this
altogether.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
| |
Having a From<std::io::Error> came from a hacky beginning in which
std::io::Error was being abused. Now the error handling is saner, so
there's no more need for that.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The readrom binary is similar to `readelf` from Linux and it will allow
to display information from an NES/Famicom ROM file. For now the
information being shown is just the header, but in the future we might
also include disassembling parts of the code, or retrieving the "CHARS"
section for a given ROM file, and similar.
In order to implement the header parsing part a new library has been
introduced, simply named "header" which abstracts everything away so you
just need to call `Header::try_from("my bytes")` to fetch the actual
information.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
|
|
|
|
| |
If the given char literal was not an ASCII one, there was the chance for
the character iterator to mess things up. Hence, when checking the
closing single quote, it might encounter a None value.
This is simply mitigated my moving the check of ASCII alphanumeric
before checking for the closing quote.
Fixes: b1623996c76f ("Add support for character literals")
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
| |
There were a lot of assumptions on the assembler that stemmed from a
fundamental missunderstanding from my side on how segments are laid out
on the final file. This commit is the first step to address this.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
| |
Allow for anonymous labels to be defined and referenced by using the
same syntax as cc65.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
| |
Instead, use a new enum type to identify the control statements that we
actually support. This way the assembler is more easily aware on the
control that it's dealing with, and can be more sure on certain aspects
of the implementation on control support.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
|
|
| |
As a way to firstly adapt on the latest changes from the parser since
184c39579227 ("Re-work the parser from scratch"), the assembler had to
leave out some features on 16114b2ca358 ("Adapt the assembler to the
changes on the parser"). This commit reintroduces support for settings
labels, variables and referencing them, while also providing a more
robust implementation at that.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
|
|
| |
As of 184c39579227 ("Re-work the parser from scratch") the parser has a
proper AST, and the assembler has to traverse it accordingly.
Moreover, the assembler has been stripped from a lot of unneeded memory
allocations and it's overall more keen on using mere references when
possible.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
| |
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
|
|
|
|
|
| |
The initial implementation was incredibly naive on how complex an
assembler can actually be. Because of this, it never bothered to define
and produce a proper AST, and hence it was overall extremely fragile on
(not so) corner cases.
This commit re-writes everything from scratch for the parser, and it
should really be the last fundamental change to the parser other than
minor additions/features here and there.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
| |
Adds to 5b1f387d451b ("Add basic support for macros") the possibility to
add parameters to macros.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
| |
Macros can now be described with the '.macro' control statement, but no
parameters can be given and it's overall pretty brittle.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
| |
Procedures are marked with the '.proc' control statement and work both
as a scoping mechanism and as a label that can be referenced.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
|
| |
This is a bare bones implementation of it, and there's a lot of nuance
that it's being missed, but at least the fundamentals have been
implemented already.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
| |
|
|
|
|
|
| |
Mappings and segments are fundamental blocks on how code is distributed
both on the actual ROM File and in the memory layout.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|
|
|
A lot is missing and there is a long road ahead to make the assembler
even work.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
|