Wiki Roadmap Timeline Tickets New Ticket Source Search Help / Guide About Trac Login

root/gen/irstate.cpp

Revision 1586:7f728c52e63c, 4.5 kB (checked in by Christian Kamm <kamm incasoftware de>, 3 years ago)

Fix several 'reaches end of function' warnings by making fatal noreturn.

The warnings also pointed out a few genuine bugs. Replace some tabs with
spaces.

Line 
1 /* DMDFE backend stubs
2  * This file contains the implementations of the backend routines.
3  * For dmdfe these do nothing but print a message saying the module
4  * has been parsed. Substitute your own behaviors for these routimes.
5  */
6
7 #include <cstdarg>
8
9 #include "gen/llvm.h"
10
11 #include "mtype.h"
12 #include "declaration.h"
13 #include "statement.h"
14
15 #include "gen/irstate.h"
16 #include "tollvm.h"
17
18 IRState* gIR = 0;
19 llvm::TargetMachine* gTargetMachine = 0;
20 const llvm::TargetData* gTargetData = 0;
21 TargetABI* gABI = 0;
22
23 //////////////////////////////////////////////////////////////////////////////////////////
24 IRScope::IRScope()
25     : builder(gIR->context())
26 {
27     begin = end = NULL;
28 }
29
30 IRScope::IRScope(llvm::BasicBlock* b, llvm::BasicBlock* e)
31     : builder(b)
32 {
33     begin = b;
34     end = e;
35 }
36
37 const IRScope& IRScope::operator=(const IRScope& rhs)
38 {
39     begin = rhs.begin;
40     end = rhs.end;
41     builder.SetInsertPoint(begin);
42     return *this;
43 }
44
45 //////////////////////////////////////////////////////////////////////////////////////////
46 IRTargetScope::IRTargetScope()
47 {
48 }
49
50 IRTargetScope::IRTargetScope(Statement* s, EnclosingHandler* enclosinghandler, llvm::BasicBlock* continueTarget, llvm::BasicBlock* breakTarget)
51 {
52     this->s = s;
53     this->enclosinghandler = enclosinghandler;
54     this->breakTarget = breakTarget;
55     this->continueTarget = continueTarget;
56 }
57
58 //////////////////////////////////////////////////////////////////////////////////////////
59 IRState::IRState(llvm::Module* m)
60     : module(m), difactory(*m)
61 {
62     interfaceInfoType = NULL;
63     mutexType = NULL;
64     moduleRefType = NULL;
65
66     dmodule = 0;
67     emitMain = false;
68     mainFunc = 0;
69     ir.state = this;
70     asmBlock = NULL;
71
72     dwarfCUs = NULL;
73     dwarfSPs = NULL;
74     dwarfGVs = NULL;
75 }
76
77 IrFunction* IRState::func()
78 {
79     assert(!functions.empty() && "Function stack is empty!");
80     return functions.back();
81 }
82
83 llvm::Function* IRState::topfunc()
84 {
85     assert(!functions.empty() && "Function stack is empty!");
86     return functions.back()->func;
87 }
88
89 TypeFunction* IRState::topfunctype()
90 {
91     assert(!functions.empty() && "Function stack is empty!");
92     return functions.back()->type;
93 }
94
95 llvm::Instruction* IRState::topallocapoint()
96 {
97     assert(!functions.empty() && "AllocaPoint stack is empty!");
98     return functions.back()->allocapoint;
99 }
100
101 IrStruct* IRState::topstruct()
102 {
103     assert(!structs.empty() && "Struct vector is empty!");
104     return structs.back();
105 }
106
107 IRScope& IRState::scope()
108 {
109     assert(!scopes.empty());
110     return scopes.back();
111 }
112
113 llvm::BasicBlock* IRState::scopebb()
114 {
115     IRScope& s = scope();
116     assert(s.begin);
117     return s.begin;
118 }
119 llvm::BasicBlock* IRState::scopeend()
120 {
121     IRScope& s = scope();
122     assert(s.end);
123     return s.end;
124 }
125 bool IRState::scopereturned()
126 {
127     //return scope().returned;
128     return !scopebb()->empty() && scopebb()->back().isTerminator();
129 }
130
131 LLCallSite IRState::CreateCallOrInvoke(LLValue* Callee, const char* Name)
132 {
133     LLSmallVector<LLValue*, 1> args;
134     return CreateCallOrInvoke(Callee, args.begin(), args.end(), Name);
135 }
136
137 LLCallSite IRState::CreateCallOrInvoke(LLValue* Callee, LLValue* Arg1, const char* Name)
138 {
139     LLSmallVector<LLValue*, 1> args;
140     args.push_back(Arg1);
141     return CreateCallOrInvoke(Callee, args.begin(), args.end(), Name);
142 }
143
144 LLCallSite IRState::CreateCallOrInvoke2(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, const char* Name)
145 {
146     LLSmallVector<LLValue*, 2> args;
147     args.push_back(Arg1);
148     args.push_back(Arg2);
149     return CreateCallOrInvoke(Callee, args.begin(), args.end(), Name);
150 }
151
152 LLCallSite IRState::CreateCallOrInvoke3(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, LLValue* Arg3, const char* Name)
153 {
154     LLSmallVector<LLValue*, 3> args;
155     args.push_back(Arg1);
156     args.push_back(Arg2);
157     args.push_back(Arg3);
158     return CreateCallOrInvoke(Callee, args.begin(), args.end(), Name);
159 }
160
161 LLCallSite IRState::CreateCallOrInvoke4(LLValue* Callee, LLValue* Arg1, LLValue* Arg2,  LLValue* Arg3, LLValue* Arg4, const char* Name)
162 {
163     LLSmallVector<LLValue*, 4> args;
164     args.push_back(Arg1);
165     args.push_back(Arg2);
166     args.push_back(Arg3);
167     args.push_back(Arg4);
168     return CreateCallOrInvoke(Callee, args.begin(), args.end(), Name);
169 }
170
171
172 //////////////////////////////////////////////////////////////////////////////////////////
173
174 IRBuilder<>* IRBuilderHelper::operator->()
175 {
176     IRBuilder<>& b = state->scope().builder;
177     assert(b.GetInsertBlock() != NULL);
178     return &b;
179 }
Note: See TracBrowser for help on using the browser.
Copyright © 2008, LDC Development Team.