Commit Graph

4529 Commits

Author SHA1 Message Date
Jakob Stoklund Olesen
0ef0937016 More layout tests and bugfixes.
Fix bugs in append methods. Linked lists are hard.
2016-07-18 18:09:31 -07:00
Jakob Stoklund Olesen
bd2945ab5e Implement instruction order.
Each EBB has a linked list of instructions in layout order.
2016-07-18 15:05:26 -07:00
Morgan Phillips
b8fbd0668c Merge pull request #9 from mrrrgn/testutils
Move test utility functions to their own module
2016-07-18 14:42:58 -07:00
Jakob Stoklund Olesen
0d924c67d0 Add Layout::ebbs() and the corresponding iterator.
Implement some tests, fix bugs in is_ebb_inserted().
2016-07-18 14:36:27 -07:00
Morgan Phillips
ea3d2f0bbd Move test utility functions to their own module 2016-07-18 14:28:00 -07:00
Jakob Stoklund Olesen
c76ba3a7f6 Add an EntityRef::wrap() method.
This is the opposite of unwrap(). It converts the ad-hoc null references like
NO_EBB and NO_INST into the more standard Option<Ebb> type which unfortunately
takes twice as much space in data structures.
2016-07-18 14:27:12 -07:00
Morgan Phillips
32f40168b5 Remove extra newline 2016-07-16 15:33:30 -07:00
Jakob Stoklund Olesen
d3ed162bac Begin a layout module.
The Layout data structure will keep track of the order of EBBs and their
instructions.

WIP.
2016-07-15 16:12:31 -07:00
Jakob Stoklund Olesen
4358a4d96e Implement EntityRef for most of the entities module.
The only exception is Value which has two dimensions.
2016-07-15 16:03:14 -07:00
Jakob Stoklund Olesen
e874393419 Add an entity_map module.
This supports the pattern of creating structs wrapping a u32 and using them as
indexes into a vector of entities. These entity references should implement the
EntityRef trait.

The EntityMap is a generic map from an EntityRef to some value type. It expects
densely indexed entities and uses a Vec to represent the mapping compactly.
2016-07-15 15:17:11 -07:00
Morgan Phillips
41d4cdba46 Add print-cfg tests 2016-07-14 13:43:11 -07:00
Morgan Phillips
4e74d85056 Id CFG graphs by function name 2016-07-14 12:22:08 -07:00
Morgan Phillips
53ed7f5ea3 Add a print-cfg subcommand.
The command returns parses a .cton file, builds a CFG, and prints it to
stdout in graphviz format.
2016-07-13 14:31:05 -07:00
Morgan Phillips
985606b12c Replace Results with assertions in invariant cases.
It seems reasonable that certain non-recoverable errors during the building of the
CFG should crash.
2016-07-13 11:04:39 -07:00
Morgan Phillips
24b421bd68 Remove misleading test comments 2016-07-12 14:46:24 -07:00
Morgan Phillips
522227c965 Cargo-fmt fixes 2016-07-12 14:42:49 -07:00
Morgan Phillips
e4a9c5c13c Add a Control Flow Graph representation.
The CFG must be instantiated against an existing function but may be
modified after creation
2016-07-12 14:37:37 -07:00
Morgan Phillips
942c4b96c9 Ignore cargo-fmt and vim related files 2016-07-12 13:59:27 -07:00
Jakob Stoklund Olesen
27b2c90a27 Add tests for parsing call and return. 2016-07-08 16:28:19 -07:00
Jakob Stoklund Olesen
8cb198b23c Delete the concept of 'local SSA form'.
This was supposed to make verification fast, but WebAssembly is no longer in
this form since it's blocks can produce values.

Also, computing a flow graph and dominator tree is really fast anyway.
2016-07-08 16:26:11 -07:00
Jakob Stoklund Olesen
3839281414 Define a return instruction.
It is possible to return multiple values from a function, so ReturnData contains
a VariableArgs instance.

