summaryrefslogtreecommitdiff
path: root/usr.bin/oasm/include
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-07-23 18:38:09 -0400
committerIan Moffett <ian@osmora.org>2025-07-23 18:47:57 -0400
commit729a19a6b7e636a8af3a15f7fe5204cc0d59dbf7 (patch)
tree9dc5dbacd0576f1aa369e9442f442e6a117865bc /usr.bin/oasm/include
parentf9a78caefd6f254e854fd6cdf64a8642ccddc34e (diff)
oasm: Add initial support for labels
A label is like a pin on a map with a number attached to it. OASM keeps track of a number referred to as the psuedo instruction pointer (PIP). This value is initially zero by default and is incremented every instruction. The purpose of this value is to pin a location in the code and mark it to be at a specific address so that further references to that label would be translated to the previous PIP value at the time of encountering the label. Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'usr.bin/oasm/include')
-rw-r--r--usr.bin/oasm/include/oasm/lex.h1
-rw-r--r--usr.bin/oasm/include/oasm/state.h4
2 files changed, 5 insertions, 0 deletions
diff --git a/usr.bin/oasm/include/oasm/lex.h b/usr.bin/oasm/include/oasm/lex.h
index 62183e0..69e50a1 100644
--- a/usr.bin/oasm/include/oasm/lex.h
+++ b/usr.bin/oasm/include/oasm/lex.h
@@ -103,6 +103,7 @@ typedef enum {
TT_INC, /* 'inc' */
TT_DEC, /* 'dec' */
TT_IMM, /* #<n> */
+ TT_LABEL, /* 'label: ...' */
/* Register sets */
__XN_REGS, /* x0-x15 */
diff --git a/usr.bin/oasm/include/oasm/state.h b/usr.bin/oasm/include/oasm/state.h
index 5f58144..6dd2435 100644
--- a/usr.bin/oasm/include/oasm/state.h
+++ b/usr.bin/oasm/include/oasm/state.h
@@ -39,6 +39,8 @@
* OASM state:
*
* @filename: Filname of unit we are parsing
+ * @pip: Pseudo instruction pointer
+ * @label_ip: IP at current label start
* @in_fd: Input file descriptor
* @out_fd: Resulting binary output file descriptor
* @line: Current line number
@@ -46,6 +48,8 @@
*/
struct oasm_state {
char *filename;
+ off_t pip;
+ off_t label_ip;
int in_fd;
int out_fd;
off_t line;