From 1e7fe5fa8e3dc8023a5ca34d6f0ac9396dc20ddb Mon Sep 17 00:00:00 2001 From: t <970370568@qq.com> Date: Sat, 13 Jan 2024 17:26:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=A5=E5=91=8A=201.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phase4/README.md | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/phase4/README.md b/phase4/README.md index f291d94..319272d 100644 --- a/phase4/README.md +++ b/phase4/README.md @@ -6,11 +6,47 @@ **12111611 Ruixiang Jiang** - +## How to Run and Test +1. make splc: `make` +2. auto test: `make test` ## Design - +### Language +Use python to implement make splc with pyinstaller ### Procedure Call +before the function is called: +1. Store Active Variables in the stack +2. jal in the target function +3. Store ra in the stack + +after the function is called: +1. get ra in the stack +2. the result is stored in the stack +3. the Active Variables are restored from the stack + +### Translation processing +check if the three address code has numbers: +1. Support the return value and input as numbers +2. Support multiplication and division containing numbers +3. The positions of registers and numbers can be switched arbitrarily (x := y - #k or x := #y - k is OK) + +More efficient: + +1. If there are no unknowns in addition, subtraction, multiplication, and division (that is, all numbers), the result is directly assigned to the target register +2. For commands that use a stack Variable, the variable in the stack is moved to the register using `lw`. Similarly, the variable in the stack can be identified by `sw` to the corresponding position + +More secure: + +In mips, an addi number greater than 32767 or less than -32767 causes an arithmetic overflow, which we detected and addressed (see test15). + +Easier to read: + +At the beginning, jal directly jumps to main, obtains the return value of main function and then ends, without adjusting the position of the three-address code function + +### Variables +We use specific registers `s6` for reading and writing and a portion of the stack space for storing common variables + +Have tried it on multiple platforms, websites, and can run on Mars and various versions of spim #### Active Variables @@ -32,3 +68,5 @@ Finally, clear the set after getting a new function TAC `FUNCTION f :` + +