aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-12-27 22:36:50 -0500
committerAlon Zakai <alonzakai@gmail.com>2012-12-27 22:36:50 -0500
commit98d5842444b419181222db88c9a1725ffc174c4b (patch)
tree3ac8a8ab0231184ef6e36878808de01aed1297e6
parent0833e5bbfe9d550714733447fa13a07546574be0 (diff)
compile given ll in compiler.html
-rw-r--r--src/compiler.html23
-rw-r--r--src/compiler.js10
2 files changed, 27 insertions, 6 deletions
diff --git a/src/compiler.html b/src/compiler.html
index 76d2dc33..9ea1c0af 100644
--- a/src/compiler.html
+++ b/src/compiler.html
@@ -5,7 +5,7 @@ Open the web console to see stderr output
<hr>
<pre id="output"></pre>
<script>
- arguments = ['', 'hello_world.ll'];
+ arguments = [];
var outputElement = document.getElementById('output');
var compilerOutput = '';
@@ -23,7 +23,26 @@ Open the web console to see stderr output
</script>
<script src="compiler.js">
</script>
-<input type="button" value="run!" onclick="eval(compilerOutput)">
+<textarea id="the_input" cols=50 rows=30>
+; ModuleID = 'tests/hello_world.bc'
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128"
+target triple = "i386-pc-linux-gnu"
+
+@.str = private unnamed_addr constant [15 x i8] c"hello, world!\0A\00", align 1 ; [#uses=1 type=[15 x i8]*]
+
+; [#uses=0]
+define i32 @main() {
+entry:
+ %retval = alloca i32, align 4 ; [#uses=1 type=i32*]
+ store i32 0, i32* %retval
+ %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0 type=i32]
+ ret i32 1
+}
+
+; [#uses=1]
+declare i32 @printf(i8*, ...)
+</textarea>
+<input type="button" value="run!" onclick="compile(document.getElementById('the_input').value); eval(compilerOutput)">
</body>
</html>
diff --git a/src/compiler.js b/src/compiler.js
index 31d033b4..7395c896 100644
--- a/src/compiler.js
+++ b/src/compiler.js
@@ -268,9 +268,11 @@ function compile(raw) {
}
}
-if (ll_file.indexOf('\n') == -1) {
- compile(read(ll_file));
-} else {
- compile(ll_file); // we are given raw .ll
+if (ll_file) {
+ if (ll_file.indexOf(String.fromCharCode(10)) == -1) {
+ compile(read(ll_file));
+ } else {
+ compile(ll_file); // we are given raw .ll
+ }
}