Skip to content

Commit

Permalink
mingw32 port.
Browse files Browse the repository at this point in the history
  • Loading branch information
schani committed May 1, 2009
1 parent 5f7f584 commit 6bee804
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 41 deletions.
56 changes: 40 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ CMDLINE = YES
#GIMP_BIN = /usr/bin/

# Choose which gif library you have.
GIFLIB = -lgif
#GIFLIB = -lgif
#GIFLIB = -lungif
#GIF_CFLAGS = -DRWIMG_GIF

# If you are building on MacOS X, uncomment the following line
#MACOSX = YES
Expand All @@ -31,14 +32,24 @@ GIFLIB = -lgif
# Prefix for the software installation
PREFIX = /usr

# Enable these two lines if you have fftw3 installed
#FFTW = fftw3
#FFTW_OBJECTS = native-filters/convolve.o
#FFTW_CFLAGS = -DHAVE_FFTW

#LLVM_GCC = llvm-gcc
LLVM_GCC = /usr/local/llvm-gcc-4.2/bin/llvm-gcc

MINGW_LDFLAGS = -lpsapi -limagehlp

# You should not need to change anything beyond this line.
# -------------------------------------------------------

VERSION = 1.3.4

#OPT_CFLAGS := -O2
OPT_CFLAGS := -O2
#COMPILER_C_OPT_CFLAGS := -O1
OPT_CFLAGS := -O0 -g -DDEBUG_OUTPUT -DDONT_UNLINK_C #-fgnu89-inline
#OPT_CFLAGS := -O0 -g -DDEBUG_OUTPUT -DDONT_UNLINK_C #-fgnu89-inline

#PROF_FLAGS := -pg

Expand All @@ -58,19 +69,20 @@ CGEN_CFLAGS=$(CGEN_CC) $(CGEN_LD)
GIMPTOOL := $(GIMP_BIN)gimptool-2.0
GIMPDIR := .gimp-$(basename $(shell $(GIMPTOOL) --version))
GIMPDATADIR := $(PREFIX)/share/gimp/2.0
GIMP_CFLAGS := $(shell $(GIMPTOOL) --cflags) $(shell pkg-config --cflags gmodule-2.0 gthread-2.0 gtksourceview-1.0 fftw3)
GIMP_LDFLAGS := $(shell $(GIMPTOOL) --libs) $(shell pkg-config --libs gmodule-2.0 gthread-2.0 gtksourceview-1.0 fftw3)
GIMP_CFLAGS := $(shell $(GIMPTOOL) --cflags) $(shell pkg-config --cflags gmodule-2.0 gthread-2.0 gtksourceview-1.0 $(FFTW))
GIMP_LDFLAGS := $(shell $(GIMPTOOL) --libs) $(shell pkg-config --libs gmodule-2.0 gthread-2.0 gtksourceview-1.0 $(FFTW))

TEMPLATE_DIR = $(GIMPDATADIR)/mathmap
PIXMAP_DIR = $(GIMPDATADIR)/mathmap
LOCALEDIR = $(PREFIX)/share/locale
#FIXME: does not honor PREFIX
LIBDIR := $(shell $(GIMPTOOL) --libdir)

C_CXX_FLAGS = -I. -D_GNU_SOURCE $(CGEN_CFLAGS) $(OPT_CFLAGS) -Wall $(GIMP_CFLAGS) -DLOCALEDIR=\"$(LOCALEDIR)\" -DTEMPLATE_DIR=\"$(TEMPLATE_DIR)\" -DPIXMAP_DIR=\"$(PIXMAP_DIR)\" $(NLS_CFLAGS) $(MACOSX_CFLAGS) -DUSE_PTHREADS $(THREADED) $(PROF_FLAGS) -DUSE_LLVM
C_CXX_FLAGS = -I. -I/usr/local/include -D_GNU_SOURCE $(CGEN_CFLAGS) $(OPT_CFLAGS) -Wall $(GIMP_CFLAGS) -DLOCALEDIR=\"$(LOCALEDIR)\" -DTEMPLATE_DIR=\"$(TEMPLATE_DIR)\" -DPIXMAP_DIR=\"$(PIXMAP_DIR)\" $(NLS_CFLAGS) $(MACOSX_CFLAGS) $(THREADED) $(PROF_FLAGS) -DUSE_LLVM $(FFTW_CFLAGS) #-DUSE_PTHREADS
CFLAGS = $(C_CXX_FLAGS) -std=gnu99
CXXFLAGS = $(C_CXX_FLAGS) `llvm-config --cxxflags`
LDFLAGS = $(GIMP_LDFLAGS) $(MACOSX_LIBS) -lm -lgsl -lgslcblas $(PROF_FLAGS)
LDFLAGS = $(GIMP_LDFLAGS) $(MACOSX_LIBS) -lm -lgsl -lgslcblas $(PROF_FLAGS) $(MINGW_LDFLAGS)
LLVM_LDFLAGS = $(shell llvm-config --ldflags --libs engine bitreader ipo)

