Add semicolons separating the statements
This commit is contained in:
parent
23b7a1ab30
commit
f3a8b2626a
33
Rakefile
33
Rakefile
@ -66,36 +66,3 @@ end
|
||||
file 'build/stage2b' => ['build/stage2b.s', 'boot/common-boot.s'] do |t|
|
||||
sh CROSS_GCC, '-nostdlib', '-o', t.name, *t.prerequisites
|
||||
end
|
||||
|
||||
desc 'Print remaining lines to rewrite'
|
||||
task :statistics do
|
||||
def is_false_positive(word)
|
||||
word.start_with?('(*') ||
|
||||
word.start_with?('*)') ||
|
||||
('A'..'Z').include?(word[0]) ||
|
||||
/^[[:alpha:]][[:digit:]]$/.match(word) ||
|
||||
['end', 'if'].include?(word)
|
||||
end
|
||||
|
||||
lines = File.read('boot/stage2.elna')
|
||||
.split("\n")
|
||||
.select { |line| line.start_with? "\t" }
|
||||
.map { |line| line.delete_prefix("\t").split(' ') }
|
||||
.reject { |words| is_false_positive(words.first) }
|
||||
.group_by do |words|
|
||||
if words.first.length < 5
|
||||
case words.first
|
||||
when 'goto'
|
||||
'Statements'
|
||||
else
|
||||
words.first
|
||||
end
|
||||
else
|
||||
'Statements'
|
||||
end
|
||||
end
|
||||
|
||||
lines.each do |key, value|
|
||||
puts "#{key}: #{value.count}"
|
||||
end
|
||||
end
|
||||
|
@ -1,6 +1,6 @@
|
||||
.global _is_alpha, _is_digit, _is_alnum, _is_upper, _is_lower
|
||||
.global _write_out, _read_file, _write_error, _put_char, _printi
|
||||
.global _get, _memcmp
|
||||
.global _get, _memcmp, _memchr, _memmem, _memcpy
|
||||
.global _divide_by_zero_error, _exit
|
||||
|
||||
.section .rodata
|
||||
@ -16,7 +16,8 @@ new_line: .ascii "\n"
|
||||
|
||||
.section .text
|
||||
|
||||
# Write the current token to stderr.
|
||||
# Write the current token to stderr. Ends the output with a newline.
|
||||
#
|
||||
# a0 - String pointer.
|
||||
# a1 - String length.
|
||||
.type _write_error, @function
|
||||
@ -306,3 +307,120 @@ _put_char:
|
||||
_get:
|
||||
lw a0, (a0)
|
||||
ret
|
||||
|
||||
# Searches for the occurences of a character in the given memory block.
|
||||
#
|
||||
# Parameters:
|
||||
# a0 - Memory block.
|
||||
# a1 - Needle.
|
||||
# a2 - Memory size.
|
||||
#
|
||||
# Sets a0 to the pointer to the found character or to null if the character
|
||||
# doesn't occur in the memory block.
|
||||
.type _memchr, @function
|
||||
_memchr:
|
||||
.Lmemchr_loop:
|
||||
beqz a2, .Lmemchr_nil # Exit if the length is 0.
|
||||
|
||||
lbu t0, (a0) # Load the character from the memory block.
|
||||
beq t0, a1, .Lmemchr_end # Exit if the character was found.
|
||||
|
||||
# Otherwise, continue with the next character.
|
||||
addi a0, a0, 1
|
||||
addi a2, a2, -1
|
||||
|
||||
j .Lmemchr_loop
|
||||
|
||||
.Lmemchr_nil:
|
||||
li a0, 0
|
||||
|
||||
.Lmemchr_end:
|
||||
ret
|
||||
|
||||
# Locates a substring.
|
||||
#
|
||||
# Parameters:
|
||||
# a0 - Haystack.
|
||||
# a1 - Haystack size.
|
||||
# a2 - Needle.
|
||||
# a3 - Needle size.
|
||||
#
|
||||
# Sets a0 to the pointer to the beginning of the substring in memory or to 0
|
||||
# if the substring doesn't occur in the block.
|
||||
.type _memmem, @function
|
||||
_memmem:
|
||||
# Prologue.
|
||||
addi sp, sp, -24
|
||||
sw ra, 20(sp)
|
||||
sw s0, 16(sp)
|
||||
addi s0, sp, 24
|
||||
|
||||
# Save preserved registers. They are used to keep arguments.
|
||||
sw s1, 12(sp)
|
||||
sw s2, 8(sp)
|
||||
sw s3, 4(sp)
|
||||
sw s4, 0(sp)
|
||||
|
||||
mv s1, a0
|
||||
mv s2, a1
|
||||
mv s3, a2
|
||||
mv s4, a3
|
||||
|
||||
.Lmemmem_loop:
|
||||
blt s2, s3, .Lmemmem_nil # Exit if the needle length is greater than memory.
|
||||
|
||||
mv a0, s1
|
||||
mv a1, s3
|
||||
mv a2, s4
|
||||
call _memcmp
|
||||
|
||||
mv t0, a0 # memcmp result.
|
||||
mv a0, s1 # Memory pointer for the case the substring was found.
|
||||
beqz t0, .Lmemmem_end
|
||||
|
||||
addi s1, s1, 1
|
||||
add s2, s2, -1
|
||||
|
||||
j .Lmemmem_loop
|
||||
|
||||
.Lmemmem_nil:
|
||||
li a0, 0
|
||||
|
||||
.Lmemmem_end:
|
||||
|
||||
# Restore the preserved registers.
|
||||
lw s1, 12(sp)
|
||||
lw s2, 8(sp)
|
||||
lw s3, 4(sp)
|
||||
lw s4, 0(sp)
|
||||
|
||||
# Epilogue.
|
||||
lw ra, 20(sp)
|
||||
lw s0, 16(sp)
|
||||
add sp, sp, 24
|
||||
ret
|
||||
|
||||
# Copies memory.
|
||||
#
|
||||
# Parameters:
|
||||
# a0 - Destination.
|
||||
# a1 - Source.
|
||||
# a2 - Size.
|
||||
#
|
||||
# Preserves a0.
|
||||
.type _memcpy, @function
|
||||
_memcpy:
|
||||
mv t0, a0
|
||||
|
||||
.Lmemcpy_loop:
|
||||
beqz a2, .Lmemcpy_end
|
||||
|
||||
lbu t1, (a1)
|
||||
sb t1, (a0)
|
||||
|
||||
addi a0, a0, 1
|
||||
addi a1, a1, 1
|
||||
|
||||
.Lmemcpy_end:
|
||||
mv a0, t0
|
||||
ret
|
||||
|
238
boot/stage1.s
238
boot/stage1.s
@ -207,11 +207,66 @@ _build_binary_expression:
|
||||
addi sp, sp, 32
|
||||
ret
|
||||
|
||||
# Checks whether the given identifier starts with "loca".
|
||||
# Parameters:
|
||||
# a0 - Pointer to the identifier.
|
||||
# a1 - Identifier length.
|
||||
#
|
||||
# Sets a0 to 1 if the identifier starts with "loca", otherwise to 0.
|
||||
.type _is_local_identifier, @function
|
||||
_is_local_identifier:
|
||||
# Prologue.
|
||||
addi sp, sp, -16
|
||||
sw ra, 12(sp)
|
||||
sw s0, 8(sp)
|
||||
addi s0, sp, 16
|
||||
|
||||
li t0, 0x61636f6c # loca
|
||||
sw t0, 4(sp)
|
||||
# a0 is already set.
|
||||
addi a1, sp, 4
|
||||
li a2, 4
|
||||
call _memcmp
|
||||
seqz a0, a0
|
||||
|
||||
# Epilogue.
|
||||
lw ra, 12(sp)
|
||||
lw s0, 8(sp)
|
||||
addi sp, sp, 16
|
||||
ret
|
||||
|
||||
# Checks whether the given identifier is a saved register name, like s1 or s2.
|
||||
# Parameters:
|
||||
# a0 - Pointer to the identifier.
|
||||
# a1 - Identifier length.
|
||||
#
|
||||
# Sets a0 to 1 if the identifier is a preserved register, otherwise to 0.
|
||||
.type _is_register_identifier, @function
|
||||
_is_register_identifier:
|
||||
# Prologue.
|
||||
addi sp, sp, -8
|
||||
sw ra, 4(sp)
|
||||
sw s0, 0(sp)
|
||||
addi s0, sp, 8
|
||||
|
||||
lbu a0, (a0)
|
||||
addi a1, a1, -2
|
||||
seqz a1, a1
|
||||
addi t0, a0, -'s'
|
||||
seqz t0, t0
|
||||
and a0, a1, t0
|
||||
|
||||
# Epilogue.
|
||||
lw ra, 4(sp)
|
||||
lw s0, 0(sp)
|
||||
addi sp, sp, 8
|
||||
ret
|
||||
|
||||
# Parameters:
|
||||
# a0 - Identifier length.
|
||||
# a1 - Register number as character.
|
||||
.type _build_identifier_expression, @function
|
||||
_build_identifier_expression:
|
||||
.type _compile_identifier_expression, @function
|
||||
_compile_identifier_expression:
|
||||
# Prologue.
|
||||
addi sp, sp, -32
|
||||
sw ra, 28(sp)
|
||||
@ -221,22 +276,15 @@ _build_identifier_expression:
|
||||
sw a0, 20(sp) # Identifier length.
|
||||
sw a1, 16(sp) # Register number as character.
|
||||
|
||||
li t0, 0x61636f6c # loca
|
||||
sw t0, 12(sp)
|
||||
mv a0, s1
|
||||
addi a1, sp, 12
|
||||
li a2, 4
|
||||
call _memcmp
|
||||
beqz a0, .Lbuild_identifier_expression_local
|
||||
lw a1, 20(sp)
|
||||
call _is_local_identifier
|
||||
bnez a0, .Lcompile_identifier_expression_local
|
||||
|
||||
lbu a0, (s1)
|
||||
lw t0, 20(sp)
|
||||
addi t0, t0, -2
|
||||
seqz t0, t0
|
||||
addi t1, a0, -'s'
|
||||
seqz t1, t1
|
||||
and t0, t0, t1
|
||||
bnez t0, .Lbuild_identifier_expression_saved
|
||||
mv a0, s1
|
||||
lw a1, 20(sp)
|
||||
call _is_register_identifier
|
||||
bnez a0, .Lcompile_identifier_expression_saved
|
||||
|
||||
# Global identifier.
|
||||
lw t1, 16(sp)
|
||||
@ -258,7 +306,7 @@ _build_identifier_expression:
|
||||
|
||||
lbu a0, (s1)
|
||||
call _is_upper
|
||||
beqz a0, .Lbuild_identifier_expression_end
|
||||
beqz a0, .Lcompile_identifier_expression_end
|
||||
|
||||
lw t1, 16(sp)
|
||||
li t0, 0x0a290061 # a\0)\n
|
||||
@ -274,9 +322,9 @@ _build_identifier_expression:
|
||||
li a1, 12
|
||||
call _write_out
|
||||
|
||||
j .Lbuild_identifier_expression_end
|
||||
j .Lcompile_identifier_expression_end
|
||||
|
||||
.Lbuild_identifier_expression_saved:
|
||||
.Lcompile_identifier_expression_saved:
|
||||
li t0, 0x00202c00 # \0,_
|
||||
lw t1, 16(sp)
|
||||
or t0, t0, t1
|
||||
@ -294,9 +342,9 @@ _build_identifier_expression:
|
||||
li a0, '\n'
|
||||
call _put_char
|
||||
|
||||
j .Lbuild_identifier_expression_end
|
||||
j .Lcompile_identifier_expression_end
|
||||
|
||||
.Lbuild_identifier_expression_local:
|
||||
.Lcompile_identifier_expression_local:
|
||||
lw t1, 16(sp)
|
||||
li t0, 0x00202c00 # \0,_
|
||||
or t0, t0, t1
|
||||
@ -321,9 +369,9 @@ _build_identifier_expression:
|
||||
li a0, '\n'
|
||||
call _put_char
|
||||
|
||||
j .Lbuild_identifier_expression_end
|
||||
j .Lcompile_identifier_expression_end
|
||||
|
||||
.Lbuild_identifier_expression_end:
|
||||
.Lcompile_identifier_expression_end:
|
||||
|
||||
# Epilogue.
|
||||
lw ra, 28(sp)
|
||||
@ -368,7 +416,7 @@ _build_expression:
|
||||
|
||||
lw a0, 20(sp)
|
||||
lw a1, 28(sp)
|
||||
call _build_identifier_expression
|
||||
call _compile_identifier_expression
|
||||
|
||||
j .Lbuild_expression_advance
|
||||
|
||||
@ -455,6 +503,86 @@ _build_expression:
|
||||
addi sp, sp, 40
|
||||
ret
|
||||
|
||||
# Compiles an lvalue.
|
||||
#
|
||||
# Parameters:
|
||||
# a0 - Pointer to the identifier.
|
||||
# a1 - Identifier length.
|
||||
.type _compile_designator_expression, @function
|
||||
_compile_designator_expression:
|
||||
# Prologue.
|
||||
addi sp, sp, -32
|
||||
sw ra, 28(sp)
|
||||
sw s0, 24(sp)
|
||||
addi s0, sp, 32
|
||||
|
||||
sw a0, 20(sp) # Identifier pointer.
|
||||
sw a1, 16(sp) # Identifier length.
|
||||
|
||||
lw a0, 20(sp)
|
||||
lw a1, 16(sp)
|
||||
call _is_local_identifier
|
||||
bnez a0, .Lcompile_designator_expression_local
|
||||
|
||||
lw a0, 20(sp)
|
||||
lw a1, 16(sp)
|
||||
call _is_register_identifier
|
||||
bnez a0, .Lcompile_designator_expression_saved
|
||||
|
||||
.Lcompile_designator_expression_local:
|
||||
li t0, 0x202c30 # 0,_
|
||||
sw t0, 12(sp)
|
||||
li t0, 0x61207773 # sw a
|
||||
sw t0, 8(sp)
|
||||
addi a0, sp, 8
|
||||
li a1, 7
|
||||
call _write_out
|
||||
|
||||
lw a0, 20(sp)
|
||||
lw a1, 16(sp)
|
||||
addi a0, a0, 4 # Skip the "loca" variable prefix.
|
||||
addi a1, a1, -4 # Skip the "loca" variable prefix.
|
||||
call _write_out
|
||||
|
||||
li t0, '\n'
|
||||
sw t0, 12(sp)
|
||||
li t0, 0x29707328 # (sp)
|
||||
sw t0, 8(sp)
|
||||
addi a0, sp, 8
|
||||
li a1, 5
|
||||
call _write_out
|
||||
|
||||
j .Lcompile_designator_expression_end
|
||||
|
||||
.Lcompile_designator_expression_saved:
|
||||
li t0, 0x20766d # mv_
|
||||
sw t0, 12(sp)
|
||||
addi a0, sp, 12
|
||||
li a1, 3
|
||||
call _write_out
|
||||
|
||||
lw a0, 20(sp)
|
||||
lw a1, 16(sp)
|
||||
call _write_out
|
||||
|
||||
li t0, 0x0a # \n
|
||||
sw t0, 12(sp)
|
||||
li t0, 0x3061202c # , a0
|
||||
sw t0, 8(sp)
|
||||
addi a0, sp, 8
|
||||
li a1, 5
|
||||
call _write_out
|
||||
|
||||
j .Lcompile_designator_expression_end
|
||||
|
||||
.Lcompile_designator_expression_end:
|
||||
|
||||
# Epilogue.
|
||||
lw ra, 28(sp)
|
||||
lw s0, 24(sp)
|
||||
addi sp, sp, 32
|
||||
ret
|
||||
|
||||
# Compiles a statement beginning with an identifier.
|
||||
#
|
||||
# Left values should be variables named "loca n", where n is the offset
|
||||
@ -508,28 +636,9 @@ _compile_identifier:
|
||||
|
||||
.Lcompile_identifier_assign:
|
||||
call _build_binary_expression
|
||||
|
||||
li t0, 0x202c30 # 0,_
|
||||
sw t0, 12(sp)
|
||||
li t0, 0x61207773 # sw a
|
||||
sw t0, 8(sp)
|
||||
addi a0, sp, 8
|
||||
li a1, 7
|
||||
call _write_out
|
||||
|
||||
lw a0, 20(sp)
|
||||
lw a1, 16(sp)
|
||||
addi a0, a0, 4 # Skip the "loca" variable prefix.
|
||||
addi a1, a1, -4 # Skip the "loca" variable prefix.
|
||||
call _write_out
|
||||
|
||||
li t0, '\n'
|
||||
sw t0, 12(sp)
|
||||
li t0, 0x29707328 # (sp)
|
||||
sw t0, 8(sp)
|
||||
addi a0, sp, 8
|
||||
li a1, 5
|
||||
call _write_out
|
||||
call _compile_designator_expression
|
||||
|
||||
j .Lcompile_identifier_end
|
||||
|
||||
@ -1310,11 +1419,7 @@ _compile_label:
|
||||
addi s0, sp, 16
|
||||
|
||||
sw a0, 0(sp) # Save the line length.
|
||||
|
||||
# Write the whole line as is.
|
||||
mv a0, s1
|
||||
lw a1, 0(sp)
|
||||
call _write_out
|
||||
mv a1, a0 # Argument for _write_out later.
|
||||
|
||||
lw t0, 0(sp) # Line length.
|
||||
mv t1, s1 # Line start.
|
||||
@ -1323,8 +1428,15 @@ _compile_label:
|
||||
addi t1, t1, -1 # Last character on the line.
|
||||
|
||||
lbu t1, (t1)
|
||||
li t2, ':'
|
||||
beq t1, t2, .Lcompile_label_colon
|
||||
li t2, ';'
|
||||
bne t1, t2, .Lcompile_label_colon
|
||||
|
||||
addi a1, a1, -1
|
||||
|
||||
.Lcompile_label_colon:
|
||||
# Write the whole line as is.
|
||||
mv a0, s1
|
||||
call _write_out
|
||||
|
||||
li t0, 0x3a # :
|
||||
sw t0, 4(sp)
|
||||
@ -1332,7 +1444,6 @@ _compile_label:
|
||||
li a1, 1
|
||||
call _write_out
|
||||
|
||||
.Lcompile_label_colon:
|
||||
li t0, '\n'
|
||||
sw t0, 4(sp)
|
||||
addi a0, sp, 4
|
||||
@ -1411,12 +1522,6 @@ _compile_if:
|
||||
call _put_char
|
||||
|
||||
.Lcompile_if_loop:
|
||||
/* DEBUG
|
||||
mv a0, s1
|
||||
li a1, 6
|
||||
call _write_error
|
||||
call _divide_by_zero_error */
|
||||
|
||||
call _skip_spaces
|
||||
call _read_token
|
||||
|
||||
@ -1532,13 +1637,15 @@ _compile_line:
|
||||
call _memcmp
|
||||
beqz a0, .Lcompile_line_exit
|
||||
|
||||
li t0, 0x61636f6c # loca
|
||||
sw t0, 12(sp)
|
||||
mv a0, s1
|
||||
addi a1, sp, 12
|
||||
li a2, 4
|
||||
call _memcmp
|
||||
beqz a0, .Lcompile_line_identifier
|
||||
lw a1, 20(sp)
|
||||
call _is_local_identifier
|
||||
bnez a0, .Lcompile_line_identifier
|
||||
|
||||
mv a0, s1
|
||||
li a1, 2
|
||||
call _is_register_identifier
|
||||
bnez a0, .Lcompile_line_identifier
|
||||
|
||||
li t0, 0x6f706d69 # impo
|
||||
sw t0, 12(sp)
|
||||
@ -1806,9 +1913,6 @@ _main:
|
||||
.type _start, @function
|
||||
_start:
|
||||
call _tokenizer_initialize
|
||||
li a1, 50
|
||||
call _write_error
|
||||
|
||||
call _main
|
||||
call _compile
|
||||
|
||||
|
1720
boot/stage2.elna
1720
boot/stage2.elna
File diff suppressed because it is too large
Load Diff
319
boot/tokenizer.s
319
boot/tokenizer.s
@ -1,165 +1,195 @@
|
||||
.global _tokenizer_initialize
|
||||
|
||||
.section .rodata
|
||||
#
|
||||
# Classes:
|
||||
#
|
||||
# 0x00: Invalid
|
||||
# 0x01: Digit
|
||||
# 0x02: Character
|
||||
# 0x03: Space
|
||||
.type classes, @object
|
||||
.size classes, 128
|
||||
classes:
|
||||
.byte 0x00 # 00 NUL
|
||||
.byte 0x00 # 01 SOH
|
||||
.byte 0x00 # 02 STX
|
||||
.byte 0x00 # 03 ETX
|
||||
.byte 0x00 # 04 EOT
|
||||
.byte 0x00 # 05 ENQ
|
||||
.byte 0x00 # 06 ACK
|
||||
.byte 0x00 # 07 BEL
|
||||
.byte 0x00 # 08 BS
|
||||
.byte 0x00 # 09 HT
|
||||
.byte 0x00 # 0A LF
|
||||
.byte 0x00 # 0B VT
|
||||
.byte 0x00 # 0C FF
|
||||
.byte 0x00 # 0D CR
|
||||
.byte 0x00 # 0E SO
|
||||
.byte 0x00 # 0F SI
|
||||
.byte 0x00 # 10 DLE
|
||||
.byte 0x00 # 11 DC1
|
||||
.byte 0x00 # 12 DC2
|
||||
.byte 0x00 # 13 DC3
|
||||
.byte 0x00 # 14 DC4
|
||||
.byte 0x00 # 15 NAK
|
||||
.byte 0x00 # 16 SYN
|
||||
.byte 0x00 # 17 ETB
|
||||
.byte 0x00 # 18 CAN
|
||||
.byte 0x00 # 19 EM
|
||||
.byte 0x00 # 1A SUB
|
||||
.byte 0x00 # 1B ESC
|
||||
.byte 0x00 # 1C FS
|
||||
.byte 0x00 # 1D GS
|
||||
.byte 0x00 # 1E RS
|
||||
.byte 0x00 # 1F US
|
||||
.byte 0x03 # 20 Space
|
||||
.byte 0x00 # 21 !
|
||||
.byte 0x00 # 22 "
|
||||
.byte 0x00 # 23 #
|
||||
.byte 0x00 # 24 $
|
||||
.byte 0x00 # 25 %
|
||||
.byte 0x00 # 26 &
|
||||
.byte 0x00 # 27 '
|
||||
.byte 0x00 # 28 (
|
||||
.byte 0x00 # 29 )
|
||||
.byte 0x00 # 2A *
|
||||
.byte 0x00 # 2B +
|
||||
.byte 0x00 # 2C ,
|
||||
.byte 0x00 # 2D -
|
||||
.byte 0x00 # 2E .
|
||||
.byte 0x00 # 2F /
|
||||
.byte 0x01 # 30 0
|
||||
.byte 0x01 # 31 1
|
||||
.byte 0x01 # 32 2
|
||||
.byte 0x01 # 33 3
|
||||
.byte 0x01 # 34 4
|
||||
.byte 0x01 # 35 5
|
||||
.byte 0x01 # 36 6
|
||||
.byte 0x01 # 37 7
|
||||
.byte 0x01 # 38 8
|
||||
.byte 0x01 # 39 9
|
||||
.byte 0x00 # 3A :
|
||||
.byte 0x00 # 3B ;
|
||||
.byte 0x00 # 3C <
|
||||
.byte 0x00 # 3D =
|
||||
.byte 0x00 # 3E >
|
||||
.byte 0x00 # 3F ?
|
||||
.byte 0x00 # 40 @
|
||||
.byte 0x02 # 41 A
|
||||
.byte 0x02 # 42 B
|
||||
.byte 0x02 # 43 C
|
||||
.byte 0x02 # 44 D
|
||||
.byte 0x02 # 45 E
|
||||
.byte 0x02 # 46 F
|
||||
.byte 0x02 # 47 G
|
||||
.byte 0x02 # 48 H
|
||||
.byte 0x02 # 49 I
|
||||
.byte 0x02 # 4A J
|
||||
.byte 0x02 # 4B K
|
||||
.byte 0x02 # 4C L
|
||||
.byte 0x02 # 4D M
|
||||
.byte 0x02 # 4E N
|
||||
.byte 0x02 # 4F O
|
||||
.byte 0x02 # 50 P
|
||||
.byte 0x02 # 51 Q
|
||||
.byte 0x02 # 52 R
|
||||
.byte 0x02 # 53 S
|
||||
.byte 0x02 # 54 T
|
||||
.byte 0x02 # 55 U
|
||||
.byte 0x02 # 56 V
|
||||
.byte 0x02 # 57 W
|
||||
.byte 0x02 # 58 X
|
||||
.byte 0x02 # 59 Y
|
||||
.byte 0x02 # 5A Z
|
||||
.byte 0x00 # 5B [
|
||||
.byte 0x00 # 5C \
|
||||
.byte 0x00 # 5D ]
|
||||
.byte 0x00 # 5E ^
|
||||
.byte 0x00 # 5F _
|
||||
.byte 0x00 # 60 `
|
||||
.byte 0x02 # 61 a
|
||||
.byte 0x02 # 62 b
|
||||
.byte 0x02 # 63 c
|
||||
.byte 0x02 # 64 d
|
||||
.byte 0x02 # 65 e
|
||||
.byte 0x02 # 66 f
|
||||
.byte 0x02 # 67 g
|
||||
.byte 0x02 # 68 h
|
||||
.byte 0x02 # 69 i
|
||||
.byte 0x02 # 6A j
|
||||
.byte 0x02 # 6B k
|
||||
.byte 0x02 # 6C l
|
||||
.byte 0x02 # 6D m
|
||||
.byte 0x02 # 6E n
|
||||
.byte 0x02 # 6F o
|
||||
.byte 0x02 # 70 p
|
||||
.byte 0x02 # 71 q
|
||||
.byte 0x02 # 72 r
|
||||
.byte 0x02 # 73 s
|
||||
.byte 0x02 # 74 t
|
||||
.byte 0x02 # 75 u
|
||||
.byte 0x02 # 76 v
|
||||
.byte 0x02 # 77 w
|
||||
.byte 0x02 # 78 x
|
||||
.byte 0x02 # 79 y
|
||||
.byte 0x02 # 7A z
|
||||
.byte 0x00 # 7B {
|
||||
.byte 0x00 # 7C |
|
||||
.byte 0x00 # 7D }
|
||||
.byte 0x00 # 7E ~
|
||||
.byte 0x00 # 7F DEL
|
||||
|
||||
raw_classes:
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "space\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "digit\n"
|
||||
.ascii "digit\n"
|
||||
.ascii "digit\n"
|
||||
.ascii "digit\n"
|
||||
.ascii "digit\n"
|
||||
.ascii "digit\n"
|
||||
.ascii "digit\n"
|
||||
.ascii "digit\n"
|
||||
.ascii "digit\n"
|
||||
.ascii "digit\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "upper\n"
|
||||
.ascii "upper\n"
|
||||
.ascii "upper\n"
|
||||
.ascii "upper\n"
|
||||
.ascii "upper\n"
|
||||
.ascii "upper\n"
|
||||
.ascii "upper\n"
|
||||
.ascii "upper\n"
|
||||
.ascii "upper\n"
|
||||
.ascii "upper\n"
|
||||
.ascii "upper\n"
|
||||
.ascii "upper\n"
|
||||
.ascii "upper\n"
|
||||
.ascii "upper\n"
|
||||
.ascii "upper\n"
|
||||
.ascii "upper\n"
|
||||
.ascii "upper\n"
|
||||
.ascii "upper\n"
|
||||
.ascii "upper\n"
|
||||
.ascii "upper\n"
|
||||
.ascii "upper\n"
|
||||
.ascii "upper\n"
|
||||
.ascii "upper\n"
|
||||
.ascii "upper\n"
|
||||
.ascii "upper\n"
|
||||
.ascii "upper\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "lower\n"
|
||||
.ascii "lower\n"
|
||||
.ascii "lower\n"
|
||||
.ascii "lower\n"
|
||||
.ascii "lower\n"
|
||||
.ascii "lower\n"
|
||||
.ascii "lower\n"
|
||||
.ascii "lower\n"
|
||||
.ascii "lower\n"
|
||||
.ascii "lower\n"
|
||||
.ascii "lower\n"
|
||||
.ascii "lower\n"
|
||||
.ascii "lower\n"
|
||||
.ascii "lower\n"
|
||||
.ascii "lower\n"
|
||||
.ascii "lower\n"
|
||||
.ascii "lower\n"
|
||||
.ascii "lower\n"
|
||||
.ascii "lower\n"
|
||||
.ascii "lower\n"
|
||||
.ascii "lower\n"
|
||||
.ascii "lower\n"
|
||||
.ascii "lower\n"
|
||||
.ascii "lower\n"
|
||||
.ascii "lower\n"
|
||||
.ascii "lower\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.ascii "invalid\n"
|
||||
.section .data
|
||||
|
||||
.section .bss
|
||||
.type class_names, @object
|
||||
.size class_names, 1024
|
||||
class_names: .zero 1024
|
||||
|
||||
.section .data
|
||||
.type classes, @object
|
||||
.size classes, 512 # 128 characters * 4 byte.
|
||||
classes:
|
||||
|
||||
.section .text
|
||||
|
||||
# Initializes the classification table.
|
||||
#
|
||||
# Paramaters:
|
||||
# a0 - Raw input for the classification table.
|
||||
.type _tokenizer_classes, @function
|
||||
_tokenizer_classes:
|
||||
.type _initialize_classes, @function
|
||||
_initialize_classes:
|
||||
# Prologue.
|
||||
addi sp, sp, -8
|
||||
sw ra, 4(sp)
|
||||
sw s0, 0(sp)
|
||||
addi s0, sp, 8
|
||||
addi sp, sp, -24
|
||||
sw ra, 20(sp)
|
||||
sw s0, 16(sp)
|
||||
addi s0, sp, 24
|
||||
|
||||
sw s1, 12(sp) # Preserve the s1 register used for the character counter.
|
||||
li s1, 128 # 128 ASCII characters.
|
||||
|
||||
.Linitialize_classes_loop:
|
||||
addi s1, s1, -1
|
||||
|
||||
la t0, classes
|
||||
add t0, t0, s1
|
||||
lbu t0, (t0)
|
||||
li t1, 0x01
|
||||
|
||||
bne t0, t1, .Linitialize_classes_step
|
||||
|
||||
/* DEBUG */
|
||||
li a0, 0x69676964
|
||||
sw a0, 8(sp) # Preserve the memory address.
|
||||
addi a0, sp, 8
|
||||
li a1, 4
|
||||
call _write_error
|
||||
|
||||
.Linitialize_classes_step:
|
||||
bnez s1, .Linitialize_classes_loop
|
||||
|
||||
lw s1, 12(sp) # Restore the saved register.
|
||||
|
||||
# Epilogue.
|
||||
lw ra, 4(sp)
|
||||
lw s0, 0(sp)
|
||||
addi sp, sp, 8
|
||||
lw ra, 20(sp)
|
||||
lw s0, 16(sp)
|
||||
addi sp, sp, 24
|
||||
ret
|
||||
|
||||
# Initializes the lookup tables.
|
||||
@ -171,8 +201,7 @@ _tokenizer_initialize:
|
||||
sw s0, 0(sp)
|
||||
addi s0, sp, 8
|
||||
|
||||
la a0, raw_classes
|
||||
call _tokenizer_classes
|
||||
call _initialize_classes
|
||||
|
||||
# Epilogue.
|
||||
lw ra, 4(sp)
|
||||
|
Loading…
x
Reference in New Issue
Block a user