forked from patrickschulz/openPCells
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generics.lua
78 lines (68 loc) · 1.67 KB
/
generics.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
local M = {}
M.__index = M
local function _create(value)
local self = {
value = value,
isgeneric = true,
get = function(self)
if self.typ == "via" then
return self.value.from, self.value.to
else
return self.value
end
end,
str = function(self)
if self.typ == "metal" then
return string.format("M%d", self:get())
elseif self.typ == "via" then
return string.format("viaM%dM%d", self:get())
elseif self.typ == "contact" then
return string.format("contact%s", self:get())
elseif self.typ == "feol" then
return "feol"
else
return self.value
end
end
}
setmetatable(self, M)
return self
end
function M.metal(num)
local self = _create(num)
self.typ = "metal"
return self
end
function M.via(from, to)
if not from or not to then
error("generic.via with nil")
end
local self = _create({ from = from, to = to })
self.typ = "via"
return self
end
function M.contact(region)
local self = _create(region)
self.typ = "contact"
return self
end
function M.feol(settings)
local self = _create(settings)
self.typ = "feol"
return self
end
function M.other(layer)
local self = _create(layer)
self.typ = "other"
return self
end
function M.mapped(layer)
local self = _create(layer)
self.typ = "mapped"
return self
end
function M.is_type(self, ...)
local comp = function(v) return self.typ == v end
return aux.any_of(comp, { ... })
end
return M