Skip to content

Commit

Permalink
Generate text IR by default, simplify format handling, generate error…
Browse files Browse the repository at this point in the history
… for unknown attr
  • Loading branch information
makxenov authored and nkaskov committed Nov 20, 2023
1 parent 259c7a1 commit f5414b5
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 27 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ option(BUILD_WITH_CCACHE "Build with ccache usage" TRUE)
option(BUILD_WITH_BOOST_STATIC_LIBS "Build using Boost static libraries" TRUE)
option(BUILD_TESTS "Build unit tests" FALSE)
option(BUILD_DOCS "Build with configuring Doxygen documentation compiler" TRUE)
option(CIRCUIT_ASSEMBLY_OUTPUT "Emit circuit IR as assembly file" TRUE)
option(CIRCUIT_BINARY_OUTPUT "Emit circuit IR as binary file" FALSE)

set(BUILD_WITH_TARGET_ARCHITECTURE "" CACHE STRING "Target build architecture")
set(DOXYGEN_OUTPUT_DIR "${CMAKE_CURRENT_LIST_DIR}/docs" CACHE STRING "Specify doxygen output directory")
Expand Down
25 changes: 11 additions & 14 deletions cmake/CircuitCompile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,8 @@ function(add_circuit_no_stdlib name)
endif()
list(REMOVE_DUPLICATES INCLUDE_DIRS_LIST)

if(CIRCUIT_ASSEMBLY_OUTPUT)
set(extension ll)
set(format_option -S)
if (NOT ${CIRCUIT_BINARY_OUTPUT})
set(link_options "-S")
else()
set(extension bc)
set(format_option -c)
endif()

if (ZKLLVM_DEV_ENVIRONMENT)
Expand All @@ -80,26 +75,26 @@ function(add_circuit_no_stdlib name)
add_custom_target(${name}_compile_sources)
foreach(source ${CIRCUIT_SOURCES})
get_filename_component(source_base_name ${source} NAME)
add_custom_target(${name}_${source_base_name}_${extension}
COMMAND ${CLANG} -target assigner
-D__ZKLLVM__ ${INCLUDE_DIRS_LIST} -emit-llvm -O1 ${format_option} ${ARG_COMPILER_OPTIONS} -o ${name}_${source_base_name}.${extension} ${source}
add_custom_target(${name}_${source_base_name}_ll
COMMAND ${CLANG} -target assigner -Xclang -fpreserve-vec3-type -Werror=unknown-attributes
-D__ZKLLVM__ ${INCLUDE_DIRS_LIST} -emit-llvm -O1 -S ${ARG_COMPILER_OPTIONS} -o ${name}_${source_base_name}.ll ${source}

VERBATIM COMMAND_EXPAND_LISTS

SOURCES ${source})
add_dependencies(${name}_compile_sources ${name}_${source_base_name}_${extension})
list(APPEND compiler_outputs "${name}_${source_base_name}.${extension}")
add_dependencies(${name}_compile_sources ${name}_${source_base_name}_ll)
list(APPEND compiler_outputs "${name}_${source_base_name}.ll")
endforeach()

# Link sources
add_custom_target(${name}
COMMAND ${LINKER} ${link_options} -o ${name}.${extension} ${compiler_outputs}
COMMAND ${LINKER} ${link_options} -o ${name}.ll ${compiler_outputs}
DEPENDS ${name}_compile_sources
VERBATIM COMMAND_EXPAND_LISTS)
if (${ZKLLVM_DEV_ENVIRONMENT})
add_dependencies(${name} zkllvm-libc)
endif()
set_target_properties(${name} PROPERTIES OUTPUT_NAME ${name}.${extension})
set_target_properties(${name} PROPERTIES OUTPUT_NAME ${name}.ll)
endfunction(add_circuit_no_stdlib)

function(add_circuit)
Expand All @@ -114,7 +109,9 @@ function(add_circuit)
set(LINKER llvm-link)
set(libc_stdlib "/usr/lib/zkllvm/zkllvm-libc.ll")
endif()
set(link_options "-S")
if (NOT ${CIRCUIT_BINARY_OUTPUT})
set(link_options "-S")
endif()

add_custom_target(${circuit_name}
COMMAND ${LINKER} ${link_options} -o ${circuit_name}.ll ${circuit_name}_no_stdlib.ll ${libc_stdlib}
Expand Down
6 changes: 1 addition & 5 deletions examples/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ function(add_example_without_proving example_target)
${Boost_LIBRARIES})
add_dependencies(circuit_cpp_examples "${example_target}")

if (CIRCUIT_ASSEMBLY_OUTPUT)
set(binary_name ${example_target}.ll)
else()
set(binary_name ${example_target}.bc)
endif()
set(binary_name ${example_target}.ll)

assign_ir(${example_target} ${binary_name} ${ARG_INPUT})
add_dependencies(assign_cpp_examples ${example_target}_assign)
Expand Down
4 changes: 2 additions & 2 deletions examples/cpp/balances_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ typename hashes::sha2<256>::block_type hash_layer(std::array<typename hashes::sh
}

[[circuit]] bool balance_tree(
[[private]] std::array<int64_t, precomputed_powers_of_two[validators_amount_log2]> validator_balances,
[[private_input]] std::array<int64_t, precomputed_powers_of_two[validators_amount_log2]> validator_balances,
typename hashes::sha2<256>::block_type expected_root,
unsigned long long expected_total_balance) {

Expand Down Expand Up @@ -162,4 +162,4 @@ typename hashes::sha2<256>::block_type hash_layer(std::array<typename hashes::sh
typename hashes::sha2<256>::block_type root = hash_layer<layer_with_zero_balance_subtrees_roots_size>(layer_with_zero_balance_subtrees_roots);

return (is_same(expected_root, root) && (expected_total_balance == total_balance));
}
}
6 changes: 1 addition & 5 deletions tests/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,7 @@ function(add_test_circuit_assign example_target)

${Boost_LIBRARIES})

if (CIRCUIT_ASSEMBLY_OUTPUT)
set(binary_name ${example_target}.ll)
else()
set(binary_name ${example_target}.bc)
endif()
set(binary_name ${example_target}.ll)

assign_ir(${example_target} ${binary_name} ${ARG_INPUT})
endfunction()
Expand Down

0 comments on commit f5414b5

Please sign in to comment.