00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 '''
00031 SPE用のいくつかの関数
00032 '''
00033
00034 import ctrump
00035
00036 __all__ = ['convert_type_ppe_to_spe']
00037
00038 def convert_type_ppe_to_spe(b, type, structs,
00039 struct_pending, struct_list, ppe_abi):
00040 decls = []
00041
00042 code = type.code
00043
00044 if (code == ctrump.TYPE_BUILTIN or
00045 code == ctrump.TYPE_ENUM):
00046 return type
00047
00048 if (code == ctrump.TYPE_TYPEDEF_NAME):
00049 struct_pending.append(type.defined_to)
00050 return type
00051
00052 elif (code == ctrump.TYPE_POINTER):
00053 struct_pending.append(type.pointer_to)
00054
00055 if ppe_abi.sizeof_pointer == 4:
00056 return b.uint
00057 elif ppe_abi.sizeof_pointer == 8:
00058 return b.qualified_type(b.ullong, 0, gcc_aligned=8)
00059 else:
00060 raise NotImplementedError('unknown size of pointer')
00061
00062 elif (code == ctrump.TYPE_UNION or
00063 code == ctrump.TYPE_STRUCT):
00064
00065 name = type.name
00066
00067 if name in structs:
00068 return structs[name]
00069
00070 if type.is_completed:
00071 for i in type.fields:
00072 field_type = convert_type_ppe_to_spe(b, i.type, structs, struct_pending, struct_list, ppe_abi)
00073 decls.append((field_type, i.name))
00074 if code == ctrump.TYPE_UNION:
00075 ret = b.union(name, decls)
00076 elif code == ctrump.TYPE_STRUCT:
00077 ret = b.struct(name, decls)
00078 else:
00079 if code == ctrump.TYPE_UNION:
00080 ret = b.incomplete_union(name)
00081 elif code == ctrump.TYPE_STRUCT:
00082 ret = b.incomplete_struct(name)
00083
00084
00085 structs[name] = ret
00086 struct_list.append(ret)
00087 struct_pending.append(ret)
00088
00089 return ret
00090
00091 elif (code == ctrump.TYPE_ARRAY):
00092 size = type.size
00093 array_of = convert_type_ppe_to_spe(b, type.array_of, structs, struct_pending, struct_list, ppe_abi)
00094
00095 return b.array_of(array_of, size)
00096
00097 elif (code == ctrump.TYPE_QUALIFIED):
00098 qual_flags = type.qual_flags
00099 gcc_flags = type.flags
00100 gcc_align = type.aligned
00101 unqual_type = convert_type_ppe_to_spe(b, type.unqualified_type, structs, struct_pending, struct_list, ppe_abi)
00102
00103 return b.qualified_type(unqual_type, qual_flags, gcc_aligned=gcc_align, gcc_flags=gcc_flags)
00104
00105 elif (code == ctrump.TYPE_FUNC or
00106 code == ctrump.TYPE_INCOMPLETE_ARRAY or
00107 code == ctrump.TYPE_VARLEN_ARRAY):
00108 raise NotImplementedError('convert function type')