Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 167 additions & 0 deletions lib/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"nodes": {
"type": "array",
"items": {
"type": "object",
"properties": {
"opcode": {
"type": "string",
"enum": [
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be actually anything. The user of this framework decides what opcodes should be present.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could limit it to the string with certain RegExp?Like in your spec?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say that the spec defines some specific opcodes that SHOULD be used, but any other opcode might be used as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You design document says:

pcode names MUST not contain : unless:

  • They are going to be consumed and renamed by one of the next stages
  • They represent platform specific low-level instructions. In this case the
    <platform-name>:prefix should be used. platform-name should not contain
    any characters except ones defined by the set [a-zA-Z0-9_\-\.]

Every node may take several literal inputs, several regular inputs, and
possibly a control input.

We can limit that with schema.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how the schema could handle:

They are going to be consumed and renamed by one of the next stages

I think I better change that MUST to SHOULD to make it less confusing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something like this?

"opcode": {
  "type": "string",
  "pattern": "^([a-zA-Z0-9\\_\\-\\.\\:])+$"
}

"if",
"jump",
"region",
"start",
"literal",
"add",
"phi",
"return"
]
},
"control": {
"type": "array",
"items": {
"type": "integer",
"minimum": 0
}
},
"inputs": {
"type": "array",
"items": {
"type": "integer",
"minimum": 0
}
},
"literals": {
"type": "array",
"items": {
"oneOf": [
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be any JavaScript value without limitation.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok.

{
"type": "integer",
"minimum": 0
},
{
"type": "string",
"enum": [
"ok",
"not-ok"
]
},
{
"type": "boolean",
"enum": [
true
]
}
]
}
}
},
"additionalProperties": false,
"required": [
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think other fields are required too.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have fixed all your requests.

"opcode"
]
}
},
"cfg": {
"type": "object",
"properties": {
"blocks": {
"type": "array",
"items": {
"type": "object",
"properties": {
"node": {
"type": "integer",
"minimum": 0
},
"nodes": {
"type": "array",
"items": {
"type": "integer",
"minimum": 0
}
},
"successors": {
"type": "array",
"items": {
"type": "integer",
"minimum": 0
}
}
},
"additionalProperties": false,
"required": [
"node",
"nodes",
"successors"
]
}
}
},
"additionalProperties": false,
"required": [
"blocks"
]
},
"dominance": {
"type": "object",
"properties": {
"blocks": {
"type": "array",
"items": {
"type": "object",
"properties": {
"node": {
"type": "integer",
"minimum": 0
},
"parent": {
"oneOf": [
{
"type": "integer",
"minimum": 0
},
{
"type": "null"
}
]
},
"frontier": {
"type": "array",
"items": {
"type": "integer",
"minimum": 0
}
}
},
"additionalProperties": false,
"required": [
"node",
"parent",
"frontier"
]
}
}
},
"additionalProperties": false,
"required": [
"blocks"
]
},
"registers": {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need this for now. Just removed it from design.md

"type": "object",
"properties": {
"nodes": {
"type": "array"
}
}
}
},
"additionalProperties": false,
"required": [
"nodes"
]
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"assert-text": "^1.1.0",
"jscs": "^1.13.1",
"jshint": "^2.8.0",
"mocha": "^2.2.5"
"mocha": "^2.2.5",
"tv4": "^1.1.12"
},
"dependencies": {
"bitfield.js": "^1.1.0"
Expand Down
8 changes: 8 additions & 0 deletions test/pipeline-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var assert = require('assert');
var assertText = require('assert-text');
var schema = require('../lib/schema.json');
var tv4 = require('tv4');

assertText.options.trim = true;

Expand All @@ -13,6 +15,12 @@ describe('JSON Pipeline', function() {
p = pipeline.create();
});

'p0 p1 p1cfg p2dom'.split(' ').forEach(function (e) {
it(e + ' should comply with the schema', function() {
assert.equal(tv4.validate(fixtures.json[e], schema), true);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why jscs did not complain, but the indent is off here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Will fix.

});
});

it('should render JSON', function() {
var start = p.add('start');
var one = p.add('literal').addLiteral(1);
Expand Down