Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for passing arguments to lambda_wrapper and added corou… #59

Merged
merged 4 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci-all-samples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jobs:
uses: actions/checkout@v2
with:
submodules: recursive
- run: sudo apt-get install g++
- run: make -C ${{ github.workspace }} -j$(nproc) run
- name: Install libunwind-dev
run: sudo apt-get install libunwind-dev libdwarf-dev=20200114-1 libdwarf1=20200114-1
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ all: executables

CHECK_CONFIG=1
CONFIG_STR=DEBUG=$(DEBUG) RECOVER_VAR_NAMES=$(RECOVER_VAR_NAMES) TRACER_USE_LIBUNWIND=$(TRACER_USE_LIBUNWIND)
CONFIG_STR+=EXTRA_CFLAGS=$(EXTRA_CFLAGS)


# Create a scratch directory where the files are stored
$(shell mkdir -p $(BASE_DIR)/scratch)
Expand Down
7 changes: 4 additions & 3 deletions include/builder/builder_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,18 @@ class tag_map {
std::unordered_map<std::string, block::stmt_block::Ptr> map;
};

void lambda_wrapper(void);
void lambda_wrapper(std::function<void(void)>);
void lambda_wrapper_close(void);
void lambda_wrapper_impl(void);

void coroutine_wrapper(std::function<void(void)>);
void coroutine_wrapper_close(void);

class builder_context {
public:
static builder_context *current_builder_context;
static int debug_creation_counter;

std::function<void(void)> internal_stored_lambda;
std::function<void(void)> current_function;

std::list<block::block::Ptr> uncommitted_sequence;
block::stmt::Ptr ast;
Expand Down
4 changes: 3 additions & 1 deletion make/setvars.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ endif
DEBUG=1
endif

EXTRA_CFLAGS?=

# Create CFLAGS, LINKER_FLAGS, CFLAGS_INTERNAL and INCLUDE_FLAGS based on config
CFLAGS_INTERNAL=-std=c++11 -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wmissing-declarations
CFLAGS_INTERNAL+=-Woverloaded-virtual -Wno-deprecated -Wdelete-non-virtual-dtor -Werror -Wno-vla -pedantic-errors
CFLAGS_INTERNAL+=-Woverloaded-virtual -Wno-deprecated -Wdelete-non-virtual-dtor -Werror -Wno-vla -pedantic-errors
CFLAGS=
LINKER_FLAGS=-L$(BUILD_DIR)/ -l$(LIBRARY_NAME)
INCLUDE_FLAGS=-I$(INCLUDE_DIR) -I$(BUILD_DIR)/gen_headers/
Expand Down Expand Up @@ -49,4 +50,5 @@ endif


LINKER_FLAGS+=-ldl
CFLAGS+=$(EXTRA_CFLAGS)
# --- flags are all ready
5 changes: 1 addition & 4 deletions src/builder/builder_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ block::stmt::Ptr builder_context::extract_ast_from_function_internal(std::vector
try {
current_builder_context = this;
// function();
lambda_wrapper();
lambda_wrapper(internal_stored_lambda);
commit_uncommitted();
ret_ast = ast;
current_builder_context = nullptr;
Expand Down Expand Up @@ -463,8 +463,5 @@ block::stmt::Ptr builder_context::extract_ast_from_function_internal(std::vector
return ret_ast;
}

void lambda_wrapper_impl(void) {
builder_context::current_builder_context->internal_stored_lambda();
}

} // namespace builder
18 changes: 13 additions & 5 deletions src/builder/builder_context_support.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@

#include <functional>
namespace builder {
void lambda_wrapper_impl(void);
void lambda_wrapper(void);
void lambda_wrapper(std::function<void(void)>);
void lambda_wrapper_close(void);
void coroutine_wrapper(std::function<void(void)>);
void coroutine_wrapper_close(void);

int tail_call_guard;

void lambda_wrapper(void) {
lambda_wrapper_impl();
void lambda_wrapper(std::function<void(void)> f) {
f();
tail_call_guard += 1;
}
void lambda_wrapper_close(void) {}


void coroutine_wrapper(std::function<void(void)> f) {
f();
tail_call_guard +=1;
}
void coroutine_wrapper_close(void) {}
} // namespace builder
2 changes: 1 addition & 1 deletion src/util/tracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#endif

namespace builder {
extern void lambda_wrapper(void);
extern void lambda_wrapper(std::function<void(void)>);
extern void lambda_wrapper_close(void);
} // namespace builder
namespace tracer {
Expand Down
Loading