ifeq ($(MOVIES),YES)
CFLAGS += -I/usr/local/include/quicktime -DMOVIES
Expand All @@ -81,7 +93,7 @@ ifeq ($(CMDLINE),YES)
CMDLINE_OBJECTS = mathmap_cmdline.o getopt.o getopt1.o generators/blender/blender.o
CMDLINE_LIBS = rwimg/librwimg.a
CMDLINE_TARGETS = librwimg
FORMATDEFS = -DRWIMG_JPEG -DRWIMG_PNG -DRWIMG_GIF
FORMATDEFS = -DRWIMG_JPEG -DRWIMG_PNG $(GIF_CFLAGS)
CFLAGS += -DMATHMAP_CMDLINE -DGIMPDATADIR=\"$(GIMPDATADIR)\"
LDFLAGS += -ljpeg -lpng $(GIFLIB)
endif
Expand All @@ -94,9 +106,9 @@ CFLAGS += -DMATHMAP_VERSION=\"$(VERSION)\"
CC = gcc
CXX = g++

export CFLAGS CC FORMATDEFS
export CFLAGS CC

COMMON_OBJECTS = mathmap_common.o builtins.o exprtree.o parser.o scanner.o vars.o tags.o tuples.o internals.o macros.o userval.o overload.o jump.o noise.o spec_func.o compiler.o bitvector.o expression_db.o drawable.o floatmap.o designer/designer.o designer/cycles.o designer/loadsave.o designer_filter.o native-filters/gauss.o native-filters/convolve.o compopt/dce.o compopt/resize.o backends/cc.o backends/llvm.o
COMMON_OBJECTS = mathmap_common.o builtins.o exprtree.o parser.o scanner.o vars.o tags.o tuples.o internals.o macros.o userval.o overload.o jump.o noise.o spec_func.o compiler.o bitvector.o expression_db.o drawable.o floatmap.o designer/designer.o designer/cycles.o designer/loadsave.o designer_filter.o native-filters/gauss.o compopt/dce.o compopt/resize.o backends/cc.o backends/llvm.o backends/lazy_creator.o $(FFTW_OBJECTS)
#COMMON_OBJECTS += designer/widget.o
COMMON_OBJECTS += designer/cairo_widget.o

Expand All @@ -107,10 +119,13 @@ OBJECTS = $(COMMON_OBJECTS) $(CMDLINE_OBJECTS) $(GIMP_OBJECTS)
TEMPLATE_INPUTS = tuples.h mathmap.h userval.h drawable.h compiler.h builtins.h noise.h

mathmap : compiler_types.h $(OBJECTS) $(CMDLINE_TARGETS) liblispreader new_template.c llvm_template.o
$(CXX) $(CGEN_LDFLAGS) -o mathmap $(OBJECTS) $(CMDLINE_LIBS) `llvm-config --ldflags --libs engine bitreader ipo` lispreader/liblispreader.a $(LDFLAGS)
$(CXX) $(CGEN_LDFLAGS) -o mathmap $(OBJECTS) $(CMDLINE_LIBS) $(LLVM_LDFLAGS) lispreader/liblispreader.a $(LDFLAGS)

llvmtest : llvmtest.o llvm_template.o Makefile
$(CXX) -o llvmtest llvmtest.o $(LLVM_LDFLAGS) $(LDFLAGS)

librwimg :
$(MAKE) -C rwimg
$(MAKE) -C rwimg "FORMATDEFS=$(FORMATDEFS)"

liblispreader :
$(MAKE) -C lispreader -f Makefile.dist
Expand Down Expand Up @@ -141,17 +156,26 @@ backends/cc.o : compiler_types.h
backends/llvm.o : backends/llvm.cpp compiler_types.h
$(CXX) $(CXXFLAGS) $(FORMATDEFS) -o $@ -c backends/llvm.cpp

