Commit 33d0c449 authored by Kenneth Graunke's avatar Kenneth Graunke
Browse files

glsl: Autogenerate builtin_functions.cpp as part of the build process.

Python is already necessary for other parts of Mesa, so there's no
reason we can't just generate it.  This patch updates both make and
SCons to do so.
parent 469ea695
glsl_compiler
glsl_parser.output
builtin_function.cpp
......@@ -24,7 +24,6 @@ CXX_SOURCES = \
ast_function.cpp \
ast_to_hir.cpp \
ast_type.cpp \
builtin_function.cpp \
glsl_lexer.cpp \
glsl_parser.cpp \
glsl_parser_extras.cpp \
......@@ -130,8 +129,8 @@ ALL_SOURCES = \
default: depend lib$(LIBNAME).a $(APPS)
lib$(LIBNAME).a: $(OBJECTS) Makefile $(TOP)/src/glsl/Makefile.template
$(MKLIB) -cplusplus -o $(LIBNAME) -static $(OBJECTS)
lib$(LIBNAME).a: $(OBJECTS) builtin_function.o Makefile $(TOP)/src/glsl/Makefile.template
$(MKLIB) -cplusplus -o $(LIBNAME) -static $(OBJECTS) builtin_function.o
depend: $(ALL_SOURCES) Makefile
rm -f depend
......@@ -140,7 +139,7 @@ depend: $(ALL_SOURCES) Makefile
# Remove .o and backup files
clean:
rm -f $(GLCPP_OBJECTS) $(GLSL2_OBJECTS) $(OBJECTS) lib$(LIBNAME).a depend depend.bak
rm -f $(GLCPP_OBJECTS) $(GLSL2_OBJECTS) $(OBJECTS) lib$(LIBNAME).a depend depend.bak builtin_function.cpp builtin_function.o builtin_stubs.o builtin_compiler
-rm -f $(APPS)
# Dummy target
......@@ -174,13 +173,11 @@ glcpp/glcpp-lex.c: glcpp/glcpp-lex.l
glcpp/glcpp-parse.c: glcpp/glcpp-parse.y
bison -v -o "$@" --defines=glcpp/glcpp-parse.h $<
builtins: builtin_function.cpp builtins/profiles/* builtins/ir/* builtins/tools/generate_builtins.py builtins/tools/texture_builtins.py
@echo Bootstrapping the compiler...
cp builtins/tools/builtin_function.cpp .
make glsl_compiler
builtin_compiler: $(GLSL2_OBJECTS) $(OBJECTS) builtin_stubs.o
$(APP_CXX) $(INCLUDES) $(CFLAGS) $(LDFLAGS) $(TALLOC_LIBS) $(OBJECTS) $(GLSL2_OBJECTS) builtin_stubs.o -o builtin_compiler
builtin_function.cpp: builtins/profiles/* builtins/ir/* builtins/tools/generate_builtins.py builtins/tools/texture_builtins.py builtin_compiler
@echo Regenerating builtin_function.cpp...
$(PYTHON2) $(PYTHON_FLAGS) builtins/tools/generate_builtins.py > builtin_function.cpp
@echo Rebuilding the real compiler...
make glsl_compiler
$(PYTHON2) $(PYTHON_FLAGS) builtins/tools/generate_builtins.py $(PWD)/builtin_compiler > builtin_function.cpp
-include depend
......@@ -2,6 +2,8 @@ import common
Import('*')
from sys import executable as python_cmd
env = env.Clone()
env.Prepend(CPPPATH = [
......@@ -20,7 +22,6 @@ sources = [
'ast_function.cpp',
'ast_to_hir.cpp',
'ast_type.cpp',
'builtin_function.cpp',
'glsl_lexer.cpp',
'glsl_parser.cpp',
'glsl_parser_extras.cpp',
......@@ -79,9 +80,28 @@ sources = [
'strtod.c',
]
env.Prepend(LIBS = ['talloc'])
env.Append(CPPPATH = ['#/src/glsl'])
builtin_compiler = env.Program(
target = 'builtin_compiler',
source = sources + ['main.cpp', 'builtin_stubs.cpp',
'#src/mesa/program/hash_table.c',
'#src/mesa/program/symbol_table.c'],
)
env.CodeGenerate(
target = 'builtin_function.cpp',
script = 'builtins/tools/generate_builtins.py',
source = builtin_compiler,
command = python_cmd + ' $SCRIPT $SOURCE > $TARGET'
)
env.Depends('builtin_function.cpp', ['builtins/tools/generate_builtins.py', 'builtins/tools/texture_builtins.py'] + Glob('builtins/ir/*'))
glsl = env.ConvenienceLibrary(
target = 'glsl',
source = sources,
source = sources + [ 'builtin_function.cpp' ],
)
Export('glsl')
......
This diff is collapsed.
......@@ -5,12 +5,20 @@ import re
from glob import glob
from os import path
from subprocess import Popen, PIPE
from sys import argv
# Local module: generator for texture lookup builtins
from texture_builtins import generate_texture_functions
builtins_dir = path.join(path.dirname(path.abspath(__file__)), "..")
# Get the path to the standalone GLSL compiler
if len(argv) != 2:
print "Usage:", argv[0], "<path to compiler>"
sys.exit(1)
compiler = argv[1]
# Read the files in builtins/ir/*...add them to the supplied dictionary.
def read_ir_files(fs):
for filename in glob(path.join(path.join(builtins_dir, 'ir'), '*')):
......@@ -47,8 +55,7 @@ def write_function_definitions():
print stringify(v), ';'
def run_compiler(args):
compiler_path = path.join(path.join(builtins_dir, '..'), 'glsl_compiler')
command = [compiler_path, '--dump-lir'] + args
command = [compiler, '--dump-lir'] + args
p = Popen(command, 1, stdout=PIPE, shell=False)
output = p.communicate()[0]
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment