qute

A software analysis framework built around the QBE intermediate language

git clone https://git.8pit.net/qute.git

 1-- SPDX-FileCopyrightText: 2025 Sören Tempel <soeren+git@soeren-tempel.net>
 2--
 3-- SPDX-License-Identifier: GPL-3.0-only
 4
 5module Main (main) where
 6
 7import Control.Monad (void)
 8import Criterion.Main (Benchmarkable, bench, bgroup, defaultMain, nfIO)
 9import Data.Word (Word32, Word64, Word8)
10import Language.QBE (parseAndFind)
11import Language.QBE.Simulator (execFunc)
12import Language.QBE.Simulator.Default.Expression qualified as D
13import Language.QBE.Simulator.Default.State (Env, mkEnv, run)
14import Language.QBE.Types qualified as QBE
15
16exec :: [D.RegVal] -> String -> IO ()
17exec params input = do
18  (prog, func) <- parseAndFind entryFunc input
19
20  env <- mkEnv prog 0 memSize :: IO (Env D.RegVal Word8)
21  void $ run env (execFunc func params)
22  where
23    memSize :: Word64
24    memSize = 1024 * 1024 * 10
25
26    entryFunc :: QBE.GlobalIdent
27    entryFunc = QBE.GlobalIdent "entry"
28
29bubbleSort :: Word32 -> Benchmarkable
30bubbleSort inputSize =
31  nfIO (readFile "bench/data/bubble-sort.qbe" >>= exec [D.VWord inputSize])
32
33-- Our benchmark harness.
34main :: IO ()
35main =
36  defaultMain
37    [ bgroup
38        "bubble-sort"
39        [ bench "10" $ bubbleSort 25,
40          bench "50" $ bubbleSort 50,
41          bench "100" $ bubbleSort 100
42        ]
43    ]