aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@mozilla.com>2011-03-13 12:13:21 -0700
committerAlon Zakai <azakai@mozilla.com>2011-03-13 12:13:21 -0700
commit6c22a66671b6f42ad63044b0fd46a5dc892298b4 (patch)
tree2dcbf1895b6d97be7b6e1a9f26561045c3e8fa28
parentf534adece703cadde53e2e14b199219376d63028 (diff)
misc compiler tweaks
-rw-r--r--src/jsifier.js30
-rw-r--r--src/preamble.js6
-rw-r--r--tests/runner.py50
-rwxr-xr-xtools/exec_llvm.py14
4 files changed, 69 insertions, 31 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index c230d22d..6742f33c 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -148,7 +148,7 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
if (type !== 'null') type = '"' + safeQuote(type) + '"';
return 'SAFE_HEAP_STORE(' + offset + ', ' + value + ', ' + type + ');';
} else {
- return makeGetSlabs(ptr, type, true).map(function(slab) { return slab + '[' + offset + '] = ' + value }).join('; ') + ';';
+ return makeGetSlabs(ptr, type, true).map(function(slab) { return slab + '[' + offset + ']=' + value }).join('; ') + ';';
}
}
@@ -312,7 +312,7 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
return ret.concat({
intertype: 'GlobalVariable',
- JS: item.ident + ' = ' + constant + ';',
+ JS: item.ident + '=' + constant + ';',
});
}
}
@@ -369,7 +369,7 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
}
var deps = Library[ident + '__deps'];
- return 'var _' + ident + ' = ' + snippet + (deps ? '\n' + deps.map(addFromLibrary).join('\n') : '');
+ return 'var _' + ident + '=' + snippet + (deps ? '\n' + deps.map(addFromLibrary).join('\n') : '');
}
item.JS = addFromLibrary(shortident);
} else {
@@ -594,7 +594,7 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
default: throw 'zz unknown impl: ' + impl;
}
if (value)
- item.JS += ' = ' + value;
+ item.JS += '=' + value;
item.JS += ';';
this.forwardItem(item, 'FunctionReconstructor');
@@ -621,13 +621,13 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
}
switch (impl) {
case VAR_NATIVIZED:
- return item.ident + ' = ' + value + ';'; // We have the actual value here
+ return item.ident + '=' + value + ';'; // We have the actual value here
break;
case VAR_EMULATED:
if (item.pointer.intertype == 'value') {
- return makeSetValue(item.ident, 0, value, item.valueType) + ';';
+ return makeSetValue(item.ident, 0, value, item.valueType);
} else {
- return makeSetValue(0, indexizeFunctions(finalizeLLVMParameter(item.pointer)), value, item.valueType) + ';';
+ return makeSetValue(0, indexizeFunctions(finalizeLLVMParameter(item.pointer)), value, item.valueType);
}
break;
default:
@@ -1115,7 +1115,7 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
// Optimized intertypes
makeFuncLineActor('fastgetelementptrload', function(item) {
- return 'var ' + item.ident + ' = ' + makeGetValue(parseNumerical(item.value.ident), getGetElementPtrIndexes(item.value), item.value.valueType, true) + ';';
+ return 'var ' + item.ident + '=' + makeGetValue(parseNumerical(item.value.ident), getGetElementPtrIndexes(item.value), item.value.valueType, true) + ';';
});
makeFuncLineActor('fastgetelementptrstore', function(item) {
return makeSetValue(item.value.ident, getGetElementPtrIndexes(item.value), parseNumerical(item.ident), item.type, true) + ';';
@@ -1145,16 +1145,18 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
if (functionsOnly) return ret;
- var body = preprocess(read('preamble.js').replace('{{RUNTIME}}', getRuntime()) + ret + read('postamble.js'), CONSTANTS);
+ var pre = preprocess(read('preamble.js').replace('{{RUNTIME}}', getRuntime()), CONSTANTS);
+ var post = preprocess(read('postamble.js'), CONSTANTS);
+ ret = pre + ret + post;
var globalVars = itemsDict.GlobalVariable.map(function(item) { return item.JS }).join('\n');
var globalVarsPostSets = itemsDict.GlobalVariablePostSet.map(function(item) { return item.JS }).join('\n');
- body = indentify(body, 2);
- // body may be a very large string at this point - we may not be able to allocate two of it. So must be careful in these last steps
+ ret = indentify(ret, 2);
+ // ret may be a very large string at this point - we may not be able to allocate two of it. So must be careful in these last steps
var shellParts = read('shell.js').split('{{BODY}}');
- body = shellParts[0] + body + shellParts[1];
+ ret = shellParts[0] + ret + shellParts[1];
globalVars = indentify(globalVars+'\n\n\n'+globalVarsPostSets, 4);
- body = body.replace('{{GLOBAL_VARS}}', globalVars);
- return processMacros(body);
+ ret = ret.replace('{{GLOBAL_VARS}}', globalVars);
+ return processMacros(ret);
}
// Data
diff --git a/src/preamble.js b/src/preamble.js
index ea0c8fa4..2eb745a5 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -269,8 +269,8 @@ function __initializeRuntime__() {
}
}
- var base = intArrayFromString('(null)').concat(0); // So printing %s of NULL gives '(null)'
- // Also this ensures we leave 0 as an invalid address, 'NULL'
+ var base = intArrayFromString('(null)'); // So printing %s of NULL gives '(null)'
+ // Also this ensures we leave 0 as an invalid address, 'NULL'
for (var i = 0; i < base.length; i++) {
{{{ makeSetValue(0, 'i', 'base[i]', 'i8') }}}
}
@@ -360,7 +360,7 @@ function jrint(label, obj) { // XXX manual debugging
print(label + JSON.stringify(obj));
}
-// This processes a 'normal' string into a C-line array of numbers.
+// This processes a JS string into a C-line array of numbers, 0-terminated.
// For LLVM-originating strings, see parser.js:parseLLVMString function
function intArrayFromString(stringy) {
var ret = [];
diff --git a/tests/runner.py b/tests/runner.py
index c7668ad0..7680d283 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -106,7 +106,7 @@ class RunnerCore(unittest.TestCase):
def do_link(self, files, target):
output = Popen([LLVM_LINK] + files + ['-o', target], stdout=PIPE, stderr=STDOUT).communicate()[0]
- assert 'Could not open input file' not in output, 'Linking error: ' + output
+ assert output is None or 'Could not open input file' not in output, 'Linking error: ' + output
# Build JavaScript code from source code
def build(self, src, dirname, filename, output_processor=None, main_file=None, additional_files=[], libraries=[], includes=[], build_ll_hook=None):
@@ -1529,6 +1529,20 @@ if 'benchmark' not in sys.argv:
'june -> 30\nPrevious (in alphabetical order) is july\nNext (in alphabetical order) is march',
main_file='main.cpp', additional_files=['hash.cpp'])
+ # This will fail without using libcxx, as libstdc++ (gnu c++ lib) will use but not link in
+ # __ZSt29_Rb_tree_insert_and_rebalancebPSt18_Rb_tree_node_baseS0_RS_
+ # So a way to avoid that problem is to include libcxx, as done here
+ self.do_test('''
+ #include <set>
+ #include <stdio.h>
+ int main() {
+ std::set<int> *fetchOriginatorNums = new std::set<int>();
+ fetchOriginatorNums->insert(171);
+ printf("hello world\\n");
+ return 1;
+ }
+ ''', 'hello world', includes=[path_from_root('tests', 'libcxx', 'include')]);
+
def test_cubescript(self):
# XXX Warning: Running this in SpiderMonkey can lead to an extreme amount of memory being
# used, see Mozilla bug 593659.
@@ -1586,14 +1600,14 @@ if 'benchmark' not in sys.argv:
temp_dir = self.get_building_dir()
project_dir = os.path.join(temp_dir, name)
- shutil.copytree(path_from_root('tests', name), project_dir)
+ shutil.copytree(path_from_root('tests', name), project_dir) # Useful in debugging sometimes to comment this out
os.chdir(project_dir)
env = os.environ.copy()
env['RANLIB'] = env['AR'] = env['CXX'] = env['CC'] = env['LIBTOOL'] = EMMAKEN
env['EMMAKEN_COMPILER'] = COMPILER
env['EMSCRIPTEN_TOOLS'] = path_from_root('tools')
env['CFLAGS'] = env['EMMAKEN_CFLAGS'] = ' '.join(COMPILER_OPTS + COMPILER_TEST_OPTS) # Normal CFLAGS is ignored by some configure's.
- if configure:
+ if configure: # Useful in debugging sometimes to comment this out (and 2 lines below)
Popen(configure + configure_args, stdout=PIPE, stderr=STDOUT, env=env).communicate()[0]
Popen(make + make_args, stdout=PIPE, stderr=STDOUT, env=env).communicate()[0]
bc_file = os.path.join(project_dir, 'bc.bc')
@@ -1646,6 +1660,10 @@ if 'benchmark' not in sys.argv:
def zzztest_poppler(self):
global SAFE_HEAP; SAFE_HEAP = 0 # Has variable object
+ global CORRECT_SIGNS; CORRECT_SIGNS = 1 # isdigit does -ord('0') and then <= 9, assuming unsigned
+ global CORRECT_OVERFLOWS; CORRECT_OVERFLOWS = 1
+
+ global COMPILER_TEST_OPTS; COMPILER_TEST_OPTS = ['-I' + path_from_root('tests', 'libcxx', 'include')] # Avoid libstdc++ linking issue, see libcxx test
def post(filename):
src = open(filename, 'r').read().replace(
@@ -1656,14 +1674,28 @@ if 'benchmark' not in sys.argv:
)
open(filename, 'w').write(src)
+ fontconfig = self.get_library('fontconfig', [os.path.join('src', '.libs', 'libfontconfig.a')])
+
poppler = self.get_library('poppler',
[os.path.join('poppler', '.libs', 'libpoppler.so.13.0.0'),
- os.path.join('utils', 'pdftoppm.o')])
- #freetype = ... link it
- self.do_ll_test(poppler,
+ os.path.join('goo', '.libs', 'libgoo.a'),
+ os.path.join('fofi', '.libs', 'libfofi.a'),
+ os.path.join('splash', '.libs', 'libsplash.a'),
+ #os.path.join('poppler', 'SplashOutputDev.o'),
+ os.path.join('utils', 'pdftoppm.o'),
+ os.path.join('utils', 'parseargs.o')],
+ configure_args=['--disable-libjpeg', '--disable-libpng'])
+
+ # Combine libraries
+ # TODO: FreeType XXX DO THIS
+
+ combined = os.path.join(self.get_building_dir(), 'combined.bc')
+ self.do_link([fontconfig, poppler], combined)
+
+ self.do_ll_test(combined,
'halp',#open(path_from_root('tests', 'poppler', 'ref.txt'), 'r').read(),
- args='-png -scale-to 512 paper.pdf filename'.split(' '),
- post_build=post)
+ args='-scale-to 512 paper.pdf filename'.split(' '),
+ post_build=post, build_ll_hook=self.do_autodebug)
def test_openjpeg(self):
global SAFE_HEAP; SAFE_HEAP = 0 # Very slow
@@ -2055,7 +2087,7 @@ class %s(T):
if LLVM_OPTS:
self.pick_llvm_opts(3, True)
COMPILER_TEST_OPTS = []
- shutil.rmtree(self.get_dir())
+ shutil.rmtree(self.get_dir()) # Useful in debugging sometimes to comment this out
self.get_dir() # make sure it exists
TT = %s
''' % (fullname, compiler['path'], compiler['quantum_size'], llvm_opts, embetter, fullname))
diff --git a/tools/exec_llvm.py b/tools/exec_llvm.py
index 05194b1a..c6071934 100755
--- a/tools/exec_llvm.py
+++ b/tools/exec_llvm.py
@@ -12,7 +12,7 @@ symbols will crash it due to
http://llvm.org/bugs/show_bug.cgi?id=6981
-So instead we compile the bitcode into native code.
+So we must get around that.
To use this, change the Makefile so that instead of
running
@@ -32,8 +32,12 @@ def path_from_root(*pathelems):
return os.path.join(os.path.sep, *(abspath.split(os.sep)[:-1] + list(pathelems)))
exec(open(path_from_root('tools', 'shared.py'), 'r').read())
-print 'EXEC_LLVM: ', sys.argv
-Popen([LLVM_COMPILER, '-march=c', sys.argv[1]]).communicate()[0]
-Popen(['gcc', sys.argv[1]+'.cbe.c']).communicate()[0]
-Popen(['./a.out'] + sys.argv[2:]).communicate()[0]
+print '// EXEC_LLVM: ', sys.argv
+
+Popen([LLVM_OPT, sys.argv[1], '-strip-debug', '-o=' + sys.argv[1]+'.clean.bc']).communicate()[0]
+Popen([LLVM_INTERPRETER, sys.argv[1]+'.clean.bc'] + sys.argv[2:]).communicate()[0]
+
+#Popen([LLVM_COMPILER, '-march=c', sys.argv[1], '-o=' + sys.argv[1]+'.cbe.c']).communicate()[0]
+#Popen(['gcc', sys.argv[1]+'.cbe.c', '-lstdc++']).communicate()[0]
+#Popen(['./a.out'] + sys.argv[2:]).communicate()[0]