We don't want return instructions to appear as 'return (v1)', so tweak the
printing of VariableArgs so the parantheses are added externally.
2016-07-08 16:19:26 -07:00
Jakob Stoklund Olesen
6587784d7d Rewrite EBB and value references after parsing.
We llow forward references to values and EBBs, so it is not possible to rewrite
these from the source domain to the in-memory domain during parsing.

Instead go through all the instructions after parsing everything and rewrite the
value and EBB references when everything has been created and mapped.
2016-07-08 15:15:53 -07:00
Jakob Stoklund Olesen
3c5c5a9e40 Don't print a space after quoted function names. 2016-07-08 11:44:20 -07:00
Jakob Stoklund Olesen
b710dd8464 Define floating point conversion instructions. 2016-07-08 11:20:19 -07:00
Jakob Stoklund Olesen
26ed45160e Fix rustc warning about unused Write trait. 2016-07-07 18:24:22 -07:00
Jakob Stoklund Olesen
62e96f4d3e Metadefs for integer reduce and extend operations.
Naming is interesting here. Since 'truncate' refers to removing the least
significant digits, use 'ireduce' instead. The 'extend' use is fairly
established. Don't abbreviate, avoid unfortunate modern vernacular.
2016-07-07 18:17:16 -07:00
Jakob Stoklund Olesen
31520717d3 Include parser tests in the test-all.sh script.
Move test-all.sh to the top level directory, and also run the parser tests from
this script.

Use a release build of cton-util to run the parser tests. As we accumulate many
tests in the tests directory tree, this will mean they can still be run quickly.

Point Travis config to the new test script.
2016-07-07 17:25:01 -07:00
Jakob Stoklund Olesen
c82b772315 Add meta definition for bitcast.
This instruction uses two type variables: input and output. Make sure that our
parser can handle it. The output type variable annotation is mandatory.

Add a ValueTypeSet::example() method which is used to provide better diagnostics
for a missing type variable.
2016-07-07 14:01:00 -07:00
Jakob Stoklund Olesen
81ca406dd0 Add meta definitions for floating point operations.
Rename the Select instruction format to Ternary since it is also used by the fma
instruction.
2016-07-07 13:16:24 -07:00
Jakob Stoklund Olesen
5d8fb0fdc3 Define icmp and fcmp comparison instructions.
Add new intcc and floatcc operand types for the immediate condition codes on
these instructions.

Add new IntCompare and FloatCompare instruction formats.

Add a generic match_enum() parser function that can match any identifier-like
enumerated operand kind that implements FromStr.

Define the icmp and fcmp instructions in case.py. Include documentation for the
condition codes with these two instructions.
2016-07-07 11:43:12 -07:00
Jakob Stoklund Olesen
70507a3be0 Add enums for condition codes.
The icmp and fmp instructions use different kinds of condition codes because
integers and floating point values behave differently.

Add a CondCode trait implementing shared behavior.
2016-07-06 15:51:41 -07:00
Jakob Stoklund Olesen
7f8479e097 Parse insertlane and extractlane instruction formats.
These instruction formats take immediate lane index operands. We store these as
u8 fields and require them to be in decimal format in the source. No hexadecimal
lane indexes are supported.
2016-07-06 13:36:15 -07:00
Jakob Stoklund Olesen
f18e5fe0fa Parse select instructions. 2016-07-05 16:51:26 -07:00
Jakob Stoklund Olesen
473e708dce Parse branch and jump instructions.
These instruction formats take EBB references with lists of argument values. For
EBBs with no arguments, the argument value list may be omitted.
2016-07-05 15:23:42 -07:00
Jakob Stoklund Olesen
cbf78c294b Print a type suffix on some polymorphic instructions. 2016-07-05 13:45:15 -07:00
Jakob Stoklund Olesen
7b03ecfe04 Add very basic test framework for parser tests.
Start with a shell script that runs .cton files through 'cton-util cat' and
compares the output to a reference. This can get fancy later.
2016-07-05 12:51:02 -07:00
Jakob Stoklund Olesen
b4525a329b Ignore comments in .cton files.
The lexer still recognizes comments and generates tokens for them. They may be
useful for test annotations at some point.
2016-07-05 12:51:02 -07:00
Jakob Stoklund Olesen
56996adabd Don't return any values from inst_results() for VOID instructions.
Instructions that don't produce any result values are marked with first_type() =
VOID. The inst_results() iterator should not return any values for such
instructions.
2016-07-05 12:35:29 -07:00
Jakob Stoklund Olesen
ab35a6e596 Add a script for reformatting all sources.
This is mostly useful when updating to a new version of rustfmt with different
behavior.
2016-07-01 14:32:04 -07:00
Jakob Stoklund Olesen
320d5b369a rustfmt v0.5.0 2016-07-01 14:26:24 -07:00
Jakob Stoklund Olesen
8e1de5c0f8 Give a better error message for unknown opcodes.
Include the name of the unrecognized opcode along with the line number.
2016-07-01 14:23:54 -07:00
Jakob Stoklund Olesen
5ce1a4f0e8 Parse and write IR in the 'cat' subcommand.
The 'cton-util cat' command parses the given files and writes them out again to
stdout. This has the effect of reformatting and stripping comments.

