Skip to content

Commit

Permalink
Merge 657813e into 90a7e1d
Browse files Browse the repository at this point in the history
  • Loading branch information
ballercat committed Jul 29, 2018
2 parents 90a7e1d + 657813e commit 0b8f716
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/walt-compiler/.eslintrc
Expand Up @@ -157,7 +157,7 @@

"array-bracket-spacing": 2, // Disallow or enforce spaces inside of brackets
"brace-style": 2, // enforce one true brace style (off by default)
"camelcase": 2, // require camel case names
"camelcase": [2, { "properties": "never" }], // require camel case names
"comma-spacing": 2, // enforce spacing before and after comma
"comma-style": 2, // enforce one true comma style (off by default)
"consistent-this": 1, // enforces consistent naming when capturing the current execution context (off by default)
Expand Down
6 changes: 6 additions & 0 deletions packages/walt-compiler/src/__tests__/native-opcode-spec.walt
Expand Up @@ -60,4 +60,10 @@ export function run() {
assert("8bit load-store, signed", test8bitSigned(), -2);
assert("16bit load-store, unsigned", test16BitUnsigned(), 0x10000);
assert("16bit load-store, signed", test16BitSigned(), -2);

// TODO: test _all_ native opcodes. Use WebAssembly Spec tests as reference
assert("shr_s", i32.shr_s(1, 1), 0);
assert("rotl", i32.rotl(1, 1), 2);
assert("rotr", i32.rotr(1, 1), 0x80000000);
assert("popcnt", i32.popcnt(-1), 32);
}
33 changes: 17 additions & 16 deletions packages/walt-compiler/src/generator/native.js
Expand Up @@ -4,28 +4,29 @@ import mapSyntax from "./map-syntax";
import { textMap } from "../emitter/opcode";
import type { GeneratorType } from "./flow/types";

const alignCodes = {
load8_s: 0,
load8_u: 0,
store8: 0,
load16_s: 1,
load16_u: 1,
store16: 1,
store32: 2,
load32_s: 2,
load32_u: 2,
store: 2,
load: 2,
};

const generateNative: GeneratorType = (node, parent) => {
const block = node.params.map(mapSyntax(parent)).reduce(mergeBlock, []);

const operation = node.value.split(".").pop();
if (operation === "clz") {

if (alignCodes[operation] == null) {
block.push({ kind: textMap[node.value], params: [] });
} else {
const alignment = (() => {
switch (operation) {
case "load8_s":
case "load8_u":
case "store8":
return 0;
case "load16_s":
case "load16_u":
case "store16":
return 1;
// "store32" as well
default:
return 2;
}
})();
const alignment = alignCodes[operation];

const params = [alignment, 0];

Expand Down

0 comments on commit 0b8f716

Please sign in to comment.