backends/lazy_creator.cpp : exported_symbols
perl -- make_lazy_creator.pl exported_symbols >$@

backends/lazy_creator.o : backends/lazy_creator.cpp
$(CXX) $(CXXFLAGS) $(FORMATDEFS) -o $@ -c backends/lazy_creator.cpp

llvmtest.o : llvmtest.cc
$(CXX) $(CXXFLAGS) $(FORMATDEFS) -o $@ -c llvmtest.cc

new_builtins.c opdefs.h opfuncs.h compiler_types.h llvm-ops.h : builtins.lisp ops.lisp
clisp builtins.lisp

new_template.c : make_template.pl new_template.c.in $(TEMPLATE_INPUTS)
./make_template.pl $(TEMPLATE_INPUTS) new_template.c.in >new_template.c
perl -- make_template.pl $(TEMPLATE_INPUTS) new_template.c.in >new_template.c

llvm_template.c : make_template.pl llvm_template.c.in $(TEMPLATE_INPUTS)
./make_template.pl $(TEMPLATE_INPUTS) llvm_template.c.in >llvm_template.c
perl -- make_template.pl $(TEMPLATE_INPUTS) llvm_template.c.in >llvm_template.c

llvm_template.o : llvm_template.c opmacros.h
llvm-gcc -emit-llvm -Wall -O3 -c llvm_template.c
$(LLVM_GCC) -emit-llvm -Wall -O3 -c llvm_template.c

blender.o : generators/blender/blender.c

Expand All @@ -174,7 +198,7 @@ install : mathmap new_template.c $(MOS)

clean :
rm -f *.o designer/*.o native-filters/*.o compopt/*.o backends/*.o generators/blender/*.o mathmap compiler parser.output core
find . -name '*~' | xargs -r -d '\n' rm
find . -name '*~' -exec rm {} ';'
$(MAKE) -C rwimg clean
$(MAKE) -C lispreader clean
rm -rf debian/mathmap debian/mathmap.substvars
Expand Down
5 changes: 5 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

* 1.3.5

** Windows
multi-threading
FFTW
why does auto bw crash?

** GIMP Plug-In
speed up rendering of GIMP drawables by processing tile for tile
make preview input drawables to be floatmaps
Expand Down
31 changes: 16 additions & 15 deletions backends/llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,14 @@ code_emitter::emit_rhs (rhs_t *rhs)
type_t type = promotion_type == TYPE_NIL ? op->arg_types[i] : promotion_type;
Value *val = emit_primary(&rhs->v.op.args[i], type == TYPE_FLOAT);
val = promote(val, type);
#ifdef DEBUG_OUTPUT
val->dump();
#endif
args.push_back(val);
}
#ifdef DEBUG_OUTPUT
func->dump();
#endif
Value *result = builder->CreateCall(func, args.begin(), args.end());
/* FIXME: this is ugly - we should check for the type
of the operation or resulting value */
Expand All @@ -423,7 +427,11 @@ code_emitter::emit_rhs (rhs_t *rhs)
Value *local = builder->CreateAlloca(llvm_type_for_type(TYPE_COMPLEX));
Value *local_ptr = builder->CreateBitCast(local, PointerType::getUnqual(Type::Int64Ty));
builder->CreateStore(result, local_ptr);
#ifdef __MINGW32__
result = builder->CreateLoad(local);
#else
result = local;
#endif
}
else if (sizeof(gpointer) == 8)
result = builder->CreateExtractValue(result, 0);
Expand Down Expand Up @@ -471,9 +479,6 @@ code_emitter::emit_rhs (rhs_t *rhs)
for (i = 0; i < rhs->v.tuple.length; ++i)
{
Value *val = emit_primary(&rhs->v.tuple.args[i], true);
std::cout << "setting tuple elem to type ";
val->getType()->print(std::cout);
std::cout << endl;
builder->CreateCall3(set_func, tuple, make_int_const(i), val);
}
return tuple;
Expand Down Expand Up @@ -614,8 +619,10 @@ code_emitter::emit_stmts (statement_t *stmt, unsigned int slice_flag)
break;

case STMT_ASSIGN :
#ifdef DEBUG_OUTPUT
compiler_print_assign_statement(stmt);
printf("\n");
#endif
if (stmt->v.assign.rhs->kind == RHS_OP
&& stmt->v.assign.rhs->v.op.op->index == OP_OUTPUT_TUPLE)
builder->CreateRet(emit_primary(&stmt->v.assign.rhs->v.op.args[0]));
Expand Down Expand Up @@ -737,21 +744,17 @@ make_filter_function (Module *module, filter_t *filter)
return cast<Function>(function_const);
}

