Add semicolons separating the statements
This commit is contained in:
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
|
||||
|
||||
|
Reference in New Issue
Block a user