From 9402da5f79f09c2422a8803deb32c09a6d5818a8 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Mon, 20 Nov 2023 17:26:37 -0500 Subject: [PATCH] code cleanup --- include/bf_mips_codegen.h | 2 +- include/bf_tokenizer.h | 48 +- mips.asm | 1587 +++++++++++++++++++++++++++++++++---- squares.bf | 8 + src/bf_mips_codegen.cpp | 75 +- src/bf_tokenizer.cpp | 100 ++- src/main.cpp | 7 +- 7 files changed, 1569 insertions(+), 258 deletions(-) create mode 100644 squares.bf diff --git a/include/bf_mips_codegen.h b/include/bf_mips_codegen.h index a649dd8..3d81314 100644 --- a/include/bf_mips_codegen.h +++ b/include/bf_mips_codegen.h @@ -11,6 +11,6 @@ #include #include -void codegen(const std::vector& tokens, std::ostream& out); +void codegen(tokenizer& tokenizer, std::ostream& out); #endif //BRAINFUCK_MISC_BF_MIPS_CODEGEN_H diff --git a/include/bf_tokenizer.h b/include/bf_tokenizer.h index b0f51c9..603d4a2 100644 --- a/include/bf_tokenizer.h +++ b/include/bf_tokenizer.h @@ -27,13 +27,53 @@ enum class bf_token struct token_t { bf_token token; - std::optional name = {}; + std::optional name = {}; - explicit token_t(bf_token token): token(token) {} + explicit token_t(bf_token token): token(token) + {} }; -std::vector tokenize(const std::string& program); -std::vector& bf_name(std::vector& tokens); +typedef std::optional> optional_token; +class tokenizer +{ + private: + std::vector tokens; + size_t conditionalCount = 0; + size_t currentIndex = 0; + + void tokenize(const std::string& program); + + void bf_name(); + + public: + explicit tokenizer(const std::string& program) + { + tokenize(program); + bf_name(); + } + + inline bool hasNext(){ + return currentIndex < tokens.size(); + } + + inline void advance(){ + currentIndex++; + } + + inline optional_token next() { + if (currentIndex >= tokens.size()) + return {}; + return tokens[currentIndex++]; + } + + inline optional_token peek(){ + if (currentIndex >= tokens.size()) + return {}; + return tokens[currentIndex]; + } + + void print(size_t index = 0); +}; #endif //BRAINFUCK_MISC_BF_TOKENIZER_H diff --git a/mips.asm b/mips.asm index 4695ee5..d3a2812 100644 --- a/mips.asm +++ b/mips.asm @@ -17,32 +17,18 @@ setup: move $t0, $v0 bf: lb $t1, ($t0) - addi $t1, $t1, 1 + bnez $t1, BF_OPEN_96064d4d39533ab4354b246d_18446744073709551615 +BF_CLOSE_96064d4d39533ab4354b246d_18446744073709551615: + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + subi $t1, $t1, 1 sb $t1, ($t0) + addi $t0, $t0, 1 lb $t1, ($t0) addi $t1, $t1, 1 sb $t1, ($t0) - lb $t1, ($t0) - addi $t1, $t1, 1 - sb $t1, ($t0) - lb $t1, ($t0) - addi $t1, $t1, 1 - sb $t1, ($t0) - lb $t1, ($t0) - addi $t1, $t1, 1 - sb $t1, ($t0) - lb $t1, ($t0) - addi $t1, $t1, 1 - sb $t1, ($t0) - lb $t1, ($t0) - addi $t1, $t1, 1 - sb $t1, ($t0) - lb $t1, ($t0) - addi $t1, $t1, 1 - sb $t1, ($t0) - lb $t1, ($t0) - beqz $t1, BF_CLOSE_03e0a731165036472c4dae07_0 -BF_OPEN_03e0a731165036472c4dae07_0: addi $t0, $t0, 1 lb $t1, ($t0) addi $t1, $t1, 1 @@ -57,13 +43,6 @@ BF_OPEN_03e0a731165036472c4dae07_0: addi $t1, $t1, 1 sb $t1, ($t0) lb $t1, ($t0) - beqz $t1, BF_CLOSE_972059b874ce5ef469e931bb_1 -BF_OPEN_972059b874ce5ef469e931bb_1: - addi $t0, $t0, 1 - lb $t1, ($t0) - addi $t1, $t1, 1 - sb $t1, ($t0) - lb $t1, ($t0) addi $t1, $t1, 1 sb $t1, ($t0) addi $t0, $t0, 1 @@ -76,6 +55,48 @@ BF_OPEN_972059b874ce5ef469e931bb_1: lb $t1, ($t0) addi $t1, $t1, 1 sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + beqz $t1, BF_CLOSE_c784f9e0e66032d6a470902e_18446744073709551615 +BF_OPEN_c784f9e0e66032d6a470902e_18446744073709551615: + lb $t1, ($t0) + beqz $t1, BF_CLOSE_f64b1668cb7210c15d0b1457_0 +BF_OPEN_f64b1668cb7210c15d0b1457_0: + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + bnez $t1, BF_OPEN_f64b1668cb7210c15d0b1457_0 +BF_CLOSE_f64b1668cb7210c15d0b1457_0: addi $t0, $t0, 1 lb $t1, ($t0) addi $t1, $t1, 1 @@ -86,6 +107,69 @@ BF_OPEN_972059b874ce5ef469e931bb_1: lb $t1, ($t0) addi $t1, $t1, 1 sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + beqz $t1, BF_CLOSE_8462ffd64424855532cc34f1_0 +BF_OPEN_8462ffd64424855532cc34f1_0: + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + bnez $t1, BF_OPEN_8462ffd64424855532cc34f1_0 +BF_CLOSE_8462ffd64424855532cc34f1_0: + subi $t0, $t0, 1 + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + bnez $t1, BF_OPEN_c784f9e0e66032d6a470902e_18446744073709551615 +BF_CLOSE_c784f9e0e66032d6a470902e_18446744073709551615: + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_e3df4010adf86b95a5d7f832_18446744073709551615 +BF_OPEN_e3df4010adf86b95a5d7f832_18446744073709551615: + lb $t1, ($t0) + beqz $t1, BF_CLOSE_50a61cd4df3d91b17a24907d_0 +BF_OPEN_50a61cd4df3d91b17a24907d_0: + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) addi $t0, $t0, 1 lb $t1, ($t0) addi $t1, $t1, 1 @@ -98,19 +182,16 @@ BF_OPEN_972059b874ce5ef469e931bb_1: subi $t1, $t1, 1 sb $t1, ($t0) lb $t1, ($t0) - bnez $t1, BF_OPEN_972059b874ce5ef469e931bb_1 -BF_CLOSE_972059b874ce5ef469e931bb_1: - addi $t0, $t0, 1 + bnez $t1, BF_OPEN_50a61cd4df3d91b17a24907d_0 +BF_CLOSE_50a61cd4df3d91b17a24907d_0: lb $t1, ($t0) addi $t1, $t1, 1 sb $t1, ($t0) - addi $t0, $t0, 1 lb $t1, ($t0) addi $t1, $t1, 1 sb $t1, ($t0) - addi $t0, $t0, 1 lb $t1, ($t0) - subi $t1, $t1, 1 + addi $t1, $t1, 1 sb $t1, ($t0) addi $t0, $t0, 1 addi $t0, $t0, 1 @@ -118,160 +199,127 @@ BF_CLOSE_972059b874ce5ef469e931bb_1: addi $t1, $t1, 1 sb $t1, ($t0) lb $t1, ($t0) - beqz $t1, BF_CLOSE_4f2d57da98e6bb1619411ff9_1 -BF_OPEN_4f2d57da98e6bb1619411ff9_1: + beqz $t1, BF_CLOSE_b07f54b520098276cd88af98_0 +BF_OPEN_b07f54b520098276cd88af98_0: subi $t0, $t0, 1 lb $t1, ($t0) - bnez $t1, BF_OPEN_4f2d57da98e6bb1619411ff9_1 -BF_CLOSE_4f2d57da98e6bb1619411ff9_1: + addi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + subi $t0, $t0, 1 + subi $t0, $t0, 1 subi $t0, $t0, 1 lb $t1, ($t0) subi $t1, $t1, 1 sb $t1, ($t0) lb $t1, ($t0) - bnez $t1, BF_OPEN_03e0a731165036472c4dae07_0 -BF_CLOSE_03e0a731165036472c4dae07_0: + bnez $t1, BF_OPEN_b07f54b520098276cd88af98_0 +BF_CLOSE_b07f54b520098276cd88af98_0: addi $t0, $t0, 1 addi $t0, $t0, 1 - li $v0, 11 - lb $a0, ($t0) - syscall + lb $t1, ($t0) + beqz $t1, BF_CLOSE_dca9da1ea4acae704471aa80_0 +BF_OPEN_dca9da1ea4acae704471aa80_0: addi $t0, $t0, 1 lb $t1, ($t0) - subi $t1, $t1, 1 - sb $t1, ($t0) + beqz $t1, BF_CLOSE_4ae6967bc19eb523a2c14321_1 +BF_OPEN_4ae6967bc19eb523a2c14321_1: lb $t1, ($t0) - subi $t1, $t1, 1 - sb $t1, ($t0) - lb $t1, ($t0) - subi $t1, $t1, 1 - sb $t1, ($t0) - li $v0, 11 - lb $a0, ($t0) - syscall - lb $t1, ($t0) - addi $t1, $t1, 1 - sb $t1, ($t0) - lb $t1, ($t0) - addi $t1, $t1, 1 - sb $t1, ($t0) - lb $t1, ($t0) - addi $t1, $t1, 1 - sb $t1, ($t0) - lb $t1, ($t0) - addi $t1, $t1, 1 - sb $t1, ($t0) - lb $t1, ($t0) - addi $t1, $t1, 1 - sb $t1, ($t0) - lb $t1, ($t0) - addi $t1, $t1, 1 - sb $t1, ($t0) - lb $t1, ($t0) - addi $t1, $t1, 1 - sb $t1, ($t0) - li $v0, 11 - lb $a0, ($t0) - syscall - li $v0, 11 - lb $a0, ($t0) - syscall - lb $t1, ($t0) - addi $t1, $t1, 1 - sb $t1, ($t0) - lb $t1, ($t0) - addi $t1, $t1, 1 - sb $t1, ($t0) - lb $t1, ($t0) - addi $t1, $t1, 1 - sb $t1, ($t0) - li $v0, 11 - lb $a0, ($t0) - syscall + beqz $t1, BF_CLOSE_98ec6f07048f23263cdce2c8_2 +BF_OPEN_98ec6f07048f23263cdce2c8_2: addi $t0, $t0, 1 addi $t0, $t0, 1 - li $v0, 11 - lb $a0, ($t0) - syscall + addi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + subi $t0, $t0, 1 + subi $t0, $t0, 1 subi $t0, $t0, 1 lb $t1, ($t0) subi $t1, $t1, 1 sb $t1, ($t0) - li $v0, 11 - lb $a0, ($t0) - syscall + lb $t1, ($t0) + bnez $t1, BF_OPEN_98ec6f07048f23263cdce2c8_2 +BF_CLOSE_98ec6f07048f23263cdce2c8_2: + subi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_4ae6967bc19eb523a2c14321_1 +BF_CLOSE_4ae6967bc19eb523a2c14321_1: + subi $t0, $t0, 1 subi $t0, $t0, 1 - li $v0, 11 - lb $a0, ($t0) - syscall lb $t1, ($t0) addi $t1, $t1, 1 sb $t1, ($t0) lb $t1, ($t0) addi $t1, $t1, 1 sb $t1, ($t0) - lb $t1, ($t0) - addi $t1, $t1, 1 - sb $t1, ($t0) - li $v0, 11 - lb $a0, ($t0) - syscall - lb $t1, ($t0) - subi $t1, $t1, 1 - sb $t1, ($t0) - lb $t1, ($t0) - subi $t1, $t1, 1 - sb $t1, ($t0) - lb $t1, ($t0) - subi $t1, $t1, 1 - sb $t1, ($t0) - lb $t1, ($t0) - subi $t1, $t1, 1 - sb $t1, ($t0) - lb $t1, ($t0) - subi $t1, $t1, 1 - sb $t1, ($t0) - lb $t1, ($t0) - subi $t1, $t1, 1 - sb $t1, ($t0) - li $v0, 11 - lb $a0, ($t0) - syscall - lb $t1, ($t0) - subi $t1, $t1, 1 - sb $t1, ($t0) - lb $t1, ($t0) - subi $t1, $t1, 1 - sb $t1, ($t0) - lb $t1, ($t0) - subi $t1, $t1, 1 - sb $t1, ($t0) - lb $t1, ($t0) - subi $t1, $t1, 1 - sb $t1, ($t0) - lb $t1, ($t0) - subi $t1, $t1, 1 - sb $t1, ($t0) - lb $t1, ($t0) - subi $t1, $t1, 1 - sb $t1, ($t0) - lb $t1, ($t0) - subi $t1, $t1, 1 - sb $t1, ($t0) - lb $t1, ($t0) - subi $t1, $t1, 1 - sb $t1, ($t0) - li $v0, 11 - lb $a0, ($t0) - syscall - addi $t0, $t0, 1 addi $t0, $t0, 1 lb $t1, ($t0) addi $t1, $t1, 1 sb $t1, ($t0) - li $v0, 11 - lb $a0, ($t0) - syscall + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + bnez $t1, BF_OPEN_dca9da1ea4acae704471aa80_0 +BF_CLOSE_dca9da1ea4acae704471aa80_0: + subi $t0, $t0, 1 + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + bnez $t1, BF_OPEN_e3df4010adf86b95a5d7f832_18446744073709551615 +BF_CLOSE_e3df4010adf86b95a5d7f832_18446744073709551615: + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_a99a4987b2123d147965a06d_18446744073709551615 +BF_OPEN_a99a4987b2123d147965a06d_18446744073709551615: + lb $t1, ($t0) + beqz $t1, BF_CLOSE_91ac166c7af79f2188b21b68_0 +BF_OPEN_91ac166c7af79f2188b21b68_0: + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + bnez $t1, BF_OPEN_91ac166c7af79f2188b21b68_0 +BF_CLOSE_91ac166c7af79f2188b21b68_0: + subi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + subi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_5d775cd53e5b4c902444d895_0 +BF_OPEN_5d775cd53e5b4c902444d895_0: addi $t0, $t0, 1 lb $t1, ($t0) addi $t1, $t1, 1 @@ -279,6 +327,1225 @@ BF_CLOSE_03e0a731165036472c4dae07_0: lb $t1, ($t0) addi $t1, $t1, 1 sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + subi $t0, $t0, 1 + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + bnez $t1, BF_OPEN_5d775cd53e5b4c902444d895_0 +BF_CLOSE_5d775cd53e5b4c902444d895_0: + subi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + bnez $t1, BF_OPEN_a99a4987b2123d147965a06d_18446744073709551615 +BF_CLOSE_a99a4987b2123d147965a06d_18446744073709551615: + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_8904e378099c118eaada9d20_18446744073709551615 +BF_OPEN_8904e378099c118eaada9d20_18446744073709551615: + lb $t1, ($t0) + beqz $t1, BF_CLOSE_f065c3935d683a06edc665a5_0 +BF_OPEN_f065c3935d683a06edc665a5_0: + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) li $v0, 11 lb $a0, ($t0) syscall + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_f065c3935d683a06edc665a5_0 +BF_CLOSE_f065c3935d683a06edc665a5_0: + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + beqz $t1, BF_CLOSE_7570984ef8d7a90e7f03b13f_0 +BF_OPEN_7570984ef8d7a90e7f03b13f_0: + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_7570984ef8d7a90e7f03b13f_0 +BF_CLOSE_7570984ef8d7a90e7f03b13f_0: + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_531828e37478203582292530_0 +BF_OPEN_531828e37478203582292530_0: + addi $t0, $t0, 1 + addi $t0, $t0, 1 + li $v0, 12 + syscall + sb $v0, ($t0) + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + beqz $t1, BF_CLOSE_f72e0db35ea6b87eace3f72c_1 +BF_OPEN_f72e0db35ea6b87eace3f72c_1: + addi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_f72e0db35ea6b87eace3f72c_1 +BF_CLOSE_f72e0db35ea6b87eace3f72c_1: + subi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_531828e37478203582292530_0 +BF_CLOSE_531828e37478203582292530_0: + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_cb0c9a316dc248b186a4adae_0 +BF_OPEN_cb0c9a316dc248b186a4adae_0: + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_e623feb140f800ac96ba161a_1 +BF_OPEN_e623feb140f800ac96ba161a_1: + addi $t0, $t0, 1 + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + beqz $t1, BF_CLOSE_d07e99f0bd82568e08012ef4_2 +BF_OPEN_d07e99f0bd82568e08012ef4_2: + subi $t0, $t0, 1 + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + bnez $t1, BF_OPEN_d07e99f0bd82568e08012ef4_2 +BF_CLOSE_d07e99f0bd82568e08012ef4_2: + subi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_1bf9422cdc40f10a97e0f880_2 +BF_OPEN_1bf9422cdc40f10a97e0f880_2: + lb $t1, ($t0) + beqz $t1, BF_CLOSE_975d5ba03e87133df76b2c40_3 +BF_OPEN_975d5ba03e87133df76b2c40_3: + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_975d5ba03e87133df76b2c40_3 +BF_CLOSE_975d5ba03e87133df76b2c40_3: + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + beqz $t1, BF_CLOSE_8a6a72606e5a13e632b3167d_3 +BF_OPEN_8a6a72606e5a13e632b3167d_3: + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + bnez $t1, BF_OPEN_8a6a72606e5a13e632b3167d_3 +BF_CLOSE_8a6a72606e5a13e632b3167d_3: + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + beqz $t1, BF_CLOSE_0c3087c2aa3431be4dc9a291_3 +BF_OPEN_0c3087c2aa3431be4dc9a291_3: + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_0c3087c2aa3431be4dc9a291_3 +BF_CLOSE_0c3087c2aa3431be4dc9a291_3: + subi $t0, $t0, 1 + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + bnez $t1, BF_OPEN_1bf9422cdc40f10a97e0f880_2 +BF_CLOSE_1bf9422cdc40f10a97e0f880_2: + addi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_be970c344518b4838113bd2d_2 +BF_OPEN_be970c344518b4838113bd2d_2: + subi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + bnez $t1, BF_OPEN_be970c344518b4838113bd2d_2 +BF_CLOSE_be970c344518b4838113bd2d_2: + addi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_7cbd3778a4fe3d96db5f6d3a_2 +BF_OPEN_7cbd3778a4fe3d96db5f6d3a_2: + lb $t1, ($t0) + beqz $t1, BF_CLOSE_f38a9ce1b14bc63a0a34773c_3 +BF_OPEN_f38a9ce1b14bc63a0a34773c_3: + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_f38a9ce1b14bc63a0a34773c_3 +BF_CLOSE_f38a9ce1b14bc63a0a34773c_3: + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + beqz $t1, BF_CLOSE_7be1608ffa465e1f95c12d60_3 +BF_OPEN_7be1608ffa465e1f95c12d60_3: + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_7be1608ffa465e1f95c12d60_3 +BF_CLOSE_7be1608ffa465e1f95c12d60_3: + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + bnez $t1, BF_OPEN_7cbd3778a4fe3d96db5f6d3a_2 +BF_CLOSE_7cbd3778a4fe3d96db5f6d3a_2: + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + beqz $t1, BF_CLOSE_ad1be31d8a35acb798d5dfa7_2 +BF_OPEN_ad1be31d8a35acb798d5dfa7_2: + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_ad1be31d8a35acb798d5dfa7_2 +BF_CLOSE_ad1be31d8a35acb798d5dfa7_2: + subi $t0, $t0, 1 + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + beqz $t1, BF_CLOSE_e93d806bda9f89a1b197a59b_2 +BF_OPEN_e93d806bda9f89a1b197a59b_2: + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_e93d806bda9f89a1b197a59b_2 +BF_CLOSE_e93d806bda9f89a1b197a59b_2: + addi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_78ce53a7f6938be98f0d8560_2 +BF_OPEN_78ce53a7f6938be98f0d8560_2: + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + subi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_78ce53a7f6938be98f0d8560_2 +BF_CLOSE_78ce53a7f6938be98f0d8560_2: + addi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + beqz $t1, BF_CLOSE_b8376336a3ad61ed4978a5ab_2 +BF_OPEN_b8376336a3ad61ed4978a5ab_2: + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_b8376336a3ad61ed4978a5ab_2 +BF_CLOSE_b8376336a3ad61ed4978a5ab_2: + addi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_e623feb140f800ac96ba161a_1 +BF_CLOSE_e623feb140f800ac96ba161a_1: + subi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_cb0c9a316dc248b186a4adae_0 +BF_CLOSE_cb0c9a316dc248b186a4adae_0: + addi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_5439ab2c390f42ded5ac5f4f_0 +BF_OPEN_5439ab2c390f42ded5ac5f4f_0: + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + beqz $t1, BF_CLOSE_da5ba2adeda491e6629f8a93_1 +BF_OPEN_da5ba2adeda491e6629f8a93_1: + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + bnez $t1, BF_OPEN_da5ba2adeda491e6629f8a93_1 +BF_CLOSE_da5ba2adeda491e6629f8a93_1: + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_80ef2aaac180da7c327abffb_1 +BF_OPEN_80ef2aaac180da7c327abffb_1: + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_80ef2aaac180da7c327abffb_1 +BF_CLOSE_80ef2aaac180da7c327abffb_1: + addi $t0, $t0, 1 + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_18cfb026bec2bcd241bf48c4_1 +BF_OPEN_18cfb026bec2bcd241bf48c4_1: + addi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_9d179819dec02705f74440a0_2 +BF_OPEN_9d179819dec02705f74440a0_2: + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + beqz $t1, BF_CLOSE_4aa624582085011b305d0b3c_3 +BF_OPEN_4aa624582085011b305d0b3c_3: + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_4aa624582085011b305d0b3c_3 +BF_CLOSE_4aa624582085011b305d0b3c_3: + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + beqz $t1, BF_CLOSE_3f07173ee69d11dfa935564f_3 +BF_OPEN_3f07173ee69d11dfa935564f_3: + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_3f07173ee69d11dfa935564f_3 +BF_CLOSE_3f07173ee69d11dfa935564f_3: + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_9d179819dec02705f74440a0_2 +BF_CLOSE_9d179819dec02705f74440a0_2: + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_f8a3eac35aa203228d3178f8_2 +BF_OPEN_f8a3eac35aa203228d3178f8_2: + addi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_872c3d3cc0f122187958ad17_3 +BF_OPEN_872c3d3cc0f122187958ad17_3: + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_872c3d3cc0f122187958ad17_3 +BF_CLOSE_872c3d3cc0f122187958ad17_3: + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_f8a3eac35aa203228d3178f8_2 +BF_CLOSE_f8a3eac35aa203228d3178f8_2: + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_6bb3722eb74b171c40257cf6_2 +BF_OPEN_6bb3722eb74b171c40257cf6_2: + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + subi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + beqz $t1, BF_CLOSE_aeffc6fa0e67c47de3a253ad_3 +BF_OPEN_aeffc6fa0e67c47de3a253ad_3: + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + bnez $t1, BF_OPEN_aeffc6fa0e67c47de3a253ad_3 +BF_CLOSE_aeffc6fa0e67c47de3a253ad_3: + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_6bb3722eb74b171c40257cf6_2 +BF_CLOSE_6bb3722eb74b171c40257cf6_2: + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + beqz $t1, BF_CLOSE_5719767dec4a57f57a316bc3_2 +BF_OPEN_5719767dec4a57f57a316bc3_2: + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + bnez $t1, BF_OPEN_5719767dec4a57f57a316bc3_2 +BF_CLOSE_5719767dec4a57f57a316bc3_2: + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_18cfb026bec2bcd241bf48c4_1 +BF_CLOSE_18cfb026bec2bcd241bf48c4_1: + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + beqz $t1, BF_CLOSE_d9760b6e0a7ba5884fee5563_1 +BF_OPEN_d9760b6e0a7ba5884fee5563_1: + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + subi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + bnez $t1, BF_OPEN_d9760b6e0a7ba5884fee5563_1 +BF_CLOSE_d9760b6e0a7ba5884fee5563_1: + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + subi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + beqz $t1, BF_CLOSE_8ad801bae2eef812a0509157_1 +BF_OPEN_8ad801bae2eef812a0509157_1: + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_766145529b58e9db8b3d42f7_2 +BF_OPEN_766145529b58e9db8b3d42f7_2: + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + subi $t0, $t0, 1 + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_7faee864e036fe56417555e9_3 +BF_OPEN_7faee864e036fe56417555e9_3: + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_7faee864e036fe56417555e9_3 +BF_CLOSE_7faee864e036fe56417555e9_3: + addi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_b14d8551e06340f17142a494_3 +BF_OPEN_b14d8551e06340f17142a494_3: + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_1be265021f521d5c146ea977_4 +BF_OPEN_1be265021f521d5c146ea977_4: + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_1be265021f521d5c146ea977_4 +BF_CLOSE_1be265021f521d5c146ea977_4: + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + subi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_f3c8804f0e689aa4bb23cbca_4 +BF_OPEN_f3c8804f0e689aa4bb23cbca_4: + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_f3c8804f0e689aa4bb23cbca_4 +BF_CLOSE_f3c8804f0e689aa4bb23cbca_4: + addi $t0, $t0, 1 + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + bnez $t1, BF_OPEN_b14d8551e06340f17142a494_3 +BF_CLOSE_b14d8551e06340f17142a494_3: + lb $t1, ($t0) + bnez $t1, BF_OPEN_766145529b58e9db8b3d42f7_2 +BF_CLOSE_766145529b58e9db8b3d42f7_2: + subi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_8d29329e22b64c37659b1b54_2 +BF_OPEN_8d29329e22b64c37659b1b54_2: + subi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_95832243201b1bc80b79045a_3 +BF_OPEN_95832243201b1bc80b79045a_3: + subi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_df68fc38dc638e4a873ef4a6_4 +BF_OPEN_df68fc38dc638e4a873ef4a6_4: + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_df68fc38dc638e4a873ef4a6_4 +BF_CLOSE_df68fc38dc638e4a873ef4a6_4: + addi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_02c1c83d59f1cfbfc19536ca_4 +BF_OPEN_02c1c83d59f1cfbfc19536ca_4: + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_02c1c83d59f1cfbfc19536ca_4 +BF_CLOSE_02c1c83d59f1cfbfc19536ca_4: + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + bnez $t1, BF_OPEN_95832243201b1bc80b79045a_3 +BF_CLOSE_95832243201b1bc80b79045a_3: + subi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_12c36532b1d325cdb96755d9_3 +BF_OPEN_12c36532b1d325cdb96755d9_3: + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_12c36532b1d325cdb96755d9_3 +BF_CLOSE_12c36532b1d325cdb96755d9_3: + lb $t1, ($t0) + bnez $t1, BF_OPEN_8d29329e22b64c37659b1b54_2 +BF_CLOSE_8d29329e22b64c37659b1b54_2: + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_d2207095634f8d1fb54c89dd_2 +BF_OPEN_d2207095634f8d1fb54c89dd_2: + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_d2207095634f8d1fb54c89dd_2 +BF_CLOSE_d2207095634f8d1fb54c89dd_2: + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_8ad801bae2eef812a0509157_1 +BF_CLOSE_8ad801bae2eef812a0509157_1: + addi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + beqz $t1, BF_CLOSE_4139bfa964c1b2231e8d8f9f_1 +BF_OPEN_4139bfa964c1b2231e8d8f9f_1: + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_18d36c80401374ce4a1be20b_2 +BF_OPEN_18d36c80401374ce4a1be20b_2: + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + bnez $t1, BF_OPEN_18d36c80401374ce4a1be20b_2 +BF_CLOSE_18d36c80401374ce4a1be20b_2: + subi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_4139bfa964c1b2231e8d8f9f_1 +BF_CLOSE_4139bfa964c1b2231e8d8f9f_1: + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + beqz $t1, BF_CLOSE_6691ea42e52a89fc748855be_1 +BF_OPEN_6691ea42e52a89fc748855be_1: + lb $t1, ($t0) + beqz $t1, BF_CLOSE_473e764bd573f6eb7d2d55aa_2 +BF_OPEN_473e764bd573f6eb7d2d55aa_2: + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_473e764bd573f6eb7d2d55aa_2 +BF_CLOSE_473e764bd573f6eb7d2d55aa_2: + subi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_2ea438a263a3c9b9eb33eab0_2 +BF_OPEN_2ea438a263a3c9b9eb33eab0_2: + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_0008687cfd7857c51bf44eba_3 +BF_OPEN_0008687cfd7857c51bf44eba_3: + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_0008687cfd7857c51bf44eba_3 +BF_CLOSE_0008687cfd7857c51bf44eba_3: + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_6d027c3712fa430372b97547_3 +BF_OPEN_6d027c3712fa430372b97547_3: + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_6d027c3712fa430372b97547_3 +BF_CLOSE_6d027c3712fa430372b97547_3: + subi $t0, $t0, 1 + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + bnez $t1, BF_OPEN_2ea438a263a3c9b9eb33eab0_2 +BF_CLOSE_2ea438a263a3c9b9eb33eab0_2: + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_4c1ef806ba420be0efb9a923_2 +BF_OPEN_4c1ef806ba420be0efb9a923_2: + addi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_9fdf192325e5783cc41b5114_3 +BF_OPEN_9fdf192325e5783cc41b5114_3: + addi $t0, $t0, 1 + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_9fdf192325e5783cc41b5114_3 +BF_CLOSE_9fdf192325e5783cc41b5114_3: + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_e8df779bf54411ddcedd73e9_3 +BF_OPEN_e8df779bf54411ddcedd73e9_3: + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_e8df779bf54411ddcedd73e9_3 +BF_CLOSE_e8df779bf54411ddcedd73e9_3: + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + bnez $t1, BF_OPEN_4c1ef806ba420be0efb9a923_2 +BF_CLOSE_4c1ef806ba420be0efb9a923_2: + addi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_6691ea42e52a89fc748855be_1 +BF_CLOSE_6691ea42e52a89fc748855be_1: + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + subi $t0, $t0, 1 + lb $t1, ($t0) + beqz $t1, BF_CLOSE_fec1fd3ab7ab016a1552e024_1 +BF_OPEN_fec1fd3ab7ab016a1552e024_1: + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + subi $t0, $t0, 1 + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + beqz $t1, BF_CLOSE_afba6ad72f92428f34a02d45_2 +BF_OPEN_afba6ad72f92428f34a02d45_2: + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + beqz $t1, BF_CLOSE_c9a39424c26f09d483798f17_3 +BF_OPEN_c9a39424c26f09d483798f17_3: + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + beqz $t1, BF_CLOSE_c117020f39526c2cf7be5e43_4 +BF_OPEN_c117020f39526c2cf7be5e43_4: + subi $t0, $t0, 1 + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + subi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + beqz $t1, BF_CLOSE_a1bbf73d7f4f1f1b324e4d9c_5 +BF_OPEN_a1bbf73d7f4f1f1b324e4d9c_5: + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + bnez $t1, BF_OPEN_a1bbf73d7f4f1f1b324e4d9c_5 +BF_CLOSE_a1bbf73d7f4f1f1b324e4d9c_5: + lb $t1, ($t0) + bnez $t1, BF_OPEN_c117020f39526c2cf7be5e43_4 +BF_CLOSE_c117020f39526c2cf7be5e43_4: + lb $t1, ($t0) + bnez $t1, BF_OPEN_c9a39424c26f09d483798f17_3 +BF_CLOSE_c9a39424c26f09d483798f17_3: + lb $t1, ($t0) + bnez $t1, BF_OPEN_afba6ad72f92428f34a02d45_2 +BF_CLOSE_afba6ad72f92428f34a02d45_2: + subi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + subi $t0, $t0, 1 + lb $t1, ($t0) + addi $t1, $t1, 1 + sb $t1, ($t0) + lb $t1, ($t0) + bnez $t1, BF_OPEN_fec1fd3ab7ab016a1552e024_1 +BF_CLOSE_fec1fd3ab7ab016a1552e024_1: + addi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_5439ab2c390f42ded5ac5f4f_0 +BF_CLOSE_5439ab2c390f42ded5ac5f4f_0: + addi $t0, $t0, 1 + addi $t0, $t0, 1 + lb $t1, ($t0) + bnez $t1, BF_OPEN_8904e378099c118eaada9d20_18446744073709551615 +BF_CLOSE_8904e378099c118eaada9d20_18446744073709551615: + lb $t1, ($t0) + beqz $t1, BF_CLOSE_6318c250706a551487b6e1de_18446744073709551615 +BF_OPEN_6318c250706a551487b6e1de_18446744073709551615: + li $v0, 11 + lb $a0, ($t0) + syscall + li $v0, 11 + lb $a0, ($t0) + syscall + li $v0, 11 + lb $a0, ($t0) + syscall + li $v0, 11 + lb $a0, ($t0) + syscall + li $v0, 12 + syscall + sb $v0, ($t0) + li $v0, 11 + lb $a0, ($t0) + syscall + li $v0, 11 + lb $a0, ($t0) + syscall + li $v0, 11 + lb $a0, ($t0) + syscall + li $v0, 12 + syscall + sb $v0, ($t0) + li $v0, 12 + syscall + sb $v0, ($t0) + li $v0, 11 + lb $a0, ($t0) + syscall + li $v0, 11 + lb $a0, ($t0) + syscall + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + li $v0, 11 + lb $a0, ($t0) + syscall + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + li $v0, 11 + lb $a0, ($t0) + syscall + li $v0, 11 + lb $a0, ($t0) + syscall + lb $t1, ($t0) + subi $t1, $t1, 1 + sb $t1, ($t0) + li $v0, 11 + lb $a0, ($t0) + syscall + li $v0, 11 + lb $a0, ($t0) + syscall + lb $t1, ($t0) + bnez $t1, BF_OPEN_6318c250706a551487b6e1de_18446744073709551615 +BF_CLOSE_6318c250706a551487b6e1de_18446744073709551615: diff --git a/squares.bf b/squares.bf new file mode 100644 index 0000000..b235485 --- /dev/null +++ b/squares.bf @@ -0,0 +1,8 @@ +++++[>+++++<-]>[<+++++>-]+<+[ + >[>+>+<<-]++>>[<<+>>-]>>>[-]++>[-]+ + >>>+[[-]++++++>>>]<<<[[<++++++++<++>>-]+<.<[>----<-]<] + <<[>>>>>[>>>[-]+++++++++<[>-<-]+++++++++>[-[<->-]+[<<<]]<[>+<-]>]<<-]<<- +] +[Outputs square numbers from 0 to 10000. +Daniel B Cristofani (cristofdathevanetdotcom) +http://www.hevanet.com/cristofd/brainfuck/] diff --git a/src/bf_mips_codegen.cpp b/src/bf_mips_codegen.cpp index 9361acd..60a8932 100644 --- a/src/bf_mips_codegen.cpp +++ b/src/bf_mips_codegen.cpp @@ -27,22 +27,22 @@ std::string preamble = ".data\n" void process_print(const std::vector& tokens, size_t index); -void codegen(const std::vector& tokens, std::ostream& out) +void codegen(tokenizer& tokenizer, std::ostream& out) { out << preamble; size_t index = 0; // skip past comments - if (tokens[index].token == bf_token::OPEN) + if (tokenizer.next().value().get().token == bf_token::OPEN) while (tokens[index].token != bf_token::CLOSE) index++; - process_print(tokens, index); + tokenizer.print(index); size_t sp = 0; while (index < tokens.size()) { auto& token = tokens[index++]; - std::string name{"UNNAMED"}; + uint64_t name = 0; if (token.name.has_value()) name = token.name.value(); switch (token.token) @@ -75,76 +75,17 @@ void codegen(const std::vector& tokens, std::ostream& out) break; case bf_token::OPEN: out << "\tlb $t1, ($t0)\n" - << "\tbeqz $t1, BF_CLOSE_" << name << "_" << std::to_string(sp) << '\n' - << "BF_OPEN_" << name << "_" << std::to_string(sp) << ":\n"; + << "\tbeqz $t1, BF_CLOSE_" << name << "_" << sp << '\n' + << "BF_OPEN_" << name << "_" << sp << ":\n"; sp++; break; case bf_token::CLOSE: sp--; out << "\tlb $t1, ($t0)\n" - << "\tbnez $t1, BF_OPEN_" << name << "_" << std::to_string(sp) << '\n' - << "BF_CLOSE_" << name << "_" << std::to_string(sp) << ":\n"; + << "\tbnez $t1, BF_OPEN_" << name << "_" << sp << '\n' + << "BF_CLOSE_" << name << "_" << sp << ":\n"; break; } } } -inline void tabulate(size_t v) -{ - for (size_t i = 0; i < v; i++) - std::cout << '\t'; -} - -void process_print(const std::vector& tokens, size_t index) -{ - size_t sp = 0; - while (index < tokens.size()) - { - auto& token = tokens[index++]; - switch (token.token) - { - case bf_token::INC_DP: - tabulate(sp); - std::cout << "Increase DP\n"; - break; - case bf_token::DEC_DP: - tabulate(sp); - std::cout << "Decrease DP\n"; - break; - case bf_token::INC_DV: - tabulate(sp); - std::cout << "Increase DV\n"; - break; - case bf_token::DEC_DV: - tabulate(sp); - std::cout << "Decrease DV\n"; - break; - case bf_token::PRINT: - tabulate(sp); - std::cout << "Print\n"; - break; - case bf_token::READ: - tabulate(sp); - std::cout << "Read\n"; - break; - case bf_token::OPEN: - tabulate(sp); - std::cout << "If("; - if (token.name.has_value()) - std::cout << token.name.value() << "\n"; - else - std::cout << "UNNAMED" << "\n"; - sp++; - break; - case bf_token::CLOSE: - sp--; - tabulate(sp); - if (token.name.has_value()) - std::cout << token.name.value(); - else - std::cout << "UNNAMED"; - std::cout << ")\n"; - break; - } - } -} diff --git a/src/bf_tokenizer.cpp b/src/bf_tokenizer.cpp index 403fc15..eac0ddc 100644 --- a/src/bf_tokenizer.cpp +++ b/src/bf_tokenizer.cpp @@ -6,11 +6,25 @@ #include #include #include +#include -std::vector tokenize(const std::string& program) +std::string generateName() { - std::vector tokens; + std::stringstream ss; + ss << std::hex; + static std::random_device rd; + static std::seed_seq seed{rd(), rd(), rd(), rd()}; + static std::mt19937_64 gen(seed); + static std::uniform_int_distribution dis(0, 15); + for (int i = 0; i < 24; i++) + ss << dis(gen); + + return ss.str(); +} + +void tokenizer::tokenize(const std::string& program) +{ size_t index = 0; while (index < program.size()) { @@ -46,33 +60,16 @@ std::vector tokenize(const std::string& program) } index++; } - - return tokens; } -std::string generateName() -{ - std::stringstream ss; - ss << std::hex; - std::random_device rd; - std::seed_seq seed{rd(), rd(), rd(), rd()}; - std::mt19937_64 gen(seed); - std::uniform_int_distribution dis(0, 15); - - for (int i = 0; i < 24; i++) - ss << dis(gen); - - return ss.str(); -} - -std::vector& bf_name(std::vector& tokens) +void tokenizer::bf_name() { size_t search_index = 0; while (search_index < tokens.size()) { if (tokens[search_index].token == bf_token::OPEN) { - auto name = generateName(); + auto name = ++conditionalCount; size_t sp = 1; size_t search_2 = search_index; tokens[search_index].name = name; @@ -89,5 +86,64 @@ std::vector& bf_name(std::vector& tokens) } search_index++; } - return tokens; +} + +inline void tabulate(signed long long v) +{ + for (signed long long i = 0; i < v; i++) + std::cout << '\t'; +} + +void tokenizer::print(size_t index) +{ + signed long long sp = 1; + while (index < tokens.size()) + { + auto& token = tokens[index++]; + switch (token.token) + { + case bf_token::INC_DP: + tabulate(sp); + std::cout << "Increase DP\n"; + break; + case bf_token::DEC_DP: + tabulate(sp); + std::cout << "Decrease DP\n"; + break; + case bf_token::INC_DV: + tabulate(sp); + std::cout << "Increase DV\n"; + break; + case bf_token::DEC_DV: + tabulate(sp); + std::cout << "Decrease DV\n"; + break; + case bf_token::PRINT: + tabulate(sp); + std::cout << "Print\n"; + break; + case bf_token::READ: + tabulate(sp); + std::cout << "Read\n"; + break; + case bf_token::OPEN: + tabulate(sp); + std::cout << "If("; + if (token.name.has_value()) + std::cout << token.name.value() << "\n"; + else + std::cout << "UNNAMED" << "\n"; + sp++; + break; + case bf_token::CLOSE: + sp--; + tabulate(sp); + if (token.name.has_value()) + std::cout << token.name.value(); + else + std::cout << "UNNAMED"; + std::cout << ")\n"; + break; + } + } } diff --git a/src/main.cpp b/src/main.cpp index abc38d1..5aa1fcc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,16 +8,15 @@ int main(int argc, const char** argv) { - std::string file{"../helloworld.bf"}; + std::string file{"../life.bf"}; if (argc > 1) file = argv[1]; auto program = blt::fs::loadBrainFuckFile(file); std::ofstream out{"../mips.asm"}; - auto tokens = tokenize(program); - bf_name(tokens); - codegen(tokens, out); + tokenizer tokenizer(program); + codegen(tokenizer, out); return 0; } \ No newline at end of file