Skip to content

OZ bytecode help #352

Description

@matdubuisson

Hello everyone,

I'm building a dataflow debugger for my thesis and it will deduce useful conclusions on the fly reading the executed bytecode of the virtual machine at run-time. To do so, I need to understand very well the OZ bytecode thus I decided to build a small OZ decompiler (maybe the name has to change) to help my to analyze it. It read an OZF file byte by byte and prints in human readable form the bytecode. I decoded all possible instructions from opCodes.hh regarding emulate.cc and cached/inline-emulate.cc to know what are their arguments however I got a lot of non interpreted bytes. I guess this is mostly constant/static data but I'm not sure and a little lost. Have you explanations or I was searching for the file from the OZ compile lib/ that actually write these bytes into an OZF file in order to understand what are these bytes.

Also I see there are instructions to create variables and move them using the different types of register, conditional ones, unification and instructions to call build-in. However no explicit I didn't find instructions to create threads so I think threads are triggered by calling built-in functions but I wanted to be sure this is not in the non-interpreted bytes ? Maybe have you places to advise me to look at ? I have already passed some time on the emulation/VM codes.

The decompiler outputs is something like below and non-interpreted bytes are the 'Word' lines :

matdubuisson@rogy:~/Mozart/thesis/decompiler$ cat Test.oz
functor
import
    System
    Application
define
    Args = {Application.getArgs record() $}
in
    {System.show {String.toAtom Args.1.1}}
