-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Converted `gen` package to use an internal CFG based representation
- Loading branch information
Showing
70 changed files
with
1,999 additions
and
1,442 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
func @main { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
func @main { | ||
.loop | ||
j .loop | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
func @main { | ||
%n = $64 #0 | ||
.loop | ||
put %n | ||
%n = add %n $64 #1 | ||
%cond = add %n $64 #-10 | ||
jnz %cond .loop | ||
term | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package gen | ||
|
||
import ( | ||
"alon.kr/x/list" | ||
"alon.kr/x/usm/core" | ||
"alon.kr/x/usm/parse" | ||
) | ||
|
||
type ArgumentGenerator struct { | ||
RegisterArgumentGenerator InstructionContextGenerator[parse.RegisterNode, ArgumentInfo] | ||
ImmediateArgumentGenerator InstructionContextGenerator[parse.ImmediateNode, ArgumentInfo] | ||
LabelArgumentGenerator InstructionContextGenerator[parse.LabelNode, ArgumentInfo] | ||
} | ||
|
||
func NewArgumentGenerator() InstructionContextGenerator[parse.ArgumentNode, ArgumentInfo] { | ||
return InstructionContextGenerator[parse.ArgumentNode, ArgumentInfo]( | ||
&ArgumentGenerator{ | ||
RegisterArgumentGenerator: NewRegisterArgumentGenerator(), | ||
ImmediateArgumentGenerator: NewImmediateArgumentGenerator(), | ||
LabelArgumentGenerator: NewLabelArgumentGenerator(), | ||
}, | ||
) | ||
} | ||
|
||
func (g *ArgumentGenerator) Generate( | ||
ctx *InstructionGenerationContext, | ||
node parse.ArgumentNode, | ||
) (ArgumentInfo, core.ResultList) { | ||
switch typedNode := node.(type) { | ||
case parse.RegisterNode: | ||
return g.RegisterArgumentGenerator.Generate(ctx, typedNode) | ||
case parse.ImmediateNode: | ||
return g.ImmediateArgumentGenerator.Generate(ctx, typedNode) | ||
case parse.LabelNode: | ||
return g.LabelArgumentGenerator.Generate(ctx, typedNode) | ||
default: | ||
v := node.View() | ||
return nil, list.FromSingle(core.Result{{ | ||
Type: core.InternalErrorResult, | ||
Message: "Unsupported argument type", | ||
Location: &v, | ||
}}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package gen | ||
|
||
import "alon.kr/x/usm/core" | ||
|
||
type ArgumentInfo interface { | ||
// A pointer to the ReferencedTypeInfo instance that corresponds to the | ||
// type of the argument. Nil if the argument does not have a type (for | ||
// example, a label). | ||
GetType() *ReferencedTypeInfo | ||
|
||
// The location where the argument appears in the source code. | ||
Declaration() core.UnmanagedSourceView | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package gen | ||
|
||
type BasicBlockInfo struct { | ||
Instructions []*InstructionInfo | ||
|
||
ForwardEdges []*BasicBlockInfo | ||
BackwardEdges []*BasicBlockInfo | ||
|
||
// All basic blocks in a function have a defined ordering between them. | ||
// The initial ordering that the USM engine produces is the order in which | ||
// the basic blocks appear in the source code. | ||
// the `NextBlock` field points to the next block that follows this block | ||
// in the ordering, or nil if this is the last basic block in the function. | ||
NextBlock *BasicBlockInfo | ||
} | ||
|
||
func NewEmptyBasicBlockInfo() *BasicBlockInfo { | ||
return &BasicBlockInfo{ | ||
Instructions: []*InstructionInfo{}, | ||
|
||
ForwardEdges: []*BasicBlockInfo{}, | ||
BackwardEdges: []*BasicBlockInfo{}, | ||
|
||
NextBlock: nil, | ||
} | ||
} | ||
|
||
func (b *BasicBlockInfo) AppendInstruction(instruction *InstructionInfo) { | ||
b.Instructions = append(b.Instructions, instruction) | ||
instruction.LinkToBasicBlock(b) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package gen | ||
|
||
type FileInfo struct { | ||
Functions []*FunctionInfo | ||
} |
Oops, something went wrong.