quebex

A software analysis framework built around the QBE intermediate language

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

 1-- SPDX-FileCopyrightText: 2025 Sören Tempel <soeren+git@soeren-tempel.net>
 2--
 3-- SPDX-License-Identifier: MIT AND GPL-3.0-only
 4
 5-- TODO: Code duplication with quebex/bench/{Main.hs,Exec.hs}
 6module Exec (execBench) where
 7
 8import Control.Monad (void)
 9import Criterion.Main
10import Data.List (find)
11import Data.Word (Word64, Word8)
12import Language.QBE (globalFuncs, parse)
13import Language.QBE.Simulator (execFunc)
14import Language.QBE.Simulator.Concolic.Expression qualified as CE
15import Language.QBE.Simulator.Default.Expression qualified as DE
16import Language.QBE.Simulator.Default.State (SimState, run)
17import Language.QBE.Simulator.Expression qualified as E
18import Language.QBE.Types qualified as QBE
19
20entryFunc :: QBE.GlobalIdent
21entryFunc = QBE.GlobalIdent "entry"
22
23exec :: [CE.Concolic DE.RegVal] -> String -> IO ()
24exec params input = do
25  prog <- case parse "input" input of
26    Left err -> fail $ "parsing error: " ++ show err
27    Right pr -> pure pr
28
29  let funcs = globalFuncs prog
30  func <- case find (\f -> QBE.fName f == entryFunc) funcs of
31    Just x -> pure x
32    Nothing -> fail $ "unknown function: " ++ show entryFunc
33
34  void $ run prog (execFunc func params :: SimState (CE.Concolic DE.RegVal) (CE.Concolic Word8) (Maybe (CE.Concolic DE.RegVal)))
35
36------------------------------------------------------------------------
37
38bubbleSort :: Word64 -> Benchmarkable
39bubbleSort inputSize =
40  nfIO (readFile "bench/data/Exec/bubble-sort.qbe" >>= exec [E.fromLit QBE.Word inputSize])
41
42execBench :: Benchmark
43execBench =
44  bgroup
45    "Concrete Execution"
46    [ bench "10" $ bubbleSort 25,
47      bench "50" $ bubbleSort 50,
48      bench "100" $ bubbleSort 100
49    ]