Skip to content

Commit

Permalink
remove trace
Browse files Browse the repository at this point in the history
  • Loading branch information
TTENSHII committed Jan 14, 2024
1 parent 26f6c47 commit cafae16
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 26 deletions.
6 changes: 2 additions & 4 deletions lvtrun/app/Parsing/Code.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import Leb128
import Types
import Errors

import Debug.Trace

-- GET LOCALS

diviseBytes :: BSL.ByteString -> [BSL.ByteString]
Expand Down Expand Up @@ -101,7 +99,7 @@ extractOpCode bytes
| (head $ BSL.unpack bytes) == 0x47 = ([0x47], 1, BSL.drop 1 bytes)
| (BSL.unpack $ BSL.take 2 bytes) == [0x3f, 0x00] = ([0x3f, 0x00], 2, BSL.drop 2 bytes)
| (BSL.unpack $ BSL.take 2 bytes) == [0x40, 0x00] = ([0x40, 0x00], 2, BSL.drop 2 bytes)
| otherwise = trace ("extractOpCode: " ++ showBytes bytes) throw $ WasmError "ExtractOpCode2: bad opcode"
| otherwise = throw $ WasmError "ExtractOpCode2: bad opcode"

createInstruction :: OpCode -> BSL.ByteString -> (Instruction, BSL.ByteString)
createInstruction [0x03] bytes = (Nop, bytes)
Expand Down Expand Up @@ -180,7 +178,7 @@ createInstruction [0x21] bytes = do
(SetLocal value, rest)
createInstruction [0x3f, 0x00] bytes = (MemorySize, bytes)
createInstruction [0x40, 0x00] bytes = (MemoryGrow, bytes)
createInstruction opCode _ = trace ("createInstruction: " ++ show opCode) throw $ WasmError "createInstruction: bad instruction"
createInstruction opCode _ = throw $ WasmError "createInstruction: bad instruction"

parseInstruction :: BSL.ByteString -> (Instruction, BSL.ByteString)
parseInstruction bytes
Expand Down
2 changes: 0 additions & 2 deletions lvtrun/app/Parsing/Functions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import Types
import Errors
import Leb128

import Debug.Trace

parseFunctionsIndex :: Int32 -> Int64 -> BSL.ByteString -> [Function]
parseFunctionsIndex idx maxIdx content
| idx > (fromIntegral maxIdx) = []
Expand Down
2 changes: 0 additions & 2 deletions lvtrun/app/Parsing/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import Parsing.Exports
import Parsing.Functions
import Parsing.Code

import Debug.Trace

parseModule :: FileContent -> WasmModule
parseModule bytes = do
let sections = getSections bytes
Expand Down
2 changes: 0 additions & 2 deletions lvtrun/app/Run/Start.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,5 @@ import Errors
import Run.Vm
import Run.Functions

import Debug.Trace

start :: WasmModule -> IO ()
start wasmMod = startExecution (createVm wasmMod) (getStartFunctionId (exports wasmMod))
30 changes: 14 additions & 16 deletions lvtrun/app/Run/Vm.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import Types
import Errors
import Run.Functions

import Debug.Trace

data Value =
I_32 Int32
| I_64 Int64
Expand Down Expand Up @@ -205,22 +203,22 @@ incrementInstIdx cEx = cEx { ceInstIdx = ceInstIdx cEx + 1 }
---------------------------

