-
-
Notifications
You must be signed in to change notification settings - Fork 419
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the pony_try function to receive Pony errors in C code (#2457)
This function is implemented in LLVM IR since it cannot be implemented in C. This change also exposes the `pony_error` function (renamed from `pony_throw`) in the public runtime interface in order to allow C programs to both raise and receive Pony errors.
- Loading branch information
Benoit Vey
authored
Jan 4, 2018
1 parent
b955480
commit 24982d5
Showing
19 changed files
with
152 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,6 +102,7 @@ ALL_CFLAGS = -std=gnu11 -fexceptions \ | |
-DPONY_VERSION_STR=\"$(version_str)\" \ | ||
-D_FILE_OFFSET_BITS=64 | ||
ALL_CXXFLAGS = -std=gnu++11 -fno-rtti | ||
LL_FLAGS = -mcpu=$(arch) | ||
|
||
# Determine pointer size in bits. | ||
BITS := $(bits) | ||
|
@@ -178,6 +179,7 @@ endif | |
|
||
ifeq ($(config),release) | ||
BUILD_FLAGS += -O3 -DNDEBUG | ||
LL_FLAGS += -O3 | ||
|
||
ifeq ($(lto),yes) | ||
BUILD_FLAGS += -flto -DPONY_USE_LTO | ||
|
@@ -201,73 +203,50 @@ ifeq ($(OSTYPE),osx) | |
endif | ||
|
||
ifndef LLVM_CONFIG | ||
ifneq (,$(shell which /usr/local/opt/llvm/bin/llvm-config 2> /dev/null)) | ||
ifneq (,$(shell which /usr/local/opt/llvm/bin/llvm-config 2> /dev/null)) | ||
LLVM_CONFIG = /usr/local/opt/llvm/bin/llvm-config | ||
LLVM_LINK = /usr/local/opt/llvm/bin/llvm-link | ||
LLVM_OPT = /usr/local/opt/llvm/bin/opt | ||
else ifneq (,$(shell which llvm-config-3.9 2> /dev/null)) | ||
LLVM_CONFIG = llvm-config-3.9 | ||
LLVM_LINK = llvm-link-3.9 | ||
LLVM_OPT = opt-3.9 | ||
else ifneq (,$(shell which /usr/local/opt/[email protected]/bin/llvm-config 2> /dev/null)) | ||
LLVM_CONFIG = /usr/local/opt/[email protected]/bin/llvm-config | ||
LLVM_LINK = /usr/local/opt/[email protected]/bin/llvm-link | ||
LLVM_OPT = /usr/local/opt/[email protected]/bin/opt | ||
else ifneq (,$(shell which llvm-config-3.8 2> /dev/null)) | ||
LLVM_CONFIG = llvm-config-3.8 | ||
LLVM_LINK = llvm-link-3.8 | ||
LLVM_OPT = opt-3.8 | ||
else ifneq (,$(shell which llvm-config-mp-3.8 2> /dev/null)) | ||
LLVM_CONFIG = llvm-config-mp-3.8 | ||
LLVM_LINK = llvm-link-mp-3.8 | ||
LLVM_OPT = opt-mp-3.8 | ||
else ifneq (,$(shell which llvm-config-3.7 2> /dev/null)) | ||
LLVM_CONFIG = llvm-config-3.7 | ||
LLVM_LINK = llvm-link-3.7 | ||
LLVM_OPT = opt-3.7 | ||
else ifneq (,$(shell which llvm-config-3.6 2> /dev/null)) | ||
LLVM_CONFIG = llvm-config-3.6 | ||
LLVM_LINK = llvm-link-3.6 | ||
LLVM_OPT = opt-3.6 | ||
else ifneq (,$(shell which llvm-config39 2> /dev/null)) | ||
LLVM_CONFIG = llvm-config39 | ||
LLVM_LINK = llvm-link39 | ||
LLVM_OPT = opt39 | ||
else ifneq (,$(shell which llvm-config38 2> /dev/null)) | ||
LLVM_CONFIG = llvm-config38 | ||
LLVM_LINK = llvm-link38 | ||
LLVM_OPT = opt38 | ||
else ifneq (,$(shell which llvm-config37 2> /dev/null)) | ||
LLVM_CONFIG = llvm-config37 | ||
LLVM_LINK = llvm-link37 | ||
LLVM_OPT = opt37 | ||
else ifneq (,$(shell which /usr/local/opt/llvm/bin/llvm-config 2> /dev/null)) | ||
LLVM_CONFIG = /usr/local/opt/llvm/bin/llvm-config | ||
LLVM_LINK = /usr/local/opt/llvm/bin/llvm-link | ||
LLVM_OPT = /usr/local/opt/llvm/bin/opt | ||
else ifneq (,$(shell which llvm-config 2> /dev/null)) | ||
LLVM_CONFIG = llvm-config | ||
LLVM_LINK = llvm-link | ||
LLVM_OPT = opt | ||
else ifneq (,$(shell which llvm-config-5.0 2> /dev/null)) | ||
LLVM_CONFIG = llvm-config-5.0 | ||
LLVM_LINK = llvm-link-5.0 | ||
LLVM_OPT = opt-5.0 | ||
else ifneq (,$(shell which llvm-config-4.0 2> /dev/null)) | ||
LLVM_CONFIG = llvm-config-4.0 | ||
LLVM_LINK = llvm-link-4.0 | ||
LLVM_OPT = opt-4.0 | ||
else ifneq (,$(shell which /usr/local/opt/[email protected]/bin/llvm-config 2> /dev/null)) | ||
else ifneq (,$(shell which /usr/local/opt/[email protected]/bin/llvm-config 2> /dev/null)) | ||
LLVM_CONFIG = /usr/local/opt/[email protected]/bin/llvm-config | ||
LLVM_LINK = /usr/local/opt/[email protected]/bin/llvm-link | ||
LLVM_OPT = /usr/local/opt/[email protected]/bin/opt | ||
else | ||
$(error No LLVM installation found!) | ||
endif | ||
endif | ||
|
||
ifndef LLVM_CONFIG | ||
else ifeq (,$(shell which $(LLVM_CONFIG) 2> /dev/null)) | ||
$(error No LLVM installation found!) | ||
endif | ||
|
||
LLVM_BINDIR := $(shell $(LLVM_CONFIG) --bindir 2> /dev/null) | ||
|
||
LLVM_LINK := $(LLVM_BINDIR)/llvm-link | ||
LLVM_OPT := $(LLVM_BINDIR)/opt | ||
LLVM_LLC := $(LLVM_BINDIR)/llc | ||
LLVM_AS := $(LLVM_BINDIR)/llvm-as | ||
|
||
llvm_version := $(shell $(LLVM_CONFIG) --version) | ||
|
||
ifeq (,$(LLVM_LINK_STATIC)) | ||
|
@@ -278,9 +257,8 @@ ifeq (,$(LLVM_LINK_STATIC)) | |
endif | ||
|
||
ifeq ($(OSTYPE),osx) | ||
llvm_bindir := $(shell $(LLVM_CONFIG) --bindir $(LLVM_LINK_STATIC)) | ||
ifneq (,$(shell which $(llvm_bindir)/llvm-ar 2> /dev/null)) | ||
AR = $(llvm_bindir)/llvm-ar | ||
ifneq (,$(shell which $(LLVM_BINDIR)/llvm-ar 2> /dev/null)) | ||
AR = $(LLVM_BINDIR)/llvm-ar | ||
AR_FLAGS := rcs | ||
else ifneq (,$(shell which llvm-ar-mp-3.8 2> /dev/null)) | ||
AR = llvm-ar-mp-3.8 | ||
|
@@ -290,7 +268,7 @@ ifeq ($(OSTYPE),osx) | |
AR_FLAGS := rcs | ||
else | ||
AR = /usr/bin/ar | ||
AR_FLAGS := -rcs | ||
AR_FLAGS := -rcs | ||
endif | ||
endif | ||
|
||
|
@@ -510,11 +488,13 @@ endif | |
|
||
ifeq ($(OSTYPE), linux) | ||
libponyrt-pic.buildoptions += -fpic | ||
libponyrt-pic.buildoptions-ll += -relocation-model=pic | ||
endif | ||
|
||
# default enable PIC compiling if requested | ||
ifdef default_pic | ||
libponyrt.buildoptions += -fpic | ||
libponyrt.buildoptions-ll += -relocation-model=pic | ||
BUILD_FLAGS += -DPONY_DEFAULT_PIC=true | ||
endif | ||
|
||
|
@@ -613,7 +593,7 @@ define ENUMERATE | |
sourcefiles := $$($(1).files) | ||
else | ||
sourcefiles := $$(shell find $$(sourcedir) -type f -name "*.c" -or -name\ | ||
"*.cc" | grep -v '.*/\.') | ||
"*.cc" -or -name "*.ll" | grep -v '.*/\.') | ||
endif | ||
|
||
ifdef $(1).except | ||
|
@@ -631,11 +611,16 @@ define CONFIGURE_COMPILER | |
compiler := $(CC) | ||
flags := $(ALL_CFLAGS) $(CFLAGS) | ||
endif | ||
|
||
ifeq ($(suffix $(1)),.bc) | ||
compiler := $(CC) | ||
flags := $(ALL_CFLAGS) $(CFLAGS) | ||
endif | ||
|
||
ifeq ($(suffix $(1)),.ll) | ||
compiler := $(CC) | ||
flags := $(ALL_CFLAGS) $(CFLAGS) -Wno-override-module | ||
endif | ||
endef | ||
|
||
define CONFIGURE_LIBS | ||
|
@@ -691,8 +676,8 @@ define PREPARE | |
$(eval objectfiles := $(subst $(sourcedir)/,$(outdir)/,$(addsuffix .o,\ | ||
$(sourcefiles)))) | ||
$(eval bitcodefiles := $(subst .o,.bc,$(objectfiles))) | ||
$(eval dependencies := $(subst .c,,$(subst .cc,,$(subst .o,.d,\ | ||
$(objectfiles))))) | ||
$(eval dependencies := $(subst .c,,$(subst .cc,,$(subst .ll,,$(subst .o,.d,\ | ||
$(objectfiles)))))) | ||
endef | ||
|
||
define EXPAND_OBJCMD | ||
|
@@ -701,17 +686,27 @@ $(eval $(call CONFIGURE_COMPILER,$(file))) | |
|
||
ifeq ($(3),libponyrtyes) | ||
ifneq ($(suffix $(file)),.bc) | ||
$(subst .c,,$(subst .cc,,$(1))): $(subst .c,.bc,$(subst .cc,.bc,$(file))) | ||
$(subst .c,,$(subst .cc,,$(subst .ll,,$(1)))): $(subst .c,.bc,$(subst .cc,.bc,$(subst .ll,.bc,$(file)))) | ||
@echo '$$(notdir $$<)' | ||
@mkdir -p $$(dir $$@) | ||
$(SILENT)$(compiler) $(flags) -c -o $$@ $$< | ||
else ifeq ($(suffix $(subst .bc,,$(file))),.ll) | ||
$(subst .ll,,$(1)): $(subst $(outdir)/,$(sourcedir)/,$(subst .bc,,$(file))) | ||
@echo '$$(notdir $$<)' | ||
@mkdir -p $$(dir $$@) | ||
$(SILENT)$(LLVM_AS) -o $$@ $$< | ||
else | ||
$(subst .c,,$(subst .cc,,$(1))): $(subst $(outdir)/,$(sourcedir)/,$(subst .bc,,$(file))) | ||
@echo '$$(notdir $$<)' | ||
@mkdir -p $$(dir $$@) | ||
$(SILENT)$(compiler) -MMD -MP $(filter-out $($(2).disable),$(BUILD_FLAGS)) \ | ||
$(flags) $($(2).buildoptions) -emit-llvm -c -o $$@ $$< $($(2).include) | ||
endif | ||
else ifeq ($(suffix $(file)),.ll) | ||
$(subst .ll,,$(1)): $(subst $(outdir)/,$(sourcedir)/,$(file)) | ||
@echo '$$(notdir $$<)' | ||
@mkdir -p $$(dir $$@) | ||
$(SILENT)$(LLVM_LLC) $(LL_FLAGS) $($(2).buildoptions-ll) -filetype=obj -o $$@ $$< | ||
else | ||
$(subst .c,,$(subst .cc,,$(1))): $(subst $(outdir)/,$(sourcedir)/,$(file)) | ||
@echo '$$(notdir $$<)' | ||
|
@@ -723,8 +718,8 @@ endef | |
|
||
define EXPAND_COMMAND | ||
$(eval $(call PREPARE,$(1))) | ||
$(eval ofiles := $(subst .c,,$(subst .cc,,$(objectfiles)))) | ||
$(eval bcfiles := $(subst .c,,$(subst .cc,,$(bitcodefiles)))) | ||
$(eval ofiles := $(subst .c,,$(subst .cc,,$(subst .ll,,$(objectfiles))))) | ||
$(eval bcfiles := $(subst .c,,$(subst .cc,,$(subst .ll,,$(bitcodefiles))))) | ||
$(eval depends := ) | ||
$(foreach d,$($(1).depends),$(eval depends += $($(d))/$(d).$(LIB_EXT))) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
; This file implements the `pony_try` function in LLVM IR as it cannot be | ||
; implemented in C. | ||
; Since the LLVM project doesn't particularly care about IR backwards | ||
; compatibility, please try to keep this file as minimal as possible in order | ||
; to minimise the chances of breakage with newer LLVM versions. | ||
|
||
declare i32 @pony_personality_v0(...) | ||
|
||
define i1 @pony_try(void (i8*)* %fun, i8* %ctx) personality i32 (...)* @pony_personality_v0 { | ||
entry: | ||
invoke void %fun(i8* %ctx) | ||
to label %post unwind label %unwind | ||
|
||
unwind: | ||
%lp = landingpad { i8*, i32 } | ||
catch i8* null | ||
br label %post | ||
|
||
post: | ||
%ret = phi i1 [ true, %entry ], [ false, %unwind ] | ||
ret i1 %ret | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
#include <platform.h> | ||
#include <pony.h> | ||
#include "lang.h" | ||
#include <string.h> | ||
|
||
PONY_EXTERN_C_BEGIN | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.