static void*
lazy_creator (const std::string &name)
{
std::cout << "resolving func " << name << endl;
if (name == "get_orig_val_pixel")
return (void*)get_orig_val_pixel;
g_assert_not_reached ();
}
void* lazy_creator (const std::string &name);

extern "C"
filter_func_t
gen_and_load_llvm_code (mathmap_t *mathmap, char *template_filename)
{
filter_code_t **filter_codes = compiler_compile_filters(mathmap);
MemoryBuffer *buffer = MemoryBuffer::getFile(template_filename, NULL);

g_assert(buffer != NULL);

Module *module = ParseBitcodeFile (buffer, NULL);
int i;
filter_t *filter;
Expand Down Expand Up @@ -797,14 +800,14 @@ gen_and_load_llvm_code (mathmap_t *mathmap, char *template_filename)
delete emitter;
}

verifyModule(*module, PrintMessageAction);
//verifyModule(*module, PrintMessageAction);

PassManager pm;
pm.add (new TargetData (module));
pm.add (createFunctionInliningPass ());
pm.run(*module);

module->dump();
//module->dump();

ExecutionEngine *ee = ExecutionEngine::create (module);

Expand All @@ -827,7 +830,5 @@ unload_llvm_code (void *module_info)
{
ExecutionEngine *ee = (ExecutionEngine*)module_info;

std::cout << "deleting execution engine" << endl;

delete ee;
}
73 changes: 73 additions & 0 deletions exported_symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
get_floatmap_pixel
_pools_alloc
render_image
make_resize_image
noise
gsl_matrix_alloc
gsl_matrix_free
gsl_matrix_set
gsl_vector_alloc
gsl_vector_free
gsl_vector_get
gsl_vector_set
gsl_linalg_HH_solve
gsl_sf_ellint_Kcomp
gsl_sf_ellint_Ecomp
gsl_sf_ellint_F
gsl_sf_ellint_E
gsl_sf_ellint_P
gsl_sf_ellint_D
gsl_sf_ellint_RC
gsl_sf_ellint_RD
gsl_sf_ellint_RF
gsl_sf_ellint_RJ
gsl_sf_elljac_e
gsl_sf_beta
gsl_sf_gamma
save_debug_tuples
fabs
sqrt
hypot
sin
cos
tan
asin
acos
atan
atan2
pow
exp
log
sinh
cosh
tanh
asinh
acosh
atanh
floor
ceil
crealf
cimagf
csqrtf
csinf
ccosf
ctanf
casinf
cacosf
catanf
cpowf
cexpf
clogf
cargf
csinhf
ccoshf
ctanhf
casinhf
cacoshf
catanhf
cgamma
floorf
ceilf
llvm_filter_init_frame
llvm_filter_init_slice
llvm_filter_calc_lines
24 changes: 24 additions & 0 deletions make_lazy_creator.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/perl

use strict;

my @names = ();

while (<>) {
chomp;
push @names, $_;
}

print "#include <iostream>\n";
print "extern \"C\" {\n";
foreach my $name (@names) {
print "extern void $name (void);\n";
}
print "}\n";
print "void*\nlazy_creator (const std::string \&name)\n{\n";
foreach my $name (@names) {
print "if (name == \"$name\") return (void*)$name;\n";
}
print "std::cout << \"could not resolve \" << name << std::endl;\n";
print "return NULL;\n";
print "}\n";
8 changes: 6 additions & 2 deletions mathmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@
#include <string.h>
#include <unistd.h>
#include <ctype.h>
#ifdef THREADED_FINAL_RENDER
#include <pthread.h>
#endif

#include <glib.h>
#include <glib/gstdio.h>
#include <gtk/gtk.h>
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
Expand Down Expand Up @@ -2563,8 +2567,8 @@ save_dialog (const char *title, const char *filename, const char *default_filena

/* We try to create the directory just in case. If it already
exists, nothing happens and it doesn't hurt. */
mkdir(mathmap_path, 0777);
mkdir(default_path, 0777);
g_mkdir(mathmap_path, 0777);
g_mkdir(default_path, 0777);

gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), default_path);
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), default_filename);
Expand Down
Loading

0 comments on commit 6bee804

Please sign in to comment.