blob: b30632de041aef23ff290424d406c6a834579d95 [file] [log] [blame]
Nicolas Capens0bac2852016-05-07 06:09:58 -04001// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
John Bauman66b8ab22014-05-06 15:57:45 -04002//
Nicolas Capens0bac2852016-05-07 06:09:58 -04003// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
John Bauman66b8ab22014-05-06 15:57:45 -04006//
Nicolas Capens0bac2852016-05-07 06:09:58 -04007// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
John Bauman66b8ab22014-05-06 15:57:45 -040014
15// debug.cpp: Debugging utilities.
16
Nicolas Capenscc863da2015-01-21 15:50:55 -050017#include "debug.h"
John Bauman66b8ab22014-05-06 15:57:45 -040018
19#include <stdarg.h>
20#include <stdio.h>
21
Nicolas Capenscc863da2015-01-21 15:50:55 -050022#include "InitializeParseContext.h"
23#include "ParseHelper.h"
John Bauman66b8ab22014-05-06 15:57:45 -040024
25static const int kTraceBufferLen = 1024;
26
27#ifdef TRACE_ENABLED
28extern "C" {
29void Trace(const char *format, ...) {
Nicolas Capens0bac2852016-05-07 06:09:58 -040030 if (!format) return;
John Bauman66b8ab22014-05-06 15:57:45 -040031
Nicolas Capens0bac2852016-05-07 06:09:58 -040032 TParseContext* parseContext = GetGlobalParseContext();
33 if (parseContext) {
34 char buf[kTraceBufferLen];
35 va_list args;
36 va_start(args, format);
37 vsnprintf(buf, kTraceBufferLen, format, args);
38 va_end(args);
John Bauman66b8ab22014-05-06 15:57:45 -040039
Nicolas Capens0bac2852016-05-07 06:09:58 -040040 parseContext->trace(buf);
41 }
John Bauman66b8ab22014-05-06 15:57:45 -040042}
43} // extern "C"
44#endif // TRACE_ENABLED
45