summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPixel <>2001-04-17 06:55:02 +0000
committerPixel <>2001-04-17 06:55:02 +0000
commita7bc5cfa7399926941a3754e3cbdc671f24b4b3d (patch)
tree6527baa45482798b61777cae9bf84eccb44075db
parent502e0cd237a9a474b224ab9a741fe4d91ecdec36 (diff)
Pout
-rw-r--r--doc/Makefile.am8
-rw-r--r--doc/archi.tex1
-rw-r--r--doc/conclusion.tex22
-rw-r--r--doc/exemples.tex171
-rw-r--r--doc/manuel.tex74
-rw-r--r--doc/probs.tex112
-rw-r--r--lib/assembler.c234
-rw-r--r--lib/hash.c8
-rw-r--r--lib/linker.c26
-rw-r--r--lib/meta.c63
-rw-r--r--lib/parser.c9
-rw-r--r--lib/simulator.c54
-rw-r--r--samples/Makefile.am8
-rw-r--r--samples/Makefile.samples11
-rw-r--r--samples/fichier1.s6
-rw-r--r--samples/fichier2.s3
-rw-r--r--samples/testtout.s11
17 files changed, 505 insertions, 316 deletions
diff --git a/doc/Makefile.am b/doc/Makefile.am
index d707057..08651de 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -1,13 +1,13 @@
EXTRA_DIST = registres.txt archi.tex bib.tex compilateur.tex conclusion.tex description.tex encodage.tex exemples.tex extensions.tex intro.tex manuel.tex probs.tex simulateur.tex Makefile.doc
-all: archi.ps
-
-source.tex:
- make -f Makefile.doc source
+#all: archi.ps
archi.dvi: archi.tex bib.tex compilateur.tex conclusion.tex description.tex encodage.tex exemples.tex extensions.tex intro.tex manuel.tex probs.tex simulateur.tex source.tex
make -f Makefile.doc
+source.tex:
+ make -f Makefile.doc source
+
archi.ps: archi.dvi
make -f Makefile.doc archi.ps
diff --git a/doc/archi.tex b/doc/archi.tex
index 20a1df8..f522549 100644
--- a/doc/archi.tex
+++ b/doc/archi.tex
@@ -11,6 +11,7 @@
\usepackage{fancyhdr}
\usepackage{oldstyle}
\usepackage{listings}
+\usepackage{verbatim}
%fin des initialisations--------------------------------------------------------
\pagestyle{fancyplain}
diff --git a/doc/conclusion.tex b/doc/conclusion.tex
index 263ea97..951ef8d 100644
--- a/doc/conclusion.tex
+++ b/doc/conclusion.tex
@@ -2,16 +2,12 @@
\addcontentsline{toc}{chapter}{Conclusion}
\markboth{CONCLUSION}{CONCLUSION}
-
-
-A MODIFIER
-
-
-
-Nous avons présenté ici nos idées pour la conception du projet. Ce
-document constitue donc un premier "cahier des charges". Nous tenterons
-de nous y tenir le plus possible afin de mener le projet à bien. Toutefois, nous
-serons peut-être (sans doute) amenés à effectuer des modifications au
-fil du développement. C'est pourquoi nous rééditerons ce document
-ultérieurement, afin d'y reporter les changements éventuels que nous
-aurons jugé utile d'effectuer.
+Ce projet a été mené à terme, et l'ensemble des idées de l'anayse ont pu être implémentées.
+L'effort de recherche mené sur l'évaluation des expression et des langages de programmation a
+sans aucun doutes été profitable pour notre connaissance personnelle. La programmation sur le simulateur
+nous a apporté une rigueur de programmation imposée par le sujet (programmation en binaire)
+L'ensemble des objectifs du projet ont été atteint et il est certain que nous avons dépassé
+les objectifs de base, pour notre propre amusement et intérêt. Il pourrait être intéressant de
+continuer à programmer quelques application en assembleur pour ce simulateur, et pourquoi pas, un compilateur
+d'un langage haut niveau vers cet assembleur. Mais ce dernier objectif ne pourra être réalisé qu'en maîtrise,
+lors du cours sur les compilateurs.
diff --git a/doc/exemples.tex b/doc/exemples.tex
index b68790b..c02ed87 100644
--- a/doc/exemples.tex
+++ b/doc/exemples.tex
@@ -1,4 +1,171 @@
\chapter{Exemples de simulations}
-%exemple de simulation avec "screenshots"
-% . codes d exemple commentes
+Nous avons créé quelques exemples en assembleur dont voici les codes sources et l'exécution par le simulateur:
+
+\section{Hello World 1: hello.s}
+Nous commençons doucement par une petite procédure appelée plusieures fois.\\
+
+hello.s:
+\verbatiminput{../samples/hello.s}
+
+Simulation:
+\begin{verbatim}
+$ ./hello
+Simul v1.0
+
+
+Performing initialisation...
+
+ o Initialising the simulator... Done!
+Hello World!
+Hello World!
+Hello World!
+Hello World!
+Hello World!
+Hello World!
+Hello World!
+Hello World!
+Hello World!
+Hello World!
+
+Performing shutdown...
+
+Exitting, bye!
+\end{verbatim}
+
+\section{Hello World 2: fichier1.s fichier2.s}
+Pour montrer l'éditeur de liens, deux fichiers séparés.\\
+
+fichier1.s
+\verbatiminput{../samples/fichier1.s}
+
+fichier2.s
+\verbatiminput{../samples/fichier2.s}
+
+Simulation:
+\begin{verbatim}
+$ ./helloworld
+Simul v1.0
+
+
+Performing initialisation...
+
+ o Initialising the simulator... Done!
+Hello World
+
+Performing shutdown...
+
+Exitting, bye!
+\end{verbatim}
+
+\section{Somme d'entiers: sommeentiers.s}
+Un exemple simple, l'addition de quelques entiers.\\
+
+sommeentiers.s
+\verbatiminput{../samples/sommeentiers.s}
+
+Simulation:
+\begin{verbatim}
+$ ./sommeentiers
+Simul v1.0
+
+
+Performing initialisation...
+
+ o Initialising the simulator... Done!
+La somme des 97 premiers entiers est égale à 4656
+
+Performing shutdown...
+
+Exitting, bye!
+\end{verbatim}
+
+\section{Recherche d'un caractère: rechcara.s}
+Un exemple un peu plus complexe, nous cherchons un caractère dans une chaîne.\\
+
+rechcara.s
+\verbatiminput{../samples/rechcara.s}
+
+Simulation:
+\begin{verbatim}
+$ ./rechcara
+Simul v1.0
+
+
+Performing initialisation...
+
+ o Initialising the simulator... Done!
+Le caractere 0x0D a été trouvé dans la chaine à l'index 26
+
+Performing shutdown...
+
+Exitting, bye!
+\end{verbatim}
+
+\section{Recherche de caractères identiques: recherche.s}
+Un exemple avancé: nous recherchons le premier caractère identique entre deux chaînes.\\
+
+recherche.s
+\verbatiminput{../samples/recherche.s}
+
+Simulation:
+\begin{verbatim}
+$ ./recherche
+Simul v1.0
+
+
+Performing initialisation...
+
+ o Initialising the simulator... Done!
+TAB1 et TAB2 ont un élément en commun à l'index 82
+
+Performing shutdown...
+
+Exitting, bye!
+\end{verbatim}
+
+\section{Relogement: testtout.s}
+Cet exemple va montrer le mécanisme de relogement: il va charger tous les exemples précédents.\\
+
+testtout.s:
+\verbatiminput{../samples/testtout.s}
+
+Simulation:
+\begin{verbatim}
+$ ./testtout
+Simul v1.0
+
+
+Performing initialisation...
+
+ o Initialising the simulator... Done!
+Exécution du programme numéro 0 appelé helloworld...
+Hello World
+Le programme s'est terminé!
+Exécution du programme numéro 1 appelé hello...
+Hello World!
+Hello World!
+Hello World!
+Hello World!
+Hello World!
+Hello World!
+Hello World!
+Hello World!
+Hello World!
+Hello World!
+Le programme s'est terminé!
+Exécution du programme numéro 2 appelé sommeentiers...
+La somme des 97 premiers entiers est égale à 4656
+Le programme s'est terminé!
+Exécution du programme numéro 3 appelé rechcara...
+Le caractere 0x0D a été trouvé dans la chaine à l'index 26
+Le programme s'est terminé!
+Exécution du programme numéro 4 appelé recherche...
+TAB1 et TAB2 ont un élément en commun à l'index 82
+Le programme s'est terminé!
+Tout est terminé, bye!
+
+Performing shutdown...
+
+Exitting, bye!
+\end{verbatim}
diff --git a/doc/manuel.tex b/doc/manuel.tex
index 7eec7ba..89bd407 100644
--- a/doc/manuel.tex
+++ b/doc/manuel.tex
@@ -27,7 +27,7 @@ méta-langage est indispensable à toute exécution de compilo.
Exemple d'exécution :
\begin{verbatim}
-$ compilo ../samples/recherche.s recherche.o
+$ ./compilo ../samples/recherche.s recherche.o
Assembler v1.0
@@ -47,13 +47,79 @@ Performing initialisation...
\end{verbatim}
+\section{L'Editeur de liens : linker}
+La ligne de commande que nous livre l'exécution sans argument du programme 'linker' est la suivante:
+\begin{verbatim}
+$ ./linker
+Linker v1.0
+Usage: linker obj1 [obj2 [obj3 [...]]] binary
+\end{verbatim}
+Nous devons donc spécifier au moins un fichier objet, et un nom de fichier binaire de sortie.
-\section{L'Editeur de liens : linker}
+Exemple d'exécution:
+\begin{verbatim}
+$ ./linker recherche.o recherche
+Linker v1.0
-\section{Le Simulateur : simul }
+Performing initialisation...
+
+ o Initialising the linker... Done!
+ Linking files...
+ Generating output file...
+ Statistics: 29 words of text, 297 words of data and reserving 0 words
+ Output file size: 343 words containing 10 relocating offsets.
+
+ Performing shutdown...
+
+ Exitting, bye!
+\end{verbatim}
+
+\section{Le Simulateur : simul }
\subsection{la ligne de commande}
+Le nom de la commande à lancer pour exécuter le simulateur est 'simul'. La ligne de commande est la suivante:
+\begin{verbatim}
+$ ./simul
+Simul v1.0
+
+Usage: linker [-s] [-d] binary
+\end{verbatim}
+L'option -s sert à sélectionner une ALU différente, et plus instable. L'option -d sert à déclanger le debugger dès la
+première instruction. Bien évidemment, il faut donner le nom d'un fichier binaire à exécuter.
+
+\subsection{le mode interactif}
+Lors de l'exécution du simulateur, le programme exécuté tourne jusqu'à ce qu'une instruction HALT est rencontrée. Pour
+interrompre l'exécution et déclanger le debugger, il est possible de frapper la combinaison de touche CTRL-C. Si l'option
+-d a été spécifiée sur la ligne de commande, nous obtenons le même résultat:
+
+\begin{verbatim}
+ o Initialising the simulator... Done!
+ R00 R01 R02 R03 R04 R05 R06 R07
+00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
+ R08 R09 R10 R11 R12 R13 R14 R15
+00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
+ R16 R17 R18 R19 R20 R21 R22 R23
+00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
+ R24 R25 R26 R27 R28 R29 R30 R31
+00000000 00000000 00000000 00000000 00000002 000027FF 00000002 00000000
+Rg: 00000000 | Rd: 00000000 | Flag: 00000000 | PC: 00000000
+Opcode: 0A, extension: 00, champ1: 00, champ2: 00, champ3: 00
+00000000:0000000A - 00000000 - 00000000 >
+\end{verbatim}
+Cette interface nous présente l'ensemble des registres du CPU, ainsi que les quelques flags spéciaux.
+De plus, les champ de l'instruction suivante sont décodés, et la dernière ligne nous indique les trois mots mémoire
+pour le compteur ordinal en cours. Le prompt > nous invite à taper une commande parmi:
+
+\begin{verbatim}
+> Help:
+G: go
+P: Proceed
+R: display registers
+Q: quit
+\end{verbatim}
-\subsection{le mode interactif} \ No newline at end of file
+Go stoppe le debugger et relance l'exécution du CPU. Proceed avance d'une instruction. Display registers réaffiche la
+page des registres, au cas où l'écrant ait été corrompu par l'exécution du programme. Enfin, quit permet de sortir immédiatement
+du simulateur. \ No newline at end of file
diff --git a/doc/probs.tex b/doc/probs.tex
index 220edad..5b7a640 100644
--- a/doc/probs.tex
+++ b/doc/probs.tex
@@ -1,17 +1,109 @@
\chapter{Description des solutions technologiques}
-\section{Parseur et Meta-Parseur}
-
-
-\section{Assembleur}
+\section{Meta-Parseur}
%description du meta langage
%format du fichier instructions.txt
%description du langage asm...
+Le meta langage a été développé comme nous l'avons proposé dans notre analyse, et voici sa decription complète\\
+Le fichier écrit en méta langage doit être écrit et analysé ligne par ligne, chaque ligne ayant une signification
+discincte suivant son premier caractère:
+\begin{itemize}
+\item F sert à décrire un champ de bits. Le champ appelé 'I' est le champ d'instruction principal et sera utilisé pour
+créer les instructions finales. Sa syntaxe est la suivante://
+\begin{verbatim}
+Fnom:champ1,taille1;champ2;taille2;...
+\end{verbatim}
+Par exemple, notre FI:c3,6;c2,6;c1,6;e,6;op,8 nous sert à décrire parfaitement le champ d'opcode général tel que décrit
+dans notre analyse. c1, c2, et c3 sont les noms des trois champs arguments, e est le nom du champ d'extension, et op est
+le nom du champ d'opcode.
+\item P sert à décrire une "pattern". Toute instruction va suivre un schéma particulier, et nous pouvons le quantifier grâce
+à ce système de partition. La variable générée par l'évaluation d'une pattern sera égale à l'indice de la chaîne trouvée
+dans la pattern. Voici la syntaxe d'une telle ligne:
+\begin{verbatim}
+Pnom:pattern1;pattern2;pattern3;...
+\end{verbatim}
+Chaque pattern possède elle même une syntaxe propre pouvant se classifier en 5 groupes principaux:
+\begin{itemize}
+\item Une chaîne de caractères qui sera reconnue telle quelle.
+\item Une autre pattern qui sera stoquée dans une variable suivant la syntaxe: nomvar=.Pnom
+\item Une déclaration d'adresse stoquée dans une valeur immédiate suivant la syntaxe: .I=.O
+\item Une déclaration de décalage (utilisant l'opérateur [) qui peut se faire soit par une pattern immédiate sous la syntaxe [nomvar=.Pnom
+soit par le décalage d'une autre adresse sous la syntaxe .I=.O[nomvar=.Pnom
+\end{itemize}
+Ainsi nous avons une pattern pour les registres (Pr:R0;R1;R2;...) et une pattern pour toutes les adresses (Pm::regop=.Pr;.I=.O;[regop=.Pr;.I=.O[regop=.Pr)
+et les numéros d'indices de chaque élément correspond bien aux spécifications données dans notre analyse.
+\item I sert à décrire une instruction. Une ligne I est décomposée en deux partie. La ligne ne suit pas de syntaxe particulière dans sa première partie,
+car nous devons pouvoir décrire n'importe quelle style d'instruction. Par exemple, nous avons I:ADD c1=.Pr,c2=.Pr,c3=.Pr; qui signifie que nous décrivons
+l'instruction ADD suivie de trois registres dont les indices correspondants seront mis dans les variables c1, c2 et c3 respectivement. La deuxième partie
+de la ligne (après le ;) sert à donner la listes des variables implicites. Dans l'exemple de notre ADD, nous avons ceci: op=0x0;e=0x0 ce qui signifie que les
+variable op et e doivent être mises à zéro. Ainsi, chaque ligne sera évaluée récursivement en fonction des différentes variables et des différents champs spécifiés.
+Dans notre cas, comme nous avons FI qui déclare les variables c1, c2, c3, e, et op, il nous faut obligatoirement ces 5 variables pour chaque instruction.
+Enfin, chaque élément de l'instruction peut suivre aussi des formes différentes. En voici la liste:
+\begin{itemize}
+\item Nous pouvons avoir une chaîne toute seule (comme ADD dans notre cas) pour dire qu'il faut que cette chaîne soit présente dans
+le code source assembleur.
+\item Nous pouvons avoir comme nous l'avons vu la syntaxe variable=.Pnom. Cela signifie qu'à cet endroit de la ligne source assembleur
+doit se trouver un mot pouvant évaluer la pattern, et qu'il faut placer l'indice évalué dans la variable spécifiée.
+\item Nous pouvois avoir .I=.C ce qui signifie qu`à cet endroit là doit se trouver une constante, qui sera placée immédiatement après
+l'opcode de l'instruction.
+\item Nous pouvons enfin avoir .I=.O ce qui signifie qu'à cet endroit là doit se trouver une adresse directe.
+\end{itemize}
+Dans la liste des instructions de la seconde partie, nous pouvons avoir aussi la déclaration variable=.Fnom, ce qui signifie que la variable
+indiquée sera évaluée par le champ de bit spécifié. Enfin nous pouvons aussi avoir la déclaration variable1=variable2.
+\end{itemize}
+Ce meta langage nous a permi de décrire une grande partie des instructions dont nous avons parlé dans l'analyse. Voici ce fichier:
+\verbatiminput{../samples/instructions.txt}
+
+\section{Parseur}
+Le parseur est un morceau de code relativement simple. Il va lire une ligne en entrée et va la décomposer en deux catégorie d'éléments:
+\begin{itemize}
+\item Des symboles
+\item Des opérateurs
+\end{itemize}
+Tout est traité suivant une pile polonaise inversée. Par exemple, l'expression 1 + 2 * 3 + 4 sera traitée comme suit:
+\begin{verbatim}
+PushSymbol(1)
+PushSymbol(2)
+PushSymbol(3)
+ActPile(*)
+ActPile(+)
+PushSymbol(4)
+ActPile(+)
+\end{verbatim}
+Les fonctions PushSymbol et ActPile sont des symboles globaux et sont définis dans l'assembleur.
+\section{Assembleur}
+L'assembleur, s'il a l'air complexe par la taille de son code source, est en fait relativement simple aussi. Il est articulé sur un mécanisme
+très simple: tout symbole provenant du parseur sera encapsulé dans des bulles qui seront évaluées au fur et à mesure de la progression de
+l'assemblage du code source. Au pire, au stade final de l'assemblage, lors de la génération du fichier objet, nous aurons des symboles
+que l'éditeur de liens se fera une joie de résoudre et de compléter. Dans tous les cas, l'analyse du fichier se fait sur quatre niveaux:
+\begin{itemize}
+\item Lors de l'ajout d'un symbole par le parseur.
+\item Lors de l'ajout d'un opérateur par le parseur.
+\item Lors d'une fin de ligne.
+\item Lors de la fin du fichier source.
+\end{itemize}
+A chacun de ces quatre niveaux se trouve des paliers d'évaluations. Si un symbole, une expression ou une ligne ne peut pas
+passer ce palier, une erreur sera générée. Ces paliers deviennent de plus en plus stricts suivant les niveaux passés. Ainsi, comme décrit
+plus haut, le dernier palier ne peut que laisser passer des valeurs immédiates ou bien des symboles à reloger par l'éditeur de liens.\\
+L'assembleur possède aussi quelques symboles prédéfinis:
+\begin{itemize}
+\item .text pour déclarer l'écriture dans le segment de text
+\item .data pour déclarer l'écriture dans le segment de data
+\item .bss pour déclarer l'écriture dans le segment bss
+\item .start pour déclarer le point d'entrée
+\item DB, DW et DD pour enregistrer un ou plusieurs mots mémoires
+\item DS pour enregistrer une chaîne de caractères
+\item DR pour enregistrer un tableau de mots non initialisés.
+\end{itemize}
\section{Editeur de liens}
-%mecanisme de relocation
+Les fichiers objets générés par l'assembleur ont une struture suffisamment simple pour que l'éditeur de liens ait un travail très simplifié:
+il charge d'affilé tous les fichiers objets à lier, et va créer une table de tous les symboles internes. Puis il va concaténer tous les
+segments de text ensemble, tous les segments de data ensemble, et va reloger les références croisées suivant la table des symboles internes.
+Le fichier de sortie est un binaire qui suit les spécification de notre analyse. La table de relogement nous sert à indiquer toutes
+les références à des symboles absolus, de sorte à pouvoir placer le binaire n'importe où dans la mémoire de notre CPU virtuel.
\section{Operations ALU} %algos ALU lente
@@ -38,11 +130,15 @@ Pour la division, nous utilisons comme pour la multiplication deux registres, un
division et pour ce faire on utilise l'algorithme de notre jeunesse.
Pour les deux fonctions de décalage, nous décalons les bits du nombre demandé et on remplace les bits manquants par 0.
+\section{MiniOS}
+Notre MiniOS n'a qu'un role très restreint: celui de charger un binaire et le reloger correctement en mémoire, et d'effectuer
+des petits travaux d'interfaces homme/machine. Toutes les fonctions d'interface pensées pendant l'analyse ont été implémentées.
+Lors du chargement d'un binaire, il va initialiser correctement toutes les informations nécessaires au bon déroulement du programme.
\section{Contrôleur}
-%decodage, execution, gestion de la ram
-
-\section{MiniOS}
+Le contrôleur va prendre la main dès qu'un binaire aura été chargé en mémoire. Il va décoder le binaire instructions par instructions,
+et va activer les différents composants de notre CPU: les registres, l'alu et la mémoire. L'accès à la mémoire fait l'objet d'un code
+très spécifique, car c'est en écrivant à certains offsets mémoire que nous pouvons récupérer des informations devant aller vers le MiniOS.
diff --git a/lib/assembler.c b/lib/assembler.c
index 0beb2df..0acf738 100644
--- a/lib/assembler.c
+++ b/lib/assembler.c
@@ -176,9 +176,7 @@ static bytestream_t *pushdword(unsigned long int d, expression_t * e)
bytestream_t *s;
if ((segment < 0) || (segment > 1)) {
- exception(1,
- _
- ("You have to be into the .text or the .data segment to define a value."));
+ exception(1, _("You have to be into the .text or the .data segment to define a value."));
}
s = pushuninit(1);
@@ -267,9 +265,7 @@ static void pushstring(char *s)
static void pushstart(void)
{
if (segment != SEG_TEXT) {
- exception(1,
- _
- ("You can't have the startpoint elsewhere than the .text segment"));
+ exception(1, _("You can't have the startpoint elsewhere than the .text segment"));
}
pushlabel("__start__");
}
@@ -282,9 +278,7 @@ static void look4pattern(pattern_t * patterns, expression_t * expression)
for (patterns = patterns->next; patterns; patterns = patterns->next) {
for (i = 0; i < patterns->nbr; i++) {
- if (!
- (patterns->expr[i]->type
- || patterns->expr[i]->string || !patterns->expr[i]->name)) {
+ if (!(patterns->expr[i]->type || patterns->expr[i]->string || !patterns->expr[i]->name)) {
if (!strcasecmp(patterns->expr[i]->name, expression->symbol)) {
expression->e_subtype = E_PATTERN;
expression->pattern = patterns;
@@ -661,8 +655,7 @@ static void evaluate(expression_t * e)
if (!e->child->e_subtype == E_VALUE) {
exception(1, _("Error: unable to compute the immediate value"));
}
- e->avalue =
- (e->op == OP_MOINS_UNARY) ? -e->child->avalue : e->child->avalue;
+ e->avalue = (e->op == OP_MOINS_UNARY) ? -e->child->avalue : e->child->avalue;
free(e->child);
e->child = NULL;
e->e_type = e->e_subtype = E_VALUE;
@@ -696,8 +689,7 @@ static void evaluate(expression_t * e)
if (e->child->next->child->e_subtype == E_LABEL) {
exception(1, _("Addresses operations not allowed"));
}
- if (e->child->next->child->e_subtype ==
- e->child->next->child->next->e_subtype) {
+ if (e->child->next->child->e_subtype == e->child->next->child->next->e_subtype) {
exception(1, _("Expression too complex or invalid"));
}
/* On veut obtenir quelque chose sous la forme LABEL[VALUE + PATTERN] */
@@ -808,9 +800,7 @@ static void evaluate(expression_t * e)
et si c'est le cas, il ne faut pas que ce soit - C. Sinon nous ne devons
pas avoir de labels pour B ou C */
- if (
- (e->child->child->next->child->next->e_subtype ==
- E_PATTERN)
+ if ((e->child->child->next->child->next->e_subtype == E_PATTERN)
&& (e->child->child->next->op == OP_MOINS)) {
exception(1, _("Address type not supported"));
}
@@ -823,18 +813,14 @@ static void evaluate(expression_t * e)
if (e->child->child->next->child->e_subtype ==
e->child->child->next->child->next->e_subtype) {
- exception(1,
- _("Expression too complex or invalid"));
+ exception(1, _("Expression too complex or invalid"));
}
/* Ok, si notre expression a réussi à franchir toutes ses étapes, c'est qu'elle
est correcte.... Enfin j'espère :) Je vais modifier l'expression de sorte a ce
qu'elle ait la forme [LABEL + (VALEUR +- PATTERN)] */
- if (
- (t =
- e->child->child->next->child)->e_subtype ==
- E_PATTERN) {
+ if ((t = e->child->child->next->child)->e_subtype == E_PATTERN) {
t->prev = t->next;
t->next = NULL;
t->prev->next = t;
@@ -851,15 +837,12 @@ static void evaluate(expression_t * e)
et si c'est le cas, il ne faut pas que ce soit - C. Sinon nous ne devons
pas avoir de patterns pour B ou C. */
- if (
- (e->child->child->next->child->next->e_subtype ==
- E_LABEL)
+ if ((e->child->child->next->child->next->e_subtype == E_LABEL)
&& (e->child->child->next->op == OP_MOINS)) {
exception(1, _("Address type not supported"));
}
- if (e->child->child->next->child->e_subtype ==
- E_PATTERN) {
+ if (e->child->child->next->child->e_subtype == E_PATTERN) {
exception(1, _("Expression invalid"));
}
@@ -867,8 +850,7 @@ static void evaluate(expression_t * e)
if (e->child->child->next->child->e_subtype ==
e->child->child->next->child->next->e_subtype) {
- exception(1,
- _("Expression too complex or invalid"));
+ exception(1, _("Expression too complex or invalid"));
}
/* Ok, si notre expression a réussi à franchir toutes ses étapes, c'est qu'elle
@@ -876,10 +858,7 @@ static void evaluate(expression_t * e)
qu'elle ait la forme [LABEL + (VALEUR +- PATTERN)] */
/* Pas mal de boulot ici... */
- if (
- (t =
- e->child->child->next->child)->e_subtype ==
- E_LABEL) {
+ if ((t = e->child->child->next->child)->e_subtype == E_LABEL) {
/* Nous avons [PATTERN + (LABEL +- VALEUR)], on inverse LABEL et VALEUR */
t->prev = t->next;
t->next = NULL;
@@ -918,8 +897,7 @@ static void evaluate(expression_t * e)
if (e->child->child->next->op == OP_MOINS) {
exception(1, _("Expression invalid"));
}
- e->child->child->avalue +=
- e->child->child->next->child->avalue;
+ e->child->child->avalue += e->child->child->next->child->avalue;
t = e->child->child->next;
e->child->child->next = t->child->next;
free_expr(t);
@@ -927,15 +905,12 @@ static void evaluate(expression_t * e)
On va pas s'embeter, on va réévaluer la chose :) */
evaluate(e);
return;
- } else if (e->child->child->next->child->
- next->e_subtype == E_VALUE) {
+ } else if (e->child->child->next->child->next->e_subtype == E_VALUE) {
/* Quasiment la même chose qu'au dessus... */
if (e->child->child->next->op == OP_MOINS) {
- e->child->child->avalue
- -= e->child->child->next->child->avalue;
+ e->child->child->avalue -= e->child->child->next->child->avalue;
} else {
- e->child->child->avalue
- += e->child->child->next->child->avalue;
+ e->child->child->avalue += e->child->child->next->child->avalue;
}
t = e->child->child->next;
e->child->child->next = t->child;
@@ -947,9 +922,7 @@ static void evaluate(expression_t * e)
if (e->child->child->next->child->e_subtype ==
e->child->child->next->child->next->e_subtype) {
- exception(1,
- _
- ("Expression too complex or invalid"));
+ exception(1, _("Expression too complex or invalid"));
}
/* Ok, si notre expression a réussi à franchir toutes ses étapes, c'est qu'elle
@@ -957,10 +930,7 @@ static void evaluate(expression_t * e)
qu'elle ait la forme [LABEL + (VALEUR +- PATTERN)] */
/* Pas mal de boulot ici... */
- if (
- (t =
- e->child->child->next->child)->e_subtype ==
- E_PATTERN) {
+ if ((t = e->child->child->next->child)->e_subtype == E_PATTERN) {
/* Nous avons [VALEUR + (PATTERN + LABEL)], on inverse LABEL et PATTERN */
t->prev = t->next;
t->next = NULL;
@@ -1254,8 +1224,7 @@ static int islabel(expression_t * e)
/* Cette fonction cherche une instruction pouvant correspondre à l'expression. */
-static instruct_t *e_match_i(phon_t * phons, instruct_t * instructs,
- expression_t * e)
+static instruct_t *e_match_i(phon_t * phons, instruct_t * instructs, expression_t * e)
{
char *stringtolook = e->symbol;
expression_t *t;
@@ -1281,8 +1250,7 @@ static instruct_t *e_match_i(phon_t * phons, instruct_t * instructs,
go_out = 0;
for (i = 0; (!go_out) && (i < instructs->nbexplicit); i++) {
if (!instructs->strings[i]) {
- if (strcasecmp
- (instructs->names[i], i ? t->symbol : stringtolook)) {
+ if (strcasecmp(instructs->names[i], i ? t->symbol : stringtolook)) {
go_out = 1;
}
} else {
@@ -1291,9 +1259,8 @@ static instruct_t *e_match_i(phon_t * phons, instruct_t * instructs,
if (!t->pattern) {
go_out = 1;
} else {
- if (strcasecmp
- (instructs->strings[i] + 1,
- t->pattern->name)) go_out = 1;
+ if (strcasecmp(instructs->strings[i] + 1, t->pattern->name))
+ go_out = 1;
}
break;
case 'C':
@@ -1323,9 +1290,7 @@ static instruct_t *e_match_i(phon_t * phons, instruct_t * instructs,
/* C'est le cas le plus simple ou presque, il suffit de tout prendre */
break;
default:
- exception(1,
- _
- ("Unknow predefined string into the meta language"));
+ exception(1, _("Unknow predefined string into the meta language"));
}
}
@@ -1347,10 +1312,8 @@ static instruct_t *e_match_i(phon_t * phons, instruct_t * instructs,
for (i = 0; i < instructs->nbexplicit; i++) {
fprintf(stderr, " + %s <= %s (type %s)\n",
instructs->names[i],
- instructs->
- strings[i] ? instructs->strings[i] :
- "Pas de chaîne associée",
- instructs->etypes[i] ? "prédéfinit" : "direct");
+ instructs->strings[i] ? instructs->strings[i] :
+ "Pas de chaîne associée", instructs->etypes[i] ? "prédéfinit" : "direct");
}
fprintf(stderr, " => Champs implicites.\n");
for (i = 0; i < instructs->nbimplicit; i++) {
@@ -1394,8 +1357,7 @@ static void evaluate_pattern(_TableauVariable * it, expression_t * e)
if (m->string) {
if (m->type) {
if (strcmp(m->name, "I")) {
- exception(1,
- _("Unknow constant type in the meta language"));
+ exception(1, _("Unknow constant type in the meta language"));
}
if (e->e_subtype == E_VALUE) {
pushdword(e->avalue, NULL);
@@ -1428,9 +1390,7 @@ static void evaluate_pattern(_TableauVariable * it, expression_t * e)
if (m->type) {
if (strcmp(m->name, "I")
|| strcmp(m->string, "O")) {
- exception(1,
- _
- ("Unknow constant type in the meta language"));
+ exception(1, _("Unknow constant type in the meta language"));
}
tv = 0;
if (e->child->next->e_subtype == E_VALUE) {
@@ -1660,9 +1620,7 @@ void asm_eol(void)
if (!e_current)
break;
if (segment != SEG_TEXT) {
- exception(1,
- _
- ("You can only have an instruction into a .text segment"));
+ exception(1, _("You can only have an instruction into a .text segment"));
}
if (!(instr = e_match_i(phons, instructs, e_current))) {
exception(1, _("Unmatched instruction"));
@@ -1686,14 +1644,10 @@ void asm_eol(void)
pushdword(0, e_current);
}
} else {
- exception(1,
- _
- ("Unknow constant type in the meta language"));
+ exception(1, _("Unknow constant type in the meta language"));
}
} else {
- InsererVarDansTab(&it,
- CreerElement
- (instr->names[i], e_current));
+ InsererVarDansTab(&it, CreerElement(instr->names[i], e_current));
}
break;
case 'O':
@@ -1705,9 +1659,7 @@ void asm_eol(void)
pushdword(0, e_current);
}
} else {
- exception(1,
- _
- ("Unknow constant type in the meta language"));
+ exception(1, _("Unknow constant type in the meta language"));
}
}
break;
@@ -1719,19 +1671,14 @@ void asm_eol(void)
t->child = t->next = NULL;
t->pattern = NULL;
t->symbol = NULL;
- InsererVarDansTab(&it,
- CreerElement(instr->names[i], t));
+ InsererVarDansTab(&it, CreerElement(instr->names[i], t));
#ifdef DEBUG
- fprintf(stderr,
- "On a %s qui vaut %i\n",
- instr->names[i], e_current->index);
+ fprintf(stderr, "On a %s qui vaut %i\n", instr->names[i], e_current->index);
#endif
evaluate_pattern(&it, e_current);
break;
default:
- exception(1,
- _
- ("Unknow constant type in the meta language"));
+ exception(1, _("Unknow constant type in the meta language"));
}
}
@@ -1756,11 +1703,9 @@ void asm_eol(void)
t->symbol = NULL;
}
#ifdef DEBUG
- fprintf(stderr, "On a %s qui vaut %i\n",
- instr->implicits[i], t->avalue);
+ fprintf(stderr, "On a %s qui vaut %i\n", instr->implicits[i], t->avalue);
#endif
- InsererVarDansTab(&it,
- CreerElement(instr->implicits[i], t));
+ InsererVarDansTab(&it, CreerElement(instr->implicits[i], t));
break;
case 1: /* type prédéfinit */
t = (expression_t *)
@@ -1774,11 +1719,9 @@ void asm_eol(void)
t->pattern = NULL;
t->symbol = NULL;
#ifdef DEBUG
- fprintf(stderr, "On a %s qui vaut %i\n",
- instr->implicits[i], t->avalue);
+ fprintf(stderr, "On a %s qui vaut %i\n", instr->implicits[i], t->avalue);
#endif
- InsererVarDansTab(&it,
- CreerElement(instr->implicits[i], t));
+ InsererVarDansTab(&it, CreerElement(instr->implicits[i], t));
break;
case 2: /* type valeur */
t = (expression_t *)
@@ -1789,11 +1732,9 @@ void asm_eol(void)
t->pattern = NULL;
t->symbol = NULL;
#ifdef DEBUG
- fprintf(stderr, "On a %s qui vaut %i\n",
- instr->implicits[i], t->avalue);
+ fprintf(stderr, "On a %s qui vaut %i\n", instr->implicits[i], t->avalue);
#endif
- InsererVarDansTab(&it,
- CreerElement(instr->implicits[i], t));
+ InsererVarDansTab(&it, CreerElement(instr->implicits[i], t));
break;
}
}
@@ -1952,9 +1893,7 @@ void asm_eof(FILE * f)
if ((ttext->Expr->child->e_subtype == E_LABEL)
&& (ttext->Expr->child->next->e_subtype == E_VALUE)) {
#ifdef DEBUG
- fprintf(stderr,
- "Symbole externe %s\n",
- ttext->Expr->child->symbol);
+ fprintf(stderr, "Symbole externe %s\n", ttext->Expr->child->symbol);
#endif
a = ttext->Expr->child->next->avalue;
nbsymbols++;
@@ -1970,35 +1909,28 @@ void asm_eof(FILE * f)
if (((ttext->Expr->child->e_subtype == E_LABEL)
&& (ttext->Expr->child->next->e_subtype == E_VALUE))
|| ((ttext->Expr->child->e_subtype == E_VALUE)
- && (ttext->Expr->child->next->e_subtype ==
- E_LABEL))) {
+ && (ttext->Expr->child->next->e_subtype == E_LABEL))) {
if (ttext->Expr->child->e_subtype == E_LABEL) {
#ifdef DEBUG
- fprintf(stderr,
- "Symbole externe %s\n",
- ttext->Expr->child->symbol);
+ fprintf(stderr, "Symbole externe %s\n", ttext->Expr->child->symbol);
#endif
a = ttext->Expr->child->next->avalue;
nbsymbols++;
writeword(1, f2, 1);
writeword(ttext->offset, f2, 1);
- writeword(strlen
- (ttext->Expr->child->symbol), f2, 1);
+ writeword(strlen(ttext->Expr->child->symbol), f2, 1);
writestring(ttext->Expr->child->symbol, f2);
nbe++;
} else {
#ifdef DEBUG
fprintf(stderr,
- "Symbole externe %s\n",
- ttext->Expr->child->next->symbol);
+ "Symbole externe %s\n", ttext->Expr->child->next->symbol);
#endif
a = ttext->Expr->child->avalue;
nbsymbols++;
writeword(1, f2, 1);
writeword(ttext->offset, f2, 1);
- writeword(strlen
- (ttext->Expr->child->next->symbol), f2,
- 1);
+ writeword(strlen(ttext->Expr->child->next->symbol), f2, 1);
writestring(ttext->Expr->child->next->symbol, f2);
nbe++;
}
@@ -2006,42 +1938,28 @@ void asm_eof(FILE * f)
}
}
if (ttext->Expr->op != OP_FUNC_CALL) {
- exception(1,
- _
- ("Can't evaluate expression for a direct value"));
+ exception(1, _("Can't evaluate expression for a direct value"));
}
if (strcmp(ttext->Expr->symbol, "diff")) {
- exception(1,
- _
- ("Can't evaluate expression for a direct value"));
+ exception(1, _("Can't evaluate expression for a direct value"));
}
if ((ttext->Expr->child->e_subtype != E_LABEL)
|| (ttext->Expr->child->next->e_subtype != E_LABEL)) {
- exception(1,
- _
- ("Can only use the diff() function onto labels"));
+ exception(1, _("Can only use the diff() function onto labels"));
}
- t =
- (bytestream_t *) NomVarToVar(ttext->Expr->child->symbol,
- labels, &trouve);
+ t = (bytestream_t *) NomVarToVar(ttext->Expr->child->symbol, labels, &trouve);
if (!trouve) {
- exception(1,
- _("Can only evaluate a diff on local symbols"));
+ exception(1, _("Can only evaluate a diff on local symbols"));
}
- u =
- (bytestream_t *)
- NomVarToVar(ttext->Expr->child->next->symbol, labels,
- &trouve);
+ u = (bytestream_t *)
+ NomVarToVar(ttext->Expr->child->next->symbol, labels, &trouve);
if (!trouve) {
- exception(1,
- _("Can only evaluate a diff on local symbols"));
+ exception(1, _("Can only evaluate a diff on local symbols"));
}
if (t->segment != u->segment) {
- exception(1,
- _
- ("Can only evaluate a diff on symbols from the same segment"));
+ exception(1, _("Can only evaluate a diff on symbols from the same segment"));
}
a = t->offset - u->offset;
@@ -2099,8 +2017,7 @@ void asm_eof(FILE * f)
case E_LABEL:
a = tdata->Expr->avalue;
#ifdef DEBUG
- fprintf(stderr, "Symbole externe %s\n",
- tdata->Expr->child->symbol);
+ fprintf(stderr, "Symbole externe %s\n", tdata->Expr->child->symbol);
#endif
nbsymbols++;
writeword(3, f2, 1);
@@ -2111,42 +2028,28 @@ void asm_eof(FILE * f)
break;
case E_OPERATION:
if (tdata->Expr->op != OP_FUNC_CALL) {
- exception(1,
- _
- ("Can't evaluate expression for a direct value"));
+ exception(1, _("Can't evaluate expression for a direct value"));
}
if (strcmp(tdata->Expr->symbol, "diff")) {
- exception(1,
- _
- ("Can't evaluate expression for a direct value"));
+ exception(1, _("Can't evaluate expression for a direct value"));
}
if ((tdata->Expr->child->e_subtype != E_LABEL)
|| (tdata->Expr->child->next->e_subtype != E_LABEL)) {
- exception(1,
- _
- ("Can only use the diff() function onto labels"));
+ exception(1, _("Can only use the diff() function onto labels"));
}
- t =
- (bytestream_t *) NomVarToVar(tdata->Expr->child->symbol,
- labels, &trouve);
+ t = (bytestream_t *) NomVarToVar(tdata->Expr->child->symbol, labels, &trouve);
if (!trouve) {
- exception(1,
- _("Can only evaluate a diff on local symbols"));
+ exception(1, _("Can only evaluate a diff on local symbols"));
}
- u =
- (bytestream_t *)
- NomVarToVar(tdata->Expr->child->next->symbol, labels,
- &trouve);
+ u = (bytestream_t *)
+ NomVarToVar(tdata->Expr->child->next->symbol, labels, &trouve);
if (!trouve) {
- exception(1,
- _("Can only evaluate a diff on local symbols"));
+ exception(1, _("Can only evaluate a diff on local symbols"));
}
if (t->segment != u->segment) {
- exception(1,
- _
- ("Can only evaluate a diff on symbols from the same segment"));
+ exception(1, _("Can only evaluate a diff on symbols from the same segment"));
}
a = t->offset - u->offset;
@@ -2209,7 +2112,7 @@ void asm_eof(FILE * f)
popcontext();
writeword(0x4f424e4e, f, 1);
- writeword(ftell(f2) + s_data + s_text + 7, f, 1);
+ writeword((ftell(f2) >> 2)+ s_data + s_text + 7, f, 1);
t = (bytestream_t *) NomVarToVar("__start__", labels, &trouve);
if (trouve) {
writeword(t->offset, f, 1);
@@ -2220,7 +2123,7 @@ void asm_eof(FILE * f)
writeword(s_text, f, 1);
writeword(s_data, f, 1);
writeword(s_bss, f, 1);
- writeword(ftell(f2) + 1, f, 1);
+ writeword((ftell(f2) >> 2) + 1, f, 1);
fclose(f2);
writeword(nbsymbols, f, 1);
@@ -2256,8 +2159,7 @@ void assembler_flush(void)
delete_bytestream(data);
delete_bytestream(bss);
}
-/* Fonction générique qui va traiter un fichier entier */ static int
-process_file(char *name)
+/* Fonction générique qui va traiter un fichier entier */ static int process_file(char *name)
{
FILE *f;
char buf[BUFSIZ], errctx[BUFSIZ], *p;
diff --git a/lib/hash.c b/lib/hash.c
index c0f5bc5..47f2961 100644
--- a/lib/hash.c
+++ b/lib/hash.c
@@ -4,9 +4,7 @@
#include "hash.h"
#include "exceptions.h"
#include "config.h"
-static char *CHAINEHACHAGE =
-
- "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
+static char *CHAINEHACHAGE = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
static int FonctionHachage(char *clef)
{
@@ -162,9 +160,7 @@ int Initialise(_TableauVariable * t)
unsigned int i;
- (*t) =
- (_TableauVariable) Emalloc(sizeof(_ListeChaine) *
- (strlen(CHAINEHACHAGE) + 1));
+ (*t) = (_TableauVariable) Emalloc(sizeof(_ListeChaine) * (strlen(CHAINEHACHAGE) + 1));
for (i = 0; i <= strlen(CHAINEHACHAGE); i++) {
(*t)[i] = NULL;
}
diff --git a/lib/linker.c b/lib/linker.c
index c66017c..b85cbb2 100644
--- a/lib/linker.c
+++ b/lib/linker.c
@@ -159,10 +159,8 @@ void addfile(char *nom)
objects[objindex]->datastart = datasize;
objects[objindex]->bssstart = bsssize;
- objects[objindex]->text =
- (Uint32 *) Emalloc(objects[objindex]->s_text * sizeof(Uint32));
- objects[objindex]->data =
- (Uint32 *) Emalloc(objects[objindex]->s_data * sizeof(Uint32));
+ objects[objindex]->text = (Uint32 *) Emalloc(objects[objindex]->s_text * sizeof(Uint32));
+ objects[objindex]->data = (Uint32 *) Emalloc(objects[objindex]->s_data * sizeof(Uint32));
pushcontext(_("Reading text and data segments"));
for (i = 0; i < objects[objindex]->s_text; i++) {
@@ -228,13 +226,10 @@ static void dumprelog(FILE * f)
decal = objects[t->objindex]->textstart + t->offset;
break;
case 2:
- decal =
- textsize + objects[t->objindex]->datastart + t->offset;
+ decal = textsize + objects[t->objindex]->datastart + t->offset;
break;
case 4:
- decal =
- textsize + datasize +
- objects[t->objindex]->bssstart + t->offset;
+ decal = textsize + datasize + objects[t->objindex]->bssstart + t->offset;
break;
default:
exception(1, _("Internal error"));
@@ -254,13 +249,10 @@ static void dumprelog(FILE * f)
decal = objects[t->objindex]->textstart + t->offset;
break;
case 2:
- decal =
- textsize + objects[t->objindex]->datastart + t->offset;
+ decal = textsize + objects[t->objindex]->datastart + t->offset;
break;
case 4:
- decal =
- textsize + datasize +
- objects[t->objindex]->bssstart + t->offset;
+ decal = textsize + datasize + objects[t->objindex]->bssstart + t->offset;
break;
default:
exception(1, _("Internal error"));
@@ -272,8 +264,7 @@ static void dumprelog(FILE * f)
s->offset, decal, s->name);
#endif
objects[s->objindex]->data[s->offset] += decal;
- writeword(textsize +
- objects[s->objindex]->datastart + s->offset, f);
+ writeword(textsize + objects[s->objindex]->datastart + s->offset, f);
break;
default:
exception(1, _("Internal error"));
@@ -327,8 +318,7 @@ void dumpfile(char *nom)
textsize, datasize, bsssize);
fprintf(stderr,
_
- ("Output file size: %i words containing %i relocating offsets.\n"),
- ftell(f), nbrsymbs);
+ ("Output file size: %i words containing %i relocating offsets.\n"), ftell(f) >> 2, nbrsymbs);
fclose(f);
}
diff --git a/lib/meta.c b/lib/meta.c
index 4f71ad7..0392770 100644
--- a/lib/meta.c
+++ b/lib/meta.c
@@ -19,12 +19,8 @@
\*************************/
static char meta_ops[] = ":.;(){}[=, ";
-static char meta_firsts[] =
-
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_";
-static char meta_chars[] =
-
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789";
+static char meta_firsts[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_";
+static char meta_chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789";
phon_t *phons = NULL;
field_t *fields = NULL;
@@ -127,8 +123,7 @@ void meta_parse_line(char *line)
}
if (*line) {
if (*line != ';') {
- exception(1,
- _("Expecting ';' for field separator."));
+ exception(1, _("Expecting ';' for field separator."));
}
line++;
gotname = 0;
@@ -249,9 +244,7 @@ void meta_parse_line(char *line)
if (isident(buffer)) {
p1 = Estrdup(buffer);
if (*line != '=') {
- exception(1,
- _
- ("Expecting operator '=' for field 'p'."));
+ exception(1, _("Expecting operator '=' for field 'p'."));
}
line++;
} else {
@@ -345,9 +338,8 @@ void meta_parse_line(char *line)
instruct->strings = (char **)
Emalloc(nbfields * sizeof(char *));
- instruct->etypes =
+ instruct->etypes = (int *) Emalloc(nbfields * sizeof(int));
- (int *) Emalloc(nbfields * sizeof(int));
instruct->implicits = (char **)
Emalloc(nbimplicit * sizeof(char *));
@@ -598,11 +590,9 @@ void main(void)
fprintf(stderr, "\nListe des champs:\n");
for (field = fields->next; field; field = field->next) {
- fprintf(stderr, " o Champ nommé %s, contenant %i parties:\n",
- field->name, field->nbr);
+ fprintf(stderr, " o Champ nommé %s, contenant %i parties:\n", field->name, field->nbr);
for (i = 0; i < field->nbr; i++) {
- fprintf(stderr, " + %s (%i bits)\n", field->names[i],
- field->sizes[i]);
+ fprintf(stderr, " + %s (%i bits)\n", field->names[i], field->sizes[i]);
}
}
@@ -613,33 +603,26 @@ void main(void)
pattern->name, pattern->nbr);
for (i = 0; i < pattern->nbr; i++) {
fprintf(stderr, " + %s (%s) type: %s\n",
- pattern->expr[i]->name ? pattern->
- expr[i]->name : "Opérateur [",
- pattern->expr[i]->string ? pattern->
- expr[i]->string : "Aucune chaîne associée",
- pattern->
- expr[i]->type ? "Constante prédéfinie" : pattern->expr[i]->
- left ? "Binaire" : pattern->
- expr[i]->right ? "Unaire" : "Feuille");
+ pattern->expr[i]->name ? pattern->expr[i]->name : "Opérateur [",
+ pattern->expr[i]->string ? pattern->expr[i]->string : "Aucune chaîne associée",
+ pattern->expr[i]->type ? "Constante prédéfinie" : pattern->
+ expr[i]->left ? "Binaire" : pattern->expr[i]->right ? "Unaire" : "Feuille");
if (pattern->expr[i]->left) {
fprintf(stderr,
" - gauche: %s (%s) type: %s\n",
- pattern->expr[i]->left->name ? pattern->expr[i]->left->
- name : "Opérateur [",
- pattern->expr[i]->left->string ? pattern->expr[i]->
- left->string : "Aucune chaîne associée",
- pattern->expr[i]->
- left->type ? "Constante prédéfinie" : "Feuille");
+ pattern->expr[i]->left->name ? pattern->expr[i]->left->name : "Opérateur [",
+ pattern->expr[i]->left->string ? pattern->expr[i]->left->
+ string : "Aucune chaîne associée",
+ pattern->expr[i]->left->type ? "Constante prédéfinie" : "Feuille");
}
if (pattern->expr[i]->right) {
fprintf(stderr,
" - droite: %s (%s) type: %s\n",
- pattern->expr[i]->right->name ? pattern->expr[i]->
- right->name : "Opérateur [",
- pattern->expr[i]->right->string ? pattern->expr[i]->
- right->string : "Aucune chaîne associée",
- pattern->expr[i]->
- right->type ? "Constante prédéfinie" : "Feuille");
+ pattern->expr[i]->right->name ? pattern->expr[i]->right->
+ name : "Opérateur [",
+ pattern->expr[i]->right->string ? pattern->expr[i]->right->
+ string : "Aucune chaîne associée",
+ pattern->expr[i]->right->type ? "Constante prédéfinie" : "Feuille");
}
}
}
@@ -653,10 +636,8 @@ void main(void)
for (i = 0; i < instruct->nbexplicit; i++) {
fprintf(stderr, " + %s <= %s (type %s)\n",
instruct->names[i],
- instruct->
- strings[i] ? instruct->strings[i] :
- "Pas de chaîne associée",
- instruct->etypes[i] ? "prédéfinit" : "direct");
+ instruct->strings[i] ? instruct->strings[i] :
+ "Pas de chaîne associée", instruct->etypes[i] ? "prédéfinit" : "direct");
}
fprintf(stderr, " => Champs implicites.\n");
for (i = 0; i < instruct->nbimplicit; i++) {
diff --git a/lib/parser.c b/lib/parser.c
index cf2eab3..e5061a7 100644
--- a/lib/parser.c
+++ b/lib/parser.c
@@ -229,8 +229,7 @@ void parse_line(char *line)
while (pileop_pos) {
op = pop_op();
if (op == '(')
- exception(-1,
- _("Parse error: too much left parenthesis"));
+ exception(-1, _("Parse error: too much left parenthesis"));
act_pile(get_func(op));
}
popcontext();
@@ -240,8 +239,7 @@ void parse_line(char *line)
/* Fin de parenthese (Appel de fonction ou expression mathématique) */
while (1) {
if (!pileop_pos)
- exception(-1,
- _("Parse error: too much right parenthesis"));
+ exception(-1, _("Parse error: too much right parenthesis"));
op = pop_op();
if (((op & 127) == '('))
break;
@@ -261,8 +259,7 @@ void parse_line(char *line)
/* Fin d'opérateur de décalage */
while (1) {
if (!pileop_pos)
- exception(-1,
- _("Parse error: too much right parenthesis"));
+ exception(-1, _("Parse error: too much right parenthesis"));
op = pop_op();
if (((op & 127) == '['))
break;
diff --git a/lib/simulator.c b/lib/simulator.c
index 1bfdcd2..ea3b142 100644
--- a/lib/simulator.c
+++ b/lib/simulator.c
@@ -58,8 +58,7 @@ Uint32 Adresse(Uint32 u, Uint32 instruction)
switch (champ(u, 4)) {
case 0:
- exception(1,
- _("Adresse: Call With Invalid r/m Field State ( r/m=00 )"));
+ exception(1, _("Adresse: Call With Invalid r/m Field State ( r/m=00 )"));
return (0);
case 1:
tmp = LireInstruction();
@@ -228,13 +227,10 @@ void DecodeExec(Uint32 instruction)
if (ValeurBit(Extension(instruction), 1) == 0) { /* Mov arg1 arg2 */
if (ValeurBit(Extension(instruction), 0) == 0) { /* arg2 = reg */
if (champ(Champ1(instruction), 2) == 0) { /* r/m de arg1 = 0 */
- EcrireRegistre(Champ3
- (instruction),
- LireRegistre(Champ2(instruction)));
+ EcrireRegistre(Champ3(instruction), LireRegistre(Champ2(instruction)));
} else {
ST(Adresse
- (Champ1(instruction),
- instruction), LireRegistre(Champ2(instruction)));
+ (Champ1(instruction), instruction), LireRegistre(Champ2(instruction)));
}
} else { /* arg2 = imm32 */
if (champ(Champ1(instruction), 2) == 0) { /* r/m de arg1 = 0 */
@@ -249,19 +245,14 @@ void DecodeExec(Uint32 instruction)
} else { /* mov arg2, arg1 */
if (ValeurBit(Extension(instruction), 0) == 0) { /* arg2 = reg */
if (champ(Champ1(instruction), 2) == 0) { /* r/m de arg1 = 0 */
- EcrireRegistre(Champ2
- (instruction),
- LireRegistre(Champ3(instruction)));
+ EcrireRegistre(Champ2(instruction), LireRegistre(Champ3(instruction)));
} else {
EcrireRegistre(Champ2
(instruction),
- LD(Adresse
- (Champ1(instruction), instruction)));
+ LD(Adresse(Champ1(instruction), instruction)));
}
} else { /* arg2 = imm32 */
- exception(1,
- _
- ("MOV: Memory to Memory Forbidden On This Type Of Processor"));
+ exception(1, _("MOV: Memory to Memory Forbidden On This Type Of Processor"));
}
}
fin:
@@ -279,26 +270,17 @@ void DecodeExec(Uint32 instruction)
if (Champ1(instruction) == Champ2(instruction)) {
test1 = 1;
} else {
- test1 =
- LireRegistre(Champ1
- (instruction)) ==
- LireRegistre(Champ2(instruction));
+ test1 = LireRegistre(Champ1(instruction)) == LireRegistre(Champ2(instruction));
}
break;
case 1:
- test1 =
- LireRegistre(Champ1(instruction)) !=
- LireRegistre(Champ2(instruction));
+ test1 = LireRegistre(Champ1(instruction)) != LireRegistre(Champ2(instruction));
break;
case 2:
- test1 =
- LireRegistre(Champ1(instruction)) <
- LireRegistre(Champ2(instruction));
+ test1 = LireRegistre(Champ1(instruction)) < LireRegistre(Champ2(instruction));
break;
case 3:
- test1 =
- LireRegistre(Champ1(instruction)) <=
- LireRegistre(Champ2(instruction));
+ test1 = LireRegistre(Champ1(instruction)) <= LireRegistre(Champ2(instruction));
break;
}
switch (champ(Extension(instruction) >> 2, 4)) {
@@ -348,8 +330,7 @@ void DecodeExec(Uint32 instruction)
if (ValeurBit(Extension(instruction), 0) == 0) {
/* RET */
of = LireRegistreFLAG();
- EcrireRegistreSP(AdditionNonSigne
- (LireRegistreSP(), Champ1(instruction)));
+ EcrireRegistreSP(AdditionNonSigne(LireRegistreSP(), Champ1(instruction)));
EcrireRegistreSP(AdditionNonSigne(LireRegistreSP(), 1));
EcrireRegistrePC(LD(LireRegistreSP()));
EcrireRegistreFLAG(of);
@@ -424,8 +405,7 @@ void AfficheReg(void) // affiche reg
fprintf(stderr, "\n");
}
fprintf(stderr, "Rg: %08lX | Rd: %08lX | Flag: %08lX | PC: %08lX\n",
- LireRegistreRG(), LireRegistreRD(), LireRegistreFLAG(),
- LireRegistrePC());
+ LireRegistreRG(), LireRegistreRD(), LireRegistreFLAG(), LireRegistrePC());
}
void Debogueur(void)
@@ -441,8 +421,7 @@ void Debogueur(void)
Opcode(instruction), Extension(instruction),
Champ1(instruction), Champ2(instruction), Champ3(instruction));
fprintf(stderr, "%08lX:%08lX - %08lX - %08lX > ",
- LireRegistrePC(), instruction, LD(LireRegistrePC() + 1),
- LD(LireRegistrePC() + 2));
+ LireRegistrePC(), instruction, LD(LireRegistrePC() + 1), LD(LireRegistrePC() + 2));
switch (fgetc(input)) {
case 'G':
@@ -464,9 +443,7 @@ void Debogueur(void)
clearterm();
exception(1, _("Shutdown requested"));
default:
- fprintf(stderr,
- _
- ("Help:\nG: go\nP: Proceed\nR: display registers\nQ: quit\n"));
+ fprintf(stderr, _("Help:\nG: go\nP: Proceed\nR: display registers\nQ: quit\n"));
}
}
}
@@ -528,8 +505,7 @@ void ChargeBinaire(char *filename)
}
for (i = 0; i < nr; i++) { /* relogement */
- ST(base_addr + relocation_table[i],
- LD(base_addr + relocation_table[i]) + base_addr);
+ ST(base_addr + relocation_table[i], LD(base_addr + relocation_table[i]) + base_addr);
}
free(relocation_table);
diff --git a/samples/Makefile.am b/samples/Makefile.am
index 2427d6a..92a419b 100644
--- a/samples/Makefile.am
+++ b/samples/Makefile.am
@@ -1,3 +1,7 @@
-EXTRA_DIST = rechcara.s recherche.s sommeentiers.s testtout.s Makefile.samples instructions.txt
+EXTRA_DIST = fichier1.s fichier2.s rechcara.s recherche.s sommeentiers.s testtout.s Makefile.samples instructions.txt boucle.s
-TESTS = make -f Makefile.samples
+all:
+ make -f Makefile.samples
+
+clean:
+ male -f Makefile.samples clean
diff --git a/samples/Makefile.samples b/samples/Makefile.samples
index 7d004ca..978d9d0 100644
--- a/samples/Makefile.samples
+++ b/samples/Makefile.samples
@@ -10,7 +10,14 @@
chmod 755 $@
rm tmp.o
-all: hello recherche rechcara sommeentiers testtout
+all: helloworld hello recherche rechcara sommeentiers testtout boucle
+
+helloworld: fichier1.s fichier2.s
+ ../src/compilo fichier1.s fichier1.o
+ ../src/compilo fichier2.s fichier2.o
+ ../src/linker fichier1.o fichier2.o helloworld
+ chmod 755 helloworld
+ rm fichier1.o fichier2.o
clean:
- rm -f recherche rechcara sommeenters testtout *.o __symbols__ __text__
+ rm -f helloworld recherche rechcara sommeenters testtout *.o __symbols__ __text__
diff --git a/samples/fichier1.s b/samples/fichier1.s
new file mode 100644
index 0000000..adefefb
--- /dev/null
+++ b/samples/fichier1.s
@@ -0,0 +1,6 @@
+.data
+Hello DS "Hello World\n"
+
+.text
+Print: MOV, [0xffffff04], Hello
+ HALT
diff --git a/samples/fichier2.s b/samples/fichier2.s
new file mode 100644
index 0000000..fc3187e
--- /dev/null
+++ b/samples/fichier2.s
@@ -0,0 +1,3 @@
+.text
+.start
+ JMP Print
diff --git a/samples/testtout.s b/samples/testtout.s
index f8bbdbf..2287a4d 100644
--- a/samples/testtout.s
+++ b/samples/testtout.s
@@ -1,8 +1,9 @@
.data
-PROG1 DS "hello"
-PROG2 DS "sommeentiers"
-PROG3 DS "rechcara"
-PROG4 DS "recherche"
+PROG1 DS "helloworld"
+PROG2 DS "hello"
+PROG3 DS "sommeentiers"
+PROG4 DS "rechcara"
+PROG5 DS "recherche"
MSG1 DS "Exécution du programme numéro "
MSG2 DS " appelé "
@@ -10,7 +11,7 @@ MSG3 DS "...\n"
MSGTERM DS "Le programme s'est terminé!\n"
MSGFIN DS "Tout est terminé, bye!\n"
-PROGS DD PROG1, PROG2, PROG3, PROG4, 0
+PROGS DD PROG1, PROG2, PROG3, PROG4, PROG5, 0
.text
.start