-
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.
Refatoraçao no leitor e no extrator de labels; Criaçao de erros custo…
…mizados
- Loading branch information
Showing
8 changed files
with
268 additions
and
70 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
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
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 |
---|---|---|
@@ -1,42 +1,26 @@ | ||
package extractor | ||
|
||
import ( | ||
"ph1-assembly/decoder" | ||
"ph1-assembly/input" | ||
) | ||
|
||
// ExtractLabels efetua a primeira passagem no código, guardando os rótulos | ||
// e seus endereços em um map que irá retornar | ||
func ExtractLabels(contents []*input.SourceLine) map[string]int { | ||
func ExtractLabels(src *input.Source) map[string]int { | ||
labels := map[string]int{} | ||
|
||
var labelMap = make(map[string]int) | ||
|
||
sections := map[string]int{ | ||
"text": 0, | ||
"data": 128, | ||
} | ||
currentSection := "" | ||
|
||
for _, srcLine := range contents { | ||
if _, ok := sections[srcLine.Name]; ok { | ||
currentSection = srcLine.Name | ||
continue | ||
} | ||
|
||
srcLine.Address = sections[currentSection] | ||
|
||
_, size, _ := decoder.Decode(srcLine.Name) | ||
|
||
if size == 0 { | ||
size = 1 | ||
// Encontra as labels | ||
for _, srcText := range src.Text { | ||
if srcText.Label != "" { | ||
labels[srcText.Label] = srcText.Address | ||
} | ||
sections[currentSection] += size | ||
} | ||
|
||
// Adiciona o label no map se a label não for vazia | ||
if srcLine.Label != "" { | ||
labelMap[srcLine.Label] = srcLine.Address | ||
for _, srcData := range src.Data { | ||
if srcData.Label != "" { | ||
labels[srcData.Label] = srcData.Address | ||
} | ||
} | ||
|
||
return labelMap | ||
return labels | ||
} |
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
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,46 @@ | ||
package pherror | ||
|
||
var ( | ||
//MissingInputFile erro de arquivo de entrada não informado | ||
MissingInputFile = &ErrorType{ | ||
Code: 1, | ||
Message: "No input file given", | ||
} | ||
|
||
//FileNotFound erro arquivo não encontrado | ||
FileNotFound = &ErrorType{ | ||
Code: 2, | ||
Message: "File \"%s\" not found", | ||
} | ||
|
||
//CannotOpenFile erro genérico ao falhar tentando abrir um arquivo | ||
CannotOpenFile = &ErrorType{ | ||
Code: 3, | ||
Message: "Error opening file %s", | ||
} | ||
|
||
//LabelNotFound erro de label não encontrada | ||
LabelNotFound = &ErrorType{ | ||
Code: 4, | ||
Message: "Label \"%s\" not found", | ||
} | ||
|
||
//NoneInstructionFound erro de nome de instrução não encontrado | ||
NoneInstructionFound = &ErrorType{ | ||
Code: 5, | ||
Message: "None instruction found for \"%s\"", | ||
} | ||
|
||
//InvalidOperandCount erro de quantidade de operadores invalidas | ||
InvalidOperandCount = &ErrorType{ | ||
Code: 6, | ||
Message: "Invalid operand count", | ||
} | ||
|
||
//DecoratorNotFound erro retornado ao não encontrar nenhuma instrução ou | ||
// decorador com o nome informado | ||
DecoratorNotFound = &ErrorType{ | ||
Code: 7, | ||
Message: "Decorator or instruction not found for \"%s\"", | ||
} | ||
) |
Oops, something went wrong.