[m-dev.] for review: Infrastructure for Java Backend
Julien Fischer
juliensf at students.cs.mu.oz.au
Tue Jan 23 17:05:39 AEDT 2001
Estimated hours taken: 11
Two main changes:
Enable support for compiling to Java, options for same etc.
Alter the MLDS so that the definition of mlds__lval for
variables includes type information about the variable. The
Java backend uses this to distinguish between integers that are
enumertion constants and those that are just integers. The definition
of ctor_name has been changed so that the names of
Added an access specifier `local' because when methods were being
generated there was no distinction between local and private variables,
and the local variables were being declared private; the Java compiler
was not particularly happy about this. These three changes are
resposible for causing most of the changes below.
I'll post the actual Java backend shortly.
Julien
compiler/globals.m
Removed comment about java not being implemented, replaced
by one saying it is work in progress
compiler/options.m
Add new options for compiling Java files:
`--java-compiler' (`--javac'),
`--java-flags',
`--java-include-directory'
`--java-object-file-extension'
`--java-flag-to-name-object-file'
compiler/handle_options.m
If compiling to Java, then don't link.
Add "java" grade
XXX need to modify other files too:
% runtime/mercury_grade.h
% scripts/parse_grade_options.sh-subr
etc.
compiler/mercury_compile.m
If Target = java then call the Java backend
compiler/mlds.m
Added new access flag, `local' because code in generated
classes was unable to tell the difference between local
and instance variables.
Added type information for lvals that are variables because the
java backend needs this information in creating enumeration objects.
Redefined ctor_name from a string, to a fully module qualified
definition.
compiler/ml_call_gen.m
Fixed up code in relation to changes made to mlds.m and ml_code_util.m
compiler/ml_code_gen.m
Mark the generated functions as `one_copy' rather than `per_instance',
so that they get generated as static methods for the Java back-end.
Fix a bug with the --det-copy-out option.
compiler/ml_code_util.m
Changed name of predicate `ml_qualify_var' to `ml_gen_var_lval'
Fixed up code in relation to changes made in mlds.m
compiler/ml_elim_nested.m
Changed code to match new definition of mlds__lval
compiler/ml_optimize.m
Changed code to match new definition of mlds__lval
compiler/ml_string_switch.m
Changed code to match new definition of mlds__lval
compiler/ml_tailcall.m
Changed code to match new definition of mlds__lval
compiler/ml_type_gen.m
Mark the generated types as `one_copy' rather than `per_instance',
so that they get generated as static nested classes for the Java
back-end.
Export functions that generate decl flags because the Java
backend needs them for some MLDS->MLDS transformations that it
does
Changed comments to reflect that classes and enumeration constants
should be static
Created function that generates decl flags for members of
`special pred' classes that the Java backend generates
compiler/ml_unify_gen.m
Fixed up problems caused by altering mlds.m and changing
the name `ml_qualify_var' to `ml_gen_var_lval'
Altered code that generates ctor_id's so that it generates
the new sort.
compiler/ml_util.m
Added two predicates, one of which tests whether an mlds defn
is a special predicate and another that tests whether a data
definition define rtti.
compiler/mlds_to_c.m
Fixed up problems caused by altering the definition of mlds__lval,
adding local access and changing the definition of ctor__name.
compiler/mlds_to_il.m
Fixed up problems caused by altering the definition of mlds__lval
compiler/mlds_to_ilasm.m
Fixed up problems caused by altering the definition of mlds__lval
compiler/rtti_to_mlds.m
Fixed up problems caused by altering the definition of mlds__lval
Index: globals.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/globals.m,v
retrieving revision 1.39
diff -u -r1.39 globals.m
--- globals.m 2001/01/10 10:53:50 1.39
+++ globals.m 2001/01/23 05:53:34
@@ -26,12 +26,11 @@
; il % Generate IL assembler code
% IL is the Microsoft .NET Intermediate Language
; java % Generate Java
- % (this target is not yet implemented)
+ % (Work in progress)
; asm. % Compile directly to assembler via the GCC back-end.
% Do not go via C, instead generate GCC's internal
% `tree' data structure.
% (Work in progress.)
-
:- type gc_method
---> none
; conservative
Index: handle_options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/handle_options.m,v
retrieving revision 1.99
diff -u -r1.99 handle_options.m
--- handle_options.m 2001/01/10 10:53:50 1.99
+++ handle_options.m 2001/01/23 05:53:34
@@ -85,13 +85,15 @@
TargetCodeOnly),
globals__io_get_target(Target),
{ GenerateIL = (if Target = il then yes else no) },
+ { GenerateJava = (if Target = java then yes else no) },
globals__io_lookup_bool_option(compile_only, CompileOnly),
globals__io_lookup_bool_option(aditi_only, AditiOnly),
{ bool__or_list([GenerateDependencies, MakeInterface,
MakePrivateInterface, MakeShortInterface,
MakeOptimizationInt, MakeTransOptInt,
ConvertToMercury, ConvertToGoedel, TypecheckOnly,
- ErrorcheckOnly, TargetCodeOnly, GenerateIL,
+ ErrorcheckOnly, TargetCodeOnly,
+ GenerateIL, GenerateJava,
CompileOnly, AditiOnly],
NotLink) },
{ bool__not(NotLink, Link) }
@@ -216,7 +218,7 @@
{ Error = yes("Invalid GC option (must be `none', `conservative' or `accurate')") }
)
;
- { Error = yes("Invalid target option (must be `c' or `il')") }
+ { Error = yes("Invalid target option (must be `c', `il', or `java')") }
).
@@ -293,7 +295,23 @@
;
[]
),
-
+ % Generating Java implies high-level code, turning off nested functions,
+ % using copy-out for both det and nondet output arguments,
+ % using zero tags, boxing enums, disabling no_tag_types and no
+ % static ground terms.
+ ( { Target = java } ->
+ globals__io_set_option(highlevel_code, bool(yes)),
+ globals__io_set_option(gcc_nested_functions, bool(no)),
+ globals__io_set_option(nondet_copy_out, bool(yes)),
+ globals__io_set_option(det_copy_out, bool(yes)),
+ globals__io_set_option(num_tag_bits, int(0)),
+ globals__io_set_option(line_numbers, bool(no))
+ % XXX These are done for IL, are they needed for Java?
+ % globals__io_set_option(unboxed_enums, bool(no)),
+ % globals__io_set_option(unboxed_no_tag_types, bool(no))
+ ;
+ []
+ ),
% Generating assembler via the gcc back-end requires
% using high-level code.
( { Target = asm } ->
@@ -310,7 +328,7 @@
;
[]
),
-
+
% --high-level-code disables the use of low-level gcc extensions
option_implies(highlevel_code, gcc_non_local_gotos, bool(no)),
option_implies(highlevel_code, gcc_global_registers, bool(no)),
@@ -936,6 +954,14 @@
gcc_nested_functions - bool(no),
highlevel_data - bool(no),
target - string("il")]).
+grade_component_table("java", gcc_ext, [
+ asm_labels - bool(no),
+ gcc_non_local_gotos - bool(no),
+ gcc_global_registers - bool(no),
+ gcc_nested_functions - bool(no),
+ highlevel_code - bool(yes),
+ highlevel_data - bool(yes),
+ target - string("java")]).
% Parallelism/multithreading components.
grade_component_table("par", par, [parallel - bool(yes)]).
Index: mercury_compile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.188
diff -u -r1.188 mercury_compile.m
--- mercury_compile.m 2001/01/18 01:18:48 1.188
+++ mercury_compile.m 2001/01/23 05:53:34
@@ -62,6 +62,7 @@
:- import_module ml_elim_nested, ml_tailcall. % MLDS -> MLDS
:- import_module ml_optimize. % MLDS -> MLDS
:- import_module mlds_to_c. % MLDS -> C
+:- import_module mlds_to_java. % MLDS -> Java
:- import_module mlds_to_ilasm. % MLDS -> IL assembler
:- import_module maybe_mlds_to_gcc. % MLDS -> GCC back-end
@@ -485,6 +486,14 @@
mercury_compile__il_assemble(ModuleName,
HasMain)
)
+ ; { Target = java } ->
+ mercury_compile__mlds_backend(HLDS50, MLDS),
+ mercury_compile__mlds_to_java(MLDS),
+ ( { TargetCodeOnly = yes } ->
+ []
+ ;
+ mercury_compile__compile_java_file(ModuleName)
+ )
; { Target = asm } ->
% compile directly assembler using the gcc back-end
mercury_compile__mlds_backend(HLDS50, MLDS),
@@ -2582,6 +2591,18 @@
maybe_write_string(Verbose, "% Finished converting MLDS to C.\n"),
maybe_report_stats(Stats).
+:- pred mercury_compile__mlds_to_java(mlds, io__state, io__state).
+:- mode mercury_compile__mlds_to_java(in, di, uo) is det.
+
+mercury_compile__mlds_to_java(MLDS) -->
+ globals__io_lookup_bool_option(verbose, Verbose),
+ globals__io_lookup_bool_option(statistics, Stats),
+
+ maybe_write_string(Verbose, "% Converting MLDS to Java...\n"),
+ mlds_to_java__output_mlds(MLDS),
+ maybe_write_string(Verbose, "% Finished converting MLDS to Java.\n"),
+ maybe_report_stats(Stats).
+
:- pred mercury_compile__maybe_mlds_to_gcc(mlds, bool, io__state, io__state).
:- mode mercury_compile__maybe_mlds_to_gcc(in, out, di, uo) is det.
@@ -2917,6 +2938,48 @@
invoke_system_command(Command, Succeeded),
( { Succeeded = no } ->
report_error("problem compiling C file.")
+ ;
+ []
+ ).
+
+:- pred mercury_compile__compile_java_file(module_name, io__state, io__state).
+:- mode mercury_compile__compile_java_file(in, di, uo) is det.
+
+mercury_compile__compile_java_file(ModuleName) -->
+ module_name_to_file_name(ModuleName, ".java", no, JavaFile),
+ globals__io_lookup_bool_option(verbose, Verbose),
+ maybe_write_string(Verbose, "% Compiling `"),
+ maybe_write_string(Verbose, JavaFile),
+ maybe_write_string(Verbose, "':\n"),
+ globals__io_lookup_string_option(java_compiler, JavaCompiler),
+ globals__io_lookup_accumulating_option(java_flags, JavaFlagsList),
+ { join_string_list(JavaFlagsList, "", "", " ", JAVAFLAGS) },
+
+ globals__io_lookup_accumulating_option(java_include_directory,
+ Java_Incl_Dirs),
+ ( { Java_Incl_Dirs = [] } ->
+ { InclOpt = "" }
+ ;
+ % XXX PathSeparator should be ";" on Windows
+ { PathSeparator = ":" },
+ { join_string_list(Java_Incl_Dirs, "", "",
+ PathSeparator, ClassPath) },
+ { InclOpt = string__append_list([
+ "-classpath ", ClassPath, " "]) }
+ ),
+ globals__io_lookup_bool_option(target_debug, Target_Debug),
+ { Target_Debug = yes ->
+ Target_DebugOpt = "-g "
+ ;
+ Target_DebugOpt = ""
+ },
+ % Be careful with the order here! Some options may override others.
+ % Also be careful that each option is separated by spaces.
+ { string__append_list([JavaCompiler, " ", InclOpt,
+ Target_DebugOpt, JAVAFLAGS, JavaFile], Command) },
+ invoke_system_command(Command, Succeeded),
+ ( { Succeeded = no } ->
+ report_error("problem compiling Java file.")
;
[]
).
Index: ml_call_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_call_gen.m,v
retrieving revision 1.19
diff -u -r1.19 ml_call_gen.m
--- ml_call_gen.m 2000/12/03 02:22:38 1.19
+++ ml_call_gen.m 2001/01/23 05:53:34
@@ -207,7 +207,7 @@
FuncVarName) },
{ FuncVarDecl = ml_gen_mlds_var_decl(var(FuncVarName), FuncType,
mlds__make_context(Context)) },
- ml_qualify_var(FuncVarName, FuncVarLval),
+ ml_gen_var_lval(FuncVarName, FuncType, FuncVarLval),
{ AssignFuncVar = ml_gen_assign(FuncVarLval, FuncRval, Context) },
{ FuncVarRval = lval(FuncVarLval) },
@@ -475,8 +475,8 @@
ml_gen_new_func_label(yes(Params),
ContFuncLabel, ContFuncLabelRval),
/* push nesting level */
- ml_gen_copy_args_to_locals(OutputArgLvals, Context,
- CopyDecls, CopyStatements),
+ ml_gen_copy_args_to_locals(OutputArgLvals, OutputArgTypes,
+ Context, CopyDecls, CopyStatements),
ml_gen_call_current_success_cont(Context, CallCont),
{ CopyStatement = ml_gen_block(CopyDecls,
list__append(CopyStatements, [CallCont]), Context) },
@@ -513,26 +513,33 @@
{ Argument = data(var(ArgName)) - Type },
ml_gen_cont_params_2(Types, ArgNum + 1, Arguments).
-:- pred ml_gen_copy_args_to_locals(list(mlds__lval), prog_context,
- mlds__defns, mlds__statements, ml_gen_info, ml_gen_info).
-:- mode ml_gen_copy_args_to_locals(in, in, out, out, in, out) is det.
+:- pred ml_gen_copy_args_to_locals(list(mlds__lval), list(mlds__type),
+ prog_context, mlds__defns, mlds__statements,
+ ml_gen_info, ml_gen_info).
+:- mode ml_gen_copy_args_to_locals(in, in, in, out, out, in, out) is det.
-ml_gen_copy_args_to_locals(ArgLvals, Context, CopyDecls, CopyStatements) -->
+ml_gen_copy_args_to_locals(ArgLvals, ArgTypes, Context,
+ CopyDecls, CopyStatements) -->
{ CopyDecls = [] },
- ml_gen_copy_args_to_locals_2(ArgLvals, 1, Context, CopyStatements).
+ ml_gen_copy_args_to_locals_2(ArgLvals, ArgTypes, 1, Context,
+ CopyStatements).
-:- pred ml_gen_copy_args_to_locals_2(list(mlds__lval), int, prog_context,
- mlds__statements, ml_gen_info, ml_gen_info).
-:- mode ml_gen_copy_args_to_locals_2(in, in, in, out, in, out) is det.
-
-ml_gen_copy_args_to_locals_2([], _, _, []) --> [].
-ml_gen_copy_args_to_locals_2([LocalLval | LocalLvals], ArgNum, Context,
- [Statement | Statements]) -->
+:- pred ml_gen_copy_args_to_locals_2(list(mlds__lval), list(mlds__type), int,
+ prog_context, mlds__statements, ml_gen_info, ml_gen_info).
+:- mode ml_gen_copy_args_to_locals_2(in, in, in, in, out, in, out) is det.
+
+ml_gen_copy_args_to_locals_2([], [], _, _, []) --> [].
+ml_gen_copy_args_to_locals_2([LocalLval | LocalLvals], [Type|Types], ArgNum,
+ Context, [Statement | Statements]) -->
{ ArgName = ml_gen_arg_name(ArgNum) },
- ml_qualify_var(ArgName, ArgLval),
+ ml_gen_var_lval(ArgName, Type, ArgLval),
{ Statement = ml_gen_assign(LocalLval, lval(ArgLval), Context) },
- ml_gen_copy_args_to_locals_2(LocalLvals, ArgNum + 1, Context,
+ ml_gen_copy_args_to_locals_2(LocalLvals, Types, ArgNum + 1, Context,
Statements).
+ml_gen_copy_args_to_locals_2([], [_|_], _, _, _) -->
+ { error("ml_gen_copy_args_to_locals_2: list length mismatch") }.
+ml_gen_copy_args_to_locals_2([_|_], [], _, _, _) -->
+ { error("ml_gen_copy_args_to_locals_2: list length mismatch") }.
:- func ml_gen_arg_name(int) = string.
ml_gen_arg_name(ArgNum) = ArgName :-
@@ -773,8 +780,8 @@
%
% If that didn't work, then we need to declare a fresh variable
% to use as the arg, and to generate statements to box/unbox
- % that fresh arg variable and assign it to/from the output argument
- % whose address we were passed.
+ % that fresh arg variable and assign it to/from the output
+ % argument whose address we were passed.
%
% generate a declaration for the fresh variable
@@ -789,7 +796,8 @@
% create the lval for the variable and use it for the
% argument lval
- ml_qualify_var(ArgVarName, ArgLval),
+ ml_gen_type(CalleeType, MLDS_CalleeType),
+ ml_gen_var_lval(ArgVarName, MLDS_CalleeType, ArgLval),
( { type_util__is_dummy_argument_type(CallerType) } ->
% if it is a dummy argument type (e.g. io__state),
Index: ml_code_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_code_gen.m,v
retrieving revision 1.73
diff -u -r1.73 ml_code_gen.m
--- ml_code_gen.m 2001/01/17 17:37:15 1.73
+++ ml_code_gen.m 2001/01/23 05:53:34
@@ -998,7 +998,7 @@
;
Access = private
),
- PerInstance = per_instance,
+ PerInstance = one_copy,
Virtuality = non_virtual,
Finality = overridable,
Constness = modifiable,
@@ -1058,25 +1058,40 @@
% value (rather than being passed by reference) and remove
% them from the byref_output_vars field in the ml_gen_info.
( CodeModel = model_non ->
- ml_set_up_initial_succ_cont(ModuleInfo,
- CopiedOutputVars, MLDSGenInfo0, MLDSGenInfo1)
+
+ ml_set_up_initial_succ_cont(ModuleInfo, CopiedOutputVars,
+ MLDSGenInfo0, MLDSGenInfo1)
+ ;
+
+ module_info_globals(ModuleInfo, Globals),
+ globals__lookup_bool_option(Globals, det_copy_out,
+ DetCopyOut),
+ (
+ DetCopyOut = yes
+ ->
+ % all of the output vars are returned by value
+ % rather than passed by reference
+ ml_gen_info_get_byref_output_vars(MLDSGenInfo0,
+ OutputVars),
+ CopiedOutputVars = OutputVars,
+ ml_gen_info_set_byref_output_vars([],
+ MLDSGenInfo0, MLDSGenInfo1)
;
- (
- is_output_det_function(ModuleInfo, PredId,
- ProcId, ResultVar)
- ->
+ is_output_det_function(ModuleInfo, PredId, ProcId,
+ ResultVar)
+ ->
CopiedOutputVars = [ResultVar],
ml_gen_info_get_byref_output_vars(MLDSGenInfo0,
ByRefOutputVars0),
- list__delete_all(ByRefOutputVars0,
- ResultVar, ByRefOutputVars),
+ list__delete_all(ByRefOutputVars0, ResultVar,
+ ByRefOutputVars),
ml_gen_info_set_byref_output_vars(
- ByRefOutputVars,
- MLDSGenInfo0, MLDSGenInfo1)
+ ByRefOutputVars, MLDSGenInfo0, MLDSGenInfo1)
;
CopiedOutputVars = [],
MLDSGenInfo1 = MLDSGenInfo0
)
+
),
% This would generate all the local variables at the top of
@@ -1561,7 +1576,7 @@
ml_gen_info_new_commit_label(CommitLabelNum),
{ string__format("commit_%d", [i(CommitLabelNum)],
CommitRef) },
- ml_qualify_var(CommitRef, CommitRefLval),
+ ml_gen_var_lval(CommitRef, mlds__commit_type, CommitRefLval),
{ CommitRefDecl = ml_gen_commit_var_decl(MLDS_Context,
CommitRef) },
{ DoCommitStmt = do_commit(lval(CommitRefLval)) },
@@ -1646,7 +1661,7 @@
ml_gen_info_new_commit_label(CommitLabelNum),
{ string__format("commit_%d", [i(CommitLabelNum)],
CommitRef) },
- ml_qualify_var(CommitRef, CommitRefLval),
+ ml_gen_var_lval(CommitRef, mlds__commit_type, CommitRefLval),
{ CommitRefDecl = ml_gen_commit_var_decl(MLDS_Context,
CommitRef) },
{ DoCommitStmt = do_commit(lval(CommitRefLval)) },
@@ -1679,7 +1694,6 @@
[TryCommitStatement], Context,
CommitFuncDecls, MLDS_Statements),
{ MLDS_Decls = LocalVarDecls ++ CommitFuncDecls },
-
ml_gen_info_set_var_lvals(OrigVarLvalMap)
;
% no commit required
@@ -1836,21 +1850,22 @@
%
=(MLDSGenInfo),
{ ml_gen_info_get_varset(MLDSGenInfo, VarSet) },
- { ml_gen_info_get_module_info(MLDSGenInfo, ModuleInfo) },
+ { ml_gen_info_get_module_info(MLDSGenInfo, _ModuleInfo) },
{ OutputVarName = ml_gen_var_name(VarSet, OutputVar) },
%
% Generate a declaration for a corresponding local variable.
- %
+ % XXX LocalVarDefn contained ModuleInfo as 4th argument
{ string__append("local_", OutputVarName, LocalVarName) },
- { LocalVarDefn = ml_gen_var_decl(LocalVarName, Type,
- mlds__make_context(Context), ModuleInfo) },
-
+ ml_gen_type(Type, MLDS_Type),
+ { LocalVarDefn = ml_gen_mlds_var_decl(var(LocalVarName), MLDS_Type,
+ mlds__make_context(Context)) },
+
%
% Generate code to assign from the local var to the output var
%
ml_gen_var(OutputVar, OutputVarLval),
- ml_qualify_var(LocalVarName, LocalVarLval),
+ ml_gen_var_lval(LocalVarName, MLDS_Type, LocalVarLval),
{ Assign = ml_gen_assign(OutputVarLval, lval(LocalVarLval), Context) },
%
Index: ml_code_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_code_util.m,v
retrieving revision 1.32
diff -u -r1.32 ml_code_util.m
--- ml_code_util.m 2000/12/10 07:39:39 1.32
+++ ml_code_util.m 2001/01/23 05:53:34
@@ -220,12 +220,11 @@
%
:- func ml_gen_var_name(prog_varset, prog_var) = mlds__var_name.
- % Qualify the name of the specified variable
- % with the current module name.
+ % Generate an lval from the variable name and type
%
-:- pred ml_qualify_var(mlds__var_name, mlds__lval,
+:- pred ml_gen_var_lval(mlds__var_name, mlds__type, mlds__lval,
ml_gen_info, ml_gen_info).
-:- mode ml_qualify_var(in, out, in, out) is det.
+:- mode ml_gen_var_lval(in, in, out, in, out) is det.
% Generate a declaration for an MLDS variable, given its HLDS type.
%
@@ -243,6 +242,12 @@
:- func ml_gen_mlds_var_decl(mlds__data_name, mlds__type, mlds__initializer,
mlds__context) = mlds__defn.
+
+ % Generate declaration flags for a local variable
+ %
+ %
+:- func ml_gen_var_decl_flags = mlds__decl_flags.
+
%-----------------------------------------------------------------------------%
%
% Routines for dealing with static constants
@@ -563,13 +568,15 @@
% Set the `const' sequence number
% corresponding to a given HLDS variable.
%
-:- pred ml_gen_info_set_const_num(prog_var, const_seq, ml_gen_info, ml_gen_info).
+:- pred ml_gen_info_set_const_num(prog_var, const_seq,
+ ml_gen_info, ml_gen_info).
:- mode ml_gen_info_set_const_num(in, in, in, out) is det.
% Lookup the `const' sequence number
% corresponding to a given HLDS variable.
%
-:- pred ml_gen_info_lookup_const_num(prog_var, const_seq, ml_gen_info, ml_gen_info).
+:- pred ml_gen_info_lookup_const_num(prog_var, const_seq,
+ ml_gen_info, ml_gen_info).
:- mode ml_gen_info_lookup_const_num(in, out, in, out) is det.
%
@@ -890,7 +897,8 @@
%
:- func ml_gen_label_func_decl_flags = mlds__decl_flags.
ml_gen_label_func_decl_flags = MLDS_DeclFlags :-
- Access = private,
+ Access = private, % XXX if we're using nested functions,
+ % this should be `local' rather than `private'
PerInstance = per_instance,
Virtuality = non_virtual,
Finality = overridable,
@@ -1277,18 +1285,23 @@
%
{ mercury_private_builtin_module(PrivateBuiltin) },
{ MLDS_Module = mercury_module_name_to_mlds(PrivateBuiltin) },
- { Lval = var(qual(MLDS_Module, "dummy_var")) }
+ %
+ % XXX Change for Java Backend
+ %
+ ml_gen_type(Type, MLDS_Type),
+ { Lval = var(qual(MLDS_Module, "dummy_var"), MLDS_Type) }
;
=(MLDSGenInfo),
{ ml_gen_info_get_varset(MLDSGenInfo, VarSet) },
{ VarName = ml_gen_var_name(VarSet, Var) },
- ml_qualify_var(VarName, VarLval),
+ ml_gen_type(Type, MLDS_Type),
+ ml_gen_var_lval(VarName, MLDS_Type, VarLval),
%
% output variables may be passed by reference...
%
{ ml_gen_info_get_byref_output_vars(MLDSGenInfo, OutputVars) },
( { list__member(Var, OutputVars) } ->
- ml_gen_type(Type, MLDS_Type),
+ %ml_gen_type(Type, MLDS_Type),
{ Lval = mem_ref(lval(VarLval), MLDS_Type) }
;
{ Lval = VarLval }
@@ -1338,11 +1351,14 @@
% Qualify the name of the specified variable
% with the current module name.
%
-ml_qualify_var(VarName, QualifiedVarLval) -->
+ml_gen_var_lval(VarName, VarType, QualifiedVarLval) -->
=(MLDSGenInfo),
{ ml_gen_info_get_module_name(MLDSGenInfo, ModuleName) },
{ MLDS_Module = mercury_module_name_to_mlds(ModuleName) },
- { QualifiedVarLval = var(qual(MLDS_Module, VarName)) }.
+ %
+ % XXX Change for java backend
+ %
+ { QualifiedVarLval = var(qual(MLDS_Module, VarName), VarType) }.
% Generate a declaration for an MLDS variable, given its HLDS type.
%
@@ -1377,10 +1393,10 @@
MLDS_Defn = mlds__defn(Name, MLDS_Context, DeclFlags, Defn).
% Return the declaration flags appropriate for a local variable.
- %
-:- func ml_gen_var_decl_flags = mlds__decl_flags.
+ % Java backend needs this
+% :- func ml_gen_var_decl_flags = mlds__decl_flags.
ml_gen_var_decl_flags = MLDS_DeclFlags :-
- Access = public,
+ Access = local,
PerInstance = per_instance,
Virtuality = non_virtual,
Finality = overridable,
@@ -1393,10 +1409,10 @@
% initialized local static constant.
%
ml_static_const_decl_flags = MLDS_DeclFlags :-
- Access = private,
+ Access = local,
PerInstance = one_copy,
Virtuality = non_virtual,
- Finality = overridable,
+ Finality = final,
Constness = const,
Abstractness = concrete,
MLDS_DeclFlags = init_decl_flags(Access, PerInstance,
@@ -1497,9 +1513,8 @@
% Return the lval for the `succeeded' flag.
% (`succeeded' is a boolean variable used to record
% the success or failure of model_semi procedures.)
- %
ml_success_lval(SucceededLval) -->
- ml_qualify_var("succeeded", SucceededLval).
+ ml_gen_var_lval("succeeded", mlds__native_bool_type, SucceededLval).
% Return an rval which will test the value of the `succeeded' flag.
% (`succeeded' is a boolean variable used to record
@@ -1529,7 +1544,8 @@
mlds__native_bool_type, Context).
ml_cond_var_lval(CondVar, CondVarLval) -->
- ml_qualify_var(ml_gen_cond_var_name(CondVar), CondVarLval).
+ ml_gen_var_lval(ml_gen_cond_var_name(CondVar), mlds__native_bool_type,
+ CondVarLval).
ml_gen_test_cond_var(CondVar, CondVarRval) -->
ml_cond_var_lval(CondVar, CondVarLval),
@@ -1542,8 +1558,13 @@
%-----------------------------------------------------------------------------%
ml_initial_cont(OutputVarLvals0, OutputVarTypes0, Cont) -->
- ml_qualify_var("cont", ContLval),
- ml_qualify_var("cont_env_ptr", ContEnvLval),
+ %
+ % XXX mlds__cont_type([]) is wrong here;
+ % the [] should be the return types if --nondet-copy-out is enabled
+ %
+ ml_gen_var_lval("cont", mlds__cont_type([]), ContLval),
+ ml_gen_var_lval("cont_env_ptr", mlds__generic_env_ptr_type,
+ ContEnvLval),
{ ml_skip_dummy_argument_types(OutputVarTypes0, OutputVarLvals0,
OutputVarTypes, OutputVarLvals) },
list__map_foldl(ml_gen_type, OutputVarTypes, MLDS_OutputVarTypes),
@@ -1638,8 +1659,13 @@
ml_gen_cont_params(ArgTypes0, InnerFuncParams0),
{ InnerFuncParams0 = func_params(InnerArgs0, Rets) },
{ InnerArgRvals = list__map(
- (func(Data - _Type)
- = lval(var(qual(MLDS_Module, VarName))) :-
+ %
+ % XXX Used to be (func(Data - _Type)
+ (func(Data - Type)
+ %
+ % XXX Change for java backend
+ %
+ = lval(var(qual(MLDS_Module, VarName), Type)) :-
( Data = data(var(VarName0)) ->
VarName = VarName0
;
@@ -1648,7 +1674,12 @@
),
InnerArgs0) },
{ InnerFuncArgType = mlds__cont_type(ArgTypes0) },
- { InnerFuncRval = lval(var(qual(MLDS_Module, "passed_cont"))) },
+ %
+ % XXX Changed for java backend
+ % Added InnerFuncArgType to lval(var(qual( .... etc
+ %
+ %
+ { InnerFuncRval = lval(var(qual(MLDS_Module, "passed_cont"), InnerFuncArgType)) },
{ InnerFuncParams = func_params(
[data(var("passed_cont")) - InnerFuncArgType | InnerArgs0],
Rets) },
@@ -1696,7 +1727,15 @@
% The ml_elim_nested pass will insert the declaration
% of the env_ptr variable.
ml_get_env_ptr(lval(EnvPtrLval)) -->
- ml_qualify_var("env_ptr", EnvPtrLval).
+ %
+ % XXX JAVA
+ % XXX Using the type `mlds__generic_env_ptr_type' here is wrong.
+ % We should really use the type that the env_ptr variable
+ % was declared with. But that type hasn't been generated yet,
+ % and it won't be generated until the ml_elim_nested pass.
+ % So getting this right is hard.
+ %
+ ml_gen_var_lval("env_ptr", mlds__generic_env_ptr_type, EnvPtrLval).
% Return an rval for a pointer to the current environment
% (the set of local variables in the containing procedure).
Index: ml_elim_nested.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_elim_nested.m,v
retrieving revision 1.20
diff -u -r1.20 ml_elim_nested.m
--- ml_elim_nested.m 2000/12/21 03:10:10 1.20
+++ ml_elim_nested.m 2001/01/23 05:53:34
@@ -329,10 +329,11 @@
FieldName = named_field(qual(EnvModuleName, VarName),
EnvPtrTypeName),
Tag = yes(0),
- EnvPtr = lval(var(qual(ModuleName, "env_ptr"))),
+ EnvPtr = lval(var(qual(ModuleName, "env_ptr"),
+ EnvPtrTypeName)),
EnvArgLval = field(Tag, EnvPtr, FieldName, FieldType,
EnvPtrTypeName),
- ArgRval = lval(var(QualVarName)),
+ ArgRval = lval(var(QualVarName, FieldType)),
AssignToEnv = assign(EnvArgLval, ArgRval),
CodeToCopyArg = mlds__statement(atomic(AssignToEnv), Context),
@@ -400,19 +401,27 @@
% generated needs to be a little different.
% XXX Perhaps if we used value classes this could go
% away.
+ % XXX JAVA we probably need to do the same for Java
+ % that we do for IL
( Target = il ->
- EnvVarAddr = lval(var(EnvVar)),
+ EnvVarAddr = lval(var(EnvVar, EnvTypeName)),
ml_init_env(EnvTypeName, EnvVarAddr, Context, ModuleName,
Globals, EnvPtrVarDecl, InitEnv0),
+
+ %
+ % XXX changed the CtorType to no
+ %
+
NewObj = mlds__statement(
- atomic(new_object(var(EnvVar),
- no, EnvTypeName, no, yes(""), [], [])),
+ atomic(new_object(
+ var(EnvVar, EnvTypeName),
+ no, EnvTypeName, no, no, [], [])),
Context),
InitEnv = mlds__statement(block([],
[NewObj, InitEnv0]), Context),
EnvDecls = [EnvVarDecl, EnvPtrVarDecl]
;
- EnvVarAddr = mem_addr(var(EnvVar)),
+ EnvVarAddr = mem_addr(var(EnvVar, EnvTypeName)),
ml_init_env(EnvTypeName, EnvVarAddr, Context, ModuleName,
Globals, EnvPtrVarDecl, InitEnv),
EnvDecls = [EnvVarDecl, EnvPtrVarDecl]
@@ -447,7 +456,8 @@
DefnBody0 = mlds__function(PredProcId, Params, yes(FuncBody0)),
statement_contains_var(FuncBody0, qual(ModuleName, "env_ptr"))
->
- EnvPtrVal = lval(var(qual(ModuleName, "env_ptr_arg"))),
+ EnvPtrVal = lval(var(qual(ModuleName, "env_ptr_arg"),
+ mlds__generic_env_ptr_type)),
ml_init_env(TypeName, EnvPtrVal, Context, ModuleName, Globals,
EnvPtrDecl, InitEnvPtr),
FuncBody = mlds__statement(block([EnvPtrDecl],
@@ -498,9 +508,11 @@
%
% env_ptr = (EnvPtrVarType) <EnvPtrVal>;
%
+ % XXX Do we need the cast? If so, why?
+ %
EnvPtrVar = qual(ModuleName, "env_ptr"),
- AssignEnvPtr = assign(var(EnvPtrVar), unop(cast(EnvPtrVarType),
- EnvPtrVal)),
+ AssignEnvPtr = assign(var(EnvPtrVar, EnvPtrVarType),
+ unop(cast(EnvPtrVarType), EnvPtrVal)),
InitEnvPtr = mlds__statement(atomic(AssignEnvPtr), Context).
% Given the declaration for a function parameter, produce a
@@ -986,8 +998,8 @@
fixup_rval(Rval0, Rval).
fixup_lval(mem_ref(Rval0, Type), mem_ref(Rval, Type)) -->
fixup_rval(Rval0, Rval).
-fixup_lval(var(Var0), VarLval) -->
- fixup_var(Var0, VarLval).
+fixup_lval(var(Var0, VarType), VarLval) -->
+ fixup_var(Var0, VarType, VarLval).
%-----------------------------------------------------------------------------%
@@ -997,10 +1009,10 @@
% containing function to go via the environment pointer
%
-:- pred fixup_var(mlds__var, mlds__lval, elim_info, elim_info).
-:- mode fixup_var(in, out, in, out) is det.
+:- pred fixup_var(mlds__var, mlds__type, mlds__lval, elim_info, elim_info).
+:- mode fixup_var(in, in, out, in, out) is det.
-fixup_var(ThisVar, Lval, ElimInfo, ElimInfo) :-
+fixup_var(ThisVar, ThisVarType, Lval, ElimInfo, ElimInfo) :-
ThisVar = qual(ThisVarModuleName, ThisVarName),
ModuleName = elim_info_get_module_name(ElimInfo),
Locals = elim_info_get_local_data(ElimInfo),
@@ -1021,7 +1033,8 @@
),
solutions(IsLocalVar, [FieldType])
->
- EnvPtr = lval(var(qual(ModuleName, "env_ptr"))),
+ EnvPtr = lval(var(qual(ModuleName, "env_ptr"),
+ EnvPtrVarType)),
EnvModuleName = ml_env_module_name(ClassType),
FieldName = named_field(qual(EnvModuleName, ThisVarName),
EnvPtrVarType),
@@ -1031,7 +1044,7 @@
%
% leave everything else unchanged
%
- Lval = var(ThisVar)
+ Lval = var(ThisVar, ThisVarType)
).
/*****************************
The following code is what we would have to use if we couldn't
@@ -1069,7 +1082,7 @@
%
% leave everything else unchanged
%
- Lval = var(ThisVar)
+ Lval = var(ThisVar, ThisVarType)
).
% check if the specified variable is contained in the
@@ -1490,7 +1503,7 @@
rval_contains_var(Rval, Name).
lval_contains_var(mem_ref(Rval, _Type), Name) :-
rval_contains_var(Rval, Name).
-lval_contains_var(var(Name), Name). /* this is where we can succeed! */
+lval_contains_var(var(Name, _VarType), Name). % this is where we can succeed!
%-----------------------------------------------------------------------------%
Index: ml_optimize.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_optimize.m,v
retrieving revision 1.4
diff -u -r1.4 ml_optimize.m
--- ml_optimize.m 2000/11/21 13:37:43 1.4
+++ ml_optimize.m 2001/01/23 05:53:34
@@ -238,7 +238,7 @@
%
% don't bother assigning a variable to itself
%
- Arg = lval(var(QualVarName))
+ Arg = lval(var(QualVarName, _VarType))
->
generate_assign_args(OptInfo, Rest, Args,
Statements, TempDefns)
@@ -268,8 +268,8 @@
Statement = statement(
atomic(assign(
- var(QualVarName),
- lval(var(QualTempName)))),
+ var(QualVarName, Type),
+ lval(var(QualTempName, Type)))),
OptInfo ^ context),
generate_assign_args(OptInfo, Rest, Args, Statements0,
TempDefns0),
Index: ml_string_switch.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_string_switch.m,v
retrieving revision 1.4
diff -u -r1.4 ml_string_switch.m
--- ml_string_switch.m 2000/11/23 04:32:44 1.4
+++ ml_string_switch.m 2001/01/23 05:53:34
@@ -57,13 +57,13 @@
{ SlotVarName = string__format("slot_%d", [i(SlotVarSeq)]) },
{ SlotVarDefn = ml_gen_mlds_var_decl(var(SlotVarName),
mlds__native_int_type, MLDS_Context) },
- ml_qualify_var(SlotVarName, SlotVarLval),
+ ml_gen_var_lval(SlotVarName, mlds__native_int_type, SlotVarLval),
ml_gen_info_new_cond_var(StringVarSeq),
{ StringVarName = string__format("str_%d", [i(StringVarSeq)]) },
{ StringVarDefn = ml_gen_mlds_var_decl(var(StringVarName),
ml_string_type, MLDS_Context) },
- ml_qualify_var(StringVarName, StringVarLval),
+ ml_gen_var_lval(StringVarName, ml_string_type, StringVarLval),
%
% Generate new labels
@@ -114,7 +114,7 @@
{ NextSlotsDefn = ml_gen_static_const_defn(NextSlotsName,
NextSlotsType,
init_array(NextSlots), Context) },
- ml_qualify_var(NextSlotsName, NextSlotsLval),
+ ml_gen_var_lval(NextSlotsName, NextSlotsType, NextSlotsLval),
ml_gen_info_new_const(StringTableSeq),
ml_format_static_const_name("string_table", StringTableSeq,
@@ -122,7 +122,7 @@
{ StringTableType = mlds__array_type(ml_string_type) },
{ StringTableDefn = ml_gen_static_const_defn(StringTableName,
StringTableType, init_array(Strings), Context) },
- ml_qualify_var(StringTableName, StringTableLval),
+ ml_gen_var_lval(StringTableName, StringTableType ,StringTableLval),
%
% Generate code which does the hash table lookup.
Index: ml_tailcall.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_tailcall.m,v
retrieving revision 1.5
diff -u -r1.5 ml_tailcall.m
--- ml_tailcall.m 2000/11/21 13:37:44 1.5
+++ ml_tailcall.m 2001/01/23 05:53:34
@@ -355,7 +355,7 @@
:- pred lval_is_local(mlds__lval).
:- mode lval_is_local(in) is semidet.
-lval_is_local(var(_)) :-
+lval_is_local(var(_, _)) :-
% We just assume it is local. (This assumption is
% true for the code generated by ml_code_gen.m.)
true.
@@ -430,7 +430,7 @@
% ever passed down to other functions, or assigned to,
% so a mem_ref lval can never refer to a local variable.
true.
-check_lval(var(Var0), Locals) :-
+check_lval(var(Var0, _), Locals) :-
\+ var_is_local(Var0, Locals).
%
Index: ml_type_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_type_gen.m,v
retrieving revision 1.4
diff -u -r1.4 ml_type_gen.m
--- ml_type_gen.m 2000/06/06 07:32:28 1.4
+++ ml_type_gen.m 2001/01/23 05:53:34
@@ -36,6 +36,14 @@
:- pred ml_gen_type_name(type_id, mlds__class, arity).
:- mode ml_gen_type_name(in, out, out) is det.
+ % The Java backend needs to use these to do some transformations
+ % on the MLDS
+ %
+:- func ml_gen_type_decl_flags = mlds__decl_flags.
+:- func ml_gen_special_member_decl_flags = mlds__decl_flags.
+:- func ml_gen_enum_constant_decl_flags = mlds__decl_flags.
+:- func ml_gen_member_decl_flags = mlds__decl_flags.
+
%-----------------------------------------------------------------------------%
:- implementation.
@@ -99,8 +107,8 @@
% For each enumeration, we generate an MLDS type of the following form:
%
% struct <ClassName> {
- % static const int <ctor1> = 0;
- % static const int <ctor2> = 1;
+ % static final const int <ctor1> = 0;
+ % static final const int <ctor2> = 1;
% ...
% int value;
% };
@@ -186,11 +194,11 @@
% For each discriminated union type, we generate an MLDS type of the
% following form:
%
- % class <ClassName> {
+ % static class <ClassName> {
% public:
% #if some_but_not_all_ctors_use_secondary_tag
% /* A nested derived class for the secondary tag */
- % class tag_type : public <ClassName> {
+ % static class tag_type : public <ClassName> {
% public:
% #endif
% #if some_ctors_use_secondary_tag
@@ -221,7 +229,7 @@
% ** secondary tag, we put the secondary tag members
% ** directly in the base class.
% */
- % class <ctor1> : public <ClassName> {
+ % static class <ctor1> : public <ClassName> {
% public:
% /*
% ** fields, one for each argument of this
@@ -231,7 +239,7 @@
% MR_Word F2;
% ...
% };
- % class <ctor2> : public <ClassName>::tag_type {
+ % static class <ctor2> : public <ClassName>::tag_type {
% public:
% ...
% };
@@ -526,6 +534,7 @@
MLDS_Type = mercury_type_to_mlds_type(ModuleInfo, Type)
),
FieldName = ml_gen_field_name(MaybeFieldName, ArgNum0),
+ % XXX this gets the access flag wrong
MLDS_Defn = ml_gen_mlds_var_decl(var(FieldName), MLDS_Type,
mlds__make_context(Context)),
ArgNum = ArgNum0 + 1.
@@ -560,11 +569,11 @@
%
% Return the declaration flags appropriate for a type.
-:- func ml_gen_type_decl_flags = mlds__decl_flags.
+% :- func ml_gen_type_decl_flags = mlds__decl_flags.
ml_gen_type_decl_flags = MLDS_DeclFlags :-
% XXX are these right?
Access = public,
- PerInstance = per_instance,
+ PerInstance = one_copy,
Virtuality = non_virtual,
Finality = overridable,
Constness = modifiable,
@@ -573,7 +582,6 @@
Virtuality, Finality, Constness, Abstractness).
% Return the declaration flags appropriate for a member variable.
-:- func ml_gen_member_decl_flags = mlds__decl_flags.
ml_gen_member_decl_flags = MLDS_DeclFlags :-
Access = public,
PerInstance = per_instance,
@@ -585,13 +593,21 @@
Virtuality, Finality, Constness, Abstractness).
% Return the declaration flags appropriate for an enumeration constant.
-:- func ml_gen_enum_constant_decl_flags = mlds__decl_flags.
ml_gen_enum_constant_decl_flags = MLDS_DeclFlags :-
Access = public,
PerInstance = one_copy,
+ Virtuality = non_virtual,
+ Finality = final,
+ Constness = const,
+ Abstractness = concrete,
+ MLDS_DeclFlags = init_decl_flags(Access, PerInstance,
+ Virtuality, Finality, Constness, Abstractness).
+
+ml_gen_special_member_decl_flags = MLDS_DeclFlags :-
+ Access = public,
+ PerInstance = per_instance,
Virtuality = non_virtual,
- Finality = overridable, % XXX should we use `final' instead?
- % does it make any difference?
+ Finality = final,
Constness = const,
Abstractness = concrete,
MLDS_DeclFlags = init_decl_flags(Access, PerInstance,
Index: ml_unify_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_unify_gen.m,v
retrieving revision 1.26
diff -u -r1.26 ml_unify_gen.m
--- ml_unify_gen.m 2000/12/14 11:48:42 1.26
+++ ml_unify_gen.m 2001/01/23 05:53:34
@@ -299,8 +299,9 @@
% If this argument is something that would normally be allocated
% on the heap, just generate a reference to the static constant
% that we must have already generated for it.
- %
- ml_gen_static_const_addr(Var, ConstAddrRval),
+ % XXX Not sure that it should by VarType
+ ml_gen_type(VarType, MLDS_Type),
+ ml_gen_static_const_addr(Var, MLDS_Type, ConstAddrRval),
{ TagVal = 0 ->
TaggedRval = ConstAddrRval
;
@@ -460,7 +461,8 @@
% the pointer will not be tagged (i.e. the tag will be zero)
%
{ Tag = 0 },
- { CtorName = "<closure>" },
+ { CtorDefn = ctor_id("<closure>", 0) },
+ { QualifiedCtorId = qual(MLDS_PrivateBuiltinModule, CtorDefn) },
%
% put all the extra arguments of the closure together
@@ -472,9 +474,9 @@
% generate a `new_object' statement (or static constant)
% for the closure
%
- ml_gen_new_object(no, Tag, CtorName, Var, ExtraArgRvals, ExtraArgTypes,
- ArgVars, ArgModes, HowToConstruct, Context,
- MLDS_Decls, MLDS_Statements).
+ ml_gen_new_object(no, Tag, QualifiedCtorId, Var, ExtraArgRvals,
+ ExtraArgTypes, ArgVars, ArgModes, HowToConstruct, Context,
+ MLDS_Decls, MLDS_Statements).
%
% ml_gen_closure_wrapper:
@@ -606,7 +608,8 @@
WrapperBoxedArgTypes, WrapperArgModes, PredOrFunc, CodeModel) },
% then insert the `closure_arg' parameter
- { ClosureArg = data(var("closure_arg")) - mlds__generic_type },
+ { ClosureArgType = mlds__generic_type },
+ { ClosureArg = data(var("closure_arg")) - ClosureArgType },
{ WrapperParams0 = mlds__func_params(WrapperArgs0, WrapperRetType) },
{ WrapperParams = mlds__func_params([ClosureArg | WrapperArgs0],
WrapperRetType) },
@@ -633,10 +636,11 @@
{ ClosureName = "closure" },
{ ClosureArgName = "closure_arg" },
{ MLDS_Context = mlds__make_context(Context) },
+ { ClosureType = mlds__generic_type },
{ ClosureDecl = ml_gen_mlds_var_decl(var(ClosureName),
- mlds__generic_type, MLDS_Context) },
- ml_qualify_var(ClosureName, ClosureLval),
- ml_qualify_var(ClosureArgName, ClosureArgLval),
+ ClosureType, MLDS_Context) },
+ ml_gen_var_lval(ClosureName, ClosureType, ClosureLval),
+ ml_gen_var_lval(ClosureArgName, ClosureArgType, ClosureArgLval),
{ InitClosure = ml_gen_assign(ClosureLval, lval(ClosureArgLval),
Context) },
@@ -774,7 +778,8 @@
ml_gen_wrapper_arg_lvals(Names1, Types1, Modes1,
PredOrFunc, CodeModel, Context,
Defns1, Lvals1, CopyOutLvals1),
- ml_qualify_var(Name, VarLval),
+ ml_gen_type(Type, MLDS_Type),
+ ml_gen_var_lval(Name, MLDS_Type, VarLval),
=(Info),
{ ml_gen_info_get_module_info(Info, ModuleInfo) },
{ mode_to_arg_mode(ModuleInfo, Mode, Type, ArgMode) },
@@ -824,7 +829,6 @@
% output arguments are passed by reference,
% so we need to dereference them
%
- ml_gen_type(Type, MLDS_Type),
{ Lval = mem_ref(lval(VarLval), MLDS_Type) },
{ CopyOutLvals = CopyOutLvals1 },
{ Defns = Defns1 }
@@ -1016,7 +1020,7 @@
% Assign the address of the local static constant to
% the variable.
%
- ml_gen_static_const_addr(Var, ConstAddrRval),
+ ml_gen_static_const_addr(Var, MLDS_Type, ConstAddrRval),
{ MaybeTag = no ->
TaggedRval = ConstAddrRval
;
@@ -1137,7 +1141,7 @@
% Return as the boxed rval the address of that constant,
% cast to mlds__generic_type
%
- ml_qualify_var(ConstName, ConstLval),
+ ml_gen_var_lval(ConstName, Type, ConstLval),
{ ConstAddrRval = mem_addr(ConstLval) },
{ BoxedRval = unop(cast(mlds__generic_type), ConstAddrRval) }
;
@@ -1186,19 +1190,26 @@
% Generate an rval containing the address of the local static constant
% for a given variable.
%
-:- pred ml_gen_static_const_addr(prog_var, mlds__rval,
+:- pred ml_gen_static_const_addr(prog_var, mlds__type, mlds__rval,
ml_gen_info, ml_gen_info).
-:- mode ml_gen_static_const_addr(in, out, in, out) is det.
-ml_gen_static_const_addr(Var, ConstAddrRval) -->
+:- mode ml_gen_static_const_addr(in, in, out, in, out) is det.
+ml_gen_static_const_addr(Var, Type, ConstAddrRval) -->
ml_lookup_static_const_name(Var, ConstName),
- ml_qualify_var(ConstName, ConstLval),
+ ml_gen_var_lval(ConstName, Type, ConstLval),
{ ConstAddrRval = mem_addr(ConstLval) }.
:- pred ml_cons_name(cons_id, ctor_name, ml_gen_info, ml_gen_info).
:- mode ml_cons_name(in, out, in, out) is det.
-ml_cons_name(ConsId, ConsName) -->
- { hlds_out__cons_id_to_string(ConsId, ConsName) }.
+ml_cons_name(HLDS_ConsId, QualifiedConsId) -->
+ ( { HLDS_ConsId = cons(SymName, Arity),
+ SymName = qualified(SymModuleName, ConsName) } ->
+ { ConsId = ctor_id(ConsName, Arity) },
+ { ModuleName = mercury_module_name_to_mlds(SymModuleName) },
+ { QualifiedConsId = qual(ModuleName, ConsId) }
+ ;
+ { error("mlds_unify_gen.m: not a constructor id") }
+ ).
% Return an rval for the `SIZEOF_WORD' constant.
% This constant is supposed to be defined by the Mercury library.
@@ -1210,7 +1221,8 @@
ml_sizeof_word_rval = SizeofWordRval :-
mercury_private_builtin_module(PrivateBuiltin),
MLDS_Module = mercury_module_name_to_mlds(PrivateBuiltin),
- SizeofWordRval = lval(var(qual(MLDS_Module, "SIZEOF_WORD"))).
+ SizeofWordRval = lval(var(qual(MLDS_Module, "SIZEOF_WORD"),
+ mlds__native_int_type)).
:- pred ml_gen_cons_args(list(mlds__lval), list(prog_type),
list(uni_mode), module_info, list(mlds__rval)).
Index: ml_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_util.m,v
retrieving revision 1.5
diff -u -r1.5 ml_util.m
--- ml_util.m 2001/01/11 14:25:39 1.5
+++ ml_util.m 2001/01/23 05:53:34
@@ -68,8 +68,17 @@
:- pred defn_is_public(mlds__defn).
:- mode defn_is_public(in) is semidet.
-%-----------------------------------------------------------------------------%
+ % Succeeds iff this definition is a function definition which
+ % defines a special_pred
+:- pred defn_is_special_pred(mlds__defn).
+:- mode defn_is_special_pred(in) is semidet.
+
+ % Succeeds iff this definition is a data definition which
+ % defines RTTI
+:- pred defn_is_rtti(mlds__defn).
+:- mode defn_is_rtti(in) is semidet.
+%-----------------------------------------------------------------------------%
:- implementation.
:- import_module rtti.
@@ -224,4 +233,13 @@
Defn = mlds__defn(_Name, _Context, Flags, _Body),
access(Flags) \= private.
+defn_is_special_pred(Defn) :-
+ Defn = mlds__defn(Name, _Context, _Flags, _Body),
+ Name = function(Label, _ProcID, _MaybeSeqNum, _PredID),
+ Label = special_pred(_, _, _, _).
+
+defn_is_rtti(Defn) :-
+ Defn = mlds__defn(_Name, _Context, _Flags, Body),
+ Body = mlds__data(Type, _),
+ Type = mlds__rtti_type(_).
%-----------------------------------------------------------------------------%
Index: mlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds.m,v
retrieving revision 1.45
diff -u -r1.45 mlds.m
--- mlds.m 2001/01/17 17:37:17 1.45
+++ mlds.m 2001/01/23 05:53:34
@@ -565,11 +565,17 @@
:- type mlds__decl_flags.
:- type access
- ---> public
- ; protected
- ; private
- ; default. % Java "default" access: accessible to anything
+ ---> public % accessible to anyone
+ ; protected % only accessible to the class and to
+ % derived classes
+ ; private % only accessible to the class
+ ; default % Java "default" access: accessible to anything
% defined in the same package.
+ ; local % use for local variables:
+ % only accessible within the function
+ % (or block) in which the variable is
+ % defined
+ .
:- type per_instance
---> one_copy % i.e. "static" storage duration
@@ -1052,8 +1058,12 @@
; name(mlds__qualified_entity_name)
.
- % XXX I'm not sure what representation we should use here
-:- type ctor_name == string.
+ % constructor id
+ % this is the version used in the java backend
+:- type ctor_name == mlds__qualified_ctor_id.
+:- type mlds__ctor_id ---> ctor_id(mlds__class_name, arity).
+:- type mlds__qualified_ctor_id ==
+ mlds__fully_qualified_name(mlds__ctor_id).
%
% trail management
@@ -1152,8 +1162,7 @@
% variables
% these may be local or they may come from some enclosing scope
% the variable name should be fully qualified
- %
- ; var(mlds__var)
+ ; var(mlds__var, mlds__type)
.
@@ -1425,6 +1434,7 @@
access_bits(private) = 0x01.
access_bits(protected) = 0x02.
access_bits(default) = 0x03.
+access_bits(local) = 0x04.
% 0x4 - 0x7 reserved
:- func access_mask = int.
Index: mlds_to_c.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_c.m,v
retrieving revision 1.77
diff -u -r1.77 mlds_to_c.m
--- mlds_to_c.m 2001/01/17 17:37:17 1.77
+++ mlds_to_c.m 2001/01/23 05:53:34
@@ -1756,6 +1756,7 @@
mlds_output_access_comment_2(private) --> io__write_string("/* private: */ ").
mlds_output_access_comment_2(protected) --> io__write_string("/* protected: */ ").
mlds_output_access_comment_2(default) --> io__write_string("/* default access */ ").
+mlds_output_access_comment_2(local) --> [].
:- pred mlds_output_per_instance_comment(per_instance, io__state, io__state).
:- mode mlds_output_per_instance_comment(in, di, uo) is det.
@@ -2260,8 +2261,10 @@
io__write_string(", """),
mlds_output_fully_qualified_name(FuncName),
io__write_string(""", "),
- ( { MaybeCtorName = yes(CtorName) } ->
+ ( { MaybeCtorName = yes(CtorId) } ->
io__write_char('"'),
+ { CtorId = qual(_ModuleName, CtorDefn) },
+ { CtorDefn = ctor_id(CtorName, _CtorArity) },
c_util__output_quoted_string(CtorName),
io__write_char('"')
;
@@ -2410,8 +2413,10 @@
io__write_int(-1)
),
io__write_string(", "),
- ( { MaybeCtorName = yes(CtorName) } ->
+ ( { MaybeCtorName = yes(QualifiedCtorId) } ->
io__write_char('"'),
+ { QualifiedCtorId = qual(_ModuleName, CtorDefn) },
+ { CtorDefn = ctor_id(CtorName, _CtorArity) },
c_util__output_quoted_string(CtorName),
io__write_char('"')
;
@@ -2584,7 +2589,7 @@
mlds_output_lval(mem_ref(Rval, _Type)) -->
io__write_string("*"),
mlds_output_bracketed_rval(Rval).
-mlds_output_lval(var(VarName)) -->
+mlds_output_lval(var(VarName, _VarType)) -->
mlds_output_var(VarName).
:- pred mlds_output_var(mlds__var, io__state, io__state).
@@ -2606,7 +2611,7 @@
mlds_output_bracketed_lval(Lval) -->
(
% if it's just a variable name, then we don't need parentheses
- { Lval = var(_) }
+ { Lval = var(_, _) }
->
mlds_output_lval(Lval)
;
@@ -2621,7 +2626,7 @@
mlds_output_bracketed_rval(Rval) -->
(
% if it's just a variable name, then we don't need parentheses
- { Rval = lval(var(_))
+ { Rval = lval(var(_,_))
; Rval = const(code_addr_const(_))
}
->
Index: mlds_to_il.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.11
diff -u -r1.11 mlds_to_il.m
--- mlds_to_il.m 2001/01/22 04:20:31 1.11
+++ mlds_to_il.m 2001/01/23 05:53:35
@@ -520,15 +520,20 @@
Tree0, Tree) -->
(
{ Name = data(DataName) },
- { Entity = mlds__data(_MldsType, Initializer) }
+ { Entity = mlds__data(MLDSType, Initializer) }
->
( { Initializer = no_initializer } ->
{ Tree = Tree0 }
;
( { DataName = var(VarName) } ->
il_info_get_module_name(ModuleName),
+
+ %
+ % XXX We are assuming that using MLDSType
+ % below is correct.
+ %
get_load_store_lval_instrs(
- var(qual(ModuleName, VarName)),
+ var(qual(ModuleName, VarName), MLDSType),
LoadMemRefInstrs, StoreLvalInstrs),
{ NameString = VarName }
;
@@ -1143,7 +1148,7 @@
:- mode load(in, out, in, out) is det.
load(lval(Lval), Instrs, Info0, Info) :-
- ( Lval = var(Var),
+ ( Lval = var(Var, _),
mangle_mlds_var(Var, MangledVarStr),
( is_local(MangledVarStr, Info0) ->
Instrs = instr_node(ldloc(name(MangledVarStr)))
@@ -1236,7 +1241,7 @@
{ Instrs = tree__list([R1LoadInstrs, R2LoadInstrs, BinaryOpInstrs]) }.
load(mem_addr(Lval), Instrs, Info0, Info) :-
- ( Lval = var(Var),
+ ( Lval = var(Var, _VarType),
mangle_mlds_var(Var, MangledVarStr),
Info0 = Info,
( is_local(MangledVarStr, Info) ->
@@ -1272,7 +1277,7 @@
% instruction. Annoying, eh?
unexpected(this_file, "store into mem_ref").
-store(var(Var), Instrs, Info, Info) :-
+store(var(Var, _VarType), Instrs, Info, Info) :-
mangle_mlds_var(Var, MangledVarStr),
( is_local(MangledVarStr, Info) ->
Instrs = instr_node(stloc(name(MangledVarStr)))
@@ -2043,7 +2048,7 @@
il_info::in, il_info::out) is det.
rval_to_type(lval(Lval), Type, Info0, Info) :-
- ( Lval = var(Var),
+ ( Lval = var(Var, _VarType),
mangle_mlds_var(Var, MangledVarStr),
il_info_get_mlds_type(MangledVarStr, Type, Info0, Info)
; Lval = field(_, _, _, Type, _),
Index: mlds_to_ilasm.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_ilasm.m,v
retrieving revision 1.7
diff -u -r1.7 mlds_to_ilasm.m
--- mlds_to_ilasm.m 2001/01/12 03:49:25 1.7
+++ mlds_to_ilasm.m 2001/01/23 05:53:35
@@ -550,7 +550,7 @@
write_managed_cpp_lval(mem_ref(Rval, _)) -->
io__write_string("*"),
write_managed_cpp_rval(Rval).
-write_managed_cpp_lval(var(Var)) -->
+write_managed_cpp_lval(var(Var, _VarType)) -->
{ mangle_mlds_var(Var, Id) },
io__write_string(Id).
Index: options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.305
diff -u -r1.305 options.m
--- options.m 2001/01/09 04:06:43 1.305
+++ options.m 2001/01/23 05:53:35
@@ -284,6 +284,12 @@
; c_include_directory
; c_flag_to_name_object_file
; object_file_extension
+
+ ; java_compiler
+ ; java_flags
+ ; java_include_directory
+ ; java_object_file_extension
+
; max_jump_table_size
; compare_specialization
; fact_table_max_array_size
@@ -652,6 +658,12 @@
% the `mmc' script will override the
% above default with a value determined
% at configuration time
+
+ java_compiler - string("javac"),
+ java_flags - accumulating([]),
+ java_include_directory - accumulating([]),
+ java_object_file_extension - string(".class"),
+
max_jump_table_size - int(0),
compare_specialization - int(4),
% 0 indicates any size.
@@ -1019,6 +1031,7 @@
long_option("num-real-r-temps", num_real_r_temps).
long_option("num-real-f-temps", num_real_f_temps).
long_option("num-real-temps", num_real_r_temps). % obsolete
+
long_option("cc", cc).
long_option("cflags", cflags).
long_option("cflags-for-regs", cflags_for_regs).
@@ -1033,6 +1046,18 @@
long_option("c-include-directory", c_include_directory).
long_option("c-flag-to-name-object-file", c_flag_to_name_object_file).
long_option("object-file-extension", object_file_extension).
+
+long_option("java-compiler", java_compiler).
+long_option("javac", java_compiler).
+long_option("java-flags", cflags).
+ % XXX we should consider the relationship between java_debug and
+ % target_debug more carefully. Perhaps target_debug could imply
+ % Java debug if the target is Java. However for the moment they are
+ % just synonyms.
+long_option("java-debug", target_debug).
+long_option("java-include-directory", java_include_directory).
+long_option("java-object-file-extension", java_object_file_extension).
+
long_option("max-jump-table-size", max_jump_table_size).
long_option("compare-specialization", compare_specialization).
long_option("fact-table-max-array-size",fact_table_max_array_size).
Index: rtti_to_mlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/rtti_to_mlds.m,v
retrieving revision 1.11
diff -u -r1.11 rtti_to_mlds.m
--- rtti_to_mlds.m 2001/01/16 03:24:39 1.11
+++ rtti_to_mlds.m 2001/01/23 05:53:35
@@ -564,7 +564,11 @@
gen_init_builtin_const(Name) = init_obj(Rval) :-
mercury_private_builtin_module(PrivateBuiltin),
MLDS_Module = mercury_module_name_to_mlds(PrivateBuiltin),
- Rval = lval(var(qual(MLDS_Module, Name))).
+ % XXX These are actually enumeration constants.
+ % Perhaps we should be using an enumeration type here,
+ % rather than `mlds__native_int_type'.
+ Type = mlds__native_int_type,
+ Rval = lval(var(qual(MLDS_Module, Name), Type)).
%-----------------------------------------------------------------------------%
%
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list