1 // Copyright 2014 Wouter van Oortmerssen. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #ifndef LOBSTER_DISASM
16 #define LOBSTER_DISASM
17
18 #include "lobster/natreg.h"
19
20 #define FLATBUFFERS_DEBUG_VERIFICATION_FAILURE
21 #include "lobster/bytecode_generated.h"
22
23 namespace lobster {
24
IdName(const bytecode::BytecodeFile * bcf,int i)25 inline string IdName(const bytecode::BytecodeFile *bcf, int i) {
26 auto idx = bcf->specidents()->Get(i)->ididx();
27 int j = i;
28 // FIXME: this theoretically can span 2 specializations of the same var.
29 while (j && bcf->specidents()->Get(j - 1)->ididx() == idx) j--;
30 auto basename = bcf->idents()->Get(idx)->name()->string_view();
31 return j == i ? string(basename) : cat(basename, '+', i - j);
32 }
33
34 const bytecode::LineInfo *LookupLine(const int *ip, const int *code,
35 const bytecode::BytecodeFile *bcf);
36
37 const int *DisAsmIns(NativeRegistry &natreg, ostringstream &ss, const int *ip, const int *code,
38 const type_elem_t *typetable, const bytecode::BytecodeFile *bcf);
39
40 void DisAsm(NativeRegistry &natreg, ostringstream &ss, string_view bytecode_buffer);
41
42 } // namespace lobster
43
44 #endif // LOBSTER_DISASM
45