Compare commits

81 Commits

Author SHA1 Message Date
6abdf8f993 mie: implement block dominance calculation using lengauer-tarjan algorithm 2026-02-01 10:33:36 +00:00
870b2bfbac mie: memref: add load op 2026-02-01 10:33:03 +00:00
5344c02b48 mie: builtin: add some diagnostics for value resolution 2026-02-01 10:25:43 +00:00
4a4f0c483a mie: ir: op: remove redundant op_dialect pointer 2026-02-01 10:24:06 +00:00
f37ee90b0e mie: func: add function-like trait 2026-01-31 23:29:17 +00:00
3f901ed83a doc: update type prefix in sample graph files 2026-01-27 20:52:35 +00:00
b28efa2d08 tool: optimise: update mie_lex usage 2026-01-27 20:51:31 +00:00
5835d25679 tool: validate: if parse fails, print any diagnostic messages 2026-01-27 20:51:18 +00:00
d4fbd75a59 tool: implement a diagnostic message printer 2026-01-27 20:48:04 +00:00
0b1d4697a2 tool: ctx-dump: show registered diag classes/messages 2026-01-27 20:47:10 +00:00
cd49417972 mie: add a system for registering and producing detailed diagnostic messages 2026-01-27 20:46:44 +00:00
bd5ba9e9fd mie: lex: move file i/o handling to a separate struct 2026-01-27 20:46:08 +00:00
b5fa40d4d8 mie: tool: add command to run optimisations on an input IR file 2026-01-25 15:12:07 +00:00
a67e4b6688 mie: tool: validate: remove functionality that was moved to internal subcommands 2026-01-25 15:11:06 +00:00
5873326138 mie: tool: split internal command into several different subcommands 2026-01-25 15:10:23 +00:00
00152cac56 mie: convert-scf-to-cf: implement if match/rewrite using new interface 2026-01-25 15:08:19 +00:00
287983fa95 mie: implement a full rewriter with pattern-matching and rewriting support
the new rewriter interface supports running patterns over an Op's children
matching Ops that conform to a pattern, and rewriting Ops in arbitrary ways.
2026-01-25 15:06:43 +00:00
8cdbf5389c mie: pass: manager: update mie_walker usage 2026-01-25 15:05:44 +00:00
00c7c3d5ea mie: parse: update parse_region_list to use new Op->Region linking mechanism 2026-01-25 15:05:18 +00:00
9e546ee32f mie: name: fix crash when destroying a zeroed mie_name 2026-01-25 15:04:37 +00:00
00ba3a3d87 mie: print: implement exception-printing of resolved, but null, op args
this is to make it easier to spot mistakes made when modifying IR.
2026-01-25 15:02:48 +00:00
d44bc8c5c0 mie: ir: op: fix crash when checking if an unresolved op is isolated 2026-01-25 15:02:17 +00:00
a22e95d88d mie: ir: op: add functions to check what an Op is, and add successors with args 2026-01-25 15:01:41 +00:00
0a791fdfb2 mie: dialect: update Op emitter functions to use mie_emitter 2026-01-25 15:00:37 +00:00
fe511011ec mie: ir: walk: implement non-recursive traversal
struct mie_walker is now a public struct that can (and should) be stack
allocated. this means that non-recursive traversal of an Op's children
uses no dynamically allocated memory.
2026-01-25 14:58:51 +00:00
e8534f8d70 mie: ir: Op->Region, Region->Block, and Block->Op lists are now b_queues rather than mie_vectors
this change has two key benefits:
 1. we no longer need to allocate large contigious buffers for Regions with lots
    of Blocks, or Blocks with lots of Ops.
 2. this simplifies re-arranging, inserting, and moving parts of the IR structure.
2026-01-25 14:56:47 +00:00
bf8c966c03 mie: ir: builder: add mie_emitter support 2026-01-25 14:53:24 +00:00
7d30e8f3ff mie: ir: add an emitter interface for emitting IR constructs
mie_emitter can be inherited from by any structure that supports
emitting IR constructs like Ops and Blocks. Dialect Op emitter
functions can wrap mie_emitter to simplify emitting specific Ops,
and these functions can then be used with any struct that inherits
from mie_emitter.
2026-01-25 14:51:36 +00:00
e9d2c0fbc7 mie: scf: implement lots of print and emit functions 2026-01-23 23:33:16 +00:00
a710ef0b24 mie: func: implement lots of print and emit functions 2026-01-23 23:22:57 +00:00
0277931ca1 mie: builtin: implement lots of print and emit functions 2026-01-23 23:22:47 +00:00
ac7860b6bd mie: ir: rewrite: add pattern and rewriter interface 2026-01-23 23:21:42 +00:00
29984307aa mie: pass: support filtering passes to any op of a given dialect 2026-01-23 23:21:16 +00:00
ac96248d7e mie: ir: builder: support adding names to non-isolated op regions 2026-01-23 23:19:29 +00:00
593eda2797 mie: trait: table: fix get_unique() unboxing the wrong pointer 2026-01-23 23:17:39 +00:00
d0ac8a9fed mie: ir: walk: re-implement walker with a stack rather than a queue 2026-01-23 22:50:05 +00:00
89ebbcc462 mie: parse: replace all op-creation with mie_block_add_op calls 2026-01-23 22:42:39 +00:00
554a1e7342 mie: ir: op: keep a pointer to the block that contains the op 2026-01-23 22:42:05 +00:00
6d1e308ff1 mie: ir: op: only create a name map if the op is isolated-from-above 2026-01-23 22:41:03 +00:00
58bd336eb8 mie: dialect: add emitter functions for various ops 2026-01-21 14:42:22 +00:00
008966e046 mie: ir: add ir builder interface 2026-01-21 14:40:22 +00:00
83343a5eea mie: ir: block: add function to create block parameters 2026-01-21 14:39:56 +00:00
76166167c9 mie: builtin: improve int attribute print callback 2026-01-21 14:39:12 +00:00
f6f6131f52 mie: builtin: add function to create mie_type_attr instances 2026-01-21 14:38:01 +00:00
33f9ccd871 mie: ir: register: implement moving and cleanup of mie_register_use 2026-01-21 14:36:24 +00:00
0c4ebe7f39 mie: ctx: add function to create ops 2026-01-21 14:17:43 +00:00
72de4ce845 mie: ir: op: add function to add op arguments 2026-01-21 14:15:02 +00:00
937dc57c4e tool: validate: resolve op definitions; run test pass 2026-01-19 14:00:25 +00:00
b8c0d139a8 vim: update type and attribute prefixes 2026-01-19 14:00:04 +00:00
abf43a9022 doc: update ir sample files 2026-01-19 13:59:43 +00:00
4700ce7778 build: bump minimum CMake version 2026-01-19 13:59:14 +00:00
95c51045b6 meta: update clang-format config 2026-01-19 13:59:00 +00:00
e62c9c4775 mie: ir: add stub rewriter interface 2026-01-19 13:58:24 +00:00
a97678a1c2 mie: add stub memref dialect 2026-01-19 13:58:12 +00:00
5e13824706 mie: add parent pointers to region and block; two-way link between a register and its users 2026-01-19 13:57:25 +00:00
da140ed0d1 mie: parse: remove duplicate sub-parsers in parse_generic_op 2026-01-19 13:52:21 +00:00
cb3d37043c mie: update b_bstr usage 2026-01-19 13:51:27 +00:00
55161cd6c8 mie: re-implement vectors of blocks and registers using vector move callbacks
vector move callbacks allow mie_name instances to be stored in movable memory,
as the internal bst pointers can now be fixed during vector resize operations.
2026-01-18 22:58:17 +00:00
759aaf9fd8 mie: vector: add copy- and move-constructor support 2026-01-18 21:52:39 +00:00
04af390fe8 mie: pass: add a group of builtin passes
right now, the group only contains a single pass: prefix-func-with-underscore.
this is a test pass that visits instances of func.func and prepends
an underscore to the func's symbol name.
2026-01-18 21:19:15 +00:00
0add39f304 mie: implement a pass system
passes allow defined units of functionality to be applied
on an IR structure. the pass manager can be used to schedule
passes at certain depths of the IR structure and/or on or within
certain types of ops (or ops that have certain traits/interfaces).
2026-01-18 21:17:44 +00:00
429ec770b5 mie: attribute: map: implement REPLACE flag in put() 2026-01-18 21:16:28 +00:00
092c9969cf mie: add NAME_EXISTS status code 2026-01-18 21:16:10 +00:00
6fcc3c8edd mie: ir: op: add functions to query a certain trait or interface 2026-01-18 21:14:50 +00:00
d335cd9823 mie: ir: walk: walk is no longer recursive by default 2026-01-18 20:27:55 +00:00
c014895051 mie: func: add return op 2026-01-17 10:31:52 +00:00
76477be5bd mie: arith: add cmpi and constant ops 2026-01-17 10:31:39 +00:00
ee9e2d3050 mie: arith: implement op printer callbacks 2026-01-17 10:31:08 +00:00
e5ecdd40e8 mie: cf: implement op printer callbacks 2026-01-17 10:29:47 +00:00
c410e0a6e3 mie: builtin: implement op printer callbacks 2026-01-17 10:28:51 +00:00
3ba20e5ed4 mie: print: add more functions to printer interface 2026-01-17 10:27:23 +00:00
f19dfaa050 mie: ctx: fix mie_ctx_resolve_op not checking op-definition pointer properly 2026-01-17 10:26:37 +00:00
2869e98556 mie: builtin: add function to get int/float value from an attribute 2026-01-17 10:25:49 +00:00
b289c6e2de mie: ir: op: add function to get type from mie_op_arg 2026-01-17 10:22:38 +00:00
fd72d217f6 mie: ir: implement a walker interface for traversing ir structures 2026-01-17 10:21:58 +00:00
e1f7f46d3e mie: ir: replace mie_module ir object with a builtin generic "module" op
the builtin.module op behaves exactly like any other op, and is designed
to be a container for other ops of any type. it can be used as the
top-level container for other ops (other top-level containers can be used
instead).

this also changes the file format. now, an ir file can only contain a
single top-level op. any other ops in the ir must be contained
directly or indirectly by this top-level op.
2026-01-16 10:01:19 +00:00
65905bc55b mie: implement support for custom op print formats 2026-01-15 14:20:13 +00:00
3c4af9c26e mie: builtin: initial implementation of a symbol system
the symbol system will allow ops to reference each other via symbolic
names, rather than just via their SSA output registers. this will
allow for links between ops that are less strict than SSA.

the two parts of the system are:
- the symbol-table trait. ops with this trait can contain symbol ops.
- the symbol interface. ops with this interface have the necessary attributes
  to be treated as symbols.
2026-01-14 18:21:28 +00:00
11fc7a6ca9 mie: implement an interface system for ops
this system allows dialects to register named interfaces, which are collections of function
pointers. an op can then implement this interface, providing callbacks for the interface's
virtual function pointers.

C code can request a pointer to an op's implementation of a given interface and call
virtual functions with no knowledge required about the op itself. this functonality
will also be extended to types, attributes, and dialects themselves.
2026-01-14 18:17:38 +00:00
50f4be621b mie: move all builtin types (int, float, index, etc) and attributes to the builtin dialect 2026-01-14 09:45:14 +00:00
da630ce382 mie: replace fixed value system with an extensible attribute interface
under this new system, dialects can define their own custom attributes,
complete with their own print() and parse() callbacks, which can then be
used as values in an op's attribute dictionary.

alongside custom dialect attributes, the former int, float, and string
constant values have been converted to attributes provided by the
arith and builtin dialects respectively. the caches for these attributes
have also been moved from mie_ctx to their respective dialect data
structures.

this system will allow new types of attributes to be implemented,
including dictionaries, arrays, and references to types themselves
(rather than just particular values of a given type).
2026-01-13 22:37:43 +00:00
176 changed files with 9990 additions and 1723 deletions

View File

@@ -1,64 +1,6 @@
BasedOnStyle: WebKit
IndentWidth: 8
---
Language: C
DerivePointerAlignment: false
PointerAlignment: Right
ColumnLimit: 80
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignConsecutiveMacros: AcrossEmptyLinesAndComments
AlignEscapedNewlines: Right
AlignOperands: AlignAfterOperator
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLambdasOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: true
ExperimentalAutoDetectBinPacking: false
BitFieldColonSpacing: Both
BreakBeforeBraces: Linux
BreakBeforeBinaryOperators: All
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeComma
BreakInheritanceList: BeforeComma
BreakStringLiterals: true
ContinuationIndentWidth: 8
Cpp11BracedListStyle: true
IncludeBlocks: Regroup
SortIncludes: true
IndentRequires: true
NamespaceIndentation: Inner
ReflowComments: true
SpacesBeforeTrailingComments: 3
TabWidth: 8
UseTab: AlignWithSpaces
PenaltyReturnTypeOnItsOwnLine: 1000000
PenaltyExcessCharacter: 5
PenaltyBreakOpenParenthesis: 5
PenaltyBreakBeforeFirstCallParameter: 5
PenaltyIndentedWhitespace: 0
AttributeMacros:
- BLUELIB_API
ForEachMacros:
- b_btree_foreach
- b_queue_foreach
MacroBlockBegin: "MIE_.*_BEGIN"
MacroBlockEnd: "MIE_.*_END"
---
Language: Cpp
DerivePointerAlignment: false
PointerAlignment: Right
@@ -114,61 +56,5 @@ AttributeMacros:
ForEachMacros:
- b_btree_foreach
- b_queue_foreach
---
Language: ObjC
DerivePointerAlignment: false
PointerAlignment: Right
ColumnLimit: 80
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignConsecutiveMacros: AcrossEmptyLinesAndComments
AlignEscapedNewlines: Right
AlignOperands: AlignAfterOperator
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLambdasOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: true
ExperimentalAutoDetectBinPacking: false
BitFieldColonSpacing: Both
BreakBeforeBraces: Linux
BreakBeforeBinaryOperators: All
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeComma
BreakInheritanceList: BeforeComma
BreakStringLiterals: true
ContinuationIndentWidth: 8
Cpp11BracedListStyle: true
IncludeBlocks: Regroup
SortIncludes: true
IndentRequires: true
NamespaceIndentation: Inner
ReflowComments: true
SpacesBeforeTrailingComments: 3
TabWidth: 8
UseTab: AlignWithSpaces
PenaltyReturnTypeOnItsOwnLine: 1000000
PenaltyExcessCharacter: 5
PenaltyBreakOpenParenthesis: 5
PenaltyBreakBeforeFirstCallParameter: 5
PenaltyIndentedWhitespace: 0
AttributeMacros:
- BLUELIB_API
ForEachMacros:
- b_btree_foreach
- b_queue_foreach
MacroBlockBegin: "B_TYPE_.*_BEGIN"
MacroBlockEnd: "B_TYPE_.*_END"
MacroBlockBegin: "MIE_.*_BEGIN"
MacroBlockEnd: "MIE_.*_END"

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.14)
project(mie C)
if (WIN32)

View File

