1 MODULE DswCompiler486Main
;
3 IMPORT Kernel
, HostFiles
, Files
, Console
, Strings
, DswDocuments
,
4 DevCPM
, DevCPT
, DevCPB
, DevCPP
, DevCPE
, DevCPV
:= DevCPV486
, DevCPS
,
8 (* compiler options: *)
9 checks
= 0; allchecks
= 1; assert
= 2; obj
= 3; ref
= 4; allref
= 5;
10 srcpos
= 6; reallib
= 7; signatures
= 8;
11 (* pVarInd = 14; bigEnd = 15; *) ctime
= 16;
12 mainprog
= 20; include0
= 21;
13 hint
= 29; oberon
= 30; errorTrap
= 31;
14 defopt
= {checks
, assert
, obj
, ref
, allref
, srcpos
, signatures
, ctime
};
22 Elem
= POINTER TO RECORD
23 dir
, name
, path
: Files
.Name
;
24 outsym
, outcode
: Files
.Name
; (* dir *)
25 insym
: DevCPM
.Directory
;
26 found
: BOOLEAN; (* COM Aware *)
31 Def
= POINTER TO RECORD
41 PROCEDURE GetPath (IN path
: ARRAY OF CHAR; OUT dir
, name
: Files
.Name
);
42 VAR i
, j
, len
: INTEGER;
46 WHILE (i
>= 0) & (path
[i
] # '
/'
) DO DEC(i
) END;
48 FOR i
:= 0 TO i
- 1 DO
63 PROCEDURE InitOptions
;
67 insym
, sym
: DevCPM
.Directory
;
68 outsym
, outcode
: Files
.Name
;
75 IF i
>= Kernel
.argc
THEN
76 Console
.WriteStr("required more parameters for ");
77 Console
.WriteStr(p
); Console
.WriteLn
;
82 PROCEDURE Define (IN name
: DevCPT
.Name
; val
: BOOLEAN);
85 NEW(def
); def
.name
:= name$
; def
.val
:= val
; def
.next
:= d
; d
:= def
89 outsym
:= ""; outcode
:= "";
90 opts
:= defopt
; opts2
:= defopt2
; found
:= FALSE
;
91 h
:= NIL; t
:= NIL; insym
:= NIL;
93 WHILE i
< Kernel
.argc
DO
94 IF Kernel
.argv
[i
, 0] = "-" THEN
99 ELSIF p
= "-outsym" THEN
101 outsym
:= Kernel
.argv
[i
]$
;
103 ELSIF p
= "-outcode" THEN
105 outcode
:= Kernel
.argv
[i
]$
;
107 ELSIF p
= "-symdir" THEN
111 insym
.path
:= Kernel
.argv
[i
]$
;
112 insym
.legacy
:= FALSE
;
115 ELSIF p
= "-legacysymdir" THEN
119 insym
.path
:= Kernel
.argv
[i
]$
;
120 insym
.legacy
:= TRUE
;
123 ELSIF p
= "-allchecks" THEN
124 INCL(opts
, allchecks
)
125 ELSIF p
= "-no-allchecks" THEN
126 EXCL(opts
, allchecks
)
127 ELSIF p
= "-srcpos" THEN
129 ELSIF p
= "-no-srcpos" THEN
131 ELSIF p
= "-structref" THEN
133 ELSIF p
= "-no-structref" THEN
135 ELSIF p
= "-ref" THEN
137 ELSIF p
= "-no-ref" THEN
139 ELSIF p
= "-obj" THEN
141 ELSIF p
= "-no-obj" THEN
143 ELSIF p
= "-assert" THEN
145 ELSIF p
= "-no-assert" THEN
147 ELSIF p
= "-checks" THEN
149 ELSIF p
= "-no-checks" THEN
151 ELSIF p
= "-hints" THEN
153 ELSIF p
= "-no-hints" THEN
155 ELSIF p
= "-trap" THEN
156 Kernel
.intTrap
:= TRUE
;
157 INCL(opts
, errorTrap
)
158 ELSIF p
= "-no-trap" THEN
159 EXCL(opts
, errorTrap
)
160 ELSIF p
= "-oberon" THEN
162 ELSIF p
= "-no-oberon" THEN
164 ELSIF p
= "-com-aware" THEN
166 ELSIF p
= "-no-com-aware" THEN
168 ELSIF (p
= "-v") OR (p
= "-verbose") THEN
169 DevCPM
.verbose
:= MIN(DevCPM
.verbose
+ 1, 3);
170 ELSIF p
= "-main" THEN
172 ELSIF p
= "-no-main" THEN
174 ELSIF p
= "-include0" THEN
176 ELSIF p
= "-no-include0" THEN
178 ELSIF p
= "-includedir" THEN
182 ELSIF p
= "-long-calls" THEN
184 ELSIF p
= "-no-long-calls" THEN
186 ELSIF p
= "-version" THEN
187 Console
.WriteStr(version
); Console
.WriteLn
;
189 ELSIF p
= "-use-time" THEN
191 ELSIF p
= "-no-use-time" THEN
193 ELSIF p
= "-define+" THEN
194 Check
; Define(Kernel
.argv
[i
]$
, TRUE
); INC(i
)
195 ELSIF p
= "-define-" THEN
196 Check
; Define(Kernel
.argv
[i
]$
, FALSE
); INC(i
)
198 Console
.WriteStr("unknown option ");
199 Console
.WriteStr(p
); Console
.WriteLn
;
203 IF h
= NIL THEN NEW(h
); t
:= h
204 ELSE NEW(t
.next
); t
:= t
.next
206 t
.path
:= Kernel
.argv
[i
]$
;
207 t
.outcode
:= outcode
;
213 GetPath(t
.path
, t
.dir
, t
.name
);
215 Console
.WriteStr("specified path to directory"); Console
.WriteLn
;
224 PROCEDURE Module (source
: POINTER TO ARRAY OF CHAR; m
: Elem
; OUT error
: BOOLEAN);
225 VAR ext
, new
: BOOLEAN; p
: DevCPT
.Node
; def
: Def
;
228 DevCPM
.symList
:= m
.insym
;
229 DevCPM
.codePath
:= m
.outcode
;
230 DevCPM
.symPath
:= m
.outsym
;
231 DevCPM
.name
:= m
.path
;
232 IF m
.found
THEN INCL(DevCPM
.options
, DevCPM
.comAware
) END;
233 IF errorTrap
IN m
.opts
THEN INCL(DevCPM
.options
, DevCPM
.trap
) END;
234 IF oberon
IN m
.opts
THEN INCL(DevCPM
.options
, DevCPM
.oberon
) END;
236 DevCPB
.typSize
:= DevCPV
.TypeSize
;
237 DevCPT
.processor
:= DevCPV
.processor
;
241 DevCPR
.Set(def
.name
, def
.val
);
247 IF DevCPT
.libName
# "" THEN EXCL(m
.opts
, obj
) END;
248 DevCPV
.Init(m
.opts
); DevCPV
.Allocate
; DevCPT
.Export(ext
, new
);
249 IF DevCPM
.noerr
& (obj
IN m
.opts
) THEN
250 IF emulong
IN m
.opts2
THEN
251 DevCPH
.UseCalls(p
, {DevCPH
.longMop
, DevCPH
.longDop
})
257 IF DevCPM
.noerr
& (new
OR ext
) THEN DevCPM
.RegisterNewSym
258 ELSE DevCPM
.DeleteNewSym
262 error
:= ~DevCPM
.noerr
;
265 IF DevCPM
.verbose
> 0 THEN DevCPM
.LogWStr(" ") END;
266 IF DevCPM
.errors
= 1 THEN
267 DevCPM
.LogWStr("one error detected")
269 DevCPM
.LogWNum(DevCPM
.errors
, 0); DevCPM
.LogWStr(" errors detected")
273 IF hint
IN m
.opts
THEN DevCPM
.InsertMarks
END
280 PROCEDURE ReadText (s
: Elem
): POINTER TO ARRAY OF CHAR;
283 m
: DswDocuments
.Model
;
284 r
: DswDocuments
.Reader
;
286 src
: POINTER TO ARRAY OF CHAR;
287 num
: ARRAY 32 OF CHAR;
289 loc
:= Files
.dir
.This(s
.dir
);
290 DswDocuments
.Open(loc
, s
.name
, m
, res
);
292 r
:= m
.NewReader(NIL);
293 NEW(src
, m
.Length() + 1);
295 FOR i
:= 0 TO m
.Length() - 1 DO
296 r
.Read
; src
[i
] := r
.char
299 ELSIF DevCPM
.verbose
> 0 THEN
300 Strings
.IntToString(res
, num
);
301 Console
.WriteStr("document error ");
302 Console
.WriteStr(num
);
306 Console
.WriteStr("unable to open file ");
307 Console
.WriteStr(s
.path
);
314 PROCEDURE CompileAll
;
315 VAR loc
: Files
.Locator
; m
: Elem
; error
: BOOLEAN; src
: POINTER TO ARRAY OF CHAR;
319 IF DevCPM
.verbose
> 0 THEN
320 Console
.WriteStr("compiling "); Console
.WriteStr(m
.path
); Console
.WriteLn
323 Module(src
, m
, error
);
324 IF error
THEN Kernel
.Quit(1) END;
331 IF Kernel
.trapCount
# 0 THEN Kernel
.Quit(1) END;
332 HostFiles
.SetRootDir(".");
339 Kernel
.intTrap
:= FALSE
;
341 END DswCompiler486Main
.