execOpCode :: VM -> CurrentExec -> Instruction -> CurrentExec
execOpCode vm cEx (I32Const val) = trace ("--i32const--" ++ show val) cEx { ceStack = stackPush (ceStack cEx) (I_32 val) }
execOpCode vm cEx (Block _) = trace "--block--" addLabel cEx { crBlockIndents = (crBlockIndents cEx) + 1 }
execOpCode vm cEx (I32Const val) = cEx { ceStack = stackPush (ceStack cEx) (I_32 val) }
execOpCode vm cEx (Block _) = cEx { crBlockIndents = (crBlockIndents cEx) + 1 }
execOpCode vm cEx (I32Eqz) = do
let value = trace "--i32eqz--" stackTop (ceStack cEx)
let value = stackTop (ceStack cEx)
case value of
I_32 0 -> cEx { ceStack = stackPush (ceStack cEx) (I_32 1) }
I_32 _ -> cEx { ceStack = stackPush (ceStack cEx) (I_32 0) }
_ -> throw $ WasmError "exec I32eqz: bad type"
execOpCode vm cEx (I32Add) = do
let (value2, newStack1) = trace "--i32add--" stackPop (ceStack cEx)
let (value2, newStack1) = stackPop (ceStack cEx)
let (value1, newStack2) = stackPop newStack1
case (value1, value2) of
(I_32 val1, I_32 val2) -> cEx { ceStack = stackPush newStack2 (I_32 (val1 + val2)) }
_ -> throw $ WasmError "exec I32Add: bad type"
execOpCode vm cEx (I32Sub) = do
let (value2, newStack1) = trace "--i32sub--" stackPop (ceStack cEx)
let (value2, newStack1) = stackPop (ceStack cEx)
let (value1, newStack2) = stackPop newStack1
case (value1, value2) of
(I_32 val1, I_32 val2) -> cEx { ceStack = stackPush newStack2 (I_32 (val1 - val2)) }
Expand All @@ -232,20 +230,20 @@ execOpCode vm cEx (BrIf labelIdx) = do
I_32 _ -> cEx { ceStack = newStack, ceInstIdx = (fromIntegral labelIdx) }
_ -> throw $ WasmError "exec brIf: bad type"
execOpCode vm cEx (Call funcIdx) = do
let newVm = trace ("--call--" ++ show funcIdx) execFunctionWithIdx vm funcIdx (ceStack cEx)
let newVm = execFunctionWithIdx vm funcIdx (ceStack cEx)
let newStack = pushResults (ceStack cEx) (vmStack newVm) (ceResults (currentExec newVm))
cEx { ceStack = newStack }
execOpCode vm cEx (End) = trace "--end--" cEx { crBlockIndents = (crBlockIndents cEx) - 1 }
execOpCode vm cEx (Return) = trace "--end--" cEx { crBlockIndents = (crBlockIndents cEx) - 1 }
execOpCode vm cEx (End) = cEx { crBlockIndents = (crBlockIndents cEx) - 1 }
execOpCode vm cEx (Return) = cEx { crBlockIndents = (crBlockIndents cEx) - 1 }
execOpCode vm cEx (Unreachable) = throw $ WasmError "execOpCode: unreachable"
execOpCode vm cEx (GetLocal localIdx) = do
let value = trace ("--getLocal--" ++ show localIdx) getLocalFromId cEx localIdx
let value = getLocalFromId cEx localIdx
cEx { ceStack = stackPush (ceStack cEx) value }
execOpCode vm cEx (SetLocal localIdx) = do
let (value, newStack) = trace ("--setLocal--" ++ show localIdx) stackPop (ceStack cEx)
let (value, newStack) = stackPop (ceStack cEx)
let newLocals = setLocalWithId 0 (ceLocals cEx) value localIdx
cEx { ceStack = newStack, ceLocals = newLocals }
execOpCode vm cEx _ = trace ("not for: " ++ show (ceInstIdx cEx)) cEx
execOpCode vm cEx _ = cEx

execOpCodes :: VM -> [Instruction] -> CurrentExec
execOpCodes vm [] = currentExec vm
Expand All @@ -254,14 +252,14 @@ execOpCodes vm instructions
| ceInstIdx cEx < 0 = throw $ WasmError "execOpCodes: bad index"
| (instructions !! ceInstIdx cEx) == End && crBlockIndents cEx == 0 = cEx
| otherwise = do
let newCEx = trace ("currentOpCode: " ++ show (instructions !! ceInstIdx cEx)) execOpCode vm cEx (instructions !! ceInstIdx cEx)
let newCEx = execOpCode vm cEx (instructions !! ceInstIdx cEx)
let newVm = vm { currentExec = (incrementInstIdx newCEx) }
execOpCodes newVm instructions
where cEx = currentExec vm

execFunction :: VM -> VM
execFunction vm = do
let newCEx = trace ("exex: " ++ show (ceInstructions (currentExec vm))) execOpCodes vm (ceInstructions (currentExec vm))
let newCEx = execOpCodes vm (ceInstructions (currentExec vm))
vm { currentExec = newCEx, vmStack = (pushResults (vmStack vm) (ceStack newCEx) (ceResults newCEx)) }

execFunctionWithIdx :: VM -> FuncIdx -> Stack -> VM
Expand All @@ -270,7 +268,7 @@ execFunctionWithIdx vm funcIdx currentStack = do
let funcTypee = getFuncTypeFromId (funcType function) (types (wasmModule vm))
let (newLocals, newStack) = initLocals (locals function) (params funcTypee) currentStack
let cexec = CurrentExec {
ceLocals = trace ("ij" ++ show newLocals) newLocals,
ceLocals = newLocals,
ceStack = newStack,
ceInstructions = body function,
ceInstIdx = 0,
Expand Down

0 comments on commit cafae16

Please sign in to comment.