Wrap the mmap2 syscall
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
||||
# obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
.global _tokenize_next, classification, transitions, keywords, byte_keywords
|
||||
.global lex_next, classification, transitions, keywords, byte_keywords
|
||||
|
||||
.include "boot/definitions.inc"
|
||||
|
||||
@@ -246,7 +246,7 @@ byte_keywords: .ascii "&.,:;()[]^=+-*@"
|
||||
# It specifies the target state. "ff" means that this is an end state and no
|
||||
# transition is possible.
|
||||
# - The next byte is the action that should be performed when transitioning.
|
||||
# For the meaning of actions see labels in the _tokenize_next function, which
|
||||
# For the meaning of actions see labels in the lex_next function, which
|
||||
# handles each action.
|
||||
#
|
||||
.type transitions, @object
|
||||
@@ -318,8 +318,8 @@ transitions:
|
||||
# a0 - Character.
|
||||
#
|
||||
# Sets a0 to the class number.
|
||||
.type _classify, @function
|
||||
_classify:
|
||||
.type classify, @function
|
||||
classify:
|
||||
la t0, classification
|
||||
add t0, t0, a0 # Character class pointer.
|
||||
lbu a0, (t0) # Character class.
|
||||
@@ -332,8 +332,8 @@ _classify:
|
||||
# a1 - Character class.
|
||||
#
|
||||
# Sets a0 to the next state.
|
||||
.type _lookup_state, @function
|
||||
_lookup_state:
|
||||
.type lookup_state, @function
|
||||
lookup_state:
|
||||
li t0, CLASS_COUNT
|
||||
mul a0, a0, t0 # Transition row.
|
||||
add a0, a0, a1 # Transition column.
|
||||
@@ -347,7 +347,7 @@ _lookup_state:
|
||||
|
||||
ret
|
||||
|
||||
# Chains _classify and _lookup_state.
|
||||
# Chains classify and lookup_state.
|
||||
#
|
||||
# Parameters:
|
||||
# a0 - Current state.
|
||||
@@ -364,11 +364,11 @@ _next_state:
|
||||
|
||||
sw a0, 4(sp)
|
||||
mv a0, a1
|
||||
call _classify
|
||||
call classify
|
||||
|
||||
mv a1, a0
|
||||
lw a0, 4(sp)
|
||||
call _lookup_state
|
||||
call lookup_state
|
||||
|
||||
# Epilogue.
|
||||
lw ra, 12(sp)
|
||||
@@ -383,8 +383,8 @@ _next_state:
|
||||
# a1 - Token pointer.
|
||||
#
|
||||
# Sets a0 to the appropriate token type.
|
||||
.type _classify_identifier, @function
|
||||
_classify_identifier:
|
||||
.type classify_identifier, @function
|
||||
classify_identifier:
|
||||
# Prologue.
|
||||
addi sp, sp, -16
|
||||
sw ra, 12(sp)
|
||||
@@ -413,8 +413,8 @@ _classify_identifier:
|
||||
# a0 - Token character.
|
||||
#
|
||||
# Sets a0 to the appropriate token type.
|
||||
.type _classify_single, @function
|
||||
_classify_single:
|
||||
.type classify_single, @function
|
||||
classify_single:
|
||||
# Prologue.
|
||||
addi sp, sp, -16
|
||||
sw ra, 12(sp)
|
||||
@@ -443,8 +443,8 @@ _classify_single:
|
||||
# a1 - Token pointer.
|
||||
#
|
||||
# Sets a0 to the appropriate token type.
|
||||
.type _classify_composite, @function
|
||||
_classify_composite:
|
||||
.type classify_composite, @function
|
||||
classify_composite:
|
||||
lbu t0, 0(a1)
|
||||
li t1, ':'
|
||||
beq t0, t1, .Lclassify_composite_assign
|
||||
@@ -465,8 +465,8 @@ _classify_composite:
|
||||
# a1 - A pointer for output value, the token kind. 4 Bytes.
|
||||
#
|
||||
# Sets a0 to the position of the next token.
|
||||
.type _tokenize_next, @function
|
||||
_tokenize_next:
|
||||
.type lex_next, @function
|
||||
lex_next:
|
||||
# Prologue.
|
||||
addi sp, sp, -32
|
||||
sw ra, 28(sp)
|
||||
@@ -484,7 +484,7 @@ _tokenize_next:
|
||||
sw a1, 0(sp)
|
||||
sw zero, (a1) # Initialize.
|
||||
|
||||
.Ltokenize_next_loop:
|
||||
.Llex_next_loop:
|
||||
mv a0, s2
|
||||
lbu a1, (s1)
|
||||
call _next_state
|
||||
@@ -498,50 +498,50 @@ _tokenize_next:
|
||||
|
||||
# Perform the provided action.
|
||||
li t0, 0x01 # Accumulate action.
|
||||
beq t1, t0, .Ltokenize_next_accumulate
|
||||
beq t1, t0, .Llex_next_accumulate
|
||||
|
||||
li t0, 0x02 # Print action.
|
||||
beq t1, t0, .Ltokenize_next_print
|
||||
beq t1, t0, .Llex_next_print
|
||||
|
||||
li t0, 0x03 # Skip action.
|
||||
beq t1, t0, .Ltokenize_next_skip
|
||||
beq t1, t0, .Llex_next_skip
|
||||
|
||||
li t0, 0x04 # Delimited string action.
|
||||
beq t1, t0, .Ltokenize_next_comment
|
||||
beq t1, t0, .Llex_next_comment
|
||||
|
||||
li t0, 0x05 # Finalize identifier.
|
||||
beq t1, t0, .Ltokenize_next_identifier
|
||||
beq t1, t0, .Llex_next_identifier
|
||||
|
||||
li t0, 0x06 # Single character symbol action.
|
||||
beq t1, t0, .Ltokenize_next_single
|
||||
beq t1, t0, .Llex_next_single
|
||||
|
||||
li t0, 0x07 # An action for symbols containing multiple characters.
|
||||
beq t1, t0, .Ltokenize_next_composite
|
||||
beq t1, t0, .Llex_next_composite
|
||||
|
||||
li t0, 0x08 # Integer action.
|
||||
beq t1, t0, .Ltokenize_next_integer
|
||||
beq t1, t0, .Llex_next_integer
|
||||
|
||||
j .Ltokenize_next_reject
|
||||
j .Llex_next_reject
|
||||
|
||||
.Ltokenize_next_reject:
|
||||
.Llex_next_reject:
|
||||
addi s1, s1, 1
|
||||
|
||||
j .Ltokenize_next_end
|
||||
j .Llex_next_end
|
||||
|
||||
.Ltokenize_next_accumulate:
|
||||
.Llex_next_accumulate:
|
||||
addi s1, s1, 1
|
||||
|
||||
j .Ltokenize_next_loop
|
||||
j .Llex_next_loop
|
||||
|
||||
.Ltokenize_next_skip:
|
||||
.Llex_next_skip:
|
||||
addi s1, s1, 1
|
||||
lw t0, 12(sp)
|
||||
addi t0, t0, 1
|
||||
sw t0, 12(sp)
|
||||
|
||||
j .Ltokenize_next_loop
|
||||
j .Llex_next_loop
|
||||
|
||||
.Ltokenize_next_print:
|
||||
.Llex_next_print:
|
||||
/* DEBUG
|
||||
addi a0, a0, 21
|
||||
sw a0, 0(sp)
|
||||
@@ -549,49 +549,49 @@ _tokenize_next:
|
||||
li a1, 1
|
||||
call _write_error */
|
||||
|
||||
j .Ltokenize_next_end
|
||||
j .Llex_next_end
|
||||
|
||||
.Ltokenize_next_comment:
|
||||
.Llex_next_comment:
|
||||
addi s1, s1, 1
|
||||
|
||||
j .Ltokenize_next_end
|
||||
j .Llex_next_end
|
||||
|
||||
.Ltokenize_next_identifier:
|
||||
.Llex_next_identifier:
|
||||
# An identifier can be a textual keyword.
|
||||
# Check the kind of the token and write it into the output parameter.
|
||||
lw a1, 12(sp)
|
||||
sub a0, s1, a1
|
||||
sw a0, 8(sp)
|
||||
call _classify_identifier
|
||||
call classify_identifier
|
||||
sw a0, 4(sp)
|
||||
lw a0, 0(sp)
|
||||
addi a1, sp, 4
|
||||
li a2, 12
|
||||
call _memcpy
|
||||
|
||||
j .Ltokenize_next_end
|
||||
j .Llex_next_end
|
||||
|
||||
.Ltokenize_next_single:
|
||||
.Llex_next_single:
|
||||
lw a0, 12(sp)
|
||||
addi s1, a0, 1
|
||||
lbu a0, (a0)
|
||||
call _classify_single
|
||||
call classify_single
|
||||
lw a1, 0(sp)
|
||||
sw a0, (a1)
|
||||
|
||||
j .Ltokenize_next_end
|
||||
j .Llex_next_end
|
||||
|
||||
.Ltokenize_next_composite:
|
||||
.Llex_next_composite:
|
||||
addi s1, s1, 1
|
||||
lw a1, 12(sp)
|
||||
sub a0, s1, a1
|
||||
call _classify_composite
|
||||
call classify_composite
|
||||
lw a1, 0(sp)
|
||||
sw a0, (a1)
|
||||
|
||||
j .Ltokenize_next_end
|
||||
j .Llex_next_end
|
||||
|
||||
.Ltokenize_next_integer:
|
||||
.Llex_next_integer:
|
||||
lw t0, 0(sp)
|
||||
li t1, TOKEN_INTEGER
|
||||
sw t1, 0(t0)
|
||||
@@ -600,9 +600,9 @@ _tokenize_next:
|
||||
sub t1, s1, t1
|
||||
sw t1, 4(t0)
|
||||
|
||||
j .Ltokenize_next_end
|
||||
j .Llex_next_end
|
||||
|
||||
.Ltokenize_next_end:
|
||||
.Llex_next_end:
|
||||
mv a0, s1 # Return the advanced text pointer.
|
||||
|
||||
# Restore saved registers.
|
||||
|
Reference in New Issue
Block a user