Fix a writer bug that inverted the blank line before the first EBB.
2016-07-01 14:12:39 -07:00
Jakob Stoklund Olesen
61094f6909 Begin a basic command line interface.
Add an external dependency to the docopt package and use it for a scaffold
command line interface for the cton-util command.

I am not too happy about taking external dependencies, and docopt pulls in 13
other packages. However, I really don't want to be writing command line parsers,
and as long as the external dependencies are confined to the tools crate, we
should be fine.

The core cretonne crate should stay free of external dependencies to avoid
trouble with embedding it.

Implement a basic 'cat' subcommand which currently behaves like unix 'cat'. It
will gain parser powers soon.
2016-07-01 13:47:17 -07:00
Jakob Stoklund Olesen
49aa38b15f Use an err! macro to build parser errors with format! arguments. 2016-06-02 08:40:47 -07:00
Jakob Stoklund Olesen
441001c1ad Avoid allocating a temporary Vec in the parser.
Wrangle the borrow checker into allowing us to iterate over function result
values while mutating the ctx.values table.
2016-06-01 20:45:58 -07:00
Jakob Stoklund Olesen
8ebf6e775d Parse controlling type variable. Do basic type inference.
Replace the make_multi_inst() function with a make_inst_results() which uses
the constraint system to create the result values. A typevar argument ensures
that this function does not infer anything from the instruction data arguments.
These arguments may not be valid during parsing.

Implement basic type inference in the parser. If the designated value operand
on a polymorphic instruction refers to a known value, use that to infer the
controlling type variable.

This simple method of type inference requires the operand value to be defined
above the use in the text. Since reordering the EBBs could place a dominating
EBB below the current one, this is a bit fragile. One possibility would be to
require the value is defined in the same EBB. In all other cases, the
controlling typevar should be explicit.
2016-06-01 10:38:34 -07:00
Jakob Stoklund Olesen
9af18728fa Clean up unused-import warnings. 2016-06-01 09:38:24 -07:00
Jakob Stoklund Olesen
840b483972 Generate Value and Ebb references in lexer.
During parsing, it is possible to see instruction operands that reference
values or EBBs that have not been created yet. These references have to be
resolved by a second pass following parsing once all EBBs and values have been
created.

To prepare for this second pass, start creating Ebb and Value references that
use the numbering from the source file rather than the in-memory real
references. Maintain Value -> Value and Ebb -> Ebb mappings. This makes it
possible to store source-numbered Ebb and Value references in instructions.

All other entities are created in the preamble, so they should have been created
before they are referenced.
2016-06-01 09:38:14 -07:00
Jakob Stoklund Olesen
96cfb40507 Add vector instructions.
Use derived type variables with the 'LaneOf' function.

Add u8 immediates to be used for lane indexes and bit shifts.
2016-05-20 15:36:03 -07:00
Jakob Stoklund Olesen
cc71744b74 Implement select and vselect instructions.
This gives us the opportunity to use the AsBool derived type variables and a
Select instruction format with a non-default typevar_operand setting.
2016-05-20 15:11:17 -07:00