aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-10-18 13:30:49 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-10-18 13:30:49 -0700
commitb89290b3456bd125b468391537487cbd2fd6f32e (patch)
tree7c4d6b98462fc6e880b98533ab2d52a9c91c617d
parent5c4bbda63c06e107c725d0edb90fafc169887eae (diff)
support for vector types nested in others
-rw-r--r--src/analyzer.js15
-rw-r--r--src/parseTools.js15
-rw-r--r--src/runtime.js3
3 files changed, 31 insertions, 2 deletions
diff --git a/src/analyzer.js b/src/analyzer.js
index bfccbd96..43730755 100644
--- a/src/analyzer.js
+++ b/src/analyzer.js
@@ -993,7 +993,20 @@ function analyzer(data, sidePass) {
var packed = type[0] == '<';
var internal = type;
if (packed) {
- if (type[1] !== '{') return; // vector type, <4 x float> etc.
+ if (type[1] !== '{') {
+ // vector type, <4 x float> etc.
+ var size = getVectorSize(type);
+ Types.types[type] = {
+ name_: type,
+ fields: zeros(size).map(function() {
+ return getVectorNativeType(type);
+ }),
+ packed: false,
+ flatSize: 4*size,
+ lineNum: '?'
+ };
+ return;
+ }
if (internal[internal.length-1] != '>') {
warnOnce('ignoring type ' + internal);
return; // function pointer or such
diff --git a/src/parseTools.js b/src/parseTools.js
index 649d6fed..aeb85426 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -324,6 +324,10 @@ function countNormalArgs(type, out, legalized) {
return ret;
}
+function getVectorSize(type) {
+ return parseInt(type.substring(1, type.indexOf(' ')));
+}
+
function getVectorBaseType(type) {
Types.usesSIMD = true;
switch (type) {
@@ -335,6 +339,17 @@ function getVectorBaseType(type) {
}
}
+function getVectorNativeType(type) {
+ Types.usesSIMD = true;
+ switch (type) {
+ case '<2 x float>':
+ case '<4 x float>': return 'float';
+ case '<2 x i32>':
+ case '<4 x i32>': return 'i32';
+ default: throw 'unknown vector type ' + type;
+ }
+}
+
function addIdent(token) {
token.ident = token.text;
return token;
diff --git a/src/runtime.js b/src/runtime.js
index e36068c8..6839f556 100644
--- a/src/runtime.js
+++ b/src/runtime.js
@@ -225,7 +225,8 @@ var Runtime = {
size = field.substr(1)|0;
alignSize = 1;
} else {
- throw 'Unclear type in struct: ' + field + ', in ' + type.name_ + ' :: ' + dump(Types.types[type.name_]);
+ assert(field[0] === '<', field); // assumed to be a vector type, if none of the above
+ size = alignSize = Types.types[field].flatSize; // fully aligned
}
if (type.packed) alignSize = 1;
type.alignSize = Math.max(type.alignSize, alignSize);