end
matdubuisson@rogy:~/Mozart/thesis/decompiler$ ozdc Test.ozf > output.txt 
matdubuisson@rogy:~/Mozart/thesis/decompiler$ head -10 output.txt 
0       Skip
1       Word    '3008'
2       Skip
3       MoveXX  %x(0),%x(3008)
4       Word    '3328'
5       Skip
6       Word    '1536'
7       MoveMoveXYXY    %y(48909),%x(0),%x(5),%y(0)
8       Word    '3006'
9       Word    '3328'
matdubuisson@rogy:~/Mozart/thesis/decompiler$ cat output.txt | grep -v "Word" | head -100
0       Skip
2       Skip
3       MoveXX  %x(0),%x(3008)
5       Skip
7       MoveMoveXYXY    %y(48909),%x(0),%x(5),%y(0)
10      Skip
12      MoveMoveXYXY    %y(48397),%x(0),%x(6),%y(0)
15      Skip
17      Skip
20      Skip
22      MoveMoveXYXY    %y(47629),%x(0),%x(6),%y(0)
25      Skip
27      MoveMoveXYXY    %y(47117),%x(0),%x(6),%y(0)
30      Skip
32      MoveMoveXYXY    %y(46605),%x(0),%x(5),%y(0)
35      Skip
37      MoveMoveXYXY    %y(46093),%x(0),%x(6),%y(0)
40      Skip
42      MoveMoveXYXY    %y(45581),%x(0),%x(6),%y(0)
45      Skip
47      MoveMoveXYXY    %y(45069),%x(0),%x(5),%y(0)
50      Skip
52      MoveMoveXYXY    %y(44557),%x(0),%x(5),%y(0)
55      Skip
57      MoveMoveXYXY    %y(44045),%x(0),%x(6),%y(0)
60      Skip
62      MoveMoveXYXY    %y(43533),%x(0),%x(5),%y(0)
65      Skip
68      MoveMoveXYXY    %y(42241),%x(0),%x(1),%y(12800)
69      MoveMoveXYXY    %y(41989),%x(0),%x(3),%y(28265)
71      MoveMoveXYXY    %y(41741),%x(0),%x(7),%y(0)
74      Skip
76      MoveMoveXYXY    %y(41229),%x(0),%x(6),%y(0)
79      Skip
81      MoveMoveXYXY    %y(40717),%x(0),%x(4),%y(0)
84      Skip
86      MoveMoveXYXY    %y(40205),%x(0),%x(5),%y(0)
89      Skip
91      MoveMoveXYXY    %y(39693),%x(0),%x(5),%y(0)
94      Skip
96      MoveMoveXYXY    %y(39181),%x(0),%x(9),%y(0)
99      Skip
101     MoveMoveXYXY    %y(38669),%x(0),%x(8),%y(0)
104     Skip
106     MoveMoveXYXY    %y(38157),%x(0),%x(8),%y(0)
109     Skip
111     MoveMoveXYXY    %y(37645),%x(0),%x(8),%y(0)
114     Skip
116     MoveMoveXYXY    %y(37133),%x(0),%x(5),%y(0)
119     Skip
121     MoveMoveXYXY    %y(36621),%x(0),%x(6),%y(0)
124     Skip
126     MoveMoveXYXY    %y(36109),%x(0),%x(6),%y(0)
129     Skip
131     MoveMoveXYXY    %y(35597),%x(0),%x(6),%y(0)
134     Skip
136     MoveMoveXYXY    %y(35085),%x(0),%x(6),%y(0)
139     Skip
141     MoveMoveXYXY    %y(34573),%x(0),%x(6),%y(0)
144     Skip
146     MoveMoveXYXY    %y(34061),%x(0),%x(6),%y(0)
149     Skip
151     MoveMoveXYXY    %y(33281),%x(0),%x(1),%y(13056)
152     MoveMoveXYXY    %y(29441),%x(0),%x(1),%y(13824)
153     MoveMoveXYXY    %y(28173),%x(0),%x(4),%y(0)
156     Skip
158     MoveMoveXYXY    %y(27393),%x(0),%x(1),%y(14592)
159     MoveMoveXYXY    %y(26125),%x(0),%x(5),%y(0)
162     Skip
164     MoveMoveXYXY    %y(25613),%x(0),%x(8),%y(0)
167     Skip
169     MoveMoveXYXY    %y(25101),%x(0),%x(7),%y(0)
172     Skip
174     MoveMoveXYXY    %y(24589),%x(0),%x(6),%y(0)
177     Skip
179     MoveMoveXYXY    %y(24077),%x(0),%x(6),%y(0)
182     Skip
184     MoveMoveXYXY    %y(21761),%x(0),%x(3),%y(12593)
186     MoveMoveXYXY    %y(20993),%x(0),%x(2),%y(12854)
187     Skip
190     Skip
192     Skip
195     Skip
197     Skip
200     Skip
202     MoveMoveXYXY    %y(17165),%x(0),%x(3),%y(0)
205     Skip
207     MoveMoveXYXY    %y(13581),%x(0),%x(4),%y(0)
210     Skip
212     MoveMoveXYXY    %y(12301),%x(0),%x(6),%y(0)
215     Skip
218     Skip
221     Skip
245     MoveMoveXYXY    %y(9985),%x(0),%x(1),%y(13312)
246     MoveMoveXYXY    %y(8973),%x(0),%x(6),%y(0)
249     Skip
251     MoveMoveXYXY    %y(6925),%x(0),%x(5),%y(0)
254     Skip
256     MoveMoveXYXY    %y(4877),%x(0),%x(5),%y(0)
259     Skip
matdubuisson@rogy:~/Mozart/thesis/decompiler$ cat output-decompiler.txt | grep CallBuilt
3973    CallBuiltin0    %k(1280)
4202    CallBuiltin1    %k(0),%x(1051)
5479    CallBuiltin1    %k(5),%x(0)
5936    CallBuiltin3    %k(1),%x(2),%x(1),%x(4)
5946    CallBuiltin1    %k(7),%x(1)
6136    CallBuiltin1    %k(7),%x(1)
6228    CallBuiltin1    %k(7),%x(0)
7236    CallBuiltin1    %k(5),%x(1)
8080    CallBuiltin1    %k(6),%x(1)
8367    CallBuiltin1    %k(6),%x(1)
9125    CallBuiltin1    %k(7),%x(0)
10176   CallBuiltin1    %k(6),%x(1)
10523   CallBuiltin3    %k(1),%x(1),%x(3),%x(4)
10541   CallBuiltin1    %k(9),%x(1)
10712   CallBuiltin1    %k(6),%x(1)
11108   CallBuiltin1    %k(6),%x(1)
11134   CallBuiltin2    %k(7),%x(0),%x(4)
11135   CallBuiltin3    %k(1),%x(2),%x(4),%x(5)
11142   CallBuiltin1    %k(6),%x(0)
11192   CallBuiltin0    %k(7)
11202   CallBuiltin1    %k(7),%x(0)
11348   CallBuiltin1    %k(8),%x(0)
11353   CallBuiltin1    %k(8),%x(0)
11467   CallBuiltin1    %k(6),%x(1)
11492   CallBuiltin3    %k(1),%x(0),%x(2),%x(3)
11688   CallBuiltin3    %k(3),%x(0),%x(1),%x(5)
11698   CallBuiltin1    %k(8),%x(0)
11703   CallBuiltin1    %k(8),%x(0)
11846   CallBuiltin1    %k(5),%x(1)
12210   CallBuiltin1    %k(5),%x(1)
12448   CallBuiltin1    %k(5),%x(1)
12488   CallBuiltin1    %k(5),%x(0)
12994   CallBuiltin1    %k(5),%x(1)
13101   CallBuiltin1    %k(7),%x(0)
13106   CallBuiltin1    %k(7),%x(1)
14185   CallBuiltin3    %k(1),%x(4),%x(5),%x(6)
14205   CallBuiltin1    %k(8),%x(0)
14315   CallBuiltin3    %k(1),%x(2),%x(3),%x(4)
14363   CallBuiltin3    %k(1),%x(3),%x(4),%x(5)
14902   CallBuiltin1    %k(5),%x(0)
14942   CallBuiltin1    %k(5),%x(0)
15314   CallBuiltin3    %k(1),%x(3),%x(4),%x(5)
15317   CallBuiltin3    %k(1),%x(4),%x(6),%x(7)
15367   CallBuiltin3    %k(1),%x(3),%x(5),%x(6)
15415   CallBuiltin3    %k(1),%x(0),%x(5),%x(6)
15426   CallBuiltin1    %k(9),%x(0)
15724   CallBuiltin3    %k(1),%x(0),%x(4),%x(1)
15727   CallBuiltin3    %k(1),%x(2),%x(4),%x(5)
15738   CallBuiltin3    %k(1),%x(0),%x(5),%x(6)
15798   CallBuiltin3    %k(1),%x(0),%x(2),%x(3)
15803   CallBuiltin3    %k(1),%x(0),%x(5),%x(6)
16308   CallBuiltin3    %k(1),%x(4),%x(5),%x(6)
16437   CallBuiltin1    %k(0),%x(2367)
16729   CallBuiltin5    %k(24),%x(6),%x(3),%x(2),%x(1),%x(45)
16751   CallBuiltin1    %k(6),%x(0)
16777   CallBuiltin1    %k(1),%x(2)
16975   CallBuiltin3    %k(1),%x(0),%x(4),%x(5)
16977   CallBuiltin3    %k(2),%x(3),%x(0),%x(4)
16978   CallBuiltin3    %k(2),%x(1),%x(0),%x(5)
16996   CallBuiltin1    %k(8),%x(0)
17427   CallBuiltin3    %k(1),%x(2),%x(3),%x(4)
18775   CallBuiltin3    %k(1),%x(0),%x(1),%x(2)
18778   CallBuiltin3    %k(3),%x(0),%x(1),%x(2)
18783   CallBuiltin3    %k(1),%x(0),%x(1),%x(2)
18786   CallBuiltin3    %k(3),%x(0),%x(1),%x(2)
18930   CallBuiltin3    %k(2),%x(0),%x(1),%x(5)
18982   CallBuiltin3    %k(1),%x(2),%x(3),%x(4)
19003   CallBuiltin2    %k(5),%x(0),%x(1)
19017   CallBuiltin2    %k(5),%x(0),%x(1)
19582   CallBuiltin5    %k(2304),%x(0),%x(61952),%x(0),%x(768),%x(11)

This is the code of this prototype https://github.com/matdubuisson/mozart2/blob/fun/lib/main/ozbatch/Decompile.oz . I guess that is not perfect there is some code repeatition of bytecode codes and maybe misplaced or named but following your advice I can adapt that.

Thank you very much for your time,
Mattéo,

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions