Compare commits
77 Commits
3c4af9c26e
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 6abdf8f993 | |||
| 870b2bfbac | |||
| 5344c02b48 | |||
| 4a4f0c483a | |||
| f37ee90b0e | |||
| 3f901ed83a | |||
| b28efa2d08 | |||
| 5835d25679 | |||
| d4fbd75a59 | |||
| 0b1d4697a2 | |||
| cd49417972 | |||
| bd5ba9e9fd | |||
| b5fa40d4d8 | |||
| a67e4b6688 | |||
| 5873326138 | |||
| 00152cac56 | |||
| 287983fa95 | |||
| 8cdbf5389c | |||
| 00c7c3d5ea | |||
| 9e546ee32f | |||
| 00ba3a3d87 | |||
| d44bc8c5c0 | |||
| a22e95d88d | |||
| 0a791fdfb2 | |||
| fe511011ec | |||
| e8534f8d70 | |||
| bf8c966c03 | |||
| 7d30e8f3ff | |||
| e9d2c0fbc7 | |||
| a710ef0b24 | |||
| 0277931ca1 | |||
| ac7860b6bd | |||
| 29984307aa | |||
| ac96248d7e | |||
| 593eda2797 | |||
| d0ac8a9fed | |||
| 89ebbcc462 | |||
| 554a1e7342 | |||
| 6d1e308ff1 | |||
| 58bd336eb8 | |||
| 008966e046 | |||
| 83343a5eea | |||
| 76166167c9 | |||
| f6f6131f52 | |||
| 33f9ccd871 | |||
| 0c4ebe7f39 | |||
| 72de4ce845 | |||
| 937dc57c4e | |||
| b8c0d139a8 | |||
| abf43a9022 | |||
| 4700ce7778 | |||
| 95c51045b6 | |||
| e62c9c4775 | |||
| a97678a1c2 | |||
| 5e13824706 | |||
| da140ed0d1 | |||
| cb3d37043c | |||
| 55161cd6c8 | |||
| 759aaf9fd8 | |||
| 04af390fe8 | |||
| 0add39f304 | |||
| 429ec770b5 | |||
| 092c9969cf | |||
| 6fcc3c8edd | |||
| d335cd9823 | |||
| c014895051 | |||
| 76477be5bd | |||
| ee9e2d3050 | |||
| e5ecdd40e8 | |||
| c410e0a6e3 | |||
| 3ba20e5ed4 | |||
| f19dfaa050 | |||
| 2869e98556 | |||
| b289c6e2de | |||
| fd72d217f6 | |||
| e1f7f46d3e | |||
| 65905bc55b |
118
.clang-format
118
.clang-format
@@ -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"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
project(mie C)
|
||||
|
||||
if (WIN32)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 } : () -> ()
|
||||
}) : () -> ()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -25,3 +25,15 @@ struct mie_attribute_definition *mie_attribute_definition_create(
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -149,6 +149,7 @@ enum mie_status mie_attribute_map_put(
|
||||
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);
|
||||
@@ -162,6 +163,17 @@ enum mie_status mie_attribute_map_put(
|
||||
|
||||
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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
183
mie/ctx.c
183
mie/ctx.c
@@ -4,12 +4,17 @@
|
||||
#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>
|
||||
@@ -35,6 +40,10 @@
|
||||
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);
|
||||
@@ -57,15 +66,35 @@ struct mie_ctx *mie_ctx_create(void)
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -95,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);
|
||||
@@ -120,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)
|
||||
{
|
||||
@@ -246,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);
|
||||
@@ -293,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);
|
||||
@@ -358,3 +407,121 @@ struct mie_type *mie_ctx_get_function_type(
|
||||
mie_id_map_put_id(&ctx->ctx_types, &new_type->func_base.ty_id);
|
||||
return (struct mie_type *)new_type;
|
||||
}
|
||||
|
||||
enum mie_status mie_ctx_register_pass(
|
||||
struct mie_ctx *ctx, struct mie_pass_definition *pass)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
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_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_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)
|
||||
{
|
||||
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_diag *mie_ctx_pop_diag(struct mie_ctx *ctx)
|
||||
{
|
||||
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
106
mie/diag/diag.c
Normal 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
6
mie/diag/diag.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef _DIAG_DIAG_H_
|
||||
#define _DIAG_DIAG_H_
|
||||
|
||||
#include <blue/core/queue.h>
|
||||
|
||||
#endif
|
||||
@@ -5,5 +5,7 @@
|
||||
|
||||
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()
|
||||
|
||||
@@ -1,9 +1,25 @@
|
||||
#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(const struct mie_op *op, b_stream *out)
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,29 @@
|
||||
#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(const struct mie_op *op, b_stream *out)
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -12,6 +32,22 @@ 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);
|
||||
|
||||
80
mie/dialect/arith/op/cmpi.c
Normal file
80
mie/dialect/arith/op/cmpi.c
Normal 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()
|
||||
81
mie/dialect/arith/op/constant.c
Normal file
81
mie/dialect/arith/op/constant.c
Normal 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()
|
||||
@@ -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()
|
||||
|
||||
@@ -51,30 +51,52 @@ static enum mie_status parse(
|
||||
struct mie_file_span span;
|
||||
|
||||
if (!mie_parser_parse_float(ctx, &value, &span)) {
|
||||
return false;
|
||||
return MIE_ERR_BAD_SYNTAX;
|
||||
}
|
||||
|
||||
if (!mie_parser_parse_symbol(ctx, MIE_SYM_COLON)) {
|
||||
return false;
|
||||
return MIE_ERR_BAD_SYNTAX;
|
||||
}
|
||||
|
||||
const struct mie_type *type = NULL;
|
||||
if (!mie_parser_parse_type(ctx, &type)) {
|
||||
return false;
|
||||
return MIE_ERR_BAD_SYNTAX;
|
||||
}
|
||||
|
||||
size_t width = mie_float_type_get_width(type);
|
||||
if (width == (size_t)-1) {
|
||||
return false;
|
||||
return MIE_ERR_BAD_SYNTAX;
|
||||
}
|
||||
|
||||
struct mie_attribute *v
|
||||
= mie_ctx_get_float(mie_parser_get_mie_ctx(ctx), value, width);
|
||||
if (!v) {
|
||||
return false;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,20 +15,34 @@ static enum mie_status print(
|
||||
{
|
||||
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;
|
||||
if (!(out->p_flags & MIE_PRINT_F_ABBREVIATED)) {
|
||||
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 : i%zu",
|
||||
int_val->i_val.v_small, int_ty->i_width);
|
||||
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 : i%zu", int_ty->i_width);
|
||||
b_stream_write_fmt(out->p_stream, NULL, "INF", int_ty->i_width);
|
||||
}
|
||||
|
||||
if (!(out->p_flags & MIE_PRINT_F_ABBREVIATED)) {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -42,30 +56,43 @@ static enum mie_status parse(
|
||||
struct mie_file_span span;
|
||||
|
||||
if (!mie_parser_parse_int(ctx, &value, &span)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!mie_parser_parse_symbol(ctx, MIE_SYM_COLON)) {
|
||||
return false;
|
||||
return MIE_ERR_BAD_SYNTAX;
|
||||
}
|
||||
|
||||
const struct mie_type *type = NULL;
|
||||
if (!mie_parser_parse_type(ctx, &type)) {
|
||||
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);
|
||||
}
|
||||
|
||||
size_t width = mie_int_type_get_width(type);
|
||||
if (width == (size_t)-1) {
|
||||
return false;
|
||||
return MIE_ERR_BAD_SYNTAX;
|
||||
}
|
||||
|
||||
struct mie_attribute *v
|
||||
= mie_ctx_get_int(mie_parser_get_mie_ctx(ctx), value, width);
|
||||
if (!v) {
|
||||
return false;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,18 +26,28 @@ static enum mie_status parse(
|
||||
b_string *str = mie_parser_get_tempstr(ctx);
|
||||
struct mie_file_span span;
|
||||
if (!mie_parser_parse_string(ctx, str, &span)) {
|
||||
return false;
|
||||
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 false;
|
||||
return MIE_ERR_NO_MEMORY;
|
||||
}
|
||||
|
||||
*out = v;
|
||||
return true;
|
||||
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")
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#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>
|
||||
@@ -81,17 +83,25 @@ struct mie_attribute *mie_ctx_get_index(struct mie_ctx *ctx, size_t val)
|
||||
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_ADD_TYPE(mie_builtin_string);
|
||||
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_ATTRIBUTE(mie_builtin_string);
|
||||
MIE_DIALECT_ADD_TYPE(mie_builtin_string);
|
||||
MIE_DIALECT_ADD_ATTRIBUTE(mie_builtin_int);
|
||||
MIE_DIALECT_ADD_ATTRIBUTE(mie_builtin_float);
|
||||
MIE_DIALECT_ADD_TRAIT(mie_builtin_isolated_from_above);
|
||||
MIE_DIALECT_ADD_TRAIT(mie_builtin_symbol_table);
|
||||
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()
|
||||
|
||||
36
mie/dialect/builtin/diag.c
Normal file
36
mie/dialect/builtin/diag.c
Normal 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)
|
||||
30
mie/dialect/builtin/op/module.c
Normal file
30
mie/dialect/builtin/op/module.c
Normal 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()
|
||||
@@ -34,7 +34,7 @@ struct mie_type *mie_ctx_get_float_type(struct mie_ctx *ctx, size_t bit_width)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
type->f_base.ty_name = b_bstr_fmt("builtin.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;
|
||||
|
||||
|
||||
@@ -15,17 +15,7 @@ static void type_init(
|
||||
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" : "!builtin.index",
|
||||
NULL);
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
MIE_TYPE_DEFINITION_BEGIN(mie_builtin_index, "index")
|
||||
MIE_TYPE_DEFINITION_STRUCT(struct index_type);
|
||||
MIE_TYPE_DEFINITION_INIT(type_init);
|
||||
MIE_TYPE_DEFINITION_PRINT(print);
|
||||
MIE_TYPE_DEFINITION_END()
|
||||
|
||||
@@ -34,7 +34,7 @@ struct mie_type *mie_ctx_get_int_type(struct mie_ctx *ctx, size_t bit_width)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
type->i_base.ty_name = b_bstr_fmt("builtin.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;
|
||||
|
||||
|
||||
@@ -15,6 +15,10 @@ static void type_init(
|
||||
|
||||
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) ? "str" : "!builtin.string",
|
||||
NULL);
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,31 @@
|
||||
#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(const struct mie_op *op, b_stream *out)
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -12,6 +34,23 @@ 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);
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
#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(const struct mie_op *op, b_stream *out)
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -12,6 +21,21 @@ 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);
|
||||
|
||||
@@ -3,5 +3,7 @@
|
||||
#include <mie/macros.h>
|
||||
|
||||
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()
|
||||
|
||||
@@ -1,13 +1,71 @@
|
||||
#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(const struct mie_op *op, b_stream *out)
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -16,9 +74,63 @@ 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, ¶m_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()
|
||||
|
||||
49
mie/dialect/func/op/return.c
Normal file
49
mie/dialect/func/op/return.c
Normal 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()
|
||||
23
mie/dialect/func/trait/function-like.c
Normal file
23
mie/dialect/func/trait/function-like.c
Normal 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()
|
||||
11
mie/dialect/memref/memref.c
Normal file
11
mie/dialect/memref/memref.c
Normal 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()
|
||||
18
mie/dialect/memref/op/load.c
Normal file
18
mie/dialect/memref/op/load.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <mie/ctx.h>
|
||||
#include <mie/ir/op-definition.h>
|
||||
#include <mie/macros.h>
|
||||
|
||||
static enum mie_status print(struct mie_printer *printer, const struct mie_op *op)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
|
||||
{
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
MIE_OP_DEFINITION_BEGIN(mie_memref_load, "load")
|
||||
MIE_OP_DEFINITION_PRINT(print);
|
||||
MIE_OP_DEFINITION_PARSE(parse);
|
||||
MIE_OP_DEFINITION_END()
|
||||
52
mie/dialect/memref/type/memref.c
Normal file
52
mie/dialect/memref/type/memref.c
Normal 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()
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,48 @@
|
||||
#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(const struct mie_op *op, b_stream *out)
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -12,6 +51,35 @@ 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);
|
||||
|
||||
@@ -1,9 +1,32 @@
|
||||
#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(const struct mie_op *op, b_stream *out)
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -12,6 +35,11 @@ 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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
2
mie/id.c
2
mie/id.c
@@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,4 +26,8 @@ struct mie_attribute_definition {
|
||||
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
|
||||
|
||||
@@ -1,10 +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
|
||||
|
||||
@@ -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
|
||||
@@ -27,17 +32,24 @@ struct mie_ctx {
|
||||
struct mie_id_map ctx_traits;
|
||||
/* 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);
|
||||
@@ -59,4 +71,17 @@ MIE_API struct mie_type *mie_ctx_get_function_type(
|
||||
|
||||
MIE_API struct mie_value *mie_ctx_get_null(struct mie_ctx *ctx);
|
||||
|
||||
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
|
||||
|
||||
36
mie/include/mie/diag/amendment.h
Normal file
36
mie/include/mie/diag/amendment.h
Normal 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
|
||||
18
mie/include/mie/diag/class.h
Normal file
18
mie/include/mie/diag/class.h
Normal 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
|
||||
34
mie/include/mie/diag/component.h
Normal file
34
mie/include/mie/diag/component.h
Normal 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
|
||||
39
mie/include/mie/diag/diag.h
Normal file
39
mie/include/mie/diag/diag.h
Normal 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
|
||||
18
mie/include/mie/diag/highlight.h
Normal file
18
mie/include/mie/diag/highlight.h
Normal 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
|
||||
10
mie/include/mie/diag/msg.h
Normal file
10
mie/include/mie/diag/msg.h
Normal 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
|
||||
0
mie/include/mie/diag/snippet.h
Normal file
0
mie/include/mie/diag/snippet.h
Normal file
@@ -8,7 +8,19 @@
|
||||
|
||||
struct mie_ctx;
|
||||
struct mie_dialect;
|
||||
struct mie_emitter;
|
||||
|
||||
MIE_API struct mie_dialect *mie_arith_dialect_create(struct mie_ctx *ctx);
|
||||
|
||||
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
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <mie/interface/interface.h>
|
||||
#include <mie/misc.h>
|
||||
#include <mie/trait/trait.h>
|
||||
#include <mie/vector.h>
|
||||
|
||||
struct mie_dialect;
|
||||
|
||||
@@ -14,6 +15,22 @@ 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,
|
||||
@@ -54,6 +71,16 @@ struct mie_index {
|
||||
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 *);
|
||||
@@ -100,10 +127,19 @@ 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);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
@@ -27,6 +30,12 @@ struct mie_dialect {
|
||||
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 *);
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
39
mie/include/mie/ir/builder.h
Normal file
39
mie/include/mie/ir/builder.h
Normal 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
42
mie/include/mie/ir/emit.h
Normal 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
|
||||
@@ -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
|
||||
@@ -12,6 +12,7 @@
|
||||
#define MIE_OP_MAX_RESULTS 8
|
||||
|
||||
struct mie_op;
|
||||
struct mie_printer;
|
||||
struct mie_parser;
|
||||
struct mie_dialect;
|
||||
|
||||
@@ -101,7 +102,7 @@ struct mie_op_definition {
|
||||
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 *);
|
||||
};
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
#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;
|
||||
@@ -29,7 +29,7 @@ struct mie_op_arg {
|
||||
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;
|
||||
};
|
||||
@@ -37,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; */
|
||||
@@ -50,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);
|
||||
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
|
||||
|
||||
@@ -1,17 +1,55 @@
|
||||
#ifndef MIE_IR_REGION_H_
|
||||
#define MIE_IR_REGION_H_
|
||||
|
||||
#include <blue/core/btree.h>
|
||||
#include <blue/core/queue.h>
|
||||
#include <mie/misc.h>
|
||||
#include <mie/vector.h>
|
||||
#include <stddef.h>
|
||||
|
||||
struct mie_op;
|
||||
struct mie_ctx;
|
||||
struct mie_block;
|
||||
|
||||
struct mie_region {
|
||||
struct mie_name_map *r_names;
|
||||
MIE_VECTOR_DECLARE(struct mie_block *, r_blocks);
|
||||
struct mie_op *r_parent;
|
||||
/* used by struct mie_op */
|
||||
b_queue_entry r_entry;
|
||||
/* queue of struct mie_block */
|
||||
b_queue r_blocks;
|
||||
/* bst of struct mie_block, as numbered by a depth-first search.
|
||||
* this ordering is recalculated by mie_region_refresh_dominance */
|
||||
b_btree r_blocks_s;
|
||||
};
|
||||
|
||||
MIE_API struct mie_block *mie_region_get_first_block(
|
||||
const struct mie_region *region);
|
||||
MIE_API struct mie_block *mie_region_get_prev_block(
|
||||
const struct mie_region *region, const struct mie_block *before);
|
||||
MIE_API struct mie_block *mie_region_get_next_block(
|
||||
const struct mie_region *region, const struct mie_block *after);
|
||||
MIE_API struct mie_block *mie_region_get_last_block(const struct mie_region *region);
|
||||
|
||||
MIE_API struct mie_block *mie_region_add_block(struct mie_region *region);
|
||||
MIE_API struct mie_block *mie_region_add_block_after(
|
||||
struct mie_region *region, struct mie_block *after);
|
||||
MIE_API struct mie_block *mie_region_find_block(
|
||||
const struct mie_region *region, const char *name);
|
||||
MIE_API struct mie_register *mie_region_find_register(
|
||||
const struct mie_region *region, const char *name);
|
||||
|
||||
/* calculate the dominance-tree of all blocks in a region.
|
||||
* this function populates the following attributes of every block in the
|
||||
* region:
|
||||
* b_id
|
||||
* b_node
|
||||
* b_parent
|
||||
* as well as the following attributes of the region itself:
|
||||
* r_blocks_s
|
||||
* only top-level blocks and ops are considered by this function. if an op
|
||||
* within the region itself contains one/more child regions, these are ignored.
|
||||
*/
|
||||
MIE_API void mie_region_refresh_dominance(struct mie_region *region);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
#define MIE_IR_REGISTER_H_
|
||||
|
||||
#include <mie/name.h>
|
||||
#include <mie/vector.h>
|
||||
|
||||
struct mie_op;
|
||||
struct mie_register;
|
||||
struct mie_target_register;
|
||||
|
||||
enum mie_register_flags {
|
||||
@@ -25,8 +28,16 @@ struct mie_register_ref {
|
||||
const struct mie_type *reg_type;
|
||||
};
|
||||
|
||||
/* represents a use of/resolved reference to a mie_register */
|
||||
struct mie_register_use {
|
||||
b_queue_entry u_entry;
|
||||
struct mie_op *u_user;
|
||||
struct mie_register *u_reg;
|
||||
};
|
||||
|
||||
struct mie_register {
|
||||
enum mie_register_flags reg_flags;
|
||||
struct mie_file_span reg_span;
|
||||
union {
|
||||
/* only valid if F_VIRTUAL is set. */
|
||||
struct mie_name reg_name;
|
||||
@@ -46,6 +57,19 @@ struct mie_register {
|
||||
* for which this register is a parameter
|
||||
* if this is a BLOCK_PARAM register, this pointer is NULL */
|
||||
struct mie_op *reg_op;
|
||||
/* list of struct mie_register_use, representing all the places
|
||||
* where this register is used. */
|
||||
b_queue reg_use;
|
||||
};
|
||||
|
||||
extern struct mie_vector_ops mie_register_vector_ops;
|
||||
extern struct mie_vector_ops mie_register_use_vector_ops;
|
||||
|
||||
MIE_API void mie_register_move(struct mie_register *dest, struct mie_register *src);
|
||||
MIE_API void mie_register_cleanup(struct mie_register *reg);
|
||||
|
||||
MIE_API void mie_register_use_move(
|
||||
struct mie_register_use *dest, struct mie_register_use *src);
|
||||
MIE_API void mie_register_use_cleanup(struct mie_register_use *reg);
|
||||
|
||||
#endif
|
||||
|
||||
14
mie/include/mie/ir/resolve.h
Normal file
14
mie/include/mie/ir/resolve.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef MIE_IR_RESOLVE_H_
|
||||
#define MIE_IR_RESOLVE_H_
|
||||
|
||||
#include <mie/misc.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
struct mie_op;
|
||||
struct mie_ctx;
|
||||
|
||||
MIE_API bool mie_resolve_op_self(struct mie_op *op, struct mie_ctx *ctx);
|
||||
MIE_API bool mie_resolve_op_args(struct mie_op *op, struct mie_ctx *ctx);
|
||||
MIE_API bool mie_resolve_op_successors(struct mie_op *op, struct mie_ctx *ctx);
|
||||
|
||||
#endif
|
||||
70
mie/include/mie/ir/walk.h
Normal file
70
mie/include/mie/ir/walk.h
Normal file
@@ -0,0 +1,70 @@
|
||||
#ifndef MIE_IR_WALK_H_
|
||||
#define MIE_IR_WALK_H_
|
||||
|
||||
#include <blue/core/queue.h>
|
||||
#include <mie/misc.h>
|
||||
#include <mie/status.h>
|
||||
#include <stddef.h>
|
||||
|
||||
struct mie_op;
|
||||
|
||||
enum mie_walker_flags {
|
||||
MIE_WALKER_F_NONE = 0x00u,
|
||||
|
||||
/* 0: default behaviour */
|
||||
MIE_WALKER_F_PREORDER = 0x00u,
|
||||
MIE_WALKER_F_POSTORDER = 0x01u,
|
||||
|
||||
/* 0: default behaviour */
|
||||
MIE_WALKER_F_FORWARD = 0x00u,
|
||||
MIE_WALKER_F_BACKWARD = 0x02u,
|
||||
|
||||
MIE_WALKER_F_RECURSIVE = 0x04u,
|
||||
|
||||
MIE_WALKER_F_INCLUDE_OPS = 0x08u,
|
||||
MIE_WALKER_F_INCLUDE_REGIONS = 0x10u,
|
||||
MIE_WALKER_F_INCLUDE_BLOCKS = 0x20u,
|
||||
};
|
||||
|
||||
enum mie_walk_item_type {
|
||||
MIE_WALK_ITEM_NONE = 0,
|
||||
MIE_WALK_ITEM_OP,
|
||||
MIE_WALK_ITEM_BLOCK,
|
||||
MIE_WALK_ITEM_REGION,
|
||||
};
|
||||
|
||||
struct mie_walk_item {
|
||||
int _f;
|
||||
b_queue_entry _e;
|
||||
enum mie_walk_item_type i_type;
|
||||
// size_t i_index;
|
||||
size_t i_depth;
|
||||
union {
|
||||
struct mie_op *i_op;
|
||||
struct mie_block *i_block;
|
||||
struct mie_region *i_region;
|
||||
};
|
||||
};
|
||||
|
||||
struct mie_walker {
|
||||
enum mie_walker_flags w_flags;
|
||||
union {
|
||||
/* used for recursive walks */
|
||||
b_queue w_stack;
|
||||
/* used for non-recursive walks */
|
||||
struct {
|
||||
struct mie_walk_item w_region, w_block, w_op;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
MIE_API void mie_walker_begin(
|
||||
struct mie_walker *walker, const struct mie_op *op,
|
||||
enum mie_walker_flags flags);
|
||||
MIE_API void mie_walker_end(struct mie_walker *walker);
|
||||
|
||||
MIE_API enum mie_status mie_walker_step(struct mie_walker *walker);
|
||||
|
||||
MIE_API struct mie_walk_item *mie_walker_get(struct mie_walker *walker);
|
||||
|
||||
#endif
|
||||
@@ -1,187 +1,334 @@
|
||||
#ifndef MIE_MACROS_H_
|
||||
#define MIE_MACROS_H_
|
||||
|
||||
#define __MIE_DIALECT_BEGIN(func_prefix, c_struct, dialect_name) \
|
||||
struct mie_dialect *func_prefix##_dialect_create(struct mie_ctx *ctx) \
|
||||
{ \
|
||||
struct mie_dialect *self = mie_dialect_create( \
|
||||
ctx, dialect_name, sizeof(c_struct)); \
|
||||
if (!self) { \
|
||||
return NULL; \
|
||||
} \
|
||||
struct mie_op_definition *op = NULL; \
|
||||
struct mie_type_definition *type = NULL; \
|
||||
struct mie_trait_definition *trait = NULL; \
|
||||
struct mie_attribute_definition *attribute = NULL; \
|
||||
struct mie_interface_definition *interface = NULL;
|
||||
/******************************************************************************/
|
||||
/* DIALECT DEFINITION MACROS */
|
||||
/******************************************************************************/
|
||||
|
||||
#define __MIE_DIALECT_END() \
|
||||
return self; \
|
||||
}
|
||||
#define MIE_DIALECT_BEGIN(func_prefix, c_struct, dialect_name) \
|
||||
struct mie_dialect* func_prefix##_dialect_create(struct mie_ctx* ctx) \
|
||||
{ \
|
||||
struct mie_dialect* self = mie_dialect_create( \
|
||||
ctx, dialect_name, sizeof(c_struct)); \
|
||||
if (!self) { \
|
||||
return NULL; \
|
||||
} \
|
||||
struct mie_op_definition* op = NULL; \
|
||||
struct mie_type_definition* type = NULL; \
|
||||
struct mie_trait_definition* trait = NULL; \
|
||||
struct mie_attribute_definition* attribute = NULL; \
|
||||
struct mie_interface_definition* interface = NULL;
|
||||
|
||||
#define __MIE_OP_DEFINITION_BEGIN(func_prefix, op_name) \
|
||||
struct mie_op_definition *func_prefix##_op_create( \
|
||||
struct mie_dialect *d, struct mie_ctx *ctx) \
|
||||
{ \
|
||||
struct mie_op_definition *op \
|
||||
= mie_op_definition_create(d, op_name); \
|
||||
if (!op) { \
|
||||
return NULL; \
|
||||
} \
|
||||
const struct mie_trait *trait = NULL; \
|
||||
struct mie_interface *i = NULL; \
|
||||
const struct mie_interface_definition *id = NULL;
|
||||
#define MIE_DIALECT_END() \
|
||||
return self; \
|
||||
}
|
||||
|
||||
#define __MIE_OP_DEFINITION_END() \
|
||||
return op; \
|
||||
}
|
||||
#define MIE_DIALECT_INIT(func) func(self)
|
||||
#define MIE_DIALECT_CLEANUP(func) self->d_cleanup = (func)
|
||||
#define MIE_DIALECT_DIAG_CLASS_LIST(list) \
|
||||
self->d_diag_classes = (list); \
|
||||
self->d_nr_diag_classes = (list##_count)
|
||||
#define MIE_DIALECT_DIAG_MSG_LIST(list) \
|
||||
self->d_diag_msgs = (list); \
|
||||
self->d_nr_diag_msgs = (list##_count)
|
||||
#define MIE_DIALECT_ADD_OP(op_id) \
|
||||
extern struct mie_op_definition* op_id##_op_create( \
|
||||
struct mie_dialect*, struct mie_ctx*); \
|
||||
op = op_id##_op_create(self, ctx)
|
||||
#define MIE_DIALECT_ADD_TYPE(type_id) \
|
||||
extern struct mie_type_definition* type_id##_type_create( \
|
||||
struct mie_dialect*, struct mie_ctx*); \
|
||||
type = type_id##_type_create(self, ctx)
|
||||
#define MIE_DIALECT_ADD_TRAIT(trait_id) \
|
||||
extern struct mie_trait_definition* trait_id##_trait_create( \
|
||||
struct mie_dialect*, struct mie_ctx*); \
|
||||
trait = trait_id##_trait_create(self, ctx)
|
||||
#define MIE_DIALECT_ADD_ATTRIBUTE(attr_id) \
|
||||
extern struct mie_attribute_definition* attr_id##_attribute_create( \
|
||||
struct mie_dialect*, struct mie_ctx*); \
|
||||
attribute = attr_id##_attribute_create(self, ctx)
|
||||
#define MIE_DIALECT_ADD_INTERFACE(iface_id) \
|
||||
extern struct mie_interface_definition* iface_id##_interface_create( \
|
||||
struct mie_dialect*, struct mie_ctx*); \
|
||||
interface = iface_id##_interface_create(self, ctx)
|
||||
|
||||
#define __MIE_TYPE_DEFINITION_BEGIN(func_prefix, type_name) \
|
||||
struct mie_type_definition *func_prefix##_type_create( \
|
||||
struct mie_dialect *d, struct mie_ctx *ctx) \
|
||||
{ \
|
||||
struct mie_type_definition *type \
|
||||
= mie_type_definition_create(d, type_name); \
|
||||
if (!type) { \
|
||||
return NULL; \
|
||||
} \
|
||||
const struct mie_trait *trait = NULL;
|
||||
/******************************************************************************/
|
||||
/* OP DEFINITION MACROS */
|
||||
/******************************************************************************/
|
||||
|
||||
#define __MIE_TYPE_DEFINITION_END() \
|
||||
return type; \
|
||||
}
|
||||
#define MIE_OP_DEFINITION_BEGIN(func_prefix, op_name) \
|
||||
struct mie_op_definition* func_prefix##_op_create( \
|
||||
struct mie_dialect* d, struct mie_ctx* ctx) \
|
||||
{ \
|
||||
struct mie_op_definition* op \
|
||||
= mie_op_definition_create(d, op_name); \
|
||||
if (!op) { \
|
||||
return NULL; \
|
||||
} \
|
||||
const struct mie_trait* trait = NULL; \
|
||||
struct mie_interface* i = NULL; \
|
||||
const struct mie_interface_definition* id = NULL;
|
||||
|
||||
#define __MIE_TRAIT_DEFINITION_BEGIN(func_prefix, trait_name) \
|
||||
struct mie_trait_definition *func_prefix##_trait_create( \
|
||||
struct mie_dialect *d, struct mie_ctx *ctx) \
|
||||
{ \
|
||||
struct mie_trait_definition *trait \
|
||||
= mie_trait_definition_create(d, trait_name); \
|
||||
if (!trait) { \
|
||||
return NULL; \
|
||||
}
|
||||
#define MIE_OP_DEFINITION_END() \
|
||||
return op; \
|
||||
}
|
||||
|
||||
#define __MIE_TRAIT_DEFINITION_END() \
|
||||
return trait; \
|
||||
}
|
||||
|
||||
#define __MIE_ATTRIBUTE_DEFINITION_BEGIN(func_prefix, attribute_name) \
|
||||
struct mie_attribute_definition *func_prefix##_attribute_create( \
|
||||
struct mie_dialect *d, struct mie_ctx *ctx) \
|
||||
{ \
|
||||
struct mie_attribute_definition *attribute \
|
||||
= mie_attribute_definition_create(d, attribute_name); \
|
||||
if (!attribute) { \
|
||||
return NULL; \
|
||||
}
|
||||
|
||||
#define __MIE_ATTRIBUTE_DEFINITION_END() \
|
||||
return attribute; \
|
||||
}
|
||||
|
||||
#define __MIE_INTERFACE_DEFINITION_BEGIN(func_prefix, iface_name) \
|
||||
struct mie_interface_definition *func_prefix##_interface_create( \
|
||||
struct mie_dialect *d, struct mie_ctx *ctx) \
|
||||
{ \
|
||||
struct mie_interface_definition *i \
|
||||
= mie_interface_definition_create(d, iface_name); \
|
||||
if (!i) { \
|
||||
return NULL; \
|
||||
}
|
||||
|
||||
#define __MIE_INTERFACE_DEFINITION_END() \
|
||||
return i; \
|
||||
}
|
||||
|
||||
#define __MIE_DIALECT_INIT(func) func(self)
|
||||
#define __MIE_DIALECT_CLEANUP(func) self->d_cleanup = (func)
|
||||
#define __MIE_DIALECT_ADD_OP(op_id) \
|
||||
extern struct mie_op_definition *op_id##_op_create( \
|
||||
struct mie_dialect *, struct mie_ctx *); \
|
||||
op = op_id##_op_create(self, ctx)
|
||||
#define __MIE_DIALECT_ADD_TYPE(type_id) \
|
||||
extern struct mie_type_definition *type_id##_type_create( \
|
||||
struct mie_dialect *, struct mie_ctx *); \
|
||||
type = type_id##_type_create(self, ctx)
|
||||
#define __MIE_DIALECT_ADD_TRAIT(trait_id) \
|
||||
extern struct mie_trait_definition *trait_id##_trait_create( \
|
||||
struct mie_dialect *, struct mie_ctx *); \
|
||||
trait = trait_id##_trait_create(self, ctx)
|
||||
#define __MIE_DIALECT_ADD_ATTRIBUTE(attribute_id) \
|
||||
extern struct mie_attribute_definition *attribute_id##_attribute_create( \
|
||||
struct mie_dialect *, struct mie_ctx *); \
|
||||
attribute = attribute_id##_attribute_create(self, ctx)
|
||||
#define __MIE_DIALECT_ADD_INTERFACE(interface_id) \
|
||||
extern struct mie_interface_definition *interface_id##_interface_create( \
|
||||
struct mie_dialect *, struct mie_ctx *); \
|
||||
interface = interface_id##_interface_create(self, ctx)
|
||||
|
||||
#define MIE_DIALECT_BEGIN(c_sym, c_struct, name) \
|
||||
__MIE_DIALECT_BEGIN(c_sym, c_struct, name)
|
||||
#define MIE_DIALECT_END() __MIE_DIALECT_END()
|
||||
#define MIE_DIALECT_INIT(func) __MIE_DIALECT_INIT(func)
|
||||
#define MIE_DIALECT_CLEANUP(func) __MIE_DIALECT_CLEANUP(func)
|
||||
#define MIE_DIALECT_ADD_OP(c_sym) __MIE_DIALECT_ADD_OP(c_sym)
|
||||
#define MIE_DIALECT_ADD_TYPE(c_sym) __MIE_DIALECT_ADD_TYPE(c_sym)
|
||||
#define MIE_DIALECT_ADD_TRAIT(c_sym) __MIE_DIALECT_ADD_TRAIT(c_sym)
|
||||
#define MIE_DIALECT_ADD_ATTRIBUTE(c_sym) __MIE_DIALECT_ADD_ATTRIBUTE(c_sym)
|
||||
#define MIE_DIALECT_ADD_INTERFACE(c_sym) __MIE_DIALECT_ADD_INTERFACE(c_sym)
|
||||
|
||||
#define MIE_OP_DEFINITION_BEGIN(c_sym, op) __MIE_OP_DEFINITION_BEGIN(c_sym, op)
|
||||
#define MIE_OP_DEFINITION_END() __MIE_OP_DEFINITION_END()
|
||||
#define MIE_OP_DEFINITION_PRINT(func) op->op_print = (func)
|
||||
#define MIE_OP_DEFINITION_PARSE(func) op->op_parse = (func)
|
||||
#define MIE_OP_DEFINITION_TRAIT(trait_dialect, trait_name) \
|
||||
trait = mie_ctx_get_trait(ctx, trait_dialect, trait_name); \
|
||||
mie_op_definition_add_trait(op, trait);
|
||||
#define MIE_OP_INTERFACE_BEGIN(dialect_name, if_name, c_struct) \
|
||||
id = mie_ctx_get_interface_definition(ctx, dialect_name, if_name); \
|
||||
if (id) { \
|
||||
c_struct *iface = (c_struct *)mie_interface_create(id);
|
||||
#define MIE_OP_DEFINITION_PRINT(func) op->op_print = (func)
|
||||
#define MIE_OP_DEFINITION_PARSE(func) op->op_parse = (func)
|
||||
#define MIE_OP_DEFINITION_TRAIT(trait_dialect, trait_name) \
|
||||
trait = mie_ctx_get_trait(ctx, trait_dialect, trait_name); \
|
||||
mie_op_definition_add_trait(op, trait);
|
||||
#define MIE_OP_INTERFACE_BEGIN(dialect_name, if_name, c_struct) \
|
||||
id = mie_ctx_get_interface_definition(ctx, dialect_name, if_name); \
|
||||
if (id) { \
|
||||
c_struct* iface = (c_struct*)mie_interface_create(id);
|
||||
#define MIE_OP_INTERFACE_FUNC(func_name) iface->func_name
|
||||
#define MIE_OP_INTERFACE_END() \
|
||||
mie_op_definition_add_interface(op, (struct mie_interface*)iface); \
|
||||
}
|
||||
|
||||
#define MIE_OP_INTERFACE_END() \
|
||||
mie_op_definition_add_interface(op, (struct mie_interface *)iface); \
|
||||
}
|
||||
/******************************************************************************/
|
||||
/* TYPE DEFINITION MACROS */
|
||||
/******************************************************************************/
|
||||
|
||||
#define MIE_TYPE_DEFINITION_BEGIN(c_sym, type) \
|
||||
__MIE_TYPE_DEFINITION_BEGIN(c_sym, type)
|
||||
#define MIE_TYPE_DEFINITION_END() __MIE_TYPE_DEFINITION_END()
|
||||
#define MIE_TYPE_DEFINITION_FLAGS(flags) type->ty_flags = flags
|
||||
#define MIE_TYPE_DEFINITION_STRUCT(name) type->ty_data_size = sizeof(name)
|
||||
#define MIE_TYPE_DEFINITION_INIT(func) type->ty_init = (func)
|
||||
#define MIE_TYPE_DEFINITION_PRINT(func) type->ty_print = (func)
|
||||
#define MIE_TYPE_DEFINITION_PARSE(func) type->ty_parse = (func)
|
||||
#define MIE_TYPE_DEFINITION_BEGIN(func_prefix, type_name) \
|
||||
struct mie_type_definition* func_prefix##_type_create( \
|
||||
struct mie_dialect* d, struct mie_ctx* ctx) \
|
||||
{ \
|
||||
struct mie_type_definition* type \
|
||||
= mie_type_definition_create(d, type_name); \
|
||||
if (!type) { \
|
||||
return NULL; \
|
||||
} \
|
||||
const struct mie_trait* trait = NULL;
|
||||
|
||||
#define MIE_TYPE_DEFINITION_END() \
|
||||
return type; \
|
||||
}
|
||||
|
||||
#define MIE_TYPE_DEFINITION_FLAGS(flags) type->ty_flags = flags
|
||||
#define MIE_TYPE_DEFINITION_STRUCT(name) type->ty_data_size = sizeof(name)
|
||||
#define MIE_TYPE_DEFINITION_INIT(func) type->ty_init = (func)
|
||||
#define MIE_TYPE_DEFINITION_PRINT(func) type->ty_print = (func)
|
||||
#define MIE_TYPE_DEFINITION_PARSE(func) type->ty_parse = (func)
|
||||
#define MIE_TYPE_DEFINITION_BUILD_ID(func) type->ty_build_id = (func)
|
||||
#define MIE_TYPE_DEFINITION_INIT(func) type->ty_init = (func)
|
||||
#define MIE_TYPE_DEFINITION_CLEANUP(func) type->ty_cleanup = (func)
|
||||
#define MIE_TYPE_DEFINITION_TRAIT(trait_dialect, trait_name) \
|
||||
trait = mie_ctx_get_trait(ctx, trait_dialect, trait_name); \
|
||||
mie_type_definition_add_trait(type, trait);
|
||||
#define MIE_TYPE_DEFINITION_INIT(func) type->ty_init = (func)
|
||||
#define MIE_TYPE_DEFINITION_CLEANUP(func) type->ty_cleanup = (func)
|
||||
#define MIE_TYPE_DEFINITION_TRAIT(trait_dialect, trait_name) \
|
||||
trait = mie_ctx_get_trait(ctx, trait_dialect, trait_name); \
|
||||
mie_type_definition_add_trait(type, trait);
|
||||
|
||||
/******************************************************************************/
|
||||
/* TRAIT DEFINITION MACROS */
|
||||
/******************************************************************************/
|
||||
|
||||
#define MIE_TRAIT_DEFINITION_BEGIN(func_prefix, trait_name) \
|
||||
struct mie_trait_definition* func_prefix##_trait_create( \
|
||||
struct mie_dialect* d, struct mie_ctx* ctx) \
|
||||
{ \
|
||||
struct mie_trait_definition* trait \
|
||||
= mie_trait_definition_create(d, trait_name); \
|
||||
if (!trait) { \
|
||||
return NULL; \
|
||||
}
|
||||
|
||||
#define MIE_TRAIT_DEFINITION_END() \
|
||||
return trait; \
|
||||
}
|
||||
|
||||
#define MIE_TRAIT_DEFINITION_BEGIN(c_sym, trait) \
|
||||
__MIE_TRAIT_DEFINITION_BEGIN(c_sym, trait)
|
||||
#define MIE_TRAIT_DEFINITION_END() __MIE_TRAIT_DEFINITION_END()
|
||||
#define MIE_TRAIT_DEFINITION_TARGETS(targets) trait->tr_target = (targets)
|
||||
#define MIE_TRAIT_DEFINITION_STRUCT(name) trait->tr_data_size = sizeof(name)
|
||||
#define MIE_TRAIT_DEFINITION_PRINT(func) trait->tr_print = (func)
|
||||
#define MIE_TRAIT_DEFINITION_BUILD_ID(func) trait->tr_build_id = (func)
|
||||
#define MIE_TRAIT_DEFINITION_CLEANUP(func) trait->tr_cleanup = (func)
|
||||
#define MIE_TRAIT_DEFINITION_VALIDATE(func) trait->tr_validate = (func)
|
||||
#define MIE_TRAIT_DEFINITION_STRUCT(name) trait->tr_data_size = sizeof(name)
|
||||
#define MIE_TRAIT_DEFINITION_PRINT(func) trait->tr_print = (func)
|
||||
#define MIE_TRAIT_DEFINITION_BUILD_ID(func) trait->tr_build_id = (func)
|
||||
#define MIE_TRAIT_DEFINITION_CLEANUP(func) trait->tr_cleanup = (func)
|
||||
#define MIE_TRAIT_DEFINITION_VALIDATE(func) trait->tr_validate = (func)
|
||||
|
||||
#define MIE_ATTRIBUTE_DEFINITION_BEGIN(c_sym, attribute) \
|
||||
__MIE_ATTRIBUTE_DEFINITION_BEGIN(c_sym, attribute)
|
||||
#define MIE_ATTRIBUTE_DEFINITION_END() __MIE_ATTRIBUTE_DEFINITION_END()
|
||||
#define MIE_ATTRIBUTE_DEFINITION_STRUCT(name) \
|
||||
attribute->a_data_size = sizeof(name)
|
||||
#define MIE_ATTRIBUTE_DEFINITION_INIT(func) attribute->a_init = (func)
|
||||
/******************************************************************************/
|
||||
/* ATTRIBUTE DEFINITION MACROS */
|
||||
/******************************************************************************/
|
||||
|
||||
#define MIE_ATTRIBUTE_DEFINITION_BEGIN(func_prefix, attribute_name) \
|
||||
struct mie_attribute_definition* func_prefix##_attribute_create( \
|
||||
struct mie_dialect* d, struct mie_ctx* ctx) \
|
||||
{ \
|
||||
struct mie_attribute_definition* attribute \
|
||||
= mie_attribute_definition_create(d, attribute_name); \
|
||||
if (!attribute) { \
|
||||
return NULL; \
|
||||
}
|
||||
|
||||
#define MIE_ATTRIBUTE_DEFINITION_END() \
|
||||
return attribute; \
|
||||
}
|
||||
|
||||
#define MIE_ATTRIBUTE_DEFINITION_STRUCT(name) \
|
||||
attribute->a_data_size = sizeof(name)
|
||||
#define MIE_ATTRIBUTE_DEFINITION_INIT(func) attribute->a_init = (func)
|
||||
#define MIE_ATTRIBUTE_DEFINITION_CLEANUP(func) attribute->a_cleanup = (func)
|
||||
#define MIE_ATTRIBUTE_DEFINITION_PRINT(func) attribute->a_print = (func)
|
||||
#define MIE_ATTRIBUTE_DEFINITION_PARSE(func) attribute->a_parse = (func)
|
||||
#define MIE_ATTRIBUTE_DEFINITION_PRINT(func) attribute->a_print = (func)
|
||||
#define MIE_ATTRIBUTE_DEFINITION_PARSE(func) attribute->a_parse = (func)
|
||||
|
||||
/******************************************************************************/
|
||||
/* INTERFACE DEFINITION MACROS */
|
||||
/******************************************************************************/
|
||||
|
||||
#define MIE_INTERFACE_DEFINITION_BEGIN(func_prefix, iface_name) \
|
||||
struct mie_interface_definition* func_prefix##_interface_create( \
|
||||
struct mie_dialect* d, struct mie_ctx* ctx) \
|
||||
{ \
|
||||
struct mie_interface_definition* i \
|
||||
= mie_interface_definition_create(d, iface_name); \
|
||||
if (!i) { \
|
||||
return NULL; \
|
||||
}
|
||||
|
||||
#define MIE_INTERFACE_DEFINITION_END() \
|
||||
return i; \
|
||||
}
|
||||
|
||||
#define MIE_INTERFACE_DEFINITION_BEGIN(c_sym, iface) \
|
||||
__MIE_INTERFACE_DEFINITION_BEGIN(c_sym, iface)
|
||||
#define MIE_INTERFACE_DEFINITION_END() __MIE_INTERFACE_DEFINITION_END()
|
||||
#define MIE_INTERFACE_DEFINITION_STRUCT(name) i->if_size = sizeof(name)
|
||||
|
||||
/******************************************************************************/
|
||||
/* PASS DEFINITION MACROS */
|
||||
/******************************************************************************/
|
||||
|
||||
#define MIE_PASS_DEFINITION_BEGIN(prefix) \
|
||||
struct mie_pass_definition* prefix##_pass_create(struct mie_ctx* ctx) \
|
||||
{ \
|
||||
struct mie_pass_definition* p = mie_pass_definition_create(); \
|
||||
if (!p) { \
|
||||
return NULL; \
|
||||
}
|
||||
|
||||
#define MIE_PASS_DEFINITION_END() \
|
||||
if (mie_ctx_register_pass(ctx, p) != MIE_SUCCESS) { \
|
||||
return NULL; \
|
||||
} \
|
||||
return p; \
|
||||
}
|
||||
|
||||
#define MIE_PASS_NAME(name) p->p_name = (name)
|
||||
#define MIE_PASS_DESCRIPTION(desc) p->p_description = (desc)
|
||||
#define MIE_PASS_STRUCT(c_struct) p->p_data_size = sizeof(c_struct)
|
||||
#define MIE_PASS_TYPE(type) p->p_type = (type)
|
||||
#define MIE_PASS_INIT(func) p->p_init = (func)
|
||||
#define MIE_PASS_TRANSFORM(func) \
|
||||
p->p_transform = (func); \
|
||||
p->p_type = MIE_PASS_TRANSFORM
|
||||
#define MIE_PASS_ANALYSE(func) \
|
||||
p->p_analyse = (func); \
|
||||
p->p_type = MIE_PASS_ANALYSE
|
||||
#define MIE_PASS_FILTER_OP(dialect, op) \
|
||||
p->p_filter.f_op = mie_ctx_get_op_definition(ctx, dialect, op)
|
||||
#define MIE_PASS_FILTER_TRAIT(dialect, tr) \
|
||||
p->p_filter.f_trait = mie_ctx_get_trait_definition(ctx, dialect, tr)
|
||||
#define MIE_PASS_FILTER_INTERFACE(dialect, ifn) \
|
||||
p->p_filter.f_iface = mie_ctx_get_iface_definition(ctx, dialect, ifn)
|
||||
|
||||
/******************************************************************************/
|
||||
/* PASS GROUP MACROS */
|
||||
/******************************************************************************/
|
||||
|
||||
#define MIE_PASS_GROUP_BEGIN(prefix) \
|
||||
enum mie_status prefix##_passes_register(struct mie_ctx* ctx) \
|
||||
{ \
|
||||
struct mie_pass_definition* pass = NULL;
|
||||
|
||||
#define MIE_PASS_GROUP_END() \
|
||||
return MIE_SUCCESS; \
|
||||
}
|
||||
|
||||
#define MIE_PASS_GROUP_DECLARATION(prefix) \
|
||||
enum mie_status prefix##_passes_register(struct mie_ctx*);
|
||||
|
||||
#define MIE_PASS_GROUP_ADD_PASS(id) \
|
||||
do { \
|
||||
extern struct mie_pass_definition* id##_pass_create( \
|
||||
struct mie_ctx*); \
|
||||
pass = id##_pass_create(ctx); \
|
||||
if (!pass) { \
|
||||
return MIE_ERR_INTERNAL_FAILURE; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#endif
|
||||
|
||||
/******************************************************************************/
|
||||
/* REWRITE PATTERN MACROS */
|
||||
/******************************************************************************/
|
||||
|
||||
#define MIE_REWRITE_PATTERN_BEGIN(name) \
|
||||
struct mie_pattern* name##_create(struct mie_pattern_set* set) \
|
||||
{ \
|
||||
struct mie_pattern* self = mie_pattern_set_add(set); \
|
||||
if (!self) { \
|
||||
return NULL; \
|
||||
}
|
||||
#define MIE_REWRITE_PATTERN_END() \
|
||||
return self; \
|
||||
}
|
||||
|
||||
#define MIE_REWRITE_PATTERN_ROOT(dialect_name, op_name) \
|
||||
self->p_root.t_dialect_name = (dialect_name); \
|
||||
self->p_root.t_op_name = (op_name)
|
||||
#define MIE_REWRITE_PATTERN_MATCH(func) self->p_match = (func)
|
||||
#define MIE_REWRITE_PATTERN_REWRITE(func) self->p_rewrite = (func)
|
||||
|
||||
/******************************************************************************/
|
||||
/* DIAG CLASS MACROS */
|
||||
/******************************************************************************/
|
||||
|
||||
#define __MIE_CNAME2(x, y) x##_##y
|
||||
#define __MIE_CNAME1(x, y) __MIE_CNAME2(x, y)
|
||||
#define __MIE_CNAME(fun) __MIE_CNAME1(MIE_DIAG_CLASS_PREFIX, fun)
|
||||
|
||||
#define __MIE_CSNAME2(x, y) #x #y
|
||||
#define __MIE_CSNAME1(x, y) __MIE_CSNAME2(x, y)
|
||||
#define __MIE_CSNAME(fun) __MIE_CSNAME1(MIE_DIAG_CLASS_PREFIX, fun)
|
||||
|
||||
#define MIE_DIAG_CLASS_LIST_EXTERN(list_name) \
|
||||
extern struct mie_diag_class list_name[]; \
|
||||
extern const size_t list_name##_count
|
||||
#define MIE_DIAG_CLASS_LIST_BEGIN(list_name) \
|
||||
struct mie_diag_class list_name[] = {
|
||||
#define MIE_DIAG_CLASS_LIST_END(list_name) \
|
||||
} \
|
||||
; \
|
||||
const size_t list_name##_count = sizeof(list_name) / sizeof(list_name[0]);
|
||||
#define MIE_DIAG_CLASS(id, type, title) \
|
||||
[__MIE_CNAME(id)] = { \
|
||||
.c_id = __MIE_CNAME(id), \
|
||||
.c_type = MIE_DIAG_CLASS_##type, \
|
||||
.c_title = (title), \
|
||||
.c_id_str_short = #id, \
|
||||
.c_id_str_long = __MIE_CSNAME(id), \
|
||||
},
|
||||
|
||||
/******************************************************************************/
|
||||
/* DIAG MSG MACROS */
|
||||
/******************************************************************************/
|
||||
|
||||
#define __MIE_MNAME2(x, y) x##_##y
|
||||
#define __MIE_MNAME1(x, y) __MIE_CNAME2(x, y)
|
||||
#define __MIE_MNAME(fun) __MIE_CNAME1(MIE_DIAG_MSG_PREFIX, fun)
|
||||
|
||||
#define __MIE_MSNAME2(x, y) #x #y
|
||||
#define __MIE_MSNAME1(x, y) __MIE_CSNAME2(x, y)
|
||||
#define __MIE_MSNAME(fun) __MIE_CSNAME1(MIE_DIAG_MSG_PREFIX, fun)
|
||||
|
||||
#define MIE_DIAG_MSG_LIST_EXTERN(list_name) \
|
||||
extern struct mie_diag_msg list_name[]; \
|
||||
extern const size_t list_name##_count
|
||||
#define MIE_DIAG_MSG_LIST_BEGIN(list_name) \
|
||||
struct mie_diag_msg list_name[] = {
|
||||
#define MIE_DIAG_MSG_LIST_END(list_name) \
|
||||
} \
|
||||
; \
|
||||
const size_t list_name##_count = sizeof(list_name) / sizeof(list_name[0]);
|
||||
#define MIE_DIAG_MSG(id, content) \
|
||||
[__MIE_MNAME(id)] = { \
|
||||
.msg_id = __MIE_MNAME(id), \
|
||||
.msg_content = (content), \
|
||||
.msg_id_str_short = #id, \
|
||||
.msg_id_str_long = __MIE_MSNAME(id), \
|
||||
},
|
||||
|
||||
@@ -35,26 +35,31 @@ struct mie_name_map_entry {
|
||||
};
|
||||
};
|
||||
|
||||
struct mie_name_bucket {
|
||||
struct mie_name_map_entry b_base;
|
||||
b_queue b_names;
|
||||
};
|
||||
|
||||
/* stores a unique name, and forms a binary tree of similar entries.
|
||||
* this struct is designed to be embedded directly within a larger struct
|
||||
* (rather than just as a pointer), allowing the larger struct to be part
|
||||
* of a name map. Because of this, mie_name CANNOT be used in any memory that
|
||||
* may be re-allocated. If a mie_name is moved after it is added to a
|
||||
* mie_name_map, the internal bst pointers that make up the map will be
|
||||
* invalidated, causing some very obscure memory-related errors. */
|
||||
* invalidated, causing some very obscure memory-related errors.
|
||||
*
|
||||
* if mie_name IS stored in movable memory, care must be taken to use
|
||||
* mie_name_move rather than memcpy/memmove to move the mie_name from
|
||||
* one location to another. */
|
||||
struct mie_name {
|
||||
struct mie_name_map_entry n_base;
|
||||
struct mie_name_map *n_parent;
|
||||
struct mie_name_bucket *n_bucket;
|
||||
char *n_str;
|
||||
|
||||
/* if this name was read from a file, these structs can be used to
|
||||
* record the location within the file where the name is found. */
|
||||
struct mie_file_span n_start, n_end;
|
||||
};
|
||||
|
||||
struct mie_name_bucket {
|
||||
struct mie_name_map_entry b_base;
|
||||
b_queue b_names;
|
||||
struct mie_file_span n_span;
|
||||
};
|
||||
|
||||
struct mie_name_map {
|
||||
@@ -73,6 +78,7 @@ extern struct mie_name *mie_name_map_put(
|
||||
struct mie_name_map *map, struct mie_name *entry, const char *hint,
|
||||
enum mie_name_map_flags flags);
|
||||
|
||||
extern void mie_name_move(struct mie_name *dst, struct mie_name *src);
|
||||
extern void mie_name_destroy(struct mie_name *name);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,17 +1,22 @@
|
||||
#ifndef MIE_PARSE_LEX_H_
|
||||
#define MIE_PARSE_LEX_H_
|
||||
|
||||
#include <blue/core/queue.h>
|
||||
#include <blue/core/stream.h>
|
||||
#include <mie/misc.h>
|
||||
#include <mie/status.h>
|
||||
|
||||
struct mie_lex;
|
||||
struct mie_ctx;
|
||||
struct mie_token;
|
||||
struct mie_line_source;
|
||||
|
||||
MIE_API struct mie_lex *mie_lex_create(b_stream *src);
|
||||
MIE_API struct mie_lex *mie_lex_create(
|
||||
struct mie_line_source *src, struct mie_ctx *ctx);
|
||||
MIE_API void mie_lex_destroy(struct mie_lex *lex);
|
||||
|
||||
MIE_API enum mie_status mie_lex_get_status(const struct mie_lex *lex);
|
||||
MIE_API struct mie_line_source *mie_lex_get_line_source(const struct mie_lex *lex);
|
||||
MIE_API struct mie_token *mie_lex_peek(struct mie_lex *lex);
|
||||
MIE_API void mie_lex_advance(struct mie_lex *lex);
|
||||
|
||||
|
||||
35
mie/include/mie/parse/line-source.h
Normal file
35
mie/include/mie/parse/line-source.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef MIE_PARSE_LINE_SOURCE_H_
|
||||
#define MIE_PARSE_LINE_SOURCE_H_
|
||||
|
||||
#include <blue/core/stream.h>
|
||||
#include <blue/ds/array.h>
|
||||
#include <blue/ds/string.h>
|
||||
#include <mie/misc.h>
|
||||
#include <mie/parse/file-span.h>
|
||||
#include <mie/status.h>
|
||||
|
||||
struct mie_line_source {
|
||||
b_stream *s_stream;
|
||||
const char *s_path;
|
||||
b_string *s_linebuf;
|
||||
b_iterator *s_linebuf_ptr;
|
||||
b_array *s_lines;
|
||||
|
||||
struct mie_file_cell s_cursor;
|
||||
};
|
||||
|
||||
MIE_API enum mie_status mie_line_source_init(
|
||||
struct mie_line_source *src, const char *path, b_stream *stream);
|
||||
MIE_API void mie_line_source_cleanup(struct mie_line_source *src);
|
||||
|
||||
MIE_API const char *mie_line_source_get_path(const struct mie_line_source *src);
|
||||
MIE_API const struct mie_file_cell *mie_line_source_get_cursor(
|
||||
const struct mie_line_source *src);
|
||||
MIE_API b_wchar mie_line_source_peekc(struct mie_line_source *src);
|
||||
MIE_API b_wchar mie_line_source_getc(struct mie_line_source *src);
|
||||
MIE_API enum mie_status mie_line_source_get_row(
|
||||
struct mie_line_source *src, size_t row, const b_string **out);
|
||||
|
||||
MIE_API bool mie_line_source_input_available(struct mie_line_source *src);
|
||||
|
||||
#endif
|
||||
@@ -102,12 +102,12 @@ MIE_API bool mie_parser_parse_register(
|
||||
struct mie_register *out);
|
||||
MIE_API bool mie_parser_parse_register_list(
|
||||
struct mie_parser *ctx, struct mie_name_map *names,
|
||||
MIE_VECTOR_REF_PARAM(struct mie_register *, out));
|
||||
MIE_VECTOR_REF_PARAM(struct mie_register, out));
|
||||
|
||||
MIE_API bool mie_parser_parse_region(
|
||||
struct mie_parser *ctx, struct mie_region *region);
|
||||
struct mie_parser *ctx, struct mie_op *parent, struct mie_region *region);
|
||||
MIE_API bool mie_parser_parse_region_list(
|
||||
struct mie_parser *ctx, MIE_VECTOR_REF_PARAM(struct mie_region, out));
|
||||
struct mie_parser *ctx, struct mie_op *parent);
|
||||
MIE_API bool mie_parser_parse_anonymous_block(
|
||||
struct mie_parser *ctx, struct mie_name_map *names,
|
||||
struct mie_block *block);
|
||||
|
||||
10
mie/include/mie/pass/builtin.h
Normal file
10
mie/include/mie/pass/builtin.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef MIE_PASS_BUILTIN_H_
|
||||
#define MIE_PASS_BUILTIN_H_
|
||||
|
||||
#include <mie/misc.h>
|
||||
|
||||
struct mie_ctx;
|
||||
|
||||
MIE_API enum mie_status mie_builtin_passes_register(struct mie_ctx *);
|
||||
|
||||
#endif
|
||||
69
mie/include/mie/pass/pass-definition.h
Normal file
69
mie/include/mie/pass/pass-definition.h
Normal file
@@ -0,0 +1,69 @@
|
||||
#ifndef MIE_PASS_PASS_DEFINITION_H_
|
||||
#define MIE_PASS_PASS_DEFINITION_H_
|
||||
|
||||
#include <mie/id.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define MIE_PASS_CONTINUE \
|
||||
((struct mie_pass_result) {.r_type = MIE_PASS_RESULT_CONTINUE, \
|
||||
.r_status = MIE_SUCCESS})
|
||||
#define MIE_PASS_INTERRUPT(status) \
|
||||
((struct mie_pass_result) {.r_type = MIE_PASS_RESULT_INTERRUPT, \
|
||||
.r_status = (status)})
|
||||
|
||||
struct mie_op;
|
||||
struct mie_ctx;
|
||||
struct mie_pass;
|
||||
struct mie_dialect;
|
||||
struct mie_op_definition;
|
||||
struct mie_trait_definition;
|
||||
struct mie_interface_definition;
|
||||
struct mie_attribute_map;
|
||||
|
||||
enum mie_pass_type {
|
||||
MIE_PASS_NONE = 0,
|
||||
MIE_PASS_TRANSFORM,
|
||||
MIE_PASS_ANALYSE,
|
||||
};
|
||||
|
||||
enum mie_pass_result_type {
|
||||
MIE_PASS_RESULT_CONTINUE = 0,
|
||||
MIE_PASS_RESULT_INTERRUPT,
|
||||
};
|
||||
|
||||
struct mie_pass_result {
|
||||
enum mie_pass_result_type r_type;
|
||||
enum mie_status r_status;
|
||||
};
|
||||
|
||||
struct mie_pass_args {
|
||||
struct mie_ctx *p_ctx;
|
||||
};
|
||||
|
||||
struct mie_pass_filter {
|
||||
const struct mie_dialect *f_dialect;
|
||||
const struct mie_op_definition *f_op;
|
||||
const struct mie_trait_definition *f_trait;
|
||||
const struct mie_interface_definition *f_iface;
|
||||
};
|
||||
|
||||
struct mie_pass_definition {
|
||||
mie_id p_id;
|
||||
const char *p_name;
|
||||
const char *p_description;
|
||||
size_t p_data_size;
|
||||
enum mie_pass_type p_type;
|
||||
|
||||
enum mie_status (*p_init)(
|
||||
struct mie_pass *, const struct mie_attribute_map *);
|
||||
struct mie_pass_result (*p_transform)(
|
||||
struct mie_pass *, struct mie_op *, struct mie_pass_args *);
|
||||
struct mie_pass_result (*p_analyse)(
|
||||
struct mie_pass *, const struct mie_op *, struct mie_pass_args *);
|
||||
|
||||
struct mie_pass_filter p_filter;
|
||||
};
|
||||
|
||||
MIE_API struct mie_pass_definition *mie_pass_definition_create(void);
|
||||
|
||||
#endif
|
||||
46
mie/include/mie/pass/pass-manager.h
Normal file
46
mie/include/mie/pass/pass-manager.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef MIE_PASS_PASS_MANAGER_H_
|
||||
#define MIE_PASS_PASS_MANAGER_H_
|
||||
|
||||
#include <mie/pass/pass-definition.h>
|
||||
#include <mie/status.h>
|
||||
#include <mie/vector.h>
|
||||
|
||||
struct mie_pass;
|
||||
|
||||
struct mie_op;
|
||||
struct mie_op_pass;
|
||||
|
||||
enum mie_pass_manager_flags {
|
||||
MIE_PASSMGR_F_NONE = 0x00u,
|
||||
};
|
||||
|
||||
struct mie_pass_manager {
|
||||
enum mie_pass_manager_flags pm_flags;
|
||||
struct mie_ctx *pm_ctx;
|
||||
size_t pm_depth;
|
||||
|
||||
MIE_VECTOR_DECLARE(struct mie_pass *, pm_passes);
|
||||
MIE_VECTOR_DECLARE(struct mie_pass_manager *, pm_nested);
|
||||
|
||||
struct mie_pass_filter pm_filter;
|
||||
};
|
||||
|
||||
MIE_API struct mie_pass_manager *mie_pass_manager_create(struct mie_ctx *ctx);
|
||||
MIE_API void mie_pass_manager_destroy(struct mie_pass_manager *pm);
|
||||
|
||||
MIE_API struct mie_pass_manager *mie_pass_manager_nest(struct mie_pass_manager *pm);
|
||||
MIE_API enum mie_status mie_pass_manager_filter_op(
|
||||
struct mie_pass_manager *pm, const char *dialect_name, const char *op_name);
|
||||
MIE_API enum mie_status mie_pass_manager_filter_trait(
|
||||
struct mie_pass_manager *pm, const char *dialect_name,
|
||||
const char *trait_name);
|
||||
MIE_API enum mie_status mie_pass_manager_filter_interface(
|
||||
struct mie_pass_manager *pm, const char *dialect_name,
|
||||
const char *iface_name);
|
||||
|
||||
MIE_API void mie_pass_manager_add_pass(
|
||||
struct mie_pass_manager *pm, struct mie_pass *pass);
|
||||
MIE_API struct mie_pass_result mie_pass_manager_run(
|
||||
struct mie_pass_manager *pm, struct mie_op *target);
|
||||
|
||||
#endif
|
||||
14
mie/include/mie/pass/pass.h
Normal file
14
mie/include/mie/pass/pass.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef MIE_PASS_PASS_H_
|
||||
#define MIE_PASS_PASS_H_
|
||||
|
||||
#include <mie/pass/pass-definition.h>
|
||||
|
||||
struct mie_pass {
|
||||
const struct mie_pass_definition *p_def;
|
||||
};
|
||||
|
||||
MIE_API const char *mie_pass_get_name(const struct mie_pass *pass);
|
||||
MIE_API struct mie_pass_result mie_pass_execute(
|
||||
struct mie_pass *pass, struct mie_op *op, struct mie_pass_args *args);
|
||||
|
||||
#endif
|
||||
@@ -8,6 +8,8 @@
|
||||
struct mie_ctx;
|
||||
struct mie_module;
|
||||
struct mie_op;
|
||||
struct mie_op_arg;
|
||||
struct mie_op_successor;
|
||||
struct mie_region;
|
||||
struct mie_block;
|
||||
struct mie_type;
|
||||
@@ -17,6 +19,12 @@ struct mie_register;
|
||||
enum mie_print_flags {
|
||||
MIE_PRINT_F_GENERIC = 0x01u,
|
||||
MIE_PRINT_F_ABBREVIATED = 0x02u,
|
||||
|
||||
MIE_PRINT_F_INCLUDE_TYPE = 0x04u,
|
||||
MIE_PRINT_F_EXCLUDE_BLOCK_HEADER = 0x08u,
|
||||
MIE_PRINT_F_EXCLUDE_FIRST_BLOCK_HEADER = 0x10u,
|
||||
|
||||
MIE_PRINT_F_MARK_UNRESOLVED_ELEMENTS = 0x20u,
|
||||
};
|
||||
|
||||
struct mie_printer {
|
||||
@@ -34,14 +42,28 @@ MIE_API void mie_printer_print_module(
|
||||
MIE_API void mie_printer_print_op(
|
||||
struct mie_printer *printer, const struct mie_op *op);
|
||||
MIE_API void mie_printer_print_region(
|
||||
struct mie_printer *printer, const struct mie_region *region);
|
||||
struct mie_printer *printer, const struct mie_region *region,
|
||||
enum mie_print_flags flags);
|
||||
MIE_API void mie_printer_print_block(
|
||||
struct mie_printer *printer, const struct mie_block *block,
|
||||
enum mie_print_flags flags);
|
||||
MIE_API void mie_printer_print_block_ref(
|
||||
struct mie_printer *printer, const struct mie_block *block);
|
||||
MIE_API void mie_printer_print_type(
|
||||
struct mie_printer *printer, const struct mie_type *type);
|
||||
MIE_API void mie_printer_print_attribute(
|
||||
struct mie_printer *printer, const struct mie_attribute *attrib);
|
||||
MIE_API void mie_printer_print_register(
|
||||
struct mie_printer *printer, const struct mie_register *reg);
|
||||
struct mie_printer *printer, const struct mie_register *reg,
|
||||
enum mie_print_flags flags);
|
||||
|
||||
MIE_API void mie_printer_print_op_name(
|
||||
struct mie_printer *printer, const struct mie_op *op);
|
||||
MIE_API void mie_printer_print_op_successor(
|
||||
struct mie_printer *printer, const struct mie_op_successor *s,
|
||||
bool compact);
|
||||
MIE_API void mie_printer_print_op_arg(
|
||||
struct mie_printer *printer, const struct mie_op_arg *arg,
|
||||
bool include_type);
|
||||
|
||||
#endif
|
||||
|
||||
20
mie/include/mie/rewrite/convert.h
Normal file
20
mie/include/mie/rewrite/convert.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef MIE_REWRITE_CONVERT_H_
|
||||
#define MIE_REWRITE_CONVERT_H_
|
||||
|
||||
#include <mie/ctx.h>
|
||||
|
||||
struct mie_pattern_set;
|
||||
struct mie_convert_config;
|
||||
|
||||
MIE_API struct mie_convert_config *mie_convert_config_create(struct mie_ctx *ctx);
|
||||
MIE_API void mie_convert_config_destroy(struct mie_convert_config *cfg);
|
||||
|
||||
MIE_API enum mie_status mie_convert_config_add_illegal_op(
|
||||
struct mie_convert_config *cfg, const char *dialect_name,
|
||||
const char *op_name);
|
||||
|
||||
MIE_API enum mie_status mie_convert_apply(
|
||||
struct mie_op *op, struct mie_convert_config *cfg,
|
||||
struct mie_pattern_set *patterns);
|
||||
|
||||
#endif
|
||||
16
mie/include/mie/rewrite/greedy.h
Normal file
16
mie/include/mie/rewrite/greedy.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef MIE_REWRITE_GREEDY_H_
|
||||
#define MIE_REWRITE_GREEDY_H_
|
||||
|
||||
#include <mie/ctx.h>
|
||||
|
||||
struct mie_pattern_set;
|
||||
struct mie_greedy_config;
|
||||
|
||||
MIE_API struct mie_greedy_config *mie_greedy_config_create(struct mie_ctx *ctx);
|
||||
MIE_API void mie_greedy_config_destroy(struct mie_greedy_config *cfg);
|
||||
|
||||
MIE_API enum mie_status mie_greedy_apply(
|
||||
struct mie_op *op, struct mie_greedy_config *cfg,
|
||||
struct mie_pattern_set *patterns);
|
||||
|
||||
#endif
|
||||
54
mie/include/mie/rewrite/pattern.h
Normal file
54
mie/include/mie/rewrite/pattern.h
Normal file
@@ -0,0 +1,54 @@
|
||||
#ifndef MIE_REWRITE_PATTERN_H_
|
||||
#define MIE_REWRITE_PATTERN_H_
|
||||
|
||||
#include <mie/vector.h>
|
||||
|
||||
#define MIE_REWRITE_RESULT(result, status) \
|
||||
((struct mie_rewrite_result) {.r_result = (result), .r_status = (status)})
|
||||
|
||||
struct mie_op;
|
||||
struct mie_rewriter;
|
||||
|
||||
enum mie_match_result {
|
||||
MIE_NO_MATCH_FOUND = 0,
|
||||
MIE_MATCH_FOUND,
|
||||
};
|
||||
|
||||
struct mie_rewrite_result {
|
||||
enum {
|
||||
MIE_REWRITE_SUCCESS = 0,
|
||||
MIE_REWRITE_IGNORE,
|
||||
MIE_REWRITE_FAILURE,
|
||||
} r_result;
|
||||
enum mie_status r_status;
|
||||
};
|
||||
|
||||
struct mie_pattern {
|
||||
struct {
|
||||
const char *t_dialect_name, *t_op_name;
|
||||
const struct mie_op_definition *t_op;
|
||||
} p_root;
|
||||
|
||||
enum mie_match_result (*p_match)(const struct mie_op *);
|
||||
struct mie_rewrite_result (*p_rewrite)(
|
||||
struct mie_op *, struct mie_rewriter *);
|
||||
};
|
||||
|
||||
struct mie_pattern_set {
|
||||
MIE_VECTOR_DECLARE(struct mie_pattern, s_patterns);
|
||||
};
|
||||
|
||||
MIE_API void mie_pattern_set_init(struct mie_pattern_set *set);
|
||||
MIE_API void mie_pattern_set_cleanup(struct mie_pattern_set *set);
|
||||
|
||||
MIE_API struct mie_pattern *mie_pattern_set_add(struct mie_pattern_set *set);
|
||||
MIE_API struct mie_pattern *mie_pattern_set_match(
|
||||
struct mie_pattern_set *set, const struct mie_op *op);
|
||||
|
||||
MIE_API enum mie_match_result mie_pattern_match(
|
||||
const struct mie_pattern *pattern, const struct mie_op *op);
|
||||
MIE_API struct mie_rewrite_result mie_pattern_rewrite(
|
||||
const struct mie_pattern *pattern, struct mie_op *op,
|
||||
struct mie_rewriter *rewriter);
|
||||
|
||||
#endif
|
||||
108
mie/include/mie/rewrite/rewriter.h
Normal file
108
mie/include/mie/rewrite/rewriter.h
Normal file
@@ -0,0 +1,108 @@
|
||||
#ifndef MIE_IR_REWRITE_H_
|
||||
#define MIE_IR_REWRITE_H_
|
||||
|
||||
#include <mie/ir/emit.h>
|
||||
#include <mie/misc.h>
|
||||
#include <mie/status.h>
|
||||
#include <mie/vector.h>
|
||||
#include <stddef.h>
|
||||
|
||||
struct mie_op;
|
||||
struct mie_ctx;
|
||||
struct mie_region;
|
||||
struct mie_register;
|
||||
struct mie_op_successor;
|
||||
|
||||
struct mie_rewriter {
|
||||
struct mie_emitter r_base;
|
||||
struct mie_ctx *r_ctx;
|
||||
/* anything ops added to the IR are inserted in this block. */
|
||||
struct mie_block *r_insert_block;
|
||||
/* anything ops added to the IR are inserted after this op.
|
||||
* if this is null, the insertion point is the end of r_insert_block. */
|
||||
struct mie_op *r_insert_point;
|
||||
};
|
||||
|
||||
MIE_API void mie_rewriter_init(struct mie_rewriter *rw, struct mie_ctx *ctx);
|
||||
MIE_API void mie_rewriter_cleanup(struct mie_rewriter *rw);
|
||||
|
||||
MIE_API struct mie_ctx *mie_rewriter_get_ctx(const struct mie_rewriter *rw);
|
||||
|
||||
MIE_API struct mie_block *mie_rewriter_get_insertion_block(struct mie_rewriter *rw);
|
||||
MIE_API struct mie_op *mie_rewriter_get_insertion_point(struct mie_rewriter *rw);
|
||||
|
||||
MIE_API struct mie_block *mie_rewriter_set_insertion_block(
|
||||
struct mie_rewriter *rw, struct mie_block *block);
|
||||
MIE_API struct mie_op *mie_rewriter_set_insertion_point(
|
||||
struct mie_rewriter *rw, struct mie_op *insert_point);
|
||||
|
||||
MIE_API struct mie_block *mie_rewriter_split_block(
|
||||
struct mie_rewriter *rw, struct mie_block *block, struct mie_op *before,
|
||||
const char *name);
|
||||
MIE_API struct mie_block *mie_rewriter_create_block(
|
||||
struct mie_rewriter *rw, struct mie_block *insert_before, const char *name);
|
||||
|
||||
MIE_API enum mie_status mie_rewriter_move_block_to_start(
|
||||
struct mie_rewriter *rw, struct mie_block *block,
|
||||
struct mie_region *from, struct mie_region *to);
|
||||
MIE_API enum mie_status mie_rewriter_move_block_to_end(
|
||||
struct mie_rewriter *rw, struct mie_block *block,
|
||||
struct mie_region *from, struct mie_region *to);
|
||||
MIE_API enum mie_status mie_rewriter_move_block_before(
|
||||
struct mie_rewriter *rw, struct mie_block *block,
|
||||
struct mie_region *from, struct mie_region *to, struct mie_block *before);
|
||||
MIE_API enum mie_status mie_rewriter_move_block_after(
|
||||
struct mie_rewriter *rw, struct mie_block *block,
|
||||
struct mie_region *from, struct mie_region *to, struct mie_block *after);
|
||||
|
||||
MIE_API enum mie_status mie_rewriter_rename_block(
|
||||
struct mie_rewriter *rw, struct mie_block *block, const char *name);
|
||||
|
||||
MIE_API enum mie_status mie_rewriter_move_blocks_to_start(
|
||||
struct mie_rewriter *rw, struct mie_region *from, struct mie_region *to);
|
||||
MIE_API enum mie_status mie_rewriter_move_blocks_to_end(
|
||||
struct mie_rewriter *rw, struct mie_region *from, struct mie_region *to);
|
||||
MIE_API enum mie_status mie_rewriter_move_blocks_before(
|
||||
struct mie_rewriter *rw, struct mie_region *from, struct mie_region *to,
|
||||
struct mie_block *before);
|
||||
MIE_API enum mie_status mie_rewriter_move_blocks_after(
|
||||
struct mie_rewriter *rw, struct mie_region *from, struct mie_region *to,
|
||||
struct mie_block *after);
|
||||
|
||||
MIE_API enum mie_status mie_rewriter_move_region_to_start(
|
||||
struct mie_rewriter *rw, struct mie_region *region, struct mie_op *from,
|
||||
struct mie_op *to);
|
||||
MIE_API enum mie_status mie_rewriter_move_region_to_end(
|
||||
struct mie_rewriter *rw, struct mie_region *region, struct mie_op *from,
|
||||
struct mie_op *to);
|
||||
MIE_API enum mie_status mie_rewriter_move_region_before(
|
||||
struct mie_rewriter *rw, struct mie_region *region, struct mie_op *from,
|
||||
struct mie_op *to, struct mie_region *before);
|
||||
MIE_API enum mie_status mie_rewriter_move_region_after(
|
||||
struct mie_rewriter *rw, struct mie_region *region, struct mie_op *from,
|
||||
struct mie_op *to, struct mie_region *after);
|
||||
|
||||
MIE_API struct mie_op *mie_rewriter_put_op(
|
||||
struct mie_rewriter *rw, const char *dialect, const char *op,
|
||||
struct mie_register **args, size_t nr_args);
|
||||
MIE_API struct mie_op *mie_rewriter_replace_op(
|
||||
struct mie_rewriter *rw, struct mie_op *op, const char *dialect_name,
|
||||
const char *op_name);
|
||||
MIE_API struct mie_op_successor *mie_rewriter_add_op_successor(
|
||||
struct mie_rewriter *rw, struct mie_op *op, struct mie_block *dest,
|
||||
struct mie_register **args, size_t nr_args);
|
||||
MIE_API enum mie_status mie_rewriter_erase_op(
|
||||
struct mie_rewriter *rw, struct mie_op *op);
|
||||
MIE_API enum mie_status mie_rewriter_move_op_args_to_successor(
|
||||
struct mie_rewriter *rw, struct mie_op *op, struct mie_op_successor *s);
|
||||
|
||||
MIE_API enum mie_status mie_rewriter_replace_register(
|
||||
struct mie_rewriter *rw, struct mie_register *old,
|
||||
struct mie_register *new);
|
||||
MIE_API enum mie_status mie_rewriter_rename_register(
|
||||
struct mie_rewriter *rw, struct mie_register *reg, const char *name);
|
||||
|
||||
MIE_API enum mie_status mie_rewriter_put_name(
|
||||
struct mie_rewriter *rw, struct mie_name *name, const char *hint);
|
||||
|
||||
#endif
|
||||
@@ -13,13 +13,14 @@ enum mie_status {
|
||||
MIE_ERR_BAD_SYNTAX,
|
||||
MIE_ERR_BAD_FORMAT,
|
||||
MIE_ERR_BAD_STATE,
|
||||
MIE_ERR_NOT_SUPPORTED,
|
||||
MIE_ERR_INVALID_VALUE,
|
||||
MIE_ERR_INVALID_ARGUMENT,
|
||||
MIE_ERR_INTERNAL_FAILURE,
|
||||
MIE_ERR_NO_MEMORY,
|
||||
MIE_ERR_NO_ENTRY,
|
||||
MIE_ERR_NO_DATA,
|
||||
MIE_ERR_NAME_EXISTS,
|
||||
MIE_ERR_NOT_SUPPORTED,
|
||||
MIE_ERR_INTERNAL_FAILURE,
|
||||
};
|
||||
|
||||
MIE_API const struct b_error_vendor *mie_error_vendor(void);
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
#define MIE_VECTOR_H_
|
||||
|
||||
#include <mie/misc.h>
|
||||
#include <mie/status.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#if 0
|
||||
#define MIE_VECTOR_DEFINE(type, name) \
|
||||
size_t name##_count = 0; \
|
||||
size_t name##_max = 0; \
|
||||
type *name = NULL
|
||||
#endif
|
||||
struct mie_vector_ops {
|
||||
enum mie_status (*v_copy)(void *, const void *, size_t);
|
||||
enum mie_status (*v_move)(void *, void *, size_t);
|
||||
enum mie_status (*v_destroy)(void *);
|
||||
};
|
||||
|
||||
#define MIE_VECTOR_DEFINE(type, name) \
|
||||
struct { \
|
||||
@@ -43,52 +43,69 @@
|
||||
#define MIE_VECTOR_REF2(name) &(name.items), &(name.count), &(name.max)
|
||||
|
||||
/* use these functions if you're accessing a vector directly. */
|
||||
#define mie_vector_push_back(vector, ptr) \
|
||||
#define mie_vector_push_back(vector, ptr, ops) \
|
||||
__mie_vector_push_back( \
|
||||
(void **)&(vector.items), ptr, sizeof *ptr, &(vector.count), \
|
||||
&(vector.max))
|
||||
#define mie_vector_pop_back(vector) \
|
||||
&(vector.max), ops)
|
||||
#define mie_vector_pop_back(vector, ops) \
|
||||
__mie_vector_pop_back( \
|
||||
(void **)&(vector), sizeof *vector, &(vector.count), \
|
||||
&(vector.max))
|
||||
#define mie_vector_emplace_back(vector) \
|
||||
(void **)&(vector.items), sizeof *vector.items, \
|
||||
&(vector.count), &(vector.max), ops)
|
||||
#define mie_vector_emplace_back(vector, ops) \
|
||||
__mie_vector_emplace_back( \
|
||||
(void **)&(vector.items), sizeof *vector.items, \
|
||||
&(vector.count), &(vector.max))
|
||||
#define mie_vector_destroy(vector, dtor) \
|
||||
&(vector.count), &(vector.max), ops)
|
||||
#define mie_vector_trim(vector, ops) \
|
||||
__mie_vector_trim( \
|
||||
(void **)&(vector.items), sizeof *vector.items, \
|
||||
&(vector.count), &(vector.max), ops)
|
||||
#define mie_vector_destroy(vector, ops) \
|
||||
__mie_vector_destroy( \
|
||||
(void **)&(vector.items), sizeof *vector.items, \
|
||||
&(vector.count), &(vector.max), dtor)
|
||||
&(vector.count), &(vector.max), ops)
|
||||
|
||||
/* use these functions if you're accessing a vector as a reference
|
||||
* via MIE_VECTOR_REF_PARAM. */
|
||||
#define mie_vector_ref_push_back(vector, ptr) \
|
||||
#define mie_vector_ref_push_back(vector, ptr, ops) \
|
||||
__mie_vector_push_back( \
|
||||
(void **)(vector), ptr, sizeof *ptr, (vector##_count), \
|
||||
(vector##_max))
|
||||
#define mie_vector_ref_pop_back(vector) \
|
||||
(vector##_max), ops)
|
||||
#define mie_vector_ref_pop_back(vector, ops) \
|
||||
__mie_vector_pop_back( \
|
||||
(void **)(vector), sizeof **vector, (vector##_count), \
|
||||
(vector##_max))
|
||||
#define mie_vector_ref_emplace_back(vector) \
|
||||
(vector##_max), ops)
|
||||
#define mie_vector_ref_emplace_back(vector, ops) \
|
||||
__mie_vector_emplace_back( \
|
||||
(void **)(vector), sizeof **vector, (vector##_count), \
|
||||
(vector##_max))
|
||||
#define mie_vector_ref_destroy(vector, dtor) \
|
||||
(vector##_max), ops)
|
||||
#define mie_vector_ref_trim(vector, ops) \
|
||||
__mie_vector_trim( \
|
||||
(void **)(vector), sizeof **vector, (vector##_count), \
|
||||
(vector##_max), ops)
|
||||
#define mie_vector_ref_destroy(vector, ops) \
|
||||
__mie_vector_destroy( \
|
||||
(void **)(vector), sizeof **vector, (vector##_count), \
|
||||
(vector##_max), dtor)
|
||||
(vector##_max), ops)
|
||||
#define mie_vector_ref_get_item(vector, index) (*vector)[index]
|
||||
#define mie_vector_ref_get_item_ptr(vector, index) (&(*vector)[index])
|
||||
#define mie_vector_ref_get_count(vector) *(vector##_count)
|
||||
#define mie_vector_ref_get_max(vector) *(vector##_count)
|
||||
|
||||
/* don't use these functions */
|
||||
MIE_API int __mie_vector_push_back(
|
||||
void **vector, const void *item, size_t item_size, size_t *count,
|
||||
size_t *max);
|
||||
size_t *max, const struct mie_vector_ops *ops);
|
||||
MIE_API void __mie_vector_pop_back(
|
||||
void **vector, size_t item_size, size_t *count, size_t *max);
|
||||
void **vector, size_t item_size, size_t *count, size_t *max,
|
||||
const struct mie_vector_ops *ops);
|
||||
MIE_API void *__mie_vector_emplace_back(
|
||||
void **vector, size_t item_size, size_t *count, size_t *max);
|
||||
void **vector, size_t item_size, size_t *count, size_t *max,
|
||||
const struct mie_vector_ops *ops);
|
||||
MIE_API void __mie_vector_trim(
|
||||
void **vector, size_t item_size, size_t *count, size_t *max,
|
||||
const struct mie_vector_ops *ops);
|
||||
MIE_API void __mie_vector_destroy(
|
||||
void **vector, size_t item_size, size_t *count, size_t *max,
|
||||
void (*dtor)(void *));
|
||||
const struct mie_vector_ops *ops);
|
||||
|
||||
#endif
|
||||
|
||||
268
mie/ir/block.c
Normal file
268
mie/ir/block.c
Normal file
@@ -0,0 +1,268 @@
|
||||
#include <mie/ir/block.h>
|
||||
#include <mie/ir/op.h>
|
||||
#include <mie/ir/register.h>
|
||||
|
||||
struct mie_op *mie_block_get_first_op(const struct mie_block *block)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_first(&block->b_ops);
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return b_unbox(struct mie_op, entry, op_entry);
|
||||
}
|
||||
|
||||
struct mie_op *mie_block_get_prev_op(
|
||||
const struct mie_block *block, const struct mie_op *before)
|
||||
{
|
||||
if (!before || before->op_container != block) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
b_queue_entry *entry = b_queue_prev(&before->op_entry);
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return b_unbox(struct mie_op, entry, op_entry);
|
||||
}
|
||||
|
||||
struct mie_op *mie_block_get_next_op(
|
||||
const struct mie_block *block, const struct mie_op *after)
|
||||
{
|
||||
if (!after || after->op_container != block) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
b_queue_entry *entry = b_queue_next(&after->op_entry);
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return b_unbox(struct mie_op, entry, op_entry);
|
||||
}
|
||||
|
||||
struct mie_op *mie_block_get_last_op(const struct mie_block *block)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_last(&block->b_ops);
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return b_unbox(struct mie_op, entry, op_entry);
|
||||
}
|
||||
|
||||
struct mie_op *mie_block_get_terminator(const struct mie_block *block)
|
||||
{
|
||||
b_queue_entry *op_entry = b_queue_last(&block->b_ops);
|
||||
return b_unbox(struct mie_op, op_entry, op_entry);
|
||||
}
|
||||
|
||||
struct mie_op_successor *mie_block_get_first_successor(const struct mie_block *block)
|
||||
{
|
||||
struct mie_op *op = mie_block_get_terminator(block);
|
||||
if (!op) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (MIE_VECTOR_COUNT(op->op_successors) == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &op->op_successors.items[0];
|
||||
}
|
||||
|
||||
struct mie_op_successor *mie_block_get_prev_successor(
|
||||
const struct mie_block *block, const struct mie_op_successor *before)
|
||||
{
|
||||
struct mie_op *op = mie_block_get_terminator(block);
|
||||
if (!op) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (MIE_VECTOR_COUNT(op->op_successors) == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t i = before - &op->op_successors.items[0];
|
||||
if (i == 0 || i >= MIE_VECTOR_COUNT(op->op_successors)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &op->op_successors.items[i - 1];
|
||||
}
|
||||
|
||||
struct mie_op_successor *mie_block_get_next_successor(
|
||||
const struct mie_block *block, const struct mie_op_successor *after)
|
||||
{
|
||||
struct mie_op *op = mie_block_get_terminator(block);
|
||||
if (!op) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (MIE_VECTOR_COUNT(op->op_successors) == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t i = after - &op->op_successors.items[0];
|
||||
if (i >= MIE_VECTOR_COUNT(op->op_successors)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (i + 1 >= MIE_VECTOR_COUNT(op->op_successors)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &op->op_successors.items[i + 1];
|
||||
}
|
||||
|
||||
struct mie_op_successor *mie_block_get_last_successor(const struct mie_block *block)
|
||||
{
|
||||
struct mie_op *op = mie_block_get_terminator(block);
|
||||
if (!op) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t nr_successors = MIE_VECTOR_COUNT(op->op_successors);
|
||||
|
||||
if (nr_successors == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &op->op_successors.items[nr_successors - 1];
|
||||
}
|
||||
|
||||
struct mie_block_predecessor *mie_block_get_first_predecessor(
|
||||
const struct mie_block *block)
|
||||
{
|
||||
size_t nr_predecessors = MIE_VECTOR_COUNT(block->b_ipred);
|
||||
|
||||
if (nr_predecessors == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &block->b_ipred.items[0];
|
||||
}
|
||||
|
||||
struct mie_block_predecessor *mie_block_get_prev_predecessor(
|
||||
const struct mie_block *block, const struct mie_block_predecessor *before)
|
||||
{
|
||||
if (MIE_VECTOR_COUNT(block->b_ipred) == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t i = before - &block->b_ipred.items[0];
|
||||
if (i == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &block->b_ipred.items[i - 1];
|
||||
}
|
||||
|
||||
struct mie_block_predecessor *mie_block_get_next_predecessor(
|
||||
const struct mie_block *block, const struct mie_block_predecessor *after)
|
||||
{
|
||||
if (MIE_VECTOR_COUNT(block->b_ipred) == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t i = after - &block->b_ipred.items[0];
|
||||
if (i >= MIE_VECTOR_COUNT(block->b_ipred)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (i + 1 >= MIE_VECTOR_COUNT(block->b_ipred)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &block->b_ipred.items[i + 1];
|
||||
}
|
||||
|
||||
struct mie_block_predecessor *mie_block_get_last_predecessor(
|
||||
const struct mie_block *block)
|
||||
{
|
||||
size_t nr_predecessors = MIE_VECTOR_COUNT(block->b_ipred);
|
||||
|
||||
if (nr_predecessors == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &block->b_ipred.items[nr_predecessors - 1];
|
||||
}
|
||||
|
||||
struct mie_op *mie_block_add_op(struct mie_block *block)
|
||||
{
|
||||
struct mie_op *op = malloc(sizeof *op);
|
||||
if (!op) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mie_op_init(op);
|
||||
op->op_container = block;
|
||||
|
||||
b_queue_push_back(&block->b_ops, &op->op_entry);
|
||||
|
||||
return op;
|
||||
}
|
||||
|
||||
struct mie_op *mie_block_add_op_after(struct mie_block *block, struct mie_op *after)
|
||||
{
|
||||
if (after && after->op_container != block) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct mie_op *op = malloc(sizeof *op);
|
||||
if (!op) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mie_op_init(op);
|
||||
op->op_container = block;
|
||||
|
||||
if (after) {
|
||||
b_queue_insert_after(&block->b_ops, &op->op_entry, &after->op_entry);
|
||||
} else {
|
||||
b_queue_push_back(&block->b_ops, &op->op_entry);
|
||||
}
|
||||
|
||||
return op;
|
||||
}
|
||||
|
||||
struct mie_register *mie_block_add_param(struct mie_block *block)
|
||||
{
|
||||
struct mie_register *result = mie_vector_emplace_back(
|
||||
block->b_params, &mie_register_vector_ops);
|
||||
result->reg_flags = MIE_REGISTER_F_VIRTUAL | MIE_REGISTER_F_BLOCK_PARAM;
|
||||
result->reg_block = block;
|
||||
result->reg_op = NULL;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
struct mie_register *mie_block_find_register(
|
||||
const struct mie_block *block, const char *name,
|
||||
const struct mie_op *start_point)
|
||||
{
|
||||
const b_queue_entry *entry = b_queue_last(&block->b_ops);
|
||||
if (start_point) {
|
||||
entry = &start_point->op_entry;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < MIE_VECTOR_COUNT(block->b_params); i++) {
|
||||
if (!strcmp(block->b_params.items[i].reg_name.n_str, name)) {
|
||||
return &block->b_params.items[i];
|
||||
}
|
||||
}
|
||||
|
||||
while (entry) {
|
||||
struct mie_op *op = b_unbox(struct mie_op, entry, op_entry);
|
||||
struct mie_register *reg = mie_op_get_result_with_name(op, name);
|
||||
if (reg) {
|
||||
return reg;
|
||||
}
|
||||
|
||||
entry = b_queue_prev(entry);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
171
mie/ir/builder.c
Normal file
171
mie/ir/builder.c
Normal file
@@ -0,0 +1,171 @@
|
||||
#include <mie/ctx.h>
|
||||
#include <mie/ir/block.h>
|
||||
#include <mie/ir/builder.h>
|
||||
#include <mie/ir/emit.h>
|
||||
#include <mie/ir/op-definition.h>
|
||||
#include <mie/ir/op.h>
|
||||
#include <mie/ir/region.h>
|
||||
|
||||
struct builder_scope {
|
||||
b_queue_entry s_entry;
|
||||
struct mie_op *s_op;
|
||||
struct mie_region *s_region;
|
||||
struct mie_block *s_block;
|
||||
};
|
||||
|
||||
struct mie_builder {
|
||||
struct mie_emitter b_base;
|
||||
struct mie_ctx *b_ctx;
|
||||
b_queue b_scope_stack;
|
||||
struct mie_op *b_root;
|
||||
struct mie_op *b_prev_op;
|
||||
};
|
||||
|
||||
struct mie_builder *mie_builder_create(struct mie_ctx *ctx, struct mie_op *root)
|
||||
{
|
||||
struct mie_builder *out = malloc(sizeof *out);
|
||||
if (!out) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(out, 0x0, sizeof *out);
|
||||
|
||||
out->b_base.e_get_ctx = (mie_emit_get_ctx)mie_builder_get_ctx;
|
||||
out->b_base.e_put_op = (mie_emit_put_op)mie_builder_put_op;
|
||||
out->b_base.e_put_name = (mie_emit_put_name)mie_builder_put_name;
|
||||
out->b_base.e_put_block = NULL;
|
||||
|
||||
out->b_ctx = ctx;
|
||||
out->b_root = root;
|
||||
|
||||
mie_builder_step_into_op(out, root);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
struct mie_ctx *mie_builder_get_ctx(struct mie_builder *builder)
|
||||
{
|
||||
return builder->b_ctx;
|
||||
}
|
||||
|
||||
static struct mie_name_map *get_current_name_map(struct mie_builder *builder)
|
||||
{
|
||||
b_queue_entry *cur = b_queue_last(&builder->b_scope_stack);
|
||||
while (cur) {
|
||||
struct builder_scope *scope
|
||||
= b_unbox(struct builder_scope, cur, s_entry);
|
||||
|
||||
if (scope->s_region && scope->s_region->r_names) {
|
||||
return scope->s_region->r_names;
|
||||
}
|
||||
|
||||
cur = b_queue_prev(cur);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct mie_block *mie_builder_get_current_block(struct mie_builder *builder)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_last(&builder->b_scope_stack);
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct builder_scope *scope
|
||||
= b_unbox(struct builder_scope, entry, s_entry);
|
||||
|
||||
return scope->s_block;
|
||||
}
|
||||
|
||||
void mie_builder_step_into_op(struct mie_builder *builder, struct mie_op *op)
|
||||
{
|
||||
struct mie_region *region = mie_op_get_last_region(op);
|
||||
|
||||
if (!region) {
|
||||
region = mie_op_add_region(op);
|
||||
}
|
||||
|
||||
mie_builder_step_into_region(builder, region);
|
||||
}
|
||||
|
||||
void mie_builder_step_into_region(
|
||||
struct mie_builder *builder, struct mie_region *region)
|
||||
{
|
||||
struct mie_block *block = mie_region_get_last_block(region);
|
||||
|
||||
if (!block) {
|
||||
block = mie_region_add_block(region);
|
||||
}
|
||||
|
||||
mie_builder_step_into_block(builder, block);
|
||||
}
|
||||
|
||||
void mie_builder_step_into_block(struct mie_builder *builder, struct mie_block *block)
|
||||
{
|
||||
struct builder_scope *scope = malloc(sizeof *scope);
|
||||
if (!scope) {
|
||||
return;
|
||||
}
|
||||
|
||||
memset(scope, 0x0, sizeof *scope);
|
||||
|
||||
scope->s_block = block;
|
||||
scope->s_region = block->b_parent;
|
||||
scope->s_op = scope->s_region->r_parent;
|
||||
|
||||
b_queue_push_back(&builder->b_scope_stack, &scope->s_entry);
|
||||
}
|
||||
|
||||
void mie_builder_step_out(struct mie_builder *builder)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_last(&builder->b_scope_stack);
|
||||
if (!entry) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct builder_scope *scope
|
||||
= b_unbox(struct builder_scope, entry, s_entry);
|
||||
b_queue_delete(&builder->b_scope_stack, entry);
|
||||
free(scope);
|
||||
}
|
||||
|
||||
struct mie_op *mie_builder_put_op(
|
||||
struct mie_builder *builder, const char *dialect, const char *op_name,
|
||||
struct mie_register **args, size_t nr_args)
|
||||
{
|
||||
struct mie_block *block = mie_builder_get_current_block(builder);
|
||||
|
||||
const struct mie_op_definition *op_def
|
||||
= mie_ctx_get_op_definition(builder->b_ctx, dialect, op_name);
|
||||
if (!op_def) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct mie_op *op = mie_block_add_op(block);
|
||||
op->op_flags = MIE_OP_F_OP_RESOLVED;
|
||||
op->op_info = op_def;
|
||||
|
||||
for (size_t i = 0; i < nr_args; i++) {
|
||||
struct mie_op_arg *arg = mie_op_add_arg(op);
|
||||
arg->arg_flags = MIE_OP_F_ARG_RESOLVED;
|
||||
arg->arg_value.u_reg = args[i];
|
||||
arg->arg_value.u_user = op;
|
||||
b_queue_push_back(&args[i]->reg_use, &arg->arg_value.u_entry);
|
||||
}
|
||||
|
||||
return op;
|
||||
}
|
||||
|
||||
enum mie_status mie_builder_put_name(
|
||||
struct mie_builder *builder, struct mie_name *name, const char *hint)
|
||||
{
|
||||
struct mie_name_map *map = get_current_name_map(builder);
|
||||
if (!map) {
|
||||
return MIE_ERR_BAD_STATE;
|
||||
}
|
||||
|
||||
struct mie_name *result = mie_name_map_put(map, name, hint, 0);
|
||||
|
||||
return result ? MIE_SUCCESS : MIE_ERR_NAME_EXISTS;
|
||||
}
|
||||
42
mie/ir/emit.c
Normal file
42
mie/ir/emit.c
Normal file
@@ -0,0 +1,42 @@
|
||||
#include <mie/ir/emit.h>
|
||||
|
||||
struct mie_ctx *mie_emitter_get_ctx(struct mie_emitter *emitter)
|
||||
{
|
||||
if (emitter->e_get_ctx) {
|
||||
return emitter->e_get_ctx(emitter);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
enum mie_status mie_emitter_put_name(
|
||||
struct mie_emitter *emitter, struct mie_name *name, const char *hint)
|
||||
{
|
||||
if (emitter->e_put_name) {
|
||||
return emitter->e_put_name(emitter, name, hint);
|
||||
}
|
||||
|
||||
return MIE_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (emitter->e_put_op) {
|
||||
return emitter->e_put_op(
|
||||
emitter, dialect_name, op_name, args, nr_args);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct mie_block *mie_emitter_put_block(
|
||||
struct mie_emitter *emitter, struct mie_block *insert_point)
|
||||
{
|
||||
if (emitter->e_put_block) {
|
||||
return emitter->e_put_block(emitter, insert_point);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
#include <mie/ir/module.h>
|
||||
#include <mie/ir/op.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct mie_module *mie_module_create(void)
|
||||
{
|
||||
struct mie_module *out = malloc(sizeof *out);
|
||||
if (!out) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(out, 0x0, sizeof *out);
|
||||
|
||||
out->m_names = mie_name_map_create(NULL);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
void mie_module_destroy(struct mie_module *mod)
|
||||
{
|
||||
/* TODO */
|
||||
}
|
||||
|
||||
struct mie_op *mie_module_add_op(struct mie_module *mod)
|
||||
{
|
||||
return mie_vector_emplace_back(mod->m_ops);
|
||||
}
|
||||
10
mie/ir/op-arg.c
Normal file
10
mie/ir/op-arg.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <mie/ir/op.h>
|
||||
|
||||
const struct mie_type *mie_op_arg_get_type(const struct mie_op_arg *arg)
|
||||
{
|
||||
if (arg->arg_flags & MIE_OP_F_ARG_RESOLVED) {
|
||||
return arg->arg_value.u_reg->reg_type;
|
||||
}
|
||||
|
||||
return arg->arg_unresolved.reg_type;
|
||||
}
|
||||
307
mie/ir/op.c
Normal file
307
mie/ir/op.c
Normal file
@@ -0,0 +1,307 @@
|
||||
#include <assert.h>
|
||||
#include <mie/ctx.h>
|
||||
#include <mie/diag/diag.h>
|
||||
#include <mie/diag/highlight.h>
|
||||
#include <mie/dialect/builtin.h>
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/ir/block.h>
|
||||
#include <mie/ir/op-definition.h>
|
||||
#include <mie/ir/op.h>
|
||||
#include <mie/ir/region.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static enum mie_status op_arg_cleanup(void *p)
|
||||
{
|
||||
struct mie_op_arg *arg = p;
|
||||
|
||||
if (arg->arg_flags & MIE_OP_F_ARG_RESOLVED) {
|
||||
b_queue_delete(
|
||||
&arg->arg_value.u_reg->reg_use, &arg->arg_value.u_entry);
|
||||
}
|
||||
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
static enum mie_status op_arg_move(void *dst, void *src, size_t itemsz)
|
||||
{
|
||||
assert(itemsz == sizeof(struct mie_op_arg));
|
||||
struct mie_op_arg *dest_arg = dst, *src_arg = src;
|
||||
memmove(dest_arg, src_arg, sizeof *src_arg);
|
||||
|
||||
if (src_arg->arg_flags & MIE_OP_F_ARG_RESOLVED) {
|
||||
mie_register_use_move(&dest_arg->arg_value, &src_arg->arg_value);
|
||||
}
|
||||
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
struct mie_vector_ops op_arg_vector_ops = {
|
||||
.v_destroy = op_arg_cleanup,
|
||||
.v_move = op_arg_move,
|
||||
};
|
||||
|
||||
struct mie_op *mie_op_create(void)
|
||||
{
|
||||
struct mie_op *out = malloc(sizeof *out);
|
||||
if (!out) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mie_op_init(out);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
void mie_op_destroy(struct mie_op *op)
|
||||
{
|
||||
mie_op_cleanup(op);
|
||||
free(op);
|
||||
}
|
||||
|
||||
void mie_op_init(struct mie_op *op)
|
||||
{
|
||||
memset(op, 0x0, sizeof *op);
|
||||
|
||||
mie_attribute_map_init(&op->op_attrib);
|
||||
}
|
||||
|
||||
void mie_op_cleanup(struct mie_op *op)
|
||||
{
|
||||
/* TODO */
|
||||
}
|
||||
|
||||
size_t mie_op_get_name(const struct mie_op *op, char *out, size_t max)
|
||||
{
|
||||
if (!(op->op_flags & MIE_OP_F_OP_RESOLVED)) {
|
||||
return snprintf(out, max, "%s", op->op_name);
|
||||
}
|
||||
|
||||
return snprintf(
|
||||
out, max, "%s.%s", op->op_info->op_parent->d_name,
|
||||
op->op_info->op_name);
|
||||
}
|
||||
|
||||
struct mie_op_arg *mie_op_add_arg(struct mie_op *op)
|
||||
{
|
||||
return mie_vector_emplace_back(op->op_args, &op_arg_vector_ops);
|
||||
}
|
||||
|
||||
struct mie_register *mie_op_add_result(struct mie_op *op, const struct mie_type *ty)
|
||||
{
|
||||
struct mie_register *result = mie_vector_emplace_back(
|
||||
op->op_result, &mie_register_vector_ops);
|
||||
result->reg_flags = MIE_REGISTER_F_VIRTUAL | MIE_REGISTER_F_OP_RESULT;
|
||||
result->reg_type = ty;
|
||||
result->reg_op = op;
|
||||
result->reg_block = op->op_container;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
struct mie_op_successor *mie_op_add_successor(
|
||||
struct mie_op *op, struct mie_block *block, struct mie_register **args,
|
||||
size_t nr_args)
|
||||
{
|
||||
struct mie_op_successor *s
|
||||
= mie_vector_emplace_back(op->op_successors, NULL);
|
||||
|
||||
s->s_flags = MIE_OP_F_SUCCESSOR_RESOLVED;
|
||||
s->s_block = block;
|
||||
|
||||
for (size_t i = 0; i < nr_args; i++) {
|
||||
struct mie_op_arg *arg
|
||||
= mie_vector_emplace_back(s->s_args, &op_arg_vector_ops);
|
||||
|
||||
arg->arg_flags = MIE_OP_F_ARG_RESOLVED;
|
||||
arg->arg_value.u_reg = args[i];
|
||||
arg->arg_value.u_user = op;
|
||||
b_queue_push_back(&args[i]->reg_use, &arg->arg_value.u_entry);
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
static bool is_isolated(const struct mie_op *op)
|
||||
{
|
||||
if (!(op->op_flags & MIE_OP_F_OP_RESOLVED)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const struct mie_trait *isolated = mie_trait_table_get_unique(
|
||||
&op->op_info->op_traits, "builtin", "isolated-from-above");
|
||||
return isolated != NULL;
|
||||
}
|
||||
|
||||
struct mie_region *mie_op_add_region(struct mie_op *op)
|
||||
{
|
||||
bool isolated = is_isolated(op);
|
||||
|
||||
struct mie_region *region = malloc(sizeof *region);
|
||||
if (!region) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
region->r_parent = op;
|
||||
|
||||
if (isolated) {
|
||||
region->r_names = mie_name_map_create(NULL);
|
||||
}
|
||||
|
||||
b_queue_push_back(&op->op_regions, ®ion->r_entry);
|
||||
|
||||
return region;
|
||||
}
|
||||
|
||||
bool mie_op_is(const struct mie_op *op, const char *dialect_name, const char *op_name)
|
||||
{
|
||||
if (!op->op_info || !op->op_info->op_parent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strcmp(op->op_info->op_parent->d_name, dialect_name) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strcmp(op->op_info->op_name, op_name) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool mie_op_has_trait(
|
||||
const struct mie_op *op, const char *dialect_name, const char *trait_name)
|
||||
{
|
||||
if (!op->op_info) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mie_trait_table_get_unique(
|
||||
&op->op_info->op_traits, dialect_name, trait_name)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
struct mie_trait_table_iterator it;
|
||||
enum mie_status status = mie_trait_table_get_generic(
|
||||
&op->op_info->op_traits, dialect_name, trait_name, &it);
|
||||
|
||||
return (status == MIE_SUCCESS);
|
||||
}
|
||||
|
||||
bool mie_op_has_interface(
|
||||
const struct mie_op *op, const char *dialect_name, const char *iface_name)
|
||||
{
|
||||
if (!op->op_info) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const struct mie_interface *p = mie_interface_map_get(
|
||||
&op->op_info->op_iface, dialect_name, iface_name);
|
||||
return p != NULL;
|
||||
}
|
||||
|
||||
struct mie_region *mie_op_get_first_region(const struct mie_op *op)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_first(&op->op_regions);
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return b_unbox(struct mie_region, entry, r_entry);
|
||||
}
|
||||
|
||||
struct mie_region *mie_op_get_prev_region(
|
||||
const struct mie_op *op, const struct mie_region *before)
|
||||
{
|
||||
if (!before || before->r_parent != op) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
b_queue_entry *entry = b_queue_prev(&before->r_entry);
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return b_unbox(struct mie_region, entry, r_entry);
|
||||
}
|
||||
|
||||
struct mie_region *mie_op_get_next_region(
|
||||
const struct mie_op *op, const struct mie_region *after)
|
||||
{
|
||||
if (!after || after->r_parent != op) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
b_queue_entry *entry = b_queue_next(&after->r_entry);
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return b_unbox(struct mie_region, entry, r_entry);
|
||||
}
|
||||
|
||||
struct mie_region *mie_op_get_last_region(const struct mie_op *op)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_last(&op->op_regions);
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return b_unbox(struct mie_region, entry, r_entry);
|
||||
}
|
||||
|
||||
struct mie_register *mie_op_get_arg(const struct mie_op *op, size_t index)
|
||||
{
|
||||
if (MIE_VECTOR_COUNT(op->op_args) <= index) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const struct mie_op_arg *arg = &op->op_args.items[index];
|
||||
if (!(arg->arg_flags & MIE_OP_F_ARG_RESOLVED)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return arg->arg_value.u_reg;
|
||||
}
|
||||
|
||||
struct mie_register *mie_op_get_result_with_name(
|
||||
const struct mie_op *op, const char *name)
|
||||
{
|
||||
for (size_t i = 0; i < MIE_VECTOR_COUNT(op->op_result); i++) {
|
||||
if (!strcmp(op->op_result.items[i].reg_name.n_str, name)) {
|
||||
return &op->op_result.items[i];
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct mie_op *mie_op_get_first_child_op(const struct mie_op *op)
|
||||
{
|
||||
struct mie_region *first_region = mie_op_get_first_region(op);
|
||||
if (!first_region) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct mie_block *first_block = mie_region_get_first_block(first_region);
|
||||
if (!first_block) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return mie_block_get_first_op(first_block);
|
||||
}
|
||||
|
||||
struct mie_op *mie_op_get_last_child_op(const struct mie_op *op)
|
||||
{
|
||||
struct mie_region *last_region = mie_op_get_last_region(op);
|
||||
if (!last_region) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct mie_block *last_block = mie_region_get_last_block(last_region);
|
||||
if (!last_block) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return mie_block_get_last_op(last_block);
|
||||
}
|
||||
116
mie/ir/region.c
116
mie/ir/region.c
@@ -1,18 +1,132 @@
|
||||
#include <limits.h>
|
||||
#include <mie/ctx.h>
|
||||
#include <mie/diag/diag.h>
|
||||
#include <mie/dialect/builtin.h>
|
||||
#include <mie/ir/block.h>
|
||||
#include <mie/ir/op.h>
|
||||
#include <mie/ir/region.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct mie_block *mie_region_get_first_block(const struct mie_region *region)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_first(®ion->r_blocks);
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return b_unbox(struct mie_block, entry, b_entry);
|
||||
}
|
||||
|
||||
struct mie_block *mie_region_get_prev_block(
|
||||
const struct mie_region *region, const struct mie_block *before)
|
||||
{
|
||||
if (!before || before->b_parent != region) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
b_queue_entry *entry = b_queue_prev(&before->b_entry);
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return b_unbox(struct mie_block, entry, b_entry);
|
||||
}
|
||||
|
||||
struct mie_block *mie_region_get_next_block(
|
||||
const struct mie_region *region, const struct mie_block *after)
|
||||
{
|
||||
if (!after || after->b_parent != region) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
b_queue_entry *entry = b_queue_next(&after->b_entry);
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return b_unbox(struct mie_block, entry, b_entry);
|
||||
}
|
||||
|
||||
struct mie_block *mie_region_get_last_block(const struct mie_region *region)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_last(®ion->r_blocks);
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return b_unbox(struct mie_block, entry, b_entry);
|
||||
}
|
||||
|
||||
struct mie_block *mie_region_add_block(struct mie_region *region)
|
||||
{
|
||||
struct mie_block *block = malloc(sizeof *block);
|
||||
|
||||
if (!block) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(block, 0x0, sizeof *block);
|
||||
block->b_parent = region;
|
||||
block->b_id = MIE_BLOCK_ID_INVALID;
|
||||
|
||||
mie_vector_push_back(region->r_blocks, &block);
|
||||
b_queue_push_back(®ion->r_blocks, &block->b_entry);
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
struct mie_block *mie_region_add_block_after(
|
||||
struct mie_region *region, struct mie_block *after)
|
||||
{
|
||||
if (after->b_parent != region) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct mie_block *block = malloc(sizeof *block);
|
||||
|
||||
if (!block) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(block, 0x0, sizeof *block);
|
||||
block->b_parent = region;
|
||||
|
||||
b_queue_insert_after(®ion->r_blocks, &block->b_entry, &after->b_entry);
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
struct mie_block *mie_region_find_block(
|
||||
const struct mie_region *region, const char *name)
|
||||
{
|
||||
b_queue_entry *cur = b_queue_first(®ion->r_blocks);
|
||||
while (cur) {
|
||||
struct mie_block *block = b_unbox(struct mie_block, cur, b_entry);
|
||||
if (!strcmp(block->b_name.n_str, name)) {
|
||||
return block;
|
||||
}
|
||||
|
||||
cur = b_queue_next(cur);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct mie_register *mie_region_find_register(
|
||||
const struct mie_region *region, const char *name)
|
||||
{
|
||||
b_queue_entry *cur = b_queue_first(®ion->r_blocks);
|
||||
|
||||
while (cur) {
|
||||
struct mie_block *block = b_unbox(struct mie_block, cur, b_entry);
|
||||
struct mie_register *reg
|
||||
= mie_block_find_register(block, name, NULL);
|
||||
if (reg) {
|
||||
return reg;
|
||||
}
|
||||
|
||||
cur = b_queue_next(cur);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
69
mie/ir/register.c
Normal file
69
mie/ir/register.c
Normal file
@@ -0,0 +1,69 @@
|
||||
#include <assert.h>
|
||||
#include <blue/core/queue.h>
|
||||
#include <mie/ir/register.h>
|
||||
|
||||
static enum mie_status reg_cleanup(void *p)
|
||||
{
|
||||
mie_register_cleanup(p);
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
static enum mie_status reg_move(void *dst, void *src, size_t itemsz)
|
||||
{
|
||||
assert(itemsz == sizeof(struct mie_register));
|
||||
struct mie_register *dest_reg = dst, *src_reg = src;
|
||||
mie_register_move(dest_reg, src_reg);
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
static enum mie_status reg_use_cleanup(void *p)
|
||||
{
|
||||
mie_register_use_cleanup(p);
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
static enum mie_status reg_use_move(void *dst, void *src, size_t itemsz)
|
||||
{
|
||||
assert(itemsz == sizeof(struct mie_register_use));
|
||||
struct mie_register_use *dest_reg = dst, *src_reg = src;
|
||||
mie_register_use_move(dest_reg, src_reg);
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
struct mie_vector_ops mie_register_vector_ops = {
|
||||
.v_destroy = reg_cleanup,
|
||||
.v_move = reg_move,
|
||||
};
|
||||
|
||||
void mie_register_move(struct mie_register *dest, struct mie_register *src)
|
||||
{
|
||||
memmove(dest, src, sizeof *dest);
|
||||
|
||||
if (src->reg_flags & MIE_REGISTER_F_VIRTUAL) {
|
||||
mie_name_move(&dest->reg_name, &src->reg_name);
|
||||
}
|
||||
}
|
||||
|
||||
void mie_register_cleanup(struct mie_register *reg)
|
||||
{
|
||||
if (reg->reg_flags & MIE_REGISTER_F_VIRTUAL) {
|
||||
mie_name_destroy(®->reg_name);
|
||||
}
|
||||
}
|
||||
|
||||
void mie_register_use_move(
|
||||
struct mie_register_use *dest, struct mie_register_use *src)
|
||||
{
|
||||
memmove(dest, src, sizeof *dest);
|
||||
|
||||
if (src->u_reg) {
|
||||
b_queue_move(&src->u_reg->reg_use, &src->u_entry, &dest->u_entry);
|
||||
}
|
||||
}
|
||||
|
||||
void mie_register_use_cleanup(struct mie_register_use *use)
|
||||
{
|
||||
if (use->u_reg) {
|
||||
b_queue_delete(&use->u_reg->reg_use, &use->u_entry);
|
||||
}
|
||||
}
|
||||
264
mie/ir/resolve.c
Normal file
264
mie/ir/resolve.c
Normal file
@@ -0,0 +1,264 @@
|
||||
#include <mie/ctx.h>
|
||||
#include <mie/diag/diag.h>
|
||||
#include <mie/diag/highlight.h>
|
||||
#include <mie/dialect/builtin.h>
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/ir/block.h>
|
||||
#include <mie/ir/op.h>
|
||||
#include <mie/ir/region.h>
|
||||
#include <mie/ir/register.h>
|
||||
|
||||
enum register_find_result {
|
||||
REG_FIND_NONE = 0,
|
||||
REG_FIND_USE_BEFORE_DEFINE,
|
||||
REG_FIND_UNDOMINATED,
|
||||
REG_FIND_ISOLATED,
|
||||
};
|
||||
|
||||
bool mie_op_resolve_self(struct mie_op *op, struct mie_ctx *ctx)
|
||||
{
|
||||
if (op->op_flags & MIE_OP_F_OP_RESOLVED) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const char *dialect_name = NULL, *op_name = NULL;
|
||||
|
||||
char *dot = strchr(op->op_name, '.');
|
||||
if (dot) {
|
||||
*dot = 0;
|
||||
dialect_name = op->op_name;
|
||||
op_name = dot + 1;
|
||||
} else {
|
||||
dialect_name = NULL;
|
||||
op_name = op->op_name;
|
||||
}
|
||||
|
||||
const struct mie_dialect *dialect = mie_ctx_get_dialect(ctx, dialect_name);
|
||||
if (dot) {
|
||||
*dot = '.';
|
||||
}
|
||||
|
||||
/* dialect_name is no longer valid after this point */
|
||||
dialect_name = NULL;
|
||||
|
||||
if (!dialect) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const struct mie_op_definition *op_info
|
||||
= mie_dialect_get_op(dialect, op_name);
|
||||
if (!op_info) {
|
||||
return false;
|
||||
}
|
||||
|
||||
op->op_info = op_info;
|
||||
|
||||
free(op->op_name);
|
||||
op->op_name = NULL;
|
||||
|
||||
op->op_flags |= MIE_OP_F_OP_RESOLVED;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static enum register_find_result find_register_wide(
|
||||
struct mie_op *op, const char *name, struct mie_register **out)
|
||||
{
|
||||
struct mie_region *region = op->op_container->b_parent;
|
||||
enum register_find_result result = REG_FIND_UNDOMINATED;
|
||||
struct mie_register *reg = NULL;
|
||||
|
||||
while (region) {
|
||||
reg = mie_region_find_register(region, name);
|
||||
if (reg) {
|
||||
*out = reg;
|
||||
break;
|
||||
}
|
||||
|
||||
struct mie_op *op = region->r_parent;
|
||||
if (mie_op_has_trait(op, "builtin", "isolated-from-above")) {
|
||||
result = REG_FIND_ISOLATED;
|
||||
}
|
||||
|
||||
region = op->op_container ? op->op_container->b_parent : NULL;
|
||||
}
|
||||
|
||||
if (!reg) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (reg->reg_block == op->op_container) {
|
||||
return REG_FIND_USE_BEFORE_DEFINE;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool resolve_arg(
|
||||
struct mie_op *op, struct mie_op_arg *arg, struct mie_ctx *ctx)
|
||||
{
|
||||
const char *arg_name = arg->arg_unresolved.reg_name;
|
||||
struct mie_block *block = op->op_container;
|
||||
struct mie_op *search_start = op;
|
||||
struct mie_register *reg = NULL;
|
||||
|
||||
while (block) {
|
||||
reg = mie_block_find_register(block, arg_name, search_start);
|
||||
if (reg) {
|
||||
break;
|
||||
}
|
||||
|
||||
search_start = NULL;
|
||||
block = block->b_idom;
|
||||
}
|
||||
|
||||
if (reg) {
|
||||
free(arg->arg_unresolved.reg_name);
|
||||
arg->arg_flags |= MIE_OP_F_ARG_RESOLVED;
|
||||
|
||||
memset(&arg->arg_value, 0x0, sizeof arg->arg_value);
|
||||
arg->arg_value.u_reg = reg;
|
||||
arg->arg_value.u_user = op;
|
||||
b_queue_push_back(®->reg_use, &arg->arg_value.u_entry);
|
||||
return true;
|
||||
}
|
||||
|
||||
enum register_find_result find_result
|
||||
= find_register_wide(op, arg_name, ®);
|
||||
|
||||
struct mie_diag *diag = mie_ctx_push_diag(
|
||||
ctx, op->op_src, &arg->arg_span.s_start, "builtin",
|
||||
MIE_BUILTIN_E_UNRESOLVED_VALUE);
|
||||
mie_diag_push_msg(diag, ctx, "builtin", MIE_BUILTIN_MSG_UNRESOLVED_VALUE);
|
||||
|
||||
struct mie_diag_highlight hl[] = {
|
||||
{
|
||||
.hl_type = MIE_DIAG_HIGHLIGHT_ERROR,
|
||||
.hl_span = arg->arg_span,
|
||||
},
|
||||
};
|
||||
|
||||
mie_diag_push_snippet(
|
||||
diag, arg->arg_span.s_start.c_row, arg->arg_span.s_end.c_row,
|
||||
NULL, 0, hl, 1);
|
||||
|
||||
if (!reg) {
|
||||
return false;
|
||||
}
|
||||
|
||||
struct mie_block *reg_container = reg->reg_block;
|
||||
|
||||
switch (find_result) {
|
||||
case REG_FIND_ISOLATED:
|
||||
mie_diag_push_msg(
|
||||
diag, ctx, "builtin",
|
||||
MIE_BUILTIN_MSG_VALUE_DEFINED_OUTSIDE_ISOLATED_REGION);
|
||||
break;
|
||||
case REG_FIND_UNDOMINATED:
|
||||
mie_diag_push_msg(
|
||||
diag, ctx, "builtin",
|
||||
MIE_BUILTIN_MSG_VALUE_DEFINED_IN_NON_DOMINANT_BLOCK);
|
||||
break;
|
||||
case REG_FIND_USE_BEFORE_DEFINE:
|
||||
mie_diag_push_msg(
|
||||
diag, ctx, "builtin",
|
||||
MIE_BUILTIN_MSG_VALUE_DEFINED_AFTER_USE);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
hl[0].hl_type = MIE_DIAG_HIGHLIGHT_HINT;
|
||||
hl[0].hl_span = reg->reg_span;
|
||||
|
||||
mie_diag_push_snippet(
|
||||
diag, reg->reg_span.s_start.c_row, reg->reg_span.s_end.c_row,
|
||||
NULL, 0, hl, 1);
|
||||
|
||||
if (!reg_container) {
|
||||
return false;
|
||||
}
|
||||
|
||||
hl[0].hl_span = reg_container->b_name.n_span;
|
||||
|
||||
mie_diag_push_snippet(
|
||||
diag, reg_container->b_name.n_span.s_start.c_row,
|
||||
reg_container->b_name.n_span.s_end.c_row, NULL, 0, hl, 1);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool resolve_successor(
|
||||
struct mie_op *op, struct mie_op_successor *s, struct mie_ctx *ctx)
|
||||
{
|
||||
if (s->s_flags & MIE_OP_F_SUCCESSOR_RESOLVED) {
|
||||
return true;
|
||||
}
|
||||
|
||||
struct mie_block *container = op->op_container;
|
||||
struct mie_region *region = container ? container->b_parent : NULL;
|
||||
if (!region) {
|
||||
return false;
|
||||
}
|
||||
|
||||
struct mie_diag *diag = NULL;
|
||||
struct mie_block *dest = mie_region_find_block(region, s->s_block_name);
|
||||
if (!dest) {
|
||||
diag = mie_ctx_push_diag(
|
||||
ctx, op->op_src, &s->s_name_span.s_start, "builtin",
|
||||
MIE_BUILTIN_E_UNRESOLVED_SUCCESSOR);
|
||||
mie_diag_push_msg(
|
||||
diag, ctx, "builtin", MIE_BUILTIN_MSG_CANNOT_FIND_BLOCK);
|
||||
const struct mie_diag_highlight hl[] = {
|
||||
{
|
||||
.hl_type = MIE_DIAG_HIGHLIGHT_ERROR,
|
||||
.hl_span = s->s_name_span,
|
||||
},
|
||||
};
|
||||
mie_diag_push_snippet(
|
||||
diag, s->s_name_span.s_start.c_row,
|
||||
s->s_name_span.s_end.c_row, NULL, 0, hl, 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
free(s->s_block_name);
|
||||
s->s_block = dest;
|
||||
s->s_flags |= MIE_OP_F_SUCCESSOR_RESOLVED;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool mie_op_resolve_args(struct mie_op *op, struct mie_ctx *ctx)
|
||||
{
|
||||
bool ok = true;
|
||||
|
||||
for (size_t i = 0; i < MIE_VECTOR_COUNT(op->op_args); i++) {
|
||||
if (!resolve_arg(op, &op->op_args.items[i], ctx)) {
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < MIE_VECTOR_COUNT(op->op_successors); i++) {
|
||||
struct mie_op_successor *s = &op->op_successors.items[i];
|
||||
for (size_t k = 0; k < MIE_VECTOR_COUNT(s->s_args); k++) {
|
||||
if (!resolve_arg(op, &s->s_args.items[k], ctx)) {
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool mie_op_resolve_successors(struct mie_op *op, struct mie_ctx *ctx)
|
||||
{
|
||||
bool ok = true;
|
||||
|
||||
for (size_t i = 0; i < MIE_VECTOR_COUNT(op->op_successors); i++) {
|
||||
if (!resolve_successor(op, &op->op_successors.items[i], ctx)) {
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
797
mie/ir/walk.c
Normal file
797
mie/ir/walk.c
Normal file
@@ -0,0 +1,797 @@
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/ir/block.h>
|
||||
#include <mie/ir/op-definition.h>
|
||||
#include <mie/ir/op.h>
|
||||
#include <mie/ir/region.h>
|
||||
#include <mie/ir/walk.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define WALK_ITEM_F_CHILDREN_VISITED 0x01u
|
||||
#define WALK_ITEM_F_VISITED 0x02u
|
||||
|
||||
#define ITEM_TYPE(f) ((f) & 0x0Fu)
|
||||
|
||||
static bool should_ignore_item(
|
||||
const struct mie_walker *walker, const struct mie_walk_item *item)
|
||||
{
|
||||
switch (item->i_type) {
|
||||
case MIE_WALK_ITEM_OP:
|
||||
return (walker->w_flags & MIE_WALKER_F_INCLUDE_OPS) == 0;
|
||||
case MIE_WALK_ITEM_BLOCK:
|
||||
return (walker->w_flags & MIE_WALKER_F_INCLUDE_BLOCKS) == 0;
|
||||
case MIE_WALK_ITEM_REGION:
|
||||
return (walker->w_flags & MIE_WALKER_F_INCLUDE_REGIONS) == 0;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
static void push_walk_item(
|
||||
struct mie_walker *walker, const struct mie_walk_item *item)
|
||||
{
|
||||
struct mie_walk_item *i = malloc(sizeof *i);
|
||||
if (!i) {
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(i, item, sizeof *i);
|
||||
b_queue_push_back(&walker->w_stack, &i->_e);
|
||||
}
|
||||
|
||||
static void pop_walk_item(struct mie_walker *walker)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_pop_back(&walker->w_stack);
|
||||
if (entry) {
|
||||
struct mie_walk_item *item
|
||||
= b_unbox(struct mie_walk_item, entry, _e);
|
||||
free(item);
|
||||
}
|
||||
}
|
||||
|
||||
static struct mie_walk_item *current_item(struct mie_walker *walker)
|
||||
{
|
||||
struct mie_walk_item *item = NULL;
|
||||
bool recursive = (walker->w_flags & MIE_WALKER_F_RECURSIVE) != 0;
|
||||
if (!recursive) {
|
||||
if (walker->w_flags & MIE_WALKER_F_INCLUDE_REGIONS) {
|
||||
item = &walker->w_region;
|
||||
} else if (walker->w_flags & MIE_WALKER_F_INCLUDE_BLOCKS) {
|
||||
item = &walker->w_block;
|
||||
} else {
|
||||
item = &walker->w_op;
|
||||
}
|
||||
|
||||
bool eof = !item || item->i_type != MIE_WALK_ITEM_NONE;
|
||||
return eof ? item : NULL;
|
||||
}
|
||||
|
||||
b_queue_entry *entry = b_queue_last(&walker->w_stack);
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
item = b_unbox(struct mie_walk_item, entry, _e);
|
||||
return item->i_type != MIE_WALK_ITEM_NONE ? item : NULL;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static struct mie_op *get_first_child(struct mie_walker *walker, struct mie_op *op)
|
||||
{
|
||||
bool backwards = (walker->w_flags & MIE_WALKER_F_BACKWARD) != 0;
|
||||
|
||||
while (1) {
|
||||
if (MIE_VECTOR_COUNT(op->op_regions) == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
size_t region_index
|
||||
= backwards ? MIE_VECTOR_COUNT(op->op_regions) - 1 : 0;
|
||||
struct mie_region *region = &op->op_regions.items[region_index];
|
||||
if (MIE_VECTOR_COUNT(region->r_blocks) == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
size_t block_index
|
||||
= backwards ? MIE_VECTOR_COUNT(region->r_blocks) - 1 : 0;
|
||||
struct mie_block *block = ®ion->r_blocks.items[block_index];
|
||||
if (MIE_VECTOR_COUNT(block->b_ops) == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
size_t op_index
|
||||
= backwards ? MIE_VECTOR_COUNT(block->b_ops) - 1 : 0;
|
||||
op = &block->b_ops.items[op_index];
|
||||
}
|
||||
|
||||
return op;
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool walk_item_has_children(const struct mie_walk_item *item)
|
||||
{
|
||||
switch (item->i_type) {
|
||||
case MIE_WALK_ITEM_OP:
|
||||
return mie_op_get_first_region(item->i_op) != NULL;
|
||||
case MIE_WALK_ITEM_BLOCK:
|
||||
return mie_block_get_first_op(item->i_block) != NULL;
|
||||
case MIE_WALK_ITEM_REGION:
|
||||
return mie_region_get_first_block(item->i_region) != NULL;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static bool should_correct_depth(
|
||||
struct mie_walker *walker, const struct mie_walk_item *item)
|
||||
{
|
||||
if (should_ignore_item(walker, item)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t temp = 0;
|
||||
switch (item->i_type) {
|
||||
case MIE_WALK_ITEM_BLOCK:
|
||||
return false; //(walker->w_flags & MIE_WALKER_F_INCLUDE_OPS) == 0;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool walk_item_get_first_child(
|
||||
struct mie_walker *walker, const struct mie_walk_item *item,
|
||||
struct mie_walk_item *child)
|
||||
{
|
||||
bool ok = false;
|
||||
b_queue_entry *entry = NULL;
|
||||
|
||||
switch (item->i_type) {
|
||||
case MIE_WALK_ITEM_OP:
|
||||
child->i_type = MIE_WALK_ITEM_REGION;
|
||||
child->i_region = mie_op_get_first_region(item->i_op);
|
||||
ok = child->i_region != NULL;
|
||||
break;
|
||||
case MIE_WALK_ITEM_BLOCK:
|
||||
child->i_type = MIE_WALK_ITEM_OP;
|
||||
child->i_op = mie_block_get_first_op(item->i_block);
|
||||
ok = child->i_op != NULL;
|
||||
break;
|
||||
case MIE_WALK_ITEM_REGION:
|
||||
child->i_type = MIE_WALK_ITEM_BLOCK;
|
||||
child->i_block = mie_region_get_first_block(item->i_region);
|
||||
ok = child->i_block != NULL;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
return false;
|
||||
}
|
||||
|
||||
child->i_depth = item->i_depth + 1;
|
||||
|
||||
if (should_correct_depth(walker, item)) {
|
||||
child->i_depth--;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool walk_item_get_last_child(
|
||||
struct mie_walker *walker, const struct mie_walk_item *item,
|
||||
struct mie_walk_item *child)
|
||||
{
|
||||
bool ok = false;
|
||||
b_queue_entry *entry = NULL;
|
||||
|
||||
switch (item->i_type) {
|
||||
case MIE_WALK_ITEM_OP:
|
||||
child->i_type = MIE_WALK_ITEM_REGION;
|
||||
child->i_region = mie_op_get_last_region(item->i_op);
|
||||
ok = child->i_region != NULL;
|
||||
break;
|
||||
case MIE_WALK_ITEM_BLOCK:
|
||||
child->i_type = MIE_WALK_ITEM_OP;
|
||||
child->i_op = mie_block_get_last_op(item->i_block);
|
||||
ok = child->i_op != NULL;
|
||||
break;
|
||||
case MIE_WALK_ITEM_REGION:
|
||||
child->i_type = MIE_WALK_ITEM_BLOCK;
|
||||
child->i_block = mie_region_get_last_block(item->i_region);
|
||||
ok = child->i_block != NULL;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
return false;
|
||||
}
|
||||
|
||||
child->i_depth = item->i_depth + 1;
|
||||
|
||||
if (should_correct_depth(walker, item)) {
|
||||
child->i_depth--;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool walk_item_get_next_sibling(
|
||||
const struct mie_walk_item *item, struct mie_walk_item *sibling)
|
||||
{
|
||||
if (item->i_depth == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sibling->i_depth = item->i_depth;
|
||||
sibling->i_type = item->i_type;
|
||||
|
||||
size_t index = 0;
|
||||
b_queue_entry *entry = NULL;
|
||||
struct mie_region *parent_r = NULL;
|
||||
struct mie_block *parent_b = NULL;
|
||||
struct mie_op *parent_o = NULL;
|
||||
|
||||
switch (item->i_type) {
|
||||
case MIE_WALK_ITEM_OP:
|
||||
parent_b = item->i_op->op_container;
|
||||
if (!parent_b) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sibling->i_op = mie_block_get_next_op(parent_b, item->i_op);
|
||||
return sibling->i_op != NULL;
|
||||
case MIE_WALK_ITEM_BLOCK:
|
||||
parent_r = item->i_block->b_parent;
|
||||
if (!parent_r) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sibling->i_block
|
||||
= mie_region_get_next_block(parent_r, item->i_block);
|
||||
return sibling->i_block != NULL;
|
||||
case MIE_WALK_ITEM_REGION:
|
||||
parent_o = item->i_region->r_parent;
|
||||
if (!parent_o) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sibling->i_region
|
||||
= mie_op_get_next_region(parent_o, item->i_region);
|
||||
return sibling->i_region != NULL;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool walk_item_get_prev_sibling(
|
||||
const struct mie_walk_item *item, struct mie_walk_item *sibling)
|
||||
{
|
||||
if (item->i_depth == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sibling->i_depth = item->i_depth;
|
||||
sibling->i_type = item->i_type;
|
||||
|
||||
size_t index = 0;
|
||||
struct mie_region *parent_r = NULL;
|
||||
struct mie_block *parent_b = NULL;
|
||||
struct mie_op *parent_o = NULL;
|
||||
|
||||
switch (item->i_type) {
|
||||
case MIE_WALK_ITEM_OP:
|
||||
parent_b = item->i_op->op_container;
|
||||
if (!parent_b) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sibling->i_op = mie_block_get_prev_op(parent_b, item->i_op);
|
||||
return sibling->i_op != NULL;
|
||||
case MIE_WALK_ITEM_BLOCK:
|
||||
parent_r = item->i_block->b_parent;
|
||||
if (!parent_r) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sibling->i_block
|
||||
= mie_region_get_prev_block(parent_r, item->i_block);
|
||||
return sibling->i_block != NULL;
|
||||
case MIE_WALK_ITEM_REGION:
|
||||
parent_o = item->i_region->r_parent;
|
||||
if (!parent_o) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sibling->i_region
|
||||
= mie_op_get_prev_region(parent_o, item->i_region);
|
||||
return sibling->i_region != NULL;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static void print_stack(struct mie_walker *walker)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_last(&walker->w_stack);
|
||||
|
||||
while (entry) {
|
||||
struct mie_walk_item *item
|
||||
= b_unbox(struct mie_walk_item, entry, _e);
|
||||
|
||||
switch (item->i_type) {
|
||||
case MIE_WALK_ITEM_OP:
|
||||
printf("* %zu: op %p", item->i_depth, item->i_op);
|
||||
if (item->i_op->op_flags & MIE_OP_F_OP_RESOLVED) {
|
||||
printf(" %s.%s",
|
||||
item->i_op->op_info->op_parent->d_name,
|
||||
item->i_op->op_info->op_name);
|
||||
} else {
|
||||
printf(" %s", item->i_op->op_name);
|
||||
}
|
||||
break;
|
||||
case MIE_WALK_ITEM_BLOCK:
|
||||
printf("* %zu: block %p %s", item->i_depth,
|
||||
item->i_block, item->i_block->b_name.n_str);
|
||||
break;
|
||||
case MIE_WALK_ITEM_REGION:
|
||||
printf("* %zu: region %p", item->i_depth, item->i_region);
|
||||
break;
|
||||
default:
|
||||
printf(" unknown");
|
||||
break;
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
entry = b_queue_prev(entry);
|
||||
}
|
||||
}
|
||||
|
||||
static bool step_pre_f(struct mie_walker *walker)
|
||||
{
|
||||
/* forward, pre-order traversal:
|
||||
* if this item has children, we need to visit the first one.
|
||||
* if this item has no children, we need to visit the next sibling.
|
||||
* if this is the last sibling, step up until we find an item that
|
||||
* has a next sibling.
|
||||
* if no item is found, we are done. */
|
||||
|
||||
struct mie_walk_item *item = current_item(walker);
|
||||
struct mie_walk_item next;
|
||||
|
||||
bool ok = false;
|
||||
bool has_children = walk_item_has_children(item);
|
||||
if (has_children) {
|
||||
ok = walk_item_get_first_child(walker, item, &next);
|
||||
|
||||
if (ok) {
|
||||
push_walk_item(walker, &next);
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
if (walk_item_get_next_sibling(item, &next)) {
|
||||
pop_walk_item(walker);
|
||||
push_walk_item(walker, &next);
|
||||
return true;
|
||||
}
|
||||
|
||||
static int i = 0;
|
||||
while (1) {
|
||||
pop_walk_item(walker);
|
||||
struct mie_walk_item *parent = current_item(walker);
|
||||
if (!parent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ok = walk_item_get_next_sibling(parent, &next);
|
||||
|
||||
if (ok) {
|
||||
pop_walk_item(walker);
|
||||
push_walk_item(walker, &next);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
static bool step_pre_b(struct mie_walker *walker)
|
||||
{
|
||||
/* backward, pre-order traversal:
|
||||
* if this item has children, we need to visit the last one.
|
||||
* if this item has no children, we need to visit the previous sibling.
|
||||
* if this is the first sibling, step up until we find an item that
|
||||
* has a previous sibling.
|
||||
* if no item is found, we are done. */
|
||||
|
||||
struct mie_walk_item *item = current_item(walker);
|
||||
struct mie_walk_item next;
|
||||
|
||||
bool ok = false;
|
||||
bool has_children = walk_item_has_children(item);
|
||||
if (has_children) {
|
||||
ok = walk_item_get_last_child(walker, item, &next);
|
||||
|
||||
if (ok) {
|
||||
push_walk_item(walker, &next);
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
if (walk_item_get_prev_sibling(item, &next)) {
|
||||
pop_walk_item(walker);
|
||||
push_walk_item(walker, &next);
|
||||
return true;
|
||||
}
|
||||
|
||||
static int i = 0;
|
||||
while (1) {
|
||||
pop_walk_item(walker);
|
||||
struct mie_walk_item *parent = current_item(walker);
|
||||
if (!parent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ok = walk_item_get_prev_sibling(parent, &next);
|
||||
|
||||
if (ok) {
|
||||
pop_walk_item(walker);
|
||||
push_walk_item(walker, &next);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
static bool step_post_f(struct mie_walker *walker)
|
||||
{
|
||||
/* forward, post-order traversal:
|
||||
* if this item has children:
|
||||
* if they have already been visited, visit the item itself
|
||||
* if they haven't been visited yet, visit the first one.
|
||||
* if this item has a next sibling, move to the sibling and goto step 1.
|
||||
* if this item is the last child, we need to visit the parent next. */
|
||||
struct mie_walk_item *item = current_item(walker);
|
||||
item->_f |= WALK_ITEM_F_VISITED;
|
||||
|
||||
struct mie_walk_item next;
|
||||
bool ok = false;
|
||||
|
||||
while (1) {
|
||||
item = current_item(walker);
|
||||
bool has_children = walk_item_has_children(item);
|
||||
|
||||
if (has_children && !(item->_f & WALK_ITEM_F_CHILDREN_VISITED)) {
|
||||
ok = walk_item_get_first_child(walker, item, &next);
|
||||
|
||||
if (ok) {
|
||||
push_walk_item(walker, &next);
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
if (!has_children && !(item->_f & WALK_ITEM_F_VISITED)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (walk_item_get_next_sibling(item, &next)) {
|
||||
pop_walk_item(walker);
|
||||
push_walk_item(walker, &next);
|
||||
continue;
|
||||
}
|
||||
|
||||
pop_walk_item(walker);
|
||||
struct mie_walk_item *parent = current_item(walker);
|
||||
if (parent) {
|
||||
parent->_f |= WALK_ITEM_F_CHILDREN_VISITED;
|
||||
}
|
||||
|
||||
return parent != NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static bool step_flat_f(struct mie_walker *walker)
|
||||
{
|
||||
struct mie_walk_item *stack[] = {
|
||||
&walker->w_region,
|
||||
&walker->w_block,
|
||||
&walker->w_op,
|
||||
};
|
||||
const int stack_size = sizeof stack / sizeof stack[0];
|
||||
|
||||
int start;
|
||||
if (walker->w_flags & MIE_WALKER_F_INCLUDE_REGIONS) {
|
||||
start = 0;
|
||||
} else if (walker->w_flags & MIE_WALKER_F_INCLUDE_BLOCKS) {
|
||||
start = 1;
|
||||
} else {
|
||||
start = 2;
|
||||
}
|
||||
|
||||
int i;
|
||||
for (i = start; i >= 0; i--) {
|
||||
struct mie_walk_item *item = stack[i];
|
||||
struct mie_walk_item next;
|
||||
if (walk_item_get_next_sibling(item, &next)) {
|
||||
*item = next;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int k = i; k < stack_size - 1; k++) {
|
||||
struct mie_walk_item *parent = stack[k];
|
||||
struct mie_walk_item *child = stack[k + 1];
|
||||
|
||||
if (!walk_item_get_first_child(walker, parent, child)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool step_flat_b(struct mie_walker *walker)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool step_post_b(struct mie_walker *walker)
|
||||
{
|
||||
/* backward, post-order traversal:
|
||||
* if this item has children:
|
||||
* if they have already been visited, visit the item itself
|
||||
* if they haven't been visited yet, visit the last one.
|
||||
* if this item has a previous sibling, move to the sibling and goto step 1.
|
||||
* if this item is the first child, we need to visit the parent next. */
|
||||
struct mie_walk_item *item = current_item(walker);
|
||||
item->_f |= WALK_ITEM_F_VISITED;
|
||||
|
||||
struct mie_walk_item next;
|
||||
bool ok = false;
|
||||
|
||||
while (1) {
|
||||
item = current_item(walker);
|
||||
bool has_children = walk_item_has_children(item);
|
||||
|
||||
if (has_children && !(item->_f & WALK_ITEM_F_CHILDREN_VISITED)) {
|
||||
ok = walk_item_get_last_child(walker, item, &next);
|
||||
|
||||
if (ok) {
|
||||
push_walk_item(walker, &next);
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
if (!has_children && !(item->_f & WALK_ITEM_F_VISITED)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (walk_item_get_prev_sibling(item, &next)) {
|
||||
pop_walk_item(walker);
|
||||
push_walk_item(walker, &next);
|
||||
continue;
|
||||
}
|
||||
|
||||
pop_walk_item(walker);
|
||||
struct mie_walk_item *parent = current_item(walker);
|
||||
if (parent) {
|
||||
parent->_f |= WALK_ITEM_F_CHILDREN_VISITED;
|
||||
}
|
||||
|
||||
return parent != NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static bool step(struct mie_walker *walker)
|
||||
{
|
||||
bool recursive = (walker->w_flags & MIE_WALKER_F_RECURSIVE) != 0;
|
||||
bool backward = (walker->w_flags & MIE_WALKER_F_BACKWARD) != 0;
|
||||
bool postorder = (walker->w_flags & MIE_WALKER_F_POSTORDER) != 0;
|
||||
|
||||
if (!recursive) {
|
||||
return backward ? step_flat_b(walker) : step_flat_f(walker);
|
||||
} else if (postorder) {
|
||||
return backward ? step_post_b(walker) : step_post_f(walker);
|
||||
} else {
|
||||
return backward ? step_pre_b(walker) : step_pre_f(walker);
|
||||
}
|
||||
}
|
||||
|
||||
static enum mie_status prepare_flat_traversal(
|
||||
struct mie_walker *walker, const struct mie_op *op)
|
||||
{
|
||||
bool backward = (walker->w_flags & MIE_WALKER_F_BACKWARD) != 0;
|
||||
bool ok = false;
|
||||
enum mie_walk_item_type target_type = MIE_WALK_ITEM_NONE;
|
||||
enum mie_status status = MIE_SUCCESS;
|
||||
|
||||
struct mie_walk_item root = {};
|
||||
root.i_op = (struct mie_op *)op;
|
||||
root.i_type = MIE_WALK_ITEM_OP;
|
||||
|
||||
if (walker->w_flags & MIE_WALKER_F_INCLUDE_REGIONS) {
|
||||
target_type = MIE_WALK_ITEM_REGION;
|
||||
} else if (walker->w_flags & MIE_WALKER_F_INCLUDE_BLOCKS) {
|
||||
target_type = MIE_WALK_ITEM_BLOCK;
|
||||
} else {
|
||||
target_type = MIE_WALK_ITEM_OP;
|
||||
}
|
||||
|
||||
bool has_children = walk_item_has_children(&root);
|
||||
if (!has_children) {
|
||||
return MIE_ERR_NO_DATA;
|
||||
}
|
||||
|
||||
if (backward) {
|
||||
ok = walk_item_get_last_child(walker, &root, &walker->w_region);
|
||||
status = ok ? MIE_SUCCESS : MIE_ERR_NO_DATA;
|
||||
} else {
|
||||
ok = walk_item_get_first_child(walker, &root, &walker->w_region);
|
||||
status = ok ? MIE_SUCCESS : MIE_ERR_NO_DATA;
|
||||
}
|
||||
|
||||
if (status != MIE_SUCCESS) {
|
||||
return status;
|
||||
}
|
||||
|
||||
if (target_type == MIE_WALK_ITEM_REGION) {
|
||||
walker->w_region.i_depth = 1;
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
has_children = walk_item_has_children(&walker->w_region);
|
||||
if (!has_children) {
|
||||
return MIE_ERR_NO_DATA;
|
||||
}
|
||||
|
||||
if (backward) {
|
||||
ok = walk_item_get_last_child(
|
||||
walker, &walker->w_region, &walker->w_block);
|
||||
status = ok ? MIE_SUCCESS : MIE_ERR_NO_DATA;
|
||||
} else {
|
||||
ok = walk_item_get_first_child(
|
||||
walker, &walker->w_region, &walker->w_block);
|
||||
status = ok ? MIE_SUCCESS : MIE_ERR_NO_DATA;
|
||||
}
|
||||
|
||||
if (status != MIE_SUCCESS) {
|
||||
return status;
|
||||
}
|
||||
|
||||
if (target_type == MIE_WALK_ITEM_BLOCK) {
|
||||
walker->w_block.i_depth = 1;
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
has_children = walk_item_has_children(&walker->w_block);
|
||||
if (!has_children) {
|
||||
return MIE_ERR_NO_DATA;
|
||||
}
|
||||
|
||||
if (backward) {
|
||||
ok = walk_item_get_last_child(
|
||||
walker, &walker->w_block, &walker->w_op);
|
||||
status = ok ? MIE_SUCCESS : MIE_ERR_NO_DATA;
|
||||
} else {
|
||||
ok = walk_item_get_first_child(
|
||||
walker, &walker->w_block, &walker->w_op);
|
||||
status = ok ? MIE_SUCCESS : MIE_ERR_NO_DATA;
|
||||
}
|
||||
|
||||
walker->w_op.i_depth = 1;
|
||||
return status;
|
||||
}
|
||||
|
||||
static enum mie_status prepare_preorder_traversal(
|
||||
struct mie_walker *walker, const struct mie_op *root)
|
||||
{
|
||||
struct mie_walk_item *item = malloc(sizeof *item);
|
||||
if (!item) {
|
||||
return MIE_ERR_NO_MEMORY;
|
||||
}
|
||||
|
||||
memset(item, 0x0, sizeof *item);
|
||||
item->i_op = (struct mie_op *)root;
|
||||
item->i_type = MIE_WALK_ITEM_OP;
|
||||
|
||||
push_walk_item(walker, item);
|
||||
|
||||
return MIE_SUCCESS;
|
||||
}
|
||||
|
||||
static enum mie_status prepare_postorder_traversal(
|
||||
struct mie_walker *walker, const struct mie_op *root)
|
||||
{
|
||||
struct mie_walk_item item = {};
|
||||
item.i_op = (struct mie_op *)root;
|
||||
item.i_type = MIE_WALK_ITEM_OP;
|
||||
|
||||
push_walk_item(walker, &item);
|
||||
|
||||
bool backward = walker->w_flags & MIE_WALKER_F_BACKWARD;
|
||||
bool ok = false;
|
||||
|
||||
while (1) {
|
||||
struct mie_walk_item *current = current_item(walker);
|
||||
struct mie_walk_item child;
|
||||
bool has_children = walk_item_has_children(current);
|
||||
if (!has_children) {
|
||||
break;
|
||||
}
|
||||
|
||||
bool ok = false;
|
||||
|
||||
if (backward) {
|
||||
ok = walk_item_get_last_child(walker, current, &child);
|
||||
} else {
|
||||
ok = walk_item_get_first_child(walker, current, &child);
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
break;
|
||||
}
|
||||
|
||||
push_walk_item(walker, &child);
|
||||
}
|
||||
|
||||
return ok ? MIE_SUCCESS : MIE_ERR_NO_DATA;
|
||||
}
|
||||
|
||||
void mie_walker_begin(
|
||||
struct mie_walker *walker, const struct mie_op *op,
|
||||
enum mie_walker_flags flags)
|
||||
{
|
||||
memset(walker, 0x0, sizeof *walker);
|
||||
|
||||
walker->w_flags = flags;
|
||||
|
||||
if (!(flags & MIE_WALKER_F_RECURSIVE)) {
|
||||
prepare_flat_traversal(walker, op);
|
||||
} else if (flags & MIE_WALKER_F_POSTORDER) {
|
||||
prepare_postorder_traversal(walker, op);
|
||||
} else {
|
||||
prepare_preorder_traversal(walker, op);
|
||||
}
|
||||
|
||||
struct mie_walk_item *cur = current_item(walker);
|
||||
if (cur && should_ignore_item(walker, cur)) {
|
||||
mie_walker_step(walker);
|
||||
}
|
||||
}
|
||||
|
||||
void mie_walker_end(struct mie_walker *walker)
|
||||
{
|
||||
/* TODO */
|
||||
}
|
||||
|
||||
enum mie_status mie_walker_step(struct mie_walker *walker)
|
||||
{
|
||||
struct mie_walk_item *cur = current_item(walker);
|
||||
bool ok = false;
|
||||
|
||||
do {
|
||||
ok = step(walker);
|
||||
cur = current_item(walker);
|
||||
} while (ok && cur && should_ignore_item(walker, cur));
|
||||
|
||||
return (ok && cur) ? MIE_SUCCESS : MIE_ERR_NO_DATA;
|
||||
}
|
||||
|
||||
struct mie_walk_item *mie_walker_get(struct mie_walker *walker)
|
||||
{
|
||||
return current_item(walker);
|
||||
}
|
||||
254
mie/lt-idom.c
Normal file
254
mie/lt-idom.c
Normal file
@@ -0,0 +1,254 @@
|
||||
#include <mie/ir/block.h>
|
||||
#include <mie/ir/op.h>
|
||||
#include <mie/ir/region.h>
|
||||
#include <stdio.h>
|
||||
|
||||
struct set {
|
||||
MIE_VECTOR_DECLARE(unsigned int, v);
|
||||
};
|
||||
|
||||
struct dfs_stack_item {
|
||||
struct mie_block *i_parent, *i_node;
|
||||
};
|
||||
|
||||
struct lt_ctx {
|
||||
size_t nr_nodes;
|
||||
struct mie_block **vertex;
|
||||
struct set *bucket;
|
||||
unsigned int *semi;
|
||||
unsigned int *idom;
|
||||
unsigned int *samedom;
|
||||
unsigned int *parent;
|
||||
unsigned int *ancestor;
|
||||
unsigned int *label;
|
||||
|
||||
MIE_VECTOR_DECLARE(struct dfs_stack_item, dfstack);
|
||||
};
|
||||
|
||||
#if 0
|
||||
static B_BTREE_DEFINE_SIMPLE_INSERT(struct mie_block, b_node, b_id, put_block_by_id);
|
||||
static B_BTREE_DEFINE_SIMPLE_GET(
|
||||
struct mie_block, size_t, b_node, b_id, get_block_by_id);
|
||||
#endif
|
||||
|
||||
static void set_add(struct set *set, unsigned int val)
|
||||
{
|
||||
for (size_t i = 0; i < MIE_VECTOR_COUNT(set->v); i++) {
|
||||
if (set->v.items[i] == val) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
mie_vector_push_back(set->v, &val, NULL);
|
||||
}
|
||||
|
||||
static struct mie_block *pop_block_successor(
|
||||
MIE_VECTOR_REF_PARAM(struct mie_block *, successors))
|
||||
{
|
||||
size_t count = mie_vector_ref_get_count(successors);
|
||||
if (count == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
struct mie_block *out = mie_vector_ref_get_item(successors, count - 1);
|
||||
mie_vector_ref_pop_back(successors, NULL);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
static void enqueue_block_successors(
|
||||
struct mie_block *block,
|
||||
MIE_VECTOR_REF_PARAM(struct mie_block *, successors))
|
||||
{
|
||||
struct mie_op_successor *s = mie_block_get_first_successor(block);
|
||||
struct mie_block_predecessor pred = {.p_block = block};
|
||||
|
||||
while (s) {
|
||||
if (s->s_flags & MIE_OP_F_SUCCESSOR_RESOLVED) {
|
||||
mie_vector_ref_push_back(successors, &s->s_block, NULL);
|
||||
mie_vector_push_back(s->s_block->b_ipred, &pred, NULL);
|
||||
}
|
||||
|
||||
s = mie_block_get_next_successor(block, s);
|
||||
}
|
||||
}
|
||||
|
||||
static void dfs_stack_pop(
|
||||
struct lt_ctx *ctx, struct mie_block **parent, struct mie_block **node)
|
||||
{
|
||||
size_t nr = MIE_VECTOR_COUNT(ctx->dfstack);
|
||||
if (!nr) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct dfs_stack_item *item = &ctx->dfstack.items[nr - 1];
|
||||
*parent = item->i_parent;
|
||||
*node = item->i_node;
|
||||
mie_vector_pop_back(ctx->dfstack, NULL);
|
||||
}
|
||||
|
||||
static void dfs_stack_push(
|
||||
struct lt_ctx *ctx, struct mie_block *parent, struct mie_block *node)
|
||||
{
|
||||
struct dfs_stack_item item = {.i_node = node, .i_parent = parent};
|
||||
mie_vector_push_back(ctx->dfstack, &item, NULL);
|
||||
}
|
||||
|
||||
static void dfs(struct lt_ctx *ctx, struct mie_block *root)
|
||||
{
|
||||
dfs_stack_push(ctx, NULL, root);
|
||||
unsigned int id = 1;
|
||||
|
||||
while (MIE_VECTOR_COUNT(ctx->dfstack) > 0) {
|
||||
struct mie_block *p, *n;
|
||||
dfs_stack_pop(ctx, &p, &n);
|
||||
|
||||
if (n->b_id != MIE_BLOCK_ID_INVALID) {
|
||||
continue;
|
||||
}
|
||||
|
||||
#if 0
|
||||
printf("dfs(p=%s, n=%s)\n", p ? p->b_name.n_str : "NA",
|
||||
n->b_name.n_str);
|
||||
#endif
|
||||
|
||||
n->b_id = id++;
|
||||
ctx->vertex[n->b_id] = n;
|
||||
ctx->semi[n->b_id] = n->b_id;
|
||||
ctx->parent[n->b_id] = p ? p->b_id : MIE_BLOCK_ID_INVALID;
|
||||
|
||||
struct mie_op_successor *s = mie_block_get_first_successor(n);
|
||||
while (s) {
|
||||
dfs_stack_push(ctx, n, s->s_block);
|
||||
mie_vector_push_back(s->s_block->b_ipred, &n, NULL);
|
||||
s = mie_block_get_next_successor(n, s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void link(struct lt_ctx *ctx, unsigned int parent, unsigned int node)
|
||||
{
|
||||
ctx->ancestor[node] = parent;
|
||||
ctx->label[node] = node;
|
||||
}
|
||||
|
||||
static unsigned int eval(struct lt_ctx *ctx, unsigned int v)
|
||||
{
|
||||
unsigned int a = ctx->ancestor[v];
|
||||
if (ctx->ancestor[a] > MIE_BLOCK_ID_INVALID) {
|
||||
unsigned int b = eval(ctx, a);
|
||||
ctx->ancestor[v] = ctx->ancestor[a];
|
||||
if (ctx->semi[b] < ctx->semi[ctx->label[v]]) {
|
||||
ctx->label[v] = b;
|
||||
}
|
||||
}
|
||||
|
||||
return ctx->label[v];
|
||||
}
|
||||
|
||||
static void reset_block_relationship_metadata(struct mie_region *region)
|
||||
{
|
||||
b_queue_entry *cur = b_queue_first(®ion->r_blocks);
|
||||
while (cur) {
|
||||
struct mie_block *block = b_unbox(struct mie_block, cur, b_entry);
|
||||
|
||||
block->b_id = MIE_BLOCK_ID_INVALID;
|
||||
block->b_idom = NULL;
|
||||
// block->b_sdom = block->b_dfs_parent = NULL;
|
||||
mie_vector_destroy(block->b_ipred, NULL);
|
||||
|
||||
cur = b_queue_next(cur);
|
||||
}
|
||||
|
||||
memset(®ion->r_blocks_s, 0x0, sizeof region->r_blocks_s);
|
||||
}
|
||||
|
||||
static void lt_ctx_init(struct lt_ctx *ctx, size_t nr_nodes)
|
||||
{
|
||||
memset(ctx, 0x0, sizeof *ctx);
|
||||
ctx->idom = calloc(nr_nodes + 1, sizeof(unsigned int));
|
||||
ctx->samedom = calloc(nr_nodes + 1, sizeof(unsigned int));
|
||||
ctx->vertex = calloc(nr_nodes + 1, sizeof(struct mie_block *));
|
||||
ctx->bucket = calloc(nr_nodes + 1, sizeof(struct set));
|
||||
ctx->semi = calloc(nr_nodes + 1, sizeof(unsigned int));
|
||||
ctx->parent = calloc(nr_nodes + 1, sizeof(unsigned int));
|
||||
ctx->ancestor = calloc(nr_nodes + 1, sizeof(unsigned int));
|
||||
ctx->label = calloc(nr_nodes + 1, sizeof(unsigned int));
|
||||
}
|
||||
|
||||
static void lt_ctx_cleanup(struct lt_ctx *ctx)
|
||||
{
|
||||
free(ctx->idom);
|
||||
free(ctx->samedom);
|
||||
free(ctx->vertex);
|
||||
free(ctx->bucket);
|
||||
free(ctx->semi);
|
||||
free(ctx->parent);
|
||||
free(ctx->ancestor);
|
||||
free(ctx->label);
|
||||
}
|
||||
|
||||
void mie_region_refresh_dominance(struct mie_region *region)
|
||||
{
|
||||
struct lt_ctx ctx;
|
||||
size_t nr_nodes = b_queue_length(®ion->r_blocks);
|
||||
lt_ctx_init(&ctx, nr_nodes);
|
||||
|
||||
struct mie_block *root = mie_region_get_first_block(region);
|
||||
|
||||
reset_block_relationship_metadata(region);
|
||||
dfs(&ctx, root);
|
||||
|
||||
for (size_t i = nr_nodes; i > 0; i--) {
|
||||
struct mie_block *n = ctx.vertex[i];
|
||||
unsigned int p = ctx.parent[i];
|
||||
unsigned int s = p;
|
||||
|
||||
struct mie_block_predecessor *pred
|
||||
= mie_block_get_first_predecessor(n);
|
||||
while (pred) {
|
||||
struct mie_block *v = pred->p_block;
|
||||
unsigned int s_prime = MIE_BLOCK_ID_INVALID;
|
||||
|
||||
if (v->b_id <= n->b_id) {
|
||||
s_prime = v->b_id;
|
||||
} else {
|
||||
s_prime = eval(&ctx, v->b_id);
|
||||
s_prime = ctx.semi[s_prime];
|
||||
}
|
||||
|
||||
if (s_prime < s) {
|
||||
s = s_prime;
|
||||
}
|
||||
|
||||
pred = mie_block_get_next_predecessor(n, pred);
|
||||
}
|
||||
|
||||
ctx.semi[n->b_id] = s;
|
||||
set_add(&ctx.bucket[s], n->b_id);
|
||||
link(&ctx, p, n->b_id);
|
||||
|
||||
for (size_t k = 0; k < MIE_VECTOR_COUNT(ctx.bucket[p].v); k++) {
|
||||
unsigned int v = ctx.bucket[p].v.items[k];
|
||||
unsigned int y = eval(&ctx, v);
|
||||
if (ctx.semi[y] == ctx.semi[p]) {
|
||||
ctx.idom[v] = p;
|
||||
} else {
|
||||
ctx.samedom[v] = y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 1; i <= nr_nodes; i++) {
|
||||
struct mie_block *n = ctx.vertex[i];
|
||||
if (ctx.samedom[i] > 0) {
|
||||
ctx.idom[i] = ctx.idom[ctx.samedom[i]];
|
||||
}
|
||||
|
||||
n->b_idom = ctx.vertex[ctx.idom[i]];
|
||||
// n->b_sdom = ctx.vertex[ctx.semi[i]];
|
||||
// n->b_dfs_parent = ctx.vertex[ctx.parent[i]];
|
||||
}
|
||||
|
||||
lt_ctx_cleanup(&ctx);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user