Skip to content

Commit a93a9b2

Browse files
committed
JIT: Add DWARF support
Signed-off-by: Paul Guyot <[email protected]>
1 parent daa43c9 commit a93a9b2

File tree

20 files changed

+2850
-192
lines changed

20 files changed

+2850
-192
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ option(AVM_DISABLE_SMP "Disable SMP." OFF)
3333
option(AVM_DISABLE_TASK_DRIVER "Disable task driver support." OFF)
3434
option(AVM_DISABLE_JIT "Disable just in time compilation." ON)
3535
option(AVM_ENABLE_PRECOMPILED "Enable execution of precompiled code, even if JIT is disabled." OFF)
36+
option(AVM_DISABLE_JIT_DWARF "Disable DWARF debug and profiling info for JIT." ON)
3637
option(AVM_USE_32BIT_FLOAT "Use 32 bit floats." OFF)
3738
option(AVM_VERBOSE_ABORT "Print module and line number on VM abort" OFF)
3839
option(AVM_RELEASE "Build an AtomVM release" OFF)

CMakeModules/BuildErlang.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ macro(pack_archive avm_name)
2222

2323
set(multiValueArgs ERLC_FLAGS MODULES)
2424
cmake_parse_arguments(PACK_ARCHIVE "" "" "${multiValueArgs}" ${ARGN})
25-
list(JOIN PACK_ARCHIVE_ERLC_FLAGS " " PACK_ARCHIVE_ERLC_FLAGS)
2625
foreach(module_name IN LISTS ${PACK_ARCHIVE_MODULES} PACK_ARCHIVE_MODULES PACK_ARCHIVE_UNPARSED_ARGUMENTS)
2726
add_custom_command(
2827
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/beams/${module_name}.beam
@@ -83,6 +82,7 @@ macro(pack_precompiled_archive avm_name)
8382
string(REGEX REPLACE "\\+.*$" "" jit_target_arch "${jit_target_arch_variant}")
8483
set(jit_compiler_modules
8584
${CMAKE_BINARY_DIR}/libs/jit/src/beams/jit.beam
85+
${CMAKE_BINARY_DIR}/libs/jit/src/beams/jit_dwarf.beam
8686
${CMAKE_BINARY_DIR}/libs/jit/src/beams/jit_precompile.beam
8787
${CMAKE_BINARY_DIR}/libs/jit/src/beams/jit_stream_binary.beam
8888
${CMAKE_BINARY_DIR}/libs/jit/src/beams/jit_${jit_target_arch}.beam

libs/jit/src/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ include(BuildErlang)
2424

2525
set(ERLANG_MODULES
2626
jit
27+
jit_dwarf
2728
jit_precompile
2829
jit_stream_binary
2930
jit_stream_mmap
@@ -35,7 +36,13 @@ set(ERLANG_MODULES
3536
jit_x86_64_asm
3637
)
3738

38-
pack_precompiled_archive(jit ${ERLANG_MODULES})
39+
if (NOT AVM_DISABLE_JIT_DWARF)
40+
set(erlc_flags -DJIT_DWARF)
41+
else()
42+
set(erlc_flags)
43+
endif()
44+
45+
pack_precompiled_archive(jit ERLC_FLAGS ${erlc_flags} MODULES ${ERLANG_MODULES})
3946

4047
include(../../../version.cmake)
4148

libs/jit/src/compact_term.hrl

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
%
2+
% This file is part of AtomVM.
3+
%
4+
% Copyright 2025 Paul Guyot <[email protected]>
5+
%
6+
% Licensed under the Apache License, Version 2.0 (the "License");
7+
% you may not use this file except in compliance with the License.
8+
% You may obtain a copy of the License at
9+
%
10+
% http://www.apache.org/licenses/LICENSE-2.0
11+
%
12+
% Unless required by applicable law or agreed to in writing, software
13+
% distributed under the License is distributed on an "AS IS" BASIS,
14+
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
% See the License for the specific language governing permissions and
16+
% limitations under the License.
17+
%
18+
% SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
19+
%
20+
21+
22+
-define(COMPACT_LITERAL, 0).
23+
-define(COMPACT_INTEGER, 1).
24+
-define(COMPACT_ATOM, 2).
25+
-define(COMPACT_XREG, 3).
26+
-define(COMPACT_YREG, 4).
27+
-define(COMPACT_LABEL, 5).
28+
-define(COMPACT_EXTENDED, 7).
29+
-define(COMPACT_LARGE_LITERAL, 8).
30+
-define(COMPACT_LARGE_INTEGER, 9).
31+
-define(COMPACT_LARGE_ATOM, 10).
32+
-define(COMPACT_LARGE_XREG, 11).
33+
-define(COMPACT_LARGE_YREG, 12).
34+
35+
% OTP-20+ format
36+
-define(COMPACT_EXTENDED_LIST, 16#17).
37+
-define(COMPACT_EXTENDED_FP_REGISTER, 16#27).
38+
-define(COMPACT_EXTENDED_ALLOCATION_LIST, 16#37).
39+
-define(COMPACT_EXTENDED_LITERAL, 16#47).
40+
% https://github.com/erlang/otp/blob/master/lib/compiler/src/beam_asm.erl#L433
41+
-define(COMPACT_EXTENDED_TYPED_REGISTER, 16#57).
42+
43+
-define(COMPACT_EXTENDED_ALLOCATOR_LIST_TAG_WORDS, 0).
44+
-define(COMPACT_EXTENDED_ALLOCATOR_LIST_TAG_FLOATS, 1).
45+
-define(COMPACT_EXTENDED_ALLOCATOR_LIST_TAG_FUNS, 2).
46+
47+
-define(COMPACT_LARGE_IMM_MASK, 16#18).
48+
-define(COMPACT_11BITS_VALUE, 16#8).
49+
-define(COMPACT_NBITS_VALUE, 16#18).
50+
51+
-define(COMPACT_LARGE_INTEGER_11BITS, (?COMPACT_LARGE_INTEGER bor ?COMPACT_11BITS_VALUE)).
52+
-define(COMPACT_LARGE_INTEGER_NBITS, (?COMPACT_LARGE_INTEGER bor ?COMPACT_NBITS_VALUE)).

0 commit comments

Comments
 (0)