@@ -1,22 +1,22 @@
select.graph {
%entry = +select.entry -> #select.chain
%entry = +select.entry -> !select.chain
%0 = +select.register @0 : i32 -> #select.register
%1 = +select.register @1 : i32 -> #select.register
%0 = +select.register @0 : i32 -> !select.register
%1 = +select.register @1 : i32 -> !select.register
%v.0, %c.0 = +select.register.read %entry, %0 \
: (#select.chain, #select.register) \
-> (i32, #select.chain)
: (!select.chain, !select.register) \
-> (i32, !select.chain)
%v.1, %c.1 = +select.register.read %entry, %1 \
: (#select.chain, #select.register) \
-> (i32, #select.chain)
: (!select.chain, !select.register) \
-> (i32, !select.chain)
%2 = +select.register @2 : i32
%v.2, %c.2 = +select.register.read %entry, %2 \
: (#select.chain, #select.register) \
-> (#select.register, #select.chain)
: (!select.chain, !select.register) \
-> (!select.register, !select.chain)
%v.3 = arith.build-pair %v.0, %v.1 : (i32, i32) -> i64
@@ -24,15 +24,15 @@ select.graph {
%v.5 = arith.mul %v.4, %v.3 : (i32, i32) -> i32
%x0 = +select.mach-register @x0 : i32 -> #select.register
%x0 = +select.mach-register @x0 : i32 -> !select.register
%c.3, %g.0 = +select.register.write %entry, %x0, %v.5 \
: (#select.chain, #select.register, i32) \
-> (#select.chain, #select.glue)
: (!select.chain, !select.register, i32) \
-> (!select.chain, !select.glue)
%c.4 = *risc-v.RET %c.3, %x0, %g.0 \
: (#select.chain, #select.register, #select.glue) \
-> #select.chain
: (!select.chain, !select.register, !select.glue) \
-> !select.chain
+select.graph-root %c.4 : #select.chain
+select.graph-root %c.4 : !select.chain
}

View File

@@ -1,31 +1,31 @@
select.graph {
%entry = +select.entry -> #select.chain
%entry = +select.entry -> !select.chain
%N1 = ptr.alloca i32 -> ptr
%N2 = i32.constant 3 -> i32
%N3.c = +ptr.store %entry, %N2, %N1 : (#select.chain, i32, ptr) -> #select.chain
%N3.c = +ptr.store %entry, %N2, %N1 : (!select.chain, i32, ptr) -> !select.chain
%N4 = ptr.alloca i32 -> ptr
%N5 = i32.constant 0 -> i32
%N6.c = +ptr.store %entry, %N5, %N4 : (#select.chain, i32, ptr) -> #select.chain
%N6.c = +ptr.store %entry, %N5, %N4 : (!select.chain, i32, ptr) -> !select.chain
%N7, %N7.c = +ptr.load %N6.c, %N1 : (#select.chain, ptr) -> (#ivy.id, #select.chain)
%N7, %N7.c = +ptr.load %N6.c, %N1 : (!select.chain, ptr) -> (!ivy.id, !select.chain)
%N8 = i32.constant 10 -> i32
%N9 = arith.cmp gt %N7, %N8 : (#ivy.id, i32) -> i1
%N9 = arith.cmp gt %N7, %N8 : (!ivy.id, i32) -> i1
%N10.c = +select.chain-group %N7.c, %N6.c : (#select.chain, #select.chain) -> #select.chain
%N10.c = +select.chain-group %N7.c, %N6.c : (!select.chain, !select.chain) -> !select.chain
%N11 = +select.block-ref @if.true -> #select.block
%N11 = +select.block-ref @if.true -> !select.block
%N12.c = +cf.br-cond %N10.c, %N9, %N11 : (#select.chain, i1, #select.block) -> #select.chain
%N12.c = +cf.br-cond %N10.c, %N9, %N11 : (!select.chain, i1, !select.block) -> !select.chain
%N13 = +select.block-ref @if.false -> #select.block
%N13 = +select.block-ref @if.false -> !select.block
%N14.c = cf.br %N12.c, %N13

View File

@@ -8,15 +8,15 @@ ivy.module {
%cout = ivy.global-ref @cout -> ptr
ivy.class @Person {
%self.name = ivy.object-var @name : #ivy.id -> ptr
%self.age = ivy.object-var @age : #ivy.id -> ptr
%self.val = ivy.object-var @val : #ivy.id -> ptr
%self.__example-property-4 = ivy.object-var @val : #ivy.id -> ptr
%self.__example-property-5 = ivy.object-var @val : #ivy.id -> ptr
%self.name = ivy.object-var @name : !ivy.id -> ptr
%self.age = ivy.object-var @age : !ivy.id -> ptr
%self.val = ivy.object-var @val : !ivy.id -> ptr
%self.__example-property-4 = ivy.object-var @val : !ivy.id -> ptr
%self.__example-property-5 = ivy.object-var @val : !ivy.id -> ptr
ivy.msgh.object init(name:%name, age:%age) -> void {
ptr.store %name, %self.name : #ivy.id, ptr
ptr.store %age, %self.age : #ivy.id, ptr
ptr.store %name, %self.name : !ivy.id, ptr
ptr.store %age, %self.age : !ivy.id, ptr
func.return : ()
}
@@ -24,41 +24,41 @@ ivy.module {
%0 = ivy.string-builder.begin
ivy.string-builder.add %0 << "Received "
ivy.string-builder.add %0 << %data : #ivy.id
ivy.string-builder.add %0 << %data : !ivy.id
ivy.string-builder.add %0 << ", "
ivy.string-builder.add %0 << %extra : #ivy.id
ivy.string-builder.add %0 << %extra : !ivy.id
%1 = ivy.string-builder.end %0 -> #ivy.id
%1 = ivy.string-builder.end %0 -> !ivy.id
%2 = ptr.load %cout : ptr -> #ivy.id
%2 = ptr.load %cout : ptr -> !ivy.id
ivy.msg.send to %2, put:%1 -> void
func.return : ()
}
ivy.msgh.object name -> #ivy.id {
%0 = ptr.load %self.name : ptr -> #ivy.id
func.return %0 : #ivy.id
ivy.msgh.object name -> !ivy.id {
%0 = ptr.load %self.name : ptr -> !ivy.id
func.return %0 : !ivy.id
}
ivy.msgh.object age -> #ivy.id {
%0 = ptr.load %self.age : ptr -> #ivy.id
func.return %0 : #ivy.id
ivy.msgh.object age -> !ivy.id {
%0 = ptr.load %self.age : ptr -> !ivy.id
func.return %0 : !ivy.id
}
ivy.msgh.object age-in-months -> #ivy.id {
%0 = ptr.load %self.age : ptr -> #ivy.id
ivy.msgh.object age-in-months -> !ivy.id {
%0 = ptr.load %self.age : ptr -> !ivy.id
%1 = arith.constant 12 : i32
%multmp = ivy.mul %0, %1 : (#ivy.id, i32) -> #ivy.id
func.return %multmp : #ivy.id
%multmp = ivy.mul %0, %1 : (!ivy.id, i32) -> !ivy.id
func.return %multmp : !ivy.id
}
ivy.msgh.object set-name:%name -> void {
ptr.store %name, %self.name : #ivy.id, ptr
ptr.store %name, %self.name : !ivy.id, ptr
func.return : ()
}
ivy.msgh.object set-age:%age -> void {
ptr.store %age, %self.age : #ivy.id, ptr
ptr.store %age, %self.age : !ivy.id, ptr
func.return : ()
}
@@ -66,28 +66,28 @@ ivy.module {
scf.switch : () -> void
case {
%0 = ivy.atom "years"
%cmptmp.0 = ivy.cmp eq %age, %0 : (#ivy.id, #ivy.atom) -> i1
%cmptmp.0 = ivy.cmp eq %age, %0 : (!ivy.id, !ivy.atom) -> i1
scf.switch-condition %cmptmp.0
} then {
ptr.store %age, %self.age : #ivy.id, ptr
ptr.store %age, %self.age : !ivy.id, ptr
scf.switch-break : ()
} case {
%1 = ivy.atom "months"
%cmptmp.1 = ivy.cmp eq %age, %1 : (#ivy.id, #ivy.atom) -> i1
%cmptmp.1 = ivy.cmp eq %age, %1 : (!ivy.id, !ivy.atom) -> i1
scf.condition %cmptmp.1
} then {
%d0 = arith.constant 12 : i32
%divtmp.0 = ivy.div %age, %d0 : (#ivy.id, i32) -> #ivy.id
ptr.store %divtmp.0, %self.age : #ivy.id, ptr
%divtmp.0 = ivy.div %age, %d0 : (!ivy.id, i32) -> !ivy.id
ptr.store %divtmp.0, %self.age : !ivy.id, ptr
scf.switch-break : ()
} case {
%2 = ivy.atom "days"
%cmptmp.2 = ivy.cmp eq %age, %2 : (#ivy.id, #ivy.atom) -> i1
%cmptmp.2 = ivy.cmp eq %age, %2 : (!ivy.id, !ivy.atom) -> i1
scf.condition %cmptmp.2
} then {
%d1 = arith.constant 365 : i32
%divtmp.1 = ivy.div %age, %d1 : (#ivy.id, i32) -> #ivy.id
ptr.store %divtmp.1, %self.age : #ivy.id, ptr
%divtmp.1 = ivy.div %age, %d1 : (!ivy.id, i32) -> !ivy.id
ptr.store %divtmp.1, %self.age : !ivy.id, ptr
scf.switch-break : ()
} default {
%d2 = arith.constant 0 : i32
@@ -97,56 +97,56 @@ ivy.module {
func.return : ()
}
ivy.msgh.object get-age-in-units:%units -> #ivy.id {
%result = scf.switch : () -> #ivy.id
ivy.msgh.object get-age-in-units:%units -> !ivy.id {
%result = scf.switch : () -> !ivy.id
case {
%0 = ivy.atom "years"
%cmptmp.0 = ivy.cmp eq %age, %0 : (#ivy.id, #ivy.atom) -> i1
%cmptmp.0 = ivy.cmp eq %age, %0 : (!ivy.id, !ivy.atom) -> i1
scf.switch-condition %cmptmp.0
} then {
%v0 = ptr.load %self.age : ptr -> #ivy.id
scf.switch-break %v0 : #ivy.id
%v0 = ptr.load %self.age : ptr -> !ivy.id
scf.switch-break %v0 : !ivy.id
} case {
%1 = ivy.atom "months"
%cmptmp.1 = ivy.cmp eq %age, %1 : (#ivy.id, #ivy.atom) -> i1
%cmptmp.1 = ivy.cmp eq %age, %1 : (!ivy.id, !ivy.atom) -> i1
scf.condition %cmptmp.1
} then {
%v0 = ptr.load %self.age : ptr -> #ivy.id
%v0 = ptr.load %self.age : ptr -> !ivy.id
%d0 = arith.constant 12 : i32
%divtmp.0 = ivy.div %v0, %d0 : (#ivy.id, i32) -> #ivy.id
scf.switch-break %divtmp.0 : #ivy.id
%divtmp.0 = ivy.div %v0, %d0 : (!ivy.id, i32) -> !ivy.id
scf.switch-break %divtmp.0 : !ivy.id
} case {
%2 = ivy.atom "days"
%cmptmp.2 = ivy.cmp eq %age, %2 : (#ivy.id, #ivy.atom) -> i1
%cmptmp.2 = ivy.cmp eq %age, %2 : (!ivy.id, !ivy.atom) -> i1
scf.condition %cmptmp.2
} then {
%v1 = ptr.load %self.age : ptr -> #ivy.id
%v1 = ptr.load %self.age : ptr -> !ivy.id
%d1 = arith.constant 365 : i32
%divtmp.1 = ivy.div %v1, %d1 : (#ivy.id, i32) -> #ivy.id
scf.switch-break %divtmp.1 : #ivy.id
%divtmp.1 = ivy.div %v1, %d1 : (!ivy.id, i32) -> !ivy.id
scf.switch-break %divtmp.1 : !ivy.id
} default {
%d2 = arith.constant 0 : i32
scf.switch-break %d2 : #ivy.id
scf.switch-break %d2 : !ivy.id
}
func.return %result : #ivy.id
func.return %result : !ivy.id
}
ivy.object-prop example-property
get {
%0 = ptr.load %self.val : ptr -> #ivy.id
func.return %0 : #ivy.id
%0 = ptr.load %self.val : ptr -> !ivy.id
func.return %0 : !ivy.id
}
set (%value: #ivy.id) {
ptr.store %value, %self.val : #ivy.id, ptr
set (%value: !ivy.id) {
ptr.store %value, %self.val : !ivy.id, ptr
func.return : ()
}
ivy.object-prop example-property-2 get {
%0 = ptr.load %self.val : ptr -> #ivy.id
func.return %0 : #ivy.id
} set (%x: #ivy.id) {
ptr.store %x, %self.val : #ivy.id, ptr
%0 = ptr.load %self.val : ptr -> !ivy.id
func.return %0 : !ivy.id
} set (%x: !ivy.id) {
ptr.store %x, %self.val : !ivy.id, ptr
func.return : ()
}
@@ -156,16 +156,16 @@ ivy.module {
}
ivy.object-prop example-property-4 get {
%0 = ptr.load %self.__example-property-4 : ptr -> #ivy.id
func.return %0 : #ivy.id
} set (%0: #ivy.id) {
ptr.store %0, %self.__example-property-4 : #ivy.id, ptr
%0 = ptr.load %self.__example-property-4 : ptr -> !ivy.id
func.return %0 : !ivy.id
} set (%0: !ivy.id) {
ptr.store %0, %self.__example-property-4 : !ivy.id, ptr
func.return : ()
}
ivy.object-prop example-property-5 get {
%0 = ptr.load %self.__example-property-5 : ptr -> #ivy.id
func.return %0 : #ivy.id
%0 = ptr.load %self.__example-property-5 : ptr -> !ivy.id
func.return %0 : !ivy.id
}
}
@@ -175,19 +175,19 @@ ivy.module {
%0 = ivy.str.constant "John Doe"
%1 = arith.constant 34 : i32
%2 = ivy.msg.send to %Person, new(name:%0, age:%1) -> #ivy.id
%2 = ivy.msg.send to %Person, new(name:%0, age:%1) -> !ivy.id
%p1 = ptr.alloca #ivy.id -> ptr
ptr.store %2, %p1 : #ivy.id, ptr
%p1 = ptr.alloca !ivy.id -> ptr
ptr.store %2, %p1 : !ivy.id, ptr
; p1 set-age:100 in-unit:$months.
%3 = ptr.load %p1 : ptr -> #ivy.id
%3 = ptr.load %p1 : ptr -> !ivy.id
%4 = arith.constant 100 : i32
%5 = ivy.atom "months"
ivy.msg.send to %3, set-age:%4 in-units:%5 -> void
; p1 test(param:'Hello', 'World').
%6 = ptr.load %p1 : ptr -> #ivy.id
%6 = ptr.load %p1 : ptr -> !ivy.id
%7 = ivy.str.constant "Hello"
%8 = ivy.str.constant "World"
ivy.msg.send to %6, test(param:%7, _:%8) -> void
@@ -213,9 +213,9 @@ ivy.module {
%14 = ptr.load %i : ptr -> i32
ivy.string-builder.add %12 << %14 : i32
%15 = ivy.string-builder.end %12 -> #ivy.id
%15 = ivy.string-builder.end %12 -> !ivy.id
%16 = ptr.load %cout : ptr -> #ivy.id
%16 = ptr.load %cout : ptr -> !ivy.id
ivy.msg.send to %16, put:%15 -> void
; i += 2
@@ -229,7 +229,7 @@ ivy.module {
%19 = arith.constant 0 : i32
%20 = arith.constant 100 : i32
%21 = arith.constant 2 : i32
%22 = ivy.msg.send to %19, to:%20 step:%21 -> #ivy.id
%22 = ivy.msg.send to %19, to:%20 step:%21 -> !ivy.id
; for x in 0 to:100 step:2 do
ivy.for %x in %22 -> void {
@@ -237,12 +237,12 @@ ivy.module {
; 'Count is {x}'
ivy.string-builder.add %23 << "Count is "
ivy.string-builder.add %23 << %x : #ivy.id
ivy.string-builder.add %23 << %x : !ivy.id
%25 = ivy.string-builder.end %23 -> #ivy.id
%25 = ivy.string-builder.end %23 -> !ivy.id
; cout put:"Count is {x}"
%26 = ptr.load %cout : ptr -> #ivy.id
%26 = ptr.load %cout : ptr -> !ivy.id
ivy.msg.send to %26, put:%25 -> void
}
@@ -251,16 +251,16 @@ ivy.module {
%28 = arith.constant 100 : i32
%29 = arith.constant 2 : i32
; [ :i | cout put:'Count: {i}' ]
%30 = ivy.lambda %i : (#ivy.id) -> void {
%30 = ivy.lambda %i : (!ivy.id) -> void {
%0 = ivy.string-builder.begin
ivy.string-builder.add %0 << "Count is "
ivy.string-builder.add %0 << %i : #ivy.id
ivy.string-builder.add %0 << %i : !ivy.id
%2 = ivy.string-builder.end %0 -> #ivy.id
%2 = ivy.string-builder.end %0 -> !ivy.id
%cout = ivy.global-ref @cout -> ptr
%3 = ptr.load %cout : ptr -> #ivy.id
%3 = ptr.load %cout : ptr -> !ivy.id
ivy.msg.send to %3, put:%2 -> void
}
@@ -273,29 +273,29 @@ ivy.module {
ptr.store %31, %q : i32, ptr
; l = [ cout put:'Value of q is {q}' ].
%l = ptr.alloca #ivy.id
%l = ptr.alloca !ivy.id
%32 = ptr.load %q : ptr -> i32
%33 = ivy.lambda (%env.q = %32) : () -> void {
%0 = ivy.string-builder.begin
ivy.string-builder.add %0 << "Value of q is "
ivy.string-builder.add %0 << %env.q : #ivy.id
ivy.string-builder.add %0 << %env.q : !ivy.id
%2 = ivy.string-builder.end %0 -> #ivy.id
%2 = ivy.string-builder.end %0 -> !ivy.id
%cout = ivy.global-ref @cout -> ptr
%3 = ptr.load %cout : ptr -> #ivy.id
%3 = ptr.load %cout : ptr -> !ivy.id
ivy.msg.send to %3, put:%2 -> void
}
ptr.store %33, %l : #ivy.id, ptr
ptr.store %33, %l : !ivy.id, ptr
; q = 64.
%34 = arith.constant 64 : i32
ptr.store %34, %q : i32, ptr
; l call.
%35 = ptr.load %l : ptr -> #ivy.id
%35 = ptr.load %l : ptr -> !ivy.id
ivy.msg.send to %35, call -> void
%j = ptr.alloca i32 -> ptr
@@ -311,14 +311,14 @@ ivy.module {
%39 = ivy.lambda : () -> void {
%cout = ivy.global-ref @cout -> ptr
%0 = ivy.str.constant "True!"
%1 = ptr.load %cout : ptr -> #ivy.id
%1 = ptr.load %cout : ptr -> !ivy.id
ivy.msg.send to %1, put:%0 -> void
}
%40 = ivy.lambda : () -> void {
%cout = ivy.global-ref @cout -> ptr
%0 = ivy.str.constant "False!"
%1 = ptr.load %cout : ptr -> #ivy.id
%1 = ptr.load %cout : ptr -> !ivy.id
ivy.msg.send to %1, put:%0 -> void
}
@@ -331,53 +331,53 @@ ivy.module {
scf.if %cmptmp.0 -> void {
%43 = ivy.str.constant "True!"
%44 = ptr.load %cout : ptr -> #ivy.id
%44 = ptr.load %cout : ptr -> !ivy.id
ivy.msg.send to %44, put:%43 -> void
}
; pkg = {}.
%pkg = ptr.alloca #ivy.id -> ptr
%pkg = ptr.alloca !ivy.id -> ptr
%Package = ivy.global-ref @std.lang.Package -> ptr
%45 = ivy.msg.send to %Package, new -> #ivy.id
ptr.store %45, %pkg : #ivy.id, ptr
%45 = ivy.msg.send to %Package, new -> !ivy.id
ptr.store %45, %pkg : !ivy.id, ptr
; pkg[0] = 16.
%46 = ptr.load %pkg : ptr -> #ivy.id
%46 = ptr.load %pkg : ptr -> !ivy.id
%47 = arith.constant 0 : i32
%48 = arith.constant 16 : i32
ivy.msg.send to %46, at:%47 put:%48 -> void
; tuple = (32, 'a string')
%tuple = ptr.alloca #ivy.id -> ptr
%tuple = ptr.alloca !ivy.id -> ptr
%49 = arith.constant 32 : i32
%50 = ivy.str.constant "a string"
%51 = ivy.tuple.create %49, %50 : (i32, #ivy.id) -> #ivy.id
%51 = ivy.tuple.create %49, %50 : (i32, !ivy.id) -> !ivy.id
ptr.store %51, %tuple : #ivy.id, ptr
ptr.store %51, %tuple : !ivy.id, ptr
%52 = ptr.load %tuple : ptr -> #ivy.id
%53 = ivy.msg.send to %52, get-iterator -> #ivy.id
%52 = ptr.load %tuple : ptr -> !ivy.id
%53 = ivy.msg.send to %52, get-iterator -> !ivy.id
ivy.for %54 in %53 -> void {
%key = ivy.tuple.get-item %54[0] : (#ivy.id, i32) -> #ivy.id
%val = ivy.tuple.get-item %54[1] : (#ivy.id, i32) -> #ivy.id
%key = ivy.tuple.get-item %54[0] : (!ivy.id, i32) -> !ivy.id
%val = ivy.tuple.get-item %54[1] : (!ivy.id, i32) -> !ivy.id
; '{key} -> {val}'
%55 = ivy.string-builder.begin
ivy.string-builder.add %55 << %key : #ivy.id
ivy.string-builder.add %55 << %key : !ivy.id
ivy.string-builder.add %55 << " -> "
ivy.string-builder.add %55 << %val : #ivy.id
ivy.string-builder.add %55 << %val : !ivy.id
%57 = ivy.string-builder.end %55 -> #ivy.id
%57 = ivy.string-builder.end %55 -> !ivy.id
; cout put:'{key} -> {val}'
%58 = ptr.load %cout : ptr -> #ivy.id
%58 = ptr.load %cout : ptr -> !ivy.id
ivy.msg.send to %58, put:%57 -> void
}
@@ -387,20 +387,20 @@ ivy.module {
%multmp = arith.mul %59, %60 : (i32, i32) -> i32
; a = (32, 64).
%a = ptr.alloca #ivy.id -> ptr
%a = ptr.alloca !ivy.id -> ptr
%61 = arith.constant 32 : i32
%62 = arith.constant 64 : i32
%63 = ivy.tuple.create %61, %62 : (i32, i32) -> #ivy.id
%63 = ivy.tuple.create %61, %62 : (i32, i32) -> !ivy.id
ptr.store %63, %a : #ivy.id, ptr
ptr.store %63, %a : !ivy.id, ptr
%v = ptr.alloca #ivy.id -> ptr
%v = ptr.alloca !ivy.id -> ptr
%64 = ptr.load %a : ptr -> #ivy.id
%65 = ivy.tuple.get-item %64[1] : #ivy.id -> #ivy.id
%64 = ptr.load %a : ptr -> !ivy.id
%65 = ivy.tuple.get-item %64[1] : !ivy.id -> !ivy.id
ptr.store %65, %v : #ivy.id, ptr
ptr.store %65, %v : !ivy.id, ptr
%66 = ivy.atom "err:number-format"
@@ -413,47 +413,47 @@ ivy.module {
}
%67 = ivy.lambda : () -> void {
%v = ptr.alloca #ivy.id -> ptr
%v = ptr.alloca !ivy.id -> ptr
%Int = ivy.global-ref @Int -> ptr
%0 = ivy.str.constant "342"
%1 = ivy.msg.send to %Int, parse:%0
ptr.store %1, %v : #ivy.id, ptr
ptr.store %1, %v : !ivy.id, ptr
}
%68 = ivy.lambda %err, %data : (#ivy.id, #ivy.id) -> void {
%68 = ivy.lambda %err, %data : (!ivy.id, !ivy.id) -> void {
%0 = ivy.string-builder.begin
ivy.string-builder.add %0 << "Cannot parse integer string ("
ivy.string-builder.add %0 << %err : #ivy.id
ivy.string-builder.add %0 << %err : !ivy.id
ivy.string-builder.add %0 << ")"
%3 = ivy.string-builder.end %0 -> #ivy.id
%3 = ivy.string-builder.end %0 -> !ivy.id
; cout put:'{key} -> {val}'
%4 = ptr.load %cout : ptr -> #ivy.id
%4 = ptr.load %cout : ptr -> !ivy.id
ivy.msg.send to %4, put:%3 -> void
}
%69 = ivy.lambda %err, %data : (#ivy.id, #ivy.id) -> void {
%69 = ivy.lambda %err, %data : (!ivy.id, !ivy.id) -> void {
%0 = ivy.string-builder.create
ivy.string-builder.add %0 << "Error "
ivy.string-builder.add %0 << %err : #ivy.id
ivy.string-builder.add %0 << %err : !ivy.id
ivy.string-builder.add %0 << " occurred ("
ivy.string-builder.add %0 << %data : #ivy.id
ivy.string-builder.add %0 << %data : !ivy.id
ivy.string-builder.add %0 << ")"
%4 = ivy.string-builder.end %0 -> #ivy.id
%4 = ivy.string-builder.end %0 -> !ivy.id
; cout put:'{key} -> {val}'
%5 = ptr.load %cout : ptr -> #ivy.id
%5 = ptr.load %cout : ptr -> !ivy.id
ivy.msg.send to %5, put:%4 -> void
}
%70 = ivy.atom "err:number-format"
ivy.msg.send to %67, on:%70 do:%68 -> #ivy.id
ivy.msg.send to %67, on:%70 do:%68 -> !ivy.id
ivy.msg.send to %67, on-error:%69 -> void
ivy.msg.send to %67, call -> void
}

View File

@@ -1,6 +1,26 @@
%1, %reg.2, $X0 = ~scf.for(%a, %b) ({
^b0:
~arith.constant() : () -> ()
^b1:
~arith.constant() : () -> ()
}) {test_attrib = 2 : i32 } : (i8, i1) -> (i32, i32, i32)
~builtin.module() ({
~func.func() ({
^entry(%buffer: i32, %lb: index, %ub: index, %step: index):
; Initial sum set to 0.
%sum.0 = ~arith.constant() {value = 0.0 : f32} : () -> f32
; iter_args binds initial values to the loop's region arguments.
;%sum = "scf.for"(%lb, %ub, %step) -> (f32) {
~cf.br() [ ^for.entry:(%lb: index, %sum.0: f32) ] : () -> ()
^for.entry(%iv: index, %sum.iter: f32):
%t, %x, %z = ~memref.load(%buffer, %iv) : (i32, index) -> (f32, i1, i1)
%sum.next = ~arith.addf(%sum.iter, %t) : (f32, f32) -> f32
~cf.br() [ ^for.cond:(%iv: index, %sum.next: f32) ] : () -> ()
^for.cond(%iv2: index, %sum.next2: f32):
; Yield current iteration sum to next iteration %sum.iter or to %sum
; if final iteration.
%iv.next = ~arith.addi(%iv, %step) : (index, index) -> index
%stop = ~arith.cmpi(%iv.next, %ub) { predicate = 9 } : (index, index) -> i1
~cf.br-cond(%stop) [ ^for.end, ^for.entry:(%iv.next: index, %sum.next: f32) ] : (i1) -> ()
^for.end(%sum: f32):
~func.return(%sum) : (f32) -> ()
}) {sym_name = "reduce", function_type = (i32, index, index, index) -> f32 } : () -> ()
}) : () -> ()

View File

@@ -31,7 +31,8 @@ syn match mieBuiltinType /\<ptr\>/
syn match mieBuiltinType /\<index\>/
syn match mieBuiltinType "\<[if][0-9]\>"
syn match mieBuiltinType "\<[if][1-9][0-9]\+\>"
syn match mieDialectType /#[A-Za-z][A-Za-z0-9\-]*\(\.[A-Za-z][A-Za-z0-9\-]*\)\+/
syn match mieDialectType /![A-Za-z][A-Za-z0-9\-]*\(\.[A-Za-z][A-Za-z0-9\-]*\)\+/
syn match mieDialectAttribute /#[A-Za-z][A-Za-z0-9\-]*\(\.[A-Za-z][A-Za-z0-9\-]*\)\+/
syn match mieInstruction /\*[A-Za-z][A-Za-z0-9\-]*\(\.[A-Za-z][A-Za-z0-9\-]*\)\+\([>\*]\)\@!\>/
syn match mieGenericOperation /\~[A-Za-z][A-Za-z0-9\-]*\(\.[A-Za-z][A-Za-z0-9\-]*\)\+\([>\*]\)\@!\>/
@@ -77,6 +78,7 @@ hi def link mieBrackets Delimiter
hi def link mieAngleBrackets StorageClass
hi def link mieDialectType Type
hi def link mieDialectAttribute @attribute
hi def link mieGenericOperation @function.builtin
hi def link mieGraphOperation Statement

View File

@@ -0,0 +1,39 @@
#include <blue/ds/string.h>
#include <mie/attribute/attribute-definition.h>
#include <mie/dialect/dialect.h>
struct mie_attribute_definition *mie_attribute_definition_create(
struct mie_dialect *parent, const char *name)
{
struct mie_attribute_definition *out = malloc(sizeof *out);
if (!out) {
return NULL;
}
memset(out, 0x0, sizeof *out);
out->a_name = b_strdup(name);
if (!out->a_name) {
free(out);
return NULL;
}
out->a_parent = parent;
b_rope name_rope = B_ROPE_CSTR(name);
mie_id_map_put(&parent->d_attributes, &out->a_id, &name_rope);
return out;
}
bool mie_attribute_definition_check_name(
const struct mie_attribute_definition *def, const char *dialect_name,
const char *attrib_name)
{
if (!def || !def->a_parent) {
return false;
}
return (!strcmp(def->a_name, attrib_name)
&& !strcmp(def->a_parent->d_name, dialect_name));
}

View File

@@ -0,0 +1,264 @@
#include <blue/core/hash.h>
#include <blue/core/queue.h>
#include <blue/ds/string.h>
#include <mie/attribute/attribute-map.h>
enum attribute_map_entry_type {
ATTRMAP_ENTRY_NONE = 0,
ATTRMAP_ENTRY_BUCKET,
ATTRMAP_ENTRY_ITEM,
};
struct attribute_map_entry {
enum attribute_map_entry_type e_type;
uint64_t e_hash;
union {
b_btree_node e_node;
b_queue_entry e_entry;
};
};
struct attribute_map_bucket {
struct attribute_map_entry b_base;
b_queue b_items;
};
struct attribute_map_item {
struct attribute_map_entry i_base;
char *i_name;
const struct mie_attribute *i_value;
};
static B_BTREE_DEFINE_SIMPLE_INSERT(
struct attribute_map_entry, e_node, e_hash, put_entry);
static B_BTREE_DEFINE_SIMPLE_GET(
struct attribute_map_entry, uint64_t, e_node, e_hash, get_entry);
void mie_attribute_map_init(struct mie_attribute_map *map)
{
memset(map, 0x0, sizeof *map);
}
void mie_attribute_map_cleanup(struct mie_attribute_map *map)
{
/* TODO */
}
static const struct mie_attribute *get_attribute_from_item(
const struct attribute_map_item *item, const char *name)
{
if (!strcmp(item->i_name, name)) {
return item->i_value;
}
return NULL;
}
static const struct mie_attribute *get_attribute_from_bucket(
const struct attribute_map_bucket *bucket, const char *name)
{
b_queue_entry *cur = b_queue_first(&bucket->b_items);
while (cur) {
const struct attribute_map_item *item = b_unbox(
const struct attribute_map_item, cur, i_base.e_entry);
if (!strcmp(item->i_name, name)) {
return item->i_value;
}
cur = b_queue_next(cur);
}
return NULL;
}
static const struct mie_attribute *get_attribute_from_entry(
const struct attribute_map_entry *entry, const char *name)
{
switch (entry->e_type) {
case ATTRMAP_ENTRY_ITEM:
return get_attribute_from_item(
(const struct attribute_map_item *)entry, name);
case ATTRMAP_ENTRY_BUCKET:
return get_attribute_from_bucket(
(const struct attribute_map_bucket *)entry, name);
default:
return NULL;
}
}
const struct mie_attribute *mie_attribute_map_get(
const struct mie_attribute_map *map, const char *name)
{
uint64_t name_hash = b_hash_cstr(name);
struct attribute_map_entry *entry = get_entry(&map->m_entries, name_hash);
if (!entry) {
return NULL;
}
return get_attribute_from_entry(entry, name);
}
static struct attribute_map_bucket *convert_item_to_bucket(
struct mie_attribute_map *map, struct attribute_map_item *item)
{
struct attribute_map_bucket *bucket = malloc(sizeof *bucket);
if (!bucket) {
return NULL;
}
b_btree_delete(&map->m_entries, &item->i_base.e_node);
memset(bucket, 0x0, sizeof *bucket);
bucket->b_base.e_type = ATTRMAP_ENTRY_BUCKET;
bucket->b_base.e_hash = item->i_base.e_hash;
b_queue_push_back(&bucket->b_items, &item->i_base.e_entry);
put_entry(&map->m_entries, &bucket->b_base);
return bucket;
}
static struct attribute_map_item *create_item(
const char *name, uint64_t name_hash, const struct mie_attribute *attrib)
{
struct attribute_map_item *out = malloc(sizeof *out);
if (!out) {
return NULL;
}
memset(out, 0x0, sizeof *out);
out->i_value = attrib;
out->i_base.e_type = ATTRMAP_ENTRY_ITEM;
out->i_base.e_hash = name_hash;
out->i_name = b_strdup(name);
if (!out->i_name) {
free(out);
return NULL;
}
return out;
}
enum mie_status mie_attribute_map_put(
struct mie_attribute_map *map, const char *name,
const struct mie_attribute *value, enum mie_attribute_map_flags flags)
{
uint64_t name_hash = b_hash_cstr(name);
struct attribute_map_entry *entry = get_entry(&map->m_entries, name_hash);
struct attribute_map_item *item = NULL;
struct attribute_map_bucket *bucket = NULL;
enum mie_status status = MIE_SUCCESS;
if (!entry) {
item = create_item(name, name_hash, value);
if (!item) {
return MIE_ERR_NO_MEMORY;
}
put_entry(&map->m_entries, &item->i_base);
return MIE_SUCCESS;
}
if (entry->e_type == ATTRMAP_ENTRY_ITEM) {
item = (struct attribute_map_item *)entry;
if (!strcmp(item->i_name, name)) {
status = MIE_ERR_NAME_EXISTS;
if (flags & MIE_ATTRMAP_F_REPLACE) {
item->i_value = value;
status = MIE_SUCCESS;
}
return status;
}
bucket = convert_item_to_bucket(map, item);
} else {
bucket = (struct attribute_map_bucket *)entry;
}
item = create_item(name, name_hash, value);
if (!item) {
return MIE_ERR_NO_MEMORY;
}
b_queue_push_back(&bucket->b_items, &item->i_base.e_entry);
return MIE_SUCCESS;
}
enum mie_status mie_attribute_map_iterator_begin(
struct mie_attribute_map_iterator *it, const struct mie_attribute_map *map)
{
memset(it, 0x0, sizeof *it);
it->_n = b_btree_first(&map->m_entries);
if (!it->_n) {
return MIE_ERR_NO_DATA;
}
struct attribute_map_entry *entry
= b_unbox(struct attribute_map_entry, it->_n, e_node);
struct attribute_map_item *item = NULL;
struct attribute_map_bucket *bucket = NULL;
switch (entry->e_type) {
case ATTRMAP_ENTRY_ITEM:
item = (struct attribute_map_item *)entry;
it->it_name = item->i_name;
it->it_value = item->i_value;
return MIE_SUCCESS;
case ATTRMAP_ENTRY_BUCKET:
bucket = (struct attribute_map_bucket *)entry;
it->_e = b_queue_first(&bucket->b_items);
item = b_unbox(struct attribute_map_item, it->_e, i_base.e_entry);
it->it_name = item->i_name;
it->it_value = item->i_value;
return MIE_SUCCESS;
default:
return MIE_ERR_BAD_STATE;
}
}
enum mie_status mie_attribute_map_iterator_move_next(
struct mie_attribute_map_iterator *it)
{
struct attribute_map_entry *next_entry = NULL;
struct attribute_map_item *next_item = NULL;
struct attribute_map_bucket *next_bucket = NULL;
if (it->_e) {
it->_e = b_queue_next(it->_e);
next_entry = b_unbox(struct attribute_map_entry, it->_e, e_entry);
} else if (it->_n) {
it->_n = b_btree_next(it->_n);
next_entry = b_unbox(struct attribute_map_entry, it->_n, e_node);
} else {
memset(it, 0x0, sizeof *it);
return MIE_ERR_NO_DATA;
}
if (!next_entry) {
memset(it, 0x0, sizeof *it);
return MIE_ERR_NO_DATA;
}
switch (next_entry->e_type) {
case ATTRMAP_ENTRY_ITEM:
next_item = (struct attribute_map_item *)next_entry;
break;
case ATTRMAP_ENTRY_BUCKET:
next_bucket = (struct attribute_map_bucket *)next_item;
it->_e = b_queue_first(&next_bucket->b_items);
next_item = b_unbox(
struct attribute_map_item, it->_e, i_base.e_entry);
break;
default:
memset(it, 0x0, sizeof *it);
return MIE_ERR_BAD_STATE;
}
it->it_name = next_item->i_name;
it->it_value = next_item->i_value;
return MIE_SUCCESS;
}

14
mie/attribute/attribute.c Normal file
View File

@@ -0,0 +1,14 @@
#include <mie/attribute/attribute-definition.h>
#include <mie/attribute/attribute.h>
bool mie_attribute_check_name(
const struct mie_attribute *attrib, const char *dialect_name,
const char *attrib_name)
{
if (!attrib || !attrib->a_def) {
return false;
}
return mie_attribute_definition_check_name(
attrib->a_def, dialect_name, attrib_name);
}

248
mie/ctx.c
View File

@@ -2,12 +2,19 @@
#include <blue/ds/hashmap.h>
#include <blue/ds/list.h>
#include <blue/ds/string.h>
#include <mie/attribute/attribute-definition.h>
#include <mie/ctx.h>
#include <mie/diag/class.h>
#include <mie/diag/diag.h>
#include <mie/dialect/arith.h>
#include <mie/dialect/builtin.h>
#include <mie/dialect/dialect.h>
#include <mie/dialect/index.h>
#include <mie/interface/interface-definition.h>
#include <mie/ir/op-definition.h>
#include <mie/ir/op.h>
#include <mie/pass/pass-definition.h>
#include <mie/pass/pass.h>
#include <mie/trait/trait-definition.h>
#include <mie/trait/trait.h>
#include <mie/type/function.h>
@@ -25,6 +32,18 @@
MIE_ID(0xf5, 0x4e, 0xc5, 0x8c, 0xc0, 0x1e, 0x48, 0x47, 0xb5, 0xf4, \
0x7b, 0xb9, 0x6b, 0x47, 0xca, 0x48)
#define TRAIT_NS_ID \
MIE_ID(0xeb, 0x02, 0xcc, 0xe5, 0x32, 0x80, 0x4e, 0xc3, 0x84, 0xf3, \
0xc0, 0x07, 0x72, 0xf0, 0x4c, 0xca)
#define ATTRIBUTE_NS_ID \
MIE_ID(0xc6, 0x94, 0x38, 0x34, 0xdb, 0x08, 0x45, 0xc7, 0xb9, 0x89, \
0x69, 0x82, 0x7a, 0x9d, 0x42, 0xd8)
#define PASS_NS_ID \
MIE_ID(0x76, 0xfc, 0xdd, 0xb5, 0xc0, 0x20, 0x47, 0x13, 0x8d, 0xfa, \
0x3f, 0x28, 0x2f, 0x81, 0x6d, 0x7d)
struct mie_ctx *mie_ctx_create(void)
{
struct mie_ctx *out = malloc(sizeof *out);
@@ -41,20 +60,41 @@ struct mie_ctx *mie_ctx_create(void)
mie_id types_ns = TYPE_NS_ID;
mie_id_map_init(&out->ctx_types, &types_ns);
out->ctx_ints = mie_int_cache_create();
out->ctx_floats = mie_float_cache_create();
out->ctx_indices = mie_index_cache_create();
out->ctx_strings = mie_string_cache_create();
mie_id traits_ns = TRAIT_NS_ID;
mie_id_map_init(&out->ctx_traits, &traits_ns);
mie_id attributes_ns = ATTRIBUTE_NS_ID;
mie_id_map_init(&out->ctx_attributes, &attributes_ns);
mie_id pass_ns = PASS_NS_ID;
mie_id_map_init(&out->ctx_passes, &pass_ns);
return out;
}
struct mie_op *mie_ctx_create_op(
const struct mie_ctx *ctx, const char *dialect, const char *op)
{
const struct mie_op_definition *def
= mie_ctx_get_op_definition(ctx, dialect, op);
if (!def) {
return NULL;
}
struct mie_op *out = mie_op_create();
if (!out) {
return NULL;
}
out->op_flags |= MIE_OP_F_OP_RESOLVED;
out->op_info = def;
return out;
}
bool mie_ctx_resolve_op(const struct mie_ctx *ctx, struct mie_op *op)
{
bool fully_resolved = MIE_TEST_FLAGS(
op->op_flags, MIE_OP_F_OP_RESOLVED | MIE_OP_F_ARG_RESOLVED);
if (fully_resolved) {
if (op->op_flags & MIE_OP_F_OP_RESOLVED) {
return true;
}
@@ -84,11 +124,10 @@ bool mie_ctx_resolve_op(const struct mie_ctx *ctx, struct mie_op *op)
const struct mie_op_definition *op_info
= mie_dialect_get_op(dialect, op_name);
if (!op) {
if (!op_info) {
return false;
}
op->op_dialect = dialect;
op->op_info = op_info;
free(op->op_name);
@@ -109,6 +148,27 @@ struct mie_dialect *mie_ctx_get_dialect(const struct mie_ctx *ctx, const char *n
return b_unbox(struct mie_dialect, target, d_id);
}
const struct mie_op_definition *mie_ctx_get_op_definition(
const struct mie_ctx *ctx, const char *dialect_name, const char *op_name)
{
b_rope dialect_name_rope = B_ROPE_CSTR(dialect_name);
mie_id id;
mie_id_init_ns(
&id, mie_id_map_get_ns(&ctx->ctx_dialects), &dialect_name_rope);
mie_id *target = mie_id_map_get(&ctx->ctx_dialects, &id);
struct mie_dialect *dialect = b_unbox(struct mie_dialect, target, d_id);
if (!dialect) {
return NULL;
}
b_rope op_name_rope = B_ROPE_CSTR(op_name);
mie_id_init_ns(&id, mie_id_map_get_ns(&dialect->d_ops), &op_name_rope);
target = mie_id_map_get(&dialect->d_ops, &id);
return b_unbox(struct mie_op_definition, target, op_id);
}
struct mie_type_definition *mie_ctx_get_type_definition(
const struct mie_ctx *ctx, const char *dialect_name, const char *type_name)
{
@@ -151,6 +211,54 @@ const struct mie_trait_definition *mie_ctx_get_trait_definition(
return b_unbox(struct mie_trait_definition, target, tr_id);
}
const struct mie_attribute_definition *mie_ctx_get_attribute_definition(
const struct mie_ctx *ctx, const char *dialect_name,
const char *attribute_name)
{
b_rope dialect_name_rope = B_ROPE_CSTR(dialect_name);
mie_id id;
mie_id_init_ns(
&id, mie_id_map_get_ns(&ctx->ctx_dialects), &dialect_name_rope);
mie_id *target = mie_id_map_get(&ctx->ctx_dialects, &id);
struct mie_dialect *dialect = b_unbox(struct mie_dialect, target, d_id);
if (!dialect) {
return NULL;
}
b_rope attribute_name_rope = B_ROPE_CSTR(attribute_name);
mie_id_init_ns(
&id, mie_id_map_get_ns(&dialect->d_attributes),
&attribute_name_rope);
target = mie_id_map_get(&dialect->d_attributes, &id);
return b_unbox(struct mie_attribute_definition, target, a_id);
}
const struct mie_interface_definition *mie_ctx_get_interface_definition(
const struct mie_ctx *ctx, const char *dialect_name,
const char *interface_name)
{
b_rope dialect_name_rope = B_ROPE_CSTR(dialect_name);
mie_id id;
mie_id_init_ns(
&id, mie_id_map_get_ns(&ctx->ctx_dialects), &dialect_name_rope);
mie_id *target = mie_id_map_get(&ctx->ctx_dialects, &id);
struct mie_dialect *dialect = b_unbox(struct mie_dialect, target, d_id);
if (!dialect) {
return NULL;
}
b_rope interface_name_rope = B_ROPE_CSTR(interface_name);
mie_id_init_ns(
&id, mie_id_map_get_ns(&dialect->d_interfaces),
&interface_name_rope);
target = mie_id_map_get(&dialect->d_interfaces, &id);
return b_unbox(struct mie_interface_definition, target, if_id);
}
struct mie_type *mie_ctx_get_type(
struct mie_ctx *ctx, const char *dialect_name, const char *type_name)
{
@@ -187,7 +295,7 @@ struct mie_type *mie_ctx_get_type(
memset(type, 0x0, sizeof *type);
type->ty_def = type_info;
type->ty_name = b_bstr_fmt("%s.%s", dialect_name, type_name);
type->ty_name = b_bstr_fmt(NULL, "%s.%s", dialect_name, type_name);
if (type_info->ty_init) {
type_info->ty_init(type_info, type);
@@ -234,7 +342,7 @@ const struct mie_trait *mie_ctx_get_trait(
memset(trait, 0x0, sizeof trait_info->tr_data_size);
trait->tr_def = trait_info;
trait->tr_name = b_bstr_fmt("%s.%s", dialect_name, trait_name);
trait->tr_name = b_bstr_fmt(NULL, "%s.%s", dialect_name, trait_name);
if (trait_info->tr_init) {
trait_info->tr_init(trait_info, trait);
@@ -300,24 +408,120 @@ struct mie_type *mie_ctx_get_function_type(
return (struct mie_type *)new_type;
}
struct mie_value *mie_ctx_get_int(struct mie_ctx *ctx, long long val, size_t nr_bits)
enum mie_status mie_ctx_register_pass(
struct mie_ctx *ctx, struct mie_pass_definition *pass)
{
return (struct mie_value *)mie_int_cache_get(
ctx->ctx_ints, ctx, val, nr_bits);
if (pass->p_data_size < sizeof(struct mie_pass)) {
return MIE_ERR_INVALID_ARGUMENT;
}
switch (pass->p_type) {
case MIE_PASS_ANALYSE:
case MIE_PASS_TRANSFORM:
break;
default:
return MIE_ERR_INVALID_ARGUMENT;
}
mie_id id;
struct mie_id_builder id_builder;
mie_id_builder_begin(&id_builder, mie_id_map_get_ns(&ctx->ctx_passes));
mie_id_builder_add_cstr(&id_builder, pass->p_name);
mie_id_builder_end(&id_builder, &id);
mie_id *target = mie_id_map_get(&ctx->ctx_passes, &id);
if (target) {
return MIE_ERR_NAME_EXISTS;
}
pass->p_id = id;
mie_id_map_put_id(&ctx->ctx_passes, &pass->p_id);
return MIE_SUCCESS;
}
struct mie_value *mie_ctx_get_float(struct mie_ctx *ctx, double val, size_t nr_bits)
enum mie_status mie_ctx_get_pass(
struct mie_ctx *ctx, const char *name,
const struct mie_attribute_map *args, struct mie_pass **out)
{
return (struct mie_value *)mie_float_cache_get(
ctx->ctx_floats, ctx, val, nr_bits);
mie_id id;
struct mie_id_builder id_builder;
mie_id_builder_begin(&id_builder, mie_id_map_get_ns(&ctx->ctx_passes));
mie_id_builder_add_cstr(&id_builder, name);
mie_id_builder_end(&id_builder, &id);
mie_id *target = mie_id_map_get(&ctx->ctx_passes, &id);
if (!target) {
return MIE_ERR_NO_ENTRY;
}
struct mie_pass_definition *pass_def
= b_unbox(struct mie_pass_definition, target, p_id);
if (pass_def->p_data_size < sizeof(struct mie_pass)) {
return MIE_ERR_BAD_STATE;
}
struct mie_pass *pass = malloc(pass_def->p_data_size);
if (!pass) {
return MIE_ERR_NO_MEMORY;
}
memset(pass, 0x0, pass_def->p_data_size);
pass->p_def = pass_def;
enum mie_status status = MIE_SUCCESS;
if (pass_def->p_init) {
status = pass_def->p_init(pass, args);
}
if (status != MIE_SUCCESS) {
free(pass);
pass = NULL;
}
*out = pass;
return status;
}
struct mie_value *mie_ctx_get_string(struct mie_ctx *ctx, const char *s)
struct mie_diag *mie_ctx_push_diag(
struct mie_ctx *ctx, struct mie_line_source *src,
const struct mie_file_cell *loc, const char *dialect_name,
unsigned long diag_class)
{
return (struct mie_value *)mie_string_cache_get(ctx->ctx_strings, ctx, s);
struct mie_diag *diag = malloc(sizeof *diag);
if (!diag) {
return NULL;
}
struct mie_dialect *dialect = mie_ctx_get_dialect(ctx, dialect_name);
if (!dialect) {
return NULL;
}
if (diag_class >= dialect->d_nr_diag_classes) {
return NULL;
}
memset(diag, 0x0, sizeof *diag);
diag->diag_src = src;
diag->diag_loc = *loc;
diag->diag_parent = dialect;
diag->diag_class = &dialect->d_diag_classes[diag_class];
b_queue_push_back(&ctx->ctx_diag, &diag->diag_entry);
return diag;
}
struct mie_value *mie_ctx_get_index(struct mie_ctx *ctx, size_t val)
struct mie_diag *mie_ctx_pop_diag(struct mie_ctx *ctx)
{
return (struct mie_value *)mie_index_cache_get(ctx->ctx_indices, ctx, val);
b_queue_entry *entry = b_queue_pop_front(&ctx->ctx_diag);
if (!entry) {
return NULL;
}
return b_unbox(struct mie_diag, entry, diag_entry);
}

106
mie/diag/diag.c Normal file
View File

@@ -0,0 +1,106 @@
#include <blue/ds/string.h>
#include <mie/ctx.h>
#include <mie/diag/amendment.h>
#include <mie/diag/component.h>
#include <mie/diag/diag.h>
#include <mie/diag/highlight.h>
#include <mie/diag/msg.h>
#include <mie/dialect/dialect.h>
#include <stdlib.h>
#include <string.h>
struct mie_diag_c_msg *diag_msg_create(const struct mie_diag_msg *content)
{
struct mie_diag_c_msg *out = malloc(sizeof *out);
if (!out) {
return NULL;
}
memset(out, 0x0, sizeof *out);
out->msg_base.c_type = MIE_DIAG_COMPONENT_MSG;
out->msg_content = b_strdup(content->msg_content);
return out;
}
struct mie_diag_c_snippet *diag_snippet_create(
unsigned long first_line, unsigned long last_line,
const struct mie_diag_amendment *amendments, size_t nr_amendments,
const struct mie_diag_highlight *highlights, size_t nr_highlights)
{
struct mie_diag_c_snippet *out = malloc(sizeof *out);
if (!out) {
return NULL;
}
memset(out, 0x0, sizeof *out);
out->s_base.c_type = MIE_DIAG_COMPONENT_SNIPPET;
out->s_first_line = first_line;
out->s_last_line = last_line;
out->s_nr_amendments = nr_amendments;
out->s_amendments = calloc(nr_amendments, sizeof *amendments);
if (!out->s_amendments) {
free(out);
return NULL;
}
memcpy(out->s_amendments, amendments, nr_amendments * sizeof *amendments);
out->s_nr_highlights = nr_highlights;
out->s_highlights = calloc(nr_highlights, sizeof *highlights);
if (!out->s_highlights) {
free(out->s_amendments);
free(out);
return NULL;
}
memcpy(out->s_highlights, highlights, nr_highlights * sizeof *highlights);
return out;
}
void mie_diag_set_location(
struct mie_diag *diag, unsigned long row, unsigned long col)
{
diag->diag_loc.c_row = row;
diag->diag_loc.c_row = col;
}
void mie_diag_push_msg(
struct mie_diag *diag, struct mie_ctx *ctx, const char *dialect_name,
unsigned long msg, ...)
{
struct mie_dialect *dialect = mie_ctx_get_dialect(ctx, dialect_name);
if (!dialect) {
return;
}
if (msg >= dialect->d_nr_diag_msgs) {
return;
}
const struct mie_diag_msg *msg_info = &dialect->d_diag_msgs[msg];
struct mie_diag_c_msg *c_msg = diag_msg_create(msg_info);
if (!c_msg) {
return;
}
b_queue_push_back(&diag->diag_components, &c_msg->msg_base.c_entry);
}
void mie_diag_push_snippet(
struct mie_diag *diag, unsigned long first_line, unsigned long last_line,
const struct mie_diag_amendment *amendments, size_t nr_amendments,
const struct mie_diag_highlight *highlights, size_t nr_highlights)
{
struct mie_diag_c_snippet *c_snippet = diag_snippet_create(
first_line, last_line, amendments, nr_amendments, highlights,
nr_highlights);
if (!c_snippet) {
return;
}
b_queue_push_back(&diag->diag_components, &c_snippet->s_base.c_entry);
}

6
mie/diag/diag.h Normal file
View File

@@ -0,0 +1,6 @@
#ifndef _DIAG_DIAG_H_
#define _DIAG_DIAG_H_
#include <blue/core/queue.h>
#endif

View File

@@ -1,18 +0,0 @@
#include <mie/dialect/dialect.h>
#include <mie/ir/op-definition.h>
#include <mie/macros.h>
static enum mie_status print(const struct mie_op *op, b_stream *out)
{
return MIE_SUCCESS;
}
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
{
return MIE_SUCCESS;
}
MIE_OP_DEFINITION_BEGIN(mie_arith_addf, "addf")
MIE_OP_DEFINITION_PRINT(print);
MIE_OP_DEFINITION_PARSE(parse);
MIE_OP_DEFINITION_END()

View File

@@ -1,9 +1,11 @@
#include <mie/ctx.h>
#include <mie/dialect/arith.h>
#include <mie/dialect/dialect.h>
#include <mie/macros.h>
MIE_DIALECT_BEGIN(mie_arith, "arith")
MIE_DIALECT_ADD_TYPE(mie_arith_int);
MIE_DIALECT_ADD_TYPE(mie_arith_float);
MIE_DIALECT_BEGIN(mie_arith, struct mie_dialect, "arith")
MIE_DIALECT_ADD_OP(mie_arith_addi);
MIE_DIALECT_ADD_OP(mie_arith_cmpi);
MIE_DIALECT_ADD_OP(mie_arith_addf);
MIE_DIALECT_ADD_OP(mie_arith_constant);
MIE_DIALECT_END()

View File

@@ -1,5 +1,6 @@
#include <blue/core/btree.h>
#include <mie/dialect/arith.h>
#include <mie/ctx.h>
#include <mie/dialect/builtin.h>
#include <stdlib.h>
#include <string.h>
@@ -145,8 +146,10 @@ static struct float_width_cache_entry *float_width_cache_entry_create(
return NULL;
}
out->e_value.f_base.v_type = mie_arith_float_get_type(ctx, width);
if (!out->e_value.f_base.v_type) {
out->e_value.f_base.a_def
= mie_ctx_get_attribute_definition(ctx, "builtin", "float");
out->e_value.f_type = mie_ctx_get_float_type(ctx, width);
if (!out->e_value.f_type) {
free(out);
return NULL;
}

View File

@@ -1,5 +1,6 @@
#include <blue/core/btree.h>
#include <mie/dialect/arith.h>
#include <mie/ctx.h>
#include <mie/dialect/builtin.h>
#include <stdlib.h>
#include <string.h>
@@ -70,9 +71,11 @@ static struct int_width_cache_entry *int_width_cache_entry_create(
memset(out, 0x0, sizeof *out);
out->e_value.i_base.a_def
= mie_ctx_get_attribute_definition(ctx, "builtin", "int");
out->e_value.i_val.v_small = value;
out->e_value.i_base.v_type = mie_arith_int_get_type(ctx, width);
if (!out->e_value.i_base.v_type) {
out->e_value.i_type = mie_ctx_get_int_type(ctx, width);
if (!out->e_value.i_type) {
free(out);
return NULL;
}

View File

@@ -0,0 +1,34 @@
#include <mie/dialect/dialect.h>
#include <mie/ir/op-definition.h>
#include <mie/ir/op.h>
#include <mie/macros.h>
#include <mie/print/printer.h>
static enum mie_status print(struct mie_printer *printer, const struct mie_op *op)
{
if (MIE_VECTOR_COUNT(op->op_args) != 2) {
return MIE_SUCCESS;
}
const struct mie_op_arg *left = &op->op_args.items[0];
const struct mie_op_arg *right = &op->op_args.items[1];
b_stream_write_char(printer->p_stream, ' ');
mie_printer_print_op_arg(printer, left, false);
b_stream_write_string(printer->p_stream, ", ", NULL);
mie_printer_print_op_arg(printer, right, false);
b_stream_write_string(printer->p_stream, " : ", NULL);
mie_printer_print_type(printer, mie_op_arg_get_type(left));
return MIE_SUCCESS;
}
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
{
return MIE_SUCCESS;
}
MIE_OP_DEFINITION_BEGIN(mie_arith_addf, "addf")
MIE_OP_DEFINITION_PRINT(print);
MIE_OP_DEFINITION_PARSE(parse);
MIE_OP_DEFINITION_END()

View File

@@ -0,0 +1,54 @@
#include <mie/ctx.h>
#include <mie/dialect/builtin.h>
#include <mie/dialect/dialect.h>
#include <mie/ir/emit.h>
#include <mie/ir/op-definition.h>
#include <mie/ir/op.h>
#include <mie/macros.h>
#include <mie/print/printer.h>
#include <mie/type/type.h>
static enum mie_status print(struct mie_printer *printer, const struct mie_op *op)
{
if (MIE_VECTOR_COUNT(op->op_args) != 2) {
return MIE_SUCCESS;
}
const struct mie_op_arg *left = &op->op_args.items[0];
const struct mie_op_arg *right = &op->op_args.items[1];
b_stream_write_char(printer->p_stream, ' ');
mie_printer_print_op_arg(printer, left, false);
b_stream_write_string(printer->p_stream, ", ", NULL);
mie_printer_print_op_arg(printer, right, false);
b_stream_write_string(printer->p_stream, " : ", NULL);
mie_printer_print_type(printer, mie_op_arg_get_type(left));
return MIE_SUCCESS;
}
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
{
return MIE_SUCCESS;
}
struct mie_register *mie_arith_addi_put(
struct mie_emitter *e, struct mie_register *left,
struct mie_register *right, const char *name)
{
struct mie_register *args[] = {left, right};
const size_t nr_args = sizeof args / sizeof args[0];
struct mie_op *op = mie_emitter_put_op(e, "arith", "addi", args, nr_args);
const struct mie_type *ty = left->reg_type;
struct mie_register *result = mie_op_add_result(op, ty);
mie_emitter_put_name(e, &result->reg_name, name);
return result;
}
MIE_OP_DEFINITION_BEGIN(mie_arith_addi, "addi")
MIE_OP_DEFINITION_PRINT(print);
MIE_OP_DEFINITION_PARSE(parse);
MIE_OP_DEFINITION_END()

View File

@@ -0,0 +1,80 @@
#include <mie/dialect/builtin.h>
#include <mie/dialect/dialect.h>
#include <mie/ir/op-definition.h>
#include <mie/ir/op.h>
#include <mie/macros.h>
#include <mie/print/printer.h>
static enum mie_status print(struct mie_printer *printer, const struct mie_op *op)
{
if (MIE_VECTOR_COUNT(op->op_args) != 2
|| MIE_VECTOR_COUNT(op->op_result) != 1) {
return MIE_SUCCESS;
}
const struct mie_op_arg *left = &op->op_args.items[0];
const struct mie_op_arg *right = &op->op_args.items[1];
const struct mie_register *result = &op->op_result.items[0];
const struct mie_attribute *pred_attr
= mie_attribute_map_get(&op->op_attrib, "predicate");
long long pred;
if (!mie_int_get_value(pred_attr, &pred)) {
return MIE_SUCCESS;
}
b_stream_write_char(printer->p_stream, ' ');
switch (pred) {
case 0:
b_stream_write_string(printer->p_stream, "eq", NULL);
break;
case 1:
b_stream_write_string(printer->p_stream, "ne", NULL);
break;
case 2:
b_stream_write_string(printer->p_stream, "slt", NULL);
break;
case 3:
b_stream_write_string(printer->p_stream, "sle", NULL);
break;
case 4:
b_stream_write_string(printer->p_stream, "sgt", NULL);
break;
case 5:
b_stream_write_string(printer->p_stream, "sge", NULL);
break;
case 6:
b_stream_write_string(printer->p_stream, "ult", NULL);
break;
case 7:
b_stream_write_string(printer->p_stream, "ule", NULL);
break;
case 8:
b_stream_write_string(printer->p_stream, "ugt", NULL);
break;
case 9:
b_stream_write_string(printer->p_stream, "uge", NULL);
break;
default:
return MIE_SUCCESS;
}
b_stream_write_char(printer->p_stream, ' ');
mie_printer_print_op_arg(printer, left, false);
b_stream_write_string(printer->p_stream, ", ", NULL);
mie_printer_print_op_arg(printer, right, false);
b_stream_write_string(printer->p_stream, " : ", NULL);
mie_printer_print_type(printer, mie_op_arg_get_type(left));
return MIE_SUCCESS;
}
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
{
return MIE_SUCCESS;
}
MIE_OP_DEFINITION_BEGIN(mie_arith_cmpi, "cmpi")
MIE_OP_DEFINITION_PRINT(print);
MIE_OP_DEFINITION_PARSE(parse);
MIE_OP_DEFINITION_END()

View File

@@ -0,0 +1,81 @@
#include <mie/attribute/attribute.h>
#include <mie/dialect/builtin.h>
#include <mie/dialect/dialect.h>
#include <mie/ir/emit.h>
#include <mie/ir/op-definition.h>
#include <mie/ir/op.h>
#include <mie/macros.h>
#include <mie/print/printer.h>
static enum mie_status print(struct mie_printer *printer, const struct mie_op *op)
{
const struct mie_attribute *value
= mie_attribute_map_get(&op->op_attrib, "value");
if (!value) {
return MIE_SUCCESS;
}
const struct mie_type *type = NULL;
if (mie_attribute_check_name(value, "builtin", "int")) {
const struct mie_int *i = (const struct mie_int *)value;
b_stream_write_fmt(
printer->p_stream, NULL, " %lld : ", i->i_val.v_small);
type = i->i_type;
} else if (mie_attribute_check_name(value, "builtin", "float")) {
const struct mie_float *f = (const struct mie_float *)value;
double d;
mie_float_get_value(value, &d);
b_stream_write_fmt(printer->p_stream, NULL, " %g : ", d);
type = f->f_type;
} else {
return MIE_SUCCESS;
}
mie_printer_print_type(printer, type);
return MIE_SUCCESS;
}
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
{
return MIE_SUCCESS;
}
struct mie_register *mie_arith_constant_i_put(
struct mie_emitter *e, long long value, const char *name)
{
struct mie_op *op = mie_emitter_put_op(e, "arith", "constant", NULL, 0);
const struct mie_type *ty
= mie_ctx_get_int_type(mie_emitter_get_ctx(e), 32);
struct mie_register *result = mie_op_add_result(op, ty);
mie_emitter_put_name(e, &result->reg_name, name);
struct mie_attribute *val
= mie_ctx_get_int(mie_emitter_get_ctx(e), value, 32);
mie_attribute_map_put(&op->op_attrib, "value", val, MIE_ATTRMAP_F_REPLACE);
return result;
}
struct mie_register *mie_arith_constant_f_put(
struct mie_emitter *e, long long value, const char *name)
{
struct mie_op *op = mie_emitter_put_op(e, "arith", "constant", NULL, 0);
const struct mie_type *ty
= mie_ctx_get_int_type(mie_emitter_get_ctx(e), 32);
struct mie_register *result = mie_op_add_result(op, ty);
mie_emitter_put_name(e, &result->reg_name, name);
struct mie_attribute *val
= mie_ctx_get_float(mie_emitter_get_ctx(e), value, 32);
mie_attribute_map_put(&op->op_attrib, "value", val, MIE_ATTRMAP_F_REPLACE);
return result;
}
MIE_OP_DEFINITION_BEGIN(mie_arith_constant, "constant")
MIE_OP_DEFINITION_PRINT(print);
MIE_OP_DEFINITION_PARSE(parse);
MIE_OP_DEFINITION_END()

View File

@@ -0,0 +1,103 @@
#include <mie/attribute/attribute-definition.h>
#include <mie/attribute/attribute.h>
#include <mie/ctx.h>
#include <mie/dialect/builtin.h>
#include <mie/dialect/dialect.h>
#include <mie/macros.h>
#include <mie/parse/parser.h>
#include <mie/print/printer.h>
static enum mie_status print(
const struct mie_attribute *value, struct mie_printer *out)
{
const struct mie_array *array = (const struct mie_array *)value;
if (!(out->p_flags & MIE_PRINT_F_ABBREVIATED)) {
b_stream_write_string(out->p_stream, "#builtin.array<", NULL);
}
b_stream_write_char(out->p_stream, '[');
for (size_t i = 0; i < MIE_VECTOR_COUNT(array->a_items); i++) {
if (i > 0) {
b_stream_write_char(out->p_stream, ',');
}
b_stream_write_char(out->p_stream, ' ');
mie_printer_print_attribute(out, array->a_items.items[i]);
}
if (MIE_VECTOR_COUNT(array->a_items) != 0) {
b_stream_write_char(out->p_stream, ' ');
}
b_stream_write_char(out->p_stream, ']');
if (!(out->p_flags & MIE_PRINT_F_ABBREVIATED)) {
b_stream_write_char(out->p_stream, '>');
}
return MIE_SUCCESS;
}
static struct mie_array *array_create(struct mie_ctx *ctx)
{
struct mie_array *array = malloc(sizeof *array);
if (!array) {
return NULL;
}
memset(array, 0x0, sizeof *array);
array->a_base.a_def
= mie_ctx_get_attribute_definition(ctx, "builtin", "array");
return array;
}
static enum mie_status parse(
struct mie_parser *ctx, const struct mie_attribute **out)
{
if (!mie_parser_parse_symbol(ctx, MIE_SYM_LEFT_BRACKET)) {
return MIE_ERR_BAD_SYNTAX;
}
struct mie_array *array = array_create(mie_parser_get_mie_ctx(ctx));
if (!array) {
return MIE_ERR_NO_MEMORY;
}
const struct mie_attribute *item = NULL;
if (!mie_parser_parse_attribute(ctx, &item)) {
free(array);
return MIE_ERR_BAD_FORMAT;
}
mie_vector_push_back(array->a_items, &item, NULL);
while (1) {
if (mie_parser_parse_symbol(ctx, MIE_SYM_RIGHT_BRACKET)) {
break;
}
if (!mie_parser_parse_symbol(ctx, MIE_SYM_COMMA)) {
return false;
}
if (!mie_parser_parse_attribute(ctx, &item)) {
free(array);
return MIE_ERR_BAD_FORMAT;
}
mie_vector_push_back(array->a_items, &item, NULL);
}
*out = (struct mie_attribute *)array;
return MIE_SUCCESS;
}
MIE_ATTRIBUTE_DEFINITION_BEGIN(mie_builtin_array, "array")
MIE_ATTRIBUTE_DEFINITION_STRUCT(struct mie_array);
MIE_ATTRIBUTE_DEFINITION_PRINT(print);
MIE_ATTRIBUTE_DEFINITION_PARSE(parse);
MIE_ATTRIBUTE_DEFINITION_END()

View File

@@ -0,0 +1,107 @@
#include "../float.h"
#include <blue/core/bstr.h>
#include <mie/attribute/attribute-definition.h>
#include <mie/attribute/attribute.h>
#include <mie/ctx.h>
#include <mie/dialect/builtin.h>
#include <mie/dialect/dialect.h>
#include <mie/macros.h>
#include <mie/parse/parser.h>
#include <mie/print/printer.h>
static enum mie_status print(
const struct mie_attribute *value, struct mie_printer *out)
{
const struct mie_float *float_val = (const struct mie_float *)value;
const struct float_type *float_ty
= (const struct float_type *)float_val->f_type;
if (!(out->p_flags & MIE_PRINT_F_ABBREVIATED)) {
b_stream_write_string(out->p_stream, "#builtin.float<", NULL);
}
switch (float_ty->f_width) {
case MIE_FLOAT_32:
b_stream_write_fmt(
out->p_stream, NULL, "%f : f%zu", float_val->f_val.v_32,
float_ty->f_width);
break;
case MIE_FLOAT_64:
b_stream_write_fmt(
out->p_stream, NULL, "%lf : f%zu",
float_val->f_val.v_64, float_ty->f_width);
break;
default:
b_stream_write_fmt(
out->p_stream, NULL, "NaN : f%zu", float_ty->f_width);
break;
}
if (!(out->p_flags & MIE_PRINT_F_ABBREVIATED)) {
b_stream_write_string(out->p_stream, ">", NULL);
}
return MIE_SUCCESS;
}
static enum mie_status parse(
struct mie_parser *ctx, const struct mie_attribute **out)
{
double value = 0;
struct mie_file_span span;
if (!mie_parser_parse_float(ctx, &value, &span)) {
return MIE_ERR_BAD_SYNTAX;
}
if (!mie_parser_parse_symbol(ctx, MIE_SYM_COLON)) {
return MIE_ERR_BAD_SYNTAX;
}
const struct mie_type *type = NULL;
if (!mie_parser_parse_type(ctx, &type)) {
return MIE_ERR_BAD_SYNTAX;
}
size_t width = mie_float_type_get_width(type);
if (width == (size_t)-1) {
return MIE_ERR_BAD_SYNTAX;
}
struct mie_attribute *v
= mie_ctx_get_float(mie_parser_get_mie_ctx(ctx), value, width);
if (!v) {
return MIE_ERR_NO_MEMORY;
}
*out = v;
return MIE_SUCCESS;
}
bool mie_float_get_value(const struct mie_attribute *attrib, double *out)
{
if (!mie_attribute_check_name(attrib, "builtin", "float")) {
return false;
}
const struct mie_float *v = (const struct mie_float *)attrib;
switch (mie_float_type_get_width(v->f_type)) {
case MIE_FLOAT_32:
*out = v->f_val.v_32;
break;
case MIE_FLOAT_64:
*out = v->f_val.v_64;
break;
default:
return false;
}
return true;
}
MIE_ATTRIBUTE_DEFINITION_BEGIN(mie_builtin_float, "float")
MIE_ATTRIBUTE_DEFINITION_STRUCT(struct mie_float);
MIE_ATTRIBUTE_DEFINITION_PRINT(print);
MIE_ATTRIBUTE_DEFINITION_PARSE(parse);
MIE_ATTRIBUTE_DEFINITION_END()

View File

@@ -0,0 +1,103 @@
#include "../int.h"
#include <blue/core/bstr.h>
#include <mie/attribute/attribute-definition.h>
#include <mie/attribute/attribute.h>
#include <mie/ctx.h>
#include <mie/dialect/builtin.h>
#include <mie/dialect/dialect.h>
#include <mie/macros.h>
#include <mie/parse/parser.h>
#include <mie/print/printer.h>
static enum mie_status print(
const struct mie_attribute *value, struct mie_printer *out)
{
const struct mie_int *int_val = (const struct mie_int *)value;
const struct int_type *int_ty = (const struct int_type *)int_val->i_type;
bool abbrev = ((out->p_flags & MIE_PRINT_F_ABBREVIATED) != 0);
if (!abbrev) {
b_stream_write_string(out->p_stream, "#builtin.int<", NULL);
}
if (int_ty->i_width <= 64) {
b_stream_write_fmt(
out->p_stream, NULL, "%zu", int_val->i_val.v_small,
int_ty->i_width);
} else {
b_stream_write_fmt(out->p_stream, NULL, "INF", int_ty->i_width);
}
if (int_ty->i_width != 64 || !abbrev) {
b_stream_write_string(out->p_stream, " : ", NULL);
if (abbrev) {
b_stream_write_fmt(
out->p_stream, NULL, "i%zu", int_ty->i_width);
} else {
b_stream_write_fmt(
out->p_stream, NULL, "!builtin.int<%zu>",
int_ty->i_width);
}
}
if (!abbrev) {
b_stream_write_string(out->p_stream, ">", NULL);
}
return MIE_SUCCESS;
}
static enum mie_status parse(
struct mie_parser *ctx, const struct mie_attribute **out)
{
long long value = 0;
struct mie_file_span span;
if (!mie_parser_parse_int(ctx, &value, &span)) {
return MIE_ERR_BAD_SYNTAX;
}
const struct mie_type *type = NULL;
size_t width = (size_t)-1;
if (!mie_parser_parse_symbol(ctx, MIE_SYM_COLON)) {
width = 64;
} else if (!mie_parser_parse_type(ctx, &type)) {
return false;
} else {
width = mie_int_type_get_width(type);
}
if (width == (size_t)-1) {
return MIE_ERR_BAD_SYNTAX;
}
struct mie_attribute *v
= mie_ctx_get_int(mie_parser_get_mie_ctx(ctx), value, width);
if (!v) {
return MIE_ERR_NO_MEMORY;
}
*out = v;
return MIE_SUCCESS;
}
bool mie_int_get_value(const struct mie_attribute *attrib, long long *out)
{
if (!mie_attribute_check_name(attrib, "builtin", "int")) {
return false;
}
const struct mie_int *v = (const struct mie_int *)attrib;
*out = v->i_val.v_small;
return true;
}
MIE_ATTRIBUTE_DEFINITION_BEGIN(mie_builtin_int, "int")
MIE_ATTRIBUTE_DEFINITION_STRUCT(struct mie_int);
MIE_ATTRIBUTE_DEFINITION_PRINT(print);
MIE_ATTRIBUTE_DEFINITION_PARSE(parse);
MIE_ATTRIBUTE_DEFINITION_END()

View File

@@ -0,0 +1,57 @@
#include <mie/attribute/attribute-definition.h>
#include <mie/attribute/attribute.h>
#include <mie/ctx.h>
#include <mie/dialect/builtin.h>
#include <mie/macros.h>
#include <mie/parse/parser.h>
#include <mie/print/printer.h>
static enum mie_status print(
const struct mie_attribute *value, struct mie_printer *out)
{
const struct mie_string *str = (const struct mie_string *)value;
if (out->p_flags & MIE_PRINT_F_ABBREVIATED) {
b_stream_write_fmt(out->p_stream, NULL, "\"%s\"", str->str_val);
} else {
b_stream_write_fmt(
out->p_stream, NULL, "#builtin.string<\"%s\">",
str->str_val);
}
return MIE_SUCCESS;
}
static enum mie_status parse(
struct mie_parser *ctx, const struct mie_attribute **out)
{
b_string *str = mie_parser_get_tempstr(ctx);
struct mie_file_span span;
if (!mie_parser_parse_string(ctx, str, &span)) {
return MIE_ERR_BAD_SYNTAX;
}
struct mie_attribute *v = mie_ctx_get_string(
mie_parser_get_mie_ctx(ctx), b_string_ptr(str));
if (!v) {
return MIE_ERR_NO_MEMORY;
}
*out = v;
return MIE_SUCCESS;
}
const char *mie_string_get_cstr(const struct mie_attribute *attrib)
{
if (!mie_attribute_check_name(attrib, "builtin", "string")) {
return NULL;
}
const struct mie_string *str = (const struct mie_string *)attrib;
return str->str_val;
}
MIE_ATTRIBUTE_DEFINITION_BEGIN(mie_builtin_string, "string")
MIE_ATTRIBUTE_DEFINITION_STRUCT(struct mie_string);
MIE_ATTRIBUTE_DEFINITION_PRINT(print);
MIE_ATTRIBUTE_DEFINITION_PARSE(parse);
MIE_ATTRIBUTE_DEFINITION_END();

View File

@@ -0,0 +1,81 @@
#include <mie/attribute/attribute-definition.h>
#include <mie/attribute/attribute.h>
#include <mie/ctx.h>
#include <mie/dialect/builtin.h>
#include <mie/dialect/dialect.h>
#include <mie/macros.h>
#include <mie/parse/parser.h>
#include <mie/print/printer.h>
struct mie_attribute *mie_type_attr_create(
struct mie_ctx *ctx, const struct mie_type *ty)
{
struct mie_type_attr *out = malloc(sizeof *out);
if (!out) {
return NULL;
}
memset(out, 0x0, sizeof *out);
out->ty_base.a_def
= mie_ctx_get_attribute_definition(ctx, "builtin", "type");
out->ty_value = ty;
return (struct mie_attribute *)out;
}
static enum mie_status print(
const struct mie_attribute *value, struct mie_printer *out)
{
const struct mie_type_attr *ty = (const struct mie_type_attr *)value;
if (!(out->p_flags & MIE_PRINT_F_ABBREVIATED)) {
b_stream_write_string(out->p_stream, "#builtin.type<", NULL);
}
mie_printer_print_type(out, ty->ty_value);
if (!(out->p_flags & MIE_PRINT_F_ABBREVIATED)) {
b_stream_write_char(out->p_stream, '>');
}
return MIE_SUCCESS;
}
static enum mie_status parse(
struct mie_parser *ctx, const struct mie_attribute **out)
{
struct mie_type_attr *ty = (struct mie_type_attr *)mie_type_attr_create(
mie_parser_get_mie_ctx(ctx), NULL);
if (!ty) {
return MIE_ERR_NO_MEMORY;
}
const struct mie_type *type = NULL;
if (!mie_parser_parse_type(ctx, &type)) {
free(ty);
return MIE_ERR_BAD_FORMAT;
}
ty->ty_value = type;
*out = (struct mie_attribute *)ty;
return MIE_SUCCESS;
}
const struct mie_type *mie_type_attr_get_type(const struct mie_attribute *attrib)
{
if (!mie_attribute_check_name(attrib, "builtin", "type")) {
return NULL;
}
const struct mie_type_attr *ty = (const struct mie_type_attr *)attrib;
return ty->ty_value;
}
MIE_ATTRIBUTE_DEFINITION_BEGIN(mie_builtin_type, "type")
MIE_ATTRIBUTE_DEFINITION_STRUCT(struct mie_type_attr);
MIE_ATTRIBUTE_DEFINITION_PRINT(print);
MIE_ATTRIBUTE_DEFINITION_PARSE(parse);
MIE_ATTRIBUTE_DEFINITION_END()

View File

@@ -1,7 +1,107 @@
#include <mie/ctx.h>
#include <mie/diag/class.h>
#include <mie/diag/msg.h>
#include <mie/dialect/builtin.h>
#include <mie/dialect/dialect.h>
#include <mie/macros.h>
MIE_DIALECT_BEGIN(mie_builtin, "builtin")
MIE_DIALECT_ADD_TYPE(mie_builtin_string);
struct builtin_dialect {
struct mie_dialect d_base;
struct mie_string_cache *ctx_strings;
struct mie_int_cache *ctx_ints;
struct mie_float_cache *ctx_floats;
struct mie_index_cache *ctx_indices;
};
static enum mie_status init(struct mie_dialect *d)
{
struct builtin_dialect *dialect = (struct builtin_dialect *)d;
dialect->ctx_strings = mie_string_cache_create();
dialect->ctx_ints = mie_int_cache_create();
dialect->ctx_floats = mie_float_cache_create();
dialect->ctx_indices = mie_index_cache_create();
return MIE_SUCCESS;
}
static enum mie_status cleanup(struct mie_dialect *d)
{
struct builtin_dialect *dialect = (struct builtin_dialect *)d;
mie_string_cache_destroy(dialect->ctx_strings);
mie_int_cache_destroy(dialect->ctx_ints);
mie_float_cache_destroy(dialect->ctx_floats);
mie_index_cache_destroy(dialect->ctx_indices);
return MIE_SUCCESS;
}
struct mie_attribute *mie_ctx_get_int(
struct mie_ctx *ctx, long long val, size_t nr_bits)
{
struct builtin_dialect *dialect
= (struct builtin_dialect *)mie_ctx_get_dialect(ctx, "builtin");
if (!dialect) {
return NULL;
}
return (struct mie_attribute *)mie_int_cache_get(
dialect->ctx_ints, ctx, val, nr_bits);
}
struct mie_attribute *mie_ctx_get_float(
struct mie_ctx *ctx, double val, size_t nr_bits)
{
struct builtin_dialect *dialect
= (struct builtin_dialect *)mie_ctx_get_dialect(ctx, "builtin");
if (!dialect) {
return NULL;
}
return (struct mie_attribute *)mie_float_cache_get(
dialect->ctx_floats, ctx, val, nr_bits);
}
struct mie_attribute *mie_ctx_get_string(struct mie_ctx *ctx, const char *s)
{
struct builtin_dialect *dialect
= (struct builtin_dialect *)mie_ctx_get_dialect(ctx, "builtin");
if (!dialect) {
return NULL;
}
return (struct mie_attribute *)mie_string_cache_get(
dialect->ctx_strings, ctx, s);
}
struct mie_attribute *mie_ctx_get_index(struct mie_ctx *ctx, size_t val)
{
struct builtin_dialect *dialect
= (struct builtin_dialect *)mie_ctx_get_dialect(ctx, "builtin");
if (!dialect) {
return NULL;
}
return (struct mie_attribute *)mie_index_cache_get(
dialect->ctx_indices, ctx, val);
}
MIE_DIAG_CLASS_LIST_EXTERN(mie_builtin_diag);
MIE_DIAG_MSG_LIST_EXTERN(mie_builtin_msg);
MIE_DIALECT_BEGIN(mie_builtin, struct builtin_dialect, "builtin")
MIE_DIALECT_INIT(init);
MIE_DIALECT_CLEANUP(cleanup);
MIE_DIALECT_DIAG_CLASS_LIST(mie_builtin_diag);
MIE_DIALECT_DIAG_MSG_LIST(mie_builtin_msg);
MIE_DIALECT_ADD_TRAIT(mie_builtin_isolated_from_above);
MIE_DIALECT_ADD_TRAIT(mie_builtin_symbol_table);
MIE_DIALECT_ADD_TYPE(mie_builtin_int);
MIE_DIALECT_ADD_TYPE(mie_builtin_float);
MIE_DIALECT_ADD_TYPE(mie_builtin_index);
MIE_DIALECT_ADD_TYPE(mie_builtin_string);
MIE_DIALECT_ADD_ATTRIBUTE(mie_builtin_int);
MIE_DIALECT_ADD_ATTRIBUTE(mie_builtin_float);
MIE_DIALECT_ADD_ATTRIBUTE(mie_builtin_type);
MIE_DIALECT_ADD_ATTRIBUTE(mie_builtin_string);
MIE_DIALECT_ADD_INTERFACE(mie_builtin_symbol);
MIE_DIALECT_ADD_ATTRIBUTE(mie_builtin_array);
MIE_DIALECT_ADD_OP(mie_builtin_module);
MIE_DIALECT_END()

View File

@@ -0,0 +1,36 @@
#include <mie/diag/class.h>
#include <mie/diag/msg.h>
#include <mie/dialect/builtin.h>
#include <mie/macros.h>
#define MIE_DIAG_CLASS_PREFIX MIE_BUILTIN_E
#define MIE_DIAG_MSG_PREFIX MIE_BUILTIN_MSG
MIE_DIAG_CLASS_LIST_BEGIN(mie_builtin_diag)
MIE_DIAG_CLASS(UNRECOGNISED_TOKEN, ERROR, "Unrecognised token")
MIE_DIAG_CLASS(UNRESOLVED_VALUE, ERROR, "Unresolved value")
MIE_DIAG_CLASS(UNRESOLVED_SUCCESSOR, ERROR, "Unresolved successor")
MIE_DIAG_CLASS_LIST_END(mie_builtin_diag)
MIE_DIAG_MSG_LIST_BEGIN(mie_builtin_msg)
MIE_DIAG_MSG(UNRECOGNISED_TOKEN, "encountered an unrecognised token.")
MIE_DIAG_MSG(UNRESOLVED_VALUE, "cannot resolve this value reference.")
MIE_DIAG_MSG(
CANNOT_FIND_BLOCK,
"cannot find a block with this name in this region.")
MIE_DIAG_MSG(
VALUE_DEFINED_IN_NON_DOMINANT_BLOCK,
"this value cannot be referenced here, as it is defined in a "
"block that does not dominate this block.")
MIE_DIAG_MSG(
VALUE_DEFINED_AFTER_USE,
"this value cannot be referenced here, as it is not defined "
"until later in this block.")
MIE_DIAG_MSG(
VALUE_DEFINED_OUTSIDE_ISOLATED_REGION,
"this value cannot be referenced here, as this region is "
"isolated from above, and the definition for this value is "
"outside of this region.")
MIE_DIAG_MSG(
VALUE_DEFINED_IN_BLOCK, "the value is defined in this block.")
MIE_DIAG_MSG_LIST_END(mie_builtin_msg)

View File

@@ -0,0 +1,12 @@
#ifndef _BUILTIN_FLOAT_H_
#define _BUILTIN_FLOAT_H_
#include <mie/attribute/attribute.h>
#include <mie/type/type.h>
struct float_type {
struct mie_type f_base;
size_t f_width;
};
#endif

View File

@@ -1,6 +1,6 @@
#include <blue/core/btree.h>
#include <mie/ctx.h>
#include <mie/dialect/index.h>
#include <mie/dialect/builtin.h>
#include <stdlib.h>
#include <string.h>
@@ -28,12 +28,9 @@ static struct index_cache_entry *index_cache_entry_create(
memset(out, 0x0, sizeof *out);
out->e_value.i_base.a_def
= mie_ctx_get_attribute_definition(ctx, "builtin", "index");
out->e_value.i_value = val;
out->e_value.i_base.v_type = mie_ctx_get_type(ctx, "index", "index");
if (!out->e_value.i_base.v_type) {
free(out);
return NULL;
}
return out;
}

12
mie/dialect/builtin/int.h Normal file
View File

@@ -0,0 +1,12 @@
#ifndef _BUILTIN_INT_H_
#define _BUILTIN_INT_H_
#include <mie/attribute/attribute.h>
#include <mie/type/type.h>
struct int_type {
struct mie_type i_base;
size_t i_width;
};
#endif

View File

@@ -0,0 +1,7 @@
#include <mie/dialect/builtin.h>
#include <mie/interface/interface-definition.h>
#include <mie/macros.h>
MIE_INTERFACE_DEFINITION_BEGIN(mie_builtin_symbol, "symbol")
MIE_INTERFACE_DEFINITION_STRUCT(struct mie_symbol);
MIE_INTERFACE_DEFINITION_END()

View File

@@ -0,0 +1,30 @@
#include <mie/ctx.h>
#include <mie/dialect/dialect.h>
#include <mie/ir/op-definition.h>
#include <mie/ir/op.h>
#include <mie/ir/region.h>
#include <mie/macros.h>
#include <mie/print/printer.h>
static enum mie_status print(struct mie_printer *out, const struct mie_op *op)
{
b_stream_write_char(out->p_stream, ' ');
struct mie_region *region = mie_op_get_first_region(op);
if (region) {
mie_printer_print_region(out, region, 0);
}
return MIE_SUCCESS;
}
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
{
return MIE_SUCCESS;
}
MIE_OP_DEFINITION_BEGIN(mie_builtin_module, "module")
MIE_OP_DEFINITION_PRINT(print);
MIE_OP_DEFINITION_PARSE(parse);
MIE_OP_DEFINITION_TRAIT("builtin", "isolated-from-above");
MIE_OP_DEFINITION_END()

View File

@@ -17,12 +17,8 @@ static struct mie_string *mie_string_create(
return NULL;
}
out->str_base.v_type = mie_ctx_get_type(ctx, "builtin", "string");
if (!out->str_base.v_type) {
free(out);
return NULL;
}
out->str_base.a_def
= mie_ctx_get_attribute_definition(ctx, "builtin", "string");
out->str_val = b_strdup(s);
if (!out->str_val) {
return NULL;

View File

@@ -0,0 +1,21 @@
#include <mie/dialect/builtin.h>
#include <mie/dialect/dialect.h>
#include <mie/macros.h>
#include <mie/trait/trait-definition.h>
#include <mie/trait/trait.h>
static enum mie_status validate(
const struct mie_trait_definition *trait_def,
const struct mie_trait *trait, const struct mie_trait_target *target)
{
return MIE_SUCCESS;
}
/* builtin.isolated-from-above trait:
* regions of an op that has this trait cannot capture or reference
* values defined in the enclosing scope. */
MIE_TRAIT_DEFINITION_BEGIN(mie_builtin_symbol_table, "symbol-table")
MIE_TRAIT_DEFINITION_TARGETS(MIE_TRAIT_TARGET_OP | MIE_TRAIT_TARGET_TYPE);
MIE_TRAIT_DEFINITION_STRUCT(struct mie_symbol_table);
MIE_TRAIT_DEFINITION_VALIDATE(validate);
MIE_TRAIT_DEFINITION_END()

View File

@@ -1,47 +1,18 @@
#include "../float.h"
#include <blue/core/bstr.h>
#include <mie/ctx.h>
#include <mie/dialect/arith.h>
#include <mie/dialect/builtin.h>
#include <mie/dialect/dialect.h>
#include <mie/macros.h>
#include <mie/print/printer.h>
#include <mie/type/type-definition.h>
#include <mie/type/type.h>
#include <mie/value.h>
struct float_type {
struct mie_type f_base;
size_t f_width;
};
static enum mie_status value_print(
const struct mie_value *value, struct mie_printer *out)
{
struct float_type *float_ty = (struct float_type *)value->v_type;
struct mie_float *float_val = (struct mie_float *)value;
switch (float_ty->f_width) {
case MIE_FLOAT_32:
b_stream_write_fmt(
out->p_stream, NULL, "%f : f%zu", float_val->f_val.v_32,
float_ty->f_width);
break;
case MIE_FLOAT_64:
b_stream_write_fmt(
out->p_stream, NULL, "%lf : f%zu",
float_val->f_val.v_64, float_ty->f_width);
break;
default:
b_stream_write_fmt(
out->p_stream, NULL, "NaN : f%zu", float_ty->f_width);
break;
}
return MIE_SUCCESS;
}
struct mie_type *mie_arith_float_get_type(struct mie_ctx *ctx, size_t bit_width)
struct mie_type *mie_ctx_get_float_type(struct mie_ctx *ctx, size_t bit_width)
{
struct mie_type_definition *type_info
= mie_ctx_get_type_definition(ctx, "arith", "float");
= mie_ctx_get_type_definition(ctx, "builtin", "float");
if (!type_info) {
return NULL;
}
@@ -63,7 +34,7 @@ struct mie_type *mie_arith_float_get_type(struct mie_ctx *ctx, size_t bit_width)
return NULL;
}
type->f_base.ty_name = b_bstr_fmt("arith.float<%zu>", bit_width);
type->f_base.ty_name = b_bstr_fmt(NULL, "builtin.float<%zu>", bit_width);
type->f_base.ty_instance_size = sizeof(struct mie_float);
type->f_width = bit_width;
@@ -71,9 +42,9 @@ struct mie_type *mie_arith_float_get_type(struct mie_ctx *ctx, size_t bit_width)
return (struct mie_type *)type;
}
size_t mie_arith_float_type_get_width(const struct mie_type *type)
size_t mie_float_type_get_width(const struct mie_type *type)
{
if (strcmp(type->ty_def->ty_parent->d_name, "arith") != 0) {
if (strcmp(type->ty_def->ty_parent->d_name, "builtin") != 0) {
return (size_t)-1;
}
@@ -90,24 +61,20 @@ static enum mie_status print(const struct mie_type *ty, struct mie_printer *out)
const struct float_type *float_type = (const struct float_type *)ty;
b_stream_write_fmt(
out->p_stream, NULL,
(out->p_flags & MIE_PRINT_F_ABBREVIATED) ? "f%zu"
: "arith.float<%zu>",
(out->p_flags & MIE_PRINT_F_ABBREVIATED) ? "f%zu" : "!builtin.float<%zu>",
float_type->f_width);
return MIE_SUCCESS;
}
static enum mie_status parse(
const struct mie_type_definition *def, struct mie_parser *parser,
struct mie_type **out)
static enum mie_status parse(struct mie_parser *parser, const struct mie_type **out)
{
return MIE_SUCCESS;
}
MIE_TYPE_DEFINITION_BEGIN(mie_arith_float, "float")
MIE_TYPE_DEFINITION_BEGIN(mie_builtin_float, "float")
// MIE_TYPE_DEFINITION_FLAGS(MIE_TYPE_DEFINITION_PARAMETISED);
MIE_TYPE_DEFINITION_STRUCT(struct float_type);
MIE_TYPE_DEFINITION_PRINT(print);
MIE_TYPE_DEFINITION_PARSE(parse);
MIE_TYPE_DEFINITION_VALUE_PRINT(value_print);
MIE_TYPE_DEFINITION_END()

View File

@@ -0,0 +1,21 @@
#include <mie/dialect/builtin.h>
#include <mie/dialect/dialect.h>
#include <mie/macros.h>
#include <mie/print/printer.h>
#include <mie/type/type-definition.h>
#include <mie/type/type.h>
struct index_type {
struct mie_type i_base;
};
static void type_init(
const struct mie_type_definition *type_info, struct mie_type *type)
{
type->ty_instance_size = sizeof(struct mie_index);
}
MIE_TYPE_DEFINITION_BEGIN(mie_builtin_index, "index")
MIE_TYPE_DEFINITION_STRUCT(struct index_type);
MIE_TYPE_DEFINITION_INIT(type_init);
MIE_TYPE_DEFINITION_END()

View File

@@ -1,39 +1,18 @@
#include "../int.h"
#include <blue/core/bstr.h>
#include <mie/ctx.h>
#include <mie/dialect/arith.h>
#include <mie/dialect/builtin.h>
#include <mie/dialect/dialect.h>
#include <mie/macros.h>
#include <mie/print/printer.h>
#include <mie/type/type-definition.h>
#include <mie/type/type.h>
#include <mie/value.h>
struct int_type {
struct mie_type i_base;
size_t i_width;
};
static enum mie_status value_print(
const struct mie_value *value, struct mie_printer *out)
{
struct int_type *int_ty = (struct int_type *)value->v_type;
struct mie_int *int_val = (struct mie_int *)value;
if (int_ty->i_width <= 64) {
b_stream_write_fmt(
out->p_stream, NULL, "%zu : i%zu",
int_val->i_val.v_small, int_ty->i_width);
} else {
b_stream_write_fmt(
out->p_stream, NULL, "INF : i%zu", int_ty->i_width);
}
return MIE_SUCCESS;
}
struct mie_type *mie_arith_int_get_type(struct mie_ctx *ctx, size_t bit_width)
struct mie_type *mie_ctx_get_int_type(struct mie_ctx *ctx, size_t bit_width)
{
struct mie_type_definition *type_info
= mie_ctx_get_type_definition(ctx, "arith", "int");
= mie_ctx_get_type_definition(ctx, "builtin", "int");
if (!type_info) {
return NULL;
}
@@ -55,7 +34,7 @@ struct mie_type *mie_arith_int_get_type(struct mie_ctx *ctx, size_t bit_width)
return NULL;
}
type->i_base.ty_name = b_bstr_fmt("arith.int<%zu>", bit_width);
type->i_base.ty_name = b_bstr_fmt(NULL, "builtin.int<%zu>", bit_width);
type->i_base.ty_instance_size = sizeof(struct mie_int);
type->i_width = bit_width;
@@ -63,9 +42,9 @@ struct mie_type *mie_arith_int_get_type(struct mie_ctx *ctx, size_t bit_width)
return (struct mie_type *)type;
}
size_t mie_arith_int_type_get_width(const struct mie_type *type)
size_t mie_int_type_get_width(const struct mie_type *type)
{
if (strcmp(type->ty_def->ty_parent->d_name, "arith") != 0) {
if (strcmp(type->ty_def->ty_parent->d_name, "builtin") != 0) {
return (size_t)-1;
}
@@ -82,23 +61,21 @@ static enum mie_status print(const struct mie_type *ty, struct mie_printer *out)
const struct int_type *int_type = (const struct int_type *)ty;
b_stream_write_fmt(
out->p_stream, NULL,
(out->p_flags & MIE_PRINT_F_ABBREVIATED) ? "i%zu" : "arith.int<%zu>",
(out->p_flags & MIE_PRINT_F_ABBREVIATED) ? "i%zu"
: "!builtin.int<%zu>",
int_type->i_width);
return MIE_SUCCESS;
}
static enum mie_status parse(
const struct mie_type_definition *def, struct mie_parser *parser,
struct mie_type **out)
static enum mie_status parse(struct mie_parser *parser, const struct mie_type **out)
{
return MIE_SUCCESS;
}
MIE_TYPE_DEFINITION_BEGIN(mie_arith_int, "int")
MIE_TYPE_DEFINITION_BEGIN(mie_builtin_int, "int")
// MIE_TYPE_DEFINITION_FLAGS(MIE_TYPE_DEFINITION_PARAMETISED);
MIE_TYPE_DEFINITION_STRUCT(struct int_type);
MIE_TYPE_DEFINITION_PRINT(print);
MIE_TYPE_DEFINITION_PARSE(parse);
MIE_TYPE_DEFINITION_VALUE_PRINT(value_print);
MIE_TYPE_DEFINITION_END()

View File

@@ -6,15 +6,6 @@
#include <mie/print/printer.h>
#include <mie/type/type-definition.h>
#include <mie/type/type.h>
#include <mie/value.h>
static enum mie_status value_print(
const struct mie_value *value, struct mie_printer *out)
{
const struct mie_string *str = (const struct mie_string *)value;
b_stream_write_fmt(out->p_stream, NULL, "\"%s\"", str->str_val);
return MIE_SUCCESS;
}
static void type_init(
const struct mie_type_definition *type_info, struct mie_type *type)
@@ -24,13 +15,10 @@ static void type_init(
static enum mie_status print(const struct mie_type *ty, struct mie_printer *out)
{
return MIE_SUCCESS;
}
static enum mie_status parse(
const struct mie_type_definition *def, struct mie_parser *parser,
struct mie_type **out)
{
b_stream_write_string(
out->p_stream,
(out->p_flags & MIE_PRINT_F_ABBREVIATED) ? "str" : "!builtin.string",
NULL);
return MIE_SUCCESS;
}
@@ -38,6 +26,4 @@ MIE_TYPE_DEFINITION_BEGIN(mie_builtin_string, "string")
MIE_TYPE_DEFINITION_STRUCT(struct mie_type);
MIE_TYPE_DEFINITION_INIT(type_init);
MIE_TYPE_DEFINITION_PRINT(print);
MIE_TYPE_DEFINITION_PARSE(parse);
MIE_TYPE_DEFINITION_VALUE_PRINT(value_print);
MIE_TYPE_DEFINITION_END()

View File

@@ -1,18 +0,0 @@
#include <mie/dialect/dialect.h>
#include <mie/ir/op-definition.h>
#include <mie/macros.h>
static enum mie_status print(const struct mie_op *op, b_stream *out)
{
return MIE_SUCCESS;
}
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
{
return MIE_SUCCESS;
}
MIE_OP_DEFINITION_BEGIN(mie_cf_br_cond, "br-cond")
MIE_OP_DEFINITION_PRINT(print);
MIE_OP_DEFINITION_PARSE(parse);
MIE_OP_DEFINITION_END()

View File

@@ -1,18 +0,0 @@
#include <mie/dialect/dialect.h>
#include <mie/ir/op-definition.h>
#include <mie/macros.h>
static enum mie_status print(const struct mie_op *op, b_stream *out)
{
return MIE_SUCCESS;
}
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
{
return MIE_SUCCESS;
}
MIE_OP_DEFINITION_BEGIN(mie_cf_br, "br")
MIE_OP_DEFINITION_PRINT(print);
MIE_OP_DEFINITION_PARSE(parse);
MIE_OP_DEFINITION_END()

View File

@@ -1,7 +1,7 @@
#include <mie/dialect/dialect.h>
#include <mie/macros.h>
MIE_DIALECT_BEGIN(mie_cf, "cf")
MIE_DIALECT_BEGIN(mie_cf, struct mie_dialect, "cf")
MIE_DIALECT_ADD_OP(mie_cf_br);
MIE_DIALECT_ADD_OP(mie_cf_br_cond);
MIE_DIALECT_END()

View File

@@ -0,0 +1,57 @@
#include <mie/dialect/dialect.h>
#include <mie/ir/emit.h>
#include <mie/ir/op-definition.h>
#include <mie/ir/op.h>
#include <mie/macros.h>
#include <mie/print/printer.h>
static enum mie_status print(struct mie_printer *printer, const struct mie_op *op)
{
if (MIE_VECTOR_COUNT(op->op_args) != 1) {
return MIE_SUCCESS;
}
if (MIE_VECTOR_COUNT(op->op_successors) != 2) {
return MIE_SUCCESS;
}
const struct mie_op_arg *cond = &op->op_args.items[0];
const struct mie_op_successor *if_true = &op->op_successors.items[0];
const struct mie_op_successor *if_false = &op->op_successors.items[1];
b_stream_write_char(printer->p_stream, ' ');
mie_printer_print_op_arg(printer, cond, false);
b_stream_write_string(printer->p_stream, ", ", NULL);
mie_printer_print_op_successor(printer, if_true, true);
b_stream_write_string(printer->p_stream, ", ", NULL);
mie_printer_print_op_successor(printer, if_false, true);
return MIE_SUCCESS;
}
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
{
return MIE_SUCCESS;
}
struct mie_op *mie_cf_br_cond_put(
struct mie_emitter *e, struct mie_register *cond,
struct mie_block *true_block, struct mie_register **true_args,
size_t nr_true_args, struct mie_block *false_block,
struct mie_register **false_args, size_t nr_false_args)
{
struct mie_op *op = mie_emitter_put_op(e, "cf", "br-cond", &cond, 1);
if (!op) {
return NULL;
}
mie_op_add_successor(op, true_block, true_args, nr_true_args);
mie_op_add_successor(op, false_block, false_args, nr_false_args);
return op;
}
MIE_OP_DEFINITION_BEGIN(mie_cf_br_cond, "br-cond")
MIE_OP_DEFINITION_PRINT(print);
MIE_OP_DEFINITION_PARSE(parse);
MIE_OP_DEFINITION_END()

42
mie/dialect/cf/op/br.c Normal file
View File

@@ -0,0 +1,42 @@
#include <mie/dialect/dialect.h>
#include <mie/ir/block.h>
#include <mie/ir/emit.h>
#include <mie/ir/op-definition.h>
#include <mie/ir/op.h>
#include <mie/macros.h>
#include <mie/print/printer.h>
static enum mie_status print(struct mie_printer *printer, const struct mie_op *op)
{
b_stream_write_char(printer->p_stream, ' ');
const struct mie_op_successor *successor = &op->op_successors.items[0];
mie_printer_print_op_successor(printer, successor, true);
return MIE_SUCCESS;
}
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
{
return MIE_SUCCESS;
}
struct mie_op *mie_cf_br_put(
struct mie_emitter *e, struct mie_block *dest,
struct mie_register **dest_args, size_t nr_dest_args)
{
struct mie_op *op = mie_emitter_put_op(e, "cf", "br", NULL, 0);
if (!op) {
return NULL;
}
struct mie_op_successor *s
= mie_op_add_successor(op, dest, dest_args, nr_dest_args);
return op;
}
MIE_OP_DEFINITION_BEGIN(mie_cf_br, "br")
MIE_OP_DEFINITION_PRINT(print);
MIE_OP_DEFINITION_PARSE(parse);
MIE_OP_DEFINITION_END()

View File

@@ -11,14 +11,31 @@
MIE_ID(0xb9, 0x97, 0xcf, 0xd3, 0x81, 0xd4, 0x45, 0x06, 0x9b, 0x44, \
0x05, 0x9f, 0xb4, 0x76, 0xf1, 0x2d)
struct mie_dialect *mie_dialect_create(struct mie_ctx *ctx, const char *name)
#define TRAIT_NS_ID \
MIE_ID(0x5a, 0x11, 0x68, 0x8e, 0x21, 0x1d, 0x4d, 0x5f, 0xb8, 0x6b, \
0x39, 0x73, 0xb0, 0x1f, 0xce, 0xf7)
#define ATTRIBUTE_NS_ID \
MIE_ID(0x86, 0x76, 0xcb, 0xfb, 0xc8, 0xe5, 0x40, 0x7d, 0xa3, 0x84, \
0x93, 0xe3, 0xa5, 0x29, 0x74, 0xfe)
#define INTERFACE_NS_ID \
MIE_ID(0xc5, 0x85, 0x7f, 0x8a, 0x7d, 0xe4, 0x4d, 0x03, 0x88, 0x8d, \
0x34, 0x32, 0xbf, 0x29, 0x5c, 0x72)
struct mie_dialect *mie_dialect_create(
struct mie_ctx *ctx, const char *name, size_t size)
{
struct mie_dialect *out = malloc(sizeof *out);
if (size < sizeof(struct mie_dialect)) {
return NULL;
}
struct mie_dialect *out = malloc(size);
if (!out) {
return NULL;
}
memset(out, 0x0, sizeof *out);
memset(out, 0x0, size);
out->d_name = b_strdup(name);
if (!out->d_name) {
@@ -32,6 +49,15 @@ struct mie_dialect *mie_dialect_create(struct mie_ctx *ctx, const char *name)
mie_id type_ns = TYPE_NS_ID;
mie_id_map_init(&out->d_types, &type_ns);
mie_id trait_ns = TRAIT_NS_ID;
mie_id_map_init(&out->d_traits, &trait_ns);
mie_id attribute_ns = ATTRIBUTE_NS_ID;
mie_id_map_init(&out->d_attributes, &attribute_ns);
mie_id interface_ns = INTERFACE_NS_ID;
mie_id_map_init(&out->d_interfaces, &interface_ns);
b_rope name_rope = B_ROPE_CSTR(name);
mie_id_map_put(&ctx->ctx_dialects, &out->d_id, &name_rope);

View File

@@ -2,21 +2,8 @@
#include <mie/ir/op-definition.h>
#include <mie/macros.h>
static enum mie_status print(const struct mie_op *op, b_stream *out)
{
return MIE_SUCCESS;
}
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
{
return MIE_SUCCESS;
}
MIE_OP_DEFINITION_BEGIN(mie_func_func, "func")
MIE_OP_DEFINITION_PRINT(print);
MIE_OP_DEFINITION_PARSE(parse);
MIE_OP_DEFINITION_END()
MIE_DIALECT_BEGIN(mie_func, "func")
MIE_DIALECT_BEGIN(mie_func, struct mie_dialect, "func")
MIE_DIALECT_ADD_TRAIT(mie_func_function_like);
MIE_DIALECT_ADD_OP(mie_func_func);
MIE_DIALECT_ADD_OP(mie_func_return);
MIE_DIALECT_END()

137
mie/dialect/func/op/func.c Normal file
View File

@@ -0,0 +1,137 @@
#include <mie/attribute/attribute-map.h>
#include <mie/ctx.h>
#include <mie/dialect/builtin.h>
#include <mie/dialect/dialect.h>
#include <mie/dialect/func.h>
#include <mie/interface/interface-definition.h>
#include <mie/interface/interface.h>
#include <mie/ir/block.h>
#include <mie/ir/emit.h>
#include <mie/ir/op-definition.h>
#include <mie/ir/op.h>
#include <mie/ir/region.h>
#include <mie/macros.h>
#include <mie/print/printer.h>
#include <mie/type/function.h>
static enum mie_status print(struct mie_printer *printer, const struct mie_op *op)
{
const struct mie_attribute *sym_name
= mie_attribute_map_get(&op->op_attrib, "sym_name");
const struct mie_attribute *function_type_attr
= mie_attribute_map_get(&op->op_attrib, "function_type");
const char *sym_name_cstr = mie_string_get_cstr(sym_name);
const struct mie_type *function_type_g
= mie_type_attr_get_type(function_type_attr);
const struct mie_function_type *function_ty
= (const struct mie_function_type *)function_type_g;
b_stream_write_fmt(printer->p_stream, NULL, " @%s(", sym_name_cstr);
const struct mie_region *code = mie_op_get_first_region(op);
const struct mie_block *entry = mie_region_get_first_block(code);
for (size_t i = 0; i < MIE_VECTOR_COUNT(entry->b_params); i++) {
if (i > 0) {
b_stream_write_string(printer->p_stream, ", ", NULL);
}
const struct mie_register *param = &entry->b_params.items[i];
mie_printer_print_register(printer, param, MIE_PRINT_F_INCLUDE_TYPE);
}
b_stream_write_string(printer->p_stream, ") -> ", NULL);
if (MIE_VECTOR_COUNT(function_ty->func_out) != 1) {
b_stream_write_char(printer->p_stream, '(');
}
for (size_t i = 0; i < MIE_VECTOR_COUNT(function_ty->func_out); i++) {
if (i > 0) {
b_stream_write_string(printer->p_stream, ", ", NULL);
}
const struct mie_type *ty = function_ty->func_out.items[i];
mie_printer_print_type(printer, ty);
}
if (MIE_VECTOR_COUNT(function_ty->func_out) != 1) {
b_stream_write_char(printer->p_stream, ')');
}
b_stream_write_char(printer->p_stream, ' ');
mie_printer_print_region(
printer, code, MIE_PRINT_F_EXCLUDE_FIRST_BLOCK_HEADER);
return MIE_SUCCESS;
}
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
{
return MIE_SUCCESS;
}
struct mie_op *mie_func_func_put(
struct mie_emitter *e, const char *name, struct mie_func_parameter *params,
size_t nr_params, const struct mie_type **ret_types, size_t nr_ret_types)
{
const struct mie_type **param_types
= calloc(nr_params, sizeof *param_types);
if (!param_types) {
return NULL;
}
for (size_t i = 0; i < nr_params; i++) {
param_types[i] = params[i].param_type;
}
const struct mie_type *func_type = mie_ctx_get_function_type(
mie_emitter_get_ctx(e), param_types, nr_params, ret_types,
nr_ret_types);
free(param_types);
if (!func_type) {
return NULL;
}
struct mie_op *op = mie_emitter_put_op(e, "func", "func", NULL, 0);
struct mie_region *region = mie_op_add_region(op);
struct mie_block *entry = mie_region_add_block(region);
mie_name_map_put(region->r_names, &entry->b_name, "entry", 0);
for (size_t i = 0; i < nr_params; i++) {
struct mie_register *param_reg = mie_block_add_param(entry);
mie_name_map_put(
region->r_names, &param_reg->reg_name,
params[i].param_name, 0);
param_reg->reg_type = params[i].param_type;
params[i].param_reg = param_reg;
}
struct mie_attribute *sym_name
= mie_ctx_get_string(mie_emitter_get_ctx(e), name);
struct mie_attribute *function_type
= mie_type_attr_create(mie_emitter_get_ctx(e), func_type);
mie_attribute_map_put(
&op->op_attrib, "sym_name", sym_name, MIE_ATTRMAP_F_REPLACE);
mie_attribute_map_put(
&op->op_attrib, "function_type", function_type,
MIE_ATTRMAP_F_REPLACE);
return op;
}
MIE_OP_DEFINITION_BEGIN(mie_func_func, "func")
MIE_OP_DEFINITION_PRINT(print);
MIE_OP_DEFINITION_PARSE(parse);
MIE_OP_DEFINITION_TRAIT("builtin", "isolated-from-above");
MIE_OP_DEFINITION_TRAIT("func", "function-like");
MIE_OP_INTERFACE_BEGIN("builtin", "symbol", struct mie_symbol)
MIE_OP_INTERFACE_FUNC(sym_get_name) = NULL;
MIE_OP_INTERFACE_END()
MIE_OP_DEFINITION_END()

View File

@@ -0,0 +1,49 @@
#include <mie/attribute/attribute-map.h>
#include <mie/ctx.h>
#include <mie/dialect/builtin.h>
#include <mie/dialect/dialect.h>
#include <mie/interface/interface-definition.h>
#include <mie/interface/interface.h>
#include <mie/ir/block.h>
#include <mie/ir/op-definition.h>
#include <mie/ir/op.h>
#include <mie/ir/region.h>
#include <mie/macros.h>
#include <mie/print/printer.h>
#include <mie/type/function.h>
static enum mie_status print(struct mie_printer *printer, const struct mie_op *op)
{
b_stream_write_char(printer->p_stream, ' ');
for (size_t i = 0; i < MIE_VECTOR_COUNT(op->op_args); i++) {
if (i > 0) {
b_stream_write_string(printer->p_stream, ", ", NULL);
}
mie_printer_print_op_arg(printer, &op->op_args.items[i], false);
}
b_stream_write_string(printer->p_stream, " : ", NULL);
for (size_t i = 0; i < MIE_VECTOR_COUNT(op->op_args); i++) {
if (i > 0) {
b_stream_write_string(printer->p_stream, ", ", NULL);
}
mie_printer_print_type(
printer, mie_op_arg_get_type(&op->op_args.items[i]));
}
return MIE_SUCCESS;
}
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
{
return MIE_SUCCESS;
}
MIE_OP_DEFINITION_BEGIN(mie_func_return, "return")
MIE_OP_DEFINITION_PRINT(print);
MIE_OP_DEFINITION_PARSE(parse);
MIE_OP_DEFINITION_END()

View File

@@ -0,0 +1,23 @@
#include <mie/dialect/dialect.h>
#include <mie/macros.h>
#include <mie/trait/trait-definition.h>
#include <mie/trait/trait.h>
static enum mie_status validate(
const struct mie_trait_definition *trait_def,
const struct mie_trait *trait, const struct mie_trait_target *target)
{
return MIE_SUCCESS;
}
/* func.function-like trait:
* the op behaves like a func.func. this means that it:
* a) has a single region
* b) that region has one or more blocks representing the body of a function.
* c) the op has sym_name, function_type, and other function-related attributes.
*/
MIE_TRAIT_DEFINITION_BEGIN(mie_func_function_like, "function-like")
MIE_TRAIT_DEFINITION_TARGETS(MIE_TRAIT_TARGET_OP);
MIE_TRAIT_DEFINITION_STRUCT(struct mie_trait);
MIE_TRAIT_DEFINITION_VALIDATE(validate);
MIE_TRAIT_DEFINITION_END()

View File

@@ -1,56 +1,10 @@
#include <mie/ctx.h>
#include <mie/dialect/dialect.h>
#include <mie/dialect/index.h>
#include <mie/macros.h>
#include <mie/print/printer.h>
#include <mie/type/type-definition.h>
#include <mie/type/type.h>
#include <mie/value.h>
struct index_type {
struct mie_type i_base;
};
static enum mie_status value_print(
const struct mie_value *value, struct mie_printer *out)
{
struct index_type *index_ty = (struct index_type *)value->v_type;
struct mie_index *index_val = (struct mie_index *)value;
b_stream_write_fmt(
out->p_stream, NULL, "%zu : %s", index_val->i_value,
index_ty->i_base.ty_def->ty_name);
return MIE_SUCCESS;
}
static void type_init(
const struct mie_type_definition *type_info, struct mie_type *type)
{
type->ty_instance_size = sizeof(struct mie_index);
}
static enum mie_status print(const struct mie_type *ty, struct mie_printer *out)
{
b_stream_write_string(
out->p_stream,
(out->p_flags & MIE_PRINT_F_ABBREVIATED) ? "index" : "index.index",
NULL);
return MIE_SUCCESS;
}
static enum mie_status parse(
const struct mie_type_definition *def, struct mie_parser *parser,
struct mie_type **out)
{
return MIE_SUCCESS;
}
MIE_TYPE_DEFINITION_BEGIN(mie_index_index, "index")
MIE_TYPE_DEFINITION_STRUCT(struct index_type);
MIE_TYPE_DEFINITION_INIT(type_init);
MIE_TYPE_DEFINITION_PRINT(print);
MIE_TYPE_DEFINITION_PARSE(parse);
MIE_TYPE_DEFINITION_VALUE_PRINT(value_print);
MIE_TYPE_DEFINITION_END()
MIE_DIALECT_BEGIN(mie_index, "index")
MIE_DIALECT_ADD_TYPE(mie_index_index);
MIE_DIALECT_BEGIN(mie_index, struct mie_dialect, "index")
MIE_DIALECT_END()

View File

@@ -0,0 +1,11 @@
#include <mie/dialect/dialect.h>
#include <mie/dialect/memref.h>
#include <mie/macros.h>
#include <mie/print/printer.h>
#include <mie/type/type-definition.h>
#include <mie/type/type.h>
MIE_DIALECT_BEGIN(mie_memref, struct mie_dialect, "memref")
MIE_DIALECT_ADD_TYPE(mie_memref_memref);
MIE_DIALECT_ADD_OP(mie_memref_load);
MIE_DIALECT_END()

View File

@@ -1,8 +1,8 @@
#include <mie/dialect/dialect.h>
#include <mie/ctx.h>
#include <mie/ir/op-definition.h>
#include <mie/macros.h>
static enum mie_status print(const struct mie_op *op, b_stream *out)
static enum mie_status print(struct mie_printer *printer, const struct mie_op *op)
{
return MIE_SUCCESS;
}
@@ -12,7 +12,7 @@ static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
return MIE_SUCCESS;
}
MIE_OP_DEFINITION_BEGIN(mie_arith_addi, "addi")
MIE_OP_DEFINITION_BEGIN(mie_memref_load, "load")
MIE_OP_DEFINITION_PRINT(print);
MIE_OP_DEFINITION_PARSE(parse);
MIE_OP_DEFINITION_END()

View File

@@ -0,0 +1,52 @@
#include <mie/dialect/dialect.h>
#include <mie/dialect/memref.h>
#include <mie/macros.h>
#include <mie/print/printer.h>
#include <mie/type/type-definition.h>
#include <mie/type/type.h>
enum memref_rank_type {
MEMREF_RANK_UNKNOWN = 0,
MEMREF_RANK_STATIC,
MEMREF_RANK_TYPE,
};
struct memref_rank {
enum memref_rank_type r_ranktype;
union {
size_t r_static;
const struct mie_type *r_type;
};
};
struct memref_type {
struct mie_type m_base;
MIE_VECTOR_DECLARE(struct memref_rank, m_rank);
};
static void type_init(
const struct mie_type_definition *type_info, struct mie_type *type)
{
}
static enum mie_status print(const struct mie_type *ty, struct mie_printer *out)
{
b_stream_write_string(
out->p_stream,
(out->p_flags & MIE_PRINT_F_ABBREVIATED) ? "memref" : "memref.memref",
NULL);
return MIE_SUCCESS;
}
static enum mie_status parse(struct mie_parser *parser, const struct mie_type **out)
{
printf("Parse memref!\n");
return MIE_ERR_BAD_FORMAT;
}
MIE_TYPE_DEFINITION_BEGIN(mie_memref_memref, "memref")
MIE_TYPE_DEFINITION_INIT(type_init);
MIE_TYPE_DEFINITION_PRINT(print);
MIE_TYPE_DEFINITION_PARSE(parse);
MIE_TYPE_DEFINITION_END()

View File

@@ -1,6 +1,6 @@
#include <mie/dialect/dialect.h>
#include <mie/macros.h>
MIE_DIALECT_BEGIN(mie_meta, "meta")
MIE_DIALECT_BEGIN(mie_meta, struct mie_dialect, "meta")
MIE_DIALECT_ADD_OP(mie_meta_source_filename);
MIE_DIALECT_END()

View File

@@ -2,7 +2,7 @@
#include <mie/ir/op-definition.h>
#include <mie/macros.h>
static enum mie_status print(const struct mie_op *op, b_stream *out)
static enum mie_status print(struct mie_printer *printer, const struct mie_op *op)
{
return MIE_SUCCESS;
}

View File

@@ -2,7 +2,7 @@
#include <mie/ir/op-definition.h>
#include <mie/macros.h>
static enum mie_status print(const struct mie_op *op, b_stream *out)
static enum mie_status print(struct mie_printer *printer, const struct mie_op *op)
{
return MIE_SUCCESS;
}

View File

@@ -2,7 +2,7 @@
#include <mie/ir/op-definition.h>
#include <mie/macros.h>
static enum mie_status print(const struct mie_op *op, b_stream *out)
static enum mie_status print(struct mie_printer *printer, const struct mie_op *op)
{
return MIE_SUCCESS;
}

View File

@@ -2,29 +2,7 @@
#include <mie/macros.h>
#include <mie/type/type-definition.h>
struct ptr_type {
struct mie_type_definition ptr_base;
};
static enum mie_status print(const struct mie_type *ty, struct mie_printer *out)
{
return MIE_SUCCESS;
}
static enum mie_status parse(
const struct mie_type_definition *def, struct mie_parser *parser,
struct mie_type **out)
{
return MIE_SUCCESS;
}
MIE_TYPE_DEFINITION_BEGIN(mie_ptr_ptr, "ptr")
MIE_TYPE_DEFINITION_STRUCT(struct ptr_type);
MIE_TYPE_DEFINITION_PRINT(print);
MIE_TYPE_DEFINITION_PARSE(parse);
MIE_TYPE_DEFINITION_END()
MIE_DIALECT_BEGIN(mie_ptr, "ptr")
MIE_DIALECT_BEGIN(mie_ptr, struct mie_dialect, "ptr")
MIE_DIALECT_ADD_OP(mie_ptr_load);
MIE_DIALECT_ADD_OP(mie_ptr_store);
MIE_DIALECT_ADD_TYPE(mie_ptr_ptr);

View File

@@ -0,0 +1,17 @@
#include <mie/dialect/dialect.h>
#include <mie/macros.h>
#include <mie/type/type-definition.h>
struct ptr_type {
struct mie_type_definition ptr_base;
};
static enum mie_status print(const struct mie_type *ty, struct mie_printer *out)
{
return MIE_SUCCESS;
}
MIE_TYPE_DEFINITION_BEGIN(mie_ptr_ptr, "ptr")
MIE_TYPE_DEFINITION_STRUCT(struct ptr_type);
MIE_TYPE_DEFINITION_PRINT(print);
MIE_TYPE_DEFINITION_END()

View File

@@ -1,18 +0,0 @@
#include <mie/dialect/dialect.h>
#include <mie/ir/op-definition.h>
#include <mie/macros.h>
static enum mie_status print(const struct mie_op *op, b_stream *out)
{
return MIE_SUCCESS;
}
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
{
return MIE_SUCCESS;
}
MIE_OP_DEFINITION_BEGIN(mie_scf_if, "if")
MIE_OP_DEFINITION_PRINT(print);
MIE_OP_DEFINITION_PARSE(parse);
MIE_OP_DEFINITION_END()

View File

@@ -2,7 +2,7 @@
#include <mie/ir/op-definition.h>
#include <mie/macros.h>
static enum mie_status print(const struct mie_op *op, b_stream *out)
static enum mie_status print(struct mie_printer *printer, const struct mie_op *op)
{
return MIE_SUCCESS;
}

86
mie/dialect/scf/op/if.c Normal file
View File

@@ -0,0 +1,86 @@
#include <mie/dialect/dialect.h>
#include <mie/ir/emit.h>
#include <mie/ir/op-definition.h>
#include <mie/ir/op.h>
#include <mie/ir/region.h>
#include <mie/macros.h>
#include <mie/print/printer.h>
static enum mie_status print(struct mie_printer *printer, const struct mie_op *op)
{
b_stream_write_char(printer->p_stream, ' ');
mie_printer_print_op_arg(printer, &op->op_args.items[0], false);
if (MIE_VECTOR_COUNT(op->op_result) > 0) {
b_stream_write_string(printer->p_stream, " -> ", NULL);
if (MIE_VECTOR_COUNT(op->op_result) > 1) {
b_stream_write_char(printer->p_stream, '(');
}
}
for (size_t i = 0; i < MIE_VECTOR_COUNT(op->op_result); i++) {
if (i > 0) {
b_stream_write_string(printer->p_stream, ", ", NULL);
}
mie_printer_print_type(printer, op->op_result.items[i].reg_type);
}
if (MIE_VECTOR_COUNT(op->op_result) > 1) {
b_stream_write_char(printer->p_stream, '(');
}
b_stream_write_char(printer->p_stream, ' ');
struct mie_region *if_region = mie_op_get_first_region(op);
struct mie_region *else_region = mie_op_get_next_region(op, if_region);
mie_printer_print_region(printer, if_region, 0);
if (else_region) {
b_stream_write_string(printer->p_stream, " else ", NULL);
mie_printer_print_region(printer, else_region, 0);
}
return MIE_SUCCESS;
}
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
{
return MIE_SUCCESS;
}
struct mie_op *mie_scf_if_put(
struct mie_emitter *e, struct mie_register *cond,
const struct mie_type *result_type, struct mie_region **out_true,
struct mie_region **out_false, const char *name)
{
struct mie_op *op = mie_emitter_put_op(e, "scf", "if", &cond, 1);
if (!op) {
return NULL;
}
if (result_type) {
struct mie_register *result = mie_op_add_result(op, result_type);
mie_emitter_put_name(e, &result->reg_name, name);
}
struct mie_region *r_true = mie_op_add_region(op);
struct mie_region *r_false = mie_op_add_region(op);
if (out_true) {
*out_true = r_true;
}
if (out_false) {
*out_false = r_false;
}
return op;
}
MIE_OP_DEFINITION_BEGIN(mie_scf_if, "if")
MIE_OP_DEFINITION_PRINT(print);
MIE_OP_DEFINITION_PARSE(parse);
MIE_OP_DEFINITION_END()

View File

@@ -0,0 +1,46 @@
#include <mie/dialect/dialect.h>
#include <mie/ir/emit.h>
#include <mie/ir/op-definition.h>
#include <mie/ir/op.h>
#include <mie/macros.h>
#include <mie/print/printer.h>
static enum mie_status print(struct mie_printer *printer, const struct mie_op *op)
{
b_stream_write_char(printer->p_stream, ' ');
for (size_t i = 0; i < MIE_VECTOR_COUNT(op->op_args); i++) {
if (i > 0) {
b_stream_write_string(printer->p_stream, ", ", NULL);
}
mie_printer_print_op_arg(printer, &op->op_args.items[i], false);
}
b_stream_write_string(printer->p_stream, " : ", NULL);
for (size_t i = 0; i < MIE_VECTOR_COUNT(op->op_args); i++) {
if (i > 0) {
b_stream_write_string(printer->p_stream, ", ", NULL);
}
mie_printer_print_type(
printer, mie_op_arg_get_type(&op->op_args.items[i]));
}
return MIE_SUCCESS;
}
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
{
return MIE_SUCCESS;
}
struct mie_op *mie_scf_yield_put(struct mie_emitter *e, struct mie_register *value)
{
return mie_emitter_put_op(e, "scf", "yield", &value, 1);
}
MIE_OP_DEFINITION_BEGIN(mie_scf_yield, "yield")
MIE_OP_DEFINITION_PRINT(print);
MIE_OP_DEFINITION_PARSE(parse);
MIE_OP_DEFINITION_END()

View File

@@ -1,7 +1,7 @@
#include <mie/dialect/dialect.h>
#include <mie/macros.h>
MIE_DIALECT_BEGIN(mie_scf, "scf")
MIE_DIALECT_BEGIN(mie_scf, struct mie_dialect, "scf")
MIE_DIALECT_ADD_OP(mie_scf_if);
MIE_DIALECT_ADD_OP(mie_scf_for);
MIE_DIALECT_ADD_OP(mie_scf_yield);

View File

@@ -1,18 +0,0 @@
#include <mie/dialect/dialect.h>
#include <mie/ir/op-definition.h>
#include <mie/macros.h>
static enum mie_status print(const struct mie_op *op, b_stream *out)
{
return MIE_SUCCESS;
}
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
{
return MIE_SUCCESS;
}
MIE_OP_DEFINITION_BEGIN(mie_scf_yield, "yield")
MIE_OP_DEFINITION_PRINT(print);
MIE_OP_DEFINITION_PARSE(parse);
MIE_OP_DEFINITION_END()

View File

@@ -4,7 +4,7 @@
#include <mie/macros.h>
#include <mie/trait/trait.h>
static enum mie_status print(const struct mie_op *op, b_stream *out)
static enum mie_status print(struct mie_printer *printer, const struct mie_op *op)
{
return MIE_SUCCESS;
}

View File

@@ -1,7 +1,7 @@
#include <mie/dialect/dialect.h>
#include <mie/macros.h>
MIE_DIALECT_BEGIN(mie_select, "select")
MIE_DIALECT_BEGIN(mie_select, struct mie_dialect, "select")
MIE_DIALECT_ADD_TRAIT(mie_select_graph_only);
MIE_DIALECT_ADD_TRAIT(mie_select_graph_op);
MIE_DIALECT_ADD_TRAIT(mie_select_graph_scope);

View File

@@ -114,7 +114,7 @@ void mie_id_to_string(const mie_id *id, char *out, size_t max)
b_bstr_write_char(&str, '-');
}
b_bstr_write_fmt(&str, "%02x", id->id_bytes[i]);
b_bstr_write_fmt(&str, NULL, "%02x", id->id_bytes[i]);
}
}

View File

@@ -0,0 +1,33 @@
#ifndef MIE_ATTRIBUTE_ATTRIBUTE_DEFINITION_H_
#define MIE_ATTRIBUTE_ATTRIBUTE_DEFINITION_H_
#include <mie/id.h>
struct mie_dialect;
struct mie_attribute;
struct mie_parser;
struct mie_printer;
struct mie_attribute_definition {
mie_id a_id;
struct mie_dialect *a_parent;
char *a_name;
size_t a_data_size;
void (*a_init)(struct mie_attribute *);
void (*a_cleanup)(struct mie_attribute *);
enum mie_status (*a_print)(
const struct mie_attribute *, struct mie_printer *);
enum mie_status (*a_parse)(
struct mie_parser *, const struct mie_attribute **);
};
MIE_API struct mie_attribute_definition *mie_attribute_definition_create(
struct mie_dialect *parent, const char *name);
MIE_API bool mie_attribute_definition_check_name(
const struct mie_attribute_definition *def, const char *dialect_name,
const char *attrib_name);
#endif

View File

@@ -0,0 +1,44 @@
#ifndef MIE_ATTRIBUTE_ATTRIBUTE_MAP_H_
#define MIE_ATTRIBUTE_ATTRIBUTE_MAP_H_
#include <blue/core/btree.h>
#include <mie/misc.h>
#include <mie/status.h>
struct b_queue_entry;
struct mie_attribute_map {
b_btree m_entries;
};
enum mie_attribute_map_flags {
MIE_ATTRMAP_F_REPLACE = 0x01u,
};
struct mie_attribute_map_iterator {
const char *it_name;
const struct mie_attribute *it_value;
b_btree_node *_n;
struct b_queue_entry *_e;
};
MIE_API void mie_attribute_map_init(struct mie_attribute_map *map);
MIE_API void mie_attribute_map_cleanup(struct mie_attribute_map *map);
static inline bool mie_attribute_map_empty(const struct mie_attribute_map *map)
{
return b_btree_empty(&map->m_entries);
}
MIE_API const struct mie_attribute *mie_attribute_map_get(
const struct mie_attribute_map *map, const char *name);
MIE_API enum mie_status mie_attribute_map_put(
struct mie_attribute_map *map, const char *name,
const struct mie_attribute *value, enum mie_attribute_map_flags flags);
MIE_API enum mie_status mie_attribute_map_iterator_begin(
struct mie_attribute_map_iterator *it, const struct mie_attribute_map *map);
MIE_API enum mie_status mie_attribute_map_iterator_move_next(
struct mie_attribute_map_iterator *it);
#endif

View File

@@ -0,0 +1,17 @@
#ifndef MIE_ATTRIBUTE_ATTRIBUTE_H_
#define MIE_ATTRIBUTE_ATTRIBUTE_H_
#include <mie/misc.h>
#include <stdbool.h>
struct mie_attribute_definition;
struct mie_attribute {
const struct mie_attribute_definition *a_def;
};
MIE_API bool mie_attribute_check_name(
const struct mie_attribute *attrib, const char *dialect_name,
const char *attrib_name);
#endif

View File

@@ -6,10 +6,15 @@
#include <mie/id.h>
struct mie_op;
struct mie_pass;
struct mie_diag;
struct mie_file_cell;
struct mie_int_cache;
struct mie_line_source;
struct mie_index_cache;
struct mie_string_cache;
;
struct mie_attribute_map;
struct mie_pass_definition;
struct mie_ctx {
#if 0
@@ -25,25 +30,35 @@ struct mie_ctx {
struct mie_id_map ctx_types;
/* map of struct mie_trait */
struct mie_id_map ctx_traits;
struct mie_int_cache *ctx_ints;
struct mie_float_cache *ctx_floats;
struct mie_index_cache *ctx_indices;
struct mie_string_cache *ctx_strings;
/* map of struct mie_attribute */
struct mie_id_map ctx_attributes;
/* map of struct mie_pass_definition */
struct mie_id_map ctx_passes;
/* queue of struct mie_diag */
b_queue ctx_diag;
};
MIE_API struct mie_ctx *mie_ctx_create(void);
MIE_API void mie_ctx_destroy(struct mie_ctx *ctx);
MIE_API bool mie_ctx_resolve_op(const struct mie_ctx *ctx, struct mie_op *op);
MIE_API struct mie_op *mie_ctx_create_op(
const struct mie_ctx *ctx, const char *dialect, const char *op);
MIE_API struct mie_dialect *mie_ctx_get_dialect(
const struct mie_ctx *ctx, const char *name);
MIE_API struct mie_type_definition *mie_ctx_get_type_definition(
const struct mie_ctx *ctx, const char *dialect_name, const char *type_name);
MIE_API const struct mie_op_definition *mie_ctx_get_op_definition(
const struct mie_ctx *ctx, const char *dialect_name, const char *op_name);
MIE_API const struct mie_trait_definition *mie_ctx_get_trait_definition(
const struct mie_ctx *ctx, const char *dialect_name,
const char *trait_name);
MIE_API const struct mie_attribute_definition *mie_ctx_get_attribute_definition(
const struct mie_ctx *ctx, const char *dialect_name,
const char *attrib_name);
MIE_API const struct mie_interface_definition *mie_ctx_get_interface_definition(
const struct mie_ctx *ctx, const char *dialect_name,
const char *iface_name);
MIE_API struct mie_type *mie_ctx_get_type(
struct mie_ctx *ctx, const char *dialect_name, const char *type_name);
MIE_API const struct mie_trait *mie_ctx_get_trait(
@@ -55,11 +70,18 @@ MIE_API struct mie_type *mie_ctx_get_function_type(
const struct mie_type **out, size_t nr_out);
MIE_API struct mie_value *mie_ctx_get_null(struct mie_ctx *ctx);
MIE_API struct mie_value *mie_ctx_get_int(
struct mie_ctx *ctx, long long val, size_t nr_bits);
MIE_API struct mie_value *mie_ctx_get_float(
struct mie_ctx *ctx, double val, size_t nr_bits);
MIE_API struct mie_value *mie_ctx_get_string(struct mie_ctx *ctx, const char *s);
MIE_API struct mie_value *mie_ctx_get_index(struct mie_ctx *ctx, size_t val);
MIE_API enum mie_status mie_ctx_register_pass(
struct mie_ctx *ctx, struct mie_pass_definition *pass);
MIE_API enum mie_status mie_ctx_get_pass(
struct mie_ctx *ctx, const char *name,
const struct mie_attribute_map *args, struct mie_pass **out);
MIE_API struct mie_diag *mie_ctx_push_diag(
struct mie_ctx *ctx, struct mie_line_source *src,
const struct mie_file_cell *loc, const char *dialect,
unsigned long diag_class);
MIE_API struct mie_diag *mie_ctx_pop_diag(struct mie_ctx *ctx);
#endif

View File

@@ -0,0 +1,36 @@
#ifndef MIE_DIAG_AMENDMENT_H_
#define MIE_DIAG_AMENDMENT_H_
#include <mie/parse/file-span.h>
enum mie_diag_amendment_type {
MIE_DIAG_AMENDMENT_NONE = 0,
MIE_DIAG_AMENDMENT_ADD,
MIE_DIAG_AMENDMENT_REMOVE,
MIE_DIAG_AMENDMENT_REPLACE,
};
struct mie_diag_amendment {
enum mie_diag_amendment_type a_type;
unsigned long __x;
union {
struct {
struct mie_file_cell a_loc;
char *a_str;
} a_add;
struct {
struct mie_file_cell a_loc;
unsigned long a_length;
} a_remove;
struct {
struct mie_file_cell a_loc;
unsigned long a_length;
char *a_str;
} a_replace;
};
};
#endif

View File

@@ -0,0 +1,18 @@
#ifndef MIE_DIAG_CLASS_H_
#define MIE_DIAG_CLASS_H_
enum mie_diag_class_type {
MIE_DIAG_CLASS_NONE = 0,
MIE_DIAG_CLASS_HINT,
MIE_DIAG_CLASS_WARNING,
MIE_DIAG_CLASS_ERROR,
};
struct mie_diag_class {
unsigned int c_id;
const char *c_id_str_short, *c_id_str_long;
enum mie_diag_class_type c_type;
const char *c_title;
};
#endif

View File

@@ -0,0 +1,34 @@
#ifndef MIE_DIAG_COMPONENT_H_
#define MIE_DIAG_COMPONENT_H_
#include <blue/core/queue.h>
#include <stddef.h>
enum mie_diag_component_type {
MIE_DIAG_COMPONENT_NONE = 0,
MIE_DIAG_COMPONENT_MSG,
MIE_DIAG_COMPONENT_SNIPPET,
};
struct mie_diag_component {
enum mie_diag_component_type c_type;
b_queue_entry c_entry;
};
struct mie_diag_c_snippet {
struct mie_diag_component s_base;
unsigned long s_first_line, s_last_line;
struct mie_diag_amendment *s_amendments;
size_t s_nr_amendments;
struct mie_diag_highlight *s_highlights;
size_t s_nr_highlights;
};
struct mie_diag_c_msg {
struct mie_diag_component msg_base;
char *msg_content;
};
#endif

View File

@@ -0,0 +1,39 @@
#ifndef MIE_DIAG_DIAG_H_
#define MIE_DIAG_DIAG_H_
#include <blue/core/queue.h>
#include <mie/parse/file-span.h>
struct mie_ctx;
struct mie_diag_class;
struct mie_diag_amendment;
struct mie_diag_highlight;
enum mie_diag_type {
MIE_DIAG_NONE = 0,
MIE_DIAG_HINT,
MIE_DIAG_WARNING,
MIE_DIAG_ERROR,
};
struct mie_diag {
struct mie_dialect *diag_parent;
const struct mie_diag_class *diag_class;
struct mie_line_source *diag_src;
struct mie_file_cell diag_loc;
b_queue_entry diag_entry;
b_queue diag_components;
};
MIE_API void mie_diag_set_location(
struct mie_diag *diag, unsigned long row, unsigned long col);
MIE_API void mie_diag_push_msg(
struct mie_diag *diag, struct mie_ctx *ctx, const char *dialect,
unsigned long msg, ...);
MIE_API void mie_diag_push_snippet(
struct mie_diag *diag, unsigned long first_line, unsigned long last_line,
const struct mie_diag_amendment *amendmends, size_t nr_amendments,
const struct mie_diag_highlight *highlights, size_t nr_highlights);
#endif

View File

@@ -0,0 +1,18 @@
#ifndef MIE_DIAG_HIGHLIGHT_H_
#define MIE_DIAG_HIGHLIGHT_H_
#include <mie/parse/file-span.h>
enum mie_diag_highlight_type {
MIE_DIAG_HIGHLIGHT_NONE = 0,
MIE_DIAG_HIGHLIGHT_HINT,
MIE_DIAG_HIGHLIGHT_WARNING,
MIE_DIAG_HIGHLIGHT_ERROR,
};
struct mie_diag_highlight {
enum mie_diag_highlight_type hl_type;
struct mie_file_span hl_span;
};
#endif

View File

@@ -0,0 +1,10 @@
#ifndef MIE_DIAG_MSG_H_
#define MIE_DIAG_MSG_H_
struct mie_diag_msg {
unsigned int msg_id;
const char *msg_id_str_short, *msg_id_str_long;
const char *msg_content;
};
#endif

View File

@@ -1,62 +1,26 @@
#ifndef MIE_DIALECT_ARITH_H_
#define MIE_DIALECT_ARITH_H_
#include <mie/attribute/attribute.h>
#include <mie/misc.h>
#include <mie/value.h>
#include <stddef.h>
#include <stdint.h>
struct mie_ctx;
struct mie_dialect;
enum mie_float_width {
MIE_FLOAT_32 = 32,
MIE_FLOAT_64 = 64,
};
struct mie_int {
struct mie_value i_base;
union {
int64_t v_small;
struct {
long *a_parts;
size_t a_nr_parts;
} v_arbitrary;
} i_val;
};
struct mie_float {
struct mie_value f_base;
union {
float v_32;
double v_64;
} f_val;
};
struct mie_int_cache;
struct mie_emitter;
MIE_API struct mie_dialect *mie_arith_dialect_create(struct mie_ctx *ctx);
MIE_API struct mie_type *mie_arith_int_get_type(
struct mie_ctx *ctx, size_t bit_width);
MIE_API struct mie_type *mie_arith_float_get_type(
struct mie_ctx *ctx, size_t bit_width);
MIE_API size_t mie_arith_int_type_get_width(const struct mie_type *type);
MIE_API size_t mie_arith_float_type_get_width(const struct mie_type *type);
MIE_API struct mie_int_cache *mie_int_cache_create(void);
MIE_API void mie_int_cache_destroy(struct mie_int_cache *cache);
MIE_API struct mie_int *mie_int_cache_get(
struct mie_int_cache *cache, struct mie_ctx *ctx, size_t value,
size_t bit_width);
MIE_API struct mie_float_cache *mie_float_cache_create(void);
MIE_API void mie_float_cache_destroy(struct mie_float_cache *cache);
MIE_API struct mie_float *mie_float_cache_get(
struct mie_float_cache *cache, struct mie_ctx *ctx, double value,
size_t bit_width);
MIE_API struct mie_register *mie_arith_constant_i_put(
struct mie_emitter *e, long long value, const char *name);
MIE_API struct mie_register *mie_arith_constant_f_put(
struct mie_emitter *e, long long value, const char *name);
MIE_API struct mie_register *mie_arith_addi_put(
struct mie_emitter *e, struct mie_register *left,
struct mie_register *right, const char *name);
MIE_API struct mie_register *mie_arith_addf_put(
struct mie_emitter *e, struct mie_register *left,
struct mie_register *right, const char *name);
#endif

View File

@@ -2,22 +2,98 @@
#define MIE_DIALECT_BUILTIN_H_
#include <blue/ds/string.h>
#include <mie/attribute/attribute.h>
#include <mie/interface/interface.h>
#include <mie/misc.h>
#include <mie/value.h>
#include <mie/trait/trait.h>
#include <mie/vector.h>
struct mie_dialect;
struct mie_ctx;
struct mie_op;
struct mie_int_type;
struct mie_float_type;
enum mie_builtin_diag {
MIE_BUILTIN_E_UNRECOGNISED_TOKEN,
MIE_BUILTIN_E_UNRESOLVED_VALUE,
MIE_BUILTIN_E_UNRESOLVED_SUCCESSOR,
};
enum mie_builtin_msg {
MIE_BUILTIN_MSG_UNRECOGNISED_TOKEN,
MIE_BUILTIN_MSG_UNRESOLVED_VALUE,
MIE_BUILTIN_MSG_CANNOT_FIND_BLOCK,
MIE_BUILTIN_MSG_VALUE_DEFINED_IN_NON_DOMINANT_BLOCK,
MIE_BUILTIN_MSG_VALUE_DEFINED_AFTER_USE,
MIE_BUILTIN_MSG_VALUE_DEFINED_OUTSIDE_ISOLATED_REGION,
MIE_BUILTIN_MSG_VALUE_DEFINED_IN_BLOCK,
};
enum mie_float_width {
MIE_FLOAT_32 = 32,
MIE_FLOAT_64 = 64,
};
struct mie_string {
struct mie_value str_base;
struct mie_attribute str_base;
char *str_val;
size_t str_len;
};
struct mie_int {
struct mie_attribute i_base;
const struct mie_type *i_type;
union {
int64_t v_small;
struct {
long *a_parts;
size_t a_nr_parts;
} v_arbitrary;
} i_val;
};
struct mie_float {
struct mie_attribute f_base;
const struct mie_type *f_type;
union {
float v_32;
double v_64;
} f_val;
};
struct mie_index {
struct mie_attribute i_base;
size_t i_value;
};
struct mie_array {
struct mie_attribute a_base;
MIE_VECTOR_DECLARE(const struct mie_attribute *, a_items);
};
struct mie_type_attr {
struct mie_attribute ty_base;
const struct mie_type *ty_value;
};
struct mie_symbol {
struct mie_interface sym_base;
const char *(*sym_get_name)(const struct mie_op *);
};
struct mie_symbol_table {
struct mie_trait tab_base;
};
struct mie_int_cache;
struct mie_float_cache;
struct mie_string_cache;
struct mie_index_cache;
MIE_API struct mie_dialect *mie_builtin_dialect_create(struct mie_ctx *ctx);
@@ -26,4 +102,45 @@ MIE_API void mie_string_cache_destroy(struct mie_string_cache *cache);
MIE_API struct mie_string *mie_string_cache_get(
struct mie_string_cache *cache, struct mie_ctx *ctx, const char *val);
MIE_API struct mie_int_cache *mie_int_cache_create(void);
MIE_API void mie_int_cache_destroy(struct mie_int_cache *cache);
MIE_API struct mie_int *mie_int_cache_get(
struct mie_int_cache *cache, struct mie_ctx *ctx, size_t value,
size_t bit_width);
MIE_API struct mie_float_cache *mie_float_cache_create(void);
MIE_API void mie_float_cache_destroy(struct mie_float_cache *cache);
MIE_API struct mie_float *mie_float_cache_get(
struct mie_float_cache *cache, struct mie_ctx *ctx, double value,
size_t bit_width);
MIE_API struct mie_index_cache *mie_index_cache_create(void);
MIE_API void mie_index_cache_destroy(struct mie_index_cache *cache);
MIE_API struct mie_index *mie_index_cache_get(
struct mie_index_cache *cache, struct mie_ctx *ctx, size_t value);
MIE_API struct mie_attribute *mie_ctx_get_int(
struct mie_ctx *ctx, long long val, size_t nr_bits);
MIE_API struct mie_attribute *mie_ctx_get_float(
struct mie_ctx *ctx, double val, size_t nr_bits);
MIE_API struct mie_attribute *mie_ctx_get_string(
struct mie_ctx *ctx, const char *s);
MIE_API struct mie_attribute *mie_ctx_get_index(struct mie_ctx *ctx, size_t val);
MIE_API const char *mie_string_get_cstr(const struct mie_attribute *attrib);
MIE_API const struct mie_type *mie_type_attr_get_type(
const struct mie_attribute *attrib);
MIE_API bool mie_int_get_value(const struct mie_attribute *attrib, long long *out);
MIE_API bool mie_float_get_value(const struct mie_attribute *attrib, double *out);
MIE_API struct mie_type *mie_ctx_get_int_type(struct mie_ctx *ctx, size_t bit_width);
MIE_API struct mie_type *mie_ctx_get_float_type(
struct mie_ctx *ctx, size_t bit_width);
MIE_API struct mie_attribute *mie_type_attr_create(
struct mie_ctx *ctx, const struct mie_type *ty);
MIE_API size_t mie_int_type_get_width(const struct mie_type *type);
MIE_API size_t mie_float_type_get_width(const struct mie_type *type);
#endif

View File

@@ -2,10 +2,23 @@
#define MIE_DIALECT_CF_H_
#include <mie/misc.h>
#include <stddef.h>
struct mie_ctx;
struct mie_block;
struct mie_dialect;
struct mie_emitter;
struct mie_register;
MIE_API struct mie_dialect *mie_cf_dialect_create(struct mie_ctx *ctx);
MIE_API struct mie_op *mie_cf_br_put(
struct mie_emitter *e, struct mie_block *dest,
struct mie_register **dest_args, size_t nr_dest_args);
MIE_API struct mie_op *mie_cf_br_cond_put(
struct mie_emitter *e, struct mie_register *cond,
struct mie_block *true_block, struct mie_register **true_args,
size_t nr_true_args, struct mie_block *false_block,
struct mie_register **false_args, size_t nr_false_args);
#endif

View File

@@ -13,6 +13,9 @@ struct mie_op_definition;
struct mie_type_definition;
struct mie_trait_definition;
struct mie_diag_class;
struct mie_diag_msg;
struct mie_dialect {
mie_id d_id;
char *d_name;
@@ -23,10 +26,22 @@ struct mie_dialect {
struct mie_id_map d_types;
/* map of struct mie_trait_definition */
struct mie_id_map d_traits;
/* map of struct mie_attribute_definition */
struct mie_id_map d_attributes;
/* map of struct mie_interface_definition */
struct mie_id_map d_interfaces;
/* array of mie_diag_class */
struct mie_diag_class *d_diag_classes;
size_t d_nr_diag_classes;
/* array of mie_diag_msg */
struct mie_diag_msg *d_diag_msgs;
size_t d_nr_diag_msgs;
enum mie_status (*d_cleanup)(struct mie_dialect *);
};
MIE_API struct mie_dialect *mie_dialect_create(
struct mie_ctx *ctx, const char *name);
struct mie_ctx *ctx, const char *name, size_t size);
MIE_API const struct mie_op_definition *mie_dialect_get_op(
const struct mie_dialect *dialect, const char *name);
@@ -34,5 +49,9 @@ MIE_API const struct mie_type_definition *mie_dialect_get_type(
const struct mie_dialect *dialect, const char *name);
MIE_API const struct mie_trait_definition *mie_dialect_get_trait(
const struct mie_dialect *dialect, const char *name);
MIE_API const struct mie_attribute_definition *mie_dialect_get_attribute(
const struct mie_dialect *dialect, const char *name);
MIE_API const struct mie_interface_definition *mie_dialect_get_interface(
const struct mie_dialect *dialect, const char *name);
#endif

View File

@@ -2,10 +2,24 @@
#define MIE_DIALECT_FUNC_H_
#include <mie/misc.h>
#include <stddef.h>
struct mie_ctx;
struct mie_type;
struct mie_dialect;
struct mie_emitter;
struct mie_register;
struct mie_func_parameter {
const char *param_name;
const struct mie_type *param_type;
struct mie_register *param_reg;
};
MIE_API struct mie_dialect *mie_func_dialect_create(struct mie_ctx *ctx);
MIE_API struct mie_op *mie_func_func_put(
struct mie_emitter *e, const char *name, struct mie_func_parameter *params,
size_t nr_params, const struct mie_type **ret_types, size_t nr_ret_types);
#endif

View File

@@ -1,26 +1,14 @@
#ifndef MIE_DIALECT_INDEX_H_
#define MIE_DIALECT_INDEX_H_
#include <mie/attribute/attribute.h>
#include <mie/misc.h>
#include <mie/value.h>
#include <stddef.h>
#include <stdint.h>
struct mie_ctx;
struct mie_dialect;
struct mie_index {
struct mie_value i_base;
size_t i_value;
};
struct mie_index_cache;
MIE_API struct mie_dialect *mie_index_dialect_create(struct mie_ctx *ctx);
MIE_API struct mie_index_cache *mie_index_cache_create(void);
MIE_API void mie_index_cache_destroy(struct mie_index_cache *cache);
MIE_API struct mie_index *mie_index_cache_get(
struct mie_index_cache *cache, struct mie_ctx *ctx, size_t value);
#endif

View File

@@ -0,0 +1,13 @@
#ifndef MIE_DIALECT_MEMREF_H_
#define MIE_DIALECT_MEMREF_H_
#include <mie/misc.h>
#include <stddef.h>
#include <stdint.h>
struct mie_ctx;
struct mie_dialect;
MIE_API struct mie_dialect *mie_memref_dialect_create(struct mie_ctx *ctx);
#endif

View File

@@ -4,8 +4,19 @@
#include <mie/misc.h>
struct mie_ctx;
struct mie_type;
struct mie_region;
struct mie_dialect;
struct mie_emitter;
struct mie_register;
MIE_API struct mie_dialect *mie_scf_dialect_create(struct mie_ctx *ctx);
MIE_API struct mie_op *mie_scf_if_put(
struct mie_emitter *e, struct mie_register *cond,
const struct mie_type *result_type, struct mie_region **out_true,
struct mie_region **out_false, const char *name);
MIE_API struct mie_op *mie_scf_yield_put(
struct mie_emitter *e, struct mie_register *value);
#endif

View File

@@ -0,0 +1,17 @@
#ifndef MIE_INTERFACE_INTERFACE_DEFINITION_H_
#define MIE_INTERFACE_INTERFACE_DEFINITION_H_
#include <mie/id.h>
#include <mie/misc.h>
struct mie_interface_definition {
mie_id if_id;
const struct mie_dialect *if_parent;
char *if_name;
size_t if_size;
};
MIE_API struct mie_interface_definition *mie_interface_definition_create(
struct mie_dialect *parent, const char *name);
#endif

View File

@@ -0,0 +1,22 @@
#ifndef MIE_INTERFACE_INTERFACE_MAP_H_
#define MIE_INTERFACE_INTERFACE_MAP_H_
#include <mie/id.h>
#include <mie/misc.h>
struct mie_interface;
struct mie_interface_map {
struct mie_id_map m_entries;
};
MIE_API void mie_interface_map_init(struct mie_interface_map *map);
MIE_API void mie_interface_map_cleanup(struct mie_interface_map *map);
MIE_API enum mie_status mie_interface_map_put(
struct mie_interface_map *map, struct mie_interface *iface);
MIE_API const struct mie_interface *mie_interface_map_get(
const struct mie_interface_map *map, const char *dialect,
const char *iface);
#endif

View File

@@ -0,0 +1,19 @@
#ifndef MIE_INTERFACE_INTERFACE_H_
#define MIE_INTERFACE_INTERFACE_H_
#include <mie/id.h>
#include <mie/misc.h>
struct mie_dialect;
struct mie_interface_definition;
struct mie_interface {
mie_id if_id;
const struct mie_interface_definition *if_def;
};
MIE_API struct mie_interface *mie_interface_create(
const struct mie_interface_definition *def);
MIE_API void mie_interface_destroy(struct mie_interface *iface);
#endif

View File

@@ -6,16 +6,69 @@
#include <mie/name.h>
#include <mie/vector.h>
#define MIE_BLOCK_ID_INVALID ((size_t)0)
struct mie_op;
struct mie_register;
struct mie_block {
struct mie_name b_name;
MIE_VECTOR_DECLARE(struct mie_register *, b_params);
MIE_VECTOR_DECLARE(struct mie_op, b_ops);
struct mie_block_predecessor {
struct mie_block *p_block;
};
struct mie_block {
struct mie_name b_name;
struct mie_region *b_parent;
/* immediate predecessor blocks */
MIE_VECTOR_DECLARE(struct mie_block_predecessor, b_ipred);
/* used by struct mie_region */
unsigned int b_id;
struct mie_block *b_idom;
// struct mie_block *b_sdom, *b_dfs_parent;
b_queue_entry b_entry;
MIE_VECTOR_DECLARE(struct mie_register, b_params);
/* queue of struct mie_op */
b_queue b_ops;
};
extern struct mie_vector_ops mie_block_vector_ops;
MIE_API struct mie_op *mie_block_get_first_op(const struct mie_block *block);
MIE_API struct mie_op *mie_block_get_prev_op(
const struct mie_block *block, const struct mie_op *before);
MIE_API struct mie_op *mie_block_get_next_op(
const struct mie_block *block, const struct mie_op *after);
MIE_API struct mie_op *mie_block_get_last_op(const struct mie_block *block);
MIE_API struct mie_op *mie_block_get_terminator(const struct mie_block *block);
MIE_API struct mie_op_successor *mie_block_get_first_successor(
const struct mie_block *block);
MIE_API struct mie_op_successor *mie_block_get_prev_successor(
const struct mie_block *block, const struct mie_op_successor *before);
MIE_API struct mie_op_successor *mie_block_get_next_successor(
const struct mie_block *block, const struct mie_op_successor *after);
MIE_API struct mie_op_successor *mie_block_get_last_successor(
const struct mie_block *block);
MIE_API struct mie_block_predecessor *mie_block_get_first_predecessor(
const struct mie_block *block);
MIE_API struct mie_block_predecessor *mie_block_get_prev_predecessor(
const struct mie_block *block, const struct mie_block_predecessor *before);
MIE_API struct mie_block_predecessor *mie_block_get_next_predecessor(
const struct mie_block *block, const struct mie_block_predecessor *after);
MIE_API struct mie_block_predecessor *mie_block_get_last_predecessor(
const struct mie_block *block);
MIE_API struct mie_op *mie_block_add_op(struct mie_block *block);
MIE_API struct mie_op *mie_block_add_op_after(
struct mie_block *block, struct mie_op *after);
MIE_API struct mie_register *mie_block_add_param(struct mie_block *block);
MIE_API struct mie_register *mie_block_find_register(
const struct mie_block *block, const char *name,
const struct mie_op *start_point);
#endif

View File

@@ -0,0 +1,39 @@
#ifndef MIE_IR_BUILDER_H_
#define MIE_IR_BUILDER_H_
#include <mie/ir/emit.h>
#include <mie/misc.h>
#include <stddef.h>
struct mie_op;
struct mie_ctx;
struct mie_type;
struct mie_name;
struct mie_block;
struct mie_region;
struct mie_register;
struct mie_builder;
MIE_API struct mie_builder *mie_builder_create(
struct mie_ctx *ctx, struct mie_op *root);
MIE_API void mie_builder_destroy(struct mie_builder *builder);
MIE_API struct mie_ctx *mie_builder_get_ctx(struct mie_builder *builder);
MIE_API struct mie_block *mie_builder_get_current_block(struct mie_builder *builder);
MIE_API void mie_builder_step_into_op(
struct mie_builder *builder, struct mie_op *op);
MIE_API void mie_builder_step_into_region(
struct mie_builder *builder, struct mie_region *region);
MIE_API void mie_builder_step_into_block(
struct mie_builder *builder, struct mie_block *block);
MIE_API void mie_builder_step_out(struct mie_builder *builder);
MIE_API struct mie_op *mie_builder_put_op(
struct mie_builder *builder, const char *dialect, const char *op,
struct mie_register **args, size_t nr_args);
MIE_API enum mie_status mie_builder_put_name(
struct mie_builder *builder, struct mie_name *name, const char *hint);
#endif

42
mie/include/mie/ir/emit.h Normal file
View File

@@ -0,0 +1,42 @@
#ifndef MIE_IR_EMIT_H_
#define MIE_IR_EMIT_H_
#include <mie/misc.h>
#include <mie/status.h>
#include <stddef.h>
#define MIE_EMITTER(p) ((struct mie_emitter *)(p))
struct mie_op;
struct mie_name;
struct mie_block;
struct mie_register;
struct mie_emitter;
typedef struct mie_ctx *(*mie_emit_get_ctx)(const struct mie_emitter *);
typedef enum mie_status (*mie_emit_put_name)(
struct mie_emitter *, struct mie_name *, const char *);
typedef struct mie_op *(*mie_emit_put_op)(
struct mie_emitter *, const char *, const char *,
struct mie_register **, size_t);
typedef struct mie_block *(*mie_emit_put_block)(
struct mie_emitter *, struct mie_block *);
struct mie_emitter {
mie_emit_get_ctx e_get_ctx;
mie_emit_put_name e_put_name;
mie_emit_put_op e_put_op;
mie_emit_put_block e_put_block;
};
MIE_API struct mie_ctx *mie_emitter_get_ctx(struct mie_emitter *emitter);
MIE_API enum mie_status mie_emitter_put_name(
struct mie_emitter *emitter, struct mie_name *name, const char *hint);
MIE_API struct mie_op *mie_emitter_put_op(
struct mie_emitter *emitter, const char *dialect_name,
const char *op_name, struct mie_register **args, size_t nr_args);
MIE_API struct mie_block *mie_emitter_put_block(
struct mie_emitter *emitter, struct mie_block *insert_point);
#endif

View File

@@ -1,22 +0,0 @@
#ifndef MIE_IR_MODULE_H_
#define MIE_IR_MODULE_H_
#include <blue/core/stream.h>
#include <mie/misc.h>
#include <mie/name.h>
#include <mie/vector.h>
#include <stddef.h>
struct mie_op;
struct mie_module {
struct mie_name_map *m_names;
MIE_VECTOR_DECLARE(struct mie_op, m_ops);
};
MIE_API struct mie_module *mie_module_create(void);
MIE_API void mie_module_destroy(struct mie_module *mod);
MIE_API struct mie_op *mie_module_add_op(struct mie_module *mod);
#endif

View File

@@ -4,6 +4,7 @@
#include <blue/core/btree.h>
#include <blue/core/stream.h>
#include <mie/id.h>
#include <mie/interface/interface-map.h>
#include <mie/status.h>
#include <mie/trait/trait-table.h>
@@ -11,6 +12,7 @@
#define MIE_OP_MAX_RESULTS 8
struct mie_op;
struct mie_printer;
struct mie_parser;
struct mie_dialect;
@@ -96,10 +98,11 @@ struct mie_op_definition {
char *op_name;
struct mie_trait_table op_traits;
struct mie_interface_map op_iface;
const struct mie_op_param op_params[MIE_OP_MAX_PARAMS];
const struct mie_op_result op_results[MIE_OP_MAX_RESULTS];
enum mie_status (*op_print)(const struct mie_op *, b_stream *);
enum mie_status (*op_print)(struct mie_printer *, const struct mie_op *);
enum mie_status (*op_parse)(struct mie_parser *, struct mie_op *);
};
@@ -108,5 +111,7 @@ MIE_API struct mie_op_definition *mie_op_definition_create(
MIE_API enum mie_status mie_op_definition_add_trait(
struct mie_op_definition *op, const struct mie_trait *trait);
MIE_API enum mie_status mie_op_definition_add_interface(
struct mie_op_definition *op, struct mie_interface *inface);
#endif

View File

@@ -3,13 +3,14 @@
#include "mie/vector.h"
#include <mie/attribute/attribute-map.h>
#include <mie/ir/register.h>
#include <mie/misc.h>
#include <mie/name.h>
#include <mie/parse/file-span.h>
struct mie_ctx;
struct mie_type;
struct mie_value;
struct mie_block;
struct mie_region;
@@ -23,17 +24,12 @@ enum mie_op_flags {
MIE_OP_F_SUCCESSOR_RESOLVED = 0x04u,
};
struct mie_op_attribute {
char *attrib_name;
struct mie_value *attrib_value;
};
struct mie_op_arg {
enum mie_op_flags arg_flags;
struct mie_file_span arg_span;
union {
/* only valid if F_ARG_RESOLVED is set in arg_flags */
struct mie_register *arg_value;
struct mie_register_use arg_value;
/* only valid if F_ARG_RESOLVED is NOT set in arg_flags */
struct mie_register_ref arg_unresolved;
};
@@ -41,6 +37,7 @@ struct mie_op_arg {
struct mie_op_successor {
enum mie_op_flags s_flags;
struct mie_file_span s_name_span;
union {
/* only valid if F_SUCCESSOR_RESOLVED is set in s_flags; */
@@ -54,25 +51,68 @@ struct mie_op_successor {
struct mie_op {
enum mie_op_flags op_flags;
/* used by struct mie_block */
b_queue_entry op_entry;
/* these pointers are only valid if the F_OP_RESOLVED flag is set */
const struct mie_dialect *op_dialect;
struct mie_line_source *op_src;
/* this pointer is only valid if the F_OP_RESOLVED flag is set */
const struct mie_op_definition *op_info;
struct mie_block *op_container;
struct mie_file_span op_name_span;
/* only valid if the F_RESOLVED flag is NOT set */
char *op_name;
MIE_VECTOR_DECLARE(struct mie_region, op_regions);
b_queue op_regions;
MIE_VECTOR_DECLARE(struct mie_op_successor, op_successors);
MIE_VECTOR_DECLARE(struct mie_op_attribute, op_attrib);
struct mie_attribute_map op_attrib;
MIE_VECTOR_DECLARE(struct mie_op_arg, op_args);
MIE_VECTOR_DECLARE(struct mie_register *, op_result);
MIE_VECTOR_DECLARE(struct mie_register, op_result);
};
MIE_API struct mie_op *mie_op_create(void);
MIE_API void mie_op_destroy(struct mie_op *op);
MIE_API void mie_op_init(struct mie_op *op);
MIE_API void mie_op_cleanup(struct mie_op *op);
MIE_API size_t mie_op_get_name(const struct mie_op *op, char *out, size_t max);
MIE_API bool mie_op_resolve_self(struct mie_op *op, struct mie_ctx *ctx);
MIE_API bool mie_op_resolve_args(struct mie_op *op, struct mie_ctx *ctx);
MIE_API bool mie_op_resolve_successors(struct mie_op *op, struct mie_ctx *ctx);
MIE_API struct mie_op_arg *mie_op_add_arg(struct mie_op *op);
MIE_API struct mie_register *mie_op_add_result(
struct mie_op *op, const struct mie_type *ty);
MIE_API struct mie_op_successor *mie_op_add_successor(
struct mie_op *op, struct mie_block *block, struct mie_register **args,
size_t nr_args);
MIE_API struct mie_region *mie_op_add_region(struct mie_op *op);
MIE_API struct mie_op_successor *mie_op_add_successor(struct mie_op *op);
MIE_API bool mie_op_is(
const struct mie_op *op, const char *dialect_name, const char *op_name);
MIE_API bool mie_op_has_trait(
const struct mie_op *op, const char *dialect_name, const char *trait_name);
MIE_API bool mie_op_has_interface(
const struct mie_op *op, const char *dialect_name, const char *iface_name);
MIE_API struct mie_op *mie_op_get_parent(const struct mie_op *op);
MIE_API struct mie_region *mie_op_get_first_region(const struct mie_op *op);
MIE_API struct mie_region *mie_op_get_prev_region(
const struct mie_op *op, const struct mie_region *before);
MIE_API struct mie_region *mie_op_get_next_region(
const struct mie_op *op, const struct mie_region *after);
MIE_API struct mie_region *mie_op_get_last_region(const struct mie_op *op);
MIE_API struct mie_register *mie_op_get_arg(const struct mie_op *op, size_t index);
MIE_API struct mie_register *mie_op_get_result_with_name(
const struct mie_op *op, const char *name);
MIE_API struct mie_op *mie_op_get_first_child_op(const struct mie_op *op);
MIE_API struct mie_op *mie_op_get_last_child_op(const struct mie_op *op);
MIE_API const struct mie_type *mie_op_arg_get_type(const struct mie_op_arg *arg);
#endif

Some files were not shown because too many files have changed in this diff Show More